From 901e2618c6bfa1eb80f5be20ceaf522824967f6b Mon Sep 17 00:00:00 2001 From: stoney420 Date: Fri, 27 Jun 2025 17:51:10 +0200 Subject: [PATCH] Update .forgejo/workflows/generate-m3u.yml --- .forgejo/workflows/generate-m3u.yml | 269 +++++++++++++++++++++------- 1 file changed, 207 insertions(+), 62 deletions(-) diff --git a/.forgejo/workflows/generate-m3u.yml b/.forgejo/workflows/generate-m3u.yml index 87bc418..653e6b6 100644 --- a/.forgejo/workflows/generate-m3u.yml +++ b/.forgejo/workflows/generate-m3u.yml @@ -23,150 +23,295 @@ jobs: git config --local user.email "actions@forgejo.plainrock127.xyz" git config --local user.name "IPTV Playlist Bot" - - name: 📁 Create directory structure + - name: 📁 Create directory structure and initial files run: | echo "=== Creating directory structure ===" mkdir -p logs config templates scripts docs - chmod 664 channels.txt 2>/dev/null || echo "channels.txt not found" - chmod 664 bulk_import.m3u 2>/dev/null || echo "bulk_import.m3u not found" + + echo "=== Creating initial config files if they don't exist ===" + if [ ! -f config/settings.json ]; then + cat > config/settings.json << 'EOF' + { + "remove_duplicates": true, + "sort_channels": true, + "validate_urls": false, + "backup_before_import": true, + "auto_cleanup_import": true + } + EOF + echo "Created config/settings.json" + fi + + if [ ! -f config/group_overrides.json ]; then + cat > config/group_overrides.json << 'EOF' + { + "ESPN": "Sports", + "Fox Sports": "Sports", + "CNN": "News", + "BBC": "News", + "Discovery": "Documentary", + "HBO": "Movies", + "Disney": "Kids", + "MTV": "Music" + } + EOF + echo "Created config/group_overrides.json" + fi + + echo "=== Creating initial channels.txt if it doesn't exist ===" + if [ ! -f channels.txt ]; then + cat > channels.txt << 'EOF' + Group = Example + Stream name = Test Channel + Logo = https://example.com/logo.png + EPG id = test.example + Stream URL = http://example.com/stream + EOF + echo "Created initial channels.txt with example channel" + fi + + echo "=== Setting permissions ===" + chmod 664 channels.txt 2>/dev/null || true + chmod 664 bulk_import.m3u 2>/dev/null || true - name: 🔍 Pre-processing diagnostics run: | echo "=== Repository Status ===" - pwd && whoami && ls -la - echo "=== File Status ===" - if [ -f channels.txt ]; then - echo "channels.txt: $(wc -l < channels.txt) lines" + echo "Directory: $(pwd)" + echo "User: $(whoami)" + echo "Files:" + ls -la + + echo "=== Checking required files ===" + echo "scripts/generate_playlist.py:" + if [ -f scripts/generate_playlist.py ]; then + echo " ✅ Found" else - echo "channels.txt: Not found" + echo " ❌ Missing - this will cause the workflow to fail" + echo " Please ensure you created the file with the exact path: scripts/generate_playlist.py" fi - if [ -f bulk_import.m3u ]; then - echo "bulk_import.m3u: $(wc -l < bulk_import.m3u) lines" + + echo "channels.txt:" + if [ -f channels.txt ]; then + echo " ✅ Found ($(wc -l < channels.txt) lines)" else - echo "bulk_import.m3u: Not found" + echo " ❌ Missing" + fi + + echo "bulk_import.m3u:" + if [ -f bulk_import.m3u ]; then + echo " ✅ Found ($(wc -l < bulk_import.m3u) lines)" + else + echo " â„šī¸ Not found (this is normal if no import needed)" fi - name: 🚀 Generate M3U Playlist run: | - echo "Starting playlist generation..." + echo "=== Starting playlist generation ===" + if [ ! -f scripts/generate_playlist.py ]; then + echo "❌ ERROR: scripts/generate_playlist.py not found!" + echo "Please create this file with the Python script content." + exit 1 + fi + + echo "Running playlist generation..." python scripts/generate_playlist.py + echo "✅ Playlist generation completed" - name: 📊 Post-processing diagnostics run: | echo "=== Processing Results ===" + echo "Files after processing:" ls -la + + echo "=== Checking outputs ===" if [ -f playlist.m3u ]; then - echo "playlist.m3u: Generated ($(wc -l < playlist.m3u) lines)" + LINES=$(wc -l < playlist.m3u) + CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0") + echo "✅ playlist.m3u: Generated successfully" + echo " 📊 $LINES total lines, $CHANNELS channels" + echo " 📄 First few lines:" + head -5 playlist.m3u | sed 's/^/ /' else - echo "playlist.m3u: Not generated" + echo "❌ playlist.m3u: Not generated" fi + if [ -f bulk_import.m3u ]; then - echo "bulk_import.m3u: Still exists" + echo "âš ī¸ bulk_import.m3u: Still exists (cleanup may have failed)" else - echo "bulk_import.m3u: Cleaned up" + echo "✅ bulk_import.m3u: Cleaned up or not present" fi - echo "=== Logs ===" - if [ -f logs/playlist_update.log ]; then - echo "Main log (last 10 lines):" - tail -10 logs/playlist_update.log - fi - if [ -f logs/error.log ]; then - echo "Errors found:" - cat logs/error.log + + echo "=== Checking logs ===" + if [ -d logs ]; then + echo "📁 Log files:" + ls -la logs/ || echo "No log files yet" + + if [ -f logs/playlist_update.log ]; then + echo "📋 Main log (last 10 lines):" + tail -10 logs/playlist_update.log | sed 's/^/ /' + fi + + if [ -f logs/error.log ]; then + echo "❌ Errors found:" + cat logs/error.log | sed 's/^/ /' + else + echo "✅ No errors logged" + fi else - echo "No errors logged" + echo "❌ No logs directory created" fi - name: 📊 Generate statistics run: | + echo "=== Playlist Statistics ===" if [ -f playlist.m3u ]; then CHANNEL_COUNT=$(grep -c "^#EXTINF" playlist.m3u || echo "0") GROUPS=$(grep -o 'group-title="[^"]*"' playlist.m3u | sort -u | wc -l || echo "0") - echo "Total channels: $CHANNEL_COUNT" - echo "Number of groups: $GROUPS" + TOTAL_LINES=$(wc -l < playlist.m3u) + + echo "đŸ“ē Total channels: $CHANNEL_COUNT" + echo "📁 Number of groups: $GROUPS" + echo "📄 Total lines in M3U: $TOTAL_LINES" + + if [ "$GROUPS" -gt 0 ]; then + echo "đŸˇī¸ Channel groups:" + grep -o 'group-title="[^"]*"' playlist.m3u | sed 's/group-title="//;s/"//' | sort | uniq -c | sort -nr | head -10 | sed 's/^/ /' + fi else - echo "No playlist generated" + echo "❌ No playlist generated - cannot show statistics" fi - name: đŸ“Ļ Prepare deployment run: | + echo "=== Preparing deployment files ===" mkdir -p docs - [ -f playlist.m3u ] && cp playlist.m3u docs/ - [ -f channels.txt ] && cp channels.txt docs/ - [ -d logs ] && cp -r logs docs/ + # Copy main files + [ -f playlist.m3u ] && cp playlist.m3u docs/ && echo "✅ Copied playlist.m3u" + [ -f channels.txt ] && cp channels.txt docs/ && echo "✅ Copied channels.txt" + [ -d logs ] && cp -r logs docs/ && echo "✅ Copied logs directory" + + # Create web interface cat > docs/index.html << 'EOF' - đŸ“ē IPTV Playlist + đŸ“ē IPTV Playlist Manager +
-

