Beispiel #1
0
def download_pp(pp_id):
    pp_src_meta = client.get_playlist_meta(pp_id, cfg['meta_lang'])[0]
    tra_src_meta = client.get_playlist_tracks(pp_id, cfg['meta_lang'])
    total = len(tra_src_meta)

    pp_fol = "{}".format(pp_src_meta['name'])
    pp_abs = os.path.join(cfg['output_dir'], sanitize(pp_fol))
    dir_setup(pp_abs)

    print(pp_fol)
    for num, track in enumerate(tra_src_meta, 1):
        if not track['isStreamable']:
            print("Track isn't allowed to be streamed.")
            continue

        alb_src_meta = client.get_album_meta(track['albumId'],
                                             cfg['meta_lang'])
        alb_meta = parse_meta(alb_src_meta, total=total)

        specs = query_quals(track['formats'] + track['losslessFormats'])
        meta = parse_meta(track, meta=alb_meta, num=num)
        pre_abs = os.path.join(pp_abs, str(num) + ".mq-dl")
        post_abs = os.path.join(pp_abs,
                                sanitize(parse_template(meta)) + specs['ext'])
        if os.path.isfile(post_abs):
            print("Track already exists locally.")
            continue
        stream_url = client.get_track_stream(specs['brate'], specs['fmt'],
                                             track['id'])
        download_track(stream_url, specs, meta['title'], num, total, pre_abs)

        cov_abs = os.path.join(pp_abs, "cover.jpg")
        try:
            download_cov(track['albumId'], cov_abs)
        except HTTPError as e:
            print("Failed to get cover.")
            err(e)
            cov_abs = None
        write_tags(pre_abs, meta, specs['fmt'], cov_abs)
        try:
            os.rename(pre_abs, post_abs)
        except OSError as e:
            print("Failed to rename track.")
            err(e)
        os.remove(cov_abs)
Beispiel #2
0
def download_tra(tra_id):
    tra_src_meta = client.get_track_meta(tra_id, cfg['meta_lang'])[0]
    alb_src_meta = client.get_album_meta(tra_src_meta['albumId'],
                                         cfg['meta_lang'])
    total = 1
    alb_meta = parse_meta(alb_src_meta, total=total)
    alb_fol = "{} - {}".format(tra_src_meta['artistName'],
                               tra_src_meta['name'])
    alb_abs = os.path.join(cfg['output_dir'], sanitize(alb_fol))
    cov_abs = os.path.join(alb_abs, "cover.jpg")
    dir_setup(alb_abs)
    print(alb_fol)
    if not tra_src_meta['isStreamable']:
        print("Track isn't allowed to be streamed.")
        return
    specs = query_quals(tra_src_meta['formats'] +
                        tra_src_meta['losslessFormats'])
    meta = parse_meta(tra_src_meta, meta=alb_meta, num=1)
    pre_abs = os.path.join(alb_abs, str(1) + ".mq-dl")
    post_abs = os.path.join(alb_abs,
                            sanitize(parse_template(meta)) + specs['ext'])
    if os.path.isfile(post_abs):
        print("Track already exists locally.")
        return
    stream_url = client.get_track_stream(specs['brate'], specs['fmt'],
                                         tra_src_meta['id'])
    download_track(stream_url, specs, meta['title'], num, total, pre_abs)
    try:
        download_cov(tra_src_meta['albumId'], cov_abs)
    except HTTPError as e:
        print("Failed to get cover.")
        err(e)
        cov_abs = None
    write_tags(pre_abs, meta, specs['fmt'], cov_abs)
    try:
        os.rename(pre_abs, post_abs)
    except OSError as e:
        print("Failed to rename track.")
        err(e)
    if cov_abs and not cfg['keep_cover']:
        os.remove(cov_abs)