Update .forgejo/workflows/generate-m3u.yml
All checks were successful
Generate M3U Playlist with Auto-Organization / build-and-organize (push) Successful in 26s

This commit is contained in:
stoney420 2025-06-28 03:55:55 +02:00
parent 08acb6998d
commit 5a2d4dcc72

View file

@ -12,40 +12,17 @@ jobs:
steps: steps:
- name: Checkout Repository - name: Checkout Repository
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Configure Git - name: Configure Git
run: | run: |
git config --local user.email "actions@forgejo.plainrock127.xyz" git config --local user.email "actions@forgejo.plainrock127.xyz"
git config --local user.name "IPTV Playlist Bot" git config --local user.name "IPTV Playlist Bot"
- name: Run Comprehensive Cleanup - name: Basic Setup
run: | run: |
echo "Running comprehensive cleanup..." echo "Setting up directories..."
if [ -f comprehensive_cleanup.py ]; then mkdir -p reports/daily
python comprehensive_cleanup.py echo "Setup completed"
echo "Comprehensive cleanup completed"
else
echo "Cleanup already completed"
fi
- name: Basic Repository Maintenance
run: |
echo "Running basic maintenance..."
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -name "*.pyc" -delete 2>/dev/null || true
find . -name "*.tmp" -delete 2>/dev/null || true
find . -name "*~" -delete 2>/dev/null || true
mkdir -p reports/logs reports/daily reports/archive backups config templates
find . -maxdepth 1 -name "*.log" -exec mv {} reports/logs/ \; 2>/dev/null || true
if [ ! -f scripts/__init__.py ]; then
echo '# IPTV Scripts Package' > scripts/__init__.py
fi
echo "Basic maintenance completed"
- name: Check Import File - name: Check Import File
run: | run: |
@ -53,9 +30,6 @@ jobs:
if [ -f bulk_import.m3u ]; then if [ -f bulk_import.m3u ]; then
LINES=$(wc -l < bulk_import.m3u) LINES=$(wc -l < bulk_import.m3u)
echo "Found bulk_import.m3u with $LINES lines" echo "Found bulk_import.m3u with $LINES lines"
if [ "$LINES" -gt 2 ]; then
echo "Contains channels to process"
fi
else else
echo "Creating empty bulk_import.m3u" echo "Creating empty bulk_import.m3u"
echo '#EXTM3U' > bulk_import.m3u echo '#EXTM3U' > bulk_import.m3u
@ -65,144 +39,78 @@ jobs:
run: | run: |
echo "Running playlist generation..." echo "Running playlist generation..."
if [ -f scripts/generate_playlist.py ]; then if [ -f scripts/generate_playlist.py ]; then
python scripts/generate_playlist.py python3 scripts/generate_playlist.py
echo "Playlist generation completed" echo "Playlist generation completed"
else else
echo "Error: generate_playlist.py not found" echo "Error: generate_playlist.py not found"
exit 1 exit 1
fi fi
- name: Smart Report Management - name: Create Simple Report
run: | run: |
echo "Managing reports..." echo "Creating report..."
if [ -f playlist.m3u ]; then if [ -f playlist.m3u ]; then
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0") CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
SIZE=$(du -h playlist.m3u | cut -f1) echo "Found $CHANNELS channels in playlist"
echo "Generated playlist: $CHANNELS channels ($SIZE)"
# Clean old reports (keep only 3 most recent)
if [ -d reports/daily ]; then
cd reports/daily
REPORT_COUNT=$(ls -1 playlist_report_*.md report_*.md 2>/dev/null | wc -l)
if [ "$REPORT_COUNT" -gt 3 ]; then
ls -t playlist_report_*.md report_*.md 2>/dev/null | tail -n +4 | while read old_report; do
if [ -f "$old_report" ]; then
REPORT_DATE=$(echo "$old_report" | sed 's/.*_//; s/\.md//; s/\(....\)\(..\)\(..\).*/\1-\2/')
mkdir -p "../archive/$REPORT_DATE"
mv "$old_report" "../archive/$REPORT_DATE/"
echo "Archived: $old_report"
fi
done
fi
cd - > /dev/null
fi
# Create new report
DATE=$(date +%Y%m%d_%H%M%S) DATE=$(date +%Y%m%d_%H%M%S)
REPORT="reports/daily/playlist_report_$DATE.md" REPORT="reports/daily/report_$DATE.md"
COUNTRIES=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l || echo "0")
echo "# IPTV Playlist Report - $(date)" > "$REPORT" echo "# Playlist Report" > "$REPORT"
echo "" >> "$REPORT" echo "Generated: $(date)" >> "$REPORT"
echo "## Summary" >> "$REPORT" echo "Channels: $CHANNELS" >> "$REPORT"
echo "- **Channels**: $CHANNELS" >> "$REPORT"
echo "- **Countries**: $COUNTRIES" >> "$REPORT"
echo "- **Size**: $SIZE" >> "$REPORT"
echo "- **Generated**: $(date)" >> "$REPORT"
echo "" >> "$REPORT"
echo "## Top Countries" >> "$REPORT"
grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort | uniq -c | sort -nr | head -10 >> "$REPORT" 2>/dev/null || echo "No country data" >> "$REPORT"
echo "" >> "$REPORT"
echo "---" >> "$REPORT"
echo "*Auto-generated report with smart management*" >> "$REPORT"
echo "Created report: $REPORT" echo "Report created: $REPORT"
else else
echo "No playlist generated" echo "No playlist found"
fi fi
- name: Archive Old Reports - name: Clean Old Reports
run: | run: |
echo "Managing archives..." echo "Cleaning old reports..."
# Simple archive management - keep only recent reports cd reports/daily
if [ -d reports/daily ]; then # Count markdown files
cd reports/daily if ls *.md >/dev/null 2>&1; then
# Count all report files COUNT=$(ls *.md | wc -l)
TOTAL_REPORTS=$(ls -1 playlist_report_*.md report_*.md 2>/dev/null | wc -l) echo "Found $COUNT reports"
echo "Found $TOTAL_REPORTS total reports" if [ "$COUNT" -gt 3 ]; then
echo "Removing excess reports..."
# If more than 5 reports, archive the oldest ones ls -t *.md | tail -n +4 | xargs rm -f
if [ "$TOTAL_REPORTS" -gt 5 ]; then echo "Cleanup done"
echo "Archiving oldest reports..."
ls -t playlist_report_*.md report_*.md 2>/dev/null | tail -n +6 | while read old_report; do
if [ -f "$old_report" ]; then
BASENAME=$(basename "$old_report")
REPORT_DATE=$(echo "$BASENAME" | sed 's/.*_//; s/\.md//; s/\(....\)\(..\)\(..\).*/\1-\2/')
mkdir -p "../archive/$REPORT_DATE"
mv "$old_report" "../archive/$REPORT_DATE/"
echo "Archived old report: $BASENAME"
fi
done
fi fi
cd - > /dev/null else
echo "No reports to clean"
fi fi
cd ../..
# Show archive status
ACTIVE_REPORTS=$(ls reports/daily/playlist_report_*.md report_*.md 2>/dev/null | wc -l)
ARCHIVED_REPORTS=$(find reports/archive -name "*.md" 2>/dev/null | wc -l)
echo "Report status: $ACTIVE_REPORTS active, $ARCHIVED_REPORTS archived"
- name: Clean Import File - name: Reset Import File
run: | run: |
echo "Cleaning import file..." echo "Resetting import file..."
if [ -f bulk_import.m3u ]; then echo '#EXTM3U' > bulk_import.m3u
LINES=$(wc -l < bulk_import.m3u) echo "Import file reset"
if [ "$LINES" -gt 2 ]; then
echo '#EXTM3U' > bulk_import.m3u
echo "Cleaned import file for next use"
fi
fi
- name: Final Cleanup
run: |
echo "Final cleanup..."
find . -name "*.pyc" -delete 2>/dev/null || true
find . -name "*~" -delete 2>/dev/null || true
find . -name "*.swp" -delete 2>/dev/null || true
rm -f comprehensive_cleanup.py 2>/dev/null || true
echo "Final cleanup completed"
- name: Commit Changes - name: Commit Changes
run: | run: |
echo "Committing changes..." echo "Committing changes..."
git add . git add .
if ! git diff --staged --quiet; then if git diff --staged --quiet; then
echo "No changes to commit"
else
CHANNELS="0" CHANNELS="0"
COUNTRIES="0"
if [ -f playlist.m3u ]; then if [ -f playlist.m3u ]; then
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0") CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
COUNTRIES=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l || echo "0")
fi fi
git commit -m "📺 Updated playlist with $CHANNELS channels - $(date '+%Y-%m-%d %H:%M')"
ACTIVE_REPORTS=$(ls reports/daily/playlist_report_*.md report_*.md 2>/dev/null | wc -l)
git commit -m "📺 Updated playlist: $CHANNELS channels across $COUNTRIES countries - Reports: $ACTIVE_REPORTS active - $(date '+%Y-%m-%d %H:%M')"
git push git push
echo "Changes committed successfully" echo "Changes committed"
else
echo "No changes to commit"
fi fi
- name: Success Summary - name: Summary
run: | run: |
echo "Workflow completed successfully!" echo "=== WORKFLOW COMPLETE ==="
if [ -f playlist.m3u ]; then if [ -f playlist.m3u ]; then
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0") CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
COUNTRIES=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l || echo "0") echo "✅ Playlist has $CHANNELS channels"
echo "Playlist: $CHANNELS channels across $COUNTRIES countries"
fi fi
echo "✅ Reports updated"
ACTIVE_REPORTS=$(ls reports/daily/playlist_report_*.md report_*.md 2>/dev/null | wc -l) echo "✅ Repository cleaned"
ARCHIVED_REPORTS=$(find reports/archive -name "*.md" 2>/dev/null | wc -l)
echo "Reports: $ACTIVE_REPORTS active, $ARCHIVED_REPORTS archived"
echo "Repository is clean and organized with smart report management!"