Skip to content

Commit

Permalink
[philomena] support downloading SVG files (#5643)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Jun 5, 2024
1 parent 8fce9ea commit 9b99d2c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
26 changes: 26 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,19 @@ Description
See `Filters <https://derpibooru.org/filters>`_ for details.


extractor.derpibooru.svg
------------------------
Type
``bool``
Default
``true``
Description
Download SVG versions of images when available.

Try to download the ``view_url`` version of these posts
when this option is disabled.


extractor.deviantart.auto-watch
-------------------------------
Type
Expand Down Expand Up @@ -3762,6 +3775,19 @@ Description
See `Filters <https://twibooru.org/filters>`__ for details.


extractor.twibooru.svg
----------------------
Type
``bool``
Default
``true``
Description
Download SVG versions of images when available.

Try to download the ``view_url`` version of these posts
when this option is disabled.


extractor.twitter.ads
---------------------
Type
Expand Down
7 changes: 6 additions & 1 deletion gallery_dl/extractor/philomena.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ class PhilomenaExtractor(BooruExtractor):

def _init(self):
self.api = PhilomenaAPI(self)
if not self.config("svg", True):
self._file_url = operator.itemgetter("view_url")

_file_url = operator.itemgetter("view_url")
def _file_url(self, post):
if post["format"] == "svg":
return post["view_url"].rpartition(".")[0] + ".svg"
return post["view_url"]

@staticmethod
def _prepare(post):
Expand Down
7 changes: 6 additions & 1 deletion gallery_dl/extractor/twibooru.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ class TwibooruExtractor(BooruExtractor):

def _init(self):
self.api = TwibooruAPI(self)
if not self.config("svg", True):
self._file_url = operator.itemgetter("view_url")

_file_url = operator.itemgetter("view_url")
def _file_url(self, post):
if post["format"] == "svg":
return post["view_url"].rpartition(".")[0] + ".svg"
return post["view_url"]

@staticmethod
def _prepare(post):
Expand Down
12 changes: 12 additions & 0 deletions test/results/derpibooru.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@
"wilson_score" : float,
},

{
"#url" : "https://derpibooru.org/images/3334658",
"#comment" : "svg (#5643)",
"#category": ("philomena", "derpibooru", "post"),
"#class" : philomena.PhilomenaPostExtractor,
"#urls" : "https://derpicdn.net/img/view/2024/4/1/3334658__safe_alternate+version_artist-colon-jp_derpibooru+exclusive_twilight+sparkle_alicorn_pony_amending+fences_g4_season+5_-dot-svg+available_female_grin_lo.svg",
"#sha1_content": "eec5adf02e2a4fe83b9211c0444d57dc03e21f50",

"extension": "svg",
"format" : "svg",
},

{
"#url" : "https://derpibooru.org/1",
"#category": ("philomena", "derpibooru", "post"),
Expand Down
25 changes: 25 additions & 0 deletions test/results/twibooru.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,31 @@
"wilson_score" : float,
},

{
"#url" : "https://twibooru.org/523964",
"#comment" : "svg (#5643)",
"#category": ("philomena", "twibooru", "post"),
"#class" : twibooru.TwibooruPostExtractor,
"#urls" : "https://cdn.twibooru.org/img/2020/7/13/523964/full.svg",
"#sha1_content": "15590fe151ff65ef767b409e46dfdf708b339f4d",

"extension": "svg",
"format" : "svg",
},

{
"#url" : "https://twibooru.org/523964",
"#comment" : "svg (#5643)",
"#category": ("philomena", "twibooru", "post"),
"#class" : twibooru.TwibooruPostExtractor,
"#options" : {"svg": False},
"#urls" : "https://cdn.twibooru.org/img/2020/7/13/523964/full.png",
"#sha1_content": "f8ff78e6a929a024f8529199f9a600617898d03c",

"extension": "png",
"format" : "svg",
},

{
"#url" : "https://twibooru.org/search?q=cute",
"#category": ("philomena", "twibooru", "search"),
Expand Down

0 comments on commit 9b99d2c

Please sign in to comment.