2016-10-02 11:39:18 +00:00
|
|
|
# coding: utf-8
|
2014-01-07 09:04:48 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2013-06-23 18:24:07 +00:00
|
|
|
import re
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2019-07-02 21:07:01 +00:00
|
|
|
from ..compat import compat_str
|
2013-06-23 18:24:07 +00:00
|
|
|
from ..utils import (
|
2017-08-17 17:58:23 +00:00
|
|
|
ExtractorError,
|
2014-10-20 13:27:59 +00:00
|
|
|
int_or_none,
|
2014-11-20 11:06:33 +00:00
|
|
|
qualities,
|
2017-10-15 15:12:34 +00:00
|
|
|
try_get,
|
2017-08-17 17:58:23 +00:00
|
|
|
unified_strdate,
|
2013-06-23 18:24:07 +00:00
|
|
|
)
|
|
|
|
|
2014-11-23 19:41:03 +00:00
|
|
|
# There are different sources of video in arte.tv, the extraction process
|
2013-10-13 11:54:31 +00:00
|
|
|
# is different for each one. The videos usually expire in 7 days, so we can't
|
|
|
|
# add tests.
|
|
|
|
|
2013-06-23 18:24:07 +00:00
|
|
|
|
2016-06-01 18:10:23 +00:00
|
|
|
class ArteTVBaseIE(InfoExtractor):
|
2016-03-06 20:19:54 +00:00
|
|
|
def _extract_from_json_url(self, json_url, video_id, lang, title=None):
|
2014-03-24 21:01:47 +00:00
|
|
|
info = self._download_json(json_url, video_id)
|
2013-10-13 11:54:31 +00:00
|
|
|
player_info = info['videoJsonPlayer']
|
|
|
|
|
2017-10-15 15:12:34 +00:00
|
|
|
vsr = try_get(player_info, lambda x: x['VSR'], dict)
|
2017-09-04 16:08:07 +00:00
|
|
|
if not vsr:
|
2017-10-15 15:12:34 +00:00
|
|
|
error = None
|
|
|
|
if try_get(player_info, lambda x: x['custom_msg']['type']) == 'error':
|
|
|
|
error = try_get(
|
|
|
|
player_info, lambda x: x['custom_msg']['msg'], compat_str)
|
|
|
|
if not error:
|
|
|
|
error = 'Video %s is not available' % player_info.get('VID') or video_id
|
|
|
|
raise ExtractorError(error, expected=True)
|
2017-08-17 17:58:23 +00:00
|
|
|
|
2014-09-29 10:45:18 +00:00
|
|
|
upload_date_str = player_info.get('shootingDate')
|
|
|
|
if not upload_date_str:
|
2016-02-17 16:51:08 +00:00
|
|
|
upload_date_str = (player_info.get('VRA') or player_info.get('VDA') or '').split(' ')[0]
|
2014-09-29 10:45:18 +00:00
|
|
|
|
2016-03-06 20:19:54 +00:00
|
|
|
title = (player_info.get('VTI') or title or player_info['VID']).strip()
|
2014-10-21 13:08:20 +00:00
|
|
|
subtitle = player_info.get('VSU', '').strip()
|
|
|
|
if subtitle:
|
|
|
|
title += ' - %s' % subtitle
|
|
|
|
|
2013-10-13 11:54:31 +00:00
|
|
|
info_dict = {
|
|
|
|
'id': player_info['VID'],
|
2014-10-21 13:08:20 +00:00
|
|
|
'title': title,
|
2013-10-13 11:54:31 +00:00
|
|
|
'description': player_info.get('VDE'),
|
2014-09-29 10:45:18 +00:00
|
|
|
'upload_date': unified_strdate(upload_date_str),
|
2013-10-13 11:54:31 +00:00
|
|
|
'thumbnail': player_info.get('programImage') or player_info.get('VTU', {}).get('IUR'),
|
|
|
|
}
|
2019-07-02 21:07:01 +00:00
|
|
|
qfunc = qualities(['MQ', 'HQ', 'EQ', 'SQ'])
|
2013-10-13 11:54:31 +00:00
|
|
|
|
2016-02-17 16:37:05 +00:00
|
|
|
LANGS = {
|
|
|
|
'fr': 'F',
|
|
|
|
'de': 'A',
|
|
|
|
'en': 'E[ANG]',
|
|
|
|
'es': 'E[ESP]',
|
2019-07-02 21:07:01 +00:00
|
|
|
'it': 'E[ITA]',
|
|
|
|
'pl': 'E[POL]',
|
2016-02-17 16:37:05 +00:00
|
|
|
}
|
|
|
|
|
2016-05-08 00:52:42 +00:00
|
|
|
langcode = LANGS.get(lang, lang)
|
|
|
|
|
2014-11-20 11:06:33 +00:00
|
|
|
formats = []
|
2017-08-17 17:58:23 +00:00
|
|
|
for format_id, format_dict in vsr.items():
|
2014-11-20 11:06:33 +00:00
|
|
|
f = dict(format_dict)
|
|
|
|
versionCode = f.get('versionCode')
|
2016-05-08 00:52:42 +00:00
|
|
|
l = re.escape(langcode)
|
|
|
|
|
|
|
|
# Language preference from most to least priority
|
2019-07-02 21:07:01 +00:00
|
|
|
# Reference: section 6.8 of
|
|
|
|
# https://www.arte.tv/sites/en/corporate/files/complete-technical-guidelines-arte-geie-v1-07-1.pdf
|
2016-05-08 00:52:42 +00:00
|
|
|
PREFERENCES = (
|
|
|
|
# original version in requested language, without subtitles
|
|
|
|
r'VO{0}$'.format(l),
|
|
|
|
# original version in requested language, with partial subtitles in requested language
|
|
|
|
r'VO{0}-ST{0}$'.format(l),
|
|
|
|
# original version in requested language, with subtitles for the deaf and hard-of-hearing in requested language
|
|
|
|
r'VO{0}-STM{0}$'.format(l),
|
|
|
|
# non-original (dubbed) version in requested language, without subtitles
|
|
|
|
r'V{0}$'.format(l),
|
|
|
|
# non-original (dubbed) version in requested language, with subtitles partial subtitles in requested language
|
|
|
|
r'V{0}-ST{0}$'.format(l),
|
|
|
|
# non-original (dubbed) version in requested language, with subtitles for the deaf and hard-of-hearing in requested language
|
|
|
|
r'V{0}-STM{0}$'.format(l),
|
|
|
|
# original version in requested language, with partial subtitles in different language
|
|
|
|
r'VO{0}-ST(?!{0}).+?$'.format(l),
|
|
|
|
# original version in requested language, with subtitles for the deaf and hard-of-hearing in different language
|
|
|
|
r'VO{0}-STM(?!{0}).+?$'.format(l),
|
|
|
|
# original version in different language, with partial subtitles in requested language
|
|
|
|
r'VO(?:(?!{0}).+?)?-ST{0}$'.format(l),
|
|
|
|
# original version in different language, with subtitles for the deaf and hard-of-hearing in requested language
|
|
|
|
r'VO(?:(?!{0}).+?)?-STM{0}$'.format(l),
|
|
|
|
# original version in different language, without subtitles
|
|
|
|
r'VO(?:(?!{0}))?$'.format(l),
|
|
|
|
# original version in different language, with partial subtitles in different language
|
|
|
|
r'VO(?:(?!{0}).+?)?-ST(?!{0}).+?$'.format(l),
|
|
|
|
# original version in different language, with subtitles for the deaf and hard-of-hearing in different language
|
|
|
|
r'VO(?:(?!{0}).+?)?-STM(?!{0}).+?$'.format(l),
|
|
|
|
)
|
|
|
|
|
|
|
|
for pref, p in enumerate(PREFERENCES):
|
|
|
|
if re.match(p, versionCode):
|
|
|
|
lang_pref = len(PREFERENCES) - pref
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
lang_pref = -1
|
|
|
|
|
2014-11-20 11:06:33 +00:00
|
|
|
format = {
|
|
|
|
'format_id': format_id,
|
|
|
|
'preference': -10 if f.get('videoFormat') == 'M3U8' else None,
|
|
|
|
'language_preference': lang_pref,
|
|
|
|
'format_note': '%s, %s' % (f.get('versionCode'), f.get('versionLibelle')),
|
|
|
|
'width': int_or_none(f.get('width')),
|
|
|
|
'height': int_or_none(f.get('height')),
|
|
|
|
'tbr': int_or_none(f.get('bitrate')),
|
2014-12-28 09:41:52 +00:00
|
|
|
'quality': qfunc(f.get('quality')),
|
2013-10-13 11:54:31 +00:00
|
|
|
}
|
2014-11-20 11:06:33 +00:00
|
|
|
|
|
|
|
if f.get('mediaType') == 'rtmp':
|
|
|
|
format['url'] = f['streamer']
|
|
|
|
format['play_path'] = 'mp4:' + f['url']
|
|
|
|
format['ext'] = 'flv'
|
2013-10-13 11:54:31 +00:00
|
|
|
else:
|
2014-11-20 11:06:33 +00:00
|
|
|
format['url'] = f['url']
|
|
|
|
|
|
|
|
formats.append(format)
|
|
|
|
|
2015-03-17 13:42:50 +00:00
|
|
|
self._check_formats(formats, video_id)
|
2014-11-20 11:06:33 +00:00
|
|
|
self._sort_formats(formats)
|
2013-10-13 11:54:31 +00:00
|
|
|
|
2014-11-20 11:06:33 +00:00
|
|
|
info_dict['formats'] = formats
|
2013-10-13 11:54:31 +00:00
|
|
|
return info_dict
|
|
|
|
|
|
|
|
|
2016-06-01 18:10:23 +00:00
|
|
|
class ArteTVPlus7IE(ArteTVBaseIE):
|
|
|
|
IE_NAME = 'arte.tv:+7'
|
2019-07-02 21:07:01 +00:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?arte\.tv/(?P<lang>fr|de|en|es|it|pl)/videos/(?P<id>\d{6}-\d{3}-[AF])'
|
2016-01-21 17:47:43 +00:00
|
|
|
|
2016-01-22 17:00:05 +00:00
|
|
|
_TESTS = [{
|
2019-07-02 21:07:01 +00:00
|
|
|
'url': 'https://www.arte.tv/en/videos/088501-000-A/mexico-stealing-petrol-to-survive/',
|
2016-01-22 17:00:05 +00:00
|
|
|
'info_dict': {
|
2019-07-02 21:07:01 +00:00
|
|
|
'id': '088501-000-A',
|
2016-01-22 17:00:05 +00:00
|
|
|
'ext': 'mp4',
|
2019-07-02 21:07:01 +00:00
|
|
|
'title': 'Mexico: Stealing Petrol to Survive',
|
|
|
|
'upload_date': '20190628',
|
2013-10-13 12:21:13 +00:00
|
|
|
},
|
2016-01-22 17:00:05 +00:00
|
|
|
}]
|
2013-12-08 13:02:14 +00:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2019-07-02 21:07:01 +00:00
|
|
|
lang, video_id = re.match(self._VALID_URL, url).groups()
|
|
|
|
return self._extract_from_json_url(
|
|
|
|
'https://api.arte.tv/api/player/v1/config/%s/%s' % (lang, video_id),
|
|
|
|
video_id, lang)
|
2016-02-08 21:17:21 +00:00
|
|
|
|
|
|
|
|
2014-03-24 21:01:47 +00:00
|
|
|
class ArteTVEmbedIE(ArteTVPlus7IE):
|
|
|
|
IE_NAME = 'arte.tv:embed'
|
|
|
|
_VALID_URL = r'''(?x)
|
2019-07-02 21:07:01 +00:00
|
|
|
https://www\.arte\.tv
|
|
|
|
/player/v3/index\.php\?json_url=
|
2014-03-24 21:01:47 +00:00
|
|
|
(?P<json_url>
|
2019-07-02 21:07:01 +00:00
|
|
|
https?://api\.arte\.tv/api/player/v1/config/
|
|
|
|
(?P<lang>[^/]+)/(?P<id>\d{6}-\d{3}-[AF])
|
2014-03-24 21:01:47 +00:00
|
|
|
)
|
|
|
|
'''
|
|
|
|
|
2016-06-01 18:10:23 +00:00
|
|
|
_TESTS = []
|
|
|
|
|
2014-03-24 21:01:47 +00:00
|
|
|
def _real_extract(self, url):
|
2019-07-02 21:07:01 +00:00
|
|
|
json_url, lang, video_id = re.match(self._VALID_URL, url).groups()
|
2014-03-24 21:01:47 +00:00
|
|
|
return self._extract_from_json_url(json_url, video_id, lang)
|
2016-10-15 17:24:06 +00:00
|
|
|
|
|
|
|
|
2016-06-01 18:10:23 +00:00
|
|
|
class ArteTVPlaylistIE(ArteTVBaseIE):
|
|
|
|
IE_NAME = 'arte.tv:playlist'
|
2019-07-02 21:07:01 +00:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?arte\.tv/(?P<lang>fr|de|en|es|it|pl)/videos/(?P<id>RC-\d{6})'
|
2016-06-01 18:10:23 +00:00
|
|
|
|
|
|
|
_TESTS = [{
|
2019-07-02 21:07:01 +00:00
|
|
|
'url': 'https://www.arte.tv/en/videos/RC-016954/earn-a-living/',
|
2016-06-01 18:10:23 +00:00
|
|
|
'info_dict': {
|
2019-07-02 21:07:01 +00:00
|
|
|
'id': 'RC-016954',
|
|
|
|
'title': 'Earn a Living',
|
|
|
|
'description': 'md5:d322c55011514b3a7241f7fb80d494c2',
|
2016-06-01 18:10:23 +00:00
|
|
|
},
|
|
|
|
'playlist_mincount': 6,
|
|
|
|
}]
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2019-07-02 21:07:01 +00:00
|
|
|
lang, playlist_id = re.match(self._VALID_URL, url).groups()
|
2016-06-01 18:10:23 +00:00
|
|
|
collection = self._download_json(
|
|
|
|
'https://api.arte.tv/api/player/v1/collectionData/%s/%s?source=videos'
|
|
|
|
% (lang, playlist_id), playlist_id)
|
|
|
|
title = collection.get('title')
|
|
|
|
description = collection.get('shortDescription') or collection.get('teaserText')
|
|
|
|
entries = [
|
|
|
|
self._extract_from_json_url(
|
|
|
|
video['jsonUrl'], video.get('programId') or playlist_id, lang)
|
|
|
|
for video in collection['videos'] if video.get('jsonUrl')]
|
|
|
|
return self.playlist_result(entries, playlist_id, title, description)
|