2025-06-28 02:12:46 +02:00
|
|
|
|
name: Generate M3U Playlist with Auto-Setup & Cleanup
|
2025-06-27 16:30:39 +02:00
|
|
|
|
|
|
|
|
|
on:
|
|
|
|
|
push:
|
|
|
|
|
branches:
|
|
|
|
|
- main
|
|
|
|
|
workflow_dispatch:
|
|
|
|
|
|
|
|
|
|
jobs:
|
2025-06-28 02:05:53 +02:00
|
|
|
|
build-and-cleanup:
|
2025-06-27 16:30:39 +02:00
|
|
|
|
runs-on: ubuntu-22.04
|
|
|
|
|
steps:
|
2025-06-27 23:41:32 +02:00
|
|
|
|
- name: Checkout Repository
|
2025-06-27 16:30:39 +02:00
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
|
2025-06-27 23:41:32 +02:00
|
|
|
|
- name: Set up Python
|
2025-06-27 16:30:39 +02:00
|
|
|
|
uses: actions/setup-python@v5
|
|
|
|
|
with:
|
2025-06-27 17:36:55 +02:00
|
|
|
|
python-version: '3.11'
|
2025-06-27 16:30:39 +02:00
|
|
|
|
|
2025-06-27 23:41:32 +02:00
|
|
|
|
- name: Configure Git
|
2025-06-27 16:30:39 +02:00
|
|
|
|
run: |
|
|
|
|
|
git config --local user.email "actions@forgejo.plainrock127.xyz"
|
2025-06-27 17:36:55 +02:00
|
|
|
|
git config --local user.name "IPTV Playlist Bot"
|
2025-06-27 16:30:39 +02:00
|
|
|
|
|
2025-06-28 02:12:46 +02:00
|
|
|
|
- name: Auto-Setup Repository (First Run)
|
2025-06-27 17:36:55 +02:00
|
|
|
|
run: |
|
2025-06-28 02:12:46 +02:00
|
|
|
|
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
|
2025-06-28 02:05:53 +02:00
|
|
|
|
run: |
|
2025-06-28 02:12:46 +02:00
|
|
|
|
echo "=== Pre-Generation Cleanup ==="
|
2025-06-28 02:05:53 +02:00
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
|
# Organize log files
|
|
|
|
|
mkdir -p reports/logs reports/archive
|
|
|
|
|
find . -maxdepth 1 -name "*.log" -exec mv {} reports/logs/ \; 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
|
|
|
|
|
|
2025-06-28 02:12:46 +02:00
|
|
|
|
echo "✅ Pre-cleanup completed"
|
2025-06-28 02:05:53 +02:00
|
|
|
|
|
2025-06-28 00:11:35 +02:00
|
|
|
|
- name: Setup Directories
|
|
|
|
|
run: |
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo "=== Directory Setup ==="
|
|
|
|
|
mkdir -p config backups reports/logs reports/archive templates
|
2025-06-28 00:11:35 +02:00
|
|
|
|
|
|
|
|
|
# Create scripts/__init__.py if missing
|
|
|
|
|
if [ ! -f scripts/__init__.py ]; then
|
|
|
|
|
echo '# Scripts package' > scripts/__init__.py
|
|
|
|
|
fi
|
2025-06-28 02:05:53 +02:00
|
|
|
|
|
|
|
|
|
- name: Debug File Structure
|
|
|
|
|
run: |
|
2025-06-28 02:12:46 +02:00
|
|
|
|
echo "=== File Structure ==="
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo "Import file status:"
|
|
|
|
|
if [ -f bulk_import.m3u ]; then
|
2025-06-28 02:12:46 +02:00
|
|
|
|
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
|
2025-06-28 02:05:53 +02:00
|
|
|
|
else
|
|
|
|
|
echo "❌ bulk_import.m3u not found"
|
|
|
|
|
fi
|
2025-06-28 00:11:35 +02:00
|
|
|
|
|
|
|
|
|
- name: Run Playlist Generation
|
|
|
|
|
run: |
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo "=== Playlist Generation ==="
|
2025-06-28 00:11:35 +02:00
|
|
|
|
python scripts/generate_playlist.py
|
2025-06-27 17:36:55 +02:00
|
|
|
|
|
2025-06-28 02:12:46 +02:00
|
|
|
|
- name: Post-Generation Analysis
|
2025-06-27 17:36:55 +02:00
|
|
|
|
run: |
|
2025-06-28 02:12:46 +02:00
|
|
|
|
echo "=== Results Analysis ==="
|
2025-06-28 00:11:35 +02:00
|
|
|
|
|
2025-06-27 17:36:55 +02:00
|
|
|
|
if [ -f playlist.m3u ]; then
|
2025-06-28 02:05:53 +02:00
|
|
|
|
CHANNEL_COUNT=$(grep -c "^#EXTINF" playlist.m3u 2>/dev/null || echo "0")
|
|
|
|
|
FILE_SIZE=$(du -h playlist.m3u | cut -f1)
|
2025-06-28 02:12:46 +02:00
|
|
|
|
echo "✅ Generated playlist.m3u:"
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo " - Channels: $CHANNEL_COUNT"
|
|
|
|
|
echo " - Size: $FILE_SIZE"
|
|
|
|
|
|
2025-06-28 02:12:46 +02:00
|
|
|
|
# Show top 3 countries
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo " - Top countries:"
|
2025-06-28 02:12:46 +02:00
|
|
|
|
grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort | uniq -c | sort -nr | head -3 || true
|
2025-06-28 00:11:35 +02:00
|
|
|
|
else
|
|
|
|
|
echo "❌ playlist.m3u not generated"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -f channels.txt ]; then
|
2025-06-28 02:05:53 +02:00
|
|
|
|
CHANNELS_SIZE=$(du -h channels.txt | cut -f1)
|
2025-06-28 02:12:46 +02:00
|
|
|
|
echo "📁 channels.txt: $CHANNELS_SIZE"
|
2025-06-28 00:57:29 +02:00
|
|
|
|
fi
|
2025-06-28 02:05:53 +02:00
|
|
|
|
|
2025-06-28 02:12:46 +02:00
|
|
|
|
- name: Final Cleanup & Organization
|
2025-06-27 16:30:39 +02:00
|
|
|
|
run: |
|
2025-06-28 02:12:46 +02:00
|
|
|
|
echo "=== Final Organization ==="
|
2025-06-28 02:05:53 +02:00
|
|
|
|
|
2025-06-28 02:12:46 +02:00
|
|
|
|
# Run Python cleanup if script exists
|
|
|
|
|
if [ -f scripts/quick_cleanup.py ]; then
|
|
|
|
|
python scripts/quick_cleanup.py
|
|
|
|
|
fi
|
2025-06-28 00:57:29 +02:00
|
|
|
|
|
2025-06-28 02:05:53 +02:00
|
|
|
|
# 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
|
2025-06-28 02:12:46 +02:00
|
|
|
|
echo "🧹 Cleaning bulk_import.m3u for next import..."
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo '#EXTM3U' > bulk_import.m3u
|
|
|
|
|
echo '' >> bulk_import.m3u
|
|
|
|
|
fi
|
2025-06-28 00:57:29 +02:00
|
|
|
|
fi
|
|
|
|
|
|
2025-06-28 02:12:46 +02:00
|
|
|
|
# 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"
|
2025-06-28 02:05:53 +02:00
|
|
|
|
|
|
|
|
|
- name: Commit Changes
|
|
|
|
|
run: |
|
|
|
|
|
echo "=== Committing Changes ==="
|
|
|
|
|
|
2025-06-28 02:12:46 +02:00
|
|
|
|
# Add specific files/directories (clean approach)
|
|
|
|
|
git add .gitignore || true
|
2025-06-28 00:57:29 +02:00
|
|
|
|
git add bulk_import.m3u || true
|
|
|
|
|
git add channels.txt || true
|
|
|
|
|
git add playlist.m3u || true
|
|
|
|
|
git add scripts/ || true
|
|
|
|
|
git add config/ || true
|
|
|
|
|
git add reports/ || true
|
2025-06-28 02:05:53 +02:00
|
|
|
|
git add backups/*.gz || true # Only compressed backups
|
2025-06-28 00:57:29 +02:00
|
|
|
|
git add templates/ || true
|
|
|
|
|
git add .forgejo/ || true
|
|
|
|
|
git add README.md || true
|
|
|
|
|
|
2025-06-28 02:12:46 +02:00
|
|
|
|
# Remove files that shouldn't be tracked
|
2025-06-28 02:05:53 +02:00
|
|
|
|
git rm --cached *.log 2>/dev/null || true
|
|
|
|
|
git rm --cached **/__pycache__/** 2>/dev/null || true
|
|
|
|
|
|
2025-06-28 02:12:46 +02:00
|
|
|
|
# Check what we're committing
|
|
|
|
|
echo "Files staged for commit:"
|
|
|
|
|
git diff --staged --name-only | head -10 || echo "No changes"
|
2025-06-28 00:57:29 +02:00
|
|
|
|
|
2025-06-27 23:42:36 +02:00
|
|
|
|
if ! git diff --staged --quiet; then
|
2025-06-28 02:12:46 +02:00
|
|
|
|
# Calculate stats for commit message
|
2025-06-27 17:36:55 +02:00
|
|
|
|
CHANNEL_COUNT="0"
|
2025-06-28 02:12:46 +02:00
|
|
|
|
REPO_SIZE="unknown"
|
|
|
|
|
|
2025-06-27 17:36:55 +02:00
|
|
|
|
if [ -f playlist.m3u ]; then
|
2025-06-28 02:05:53 +02:00
|
|
|
|
CHANNEL_COUNT=$(grep -c "^#EXTINF" playlist.m3u 2>/dev/null || echo "0")
|
2025-06-27 17:36:55 +02:00
|
|
|
|
fi
|
2025-06-28 00:57:29 +02:00
|
|
|
|
|
2025-06-28 02:05:53 +02:00
|
|
|
|
REPO_SIZE=$(du -sh . 2>/dev/null | cut -f1 || echo "unknown")
|
|
|
|
|
|
2025-06-28 02:12:46 +02:00
|
|
|
|
# Create clean commit message
|
|
|
|
|
COMMIT_MSG="📺 Updated playlist: $CHANNEL_COUNT channels ($(date '+%Y-%m-%d %H:%M'))
|
2025-06-28 02:05:53 +02:00
|
|
|
|
|
2025-06-28 02:12:46 +02:00
|
|
|
|
🧹 Auto-cleaned repository:
|
|
|
|
|
- Size: $REPO_SIZE
|
|
|
|
|
- Channels: $CHANNEL_COUNT
|
|
|
|
|
- Organized structure
|
|
|
|
|
- Ready for next import"
|
2025-06-28 02:05:53 +02:00
|
|
|
|
|
|
|
|
|
git commit -m "$COMMIT_MSG"
|
2025-06-27 23:42:36 +02:00
|
|
|
|
git push
|
2025-06-28 00:57:29 +02:00
|
|
|
|
|
2025-06-28 02:12:46 +02:00
|
|
|
|
echo "✅ Repository updated and cleaned"
|
|
|
|
|
echo "📺 Channels: $CHANNEL_COUNT"
|
|
|
|
|
echo "📁 Size: $REPO_SIZE"
|
2025-06-28 00:57:29 +02:00
|
|
|
|
else
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo "ℹ️ No changes to commit"
|
|
|
|
|
fi
|
|
|
|
|
|
2025-06-28 02:12:46 +02:00
|
|
|
|
- name: Success Summary
|
2025-06-28 02:05:53 +02:00
|
|
|
|
run: |
|
2025-06-28 02:12:46 +02:00
|
|
|
|
echo "=== Workflow Complete ==="
|
|
|
|
|
echo "🎉 IPTV Playlist Generator workflow finished successfully!"
|
2025-06-28 02:05:53 +02:00
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
|
|
if [ -f playlist.m3u ]; then
|
|
|
|
|
CHANNEL_COUNT=$(grep -c "^#EXTINF" playlist.m3u 2>/dev/null || echo "0")
|
2025-06-28 02:12:46 +02:00
|
|
|
|
echo "📊 Results:"
|
|
|
|
|
echo " - Channels processed: $CHANNEL_COUNT"
|
|
|
|
|
echo " - Repository: Clean and organized"
|
|
|
|
|
echo " - Ready for: Next bulk import"
|
2025-06-28 02:05:53 +02:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo ""
|
2025-06-28 02:12:46 +02:00
|
|
|
|
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!"
|