1
1
mirror of https://github.com/ytdl-org/youtube-dl synced 2024-11-09 05:37:09 +01:00
youtube-dl/youtube_dl/extractor/europa.py

94 lines
3.3 KiB
Python
Raw Normal View History

2015-08-12 16:59:04 +02:00
# coding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
2015-10-02 18:29:15 +02:00
from ..compat import compat_urlparse
2015-08-12 16:59:04 +02:00
from ..utils import (
2015-10-02 18:29:15 +02:00
int_or_none,
orderedSet,
parse_duration,
qualities,
unified_strdate,
2015-08-12 16:59:04 +02:00
xpath_text
)
class EuropaIE(InfoExtractor):
2015-10-02 19:22:53 +02:00
_VALID_URL = r'https?://ec\.europa\.eu/avservices/(?:video/player|audio/audioDetails)\.cfm\?.*?\bref=(?P<id>[A-Za-z0-9-]+)'
2015-10-02 18:29:15 +02:00
_TESTS = [{
2015-08-12 16:59:04 +02:00
'url': 'http://ec.europa.eu/avservices/video/player.cfm?ref=I107758',
2015-10-02 18:29:15 +02:00
'md5': '574f080699ddd1e19a675b0ddf010371',
2015-08-12 16:59:04 +02:00
'info_dict': {
'id': 'I107758',
'ext': 'mp4',
'title': 'TRADE - Wikileaks on TTIP',
'description': 'NEW LIVE EC Midday press briefing of 11/08/2015',
2015-10-02 18:29:15 +02:00
'thumbnail': 're:^https?://.*\.jpg$',
'upload_date': '20150811',
'duration': 34,
'view_count': int,
'formats': 'mincount:3',
2015-08-12 16:59:04 +02:00
}
2015-10-02 18:29:15 +02:00
}, {
'url': 'http://ec.europa.eu/avservices/video/player.cfm?sitelang=en&ref=I107786',
'only_matching': True,
2015-10-02 19:22:53 +02:00
}, {
'url': 'http://ec.europa.eu/avservices/audio/audioDetails.cfm?ref=I-109295&sitelang=en',
'only_matching': True,
2015-10-02 18:29:15 +02:00
}]
2015-08-12 16:59:04 +02:00
def _real_extract(self, url):
video_id = self._match_id(url)
2015-10-02 18:29:15 +02:00
playlist = self._download_xml(
'http://ec.europa.eu/avservices/video/player/playlist.cfm?ID=%s' % video_id, video_id)
2015-08-12 16:59:04 +02:00
2015-10-02 18:29:15 +02:00
def get_item(type_, preference):
items = {}
for item in playlist.findall('./info/%s/item' % type_):
lang, label = xpath_text(item, 'lg', default=None), xpath_text(item, 'label', default=None)
if lang and label:
items[lang] = label.strip()
for p in preference:
if items.get(p):
return items[p]
2015-08-12 16:59:04 +02:00
2015-10-02 18:29:15 +02:00
query = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
preferred_lang = query.get('sitelang', ('en', ))[0]
2015-08-12 16:59:04 +02:00
2015-10-02 18:29:15 +02:00
preferred_langs = orderedSet((preferred_lang, 'en', 'int'))
2015-08-12 16:59:04 +02:00
2015-10-02 18:29:15 +02:00
title = get_item('title', preferred_langs) or video_id
description = get_item('description', preferred_langs)
thumbnmail = xpath_text(playlist, './info/thumburl', 'thumbnail')
upload_date = unified_strdate(xpath_text(playlist, './info/date', 'upload date'))
duration = parse_duration(xpath_text(playlist, './info/duration', 'duration'))
view_count = int_or_none(xpath_text(playlist, './info/views', 'views'))
2015-08-12 16:59:04 +02:00
2015-10-02 18:29:15 +02:00
language_preference = qualities(preferred_langs[::-1])
2015-08-12 16:59:04 +02:00
2015-10-02 18:29:15 +02:00
formats = []
for file_ in playlist.findall('./files/file'):
video_url = xpath_text(file_, './url')
if not video_url:
continue
lang = xpath_text(file_, './lg')
formats.append({
'url': video_url,
'format_id': lang,
'format_note': xpath_text(file_, './lglabel'),
'language_preference': language_preference(lang)
})
self._sort_formats(formats)
2015-08-12 16:59:04 +02:00
return {
'id': video_id,
2015-10-02 18:29:15 +02:00
'title': title,
'description': description,
'thumbnail': thumbnmail,
'upload_date': upload_date,
'duration': duration,
'view_count': view_count,
2015-08-12 16:59:04 +02:00
'formats': formats
}