1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-18 08:16:10 +00:00
youtube-dl/youtube_dl/extractor/videa.py

107 lines
3.4 KiB
Python
Raw Normal View History

2016-11-03 11:53:45 +00:00
# coding: utf-8
from __future__ import unicode_literals
2016-12-31 15:04:29 +00:00
import re
2016-11-03 11:53:45 +00:00
from .common import InfoExtractor
from ..utils import (
int_or_none,
mimetype2ext,
parse_codecs,
2016-11-03 11:53:45 +00:00
xpath_element,
xpath_text,
)
class VideaIE(InfoExtractor):
_VALID_URL = r'''(?x)
https?://
2018-03-27 15:02:04 +00:00
videa(?:kid)?\.hu/
(?:
videok/(?:[^/]+/)*[^?#&]+-|
player\?.*?\bv=|
player/v/
)
(?P<id>[^?#&]+)
'''
2016-11-03 11:53:45 +00:00
_TESTS = [{
'url': 'http://videa.hu/videok/allatok/az-orult-kigyasz-285-kigyot-kigyo-8YfIAjxwWGwT8HVQ',
'md5': '97a7af41faeaffd9f1fc864a7c7e7603',
'info_dict': {
'id': '8YfIAjxwWGwT8HVQ',
'ext': 'mp4',
'title': 'Az őrült kígyász 285 kígyót enged szabadon',
2018-03-27 15:02:04 +00:00
'thumbnail': r're:^https?://.*',
2016-11-03 11:53:45 +00:00
'duration': 21,
},
}, {
'url': 'http://videa.hu/videok/origo/jarmuvek/supercars-elozes-jAHDWfWSJH5XuFhH',
'only_matching': True,
}, {
'url': 'http://videa.hu/player?v=8YfIAjxwWGwT8HVQ',
'only_matching': True,
}, {
'url': 'http://videa.hu/player/v/8YfIAjxwWGwT8HVQ?autoplay=1',
'only_matching': True,
2018-03-27 15:02:04 +00:00
}, {
'url': 'https://videakid.hu/videok/origo/jarmuvek/supercars-elozes-jAHDWfWSJH5XuFhH',
'only_matching': True,
}, {
'url': 'https://videakid.hu/player?v=8YfIAjxwWGwT8HVQ',
'only_matching': True,
}, {
'url': 'https://videakid.hu/player/v/8YfIAjxwWGwT8HVQ?autoplay=1',
'only_matching': True,
2016-11-03 11:53:45 +00:00
}]
2016-12-31 15:04:29 +00:00
@staticmethod
def _extract_urls(webpage):
return [url for _, url in re.findall(
r'<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//videa\.hu/player\?.*?\bv=.+?)\1',
webpage)]
2016-11-03 11:53:45 +00:00
def _real_extract(self, url):
video_id = self._match_id(url)
info = self._download_xml(
'http://videa.hu/videaplayer_get_xml.php', video_id,
query={'v': video_id})
2016-11-03 11:53:45 +00:00
video = xpath_element(info, './/video', 'video', fatal=True)
sources = xpath_element(info, './/video_sources', 'sources', fatal=True)
2016-11-03 11:53:45 +00:00
title = xpath_text(video, './title', fatal=True)
2016-11-03 11:53:45 +00:00
formats = []
for source in sources.findall('./video_source'):
source_url = source.text
if not source_url:
continue
f = parse_codecs(source.get('codecs'))
f.update({
'url': source_url,
'ext': mimetype2ext(source.get('mimetype')) or 'mp4',
'format_id': source.get('name'),
'width': int_or_none(source.get('width')),
'height': int_or_none(source.get('height')),
})
formats.append(f)
self._sort_formats(formats)
2016-11-03 11:53:45 +00:00
thumbnail = xpath_text(video, './poster_src')
duration = int_or_none(xpath_text(video, './duration'))
2016-11-03 11:53:45 +00:00
age_limit = None
is_adult = xpath_text(video, './is_adult_content', default=None)
if is_adult:
age_limit = 18 if is_adult == '1' else 0
2016-11-03 11:53:45 +00:00
return {
'id': video_id,
'title': title,
'thumbnail': thumbnail,
'duration': duration,
'age_limit': age_limit,
'formats': formats,
}