hotfix: skip email required albums

This commit is contained in:
7x11x13
2025-03-06 12:22:37 -05:00
parent 6f40880343
commit ac8e841e02
2 changed files with 18 additions and 10 deletions
+15 -7
View File
@@ -127,12 +127,10 @@ class BCFreeDownloader:
self.mail_album_data: Dict[str, BCFreeDownloaderAlbumData] = {} self.mail_album_data: Dict[str, BCFreeDownloaderAlbumData] = {}
self.unzip = unzip self.unzip = unzip
self.session = None self.session = None
self._init_email()
self._init_downloaded() self._init_downloaded()
self._init_session(cookies_file, identity) self._init_session(cookies_file, identity)
def _init_email(self): def _init_email(self):
if not self.options.email or self.options.email == "auto":
self.mail_session = secmail.Client(self.config_dir) self.mail_session = secmail.Client(self.config_dir)
self.options.email = self.mail_session.random_email(1, "1secmail.com")[0] self.options.email = self.mail_session.random_email(1, "1secmail.com")[0]
@@ -301,7 +299,9 @@ class BCFreeDownloader:
album_data = self._get_album_data_from_soup(soup) album_data = self._get_album_data_from_soup(soup)
url = soup.head.find("meta", attrs={"property": "og:url"})["content"] url = soup.head.find("meta", attrs={"property": "og:url"})["content"]
if not force and self.is_downloaded(album_data.id, url): if not force and self.is_downloaded(album_data.id, url):
raise BCFreeDownloadError(f"{url} already downloaded. To download anyways, use option --force") raise BCFreeDownloadError(
f"{url} already downloaded. To download anyways, use option --force"
)
logger.debug(f"Album data: {album_data}") logger.debug(f"Album data: {album_data}")
@@ -311,7 +311,9 @@ class BCFreeDownloader:
if not tralbum_data["hasAudio"]: if not tralbum_data["hasAudio"]:
raise BCFreeDownloadError(f"{url} has no audio. Skipping...") raise BCFreeDownloadError(f"{url} has no audio. Skipping...")
head_data = soup.head.find("script", {"type": "application/ld+json"}, recursive=False).string head_data = soup.head.find(
"script", {"type": "application/ld+json"}, recursive=False
).string
head_data = json.loads(head_data) head_data = json.loads(head_data)
head_id = head_data.get("@id") head_id = head_data.get("@id")
@@ -328,6 +330,9 @@ class BCFreeDownloader:
if head_data["offers"]["price"] == 0.0: if head_data["offers"]["price"] == 0.0:
if tralbum_data["current"]["require_email"]: if tralbum_data["current"]["require_email"]:
raise BCFreeDownloadError(f"{url} requires email. Skipping...")
if not self.options.email or self.options.email == "auto":
self._init_email()
logger.info(f"{url} requires email") logger.info(f"{url} requires email")
email_post_url = urljoin(url, "/email_download") email_post_url = urljoin(url, "/email_download")
r = self.session.post( r = self.session.post(
@@ -374,11 +379,11 @@ class BCFreeDownloader:
if "display:none" in li.get("style", ""): if "display:none" in li.get("style", ""):
continue continue
data = li["data-item-id"].split("-") data = li["data-item-id"].split("-")
albums += [ { "url": li.a["href"], "id": f'{data[0][0]}:{data[1]}' } ] albums += [{"url": li.a["href"], "id": f"{data[0][0]}:{data[1]}"}]
for obj in json.loads(html.unescape(grid.get("data-client-items", {}))): for obj in json.loads(html.unescape(grid.get("data-client-items", {}))):
if obj.get("filtered"): if obj.get("filtered"):
continue continue
albums += [ { "url": obj["page_url"], "id": f'{obj["type"][0]}:{obj["id"]}' } ] albums += [{"url": obj["page_url"], "id": f"{obj['type'][0]}:{obj['id']}"}]
for album in albums: for album in albums:
if album["url"][0] == "/": if album["url"][0] == "/":
@@ -387,7 +392,9 @@ class BCFreeDownloader:
# perform a check here for already-downloaded album to prevent mass requests # perform a check here for already-downloaded album to prevent mass requests
# to bandcamp for large labels and getting rate limited as a result # to bandcamp for large labels and getting rate limited as a result
if not force and self.is_downloaded(album["id"], album["url"]): if not force and self.is_downloaded(album["id"], album["url"]):
logger.info(f"{album['url']} already downloaded. To download anyways, use option --force") logger.info(
f"{album['url']} already downloaded. To download anyways, use option --force"
)
continue continue
logger.info(f"Downloading {album['url']}") logger.info(f"Downloading {album['url']}")
@@ -577,5 +584,6 @@ def main():
# finish up downloading # finish up downloading
downloader.wait_for_email_downloads() downloader.wait_for_email_downloads()
if __name__ == "__main__": if __name__ == "__main__":
main() main()
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "free-bandcamp-downloader" name = "free-bandcamp-downloader"
version = "0.4.1" version = "0.4.2"
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"