You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.8 KiB

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