logo

youtube-dl

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

tmz.py (4382B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from .jwplatform import JWPlatformIE
  5. from .kaltura import KalturaIE
  6. from ..utils import (
  7. int_or_none,
  8. unified_timestamp,
  9. )
  10. class TMZIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?tmz\.com/videos/(?P<id>[^/?#&]+)'
  12. _TESTS = [{
  13. 'url': 'http://www.tmz.com/videos/0-cegprt2p/',
  14. 'md5': '31f9223e20eef55954973359afa61a20',
  15. 'info_dict': {
  16. 'id': 'P6YjLBLk',
  17. 'ext': 'mp4',
  18. 'title': "No Charges Against Hillary Clinton? Harvey Says It Ain't Over Yet",
  19. 'description': 'md5:b714359fc18607715ebccbd2da8ff488',
  20. 'timestamp': 1467831837,
  21. 'upload_date': '20160706',
  22. },
  23. 'add_ie': [JWPlatformIE.ie_key()],
  24. }, {
  25. 'url': 'http://www.tmz.com/videos/0_okj015ty/',
  26. 'only_matching': True,
  27. }, {
  28. 'url': 'https://www.tmz.com/videos/071119-chris-morgan-women-4590005-0-zcsejvcr/',
  29. 'only_matching': True,
  30. }, {
  31. 'url': 'https://www.tmz.com/videos/2021-02-19-021921-floyd-mayweather-1043872/',
  32. 'only_matching': True,
  33. }]
  34. def _real_extract(self, url):
  35. video_id = self._match_id(url).replace('-', '_')
  36. webpage = self._download_webpage(url, video_id, fatal=False)
  37. if webpage:
  38. tmz_video_id = self._search_regex(
  39. r'nodeRef\s*:\s*["\']tmz:video:([\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12})',
  40. webpage, 'video id', default=None)
  41. video = self._download_json(
  42. 'https://www.tmz.com/_/video/%s' % tmz_video_id, video_id,
  43. fatal=False)
  44. if video:
  45. message = video['message']
  46. info = {
  47. '_type': 'url_transparent',
  48. 'title': message.get('title'),
  49. 'description': message.get('description'),
  50. 'timestamp': unified_timestamp(message.get('published_at')),
  51. 'duration': int_or_none(message.get('duration')),
  52. }
  53. jwplatform_id = message.get('jwplayer_media_id')
  54. if jwplatform_id:
  55. info.update({
  56. 'url': 'jwplatform:%s' % jwplatform_id,
  57. 'ie_key': JWPlatformIE.ie_key(),
  58. })
  59. else:
  60. kaltura_entry_id = message.get('kaltura_entry_id') or video_id
  61. kaltura_partner_id = message.get('kaltura_partner_id') or '591531'
  62. info.update({
  63. 'url': 'kaltura:%s:%s' % (kaltura_partner_id, kaltura_entry_id),
  64. 'ie_key': KalturaIE.ie_key(),
  65. })
  66. return info
  67. return self.url_result(
  68. 'kaltura:591531:%s' % video_id, KalturaIE.ie_key(), video_id)
  69. class TMZArticleIE(InfoExtractor):
  70. _VALID_URL = r'https?://(?:www\.)?tmz\.com/\d{4}/\d{2}/\d{2}/(?P<id>[^/?#&]+)'
  71. _TEST = {
  72. 'url': 'http://www.tmz.com/2015/04/19/bobby-brown-bobbi-kristina-awake-video-concert',
  73. 'info_dict': {
  74. 'id': 'PAKZa97W',
  75. 'ext': 'mp4',
  76. 'title': 'Bobby Brown Tells Crowd ... Bobbi Kristina is Awake',
  77. 'description': 'Bobby Brown stunned his audience during a concert Saturday night, when he told the crowd, "Bobbi is awake. She\'s watching me."',
  78. 'timestamp': 1429466400,
  79. 'upload_date': '20150419',
  80. },
  81. 'params': {
  82. 'skip_download': True,
  83. },
  84. 'add_ie': [JWPlatformIE.ie_key()],
  85. }
  86. def _real_extract(self, url):
  87. video_id = self._match_id(url)
  88. webpage = self._download_webpage(url, video_id)
  89. tmz_url = self._search_regex(
  90. r'clickLink\s*\(\s*["\'](?P<url>%s)' % TMZIE._VALID_URL, webpage,
  91. 'video id', default=None, group='url')
  92. if tmz_url:
  93. return self.url_result(tmz_url, ie=TMZIE.ie_key())
  94. embedded_video_info = self._parse_json(self._html_search_regex(
  95. r'tmzVideoEmbed\(({.+?})\);', webpage, 'embedded video info'),
  96. video_id)
  97. return self.url_result(
  98. 'http://www.tmz.com/videos/%s/' % embedded_video_info['id'],
  99. ie=TMZIE.ie_key())