From d6d08ce4aa9410d64d95d2dff91a0c13d5e94934 Mon Sep 17 00:00:00 2001 From: stoney420 Date: Sat, 28 Jun 2025 03:41:57 +0200 Subject: [PATCH] Update .forgejo/workflows/generate-m3u.yml --- .forgejo/workflows/generate-m3u.yml | 292 ++++------------------------ 1 file changed, 42 insertions(+), 250 deletions(-) diff --git a/.forgejo/workflows/generate-m3u.yml b/.forgejo/workflows/generate-m3u.yml index d29cdf9..852150c 100644 --- a/.forgejo/workflows/generate-m3u.yml +++ b/.forgejo/workflows/generate-m3u.yml @@ -1,4 +1,4 @@ -]name: Generate M3U Playlist with Auto-Organization +name: Generate M3U Playlist with Auto-Organization on: push: @@ -72,263 +72,75 @@ jobs: exit 1 fi - - name: Enhanced Results Analysis and Report Management + - name: Smart Report Management run: | - echo "=== Enhanced Results Analysis with Smart Report Management ===" - + echo "Managing reports..." 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)" - # 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..." + # Clean old reports (keep only 3 most recent) 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/" + mkdir -p "../archive/$REPORT_DATE" + mv "$old_report" "../archive/$REPORT_DATE/" + echo "Archived: $old_report" 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 + # Create new report DATE=$(date +%Y%m%d_%H%M%S) 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 - 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") + echo "# IPTV Playlist Report - $(date)" > "$REPORT" + echo "" >> "$REPORT" + echo "## Summary" >> "$REPORT" + 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 - 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)" + echo "Created report: $REPORT" 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 + echo "No playlist generated" fi - - name: Advanced Archive Management + - name: Archive Old Reports 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 - + echo "Managing archives..." + # Archive reports older than 7 days + CUTOFF_DATE=$(date -d '7 days ago' +%s 2>/dev/null || date -v-7d +%s 2>/dev/null || echo "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/" + mkdir -p "reports/archive/$REPORT_DATE" + mv "$report_file" "reports/archive/$REPORT_DATE/" + echo "Archived old report: $BASENAME" 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 + # Show archive status 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" + ARCHIVED_REPORTS=$(find reports/archive -name "*.md" 2>/dev/null | wc -l) + echo "Report status: $ACTIVE_REPORTS active, $ARCHIVED_REPORTS archived" - name: Clean Import File run: | @@ -362,45 +174,25 @@ jobs: 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 commit -m "๐Ÿ“บ Updated playlist: $CHANNELS channels across $COUNTRIES countries - Reports: $ACTIVE_REPORTS/3 active - $(date '+%Y-%m-%d %H:%M')" git push - echo "โœ… Changes committed successfully" + echo "Changes committed successfully" else - echo "โ„น๏ธ No changes to commit" + 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") 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 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!" \ No newline at end of file + echo "Reports: $ACTIVE_REPORTS active, $ARCHIVED_REPORTS archived" + echo "Repository is clean and organized with smart report management!" \ No newline at end of file