Update scripts/generate_playlist.py
All checks were successful
Generate M3U Playlist with Auto-Organization / build-and-organize (push) Successful in 20s

This commit is contained in:
stoney420 2025-06-29 02:06:07 +02:00
parent a84e840798
commit 4dc0866217

View file

@ -1,12 +1,21 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
IPTV Playlist Generator - Guaranteed Working Version IPTV Playlist Generator - Enhanced Country Detection
Has enhanced country detection built-in, no complex imports needed FIXED: Properly handles working directory for Forgejo
""" """
import os import os
import sys
import shutil import shutil
from datetime import datetime from datetime import datetime
from pathlib import Path
# FIXED: Ensure we're in the right directory
script_dir = Path(__file__).parent
root_dir = script_dir.parent
# Change to root directory where channels.txt should be
os.chdir(root_dir)
def setup_directories(): def setup_directories():
"""Create required directories.""" """Create required directories."""
@ -101,18 +110,40 @@ def detect_country_enhanced(channel_name, epg_id="", logo_url=""):
return "🌍 International" return "🌍 International"
def debug_current_directory():
"""Debug what files are available in current directory."""
current_dir = os.getcwd()
print(f"🗂️ Current working directory: {current_dir}")
files = os.listdir('.')
print(f"📁 Files in directory: {len(files)} items")
# Check for our key files
key_files = ['channels.txt', 'playlist.m3u', 'bulk_import.m3u']
for file in key_files:
if os.path.exists(file):
size = os.path.getsize(file)
print(f"✅ Found {file} ({size} bytes)")
else:
print(f"❌ Missing {file}")
def load_channels(): def load_channels():
"""Load existing channels from channels.txt.""" """Load existing channels from channels.txt."""
channels = [] channels = []
# Debug first
debug_current_directory()
if not os.path.exists('channels.txt'): if not os.path.exists('channels.txt'):
print("No existing channels.txt found") print("No existing channels.txt found")
return channels return channels
try: try:
with open('channels.txt', 'r', encoding='utf-8') as f: with open('channels.txt', 'r', encoding='utf-8') as f:
content = f.read() content = f.read()
print(f"📄 channels.txt size: {len(content)} characters")
blocks = content.split('\n\n') blocks = content.split('\n\n')
for block in blocks: for block in blocks: