Exemplo n.º 1
0
def download_file(url, output_path, stream=True):
    output_dir = os.path.dirname(output_path)
    os.makedirs(output_dir, exist_ok=True)
    if not url:
        log.error("URL is empty")
        return
    try:
        log.info('downloading ' + os.path.basename(output_path))
        r = requests.get(
            url,
            stream=stream,
            headers=config.get("wget_headers"),
            proxies=config.get("proxies"),
        )
        if stream:
            # TODO: implement cache playing later
            total_size = int(r.headers["content-length"])
            with open(output_path, "wb") as f:
                for chunk in r.iter_content(chunk_size=1024):
                    if chunk:
                        f.write(chunk)
                f.close()
        else:
            with open(output_path, "wb") as f:
                f.write(r.content)
                f.close()

        log.info(os.path.basename(output_path) + ' is downloaded')
    except Exception as e:
        log.error(e)
Exemplo n.º 2
0
def test_set():
    config.init()
    assert config.get("fasdfjklasd") == ""
    config.set("fasdfjklasd", "music-dl")
    assert config.get("fasdfjklasd") == "music-dl"
    proxies = {"http": "http://127.0.0.1:1087", "https": "http://127.0.0.1:1087"}
    config.set("proxies", proxies)
    assert config.get("proxies")["http"] == "http://127.0.0.1:1087"
    assert config.get("proxies")["https"] == "http://127.0.0.1:1087"
Exemplo n.º 3
0
def test_playlist():
    config.init()
    config.set('outdir', 'E:\\My Documents\\My Musics\\')
    # config.set('outdir', 'E:\\test\\')
    config.set('lyrics', True)
    # config.set('lyricsOnly', True)
    config.set('source', 'netease')
    config.set('playlist', 'https://music.163.com/playlist?id=4943411818&userid=52794579')

    ms = MusicSource()
    songs_list = ms.playlist(config.get("playlist"))
    for idx in songs_list:
        idx.download()

    assert songs_list is not None
Exemplo n.º 4
0
def test_get():
    config.init()
    assert config.get("number") == 5
    assert config.get("outdir") == "."
    assert config.get("fasdfjklasd") == ""
Exemplo n.º 5
0
def download_cover(self):
    if self.cover_url and config.get('cover'):
        download_file(self.cover_url, self.cover_fullname, stream=False)
Exemplo n.º 6
0
def download_lyrics(self):
    if self.lyrics_url and config.get('lyrics'):
        download_file(self.lyrics_url, self.lyrics_fullname, stream=False)