warp-beacon 1.0.2__py3-none-any.whl → 1.0.4__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__ = "1.0.2"
1
+ __version__ = "1.0.4"
2
2
 
@@ -49,6 +49,14 @@ class AbstractJob(ABC):
49
49
  def __repr__(self) -> str:
50
50
  return str(self.to_dict())
51
51
 
52
+ def is_empty(self) -> bool:
53
+ if self.media_type == "collection":
54
+ if not self.media_collection:
55
+ return True
56
+ elif not self.local_media_path:
57
+ return True
58
+ return False
59
+
52
60
  def to_dict(self) -> dict:
53
61
  d = {}
54
62
  for key in dir(self.__class__):
@@ -20,4 +20,4 @@ class DownloadJob(AbstractJob):
20
20
  if "media_collection" in d:
21
21
  for k, v in enumerate(d["media_collection"]):
22
22
  d["media_collection"][k] = UploadJob.build(**v)
23
- return UploadJob.build(**d)
23
+ return UploadJob.build(**d)
@@ -23,4 +23,4 @@ class UploadJob(AbstractJob):
23
23
  if key in self.__dict__:
24
24
  self.__dict__[key] = value
25
25
 
26
- return self
26
+ return self
@@ -3,7 +3,7 @@ import multiprocessing
3
3
  import time
4
4
  import logging
5
5
  from requests.exceptions import ConnectTimeout, HTTPError
6
- from instagrapi.exceptions import MediaNotFound, UnknownError
6
+ from instagrapi.exceptions import MediaNotFound, UnknownError, ClientNotFoundError, UserNotFound
7
7
 
8
8
  from warp_beacon.mediainfo.video import VideoInfo
9
9
  from warp_beacon.uploader import AsyncUploader
@@ -70,8 +70,8 @@ class AsyncDownloader(object):
70
70
  logging.error("ConnectTimeout download error!")
71
71
  logging.exception(e)
72
72
  time.sleep(2)
73
- except MediaNotFound as e:
74
- logging.warning("MediaNotFound occurred!")
73
+ except (MediaNotFound, ClientNotFoundError, UserNotFound) as e:
74
+ logging.warning("Not found error occurred!")
75
75
  logging.exception(e)
