[utils] Extract known extensions for reuse
This commit is contained in:
parent
ea6abd740f
commit
a7aaa39863
|
@ -70,6 +70,21 @@ ENGLISH_MONTH_NAMES = [
|
||||||
'January', 'February', 'March', 'April', 'May', 'June',
|
'January', 'February', 'March', 'April', 'May', 'June',
|
||||||
'July', 'August', 'September', 'October', 'November', 'December']
|
'July', 'August', 'September', 'October', 'November', 'December']
|
||||||
|
|
||||||
|
KNOWN_EXTENSIONS = (
|
||||||
|
'mp4', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v', 'aac',
|
||||||
|
'flv', 'f4v', 'f4a', 'f4b',
|
||||||
|
'webm', 'ogg', 'ogv', 'oga', 'ogx', 'spx', 'opus',
|
||||||
|
'mkv', 'mka', 'mk3d',
|
||||||
|
'avi', 'divx',
|
||||||
|
'mov',
|
||||||
|
'asf', 'wmv', 'wma',
|
||||||
|
'3gp', '3g2',
|
||||||
|
'mp3',
|
||||||
|
'flac',
|
||||||
|
'ape',
|
||||||
|
'wav',
|
||||||
|
'f4f', 'f4m', 'm3u8', 'smil')
|
||||||
|
|
||||||
|
|
||||||
def preferredencoding():
|
def preferredencoding():
|
||||||
"""Get preferred encoding.
|
"""Get preferred encoding.
|
||||||
|
@ -942,20 +957,8 @@ def determine_ext(url, default_ext='unknown_video'):
|
||||||
guess = url.partition('?')[0].rpartition('.')[2]
|
guess = url.partition('?')[0].rpartition('.')[2]
|
||||||
if re.match(r'^[A-Za-z0-9]+$', guess):
|
if re.match(r'^[A-Za-z0-9]+$', guess):
|
||||||
return guess
|
return guess
|
||||||
elif guess.rstrip('/') in (
|
# Try extract ext from URLs like http://example.com/foo/bar.mp4/?download
|
||||||
'mp4', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v', 'aac',
|
elif guess.rstrip('/') in KNOWN_EXTENSIONS:
|
||||||
'flv', 'f4v', 'f4a', 'f4b',
|
|
||||||
'webm', 'ogg', 'ogv', 'oga', 'ogx', 'spx', 'opus',
|
|
||||||
'mkv', 'mka', 'mk3d',
|
|
||||||
'avi', 'divx',
|
|
||||||
'mov',
|
|
||||||
'asf', 'wmv', 'wma',
|
|
||||||
'3gp', '3g2',
|
|
||||||
'mp3',
|
|
||||||
'flac',
|
|
||||||
'ape',
|
|
||||||
'wav',
|
|
||||||
'f4f', 'f4m', 'm3u8', 'smil'):
|
|
||||||
return guess.rstrip('/')
|
return guess.rstrip('/')
|
||||||
else:
|
else:
|
||||||
return default_ext
|
return default_ext
|
||||||
|
|
Loading…
Reference in New Issue