Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
feat: add google drive options
NTFSvolumeeae0334b485b
diff --git a/cyberdrop_dl/config/crawlers.py b/cyberdrop_dl/config/crawlers.pyindex 61fd5950c..cbd8855c1 100644--- a/cyberdrop_dl/config/crawlers.py+++ b/cyberdrop_dl/config/crawlers.py@@ -1,13 +1,35 @@from typing import Annotated, Any, Literal, overridefrom pydantic import Field-from pydantic.functional_validators import AfterValidator+from pydantic.functional_validators import AfterValidator, field_validatorfrom cyberdrop_dl.models import ConfigGroup, ConfigModelfrom cyberdrop_dl.models.types import FormatStr, HttpURL, NonEmptyStrfrom cyberdrop_dl.models.validators import remove_duplicates, strings+class GoogleDriveFormats(ConfigModel):+ docs: Literal["docx", "odt", "rtf", "txt", "epub", "pdf", "md", "zip"] = "docx"+ "Default format for documents (can be overridden per URL with the 'format' query param)"++ sheets: Literal["xslx", "ods", "html", "csv", "tsv"] = "xslx"+ "Default format for spreedsheets (can be overridden per URL with the 'format' query param)"++ slides: Literal["pptx", "odp"] = "pptx"+ "Default format for presentations (can be overridden per URL with the 'format' query param)"++ @field_validator("*", mode="before")+ @classmethod+ def _remove_dots(cls, value: object) -> object:+ if isinstance(value, str):+ return value.lstrip(".")+ return value+++class GoogleDriveConfig(ConfigModel):+ default_formats: GoogleDriveFormats = Field(default_factory=GoogleDriveFormats)++class KemonoConfig(ConfigModel):file: bool = True"Download the main file in a post (if any)"@@ -146,13 +168,14 @@ class Crawlers(ConfigGroup, name=None):"Name of crawlers to disable for the current run"bandcamp: BandcampConfig = Field(default_factory=BandcampConfig)+ clonr: ClonrConfig = Field(default_factory=ClonrConfig)clypit: ClypitConfig = Field(default_factory=ClypitConfig)generic: GenericCrawlers = Field(default_factory=GenericCrawlers)+ google_drive: GoogleDriveConfig = Field(default_factory=GoogleDriveConfig)+ octave_music: OctaveMusicConfig = Field(default_factory=OctaveMusicConfig)one_pace: OnePaceConfig = Field(default_factory=OnePaceConfig)- tiktok: TikTokConfig = Field(default_factory=TikTokConfig)- twitter: TwitterConfig = Field(default_factory=TwitterConfig)- pawchive: KemonoConfig = Field(default_factory=KemonoConfig)only_haven: KemonoConfig = Field(default_factory=KemonoConfig)- octave_music: OctaveMusicConfig = Field(default_factory=OctaveMusicConfig)- clonr: ClonrConfig = Field(default_factory=ClonrConfig)+ pawchive: KemonoConfig = Field(default_factory=KemonoConfig)pornhub: PornHubConfig = Field(default_factory=PornHubConfig)+ tiktok: TikTokConfig = Field(default_factory=TikTokConfig)+ twitter: TwitterConfig = Field(default_factory=TwitterConfig)diff --git a/cyberdrop_dl/config/default.yaml b/cyberdrop_dl/config/default.yamlindex bc79b85a6..9fa98eba4 100644--- a/cyberdrop_dl/config/default.yaml+++ b/cyberdrop_dl/config/default.yaml@@ -39,6 +39,11 @@ crawlers:video: []wordpress_html: []wordpress_media: []+ google_drive:+ default_formats:+ docs: docx+ sheets: xslx+ slides: pptxoctave_music:filename_format: '{artist} - {title}{ext}'quality: mp3-320diff --git a/cyberdrop_dl/config/schema.json b/cyberdrop_dl/config/schema.jsonindex f96ddab46..78c036dba 100644--- a/cyberdrop_dl/config/schema.json+++ b/cyberdrop_dl/config/schema.json@@ -191,6 +191,9 @@},"pornhub": {"$ref": "#/$defs/PornHubConfig"+ },+ "google_drive": {+ "$ref": "#/$defs/GoogleDriveConfig"}},"title": "Crawlers",@@ -540,6 +543,59 @@"title": "GenericCrawlers","type": "object"},+ "GoogleDriveConfig": {+ "additionalProperties": false,+ "properties": {+ "default_formats": {+ "$ref": "#/$defs/GoogleDriveFormats"+ }+ },+ "title": "GoogleDriveConfig",+ "type": "object"+ },+ "GoogleDriveFormats": {+ "additionalProperties": false,+ "properties": {+ "sheets": {+ "default": "xslx",+ "enum": [+ "xslx",+ "ods",+ "html",+ "csv",+ "tsv"+ ],+ "title": "Sheets",+ "type": "string"+ },+ "slides": {+ "default": "pptx",+ "enum": [+ "pptx",+ "odp"+ ],+ "title": "Slides",+ "type": "string"+ },+ "docs": {+ "default": "docx",+ "enum": [+ "docx",+ "odt",+ "rtf",+ "txt",+ "epub",+ "pdf",+ "md",+ "zip"+ ],+ "title": "Docs",+ "type": "string"+ }+ },+ "title": "GoogleDriveFormats",+ "type": "object"+ },"HashMode": {"enum": ["off",diff --git a/cyberdrop_dl/crawlers/google_drive.py b/cyberdrop_dl/crawlers/google_drive.pyindex c1ae13116..62dcd91b6 100644--- a/cyberdrop_dl/crawlers/google_drive.py+++ b/cyberdrop_dl/crawlers/google_drive.py@@ -42,6 +42,7 @@ from cyberdrop_dl.utils import cssfrom cyberdrop_dl.utils.errors import error_handling_wrapperif TYPE_CHECKING:+ from cyberdrop_dl.config.crawlers import GoogleDriveConfigfrom cyberdrop_dl.url_objects import ScrapeItem@@ -52,7 +53,6 @@ _DRIVE_ID_LEN = 28 # v0 uses 28, v1 uses 33_DOCS_ID_LEN = 44 # v1 uses 44. I have not seen v0 doc URL-_PRIMARY_URL = AbsoluteHttpURL("https://drive.google.com")_DOCS_URL = AbsoluteHttpURL("https://docs.google.com")_FOLDER_ITEM_SELECTOR = "div.flip-entry-info > a[href]"@@ -90,7 +90,7 @@ class GoogleDriveCrawler(Crawler):),}SUPPORTED_DOMAINS: ClassVar[SupportedDomains] = "drive.google", "docs.google", "drive.usercontent.google.com"- PRIMARY_URL: ClassVar[AbsoluteHttpURL] = _PRIMARY_URL+ PRIMARY_URL: ClassVar[AbsoluteHttpURL] = AbsoluteHttpURL("https://drive.google.com")DOMAIN: ClassVar[str] = "drive.google"FOLDER_DOMAIN: ClassVar[str] = "GoogleDrive"@@ -150,8 +150,8 @@ class GoogleDriveCrawler(Crawler):return await self._docs_file(scrape_item, file_id, doc)async def _drive_file(self, scrape_item: ScrapeItem, file_id: str) -> None:- scrape_item.url = _PRIMARY_URL / "file/d" / file_id- export_url = (_PRIMARY_URL / "uc").with_query(id=file_id, export="download", confirm="True")+ scrape_item.url = self.PRIMARY_URL / "file/d" / file_id+ export_url = (self.PRIMARY_URL / "uc").with_query(id=file_id, export="download", confirm="True")return await self._file(scrape_item, export_url)@error_handling_wrapper@@ -165,10 +165,10 @@ class GoogleDriveCrawler(Crawler):if not doc:raise ScrapeError(422, "Unable to identify google docs file type")- format_ = scrape_item.url.query.get("format")- proper_format = _get_proper_doc_format(doc, format_)- if format_ and format_ != proper_format:- msg = f"{scrape_item.url} with {format_ = } is not valid. Falling back to {proper_format}"+ q_format = scrape_item.url.query.get("format")+ proper_format = _get_proper_doc_format(doc, q_format, self.config.crawlers.google_drive)+ if q_format and q_format != proper_format:+ msg = f"{scrape_item.url} with {q_format = } is not valid. Falling back to {proper_format}"self.log.warning(msg)scrape_item.url = (_DOCS_URL / doc / "d" / file_id).with_query(format=proper_format)@@ -195,6 +195,18 @@ class GoogleDriveCrawler(Crawler):return resp.url, resp.content_disposition.filename-def _get_proper_doc_format(doc: str, fmt: str | None) -> str:- valid_formats = _DOC_FORMATS[doc]- return fmt if fmt in valid_formats else valid_formats[0]+def _get_proper_doc_format(doc: str, query_format: str | None, config: GoogleDriveConfig) -> str:+ if query_format:+ valid_formats = _DOC_FORMATS[doc]+ if query_format in valid_formats:+ return query_format++ match doc:+ case "spreadsheets":+ return config.default_formats.sheets+ case "presentation":+ return config.default_formats.slides+ case "document":+ return config.default_formats.docs+ case _:+ raise ValueError(doc)diff --git a/docs/reference/config/crawlers.md b/docs/reference/config/crawlers.mdindex 03db14010..9afa63776 100644--- a/docs/reference/config/crawlers.md+++ b/docs/reference/config/crawlers.md@@ -101,6 +101,12 @@ crawlers:# Clyp.it+```yaml+crawlers:+ clypit:+ prefer_mp3: false+```+## `prefer_mp3`| Type | Default |@@ -109,6 +115,43 @@ crawlers:Download audios as `.mp3` files even if WAV (high quality) versions are available+# Google Drive++```yaml+crawlers:+ google_drive:+ default_formats:+ docs: docx+ sheets: xslx+ slides: pptx+```++## `default_formats`++### `docs`++| Type | Default |+| --------------------------------------------------------- | ------- |+| `docx`, `odt`, `rtf`, `txt`, `epub`, `pdf`, `md` or `zip` | `docx` |++Default format for documents (can be overridden per URL with the 'format' query param)++### `sheets`++| Type | Default |+| ------------------------------------- | ------- |+| `xslx`, `ods`, `html`, `csv` or `tsv` | `xslx` |++Default format for spreedsheets (can be overridden per URL with the 'format' query param)++### `slides`++| Type | Default |+| --------------- | ------- |+| `pptx` or `odp` | `pptx` |++Default format for presentations (can be overridden per URL with the 'format' query param)+# OnePace## `prefer_dub`