bandcamp-dl/bandcamp_dl/bandcamp_dl.py

68 lines
2.1 KiB
Python
Raw Normal View History

2016-03-26 09:03:46 -07:00
#!/usr/bin/env python2
"""bandcamp-dl
Usage:
bandcamp-dl.py <url>
bandcamp-dl.py [--template=<template>] [--base-dir=<dir>]
[--full-album]
(<url> | --artist=<artist> --album=<album>)
2014-06-07 21:14:56 -07:00
[--overwrite]
bandcamp-dl.py (-h | --help)
bandcamp-dl.py (--version)
2013-04-29 23:59:57 -07:00
Options:
-h --help Show this screen.
-v --version Show version.
-a --artist=<artist> The artist's slug (from the URL)
-b --album=<album> The album's slug (from the URL)
-t --template=<template> Output filename template.
[default: %{artist}/%{album}/%{track} - %{title}]
2014-06-07 21:14:56 -07:00
-d --base-dir=<dir> Base location of which all files are downloaded.
-f --full-album Download only if all tracks are availiable.
-o --overwrite Overwrite tracks that already exist. Default is False.
"""
2013-04-29 23:59:57 -07:00
""" Coded by:
2013-04-29 23:59:57 -07:00
Iheanyi Ekechukwu
http://twitter.com/kwuchu
http://github.com/iheanyi
2013-04-29 18:57:50 -07:00
Simon W. Jackson
http://miniarray.com
http://twitter.com/miniarray
http://github.com/miniarray
2013-04-29 18:57:50 -07:00
Iheanyi:
Feel free to use this in any way you wish. I made this just for fun.
Shout out to darkf for writing a helper function for parsing the JavaScript! """
2013-04-29 18:57:50 -07:00
from docopt import docopt
from Bandcamp import Bandcamp
from BandcampDownloader import BandcampDownloader
import os
def main():
arguments = docopt(__doc__, version='bandcamp-dl 1.0')
bandcamp = Bandcamp()
2013-04-29 18:57:50 -07:00
2014-06-07 21:14:56 -07:00
if (arguments['--artist'] and arguments['--album']):
url = Bandcamp.generate_album_url(arguments['--artist'], arguments['--album'])
else:
url = arguments['<url>']
2014-06-07 21:14:56 -07:00
album = bandcamp.parse(url)
basedir = arguments['--base-dir'] or os.getcwd()
2013-04-29 18:57:50 -07:00
2014-06-07 21:14:56 -07:00
if not album:
print "The url {} is not a valid bandcamp page.".format(url)
elif arguments['--full-album'] and not album['full']:
2014-07-07 18:11:38 -07:00
print "Full album not available. Skipping..."
else:
2014-06-07 21:14:56 -07:00
bandcamp_downloader = BandcampDownloader(url, arguments['--template'], basedir, arguments['--overwrite'])
bandcamp_downloader.start(album)
if __name__ == '__main__':
main()