Files
gallery-dl/gallery_dl/extractor/directlink.py
H R X N 45f9d64c23 Update directlink.py with additional file exts. (#30)
Add WebP, still not that common, but it's increasing.
Add 3rd JPEG variant (https://en.wikipedia.org/wiki/JPEG#JPEG_filename_extensions)
Never seen JFIF in the wild, would probably be overkill.
Extend Ogg formats (https://en.wikipedia.org/wiki/Ogg; https://wiki.xiph.org/MIME_Types_and_File_Extensions)
2017-07-27 20:40:00 +02:00

37 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
# Copyright 2017 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
# published by the Free Software Foundation.
"""Direct link handling"""
from .common import Extractor, Message
from .. import text
class DirectlinkExtractor(Extractor):
"""Extractor for direct links to images"""
category = "directlink"
filename_fmt = "{domain}/{path}"
pattern = [r"https?://([^/]+)/([^?&#]+\.(?:jpe?g?|png|gif|webp|webm|mp4|mkv|ogg|ogm|ogv|opus))"]
test = [(("https://photos.smugmug.com/The-World/Hawaii/"
"i-SWz2K6n/2/X3/IMG_0311-X3.jpg"), {
"url": "32ee1045881e17ef3f13a9958595afa42421ec6c",
"keyword": "1abd2f2c115cdf2cf2671d2611349b4213c3ab3e",
})]
def __init__(self, match):
Extractor.__init__(self)
self.domain, self.path = match.groups()
self.url = match.string
def items(self):
data = {"domain": self.domain, "path": self.path}
text.nameext_from_url(self.url, data)
yield Message.Version, 1
yield Message.Directory, data
yield Message.Url, self.url, data