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.

101 lines
3.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. determine_ext,
  8. parse_age_limit,
  9. )
  10. class GoIE(InfoExtractor):
  11. _BRANDS = {
  12. 'abc': '001',
  13. 'freeform': '002',
  14. 'watchdisneychannel': '004',
  15. 'watchdisneyjunior': '008',
  16. 'watchdisneyxd': '009',
  17. }
  18. _VALID_URL = r'https?://(?:(?P<sub_domain>%s)\.)?go\.com/.*?vdka(?P<id>\w+)' % '|'.join(_BRANDS.keys())
  19. _TESTS = [{
  20. 'url': 'http://abc.go.com/shows/castle/video/most-recent/vdka0_g86w5onx',
  21. 'info_dict': {
  22. 'id': '0_g86w5onx',
  23. 'ext': 'mp4',
  24. 'title': 'Sneak Peek: Language Arts',
  25. 'description': 'md5:7dcdab3b2d17e5217c953256af964e9c',
  26. },
  27. 'params': {
  28. # m3u8 download
  29. 'skip_download': True,
  30. },
  31. }, {
  32. 'url': 'http://abc.go.com/shows/after-paradise/video/most-recent/vdka3335601',
  33. 'only_matching': True,
  34. }]
  35. def _real_extract(self, url):
  36. sub_domain, video_id = re.match(self._VALID_URL, url).groups()
  37. video_data = self._download_json(
  38. 'http://api.contents.watchabc.go.com/vp2/ws/contents/3000/videos/%s/001/-1/-1/-1/%s/-1/-1.json' % (self._BRANDS[sub_domain], video_id),
  39. video_id)['video'][0]
  40. title = video_data['title']
  41. formats = []
  42. for asset in video_data.get('assets', {}).get('asset', []):
  43. asset_url = asset.get('value')
  44. if not asset_url:
  45. continue
  46. format_id = asset.get('format')
  47. ext = determine_ext(asset_url)
  48. if ext == 'm3u8':
  49. formats.extend(self._extract_m3u8_formats(
  50. asset_url, video_id, 'mp4', m3u8_id=format_id or 'hls', fatal=False))
  51. else:
  52. formats.append({
  53. 'format_id': format_id,
  54. 'url': asset_url,
  55. 'ext': ext,
  56. })
  57. self._sort_formats(formats)
  58. subtitles = {}
  59. for cc in video_data.get('closedcaption', {}).get('src', []):
  60. cc_url = cc.get('value')
  61. if not cc_url:
  62. continue
  63. ext = determine_ext(cc_url)
  64. if ext == 'xml':
  65. ext = 'ttml'
  66. subtitles.setdefault(cc.get('lang'), []).append({
  67. 'url': cc_url,
  68. 'ext': ext,
  69. })
  70. thumbnails = []
  71. for thumbnail in video_data.get('thumbnails', {}).get('thumbnail', []):
  72. thumbnail_url = thumbnail.get('value')
  73. if not thumbnail_url:
  74. continue
  75. thumbnails.append({
  76. 'url': thumbnail_url,
  77. 'width': int_or_none(thumbnail.get('width')),
  78. 'height': int_or_none(thumbnail.get('height')),
  79. })
  80. return {
  81. 'id': video_id,
  82. 'title': title,
  83. 'description': video_data.get('longdescription') or video_data.get('description'),
  84. 'duration': int_or_none(video_data.get('duration', {}).get('value'), 1000),
  85. 'age_limit': parse_age_limit(video_data.get('tvrating', {}).get('rating')),
  86. 'episode_number': int_or_none(video_data.get('episodenumber')),
  87. 'series': video_data.get('show', {}).get('title'),
  88. 'season_number': int_or_none(video_data.get('season', {}).get('num')),
  89. 'thumbnails': thumbnails,
  90. 'formats': formats,
  91. 'subtitles': subtitles,
  92. }