2016-12-30 05:38:23 -08:00
|
|
|
"""bandcamp-dl
|
|
|
|
|
2014-05-12 04:59:34 -07:00
|
|
|
Usage:
|
2020-09-27 08:11:01 -07:00
|
|
|
bandcamp-dl [options] [URL ...]
|
2017-05-23 10:51:19 -07:00
|
|
|
|
|
|
|
Arguments:
|
|
|
|
URL Bandcamp album/track URL
|
2013-04-29 23:59:57 -07:00
|
|
|
|
2014-05-12 04:59:34 -07:00
|
|
|
Options:
|
2017-05-23 10:51:19 -07:00
|
|
|
-h --help Show this screen.
|
|
|
|
-v --version Show version.
|
2017-05-25 08:22:45 -07:00
|
|
|
-d --debug Verbose logging.
|
2017-09-27 11:22:03 -07:00
|
|
|
--artist=<artist> The artist's slug (from the URL, --track or --album is required)
|
|
|
|
--track=<track> The track's slug (from the URL, for use with --artist)
|
|
|
|
--album=<album> The album's slug (from the URL, for use with --artist)
|
2017-05-23 10:51:19 -07:00
|
|
|
--template=<template> Output filename template.
|
|
|
|
[default: %{artist}/%{album}/%{track} - %{title}]
|
|
|
|
--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.
|
2017-05-25 08:22:45 -07:00
|
|
|
-n --no-art Skip grabbing album art.
|
2017-05-23 10:51:19 -07:00
|
|
|
-e --embed-lyrics Embed track lyrics (If available)
|
2017-05-25 08:22:45 -07:00
|
|
|
-g --group Use album/track Label as iTunes grouping.
|
2017-05-23 10:51:19 -07:00
|
|
|
-r --embed-art Embed album art (If available)
|
|
|
|
-y --no-slugify Disable slugification of track, album, and artist names.
|
2021-01-10 12:03:53 -08:00
|
|
|
-c --ok-chars=<chars> Specify allowed chars in slugify.
|
|
|
|
[default: -_~]
|
|
|
|
-s --space-char=<char> Specify the char to use in place of spaces.
|
|
|
|
[default: -]
|
|
|
|
-a --ascii-only Only allow ASCII chars (北京 (capital of china) -> bei-jing-capital-of-china)
|
|
|
|
-k --keep-spaces Retain whitespace in filenames
|
|
|
|
-u --keep-upper Retain uppercase letters in filenames
|
|
|
|
|
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-05-25 08:22:45 -07:00
|
|
|
import logging
|
2020-09-27 08:11:01 -07:00
|
|
|
import importlib
|
2016-12-15 17:28:24 -08:00
|
|
|
from docopt import docopt
|
2020-09-27 08:11:01 -07:00
|
|
|
import bandcamp_dl.bandcamp
|
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
|
|
|
|
2017-05-25 08:22:45 -07:00
|
|
|
if arguments['--debug']:
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
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
|
|
|
|
2017-09-27 11:22:03 -07:00
|
|
|
if os.path.isfile(session_file) and arguments['URL'] is None:
|
2017-01-12 16:25:43 -08:00
|
|
|
with open(session_file, "r") as f:
|
|
|
|
arguments = ast.literal_eval(f.readline())
|
|
|
|
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']:
|
2020-09-27 08:11:01 -07:00
|
|
|
urls = Bandcamp.generate_album_url(arguments['--artist'], arguments['--album'], "album")
|
2017-04-15 06:30:34 -07:00
|
|
|
elif arguments['--artist'] and arguments['--track']:
|
2020-09-27 08:11:01 -07:00
|
|
|
urls = Bandcamp.generate_album_url(arguments['--artist'], arguments['--track'], "track")
|
2017-09-27 11:22:03 -07:00
|
|
|
elif arguments['--artist']:
|
|
|
|
print(__doc__)
|
2017-09-27 14:10:45 -07:00
|
|
|
os.remove(session_file)
|
|
|
|
exit()
|
2014-06-07 21:14:56 -07:00
|
|
|
else:
|
2020-09-27 08:11:01 -07:00
|
|
|
urls = arguments['URL']
|
|
|
|
for url in urls:
|
|
|
|
logging.debug("\n\tURL: {}".format(url))
|
|
|
|
# url is now a list of URLs. So lets make an albumList and append each parsed album to it.
|
2021-01-10 12:03:53 -08:00
|
|
|
albumList = []
|
2020-09-27 08:11:01 -07:00
|
|
|
for url in urls:
|
|
|
|
albumList.append(bandcamp.parse(url, not arguments['--no-art'], arguments['--embed-lyrics'], arguments['--debug']))
|
|
|
|
|
|
|
|
for album in albumList:
|
|
|
|
logging.debug(" Album data:\n\t{}".format(album))
|
|
|
|
|
|
|
|
for album in albumList:
|
|
|
|
if arguments['--full-album'] and not album['full']:
|
|
|
|
print("Full album not available. Skipping ", album['title'], " ...")
|
2021-01-10 12:03:53 -08:00
|
|
|
albumList.remove(album) # Remove not-full albums BUT continue with the rest of the albums.
|
2020-09-27 08:11:01 -07:00
|
|
|
|
|
|
|
if arguments['URL'] or arguments['--artist']:
|
2017-05-25 08:22:45 -07:00
|
|
|
logging.debug("Preparing download process..")
|
2020-09-27 08:11:01 -07:00
|
|
|
for album in albumList:
|
|
|
|
bandcamp_downloader = BandcampDownloader(arguments['--template'], basedir, arguments['--overwrite'],
|
2021-01-10 12:03:53 -08:00
|
|
|
arguments['--embed-lyrics'], arguments['--group'],
|
|
|
|
arguments['--embed-art'], arguments['--no-slugify'],
|
|
|
|
arguments['--ok-chars'], arguments['--space-char'],
|
|
|
|
arguments['--ascii-only'], arguments['--keep-spaces'],
|
|
|
|
arguments['--keep-upper'], arguments['--debug'], album['url'])
|
2020-09-27 08:11:01 -07:00
|
|
|
logging.debug("Initiating download process..")
|
|
|
|
bandcamp_downloader.start(album)
|
|
|
|
# Add a newline to stop prompt mangling
|
|
|
|
print("")
|
2017-05-25 08:22:45 -07:00
|
|
|
else:
|
2020-09-27 08:11:01 -07:00
|
|
|
logging.debug(r" /!\ Something went horribly wrong /!\ ")
|
2015-12-11 16:02:43 -08:00
|
|
|
|
2017-09-27 11:22:03 -07:00
|
|
|
|
2015-12-11 16:02:43 -08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|