my-private-iptv-m3u/.forgejo/workflows/generate-m3u.yml
Workflow config file is invalid. Please check your config file: yaml: mapping values are not allowed in this context

406 lines
No EOL
16 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

]name: Generate M3U Playlist with Auto-Organization
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build-and-organize:
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Configure Git
run: |
git config --local user.email "actions@forgejo.plainrock127.xyz"
git config --local user.name "IPTV Playlist Bot"
- name: Run Comprehensive Cleanup
run: |
echo "Running comprehensive cleanup..."
if [ -f comprehensive_cleanup.py ]; then
python comprehensive_cleanup.py
echo "Comprehensive cleanup completed"
else
echo "Cleanup already completed"
fi
- name: Basic Repository Maintenance
run: |
echo "Running basic maintenance..."
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
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 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
fi
echo "Basic maintenance completed"
- name: Check Import File
run: |
echo "Checking import file..."
if [ -f bulk_import.m3u ]; then
LINES=$(wc -l < bulk_import.m3u)
echo "Found bulk_import.m3u with $LINES lines"
if [ "$LINES" -gt 2 ]; then
echo "Contains channels to process"
fi
else
echo "Creating empty bulk_import.m3u"
echo '#EXTM3U' > bulk_import.m3u
fi
- name: Run Playlist Generation
run: |
echo "Running playlist generation..."
if [ -f scripts/generate_playlist.py ]; then
python scripts/generate_playlist.py
echo "Playlist generation completed"
else
echo "Error: generate_playlist.py not found"
exit 1
fi
- name: Enhanced Results Analysis and Report Management
run: |
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)"
# 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 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..."
if [ -f bulk_import.m3u ]; then
LINES=$(wc -l < bulk_import.m3u)
if [ "$LINES" -gt 2 ]; then
echo '#EXTM3U' > bulk_import.m3u
echo "Cleaned import file for next use"
fi
fi
- name: Final Cleanup
run: |
echo "Final cleanup..."
find . -name "*.pyc" -delete 2>/dev/null || true
find . -name "*~" -delete 2>/dev/null || true
find . -name "*.swp" -delete 2>/dev/null || true
rm -f comprehensive_cleanup.py 2>/dev/null || true
echo "Final cleanup completed"
- name: Commit Changes
run: |
echo "Committing changes..."
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")
COUNTRIES=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l || echo "0")
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)
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! ==="
if [ -f playlist.m3u ]; then
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")
echo "📺 Playlist: $CHANNELS channels across $COUNTRIES countries"
fi
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!"