Skip to content

Commit

Permalink
feat:update multicast tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Guovin committed Aug 29, 2024
1 parent 409ee07 commit 80eaad9
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 94 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ verify_ssl = true
[scripts]
build = "python main.py"
ui = "python tkinter_ui/tkinter_ui.py"
multicast_tmp = "python updates/multicast/update_tmp.py"

[dev-packages]

Expand Down
60 changes: 39 additions & 21 deletions updates/multicast/multicast_region_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -1319,8 +1319,7 @@
"rtsp://112.86.202.37:554/JSBC_iptv/C10000009@JSBC"
],
"电信": [
"rtp://239.49.8.75:8000",
"rtp://239.49.8.18:9610"
"rtp://239.49.8.75:8000"
]
},
"江西": {
Expand Down Expand Up @@ -4581,6 +4580,9 @@
"联通": [
"rtsp://112.86.202.37:554/JSBC_iptv/C10000040@JSBC",
"rtsp://157.0.143.37:554/JSBC_iptv/C10000040@JSBC"
],
"电信": [
"rtp://239.49.8.18:9610"
]
},
"吉林": {
Expand Down Expand Up @@ -13215,6 +13217,11 @@
"rtp://239.1.0.175:1025"
]
},
"江苏": {
"电信": [
"rtp://239.49.8.31:8000"
]
},
"吉林": {
"电信": [
"rtp://239.37.1.21:5540"
Expand Down Expand Up @@ -14426,6 +14433,11 @@
"rtp://239.76.252.254:9000"
]
},
"江苏": {
"电信": [
"rtp://239.49.0.125:8000"
]
},
"辽宁": {
"电信": [
"rtp://239.33.4.220:22200"
Expand Down Expand Up @@ -15333,6 +15345,11 @@
"rtp://239.1.1.39:1025"
]
},
"江苏": {
"电信": [
"rtp://239.49.0.111:8000"
]
},
"江西": {
"电信": [
"rtp://239.252.219.67:5140"
Expand Down Expand Up @@ -22349,11 +22366,26 @@
]
}
},
"凤凰資訊": {
"凤凰资讯": {
"福建": {
"移动": [
"http://183.251.61.207/PLTV/88888888/224/3221225901/index.m3u8"
]
},
"甘肃": {
"电信": [
"rtp://239.255.30.70:8231"
]
},
"湖南": {
"电信": [
"rtp://239.76.246.8:1234"
]
},
"陕西": {
"电信": [
"rtp://239.111.205.82:5140"
]
}
},
"炫动卡通": {
Expand Down Expand Up @@ -22466,6 +22498,9 @@
"联通": [
"rtsp://112.86.202.37:554/JSBC_iptv/C10000228@JSBC",
"rtsp://157.0.143.37:554/JSBC_iptv/C10000228@JSBC"
],
"电信": [
"rtp://239.49.8.119:8000"
]
},
"辽宁": {
Expand Down Expand Up @@ -24026,23 +24061,6 @@
]
}
},
"凤凰资讯": {
"甘肃": {
"电信": [
"rtp://239.255.30.70:8231"
]
},
"湖南": {
"电信": [
"rtp://239.76.246.8:1234"
]
},
"陕西": {
"电信": [
"rtp://239.111.205.82:5140"
]
}
},
"凤凰香港": {
"甘肃": {
"电信": [
Expand Down Expand Up @@ -34420,7 +34438,7 @@
]
}
},
"吉林乾安综合普清": {
"吉林干安综合普清": {
"吉林": {
"电信": [
"rtp://239.37.0.181:5540"
Expand Down
71 changes: 0 additions & 71 deletions updates/multicast/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
from requests_custom.utils import get_soup_requests, close_session
import urllib.parse as urlparse
from urllib.parse import parse_qs
from updates.subscribe import get_channels_by_subscribe_urls
from driver.utils import get_soup_driver
import json
from collections import defaultdict

Expand Down Expand Up @@ -66,75 +64,6 @@ def search_submit(driver, name):
driver.execute_script("arguments[0].click();", submit_button)


def get_region_urls_from_IPTV_Multicast_source():
"""
Get the region urls from IPTV_Multicast_source
"""
region_url = {}
origin_url = "https://github.com/xisohi/IPTV-Multicast-source/blob/main/README.md"
soup = get_soup_driver(origin_url)
tbody = soup.find("tbody")
trs = tbody.find_all("tr") if tbody else []
for tr in trs:
tds = tr.find_all("td")
name = tds[0].get_text().strip()
unicom = tds[1].find("a", href=True).get("href")
mobile = tds[2].find("a", href=True).get("href")
telecom = tds[3].find("a", href=True).get("href")
if name not in region_url:
region_url[name] = {}
region_url[name]["联通"] = unicom
region_url[name]["移动"] = mobile
region_url[name]["电信"] = telecom
with open(
resource_path("updates/multicast/multicast_map.json"), "w", encoding="utf-8"
) as f:
json.dump(region_url, f, ensure_ascii=False, indent=4)


def get_multicast_urls_info_from_region_list():
"""
Get the multicast urls info from region
"""
region_list = config.get("Settings", "multicast_region_list").split(",")
urls_info = []
with open(
resource_path("updates/multicast/multicast_map.json"), "r", encoding="utf-8"
) as f:
region_url = json.load(f)
if "all" in region_list or "全部" in region_list:
urls_info = [
{"region": region, "type": type, "url": url}
for region, value in region_url.items()
for type, url in value.items()
]
else:
for region in region_list:
if region in region_url:
region_data = [
{"region": region, "type": type, "url": url}
for type, url in region_url[region].items()
]
urls_info.append(region_data)
return urls_info


async def get_multicast_region_result():
"""
Get multicast region result
"""
multicast_region_urls_info = get_multicast_urls_info_from_region_list()
multicast_result = await get_channels_by_subscribe_urls(
multicast_region_urls_info, multicast=True
)
with open(
resource_path("updates/multicast/multicast_region_result.json"),
"w",
encoding="utf-8",
) as f:
json.dump(multicast_result, f, ensure_ascii=False, indent=4)


async def get_channels_by_multicast(names, callback):
"""
Get the channels by multicase
Expand Down
84 changes: 84 additions & 0 deletions updates/multicast/update_tmp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import sys
import os

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))

from updates.subscribe import get_channels_by_subscribe_urls
from driver.utils import get_soup_driver
from utils.config import config, resource_path
import json
import asyncio


def get_region_urls_from_IPTV_Multicast_source():
"""
Get the region urls from IPTV_Multicast_source
"""
region_url = {}
origin_url = "https://github.com/xisohi/IPTV-Multicast-source/blob/main/README.md"
soup = get_soup_driver(origin_url)
tbody = soup.find("tbody")
trs = tbody.find_all("tr") if tbody else []
for tr in trs:
tds = tr.find_all("td")
name = tds[0].get_text().strip()
unicom = tds[1].find("a", href=True).get("href")
mobile = tds[2].find("a", href=True).get("href")
telecom = tds[3].find("a", href=True).get("href")
if name not in region_url:
region_url[name] = {}
region_url[name]["联通"] = unicom
region_url[name]["移动"] = mobile
region_url[name]["电信"] = telecom
with open(
resource_path("updates/multicast/multicast_map.json"), "w", encoding="utf-8"
) as f:
json.dump(region_url, f, ensure_ascii=False, indent=4)


def get_multicast_urls_info_from_region_list():
"""
Get the multicast urls info from region
"""
region_list = config.get("Settings", "multicast_region_list").split(",")
urls_info = []
with open(
resource_path("updates/multicast/multicast_map.json"), "r", encoding="utf-8"
) as f:
region_url = json.load(f)
if "all" in region_list or "全部" in region_list:
urls_info = [
{"region": region, "type": type, "url": url}
for region, value in region_url.items()
for type, url in value.items()
]
else:
for region in region_list:
if region in region_url:
region_data = [
{"region": region, "type": type, "url": url}
for type, url in region_url[region].items()
]
urls_info.append(region_data)
return urls_info


async def get_multicast_region_result():
"""
Get multicast region result
"""
multicast_region_urls_info = get_multicast_urls_info_from_region_list()
multicast_result = await get_channels_by_subscribe_urls(
multicast_region_urls_info, multicast=True
)
with open(
resource_path("updates/multicast/multicast_region_result.json"),
"w",
encoding="utf-8",
) as f:
json.dump(multicast_result, f, ensure_ascii=False, indent=4)


if __name__ == "__main__":
get_region_urls_from_IPTV_Multicast_source()
asyncio.run(get_multicast_region_result())
5 changes: 3 additions & 2 deletions updates/subscribe/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ def process_subscribe_channels(subscribe_info):
value = url if multicast else (url, None, resolution)
name = format_channel_name(key)
if name in channels:
if multicast and value not in channels[name][region][type]:
channels[name][region][type].append(value)
if multicast:
if value not in channels[name][region][type]:
channels[name][region][type].append(value)
elif value not in channels[name]:
channels[name].append(value)
else:
Expand Down

0 comments on commit 80eaad9

Please sign in to comment.