podflow 20250212__py3-none-any.whl → 20250301__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ from Podflow.basic.write_log import write_log
8
8
  from Podflow.message.media_format import media_format
9
9
 
10
10
 
11
- def makeup_yt_format(video_id, makeup_yt_format_lock):
11
+ def makeup_format(video_id, makeup_format_lock):
12
12
  id_value = gVar.make_up_file_format[video_id]
13
13
  makeup_id_format = media_format(
14
14
  id_value["url"],
@@ -62,7 +62,7 @@ def makeup_yt_format(video_id, makeup_yt_format_lock):
62
62
  }
63
63
  del gVar.make_up_file_format[video_id]
64
64
  else:
65
- with makeup_yt_format_lock:
65
+ with makeup_format_lock:
66
66
  write_log(f"{id_value['name']}|{video_id}|{makeup_id_format}")
67
67
  gVar.make_up_file_format_fail[video_id] = id_value[
68
68
  "id"
@@ -78,19 +78,19 @@ def make_up_file_format_mod():
78
78
  f"{datetime.now().strftime('%H:%M:%S')}|补全缺失媒体 \033[34m下载准备中...\033[0m"
79
79
  )
80
80
  # 创建线程锁
81
- makeup_yt_format_lock = threading.Lock()
81
+ makeup_format_lock = threading.Lock()
82
82
  # 创建线程列表
83
- makeup_yt_format_threads = []
83
+ makeup_format_threads = []
84
84
  for video_id in gVar.make_up_file_format:
85
85
  thread = threading.Thread(
86
- target=makeup_yt_format,
86
+ target=makeup_format,
87
87
  args=(
88
88
  video_id,
89
- makeup_yt_format_lock,
89
+ makeup_format_lock,
90
90
  ),
91
91
  )
92
- makeup_yt_format_threads.append(thread)
92
+ makeup_format_threads.append(thread)
93
93
  thread.start()
94
94
  # 等待所有线程完成
95
- for thread in makeup_yt_format_threads:
95
+ for thread in makeup_format_threads:
96
96
  thread.join()
@@ -1,44 +1,69 @@
1
1
  # Podflow/message/create_main_rss.py
2
2
  # coding: utf-8
3
3
 
4
- import re
4
+ import time
5
5
  from Podflow import gVar
6
6
  from Podflow.youtube.build import youtube_xml_items
7
7
  from Podflow.bilibili.build import bilibili_xml_items
8
- from Podflow.message.display_qrcode_and_url import display_qrcode_and_url
8
+ from Podflow.message.get_media_name import get_media_name
9
+
10
+
11
+ def update_output_dir():
12
+ output_dirs = []
13
+ for format_value in gVar.video_id_update_format.values():
14
+ if (
15
+ isinstance(format_value, dict)
16
+ and format_value["main"] not in gVar.video_id_failed
17
+ ):
18
+ output_dirs.append(format_value["id"])
19
+ return output_dirs
9
20
 
10
21
 
11
22
  # 生成主rss模块
12
23
  def create_main_rss():
13
24
  channelid_youtube_ids = gVar.channelid_youtube_ids
14
- for output_dir, output_dir_youtube in channelid_youtube_ids.items():
15
- channelid_youtube_value = gVar.channelid_youtube[output_dir_youtube]
16
- items = youtube_xml_items(output_dir)
17
- display_qrcode_and_url(
18
- output_dir,
19
- channelid_youtube_value,
20
- output_dir_youtube,
21
- gVar.channelid_youtube_ids_update,
22
- )
23
- if channelid_youtube_value["InmainRSS"]:
24
- gVar.all_items.append(items)
25
- gVar.all_youtube_content_ytid[output_dir] = re.findall(
26
- r"(?:/UC.{22}/)(.{11}\.m4a|.{11}\.mp4)(?=\"|\?)",
27
- items,
28
- )
29
25
  channelid_bilibili_ids = gVar.channelid_bilibili_ids
