[utils] Add urshift()
authorYen Chi Hsuan <yan12125@gmail.com>
Sun, 26 Jun 2016 07:16:49 +0000 (15:16 +0800)
committerYen Chi Hsuan <yan12125@gmail.com>
Sun, 26 Jun 2016 07:16:49 +0000 (15:16 +0800)
Used in IqiyiIE and LeIE

test/test_utils.py
youtube_dl/utils.py

index 7f9385deb68705613ddf44735db6ae3257ec6155..ed61e4c2751c82c062db6339b4245cb4cae6c9bf 100644 (file)
@@ -66,6 +66,7 @@ from youtube_dl.utils import (
     lowercase_escape,
     url_basename,
     urlencode_postdata,
+    urshift,
     update_url_query,
     version_tuple,
     xpath_with_ns,
@@ -980,5 +981,9 @@ The first line
         self.assertRaises(ValueError, encode_base_n, 0, 70)
         self.assertRaises(ValueError, encode_base_n, 0, 60, custom_table)
 
+    def test_urshift(self):
+        self.assertEqual(urshift(3, 1), 1)
+        self.assertEqual(urshift(-3, 1), 2147483646)
+
 if __name__ == '__main__':
     unittest.main()
index a375282f231d507bda3099b85133092396441afe..a2cfb48a6da9236be636fa474de834af2cf525d2 100644 (file)
@@ -2899,3 +2899,7 @@ def parse_m3u8_attributes(attrib):
             val = val[1:-1]
         info[key] = val
     return info
+
+
+def urshift(val, n):
+    return val >> n if val >= 0 else (val + 0x100000000) >> n