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.

158 lines
7.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. get_element_by_attribute,
  8. )
  9. class TMZIE(InfoExtractor):
  10. _VALID_URL = r"https?://(?:www\.)?tmz\.com/.*"
  11. _TESTS = [
  12. {
  13. "url": "http://www.tmz.com/videos/0-cegprt2p/",
  14. "info_dict": {
  15. "id": "http://www.tmz.com/videos/0-cegprt2p/",
  16. "ext": "mp4",
  17. "title": "No Charges Against Hillary Clinton? Harvey Says It Ain't Over Yet",
  18. "description": "Harvey talks about Director Comey’s decision not to prosecute Hillary Clinton.",
  19. "timestamp": 1467831837,
  20. "uploader": "{'@type': 'Person', 'name': 'TMZ Staff'}",
  21. "upload_date": "20160706",
  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": "{'@type': 'Person', 'name': 'TMZ Staff'}",
  33. "upload_date": "20190711",
  34. },
  35. },
  36. {
  37. "url": "http://www.tmz.com/2015/04/19/bobby-brown-bobbi-kristina-awake-video-concert",
  38. "md5": "5429c85db8bde39a473a56ca8c4c5602",
  39. "info_dict": {
  40. "id": "http://www.tmz.com/2015/04/19/bobby-brown-bobbi-kristina-awake-video-concert",
  41. "ext": "mp4",
  42. "title": "Bobby Brown Tells Crowd ... Bobbi Kristina is Awake",
  43. "description": 'Bobby Brown stunned his audience during a concert Saturday night, when he told the crowd, "Bobbi is awake. She\'s watching me."',
  44. "timestamp": 1429467813,
  45. "uploader": "{'@type': 'Person', 'name': 'TMZ Staff'}",
  46. "upload_date": "20150419",
  47. },
  48. },
  49. {
  50. "url": "http://www.tmz.com/2015/09/19/patti-labelle-concert-fan-stripping-kicked-out-nicki-minaj/",
  51. "info_dict": {
  52. "id": "http://www.tmz.com/2015/09/19/patti-labelle-concert-fan-stripping-kicked-out-nicki-minaj/",
  53. "ext": "mp4",
  54. "title": "Patti LaBelle -- Goes Nuclear On Stripping Fan",
  55. "description": "Patti LaBelle made it known loud and clear last night ... NO "
  56. "ONE gets on her stage and strips down.",
  57. "timestamp": 1442683746,
  58. "uploader": "{'@type': 'Person', 'name': 'TMZ Staff'}",
  59. "upload_date": "20150919",
  60. },
  61. },
  62. {
  63. "url": "http://www.tmz.com/2016/01/28/adam-silver-sting-drake-blake-griffin/",
  64. "info_dict": {
  65. "id": "http://www.tmz.com/2016/01/28/adam-silver-sting-drake-blake-griffin/",
  66. "ext": "mp4",
  67. "title": "NBA's Adam Silver -- Blake Griffin's a Great Guy ... He'll Learn from This",
  68. "description": "Two pretty parts of this video with NBA Commish Adam Silver.",
  69. "timestamp": 1454010989,
  70. "uploader": "{'@type': 'Person', 'name': 'TMZ Staff'}",
  71. "upload_date": "20160128",
  72. },
  73. },
  74. {
  75. "url": "http://www.tmz.com/2016/10/27/donald-trump-star-vandal-arrested-james-otis/",
  76. "info_dict": {
  77. "id": "http://www.tmz.com/2016/10/27/donald-trump-star-vandal-arrested-james-otis/",
  78. "ext": "mp4",
  79. "title": "Trump Star Vandal -- I'm Not Afraid of Donald or the Cops!",
  80. "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.",
  81. "timestamp": 1477500095,
  82. "uploader": "{'@type': 'Person', 'name': 'TMZ Staff'}",
  83. "upload_date": "20161026",
  84. },
  85. },
  86. {
  87. "url": "https://www.tmz.com/videos/2020-10-31-103120-beverly-hills-protest-4878209/",
  88. "info_dict": {
  89. "id": "https://www.tmz.com/videos/2020-10-31-103120-beverly-hills-protest-4878209/",
  90. "ext": "mp4",
  91. "title": "Cops Use Billy Clubs Against Pro-Trump and Anti-Fascist "
  92. "Demonstrators",
  93. "description": "Beverly Hills may be an omen of what's coming next week, "
  94. "because things got crazy on the streets and cops started "
  95. "swinging their billy clubs at both Anti-Fascist and Pro-Trump "
  96. "demonstrators.",
  97. "timestamp": 1604182772,
  98. "uploader": "{'@type': 'Person', 'name': 'TMZ Staff'}",
  99. "upload_date": "20201031",
  100. },
  101. },
  102. {
  103. "url": "https://www.tmz.com/2020/11/05/gervonta-davis-car-crash-hit-and-run-police/",
  104. "info_dict": {
  105. "id": "Dddb6IGe-ws",
  106. "ext": "mp4",
  107. "title": "SICK LAMBO GERVONTA DAVIS IN HIS NEW RIDE RIGHT AFTER KO AFTER LEO EsNews Boxing",
  108. "uploader": "ESNEWS",
  109. "description": "md5:49675bc58883ccf80474b8aa701e1064",
  110. "upload_date": "20201101",
  111. "uploader_id": "ESNEWS",
  112. },
  113. },
  114. {
  115. "url": "https://www.tmz.com/2020/11/19/conor-mcgregor-dustin-poirier-contract-fight-ufc-257-fight-island/",
  116. "info_dict": {
  117. "id": "1329450007125225473",
  118. "ext": "mp4",
  119. "title": "TheMacLife - BREAKING: Conor McGregor (@thenotoriousmma) has signed his bout agreement for his rematch with Dustin Poirier for January 23.",
  120. "uploader": "TheMacLife",
  121. "description": "md5:56e6009bbc3d12498e10d08a8e1f1c69",
  122. "upload_date": "20201119",
  123. "uploader_id": "Maclifeofficial",
  124. "timestamp": 1605800556,
  125. },
  126. },
  127. ]
  128. def _real_extract(self, url):
  129. webpage = self._download_webpage(url, url)
  130. jsonld = self._search_json_ld(webpage, url)
  131. if not jsonld or "url" not in jsonld:
  132. # try to extract from YouTube Player API
  133. # see https://developers.google.com/youtube/iframe_api_reference#Video_Queueing_Functions
  134. match_obj = re.search(r'\.cueVideoById\(\s*(?P<quote>[\'"])(?P<id>.*?)(?P=quote)', webpage)
  135. if match_obj:
  136. res = self.url_result(match_obj.group("id"))
  137. return res
  138. # try to extract from twitter
  139. blockquote_el = get_element_by_attribute("class", "twitter-tweet", webpage)
  140. if blockquote_el:
  141. matches = re.findall(
  142. r'<a[^>]+href=\s*(?P<quote>[\'"])(?P<link>.*?)(?P=quote)',
  143. blockquote_el)
  144. if matches:
  145. for _, match in matches:
  146. if "/status/" in match:
  147. res = self.url_result(match)
  148. return res
  149. raise ExtractorError("No video found!")
  150. if id not in jsonld:
  151. jsonld["id"] = url
  152. return jsonld