mirror of
https://github.com/glomatico/gamdl.git
synced 2025-01-23 11:48:39 +00:00
start session and start cdm
This commit is contained in:
parent
9358a8b760
commit
6f96166cf0
41
gamdl/cli.py
41
gamdl/cli.py
@ -300,21 +300,13 @@ def main(
|
|||||||
)
|
)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.setLevel(log_level)
|
logger.setLevel(log_level)
|
||||||
|
dl = Dl(**locals())
|
||||||
if not wvd_location.exists() and not lrc_only:
|
if not wvd_location.exists() and not lrc_only:
|
||||||
logger.critical(X_NOT_FOUND_STRING.format(".wvd file", wvd_location))
|
logger.critical(X_NOT_FOUND_STRING.format(".wvd file", wvd_location))
|
||||||
return
|
return
|
||||||
if not cookies_location.exists():
|
if not cookies_location.exists():
|
||||||
logger.critical(X_NOT_FOUND_STRING.format("Cookies file", cookies_location))
|
logger.critical(X_NOT_FOUND_STRING.format("Cookies file", cookies_location))
|
||||||
return
|
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 remux_mode == "ffmpeg" and not lrc_only:
|
||||||
if not dl.ffmpeg_location:
|
if not dl.ffmpeg_location:
|
||||||
logger.critical(X_NOT_FOUND_STRING.format("FFmpeg", ffmpeg_location))
|
logger.critical(X_NOT_FOUND_STRING.format("FFmpeg", ffmpeg_location))
|
||||||
@ -342,10 +334,33 @@ def main(
|
|||||||
if not dl.ffmpeg_location:
|
if not dl.ffmpeg_location:
|
||||||
logger.critical(X_NOT_FOUND_STRING.format("FFmpeg", ffmpeg_location))
|
logger.critical(X_NOT_FOUND_STRING.format("FFmpeg", ffmpeg_location))
|
||||||
return
|
return
|
||||||
if not dl.session.cookies.get_dict().get("media-user-token"):
|
logger.debug("Setting up session")
|
||||||
logger.critical("Invalid cookies file")
|
try:
|
||||||
|
dl.setup_session()
|
||||||
|
except Exception:
|
||||||
|
logger.critical(
|
||||||
|
"Failed to setup session, check your cookies file",
|
||||||
|
exc_info=print_exceptions,
|
||||||
|
)
|
||||||
return
|
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 = []
|
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):
|
for i, url in enumerate(urls, start=1):
|
||||||
try:
|
try:
|
||||||
logger.debug(f'Checking "{url}" (URL {i}/{len(urls)})')
|
logger.debug(f'Checking "{url}" (URL {i}/{len(urls)})')
|
||||||
@ -357,7 +372,9 @@ def main(
|
|||||||
error_count = 0
|
error_count = 0
|
||||||
for i, url in enumerate(download_queue, start=1):
|
for i, url in enumerate(download_queue, start=1):
|
||||||
for j, track in enumerate(url, 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
|
continue
|
||||||
logger.info(
|
logger.info(
|
||||||
f'Downloading "{track["attributes"]["name"]}" (track {j}/{len(url)} from URL {i}/{len(download_queue)})'
|
f'Downloading "{track["attributes"]["name"]}" (track {j}/{len(url)} from URL {i}/{len(download_queue)})'
|
||||||
|
14
gamdl/dl.py
14
gamdl/dl.py
@ -69,12 +69,13 @@ class Dl:
|
|||||||
prefer_hevc: bool = None,
|
prefer_hevc: bool = None,
|
||||||
ask_video_format: bool = None,
|
ask_video_format: bool = None,
|
||||||
disable_music_video_album_skip: bool = None,
|
disable_music_video_album_skip: bool = None,
|
||||||
lrc_only: bool = None,
|
|
||||||
songs_heaac: bool = None,
|
songs_heaac: bool = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
self.final_path = final_path
|
self.final_path = final_path
|
||||||
self.temp_path = temp_path
|
self.temp_path = temp_path
|
||||||
|
self.cookies_location = cookies_location
|
||||||
|
self.wvd_location = wvd_location
|
||||||
self.ffmpeg_location = (
|
self.ffmpeg_location = (
|
||||||
shutil.which(ffmpeg_location) if ffmpeg_location else None
|
shutil.which(ffmpeg_location) if ffmpeg_location else None
|
||||||
)
|
)
|
||||||
@ -107,10 +108,9 @@ class Dl:
|
|||||||
self.ask_video_format = ask_video_format
|
self.ask_video_format = ask_video_format
|
||||||
self.disable_music_video_album_skip = disable_music_video_album_skip
|
self.disable_music_video_album_skip = disable_music_video_album_skip
|
||||||
self.songs_flavor = "32:ctrp64" if songs_heaac else "28:ctrp256"
|
self.songs_flavor = "32:ctrp64" if songs_heaac else "28:ctrp256"
|
||||||
if not lrc_only:
|
|
||||||
self.cdm = Cdm.from_device(Device.load(wvd_location))
|
def setup_session(self):
|
||||||
self.cdm_session = self.cdm.open()
|
cookies = MozillaCookieJar(self.cookies_location)
|
||||||
cookies = MozillaCookieJar(cookies_location)
|
|
||||||
cookies.load(ignore_discard=True, ignore_expires=True)
|
cookies.load(ignore_discard=True, ignore_expires=True)
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
self.session.cookies.update(cookies)
|
self.session.cookies.update(cookies)
|
||||||
@ -143,6 +143,10 @@ class Dl:
|
|||||||
self.country = self.session.cookies.get_dict()["itua"]
|
self.country = self.session.cookies.get_dict()["itua"]
|
||||||
self.storefront = getattr(gamdl.storefronts, self.country.upper())
|
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):
|
def get_download_queue(self, url):
|
||||||
download_queue = []
|
download_queue = []
|
||||||
track_id = url.split("/")[-1].split("i=")[-1].split("&")[0].split("?")[0]
|
track_id = url.split("/")[-1].split("i=")[-1].split("&")[0].split("?")[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user