[camwithher] Add extractor
[youtube-dl] / youtube_dl / extractor / camwithher.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4
5
6 class CamWithHerIE(InfoExtractor):
7     _VALID_URL = r'https?://(?:www\.)?camwithher\.tv/view_video\.php\?.*viewkey=(?P<id>\w+)'
8
9     _TESTS = [
10         {
11             'url': 'http://camwithher.tv/view_video.php?viewkey=6e9a24e2c0e842e1f177&page=&viewtype=&category=',
12             'info_dict': {
13                 'id': '5644',
14                 'ext': 'flv',
15                 'title': 'Periscope Tease',
16             },
17             'params': {
18                 'skip_download': True,
19             }
20         },
21         {
22             'url': 'http://camwithher.tv/view_video.php?viewkey=6dfd8b7c97531a459937',
23             'only_matching': True,
24         },
25         {
26             'url': 'http://camwithher.tv/view_video.php?page=&viewkey=6e9a24e2c0e842e1f177&viewtype=&category=',
27             'only_matching': True,
28         },
29         {
30             'url': 'http://camwithher.tv/view_video.php?viewkey=b6c3b5bea9515d1a1fc4&page=&viewtype=&category=mv',
31             'only_matching': True,
32         }
33     ]
34
35     def _real_extract(self, url):
36         video_id = self._match_id(url)
37
38         webpage = self._download_webpage(url, video_id)
39
40         flv_id = self._html_search_regex(r'<a href="/download/\?v=(\d+)', webpage, 'id')
41
42         # The number "2010" was reverse-engineered from cwhplayer.swf.
43         # It appears that they changed their video codec, and hence the RTMP URL
44         # scheme at that video's ID.
45         rtmp_url = 'rtmp://camwithher.tv/clipshare/%s' % (('mp4:%s.mp4' % flv_id) if int(flv_id) > 2010 else flv_id)
46
47         title = self._html_search_regex(r'<div style="float:left">\s+<h2>(.+?)</h2>', webpage, 'title')
48
49         return {
50             'id': flv_id,
51             'url': rtmp_url,
52             'no_resume': True,
53             'ext': 'flv',
54             'title': title,
55         }