]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/vshare.py
Completely change project name to yt-dlp (#85)
[yt-dlp.git] / yt_dlp / extractor / vshare.py
CommitLineData
2ab0bfcd
S
1# coding: utf-8
2from __future__ import unicode_literals
3
0987f2dd
T
4import re
5
2ab0bfcd 6from .common import InfoExtractor
0987f2dd 7from ..compat import compat_chr
ff31f2d5
S
8from ..utils import (
9 decode_packed_codes,
10 ExtractorError,
11)
2ab0bfcd
S
12
13
14class VShareIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?vshare\.io/[dv]/(?P<id>[^/?#&]+)'
16 _TESTS = [{
17 'url': 'https://vshare.io/d/0f64ce6',
0987f2dd 18 'md5': '17b39f55b5497ae8b59f5fbce8e35886',
2ab0bfcd
S
19 'info_dict': {
20 'id': '0f64ce6',
21 'title': 'vl14062007715967',
22 'ext': 'mp4',
23 }
24 }, {
25 'url': 'https://vshare.io/v/0f64ce6/width-650/height-430/1',
26 'only_matching': True,
27 }]
28
a2b6aba8
S
29 @staticmethod
30 def _extract_urls(webpage):
31 return re.findall(
32 r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?vshare\.io/v/[^/?#&]+)',
33 webpage)
34
0987f2dd 35 def _extract_packed(self, webpage):
a2b6aba8
S
36 packed = self._search_regex(
37 r'(eval\(function.+)', webpage, 'packed code')
0987f2dd
T
38 unpacked = decode_packed_codes(packed)
39 digits = self._search_regex(r'\[((?:\d+,?)+)\]', unpacked, 'digits')
a2b6aba8
S
40 digits = [int(digit) for digit in digits.split(',')]
41 key_digit = self._search_regex(
42 r'fromCharCode\(.+?(\d+)\)}', unpacked, 'key digit')
0987f2dd
T
43 chars = [compat_chr(d - int(key_digit)) for d in digits]
44 return ''.join(chars)
45
2ab0bfcd
S
46 def _real_extract(self, url):
47 video_id = self._match_id(url)
48
49 webpage = self._download_webpage(
a2b6aba8 50 'https://vshare.io/v/%s/width-650/height-430/1' % video_id,
794c1b6e 51 video_id, headers={'Referer': url})
2ab0bfcd 52
a2b6aba8
S
53 title = self._html_search_regex(
54 r'<title>([^<]+)</title>', webpage, 'title')
0987f2dd 55 title = title.split(' - ')[0]
2ab0bfcd 56
ff31f2d5
S
57 error = self._html_search_regex(
58 r'(?s)<div[^>]+\bclass=["\']xxx-error[^>]+>(.+?)</div', webpage,
59 'error', default=None)
60 if error:
61 raise ExtractorError(error, expected=True)
62
a2b6aba8
S
63 info = self._parse_html5_media_entries(
64 url, '<video>%s</video>' % self._extract_packed(webpage),
65 video_id)[0]
66
67 self._sort_formats(info['formats'])
68
69 info.update({
2ab0bfcd
S
70 'id': video_id,
71 'title': title,
a2b6aba8 72 })
0987f2dd 73
a2b6aba8 74 return info