30
- for output_dir, output_dir_bilibili in channelid_bilibili_ids.items():
31
- channelid_bilibili_value = gVar.channelid_bilibili[output_dir_bilibili]
32
- items = bilibili_xml_items(output_dir)
33
- display_qrcode_and_url(
34
- output_dir,
35
- channelid_bilibili_value,
36
- output_dir_bilibili,
37
- gVar.channelid_bilibili_ids_update,
38
- )
39
- if channelid_bilibili_value["InmainRSS"]:
40
- gVar.all_items.append(items)
41
- gVar.all_bilibili_content_bvid[output_dir] = re.findall(
42
- r"(?:/[0-9]+/)(BV.{10}\.m4a|BV.{10}\.mp4|BV.{10}_p[0-9]+\.m4a|BV.{10}_p[0-9]+\.mp4|BV.{10}_[0-9]{9}\.m4a|BV.{10}_[0-9]{9}\.mp4)(?=\"|\?)",
43
- items,
44
- )
26
+ gVar.all_items = {
27
+ key: {} for key in channelid_youtube_ids | channelid_bilibili_ids
28
+ }
29
+ all_channelid = list(gVar.all_items.keys())
30
+
31
+ while all_channelid:
32
+ for index, output_dir in enumerate(all_channelid):
33
+ if output_dir in update_output_dir():
34
+ time.sleep(1)
35
+ else:
36
+ if output_dir in channelid_youtube_ids:
37
+ output_dir_youtube = channelid_youtube_ids[output_dir]
38
+ channelid_youtube_value = gVar.channelid_youtube[output_dir_youtube]
39
+ items = youtube_xml_items(output_dir)
40
+ items["DisplayRSSaddress"] = channelid_youtube_value[
41
+ "DisplayRSSaddress"
42
+ ]
43
+ items["QRcode"] = channelid_youtube_value["QRcode"]
44
+ items["ID_Name"] = output_dir_youtube
45
+ items["InmainRSS"] = channelid_youtube_value["InmainRSS"]
46
+ items["type"] = "youtube"
47
+ gVar.all_youtube_content_ytid[output_dir] = get_media_name(
48
+ "youtube", items["items"]
49
+ )
50
+ gVar.all_items[output_dir] = items
51
+ elif output_dir in channelid_bilibili_ids:
52
+ output_dir_bilibili = channelid_bilibili_ids[output_dir]
53
+ channelid_bilibili_value = gVar.channelid_bilibili[
54
+ output_dir_bilibili
55
+ ]
56
+ items = bilibili_xml_items(output_dir)
57
+ items["DisplayRSSaddress"] = channelid_bilibili_value[
58
+ "DisplayRSSaddress"
59
+ ]
60
+ items["QRcode"] = channelid_bilibili_value["QRcode"]
61
+ items["ID_Name"] = output_dir_bilibili
62
+ items["InmainRSS"] = channelid_bilibili_value["InmainRSS"]
63
+ items["type"] = "bilibili"
64
+ gVar.all_bilibili_content_bvid[output_dir] = get_media_name(
65
+ "bilibili", items["items"]
66
+ )
67
+ gVar.all_items[output_dir] = items
68
+ del all_channelid[index]
69
+ break
@@ -9,9 +9,10 @@ from Podflow.basic.qr_code import qr_code
9
9
  # 显示网址及二维码模块
10
10
  def display_qrcode_and_url(
11
11
  output_dir,
12
- channelid_video,
13
- channelid_video_name,
14
- channelid_video_ids_update,
12
+ display_rss_address,
13
+ qrcode,
14
+ name,
15
+ ids_update,
15
16
  ):
16
17
  address = gVar.config["address"]
17
18
  if token := gVar.config["token"]:
