]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/ndtv.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / ndtv.py
CommitLineData
ac668111 1import urllib.parse
2
caefb1de 3from .common import InfoExtractor
ac668111 4from ..utils import parse_duration, remove_end, unified_strdate, urljoin
caefb1de
PH
5
6
7class NDTVIE(InfoExtractor):
df773c3d 8 _WORKING = False
55c727a5 9 _VALID_URL = r'https?://(?:[^/]+\.)?ndtv\.com/(?:[^/]+/)*videos?/?(?:[^/]+/)*[^/?^&]+-(?P<id>\d+)'
10
11 _TESTS = [
12 {
13 'url': 'https://khabar.ndtv.com/video/show/prime-time/prime-time-ill-system-and-poor-education-468818',
14 'md5': '78efcf3880ef3fd9b83d405ca94a38eb',
15 'info_dict': {
16 'id': '468818',
17 'ext': 'mp4',
add96eb9 18 'title': 'प्राइम टाइम: सिस्टम बीमार, स्कूल बदहाल',
55c727a5 19 'description': 'md5:f410512f1b49672e5695dea16ef2731d',
20 'upload_date': '20170928',
21 'duration': 2218,
22 'thumbnail': r're:https?://.*\.jpg',
add96eb9 23 },
55c727a5 24 },
25 {
26 # __filename is url
27 'url': 'http://movies.ndtv.com/videos/cracker-free-diwali-wishes-from-karan-johar-kriti-sanon-other-stars-470304',
28 'md5': 'f1d709352305b44443515ac56b45aa46',
29 'info_dict': {
30 'id': '470304',
31 'ext': 'mp4',
add96eb9 32 'title': 'Cracker-Free Diwali Wishes From Karan Johar, Kriti Sanon & Other Stars',
55c727a5 33 'description': 'md5:f115bba1adf2f6433fa7c1ade5feb465',
34 'upload_date': '20171019',
35 'duration': 137,
36 'thumbnail': r're:https?://.*\.jpg',
add96eb9 37 },
55c727a5 38 },
39 {
40 'url': 'https://www.ndtv.com/video/news/news/delhi-s-air-quality-status-report-after-diwali-is-very-poor-470372',
add96eb9 41 'only_matching': True,
55c727a5 42 },
43 {
44 'url': 'https://auto.ndtv.com/videos/the-cnb-daily-october-13-2017-469935',
add96eb9 45 'only_matching': True,
55c727a5 46 },
47 {
48 'url': 'https://sports.ndtv.com/cricket/videos/2nd-t20i-rock-thrown-at-australia-cricket-team-bus-after-win-over-india-469764',
add96eb9 49 'only_matching': True,
55c727a5 50 },
51 {
52 'url': 'http://gadgets.ndtv.com/videos/uncharted-the-lost-legacy-review-465568',
add96eb9 53 'only_matching': True,
55c727a5 54 },
55 {
56 'url': 'http://profit.ndtv.com/videos/news/video-indian-economy-on-very-solid-track-international-monetary-fund-chief-470040',
add96eb9 57 'only_matching': True,
55c727a5 58 },
59 {
60 'url': 'http://food.ndtv.com/video-basil-seeds-coconut-porridge-419083',
add96eb9 61 'only_matching': True,
55c727a5 62 },
63 {
64 'url': 'https://doctor.ndtv.com/videos/top-health-stories-of-the-week-467396',
add96eb9 65 'only_matching': True,
55c727a5 66 },
67 {
68 'url': 'https://swirlster.ndtv.com/video/how-to-make-friends-at-work-469324',
add96eb9 69 'only_matching': True,
70 },
55c727a5 71 ]
caefb1de
PH
72
73 def _real_extract(self, url):
c511f13f 74 video_id = self._match_id(url)
caefb1de
PH
75 webpage = self._download_webpage(url, video_id)
76
55c727a5 77 # '__title' does not contain extra words such as sub-site name, "Video" etc.
ac668111 78 title = urllib.parse.unquote_plus(
3089bc74
S
79 self._search_regex(r"__title\s*=\s*'([^']+)'", webpage, 'title', default=None)
80 or self._og_search_title(webpage))
dd81769c 81
caefb1de 82 filename = self._search_regex(
55c727a5 83 r"(?:__)?filename\s*[:=]\s*'([^']+)'", webpage, 'video filename')
84 # in "movies" sub-site pages, filename is URL
85 video_url = urljoin('https://ndtvod.bc-ssl.cdn.bitgravity.com/23372/ndtv/', filename.lstrip('/'))
caefb1de 86
55c727a5 87 # "doctor" sub-site has MM:SS format
88 duration = parse_duration(self._search_regex(
89 r"(?:__)?duration\s*[:=]\s*'([^']+)'", webpage, 'duration', fatal=False))
caefb1de 90
55c727a5 91 # "sports", "doctor", "swirlster" sub-sites don't have 'publish-date'
dd81769c 92 upload_date = unified_strdate(self._html_search_meta(
55c727a5 93 'publish-date', webpage, 'upload date', default=None) or self._html_search_meta(
94 'uploadDate', webpage, 'upload date', default=None) or self._search_regex(
95 r'datePublished"\s*:\s*"([^"]+)"', webpage, 'upload date', fatal=False))
caefb1de 96
dd81769c 97 description = remove_end(self._og_search_description(webpage), ' (Read more)')
3141feb7 98
caefb1de
PH
99 return {
100 'id': video_id,
101 'url': video_url,
3141feb7 102 'title': title,
caefb1de
PH
103 'description': description,
104 'thumbnail': self._og_search_thumbnail(webpage),
105 'duration': duration,
106 'upload_date': upload_date,
107 }