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