2016-12-30 05:38:23 -08:00
|
|
|
"""bandcamp-dl
|
|
|
|
|
2014-05-12 04:59:34 -07:00
|
|
|
Usage:
|
2017-01-12 16:25:43 -08:00
|
|
|
bandcamp-dl [url]
|
|
|
|
bandcamp-dl [--template=<template>] [--base-dir=<dir>]
|
|
|
|
[--full-album]
|
2017-04-15 06:30:34 -07:00
|
|
|
(<url> | --artist=<artist> --album=<album> | --artist=<artist> --track=<track>)
|
2017-01-12 16:25:43 -08:00
|
|
|
[--overwrite]
|
|
|
|
[--no-art]
|
2017-02-17 19:09:17 -08:00
|
|
|
[--embed-lyrics]
|
|
|
|
[--group]
|
2017-04-15 06:30:34 -07:00
|
|
|
[--embed-art]
|
2017-05-08 18:31:56 -07:00
|
|
|
[--no-slugify]
|
2017-01-12 16:25:43 -08:00
|
|
|
bandcamp-dl (-h | --help)
|
|
|
|
bandcamp-dl (--version)
|
2013-04-29 23:59:57 -07:00
|
|
|
|
2014-05-12 04:59:34 -07:00
|
|
|
Options:
|
2017-01-12 16:25:43 -08:00
|
|
|
-h --help Show this screen.
|
|
|
|
-v --version Show version.
|
|
|
|
-a --artist=<artist> The artist's slug (from the URL)
|
2017-04-15 06:30:34 -07:00
|
|
|
-s --track=<track> The track's slug (from the URL)
|
2017-01-12 16:25:43 -08:00
|
|
|
-b --album=<album> The album's slug (from the URL)
|
|
|
|
-t --template=<template> Output filename template.
|
|
|
|
[default: %{artist}/%{album}/%{track} - %{title}]
|
|
|
|
-d --base-dir=<dir> Base location of which all files are downloaded.
|
|
|
|
-f --full-album Download only if all tracks are available.
|
|
|
|
-o --overwrite Overwrite tracks that already exist. Default is False.
|
|
|
|
-n --no-art Skip grabbing album art
|
2017-02-17 19:09:17 -08:00
|
|
|
-e --embed-lyrics Embed track lyrics (If available)
|
|
|
|
-g --group Use album/track Label as iTunes grouping
|
2017-04-15 06:30:34 -07:00
|
|
|
-r --embed-art Embed album art (If available)
|
2017-05-08 18:31:56 -07:00
|
|
|
-n --no-slugify Disable slugification of track, album, and artist names.
|
2017-01-12 16:25:43 -08:00
|
|
|
"""
|
|
|
|
"""
|
2016-12-15 17:28:24 -08:00
|
|
|
Coded by:
|
2013-04-29 23:59:57 -07:00
|
|
|
|
2014-05-12 04:59:34 -07:00
|
|
|
Iheanyi Ekechukwu
|
|
|
|
http://twitter.com/kwuchu
|
|
|
|
http://github.com/iheanyi
|
2013-04-29 18:57:50 -07:00
|
|
|
|
2014-05-12 04:59:34 -07:00
|
|
|
Simon W. Jackson
|
|
|
|
http://miniarray.com
|
|
|
|
http://twitter.com/miniarray
|
|
|
|
http://github.com/miniarray
|
2013-04-29 18:57:50 -07:00
|
|
|
|
2016-12-15 17:28:24 -08:00
|
|
|
Anthony Forsberg:
|
|
|
|
http://evolution0.github.io
|
|
|
|
http://github.com/evolution0
|
|
|
|
|
2014-05-12 04:59:34 -07:00
|
|
|
Iheanyi:
|
|
|
|
Feel free to use this in any way you wish. I made this just for fun.
|
2017-01-12 16:25:43 -08:00
|
|
|
Shout out to darkf for writing the previous helper function for parsing the JavaScript!
|
2016-12-15 17:28:24 -08:00
|
|
|
"""
|
2013-04-29 18:57:50 -07:00
|
|
|
|
2014-05-21 06:28:55 -07:00
|
|
|
import os
|
2017-01-12 16:25:43 -08:00
|
|
|
import ast
|
2017-02-17 19:09:17 -08:00
|
|
|
|
2016-12-15 17:28:24 -08:00
|
|
|
from docopt import docopt
|
2017-02-17 19:09:17 -08:00
|
|
|
|
|
|
|
from bandcamp_dl.bandcamp import Bandcamp
|
|
|
|
from bandcamp_dl.bandcampdownloader import BandcampDownloader
|
2017-05-20 13:02:17 -07:00
|
|
|
from bandcamp_dl.__init__ import __version__
|
2016-12-15 17:28:24 -08:00
|
|
|
|
2014-05-21 06:28:55 -07:00
|
|
|
|
2015-12-11 16:02:43 -08:00
|
|
|
def main():
|
2017-05-20 13:02:17 -07:00
|
|
|
arguments = docopt(__doc__, version='bandcamp-dl {}'.format(__version__))
|
2017-02-27 05:02:24 -08:00
|
|
|
|
2014-05-12 04:59:34 -07:00
|
|
|
bandcamp = Bandcamp()
|
2013-04-29 18:57:50 -07:00
|
|
|
|
2017-01-12 16:25:43 -08:00
|
|
|
basedir = arguments['--base-dir'] or os.getcwd()
|
2017-05-20 13:02:17 -07:00
|
|
|
session_file = "{}/{}.not.finished".format(basedir, __version__)
|
2017-01-12 16:25:43 -08:00
|
|
|
|
|
|
|
if os.path.isfile(session_file):
|
|
|
|
with open(session_file, "r") as f:
|
|
|
|
arguments = ast.literal_eval(f.readline())
|
2017-04-15 06:30:34 -07:00
|
|
|
elif arguments['<url>'] is None and arguments['--artist'] is None:
|
2017-01-12 16:25:43 -08:00
|
|
|
print(__doc__)
|
|
|
|
else:
|
|
|
|
with open(session_file, "w") as f:
|
|
|
|
f.write("".join(str(arguments).split('\n')))
|
|
|
|
|
2016-12-15 17:28:24 -08:00
|
|
|
if arguments['--artist'] and arguments['--album']:
|
2017-04-15 06:30:34 -07:00
|
|
|
url = Bandcamp.generate_album_url(arguments['--artist'], arguments['--album'], "album")
|
|
|
|
elif arguments['--artist'] and arguments['--track']:
|
|
|
|
url = Bandcamp.generate_album_url(arguments['--artist'], arguments['--track'], "track")
|
2014-06-07 21:14:56 -07:00
|
|
|
else:
|
|
|
|
url = arguments['<url>']
|
2014-05-21 06:28:55 -07:00
|
|
|
|
2016-12-30 05:38:23 -08:00
|
|
|
if arguments['--no-art']:
|
|
|
|
album = bandcamp.parse(url, False)
|
|
|
|
else:
|
|
|
|
album = bandcamp.parse(url)
|
2013-04-29 18:57:50 -07:00
|
|
|
|
2014-06-07 21:14:56 -07:00
|
|
|
if not album:
|
2016-12-15 17:28:24 -08:00
|
|
|
print("The url {} is not a valid bandcamp page.".format(url))
|
2014-06-07 21:14:56 -07:00
|
|
|
elif arguments['--full-album'] and not album['full']:
|
2016-12-15 17:28:24 -08:00
|
|
|
print("Full album not available. Skipping...")
|
2014-05-21 06:28:55 -07:00
|
|
|
else:
|
2017-02-17 19:09:17 -08:00
|
|
|
bandcamp_downloader = BandcampDownloader(url, arguments['--template'], basedir, arguments['--overwrite'],
|
2017-04-15 06:30:34 -07:00
|
|
|
arguments['--embed-lyrics'], arguments['--group'],
|
2017-05-08 18:31:56 -07:00
|
|
|
arguments['--embed-art'], arguments['--no-slugify'])
|
2014-06-07 21:14:56 -07:00
|
|
|
bandcamp_downloader.start(album)
|
2015-12-11 16:02:43 -08:00
|
|
|
|
2017-04-15 06:30:34 -07:00
|
|
|
|
2015-12-11 16:02:43 -08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|