deemix-py/deemix/types/Picture.py

27 lines
728 B
Python
Raw Normal View History

2021-01-31 16:59:15 +00:00
class Picture:
2021-03-13 10:54:01 +00:00
def __init__(self, md5="", type="", url=None):
2021-01-31 16:59:15 +00:00
self.md5 = md5
self.type = type
2021-03-13 10:54:01 +00:00
self.staticUrl = url
2021-01-31 16:59:15 +00:00
def generatePictureURL(self, size, format):
2021-03-13 10:54:01 +00:00
if self.staticUrl: return self.staticUrl
url = "https://e-cdns-images.dzcdn.net/images/{}/{}/{}x{}".format(
self.type,
self.md5,
size, size
)
2021-01-31 16:59:15 +00:00
if format.startswith("jpg"):
if '-' in format:
quality = format[4:]
else:
quality = 80
format = 'jpg'
2021-03-13 10:54:01 +00:00
return url + f'-000000-{quality}-0-0.jpg'
2021-01-31 16:59:15 +00:00
if format == 'png':
2021-03-13 10:54:01 +00:00
return url + '-none-100-0-0.png'
return url+'.jpg'