From c7dcd2a6a50d98cfaf362a5bb56e93fc9aca4655 Mon Sep 17 00:00:00 2001 From: stoney420 Date: Sat, 28 Jun 2025 02:17:09 +0200 Subject: [PATCH] Update .forgejo/workflows/generate-m3u.yml --- .forgejo/workflows/generate-m3u.yml | 164 +++++++++------------------- 1 file changed, 50 insertions(+), 114 deletions(-) diff --git a/.forgejo/workflows/generate-m3u.yml b/.forgejo/workflows/generate-m3u.yml index ce59311..3fbb52b 100644 --- a/.forgejo/workflows/generate-m3u.yml +++ b/.forgejo/workflows/generate-m3u.yml @@ -26,186 +26,137 @@ jobs: - name: Pre-Cleanup Repository run: | echo "=== Pre-Cleanup Phase ===" - - # Remove Python cache thoroughly find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true find . -name "*.pyc" -delete 2>/dev/null || true find . -name "*.pyo" -delete 2>/dev/null || true - - # Remove temporary files find . -name "*_temp*" -type f -delete 2>/dev/null || true find . -name "*.tmp" -delete 2>/dev/null || true find . -name "*~" -delete 2>/dev/null || true find . -name "*.swp" -delete 2>/dev/null || true - - # Organize log files mkdir -p reports/logs reports/archive find . -maxdepth 1 -name "*.log" -exec mv {} reports/logs/ \; 2>/dev/null || true - - # Clean backup files older than 30 days find backups -name "*.txt" -type f -mtime +30 -delete 2>/dev/null || true - - # Compress old backups (older than 7 days) find backups -name "*.txt" -type f -mtime +7 -exec gzip {} \; 2>/dev/null || true - - echo "โœ… Pre-cleanup completed" + echo "Pre-cleanup completed" - name: Setup Directories run: | echo "=== Directory Setup ===" mkdir -p config backups reports/logs reports/archive templates - - # Create scripts/__init__.py if missing if [ ! -f scripts/__init__.py ]; then echo '# Scripts package' > scripts/__init__.py fi - - # Ensure proper directory structure - echo "Directory structure verified" - name: Debug File Structure run: | echo "=== File Structure Debug ===" - echo "Root files:" - ls -la | head -15 - echo "" + ls -la echo "Scripts directory:" ls -la scripts/ 2>/dev/null || echo "Scripts directory not found" - echo "" echo "Import file status:" if [ -f bulk_import.m3u ]; then LINES=$(wc -l < bulk_import.m3u) SIZE=$(du -h bulk_import.m3u | cut -f1) - echo "โœ… bulk_import.m3u found: $LINES lines ($SIZE)" + echo "bulk_import.m3u found: $LINES lines ($SIZE)" if [ "$LINES" -gt 2 ]; then - echo "๐Ÿ“ฅ Contains channels to process" - echo "First few lines:" + echo "Contains channels to process" head -3 bulk_import.m3u else - echo "๐Ÿ“ญ Empty (ready for import)" + echo "Empty - ready for import" fi else - echo "โŒ bulk_import.m3u not found" + echo "bulk_import.m3u not found" fi - name: Run Playlist Generation run: | echo "=== Playlist Generation ===" - - # Check if generate_playlist.py exists if [ ! -f scripts/generate_playlist.py ]; then - echo "โŒ Error: scripts/generate_playlist.py not found" + echo "Error: scripts/generate_playlist.py not found" exit 1 fi - - # Run the playlist generation - echo "๐Ÿš€ Starting playlist generation..." + echo "Starting playlist generation..." python scripts/generate_playlist.py - - echo "โœ… Playlist generation completed" + echo "Playlist generation completed" - name: Post-Generation Analysis run: | echo "=== Post-Generation Analysis ===" - if [ -f playlist.m3u ]; then CHANNEL_COUNT=$(grep -c "^#EXTINF" playlist.m3u 2>/dev/null || echo "0") FILE_SIZE=$(du -h playlist.m3u | cut -f1) - echo "โœ… Generated playlist.m3u:" - echo " ๐Ÿ“บ Channels: $CHANNEL_COUNT" - echo " ๐Ÿ“ Size: $FILE_SIZE" - - # Show top countries if available - echo " ๐ŸŒ Top countries:" + echo "Generated playlist.m3u:" + echo " Channels: $CHANNEL_COUNT" + echo " Size: $FILE_SIZE" + 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 -5 | \ - while read count country; do - echo " $country: $count channels" - done + grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort | uniq -c | sort -nr | head -5 | while read count country; do + echo " $country: $count channels" + done else - echo " No country grouping found" + echo " No country grouping found" fi else - echo "โŒ playlist.m3u not generated" - echo "Checking for errors..." + echo "playlist.m3u not generated" if [ -f reports/logs/playlist_update.log ]; then echo "Last few log entries:" tail -10 reports/logs/playlist_update.log fi fi - if [ -f channels.txt ]; then CHANNELS_SIZE=$(du -h channels.txt | cut -f1) CHANNELS_LINES=$(wc -l < channels.txt) - echo "๐Ÿ“‹ channels.txt: $CHANNELS_SIZE ($CHANNELS_LINES lines)" + echo "channels.txt: $CHANNELS_SIZE ($CHANNELS_LINES lines)" else - echo "๐Ÿ“‹ channels.txt: Not found" + echo "channels.txt: Not found" fi - - name: Final Cleanup & Organization + - name: Final Cleanup and Organization run: | echo "=== Final Organization ===" - - # Remove any remaining cache/temp files find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true find . -name "*.pyc" -delete 2>/dev/null || true find . -name "*.swp" -delete 2>/dev/null || true find . -name ".DS_Store" -delete 2>/dev/null || true find . -name "*~" -delete 2>/dev/null || true - - # Move any stray log files to reports/logs find . -maxdepth 1 -name "*.log" -exec mv {} reports/logs/ \; 2>/dev/null || true - - # Ensure bulk_import.m3u is clean for next use if [ -f bulk_import.m3u ]; then LINE_COUNT=$(wc -l < bulk_import.m3u) if [ "$LINE_COUNT" -gt 2 ]; then - echo "๐Ÿงน Cleaning bulk_import.m3u for next import..." + echo "Cleaning bulk_import.m3u for next import..." echo '#EXTM3U' > bulk_import.m3u echo '' >> bulk_import.m3u - echo "โœ… bulk_import.m3u cleared and ready" + echo "bulk_import.m3u cleared and ready" else - echo "โœ… bulk_import.m3u already clean" + echo "bulk_import.m3u already clean" fi fi - - echo "โœ… Final cleanup completed" + echo "Final cleanup completed" - name: Repository Health Check run: | echo "=== Repository Health Check ===" - - # Calculate repository stats TOTAL_FILES=$(find . -type f | grep -v '.git' | wc -l) REPO_SIZE=$(du -sh . 2>/dev/null | cut -f1 || echo "unknown") - - echo "๐Ÿ“Š Repository Statistics:" - echo " ๐Ÿ“ Total files: $TOTAL_FILES" - echo " ๐Ÿ’พ Repository size: $REPO_SIZE" - - # Check for common issues + echo "Repository Statistics:" + echo " Total files: $TOTAL_FILES" + echo " Repository size: $REPO_SIZE" 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) - - echo "๐Ÿ” Cleanliness Check:" - echo " ๐Ÿ Python cache dirs: $CACHE_DIRS" - echo " ๐Ÿ—‘๏ธ Temporary files: $TEMP_FILES" - echo " ๐Ÿ“‹ Root log files: $LOG_FILES_ROOT" - + echo "Cleanliness Check:" + echo " Python cache dirs: $CACHE_DIRS" + echo " Temporary files: $TEMP_FILES" + echo " Root log files: $LOG_FILES_ROOT" if [ "$CACHE_DIRS" -eq 0 ] && [ "$TEMP_FILES" -eq 0 ] && [ "$LOG_FILES_ROOT" -eq 0 ]; then - echo "โœ… Repository is clean!" + echo "Repository is clean!" else - echo "โš ๏ธ Some cleanup items remain" + echo "Some cleanup items remain" fi - name: Commit Changes run: | echo "=== Committing Changes ===" - - # Add specific files/directories only (clean approach) git add bulk_import.m3u || true git add channels.txt || true git add playlist.m3u || true @@ -217,26 +168,17 @@ jobs: git add .forgejo/ || true git add README.md || true git add .gitignore || true - - # Remove files that shouldn't be tracked git rm --cached *.log 2>/dev/null || true git rm --cached **/__pycache__/** 2>/dev/null || true git rm --cached **/*.pyc 2>/dev/null || true - - # Check what we're about to commit - echo "๐Ÿ“ Files staged for commit:" + echo "Files staged for commit:" git diff --staged --name-only | head -10 || echo "No staged changes" - if ! git diff --staged --quiet; then - # Calculate stats for commit message CHANNEL_COUNT="0" if [ -f playlist.m3u ]; then CHANNEL_COUNT=$(grep -c "^#EXTINF" playlist.m3u 2>/dev/null || echo "0") fi - REPO_SIZE=$(du -sh . 2>/dev/null | cut -f1 || echo "unknown") - - # Create informative commit message COMMIT_MSG="๐Ÿ“บ Updated playlist: $CHANNEL_COUNT channels ($(date '+%Y-%m-%d %H:%M')) ๐Ÿงน Repository Status: @@ -244,36 +186,30 @@ jobs: - Size: $REPO_SIZE - Auto-cleaned and organized - $(date '+%Y-%m-%d %H:%M:%S UTC')" - git commit -m "$COMMIT_MSG" git push - - echo "โœ… Repository updated successfully" - echo "๐Ÿ“บ Channels: $CHANNEL_COUNT" - echo "๐Ÿ“ Size: $REPO_SIZE" + echo "Repository updated successfully" + echo "Channels: $CHANNEL_COUNT" + echo "Size: $REPO_SIZE" else - echo "โ„น๏ธ No changes to commit" + echo "No changes to commit" fi - name: Workflow Summary run: | echo "=== Workflow Summary ===" - echo "๐ŸŽ‰ IPTV Playlist workflow completed!" - echo "" - + echo "IPTV Playlist workflow completed!" if [ -f playlist.m3u ]; then CHANNEL_COUNT=$(grep -c "^#EXTINF" playlist.m3u 2>/dev/null || echo "0") - echo "โœ… Success Summary:" - echo " ๐Ÿ“บ Playlist generated with $CHANNEL_COUNT channels" - echo " ๐Ÿงน Repository cleaned and organized" - echo " ๐Ÿ“ Files properly structured" - echo " ๐Ÿš€ Ready for next import" + echo "Success Summary:" + echo " Playlist generated with $CHANNEL_COUNT channels" + echo " Repository cleaned and organized" + echo " Files properly structured" + echo " Ready for next import" else - echo "โš ๏ธ Playlist not generated - check logs" + echo "Playlist not generated - check logs" fi - - echo "" - echo "๐Ÿ“‹ Next Steps:" - echo " 1. Add channels to bulk_import.m3u" - echo " 2. Push changes to trigger workflow" - echo " 3. Playlist will be automatically updated" \ No newline at end of file + echo "Next Steps:" + echo " 1. Add channels to bulk_import.m3u" + echo " 2. Push changes to trigger workflow" + echo " 3. Playlist will be automatically updated" \ No newline at end of file