summary refs log tree commit diff
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2014-10-03 19:37:25 +0700
committerSergey M․ <dstftw@gmail.com>2014-10-03 19:37:25 +0700
commit146c80e2562dab0f229f13a1fbc0e8ae116d4cb3 (patch)
treed9ce510f6f2362668a589c9dd09187202e2f85e8
parentf78c01f68b1e16e385ec319c7f5d351b173c7ec5 (diff)
downloadyoutube-dl-146c80e2562dab0f229f13a1fbc0e8ae116d4cb3.tar.gz
youtube-dl-146c80e2562dab0f229f13a1fbc0e8ae116d4cb3.tar.xz
youtube-dl-146c80e2562dab0f229f13a1fbc0e8ae116d4cb3.zip
[utils] Add parse_age_limit
-rw-r--r--youtube_dl/utils.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index f8dd9c72d..2615553c1 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -1574,6 +1574,13 @@ US_RATINGS = {
 }
 
 
+def parse_age_limit(s):
+    if s is None:
+        return 0
+    m = re.match(r'^(?P<age>\d{1,2})\+?$', s)
+    return int(m.group('age')) if m else US_RATINGS.get(s, 0)
+
+
 def strip_jsonp(code):
     return re.sub(r'(?s)^[a-zA-Z0-9_]+\s*\(\s*(.*)\);?\s*?\s*$', r'\1', code)