Update .forgejo/workflows/generate-m3u.yml
All checks were successful
Generate M3U Playlist with Auto-Organization / build-and-organize (push) Successful in 26s
All checks were successful
Generate M3U Playlist with Auto-Organization / build-and-organize (push) Successful in 26s
This commit is contained in:
parent
08acb6998d
commit
5a2d4dcc72
1 changed files with 42 additions and 134 deletions
|
@ -13,39 +13,16 @@ jobs:
|
|||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Configure Git
|
||||
run: |
|
||||
git config --local user.email "actions@forgejo.plainrock127.xyz"
|
||||
git config --local user.name "IPTV Playlist Bot"
|
||||
|
||||
- name: Run Comprehensive Cleanup
|
||||
- name: Basic Setup
|
||||
run: |
|
||||
echo "Running comprehensive cleanup..."
|
||||
if [ -f comprehensive_cleanup.py ]; then
|
||||
python comprehensive_cleanup.py
|
||||
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"
|
||||
echo "Setting up directories..."
|
||||
mkdir -p reports/daily
|
||||
echo "Setup completed"
|
||||
|
||||
- name: Check Import File
|
||||
run: |
|
||||
|
@ -53,9 +30,6 @@ jobs:
|
|||
if [ -f bulk_import.m3u ]; then
|
||||
LINES=$(wc -l < bulk_import.m3u)
|
||||
echo "Found bulk_import.m3u with $LINES lines"
|
||||
if [ "$LINES" -gt 2 ]; then
|
||||
echo "Contains channels to process"
|
||||
fi
|
||||
else
|
||||
echo "Creating empty bulk_import.m3u"
|
||||
echo '#EXTM3U' > bulk_import.m3u
|
||||
|
@ -65,144 +39,78 @@ jobs:
|
|||
run: |
|
||||
echo "Running playlist generation..."
|
||||
if [ -f scripts/generate_playlist.py ]; then
|
||||
python scripts/generate_playlist.py
|
||||
python3 scripts/generate_playlist.py
|
||||
echo "Playlist generation completed"
|
||||
else
|
||||
echo "Error: generate_playlist.py not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Smart Report Management
|
||||
- name: Create Simple Report
|
||||
run: |
|
||||
echo "Managing reports..."
|
||||
echo "Creating report..."
|
||||
if [ -f playlist.m3u ]; then
|
||||
CHANNELS=$(grep -c "^#EXTINF" playlist.m3u || echo "0")
|
||||
SIZE=$(du -h playlist.m3u | cut -f1)
|
||||
echo "Generated playlist: $CHANNELS channels ($SIZE)"
|
||||
echo "Found $CHANNELS channels in playlist"
|
||||
|
||||
# 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)
|
||||
REPORT="reports/daily/playlist_report_$DATE.md"
|
||||
COUNTRIES=$(grep 'group-title=' playlist.m3u | sed 's/.*group-title="//; s/".*//' | sort -u | wc -l || echo "0")
|
||||
REPORT="reports/daily/report_$DATE.md"
|
||||
|
||||
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 "# Playlist Report" > "$REPORT"
|
||||
echo "Generated: $(date)" >> "$REPORT"
|
||||
echo "Channels: $CHANNELS" >> "$REPORT"
|
||||
|
||||
echo "Created report: $REPORT"
|
||||
echo "Report created: $REPORT"
|
||||
else
|
||||
echo "No playlist generated"
|
||||
echo "No playlist found"
|
||||
fi
|
||||
|
||||
- name: Archive Old Reports
|
||||
- name: Clean Old Reports
|
||||
run: |
|
||||
echo "Managing archives..."
|
||||
# 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
|
||||
echo "Cleaning old reports..."
|
||||
cd reports/daily
|
||||
# Count markdown files
|
||||
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
|
||||
cd - > /dev/null
|
||||
else
|
||||
echo "No reports to clean"
|
||||
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: |
|
||||
echo "Cleaning import file..."
|
||||
if [ -f bulk_import.m3u ]; then
|
||||
LINES=$(wc -l < bulk_import.m3u)
|
||||
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"
|
||||
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
|
||||
if git diff --staged --quiet; then
|
||||
echo "No changes to commit"
|
||||
else
|
||||
CHANNELS="0"
|
||||
COUNTRIES="0"
|
||||
if [ -f playlist.m3u ]; then
|
||||
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
|
||||
|
||||
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 commit -m "📺 Updated playlist with $CHANNELS channels - $(date '+%Y-%m-%d %H:%M')"
|
||||
git push
|
||||
echo "Changes committed successfully"
|
||||
else
|
||||
echo "No changes to commit"
|
||||
echo "Changes committed"
|
||||
fi
|
||||
|
||||
- name: Success Summary
|
||||
- name: Summary
|
||||
run: |
|
||||
echo "Workflow completed successfully!"
|
||||
echo "=== WORKFLOW COMPLETE ==="
|
||||
if [ -f playlist.m3u ]; then
|
||||
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: $CHANNELS channels across $COUNTRIES countries"
|
||||
echo "✅ Playlist has $CHANNELS channels"
|
||||
fi
|
||||
|
||||
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 "Reports: $ACTIVE_REPORTS active, $ARCHIVED_REPORTS archived"
|
||||
echo "Repository is clean and organized with smart report management!"
|
||||
echo "✅ Reports updated"
|
||||
echo "✅ Repository cleaned"
|
Loading…
Add table
Add a link
Reference in a new issue