projects
/
youtube-dl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'vgtv' of https://github.com/mrkolby/youtube-dl into mrkolby-vgtv
[youtube-dl]
/
youtube_dl
/
utils.py
diff --git
a/youtube_dl/utils.py
b/youtube_dl/utils.py
index 4f02108720d5699a017a78fb25bb30ae3c23c831..0bc410e91b01d08bd01f3b8fe2315b4b2e2b97e0 100644
(file)
--- a/
youtube_dl/utils.py
+++ b/
youtube_dl/utils.py
@@
-1076,12
+1076,6
@@
def intlist_to_bytes(xs):
return bytes(xs)
return bytes(xs)
-def get_cachedir(params={}):
- cache_root = os.environ.get('XDG_CACHE_HOME',
- os.path.expanduser('~/.cache'))
- return params.get('cachedir', os.path.join(cache_root, 'youtube-dl'))
-
-
# Cross-platform file locking
if sys.platform == 'win32':
import ctypes.wintypes
# Cross-platform file locking
if sys.platform == 'win32':
import ctypes.wintypes
@@
-1141,10
+1135,10
@@
else:
import fcntl
def _lock_file(f, exclusive):
import fcntl
def _lock_file(f, exclusive):
- fcntl.
lockf
(f, fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH)
+ fcntl.
flock
(f, fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH)
def _unlock_file(f):
def _unlock_file(f):
- fcntl.
lockf
(f, fcntl.LOCK_UN)
+ fcntl.
flock
(f, fcntl.LOCK_UN)
class locked_file(object):
class locked_file(object):
@@
-1318,9
+1312,10
@@
def str_or_none(v, default=None):
def str_to_int(int_str):
def str_to_int(int_str):
+ """ A more relaxed version of int_or_none """
if int_str is None:
return None
if int_str is None:
return None
- int_str = re.sub(r'[,\.]', u'', int_str)
+ int_str = re.sub(r'[,\.
\+
]', u'', int_str)
return int(int_str)
return int(int_str)
@@
-1332,8
+1327,10
@@
def parse_duration(s):
if s is None:
return None
if s is None:
return None
+ s = s.strip()
+
m = re.match(
m = re.match(
- r'(?
:(?:(?P<hours>[0-9]+)[:h])?(?P<mins>[0-9]+)[:m])?(?P<secs>[0-9]+)s?(?::[0-9]+)?(?P<ms>\.[0-9]+
)?$', s)
+ r'(?
i)(?:(?:(?P<hours>[0-9]+)\s*(?:[:h]|hours?)\s*)?(?P<mins>[0-9]+)\s*(?:[:m]|mins?|minutes?)\s*)?(?P<secs>[0-9]+)(?P<ms>\.[0-9]+)?\s*(?:s|secs?|seconds?
)?$', s)
if not m:
return None
res = int(m.group('secs'))
if not m:
return None
res = int(m.group('secs'))