]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/azmedien.py
New upstream version 2019.09.01
[youtubedl] / youtube_dl / extractor / azmedien.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import json
5 import re
6
7 from .common import InfoExtractor
8 from .kaltura import KalturaIE
9
10
11 class AZMedienIE(InfoExtractor):
12 IE_DESC = 'AZ Medien videos'
13 _VALID_URL = r'''(?x)
14 https?://
15 (?:www\.)?
16 (?P<host>
17 telezueri\.ch|
18 telebaern\.tv|
19 telem1\.ch
20 )/
21 [^/]+/
22 (?P<id>
23 [^/]+-(?P<article_id>\d+)
24 )
25 (?:
26 \#video=
27 (?P<kaltura_id>
28 [_0-9a-z]+
29 )
30 )?
31 '''
32
33 _TESTS = [{
34 'url': 'https://www.telezueri.ch/sonntalk/bundesrats-vakanzen-eu-rahmenabkommen-133214569',
35 'info_dict': {
36 'id': '1_anruz3wy',
37 'ext': 'mp4',
38 'title': 'Bundesrats-Vakanzen / EU-Rahmenabkommen',
39 'uploader_id': 'TVOnline',
40 'upload_date': '20180930',
41 'timestamp': 1538328802,
42 },
43 'params': {
44 'skip_download': True,
45 },
46 }, {
47 'url': 'https://www.telebaern.tv/telebaern-news/montag-1-oktober-2018-ganze-sendung-133531189#video=0_7xjo9lf1',
48 'only_matching': True
49 }]
50
51 _PARTNER_ID = '1719221'
52
53 def _real_extract(self, url):
54 mobj = re.match(self._VALID_URL, url)
55 host = mobj.group('host')
56 video_id = mobj.group('id')
57 entry_id = mobj.group('kaltura_id')
58
59 if not entry_id:
60 api_url = 'https://www.%s/api/pub/gql/%s' % (host, host.split('.')[0])
61 payload = {
62 'query': '''query VideoContext($articleId: ID!) {
63 article: node(id: $articleId) {
64 ... on Article {
65 mainAssetRelation {
66 asset {
67 ... on VideoAsset {
68 kalturaId
69 }
70 }
71 }
72 }
73 }
74 }''',
75 'variables': {'articleId': 'Article:%s' % mobj.group('article_id')},
76 }
77 json_data = self._download_json(
78 api_url, video_id, headers={
79 'Content-Type': 'application/json',
80 },
81 data=json.dumps(payload).encode())
82 entry_id = json_data['data']['article']['mainAssetRelation']['asset']['kalturaId']
83
84 return self.url_result(
85 'kaltura:%s:%s' % (self._PARTNER_ID, entry_id),
86 ie=KalturaIE.ie_key(), video_id=entry_id)