From daf9b9e8d69a78984fe63329882e0bbeb7ed252b Mon Sep 17 00:00:00 2001 From: stoney420 Date: Sun, 29 Jun 2025 05:57:58 +0200 Subject: [PATCH] Update .forgejo/workflows/generate-m3u.yml --- .forgejo/workflows/generate-m3u.yml | 235 ++++++++++++++-------------- 1 file changed, 120 insertions(+), 115 deletions(-) diff --git a/.forgejo/workflows/generate-m3u.yml b/.forgejo/workflows/generate-m3u.yml index 0022c6e..be37cce 100644 --- a/.forgejo/workflows/generate-m3u.yml +++ b/.forgejo/workflows/generate-m3u.yml @@ -1,136 +1,141 @@ -name: Generate M3U Playlist with Auto-Organization +name: IPTV Channel Country Detection on: push: - branches: - - main + branches: [ main, master ] + paths: + - 'bulk_import.m3u' + - 'iptv_country_script.py' + pull_request: + branches: [ main, master ] workflow_dispatch: + inputs: + run_processing: + description: 'Run IPTV processing' + required: false + default: 'true' jobs: - build-and-organize: - runs-on: ubuntu-22.04 + process-iptv-channels: + runs-on: ubuntu-latest + steps: - - name: Checkout Repository + - name: πŸ“¦ Checkout Repository uses: actions/checkout@v4 - - - name: Configure Git - run: | - git config --local user.email "actions@forgejo.plainrock127.xyz" - git config --local user.name "IPTV Playlist Bot" - - - name: Set up Python 3.10 - uses: actions/setup-python@v5 + + - name: 🐍 Set up Python + uses: actions/setup-python@v4 with: - python-version: '3.10' - - - name: Check Import File + python-version: '3.11' + + - name: πŸ“‹ Install Dependencies run: | - echo "Checking import file..." - if [ -f bulk_import.m3u ]; - then - LINES=$(wc -l < bulk_import.m3u) - echo "Found bulk_import.m3u with $LINES lines" + python -m pip install --upgrade pip + # Add any additional dependencies if needed + # pip install requests beautifulsoup4 + + - name: πŸ” Check for Input File + run: | + if [ -f "bulk_import.m3u" ]; then + echo "βœ… Found bulk_import.m3u file" + echo "πŸ“Š File size: $(stat -f%z bulk_import.m3u 2>/dev/null || stat -c%s bulk_import.m3u) bytes" + echo "πŸ“ First 5 lines:" + head -5 bulk_import.m3u else - echo "Creating empty bulk_import.m3u" - echo '#EXTM3U' > bulk_import.m3u + echo "⚠️ No bulk_import.m3u file found" + echo "πŸ“ Creating sample file for testing..." + cat > bulk_import.m3u << 'EOF' + #EXTM3U + #EXTINF:-1 tvg-id="TSN1.ca" tvg-logo="https://raw.githubusercontent.com/tv-logo/tv-logos/main/countries/canada/tsn-1-ca.png" group-title="πŸ‡¬πŸ‡§ United Kingdom",TSN 1 + https://ott.udptv.net/stream/iptv/tsn1/master.m3u8 + #EXTINF:-1 tvg-id="CBC.ca" tvg-logo="https://raw.githubusercontent.com/tv-logo/tv-logos/main/countries/canada/cbc-ca.png" group-title="πŸ‡ΊπŸ‡Έ United States",CBC News + https://tvnow.best/api/stream/cbc/news.m3u8 + #EXTINF:-1 tvg-id="" tvg-logo="" group-title="DaddyLive USA",DaddyLive Channel + https://daddylive.com/stream123.m3u8 + #EXTINF:-1 tvg-id="bbc.one.uk" tvg-logo="https://raw.githubusercontent.com/tv-logo/tv-logos/main/countries/uk/bbc-one-uk.png" group-title="πŸ‡¬πŸ‡§ United Kingdom",BBC One + https://bbc.co.uk/live/bbcone.m3u8 + EOF + echo "βœ… Sample file created for testing" fi - - - name: Verify Scripts Directory + + - name: 🎯 Run IPTV Channel Processing run: | - echo "Checking scripts directory..." - if [ -d scripts ]; - then - echo "Scripts directory exists" - ls -la scripts/ + echo "πŸš€ Starting IPTV channel processing..." + cd scripts + python generate_playlist.py + + - name: πŸ“Š Show Results + run: | + if [ -f "playlist.m3u" ]; then + echo "βœ… Processing completed successfully!" + echo "πŸ“Š Output file size: $(stat -f%z playlist.m3u 2>/dev/null || stat -c%s playlist.m3u) bytes" + echo "" + echo "πŸ“ First 20 lines of processed playlist:" + head -20 playlist.m3u + echo "" + echo "🏁 Last 10 lines of processed playlist:" + tail -10 playlist.m3u + echo "" + echo "πŸ“ˆ Group distribution:" + grep -o 'group-title="[^"]*"' playlist.m3u | sort | uniq -c | sort -nr else - echo "Scripts directory not found!" + echo "❌ Processing failed - no output file generated" exit 1 fi - - - name: Run Playlist Generation + + - name: πŸ“¦ Upload Processed Playlist + uses: actions/upload-artifact@v4 + if: always() + with: + name: processed-playlist + path: | + playlist.m3u + *.backup_* + retention-days: 30 + + - name: πŸ’Ύ Commit Changes (if any) run: | - set -x # Enable debug output - echo "Running playlist generation..." - if [ -f scripts/generate_playlist.py ]; - then - echo "Found generate_playlist.py, executing..." - python3 scripts/generate_playlist.py - echo "Playlist generation completed" - else - echo "Error: generate_playlist.py not found" - exit 1 - fi - - - name: Create Simple Report - run: | - echo "Creating report..." - if [ -f playlist.m3u ]; - then - CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0") - echo "Found $CHANNELS channels in playlist" + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + + if [ -f "playlist.m3u" ]; then + git add playlist.m3u - DATE=$(date +%Y%m%d_%H%M%S) - REPORT="reports/daily/report_$DATE.md" - - echo "# Playlist Report" > "$REPORT" - echo "Generated: $(date)" >> "$REPORT" - echo "Channels: $CHANNELS" >> "$REPORT" - - echo "Report created: $REPORT" - else - echo "No playlist found" - fi - - - name: Clean Old Reports - run: | - echo "Cleaning old reports..." - cd reports/daily - if ls *.md >/dev/null 2>&1; - then - COUNT=$(ls *.md | wc -l) - echo "Found $COUNT reports" - if [ "$COUNT" -gt 3 ]; - then - echo "Removing excess reports..." - ls -t *.md | tail -n +4 | xargs rm -f - echo "Cleanup done" + if git diff --staged --quiet; then + echo "πŸ“ No changes to commit" + else + git commit -m "🎯 Auto-processed IPTV playlist - $(date '+%Y-%m-%d %H:%M:%S')" + echo "βœ… Changes committed" + + # Only push if running on main/master branch and not a PR + if [[ "${GITHUB_REF}" == "refs/heads/main" || "${GITHUB_REF}" == "refs/heads/master" ]] && [[ "${GITHUB_EVENT_NAME}" != "pull_request" ]]; then + echo "πŸš€ Pushing changes..." + git push + else + echo "πŸ“ Skipping push (not on main branch or is PR)" + fi fi + fi + + - name: πŸ“Š Summary Report + if: always() + run: | + echo "🎯 IPTV Processing Summary" + echo "=========================" + echo "πŸ“… Date: $(date)" + echo "🌿 Branch: ${GITHUB_REF##*/}" + echo "πŸ“ Event: ${GITHUB_EVENT_NAME}" + + if [ -f "bulk_import.m3u" ]; then + echo "πŸ“Š Input channels: $(grep -c '^#EXTINF:' bulk_import.m3u || echo '0')" + fi + + if [ -f "playlist.m3u" ]; then + echo "πŸ“Š Output channels: $(grep -c '^#EXTINF:' playlist.m3u || echo '0')" + echo "βœ… Status: Success" else - echo "No reports to clean" + echo "❌ Status: Failed" fi - cd ../.. - - - name: Reset Import File - run: | - echo "Resetting import file..." - echo '#EXTM3U' > bulk_import.m3u - echo "Import file reset" - - - name: Commit Changes - run: | - echo "Committing changes..." - git add . - if git diff --staged --quiet; - then - echo "No changes to commit" - else - CHANNELS="0" - if [ -f playlist.m3u ]; - then - CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0") - fi - git commit -m "πŸ“Ί Updated playlist with $CHANNELS channels - $(date '+%Y-%m-%d %H:%M')" - git push - echo "Changes committed" - fi - - - name: Summary - run: | - echo "=== WORKFLOW COMPLETE ===" - if [ -f playlist.m3u ]; - then - CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0") - echo "βœ… Playlist has $CHANNELS channels" - fi - echo "βœ… Reports updated" - echo "βœ… Repository cleaned" \ No newline at end of file + + echo "" + echo "πŸ”— Download processed playlist from artifacts above ⬆️" \ No newline at end of file