mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-27 06:10:12 +01:00
updated extractor to a simpler process
This commit is contained in:
parent
db4b19eaff
commit
dbb1b746d4
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import clean_html, parse_duration, remove_end, unified_strdate
|
from ..utils import clean_html, determine_ext, parse_duration, traverse_obj, unescapeHTML, unified_strdate
|
||||||
|
|
||||||
|
|
||||||
class NDTVIE(InfoExtractor):
|
class NDTVIE(InfoExtractor):
|
||||||
|
@ -10,7 +10,7 @@ class NDTVIE(InfoExtractor):
|
||||||
_TESTS = [
|
_TESTS = [
|
||||||
{
|
{
|
||||||
'url': 'https://khabar.ndtv.com/video/show/prime-time/prime-time-ill-system-and-poor-education-468818',
|
'url': 'https://khabar.ndtv.com/video/show/prime-time/prime-time-ill-system-and-poor-education-468818',
|
||||||
'md5': '78efcf3880ef3fd9b83d405ca94a38eb',
|
'md5': '5237500d57c8af47a519c4af9e2fd9c0',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '468818',
|
'id': '468818',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
|
@ -19,11 +19,13 @@ class NDTVIE(InfoExtractor):
|
||||||
'upload_date': '20170928',
|
'upload_date': '20170928',
|
||||||
'duration': 2218,
|
'duration': 2218,
|
||||||
'thumbnail': r're:https?://.*\.jpg',
|
'thumbnail': r're:https?://.*\.jpg',
|
||||||
|
'categories': 'shows',
|
||||||
|
'channel_id': '2',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'url': 'http://movies.ndtv.com/videos/cracker-free-diwali-wishes-from-karan-johar-kriti-sanon-other-stars-470304',
|
'url': 'http://movies.ndtv.com/videos/cracker-free-diwali-wishes-from-karan-johar-kriti-sanon-other-stars-470304',
|
||||||
'md5': 'f1d709352305b44443515ac56b45aa46',
|
'md5': 'b7ef90f55e63885aef59c59cf2e44e81',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '470304',
|
'id': '470304',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
|
@ -32,6 +34,8 @@ class NDTVIE(InfoExtractor):
|
||||||
'upload_date': '20171019',
|
'upload_date': '20171019',
|
||||||
'duration': 137,
|
'duration': 137,
|
||||||
'thumbnail': r're:https?://.*\.jpg',
|
'thumbnail': r're:https?://.*\.jpg',
|
||||||
|
'categories': 'entertainment',
|
||||||
|
'channel_id': '1',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -45,6 +49,8 @@ class NDTVIE(InfoExtractor):
|
||||||
'upload_date': '20240818',
|
'upload_date': '20240818',
|
||||||
'duration': 220,
|
'duration': 220,
|
||||||
'thumbnail': 'https://c.ndtvimg.com/2024-08/be8djnjc_jai-jawan_640x480_18_August_24.jpg',
|
'thumbnail': 'https://c.ndtvimg.com/2024-08/be8djnjc_jai-jawan_640x480_18_August_24.jpg',
|
||||||
|
'categories': 'entertainment',
|
||||||
|
'channel_id': '1',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -58,6 +64,8 @@ class NDTVIE(InfoExtractor):
|
||||||
'upload_date': '20240818',
|
'upload_date': '20240818',
|
||||||
'duration': 931,
|
'duration': 931,
|
||||||
'thumbnail': 'https://c.ndtvimg.com/2024-08/hh48aduk_dr-sameer-kaul_640x480_18_August_24.jpg',
|
'thumbnail': 'https://c.ndtvimg.com/2024-08/hh48aduk_dr-sameer-kaul_640x480_18_August_24.jpg',
|
||||||
|
'categories': 'news',
|
||||||
|
'channel_id': '1',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -71,6 +79,8 @@ class NDTVIE(InfoExtractor):
|
||||||
'upload_date': '20240730',
|
'upload_date': '20240730',
|
||||||
'duration': 45,
|
'duration': 45,
|
||||||
'thumbnail': 'https://c.ndtvimg.com/2024-07/itrg8ilo_msdhoni_640x480_31_July_24.jpg',
|
'thumbnail': 'https://c.ndtvimg.com/2024-07/itrg8ilo_msdhoni_640x480_31_July_24.jpg',
|
||||||
|
'categories': 'fangully',
|
||||||
|
'channel_id': '',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -84,6 +94,8 @@ class NDTVIE(InfoExtractor):
|
||||||
'upload_date': '20240805',
|
'upload_date': '20240805',
|
||||||
'duration': 1304,
|
'duration': 1304,
|
||||||
'thumbnail': 'https://c.ndtvimg.com/2024-08/kh67tomo_heartattack_640x480_05_August_24.jpg',
|
'thumbnail': 'https://c.ndtvimg.com/2024-08/kh67tomo_heartattack_640x480_05_August_24.jpg',
|
||||||
|
'categories': 'Health',
|
||||||
|
'channel_id': '1',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -93,10 +105,12 @@ class NDTVIE(InfoExtractor):
|
||||||
'id': '767098',
|
'id': '767098',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Watch NDTV Food Awards 2024 On NDTV 24x7 On Saturday 9th March, 2024',
|
'title': 'Watch NDTV Food Awards 2024 On NDTV 24x7 On Saturday 9th March, 2024',
|
||||||
'description': 'md5:4a8831a038ab50dc5ea76b1fad4b51d0',
|
'description': 'md5:11948e8404b058cd0a9d174aa1e88e84',
|
||||||
'upload_date': '20240307',
|
'upload_date': '20240307',
|
||||||
'duration': 35,
|
'duration': 35,
|
||||||
'thumbnail': 'https://c.ndtvimg.com/2024-03/2eianfs_food-awards_640x480_08_March_24.jpg',
|
'thumbnail': 'https://c.ndtvimg.com/2024-03/2eianfs_food-awards_640x480_08_March_24.jpg',
|
||||||
|
'categories': 'food',
|
||||||
|
'channel_id': '1',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -137,44 +151,46 @@ def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
webpage = self._download_webpage(url, video_id)
|
webpage = self._download_webpage(url, video_id)
|
||||||
|
|
||||||
title = clean_html(
|
# required for removing unwanted js expression in the json data
|
||||||
self._html_search_meta('taboola:title', webpage, 'title', default=None)
|
# found this expression in one article
|
||||||
or self._html_search_meta('name', webpage, 'title', default=None)
|
# will update this json data handler more generic if more of similar patterns found
|
||||||
or self._og_search_title(webpage))
|
webpage = webpage.replace('true / false', 'true')
|
||||||
|
|
||||||
# in "movies" sub-site pages, filename is URL
|
data = self._search_json(r'__html5playerdata\s*=\s*', webpage, 'json_data', video_id)
|
||||||
# in "food" sub-site pages, url string contains escape characters
|
|
||||||
video_url = (self._html_search_meta('contentUrl', webpage, 'video-url', default=None)
|
|
||||||
or self._search_regex(r'"media_mp4"\s*:\s*"([^"]+)', webpage, 'video-url'))
|
|
||||||
if video_url is not None:
|
|
||||||
video_url = video_url.replace('\\/', '/')
|
|
||||||
|
|
||||||
# "doctor" sub-site has MM:SS format
|
title = clean_html(unescapeHTML(traverse_obj(data, ('title'))))
|
||||||
duration = parse_duration(
|
duration = parse_duration(traverse_obj(data, ('dur')))
|
||||||
self._html_search_meta('video:duration', webpage, 'duration', default=None)
|
upload_date = unified_strdate(traverse_obj(data, ('date')))
|
||||||
or self._search_regex(r'"dur"\s*:\s*"([^"]+)', webpage, 'duration', fatal=False, default=None))
|
video_m3u8 = traverse_obj(data, ('media'))
|
||||||
|
video_mp4 = traverse_obj(data, ('media_mp4'))
|
||||||
|
video_webm = traverse_obj(data, ('media_webm'))
|
||||||
|
description = clean_html(unescapeHTML(traverse_obj(data, ('description'))))
|
||||||
|
thumbnail = traverse_obj(data, ('image'))
|
||||||
|
channel_id = traverse_obj(data, ('channel'))
|
||||||
|
categories = traverse_obj(data, ('category'))
|
||||||
|
|
||||||
# "sports", "doctor", "swirlster" sub-sites don't have 'publish-date'
|
formats = []
|
||||||
upload_date = unified_strdate(
|
if video_mp4:
|
||||||
self._html_search_meta('publish-date', webpage, 'upload date', default=None)
|
formats.append({'url': video_mp4, 'ext': determine_ext(video_mp4)})
|
||||||
or self._html_search_meta('uploadDate', webpage, 'upload date', default=None)
|
if video_webm:
|
||||||
or self._search_regex(r'datePublished"\s*:\s*"([^"]+)', webpage, 'upload date', fatal=False, default=None))
|
formats.append({'url': video_webm, 'ext': determine_ext(video_webm)})
|
||||||
|
if video_m3u8:
|
||||||
description = clean_html(
|
m3u8_data = self._extract_m3u8_formats(video_m3u8, video_id)
|
||||||
self._html_search_meta('description', webpage, 'description', default=None)
|
formats.extend(m3u8_data)
|
||||||
or remove_end(self._og_search_description(webpage, default=None), ' (Read more)'))
|
# here, making the assumption that mp4 video available is always the highest quality
|
||||||
|
# will update if any deviation found
|
||||||
thumbnail = (self._html_search_meta('thumbnailUrl', webpage, 'thumbnail', default=None)
|
formats[0]['width'] = m3u8_data[-1]['width']
|
||||||
or self._search_regex(r'"image"\s*:\s*"([^\"]+)', webpage, 'thumbnail', fatal=False, default=None))
|
formats[0]['height'] = m3u8_data[-1]['height']
|
||||||
if thumbnail is not None:
|
formats[0]['tbr'] = m3u8_data[-1]['tbr']
|
||||||
thumbnail = thumbnail.replace('\\/', '/')
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'url': video_url,
|
'formats': formats,
|
||||||
'title': title,
|
'title': title,
|
||||||
'description': description,
|
'description': description,
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'upload_date': upload_date,
|
'upload_date': upload_date,
|
||||||
|
'categories': categories,
|
||||||
|
'channel_id': channel_id,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user