2025-06-28 03:41:57 +02:00
|
|
|
name: Generate M3U Playlist with Auto-Organization
|
2025-06-27 16:30:39 +02:00
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
workflow_dispatch:
|
|
|
|
|
|
|
|
jobs:
|
2025-06-28 03:07:40 +02:00
|
|
|
build-and-organize:
|
2025-06-27 16:30:39 +02:00
|
|
|
runs-on: ubuntu-22.04
|
|
|
|
steps:
|
2025-06-28 03:07:40 +02:00
|
|
|
- name: Checkout Repository
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
|
|
|
- name: Set up Python
|
|
|
|
uses: actions/setup-python@v5
|
2025-06-27 16:30:39 +02:00
|
|
|
with:
|
2025-06-27 17:36:55 +02:00
|
|
|
python-version: '3.11'
|
2025-06-27 16:30:39 +02:00
|
|
|
|
2025-06-27 23:41:32 +02:00
|
|
|
- name: Configure Git
|
2025-06-27 16:30:39 +02:00
|
|
|
run: |
|
|
|
|
git config --local user.email "actions@forgejo.plainrock127.xyz"
|
2025-06-27 17:36:55 +02:00
|
|
|
git config --local user.name "IPTV Playlist Bot"
|
2025-06-27 16:30:39 +02:00
|
|
|
|
2025-06-28 03:08:40 +02:00
|
|
|
- name: Run Comprehensive Cleanup
|
2025-06-28 02:05:53 +02:00
|
|
|
run: |
|
2025-06-28 03:08:40 +02:00
|
|
|
echo "Running comprehensive cleanup..."
|
2025-06-28 03:07:40 +02:00
|
|
|
if [ -f comprehensive_cleanup.py ]; then
|
|
|
|
python comprehensive_cleanup.py
|
2025-06-28 03:08:40 +02:00
|
|
|
echo "Comprehensive cleanup completed"
|
2025-06-28 03:07:40 +02:00
|
|
|
else
|
2025-06-28 03:08:40 +02:00
|
|
|
echo "Cleanup already completed"
|
2025-06-28 03:07:40 +02:00
|
|
|
fi
|
|
|
|
|
2025-06-28 03:08:40 +02:00
|
|
|
- name: Basic Repository Maintenance
|
2025-06-28 00:11:35 +02:00
|
|
|
run: |
|
2025-06-28 03:08:40 +02:00
|
|
|
echo "Running basic maintenance..."
|
2025-06-28 03:07:40 +02:00
|
|
|
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
|
2025-06-28 03:38:47 +02:00
|
|
|
mkdir -p reports/logs reports/daily reports/archive backups config templates
|
2025-06-28 03:07:40 +02:00
|
|
|
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
|
2025-06-28 03:08:40 +02:00
|
|
|
echo "Basic maintenance completed"
|
2025-06-28 03:07:40 +02:00
|
|
|
|
2025-06-28 03:08:40 +02:00
|
|
|
- name: Check Import File
|
2025-06-28 03:07:40 +02:00
|
|
|
run: |
|
2025-06-28 03:08:40 +02:00
|
|
|
echo "Checking import file..."
|
2025-06-28 03:07:40 +02:00
|
|
|
if [ -f bulk_import.m3u ]; then
|
|
|
|
LINES=$(wc -l < bulk_import.m3u)
|
2025-06-28 03:08:40 +02:00
|
|
|
echo "Found bulk_import.m3u with $LINES lines"
|
2025-06-28 03:07:40 +02:00
|
|
|
if [ "$LINES" -gt 2 ]; then
|
2025-06-28 03:08:40 +02:00
|
|
|
echo "Contains channels to process"
|
2025-06-28 03:07:40 +02:00
|
|
|
fi
|
|
|
|
else
|
2025-06-28 03:08:40 +02:00
|
|
|
echo "Creating empty bulk_import.m3u"
|
2025-06-28 03:07:40 +02:00
|
|
|
echo '#EXTM3U' > bulk_import.m3u
|
|
|
|
fi
|
|
|
|
|
|
|
|
- name: Run Playlist Generation
|
|
|
|
run: |
|
2025-06-28 03:08:40 +02:00
|
|
|
echo "Running playlist generation..."
|
|
|
|
if [ -f scripts/generate_playlist.py ]; then
|
|
|
|
python scripts/generate_playlist.py
|
|
|
|
echo "Playlist generation completed"
|
|
|
|
else
|
|
|
|
echo "Error: generate_playlist.py not found"
|
2025-06-28 03:07:40 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2025-06-28 03:38:47 +02:00
|
|
|
|
2025-06-28 03:41:57 +02:00
|
|
|
- name: Smart Report Management
|
2025-06-27 17:36:55 +02:00
|
|
|
run: |
|
2025-06-28 03:41:57 +02:00
|
|
|
echo "Managing reports..."
|
2025-06-27 17:36:55 +02:00
|
|
|
if [ -f playlist.m3u ]; then
|
2025-06-28 03:08:40 +02:00
|
|
|
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
|
|
|
|
SIZE=$(du -h playlist.m3u | cut -f1)
|
2025-06-28 03:41:57 +02:00
|
|
|
echo "Generated playlist: $CHANNELS channels ($SIZE)"
|
2025-06-28 03:38:47 +02:00
|
|
|
|
2025-06-28 03:41:57 +02:00
|
|
|
# Clean old reports (keep only 3 most recent)
|
2025-06-28 03:38:47 +02:00
|
|
|
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
|
2025-06-28 03:49:44 +02:00
|
|
|
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
|
2025-06-28 03:38:47 +02:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
cd - > /dev/null
|
|
|
|
fi
|
2025-06-28 03:07:40 +02:00
|
|
|
|
2025-06-28 03:41:57 +02:00
|
|
|
# Create new report
|
2025-06-28 03:08:40 +02:00
|
|
|
DATE=$(date +%Y%m%d_%H%M%S)
|
2025-06-28 03:38:47 +02:00
|
|
|
REPORT="reports/daily/playlist_report_$DATE.md"
|
2025-06-28 03:41:57 +02:00
|
|
|
COUNTRIES=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l || echo "0")
|
2025-06-28 03:38:47 +02:00
|
|
|
|
2025-06-28 03:41:57 +02:00
|
|
|
echo "# IPTV Playlist Report - $(date)" > "$REPORT"
|
|
|
|
echo "" >> "$REPORT"
|
|
|
|
echo "## Summary" >> "$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"
|
2025-06-28 03:07:40 +02:00
|
|
|
else
|
2025-06-28 03:41:57 +02:00
|
|
|
echo "No playlist generated"
|
2025-06-28 03:38:47 +02:00
|
|
|
fi
|
|
|
|
|
2025-06-28 03:41:57 +02:00
|
|
|
- name: Archive Old Reports
|
2025-06-28 03:38:47 +02:00
|
|
|
run: |
|
2025-06-28 03:41:57 +02:00
|
|
|
echo "Managing archives..."
|
2025-06-28 03:49:44 +02:00
|
|
|
# Simple archive management - keep only recent reports
|
|
|
|
if [ -d reports/daily ]; then
|
|
|
|
cd reports/daily
|
|
|
|
# Count all report files
|
|
|
|
TOTAL_REPORTS=$(ls -1 playlist_report_*.md report_*.md 2>/dev/null | wc -l)
|
|
|
|
echo "Found $TOTAL_REPORTS total reports"
|
|
|
|
|
|
|
|
# If more than 5 reports, archive the oldest ones
|
|
|
|
if [ "$TOTAL_REPORTS" -gt 5 ]; then
|
|
|
|
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
|
2025-06-28 03:38:47 +02:00
|
|
|
fi
|
2025-06-28 03:49:44 +02:00
|
|
|
cd - > /dev/null
|
|
|
|
fi
|
2025-06-28 03:38:47 +02:00
|
|
|
|
2025-06-28 03:41:57 +02:00
|
|
|
# Show archive status
|
2025-06-28 03:38:47 +02:00
|
|
|
ACTIVE_REPORTS=$(ls reports/daily/playlist_report_*.md report_*.md 2>/dev/null | wc -l)
|
2025-06-28 03:41:57 +02:00
|
|
|
ARCHIVED_REPORTS=$(find reports/archive -name "*.md" 2>/dev/null | wc -l)
|
|
|
|
echo "Report status: $ACTIVE_REPORTS active, $ARCHIVED_REPORTS archived"
|
2025-06-28 03:07:40 +02:00
|
|
|
|
2025-06-28 03:08:40 +02:00
|
|
|
- name: Clean Import File
|
2025-06-28 03:07:40 +02:00
|
|
|
run: |
|
2025-06-28 03:08:40 +02:00
|
|
|
echo "Cleaning import file..."
|
2025-06-28 03:07:40 +02:00
|
|
|
if [ -f bulk_import.m3u ]; then
|
2025-06-28 03:08:40 +02:00
|
|
|
LINES=$(wc -l < bulk_import.m3u)
|
|
|
|
if [ "$LINES" -gt 2 ]; then
|
2025-06-28 03:07:40 +02:00
|
|
|
echo '#EXTM3U' > bulk_import.m3u
|
2025-06-28 03:08:40 +02:00
|
|
|
echo "Cleaned import file for next use"
|
2025-06-28 03:07:40 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2025-06-28 03:08:40 +02:00
|
|
|
- name: Final Cleanup
|
2025-06-28 03:07:40 +02:00
|
|
|
run: |
|
2025-06-28 03:08:40 +02:00
|
|
|
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"
|
2025-06-28 03:07:40 +02:00
|
|
|
|
2025-06-28 03:08:40 +02:00
|
|
|
- name: Commit Changes
|
2025-06-28 02:05:53 +02:00
|
|
|
run: |
|
2025-06-28 03:08:40 +02:00
|
|
|
echo "Committing changes..."
|
|
|
|
git add .
|
2025-06-27 23:42:36 +02:00
|
|
|
if ! git diff --staged --quiet; then
|
2025-06-28 03:08:40 +02:00
|
|
|
CHANNELS="0"
|
2025-06-28 03:38:47 +02:00
|
|
|
COUNTRIES="0"
|
2025-06-28 03:07:40 +02:00
|
|
|
if [ -f playlist.m3u ]; then
|
2025-06-28 03:08:40 +02:00
|
|
|
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
|
2025-06-28 03:38:47 +02:00
|
|
|
COUNTRIES=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l || echo "0")
|
2025-06-28 03:07:40 +02:00
|
|
|
fi
|
2025-06-28 03:38:47 +02:00
|
|
|
|
|
|
|
ACTIVE_REPORTS=$(ls reports/daily/playlist_report_*.md report_*.md 2>/dev/null | wc -l)
|
|
|
|
|
2025-06-28 03:49:44 +02:00
|
|
|
git commit -m "📺 Updated playlist: $CHANNELS channels across $COUNTRIES countries - Reports: $ACTIVE_REPORTS active - $(date '+%Y-%m-%d %H:%M')"
|
2025-06-27 23:42:36 +02:00
|
|
|
git push
|
2025-06-28 03:41:57 +02:00
|
|
|
echo "Changes committed successfully"
|
2025-06-28 03:07:40 +02:00
|
|
|
else
|
2025-06-28 03:41:57 +02:00
|
|
|
echo "No changes to commit"
|
2025-06-28 03:07:40 +02:00
|
|
|
fi
|
|
|
|
|
2025-06-28 03:38:47 +02:00
|
|
|
- name: Success Summary
|
2025-06-28 03:07:40 +02:00
|
|
|
run: |
|
2025-06-28 03:41:57 +02:00
|
|
|
echo "Workflow completed successfully!"
|
2025-06-28 03:07:40 +02:00
|
|
|
if [ -f playlist.m3u ]; then
|
2025-06-28 03:08:40 +02:00
|
|
|
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
|
2025-06-28 03:38:47 +02:00
|
|
|
COUNTRIES=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l || echo "0")
|
2025-06-28 03:41:57 +02:00
|
|
|
echo "Playlist: $CHANNELS channels across $COUNTRIES countries"
|
2025-06-28 03:07:40 +02:00
|
|
|
fi
|
2025-06-28 03:38:47 +02:00
|
|
|
|
|
|
|
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)
|
2025-06-28 03:41:57 +02:00
|
|
|
echo "Reports: $ACTIVE_REPORTS active, $ARCHIVED_REPORTS archived"
|
|
|
|
echo "Repository is clean and organized with smart report management!"
|