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