]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/joj.py
Annotate changelog with bug being closed.
[youtubedl] / youtube_dl / extractor / joj.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 compat_str
8 from ..utils import (
9 int_or_none,
10 js_to_json,
11 try_get,
12 )
13
14
15 class JojIE(InfoExtractor):
16 _VALID_URL = r'''(?x)
17 (?:
18 joj:|
19 https?://media\.joj\.sk/embed/
20 )
21 (?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})
22 '''
23 _TESTS = [{
24 'url': 'https://media.joj.sk/embed/a388ec4c-6019-4a4a-9312-b1bee194e932',
25 'info_dict': {
26 'id': 'a388ec4c-6019-4a4a-9312-b1bee194e932',
27 'ext': 'mp4',
28 'title': 'NOVÉ BÝVANIE',
29 'thumbnail': r're:^https?://.*\.jpg$',
30 'duration': 3118,
31 }
32 }, {
33 'url': 'joj:a388ec4c-6019-4a4a-9312-b1bee194e932',
34 'only_matching': True,
35 }]
36
37 @staticmethod
38 def _extract_urls(webpage):
39 return re.findall(
40 r'<iframe\b[^>]+\bsrc=["\'](?P<url>(?:https?:)?//media\.joj\.sk/embed/[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})',
41 webpage)
42
43 def _real_extract(self, url):
44 video_id = self._match_id(url)
45
46 webpage = self._download_webpage(
47 'https://media.joj.sk/embed/%s' % video_id, video_id)
48
49 title = self._search_regex(
50 (r'videoTitle\s*:\s*(["\'])(?P<title>(?:(?!\1).)+)\1',
51 r'<title>(?P<title>[^<]+)'), webpage, 'title',
52 default=None, group='title') or self._og_search_title(webpage)
53
54 bitrates = self._parse_json(
55 self._search_regex(
56 r'(?s)bitrates\s*=\s*({.+?});', webpage, 'bitrates',
57 default='{}'),
58 video_id, transform_source=js_to_json, fatal=False)
59
60 formats = []
61 for format_url in try_get(bitrates, lambda x: x['mp4'], list) or []:
62 if isinstance(format_url, compat_str):
63 height = self._search_regex(
64 r'(\d+)[pP]\.', format_url, 'height', default=None)
65 formats.append({
66 'url': format_url,
67 'format_id': '%sp' % height if height else None,
68 'height': int(height),
69 })
70 if not formats:
71 playlist = self._download_xml(
72 'https://media.joj.sk/services/Video.php?clip=%s' % video_id,
73 video_id)
74 for file_el in playlist.findall('./files/file'):
75 path = file_el.get('path')
76 if not path:
77 continue
78 format_id = file_el.get('id') or file_el.get('label')
79 formats.append({
80 'url': 'http://n16.joj.sk/storage/%s' % path.replace(
81 'dat/', '', 1),
82 'format_id': format_id,
83 'height': int_or_none(self._search_regex(
84 r'(\d+)[pP]', format_id or path, 'height',
85 default=None)),
86 })
87 self._sort_formats(formats)
88
89 thumbnail = self._og_search_thumbnail(webpage)
90
91 duration = int_or_none(self._search_regex(
92 r'videoDuration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
93
94 return {
95 'id': video_id,
96 'title': title,
97 'thumbnail': thumbnail,
98 'duration': duration,
99 'formats': formats,
100 }