]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/snotr.py
[tiktok] Fix `extractor_key` used in archive
[yt-dlp.git] / yt_dlp / extractor / snotr.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4
5 from .common import InfoExtractor
6 from ..utils import (
7 parse_duration,
8 parse_filesize,
9 str_to_int,
10 )
11
12
13 class SnotrIE(InfoExtractor):
14 _VALID_URL = r'http?://(?:www\.)?snotr\.com/video/(?P<id>\d+)/([\w]+)'
15 _TESTS = [{
16 'url': 'http://www.snotr.com/video/13708/Drone_flying_through_fireworks',
17 'info_dict': {
18 'id': '13708',
19 'ext': 'mp4',
20 'title': 'Drone flying through fireworks!',
21 'duration': 248,
22 'filesize_approx': 40700000,
23 'description': 'A drone flying through Fourth of July Fireworks',
24 'thumbnail': r're:^https?://.*\.jpg$',
25 },
26 'expected_warnings': ['description'],
27 }, {
28 'url': 'http://www.snotr.com/video/530/David_Letteman_-_George_W_Bush_Top_10',
29 'info_dict': {
30 'id': '530',
31 'ext': 'mp4',
32 'title': 'David Letteman - George W. Bush Top 10',
33 'duration': 126,
34 'filesize_approx': 8500000,
35 'description': 'The top 10 George W. Bush moments, brought to you by David Letterman!',
36 'thumbnail': r're:^https?://.*\.jpg$',
37 }
38 }]
39
40 def _real_extract(self, url):
41 mobj = self._match_valid_url(url)
42 video_id = mobj.group('id')
43
44 webpage = self._download_webpage(url, video_id)
45 title = self._og_search_title(webpage)
46
47 description = self._og_search_description(webpage)
48 info_dict = self._parse_html5_media_entries(
49 url, webpage, video_id, m3u8_entry_protocol='m3u8_native')[0]
50
51 view_count = str_to_int(self._html_search_regex(
52 r'<p[^>]*>\s*<strong[^>]*>Views:</strong>\s*<span[^>]*>([\d,\.]+)',
53 webpage, 'view count', fatal=False))
54
55 duration = parse_duration(self._html_search_regex(
56 r'<p[^>]*>\s*<strong[^>]*>Length:</strong>\s*<span[^>]*>([\d:]+)',
57 webpage, 'duration', fatal=False))
58
59 filesize_approx = parse_filesize(self._html_search_regex(
60 r'<p[^>]*>\s*<strong[^>]*>Filesize:</strong>\s*<span[^>]*>([^<]+)',
61 webpage, 'filesize', fatal=False))
62
63 info_dict.update({
64 'id': video_id,
65 'description': description,
66 'title': title,
67 'view_count': view_count,
68 'duration': duration,
69 'filesize_approx': filesize_approx,
70 })
71
72 return info_dict