shvchenko commited on
Commit
d8577e2
·
verified ·
1 Parent(s): e042ee3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -19
app.py CHANGED
@@ -7,6 +7,18 @@ 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)
@@ -50,7 +62,6 @@ def process_playlist(m3u_content):
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:
@@ -66,30 +77,41 @@ def process_playlist(m3u_content):
66
  parts = line.split(',')
67
  ch_name = parts[-1].strip()
68
 
 
 
69
  if is_event:
70
  match_brackets = re.search(r'\[(.*?)\]', ch_name)
71
  ch_name_to_match = match_brackets.group(1) if match_brackets else ch_name
72
 
73
- ch_name_norm = normalize(ch_name_to_match)
74
- json_keys_norm = {k: normalize(k) for k in channels_ref.keys()}
75
-
76
- match_key = None
77
- matches = get_close_matches(ch_name_norm, list(json_keys_norm.values()), n=1, cutoff=0.7)
78
- if matches:
79
- for k, v in json_keys_norm.items():
80
- if v == matches[0]:
81
- match_key = k
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)
@@ -126,7 +148,7 @@ demo = gr.Interface(
126
  gr.File(label="Download Events M3U")
127
  ],
128
  title="Project 1 Playlist Updater - Smart Events",
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()
 
7
 
8
  CHANNELS_JSON = "channels_fixed.json"
9
 
10
+ # Abbreviations mapping for Events channels
11
+ ABBREVIATIONS = {
12
+ "BTN": "BIG TEN Network (BTN USA)"
13
+ # Add more abbreviations here if needed
14
+ }
15
+
16
+ # Special cases mapping
17
+ SPECIAL_CASES = {
18
+ "MLB LEAGUE PASS": "MLB.Baseball.Dummy.us",
19
+ "NHL GAMECENTER": "NHL.Hockey.Dummy.us"
20
+ }
21
+
22
  def normalize(name):
23
  name = name.lower()
24
  name = re.sub(r'[^a-z0-9]', '', name)
 
62
  if current_section == '24_7':
63
  m3u_24_7.append(line)
64
  elif current_section == 'events':
 
65
  line = re.sub(r'group-title="24/7 CHANNELS[^"]*"', '', line)
66
  m3u_events.append(line)
67
  else:
 
77
  parts = line.split(',')
78
  ch_name = parts[-1].strip()
79
 
80
+ new_tvg_id = None
81
+
82
  if is_event:
83
  match_brackets = re.search(r'\[(.*?)\]', ch_name)
84
  ch_name_to_match = match_brackets.group(1) if match_brackets else ch_name
85
 
86
+ if ch_name_to_match in SPECIAL_CASES:
87
+ new_tvg_id = SPECIAL_CASES[ch_name_to_match]
88
+ elif ch_name_to_match in ABBREVIATIONS:
89
+ match_key = ABBREVIATIONS[ch_name_to_match]
90
+ new_tvg_id = channels_ref.get(match_key, {}).get('tvg_id', 'Live.Event.us')
91
+ else:
92
+ if re.search(r'ATP|WTA', ch_name_to_match, re.IGNORECASE):
93
+ new_tvg_id = 'Tennis.Channel.us'
94
+ else:
95
+ ch_name_norm = normalize(ch_name_to_match)
96
+ json_keys_norm = {k: normalize(k) for k in channels_ref.keys()}
97
+ match_key = None
98
+ matches = get_close_matches(ch_name_norm, list(json_keys_norm.values()), n=1, cutoff=0.7)
99
+ if matches:
100
+ for k, v in json_keys_norm.items():
101
+ if v == matches[0]:
102
+ match_key = k
103
+ break
104
+ new_tvg_id = channels_ref[match_key]['tvg_id'] if match_key else 'Live.Event.us'
105
+
106
+ # Ensure tvg-id="test" is replaced with tvg-id="Live.Event.us"
107
+ line = re.sub(r'tvg-id="test"', 'tvg-id="Live.Event.us"', line)
108
  else:
109
  match_key = fuzzy_match(ch_name, channels_ref.keys())
110
  new_tvg_id = channels_ref[match_key]['tvg_id'] if match_key else 'Info.Guide.Dummy.us'
111
+ line = re.sub(r'tvg-id="test"', 'tvg-id="Info.Guide.Dummy.us"', line)
112
+
113
+ if is_event:
114
+ line = re.sub(r'group-title="[^"]*"', '', line)
115
 
116
  if 'tvg-id=' in line:
117
  line = re.sub(r'tvg-id=".*?"', f'tvg-id="{new_tvg_id}"', line)
 
148
  gr.File(label="Download Events M3U")
149
  ],
150
  title="Project 1 Playlist Updater - Smart Events",
151
+ description="Paste the M3U8 playlist content. Updates 24/7 and Events channels tvg-id using channels_fixed.json with smart Events matching. Handles special cases like MLB, NHL, ATP/WTA. Replaces tvg-id=\"test\" properly."
152
  )
153
 
154
  demo.launch()