Add --identity argument

This commit is contained in:
7x11x13
2024-06-22 15:10:48 -04:00
parent 964d42540e
commit 247c3f2193
3 changed files with 19 additions and 7 deletions
+9 -2
View File
@@ -2,7 +2,7 @@
Download free and $0 minimum name-your-price albums and tracks from Bandcamp (including ones that are sent to email), Download free and $0 minimum name-your-price albums and tracks from Bandcamp (including ones that are sent to email),
and tag them with data from the Bandcamp page. Also able to download items in your collection, if login cookies are and tag them with data from the Bandcamp page. Also able to download items in your collection, if login cookies are
supplied using the `--cookies` argument. supplied using the `--cookies` or `--identity` argument.
## Installation ## Installation
@@ -11,13 +11,19 @@ Install with pip
pip install free-bandcamp-downloader pip install free-bandcamp-downloader
``` ```
## Note on passing cookies
Only one cookie is needed to login, which has the name "identity". You can pass this cookie to `bcdl-free` using the
`--cookies` argument which you must supply a path to a Netscape cookies.txt formatted file, or using the `--identity`
argument which you must supply the value of your "identity" cookie.
## Usage ## Usage
``` ```
Usage: Usage:
bcdl-free (-a <URL> | -l <URL>)[--force][--no-unzip][-d | --dir <dir>][-e | --email <email>] bcdl-free (-a <URL> | -l <URL>)[--force][--no-unzip][-d | --dir <dir>][-e | --email <email>]
[-z | --zipcode <zipcode>][-c | --country <country>][-f | --format <format>] [-z | --zipcode <zipcode>][-c | --country <country>][-f | --format <format>]
[--cookies <file>][--debug] [--cookies <file>][--identity <value>][--debug]
bcdl-free setdefault [-d | --dir <dir>][-e | --email <email>][-z | --zipcode <zipcode>] bcdl-free setdefault [-d | --dir <dir>][-e | --email <email>][-z | --zipcode <zipcode>]
[-c | --country <country>][-f | --format <format>] [-c | --country <country>][-f | --format <format>]
bcdl-free defaults bcdl-free defaults
@@ -40,6 +46,7 @@ Options:
-e --email <email> Set email (set to 'auto' to automatically download from a disposable email) -e --email <email> Set email (set to 'auto' to automatically download from a disposable email)
-f --format <format> Set format -f --format <format> Set format
--cookies <file> Path to cookies.txt file so albums in your collection can be downloaded --cookies <file> Path to cookies.txt file so albums in your collection can be downloaded
--identity <value> Value of identity cookie so albums in your collection can be downloaded
--debug Set loglevel to debug --debug Set loglevel to debug
Formats: Formats:
- FLAC - FLAC
+9 -4
View File
@@ -2,7 +2,7 @@
Usage: Usage:
bcdl-free (-a <URL> | -l <URL>)[--force][--no-unzip][-d | --dir <dir>][-e | --email <email>] bcdl-free (-a <URL> | -l <URL>)[--force][--no-unzip][-d | --dir <dir>][-e | --email <email>]
[-z | --zipcode <zipcode>][-c | --country <country>][-f | --format <format>] [-z | --zipcode <zipcode>][-c | --country <country>][-f | --format <format>]
[--cookies <file>][--debug] [--cookies <file>][--identity <value>][--debug]
bcdl-free setdefault [-d | --dir <dir>][-e | --email <email>][-z | --zipcode <zipcode>] bcdl-free setdefault [-d | --dir <dir>][-e | --email <email>][-z | --zipcode <zipcode>]
[-c | --country <country>][-f | --format <format>] [-c | --country <country>][-f | --format <format>]
bcdl-free defaults bcdl-free defaults
@@ -25,6 +25,7 @@ Options:
-e --email <email> Set email (set to 'auto' to automatically download from a disposable email) -e --email <email> Set email (set to 'auto' to automatically download from a disposable email)
-f --format <format> Set format -f --format <format> Set format
--cookies <file> Path to cookies.txt file so albums in your collection can be downloaded --cookies <file> Path to cookies.txt file so albums in your collection can be downloaded
--identity <value> Value of identity cookie so albums in your collection can be downloaded
--debug Set loglevel to debug --debug Set loglevel to debug
Formats: Formats:
- FLAC - FLAC
@@ -110,6 +111,7 @@ class BCFreeDownloader:
download_history_file: str, download_history_file: str,
unzip: bool = True, unzip: bool = True,
cookies_file: Optional[str] = None, cookies_file: Optional[str] = None,
identity: Optional[str] = None,
): ):
self.options = options self.options = options
self.config_dir = config_dir self.config_dir = config_dir
@@ -121,7 +123,7 @@ class BCFreeDownloader:
self.session = None self.session = None
self._init_email() self._init_email()
self._init_downloaded() self._init_downloaded()
self._init_session(cookies_file) self._init_session(cookies_file, identity)
def _init_email(self): def _init_email(self):
if not self.options.email or self.options.email == "auto": if not self.options.email or self.options.email == "auto":
@@ -134,12 +136,14 @@ class BCFreeDownloader:
for line in f: for line in f:
self.downloaded.add(line.strip()) self.downloaded.add(line.strip())
def _init_session(self, cookies_file: Optional[str]): def _init_session(self, cookies_file: Optional[str], identity: Optional[str]):
self.session = requests.Session() self.session = requests.Session()
if cookies_file: if cookies_file:
cj = MozillaCookieJar(cookies_file) cj = MozillaCookieJar(cookies_file)
cj.load() cj.load()
self.session.cookies = cj self.session.cookies = cj
if identity:
self.session.cookies.set("identity", identity)
def _download_file( def _download_file(
self, self,
@@ -355,7 +359,7 @@ class BCFreeDownloader:
else: else:
raise BCFreeDownloadError( raise BCFreeDownloadError(
f"{url} is not free. If you have purchased this album, " f"{url} is not free. If you have purchased this album, "
"use the --cookies flag to pass your login cookies." "use the --cookies flag or --identity flag to pass your login cookie."
) )
def download_label(self, url: str, force: bool = False): def download_label(self, url: str, force: bool = False):
@@ -501,6 +505,7 @@ def main():
config.get("download_history_file"), config.get("download_history_file"),
not arguments["--no-unzip"], not arguments["--no-unzip"],
arguments["--cookies"], arguments["--cookies"],
arguments["--identity"],
) )
if arguments["-a"]: if arguments["-a"]:
downloader.download_album(arguments["-a"], arguments["--force"]) downloader.download_album(arguments["-a"], arguments["--force"])
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "free-bandcamp-downloader" name = "free-bandcamp-downloader"
version = "0.3.2" version = "0.3.3"
description = "Download free and name-your-price albums from Bandcamp in lossless quality" description = "Download free and name-your-price albums from Bandcamp in lossless quality"
authors = ["7x11x13 <x7x11x13@gmail.com>"] authors = ["7x11x13 <x7x11x13@gmail.com>"]
license = "MIT" license = "MIT"