tmz.py 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. get_element_by_attribute,
  6. )
  7. class TMZIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?tmz\.com/.*'
  9. _TESTS = [
  10. {
  11. 'url': 'http://www.tmz.com/videos/0-cegprt2p/',
  12. 'info_dict': {
  13. 'id': 'http://www.tmz.com/videos/0-cegprt2p/',
  14. 'ext': 'mp4',
  15. 'title': 'No Charges Against Hillary Clinton? Harvey Says It Ain\'t Over Yet',
  16. 'description': 'Harvey talks about Director Comey’s decision not to prosecute Hillary Clinton.',
  17. 'timestamp': 1467831837,
  18. 'uploader': 'TMZ Staff',
  19. 'upload_date': '20160706',
  20. 'thumbnail': 'https://imagez.tmz.com/image/5e/4by3/2016/07/06/5eea7dc01baa5c2e83eb06930c170e46_xl.jpg',
  21. 'duration': 772.0,
  22. },
  23. },
  24. {
  25. 'url': 'https://www.tmz.com/videos/071119-chris-morgan-women-4590005-0-zcsejvcr/',
  26. 'info_dict': {
  27. 'id': 'https://www.tmz.com/videos/071119-chris-morgan-women-4590005-0-zcsejvcr/',
  28. 'ext': 'mp4',
  29. 'title': 'Angry Bagel Shop Guy Says He Doesn\'t Trust Women',
  30. 'description': 'The enraged man who went viral for ranting about women on dating sites before getting ragdolled in a bagel shop is defending his misogyny ... he says it\'s women\'s fault in the first place.',
  31. 'timestamp': 1562889485,
  32. 'uploader': 'TMZ Staff',
  33. 'upload_date': '20190711',
  34. 'thumbnail': 'https://imagez.tmz.com/image/a8/4by3/2019/07/12/a85480d27b2f50a7bfea2322151d67a5_xl.jpg',
  35. 'duration': 123.0,
  36. },
  37. },
  38. {
  39. 'url': 'http://www.tmz.com/2015/04/19/bobby-brown-bobbi-kristina-awake-video-concert',
  40. 'md5': '5429c85db8bde39a473a56ca8c4c5602',
  41. 'info_dict': {
  42. 'id': 'http://www.tmz.com/2015/04/19/bobby-brown-bobbi-kristina-awake-video-concert',
  43. 'ext': 'mp4',
  44. 'title': 'Bobby Brown Tells Crowd ... Bobbi Kristina is Awake',
  45. 'description': 'Bobby Brown stunned his audience during a concert Saturday night, when he told the crowd, "Bobbi is awake. She\'s watching me."',
  46. 'timestamp': 1429467813,
  47. 'uploader': 'TMZ Staff',
  48. 'upload_date': '20150419',
  49. 'duration': 29.0,
  50. 'thumbnail': 'https://imagez.tmz.com/image/15/4by3/2015/04/20/1539c7ae136359fc979236fa6a9449dd_xl.jpg',
  51. },
  52. },
  53. {
  54. 'url': 'http://www.tmz.com/2015/09/19/patti-labelle-concert-fan-stripping-kicked-out-nicki-minaj/',
  55. 'info_dict': {
  56. 'id': 'http://www.tmz.com/2015/09/19/patti-labelle-concert-fan-stripping-kicked-out-nicki-minaj/',
  57. 'ext': 'mp4',
  58. 'title': 'Patti LaBelle -- Goes Nuclear On Stripping Fan',
  59. 'description': 'Patti LaBelle made it known loud and clear last night ... NO '
  60. 'ONE gets on her stage and strips down.',
  61. 'timestamp': 1442683746,
  62. 'uploader': 'TMZ Staff',
  63. 'upload_date': '20150919',
  64. 'duration': 104.0,
  65. 'thumbnail': 'https://imagez.tmz.com/image/5e/4by3/2015/09/20/5e57d7575062528082994e18ac3f0f48_xl.jpg',
  66. },
  67. },
  68. {
  69. 'url': 'http://www.tmz.com/2016/01/28/adam-silver-sting-drake-blake-griffin/',
  70. 'info_dict': {
  71. 'id': 'http://www.tmz.com/2016/01/28/adam-silver-sting-drake-blake-griffin/',
  72. 'ext': 'mp4',
  73. 'title': 'NBA\'s Adam Silver -- Blake Griffin\'s a Great Guy ... He\'ll Learn from This',
  74. 'description': 'Two pretty parts of this video with NBA Commish Adam Silver.',
  75. 'timestamp': 1454010989,
  76. 'uploader': 'TMZ Staff',
  77. 'upload_date': '20160128',
  78. 'duration': 59.0,
  79. 'thumbnail': 'https://imagez.tmz.com/image/38/4by3/2016/01/29/3856e83e0beb57059ec412122b842fb1_xl.jpg',
  80. },
  81. },
  82. {
  83. 'url': 'http://www.tmz.com/2016/10/27/donald-trump-star-vandal-arrested-james-otis/',
  84. 'info_dict': {
  85. 'id': 'http://www.tmz.com/2016/10/27/donald-trump-star-vandal-arrested-james-otis/',
  86. 'ext': 'mp4',
  87. 'title': 'Trump Star Vandal -- I\'m Not Afraid of Donald or the Cops!',
  88. 'description': 'James Otis is the the guy who took a pickaxe to Donald Trump\'s star on the Walk of Fame, and he tells TMZ .. he\'s ready and willing to go to jail for the crime.',
  89. 'timestamp': 1477500095,
  90. 'uploader': 'TMZ Staff',
  91. 'upload_date': '20161026',
  92. 'thumbnail': 'https://imagez.tmz.com/image/0d/4by3/2016/10/27/0d904814d4a75dcf9cc3b8cfd1edc1a3_xl.jpg',
  93. 'duration': 128.0,
  94. },
  95. },
  96. {
  97. 'url': 'https://www.tmz.com/videos/2020-10-31-103120-beverly-hills-protest-4878209/',
  98. 'info_dict': {
  99. 'id': 'https://www.tmz.com/videos/2020-10-31-103120-beverly-hills-protest-4878209/',
  100. 'ext': 'mp4',
  101. 'title': 'Cops Use Billy Clubs Against Pro-Trump and Anti-Fascist '
  102. 'Demonstrators',
  103. 'description': 'Beverly Hills may be an omen of what\'s coming next week, '
  104. 'because things got crazy on the streets and cops started '
  105. 'swinging their billy clubs at both Anti-Fascist and Pro-Trump '
  106. 'demonstrators.',
  107. 'timestamp': 1604182772,
  108. 'uploader': 'TMZ Staff',
  109. 'upload_date': '20201031',
  110. 'duration': 96.0,
  111. 'thumbnail': 'https://imagez.tmz.com/image/f3/4by3/2020/10/31/f37bd5a8aef84497866f425130c58be3_xl.jpg',
  112. },
  113. },
  114. {
  115. 'url': 'https://www.tmz.com/2020/11/05/gervonta-davis-car-crash-hit-and-run-police/',
  116. 'info_dict': {
  117. 'id': 'Dddb6IGe-ws',
  118. 'ext': 'mp4',
  119. 'title': 'SICK LAMBO GERVONTA DAVIS IN HIS NEW RIDE RIGHT AFTER KO AFTER LEO EsNews Boxing',
  120. 'uploader': 'ESNEWS',
  121. 'description': 'md5:49675bc58883ccf80474b8aa701e1064',
  122. 'upload_date': '20201102',
  123. 'uploader_id': '@ESNEWS',
  124. 'uploader_url': 'https://www.youtube.com/@ESNEWS',
  125. 'like_count': int,
  126. 'channel_id': 'UCI-Oq7oFGakzSzHFlTtsUsQ',
  127. 'channel': 'ESNEWS',
  128. 'view_count': int,
  129. 'duration': 225,
  130. 'live_status': 'not_live',
  131. 'thumbnail': 'https://i.ytimg.com/vi_webp/Dddb6IGe-ws/maxresdefault.webp',
  132. 'channel_url': 'https://www.youtube.com/channel/UCI-Oq7oFGakzSzHFlTtsUsQ',
  133. 'channel_follower_count': int,
  134. 'playable_in_embed': True,
  135. 'categories': ['Sports'],
  136. 'age_limit': 0,
  137. 'tags': 'count:10',
  138. 'availability': 'public',
  139. 'comment_count': int,
  140. },
  141. },
  142. {
  143. 'url': 'https://www.tmz.com/2020/11/19/conor-mcgregor-dustin-poirier-contract-fight-ufc-257-fight-island/',
  144. 'info_dict': {
  145. 'id': '1329448013937471491',
  146. 'ext': 'mp4',
  147. 'title': 'The Mac Life - BREAKING: Conor McGregor (@thenotoriousmma) has signed his bout agreement for his rematch with Dustin Poirier for January 23.',
  148. 'uploader': 'The Mac Life',
  149. 'description': 'md5:56e6009bbc3d12498e10d08a8e1f1c69',
  150. 'upload_date': '20201119',
  151. 'display_id': '1329450007125225473',
  152. 'uploader_id': 'TheMacLife',
  153. 'timestamp': 1605800556,
  154. 'thumbnail': 'https://pbs.twimg.com/media/EnMmfT8XYAExgxJ.jpg?name=small',
  155. 'like_count': int,
  156. 'duration': 11.812,
  157. 'uploader_url': 'https://twitter.com/TheMacLife',
  158. 'age_limit': 0,
  159. 'repost_count': int,
  160. 'tags': [],
  161. 'comment_count': int,
  162. },
  163. },
  164. ]
  165. def _real_extract(self, url):
  166. webpage = self._download_webpage(url, url)
  167. jsonld = self._search_json_ld(webpage, url)
  168. if not jsonld or 'url' not in jsonld:
  169. # try to extract from YouTube Player API
  170. # see https://developers.google.com/youtube/iframe_api_reference#Video_Queueing_Functions
  171. match_obj = re.search(r'\.cueVideoById\(\s*(?P<quote>[\'"])(?P<id>.*?)(?P=quote)', webpage)
  172. if match_obj:
  173. return self.url_result(match_obj.group('id'))
  174. # try to extract from twitter
  175. blockquote_el = get_element_by_attribute('class', 'twitter-tweet', webpage)
  176. if blockquote_el:
  177. matches = re.findall(
  178. r'<a[^>]+href=\s*(?P<quote>[\'"])(?P<link>.*?)(?P=quote)',
  179. blockquote_el)
  180. if matches:
  181. for _, match in matches:
  182. if '/status/' in match:
  183. return self.url_result(match)
  184. raise ExtractorError('No video found!')
  185. if id not in jsonld:
  186. jsonld['id'] = url
  187. return jsonld