Fix for #21

Fix for #20

Feature for #18
This commit is contained in:
vitiko98 2020-12-12 17:32:09 -04:00
parent 2ff4835299
commit 9cec3fccfb
4 changed files with 52 additions and 27 deletions

View File

@ -1,2 +1,2 @@
from .qopy import Client
from .cli import main
from .qopy import Client

View File

@ -38,15 +38,23 @@ def getDesc(u, mt, multiple=None):
)
def get_format(album_dict, quality):
def get_format(client, item_dict, quality, is_track_id=False):
if int(quality) == 5:
return "MP3"
track_dict = item_dict
if not is_track_id:
track_dict = [i for i in item_dict["tracks"]["items"]][0]
try:
if int(quality) == 5:
return "MP3"
if album_dict["maximum_bit_depth"] == 16 and int(quality) < 7:
new_track_dict = client.get_track_url(track_dict["id"], quality)
if (
new_track_dict["bit_depth"] == 16
and new_track_dict["sampling_rate"] == 44.1
):
return "FLAC"
return "Hi-Res"
except KeyError:
return "Unknown"
return "Hi-Res"
def get_extra(i, dirn, extra="cover.jpg"):
@ -134,17 +142,16 @@ def download_id_by_type(client, item_id, path, quality, album=False, embed_art=F
if album:
meta = client.get_album_meta(item_id)
album_title = (
"{} ({})".format(meta["title"], meta["version"])
if meta["version"]
else meta["title"]
)
try:
album_title = "{} ({})".format(meta["title"], meta["version"])
except KeyError:
album_title = meta["title"]
print("\nDownloading: {}\n".format(album_title))
dirT = (
meta["artist"]["name"],
album_title,
meta["release_date_original"].split("-")[0],
get_format(meta, quality),
get_format(client, meta, quality),
)
sanitized_title = sanitize_filename("{} - {} [{}] [{}]".format(*dirT))
dirn = os.path.join(path, sanitized_title)
@ -180,17 +187,16 @@ def download_id_by_type(client, item_id, path, quality, album=False, embed_art=F
if "sample" not in parse and parse["sampling_rate"]:
meta = client.get_track_meta(item_id)
track_title = (
"{} ({})".format(meta["title"], meta["version"])
if meta["version"]
else meta["title"]
)
try:
track_title = "{} ({})".format(meta["title"], meta["version"])
except KeyError:
track_title = meta["title"]
print("\nDownloading: {}\n".format(track_title))
dirT = (
meta["album"]["artist"]["name"],
track_title,
meta["album"]["release_date_original"].split("-")[0],
get_format(meta, quality),
get_format(client, meta, quality, True),
)
sanitized_title = sanitize_filename("{} - {} [{}] [{}]".format(*dirT))
dirn = os.path.join(path, sanitized_title)

View File

@ -18,10 +18,18 @@ def tag_flac(filename, root_dir, final_name, d, album, istrack=True, em_image=Fa
"""
audio = FLAC(filename)
audio["TITLE"] = (
"{} ({})".format(d["title"], d["version"]) if d["version"] else d["title"]
) # TRACK TITLE
try:
audio["TITLE"] = "{} ({})".format(d["title"], d["version"])
except KeyError:
audio["TITLE"] = d["title"]
audio["TRACKNUMBER"] = str(d["track_number"]) # TRACK NUMBER
try:
audio["WORK"] = d["work"]
except KeyError:
pass
try:
audio["COMPOSER"] = d["composer"]["name"] # COMPOSER
except KeyError:
@ -73,17 +81,23 @@ def tag_mp3(filename, root_dir, final_name, d, album, istrack=True, em_image=Fal
:param str root_dir: Root dir used to get the cover art
:param str final_name: Final name of the mp3 file (complete path)
:param dict d: Track dictionary from Qobuz_client
:param dict album: Album dictionary from Qobuz_client
:param bool istrack
:param bool istrack: Embed cover art into file
:param bool em_image: Embed cover art into file
"""
# TODO: add embedded cover art support for mp3
audio = EasyMP3(filename)
audio["title"] = (
"{} ({})".format(d["title"], d["version"]) if d["version"] else d["title"]
) # TRACK TITLE
try:
audio["title"] = "{} ({})".format(d["title"], d["version"])
except KeyError:
audio["title"] = d["title"]
audio["tracknumber"] = str(d["track_number"])
try:
audio["discsubtitle"] = d["work"]
except KeyError:
pass
try:
audio["composer"] = d["composer"]["name"]
except KeyError:

View File

@ -29,8 +29,13 @@ class Search:
self.Total.append("[RELEASE] {} - {} - {} [{}]".format(*items))
self.appendInfo(i, True)
except KeyError:
try:
artist_field = i["performer"]["name"]
except KeyError:
print("Download: " + i["title"])
artist_field = i["composer"]["name"]
items = (
i["performer"]["name"],
artist_field,
i["title"],
self.seconds(i["duration"]),
"HI-RES" if i["hires"] else "Lossless",