shvchenko commited on
Commit
a1c6b12
·
verified ·
1 Parent(s): 0b15a62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -5,14 +5,12 @@ import string
5
  import gradio as gr
6
  from difflib import get_close_matches
7
 
8
- # Local JSON file path
9
  CHANNELS_JSON = "channels_fixed.json"
10
 
11
- # --- Helpers ---
12
  def normalize(name):
13
  name = name.lower()
14
  name = re.sub(r'[^a-z0-9]', '', name)
15
- name = re.sub(r'0+', '', name) # remove leading zeros
16
  return name
17
 
18
  def fuzzy_match(name, json_keys, cutoff=0.8):
@@ -27,7 +25,6 @@ def generate_filename(upper=False):
27
  chars = ''.join(random.choices(string.ascii_uppercase if upper else string.ascii_lowercase, k=3))
28
  return f"{chars}.m3u"
29
 
30
- # --- Main Processing ---
31
  def process_playlist(m3u_content):
32
  m3u_lines = m3u_content.splitlines()
33
 
@@ -53,6 +50,8 @@ def process_playlist(m3u_content):
53
  if current_section == '24_7':
54
  m3u_24_7.append(line)
55
  elif current_section == 'events':
 
 
56
  m3u_events.append(line)
57
  else:
58
  m3u_24_7.append(line)
@@ -83,9 +82,14 @@ def process_playlist(m3u_content):
83
  break
84
 
85
  new_tvg_id = channels_ref[match_key]['tvg_id'] if match_key else 'Live.Event.us'
 
 
 
86
  else:
87
  match_key = fuzzy_match(ch_name, channels_ref.keys())
88
  new_tvg_id = channels_ref[match_key]['tvg_id'] if match_key else 'Info.Guide.Dummy.us'
 
 
89
 
90
  if 'tvg-id=' in line:
91
  line = re.sub(r'tvg-id=".*?"', f'tvg-id="{new_tvg_id}"', line)
@@ -125,4 +129,4 @@ demo = gr.Interface(
125
  description="Paste the M3U8 playlist content. Updates 24/7 and Events channels tvg-id using channels_fixed.json with smart Events matching."
126
  )
127
 
128
- demo.launch()
 
5
  import gradio as gr
6
  from difflib import get_close_matches
7
 
 
8
  CHANNELS_JSON = "channels_fixed.json"
9
 
 
10
  def normalize(name):
11
  name = name.lower()
12
  name = re.sub(r'[^a-z0-9]', '', name)
13
+ name = re.sub(r'0+', '', name)
14
  return name
15
 
16
  def fuzzy_match(name, json_keys, cutoff=0.8):
 
25
  chars = ''.join(random.choices(string.ascii_uppercase if upper else string.ascii_lowercase, k=3))
26
  return f"{chars}.m3u"
27
 
 
28
  def process_playlist(m3u_content):
29
  m3u_lines = m3u_content.splitlines()
30
 
 
50
  if current_section == '24_7':
51
  m3u_24_7.append(line)
52
  elif current_section == 'events':
53
+ # Remove 24/7 group-title if mistakenly present
54
+ line = re.sub(r'group-title="24/7 CHANNELS[^"]*"', '', line)
55
  m3u_events.append(line)
56
  else:
57
  m3u_24_7.append(line)
 
82
  break
83
 
84
  new_tvg_id = channels_ref[match_key]['tvg_id'] if match_key else 'Live.Event.us'
85
+ # Replace any tvg-id="test" with Live.Event.us
86
+ if 'tvg-id="test"' in line:
87
+ new_tvg_id = 'Live.Event.us'
88
  else:
89
  match_key = fuzzy_match(ch_name, channels_ref.keys())
90
  new_tvg_id = channels_ref[match_key]['tvg_id'] if match_key else 'Info.Guide.Dummy.us'
91
+ if 'tvg-id="test"' in line:
92
+ new_tvg_id = 'Info.Guide.Dummy.us'
93
 
94
  if 'tvg-id=' in line:
95
  line = re.sub(r'tvg-id=".*?"', f'tvg-id="{new_tvg_id}"', line)
 
129
  description="Paste the M3U8 playlist content. Updates 24/7 and Events channels tvg-id using channels_fixed.json with smart Events matching."
130
  )
131
 
132
+ demo.launch()