Big update, see description.

Refactored to match Python 3 branch.

Switched to a README.rst (for PyPI support) spell checked, updated
information, removed IRC link in favor of Discord (No one was ever in
the IRC channel)

Updated deps, requirements, and setup.py.

Now using the latest versions of the required dependencies.
Note: May cause lextab.py/yacctab.py warnings, they are harmless. If the
warning are annoying delete those two files in site-packages/Slimit
(That are generated anyway)

Updated code, using latest supported syntax for everything possible
while still supporting Python 2.7.x.

Currently code is 1:1 with the Python 3 branch.
master
Anthony Forsberg 2016-12-15 20:28:24 -05:00
parent 5ae6aa5740
commit a8ebb47e3e
12 changed files with 445 additions and 308 deletions

2
.gitignore vendored
View File

@ -36,3 +36,5 @@ nosetests.xml
.mr.developer.cfg
.project
.pydevproject
*.iml
*.xml

View File

@ -3,7 +3,8 @@ include *.rst
exclude *.mp3
exclude .gitignore
exclude yacctab.py
exclude lextab.py
global-exclude *.pyc
global-exclude *.DS_STORE

133
README.md
View File

@ -1,133 +0,0 @@
bandcamp-dl - download audio from BandCamp.com
# Synopsis
bandcamp-dl URL
# Installation
## Through Pip
1. Run `pip install bandcamp-downloader`
2. Use the command `bandcamp-dl` in order to download songs.
## From Source
1. Clone the project or [download the zip](https://github.com/iheanyi/bandcamp-dl/archive/master.zip)
2. Make sure you have [pip](https://pip.pypa.io/en/latest/installing.html) installed
3. `cd` to the directory with the `requirements.txt` file in it
4. `pip install -r requirements.txt`
# Description
bandcamp.dl is a small command-line app to download audio from BandCamp.com.
It requires the Python interpreter, version 2.7.x and is not platform specific.
It is released to the public domain, which means you can modify it, redistribute
it or use it how ever you like.
# Details
Usage:
bandcamp-dl.py <url>
bandcamp-dl.py [--template=<template>] [--base-dir=<dir>]
[--full-album]
(<url> | --artist=<artist> --album=<album>)
[--overwrite]
bandcamp-dl.py (-h | --help)
bandcamp-dl.py (--version)
# Options
Options:
-h --help Show this screen.
-v --version Show version.
--artist=<artist> The artist's slug (from the URL)
--album=<album> The album's slug (from the URL)
--template=<template> Output filename template.
[default: %{artist}/%{album}/%{track} - %{title}]
--base-dir=<dir> Base location of which all files are downloaded
# Filename Template
The `--template` option allows users to indicate a template for the output file
names and directories. Templates can be built using special tokens with the
format of `%{artist}`. Here is a list of allowed tokens:
* `artist`: The artist name.
* `album`: The album name.
* `track`: The track number.
* `title`: The track title.
The default template is: `%{artist}/%{album}/%{track} - %{title}`.
# Bugs
Bus should be reported at [https://github.com/iheanyi/bandcamp-dl/issues]().
Please include the full output of the command when run with `--verbose`.
The output (including the first lines) contain important debugging
information. Issues without the full output are often not reproducible and
therefore do not get solved in short order, if ever.
For discussions, join us in the irc channel [#bandcamp-dl](irc://chat.freenode.net/bandcamp) on freenode.
When you submit a request, please re-read it once to avoid a couple of mistakes (you can and should use this as a checklist):
### Is the description of the issue itself sufficient?
We often get issue reports that we cannot really decipher. While in most cases we eventually get the required information after asking back multiple times, this poses an unnecessary drain on our resources. Many contributors, including myself, are also not native speakers, so we may misread some parts.
So please elaborate on what feature you are requesting, or what bug you want to be fixed. Make sure that it's obvious
- What the problem is
- How it could be fixed
- How your proposed solution would look like
If your report is shorter than two lines, it is almost certainly missing some of these, which makes it hard for us to respond to it. We're often too polite to close the issue outright, but the missing info makes misinterpretation likely. As a commiter myself, I often get frustrated by these issues, since the only possible way for me to move forward on them is to ask for clarification over and over.
For bug reports, this means that your report should contain the *complete* output of bandcamp-dl when called with the `-v` flag. The error message you get for (most) bugs even says so, but you would not believe how many of our bug reports do not contain this information.
Site support requests **must contain an example URL**. An example URL is a URL you might want to download, like `lifeformed.bandcamp.com/album/fastfall`.
### Are you using the latest version?
This should report that you're up-to-date. About 20% of the reports we receive are already fixed, but people are using outdated versions. This goes for feature requests as well.
### Is the issue already documented?
Make sure that someone has not already opened the issue you're trying to open. Search at the top of the window or at [https://github.com/iheanyi/bandcamp-dl/search?type=Issues](Issues) . If there is an issue, feel free to write something along the lines of "This affects me as well, with version 2015.01.01. Here is some more information on the issue: ...". While some issues may be old, a new post into them often spurs rapid activity.
### Why are existing options not enough?
Before requesting a new feature, please have a quick peek at [the list of supported options](https://github.com/simonwjackson/bandcamp-dl/blob/master/README.md#synopsis). Many feature requests are for features that actually exist already! Please, absolutely do show off your work in the issue report and detail how the existing similar options do *not* solve your problem.
### Is there enough context in your bug report?
People want to solve problems, and often think they do us a favor by breaking down their larger problems (e.g. wanting to skip already downloaded files) to a specific request (e.g. requesting us to look whether the file exists before downloading the info page). However, what often happens is that they break down the problem into two steps: One simple, and one impossible (or extremely complicated one).
We are then presented with a very complicated request when the original problem could be solved far easier, e.g. by recording the downloaded video IDs in a separate file. To avoid this, you must include the greater context where it is non-obvious. In particular, every feature request that does not consist of adding support for a new site should contain a use case scenario that explains in what situation the missing feature would be useful.
### Does the issue involve one problem, and one problem only?
Some of our users seem to think there is a limit of issues they can or should open. There is no limit of issues they can or should open. While it may seem appealing to be able to dump all your issues into one ticket, that means that someone who solves one of your issues cannot mark the issue as closed. Typically, reporting a bunch of issues leads to the ticket lingering since nobody wants to attack that behemoth, until someone mercifully splits the issue into multiple ones.
In particular, every site support request issue should only pertain to services at one site (generally under a common domain, but always using the same backend technology). Do not request support for vimeo user videos, Whitehouse podcasts, and Google Plus pages in the same issue. Also, make sure that you don't post bug reports alongside feature requests. As a rule of thumb, a feature request does not include outputs of bandcamp-dl that are not immediately related to the feature at hand. Do not post reports of a network error alongside the request for a new video service.
### Is anyone going to need the feature?
Only post features that you (or an incapacitated friend you can personally talk to) require. Do not post features because they seem like a good idea. If they are really useful, they will be requested by someone who requires them.
### Is your question about bandcamp-dl?
It may sound strange, but some bug reports we receive are completely unrelated to bandcamp-dl and relate to a different or even the reporter's own application. Please make sure that you are actually using bandcamp-dl. If you are using a UI for bandcamp-dl, report the bug to the maintainer of the actual application providing the UI. On the other hand, if your UI for bandcamp-dl fails in some way you believe is related to bandcamp-dl, by all means, go ahead and report the bug.
# Dependencies
* [BeautifulSoup](https://pypi.python.org/pypi/beautifulsoup4) - HTML Parsing
* [Mutagen](https://pypi.python.org/pypi/mutagen) - ID3 Encoding
* [Requests](https://pypi.python.org/pypi/requests) - for retriving the HTML
* [Slimit](https://pypi.python.org/pypi/slimit) - Javascript parsing
* [Slugify](https://pypi.python.org/pypi/slugify) - A generic slugifier
# Copyright
bandcamp-dl is released into the public domain by the copyright holders
This README file was inspired by the [youtube-dl](https://github.com/rg3/youtube-dl/blob/master/README.md) docs and is likewise released into the public domain.

226
README.rst Normal file
View File

@ -0,0 +1,226 @@
bandcamp-dl - download audio from BandCamp.com
Synopsis
========
bandcamp-dl URL
Installation
============
From PyPI
---------
Coming Soon
From Source
-----------
1. Clone the project or `download the zip <https://github.com/iheanyi/bandcamp-dl/archive/bandcamp-dl-py2.zip>`_
2. Make sure you have `pip <https://pip.pypa.io/en/latest/installing.html>`_ installed
3. ``cd`` to the directory with the ``requirements.txt`` file in it
4. ``pip install -r requirements.txt``
Description
===========
bandcamp-dl is a small command-line app to download audio from
BandCamp.com. It requires the Python interpreter, version 2.7.x and is
not platform specific. It is released to the public domain, which means
you can modify it, redistribute it or use it how ever you like.
Details
=======
::
Usage:
bandcamp-dl.py <url>
bandcamp-dl.py [--template=<template>] [--base-dir=<dir>]
[--full-album]
(<url> | --artist=<artist> --album=<album>)
[--overwrite]
bandcamp-dl.py (-h | --help)
bandcamp-dl.py (--version)
Options
=======
::
Options:
-h --help Show this screen.
-v --version Show version.
--artist=<artist> The artist's slug (from the URL)
--album=<album> The album's slug (from the URL)
--template=<template> Output filename template.
[default: %{artist}/%{album}/%{track} - %{title}]
--base-dir=<dir> Base location of which all files are downloaded
Filename Template
=================
The ``--template`` option allows users to indicate a template for the
output file names and directories. Templates can be built using special
tokens with the format of ``%{artist}``. Here is a list of allowed
tokens:
- ``artist``: The artist name.
- ``album``: The album name.
- ``track``: The track number.
- ``title``: The track title.
The default template is: ``%{artist}/%{album}/%{track} - %{title}``.
Bugs
====
Bugs should be reported `here <https://github.com/iheanyi/bandcamp-dl/issues>`_. Please include
the full output of the command when run with ``--verbose``. The output
(including the first lines) contain important debugging information.
Issues without the full output are often not reproducible and therefore
do not get solved in short order, if ever.
For discussions, join us in `Discord <https://discord.gg/nwdT4MP>`_.
When you submit a request, please re-read it once to avoid a couple of
mistakes (you can and should use this as a checklist):
Is the description of the issue itself sufficient?
==================================================
We often get issue reports that we cannot really decipher. While in most
cases we eventually get the required information after asking back
multiple times, this poses an unnecessary drain on our resources. Many
contributors, including myself, are also not native speakers, so we may
misread some parts.
So please elaborate on what feature you are requesting, or what bug you
want to be fixed. Make sure that it's obvious
- What the problem is
- How it could be fixed
- How your proposed solution would look like
If your report is shorter than two lines, it is almost certainly missing
some of these, which makes it hard for us to respond to it. We're often
too polite to close the issue outright, but the missing info makes
misinterpretation likely. As a commiter myself, I often get frustrated
by these issues, since the only possible way for me to move forward on
them is to ask for clarification over and over.
For bug reports, this means that your report should contain the
*complete* output of bandcamp-dl when called with the ``-v`` flag. The
error message you get for (most) bugs even says so, but you would not
believe how many of our bug reports do not contain this information.
Site support requests **must contain an example URL**. An example URL is
a URL you might want to download, like
``lifeformed.bandcamp.com/album/fastfall``.
Are you using the latest version?
=================================
This should report that you're up-to-date. About 20% of the reports we
receive are already fixed, but people are using outdated versions. This
goes for feature requests as well.
Is the issue already documented?
================================
Make sure that someone has not already opened the issue you're trying to
open. Search at the top of the window or at
`Issues <https://github.com/iheanyi/bandcamp-dl/search?type=Issues>`_.
If there is an issue, feel free to write something along the lines of
"This affects me as well, with version 2015.01.01. Here is some more
information on the issue: ...". While some issues may be old, a new post
into them often spurs rapid activity.
Why are existing options not enough?
====================================
Before requesting a new feature, please have a quick peek at `the list
of supported
options <https://github.com/iheanyi/bandcamp-dl/blob/master/README.rst#synopsis>`_.
Many feature requests are for features that actually exist already!
Please, absolutely do show off your work in the issue report and detail
how the existing similar options do *not* solve your problem.
Is there enough context in your bug report?
===========================================
People want to solve problems, and often think they do us a favor by
breaking down their larger problems (e.g. wanting to skip already
downloaded files) to a specific request (e.g. requesting us to look
whether the file exists before downloading the info page). However, what
often happens is that they break down the problem into two steps: One
simple, and one impossible (or extremely complicated one).
We are then presented with a very complicated request when the original
problem could be solved far easier, e.g. by recording the downloaded
video IDs in a separate file. To avoid this, you must include the
greater context where it is non-obvious. In particular, every feature
request that does not consist of adding support for a new site should
contain a use case scenario that explains in what situation the missing
feature would be useful.
Does the issue involve one problem, and one problem only?
=========================================================
Some of our users seem to think there is a limit of issues they can or
should open. There is no limit of issues they can or should open. While
it may seem appealing to be able to dump all your issues into one
ticket, that means that someone who solves one of your issues cannot
mark the issue as closed. Typically, reporting a bunch of issues leads
to the ticket lingering since nobody wants to attack that behemoth,
until someone mercifully splits the issue into multiple ones.
In particular, every site support request issue should only pertain to
services at one site (generally under a common domain, but always using
the same backend technology). Do not request support for vimeo user
videos, Whitehouse podcasts, and Google Plus pages in the same issue.
Also, make sure that you don't post bug reports alongside feature
requests. As a rule of thumb, a feature request does not include outputs
of bandcamp-dl that are not immediately related to the feature at hand.
Do not post reports of a network error alongside the request for a new
video service.
Is anyone going to need the feature?
====================================
Only post features that you (or an incapacitated friend you can
personally talk to) require. Do not post features because they seem like
a good idea. If they are really useful, they will be requested by
someone who requires them.
Is your question about bandcamp-dl?
===================================
It may sound strange, but some bug reports we receive are completely
unrelated to bandcamp-dl and relate to a different or even the
reporter's own application. Please make sure that you are actually using
bandcamp-dl. If you are using a UI for bandcamp-dl, report the bug to
the maintainer of the actual application providing the UI. On the other
hand, if your UI for bandcamp-dl fails in some way you believe is
related to bandcamp-dl, by all means, go ahead and report the bug.
Dependencies
============
- `BeautifulSoup <https://pypi.python.org/pypi/beautifulsoup4>`_ -
HTML Parsing
- `Mutagen <https://pypi.python.org/pypi/mutagen>`_ - ID3 Encoding
- `Requests <https://pypi.python.org/pypi/requests>`_ - for retriving
the HTML
- `Slimit <https://pypi.python.org/pypi/slimit>`_ - Javascript parsing
- `Unicode-Slugify <https://pypi.python.org/pypi/unicode-slugify>`_ -
A slug generator that turns strings into unicode slugs.
Copyright
=========
bandcamp-dl is released into the public domain by the copyright holders
This README file was inspired by the
`youtube-dl <https://github.com/rg3/youtube-dl/blob/master/README.md>`_
docs and is likewise released into the public domain.

View File

@ -1,107 +0,0 @@
import wgetter
from mutagen.mp3 import MP3
from mutagen.id3 import TIT2
from mutagen.easyid3 import EasyID3
import os
from slugify import slugify
class BandcampDownloader():
def __init__(self, urls=None, template=None, directory=None, overwrite=False):
if type(urls) is str:
self.urls = [urls]
if directory:
directory = os.path.expanduser(directory)
if os.path.isdir(directory):
self.directory = directory
self.urls = urls
self.template = template
self.overwrite = overwrite
def start(self, album):
print "Starting download process."
self.download_album(album)
def template_to_path(self, track):
path = self.template
path = path.replace("%{artist}", slugify(unicode(track['artist'])))
path = path.replace("%{album}", slugify(unicode(track['album'])))
path = path.replace("%{track}", str(track['track']).zfill(2))
path = path.replace("%{title}", slugify(track['title']))
path = u"{0}/{1}.{2}".format(self.directory, path, "mp3")
return path
def create_directory(self, filename):
directory = os.path.dirname(filename)
if not os.path.exists(directory):
os.makedirs(directory)
return directory
def download_album(self, album):
for track_index,track in enumerate(album['tracks']):
track_meta = {
"artist": album['artist'],
"album": album['title'],
"title": track['title'],
"track": track['track'],
"date": album['date']
}
print("Accessing track " + str(track_index+1) + " of " + str(len(album['tracks'])))
filename = self.template_to_path(track_meta).encode('utf-8')
dirname = self.create_directory(filename)
if not self.overwrite and os.path.isfile(filename):
re_encoded_track_title = track['title'].encode('utf-8')
print "Skipping track {} - {} as it's already downloaded, use --overwrite to overwrite existing files".format(track['track'], re_encoded_track_title)
continue
if not track.get('url'):
re_encoded_track_title = track['title'].encode('utf-8')
print "Skipping track {} - {} as it is not available".format(track['track'], re_encoded_track_title)
continue
try:
track_url = track['url']
# Check and see if HTTP is in the track_url
if 'http' not in track_url:
track_url = 'http:%s' % track_url
tmp_file = wgetter.download(track_url, outdir=dirname)
os.rename(tmp_file, filename)
self.write_id3_tags(filename, track_meta)
except Exception as e:
print e
print "Downloading failed.."
return False
try:
tmp_art_file = wgetter.download(album['art'], outdir=dirname)
os.rename(tmp_art_file, dirname + "/cover.jpg")
except Exception as e:
print e
print "Couldn't download album art."
return True
def write_id3_tags(self, filename, meta):
print "Encoding . . . "
audio = MP3(filename)
audio["TIT2"] = TIT2(encoding=3, text=["title"])
audio.save(filename=None,v1=2)
audio = EasyID3(filename)
audio["tracknumber"] = meta['track']
audio["title"] = meta['title']
audio["artist"] = meta['artist']
audio["album"] = meta['album']
audio["date"] = meta['date']
audio.save()
print "Done encoding . . . "

View File

@ -0,0 +1,124 @@
import os
import sys
import requests
from mutagen.mp3 import MP3
from mutagen.id3._id3v1 import TIT2
from mutagen.easyid3 import EasyID3
from slugify import slugify
class BandcampDownloader:
def __init__(self, urls=None, template=None, directory=None, overwrite=False):
if type(urls) is str:
self.urls = [urls]
self.urls = urls
self.template = template
self.directory = directory
self.overwrite = overwrite
def start(self, album):
print("Starting download process.")
self.download_album(album)
def template_to_path(self, track):
path = self.template
path = path.replace("%{artist}", slugify(track['artist']))
path = path.replace("%{album}", slugify(track['album']))
path = path.replace("%{track}", str(track['track']).zfill(2))
path = path.replace("%{title}", slugify(track['title']))
path = "{0}/{1}.{2}".format(self.directory, path, "mp3")
return path
def create_directory(self, filename):
directory = os.path.dirname(filename)
if not os.path.exists(directory):
os.makedirs(directory)
return directory
def download_album(self, album):
for track_index, track in enumerate(album['tracks']):
track_meta = {
"artist": album['artist'],
"album": album['title'],
"title": track['title'],
"track": track['track'],
"date": album['date']
}
print("Accessing track " + str(track_index+1) + " of " + str(len(album['tracks'])))
filename = self.template_to_path(track_meta)
dirname = self.create_directory(filename)
if not track.get('url'):
print("Skipping track {0} - {1} as it is not available"
.format(track['track'], track['title']))
continue
try:
track_url = track['url']
# Check and see if HTTP is in the track_url
if 'http' not in track_url:
track_url = 'http:{}'.format(track_url)
r = requests.get(track_url, stream=True)
file_length = r.headers.get('content-length')
if not self.overwrite and os.path.isfile(filename):
file_size = os.path.getsize(filename) - 128
if int(file_size) != int(file_length):
print(filename + " is incomplete, redownloading.")
os.remove(filename)
else:
print("Skipping track {0} - {1} as it's already downloaded, use --overwrite to overwrite existing files"
.format(track['track'], track['title']))
continue
with open(filename, "wb") as f:
print("Downloading: " + filename[:-4])
if file_length is None:
f.write(r.content)
else:
dl = 0
total_length = int(file_length)
for data in r.iter_content(chunk_size=int(total_length/100)):
dl += len(data)
f.write(data)
done = int(50 * dl / total_length)
sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50 - done)))
sys.stdout.flush()
self.write_id3_tags(filename, track_meta)
except Exception as e:
print(e)
print("Downloading failed..")
return False
try:
with open(dirname + "/cover.jpg", "wb") as f:
r = requests.get(album['art'], stream=True)
f.write(r.content)
except Exception as e:
print(e)
print("Couldn't download album art.")
return True
def write_id3_tags(self, filename, meta):
print("\nEncoding . . .")
audio = MP3(filename)
audio["TIT2"] = TIT2(encoding=3, text=["title"])
audio.save(filename=None, v1=2)
audio = EasyID3(filename)
audio["tracknumber"] = meta['track']
audio["title"] = meta['title']
audio["artist"] = meta['artist']
audio["album"] = meta['album']
audio["date"] = meta['date']
audio.save()
print("Done encoding . . .")

View File

@ -1,11 +1,9 @@
from bs4 import BeautifulSoup
import requests
import jsobj
class Bandcamp:
def parse(self, url):
try:
r = requests.get(url)
@ -15,7 +13,11 @@ class Bandcamp:
if r.status_code is not 200:
return None
self.soup = BeautifulSoup(r.text, "lxml")
try:
self.soup = BeautifulSoup(r.text, "lxml")
except:
self.soup = BeautifulSoup(r.text, "html.parser")
album = {
"tracks": [],
"title": "",
@ -47,9 +49,14 @@ class Bandcamp:
return True
def is_basestring(self, obj):
if isinstance(obj, str) or isinstance(obj, bytes) or isinstance(obj, bytearray):
return True
return False
def get_track_meta_data(self, track):
new_track = {}
if not (isinstance(track['file'], unicode) or isinstance(track['file'], str)):
if not self.is_basestring(track['file']):
if 'mp3-128' in track['file']:
new_track['url'] = track['file']['mp3-128']
else:
@ -71,14 +78,20 @@ class Bandcamp:
stringBlock = block[1]
stringBlock = stringBlock.split("};")[0] + "};"
stringBlock = jsobj.read_js_object("var TralbumData = %s" % stringBlock)
stringBlock = jsobj.read_js_object("var TralbumData = {}".format(stringBlock))
if 'album_title' not in embedData['EmbedData']:
album['title'] = "Unknown Album"
else:
album['title'] = embedData['EmbedData']['album_title']
album['title'] = "Unknown Album" if not \
'album_title' in embedData['EmbedData'] else embedData['EmbedData']['album_title']
album['artist'] = stringBlock['TralbumData']['artist']
album['tracks'] = stringBlock['TralbumData']['trackinfo']
album['date'] = "" if stringBlock['TralbumData']['album_release_date'] \
== "null" else stringBlock['TralbumData']['album_release_date'].split()[2]
if stringBlock['TralbumData']['album_release_date'] == "null":
album['date'] = ""
else:
album['date'] = stringBlock['TralbumData']['album_release_date'].split()[2]
return album
@ -93,12 +106,11 @@ class Bandcamp:
except:
pass
def get_embed_string_block(self, request):
embedBlock = request.text.split("var EmbedData = ")
embedStringBlock = embedBlock[1]
embedStringBlock = embedStringBlock.split("};")[0] + "};"
embedStringBlock = jsobj.read_js_object("var EmbedData = %s" % embedStringBlock)
embedStringBlock = jsobj.read_js_object("var EmbedData = {}".format(embedStringBlock))
return embedStringBlock

View File

@ -1,6 +1,5 @@
#!/usr/bin/env python2
"""bandcamp-dl
"""
bandcamp-dl
Usage:
bandcamp-dl.py <url>
bandcamp-dl.py [--template=<template>] [--base-dir=<dir>]
@ -20,9 +19,8 @@ Options:
-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.
"""
""" Coded by:
Coded by:
Iheanyi Ekechukwu
http://twitter.com/kwuchu
@ -33,21 +31,26 @@ Simon W. Jackson
http://twitter.com/miniarray
http://github.com/miniarray
Anthony Forsberg:
http://evolution0.github.io
http://github.com/evolution0
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! """
Shout out to darkf for writing a helper function for parsing the JavaScript!
"""
from docopt import docopt
from Bandcamp import Bandcamp
from BandcampDownloader import BandcampDownloader
import os
from docopt import docopt
from Bandcamp_Parse import Bandcamp
from Bandcamp_Download import BandcampDownloader
def main():
arguments = docopt(__doc__, version='bandcamp-dl 1.0')
arguments = docopt(__doc__, version='bandcamp-dl 0.0.5')
bandcamp = Bandcamp()
if (arguments['--artist'] and arguments['--album']):
if arguments['--artist'] and arguments['--album']:
url = Bandcamp.generate_album_url(arguments['--artist'], arguments['--album'])
else:
url = arguments['<url>']
@ -56,9 +59,9 @@ def main():
basedir = arguments['--base-dir'] or os.getcwd()
if not album:
print "The url {} is not a valid bandcamp page.".format(url)
print("The url {} is not a valid bandcamp page.".format(url))
elif arguments['--full-album'] and not album['full']:
print "Full album not available. Skipping..."
print("Full album not available. Skipping...")
else:
bandcamp_downloader = BandcampDownloader(url, arguments['--template'], basedir, arguments['--overwrite'])
bandcamp_downloader.start(album)

View File

@ -1,9 +1,7 @@
beautifulsoup4==4.4.1
beautifulsoup4==4.5.1
docopt==0.6.2
lxml==3.5.0
mutagen==1.31
ply==3.4
requests==2.8.1
mutagen==1.35.1
ply==3.9
requests==2.12.4
slimit==0.8.1
slugify==0.0.1
wgetter==0.6
unicode-slugify==0.1.3

View File

@ -1,4 +1,5 @@
""" Simple JavaScript/ECMAScript object literal reader
"""
Simple JavaScript/ECMAScript object literal reader
Only supports object literals wrapped in `var x = ...;` statements, so you
might want to do read_js_object('var x = %s;' % literal) if it's in another format.
@ -12,14 +13,14 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
"""
@ -28,6 +29,8 @@ import slimit.ast as ast
def read_js_object(code):
parser = Parser()
def visit(node):
if isinstance(node, ast.Program):
d = {}
@ -40,7 +43,7 @@ def read_js_object(code):
elif isinstance(node, ast.VarStatement):
return visit(node.children()[0])
elif isinstance(node, ast.VarDecl):
return (visit(node.identifier), visit(node.initializer))
return visit(node.identifier), visit(node.initializer)
elif isinstance(node, ast.Object):
d = {}
for property in node:
@ -58,19 +61,21 @@ def read_js_object(code):
else:
raise ValueError("Cannot + on anything other than two literals")
else:
raise ValueError("Cannot do operator '%s'" % node.op)
raise ValueError("Cannot do operator '{}'".format(node.op))
elif isinstance(node, ast.String):
return node.value.strip('"').strip("'")
elif isinstance(node, ast.Array):
return [visit(x) for x in node]
elif isinstance(node, ast.Number) or isinstance(node, ast.Identifier) or isinstance(node, ast.Boolean) or isinstance(node, ast.Null):
elif isinstance(node, ast.Number) or isinstance(node, ast.Identifier)\
or isinstance(node, ast.Boolean) or isinstance(node, ast.Null):
return node.value
else:
raise Exception("Unhandled node: %r" % node)
return visit(Parser().parse(code))
raise Exception("Unhandled node: {}".format(node))
return visit(parser.parse(code))
if __name__ == "__main__":
# test
print read_js_object("""var foo = {x: 10, y: "hi " + "there!"};
var bar = {derp: ["herp", "it", "up", "forever"]};""")
print(read_js_object("""var foo = {x: 10, y: "hi " + "there!"};
var bar = {derp: ["herp", "it", "up", "forever"]};"""))

View File

@ -1,9 +1,7 @@
beautifulsoup4==4.4.1
beautifulsoup4==4.5.1
docopt==0.6.2
lxml==3.5.0
mutagen==1.31
ply==3.4
requests==2.8.1
mutagen==1.35.1
ply==3.9
requests==2.12.4
slimit==0.8.1
slugify==0.0.1
wgetter==0.6
unicode-slugify==0.1.3

View File

@ -1,30 +1,38 @@
#!/usr/bin/python
from setuptools import setup, find_packages
from codecs import open
from os import path
version = '0.0.4'
here = path.abspath(path.dirname(__file__))
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
long_description = f.read()
setup(
name='bandcamp-downloader',
version=version,
version='0.0.5',
description='bandcamp-dl downloads albums and tracks from Bandcamp for you',
long_description=open('README.md').read(),
long_description=long_description,
url='https://github.com/iheanyi/bandcamp-dl',
author='Iheanyi Ekechukwu',
author_email='iekechukwu@gmail.com',
license='Unlicense',
license='Public Domain',
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: End Users/Desktop',
'Topic :: Multimedia :: Sound/Audio',
'License :: Public Domain',
'Programming Language :: Python :: 2.7',
],
keywords=['bandcamp', 'downloader', 'music', 'cli', 'albums', 'dl'],
url='http://github.com/iheanyi/bandcamp-dl',
packages=find_packages(),
package_data={},
install_requires=[
'wgetter>=0.6',
'slimit>=0.8.1',
'ply==3.4',
'mutagen>=1.31',
'lxml>=3.5.0',
'docopt>=0.6.2',
'beautifulsoup4>=4.4.1',
'slugify==0.0.1',
'beautifulsoup4==4.5.1',
'docopt==0.6.2',
'mutagen==1.35.1',
'ply==3.9',
'requests==2.12.4',
'slimit==0.8.1',
'unicode-slugify==0.1.3'
],
entry_points={
'console_scripts': [