]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/europa.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / europa.py
CommitLineData
3bb3f041 1from .common import InfoExtractor
2from ..utils import (
af17794c
S
3 int_or_none,
4 orderedSet,
5 parse_duration,
4dfbf869 6 parse_qs,
af17794c
S
7 qualities,
8 unified_strdate,
3bb3f041 9 xpath_text
10)
11
12
13class EuropaIE(InfoExtractor):
f3b098fb 14 _VALID_URL = r'https?://ec\.europa\.eu/avservices/(?:video/player|audio/audioDetails)\.cfm\?.*?\bref=(?P<id>[A-Za-z0-9-]+)'
af17794c 15 _TESTS = [{
3bb3f041 16 'url': 'http://ec.europa.eu/avservices/video/player.cfm?ref=I107758',
af17794c 17 'md5': '574f080699ddd1e19a675b0ddf010371',
3bb3f041 18 'info_dict': {
19 'id': 'I107758',
20 'ext': 'mp4',
21 'title': 'TRADE - Wikileaks on TTIP',
22 'description': 'NEW LIVE EC Midday press briefing of 11/08/2015',
ec85ded8 23 'thumbnail': r're:^https?://.*\.jpg$',
af17794c
S
24 'upload_date': '20150811',
25 'duration': 34,
26 'view_count': int,
27 'formats': 'mincount:3',
3bb3f041 28 }
af17794c
S
29 }, {
30 'url': 'http://ec.europa.eu/avservices/video/player.cfm?sitelang=en&ref=I107786',
31 'only_matching': True,
f3b098fb
S
32 }, {
33 'url': 'http://ec.europa.eu/avservices/audio/audioDetails.cfm?ref=I-109295&sitelang=en',
34 'only_matching': True,
af17794c 35 }]
3bb3f041 36
37 def _real_extract(self, url):
38 video_id = self._match_id(url)
3bb3f041 39
af17794c
S
40 playlist = self._download_xml(
41 'http://ec.europa.eu/avservices/video/player/playlist.cfm?ID=%s' % video_id, video_id)
3bb3f041 42
af17794c
S
43 def get_item(type_, preference):
44 items = {}
45 for item in playlist.findall('./info/%s/item' % type_):
46 lang, label = xpath_text(item, 'lg', default=None), xpath_text(item, 'label', default=None)
47 if lang and label:
48 items[lang] = label.strip()
49 for p in preference:
50 if items.get(p):
51 return items[p]
3bb3f041 52
4dfbf869 53 query = parse_qs(url)
af17794c 54 preferred_lang = query.get('sitelang', ('en', ))[0]
3bb3f041 55
af17794c 56 preferred_langs = orderedSet((preferred_lang, 'en', 'int'))
3bb3f041 57
af17794c
S
58 title = get_item('title', preferred_langs) or video_id
59 description = get_item('description', preferred_langs)
a0566bbf 60 thumbnail = xpath_text(playlist, './info/thumburl', 'thumbnail')
af17794c
S
61 upload_date = unified_strdate(xpath_text(playlist, './info/date', 'upload date'))
62 duration = parse_duration(xpath_text(playlist, './info/duration', 'duration'))
b203095d 63 view_count = int_or_none(xpath_text(playlist, './info/views', 'views'))
3bb3f041 64
af17794c 65 language_preference = qualities(preferred_langs[::-1])
3bb3f041 66
af17794c
S
67 formats = []
68 for file_ in playlist.findall('./files/file'):
69 video_url = xpath_text(file_, './url')
70 if not video_url:
71 continue
72 lang = xpath_text(file_, './lg')
73 formats.append({
74 'url': video_url,
75 'format_id': lang,
76 'format_note': xpath_text(file_, './lglabel'),
77 'language_preference': language_preference(lang)
78 })
3bb3f041 79
80 return {
81 'id': video_id,
af17794c
S
82 'title': title,
83 'description': description,
a0566bbf 84 'thumbnail': thumbnail,
af17794c
S
85 'upload_date': upload_date,
86 'duration': duration,
87 'view_count': view_count,
3bb3f041 88 'formats': formats
89 }