đŸ“ē IPTV Playlist Manager

+

đŸ“ēIPTV Playlist Manager

-
-

📊 Quick Access

- đŸ“ē Download Playlist - 📋 View Channels + -

📁 Available Files

+

📁Available Files

-

Last Updated:

- +
+

+ 🕒 Last Updated: + +

+
+ + EOF + echo "✅ Created docs/index.html" - name: 💾 Commit and push changes run: | + echo "=== Preparing to commit ===" + + # Clean up backup files rm -f *.backup* || true - [ -f channels.txt ] && git add channels.txt - [ -f playlist.m3u ] && git add playlist.m3u - [ -d logs ] && git add logs/ - [ -d config ] && git add config/ - [ -d docs ] && git add docs/ + # Stage files for commit + git add channels.txt && echo "✅ Staged channels.txt" || echo "âš ī¸ channels.txt not changed" + git add playlist.m3u && echo "✅ Staged playlist.m3u" || echo "âš ī¸ playlist.m3u not found" + git add logs/ && echo "✅ Staged logs/" || echo "âš ī¸ logs/ not found" + git add config/ && echo "✅ Staged config/" || echo "âš ī¸ config/ not changed" + git add docs/ && echo "✅ Staged docs/" || echo "âš ī¸ docs/ not found" + echo "=== Git status ===" git status + # Check if there are changes to commit if git diff --staged --quiet; then - echo "No changes to commit" - exit 0 + echo "â„šī¸ No changes to commit" else + # Generate commit statistics CHANNEL_COUNT="0" if [ -f playlist.m3u ]; then CHANNEL_COUNT=$(grep -c "^#EXTINF" playlist.m3u || echo "0") fi - COMMIT_MSG="đŸŽŦ Updated IPTV playlist: $CHANNEL_COUNT channels ($(date '+%Y-%m-%d %H:%M'))" + TIMESTAMP=$(date '+%Y-%m-%d %H:%M') + COMMIT_MSG="đŸŽŦ Updated IPTV playlist: $CHANNEL_COUNT channels ($TIMESTAMP)" + + echo "📝 Committing with message: $COMMIT_MSG" git commit -m "$COMMIT_MSG" git push - echo "Changes committed successfully!" + echo "✅ Changes committed and pushed successfully!" fi env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file