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