warp-beacon 2.2.13__py3-none-any.whl → 2.2.15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- __version__ = "2.2.13"
1
+ __version__ = "2.2.15"
2
2
 
@@ -1,6 +1,7 @@
1
1
  import os, io
2
2
  import pathlib
3
3
  import time
4
+ import math
4
5
  import socket
5
6
  import ssl
6
7
  #from abc import abstractmethod
@@ -9,7 +10,7 @@ import json
9
10
  import urllib
10
11
  import requests
11
12
  import http.client
12
- from PIL import Image
13
+ from PIL import Image, ImageOps
13
14
 
14
15
  from warp_beacon.scraper.abstract import ScraperAbstract
15
16
  from warp_beacon.mediainfo.abstract import MediaInfoAbstract
@@ -102,6 +103,34 @@ class YoutubeAbstract(ScraperAbstract):
102
103
  if "yt_download_" in i:
103
104
  os.unlink("%s/%s" % (self.DOWNLOAD_DIR, i))
104
105
 
106
+ def calculate_size(self, aspect_ratio_width: int, aspect_ratio_height: int, max_width: int=1280, max_height: int=1280, min_width: int=320, min_height: int=320) -> tuple:
107
+ # check ratio
108
+ aspect_ratio = aspect_ratio_width / aspect_ratio_height
109
+
110
+ # probe the max width and calculate height
111
+ width = max_width
112
+ height = int(width / aspect_ratio)
113
+
114
+ # if height exceeds max height of Telegram recalculate based on max height
115
+ if height > max_height:
116
+ height = max_height
117
+ width = int(height * aspect_ratio)
118
+
119
+ # check min sizes
120
+ if width < min_width:
121
+ width = min_width
122
+ height = int(width / aspect_ratio)
123
+
124
+ if height < min_height:
125
+ height = min_height
126
+ width = int(height * aspect_ratio)
127
+
128
+ return width, height
129
+
130
+ def aspect_ratio(self, size: tuple) -> tuple:
131
+ gcd = math.gcd(size[0], size[1])
132
+ return size[0] // gcd, size[1] // gcd
133
+
105
134
  def download_thumbnail(self, video_id: str, timeout: int) -> Optional[io.BytesIO]:
