Update .forgejo/workflows/generate-m3u.yml
This commit is contained in:
parent
3c2070236e
commit
004553458d
1 changed files with 289 additions and 21 deletions
|
@ -1,4 +1,4 @@
|
|||
name: Generate M3U Playlist with Auto-Organization
|
||||
]name: Generate M3U Playlist with Auto-Organization
|
||||
|
||||
on:
|
||||
push:
|
||||
|
@ -40,7 +40,7 @@ jobs:
|
|||
find . -name "*.pyc" -delete 2>/dev/null || true
|
||||
find . -name "*.tmp" -delete 2>/dev/null || true
|
||||
find . -name "*~" -delete 2>/dev/null || true
|
||||
mkdir -p reports/logs reports/daily backups config templates
|
||||
mkdir -p reports/logs reports/daily reports/archive backups config templates
|
||||
find . -maxdepth 1 -name "*.log" -exec mv {} reports/logs/ \; 2>/dev/null || true
|
||||
if [ ! -f scripts/__init__.py ]; then
|
||||
echo '# IPTV Scripts Package' > scripts/__init__.py
|
||||
|
@ -72,26 +72,264 @@ jobs:
|
|||
exit 1
|
||||
fi
|
||||
|
||||
- name: Check Results
|
||||
- name: Enhanced Results Analysis and Report Management
|
||||
run: |
|
||||
echo "Checking results..."
|
||||
echo "=== Enhanced Results Analysis with Smart Report Management ==="
|
||||
|
||||
if [ -f playlist.m3u ]; then
|
||||
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
|
||||
SIZE=$(du -h playlist.m3u | cut -f1)
|
||||
echo "Generated playlist: $CHANNELS channels ($SIZE)"
|
||||
echo "✅ Generated playlist: $CHANNELS channels ($SIZE)"
|
||||
|
||||
# Create simple report
|
||||
DATE=$(date +%Y%m%d_%H%M%S)
|
||||
REPORT="reports/daily/report_$DATE.md"
|
||||
echo "# Playlist Report - $(date)" > "$REPORT"
|
||||
echo "- Channels: $CHANNELS" >> "$REPORT"
|
||||
echo "- Size: $SIZE" >> "$REPORT"
|
||||
echo "- Generated: $(date)" >> "$REPORT"
|
||||
echo "Created report: $REPORT"
|
||||
# Show country distribution
|
||||
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 playlist generated"
|
||||
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
|
||||
cd reports/daily
|
||||
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
|
||||
# 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
|
||||
REPORT_DATE=$(echo "$old_report" | sed 's/.*_//; s/\.md//; s/\(....\)\(..\)\(..\).*/\1-\2/')
|
||||
ARCHIVE_DIR="../archive/$REPORT_DATE"
|
||||
mkdir -p "$ARCHIVE_DIR"
|
||||
|
||||
mv "$old_report" "$ARCHIVE_DIR/"
|
||||
echo " 📚 Archived: $old_report → archive/$REPORT_DATE/"
|
||||
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
|
||||
cd - > /dev/null
|
||||
fi
|
||||
|
||||
# Auto-archive old reports (older than 7 days)
|
||||
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)
|
||||
REPORT="reports/daily/playlist_report_$DATE.md"
|
||||
|
||||
# Get countries count and repository stats
|
||||
COUNTRIES_COUNT=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l 2>/dev/null || echo "0")
|
||||
TOTAL_FILES=$(find . -type f -not -path './.git/*' | wc -l)
|
||||
REPO_SIZE=$(du -sh . 2>/dev/null | cut -f1 || echo "unknown")
|
||||
|
||||
# Calculate quality score
|
||||
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
|
||||
echo "- **Archive**: No archived reports yet"
|
||||
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
|
||||
|
||||
- name: Advanced Archive Management
|
||||
run: |
|
||||
echo "=== Advanced Archive Management ==="
|
||||
|
||||
# Archive very old reports (older than 30 days) into monthly folders
|
||||
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
|
||||
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 " 📚 Long-term archived: $BASENAME → archive/$REPORT_DATE/"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$ARCHIVED_COUNT" -gt 0 ]; then
|
||||
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)
|
||||
ARCHIVE_FOLDERS=$(find reports/archive -type d -mindepth 1 2>/dev/null | wc -l)
|
||||
ARCHIVE_REPORTS=$(find reports/archive -name "*.md" 2>/dev/null | wc -l)
|
||||
|
||||
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
|
||||
run: |
|
||||
echo "Cleaning import file..."
|
||||
|
@ -118,21 +356,51 @@ jobs:
|
|||
git add .
|
||||
if ! git diff --staged --quiet; then
|
||||
CHANNELS="0"
|
||||
COUNTRIES="0"
|
||||
if [ -f playlist.m3u ]; then
|
||||
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
|
||||
fi
|
||||
git commit -m "Updated playlist: $CHANNELS channels - $(date '+%Y-%m-%d %H:%M')"
|
||||
git push
|
||||
echo "Changes committed successfully"
|
||||
else
|
||||
echo "No changes to commit"
|
||||
COUNTRIES=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l || echo "0")
|
||||
fi
|
||||
|
||||
- name: Summary
|
||||
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)
|
||||
|
||||
COMMIT_MSG="📺 Updated playlist: $CHANNELS channels across $COUNTRIES countries
|
||||
|
||||
🎯 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
|
||||
echo "✅ Changes committed successfully"
|
||||
else
|
||||
echo "ℹ️ No changes to commit"
|
||||
fi
|
||||
|
||||
- name: Success Summary
|
||||
run: |
|
||||
echo "Workflow completed successfully!"
|
||||
echo "=== 🎉 Workflow Completed Successfully! ==="
|
||||
if [ -f playlist.m3u ]; then
|
||||
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
|
||||
echo "Playlist: $CHANNELS channels"
|
||||
COUNTRIES=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l || echo "0")
|
||||
echo "📺 Playlist: $CHANNELS channels across $COUNTRIES countries"
|
||||
fi
|
||||
echo "Repository is clean and organized"
|
||||
|
||||
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:"
|
||||
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!"
|
Loading…
Add table
Add a link
Reference in a new issue