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