76
76
  self.uploader.queue_task(job.to_upload_job(
77
77
  job_failed=True,
@@ -118,8 +118,17 @@ class AsyncDownloader(object):
118
118
  else:
119
119
  job_args["local_media_path"] = item["local_media_path"]
120
120
 
121
+ logging.debug("local_media_path: '%s'", job_args.get("local_media_path", ""))
122
+ logging.debug("media_collection: '%s'", str(job_args.get("media_collection", {})))
121
123
  upload_job = job.to_upload_job(**job_args)
122
- self.uploader.queue_task(upload_job)
124
+ if upload_job.is_empty():
125
+ logging.info("Upload job is empty. Nothing to do here!")
126
+ self.uploader.queue_task(job.to_upload_job(
127
+ job_failed=True,
128
+ job_failed_msg="Seems like this link doesn't contains any media.")
129
+ )
130
+ else:
131
+ self.uploader.queue_task(upload_job)
123
132
  else:
124
133
  logging.info("Job already in work in parallel worker. Redirecting job to upload worker.")
125
134
  self.uploader.queue_task(job.to_upload_job())
@@ -6,6 +6,7 @@ from typing import Callable, Optional, Union
6
6
 
7
7
  import requests
8
8
  import urllib3
9
+ from urllib.parse import urljoin, urlparse
9
10
  import logging
10
11
 
11
12
  from instagrapi.mixins.story import Story
@@ -51,7 +52,10 @@ class InstagramScrapler(ScraplerAbstract):
51
52
  self.load_session()
52
53
  def _scrap() -> tuple[str]:
53
54
  if "stories" in url:
54
- url_last_part = list(filter(None, url.split('/')))[-1]
55
+ # remove URL options
56
+ _url = urljoin(url, urlparse(url).path)
57
+ url_last_part = list(filter(None, _url.split('/')))[-1]
58
+ logging.debug("url last part: '%s'", url_last_part)
55
59
  if url_last_part.isnumeric():
56
60
  return "story", self.scrap_story(url)
57
61
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: warp_beacon
3
- Version: 1.0.2
3
+ Version: 1.0.4
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
@@ -231,14 +231,14 @@ Requires-Dist: pillow
231
231
  Requires-Dist: pymongo
232
232
  Requires-Dist: instagrapi ==2.0.0
233
233
 
234
- # warp_beacon [![Upload Python Package](https://github.com/sb0y/warp_beacon/actions/workflows/python-publish.yml/badge.svg)](https://github.com/sb0y/warp_beacon/actions/workflows/python-publish.yml) [![Docker Image CI](https://github.com/sb0y/warp_beacon/actions/workflows/docker-image.yml/badge.svg)](https://github.com/sb0y/warp_beacon/actions/workflows/docker-image.yml)
234
+ # warp_beacon [![Upload Python Package](https://github.com/sb0y/warp_beacon/actions/workflows/python-publish.yml/badge.svg)](https://github.com/sb0y/warp_beacon/actions/workflows/python-publish.yml) [![Docker Image CI](https://github.com/sb0y/warp_beacon/actions/workflows/docker-image.yml/badge.svg)](https://github.com/sb0y/warp_beacon/actions/workflows/docker-image.yml) [![Build DEB package](https://github.com/sb0y/warp_beacon/actions/workflows/build-deb.yml/badge.svg)](https://github.com/sb0y/warp_beacon/actions/workflows/build-deb.yml)
235
235
 
236
236
  Telegram bot for external social networks media scrapling.
237
237
  Works with links in personal messages and also with group chats.
238
238
 
239
239
  Just send to bot media link and get video.
240
240
 
241
- All bot configuration stored in [variables.env](https://github.com/sb0y/warp_beacon/blob/main/variables.env) file.
241
+ All bot configuration stored in [warp_beacon.conf](https://github.com/sb0y/warp_beacon/blob/main/etc/warp_beacon.conf) file.
242
242
 
243
243
  ## Configuration example ##
244
244
 
@@ -261,9 +261,21 @@ WORKERS_POOL_SIZE=3
261
261
  Any Linux machine will suit in.
262
262
 
263
263
  Install docker and git
264
- ```
265
- apt update
266
- apt install docker-compose git
264
+ ```bash
265
+ sudo apt update
266
+ # uninstall old docker packages
267
+ for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
268
+ sudo apt install ca-certificates curl git
269
+ sudo install -m 0755 -d /etc/apt/keyrings
270
+ sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
271
+ sudo chmod a+r /etc/apt/keyrings/docker.asc
272
+ # Add the repository to Apt sources:
273
+ echo \
274
+ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
275
+ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
276
+ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
277
+ sudo apt update
278
+ sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin git
267
279
  ```
268
280
 
269
281
  Download sources
@@ -277,10 +289,65 @@ cd warp_beacon
277
289
 
278
290
  Run app
279
291
  ```bash
280
- docker-compose up -d
292
+ sudo docker compose up -d
281
293
  ```
282
294
 
283
295
  Check logs
284
296
  ```bash
285
- docker-compose logs warp_beacon -f
297
+ sudo docker compose logs warp_beacon -f
298
+ ```
299
+
300
+ ## How to install from PIP ##
301
+
302
+ ```bash
303
+ sudo apt update
304
+ sudo apt install python3-pip
305
+ sudo pip install warp-beacon
306
+ ```
307
+
308
+ Your configuration file will be located at `/usr/local/lib/python3.10/dist-packages/etc/warp_beacon/warp_beacon.conf`.
309
+ For convenience, we will copy it to a common directory:
310
+
311
+ ```bash
312
+ mkdir /etc/warp_beacon
313
+ cp /usr/local/lib/python3.10/dist-packages/etc/warp_beacon/warp_beacon.conf /etc/warp_beacon/warp_beacon.conf
314
+ ```
315
+
316
+ Run the app
317
+
318
+ ```bash
319
+ source /etc/warp_beacon/warp_beacon.conf && /usr/local/bin/warp_beacon
320
+ ```
321
+
322
+ Most likely you will need a systemd service so that you don't have to start the service manually and don't have to worry about service start on server reboot.
323
+
324
+ ```bash
325
+ cp /usr/local/lib/python3.10/dist-packages/lib/systemd/system/warp_beacon.service /lib/systemd/system
326
+ systemctl unmask warp_beacon.service
327
+ systemctl enable warp_beacon.service
328
+ # start the service app
329
+ systemctl start warp_beacon.service
330
+ ```
331
+
332
+ ## How to build Python whl package ##
333
+ ```bash
334
+ sudo apt install python3-pip python3-build python3-virtualenv dh-virtualenv
335
+ # If you are getting build errors you probably need the latest version of python3-build
336
+ sudo python3 -m pip install --upgrade build
337
+ python3 -m build
338
+ ```
339
+
340
+ ## How to build Ubuntu deb package ##
341
+
342
+ ```bash
343
+ sudo apt update
344
+ sudo apt install debhelper python3-pip python3-build python3-virtualenv dh-virtualenv dh-python
345
+ # If you are getting build errors you probably need the latest version of python3-build
346
+ sudo python3 -m pip install --upgrade build
347
+ ```
348
+
349
+ build deb file
350
+
351
+ ```bash
352
+ dpkg-buildpackage -us -uc -b
286
353
  ```
@@ -1,22 +1,22 @@
1
1
  etc/warp_beacon/warp_beacon.conf,sha256=De80YgoU2uZ5-v2s3QX3etAGZ4bZxaBqV0d2xk872RQ,240
2
2
  lib/systemd/system/warp_beacon.service,sha256=lPmHqLqcI2eIV7nwHS0qcALQrznixqJuwwPfa2mDLUA,372
3
3
  warp_beacon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- warp_beacon/__version__.py,sha256=8LGbZNBoG5xuNYIYHgCEGGM0sb3ykIY8LZgr4orLfPc,23
4
+ warp_beacon/__version__.py,sha256=6wBrqLaWadCfrxfgwwZYsCOPDrwUXxTkLxUFuR0WLPo,23
5
5
  warp_beacon/warp_beacon.py,sha256=7vjHQdrwezQOpw_5I_cDsl8WHOEraX72Ft3gTySRZrg,12191
6
6
  warp_beacon/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- warp_beacon/jobs/abstract.py,sha256=8WognrL1izF3MiKUfoFaxjn46xzsXfJAK7w9Yj9spBk,1247
8
- warp_beacon/jobs/download_job.py,sha256=q2ZBc4mNb0vf_e5_PCyPDzFnPJ564Tm218PZysjauHA,735
9
- warp_beacon/jobs/upload_job.py,sha256=eUBudKV0Z-pqCJ_kdeY_lWMrEqX8Yte5MlEB7Cekvew,739
7
+ warp_beacon/jobs/abstract.py,sha256=LxPRt6ojM6lHXKnZ79H1lMSL9vs9H0yUkN4ZWo4Whjk,1428
8
+ warp_beacon/jobs/download_job.py,sha256=wfZrKUerfYIjWkRxPzfl5gwIlcotIMH7OpTUM9ae8NY,736
9
+ warp_beacon/jobs/upload_job.py,sha256=Vaogc4vbpAfyaT4VkIHEPLFRELmM44TDqkmnPYh3Ymc,740
10
10
  warp_beacon/mediainfo/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  warp_beacon/mediainfo/video.py,sha256=wYPf1_55PW_x6ifSsgXTKVNbTHU_31IumVpUk1ua5dY,2172
12
- warp_beacon/scrapler/__init__.py,sha256=-fmjF6F9SyYCR4vHwwYwPTZHD6vPlZmdbLqCeTor1Ms,5547
12
+ warp_beacon/scrapler/__init__.py,sha256=4CKmUOVlQO2_nI47Pa1eQNPGpoqrXSk4JH4EjH-etOk,6099
13
13
  warp_beacon/scrapler/abstract.py,sha256=MJxpEovCWDYq2SwbbMsRDfp77WTwvbXXKiQxKWoj0ZQ,304
14
- warp_beacon/scrapler/instagram.py,sha256=30ewlKdAajRUMdV9EgjW4xJV_p--ev-7qcdNXUpauYM,7079
14
+ warp_beacon/scrapler/instagram.py,sha256=8CF_Zdxn1hStz_PgLxTc0FTt5heI84d-Ks0XzmD7-_o,7248
15
15
  warp_beacon/storage/__init__.py,sha256=NhD3V7UNRiZNf61yQEAjXOfi-tfA2LaJa7a7kvbkmtE,2402
16
16
  warp_beacon/uploader/__init__.py,sha256=39rXMYel1iqSgpS7QbFU6wk-WKF1f6EL6W3qceNxLhk,3685
17
- warp_beacon-1.0.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
18
- warp_beacon-1.0.2.dist-info/METADATA,sha256=2OEflfim_cJ8SwuSxx2HdbJWZGrlGFkbDiQNPaHfjdM,15664
19
- warp_beacon-1.0.2.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
20
- warp_beacon-1.0.2.dist-info/entry_points.txt,sha256=eSB61Rb89d56WY0O-vEIQwkn18J-4CMrJcLA_R_8h3g,119
21
- warp_beacon-1.0.2.dist-info/top_level.txt,sha256=VZcz1AU0_EdW3t-74hnT1eazFqSyWgGdF5divvARwmM,334
22
- warp_beacon-1.0.2.dist-info/RECORD,,
17
+ warp_beacon-1.0.4.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
18
+ warp_beacon-1.0.4.dist-info/METADATA,sha256=6oR7v-3jpNm3zZ30DKvshv01MgaNKCZXBRh5J0tl_9o,18201
19
+ warp_beacon-1.0.4.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
20
+ warp_beacon-1.0.4.dist-info/entry_points.txt,sha256=eSB61Rb89d56WY0O-vEIQwkn18J-4CMrJcLA_R_8h3g,119
21
+ warp_beacon-1.0.4.dist-info/top_level.txt,sha256=VZcz1AU0_EdW3t-74hnT1eazFqSyWgGdF5divvARwmM,334
22
+ warp_beacon-1.0.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.2.0)
2
+ Generator: setuptools (70.3.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5