1
mirror of https://github.com/yt-dlp/yt-dlp synced 2024-12-20 18:15:54 +01:00
yt-dlp/youtube_dl/extractor/gamersyde.py

71 lines
2.1 KiB
Python
Raw Normal View History

2015-04-03 15:34:49 +02:00
from __future__ import unicode_literals
2015-04-04 13:53:22 +02:00
2015-04-03 15:34:49 +02:00
import re
2015-04-03 15:34:49 +02:00
from .common import InfoExtractor
2015-04-04 13:53:22 +02:00
from ..utils import (
js_to_json,
parse_duration,
remove_start,
)
2015-04-03 15:34:49 +02:00
class GamersydeIE(InfoExtractor):
2015-04-04 13:53:22 +02:00
_VALID_URL = r'https?://(?:www\.)?gamersyde\.com/hqstream_(?P<display_id>[\da-z_]+)-(?P<id>\d+)_[a-z]{2}\.html'
_TEST = {
2015-04-03 15:34:49 +02:00
'url': 'http://www.gamersyde.com/hqstream_bloodborne_birth_of_a_hero-34371_en.html',
'md5': 'f38d400d32f19724570040d5ce3a505f',
'info_dict': {
'id': '34371',
'ext': 'mp4',
'duration': 372,
2015-04-03 15:34:49 +02:00
'title': 'Bloodborne - Birth of a hero',
'thumbnail': 're:^https?://.*\.jpg$',
}
}
def _real_extract(self, url):
2015-04-04 13:53:22 +02:00
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
display_id = mobj.group('display_id')
2015-04-03 15:34:49 +02:00
2015-04-04 13:53:22 +02:00
webpage = self._download_webpage(url, display_id)
2015-04-03 15:34:49 +02:00
2015-04-04 13:53:22 +02:00
playlist = self._parse_json(
self._search_regex(
r'(?s)playlist: \[({.+?})\]\s*}\);', webpage, 'files'),
display_id, transform_source=js_to_json)
2015-04-03 15:34:49 +02:00
formats = []
2015-04-04 13:53:22 +02:00
for source in playlist['sources']:
video_url = source.get('file')
if not video_url:
continue
format_id = source.get('label')
f = {
'url': video_url,
'format_id': format_id,
2015-04-03 15:34:49 +02:00
}
2015-04-04 13:53:22 +02:00
m = re.search(r'^(?P<height>\d+)[pP](?P<fps>\d+)fps', format_id)
if m:
f.update({
'height': int(m.group('height')),
'fps': int(m.group('fps')),
})
formats.append(f)
self._sort_formats(formats)
2015-04-03 15:34:49 +02:00
2015-04-04 13:53:22 +02:00
title = remove_start(playlist['title'], '%s - ' % video_id)
thumbnail = playlist.get('image')
duration = parse_duration(self._search_regex(
r'Length:</label>([^<]+)<', webpage, 'duration', fatal=False))
2015-04-03 15:34:49 +02:00
return {
'id': video_id,
2015-04-04 13:53:22 +02:00
'display_id': display_id,
2015-04-03 15:34:49 +02:00
'title': title,
2015-04-04 13:53:22 +02:00
'thumbnail': thumbnail,
'duration': duration,
2015-04-04 13:53:22 +02:00
'formats': formats,
}