@@ -19,17 +20,14 @@ def display_qrcode_and_url(
19
20
  else:
20
21
  xml_url = f"{address}/channel_rss/{output_dir}.xml"
21
22
 
22
- if channelid_video["DisplayRSSaddress"] or output_dir in channelid_video_ids_update:
23
- update_text = "已更新" if output_dir in channelid_video_ids_update else "无更新"
23
+ if display_rss_address or output_dir in ids_update:
24
+ update_text = "已更新" if output_dir in ids_update else "无更新"
24
25
  print(
25
- f"{datetime.now().strftime('%H:%M:%S')}|{channelid_video_name} 播客{update_text}|地址:\n\033[34m{xml_url}\033[0m"
26
+ f"{datetime.now().strftime('%H:%M:%S')}|{name} 播客{update_text}|地址:\n\033[34m{xml_url}\033[0m"
26
27
  )
27
28
  if (
28
- (
29
- channelid_video["DisplayRSSaddress"]
30
- or output_dir in channelid_video_ids_update
31
- )
32
- and channelid_video["QRcode"]
29
+ (display_rss_address or output_dir in ids_update)
30
+ and qrcode
33
31
  and output_dir not in gVar.displayed_QRcode
34
32
  ):
35
33
  qr_code(xml_url)
@@ -139,6 +139,11 @@ error_reason = [
139
139
  "\033[31m响应超时\033[0m",
140
140
  "regexp",
141
141
  ],
142
+ [
143
+ r"Requested format is not available. Use --list-formats for a list of available formats",
144
+ "\033[31m格式不可用\033[0m",
145
+ "text",
146
+ ],
142
147
  ]
143
148
 
144
149
 
@@ -0,0 +1,26 @@
1
+ # Podflow/message/get_media_name.py
2
+ # coding: utf-8
3
+
4
+ import re
5
+
6
+
7
+ # 定义一个函数,用于获取媒体名称
8
+ def get_media_name(id_type, items):
9
+ # 如果id_type为youtube
10
+ if id_type == "youtube":
11
+ # 使用正则表达式匹配items中的youtube链接,返回匹配结果
12
+ return re.findall(
13
+ r"(?:/UC.{22}/)(.{11}\.m4a|.{11}\.mp4)(?=\"|\?)",
14
+ items,
15
+ )
16
+ # 如果id_type为bilibili
17
+ elif id_type == "bilibili":
18
+ # 使用正则表达式匹配items中的bilibili链接,返回匹配结果
19
+ return re.findall(
20
+ r"(?:/[0-9]+/)(BV.{10}\.m4a|BV.{10}\.mp4|BV.{10}_p[0-9]+\.m4a|BV.{10}_p[0-9]+\.mp4|BV.{10}_[0-9]{9}\.m4a|BV.{10}_[0-9]{9}\.mp4)(?=\"|\?)",
21
+ items,
22
+ )
23
+ # 如果id_type不是youtube或bilibili
24
+ else:
25
+ # 返回空列表
26
+ return []
@@ -0,0 +1,85 @@
1
+ # Podflow/message/save_rss.py
2
+ # coding: utf-8
3
+
4
+ from Podflow import gVar
5
+ from Podflow.basic.qr_code import qr_code
6
+ from Podflow.message.xml_rss import xml_rss
7
+ from Podflow.basic.file_save import file_save
8
+ from Podflow.basic.write_log import write_log
9
+ from Podflow.message.backup_zip_save import backup_zip_save
10
+ from Podflow.message.display_qrcode_and_url import display_qrcode_and_url
11
+
12
+
13
+ # 保存rss文件模块
14
+ def save_rss():
15
+ # 定义一个空列表,用于存储所有rss的items
16
+ main_items = []
17
+ # 遍历gVar.all_items字典,获取每个rss的输出目录和items_dict
18
+ for output_dir, items_dict in gVar.all_items.items():
19
+ # 获取items_dict中的各个字段
20
+ title = items_dict["title"]
21
+ link = items_dict["link"]
22
+ description = items_dict["description"]
23
+ category = items_dict["category"]
24
+ icon = items_dict["icon"]
25
+ items = items_dict["items"]
26
+ # 调用file_save函数,将rss保存到指定目录
27
+ file_save(
28
+ xml_rss(title, link, description, category, icon, items),
29
+ f"{output_dir}.xml",
30
+ "channel_rss",
31
+ )
32
+ # 获取items_dict中的其他字段
33
+ display_rss_address = items_dict["DisplayRSSaddress"]
34
+ qrcode = items_dict["QRcode"]
35
+ id_name = items_dict["ID_Name"]
36
+ id_type = items_dict["type"]
37
+ # 根据id_type获取对应的ids_update
38
+ if id_type == "youtube":
39
+ ids_update = gVar.channelid_youtube_ids_update
40
+ elif id_type == "bilibili":
41
+ ids_update = gVar.channelid_bilibili_ids_update
42
+ else:
43
+ ids_update = {}
44
+ # 调用display_qrcode_and_url函数,显示rss地址和二维码
45
+ display_qrcode_and_url(
46
+ output_dir,
47
+ display_rss_address,
48
+ qrcode,
49
+ id_name,
50
+ ids_update,
51
+ )
52
+ # 如果items_dict中的InmainRSS字段为True,则将items添加到main_items列表中
53
+ if items_dict["InmainRSS"]:
54
+ main_items.append(items)
55
+
56
+ # 生成主rss
57
+ overall_rss = xml_rss(
58
+ gVar.config["title"],
59
+ gVar.config["link"],
60
+ gVar.config["description"],
61
+ gVar.config["category"],
62
+ gVar.config["icon"],
63
+ "\n".join(main_items),
64
+ )
65
+
66
+ # 保存主rss
67
+ file_save(overall_rss, f"{gVar.config['filename']}.xml")
68
+
69
+ # 获取gVar.config中的地址和文件名
70
+ address = gVar.config["address"]
71
+ filename = gVar.config["filename"]
72
+ # 如果gVar.config中的token字段存在,则将token添加到overall_url中
73
+ if token := gVar.config["token"]:
74
+ overall_url = f"{address}/{filename}.xml?token={token}"
75
+ else:
76
+ overall_url = f"{address}/{filename}.xml"
77
+ # 调用write_log函数,记录总播客已更新
78
+ write_log("总播客已更新", f"地址:\n\033[34m{overall_url}\033[0m")
79
+ # 如果gVar.displayed_QRcode中不包含"main",则调用qr_code函数,显示总播客的二维码,并将"main"添加到gVar.displayed_QRcode中
80
+ if "main" not in gVar.displayed_QRcode:
81
+ qr_code(overall_url)
82
+ gVar.displayed_QRcode.append("main")
83
+
84
+ # 备份主rss
85
+ backup_zip_save(overall_rss)
@@ -9,6 +9,7 @@ from Podflow.basic.write_log import write_log
9
9
  # 删除多余媒体文件模块
