logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

byutv.py (4172B)


  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. merge_dicts,
  7. parse_duration,
  8. url_or_none,
  9. )
  10. class BYUtvIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?byutv\.org/(?:watch|player)/(?!event/)(?P<id>[0-9a-f-]+)(?:/(?P<display_id>[^/?#&]+))?'
  12. _TESTS = [{
  13. # ooyalaVOD
  14. 'url': 'http://www.byutv.org/watch/6587b9a3-89d2-42a6-a7f7-fd2f81840a7d/studio-c-season-5-episode-5',
  15. 'info_dict': {
  16. 'id': 'ZvanRocTpW-G5_yZFeltTAMv6jxOU9KH',
  17. 'display_id': 'studio-c-season-5-episode-5',
  18. 'ext': 'mp4',
  19. 'title': 'Season 5 Episode 5',
  20. 'description': 'md5:1d31dc18ef4f075b28f6a65937d22c65',
  21. 'thumbnail': r're:^https?://.*',
  22. 'duration': 1486.486,
  23. },
  24. 'params': {
  25. 'skip_download': True,
  26. },
  27. 'add_ie': ['Ooyala'],
  28. }, {
  29. # dvr
  30. 'url': 'https://www.byutv.org/player/8f1dab9b-b243-47c8-b525-3e2d021a3451/byu-softball-pacific-vs-byu-41219---game-2',
  31. 'info_dict': {
  32. 'id': '8f1dab9b-b243-47c8-b525-3e2d021a3451',
  33. 'display_id': 'byu-softball-pacific-vs-byu-41219---game-2',
  34. 'ext': 'mp4',
  35. 'title': 'Pacific vs. BYU (4/12/19)',
  36. 'description': 'md5:1ac7b57cb9a78015910a4834790ce1f3',
  37. 'duration': 11645,
  38. },
  39. 'params': {
  40. 'skip_download': True
  41. },
  42. }, {
  43. 'url': 'http://www.byutv.org/watch/6587b9a3-89d2-42a6-a7f7-fd2f81840a7d',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'https://www.byutv.org/player/27741493-dc83-40b0-8420-e7ae38a2ae98/byu-football-toledo-vs-byu-93016?listid=4fe0fee5-0d3c-4a29-b725-e4948627f472&listindex=0&q=toledo',
  47. 'only_matching': True,
  48. }]
  49. def _real_extract(self, url):
  50. mobj = re.match(self._VALID_URL, url)
  51. video_id = mobj.group('id')
  52. display_id = mobj.group('display_id') or video_id
  53. video = self._download_json(
  54. 'https://api.byutv.org/api3/catalog/getvideosforcontent',
  55. display_id, query={
  56. 'contentid': video_id,
  57. 'channel': 'byutv',
  58. 'x-byutv-context': 'web$US',
  59. }, headers={
  60. 'x-byutv-context': 'web$US',
  61. 'x-byutv-platformkey': 'xsaaw9c7y5',
  62. })
  63. ep = video.get('ooyalaVOD')
  64. if ep:
  65. return {
  66. '_type': 'url_transparent',
  67. 'ie_key': 'Ooyala',
  68. 'url': 'ooyala:%s' % ep['providerId'],
  69. 'id': video_id,
  70. 'display_id': display_id,
  71. 'title': ep.get('title'),
  72. 'description': ep.get('description'),
  73. 'thumbnail': ep.get('imageThumbnail'),
  74. }
  75. info = {}
  76. formats = []
  77. for format_id, ep in video.items():
  78. if not isinstance(ep, dict):
  79. continue
  80. video_url = url_or_none(ep.get('videoUrl'))
  81. if not video_url:
  82. continue
  83. ext = determine_ext(video_url)
  84. if ext == 'm3u8':
  85. formats.extend(self._extract_m3u8_formats(
  86. video_url, video_id, 'mp4', entry_protocol='m3u8_native',
  87. m3u8_id='hls', fatal=False))
  88. elif ext == 'mpd':
  89. formats.extend(self._extract_mpd_formats(
  90. video_url, video_id, mpd_id='dash', fatal=False))
  91. else:
  92. formats.append({
  93. 'url': video_url,
  94. 'format_id': format_id,
  95. })
  96. merge_dicts(info, {
  97. 'title': ep.get('title'),
  98. 'description': ep.get('description'),
  99. 'thumbnail': ep.get('imageThumbnail'),
  100. 'duration': parse_duration(ep.get('length')),
  101. })
  102. self._sort_formats(formats)
  103. return merge_dicts(info, {
  104. 'id': video_id,
  105. 'display_id': display_id,
  106. 'title': display_id,
  107. 'formats': formats,
  108. })