diff options
| author | 2023-03-13 02:07:49 -0400 | |
|---|---|---|
| committer | 2023-03-13 02:07:49 -0400 | |
| commit | 10987f08f8b6c510ba64f4b42d95ba67eec6e5b0 (patch) | |
| tree | 1af82cad9ac859a70cafc976a980280b939cfcc7 /gallery_dl/extractor/reddit.py | |
| parent | 919f8ba16a7b82ba1099bd25b2c61c7881a05aa2 (diff) | |
New upstream version 1.25.0.upstream/1.25.0
Diffstat (limited to 'gallery_dl/extractor/reddit.py')
| -rw-r--r-- | gallery_dl/extractor/reddit.py | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/gallery_dl/extractor/reddit.py b/gallery_dl/extractor/reddit.py index 204562e..305de2a 100644 --- a/gallery_dl/extractor/reddit.py +++ b/gallery_dl/extractor/reddit.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2017-2022 Mike Fährmann +# Copyright 2017-2023 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -29,7 +29,14 @@ class RedditExtractor(Extractor): parentdir = self.config("parent-directory") max_depth = self.config("recursion", 0) + videos = self.config("videos", True) + if videos: + if videos == "ytdl": + self._extract_video = self._extract_video_ytdl + elif videos == "dash": + self._extract_video = self._extract_video_dash + videos = True submissions = self.submissions() visited = set() @@ -62,19 +69,8 @@ class RedditExtractor(Extractor): elif submission["is_video"]: if videos: text.nameext_from_url(url, submission) - if videos == "ytdl": - url = "https://www.reddit.com" + \ - submission["permalink"] - else: - submission["_ytdl_extra"] = { - "title": submission["title"], - } - try: - url = (submission["secure_media"] - ["reddit_video"]["dash_url"]) - except (KeyError, TypeError): - pass - yield Message.Url, "ytdl:" + url, submission + url = "ytdl:" + self._extract_video(submission) + yield Message.Url, url, submission elif not submission["is_self"]: urls.append((url, submission)) @@ -145,6 +141,21 @@ class RedditExtractor(Extractor): submission["id"], item["media_id"]) self.log.debug(src) + def _extract_video_ytdl(self, submission): + return "https://www.reddit.com" + submission["permalink"] + + def _extract_video_dash(self, submission): + submission["_ytdl_extra"] = {"title": submission["title"]} + try: + return (submission["secure_media"]["reddit_video"]["dash_url"] + + "#__youtubedl_smuggle=%7B%22to_generic%22%3A+1%7D") + except Exception: + return submission["url"] + + def _extract_video(self, submission): + submission["_ytdl_extra"] = {"title": submission["title"]} + return submission["url"] + class RedditSubredditExtractor(RedditExtractor): """Extractor for URLs from subreddits on reddit.com""" @@ -233,6 +244,25 @@ class RedditSubmissionExtractor(RedditExtractor): "content": "1e7dde4ee7d5f4c4b45749abfd15b2dbfa27df3f", "count": 3, }), + # video + ("https://www.reddit.com/r/aww/comments/90bu6w/", { + "pattern": r"ytdl:https://v.redd.it/gyh95hiqc0b11", + "count": 1, + }), + # video (ytdl) + ("https://www.reddit.com/r/aww/comments/90bu6w/", { + "options": (("videos", "ytdl"),), + "pattern": r"ytdl:https://www.reddit.com/r/aww/comments/90bu6w" + r"/heat_index_was_110_degrees_so_we_offered_him_a/", + "count": 1, + }), + # video (dash) + ("https://www.reddit.com/r/aww/comments/90bu6w/", { + "options": (("videos", "dash"),), + "pattern": r"ytdl:https://v.redd.it/gyh95hiqc0b11" + r"/DASHPlaylist.mpd\?a=", + "count": 1, + }), # deleted gallery (#953) ("https://www.reddit.com/gallery/icfgzv", { "count": 0, |