10
10
  def remove_file():
11
11
  channelid_youtube_ids = gVar.channelid_youtube_ids
12
+
12
13
  for output_dir, name in channelid_youtube_ids.items():
13
14
  for file_name in os.listdir(f"channel_audiovisual/{output_dir}"):
14
15
  if file_name not in gVar.all_youtube_content_ytid[output_dir]:
@@ -0,0 +1,36 @@
1
+ # Podflow/upload/add_upload.py
2
+ # coding: utf-8
3
+
4
+ import time
5
+ from Podflow import gVar
6
+
7
+
8
+ # 添加新媒体至上传列表模块
9
+ def add_upload():
10
+ # 获取video_id_update_format和video_id_failed的值
11
+ video_id_update_format = gVar.video_id_update_format
12
+ video_id_failed = gVar.video_id_failed
13
+ # 遍历video_id_update_format的键值对
14
+ for video_id, video_id_value in video_id_update_format.items():
15
+ # 判断video_id_value是否为字典,并且main不在video_id_failed中
16
+ if (
17
+ isinstance(video_id_value, dict)
18
+ and video_id_value["main"] not in video_id_failed
19
+ ):
20
+ # 构造media_id
21
+ media_id = f"{video_id}.{video_id_value['media']}"
22
+ # 判断gVar.upload_original中是否存在media_id
23
+ if not any(
24
+ item.get("media_id") == media_id for item in gVar.upload_original
25
+ ):
26
+ # 如果不存在,则将media_id、channel_id、media_time、upload、remove、hash添加到gVar.upload_original中
27
+ gVar.upload_original.append(
28
+ {
29
+ "media_id": media_id,
30
+ "channel_id": video_id_value["id"],
31
+ "media_time": int(time.time()),
32
+ "upload": False,
33
+ "remove": False,
34
+ "hash": None,
35
+ }
36
+ )
@@ -3,15 +3,17 @@
3
3
 
4
4
  import re
5
5
  import json
6
+ from datetime import datetime
6
7
  from collections import Counter
7
8
  from email.utils import parsedate_tz, mktime_tz
