1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-12-15 17:21:24 +01:00
youtube-dl/youtube_dl/extractor/snotr.py

74 lines
2.4 KiB
Python
Raw Normal View History

2014-07-19 19:49:25 +02:00
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..utils import (
2014-07-21 12:02:44 +02:00
parse_duration,
2016-08-19 18:18:22 +02:00
parse_filesize,
str_to_int,
2014-07-19 19:49:25 +02:00
)
2014-07-21 12:02:44 +02:00
2014-07-19 19:49:25 +02:00
class SnotrIE(InfoExtractor):
_VALID_URL = r'http?://(?:www\.)?snotr\.com/video/(?P<id>\d+)/([\w]+)'
2014-07-21 12:02:44 +02:00
_TESTS = [{
2014-07-19 19:49:25 +02:00
'url': 'http://www.snotr.com/video/13708/Drone_flying_through_fireworks',
'info_dict': {
'id': '13708',
2016-08-19 18:18:22 +02:00
'ext': 'mp4',
2014-07-19 19:49:25 +02:00
'title': 'Drone flying through fireworks!',
2016-08-19 18:18:22 +02:00
'duration': 248,
'filesize_approx': 40700000,
2014-07-21 12:08:44 +02:00
'description': 'A drone flying through Fourth of July Fireworks',
'thumbnail': r're:^https?://.*\.jpg$',
2016-08-19 18:18:22 +02:00
},
'expected_warnings': ['description'],
2014-07-21 12:02:44 +02:00
}, {
2014-07-19 19:49:25 +02:00
'url': 'http://www.snotr.com/video/530/David_Letteman_-_George_W_Bush_Top_10',
'info_dict': {
'id': '530',
2016-08-19 18:18:22 +02:00
'ext': 'mp4',
2014-07-19 19:49:25 +02:00
'title': 'David Letteman - George W. Bush Top 10',
'duration': 126,
2016-08-19 18:18:22 +02:00
'filesize_approx': 8500000,
2014-07-21 12:08:44 +02:00
'description': 'The top 10 George W. Bush moments, brought to you by David Letterman!',
'thumbnail': r're:^https?://.*\.jpg$',
2014-07-21 12:02:44 +02:00
}
}]
2014-07-19 19:49:25 +02:00
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
webpage = self._download_webpage(url, video_id)
title = self._og_search_title(webpage)
description = self._og_search_description(webpage)
info_dict = self._parse_html5_media_entries(
url, webpage, video_id, m3u8_entry_protocol='m3u8_native')[0]
2014-07-19 19:49:25 +02:00
2014-07-21 12:02:44 +02:00
view_count = str_to_int(self._html_search_regex(
2016-08-19 18:18:22 +02:00
r'<p[^>]*>\s*<strong[^>]*>Views:</strong>\s*<span[^>]*>([\d,\.]+)',
2014-07-21 12:02:44 +02:00
webpage, 'view count', fatal=False))
2014-07-19 19:49:25 +02:00
2014-07-21 12:02:44 +02:00
duration = parse_duration(self._html_search_regex(
2016-08-19 18:18:22 +02:00
r'<p[^>]*>\s*<strong[^>]*>Length:</strong>\s*<span[^>]*>([\d:]+)',
2014-07-21 12:02:44 +02:00
webpage, 'duration', fatal=False))
2014-07-19 19:49:25 +02:00
2016-08-19 18:18:22 +02:00
filesize_approx = parse_filesize(self._html_search_regex(
r'<p[^>]*>\s*<strong[^>]*>Filesize:</strong>\s*<span[^>]*>([^<]+)',
webpage, 'filesize', fatal=False))
2014-07-19 19:49:25 +02:00
2016-08-19 18:18:22 +02:00
info_dict.update({
2014-07-19 19:49:25 +02:00
'id': video_id,
2014-07-21 12:08:44 +02:00
'description': description,
2014-07-19 19:49:25 +02:00
'title': title,
2014-07-21 12:02:44 +02:00
'view_count': view_count,
'duration': duration,
'filesize_approx': filesize_approx,
2016-08-19 18:18:22 +02:00
})
return info_dict