brightcove.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. from .common import InfoExtractor
  6. from ..compat import (
  7. compat_etree_fromstring,
  8. compat_parse_qs,
  9. compat_str,
  10. compat_urllib_parse,
  11. compat_urllib_parse_urlparse,
  12. compat_urlparse,
  13. compat_xml_parse_error,
  14. compat_HTTPError,
  15. )
  16. from ..utils import (
  17. determine_ext,
  18. ExtractorError,
  19. find_xpath_attr,
  20. fix_xml_ampersands,
  21. float_or_none,
  22. js_to_json,
  23. int_or_none,
  24. parse_iso8601,
  25. unescapeHTML,
  26. unsmuggle_url,
  27. update_url_query,
  28. )
  29. class BrightcoveLegacyIE(InfoExtractor):
  30. IE_NAME = 'brightcove:legacy'
  31. _VALID_URL = r'(?:https?://.*brightcove\.com/(services|viewer).*?\?|brightcove:)(?P<query>.*)'
  32. _FEDERATED_URL = 'http://c.brightcove.com/services/viewer/htmlFederated'
  33. _TESTS = [
  34. {
  35. # From http://www.8tv.cat/8aldia/videos/xavier-sala-i-martin-aquesta-tarda-a-8-al-dia/
  36. 'url': 'http://c.brightcove.com/services/viewer/htmlFederated?playerID=1654948606001&flashID=myExperience&%40videoPlayer=2371591881001',
  37. 'md5': '5423e113865d26e40624dce2e4b45d95',
  38. 'note': 'Test Brightcove downloads and detection in GenericIE',
  39. 'info_dict': {
  40. 'id': '2371591881001',
  41. 'ext': 'mp4',
  42. 'title': 'Xavier Sala i Martín: “Un banc que no presta és un banc zombi que no serveix per a res”',
  43. 'uploader': '8TV',
  44. 'description': 'md5:a950cc4285c43e44d763d036710cd9cd',
  45. }
  46. },
  47. {
  48. # From http://medianetwork.oracle.com/video/player/1785452137001
  49. 'url': 'http://c.brightcove.com/services/viewer/htmlFederated?playerID=1217746023001&flashID=myPlayer&%40videoPlayer=1785452137001',
  50. 'info_dict': {
  51. 'id': '1785452137001',
  52. 'ext': 'flv',
  53. 'title': 'JVMLS 2012: Arrays 2.0 - Opportunities and Challenges',
  54. 'description': 'John Rose speaks at the JVM Language Summit, August 1, 2012.',
  55. 'uploader': 'Oracle',
  56. },
  57. },
  58. {
  59. # From http://mashable.com/2013/10/26/thermoelectric-bracelet-lets-you-control-your-body-temperature/
  60. 'url': 'http://c.brightcove.com/services/viewer/federated_f9?&playerID=1265504713001&publisherID=AQ%7E%7E%2CAAABBzUwv1E%7E%2CxP-xFHVUstiMFlNYfvF4G9yFnNaqCw_9&videoID=2750934548001',
  61. 'info_dict': {
  62. 'id': '2750934548001',
  63. 'ext': 'mp4',
  64. 'title': 'This Bracelet Acts as a Personal Thermostat',
  65. 'description': 'md5:547b78c64f4112766ccf4e151c20b6a0',
  66. 'uploader': 'Mashable',
  67. },
  68. },
  69. {
  70. # test that the default referer works
  71. # from http://national.ballet.ca/interact/video/Lost_in_Motion_II/
  72. 'url': 'http://link.brightcove.com/services/player/bcpid756015033001?bckey=AQ~~,AAAApYJi_Ck~,GxhXCegT1Dp39ilhXuxMJxasUhVNZiil&bctid=2878862109001',
  73. 'info_dict': {
  74. 'id': '2878862109001',
  75. 'ext': 'mp4',
  76. 'title': 'Lost in Motion II',
  77. 'description': 'md5:363109c02998fee92ec02211bd8000df',
  78. 'uploader': 'National Ballet of Canada',
  79. },
  80. },
  81. {
  82. # test flv videos served by akamaihd.net
  83. # From http://www.redbull.com/en/bike/stories/1331655643987/replay-uci-dh-world-cup-2014-from-fort-william
  84. 'url': 'http://c.brightcove.com/services/viewer/htmlFederated?%40videoPlayer=ref%3ABC2996102916001&linkBaseURL=http%3A%2F%2Fwww.redbull.com%2Fen%2Fbike%2Fvideos%2F1331655630249%2Freplay-uci-fort-william-2014-dh&playerKey=AQ%7E%7E%2CAAAApYJ7UqE%7E%2Cxqr_zXk0I-zzNndy8NlHogrCb5QdyZRf&playerID=1398061561001#__youtubedl_smuggle=%7B%22Referer%22%3A+%22http%3A%2F%2Fwww.redbull.com%2Fen%2Fbike%2Fstories%2F1331655643987%2Freplay-uci-dh-world-cup-2014-from-fort-william%22%7D',
  85. # The md5 checksum changes on each download
  86. 'info_dict': {
  87. 'id': '2996102916001',
  88. 'ext': 'flv',
  89. 'title': 'UCI MTB World Cup 2014: Fort William, UK - Downhill Finals',
  90. 'uploader': 'Red Bull TV',
  91. 'description': 'UCI MTB World Cup 2014: Fort William, UK - Downhill Finals',
  92. },
  93. },
  94. {
  95. # playlist test
  96. # from http://support.brightcove.com/en/video-cloud/docs/playlist-support-single-video-players
  97. 'url': 'http://c.brightcove.com/services/viewer/htmlFederated?playerID=3550052898001&playerKey=AQ%7E%7E%2CAAABmA9XpXk%7E%2C-Kp7jNgisre1fG5OdqpAFUTcs0lP_ZoL',
  98. 'info_dict': {
  99. 'title': 'Sealife',
  100. 'id': '3550319591001',
  101. },
  102. 'playlist_mincount': 7,
  103. },
  104. ]
  105. @classmethod
  106. def _build_brighcove_url(cls, object_str):
  107. """
  108. Build a Brightcove url from a xml string containing
  109. <object class="BrightcoveExperience">{params}</object>
  110. """
  111. # Fix up some stupid HTML, see https://github.com/rg3/youtube-dl/issues/1553
  112. object_str = re.sub(r'(<param(?:\s+[a-zA-Z0-9_]+="[^"]*")*)>',
  113. lambda m: m.group(1) + '/>', object_str)
  114. # Fix up some stupid XML, see https://github.com/rg3/youtube-dl/issues/1608
  115. object_str = object_str.replace('<--', '<!--')
  116. # remove namespace to simplify extraction
  117. object_str = re.sub(r'(<object[^>]*)(xmlns=".*?")', r'\1', object_str)
  118. object_str = fix_xml_ampersands(object_str)
  119. try:
  120. object_doc = compat_etree_fromstring(object_str.encode('utf-8'))
  121. except compat_xml_parse_error:
  122. return
  123. fv_el = find_xpath_attr(object_doc, './param', 'name', 'flashVars')
  124. if fv_el is not None:
  125. flashvars = dict(
  126. (k, v[0])
  127. for k, v in compat_parse_qs(fv_el.attrib['value']).items())
  128. else:
  129. flashvars = {}
  130. def find_param(name):
  131. if name in flashvars:
  132. return flashvars[name]
  133. node = find_xpath_attr(object_doc, './param', 'name', name)
  134. if node is not None:
  135. return node.attrib['value']
  136. return None
  137. params = {}
  138. playerID = find_param('playerID')
  139. if playerID is None:
  140. raise ExtractorError('Cannot find player ID')
  141. params['playerID'] = playerID
  142. playerKey = find_param('playerKey')
  143. # Not all pages define this value
  144. if playerKey is not None:
  145. params['playerKey'] = playerKey
  146. # These fields hold the id of the video
  147. videoPlayer = find_param('@videoPlayer') or find_param('videoId') or find_param('videoID') or find_param('@videoList')
  148. if videoPlayer is not None:
  149. params['@videoPlayer'] = videoPlayer
  150. linkBase = find_param('linkBaseURL')
  151. if linkBase is not None:
  152. params['linkBaseURL'] = linkBase
  153. return cls._make_brightcove_url(params)
  154. @classmethod
  155. def _build_brighcove_url_from_js(cls, object_js):
  156. # The layout of JS is as follows:
  157. # customBC.createVideo = function (width, height, playerID, playerKey, videoPlayer, VideoRandomID) {
  158. # // build Brightcove <object /> XML
  159. # }
  160. m = re.search(
  161. r'''(?x)customBC.\createVideo\(
  162. .*? # skipping width and height
  163. ["\'](?P<playerID>\d+)["\']\s*,\s* # playerID
  164. ["\'](?P<playerKey>AQ[^"\']{48})[^"\']*["\']\s*,\s* # playerKey begins with AQ and is 50 characters
  165. # in length, however it's appended to itself
  166. # in places, so truncate
  167. ["\'](?P<videoID>\d+)["\'] # @videoPlayer
  168. ''', object_js)
  169. if m:
  170. return cls._make_brightcove_url(m.groupdict())
  171. @classmethod
  172. def _make_brightcove_url(cls, params):
  173. return update_url_query(cls._FEDERATED_URL, params)
  174. @classmethod
  175. def _extract_brightcove_url(cls, webpage):
  176. """Try to extract the brightcove url from the webpage, returns None
  177. if it can't be found
  178. """
  179. urls = cls._extract_brightcove_urls(webpage)
  180. return urls[0] if urls else None
  181. @classmethod
  182. def _extract_brightcove_urls(cls, webpage):
  183. """Return a list of all Brightcove URLs from the webpage """
  184. url_m = re.search(
  185. r'<meta\s+property=[\'"]og:video[\'"]\s+content=[\'"](https?://(?:secure|c)\.brightcove.com/[^\'"]+)[\'"]',
  186. webpage)
  187. if url_m:
  188. url = unescapeHTML(url_m.group(1))
  189. # Some sites don't add it, we can't download with this url, for example:
  190. # http://www.ktvu.com/videos/news/raw-video-caltrain-releases-video-of-man-almost/vCTZdY/
  191. if 'playerKey' in url or 'videoId' in url:
  192. return [url]
  193. matches = re.findall(
  194. r'''(?sx)<object
  195. (?:
  196. [^>]+?class=[\'"][^>]*?BrightcoveExperience.*?[\'"] |
  197. [^>]*?>\s*<param\s+name="movie"\s+value="https?://[^/]*brightcove\.com/
  198. ).+?>\s*</object>''',
  199. webpage)
  200. if matches:
  201. return list(filter(None, [cls._build_brighcove_url(m) for m in matches]))
  202. return list(filter(None, [
  203. cls._build_brighcove_url_from_js(custom_bc)
  204. for custom_bc in re.findall(r'(customBC\.createVideo\(.+?\);)', webpage)]))
  205. def _real_extract(self, url):
  206. url, smuggled_data = unsmuggle_url(url, {})
  207. # Change the 'videoId' and others field to '@videoPlayer'
  208. url = re.sub(r'(?<=[?&])(videoI(d|D)|bctid)', '%40videoPlayer', url)
  209. # Change bckey (used by bcove.me urls) to playerKey
  210. url = re.sub(r'(?<=[?&])bckey', 'playerKey', url)
  211. mobj = re.match(self._VALID_URL, url)
  212. query_str = mobj.group('query')
  213. query = compat_urlparse.parse_qs(query_str)
  214. videoPlayer = query.get('@videoPlayer')
  215. if videoPlayer:
  216. # We set the original url as the default 'Referer' header
  217. referer = smuggled_data.get('Referer', url)
  218. return self._get_video_info(
  219. videoPlayer[0], query, referer=referer)
  220. elif 'playerKey' in query:
  221. player_key = query['playerKey']
  222. return self._get_playlist_info(player_key[0])
  223. else:
  224. raise ExtractorError(
  225. 'Cannot find playerKey= variable. Did you forget quotes in a shell invocation?',
  226. expected=True)
  227. def _get_video_info(self, video_id, query, referer=None):
  228. headers = {}
  229. linkBase = query.get('linkBaseURL')
  230. if linkBase is not None:
  231. referer = linkBase[0]
  232. if referer is not None:
  233. headers['Referer'] = referer
  234. webpage = self._download_webpage(self._FEDERATED_URL, video_id, headers=headers, query=query)
  235. error_msg = self._html_search_regex(
  236. r"<h1>We're sorry.</h1>([\s\n]*<p>.*?</p>)+", webpage,
  237. 'error message', default=None)
  238. if error_msg is not None:
  239. raise ExtractorError(
  240. 'brightcove said: %s' % error_msg, expected=True)
  241. self.report_extraction(video_id)
  242. info = self._search_regex(r'var experienceJSON = ({.*});', webpage, 'json')
  243. info = json.loads(info)['data']
  244. video_info = info['programmedContent']['videoPlayer']['mediaDTO']
  245. video_info['_youtubedl_adServerURL'] = info.get('adServerURL')
  246. return self._extract_video_info(video_info)
  247. def _get_playlist_info(self, player_key):
  248. info_url = 'http://c.brightcove.com/services/json/experience/runtime/?command=get_programming_for_experience&playerKey=%s' % player_key
  249. playlist_info = self._download_webpage(
  250. info_url, player_key, 'Downloading playlist information')
  251. json_data = json.loads(playlist_info)
  252. if 'videoList' not in json_data:
  253. raise ExtractorError('Empty playlist')
  254. playlist_info = json_data['videoList']
  255. videos = [self._extract_video_info(video_info) for video_info in playlist_info['mediaCollectionDTO']['videoDTOs']]
  256. return self.playlist_result(videos, playlist_id='%s' % playlist_info['id'],
  257. playlist_title=playlist_info['mediaCollectionDTO']['displayName'])
  258. def _extract_video_info(self, video_info):
  259. info = {
  260. 'id': compat_str(video_info['id']),
  261. 'title': video_info['displayName'].strip(),
  262. 'description': video_info.get('shortDescription'),
  263. 'thumbnail': video_info.get('videoStillURL') or video_info.get('thumbnailURL'),
  264. 'uploader': video_info.get('publisherName'),
  265. }
  266. renditions = video_info.get('renditions')
  267. if renditions:
  268. formats = []
  269. for rend in renditions:
  270. url = rend['defaultURL']
  271. if not url:
  272. continue
  273. ext = None
  274. if rend['remote']:
  275. url_comp = compat_urllib_parse_urlparse(url)
  276. if url_comp.path.endswith('.m3u8'):
  277. formats.extend(
  278. self._extract_m3u8_formats(url, info['id'], 'mp4'))
  279. continue
  280. elif 'akamaihd.net' in url_comp.netloc:
  281. # This type of renditions are served through
  282. # akamaihd.net, but they don't use f4m manifests
  283. url = url.replace('control/', '') + '?&v=3.3.0&fp=13&r=FEEFJ&g=RTSJIMBMPFPB'
  284. ext = 'flv'
  285. if ext is None:
  286. ext = determine_ext(url)
  287. size = rend.get('size')
  288. formats.append({
  289. 'url': url,
  290. 'ext': ext,
  291. 'height': rend.get('frameHeight'),
  292. 'width': rend.get('frameWidth'),
  293. 'filesize': size if size != 0 else None,
  294. })
  295. self._sort_formats(formats)
  296. info['formats'] = formats
  297. elif video_info.get('FLVFullLengthURL') is not None:
  298. info.update({
  299. 'url': video_info['FLVFullLengthURL'],
  300. })
  301. if self._downloader.params.get('include_ads', False):
  302. adServerURL = video_info.get('_youtubedl_adServerURL')
  303. if adServerURL:
  304. ad_info = {
  305. '_type': 'url',
  306. 'url': adServerURL,
  307. }
  308. if 'url' in info:
  309. return {
  310. '_type': 'playlist',
  311. 'title': info['title'],
  312. 'entries': [ad_info, info],
  313. }
  314. else:
  315. return ad_info
  316. if 'url' not in info and not info.get('formats'):
  317. raise ExtractorError('Unable to extract video url for %s' % info['id'])
  318. return info
  319. class BrightcoveNewIE(InfoExtractor):
  320. IE_NAME = 'brightcove:new'
  321. _VALID_URL = r'https?://players\.brightcove\.net/(?P<account_id>\d+)/(?P<player_id>[^/]+)_(?P<embed>[^/]+)/index\.html\?.*videoId=(?P<video_id>\d+|ref:[^&]+)'
  322. _TESTS = [{
  323. 'url': 'http://players.brightcove.net/929656772001/e41d32dc-ec74-459e-a845-6c69f7b724ea_default/index.html?videoId=4463358922001',
  324. 'md5': 'c8100925723840d4b0d243f7025703be',
  325. 'info_dict': {
  326. 'id': '4463358922001',
  327. 'ext': 'mp4',
  328. 'title': 'Meet the man behind Popcorn Time',
  329. 'description': 'md5:eac376a4fe366edc70279bfb681aea16',
  330. 'duration': 165.768,
  331. 'timestamp': 1441391203,
  332. 'upload_date': '20150904',
  333. 'uploader_id': '929656772001',
  334. 'formats': 'mincount:22',
  335. },
  336. }, {
  337. # with rtmp streams
  338. 'url': 'http://players.brightcove.net/4036320279001/5d112ed9-283f-485f-a7f9-33f42e8bc042_default/index.html?videoId=4279049078001',
  339. 'info_dict': {
  340. 'id': '4279049078001',
  341. 'ext': 'mp4',
  342. 'title': 'Titansgrave: Chapter 0',
  343. 'description': 'Titansgrave: Chapter 0',
  344. 'duration': 1242.058,
  345. 'timestamp': 1433556729,
  346. 'upload_date': '20150606',
  347. 'uploader_id': '4036320279001',
  348. 'formats': 'mincount:41',
  349. },
  350. 'params': {
  351. 'skip_download': True,
  352. }
  353. }, {
  354. # ref: prefixed video id
  355. 'url': 'http://players.brightcove.net/3910869709001/21519b5c-4b3b-4363-accb-bdc8f358f823_default/index.html?videoId=ref:7069442',
  356. 'only_matching': True,
  357. }, {
  358. # non numeric ref: prefixed video id
  359. 'url': 'http://players.brightcove.net/710858724001/default_default/index.html?videoId=ref:event-stream-356',
  360. 'only_matching': True,
  361. }]
  362. @staticmethod
  363. def _extract_url(webpage):
  364. urls = BrightcoveNewIE._extract_urls(webpage)
  365. return urls[0] if urls else None
  366. @staticmethod
  367. def _extract_urls(webpage):
  368. # Reference:
  369. # 1. http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/publish-video.html#setvideoiniframe
  370. # 2. http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/publish-video.html#setvideousingjavascript
  371. # 3. http://docs.brightcove.com/en/video-cloud/brightcove-player/guides/embed-in-page.html
  372. # 4. https://support.brightcove.com/en/video-cloud/docs/dynamically-assigning-videos-player
  373. entries = []
  374. # Look for iframe embeds [1]
  375. for _, url in re.findall(
  376. r'<iframe[^>]+src=(["\'])((?:https?:)?//players\.brightcove\.net/\d+/[^/]+/index\.html.+?)\1', webpage):
  377. entries.append(url if url.startswith('http') else 'http:' + url)
  378. # Look for embed_in_page embeds [2]
  379. for video_id, account_id, player_id, embed in re.findall(
  380. # According to examples from [3] it's unclear whether video id
  381. # may be optional and what to do when it is
  382. # According to [4] data-video-id may be prefixed with ref:
  383. r'''(?sx)
  384. <video[^>]+
  385. data-video-id=["\'](\d+|ref:[^"\']+)["\'][^>]*>.*?
  386. </video>.*?
  387. <script[^>]+
  388. src=["\'](?:https?:)?//players\.brightcove\.net/
  389. (\d+)/([\da-f-]+)_([^/]+)/index(?:\.min)?\.js
  390. ''', webpage):
  391. entries.append(
  392. 'http://players.brightcove.net/%s/%s_%s/index.html?videoId=%s'
  393. % (account_id, player_id, embed, video_id))
  394. return entries
  395. def _real_extract(self, url):
  396. account_id, player_id, embed, video_id = re.match(self._VALID_URL, url).groups()
  397. webpage = self._download_webpage(
  398. 'http://players.brightcove.net/%s/%s_%s/index.min.js'
  399. % (account_id, player_id, embed), video_id)
  400. policy_key = None
  401. catalog = self._search_regex(
  402. r'catalog\(({.+?})\);', webpage, 'catalog', default=None)
  403. if catalog:
  404. catalog = self._parse_json(
  405. js_to_json(catalog), video_id, fatal=False)
  406. if catalog:
  407. policy_key = catalog.get('policyKey')
  408. if not policy_key:
  409. policy_key = self._search_regex(
  410. r'policyKey\s*:\s*(["\'])(?P<pk>.+?)\1',
  411. webpage, 'policy key', group='pk')
  412. api_url = 'https://edge.api.brightcove.com/playback/v1/accounts/%s/videos/%s' % (account_id, video_id)
  413. try:
  414. json_data = self._download_json(api_url, video_id, headers={
  415. 'Accept': 'application/json;pk=%s' % policy_key
  416. })
  417. except ExtractorError as e:
  418. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
  419. json_data = self._parse_json(e.cause.read().decode(), video_id)
  420. raise ExtractorError(json_data[0]['message'], expected=True)
  421. raise
  422. title = json_data['name']
  423. formats = []
  424. for source in json_data.get('sources', []):
  425. container = source.get('container')
  426. source_type = source.get('type')
  427. src = source.get('src')
  428. if source_type == 'application/x-mpegURL' or container == 'M2TS':
  429. if not src:
  430. continue
  431. formats.extend(self._extract_m3u8_formats(
  432. src, video_id, 'mp4', m3u8_id='hls', fatal=False))
  433. elif source_type == 'application/dash+xml':
  434. if not src:
  435. continue
  436. formats.extend(self._extract_mpd_formats(src, video_id, 'dash', fatal=False))
  437. else:
  438. streaming_src = source.get('streaming_src')
  439. stream_name, app_name = source.get('stream_name'), source.get('app_name')
  440. if not src and not streaming_src and (not stream_name or not app_name):
  441. continue
  442. tbr = float_or_none(source.get('avg_bitrate'), 1000)
  443. height = int_or_none(source.get('height'))
  444. width = int_or_none(source.get('width'))
  445. f = {
  446. 'tbr': tbr,
  447. 'filesize': int_or_none(source.get('size')),
  448. 'container': container,
  449. 'ext': container.lower(),
  450. }
  451. if width == 0 and height == 0:
  452. f.update({
  453. 'vcodec': 'none',
  454. })
  455. else:
  456. f.update({
  457. 'width': width,
  458. 'height': height,
  459. 'vcodec': source.get('codec'),
  460. })
  461. def build_format_id(kind):
  462. format_id = kind
  463. if tbr:
  464. format_id += '-%dk' % int(tbr)
  465. if height:
  466. format_id += '-%dp' % height
  467. return format_id
  468. if src or streaming_src:
  469. f.update({
  470. 'url': src or streaming_src,
  471. 'format_id': build_format_id('http' if src else 'http-streaming'),
  472. 'preference': 2 if src else 1,
  473. })
  474. else:
  475. f.update({
  476. 'url': app_name,
  477. 'play_path': stream_name,
  478. 'format_id': build_format_id('rtmp'),
  479. })
  480. formats.append(f)
  481. self._sort_formats(formats)
  482. description = json_data.get('description')
  483. thumbnail = json_data.get('thumbnail')
  484. timestamp = parse_iso8601(json_data.get('published_at'))
  485. duration = float_or_none(json_data.get('duration'), 1000)
  486. tags = json_data.get('tags', [])
  487. return {
  488. 'id': video_id,
  489. 'title': title,
  490. 'description': description,
  491. 'thumbnail': thumbnail,
  492. 'duration': duration,
  493. 'timestamp': timestamp,
  494. 'uploader_id': account_id,
  495. 'formats': formats,
  496. 'tags': tags,
  497. }