[vshare] Add extractor (closes #12278)
[youtube-dl] / youtube_dl / extractor / vshare.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6
7 class VShareIE(InfoExtractor):
8     _VALID_URL = r'https?://(?:www\.)?vshare\.io/[dv]/(?P<id>[^/?#&]+)'
9     _TESTS = [{
10         'url': 'https://vshare.io/d/0f64ce6',
11         'md5': '16d7b8fef58846db47419199ff1ab3e7',
12         'info_dict': {
13             'id': '0f64ce6',
14             'title': 'vl14062007715967',
15             'ext': 'mp4',
16         }
17     }, {
18         'url': 'https://vshare.io/v/0f64ce6/width-650/height-430/1',
19         'only_matching': True,
20     }]
21
22     def _real_extract(self, url):
23         video_id = self._match_id(url)
24
25         webpage = self._download_webpage(
26             'https://vshare.io/d/%s' % video_id, video_id)
27
28         title = self._html_search_regex(
29             r'(?s)<div id="root-container">(.+?)<br/>', webpage, 'title')
30         video_url = self._search_regex(
31             r'<a[^>]+href=(["\'])(?P<url>(?:https?:)?//.+?)\1[^>]*>[Cc]lick\s+here',
32             webpage, 'video url', group='url')
33
34         return {
35             'id': video_id,
36             'title': title,
37             'url': video_url,
38         }