aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2018-03-02 23:39:04 +0700
committerSergey M․ <dstftw@gmail.com>2018-03-02 23:39:04 +0700
commitb871d7e954350ec8525540b9dd319541560bfef0 (patch)
tree3e1a4697adb584a137148296ec122bae265ffe07 /youtube_dl/utils.py
parent44dc11db6191f529fddc6037ba4d0fb05c946382 (diff)
downloadyoutube-dl-b871d7e954350ec8525540b9dd319541560bfef0.tar.xz
[utils] Add parse_resolution
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index af639a124..a21455f70 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -1689,6 +1689,28 @@ def parse_count(s):
return lookup_unit_table(_UNIT_TABLE, s)
+def parse_resolution(s):
+ if s is None:
+ return {}
+
+ mobj = re.search(r'\b(?P<w>\d+)\s*[xX×]\s*(?P<h>\d+)\b', s)
+ if mobj:
+ return {
+ 'width': int(mobj.group('w')),
+ 'height': int(mobj.group('h')),
+ }
+
+ mobj = re.search(r'\b(\d+)[pPiI]\b', s)
+ if mobj:
+ return {'height': int(mobj.group(1))}
+
+ mobj = re.search(r'\b([48])[kK]\b', s)
+ if mobj:
+ return {'height': int(mobj.group(1)) * 540}
+
+ return {}
+
+
def month_by_name(name, lang='en'):
""" Return the number of a month by (locale-independently) English name """