diff --git a/.forgejo/workflows/generate-m3u.yml b/.forgejo/workflows/generate-m3u.yml index f6e7209..36d3879 100644 --- a/.forgejo/workflows/generate-m3u.yml +++ b/.forgejo/workflows/generate-m3u.yml @@ -1,4 +1,4 @@ -name: Generate M3U Playlist with Auto-Cleanup +name: Generate M3U Playlist with Auto-Setup & Cleanup on: push: @@ -23,27 +23,95 @@ jobs: git config --local user.email "actions@forgejo.plainrock127.xyz" git config --local user.name "IPTV Playlist Bot" - - name: Pre-Cleanup Health Check + - name: Auto-Setup Repository (First Run) run: | - echo "=== Repository Health Check ===" - python -c " - import sys, os - sys.path.insert(0, 'scripts') - from repo_health import RepoHealthMonitor - monitor = RepoHealthMonitor() - health = monitor.run_health_check() - print(f'Organization Score: {health[\"organization_score\"]}/100') - print(f'Total Size: {health[\"repository_size\"][\"total_mb\"]:.1f} MB') - print(f'Files: {health[\"file_counts\"][\"total_files\"]}') - if health['cleanup_suggestions']: - print('Cleanup needed:') - for suggestion in health['cleanup_suggestions'][:3]: - print(f' - {suggestion}') - " 2>/dev/null || echo "Health check skipped (first run)" - - - name: Auto-Cleanup Repository + echo "=== Auto-Setup Check ===" + + # Check if enhanced .gitignore exists + if [ ! -f .gitignore ] || ! grep -q "IPTV Playlist Generator" .gitignore; then + echo "๐Ÿ”ง Setting up enhanced .gitignore..." + cat > .gitignore << 'EOF' + # IPTV Playlist Generator - Enhanced .gitignore + + # ===== PYTHON ===== + __pycache__/ + *.py[cod] + *$py.class + *.so + + # ===== LOGS & TEMPORARY FILES ===== + *.log + *.tmp + *_temp* + *.backup.* + temp_* + + # ===== IDE & EDITOR FILES ===== + .vscode/ + .idea/ + *.swp + *.swo + *~ + .DS_Store + Thumbs.db + + # ===== IPTV SPECIFIC ===== + bulk_import_temp.m3u + import_temp_*.m3u + *_processing.m3u + playlist_temp.m3u + temp_playlist_*.m3u + EOF + echo "โœ… Enhanced .gitignore created" + fi + + # Create quick cleanup script if missing + if [ ! -f scripts/quick_cleanup.py ]; then + echo "๐Ÿ”ง Creating cleanup script..." + mkdir -p scripts + cat > scripts/quick_cleanup.py << 'EOF' + #!/usr/bin/env python3 + """Quick cleanup for IPTV repository""" + import os + import shutil + from pathlib import Path + + def cleanup(): + root = Path.cwd() + cleaned = 0 + + # Remove Python cache + for cache in root.rglob('__pycache__'): + if cache.is_dir(): + shutil.rmtree(cache, ignore_errors=True) + cleaned += 1 + + # Remove temp files + for pattern in ['*.pyc', '*.pyo', '*_temp*', '*.tmp', '*~']: + for file in root.rglob(pattern): + if file.is_file() and '.git' not in str(file): + file.unlink(missing_ok=True) + cleaned += 1 + + # Organize logs + logs_dir = root / 'reports' / 'logs' + logs_dir.mkdir(parents=True, exist_ok=True) + for log in root.glob('*.log'): + shutil.move(str(log), str(logs_dir / log.name)) + cleaned += 1 + + print(f"๐Ÿงน Cleaned {cleaned} items") + return cleaned + + if __name__ == "__main__": + cleanup() + EOF + echo "โœ… Cleanup script created" + fi + + - name: Pre-Generation Cleanup run: | - echo "=== Auto-Cleanup Phase ===" + echo "=== Pre-Generation Cleanup ===" # Remove Python cache thoroughly find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true @@ -55,9 +123,6 @@ jobs: find . -name "*.tmp" -delete 2>/dev/null || true find . -name "*~" -delete 2>/dev/null || true - # Clean backup files older than 30 days - find backups -name "*.txt" -type f -mtime +30 -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 @@ -65,7 +130,7 @@ jobs: # Compress old backups (older than 7 days) find backups -name "*.txt" -type f -mtime +7 -exec gzip {} \; 2>/dev/null || true - echo "โœ… Cleanup completed" + echo "โœ… Pre-cleanup completed" - name: Setup Directories run: | @@ -76,24 +141,18 @@ jobs: if [ ! -f scripts/__init__.py ]; then echo '# Scripts package' > scripts/__init__.py fi - - # Ensure proper directory structure - ls -la scripts/ || echo "Scripts directory missing" - name: Debug File Structure run: | - echo "=== File Structure Debug ===" - echo "Root files:" - ls -la | head -20 - echo "" - echo "Scripts directory:" - ls -la scripts/ 2>/dev/null || echo "Scripts directory not found" - echo "" + echo "=== File Structure ===" echo "Import file status:" if [ -f bulk_import.m3u ]; then - echo "โœ… bulk_import.m3u found ($(wc -l < bulk_import.m3u) lines, $(du -h bulk_import.m3u | cut -f1))" - echo "First few lines:" - head -5 bulk_import.m3u + LINES=$(wc -l < bulk_import.m3u) + SIZE=$(du -h bulk_import.m3u | cut -f1) + echo "โœ… bulk_import.m3u: $LINES lines, $SIZE" + if [ "$LINES" -gt 2 ]; then + echo "๐Ÿ“ฅ Contains channels to process" + fi else echo "โŒ bulk_import.m3u not found" fi @@ -103,68 +162,60 @@ jobs: echo "=== Playlist Generation ===" python scripts/generate_playlist.py - - name: Post-Generation Health Check + - name: Post-Generation Analysis run: | - echo "=== Post-Generation Analysis ===" + echo "=== Results 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 "โœ… playlist.m3u generated:" + echo "โœ… Generated playlist.m3u:" echo " - Channels: $CHANNEL_COUNT" echo " - Size: $FILE_SIZE" - # Show top countries + # Show top 3 countries echo " - Top countries:" - grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort | uniq -c | sort -nr | head -5 || echo " No country data" + grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort | uniq -c | sort -nr | head -3 || true else echo "โŒ playlist.m3u not generated" 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)" - fi - - # Check for any error logs - if [ -f reports/logs/playlist_update.log ]; then - echo "๐Ÿ“‹ Recent log entries:" - tail -10 reports/logs/playlist_update.log || tail -10 playlist_update.log 2>/dev/null || echo "No logs found" + echo "๐Ÿ“ channels.txt: $CHANNELS_SIZE" fi - - name: Repository Cleanup & Organization + - name: Final Cleanup & Organization run: | - echo "=== Final Repository Organization ===" + echo "=== Final Organization ===" - # Remove any remaining cache files - find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true - - # Move any stray log files - find . -maxdepth 1 -name "*.log" -exec mv {} reports/logs/ \; 2>/dev/null || true - - # Clean up any editor backup files - find . -name "*~" -delete 2>/dev/null || true - find . -name "*.swp" -delete 2>/dev/null || true + # Run Python cleanup if script exists + if [ -f scripts/quick_cleanup.py ]; then + python scripts/quick_cleanup.py + fi # Ensure bulk_import.m3u is clean for next use if [ -f bulk_import.m3u ]; then - # If it has more than just the header, it means it wasn't cleaned by the script LINE_COUNT=$(wc -l < bulk_import.m3u) if [ "$LINE_COUNT" -gt 2 ]; then - echo "โš ๏ธ Manually cleaning bulk_import.m3u (had $LINE_COUNT lines)" + echo "๐Ÿงน Cleaning bulk_import.m3u for next import..." echo '#EXTM3U' > bulk_import.m3u echo '' >> bulk_import.m3u fi fi - echo "โœ… Repository organized" + # Remove any remaining clutter + find . -name "*.swp" -delete 2>/dev/null || true + find . -name ".DS_Store" -delete 2>/dev/null || true + + echo "โœ… Final cleanup completed" - name: Commit Changes run: | echo "=== Committing Changes ===" - # Add specific files/directories (exclude unnecessary items) + # Add specific files/directories (clean approach) + git add .gitignore || true git add bulk_import.m3u || true git add channels.txt || true git add playlist.m3u || true @@ -175,72 +226,61 @@ jobs: git add templates/ || true git add .forgejo/ || true git add README.md || true - git add .gitignore || true - # Remove any files that shouldn't be tracked + # 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 to be committed:" - git diff --staged --name-only || echo "No staged changes" + # Check what we're committing + echo "Files staged for commit:" + git diff --staged --name-only | head -10 || echo "No changes" if ! git diff --staged --quiet; then - # Calculate channel count for commit message + # Calculate stats for commit message CHANNEL_COUNT="0" + REPO_SIZE="unknown" + if [ -f playlist.m3u ]; then CHANNEL_COUNT=$(grep -c "^#EXTINF" playlist.m3u 2>/dev/null || echo "0") fi - # Calculate repository size 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')) + # Create clean commit message + COMMIT_MSG="๐Ÿ“บ Updated playlist: $CHANNEL_COUNT channels ($(date '+%Y-%m-%d %H:%M')) -Repository Status: -- Size: $REPO_SIZE -- Channels: $CHANNEL_COUNT -- Auto-cleaned and organized -- $(date '+%Y-%m-%d %H:%M:%S UTC')" +๐Ÿงน Auto-cleaned repository: + - Size: $REPO_SIZE + - Channels: $CHANNEL_COUNT + - Organized structure + - Ready for next import" git commit -m "$COMMIT_MSG" git push - echo "โœ… Repository updated successfully" - echo " ๐Ÿ“บ Channels: $CHANNEL_COUNT" - echo " ๐Ÿ“ Size: $REPO_SIZE" + echo "โœ… Repository updated and cleaned" + echo "๐Ÿ“บ Channels: $CHANNEL_COUNT" + echo "๐Ÿ“ Size: $REPO_SIZE" else echo "โ„น๏ธ No changes to commit" fi - - name: Final Status Report + - name: Success Summary run: | - echo "=== Final Status Report ===" - echo "๐ŸŽฏ Workflow completed successfully!" - echo "" - echo "๐Ÿ“Š Repository Statistics:" - echo " - Total files: $(find . -type f | wc -l)" - echo " - Directory size: $(du -sh . | cut -f1)" - echo " - Git status: $(git status --porcelain | wc -l) pending changes" + echo "=== Workflow Complete ===" + echo "๐ŸŽ‰ IPTV Playlist Generator workflow finished successfully!" echo "" if [ -f playlist.m3u ]; then CHANNEL_COUNT=$(grep -c "^#EXTINF" playlist.m3u 2>/dev/null || echo "0") - echo "โœ… Playlist Status:" - echo " - Channels: $CHANNEL_COUNT" - echo " - File size: $(du -h playlist.m3u | cut -f1)" - echo " - Last updated: $(date)" - else - echo "โŒ No playlist generated" + echo "๐Ÿ“Š Results:" + echo " - Channels processed: $CHANNEL_COUNT" + echo " - Repository: Clean and organized" + echo " - Ready for: Next bulk import" fi echo "" - echo "๐Ÿงน Cleanup Summary:" - echo " - Python cache: Removed" - echo " - Log files: Organized in reports/logs/" - echo " - Backup files: Compressed if older than 7 days" - echo " - Temporary files: Cleaned" - echo "" - echo "๐Ÿš€ Ready for next import!" \ No newline at end of file + echo "๐Ÿš€ Next steps:" + echo " 1. Add channels to bulk_import.m3u" + echo " 2. Push to trigger this workflow" + echo " 3. Your playlist will be automatically updated!" \ No newline at end of file