]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/played.py
debian/rules: Ignore tests temporarily.
[youtubedl] / youtube_dl / extractor / played.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import os.path
6
7 from .common import InfoExtractor
8 from ..utils import (
9 ExtractorError,
10 sanitized_Request,
11 urlencode_postdata,
12 )
13
14
15 class PlayedIE(InfoExtractor):
16 IE_NAME = 'played.to'
17 _VALID_URL = r'https?://(?:www\.)?played\.to/(?P<id>[a-zA-Z0-9_-]+)'
18
19 _TEST = {
20 'url': 'http://played.to/j2f2sfiiukgt',
21 'md5': 'c2bd75a368e82980e7257bf500c00637',
22 'info_dict': {
23 'id': 'j2f2sfiiukgt',
24 'ext': 'flv',
25 'title': 'youtube-dl_test_video.mp4',
26 },
27 'skip': 'Removed for copyright infringement.', # oh wow
28 }
29
30 def _real_extract(self, url):
31 video_id = self._match_id(url)
32 orig_webpage = self._download_webpage(url, video_id)
33
34 m_error = re.search(
35 r'(?s)Reason for deletion:.*?<b class="err"[^>]*>(?P<msg>[^<]+)</b>', orig_webpage)
36 if m_error:
37 raise ExtractorError(m_error.group('msg'), expected=True)
38
39 data = self._hidden_inputs(orig_webpage)
40
41 self._sleep(2, video_id)
42
43 post = urlencode_postdata(data)
44 headers = {
45 b'Content-Type': b'application/x-www-form-urlencoded',
46 }
47 req = sanitized_Request(url, post, headers)
48 webpage = self._download_webpage(
49 req, video_id, note='Downloading video page ...')
50
51 title = os.path.splitext(data['fname'])[0]
52
53 video_url = self._search_regex(
54 r'file: "?(.+?)",', webpage, 'video URL')
55
56 return {
57 'id': video_id,
58 'title': title,
59 'url': video_url,
60 }