Update scripts/generate_playlist.py
Some checks failed
Generate M3U Playlist / build (push) Has been cancelled

This commit is contained in:
stoney420 2025-06-27 23:57:37 +02:00
parent 41b9f2d8bd
commit e83930d6e9

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
IPTV Playlist Generator - Main Script (Scripts Folder Version) IPTV Playlist Generator - Debug Version
Modular design for better maintainability and easier development. Enhanced debugging to find why channels.txt is empty
""" """
import logging import logging
@ -23,7 +23,7 @@ from report_generator import ReportGenerator
def setup_logging(): def setup_logging():
"""Setup comprehensive logging.""" """Setup comprehensive logging."""
logging.basicConfig( logging.basicConfig(
level=logging.INFO, level=logging.DEBUG, # Changed to DEBUG for more info
format='[%(asctime)s] %(levelname)s: %(message)s', format='[%(asctime)s] %(levelname)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S', datefmt='%Y-%m-%d %H:%M:%S',
handlers=[ handlers=[
@ -32,14 +32,67 @@ def setup_logging():
] ]
) )
def debug_file_system():
"""Debug the file system to see what files exist."""
logging.info("=== FILE SYSTEM DEBUG ===")
# Check current directory
current_dir = os.getcwd()
logging.info(f"Current working directory: {current_dir}")
# List all files in current directory
try:
files = os.listdir('.')
logging.info(f"Files in current directory: {files}")
except Exception as e:
logging.error(f"Could not list current directory: {e}")
# Check for specific files
files_to_check = [
'bulk_import.m3u',
'channels.txt',
'playlist.m3u',
'../bulk_import.m3u',
'../channels.txt'
]
for file_path in files_to_check:
if os.path.exists(file_path):
try:
size = os.path.getsize(file_path)
logging.info(f"✅ Found {file_path} (size: {size} bytes)")
# If it's the import file, show first few lines
if 'bulk_import.m3u' in file_path and size > 0:
with open(file_path, 'r', encoding='utf-8') as f:
first_lines = [f.readline().strip() for _ in range(3)]
logging.info(f" First 3 lines: {first_lines}")
except Exception as e:
logging.error(f" Error reading {file_path}: {e}")
else:
logging.info(f"❌ Missing: {file_path}")
logging.info("=== END FILE SYSTEM DEBUG ===")
def generate_playlist(): def generate_playlist():
"""Main playlist generation function - coordinates all modules.""" """Main playlist generation function with enhanced debugging."""
try: try:
setup_logging() setup_logging()
logging.info("Starting modular playlist generation...") logging.info("Starting DEBUG playlist generation...")
# Debug file system first
debug_file_system()
# Initialize all modules # Initialize all modules
logging.info("Initializing modules...")
config = ConfigManager() config = ConfigManager()
# Debug config
logging.info(f"Config channels_file: {config.channels_file}")
logging.info(f"Config import_file: {config.import_file}")
logging.info(f"Config settings: {config.settings}")
file_manager = FileManager(config) file_manager = FileManager(config)
processor = ChannelProcessor(config) processor = ChannelProcessor(config)
builder = PlaylistBuilder(config) builder = PlaylistBuilder(config)
@ -61,26 +114,57 @@ def generate_playlist():
} }
# Step 1: Create backup # Step 1: Create backup
logging.info("=== STEP 1: Creating backup ===")
file_manager.create_backup('channels.txt') file_manager.create_backup('channels.txt')
# Step 2: Clean existing corrupted entries # Step 2: Clean existing corrupted entries
logging.info("=== STEP 2: Cleaning corrupted channels ===")
processor.clean_corrupted_channels() processor.clean_corrupted_channels()
# Step 3: Force update existing channels with new country detection # Step 3: Force update existing channels with new country detection
logging.info("=== STEP 3: Updating existing channels ===")
processor.update_existing_channels_with_country_detection() processor.update_existing_channels_with_country_detection()
# Step 4: Process imports # Step 4: Process imports (THE CRITICAL STEP)
logging.info("=== STEP 4: Processing imports ===")
# Extra debugging for import process
import_file_paths = ['bulk_import.m3u', '../bulk_import.m3u']
for path in import_file_paths:
if os.path.exists(path):
logging.info(f"Found import file at: {path}")
# Temporarily update config to use this path
config.import_file = path
break
imported_channels = processor.process_import() imported_channels = processor.process_import()
stats['imported_channels'] = len(imported_channels) stats['imported_channels'] = len(imported_channels)
logging.info(f"Import returned {len(imported_channels)} channels") logging.info(f"Import returned {len(imported_channels)} channels")
if len(imported_channels) == 0:
logging.warning("NO CHANNELS IMPORTED! This is the problem.")
logging.info("Checking import file details...")
# Manual check of import file
for path in ['bulk_import.m3u', '../bulk_import.m3u']:
if os.path.exists(path):
with open(path, 'r', encoding='utf-8') as f:
content = f.read()
logging.info(f"Import file {path} has {len(content)} characters")
logging.info(f"Import file first 200 chars: {content[:200]}")
break
# Step 5: Load all channels # Step 5: Load all channels
logging.info("=== STEP 5: Loading all channels ===")
all_channels = file_manager.load_all_channels() all_channels = file_manager.load_all_channels()
stats['total_channels'] = len(all_channels) stats['total_channels'] = len(all_channels)
logging.info(f"Loaded {len(all_channels)} total channels")
# Step 6: Remove duplicates # Step 6: Remove duplicates
logging.info("=== STEP 6: Removing duplicates ===")
unique_channels = processor.remove_duplicates_optimized(all_channels) unique_channels = processor.remove_duplicates_optimized(all_channels)
stats['duplicates_removed'] = len(all_channels) - len(unique_channels) stats['duplicates_removed'] = len(all_channels) - len(unique_channels)
logging.info(f"After deduplication: {len(unique_channels)} channels")
# Step 7: Sort channels # Step 7: Sort channels
if config.settings.get('sort_channels', True): if config.settings.get('sort_channels', True):
@ -92,16 +176,21 @@ def generate_playlist():
health_results = health_checker.batch_health_check(unique_channels) health_results = health_checker.batch_health_check(unique_channels)
# Step 9: Generate M3U playlist # Step 9: Generate M3U playlist
logging.info("=== STEP 9: Generating M3U ===")
valid_channels, country_stats = builder.generate_m3u(unique_channels) valid_channels, country_stats = builder.generate_m3u(unique_channels)
stats['valid_channels'] = valid_channels stats['valid_channels'] = valid_channels
stats['country_distribution'] = country_stats stats['country_distribution'] = country_stats
stats['countries_detected'] = len(country_stats) stats['countries_detected'] = len(country_stats)
# Step 10: Generate report # Step 10: Generate report
logging.info("=== STEP 10: Generating report ===")
report_gen.save_report(stats, health_results) report_gen.save_report(stats, health_results)
logging.info(f"Playlist generation complete: {valid_channels} channels across {len(country_stats)} countries") logging.info(f"Playlist generation complete: {valid_channels} channels across {len(country_stats)} countries")
logging.info(f"Top countries: {dict(list(sorted(country_stats.items(), key=lambda x: x[1], reverse=True))[:5])}")
# Final debug
logging.info("=== FINAL DEBUG ===")
debug_file_system()
return True return True