Skip to content

Commit

Permalink
M3U channel recognition improved
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsettrack4 committed Jul 16, 2023
1 parent bee70d4 commit 83cd55e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions resources/lib/web.py
Expand Up @@ -304,13 +304,13 @@ def provide_json(file_name):
def upload_m3u_file():
m3u = request.body.read()
try:
r = convert_m3u(str(convert_codec(m3u)))
tools.save_file(str(convert_codec(m3u)), f['storage'])
g.user_db.main["settings"]["file"] = True
if g.user_db.main["settings"].get("file_url"):
del g.user_db.main["settings"]["file_url"]
g.user_db.save_settings()
return json.dumps({"success": True, "result": r})
m3u = tools.read_file(f['storage'])
return json.dumps({"success": True, "result": convert_m3u(str(convert_codec(m3u)))})
except Exception as e:
print_error(traceback.format_exc())
return json.dumps({"success": False, "message": str(e)})
Expand All @@ -330,19 +330,23 @@ def get_m3u_file():
def upload_m3u_link():
try:
l = json.loads(request.body.read())["link"]
r = convert_m3u(str(convert_codec(load_m3u(l))))
tools.save_file(str(convert_codec(load_m3u(l))), f['storage'])
g.user_db.main["settings"]["file"] = True
g.user_db.main["settings"]["file_url"] = l
g.user_db.save_settings()
return json.dumps({"success": True, "result": r})
m3u = tools.read_file(f['storage'])
return json.dumps({"success": True, "result": convert_m3u(str(convert_codec(m3u)))})
except Exception as e:
print_error(traceback.format_exc())
return json.dumps({"success": False, "message": str(e)})

@route("/api/playlist-link", method="GET")
def load_via_m3u_link():
try:
return json.dumps({"success": True, "result": convert_m3u(str(load_m3u(g.user_db.main["settings"]["file_url"])))})
l = g.user_db.main["settings"]["file_url"]
tools.save_file(str(convert_codec(load_m3u(l))), f['storage'])
m3u = tools.read_file(f['storage'])
return json.dumps({"success": True, "result": convert_m3u(str(convert_codec(m3u)))})
except Exception as e:
print_error(traceback.format_exc())
return json.dumps({"success": False, "message": str(e)})
Expand Down Expand Up @@ -371,6 +375,10 @@ def convert_m3u(file):
tvg_id = item.split('tvg-id="')[1].split('"')[0]
if tvg_id != "":
ch_dict[tvg_id] = {"name": item.replace(", ", ",").split(",")[1]}
elif "#EXTINF" in item and "," in item:
tvg_id = item.replace(", ", ",").split(",")[1]
if tvg_id != "":
ch_dict[tvg_id] = {"name": tvg_id}
for i in ch_check.keys():
if ch_dict.get(ch_check[i].get("tvg-id", "")):
ch_dict[ch_check[i]["tvg-id"]]["mapped"] = True
Expand Down

0 comments on commit 83cd55e

Please sign in to comment.