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.

189 lines
6.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. from .turner import TurnerBaseIE
  5. from ..utils import (
  6. determine_ext,
  7. ExtractorError,
  8. int_or_none,
  9. mimetype2ext,
  10. parse_duration,
  11. parse_iso8601,
  12. qualities,
  13. )
  14. class TeamcocoIE(TurnerBaseIE):
  15. _VALID_URL = r'https?://teamcoco\.com/(?P<id>([^/]+/)*[^/?#]+)'
  16. _TESTS = [
  17. {
  18. 'url': 'http://teamcoco.com/video/mary-kay-remote',
  19. 'md5': '55d532f81992f5c92046ad02fec34d7d',
  20. 'info_dict': {
  21. 'id': '80187',
  22. 'ext': 'mp4',
  23. 'title': 'Conan Becomes A Mary Kay Beauty Consultant',
  24. 'description': 'Mary Kay is perhaps the most trusted name in female beauty, so of course Conan is a natural choice to sell their products.',
  25. 'duration': 495.0,
  26. 'upload_date': '20140402',
  27. 'timestamp': 1396407600,
  28. }
  29. }, {
  30. 'url': 'http://teamcoco.com/video/louis-ck-interview-george-w-bush',
  31. 'md5': 'cde9ba0fa3506f5f017ce11ead928f9a',
  32. 'info_dict': {
  33. 'id': '19705',
  34. 'ext': 'mp4',
  35. 'description': 'Louis C.K. got starstruck by George W. Bush, so what? Part one.',
  36. 'title': 'Louis C.K. Interview Pt. 1 11/3/11',
  37. 'duration': 288,
  38. 'upload_date': '20111104',
  39. 'timestamp': 1320405840,
  40. }
  41. }, {
  42. 'url': 'http://teamcoco.com/video/timothy-olyphant-drinking-whiskey',
  43. 'info_dict': {
  44. 'id': '88748',
  45. 'ext': 'mp4',
  46. 'title': 'Timothy Olyphant Raises A Toast To “Justified”',
  47. 'description': 'md5:15501f23f020e793aeca761205e42c24',
  48. 'upload_date': '20150415',
  49. 'timestamp': 1429088400,
  50. },
  51. 'params': {
  52. 'skip_download': True, # m3u8 downloads
  53. }
  54. }, {
  55. 'url': 'http://teamcoco.com/video/full-episode-mon-6-1-joel-mchale-jake-tapper-and-musical-guest-courtney-barnett?playlist=x;eyJ0eXBlIjoidGFnIiwiaWQiOjl9',
  56. 'info_dict': {
  57. 'id': '89341',
  58. 'ext': 'mp4',
  59. 'title': 'Full Episode - Mon. 6/1 - Joel McHale, Jake Tapper, And Musical Guest Courtney Barnett',
  60. 'description': 'Guests: Joel McHale, Jake Tapper, And Musical Guest Courtney Barnett',
  61. },
  62. 'params': {
  63. 'skip_download': True, # m3u8 downloads
  64. },
  65. 'skip': 'This video is no longer available.',
  66. }, {
  67. 'url': 'http://teamcoco.com/video/the-conan-audiencey-awards-for-04/25/18',
  68. 'only_matching': True,
  69. }, {
  70. 'url': 'http://teamcoco.com/italy/conan-jordan-schlansky-hit-the-streets-of-florence',
  71. 'only_matching': True,
  72. }, {
  73. 'url': 'http://teamcoco.com/haiti/conan-s-haitian-history-lesson',
  74. 'only_matching': True,
  75. }, {
  76. 'url': 'http://teamcoco.com/israel/conan-hits-the-streets-beaches-of-tel-aviv',
  77. 'only_matching': True,
  78. }
  79. ]
  80. def _graphql_call(self, query_template, object_type, object_id):
  81. find_object = 'find' + object_type
  82. return self._download_json(
  83. 'http://teamcoco.com/graphql/', object_id, data=json.dumps({
  84. 'query': query_template % (find_object, object_id)
  85. }))['data'][find_object]
  86. def _real_extract(self, url):
  87. display_id = self._match_id(url)
  88. response = self._graphql_call('''{
  89. %s(slug: "%s") {
  90. ... on RecordSlug {
  91. record {
  92. id
  93. title
  94. teaser
  95. publishOn
  96. thumb {
  97. preview
  98. }
  99. file {
  100. url
  101. }
  102. tags {
  103. name
  104. }
  105. duration
  106. turnerMediaId
  107. turnerMediaAuthToken
  108. }
  109. }
  110. ... on NotFoundSlug {
  111. status
  112. }
  113. }
  114. }''', 'Slug', display_id)
  115. if response.get('status'):
  116. raise ExtractorError('This video is no longer available.', expected=True)
  117. record = response['record']
  118. video_id = record['id']
  119. info = {
  120. 'id': video_id,
  121. 'display_id': display_id,
  122. 'title': record['title'],
  123. 'thumbnail': record.get('thumb', {}).get('preview'),
  124. 'description': record.get('teaser'),
  125. 'duration': parse_duration(record.get('duration')),
  126. 'timestamp': parse_iso8601(record.get('publishOn')),
  127. }
  128. media_id = record.get('turnerMediaId')
  129. if media_id:
  130. self._initialize_geo_bypass({
  131. 'countries': ['US'],
  132. })
  133. info.update(self._extract_ngtv_info(media_id, {
  134. 'accessToken': record['turnerMediaAuthToken'],
  135. 'accessTokenType': 'jws',
  136. }))
  137. else:
  138. video_sources = self._graphql_call('''{
  139. %s(id: "%s") {
  140. src
  141. }
  142. }''', 'RecordVideoSource', video_id) or {}
  143. formats = []
  144. get_quality = qualities(['low', 'sd', 'hd', 'uhd'])
  145. for format_id, src in video_sources.get('src', {}).items():
  146. if not isinstance(src, dict):
  147. continue
  148. src_url = src.get('src')
  149. if not src_url:
  150. continue
  151. ext = determine_ext(src_url, mimetype2ext(src.get('type')))
  152. if format_id == 'hls' or ext == 'm3u8':
  153. # compat_urllib_parse.urljoin does not work here
  154. if src_url.startswith('/'):
  155. src_url = 'http://ht.cdn.turner.com/tbs/big/teamcoco' + src_url
  156. formats.extend(self._extract_m3u8_formats(
  157. src_url, video_id, 'mp4', m3u8_id=format_id, fatal=False))
  158. else:
  159. if src_url.startswith('/mp4:protected/'):
  160. # TODO Correct extraction for these files
  161. continue
  162. tbr = int_or_none(self._search_regex(
  163. r'(\d+)k\.mp4', src_url, 'tbr', default=None))
  164. formats.append({
  165. 'url': src_url,
  166. 'ext': ext,
  167. 'tbr': tbr,
  168. 'format_id': format_id,
  169. 'quality': get_quality(format_id),
  170. })
  171. if not formats:
  172. formats = self._extract_m3u8_formats(
  173. record['file']['url'], video_id, 'mp4', fatal=False)
  174. self._sort_formats(formats)
  175. info['formats'] = formats
  176. return info