warp-beacon 1.2.6__py3-none-any.whl → 2.0.1__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.
- etc/warp_beacon/warp_beacon.conf +4 -2
- warp_beacon/__version__.py +1 -1
- warp_beacon/jobs/__init__.py +2 -0
- warp_beacon/jobs/abstract.py +21 -4
- warp_beacon/jobs/download_job.py +6 -3
- warp_beacon/jobs/types.py +9 -0
- warp_beacon/jobs/upload_job.py +1 -0
- warp_beacon/mediainfo/abstract.py +11 -1
- warp_beacon/mediainfo/silencer.py +46 -0
- warp_beacon/mediainfo/video.py +13 -1
- warp_beacon/scraper/__init__.py +38 -23
- warp_beacon/scraper/abstract.py +26 -0
- warp_beacon/scraper/instagram.py +35 -24
- warp_beacon/scraper/youtube/abstract.py +105 -0
- warp_beacon/scraper/youtube/music.py +12 -108
- warp_beacon/scraper/youtube/shorts.py +20 -73
- warp_beacon/scraper/youtube/youtube.py +41 -0
- warp_beacon/storage/__init__.py +27 -6
- warp_beacon/telegram/__init__.py +0 -0
- warp_beacon/telegram/bot.py +348 -0
- warp_beacon/telegram/handlers.py +163 -0
- warp_beacon/telegram/placeholder_message.py +191 -0
- warp_beacon/telegram/utils.py +73 -0
- warp_beacon/uploader/__init__.py +9 -9
- warp_beacon/warp_beacon.py +8 -594
- {warp_beacon-1.2.6.dist-info → warp_beacon-2.0.1.dist-info}/METADATA +4 -2
- warp_beacon-2.0.1.dist-info/RECORD +40 -0
- {warp_beacon-1.2.6.dist-info → warp_beacon-2.0.1.dist-info}/WHEEL +1 -1
- {warp_beacon-1.2.6.dist-info → warp_beacon-2.0.1.dist-info}/top_level.txt +9 -0
- warp_beacon-1.2.6.dist-info/RECORD +0 -31
- {warp_beacon-1.2.6.dist-info → warp_beacon-2.0.1.dist-info}/LICENSE +0 -0
- {warp_beacon-1.2.6.dist-info → warp_beacon-2.0.1.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
import re
|
2
|
+
|
3
|
+
import requests
|
4
|
+
|
5
|
+
from enum import Enum
|
6
|
+
from typing import Union
|
7
|
+
|
8
|
+
from warp_beacon.jobs import Origin
|
9
|
+
from warp_beacon.jobs.types import JobType
|
10
|
+
|
11
|
+
import logging
|
12
|
+
|
13
|
+
class Utils(object):
|
14
|
+
expected_patronum_compiled_re = re.compile(r'Expected ([A-Z]+), got ([A-Z]+) file id instead')
|
15
|
+
|
16
|
+
@staticmethod
|
17
|
+
def extract_file_id(message: "Message") -> Union[None, str]:
|
18
|
+
possible_attrs = ("video", "photo", "audio", "animation", "document")
|
19
|
+
for attr in possible_attrs:
|
20
|
+
if hasattr(message, attr):
|
21
|
+
_attr = getattr(message, attr, None)
|
22
|
+
if _attr:
|
23
|
+
tg_id = getattr(_attr, "file_id", None)
|
24
|
+
if tg_id:
|
25
|
+
return tg_id
|
26
|
+
return None
|
27
|
+
|
28
|
+
@staticmethod
|
29
|
+
def extract_origin(url: str) -> Origin:
|
30
|
+
if "instagram.com/" in url:
|
31
|
+
return Origin.INSTAGRAM
|
32
|
+
|
33
|
+
if "youtube.com/" in url and "shorts/" in url:
|
34
|
+
return Origin.YT_SHORTS
|
35
|
+
|
36
|
+
if "youtube.com/" in url and "music." in url:
|
37
|
+
return Origin.YT_MUSIC
|
38
|
+
|
39
|
+
if "youtu.be/" in url:
|
40
|
+
return Origin.YOUTU_BE
|
41
|
+
|
42
|
+
if "youtube.com/" in url:
|
43
|
+
return Origin.YOUTUBE
|
44
|
+
|
45
|
+
return Origin.UNKNOWN
|
46
|
+
|
47
|
+
@staticmethod
|
48
|
+
def extract_youtu_be_link(url: str) -> str:
|
49
|
+
try:
|
50
|
+
response = requests.get(
|
51
|
+
url=url,
|
52
|
+
allow_redirects=False
|
53
|
+
)
|
54
|
+
return response.headers["Location"]
|
55
|
+
except Exception as e:
|
56
|
+
logging.error("Failed to extract YouTube link!")
|
57
|
+
logging.exception(e)
|
58
|
+
|
59
|
+
return ''
|
60
|
+
|
61
|
+
@staticmethod
|
62
|
+
def parse_expected_patronum_error(err_text: str) -> tuple:
|
63
|
+
'''
|
64
|
+
Input example: 'Expected VIDEO, got ANIMATION file id instead'
|
65
|
+
'''
|
66
|
+
capture = re.match(Utils.expected_patronum_compiled_re, err_text)
|
67
|
+
expected_value, got_value = capture[1], capture[2]
|
68
|
+
|
69
|
+
return JobType[expected_value], JobType[got_value]
|
70
|
+
|
71
|
+
@staticmethod
|
72
|
+
def chunker(seq: list, size: int) -> list:
|
73
|
+
return (seq[pos:pos + size] for pos in range(0, len(seq), size))
|
warp_beacon/uploader/__init__.py
CHANGED
@@ -5,12 +5,11 @@ from warp_beacon.jobs.upload_job import UploadJob
|
|
5
5
|
import logging
|
6
6
|
|
7
7
|
import asyncio
|
8
|
-
from telegram import Update
|
9
|
-
from telegram.ext import ContextTypes
|
10
8
|
|
11
9
|
from typing import Optional, Callable, Coroutine
|
12
10
|
|
13
11
|
from warp_beacon.storage import Storage
|
12
|
+
from warp_beacon.jobs.types import JobType
|
14
13
|
|
15
14
|
class AsyncUploader(object):
|
16
15
|
__JOE_BIDEN_WAKEUP = None
|
@@ -38,12 +37,12 @@ class AsyncUploader(object):
|
|
38
37
|
thread.start()
|
39
38
|
self.threads.append(thread)
|
40
39
|
|
41
|
-
def add_callback(self, message_id: int, callback: Callable
|
40
|
+
def add_callback(self, message_id: int, callback: Callable) -> None:
|
42
41
|
def callback_wrap(*args, **kwargs) -> None:
|
43
42
|
ret = callback(*args, **kwargs)
|
44
43
|
#self.remove_callback(message_id)
|
45
44
|
return ret
|
46
|
-
self.callbacks[message_id] = {"callback": callback_wrap
|
45
|
+
self.callbacks[message_id] = {"callback": callback_wrap}
|
47
46
|
|
48
47
|
def remove_callback(self, message_id: int) -> None:
|
49
48
|
if message_id in self.callbacks:
|
@@ -82,15 +81,16 @@ class AsyncUploader(object):
|
|
82
81
|
if job is self.__JOE_BIDEN_WAKEUP:
|
83
82
|
continue
|
84
83
|
path = ""
|
85
|
-
if job.media_type ==
|
84
|
+
if job.media_type == JobType.COLLECTION:
|
86
85
|
for i in job.media_collection:
|
87
|
-
|
86
|
+
for j in i:
|
87
|
+
path += "%s; " % j.local_media_path
|
88
88
|
else:
|
89
89
|
path = job.local_media_path
|
90
90
|
in_process = job.in_process
|
91
91
|
uniq_id = job.uniq_id
|
92
92
|
message_id = job.placeholder_message_id
|
93
|
-
if not in_process and
|
93
|
+
if not in_process and not job.job_failed and not job.job_warning:
|
94
94
|
logging.info("Accepted upload job, file(s): '%s'", path)
|
95
95
|
try:
|
96
96
|
if message_id in self.callbacks:
|
@@ -113,10 +113,10 @@ class AsyncUploader(object):
|
|
113
113
|
dlds_len = len(db_list_dicts)
|
114
114
|
if dlds_len > 1:
|
115
115
|
job.tg_file_id = ",".join(tg_file_ids)
|
116
|
-
job.media_type =
|
116
|
+
job.media_type = JobType.COLLECTION
|
117
117
|
elif dlds_len:
|
118
118
|
job.tg_file_id = ",".join(tg_file_ids)
|
119
|
-
job.media_type = db_list_dicts.pop()["media_type"]
|
119
|
+
job.media_type = JobType[db_list_dicts.pop()["media_type"].upper()]
|
120
120
|
asyncio.ensure_future(self.callbacks[message_id]["callback"](job), loop=self.loop)
|
121
121
|
self.process_done(uniq_id)
|
122
122
|
self.remove_callback(message_id)
|