[cleanup] Misc (#8300)

* Simplify nuxt regex
* Fix tmz quotes and tests
* Update test python versions

Authored by: dirkf, gamer191, Grub4K
This commit is contained in:
Simon Sawicki 2023-10-07 03:02:45 +02:00 committed by GitHub
parent 03e85ea99d
commit 377e85a179
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 138 additions and 136 deletions

View file

@ -13,7 +13,7 @@ jobs:
matrix: matrix:
os: [ubuntu-latest] os: [ubuntu-latest]
# CPython 3.11 is in quick-test # CPython 3.11 is in quick-test
python-version: ['3.8', '3.9', '3.10', '3.12-dev', pypy-3.7, pypy-3.8, pypy-3.10] python-version: ['3.8', '3.9', '3.10', '3.12', pypy-3.7, pypy-3.8, pypy-3.10]
run-tests-ext: [sh] run-tests-ext: [sh]
include: include:
# atleast one of each CPython/PyPy tests must be in windows # atleast one of each CPython/PyPy tests must be in windows
@ -21,7 +21,7 @@ jobs:
python-version: '3.7' python-version: '3.7'
run-tests-ext: bat run-tests-ext: bat
- os: windows-latest - os: windows-latest
python-version: '3.12-dev' python-version: '3.12'
run-tests-ext: bat run-tests-ext: bat
- os: windows-latest - os: windows-latest
python-version: pypy-3.9 python-version: pypy-3.9

View file

@ -28,7 +28,7 @@ jobs:
fail-fast: true fail-fast: true
matrix: matrix:
os: [ubuntu-latest] os: [ubuntu-latest]
python-version: ['3.7', '3.10', 3.11-dev, pypy-3.7, pypy-3.8] python-version: ['3.7', '3.10', '3.12', pypy-3.7, pypy-3.8, pypy-3.10]
run-tests-ext: [sh] run-tests-ext: [sh]
include: include:
# atleast one of each CPython/PyPy tests must be in windows # atleast one of each CPython/PyPy tests must be in windows

View file

@ -1687,7 +1687,7 @@ def _search_nextjs_data(self, webpage, video_id, *, transform_source=None, fatal
def _search_nuxt_data(self, webpage, video_id, context_name='__NUXT__', *, fatal=True, traverse=('data', 0)): def _search_nuxt_data(self, webpage, video_id, context_name='__NUXT__', *, fatal=True, traverse=('data', 0)):
"""Parses Nuxt.js metadata. This works as long as the function __NUXT__ invokes is a pure function""" """Parses Nuxt.js metadata. This works as long as the function __NUXT__ invokes is a pure function"""
rectx = re.escape(context_name) rectx = re.escape(context_name)
FUNCTION_RE = r'\(function\((?P<arg_keys>.*?)\){(?:.*?)return\s+(?P<js>{.*?})\s*;?\s*}\((?P<arg_vals>.*?)\)' FUNCTION_RE = r'\(function\((?P<arg_keys>.*?)\){.*?\breturn\s+(?P<js>{.*?})\s*;?\s*}\((?P<arg_vals>.*?)\)'
js, arg_keys, arg_vals = self._search_regex( js, arg_keys, arg_vals = self._search_regex(
(rf'<script>\s*window\.{rectx}={FUNCTION_RE}\s*\)\s*;?\s*</script>', rf'{rectx}\(.*?{FUNCTION_RE}'), (rf'<script>\s*window\.{rectx}={FUNCTION_RE}\s*\)\s*;?\s*</script>', rf'{rectx}\(.*?{FUNCTION_RE}'),
webpage, context_name, group=('js', 'arg_keys', 'arg_vals'), webpage, context_name, group=('js', 'arg_keys', 'arg_vals'),

View file

@ -8,158 +8,160 @@
class TMZIE(InfoExtractor): class TMZIE(InfoExtractor):
_VALID_URL = r"https?://(?:www\.)?tmz\.com/.*" _VALID_URL = r'https?://(?:www\.)?tmz\.com/.*'
_TESTS = [ _TESTS = [
{ {
"url": "http://www.tmz.com/videos/0-cegprt2p/", 'url': 'http://www.tmz.com/videos/0-cegprt2p/',
"info_dict": { 'info_dict': {
"id": "http://www.tmz.com/videos/0-cegprt2p/", 'id': 'http://www.tmz.com/videos/0-cegprt2p/',
"ext": "mp4", 'ext': 'mp4',
"title": "No Charges Against Hillary Clinton? Harvey Says It Ain't Over Yet", 'title': 'No Charges Against Hillary Clinton? Harvey Says It Ain\'t Over Yet',
"description": "Harvey talks about Director Comeys decision not to prosecute Hillary Clinton.", 'description': 'Harvey talks about Director Comeys decision not to prosecute Hillary Clinton.',
"timestamp": 1467831837, 'timestamp': 1467831837,
"uploader": "TMZ Staff", 'uploader': 'TMZ Staff',
"upload_date": "20160706", 'upload_date': '20160706',
"thumbnail": "https://imagez.tmz.com/image/5e/4by3/2016/07/06/5eea7dc01baa5c2e83eb06930c170e46_xl.jpg", 'thumbnail': 'https://imagez.tmz.com/image/5e/4by3/2016/07/06/5eea7dc01baa5c2e83eb06930c170e46_xl.jpg',
"duration": 772.0, 'duration': 772.0,
}, },
}, },
{ {
"url": "https://www.tmz.com/videos/071119-chris-morgan-women-4590005-0-zcsejvcr/", 'url': 'https://www.tmz.com/videos/071119-chris-morgan-women-4590005-0-zcsejvcr/',
"info_dict": { 'info_dict': {
"id": "https://www.tmz.com/videos/071119-chris-morgan-women-4590005-0-zcsejvcr/", 'id': 'https://www.tmz.com/videos/071119-chris-morgan-women-4590005-0-zcsejvcr/',
"ext": "mp4", 'ext': 'mp4',
"title": "Angry Bagel Shop Guy Says He Doesn't Trust Women", 'title': 'Angry Bagel Shop Guy Says He Doesn\'t Trust Women',
"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.", '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.',
"timestamp": 1562889485, 'timestamp': 1562889485,
"uploader": "TMZ Staff", 'uploader': 'TMZ Staff',
"upload_date": "20190711", 'upload_date': '20190711',
"thumbnail": "https://imagez.tmz.com/image/a8/4by3/2019/07/12/a85480d27b2f50a7bfea2322151d67a5_xl.jpg", 'thumbnail': 'https://imagez.tmz.com/image/a8/4by3/2019/07/12/a85480d27b2f50a7bfea2322151d67a5_xl.jpg',
"duration": 123.0, 'duration': 123.0,
}, },
}, },
{ {
"url": "http://www.tmz.com/2015/04/19/bobby-brown-bobbi-kristina-awake-video-concert", 'url': 'http://www.tmz.com/2015/04/19/bobby-brown-bobbi-kristina-awake-video-concert',
"md5": "5429c85db8bde39a473a56ca8c4c5602", 'md5': '5429c85db8bde39a473a56ca8c4c5602',
"info_dict": { 'info_dict': {
"id": "http://www.tmz.com/2015/04/19/bobby-brown-bobbi-kristina-awake-video-concert", 'id': 'http://www.tmz.com/2015/04/19/bobby-brown-bobbi-kristina-awake-video-concert',
"ext": "mp4", 'ext': 'mp4',
"title": "Bobby Brown Tells Crowd ... Bobbi Kristina is Awake", 'title': 'Bobby Brown Tells Crowd ... Bobbi Kristina is Awake',
"description": 'Bobby Brown stunned his audience during a concert Saturday night, when he told the crowd, "Bobbi is awake. She\'s watching me."', 'description': 'Bobby Brown stunned his audience during a concert Saturday night, when he told the crowd, "Bobbi is awake. She\'s watching me."',
"timestamp": 1429467813, 'timestamp': 1429467813,
"uploader": "TMZ Staff", 'uploader': 'TMZ Staff',
"upload_date": "20150419", 'upload_date': '20150419',
"duration": 29.0, 'duration': 29.0,
"thumbnail": "https://imagez.tmz.com/image/15/4by3/2015/04/20/1539c7ae136359fc979236fa6a9449dd_xl.jpg", 'thumbnail': 'https://imagez.tmz.com/image/15/4by3/2015/04/20/1539c7ae136359fc979236fa6a9449dd_xl.jpg',
}, },
}, },
{ {
"url": "http://www.tmz.com/2015/09/19/patti-labelle-concert-fan-stripping-kicked-out-nicki-minaj/", 'url': 'http://www.tmz.com/2015/09/19/patti-labelle-concert-fan-stripping-kicked-out-nicki-minaj/',
"info_dict": { 'info_dict': {
"id": "http://www.tmz.com/2015/09/19/patti-labelle-concert-fan-stripping-kicked-out-nicki-minaj/", 'id': 'http://www.tmz.com/2015/09/19/patti-labelle-concert-fan-stripping-kicked-out-nicki-minaj/',
"ext": "mp4", 'ext': 'mp4',
"title": "Patti LaBelle -- Goes Nuclear On Stripping Fan", 'title': 'Patti LaBelle -- Goes Nuclear On Stripping Fan',
"description": "Patti LaBelle made it known loud and clear last night ... NO " 'description': 'Patti LaBelle made it known loud and clear last night ... NO '
"ONE gets on her stage and strips down.", 'ONE gets on her stage and strips down.',
"timestamp": 1442683746, 'timestamp': 1442683746,
"uploader": "TMZ Staff", 'uploader': 'TMZ Staff',
"upload_date": "20150919", 'upload_date': '20150919',
"duration": 104.0, 'duration': 104.0,
"thumbnail": "https://imagez.tmz.com/image/5e/4by3/2015/09/20/5e57d7575062528082994e18ac3f0f48_xl.jpg", 'thumbnail': 'https://imagez.tmz.com/image/5e/4by3/2015/09/20/5e57d7575062528082994e18ac3f0f48_xl.jpg',
}, },
}, },
{ {
"url": "http://www.tmz.com/2016/01/28/adam-silver-sting-drake-blake-griffin/", 'url': 'http://www.tmz.com/2016/01/28/adam-silver-sting-drake-blake-griffin/',
"info_dict": { 'info_dict': {
"id": "http://www.tmz.com/2016/01/28/adam-silver-sting-drake-blake-griffin/", 'id': 'http://www.tmz.com/2016/01/28/adam-silver-sting-drake-blake-griffin/',
"ext": "mp4", 'ext': 'mp4',
"title": "NBA's Adam Silver -- Blake Griffin's a Great Guy ... He'll Learn from This", 'title': 'NBA\'s Adam Silver -- Blake Griffin\'s a Great Guy ... He\'ll Learn from This',
"description": "Two pretty parts of this video with NBA Commish Adam Silver.", 'description': 'Two pretty parts of this video with NBA Commish Adam Silver.',
"timestamp": 1454010989, 'timestamp': 1454010989,
"uploader": "TMZ Staff", 'uploader': 'TMZ Staff',
"upload_date": "20160128", 'upload_date': '20160128',
"duration": 59.0, 'duration': 59.0,
"thumbnail": "https://imagez.tmz.com/image/38/4by3/2016/01/29/3856e83e0beb57059ec412122b842fb1_xl.jpg", 'thumbnail': 'https://imagez.tmz.com/image/38/4by3/2016/01/29/3856e83e0beb57059ec412122b842fb1_xl.jpg',
}, },
}, },
{ {
"url": "http://www.tmz.com/2016/10/27/donald-trump-star-vandal-arrested-james-otis/", 'url': 'http://www.tmz.com/2016/10/27/donald-trump-star-vandal-arrested-james-otis/',
"info_dict": { 'info_dict': {
"id": "http://www.tmz.com/2016/10/27/donald-trump-star-vandal-arrested-james-otis/", 'id': 'http://www.tmz.com/2016/10/27/donald-trump-star-vandal-arrested-james-otis/',
"ext": "mp4", 'ext': 'mp4',
"title": "Trump Star Vandal -- I'm Not Afraid of Donald or the Cops!", 'title': 'Trump Star Vandal -- I\'m Not Afraid of Donald or the Cops!',
"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.", '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.',
"timestamp": 1477500095, 'timestamp': 1477500095,
"uploader": "TMZ Staff", 'uploader': 'TMZ Staff',
"upload_date": "20161026", 'upload_date': '20161026',
"thumbnail": "https://imagez.tmz.com/image/0d/4by3/2016/10/27/0d904814d4a75dcf9cc3b8cfd1edc1a3_xl.jpg", 'thumbnail': 'https://imagez.tmz.com/image/0d/4by3/2016/10/27/0d904814d4a75dcf9cc3b8cfd1edc1a3_xl.jpg',
"duration": 128.0, 'duration': 128.0,
}, },
}, },
{ {
"url": "https://www.tmz.com/videos/2020-10-31-103120-beverly-hills-protest-4878209/", 'url': 'https://www.tmz.com/videos/2020-10-31-103120-beverly-hills-protest-4878209/',
"info_dict": { 'info_dict': {
"id": "https://www.tmz.com/videos/2020-10-31-103120-beverly-hills-protest-4878209/", 'id': 'https://www.tmz.com/videos/2020-10-31-103120-beverly-hills-protest-4878209/',
"ext": "mp4", 'ext': 'mp4',
"title": "Cops Use Billy Clubs Against Pro-Trump and Anti-Fascist " 'title': 'Cops Use Billy Clubs Against Pro-Trump and Anti-Fascist '
"Demonstrators", 'Demonstrators',
"description": "Beverly Hills may be an omen of what's coming next week, " 'description': 'Beverly Hills may be an omen of what\'s coming next week, '
"because things got crazy on the streets and cops started " 'because things got crazy on the streets and cops started '
"swinging their billy clubs at both Anti-Fascist and Pro-Trump " 'swinging their billy clubs at both Anti-Fascist and Pro-Trump '
"demonstrators.", 'demonstrators.',
"timestamp": 1604182772, 'timestamp': 1604182772,
"uploader": "TMZ Staff", 'uploader': 'TMZ Staff',
"upload_date": "20201031", 'upload_date': '20201031',
"duration": 96.0, 'duration': 96.0,
"thumbnail": "https://imagez.tmz.com/image/f3/4by3/2020/10/31/f37bd5a8aef84497866f425130c58be3_xl.jpg", 'thumbnail': 'https://imagez.tmz.com/image/f3/4by3/2020/10/31/f37bd5a8aef84497866f425130c58be3_xl.jpg',
}, },
}, },
{ {
"url": "https://www.tmz.com/2020/11/05/gervonta-davis-car-crash-hit-and-run-police/", 'url': 'https://www.tmz.com/2020/11/05/gervonta-davis-car-crash-hit-and-run-police/',
"info_dict": { 'info_dict': {
"id": "Dddb6IGe-ws", 'id': 'Dddb6IGe-ws',
"ext": "mp4", 'ext': 'mp4',
"title": "SICK LAMBO GERVONTA DAVIS IN HIS NEW RIDE RIGHT AFTER KO AFTER LEO EsNews Boxing", 'title': 'SICK LAMBO GERVONTA DAVIS IN HIS NEW RIDE RIGHT AFTER KO AFTER LEO EsNews Boxing',
"uploader": "ESNEWS", 'uploader': 'ESNEWS',
"description": "md5:49675bc58883ccf80474b8aa701e1064", 'description': 'md5:49675bc58883ccf80474b8aa701e1064',
"upload_date": "20201102", 'upload_date': '20201102',
"uploader_id": "ESNEWS", 'uploader_id': '@ESNEWS',
"uploader_url": "http://www.youtube.com/user/ESNEWS", 'uploader_url': 'https://www.youtube.com/@ESNEWS',
"like_count": int, 'like_count': int,
"channel_id": "UCI-Oq7oFGakzSzHFlTtsUsQ", 'channel_id': 'UCI-Oq7oFGakzSzHFlTtsUsQ',
"channel": "ESNEWS", 'channel': 'ESNEWS',
"view_count": int, 'view_count': int,
"duration": 225, 'duration': 225,
"live_status": "not_live", 'live_status': 'not_live',
"thumbnail": "https://i.ytimg.com/vi_webp/Dddb6IGe-ws/maxresdefault.webp", 'thumbnail': 'https://i.ytimg.com/vi_webp/Dddb6IGe-ws/maxresdefault.webp',
"channel_url": "https://www.youtube.com/channel/UCI-Oq7oFGakzSzHFlTtsUsQ", 'channel_url': 'https://www.youtube.com/channel/UCI-Oq7oFGakzSzHFlTtsUsQ',
"channel_follower_count": int, 'channel_follower_count': int,
"playable_in_embed": True, 'playable_in_embed': True,
"categories": ["Sports"], 'categories': ['Sports'],
"age_limit": 0, 'age_limit': 0,
"tags": "count:10", 'tags': 'count:10',
"availability": "public", 'availability': 'public',
'comment_count': int,
}, },
}, },
{ {
"url": "https://www.tmz.com/2020/11/19/conor-mcgregor-dustin-poirier-contract-fight-ufc-257-fight-island/", 'url': 'https://www.tmz.com/2020/11/19/conor-mcgregor-dustin-poirier-contract-fight-ufc-257-fight-island/',
"info_dict": { 'info_dict': {
"id": "1329450007125225473", 'id': '1329448013937471491',
"ext": "mp4", 'ext': 'mp4',
"title": "The Mac Life - BREAKING: Conor McGregor (@thenotoriousmma) has signed his bout agreement for his rematch with Dustin Poirier for January 23.", 'title': 'The Mac Life - BREAKING: Conor McGregor (@thenotoriousmma) has signed his bout agreement for his rematch with Dustin Poirier for January 23.',
"uploader": "The Mac Life", 'uploader': 'The Mac Life',
"description": "md5:56e6009bbc3d12498e10d08a8e1f1c69", 'description': 'md5:56e6009bbc3d12498e10d08a8e1f1c69',
"upload_date": "20201119", 'upload_date': '20201119',
"uploader_id": "TheMacLife", 'display_id': '1329450007125225473',
"timestamp": 1605800556, 'uploader_id': 'TheMacLife',
"thumbnail": "https://pbs.twimg.com/media/EnMmfT8XYAExgxJ.jpg?name=small", 'timestamp': 1605800556,
"like_count": int, 'thumbnail': 'https://pbs.twimg.com/media/EnMmfT8XYAExgxJ.jpg?name=small',
"duration": 11.812, 'like_count': int,
"uploader_url": "https://twitter.com/TheMacLife", 'duration': 11.812,
"age_limit": 0, 'uploader_url': 'https://twitter.com/TheMacLife',
"repost_count": int, 'age_limit': 0,
"tags": [], 'repost_count': int,
"comment_count": int, 'tags': [],
'comment_count': int,
}, },
}, },
] ]
@ -167,25 +169,25 @@ class TMZIE(InfoExtractor):
def _real_extract(self, url): def _real_extract(self, url):
webpage = self._download_webpage(url, url) webpage = self._download_webpage(url, url)
jsonld = self._search_json_ld(webpage, url) jsonld = self._search_json_ld(webpage, url)
if not jsonld or "url" not in jsonld: if not jsonld or 'url' not in jsonld:
# try to extract from YouTube Player API # try to extract from YouTube Player API
# see https://developers.google.com/youtube/iframe_api_reference#Video_Queueing_Functions # see https://developers.google.com/youtube/iframe_api_reference#Video_Queueing_Functions
match_obj = re.search(r'\.cueVideoById\(\s*(?P<quote>[\'"])(?P<id>.*?)(?P=quote)', webpage) match_obj = re.search(r'\.cueVideoById\(\s*(?P<quote>[\'"])(?P<id>.*?)(?P=quote)', webpage)
if match_obj: if match_obj:
res = self.url_result(match_obj.group("id")) res = self.url_result(match_obj.group('id'))
return res return res
# try to extract from twitter # try to extract from twitter
blockquote_el = get_element_by_attribute("class", "twitter-tweet", webpage) blockquote_el = get_element_by_attribute('class', 'twitter-tweet', webpage)
if blockquote_el: if blockquote_el:
matches = re.findall( matches = re.findall(
r'<a[^>]+href=\s*(?P<quote>[\'"])(?P<link>.*?)(?P=quote)', r'<a[^>]+href=\s*(?P<quote>[\'"])(?P<link>.*?)(?P=quote)',
blockquote_el) blockquote_el)
if matches: if matches:
for _, match in matches: for _, match in matches:
if "/status/" in match: if '/status/' in match:
res = self.url_result(match) res = self.url_result(match)
return res return res
raise ExtractorError("No video found!") raise ExtractorError('No video found!')
if id not in jsonld: if id not in jsonld:
jsonld["id"] = url jsonld['id'] = url
return jsonld return jsonld