Skip to content

Commit

Permalink
同时生成播放列表和节目单文件的 sha256 摘要文件
Browse files Browse the repository at this point in the history
  • Loading branch information
VergilGao committed Dec 31, 2024
1 parent f94dace commit ae5a377
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
21 changes: 15 additions & 6 deletions src/stbmock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
from typing import Tuple
import requests
from urllib.parse import urlparse
from utils import getAuthenticator
from utils import getAuthenticator, generate_sha256
from config import StbConfig, UdpxyConfig
from collections import namedtuple
from storage import Storage
from os import path
import re
import ast


def stb_login(
storage: Storage,
Expand Down Expand Up @@ -213,7 +211,8 @@ def stb_login(

print("第六步,生成播放列表")

with open(path.join(data_dir, "iptv.m3u"), "w", encoding="utf-8") as m3u_file:
m3u_file_path = path.join(data_dir, "iptv.m3u")
with open(m3u_file_path, "w", encoding="utf-8") as m3u_file:
m3u_file.write("#EXTM3U")
for channel_info in channel_infos:
m3u_file.write(
Expand All @@ -223,9 +222,12 @@ def stb_login(
{udpxy_config.udpxy_url}/{udpxy_config.udpxy_protocal}/{channel_info.igmp_url}"""
)

print("播放列表已生成")
m3u_hash = generate_sha256(m3u_file_path)

with open(f"{m3u_file_path}.sha256sums", "w") as file:
file.write(m3u_hash)

print("播放列表已生成")

print("第七步,获取节目单服务器地址")

Expand Down Expand Up @@ -323,8 +325,15 @@ def stb_login(

print("最终步,生成epg电子节目单")

epg_file_path = path.join(data_dir, "epg.xml")

storage.epg_generator(
path.join(data_dir, "epg.xml"),
epg_file_path,
today + timedelta(days=-7),
today + timedelta(days=2),
)

epg_hash = generate_sha256(epg_file_path)

with open(f"{epg_file_path}.sha256sums", "w") as file:
file.write(epg_hash)
15 changes: 13 additions & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from Crypto.Cipher import DES
from hashlib import md5

from hashlib import md5, sha256

def pretty_xml(element, indent, newline, level=0):
# 判断element是否有子元素
Expand Down Expand Up @@ -35,3 +34,15 @@ def getAuthenticator(userid: str, password: str, stbid: str, mac: str, encry_tok

key: bytes = bytes(md5(salty).hexdigest()[:8], encoding='ascii')
return (DES.new(key, DES.MODE_ECB).encrypt(payload)).hex().upper()

def generate_sha256(file_path):
# 创建一个 SHA-256 哈希对象
sha256_hash = sha256()

# 以二进制方式读取文件,并更新哈希对象
with open(file_path, "rb") as file:
for byte_block in iter(lambda: file.read(4096), b""):
sha256_hash.update(byte_block)

# 返回文件的 SHA-256 摘要
return sha256_hash.hexdigest()

0 comments on commit ae5a377

Please sign in to comment.