]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/promptfile.py
[SBS] fixes due to website changes
[youtube-dl] / youtube_dl / extractor / promptfile.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import (
8     compat_urllib_parse,
9     compat_urllib_request,
10 )
11 from ..utils import (
12     determine_ext,
13     ExtractorError,
14 )
15
16
17 class PromptFileIE(InfoExtractor):
18     _VALID_URL = r'https?://(?:www\.)?promptfile\.com/l/(?P<id>[0-9A-Z\-]+)'
19     _TEST = {
20         'url': 'http://www.promptfile.com/l/D21B4746E9-F01462F0FF',
21         'md5': 'd1451b6302da7215485837aaea882c4c',
22         'info_dict': {
23             'id': 'D21B4746E9-F01462F0FF',
24             'ext': 'mp4',
25             'title': 'Birds.mp4',
26             'thumbnail': 're:^https?://.*\.jpg$',
27         }
28     }
29
30     def _real_extract(self, url):
31         video_id = self._match_id(url)
32         webpage = self._download_webpage(url, video_id)
33
34         if re.search(r'<div.+id="not_found_msg".+>(?!We are).+</div>[^-]', webpage) is not None:
35             raise ExtractorError('Video %s does not exist' % video_id,
36                                  expected=True)
37
38         fields = self._form_hidden_inputs(webpage)
39         post = compat_urllib_parse.urlencode(fields)
40         req = compat_urllib_request.Request(url, post)
41         req.add_header('Content-type', 'application/x-www-form-urlencoded')
42         webpage = self._download_webpage(
43             req, video_id, 'Downloading video page')
44
45         url = self._html_search_regex(r'url:\s*\'([^\']+)\'', webpage, 'URL')
46         title = self._html_search_regex(
47             r'<span.+title="([^"]+)">', webpage, 'title')
48         thumbnail = self._html_search_regex(
49             r'<div id="player_overlay">.*button>.*?<img src="([^"]+)"',
50             webpage, 'thumbnail', fatal=False, flags=re.DOTALL)
51
52         formats = [{
53             'format_id': 'sd',
54             'url': url,
55             'ext': determine_ext(title),
56         }]
57         self._sort_formats(formats)
58
59         return {
60             'id': video_id,
61             'title': title,
62             'thumbnail': thumbnail,
63             'formats': formats,
64         }