Created
April 21, 2021 17:30
-
-
Save grahams/eb23cf7b35398fb680f6ff59971d4d44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import asyncio | |
from dataclasses import dataclass | |
from pathlib import Path | |
from os.path import expanduser | |
@dataclass | |
class Track: | |
title: str | |
artist: str | |
album: str | |
length: str | |
artworkURL: str | |
uniqueId: str | |
ignore: bool | |
def fetchArtwork(self, coverImagePath): | |
p = Path(f'{expanduser(coverImagePath)}/{self.uniqueId}.jpg') | |
asyncio.run(fetch(p, self.artworkURL)) | |
return p | |
async def fetch(p, artworkURL): | |
if(p.is_file() == False): | |
with p.open(mode='wb') as handle: | |
response = requests.get(artworkURL, stream=True) | |
if not response.ok: | |
return False | |
for block in response.iter_content(1024): | |
if not block: | |
return False | |
handle.write(block) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment