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