fix extensions, compatibility for python < 3.11
This commit is contained in:
parent
6f137fd50d
commit
036e981fe2
7 changed files with 34 additions and 17 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -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
|
||||
- [ ] proper SIGTERM handling
|
||||
- [ ] 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 =
|
||||
|
||||
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
|
||||
# The artist is derived from the album a track is in rather than the track itself.
|
||||
album_dir = "{artist.name}/{album.name}/"
|
||||
album_dir = "{album.artist.name}/{album.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
|
||||
playlist_image_size = 1080
|
||||
# One of 80, 160, 320, 640, 1280
|
||||
album_image_size = 1280
|
||||
|
||||
debug = false
|
||||
|
|
|
@ -2,3 +2,4 @@ git+https://github.com/tamland/python-tidal
|
|||
pycrypto
|
||||
tqdm
|
||||
mutagen
|
||||
toml
|
||||
|
|
|
@ -60,10 +60,14 @@ def download_track(track: tidalapi.Track, dest: str) -> None:
|
|||
album = track.album
|
||||
assert album
|
||||
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
|
||||
while http_failures <= 3:
|
||||
try:
|
||||
print("running")
|
||||
stream = track.stream()
|
||||
manifest = json.loads(b64decode(stream.manifest))
|
||||
if conf["debug"]:
|
||||
|
@ -76,8 +80,10 @@ def download_track(track: tidalapi.Track, dest: str) -> None:
|
|||
else:
|
||||
dest += ".m4a"
|
||||
else:
|
||||
for ext in (x for x in extensions if x != ".mp4"):
|
||||
dest += ext
|
||||
for ext in extensions:
|
||||
if ext in url:
|
||||
dest += ext
|
||||
break
|
||||
if os.path.exists(dest) and conf["skip_downloaded"]:
|
||||
print(f"Skipping track")
|
||||
return
|
||||
|
@ -105,7 +111,9 @@ def download_track(track: tidalapi.Track, dest: str) -> None:
|
|||
break
|
||||
except requests.HTTPError:
|
||||
http_failures += 1
|
||||
except:
|
||||
except KeyboardInterrupt as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
log_error(
|
||||
"Failure while downloading {artist} - {track}",
|
||||
artist=album.artist.name,
|
||||
|
@ -129,7 +137,6 @@ def download_album(album: tidalapi.Album) -> None:
|
|||
dest = clean_template(
|
||||
conf["dest_dir"] + "/" + conf["album_dir"],
|
||||
album=album,
|
||||
artist=album.artist,
|
||||
)
|
||||
os.makedirs(os.path.dirname(dest), exist_ok=True)
|
||||
download_cover(album, dest, conf["album_image_size"])
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import re
|
||||
import os
|
||||
import tomllib
|
||||
import toml
|
||||
# TODO: wait for python to update to 3.11 for ubuntu users
|
||||
# import tomllib
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
|
@ -19,8 +21,10 @@ if not conf_dir:
|
|||
conf_dir += "/tidal-scraper"
|
||||
state_dir += "/tidal-scraper"
|
||||
|
||||
with open(conf_dir + "/conf.toml", "rb") as f:
|
||||
conf = tomllib.load(f)
|
||||
with open(conf_dir + "/conf.toml", "r") as 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:
|
||||
|
@ -33,5 +37,6 @@ def clean_template(path: str, **kwargs) -> str:
|
|||
def log_error(template: str, **kwargs):
|
||||
with open(conf["error_log"], "a") as f:
|
||||
msg = template.format(**kwargs)
|
||||
f.write(msg + "\n\n\n")
|
||||
f.write(msg + "\n")
|
||||
traceback.format_exception(*sys.exc_info())
|
||||
f.write("\n\n")
|
||||
|
|
2
tidal-scraper/run.py
Normal file → Executable file
2
tidal-scraper/run.py
Normal file → Executable file
|
@ -1,4 +1,4 @@
|
|||
#!/bin/env python
|
||||
#!/bin/env python3
|
||||
from download import download_album
|
||||
from state import State
|
||||
from helper import conf
|
||||
|
|
Loading…
Add table
Reference in a new issue