Update .forgejo/workflows/generate-m3u.yml
This commit is contained in:
parent
e87a55e2fe
commit
3e4419cfcb
1 changed files with 119 additions and 108 deletions
|
@ -1,130 +1,141 @@
|
||||||
name: Generate M3U Playlist with Auto-Organization
|
name: IPTV Channel Country Detection
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches: [ main, master ]
|
||||||
- main
|
paths:
|
||||||
|
- 'bulk_import.m3u'
|
||||||
|
- 'iptv_country_script.py'
|
||||||
|
pull_request:
|
||||||
|
branches: [ main, master ]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
run_processing:
|
||||||
|
description: 'Run IPTV processing'
|
||||||
|
required: false
|
||||||
|
default: 'true'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-organize:
|
process-iptv-channels:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repository
|
- name: 📦 Checkout Repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Configure Git
|
- name: 🐍 Set up Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.11'
|
||||||
|
|
||||||
|
- name: 📋 Install Dependencies
|
||||||
run: |
|
run: |
|
||||||
git config --local user.email "actions@forgejo.plainrock127.xyz"
|
python -m pip install --upgrade pip
|
||||||
git config --local user.name "IPTV Playlist Bot"
|
# Add any additional dependencies if needed
|
||||||
|
# pip install requests beautifulsoup4
|
||||||
- name: Setup Python Environment
|
|
||||||
|
- name: 🔍 Check for Input File
|
||||||
run: |
|
run: |
|
||||||
echo "Setting up Python environment..."
|
if [ -f "bulk_import.m3u" ]; then
|
||||||
python3 --version
|
echo "✅ Found bulk_import.m3u file"
|
||||||
echo "Setting up directories..."
|
echo "📊 File size: $(stat -f%z bulk_import.m3u 2>/dev/null || stat -c%s bulk_import.m3u) bytes"
|
||||||
mkdir -p reports/daily reports/logs backups config
|
echo "📝 First 5 lines:"
|
||||||
echo "Setup completed"
|
head -5 bulk_import.m3u
|
||||||
|
|
||||||
- name: Check Import File
|
|
||||||
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"
|
|
||||||
else
|
else
|
||||||
echo "Creating empty bulk_import.m3u"
|
echo "⚠️ No bulk_import.m3u file found"
|
||||||
echo '#EXTM3U' > bulk_import.m3u
|
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
|
fi
|
||||||
|
|
||||||
- name: Verify Scripts Directory
|
- name: 🎯 Run IPTV Channel Processing
|
||||||
run: |
|
run: |
|
||||||
echo "Checking scripts directory..."
|
echo "🚀 Starting IPTV channel processing..."
|
||||||
if [ -d scripts ]; then
|
|
||||||
echo "Scripts directory exists"
|
|
||||||
ls -la scripts/
|
|
||||||
else
|
|
||||||
echo "Scripts directory not found!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Run Playlist Generation
|
|
||||||
run: |
|
|
||||||
echo "Running playlist generation..."
|
|
||||||
cd scripts
|
cd scripts
|
||||||
if [ -f generate_playlist.py ]; then
|
python generate_playlist.py
|
||||||
echo "Found generate_playlist.py, executing..."
|
|
||||||
python3 generate_playlist.py
|
- name: 📊 Show Results
|
||||||
echo "Playlist generation completed"
|
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
|
else
|
||||||
echo "Error: generate_playlist.py not found"
|
echo "❌ Processing failed - no output file generated"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Create Simple Report
|
- 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: |
|
run: |
|
||||||
echo "Creating report..."
|
git config --local user.email "action@github.com"
|
||||||
if [ -f playlist.m3u ]; then
|
git config --local user.name "GitHub Action"
|
||||||
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
|
|
||||||
echo "Found $CHANNELS channels in playlist"
|
if [ -f "playlist.m3u" ]; then
|
||||||
|
git add playlist.m3u
|
||||||
|
|
||||||
DATE=$(date +%Y%m%d_%H%M%S)
|
if git diff --staged --quiet; then
|
||||||
REPORT="reports/daily/report_$DATE.md"
|
echo "📝 No changes to commit"
|
||||||
|
else
|
||||||
echo "# Playlist Report" > "$REPORT"
|
git commit -m "🎯 Auto-processed IPTV playlist - $(date '+%Y-%m-%d %H:%M:%S')"
|
||||||
echo "Generated: $(date)" >> "$REPORT"
|
echo "✅ Changes committed"
|
||||||
echo "Channels: $CHANNELS" >> "$REPORT"
|
|
||||||
|
# Only push if running on main/master branch and not a PR
|
||||||
echo "Report created: $REPORT"
|
if [[ "${GITHUB_REF}" == "refs/heads/main" || "${GITHUB_REF}" == "refs/heads/master" ]] && [[ "${GITHUB_EVENT_NAME}" != "pull_request" ]]; then
|
||||||
else
|
echo "🚀 Pushing changes..."
|
||||||
echo "No playlist found"
|
git push
|
||||||
fi
|
else
|
||||||
|
echo "📝 Skipping push (not on main branch or is PR)"
|
||||||
- name: Clean Old Reports
|
fi
|
||||||
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"
|
|
||||||
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
|
else
|
||||||
echo "No reports to clean"
|
echo "❌ Status: Failed"
|
||||||
fi
|
fi
|
||||||
cd ../..
|
|
||||||
|
echo ""
|
||||||
- name: Reset Import File
|
echo "🔗 Download processed playlist from artifacts above ⬆️"
|
||||||
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"
|
|
Loading…
Add table
Add a link
Reference in a new issue