From 67596f24a494ed3ddada9aeed6c7a1df9da257e5 Mon Sep 17 00:00:00 2001 From: stoney420 Date: Sat, 28 Jun 2025 21:50:24 +0200 Subject: [PATCH] Update .forgejo/workflows/generate-m3u.yml --- .forgejo/workflows/generate-m3u.yml | 205 +++++++++++++++++++++++----- 1 file changed, 174 insertions(+), 31 deletions(-) diff --git a/.forgejo/workflows/generate-m3u.yml b/.forgejo/workflows/generate-m3u.yml index c67d02d..795e649 100644 --- a/.forgejo/workflows/generate-m3u.yml +++ b/.forgejo/workflows/generate-m3u.yml @@ -13,51 +13,194 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.11' # Ensure Python 3.11 is available - - name: Configure Git run: | git config --local user.email "actions@forgejo.plainrock127.xyz" git config --local user.name "IPTV Playlist Bot" - - name: Basic Setup + - name: Setup Python Environment run: | - echo "Basic setup complete." + echo "Setting up Python environment..." + python3 --version + echo "Setting up directories..." + mkdir -p reports/daily reports/logs backups config + echo "Setup completed" + + - name: Check Import File + run: | + echo "Checking import file..." + if [ -f bulk_import.m3u ]; then + LINES=$(wc -l < bulk_import.m3u) + SIZE=$(du -h bulk_import.m3u | cut -f1) + echo "Found bulk_import.m3u with $LINES lines ($SIZE)" + + # Show first few lines to verify content + echo "First 5 lines:" + head -n 5 bulk_import.m3u || echo "Could not read file" + else + echo "Creating empty bulk_import.m3u" + echo '#EXTM3U' > bulk_import.m3u + fi + + - name: Verify Scripts Directory + run: | + echo "Checking scripts directory..." + if [ -d scripts ]; then + echo "Scripts directory exists" + ls -la scripts/ + else + echo "❌ Scripts directory not found!" + exit 1 + fi - name: Run Playlist Generation run: | echo "Running playlist generation..." - python scripts/generate_playlist.py - - - name: Commit and Push if Changes - run: | - git add . - if ! git diff-index --quiet HEAD; then - echo "Changes detected, committing..." - - # --- NEW STEPS --- - # 1. Commit the changes made by this workflow locally first. - # This puts the local repository in a clean state for git pull --rebase. - CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0") - git commit -m "📺 Workflow generated files: $CHANNELS channels (temp commit for rebase)" - - # 2. Pull the latest changes from remote and rebase our local commit on top. - git pull --rebase origin main - - # --- END NEW STEPS --- - - # Now, push the rebased commit. - git push - echo "Changes committed successfully" + cd scripts + if [ -f generate_playlist.py ]; then + echo "Found generate_playlist.py, executing..." + python3 generate_playlist.py + echo "Playlist generation completed with exit code: $?" else + echo "❌ Error: generate_playlist.py not found in scripts/" + exit 1 + fi + + - name: Verify Generated Files + run: | + echo "Verifying generated files..." + if [ -f playlist.m3u ]; then + CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0") + SIZE=$(du -h playlist.m3u | cut -f1) + echo "✅ Generated playlist.m3u with $CHANNELS channels ($SIZE)" + else + echo "⚠️ No playlist.m3u generated" + fi + + if [ -f channels.txt ]; then + SIZE=$(du -h channels.txt | cut -f1) + echo "✅ Updated channels.txt ($SIZE)" + else + echo "⚠️ No channels.txt found" + fi + + - name: Create Simple Report + run: | + echo "Creating report..." + DATE=$(date +%Y%m%d_%H%M%S) + REPORT="reports/daily/report_$DATE.md" + + echo "# IPTV Playlist Report" > "$REPORT" + echo "Generated: $(date)" >> "$REPORT" + echo "" >> "$REPORT" + + if [ -f playlist.m3u ]; then + CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0") + echo "## Summary" >> "$REPORT" + echo "- **Channels:** $CHANNELS" >> "$REPORT" + echo "- **Generated:** $(date)" >> "$REPORT" + echo "- **File size:** $(du -h playlist.m3u | cut -f1)" >> "$REPORT" + + # Add top 10 groups + echo "" >> "$REPORT" + echo "## Top Channel Groups" >> "$REPORT" + if command -v python3 >/dev/null 2>&1; then + python3 -c " +import re +try: + with open('playlist.m3u', 'r') as f: + content = f.read() + groups = {} + for line in content.split('\n'): + if 'group-title=' in line: + match = re.search(r'group-title=\"([^\"]*)', line) + if match: + group = match.group(1) + groups[group] = groups.get(group, 0) + 1 + + for group, count in sorted(groups.items(), key=lambda x: x[1], reverse=True)[:10]: + print(f'- **{group}:** {count} channels') +except Exception as e: + print(f'- Error analyzing groups: {e}') + " >> "$REPORT" + fi + + echo "Report created: $REPORT" + else + echo "**Status:** No playlist generated" >> "$REPORT" + echo "⚠️ No playlist found for report" + fi + + - name: Clean Old Reports + run: | + echo "Cleaning old reports..." + cd reports/daily + if ls *.md >/dev/null 2>&1; then + COUNT=$(ls *.md | wc -l) + echo "Found $COUNT reports" + if [ "$COUNT" -gt 5 ]; then + echo "Removing excess reports (keeping 5 most recent)..." + ls -t *.md | tail -n +6 | xargs rm -f + echo "Cleanup done" + fi + else + echo "No reports to clean" + fi + cd ../.. + + - name: Reset Import File + run: | + echo "Resetting import file..." + echo '#EXTM3U' > bulk_import.m3u + echo "# Import file cleared after processing" >> bulk_import.m3u + echo "# Add your M3U content here for next run" >> bulk_import.m3u + echo "Import file reset and ready for next import" + + - name: Commit Changes + run: | + echo "Committing changes..." + git add . + if git diff --staged --quiet; then echo "No changes to commit" + else + CHANNELS="0" + if [ -f playlist.m3u ]; then + CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0") + fi + + # Create detailed commit message + COMMIT_MSG="📺 Updated playlist with $CHANNELS channels - $(date '+%Y-%m-%d %H:%M')" + + if [ -f reports/daily/report_*.md ]; then + LATEST_REPORT=$(ls -t reports/daily/report_*.md | head -n 1) + if [ -f "$LATEST_REPORT" ]; then + COMMIT_MSG="$COMMIT_MSG + +📊 Latest Report: $(basename "$LATEST_REPORT") +🔄 Auto-processed via workflow" + fi + fi + + git commit -m "$COMMIT_MSG" + git push + echo "✅ Changes committed and pushed" fi - name: Summary run: | - CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0") echo "=== WORKFLOW COMPLETE ===" - echo "✅ Playlist has $CHANNELS channels" \ No newline at end of file + if [ -f playlist.m3u ]; then + CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0") + echo "✅ Playlist has $CHANNELS channels" + + # Show file sizes + echo "📊 File sizes:" + [ -f playlist.m3u ] && echo " - playlist.m3u: $(du -h playlist.m3u | cut -f1)" + [ -f channels.txt ] && echo " - channels.txt: $(du -h channels.txt | cut -f1)" + else + echo "⚠️ No playlist generated" + fi + + echo "✅ Reports updated" + echo "✅ Repository cleaned" + echo "✅ Ready for next import" \ No newline at end of file