]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/dotsub.py
079f837500c65c13a7cdad3d65d281adfeff4907
[yt-dlp.git] / yt_dlp / extractor / dotsub.py
1 from .common import InfoExtractor
2 from ..utils import (
3 float_or_none,
4 int_or_none,
5 )
6
7
8 class DotsubIE(InfoExtractor):
9 _VALID_URL = r'https?://(?:www\.)?dotsub\.com/view/(?P<id>[^/]+)'
10 _TESTS = [{
11 'url': 'https://dotsub.com/view/9c63db2a-fa95-4838-8e6e-13deafe47f09',
12 'md5': '21c7ff600f545358134fea762a6d42b6',
13 'info_dict': {
14 'id': '9c63db2a-fa95-4838-8e6e-13deafe47f09',
15 'ext': 'flv',
16 'title': 'MOTIVATION - "It\'s Possible" Best Inspirational Video Ever',
17 'description': 'md5:41af1e273edbbdfe4e216a78b9d34ac6',
18 'thumbnail': 're:^https?://dotsub.com/media/9c63db2a-fa95-4838-8e6e-13deafe47f09/p',
19 'duration': 198,
20 'uploader': 'liuxt',
21 'timestamp': 1385778501.104,
22 'upload_date': '20131130',
23 'view_count': int,
24 }
25 }, {
26 'url': 'https://dotsub.com/view/747bcf58-bd59-45b7-8c8c-ac312d084ee6',
27 'md5': '2bb4a83896434d5c26be868c609429a3',
28 'info_dict': {
29 'id': '168006778',
30 'ext': 'mp4',
31 'title': 'Apartments and flats in Raipur the white symphony',
32 'description': 'md5:784d0639e6b7d1bc29530878508e38fe',
33 'thumbnail': 're:^https?://dotsub.com/media/747bcf58-bd59-45b7-8c8c-ac312d084ee6/p',
34 'duration': 290,
35 'timestamp': 1476767794.2809999,
36 'upload_date': '20161018',
37 'uploader': 'parthivi001',
38 'uploader_id': 'user52596202',
39 'view_count': int,
40 },
41 'add_ie': ['Vimeo'],
42 }]
43
44 def _real_extract(self, url):
45 video_id = self._match_id(url)
46
47 info = self._download_json(
48 'https://dotsub.com/api/media/%s/metadata' % video_id, video_id)
49 video_url = info.get('mediaURI')
50
51 if not video_url:
52 webpage = self._download_webpage(url, video_id)
53 video_url = self._search_regex(
54 [r'<source[^>]+src="([^"]+)"', r'"file"\s*:\s*\'([^\']+)'],
55 webpage, 'video url', default=None)
56 info_dict = {
57 'id': video_id,
58 'url': video_url,
59 'ext': 'flv',
60 }
61
62 if not video_url:
63 setup_data = self._parse_json(self._html_search_regex(
64 r'(?s)data-setup=([\'"])(?P<content>(?!\1).+?)\1',
65 webpage, 'setup data', group='content'), video_id)
66 info_dict = {
67 '_type': 'url_transparent',
68 'url': setup_data['src'],
69 }
70
71 info_dict.update({
72 'title': info['title'],
73 'description': info.get('description'),
74 'thumbnail': info.get('screenshotURI'),
75 'duration': int_or_none(info.get('duration'), 1000),
76 'uploader': info.get('user'),
77 'timestamp': float_or_none(info.get('dateCreated'), 1000),
78 'view_count': int_or_none(info.get('numberOfViews')),
79 })
80
81 return info_dict