8
9
  from Podflow import gVar
9
10
  from Podflow.basic.file_save import file_save
10
11
  from Podflow.basic.write_log import write_log
12
+ from Podflow.message.get_media_name import get_media_name
11
13
 
12
14
 
13
15
  # 获取原始上传数据模块
14
- def get_upload_original():
16
+ def get_upload():
15
17
  xmls_original = gVar.xmls_original
16
18
  try:
17
19
  # 尝试打开并读取 JSON 文件
@@ -28,49 +30,38 @@ def get_upload_original():
28
30
  if upload_original:
29
31
  # 提取每个条目的 channel_id
30
32
  channel_ids = [item.get("channel_id") for item in upload_original]
31
-
32
33
  # 统计每个 channel_id 的出现次数
33
34
  channelid_counts = Counter(channel_ids)
34
-
35
35
  # 将出现次数转换为字典
36
36
  age_counts = dict(channelid_counts)
37
-
38
37
  # 统计 xmls_original 中每个键对应的 <guid> 标签内的元素数量
39
38
  xmls_original_counts = {
40
39
  key: len(re.findall(r"(?<=<guid>).+(?=</guid>)", value))
41
40
  for key, value in xmls_original.items()
42
41
  }
43
-
44
- # 如果两个计数字典不相等,清空 upload_original
42
+ # 如果两个计数字典不相等,提示错误
45
43
  if age_counts != xmls_original_counts:
46
- upload_original = []
47
-
48
- # 如果 upload_original 仍然为空
49
- if not upload_original:
44
+ print(
45
+ f"{datetime.now().strftime('%H:%M:%S')}|无法获取完整原始上传信息"
46
+ )
47
+ # 如果 upload_original 为空
48
+ else:
50
49
  # 遍历 xmls_original 的每个键值对
51
50
  for xmls_original_key, xmls_original_value in xmls_original.items():
52
51
  # 如果当前键在 channelid_youtube_ids 中
53
52
  if xmls_original_key in gVar.channelid_youtube_ids:
54
53
  # 使用正则表达式解析包含特定格式媒体ID的字符串
55
- media = re.findall(
56
- r"(?:/UC.{22}/)(.{11}\.m4a|.{11}\.mp4)(?=\"|\?)",
57
- xmls_original_value,
58
- )
54
+ media = get_media_name("youtube", xmls_original_value)
59
55
  # 如果当前键在 channelid_bilibili_ids 中
60
56
  elif xmls_original_key in gVar.channelid_bilibili_ids:
61
- media = re.findall(
62
- r"(?:/[0-9]+/)(BV.{10}\.m4a|BV.{10}\.mp4|BV.{10}_p[0-9]+\.m4a|BV.{10}_p[0-9]+\.mp4|BV.{10}_[0-9]{9}\.m4a|BV.{10}_[0-9]{9}\.mp4)(?=\"|\?)",
63
- xmls_original_value,
64
- )
57
+ media = get_media_name("bilibili", xmls_original_value)
65
58
  else:
66
59
  media = []
67
-
68
60
  # 查找每个上传条目的发布时间
69
61
  upload_time = re.findall(
70
62
  r"(?<=<pubDate>).+(?=</pubDate>)",
71
63
  xmls_original_value,
72
64
  )
73
-
74
65
  # 将日期字符串列表转换为 Unix 时间戳列表
