start session and start cdm

This commit is contained in:
R. M 2023-09-04 17:12:36 -03:00
parent 9358a8b760
commit 6f96166cf0
2 changed files with 38 additions and 17 deletions

View File

@ -300,21 +300,13 @@ def main(
)
logger = logging.getLogger(__name__)
logger.setLevel(log_level)
dl = Dl(**locals())
if not wvd_location.exists() and not lrc_only:
logger.critical(X_NOT_FOUND_STRING.format(".wvd file", wvd_location))
return
if not cookies_location.exists():
logger.critical(X_NOT_FOUND_STRING.format("Cookies file", cookies_location))
return
if url_txt:
logger.debug("Reading URLs from text files")
_urls = []
for url in urls:
with open(url, "r") as f:
_urls.extend(f.read().splitlines())
urls = tuple(_urls)
logger.debug("Starting downloader")
dl = Dl(**locals())
if remux_mode == "ffmpeg" and not lrc_only:
if not dl.ffmpeg_location:
logger.critical(X_NOT_FOUND_STRING.format("FFmpeg", ffmpeg_location))
@ -342,10 +334,33 @@ def main(
if not dl.ffmpeg_location:
logger.critical(X_NOT_FOUND_STRING.format("FFmpeg", ffmpeg_location))
return
if not dl.session.cookies.get_dict().get("media-user-token"):
logger.critical("Invalid cookies file")
logger.debug("Setting up session")
try:
dl.setup_session()
except Exception:
logger.critical(
"Failed to setup session, check your cookies file",
exc_info=print_exceptions,
)
return
if not lrc_only:
logger.debug("Setting up CDM")
try:
dl.setup_cdm()
except Exception:
logger.critical(
"Failed to setup CDM, check your .wvd file",
exc_info=print_exceptions,
)
return
download_queue = []
if url_txt:
logger.debug("Reading URLs from text files")
_urls = []
for url in urls:
with open(url, "r") as f:
_urls.extend(f.read().splitlines())
urls = tuple(_urls)
for i, url in enumerate(urls, start=1):
try:
logger.debug(f'Checking "{url}" (URL {i}/{len(urls)})')
@ -357,7 +372,9 @@ def main(
error_count = 0
for i, url in enumerate(download_queue, start=1):
for j, track in enumerate(url, start=1):
if track["type"] == "music-videos" and (not dl.mp4decrypt_location or lrc_only):
if track["type"] == "music-videos" and (
not dl.mp4decrypt_location or lrc_only
):
continue
logger.info(
f'Downloading "{track["attributes"]["name"]}" (track {j}/{len(url)} from URL {i}/{len(download_queue)})'

View File

@ -69,12 +69,13 @@ class Dl:
prefer_hevc: bool = None,
ask_video_format: bool = None,
disable_music_video_album_skip: bool = None,
lrc_only: bool = None,
songs_heaac: bool = None,
**kwargs,
):
self.final_path = final_path
self.temp_path = temp_path
self.cookies_location = cookies_location
self.wvd_location = wvd_location
self.ffmpeg_location = (
shutil.which(ffmpeg_location) if ffmpeg_location else None
)
@ -107,10 +108,9 @@ class Dl:
self.ask_video_format = ask_video_format
self.disable_music_video_album_skip = disable_music_video_album_skip
self.songs_flavor = "32:ctrp64" if songs_heaac else "28:ctrp256"
if not lrc_only:
self.cdm = Cdm.from_device(Device.load(wvd_location))
self.cdm_session = self.cdm.open()
cookies = MozillaCookieJar(cookies_location)
def setup_session(self):
cookies = MozillaCookieJar(self.cookies_location)
cookies.load(ignore_discard=True, ignore_expires=True)
self.session = requests.Session()
self.session.cookies.update(cookies)
@ -143,6 +143,10 @@ class Dl:
self.country = self.session.cookies.get_dict()["itua"]
self.storefront = getattr(gamdl.storefronts, self.country.upper())
def setup_cdm(self):
self.cdm = Cdm.from_device(Device.load(self.wvd_location))
self.cdm_session = self.cdm.open()
def get_download_queue(self, url):
download_queue = []
track_id = url.split("/")[-1].split("i=")[-1].split("&")[0].split("?")[0]