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