logo

youtube-dl

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

teamcoco.py (7310B)


  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?://(?:\w+\.)?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. 'url': 'https://conan25.teamcoco.com/video/ice-cube-kevin-hart-conan-share-lyft',
  80. 'only_matching': True,
  81. }
  82. ]
  83. _RECORD_TEMPL = '''id
  84. title
  85. teaser
  86. publishOn
  87. thumb {
  88. preview
  89. }
  90. tags {
  91. name
  92. }
  93. duration
  94. turnerMediaId
  95. turnerMediaAuthToken'''
  96. def _graphql_call(self, query_template, object_type, object_id):
  97. find_object = 'find' + object_type
  98. return self._download_json(
  99. 'https://teamcoco.com/graphql', object_id, data=json.dumps({
  100. 'query': query_template % (find_object, object_id)
  101. }).encode(), headers={
  102. 'Content-Type': 'application/json',
  103. })['data'][find_object]
  104. def _real_extract(self, url):
  105. display_id = self._match_id(url)
  106. response = self._graphql_call('''{
  107. %%s(slug: "%%s") {
  108. ... on RecordSlug {
  109. record {
  110. %s
  111. }
  112. }
  113. ... on PageSlug {
  114. child {
  115. id
  116. }
  117. }
  118. ... on NotFoundSlug {
  119. status
  120. }
  121. }
  122. }''' % self._RECORD_TEMPL, 'Slug', display_id)
  123. if response.get('status'):
  124. raise ExtractorError('This video is no longer available.', expected=True)
  125. child = response.get('child')
  126. if child:
  127. record = self._graphql_call('''{
  128. %%s(id: "%%s") {
  129. ... on Video {
  130. %s
  131. }
  132. }
  133. }''' % self._RECORD_TEMPL, 'Record', child['id'])
  134. else:
  135. record = response['record']
  136. video_id = record['id']
  137. info = {
  138. 'id': video_id,
  139. 'display_id': display_id,
  140. 'title': record['title'],
  141. 'thumbnail': record.get('thumb', {}).get('preview'),
  142. 'description': record.get('teaser'),
  143. 'duration': parse_duration(record.get('duration')),
  144. 'timestamp': parse_iso8601(record.get('publishOn')),
  145. }
  146. media_id = record.get('turnerMediaId')
  147. if media_id:
  148. self._initialize_geo_bypass({
  149. 'countries': ['US'],
  150. })
  151. info.update(self._extract_ngtv_info(media_id, {
  152. 'accessToken': record['turnerMediaAuthToken'],
  153. 'accessTokenType': 'jws',
  154. }))
  155. else:
  156. video_sources = self._download_json(
  157. 'https://teamcoco.com/_truman/d/' + video_id,
  158. video_id)['meta']['src']
  159. if isinstance(video_sources, dict):
  160. video_sources = video_sources.values()
  161. formats = []
  162. get_quality = qualities(['low', 'sd', 'hd', 'uhd'])
  163. for src in video_sources:
  164. if not isinstance(src, dict):
  165. continue
  166. src_url = src.get('src')
  167. if not src_url:
  168. continue
  169. format_id = src.get('label')
  170. ext = determine_ext(src_url, mimetype2ext(src.get('type')))
  171. if format_id == 'hls' or ext == 'm3u8':
  172. # compat_urllib_parse.urljoin does not work here
  173. if src_url.startswith('/'):
  174. src_url = 'http://ht.cdn.turner.com/tbs/big/teamcoco' + src_url
  175. formats.extend(self._extract_m3u8_formats(
  176. src_url, video_id, 'mp4', m3u8_id=format_id, fatal=False))
  177. else:
  178. if src_url.startswith('/mp4:protected/'):
  179. # TODO Correct extraction for these files
  180. continue
  181. tbr = int_or_none(self._search_regex(
  182. r'(\d+)k\.mp4', src_url, 'tbr', default=None))
  183. formats.append({
  184. 'url': src_url,
  185. 'ext': ext,
  186. 'tbr': tbr,
  187. 'format_id': format_id,
  188. 'quality': get_quality(format_id),
  189. })
  190. self._sort_formats(formats)
  191. info['formats'] = formats
  192. return info