diff --git a/devine/core/manifests/dash.py b/devine/core/manifests/dash.py index cf500f7..f0d3680 100644 --- a/devine/core/manifests/dash.py +++ b/devine/core/manifests/dash.py @@ -11,11 +11,11 @@ from concurrent import futures from concurrent.futures import ThreadPoolExecutor from copy import copy from functools import partial -from hashlib import md5 from pathlib import Path from typing import Any, Callable, MutableMapping, Optional, Union from urllib.parse import urljoin, urlparse from uuid import UUID +from zlib import crc32 import requests from langcodes import Language, tag_is_valid @@ -195,14 +195,14 @@ class DASH: # a good and actually unique track ID, sometimes because of the lang # dialect not being represented in the id, or the bitrate, or such. # this combines all of them as one and hashes it to keep it small(ish). - track_id = md5("{codec}-{lang}-{bitrate}-{base_url}-{ids}-{track_args}".format( + track_id = hex(crc32("{codec}-{lang}-{bitrate}-{base_url}-{ids}-{track_args}".format( codec=codecs, lang=track_lang, bitrate=get("bitrate"), base_url=(rep.findtext("BaseURL") or "").split("?")[0], ids=[get("audioTrackId"), get("id"), period.get("id")], track_args=track_args - ).encode()).hexdigest() + ).encode()))[2:] tracks.add(track_type( id_=track_id, diff --git a/devine/core/manifests/hls.py b/devine/core/manifests/hls.py index ec0f7cd..6c1fe86 100644 --- a/devine/core/manifests/hls.py +++ b/devine/core/manifests/hls.py @@ -10,12 +10,12 @@ import time from concurrent import futures from concurrent.futures import ThreadPoolExecutor from functools import partial -from hashlib import md5 from pathlib import Path from queue import Queue from threading import Lock from typing import Any, Callable, Optional, Union from urllib.parse import urljoin +from zlib import crc32 import m3u8 import requests @@ -115,7 +115,7 @@ class HLS: primary_track_type = Video tracks.add(primary_track_type( - id_=md5(str(playlist).encode()).hexdigest()[0:7], # 7 chars only for filename length + id_=hex(crc32(str(playlist).encode()))[2:], url=urljoin(playlist.base_uri, playlist.uri), codec=primary_track_type.Codec.from_codecs(playlist.stream_info.codecs), language=language, # HLS manifests do not seem to have language info @@ -166,7 +166,7 @@ class HLS: raise ValueError(msg) tracks.add(track_type( - id_=md5(str(media).encode()).hexdigest()[0:6], # 6 chars only for filename length + id_=hex(crc32(str(media).encode()))[2:], url=urljoin(media.base_uri, media.uri), codec=codec, language=track_lang, # HLS media may not have language info, fallback if needed