[Primesharetv] Add public domain example video
[youtube-dl] / youtube_dl / extractor / primesharetv.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     int_or_none,
7     parse_filesize,
8     unified_strdate,
9     urlencode_postdata,
10 )
11 from ..compat import (
12     compat_urllib_request,
13 )
14
15 class PrimesharetvIE(InfoExtractor):
16     _VALID_URL = r'https?://(?:www\.)?primeshare\.tv/download/(?P<id>.*)(?:.*)'
17
18     _TESTS = [
19         {
20             'url': 'http://primeshare.tv/download/238790B611',
21             'md5': 'bb41f9f6c0dd434c729f04ce5b677192',
22             'info_dict': {
23                 'id': '238790B611',
24                 'ext': 'mp4',
25                 "title": "Public Domain - 1960s Commercial - Crest Toothpaste-YKsuFona [...]",
26                 "duration": 10,
27             },
28         }
29     ]
30
31     def _real_extract(self, url):
32         video_id = self._match_id(url)
33         webpage = self._download_webpage(url, video_id)
34        
35         self._sleep(9, video_id)
36         
37         hashtoken = self._search_regex(r' name="hash" value="(.*?)" ', webpage, 'hash token')
38         data = urlencode_postdata({
39             'hash': hashtoken,
40         })
41         headers = {
42             'Referer': url,
43             'Content-Type': 'application/x-www-form-urlencoded',
44         }
45         video_page_request = compat_urllib_request.Request(url, data, headers=headers)
46         video_page = self._download_webpage(video_page_request, None, False, '')
47
48         video_url = self._html_search_regex(
49             r'url: \'(http://[a-z0-9]+\.primeshare\.tv:443/file/get/[^\']+)\',', video_page, 'video url')
50
51         title = self._html_search_regex(
52             r'<h1>Watch&nbsp;[^\(]+\(([^/)]+)\)&nbsp;', video_page, 'title')
53
54         return {
55             'id': video_id,
56             'url': video_url,
57             'title': title,
58             'ext': 'mp4',
59         }