]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/promptfile.py
Imported Upstream version 2016.06.25
[youtubedl] / 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 ..utils import (
8 determine_ext,
9 ExtractorError,
10 sanitized_Request,
11 urlencode_postdata,
12 )
13
14
15 class PromptFileIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?promptfile\.com/l/(?P<id>[0-9A-Z\-]+)'
17 _TEST = {
18 'url': 'http://www.promptfile.com/l/D21B4746E9-F01462F0FF',
19 'md5': 'd1451b6302da7215485837aaea882c4c',
20 'info_dict': {
21 'id': 'D21B4746E9-F01462F0FF',
22 'ext': 'mp4',
23 'title': 'Birds.mp4',
24 'thumbnail': 're:^https?://.*\.jpg$',
25 }
26 }
27
28 def _real_extract(self, url):
29 video_id = self._match_id(url)
30 webpage = self._download_webpage(url, video_id)
31
32 if re.search(r'<div.+id="not_found_msg".+>(?!We are).+</div>[^-]', webpage) is not None:
33 raise ExtractorError('Video %s does not exist' % video_id,
34 expected=True)
35
36 fields = self._hidden_inputs(webpage)
37 post = urlencode_postdata(fields)
38 req = sanitized_Request(url, post)
39 req.add_header('Content-type', 'application/x-www-form-urlencoded')
40 webpage = self._download_webpage(
41 req, video_id, 'Downloading video page')
42
43 url = self._html_search_regex(r'url:\s*\'([^\']+)\'', webpage, 'URL')
44 title = self._html_search_regex(
45 r'<span.+title="([^"]+)">', webpage, 'title')
46 thumbnail = self._html_search_regex(
47 r'<div id="player_overlay">.*button>.*?<img src="([^"]+)"',
48 webpage, 'thumbnail', fatal=False, flags=re.DOTALL)
49
50 formats = [{
51 'format_id': 'sd',
52 'url': url,
53 'ext': determine_ext(title),
54 }]
55 self._sort_formats(formats)
56
57 return {
58 'id': video_id,
59 'title': title,
60 'thumbnail': thumbnail,
61 'formats': formats,
62 }