shvchenko commited on
Commit
8b0711f
·
verified ·
1 Parent(s): 9b914af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -4,6 +4,9 @@ import random
4
  import string
5
  import gradio as gr
6
 
 
 
 
7
  # --- Helpers ---
8
  def normalize(s):
9
  return re.sub(r'[^a-z0-9]', '', s.lower())
@@ -22,17 +25,13 @@ def generate_filename(upper=False):
22
  return f"{chars}.m3u"
23
 
24
  # --- Main Processing ---
25
- def process_playlist(m3u_file_path, json_file_path):
26
- # Lazy load playlist
27
- try:
28
- with open(m3u_file_path, 'r', encoding='utf-8') as f:
29
- m3u_lines = f.read().splitlines()
30
- except Exception as e:
31
- return f"Error reading playlist: {e}", None, None
32
 
33
  # Load JSON reference
34
  try:
35
- with open(json_file_path, 'r', encoding='utf-8') as f:
36
  channels_ref = json.load(f)
37
  except Exception as e:
38
  return f"Error reading JSON: {e}", None, None
@@ -98,17 +97,14 @@ def process_playlist(m3u_file_path, json_file_path):
98
  # --- Gradio UI ---
99
  demo = gr.Interface(
100
  fn=process_playlist,
101
- inputs=[
102
- gr.Textbox(label="M3U8 Playlist File Path"),
103
- gr.Textbox(label="JSON File Path")
104
- ],
105
  outputs=[
106
  gr.Textbox(label="Update Log", lines=25),
107
  gr.File(label="Download 24/7 Channels M3U"),
108
  gr.File(label="Download Events M3U")
109
  ],
110
- title="Project 1 Playlist Updater - Local",
111
- description="Updates tvg-id for 24/7 and Events channels based on provided JSON with fuzzy matching."
112
  )
113
 
114
- demo.launch()
 
4
  import string
5
  import gradio as gr
6
 
7
+ # Local JSON file path
8
+ CHANNELS_JSON = "channels_fixed.json"
9
+
10
  # --- Helpers ---
11
  def normalize(s):
12
  return re.sub(r'[^a-z0-9]', '', s.lower())
 
25
  return f"{chars}.m3u"
26
 
27
  # --- Main Processing ---
28
+ def process_playlist(m3u_content):
29
+ # Use pasted M3U content
30
+ m3u_lines = m3u_content.splitlines()
 
 
 
 
31
 
32
  # Load JSON reference
33
  try:
34
+ with open(CHANNELS_JSON, 'r', encoding='utf-8') as f:
35
  channels_ref = json.load(f)
36
  except Exception as e:
37
  return f"Error reading JSON: {e}", None, None
 
97
  # --- Gradio UI ---
98
  demo = gr.Interface(
99
  fn=process_playlist,
100
+ inputs=[gr.Textbox(label="Paste M3U8 Playlist Here", lines=25)],
 
 
 
101
  outputs=[
102
  gr.Textbox(label="Update Log", lines=25),
103
  gr.File(label="Download 24/7 Channels M3U"),
104
  gr.File(label="Download Events M3U")
105
  ],
106
+ title="Project 1 Playlist Updater - Paste M3U8",
107
+ description="Paste the M3U8 playlist content and update tvg-ids using channels_fixed.json with fuzzy matching."
108
  )
109
 
110
+ demo.launch()