Update .forgejo/workflows/generate-m3u.yml
Some checks failed
Generate M3U Playlist with Auto-Organization / build-and-organize (push) Failing after 1m23s

This commit is contained in:
stoney420 2025-06-28 03:41:57 +02:00
parent 004553458d
commit d6d08ce4aa

View file

@ -1,4 +1,4 @@
]name: Generate M3U Playlist with Auto-Organization name: Generate M3U Playlist with Auto-Organization
on: on:
push: push:
@ -72,263 +72,75 @@ jobs:
exit 1 exit 1
fi fi
- name: Enhanced Results Analysis and Report Management - name: Smart Report Management
run: | run: |
echo "=== Enhanced Results Analysis with Smart Report Management ===" echo "Managing reports..."
if [ -f playlist.m3u ]; then if [ -f playlist.m3u ]; then
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0") CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
SIZE=$(du -h playlist.m3u | cut -f1) SIZE=$(du -h playlist.m3u | cut -f1)
echo "Generated playlist: $CHANNELS channels ($SIZE)" echo "Generated playlist: $CHANNELS channels ($SIZE)"
# Show country distribution # Clean old reports (keep only 3 most recent)
echo "🌍 Top countries:"
if grep -q 'group-title=' playlist.m3u; then
grep 'group-title=' playlist.m3u | \
sed 's/.*group-title="//; s/".*//' | \
sort | uniq -c | sort -nr | head -10 | \
while read count country; do
echo " $country: $count channels"
done
else
echo " No country grouping found"
fi
# ============ SMART REPORT MANAGEMENT ============
echo "=== Smart Report Management ==="
# Auto-cleanup duplicate reports (keep only 3 most recent)
echo "🧹 Managing report count..."
if [ -d reports/daily ]; then if [ -d reports/daily ]; then
cd reports/daily cd reports/daily
REPORT_COUNT=$(ls -1 playlist_report_*.md report_*.md 2>/dev/null | wc -l) REPORT_COUNT=$(ls -1 playlist_report_*.md report_*.md 2>/dev/null | wc -l)
echo " Found $REPORT_COUNT existing reports"
if [ "$REPORT_COUNT" -gt 3 ]; then if [ "$REPORT_COUNT" -gt 3 ]; then
# Keep only 3 most recent, archive the rest
ls -t playlist_report_*.md report_*.md 2>/dev/null | tail -n +4 | while read old_report; do ls -t playlist_report_*.md report_*.md 2>/dev/null | tail -n +4 | while read old_report; do
REPORT_DATE=$(echo "$old_report" | sed 's/.*_//; s/\.md//; s/\(....\)\(..\)\(..\).*/\1-\2/') REPORT_DATE=$(echo "$old_report" | sed 's/.*_//; s/\.md//; s/\(....\)\(..\)\(..\).*/\1-\2/')
ARCHIVE_DIR="../archive/$REPORT_DATE" mkdir -p "../archive/$REPORT_DATE"
mkdir -p "$ARCHIVE_DIR" mv "$old_report" "../archive/$REPORT_DATE/"
echo "Archived: $old_report"
mv "$old_report" "$ARCHIVE_DIR/"
echo " 📚 Archived: $old_report → archive/$REPORT_DATE/"
done done
REMAINING=$(ls -1 playlist_report_*.md report_*.md 2>/dev/null | wc -l)
echo " ✅ Kept $REMAINING most recent reports"
else
echo " ✅ Report count ($REPORT_COUNT) is optimal"
fi fi
cd - > /dev/null cd - > /dev/null
fi fi
# Auto-archive old reports (older than 7 days) # Create new report
echo "🗄️ Auto-archiving old reports..."
CUTOFF_DATE=$(date -d '7 days ago' +%s 2>/dev/null || date -v-7d +%s 2>/dev/null || echo "0")
ARCHIVED_COUNT=0
for report_file in reports/daily/playlist_report_*.md reports/daily/report_*.md; do
if [ -f "$report_file" ]; then
FILE_DATE=$(stat -c %Y "$report_file" 2>/dev/null || stat -f %m "$report_file" 2>/dev/null || echo "0")
if [ "$FILE_DATE" -lt "$CUTOFF_DATE" ] && [ "$FILE_DATE" -gt "0" ]; then
BASENAME=$(basename "$report_file")
REPORT_DATE=$(echo "$BASENAME" | sed 's/.*_//; s/\.md//; s/\(....\)\(..\)\(..\).*/\1-\2/')
ARCHIVE_DIR="reports/archive/$REPORT_DATE"
mkdir -p "$ARCHIVE_DIR"
mv "$report_file" "$ARCHIVE_DIR/"
ARCHIVED_COUNT=$((ARCHIVED_COUNT + 1))
echo " 📚 Auto-archived: $BASENAME → archive/$REPORT_DATE/"
fi
fi
done
if [ "$ARCHIVED_COUNT" -gt 0 ]; then
echo " ✅ Auto-archived $ARCHIVED_COUNT old reports"
else
echo " ✅ No old reports to archive"
fi
# Create enhanced daily report
DATE=$(date +%Y%m%d_%H%M%S) DATE=$(date +%Y%m%d_%H%M%S)
REPORT="reports/daily/playlist_report_$DATE.md" REPORT="reports/daily/playlist_report_$DATE.md"
COUNTRIES=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l || echo "0")
# Get countries count and repository stats echo "# IPTV Playlist Report - $(date)" > "$REPORT"
COUNTRIES_COUNT=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l 2>/dev/null || echo "0") echo "" >> "$REPORT"
TOTAL_FILES=$(find . -type f -not -path './.git/*' | wc -l) echo "## Summary" >> "$REPORT"
REPO_SIZE=$(du -sh . 2>/dev/null | cut -f1 || echo "unknown") echo "- **Channels**: $CHANNELS" >> "$REPORT"
echo "- **Countries**: $COUNTRIES" >> "$REPORT"
echo "- **Size**: $SIZE" >> "$REPORT"
echo "- **Generated**: $(date)" >> "$REPORT"
echo "" >> "$REPORT"
echo "## Top Countries" >> "$REPORT"
grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort | uniq -c | sort -nr | head -10 >> "$REPORT" 2>/dev/null || echo "No country data" >> "$REPORT"
echo "" >> "$REPORT"
echo "---" >> "$REPORT"
echo "*Auto-generated report with smart management*" >> "$REPORT"
# Calculate quality score echo "Created report: $REPORT"
CACHE_DIRS=$(find . -type d -name "__pycache__" | wc -l)
TEMP_FILES=$(find . -name "*.tmp" -o -name "*_temp*" | wc -l)
LOG_FILES_ROOT=$(find . -maxdepth 1 -name "*.log" | wc -l)
TOTAL_ISSUES=$((CACHE_DIRS + TEMP_FILES + LOG_FILES_ROOT))
if [ "$TOTAL_ISSUES" -eq 0 ]; then
QUALITY_SCORE="100/100"
QUALITY_STATUS="🏆 Pristine"
elif [ "$TOTAL_ISSUES" -le 2 ]; then
QUALITY_SCORE="90/100"
QUALITY_STATUS="✅ Excellent"
else
QUALITY_SCORE="75/100"
QUALITY_STATUS="🧹 Good"
fi
cat > "$REPORT" << EOF
# 📺 IPTV Playlist Report - $(date '+%Y-%m-%d %H:%M')
## 📊 Summary
- **Total Channels**: $CHANNELS
- **Countries/Groups**: $COUNTRIES_COUNT
- **File Size**: $SIZE
- **Generated**: $(date '+%Y-%m-%d %H:%M:%S UTC')
- **Repository Status**: $QUALITY_STATUS ($QUALITY_SCORE)
## 🌍 Country Distribution
\`\`\`
$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort | uniq -c | sort -nr | head -15 || echo "No country data available")
\`\`\`
## 📈 Repository Health
- **Total Files**: $TOTAL_FILES
- **Repository Size**: $REPO_SIZE
- **Quality Score**: $QUALITY_SCORE
- **Organization**: Professional ✅
- **Cleanup**: Automated ✅
- **Reports**: Auto-managed ✅
- **Archives**: Auto-organized ✅
## 📋 Report Management Status
- **Active Reports**: $(ls reports/daily/playlist_report_*.md report_*.md 2>/dev/null | wc -l)/3 (auto-managed)
- **Archive Status**: Auto-archiving enabled (7+ days)
- **Log Management**: Centralized in reports/logs/
- **Cleanup Status**: Automated on every run
## 🗂️ Archive Summary
$(if [ -d reports/archive ]; then
echo "- **Archive Folders**: $(find reports/archive -type d -mindepth 1 | wc -l)"
echo "- **Archived Reports**: $(find reports/archive -name "*.md" | wc -l)"
else else
echo "- **Archive**: No archived reports yet" echo "No playlist generated"
fi)
## 🚀 Next Steps
1. Add new channels to \`bulk_import.m3u\`
2. Push changes to trigger automatic processing
3. Reports will be auto-managed (keep 3 recent, archive old)
4. Check \`reports/archive/YYYY-MM/\` for historical reports
---
*Generated automatically by IPTV Playlist Bot with Smart Report Management*
EOF
echo "📋 Created enhanced report: $REPORT"
# Report management summary
ACTIVE_REPORTS=$(ls reports/daily/playlist_report_*.md report_*.md 2>/dev/null | wc -l)
ARCHIVED_REPORTS=$(find reports/archive -name "*.md" 2>/dev/null | wc -l)
echo "📊 Report Management Summary:"
echo " 📋 Active reports: $ACTIVE_REPORTS/3"
echo " 📚 Archived reports: $ARCHIVED_REPORTS"
else
echo "❌ No playlist generated"
if [ -f reports/logs/playlist_update.log ]; then
echo "📋 Last few log entries:"
tail -5 reports/logs/playlist_update.log
fi
fi fi
- name: Advanced Archive Management - name: Archive Old Reports
run: | run: |
echo "=== Advanced Archive Management ===" echo "Managing archives..."
# Archive reports older than 7 days
# Archive very old reports (older than 30 days) into monthly folders CUTOFF_DATE=$(date -d '7 days ago' +%s 2>/dev/null || date -v-7d +%s 2>/dev/null || echo "0")
echo "📚 Managing long-term archives..."
CUTOFF_DATE=$(date -d '30 days ago' +%s 2>/dev/null || date -v-30d +%s 2>/dev/null || echo "0")
ARCHIVED_COUNT=0
for report_file in reports/daily/playlist_report_*.md reports/daily/report_*.md; do for report_file in reports/daily/playlist_report_*.md reports/daily/report_*.md; do
if [ -f "$report_file" ]; then if [ -f "$report_file" ]; then
FILE_DATE=$(stat -c %Y "$report_file" 2>/dev/null || stat -f %m "$report_file" 2>/dev/null || echo "0") FILE_DATE=$(stat -c %Y "$report_file" 2>/dev/null || stat -f %m "$report_file" 2>/dev/null || echo "0")
if [ "$FILE_DATE" -lt "$CUTOFF_DATE" ] && [ "$FILE_DATE" -gt "0" ]; then if [ "$FILE_DATE" -lt "$CUTOFF_DATE" ] && [ "$FILE_DATE" -gt "0" ]; then
BASENAME=$(basename "$report_file") BASENAME=$(basename "$report_file")
REPORT_DATE=$(echo "$BASENAME" | sed 's/.*_//; s/\.md//; s/\(....\)\(..\)\(..\).*/\1-\2/') REPORT_DATE=$(echo "$BASENAME" | sed 's/.*_//; s/\.md//; s/\(....\)\(..\)\(..\).*/\1-\2/')
ARCHIVE_DIR="reports/archive/$REPORT_DATE" mkdir -p "reports/archive/$REPORT_DATE"
mkdir -p "$ARCHIVE_DIR" mv "$report_file" "reports/archive/$REPORT_DATE/"
echo "Archived old report: $BASENAME"
mv "$report_file" "$ARCHIVE_DIR/"
ARCHIVED_COUNT=$((ARCHIVED_COUNT + 1))
echo " 📚 Long-term archived: $BASENAME → archive/$REPORT_DATE/"
fi fi
fi fi
done done
if [ "$ARCHIVED_COUNT" -gt 0 ]; then # Show archive status
echo " ✅ Long-term archived $ARCHIVED_COUNT reports"
else
echo " ✅ No reports need long-term archiving"
fi
# Compress very old archives (older than 90 days)
echo "🗜️ Compressing very old archives..."
COMPRESSED_COUNT=0
CUTOFF_DATE=$(date -d '90 days ago' +%s 2>/dev/null || date -v-90d +%s 2>/dev/null || echo "0")
for archive_dir in reports/archive/*/; do
if [ -d "$archive_dir" ]; then
DIR_DATE=$(basename "$archive_dir")
DIR_TIMESTAMP=$(date -d "${DIR_DATE}-01" +%s 2>/dev/null || date -j -f "%Y-%m-%d" "${DIR_DATE}-01" +%s 2>/dev/null || echo "0")
if [ "$DIR_TIMESTAMP" -lt "$CUTOFF_DATE" ] && [ "$DIR_TIMESTAMP" -gt "0" ]; then
REPORT_COUNT=$(find "$archive_dir" -name "*.md" | wc -l)
if [ "$REPORT_COUNT" -gt 0 ]; then
SUMMARY_FILE="reports/archive/${DIR_DATE}_summary.md"
cat > "$SUMMARY_FILE" << EOF
# Monthly Archive Summary - $DIR_DATE
## Summary
- **Month**: $DIR_DATE
- **Reports Archived**: $REPORT_COUNT
- **Compressed**: $(date '+%Y-%m-%d')
## Reports in Archive
$(find "$archive_dir" -name "*.md" -exec basename {} \; | sort)
---
*Compressed archive summary*
EOF
rm -rf "$archive_dir"
COMPRESSED_COUNT=$((COMPRESSED_COUNT + 1))
echo " 🗜️ Compressed: $DIR_DATE ($REPORT_COUNT reports → summary)"
fi
fi
fi
done
if [ "$COMPRESSED_COUNT" -gt 0 ]; then
echo " ✅ Compressed $COMPRESSED_COUNT old archive folders"
else
echo " ✅ No archives need compression yet"
fi
# Final archive summary
ACTIVE_REPORTS=$(ls reports/daily/playlist_report_*.md report_*.md 2>/dev/null | wc -l) ACTIVE_REPORTS=$(ls reports/daily/playlist_report_*.md report_*.md 2>/dev/null | wc -l)
ARCHIVE_FOLDERS=$(find reports/archive -type d -mindepth 1 2>/dev/null | wc -l) ARCHIVED_REPORTS=$(find reports/archive -name "*.md" 2>/dev/null | wc -l)
ARCHIVE_REPORTS=$(find reports/archive -name "*.md" 2>/dev/null | wc -l) echo "Report status: $ACTIVE_REPORTS active, $ARCHIVED_REPORTS archived"
echo "📊 Final Archive Status:"
echo " 📋 Active reports: $ACTIVE_REPORTS (max 3)"
echo " 📁 Archive folders: $ARCHIVE_FOLDERS"
echo " 📚 Archived reports: $ARCHIVE_REPORTS"
- name: Clean Import File - name: Clean Import File
run: | run: |
@ -362,45 +174,25 @@ jobs:
COUNTRIES=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l || echo "0") COUNTRIES=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l || echo "0")
fi fi
REPO_SIZE=$(du -sh . 2>/dev/null | cut -f1 || echo "unknown")
ACTIVE_REPORTS=$(ls reports/daily/playlist_report_*.md report_*.md 2>/dev/null | wc -l) ACTIVE_REPORTS=$(ls reports/daily/playlist_report_*.md report_*.md 2>/dev/null | wc -l)
COMMIT_MSG="📺 Updated playlist: $CHANNELS channels across $COUNTRIES countries git commit -m "📺 Updated playlist: $CHANNELS channels across $COUNTRIES countries - Reports: $ACTIVE_REPORTS/3 active - $(date '+%Y-%m-%d %H:%M')"
🎯 Repository Status:
📺 Channels: $CHANNELS
🌍 Countries: $COUNTRIES
📁 Size: $REPO_SIZE
📋 Active Reports: $ACTIVE_REPORTS/3
🗂️ Archive: Auto-managed
🧹 Status: Clean & Organized
🚀 Auto-maintained with smart report management
Generated: $(date '+%Y-%m-%d %H:%M UTC')"
git commit -m "$COMMIT_MSG"
git push git push
echo "Changes committed successfully" echo "Changes committed successfully"
else else
echo " No changes to commit" echo "No changes to commit"
fi fi
- name: Success Summary - name: Success Summary
run: | run: |
echo "=== 🎉 Workflow Completed Successfully! ===" echo "Workflow completed successfully!"
if [ -f playlist.m3u ]; then if [ -f playlist.m3u ]; then
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0") CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
COUNTRIES=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l || echo "0") COUNTRIES=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l || echo "0")
echo "📺 Playlist: $CHANNELS channels across $COUNTRIES countries" echo "Playlist: $CHANNELS channels across $COUNTRIES countries"
fi fi
ACTIVE_REPORTS=$(ls reports/daily/playlist_report_*.md report_*.md 2>/dev/null | wc -l) ACTIVE_REPORTS=$(ls reports/daily/playlist_report_*.md report_*.md 2>/dev/null | wc -l)
ARCHIVED_REPORTS=$(find reports/archive -name "*.md" 2>/dev/null | wc -l) ARCHIVED_REPORTS=$(find reports/archive -name "*.md" 2>/dev/null | wc -l)
echo "Reports: $ACTIVE_REPORTS active, $ARCHIVED_REPORTS archived"
echo "📊 Report Management:" echo "Repository is clean and organized with smart report management!"
echo " 📋 Active: $ACTIVE_REPORTS/3 reports"
echo " 📚 Archived: $ARCHIVED_REPORTS reports"
echo " 🎯 Status: Fully automated"
echo ""
echo "🚀 Repository is clean, organized, and ready for next import!"