75
66
  timestamps = [
76
67
  mktime_tz(
@@ -79,13 +70,11 @@ def get_upload_original():
79
70
  for date_string in upload_time
80
71
  if parsedate_tz(date_string) # 确保解析成功
81
72
  ]
82
-
83
73
  # 如果媒体和时间戳的数量不匹配,记录错误并清空 upload_original
84
74
  if len(media) != len(timestamps):
85
75
  write_log("获取原始上传内容失败") # 错误日志
86
76
  upload_original.clear() # 清空 upload_original
87
77
  break # 退出循环
88
-
89
78
  # 如果数量匹配,则整合 media_id、channel_id 和上传时间到 upload_original 列表
90
79
  upload_original += [
91
80
  {
@@ -93,13 +82,23 @@ def get_upload_original():
93
82
  "channel_id": xmls_original_key,
94
83
  "media_time": value,
95
84
  "upload": False,
85
+ "remove": False,
86
+ "hash": None,
96
87
  }
97
88
  for value, key in zip(
98
89
  timestamps, media
99
90
  ) # 使用 zip() 将 media 和 timestamps 组合成对
100
91
  ]
101
-
102
92
  # 如果成功填充 upload_original
103
93
  if upload_original:
104
94
  file_save(upload_original, "upload.json", "channel_data") # 保存到文件
105
95
  return upload_original
96
+
97
+
98
+ # 初始化原始上传信息
99
+ def get_upload_original():
100
+ if gVar.config["upload"]:
101
+ if upload_original := get_upload():
102
+ gVar.upload_original = upload_original
103
+ else:
104
+ gVar.config["upload"] = False
@@ -0,0 +1,74 @@
1
+ # Podflow/upload/linked_client.py
2
+ # coding: utf-8
3
+
4
+ import time
5
+ import socket
6
+ from datetime import datetime
7
+ from Podflow.upload.upload_print import upload_print
8
+
9
+
10
+ BROADCAST_PORT = 37000
11
+ TIMEOUT = 1 # 搜索超时时间(秒)
12
+ MAX_BROADCAST_PORT = 37101 # 尝试广播的最大端口
13
+
14
+
15
+ # 发现局域网内的服务器
16
+ def discover_server(broadcast_port, timeout):
17
+ servers = []
18
+
19
+ # 创建UDP socket
20
+ with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
21
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
22
+ sock.settimeout(timeout)
23
+
24
+ try:
25
+ # 发送广播请求
26
+ sock.sendto(b"DISCOVER_SERVER_REQUEST", ("<broadcast>", broadcast_port))
27
+ except Exception as e:
28
+ upload_print(f"广播请求发送失败: {e}")
29
+ return servers
30
+
31
+ # 等待响应
32
+ start_time = time.time()
33
+ while time.time() - start_time < timeout:
34
+ try:
35
+ data, addr = sock.recvfrom(1024)
36
+ if data.startswith(b"SERVER_INFO|"):
37
+ try:
38
+ port = int(data.decode().split("|")[1])
39
+ servers.append((addr[0], port))
40
+ except (IndexError, ValueError):
41
+ upload_print(f"收到来自 {addr} 的服务响应格式不正确")
42
+ except socket.timeout:
43
+ break
44
+ except Exception as e:
45
+ upload_print(f"接收数据出错: {e}")
46
+ break
47
+
48
+ return servers
49
+
50
+
51
+ # 自动发现并连接服务器模块
52
+ def connect_server():
53
+ upload_print("正在搜索服务器...")
54
+
55
+ current_port = BROADCAST_PORT
56
+ servers = []
57
+ time_print = f"{datetime.now().strftime('%H:%M:%S')}|"
58
+
59
+ # 在允许的端口范围内尝试发现服务器
60
+ while current_port < MAX_BROADCAST_PORT:
61
+ print(f"\r{time_print}正在尝试广播端口 {current_port}...", end="")
62
+ servers = discover_server(current_port, TIMEOUT)
63
+ if servers:
64
+ print("")
65
+ break
66
+ current_port += 1
67
+
68
+ if not servers:
69
+ upload_print("找不到服务器")
70
+ return
71
+
72
+ # 选择第一个找到的服务器
73
+ server_ip, server_port = servers[0]
74
+ upload_print(f"正在连接到{server_ip}:{server_port}")
@@ -0,0 +1,32 @@
1
+ # Podflow/upload/linked_server.py
2
+ # coding: utf-8
3
+
4
+ import socket
5
+ from Podflow.httpfs.port_judge import port_judge
6
+ from Podflow.upload.upload_print import upload_print
7
+
8
+
9
+ def usable_port(port, max_num):
10
+ hostip = "0.0.0.0"
11
+ while port <= max_num:
12
+ if port_judge(hostip, port):
13
+ return port
14
+ else:
15
+ port += 1
16
+ return None
17
+
18
+
19
+ # 处理服务发现请求的UDP服务模块
20
+ def handle_discovery(broadcast_port, service_port):
21
+ with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
22
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
23
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
24
+ sock.bind(("", broadcast_port))
25
+
26
+ upload_print("发现服务已启动...")
27
+ while True:
28
+ data, addr = sock.recvfrom(1024)
29
+ if data == b"DISCOVER_SERVER_REQUEST":
30
+ upload_print(f"来自{addr}的发现请求")
31
+ response = f"SERVER_INFO|{service_port}".encode()
32
+ sock.sendto(response, addr)
@@ -0,0 +1,74 @@
1
+ # Podflow/upload/update_upload.py
2
+ # coding: utf-8
3
+
4
+ import re
5
+ import time
6
+ from email.utils import parsedate_tz, mktime_tz
7
+ from Podflow import gVar
8
+ from Podflow.basic.file_save import file_save
9
+ from Podflow.message.get_media_name import get_media_name
10
+
11
+
12
+ # 更新并保存上传列表模块
13
+ def update_upload():
14
+ # 如果没有开启上传功能,则直接返回
15
+ if not gVar.config["upload"]:
16
+ return
17
+ # 初始化一个字典,用于存储每个输出目录的媒体名称
18
+ media_name = {}
19
+ # 初始化一个列表,用于存储需要上传的媒体部分
20
+ main_upload = []
21
+ # 获取原始上传列表
22
+ upload_original = gVar.upload_original
23
+ # 获取所有项目
24
+ all_items = gVar.all_items
25
+ # 遍历所有项目,获取每个输出目录的媒体名称
26
+ for output_dir, items_dict in all_items.items():
27
+ media_name[output_dir] = get_media_name(items_dict["type"], items_dict["items"])
28
+ # 遍历原始上传列表,筛选出需要上传的媒体部分
29
+ for upload_part in upload_original:
30
+ if (
31
+ upload_part["channel_id"] in media_name
32
+ and upload_part["media_id"] in media_name[upload_part["channel_id"]]
33
+ ):
34
+ main_upload.append(upload_part)
35
+
36
+ # 获取需要上传的媒体部分的ID
37
+ media_ids = [item["media_id"] for item in main_upload if "media_id" in item]
38
+ # 遍历每个输出目录的媒体部分,筛选出需要上传的媒体部分
39
+ for output_dir, media_parts in media_name.items():
40
+ for part in media_parts:
41
+ if part not in media_ids:
42
+ # 构造正则表达式,用于匹配媒体部分
43
+ pattern = rf"<!-- {output_dir} -->(?:(?!<!-- {output_dir} -->).)+channel_audiovisual/{output_dir}/{part}.+?<!-- {output_dir} -->"
44
+ pubdate_text = ""
45
+ # 在所有项目中匹配媒体部分
46
+ if match := re.search(
47
+ pattern, all_items[output_dir]["items"], flags=re.DOTALL
48
+ ):
49
+ date_text = match.group()
50
+ # 在匹配的媒体部分中提取发布日期
51
+ pattern = r"(?<=<pubDate>).+(?=</pubDate>)"
52
+ if match := re.search(pattern, date_text):
53
+ pubdate_text = match.group()
54
+ # 如果发布日期存在,则转换为时间戳;否则,使用当前时间戳
55
+ pubdate_text = (
56
+ mktime_tz(parsedate_tz(pubdate_text))
57
+ if parsedate_tz(pubdate_text)
58
+ else int(time.time())
59
+ )
60
+
61
+ # 将需要上传的媒体部分添加到列表中
62
+ main_upload.append(
63
+ {
64
+ "media_id": part,
65
+ "channel_id": output_dir,
66
+ "media_time": pubdate_text,
67
+ "upload": False,
68
+ "remove": False,
69
+ "hash": None,
70
+ }
71
+ )
72
+
73
+ # 将需要上传的媒体部分保存到文件中
74
+ file_save(main_upload, "upload.json", "channel_data") # 保存到文件
@@ -0,0 +1,8 @@
1
+ # Podflow/upload/upload_print.py
2
+ # coding: utf-8
3
+
4
+ from datetime import datetime
5
+
6
+
7
+ def upload_print(text):
8
+ print(f"{datetime.now().strftime('%H:%M:%S')}|{text}")