]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/thescene.py
b8504f0ebdc04ade7d580102f0bcf506bebc4230
[youtubedl] / youtube_dl / extractor / thescene.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4
5 from ..compat import compat_urlparse
6 from ..utils import (
7 int_or_none,
8 qualities,
9 )
10
11
12 class TheSceneIE(InfoExtractor):
13 _VALID_URL = r'https?://thescene\.com/watch/[^/]+/(?P<id>[^/#?]+)'
14
15 _TEST = {
16 'url': 'https://thescene.com/watch/vogue/narciso-rodriguez-spring-2013-ready-to-wear',
17 'info_dict': {
18 'id': '520e8faac2b4c00e3c6e5f43',
19 'ext': 'mp4',
20 'title': 'Narciso Rodriguez: Spring 2013 Ready-to-Wear',
21 'display_id': 'narciso-rodriguez-spring-2013-ready-to-wear',
22 'duration': 127,
23 'series': 'Style.com Fashion Shows',
24 'season': 'Ready To Wear Spring 2013',
25 'tags': list,
26 'categories': list,
27 },
28 }
29
30 def _real_extract(self, url):
31 display_id = self._match_id(url)
32
33 webpage = self._download_webpage(url, display_id)
34
35 player_url = compat_urlparse.urljoin(
36 url,
37 self._html_search_regex(
38 r'id=\'js-player-script\'[^>]+src=\'(.+?)\'', webpage, 'player url'))
39
40 player = self._download_webpage(player_url, display_id)
41 info = self._parse_json(
42 self._search_regex(
43 r'(?m)video\s*:\s*({.+?}),$', player, 'info json'),
44 display_id)
45
46 video_id = info['id']
47 title = info['title']
48
49 qualities_order = qualities(('low', 'high'))
50 formats = [{
51 'format_id': '{0}-{1}'.format(f['type'].split('/')[0], f['quality']),
52 'url': f['src'],
53 'quality': qualities_order(f['quality']),
54 } for f in info['sources']]
55 self._sort_formats(formats)
56
57 return {
58 'id': video_id,
59 'display_id': display_id,
60 'title': title,
61 'formats': formats,
62 'thumbnail': info.get('poster_frame'),
63 'duration': int_or_none(info.get('duration')),
64 'series': info.get('series_title'),
65 'season': info.get('season_title'),
66 'tags': info.get('tags'),
67 'categories': info.get('categories'),
68 }