fix extensions, compatibility for python < 3.11
This commit is contained in:
parent
6f137fd50d
commit
036e981fe2
|
@ -1,3 +1 @@
|
||||||
auth.json
|
|
||||||
|
|
||||||
tidal-scraper/__pycache__
|
tidal-scraper/__pycache__
|
3
TODO.md
3
TODO.md
|
@ -2,3 +2,6 @@
|
||||||
- [ ] installer should create state and config homes if not existing
|
- [ ] installer should create state and config homes if not existing
|
||||||
- [ ] proper SIGTERM handling
|
- [ ] proper SIGTERM handling
|
||||||
- [ ] decrypt and write in chunks
|
- [ ] decrypt and write in chunks
|
||||||
|
- [ ] test error logger
|
||||||
|
|
||||||
|
- [ ] Switch to tomllib once ubuntu updates their python package to 3.11 (I haven't switched yet to avoid github issues being made)
|
||||||
|
|
11
conf.toml
11
conf.toml
|
@ -7,14 +7,17 @@ quality = "lossless"
|
||||||
user_id =
|
user_id =
|
||||||
|
|
||||||
dest_dir = "./downloads/"
|
dest_dir = "./downloads/"
|
||||||
# The following templates are passed an artist, album and track object.
|
|
||||||
|
# These templates are passed their respective tidalapi objects
|
||||||
# Possible attributes can be found here: https://tidalapi.netlify.app/api.html
|
# Possible attributes can be found here: https://tidalapi.netlify.app/api.html
|
||||||
# The artist is derived from the album a track is in rather than the track itself.
|
album_dir = "{album.artist.name}/{album.name}/"
|
||||||
album_dir = "{artist.name}/{album.name}/"
|
|
||||||
playlist_dir = "{playlist.name}/"
|
playlist_dir = "{playlist.name}/"
|
||||||
track_name = "{track.track_num}: {track.name}"
|
# Rather than receiving an artist, the track receives both "albumartist" and a "trackartist"
|
||||||
|
track_name = "{track.track_num}: {track.artist.name} - {track.name}"
|
||||||
|
|
||||||
# One of 160, 320, 480, 640, 750, 1080
|
# One of 160, 320, 480, 640, 750, 1080
|
||||||
playlist_image_size = 1080
|
playlist_image_size = 1080
|
||||||
# One of 80, 160, 320, 640, 1280
|
# One of 80, 160, 320, 640, 1280
|
||||||
album_image_size = 1280
|
album_image_size = 1280
|
||||||
|
|
||||||
|
debug = false
|
||||||
|
|
|
@ -2,3 +2,4 @@ git+https://github.com/tamland/python-tidal
|
||||||
pycrypto
|
pycrypto
|
||||||
tqdm
|
tqdm
|
||||||
mutagen
|
mutagen
|
||||||
|
toml
|
||||||
|
|
|
@ -60,10 +60,14 @@ def download_track(track: tidalapi.Track, dest: str) -> None:
|
||||||
album = track.album
|
album = track.album
|
||||||
assert album
|
assert album
|
||||||
print(f"Starting {album.artist.name} - {track.name}")
|
print(f"Starting {album.artist.name} - {track.name}")
|
||||||
dest += clean_template(conf["track_name"], track=track)
|
dest += clean_template(
|
||||||
|
conf["track_name"],
|
||||||
|
track=track,
|
||||||
|
)
|
||||||
http_failures = 0
|
http_failures = 0
|
||||||
while http_failures <= 3:
|
while http_failures <= 3:
|
||||||
try:
|
try:
|
||||||
|
print("running")
|
||||||
stream = track.stream()
|
stream = track.stream()
|
||||||
manifest = json.loads(b64decode(stream.manifest))
|
manifest = json.loads(b64decode(stream.manifest))
|
||||||
if conf["debug"]:
|
if conf["debug"]:
|
||||||
|
@ -76,8 +80,10 @@ def download_track(track: tidalapi.Track, dest: str) -> None:
|
||||||
else:
|
else:
|
||||||
dest += ".m4a"
|
dest += ".m4a"
|
||||||
else:
|
else:
|
||||||
for ext in (x for x in extensions if x != ".mp4"):
|
for ext in extensions:
|
||||||
|
if ext in url:
|
||||||
dest += ext
|
dest += ext
|
||||||
|
break
|
||||||
if os.path.exists(dest) and conf["skip_downloaded"]:
|
if os.path.exists(dest) and conf["skip_downloaded"]:
|
||||||
print(f"Skipping track")
|
print(f"Skipping track")
|
||||||
return
|
return
|
||||||
|
@ -105,7 +111,9 @@ def download_track(track: tidalapi.Track, dest: str) -> None:
|
||||||
break
|
break
|
||||||
except requests.HTTPError:
|
except requests.HTTPError:
|
||||||
http_failures += 1
|
http_failures += 1
|
||||||
except:
|
except KeyboardInterrupt as e:
|
||||||
|
raise e
|
||||||
|
except Exception as e:
|
||||||
log_error(
|
log_error(
|
||||||
"Failure while downloading {artist} - {track}",
|
"Failure while downloading {artist} - {track}",
|
||||||
artist=album.artist.name,
|
artist=album.artist.name,
|
||||||
|
@ -129,7 +137,6 @@ def download_album(album: tidalapi.Album) -> None:
|
||||||
dest = clean_template(
|
dest = clean_template(
|
||||||
conf["dest_dir"] + "/" + conf["album_dir"],
|
conf["dest_dir"] + "/" + conf["album_dir"],
|
||||||
album=album,
|
album=album,
|
||||||
artist=album.artist,
|
|
||||||
)
|
)
|
||||||
os.makedirs(os.path.dirname(dest), exist_ok=True)
|
os.makedirs(os.path.dirname(dest), exist_ok=True)
|
||||||
download_cover(album, dest, conf["album_image_size"])
|
download_cover(album, dest, conf["album_image_size"])
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import tomllib
|
import toml
|
||||||
|
# TODO: wait for python to update to 3.11 for ubuntu users
|
||||||
|
# import tomllib
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
@ -19,8 +21,10 @@ if not conf_dir:
|
||||||
conf_dir += "/tidal-scraper"
|
conf_dir += "/tidal-scraper"
|
||||||
state_dir += "/tidal-scraper"
|
state_dir += "/tidal-scraper"
|
||||||
|
|
||||||
with open(conf_dir + "/conf.toml", "rb") as f:
|
with open(conf_dir + "/conf.toml", "r") as f:
|
||||||
conf = tomllib.load(f)
|
conf = toml.load(f)
|
||||||
|
# with open(conf_dir + "/conf.toml", "rb") as f:
|
||||||
|
# conf = tomllib.load(f)
|
||||||
|
|
||||||
|
|
||||||
def clean_template(path: str, **kwargs) -> str:
|
def clean_template(path: str, **kwargs) -> str:
|
||||||
|
@ -33,5 +37,6 @@ def clean_template(path: str, **kwargs) -> str:
|
||||||
def log_error(template: str, **kwargs):
|
def log_error(template: str, **kwargs):
|
||||||
with open(conf["error_log"], "a") as f:
|
with open(conf["error_log"], "a") as f:
|
||||||
msg = template.format(**kwargs)
|
msg = template.format(**kwargs)
|
||||||
f.write(msg + "\n\n\n")
|
f.write(msg + "\n")
|
||||||
traceback.format_exception(*sys.exc_info())
|
traceback.format_exception(*sys.exc_info())
|
||||||
|
f.write("\n\n")
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/env python
|
#!/bin/env python3
|
||||||
from download import download_album
|
from download import download_album
|
||||||
from state import State
|
from state import State
|
||||||
from helper import conf
|
from helper import conf
|
||||||
|
|
Loading…
Reference in New Issue