shvchenko commited on
Commit
2c0451d
·
verified ·
1 Parent(s): 2465e4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -15
app.py CHANGED
@@ -14,17 +14,27 @@ def random_filename(uppercase=True):
14
  letters = string.ascii_uppercase if uppercase else string.ascii_lowercase
15
  return "".join(random.choice(letters) for _ in range(3)) + ".m3u"
16
 
 
 
 
 
 
 
 
 
 
 
17
  # Apply special event rules
18
  def apply_event_special_cases(extinf_line, channel_name):
19
  line = extinf_line
20
  if "MLB LEAGUE PASS" in channel_name:
21
- return re.sub(r'tvg-id="[^"]*"', 'tvg-id="MLB.Baseball.Dummy.us"', line)
22
  if "NHL GAMECENTER" in channel_name:
23
- return re.sub(r'tvg-id="[^"]*"', 'tvg-id="NHL.Hockey.Dummy.us"', line)
24
  if "ATP" in channel_name or "WTA" in channel_name:
25
- return re.sub(r'tvg-id="[^"]*"', 'tvg-id="Tennis.Channel.us"', line)
26
  if 'tvg-id="test"' in line:
27
- return line.replace('tvg-id="test"', 'tvg-id="Live.Event.us"')
28
  return line
29
 
30
  # Main processor
@@ -34,11 +44,13 @@ def process_m3u(m3u_text):
34
  out_events_blocks = []
35
  log = []
36
 
37
- # Hardcoded abbreviation exceptions
38
  exceptions = {
39
  "BTN": "Big.Ten.Network.HD.us2",
40
  "SNY": "SNY.SportsNet.New.York.HD.us2",
41
  "MASN": "MASN.-.Mid.Atlantic.Sports.Network.us2",
 
 
42
  }
43
 
44
  for i, line in enumerate(lines):
@@ -59,8 +71,7 @@ def process_m3u(m3u_text):
59
  # --- 24/7 CHANNELS ---
60
  if "24/7" in group_title:
61
  if tvg_id == "test" or not tvg_id:
62
- new_ext = re.sub(r'tvg-id="[^"]*"', 'tvg-id="Info.Guide.Dummy.us"', extinf) \
63
- if 'tvg-id="' in extinf else extinf + ' tvg-id="Info.Guide.Dummy.us"'
64
  log.append(f"ℹ️ 24/7 | {channel_name} → Info.Guide.Dummy.us")
65
  else:
66
  new_ext = extinf
@@ -74,12 +85,10 @@ def process_m3u(m3u_text):
74
  matched_exception = False
75
  for abbr, fixed_id in exceptions.items():
76
  if candidate.upper().startswith(abbr):
77
- tvg_id = fixed_id
78
- new_ext = re.sub(r'tvg-id="[^"]*"', f'tvg-id="{tvg_id}"', extinf) \
79
- if 'tvg-id="' in extinf else extinf + f' tvg-id="{tvg_id}"'
80
  new_ext = apply_event_special_cases(new_ext, candidate)
81
  out_events_blocks.append((new_ext, url))
82
- log.append(f"✅ EVENTS | {candidate} → {tvg_id} (hardcoded {abbr} exception)")
83
  matched_exception = True
84
  break
85
  if matched_exception:
@@ -98,12 +107,10 @@ def process_m3u(m3u_text):
98
  match = channel_map[guesses[0]].get("tvg_id")
99
 
100
  if match:
101
- new_ext = re.sub(r'tvg-id="[^"]*"', f'tvg-id="{match}"', extinf) \
102
- if 'tvg-id="' in extinf else extinf + f' tvg-id="{match}"'
103
  log.append(f"✅ EVENTS | {candidate} → {match}")
104
  else:
105
- new_ext = re.sub(r'tvg-id="[^"]*"', 'tvg-id="Live.Event.us"', extinf) \
106
- if 'tvg-id="' in extinf else extinf + ' tvg-id="Live.Event.us"'
107
  log.append(f"⚠️ EVENTS | {candidate} → Live.Event.us (fallback)")
108
 
109
  new_ext = apply_event_special_cases(new_ext, candidate)
 
14
  letters = string.ascii_uppercase if uppercase else string.ascii_lowercase
15
  return "".join(random.choice(letters) for _ in range(3)) + ".m3u"
16
 
17
+ # Insert tvg-id immediately after #EXTINF:-1
18
+ def insert_tvg_id(extinf_line, tvg_id):
19
+ # Remove existing tvg-id if present
20
+ line = re.sub(r'tvg-id="[^"]*"', '', extinf_line)
21
+ # Insert tvg-id immediately after #EXTINF:-1
22
+ line = line.replace('#EXTINF:-1', f'#EXTINF:-1 tvg-id="{tvg_id}"', 1)
23
+ # Clean multiple spaces
24
+ line = re.sub(r'\s+', ' ', line).strip()
25
+ return line
26
+
27
  # Apply special event rules
28
  def apply_event_special_cases(extinf_line, channel_name):
29
  line = extinf_line
30
  if "MLB LEAGUE PASS" in channel_name:
31
+ return insert_tvg_id(line, "MLB.Baseball.Dummy.us")
32
  if "NHL GAMECENTER" in channel_name:
33
+ return insert_tvg_id(line, "NHL.Hockey.Dummy.us")
34
  if "ATP" in channel_name or "WTA" in channel_name:
35
+ return insert_tvg_id(line, "Tennis.Channel.us")
36
  if 'tvg-id="test"' in line:
37
+ return insert_tvg_id(line, "Live.Event.us")
38
  return line
39
 
40
  # Main processor
 
44
  out_events_blocks = []
45
  log = []
46
 
47
+ # Hardcoded abbreviation exceptions for Events
48
  exceptions = {
49
  "BTN": "Big.Ten.Network.HD.us2",
50
  "SNY": "SNY.SportsNet.New.York.HD.us2",
51
  "MASN": "MASN.-.Mid.Atlantic.Sports.Network.us2",
52
+ "YES": "Yes.Network.us2",
53
+ "MSG": "MSG.National.us2",
54
  }
55
 
56
  for i, line in enumerate(lines):
 
71
  # --- 24/7 CHANNELS ---
72
  if "24/7" in group_title:
73
  if tvg_id == "test" or not tvg_id:
74
+ new_ext = insert_tvg_id(extinf, "Info.Guide.Dummy.us")
 
75
  log.append(f"ℹ️ 24/7 | {channel_name} → Info.Guide.Dummy.us")
76
  else:
77
  new_ext = extinf
 
85
  matched_exception = False
86
  for abbr, fixed_id in exceptions.items():
87
  if candidate.upper().startswith(abbr):
88
+ new_ext = insert_tvg_id(extinf, fixed_id)
 
 
89
  new_ext = apply_event_special_cases(new_ext, candidate)
90
  out_events_blocks.append((new_ext, url))
91
+ log.append(f"✅ EVENTS | {candidate} → {fixed_id} (hardcoded {abbr} exception)")
92
  matched_exception = True
93
  break
94
  if matched_exception:
 
107
  match = channel_map[guesses[0]].get("tvg_id")
108
 
109
  if match:
110
+ new_ext = insert_tvg_id(extinf, match)
 
111
  log.append(f"✅ EVENTS | {candidate} → {match}")
112
  else:
113
+ new_ext = insert_tvg_id(extinf, "Live.Event.us")
 
114
  log.append(f"⚠️ EVENTS | {candidate} → Live.Event.us (fallback)")
115
 
116
  new_ext = apply_event_special_cases(new_ext, candidate)