warp-beacon 2.2.54__py3-none-any.whl → 2.2.56__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.54"
1
+ __version__ = "2.2.56"
2
2
 
@@ -1,7 +1,6 @@
1
- import io, os
1
+ import io
2
2
 
3
3
  from typing import Union
4
- from PIL import Image
5
4
 
6
5
  from warp_beacon.mediainfo.abstract import MediaInfoAbstract
7
6
 
@@ -141,10 +141,19 @@ class YoutubeAbstract(ScraperAbstract):
141
141
 
142
142
  def crop_black_edges_pil(self, img: Image, threshold: int = 35) -> Image:
143
143
  y_nonzero, x_nonzero, _ = np.nonzero(np.array(img) > threshold)
144
- return img.crop((np.min(x_nonzero), np.min(y_nonzero)+15, np.max(x_nonzero), np.max(y_nonzero)-5))
144
+ return img.crop((np.min(x_nonzero), np.min(y_nonzero), np.max(x_nonzero), np.max(y_nonzero)))
145
145
 
146
- def download_thumbnail(self, video_id: str, timeout: int) -> Optional[io.BytesIO]:
147
- for i in (#"https://img.youtube.com/vi/{VIDEO_ID}/maxresdefault.jpg",
146
+ def crop_center(self, image: Image, width: int, height: int) -> Image:
147
+ img_width, img_height = image.size
148
+ left = (img_width - width) // 2
149
+ top = (img_height - height) // 2
150
+ right = left + width
151
+ bottom = top + height
152
+
153
+ return image.crop((left, top, right, bottom))
154
+
155
+ def download_thumbnail(self, video_id: str, timeout: int, crop_center: dict = None) -> Optional[io.BytesIO]:
156
+ for i in ("https://img.youtube.com/vi/{VIDEO_ID}/maxresdefault.jpg",
148
157
  "https://img.youtube.com/vi/{VIDEO_ID}/hqdefault.jpg",
149
158
  "https://img.youtube.com/vi/{VIDEO_ID}/sddefault.jpg"):
150
159
  try:
@@ -155,6 +164,8 @@ class YoutubeAbstract(ScraperAbstract):
155
164
  image = Image.open(io.BytesIO(response.content))
156
165
  ratio = self.aspect_ratio(image.size)
157
166
  image = self.crop_black_edges_pil(image)
167
+ if crop_center:
168
+ image = self.crop_center(image, width=crop_center["width"], height=crop_center["height"])
158
169
  logging.info("thumb ratio: '%s'", ratio)
159
170
  new_image = self.resize_aspect_ratio(image)
160
171
  logging.info("thumb size: '%s'", new_image.size)
@@ -169,7 +180,7 @@ class YoutubeAbstract(ScraperAbstract):
169
180
 
170
181
  return None
171
182
 
172
- def _download_hndlr(self, func: Callable, *args: tuple[str], **kwargs: dict[str]) -> Union[str, dict, io.BytesIO]:
183
+ def _download_hndlr(self, func: Callable, *args: tuple[Union[str, int, dict, tuple]], **kwargs: dict[Union[str, int, dict, tuple]]) -> Union[str, dict, io.BytesIO]:
173
184
  ret_val = ''
174
185
  max_retries = int(os.environ.get("YT_MAX_RETRIES", default=self.YT_MAX_RETRIES_DEFAULT))
175
186
  pause_secs = int(os.environ.get("YT_PAUSE_BEFORE_RETRY", default=self.YT_PAUSE_BEFORE_RETRY_DEFAULT))
@@ -2,6 +2,8 @@ from warp_beacon.jobs.types import JobType
2
2
  from warp_beacon.scraper.youtube.abstract import YoutubeAbstract
3
3
  from warp_beacon.scraper.exceptions import NotFound
4
4
 
5
+ from warp_beacon.mediainfo.video import VideoInfo
6
+
5
7
  import logging
6
8
 
7
9
  class YoutubeShortsScraper(YoutubeAbstract):
@@ -19,9 +21,6 @@ class YoutubeShortsScraper(YoutubeAbstract):
19
21
  if not stream:
20
22
  raise NotFound("No suitable video stream found")
21
23
 
22
- if yt:
23
- thumbnail = self._download_hndlr(self.download_thumbnail, yt.video_id)
24
-
25
24
  local_file = stream.download(
26
25
  output_path=self.DOWNLOAD_DIR,
27
26
  max_retries=0,
@@ -29,9 +28,14 @@ class YoutubeShortsScraper(YoutubeAbstract):
29
28
  skip_existing=False,
30
29
  filename_prefix="yt_download_"
31
30
  )
31
+
32
+ local_file = self.rename_local_file(local_file)
33
+ vinfo = VideoInfo(local_file)
34
+ thumbnail = self._download_hndlr(self.download_thumbnail, video_id=yt.video_id, crop_center=vinfo.get_demensions())
35
+
32
36
  logging.debug("Temp filename: '%s'", local_file)
33
37
  res.append({
34
- "local_media_path": self.rename_local_file(local_file),
38
+ "local_media_path": local_file,
35
39
  "performer": yt.author,
36
40
  "thumb": thumbnail,
37
41
  "canonical_name": stream.title,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: warp_beacon
3
- Version: 2.2.54
3
+ Version: 2.2.56
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=2QQMS9N_Z-TnfZq4U1vSUe4IKyZGmTFdgo8BoF4hQ7E,1710
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=hC7dBZmWozPVWJEfB0wjEJJ7RQG4YMJ25mAyPY5gz8A,24
6
+ warp_beacon/__version__.py,sha256=IyD1C6RVjSbNqVBJ2tJyFqneScje0JT550cRO2y6sBc,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
@@ -16,7 +16,7 @@ warp_beacon/mediainfo/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3h
16
16
  warp_beacon/mediainfo/abstract.py,sha256=ZR2JMuRpoh7nDNov9a8YkAfr6BI2HXnXzQtVrLgDxjs,1185
17
17
  warp_beacon/mediainfo/audio.py,sha256=ous88kwQj4bDIChN5wnGil5LqTs0IQHH0d-nyrL0-ZM,651
18
18
  warp_beacon/mediainfo/silencer.py,sha256=MgUc9Ibbhjhg9GbJMNfJqrdDkMsQShZkQ1sCwvW_-qI,1647
19
- warp_beacon/mediainfo/video.py,sha256=DXHiWAOyJPSVXQ0OP7uOBikUFT7noFmMaMSIx04Mhs4,2506
19
+ warp_beacon/mediainfo/video.py,sha256=UBZrhTN5IDI-aYu6tsJEILo9nFkjHhkldGVFmvV7tEI,2480
20
20
  warp_beacon/scheduler/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  warp_beacon/scheduler/scheduler.py,sha256=F9jF6myIHOI0TmC0-rBt2Un8gVvuhBW9zL-nEAEj0Bc,2585
22
22
  warp_beacon/scraper/__init__.py,sha256=Nc-wdqu1KLLQkf3kkhl7jXzDWiv6vzKPudJdwL9sb24,15938
@@ -26,9 +26,9 @@ warp_beacon/scraper/exceptions.py,sha256=fHywTm2-y2RkgM6hVz12CkDMBgHcEoN2a1TBLaV
26
26
  warp_beacon/scraper/instagram/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  warp_beacon/scraper/instagram/instagram.py,sha256=m2bAqLu-_HchlF5CVZDlytB9cFGxrN7EEbQW-G1f5u4,12857
28
28
  warp_beacon/scraper/youtube/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
- warp_beacon/scraper/youtube/abstract.py,sha256=C2EI_NFulyKMyD1D8TlhtTr5tvGL3UVXi2zIK629AmU,8297
29
+ warp_beacon/scraper/youtube/abstract.py,sha256=8aeJv11i4FxD8MbjTTUGILElXjDYB6lw-h6WVApfxvY,8761
30
30
  warp_beacon/scraper/youtube/music.py,sha256=nbTDFdgXGbTNqttE828DEgvSc8-SuAsQAHeqUwU6yFM,1484
31
- warp_beacon/scraper/youtube/shorts.py,sha256=RqMYDq4XHChtp-LdlxXyHej4h3NI3Qi9T8USxwk-pIk,1177
31
+ warp_beacon/scraper/youtube/shorts.py,sha256=WMjStmQz24zJwpzGak4-UuaVLo4-0hPtH_rAHQWgKdU,1322
32
32
  warp_beacon/scraper/youtube/youtube.py,sha256=JvN5pVz0jtxCY9FGMl1dIg5Ccr2Kulaoxtym0Vb1QwQ,2224
33
33
  warp_beacon/storage/__init__.py,sha256=m86MDXBMtZZsTPLI2cD-pM5Xkh2g2NYVvp_dtW8eH0Q,3548
34
34
  warp_beacon/telegram/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -37,9 +37,9 @@ warp_beacon/telegram/handlers.py,sha256=SyYSDYbHnMpXDqockHTN-8Rg_YimLDfJAOhuubQf
37
37
  warp_beacon/telegram/placeholder_message.py,sha256=N1fSL1xbFLF5alhnEvk-xbf3v2A_nLWg6xHtVZTaoiA,6396
38
38
  warp_beacon/telegram/utils.py,sha256=wSyJJsv1chaK4hqnBP-dDiY1hYD7wFhzBzw5H_AwE88,2450
39
39
  warp_beacon/uploader/__init__.py,sha256=rbfsm_eYcfsBRkiaG0glVgBNtQCEe7cVQTWEIAHz5aw,4763
40
- warp_beacon-2.2.54.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
41
- warp_beacon-2.2.54.dist-info/METADATA,sha256=5Iw255c_fpaLDhlrq66epuKljmaC2RzEqwd0AF-32qc,21272
42
- warp_beacon-2.2.54.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
43
- warp_beacon-2.2.54.dist-info/entry_points.txt,sha256=eSB61Rb89d56WY0O-vEIQwkn18J-4CMrJcLA_R_8h3g,119
44
- warp_beacon-2.2.54.dist-info/top_level.txt,sha256=ALb_Ft_eG-OY4_m0TWUifNUOZsrx483L-zw7G7vqXoc,971
45
- warp_beacon-2.2.54.dist-info/RECORD,,
40
+ warp_beacon-2.2.56.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
41
+ warp_beacon-2.2.56.dist-info/METADATA,sha256=1YwCmlcs_8nvo_S5QZM1MitqmafX1vVwN42OZCmPmoE,21272
42
+ warp_beacon-2.2.56.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
43
+ warp_beacon-2.2.56.dist-info/entry_points.txt,sha256=eSB61Rb89d56WY0O-vEIQwkn18J-4CMrJcLA_R_8h3g,119
44
+ warp_beacon-2.2.56.dist-info/top_level.txt,sha256=ALb_Ft_eG-OY4_m0TWUifNUOZsrx483L-zw7G7vqXoc,971
45
+ warp_beacon-2.2.56.dist-info/RECORD,,