Update .forgejo/workflows/generate-m3u.yml

This commit is contained in:
stoney420 2025-06-29 04:57:48 +02:00
parent dc1ea7ec13
commit dca7d082bd

View file

@ -2,129 +2,109 @@ name: Generate M3U Playlist with Auto-Organization
on:
push:
branches:
- main
workflow_dispatch:
branches:
- main
workflow_dispatch:
jobs:
build-and-organize:
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
jobs:
build-and-organize:
runs-on: ubuntu-latest # Changed to ubuntu-latest for broader Forgejo compatibility
- name: Configure Git
run: |
git config --local user.email "actions@forgejo.plainrock127.xyz"
git config --local user.name "IPTV Playlist Bot"
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Python Environment
run: |
echo "Setting up Python environment..."
python3 --version
echo "Setting up directories..."
mkdir -p reports/daily reports/logs backups config
echo "Setup completed"
- name: Configure Git
run: |
git config --local user.email "actions@forgejo.plainrock127.xyz"
git config --local user.name "IPTV Playlist Bot"
- 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
echo "Creating empty bulk_import.m3u"
echo '#EXTM3U' > bulk_import.m3u
fi
- name: Setup Python Environment
run: |
echo "Setting up Python environment..."
python3 --version
echo "Setting up directories..."
mkdir -p reports/daily reports/logs backups config
echo "Setup completed"
- name: Verify Scripts Directory
run: |
echo "Checking scripts directory..."
if [ -d scripts ]; then
echo "Scripts directory exists"
ls -la scripts/
else
echo "Scripts directory not found!"
exit 1
fi
- 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
echo "Creating empty bulk_import.m3u"
echo '#EXTM3U' > bulk_import.m3u
fi
- name: Run Playlist Generation
run: |
echo "Running playlist generation..."
cd scripts
if [ -f generate_playlist.py ]; then
echo "Found generate_playlist.py, executing..."
python3 generate_playlist.py
echo "Playlist generation completed"
else
echo "Error: generate_playlist.py not found"
exit 1
fi
- name: Verify Scripts Directory
run: |
echo "Checking scripts directory..."
if [ -d scripts ]; then
echo "Scripts directory exists"
ls -la scripts/
else
echo "Scripts directory 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"
- name: Run Playlist Generation
run: |
echo "Running playlist generation..."
python3 scripts/generate_playlist.py
DATE=$(date +%Y%m%d_%H%M%S)
REPORT="reports/daily/report_$DATE.md"
- name: Clean Old Reports
run: |
echo "Cleaning old reports..."
# Ensure we are in the correct directory before listing files
if [ -d reports/daily ]; then
cd reports/daily || exit 1 # Exit if directory change fails
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
else
echo "No reports to clean"
fi
cd ../.. # Go back to root
else
echo "Reports daily directory not found, skipping cleanup."
fi
echo "# Playlist Report" > "$REPORT"
echo "Generated: $(date)" >> "$REPORT"
echo "Channels: $CHANNELS" >> "$REPORT"
- name: Reset Import File
run: |
echo "Resetting import file..."
echo '#EXTM3U' > bulk_import.m3u
echo "Import file reset"
echo "Report created: $REPORT"
else
echo "No playlist found"
fi
- 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: 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"
fi
else
echo "No reports to clean"
fi
cd ../..
- name: Summary
run: |
echo "=== WORKFLOW COMPLETE ==="
if [ -f playlist.m3u ]; then
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
echo "Final playlist.m3u has $CHANNELS channels."
else
echo "No playlist.m3u file found."
fi
- 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"