mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-21 20:46:36 -05:00
[snotr] PEP8 and minor fixes (#3296)
This commit is contained in:
parent
199ece7eb8
commit
9732d77ed2
4 changed files with 41 additions and 42 deletions
|
@ -1197,6 +1197,10 @@ def _format_note(self, fdict):
|
||||||
if res:
|
if res:
|
||||||
res += ', '
|
res += ', '
|
||||||
res += format_bytes(fdict['filesize'])
|
res += format_bytes(fdict['filesize'])
|
||||||
|
elif fdict.get('filesize_approx') is not None:
|
||||||
|
if res:
|
||||||
|
res += ', '
|
||||||
|
res += '~' + format_bytes(fdict['filesize_approx'])
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def list_formats(self, info_dict):
|
def list_formats(self, info_dict):
|
||||||
|
|
|
@ -69,6 +69,7 @@ class InfoExtractor(object):
|
||||||
* vcodec Name of the video codec in use
|
* vcodec Name of the video codec in use
|
||||||
* container Name of the container format
|
* container Name of the container format
|
||||||
* filesize The number of bytes, if known in advance
|
* filesize The number of bytes, if known in advance
|
||||||
|
* filesize_approx An estimate for the number of bytes
|
||||||
* player_url SWF Player URL (used for rtmpdump).
|
* player_url SWF Player URL (used for rtmpdump).
|
||||||
* protocol The protocol that will be used for the actual
|
* protocol The protocol that will be used for the actual
|
||||||
download, lower-case.
|
download, lower-case.
|
||||||
|
@ -555,6 +556,7 @@ def _formats_key(f):
|
||||||
f.get('abr') if f.get('abr') is not None else -1,
|
f.get('abr') if f.get('abr') is not None else -1,
|
||||||
audio_ext_preference,
|
audio_ext_preference,
|
||||||
f.get('filesize') if f.get('filesize') is not None else -1,
|
f.get('filesize') if f.get('filesize') is not None else -1,
|
||||||
|
f.get('filesize_approx') if f.get('filesize_approx') is not None else -1,
|
||||||
f.get('format_id'),
|
f.get('format_id'),
|
||||||
)
|
)
|
||||||
formats.sort(key=_formats_key)
|
formats.sort(key=_formats_key)
|
||||||
|
|
|
@ -4,49 +4,39 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
|
float_or_none,
|
||||||
str_to_int,
|
str_to_int,
|
||||||
parse_iso8601,
|
parse_duration,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class SnotrIE(InfoExtractor):
|
class SnotrIE(InfoExtractor):
|
||||||
_VALID_URL = r'http?://(?:www\.)?snotr\.com/video/(?P<id>\d+)/([\w]+)'
|
_VALID_URL = r'http?://(?:www\.)?snotr\.com/video/(?P<id>\d+)/([\w]+)'
|
||||||
_TESTS =[ {
|
_TESTS = [{
|
||||||
'url': 'http://www.snotr.com/video/13708/Drone_flying_through_fireworks',
|
'url': 'http://www.snotr.com/video/13708/Drone_flying_through_fireworks',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '13708',
|
'id': '13708',
|
||||||
'ext': 'flv',
|
'ext': 'flv',
|
||||||
'title': 'Drone flying through fireworks!',
|
'title': 'Drone flying through fireworks!',
|
||||||
'duration': 247,
|
'duration': 247,
|
||||||
'filesize':12320768
|
'filesize_approx': 98566144,
|
||||||
}
|
}
|
||||||
},
|
}, {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
'url': 'http://www.snotr.com/video/530/David_Letteman_-_George_W_Bush_Top_10',
|
'url': 'http://www.snotr.com/video/530/David_Letteman_-_George_W_Bush_Top_10',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '530',
|
'id': '530',
|
||||||
'ext': 'flv',
|
'ext': 'flv',
|
||||||
'title': 'David Letteman - George W. Bush Top 10',
|
'title': 'David Letteman - George W. Bush Top 10',
|
||||||
'duration': 126,
|
'duration': 126,
|
||||||
'filesize': 1048576
|
'filesize_approx': 8912896,
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
mobj = re.match(self._VALID_URL, url)
|
mobj = re.match(self._VALID_URL, url)
|
||||||
video_id = mobj.group('id')
|
video_id = mobj.group('id')
|
||||||
|
|
||||||
# TODO more code goes here, for example ...
|
|
||||||
webpage = self._download_webpage(url, video_id)
|
webpage = self._download_webpage(url, video_id)
|
||||||
title = self._og_search_title(webpage)
|
title = self._og_search_title(webpage)
|
||||||
|
|
||||||
|
@ -54,20 +44,23 @@ def _real_extract(self, url):
|
||||||
|
|
||||||
video_url = "http://cdn.videos.snotr.com/%s.flv" % video_id
|
video_url = "http://cdn.videos.snotr.com/%s.flv" % video_id
|
||||||
|
|
||||||
view_count = str_to_int(self._html_search_regex(r'<p>\n<strong>Views:</strong>\n([\d,\.]+)</p>',webpage,'view count'))
|
view_count = str_to_int(self._html_search_regex(
|
||||||
|
r'<p>\n<strong>Views:</strong>\n([\d,\.]+)</p>',
|
||||||
|
webpage, 'view count', fatal=False))
|
||||||
|
|
||||||
duration = self._html_search_regex(r'<p>\n<strong>Length:</strong>\n(.*?)</p>',webpage,'duration')
|
duration = parse_duration(self._html_search_regex(
|
||||||
duration = str_to_int(duration[:1])*60 + str_to_int(duration[2:4])
|
r'<p>\n<strong>Length:</strong>\n\s*([0-9:]+).*?</p>',
|
||||||
|
webpage, 'duration', fatal=False))
|
||||||
|
|
||||||
file_size = self._html_search_regex(r'<p>\n<strong>Filesize:</strong>\n(.*?)</p>',webpage,'filesize')
|
filesize_approx = float_or_none(self._html_search_regex(
|
||||||
file_size = str_to_int(re.match(r'\d+',file_size).group())*131072
|
r'<p>\n<strong>Filesize:</strong>\n\s*([0-9.]+)\s*megabyte</p>',
|
||||||
|
webpage, 'filesize', fatal=False), invscale=1024 * 1024)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'title': title,
|
'title': title,
|
||||||
'url':video_url,
|
'url': video_url,
|
||||||
'view_count':view_count,
|
'view_count': view_count,
|
||||||
'duration':duration,
|
'duration': duration,
|
||||||
'filesize':file_size
|
'filesize_approx': filesize_approx,
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1193,13 +1193,6 @@ def format_bytes(bytes):
|
||||||
return u'%.2f%s' % (converted, suffix)
|
return u'%.2f%s' % (converted, suffix)
|
||||||
|
|
||||||
|
|
||||||
def str_to_int(int_str):
|
|
||||||
if int_str is None:
|
|
||||||
return None
|
|
||||||
int_str = re.sub(r'[,\.]', u'', int_str)
|
|
||||||
return int(int_str)
|
|
||||||
|
|
||||||
|
|
||||||
def get_term_width():
|
def get_term_width():
|
||||||
columns = os.environ.get('COLUMNS', None)
|
columns = os.environ.get('COLUMNS', None)
|
||||||
if columns:
|
if columns:
|
||||||
|
@ -1267,15 +1260,22 @@ def get_method(self):
|
||||||
return "HEAD"
|
return "HEAD"
|
||||||
|
|
||||||
|
|
||||||
def int_or_none(v, scale=1, default=None, get_attr=None):
|
def int_or_none(v, scale=1, default=None, get_attr=None, invscale=1):
|
||||||
if get_attr:
|
if get_attr:
|
||||||
if v is not None:
|
if v is not None:
|
||||||
v = getattr(v, get_attr, None)
|
v = getattr(v, get_attr, None)
|
||||||
return default if v is None else (int(v) // scale)
|
return default if v is None else (int(v) * invscale // scale)
|
||||||
|
|
||||||
|
|
||||||
def float_or_none(v, scale=1, default=None):
|
def str_to_int(int_str):
|
||||||
return default if v is None else (float(v) / scale)
|
if int_str is None:
|
||||||
|
return None
|
||||||
|
int_str = re.sub(r'[,\.]', u'', int_str)
|
||||||
|
return int(int_str)
|
||||||
|
|
||||||
|
|
||||||
|
def float_or_none(v, scale=1, invscale=1, default=None):
|
||||||
|
return default if v is None else (float(v) * invscale / scale)
|
||||||
|
|
||||||
|
|
||||||
def parse_duration(s):
|
def parse_duration(s):
|
||||||
|
|
Loading…
Reference in a new issue