Compare commits
5 Commits
2013.12.09
...
2013.12.10
Author | SHA1 | Date | |
---|---|---|---|
|
a30a60d8eb | ||
|
5a3ea17c94 | ||
|
475700acfe | ||
|
45598aab08 | ||
|
26e6393134 |
@@ -7,6 +7,7 @@ import unittest
|
|||||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
from test.helper import FakeYDL
|
from test.helper import FakeYDL
|
||||||
|
from youtube_dl import YoutubeDL
|
||||||
|
|
||||||
|
|
||||||
class YDL(FakeYDL):
|
class YDL(FakeYDL):
|
||||||
@@ -140,6 +141,20 @@ class TestFormatSelection(unittest.TestCase):
|
|||||||
self.assertEqual(test_dict['extractor'], 'Foo')
|
self.assertEqual(test_dict['extractor'], 'Foo')
|
||||||
self.assertEqual(test_dict['playlist'], 'funny videos')
|
self.assertEqual(test_dict['playlist'], 'funny videos')
|
||||||
|
|
||||||
|
def test_prepare_filename(self):
|
||||||
|
info = {
|
||||||
|
u'id': u'1234',
|
||||||
|
u'ext': u'mp4',
|
||||||
|
u'width': None,
|
||||||
|
}
|
||||||
|
def fname(templ):
|
||||||
|
ydl = YoutubeDL({'outtmpl': templ})
|
||||||
|
return ydl.prepare_filename(info)
|
||||||
|
self.assertEqual(fname(u'%(id)s.%(ext)s'), u'1234.mp4')
|
||||||
|
self.assertEqual(fname(u'%(id)s-%(width)s.%(ext)s'), u'1234-NA.mp4')
|
||||||
|
# Replace missing fields with 'NA'
|
||||||
|
self.assertEqual(fname(u'%(uploader_date)s-%(id)s.%(ext)s'), u'NA-1234.mp4')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import collections
|
||||||
import errno
|
import errno
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
@@ -396,18 +397,17 @@ class YoutubeDL(object):
|
|||||||
template_dict['playlist_index'] = u'%05d' % template_dict['playlist_index']
|
template_dict['playlist_index'] = u'%05d' % template_dict['playlist_index']
|
||||||
|
|
||||||
sanitize = lambda k, v: sanitize_filename(
|
sanitize = lambda k, v: sanitize_filename(
|
||||||
u'NA' if v is None else compat_str(v),
|
compat_str(v),
|
||||||
restricted=self.params.get('restrictfilenames'),
|
restricted=self.params.get('restrictfilenames'),
|
||||||
is_id=(k == u'id'))
|
is_id=(k == u'id'))
|
||||||
template_dict = dict((k, sanitize(k, v))
|
template_dict = dict((k, sanitize(k, v))
|
||||||
for k, v in template_dict.items())
|
for k, v in template_dict.items()
|
||||||
|
if v is not None)
|
||||||
|
template_dict = collections.defaultdict(lambda: u'NA', template_dict)
|
||||||
|
|
||||||
tmpl = os.path.expanduser(self.params['outtmpl'])
|
tmpl = os.path.expanduser(self.params['outtmpl'])
|
||||||
filename = tmpl % template_dict
|
filename = tmpl % template_dict
|
||||||
return filename
|
return filename
|
||||||
except KeyError as err:
|
|
||||||
self.report_error(u'Erroneous output template')
|
|
||||||
return None
|
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
self.report_error(u'Error in output template: ' + str(err) + u' (encoding: ' + repr(preferredencoding()) + ')')
|
self.report_error(u'Error in output template: ' + str(err) + u' (encoding: ' + repr(preferredencoding()) + ')')
|
||||||
return None
|
return None
|
||||||
|
@@ -99,7 +99,7 @@ class SoundcloudIE(InfoExtractor):
|
|||||||
thumbnail = info['artwork_url']
|
thumbnail = info['artwork_url']
|
||||||
if thumbnail is not None:
|
if thumbnail is not None:
|
||||||
thumbnail = thumbnail.replace('-large', '-t500x500')
|
thumbnail = thumbnail.replace('-large', '-t500x500')
|
||||||
ext = info.get('original_format', u'mp3')
|
ext = u'mp3'
|
||||||
result = {
|
result = {
|
||||||
'id': track_id,
|
'id': track_id,
|
||||||
'uploader': info['user']['username'],
|
'uploader': info['user']['username'],
|
||||||
|
@@ -73,14 +73,14 @@ class ZDFIE(InfoExtractor):
|
|||||||
try:
|
try:
|
||||||
proto_pref = -PROTO_ORDER.index(format_m.group('proto'))
|
proto_pref = -PROTO_ORDER.index(format_m.group('proto'))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
proto_pref = 999
|
proto_pref = -999
|
||||||
|
|
||||||
quality = fnode.find('./quality').text
|
quality = fnode.find('./quality').text
|
||||||
QUALITY_ORDER = ['veryhigh', '300', 'high', 'med', 'low']
|
QUALITY_ORDER = ['veryhigh', '300', 'high', 'med', 'low']
|
||||||
try:
|
try:
|
||||||
quality_pref = -QUALITY_ORDER.index(quality)
|
quality_pref = -QUALITY_ORDER.index(quality)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
quality_pref = 999
|
quality_pref = -999
|
||||||
|
|
||||||
abr = int(fnode.find('./audioBitrate').text) // 1000
|
abr = int(fnode.find('./audioBitrate').text) // 1000
|
||||||
vbr = int(fnode.find('./videoBitrate').text) // 1000
|
vbr = int(fnode.find('./videoBitrate').text) // 1000
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
|
|
||||||
__version__ = '2013.12.09.4'
|
__version__ = '2013.12.10'
|
||||||
|
Reference in New Issue
Block a user