master
Anthony Forsberg 2017-01-12 19:20:52 -05:00
parent 98ccac604a
commit 0176249237
3 changed files with 10 additions and 8 deletions

View File

@ -49,7 +49,7 @@ from .bandcampdownloader import BandcampDownloader
def main(): def main():
arguments = docopt(__doc__, version='bandcamp-dl 0.0.6-01') arguments = docopt(__doc__, version='bandcamp-dl 0.0.6-03')
bandcamp = Bandcamp() bandcamp = Bandcamp()
if arguments['--artist'] and arguments['--album']: if arguments['--artist'] and arguments['--album']:

View File

@ -31,7 +31,8 @@ class BandcampDownloader:
return path.encode('utf-8') return path.encode('utf-8')
def create_directory(self, filename): @staticmethod
def create_directory(filename):
directory = os.path.dirname(filename) directory = os.path.dirname(filename)
if not os.path.exists(directory): if not os.path.exists(directory):
os.makedirs(directory) os.makedirs(directory)
@ -50,7 +51,7 @@ class BandcampDownloader:
print("Accessing track " + str(track_index + 1) + " of " + str(len(album['tracks']))) print("Accessing track " + str(track_index + 1) + " of " + str(len(album['tracks'])))
filename = self.template_to_path(track_meta) filename = self.template_to_path(track_meta).decode()
dirname = self.create_directory(filename) dirname = self.create_directory(filename)
if not track.get('url'): if not track.get('url'):
@ -70,7 +71,7 @@ class BandcampDownloader:
if not self.overwrite and os.path.isfile(filename): if not self.overwrite and os.path.isfile(filename):
file_size = os.path.getsize(filename) - 128 file_size = os.path.getsize(filename) - 128
if int(file_size) != int(file_length): if int(file_size) != int(file_length):
print(filename + " is incomplete, redownloading.") print("{} is incomplete, redownloading.".format(filename))
os.remove(filename) os.remove(filename)
else: else:
print("Skipping track {0} - {1} as it's already downloaded, use --overwrite to overwrite existing files" print("Skipping track {0} - {1} as it's already downloaded, use --overwrite to overwrite existing files"
@ -78,7 +79,7 @@ class BandcampDownloader:
continue continue
with open(filename, "wb") as f: with open(filename, "wb") as f:
print("Downloading: " + filename[:-4]) print("Downloading: {}".format(filename[:-4]))
if file_length is None: if file_length is None:
f.write(r.content) f.write(r.content)
else: else:
@ -97,7 +98,7 @@ class BandcampDownloader:
return False return False
if album['art']: if album['art']:
try: try:
with open(dirname + "/cover.jpg", "wb") as f: with open("{}/cover.jpg".format(dirname), "wb") as f:
r = requests.get(album['art'], stream=True) r = requests.get(album['art'], stream=True)
f.write(r.content) f.write(r.content)
except Exception as e: except Exception as e:
@ -106,7 +107,8 @@ class BandcampDownloader:
return True return True
def write_id3_tags(self, filename, meta): @staticmethod
def write_id3_tags(filename, meta):
print("\nEncoding . . .") print("\nEncoding . . .")
audio = MP3(filename) audio = MP3(filename)

View File

@ -6,7 +6,7 @@ here = path.abspath(path.dirname(__file__))
setup( setup(
name='bandcamp-downloader', name='bandcamp-downloader',
version='0.0.6-02', version='0.0.6-03',
description='bandcamp-dl downloads albums and tracks from Bandcamp for you', description='bandcamp-dl downloads albums and tracks from Bandcamp for you',
long_description=open('README.rst').read(), long_description=open('README.rst').read(),
url='https://github.com/iheanyi/bandcamp-dl', url='https://github.com/iheanyi/bandcamp-dl',