Update app.py
Browse files
app.py
CHANGED
|
@@ -16,11 +16,8 @@ def random_filename(uppercase=True):
|
|
| 16 |
|
| 17 |
# Insert tvg-id immediately after #EXTINF:-1
|
| 18 |
def insert_tvg_id(extinf_line, tvg_id):
|
| 19 |
-
|
| 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 |
|
|
@@ -44,13 +41,20 @@ def process_m3u(m3u_text):
|
|
| 44 |
out_events_blocks = []
|
| 45 |
log = []
|
| 46 |
|
| 47 |
-
# Hardcoded abbreviation
|
| 48 |
-
|
| 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):
|
|
@@ -81,17 +85,17 @@ def process_m3u(m3u_text):
|
|
| 81 |
elif group_title and "EVENTS" in group_title:
|
| 82 |
candidate = channel_name
|
| 83 |
|
| 84 |
-
# Check hardcoded
|
| 85 |
-
|
| 86 |
-
for
|
| 87 |
-
if candidate.upper().startswith(
|
| 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
|
| 92 |
-
|
| 93 |
break
|
| 94 |
-
if
|
| 95 |
continue
|
| 96 |
|
| 97 |
# Try matching against JSON
|
|
@@ -105,7 +109,6 @@ def process_m3u(m3u_text):
|
|
| 105 |
guesses = get_close_matches(candidate, keys, n=1, cutoff=0.6)
|
| 106 |
if guesses:
|
| 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}")
|
|
@@ -122,7 +125,7 @@ def process_m3u(m3u_text):
|
|
| 122 |
|
| 123 |
return out_247, out_events, "\n".join(log)
|
| 124 |
|
| 125 |
-
# Gradio UI with
|
| 126 |
def run_app(m3u_text):
|
| 127 |
out_247, out_events, log = process_m3u(m3u_text)
|
| 128 |
file_247 = random_filename(uppercase=True)
|
|
@@ -131,15 +134,18 @@ def run_app(m3u_text):
|
|
| 131 |
f.write(out_247)
|
| 132 |
with open(file_events, "w", encoding="utf-8") as f:
|
| 133 |
f.write(out_events)
|
| 134 |
-
|
| 135 |
return file_247, file_events, log
|
| 136 |
|
| 137 |
iface = gr.Interface(
|
| 138 |
fn=run_app,
|
| 139 |
-
inputs=gr.Textbox(lines=
|
| 140 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
title="Project 1 Playlist Processor",
|
| 142 |
-
description="Splits 24/7 and Events playlists, applies JSON tvg-id mappings, adds special
|
| 143 |
)
|
| 144 |
|
| 145 |
if __name__ == "__main__":
|
|
|
|
| 16 |
|
| 17 |
# Insert tvg-id immediately after #EXTINF:-1
|
| 18 |
def insert_tvg_id(extinf_line, tvg_id):
|
| 19 |
+
line = re.sub(r'tvg-id="[^"]*"', '', extinf_line) # remove existing
|
|
|
|
|
|
|
| 20 |
line = line.replace('#EXTINF:-1', f'#EXTINF:-1 tvg-id="{tvg_id}"', 1)
|
|
|
|
| 21 |
line = re.sub(r'\s+', ' ', line).strip()
|
| 22 |
return line
|
| 23 |
|
|
|
|
| 41 |
out_events_blocks = []
|
| 42 |
log = []
|
| 43 |
|
| 44 |
+
# Hardcoded abbreviation + forced fixes
|
| 45 |
+
hardcoded_fixes = {
|
| 46 |
"BTN": "Big.Ten.Network.HD.us2",
|
| 47 |
"SNY": "SNY.SportsNet.New.York.HD.us2",
|
| 48 |
"MASN": "MASN.-.Mid.Atlantic.Sports.Network.us2",
|
| 49 |
"YES": "Yes.Network.us2",
|
| 50 |
"MSG": "MSG.National.us2",
|
| 51 |
+
"REELZ USA": "ReelzChannel.HD.us2",
|
| 52 |
+
"ABCNY USA": "ABC.(WABC).New.York,.NY.us",
|
| 53 |
+
"OWN USA": "Oprah.Winfrey.Network.HD.us2",
|
| 54 |
+
"DISCOVERY USA": "Discovery.Channel.ca2",
|
| 55 |
+
"OUTDOOR CHANNEL": "Outdoor.Channel.HD.us2",
|
| 56 |
+
"OUTDOOR CHANNEL USA": "Outdoor.Channel.HD.us2",
|
| 57 |
+
"LOITV": "Soccer.Dummy.us",
|
| 58 |
}
|
| 59 |
|
| 60 |
for i, line in enumerate(lines):
|
|
|
|
| 85 |
elif group_title and "EVENTS" in group_title:
|
| 86 |
candidate = channel_name
|
| 87 |
|
| 88 |
+
# Check hardcoded fixes first
|
| 89 |
+
matched_fix = False
|
| 90 |
+
for key, fixed_id in hardcoded_fixes.items():
|
| 91 |
+
if candidate.upper().startswith(key.upper()):
|
| 92 |
new_ext = insert_tvg_id(extinf, fixed_id)
|
| 93 |
new_ext = apply_event_special_cases(new_ext, candidate)
|
| 94 |
out_events_blocks.append((new_ext, url))
|
| 95 |
+
log.append(f"β
EVENTS | {candidate} β {fixed_id} (hardcoded)")
|
| 96 |
+
matched_fix = True
|
| 97 |
break
|
| 98 |
+
if matched_fix:
|
| 99 |
continue
|
| 100 |
|
| 101 |
# Try matching against JSON
|
|
|
|
| 109 |
guesses = get_close_matches(candidate, keys, n=1, cutoff=0.6)
|
| 110 |
if guesses:
|
| 111 |
match = channel_map[guesses[0]].get("tvg_id")
|
|
|
|
| 112 |
if match:
|
| 113 |
new_ext = insert_tvg_id(extinf, match)
|
| 114 |
log.append(f"β
EVENTS | {candidate} β {match}")
|
|
|
|
| 125 |
|
| 126 |
return out_247, out_events, "\n".join(log)
|
| 127 |
|
| 128 |
+
# Gradio UI with better panel sizing
|
| 129 |
def run_app(m3u_text):
|
| 130 |
out_247, out_events, log = process_m3u(m3u_text)
|
| 131 |
file_247 = random_filename(uppercase=True)
|
|
|
|
| 134 |
f.write(out_247)
|
| 135 |
with open(file_events, "w", encoding="utf-8") as f:
|
| 136 |
f.write(out_events)
|
|
|
|
| 137 |
return file_247, file_events, log
|
| 138 |
|
| 139 |
iface = gr.Interface(
|
| 140 |
fn=run_app,
|
| 141 |
+
inputs=gr.Textbox(lines=5, placeholder="Paste your M3U playlist here..."), # smaller input
|
| 142 |
+
outputs=[
|
| 143 |
+
gr.File(label="24/7 Playlist"),
|
| 144 |
+
gr.File(label="Events Playlist"),
|
| 145 |
+
gr.Textbox(label="Log", lines=30), # larger log
|
| 146 |
+
],
|
| 147 |
title="Project 1 Playlist Processor",
|
| 148 |
+
description="Splits 24/7 and Events playlists, applies JSON tvg-id mappings, adds hardcoded + special rules, and outputs two clean M3Us."
|
| 149 |
)
|
| 150 |
|
| 151 |
if __name__ == "__main__":
|