106
135
  for i in ("https://img.youtube.com/vi/{VIDEO_ID}/maxresdefault.jpg",
107
136
  "https://img.youtube.com/vi/{VIDEO_ID}/hqdefault.jpg",
@@ -112,9 +141,17 @@ class YoutubeAbstract(ScraperAbstract):
112
141
  with requests.get(url, timeout=(timeout, timeout)) as response:
113
142
  if response.status_code == 200:
114
143
  image = Image.open(io.BytesIO(response.content))
115
- image = MediaInfoAbstract.shrink_image_to_fit(image, size=(320, 180))
144
+ ratio = self.aspect_ratio(image.size)
145
+ desired_size = self.calculate_size(ratio[0], ratio[1])
146
+ new_image = Image.new("RGB", desired_size, (255, 255, 255))
147
+ image = MediaInfoAbstract.shrink_image_to_fit(image, size=desired_size)
148
+ image_position = (
149
+ (desired_size[0] - image.size[0]) // 2,
150
+ (desired_size[1] - image.size[1]) // 2
151
+ )
152
+ new_image.paste(image, image_position)
116
153
  io_buf = io.BytesIO()
117
- image.save(io_buf, format='JPEG', subsampling=0, quality=100, progressive=True, optimize=False, icc_profile=image.info.get('icc_profile'))
154
+ new_image.save(io_buf, format='JPEG', subsampling=0, quality=100, progressive=True, optimize=False)
118
155
  io_buf.seek(0)
119
156
  return io_buf
120
157
  except Exception as e:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: warp_beacon
3
- Version: 2.2.13
3
+ Version: 2.2.15
4
4
  Summary: Telegram bot for expanding external media links
5
5
  Home-page: https://github.com/sb0y/warp_beacon
6
6
  Author: Andrey Bagrintsev
@@ -3,7 +3,7 @@ lib/systemd/system/warp_beacon.service,sha256=lPmHqLqcI2eIV7nwHS0qcALQrznixqJuww
3
3
  var/warp_beacon/accounts.json,sha256=rKFQM_b9eoDS4mJ1B_SZNolPLXx1SQdQMdY2F_ZcBt8,1523
4
4
  var/warp_beacon/placeholder.gif,sha256=cE5CGJVaop4Sx21zx6j4AyoHU0ncmvQuS2o6hJfEH88,6064
5
5
  warp_beacon/__init__.py,sha256=_rThNODmz0nDp_n4mWo_HKaNFE5jk1_7cRhHyYaencI,163
6
- warp_beacon/__version__.py,sha256=EZY_dqBzsnya3iCnVLRbelstvtMaEBju3Df3nOEp0yg,24
6
+ warp_beacon/__version__.py,sha256=FDkX74nYOV53ZX4kQ7ePuEHrPbZ5BHYRGPUeFPXhtVY,24
7
7
  warp_beacon/warp_beacon.py,sha256=7KEtZDj-pdhtl6m-zFLsSojs1ZR4o7L0xbqtdmYPvfE,342
8
8
  warp_beacon/compress/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  warp_beacon/compress/video.py,sha256=_PDMVYCyzLYxHv1uZmmzGcG_8rjaZr7BTXsXTTy_oS4,2846
@@ -26,7 +26,7 @@ warp_beacon/scraper/exceptions.py,sha256=lHsPrYy5iYnHsIdUHqRxZmzlqrkNj_TS4TkiTJf
26
26
  warp_beacon/scraper/instagram/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  warp_beacon/scraper/instagram/instagram.py,sha256=iT66IM7nsbVDWQzBW-CJUWDBjoBbRZH4BHx6TJw3oqo,13517
28
28
  warp_beacon/scraper/youtube/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
- warp_beacon/scraper/youtube/abstract.py,sha256=U1uQpH8dAktYXHZHAWcHNC9LKLuYI1uHpQivB6r1v5w,6468
29
+ warp_beacon/scraper/youtube/abstract.py,sha256=OCi7aB2VN_blEvKho35Eg_3p6szmrkJI7POAWqEHg7U,7656
30
30
  warp_beacon/scraper/youtube/music.py,sha256=nbTDFdgXGbTNqttE828DEgvSc8-SuAsQAHeqUwU6yFM,1484
31
31
  warp_beacon/scraper/youtube/shorts.py,sha256=RqMYDq4XHChtp-LdlxXyHej4h3NI3Qi9T8USxwk-pIk,1177
32
32
  warp_beacon/scraper/youtube/youtube.py,sha256=JvN5pVz0jtxCY9FGMl1dIg5Ccr2Kulaoxtym0Vb1QwQ,2224
@@ -37,9 +37,9 @@ warp_beacon/telegram/handlers.py,sha256=xSNG_v4D4FaA5q1_5wXvJkjcDUhy5GaQnfpijJZp
37
37
  warp_beacon/telegram/placeholder_message.py,sha256=32U-R_IMPRJd-S5UwlpemLkArJOxCmO7whcynduSbMA,6418
38
38
  warp_beacon/telegram/utils.py,sha256=CeWXMwyzv2l4Af6I-wW2ySU490c-5k82sBhkjabv0n4,2452
39
39
  warp_beacon/uploader/__init__.py,sha256=rsUkzzmtaeQY-kNkcIiPsrayS9idFKY3hBC71mR19XE,4743
40
- warp_beacon-2.2.13.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
41
- warp_beacon-2.2.13.dist-info/METADATA,sha256=MDPBsAXM9L0BwDs-FCLqNLAqVYEpQU3-WSHe02150Ac,21251
42
- warp_beacon-2.2.13.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
43
- warp_beacon-2.2.13.dist-info/entry_points.txt,sha256=eSB61Rb89d56WY0O-vEIQwkn18J-4CMrJcLA_R_8h3g,119
44
- warp_beacon-2.2.13.dist-info/top_level.txt,sha256=ALb_Ft_eG-OY4_m0TWUifNUOZsrx483L-zw7G7vqXoc,971
45
- warp_beacon-2.2.13.dist-info/RECORD,,
40
+ warp_beacon-2.2.15.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
41
+ warp_beacon-2.2.15.dist-info/METADATA,sha256=I6taPqK-TX1_8OvtPEhHAYDa8UcuzqjgXry8odMEV70,21251
42
+ warp_beacon-2.2.15.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
43
+ warp_beacon-2.2.15.dist-info/entry_points.txt,sha256=eSB61Rb89d56WY0O-vEIQwkn18J-4CMrJcLA_R_8h3g,119
44
+ warp_beacon-2.2.15.dist-info/top_level.txt,sha256=ALb_Ft_eG-OY4_m0TWUifNUOZsrx483L-zw7G7vqXoc,971
45
+ warp_beacon-2.2.15.dist-info/RECORD,,