-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
35 lines (29 loc) · 1017 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import json
import re
import uuid
class NoIndent(object):
def __init__(self, value):
self.value = value
# json custom indent
class NoIndentEncoder(json.JSONEncoder):
def __init__(self, *args, **kwargs):
super(NoIndentEncoder, self).__init__(*args, **kwargs)
self.kwargs = dict(kwargs)
del self.kwargs['indent']
self._replacement_map = {}
def default(self, o):
if isinstance(o, NoIndent):
key = uuid.uuid4().hex
self._replacement_map[key] = json.dumps(o.value, **self.kwargs)
return "@@%s@@" % (key,)
else:
return super(NoIndentEncoder, self).default(o)
def encode(self, o):
result = super(NoIndentEncoder, self).encode(o)
for k, v in iter(self._replacement_map.items()):
result = result.replace('"@@%s@@"' % (k,), v)
return result
def download_resolution(h):
for i in [144, 360, 480, 720, 1080, 1440, 2160]:
if h <= i: return i
return 2160