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