]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/goshgay.py
18474cbb72684ac6327957fb3385fb9de3bc4480
[youtubedl] / youtube_dl / extractor / goshgay.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 compat_urlparse,
7 ExtractorError,
8 )
9
10
11 class GoshgayIE(InfoExtractor):
12 _VALID_URL = r'^(?:https?://)www.goshgay.com/video(?P<id>\d+?)($|/)'
13 _TEST = {
14 'url': 'http://www.goshgay.com/video4116282',
15 'md5': '268b9f3c3229105c57859e166dd72b03',
16 'info_dict': {
17 'id': '4116282',
18 'ext': 'flv',
19 'title': 'md5:089833a4790b5e103285a07337f245bf',
20 'thumbnail': 're:http://.*\.jpg',
21 'age_limit': 18,
22 }
23 }
24
25 def _real_extract(self, url):
26 video_id = self._match_id(url)
27
28 webpage = self._download_webpage(url, video_id)
29 title = self._og_search_title(webpage)
30 thumbnail = self._og_search_thumbnail(webpage)
31 family_friendly = self._html_search_meta(
32 'isFamilyFriendly', webpage, default='false')
33 config_url = self._search_regex(
34 r"'config'\s*:\s*'([^']+)'", webpage, 'config URL')
35
36 config = self._download_xml(
37 config_url, video_id, 'Downloading player config XML')
38
39 if config is None:
40 raise ExtractorError('Missing config XML')
41 if config.tag != 'config':
42 raise ExtractorError('Missing config attribute')
43 fns = config.findall('file')
44 if len(fns) < 1:
45 raise ExtractorError('Missing media URI')
46 video_url = fns[0].text
47
48 url_comp = compat_urlparse.urlparse(url)
49 ref = "%s://%s%s" % (url_comp[0], url_comp[1], url_comp[2])
50
51 return {
52 'id': video_id,
53 'url': video_url,
54 'title': title,
55 'thumbnail': thumbnail,
56 'http_referer': ref,
57 'age_limit': 0 if family_friendly == 'true' else 18,
58 }