plexflow 0.0.71__py3-none-any.whl → 0.0.72__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.
- plexflow/core/subtitles/providers/__pycache__/auto_subtitles.cpython-312.pyc +0 -0
- plexflow/core/subtitles/providers/auto_subtitles.py +4 -3
- plexflow/core/subtitles/providers/oss/__pycache__/download.cpython-312.pyc +0 -0
- plexflow/core/subtitles/providers/oss/__pycache__/oss.cpython-312.pyc +0 -0
- plexflow/core/subtitles/providers/oss/__pycache__/search.cpython-312.pyc +0 -0
- plexflow/core/subtitles/providers/oss/__pycache__/unlimited_oss.cpython-312.pyc +0 -0
- plexflow/core/subtitles/providers/oss/download.py +5 -4
- plexflow/core/subtitles/providers/oss/oss.py +6 -5
- plexflow/core/subtitles/providers/oss/search.py +5 -4
- plexflow/core/subtitles/providers/oss/unlimited_oss.py +7 -7
- {plexflow-0.0.71.dist-info → plexflow-0.0.72.dist-info}/METADATA +1 -1
- {plexflow-0.0.71.dist-info → plexflow-0.0.72.dist-info}/RECORD +14 -14
- {plexflow-0.0.71.dist-info → plexflow-0.0.72.dist-info}/WHEEL +0 -0
- {plexflow-0.0.71.dist-info → plexflow-0.0.72.dist-info}/entry_points.txt +0 -0
Binary file
|
@@ -8,6 +8,7 @@ from plexflow.utils.retry.utils import execute_until_success
|
|
8
8
|
import time
|
9
9
|
from pathlib import Path
|
10
10
|
from plexflow.logging.log_setup import logger
|
11
|
+
import redis
|
11
12
|
|
12
13
|
class AutoSubtitles:
|
13
14
|
"""
|
@@ -22,20 +23,20 @@ class AutoSubtitles:
|
|
22
23
|
def __init__(self, imdb_id: str, languages: List[str] = (), **kwargs: Any) -> None:
|
23
24
|
self.imdb_id = imdb_id
|
24
25
|
self.languages = languages
|
25
|
-
self.
|
26
|
+
self.redis = kwargs.pop("redis", redis.Redis())
|
26
27
|
self.download = kwargs.pop("download", False)
|
27
28
|
self.download_folder = Path(kwargs.pop("download_folder", Path(".")))
|
28
29
|
self.kwargs = kwargs
|
29
30
|
|
30
31
|
def __iter__(self) -> Iterator[OSSSubtitle]:
|
31
|
-
subtitles = get_subtitles(self.imdb_id, self.languages, self.
|
32
|
+
subtitles = get_subtitles(self.imdb_id, self.languages, self.redis, ignore_blacklist=True, **self.kwargs)
|
32
33
|
if len(subtitles) == 0:
|
33
34
|
logger.warning(f"No subtitles found for IMDb ID: {self.imdb_id}")
|
34
35
|
return
|
35
36
|
|
36
37
|
for subtitle in tqdm(subtitles, total=len(subtitles)):
|
37
38
|
if self.download:
|
38
|
-
subtitle_path, skipped = execute_until_success(download_subtitle, delay_type='constant', delay=3, max_retries=10, subtitle=subtitle,
|
39
|
+
subtitle_path, skipped = execute_until_success(download_subtitle, delay_type='constant', delay=3, max_retries=10, subtitle=subtitle, r=self.redis, retry_exceptions=[OpenSubtitlesDownloadQuotaReachedException], save_dir=self.download_folder)
|
39
40
|
if not skipped:
|
40
41
|
logger.debug(f"Subtitle downloaded: {subtitle_path}")
|
41
42
|
# time.sleep(1.2)
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -6,8 +6,9 @@ from plexflow.utils.retry.utils import execute_until_success
|
|
6
6
|
from plexflow.utils.hooks.redis import UniversalRedisHook
|
7
7
|
from pathlib import Path
|
8
8
|
from plexflow.logging.log_setup import logger
|
9
|
+
import redis
|
9
10
|
|
10
|
-
def download_subtitle(subtitle: OSSSubtitle,
|
11
|
+
def download_subtitle(subtitle: OSSSubtitle, r: redis.Redis = None, save_dir: Path = Path('.'), skip_exists: bool = True) -> None:
|
11
12
|
"""
|
12
13
|
Downloads and saves the subtitle file using the OpenSubtitlesManager.
|
13
14
|
|
@@ -27,7 +28,7 @@ def download_subtitle(subtitle: OSSSubtitle, redis_hook: UniversalRedisHook = No
|
|
27
28
|
else:
|
28
29
|
with OpenSubtitlesManager.from_yaml(
|
29
30
|
yaml_file='config/credentials.yaml',
|
30
|
-
|
31
|
+
r=r,
|
31
32
|
) as manager:
|
32
33
|
filepath.parent.mkdir(parents=True, exist_ok=True)
|
33
34
|
metapath.write_text(subtitle.subtitle.to_json())
|
@@ -43,6 +44,6 @@ def download_subtitles(subtitles: List[OSSSubtitle], **kwargs) -> None:
|
|
43
44
|
Returns:
|
44
45
|
None
|
45
46
|
"""
|
46
|
-
|
47
|
+
r = kwargs.pop("redis", redis.Redis())
|
47
48
|
for subtitle in subtitles:
|
48
|
-
execute_until_success(download_subtitle, delay_type='constant', delay=3, max_retries=10, subtitle=subtitle,
|
49
|
+
execute_until_success(download_subtitle, delay_type='constant', delay=3, max_retries=10, subtitle=subtitle, r=r, retry_exceptions=[OpenSubtitlesDownloadQuotaReachedException])
|
@@ -22,11 +22,12 @@ from plexflow.core.subtitles.providers.oss.utils.download_client import Download
|
|
22
22
|
from plexflow.core.subtitles.providers.oss.utils.languages import language_codes
|
23
23
|
from plexflow.utils.hooks.redis import UniversalRedisHook
|
24
24
|
from plexflow.logging.log_setup import logger
|
25
|
+
import redis
|
25
26
|
|
26
27
|
class OpenSubtitles:
|
27
28
|
"""OpenSubtitles REST API Wrapper."""
|
28
29
|
|
29
|
-
def __init__(self, user_agent: str, api_key: str,
|
30
|
+
def __init__(self, user_agent: str, api_key: str, r: redis.Redis = None):
|
30
31
|
"""Initialize the OpenSubtitles object.
|
31
32
|
|
32
33
|
:param api_key:
|
@@ -41,13 +42,13 @@ class OpenSubtitles:
|
|
41
42
|
self.downloads_dir = "."
|
42
43
|
self.user_downloads_remaining = 0
|
43
44
|
self.reset_time = None
|
44
|
-
self.
|
45
|
+
self.redis = r
|
45
46
|
|
46
47
|
@property
|
47
48
|
def cached_token(self):
|
48
49
|
try:
|
49
|
-
if self.
|
50
|
-
return self.
|
50
|
+
if self.redis:
|
51
|
+
return self.redis.get(f"@opensubtitles/{self.api_key}/token").decode("utf-8")
|
51
52
|
else:
|
52
53
|
return None
|
53
54
|
except Exception as e:
|
@@ -59,7 +60,7 @@ class OpenSubtitles:
|
|
59
60
|
def cached_token(self, token: str):
|
60
61
|
try:
|
61
62
|
logger.debug(f"caching token: {token}")
|
62
|
-
self.
|
63
|
+
self.redis.set(f"@opensubtitles/{self.api_key}/token", token, ex=60*60)
|
63
64
|
except Exception as e:
|
64
65
|
logger.error(f"Error setting cached token: {e}")
|
65
66
|
|
@@ -5,9 +5,10 @@ from plexflow.core.subtitles.providers.oss.oss_subtitle import OSSSubtitle
|
|
5
5
|
from typing import Any, List
|
6
6
|
from contextlib import contextmanager, ExitStack
|
7
7
|
from plexflow.utils.hooks.redis import UniversalRedisHook
|
8
|
+
import redis
|
8
9
|
|
9
10
|
@contextmanager
|
10
|
-
def open_subtitles_manager(credentials_path: str,
|
11
|
+
def open_subtitles_manager(credentials_path: str, r: redis.Redis = None, **kwargs: Any):
|
11
12
|
"""
|
12
13
|
Context manager for managing the OpenSubtitlesManager instance.
|
13
14
|
|
@@ -22,12 +23,12 @@ def open_subtitles_manager(credentials_path: str, redis_hook: UniversalRedisHook
|
|
22
23
|
with ExitStack() as stack:
|
23
24
|
manager = stack.enter_context(OpenSubtitlesManager.from_yaml(
|
24
25
|
yaml_file=credentials_path,
|
25
|
-
|
26
|
+
r=r,
|
26
27
|
**kwargs
|
27
28
|
))
|
28
29
|
yield manager
|
29
30
|
|
30
|
-
def get_subtitles(imdb_id: str, languages: List[str] = (),
|
31
|
+
def get_subtitles(imdb_id: str, languages: List[str] = (), r: redis.Redis = None, ignore_blacklist: bool = False, **kwargs) -> List[OSSSubtitle]:
|
31
32
|
"""
|
32
33
|
Retrieves subtitles using OpenSubtitlesManager.
|
33
34
|
|
@@ -40,7 +41,7 @@ def get_subtitles(imdb_id: str, languages: List[str] = (), redis_hook: Universal
|
|
40
41
|
"""
|
41
42
|
with open_subtitles_manager(
|
42
43
|
credentials_path=kwargs.pop("credentials_path"),
|
43
|
-
|
44
|
+
r=r,
|
44
45
|
ignore_blacklist=ignore_blacklist,
|
45
46
|
) as manager:
|
46
47
|
subtitles = manager.search(
|
@@ -53,7 +53,7 @@ class OpenSubtitlesManager:
|
|
53
53
|
REDIS_DEFAULT_PORT = 6379
|
54
54
|
DEFAULT_TTL = 60*60 # 1 hour
|
55
55
|
|
56
|
-
def __init__(self, credentials: List[Dict[str, str]],
|
56
|
+
def __init__(self, credentials: List[Dict[str, str]], r: redis.Redis = None, **kwargs):
|
57
57
|
"""
|
58
58
|
Initializes an instance of the OpenSubtitlesManager class.
|
59
59
|
|
@@ -64,7 +64,7 @@ class OpenSubtitlesManager:
|
|
64
64
|
redis_port (int, optional): The port of the Redis server used for blacklisting credentials. Defaults to 6379.
|
65
65
|
"""
|
66
66
|
self.credentials = credentials
|
67
|
-
self.
|
67
|
+
self.redis = r
|
68
68
|
self.current_instance = None
|
69
69
|
self.current_credential = None
|
70
70
|
self.ignore_blacklist = kwargs.get('ignore_blacklist', False)
|
@@ -72,7 +72,7 @@ class OpenSubtitlesManager:
|
|
72
72
|
self.instances = {}
|
73
73
|
|
74
74
|
@classmethod
|
75
|
-
def from_yaml(cls, yaml_file: str,
|
75
|
+
def from_yaml(cls, yaml_file: str, r: redis.Redis = None, **kwargs) -> 'OpenSubtitlesManager':
|
76
76
|
"""
|
77
77
|
Creates an instance of the OpenSubtitlesManager class from a YAML file.
|
78
78
|
|
@@ -86,7 +86,7 @@ class OpenSubtitlesManager:
|
|
86
86
|
"""
|
87
87
|
with open(yaml_file, 'r') as file:
|
88
88
|
credentials = yaml.safe_load(file)
|
89
|
-
return cls(credentials=credentials,
|
89
|
+
return cls(credentials=credentials, r=r, **kwargs)
|
90
90
|
|
91
91
|
def __enter__(self) -> OpenSubtitles:
|
92
92
|
"""
|
@@ -181,7 +181,7 @@ class OpenSubtitlesManager:
|
|
181
181
|
if api_key in self.instances:
|
182
182
|
return self.instances[api_key]
|
183
183
|
|
184
|
-
instance = OpenSubtitles(user_agent, api_key,
|
184
|
+
instance = OpenSubtitles(user_agent, api_key, r=self.redis)
|
185
185
|
instance.login(username, password)
|
186
186
|
|
187
187
|
# Cache the instance for later reuse
|
@@ -201,7 +201,7 @@ class OpenSubtitlesManager:
|
|
201
201
|
"""
|
202
202
|
key = self.generate_credential_key(credential)
|
203
203
|
self.logger.debug(f"Generated credential key: {key}")
|
204
|
-
return self.
|
204
|
+
return self.redis.exists(key)
|
205
205
|
|
206
206
|
def blacklist_credential(self):
|
207
207
|
"""
|
@@ -209,7 +209,7 @@ class OpenSubtitlesManager:
|
|
209
209
|
|
210
210
|
"""
|
211
211
|
key = self.generate_credential_key(self.current_credential)
|
212
|
-
self.
|
212
|
+
self.redis.setex(key, self.DEFAULT_TTL, 'blacklisted')
|
213
213
|
self.logger.debug(f"Credential blacklisted for {self.DEFAULT_TTL} seconds: {self.current_credential}")
|
214
214
|
self.logger.debug(f"Blacklisted credential key: {key}")
|
215
215
|
|
@@ -301,29 +301,29 @@ plexflow/core/subtitles/providers/__pycache__/__init__.cpython-311.pyc,sha256=2z
|
|
301
301
|
plexflow/core/subtitles/providers/__pycache__/__init__.cpython-312.pyc,sha256=gp9rHSu09WohhuFlVII26NTnqB9maGtEsjc8rKQ7pvo,171
|
302
302
|
plexflow/core/subtitles/providers/__pycache__/auto_subtiltes.cpython-311.pyc,sha256=Coddhp2j6Ay3oA1H5qQEHbn1qqpBLrHaINC8K-TaZqI,3857
|
303
303
|
plexflow/core/subtitles/providers/__pycache__/auto_subtitles.cpython-311.pyc,sha256=BEiGR-WcFPy0Lp4bgA8ykjs081bpT5m0L3sqy6Kqfdg,3893
|
304
|
-
plexflow/core/subtitles/providers/__pycache__/auto_subtitles.cpython-312.pyc,sha256=
|
305
|
-
plexflow/core/subtitles/providers/auto_subtitles.py,sha256=
|
304
|
+
plexflow/core/subtitles/providers/__pycache__/auto_subtitles.cpython-312.pyc,sha256=JqzDzkfmfCe_2Oa_XKWtvGAb7s2QbYP3ExS0xQGXB6c,3463
|
305
|
+
plexflow/core/subtitles/providers/auto_subtitles.py,sha256=lq7pEBBkrrkVjieB7uPs89v-SDlrOGbMhUzkA0pzii0,2200
|
306
306
|
plexflow/core/subtitles/providers/oss/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
307
307
|
plexflow/core/subtitles/providers/oss/__pycache__/__init__.cpython-311.pyc,sha256=fisyzWOS6ZR67F7A-k7WEaapRbm2h0mapOixVKgavqs,187
|
308
308
|
plexflow/core/subtitles/providers/oss/__pycache__/__init__.cpython-312.pyc,sha256=H2fhQnTvVsfRSfrDSReYATGTisbG-QEA6P-AHi8y-1U,175
|
309
309
|
plexflow/core/subtitles/providers/oss/__pycache__/datatypes.cpython-311.pyc,sha256=wCE0qHCaISXvsiDdrakvfbW8_Fww3JeG8ep2wmfwgQ4,8771
|
310
310
|
plexflow/core/subtitles/providers/oss/__pycache__/download.cpython-311.pyc,sha256=qyfLK7z1Yb0r5aM8KvPLeu0P1hflX5zqHEvfLtmF_hw,3733
|
311
|
-
plexflow/core/subtitles/providers/oss/__pycache__/download.cpython-312.pyc,sha256=
|
311
|
+
plexflow/core/subtitles/providers/oss/__pycache__/download.cpython-312.pyc,sha256=AJ3vVJBQKuvE0xI9CrhwXDyKm2bG-gfZWNbWfn9PWgg,3307
|
312
312
|
plexflow/core/subtitles/providers/oss/__pycache__/oss.cpython-311.pyc,sha256=tbcGIfaslOGnfjwoko8TSKIGRRO4sM86Gbmy7OG9occ,21609
|
313
|
-
plexflow/core/subtitles/providers/oss/__pycache__/oss.cpython-312.pyc,sha256=
|
313
|
+
plexflow/core/subtitles/providers/oss/__pycache__/oss.cpython-312.pyc,sha256=UXRE-8qiUAEkB55aYFtWb7WL8jHXozdIDGHZWkyQKRM,19694
|
314
314
|
plexflow/core/subtitles/providers/oss/__pycache__/oss_subtitle.cpython-311.pyc,sha256=IfUEII4Khd7b4vs1Ag73irbmoulk1f9uKOX9xI0vtlo,2396
|
315
315
|
plexflow/core/subtitles/providers/oss/__pycache__/oss_subtitle.cpython-312.pyc,sha256=0PePMgbDM2KZPA7JUib_JjKtDziyICdBDU6xBc09Lz8,2287
|
316
316
|
plexflow/core/subtitles/providers/oss/__pycache__/search.cpython-311.pyc,sha256=Hb6ZX9B0wjeOvOMNaw-eZnPBITsINQ3Cs8cYebq-dKs,3038
|
317
|
-
plexflow/core/subtitles/providers/oss/__pycache__/search.cpython-312.pyc,sha256=
|
317
|
+
plexflow/core/subtitles/providers/oss/__pycache__/search.cpython-312.pyc,sha256=nSqaXHXI1Fe9mncp492AhLr444SMze-6QrZkdz94wr8,2662
|
318
318
|
plexflow/core/subtitles/providers/oss/__pycache__/unlimited_oss.cpython-311.pyc,sha256=OUvBlMRcl1mDpT9UnhZl9g9YZgfJj5Y8Gff2oIto1V8,12587
|
319
|
-
plexflow/core/subtitles/providers/oss/__pycache__/unlimited_oss.cpython-312.pyc,sha256=
|
319
|
+
plexflow/core/subtitles/providers/oss/__pycache__/unlimited_oss.cpython-312.pyc,sha256=Z4akT251BicN1_OsJ8VWq-7b5EoPyHL-JfalKVEi0xA,11705
|
320
320
|
plexflow/core/subtitles/providers/oss/datatypes.py,sha256=7YvjS8a3riEJ4yqLKzTRv5g6vftcrcoYKGcBoq0MCLo,3620
|
321
|
-
plexflow/core/subtitles/providers/oss/download.py,sha256=
|
321
|
+
plexflow/core/subtitles/providers/oss/download.py,sha256=L01YhbG85kYO1NjhsP5djrtra8TX8fQziha-bhilFA4,2103
|
322
322
|
plexflow/core/subtitles/providers/oss/old.py,sha256=IoZ7iIRs3FoxxJgzGrgMGNJpVXqZ3aAaadjKJJ3Lw0o,5566
|
323
|
-
plexflow/core/subtitles/providers/oss/oss.py,sha256=
|
323
|
+
plexflow/core/subtitles/providers/oss/oss.py,sha256=m0UGVMs50-et8_RfYCOOJXPDRabBZOW8UyLiPeq83AQ,15921
|
324
324
|
plexflow/core/subtitles/providers/oss/oss_subtitle.py,sha256=SuFv90Z_KUELHnAm85SpZNsH0tXKJMMgFKODYgjDmzc,879
|
325
|
-
plexflow/core/subtitles/providers/oss/search.py,sha256=
|
326
|
-
plexflow/core/subtitles/providers/oss/unlimited_oss.py,sha256=
|
325
|
+
plexflow/core/subtitles/providers/oss/search.py,sha256=VKMVgaZ67Juxlvf7IRqpo1QYKVKAaJg8Zhj-NQhjoy0,1865
|
326
|
+
plexflow/core/subtitles/providers/oss/unlimited_oss.py,sha256=7PN6N5-1Pc9TNQqmnIPX5Q9ZQhEAnRTrO2ExlE2xOWc,9562
|
327
327
|
plexflow/core/subtitles/providers/oss/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
328
328
|
plexflow/core/subtitles/providers/oss/utils/__pycache__/__init__.cpython-311.pyc,sha256=nBHOv53UkuFjaPU3Zih_W5tvdRYEmZOeySSrsa3qsGo,193
|
329
329
|
plexflow/core/subtitles/providers/oss/utils/__pycache__/__init__.cpython-312.pyc,sha256=nWQpxGf6NgdB_p8RS6e0DO4jYZ9h8xjAc8GGiJUs8wk,181
|
@@ -643,7 +643,7 @@ plexflow/utils/video/__pycache__/audio.cpython-312.pyc,sha256=vXBnJwWgTDFdixMBs-
|
|
643
643
|
plexflow/utils/video/__pycache__/subtitle.cpython-312.pyc,sha256=PCjpCLydGXaRsQy6cikhgsEs8WlComfOoYPiLFqfVMA,2515
|
644
644
|
plexflow/utils/video/audio.py,sha256=tJ_lNwcjVuBQYD5cYOlXpr__eh8-hnReIgNRgIYOpqo,3380
|
645
645
|
plexflow/utils/video/subtitle.py,sha256=LOGONGxs_RzmqtGP-DBKreOzS1eUFEKo75Q6AfnavW0,1290
|
646
|
-
plexflow-0.0.
|
647
|
-
plexflow-0.0.
|
648
|
-
plexflow-0.0.
|
649
|
-
plexflow-0.0.
|
646
|
+
plexflow-0.0.72.dist-info/METADATA,sha256=2DaRTicObE0Ur301xwko7FCy7TE2Fcr_k36uOMojxnE,2954
|
647
|
+
plexflow-0.0.72.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
648
|
+
plexflow-0.0.72.dist-info/entry_points.txt,sha256=A-_w_iUmjrSgDtOcX-G5H3NboAAZNzwiFoQbBf4bVjg,1302
|
649
|
+
plexflow-0.0.72.dist-info/RECORD,,
|
File without changes
|
File without changes
|