mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-17 15:25:49 +00:00
[ina] improve extraction
This commit is contained in:
parent
de74ef83b7
commit
b27a71e66c
@ -1,36 +1,72 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from ..utils import (
|
||||||
|
int_or_none,
|
||||||
|
strip_or_none,
|
||||||
|
xpath_attr,
|
||||||
|
xpath_text,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class InaIE(InfoExtractor):
|
class InaIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?ina\.fr/video/(?P<id>I?[A-Z0-9]+)'
|
_VALID_URL = r'https?://(?:www\.)?ina\.fr/video/(?P<id>[A-Z0-9_]+)'
|
||||||
_TEST = {
|
_TESTS = [{
|
||||||
'url': 'http://www.ina.fr/video/I12055569/francois-hollande-je-crois-que-c-est-clair-video.html',
|
'url': 'http://www.ina.fr/video/I12055569/francois-hollande-je-crois-que-c-est-clair-video.html',
|
||||||
'md5': 'a667021bf2b41f8dc6049479d9bb38a3',
|
'md5': 'a667021bf2b41f8dc6049479d9bb38a3',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'I12055569',
|
'id': 'I12055569',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'François Hollande "Je crois que c\'est clair"',
|
'title': 'François Hollande "Je crois que c\'est clair"',
|
||||||
|
'description': 'md5:3f09eb072a06cb286b8f7e4f77109663',
|
||||||
}
|
}
|
||||||
}
|
}, {
|
||||||
|
'url': 'https://www.ina.fr/video/S806544_001/don-d-organes-des-avancees-mais-d-importants-besoins-video.html',
|
||||||
|
'only_matching': True,
|
||||||
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
mobj = re.match(self._VALID_URL, url)
|
video_id = self._match_id(url)
|
||||||
|
info_doc = self._download_xml(
|
||||||
|
'http://player.ina.fr/notices/%s.mrss' % video_id, video_id)
|
||||||
|
item = info_doc.find('channel/item')
|
||||||
|
title = xpath_text(item, 'title', fatal=True)
|
||||||
|
media_ns_xpath = lambda x: self._xpath_ns(x, 'http://search.yahoo.com/mrss/')
|
||||||
|
content = item.find(media_ns_xpath('content'))
|
||||||
|
|
||||||
video_id = mobj.group('id')
|
get_furl = lambda x: xpath_attr(content, media_ns_xpath(x), 'url')
|
||||||
mrss_url = 'http://player.ina.fr/notices/%s.mrss' % video_id
|
formats = []
|
||||||
info_doc = self._download_xml(mrss_url, video_id)
|
for q, w, h in (('bq', 400, 300), ('mq', 512, 384), ('hq', 768, 576)):
|
||||||
|
q_url = get_furl(q)
|
||||||
|
if not q_url:
|
||||||
|
continue
|
||||||
|
formats.append({
|
||||||
|
'format_id': q,
|
||||||
|
'url': q_url,
|
||||||
|
'width': w,
|
||||||
|
'height': h,
|
||||||
|
})
|
||||||
|
if not formats:
|
||||||
|
formats = [{
|
||||||
|
'url': get_furl('player') or content.attrib['url'],
|
||||||
|
}]
|
||||||
|
|
||||||
self.report_extraction(video_id)
|
thumbnails = []
|
||||||
|
for thumbnail in content.findall(media_ns_xpath('thumbnail')):
|
||||||
video_url = info_doc.find('.//{http://search.yahoo.com/mrss/}player').attrib['url']
|
thumbnail_url = thumbnail.get('url')
|
||||||
|
if not thumbnail_url:
|
||||||
|
continue
|
||||||
|
thumbnails.append({
|
||||||
|
'url': thumbnail_url,
|
||||||
|
'height': int_or_none(thumbnail.get('height')),
|
||||||
|
'width': int_or_none(thumbnail.get('width')),
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'url': video_url,
|
'formats': formats,
|
||||||
'title': info_doc.find('.//title').text,
|
'title': title,
|
||||||
|
'description': strip_or_none(xpath_text(item, 'description')),
|
||||||
|
'thumbnails': thumbnails,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user