1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-29 19:47:54 +01:00

[giphy] Add extractor

This commit is contained in:
Jakub Wilk 2019-04-10 20:24:17 +02:00
parent f8c55c6664
commit 70ad513a1c
2 changed files with 63 additions and 0 deletions

View File

@ -423,6 +423,7 @@ from .gaskrank import GaskrankIE
from .gazeta import GazetaIE
from .gdcvault import GDCVaultIE
from .generic import GenericIE
from .giphy import GiphyIE
from .gfycat import GfycatIE
from .giantbomb import GiantBombIE
from .giga import GigaIE

View File

@ -0,0 +1,62 @@
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..utils import (
int_or_none,
remove_end,
remove_start,
)
class GiphyIE(InfoExtractor):
_VALID_URL = r'https://(?:i|media)\.giphy\.com/media/(\w+)/|https://giphy\.com/gifs/[^/#?]+-(\w+)(?:[#?]|$)'
_TESTS = [{
'url': 'https://media.giphy.com/media/2rj8VysAig8QE/giphy.gif',
'md5': 'faa04a4e3134cb74005b78b28c34cc29',
'info_dict': {
'id': '2rj8VysAig8QE',
'ext': 'mp4',
'title': 'Css GIF',
}
}, {
'url': 'https://i.giphy.com/media/oY7zuBsNna7CM/giphy.mp4',
'only_matching': True
}, {
'url': 'https://giphy.com/gifs/quit-playin-MZAvNpYCrFUJi',
'only_matching': True
}]
def _real_extract(self, url):
[video_id] = filter(None, re.match(self._VALID_URL, url).groups())
page_url = 'https://media.giphy.com/media/{id}/giphy.gif'.format(id=video_id)
webpage = self._download_webpage(page_url, video_id)
title = self._og_search_title(webpage)
title = remove_end(title, ' - Find & Share on GIPHY')
formats = []
for prop in 'image', 'video':
url = self._og_search_property(prop, webpage)
mime_type = self._og_search_property(prop + ':type', webpage)
if mime_type == 'image/gif':
format_id = 'gif'
quality = 0
else:
format_id = remove_start(mime_type, 'video/')
quality = 1
fmt = {
'url': url,
'format_id': format_id,
'quality': quality,
}
for dim in 'width', 'height':
fmt[dim] = int_or_none(
self._og_search_property(prop + ':' + dim, webpage, fatal=False))
formats.append(fmt)
self._sort_formats(formats)
return {
'id': video_id,
'title': title,
'formats': formats,
}