Skip to content

Commit 7fa60f1

Browse files
committed
fix: fixed resume button in frontend, notifications for shows, and alldebrid missing path attr bug
1 parent 07e2b84 commit 7fa60f1

File tree

5 files changed

+23
-44
lines changed

5 files changed

+23
-44
lines changed

src/program/media/item.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ def is_scraped(self) -> bool:
240240
try:
241241
session.refresh(self, attribute_names=["blacklisted_streams"])
242242
return (len(self.streams) > 0 and any(stream not in self.blacklisted_streams for stream in self.streams))
243-
except Exception as e:
244-
logger.error(f"Error refreshing item streams for {self.log_string}: {str(e)}")
243+
except:
244+
...
245245
return False
246246

247247
def to_dict(self):
@@ -541,7 +541,7 @@ def _determine_state(self):
541541
return States.Requested
542542
return States.Unknown
543543

544-
def store_state(self, given_state: States =None) -> None:
544+
def store_state(self, given_state: States = None) -> None:
545545
for season in self.seasons:
546546
season.store_state(given_state)
547547
super().store_state(given_state)

src/program/services/downloaders/models.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"m4v", "webm", "mpg","mpeg", "m2ts", "ts",
1313
]
1414

15-
ANIME_SPECIALS_PATTERN: regex.Pattern = regex.compile(r"\b(OVA|NCED|NCOP|NC|OVA|ED(\d?v?\d?)|OPv?(\d+)?)\b", regex.IGNORECASE)
15+
ANIME_SPECIALS_PATTERN: regex.Pattern = regex.compile(r"\b(OVA|NCED|NCOP|NC|OVA|ED(\d?v?\d?)|OPv?(\d+)?|SP\d+)\b", regex.IGNORECASE)
1616

1717
VIDEO_EXTENSIONS: list[str] = settings_manager.settings.downloaders.video_extensions or DEFAULT_VIDEO_EXTENSIONS
1818
VALID_VIDEO_EXTENSIONS = [ext for ext in VIDEO_EXTENSIONS if ext in ALLOWED_VIDEO_EXTENSIONS]
@@ -54,10 +54,10 @@ class DebridFile(BaseModel):
5454
@classmethod
5555
def create(
5656
cls,
57-
path: str,
58-
filename: str,
59-
filesize_bytes: int,
60-
filetype: Literal["movie", "show", "season", "episode"],
57+
path: str = None,
58+
filename: str = None,
59+
filesize_bytes: int = None,
60+
filetype: Literal["movie", "show", "season", "episode"] = None,
6161
file_id: Optional[int] = None,
6262
limit_filesize: bool = True
6363
) -> Optional["DebridFile"]:
@@ -70,7 +70,7 @@ def create(
7070
if not any(filename_lower.endswith(ext) for ext in VALID_VIDEO_EXTENSIONS):
7171
raise InvalidDebridFileException(f"Skipping non-video file: '{filename}'")
7272

73-
if ANIME_SPECIALS_PATTERN.search(path):
73+
if path and ANIME_SPECIALS_PATTERN.search(path):
7474
raise InvalidDebridFileException(f"Skipping anime special: '{path}'")
7575

7676
if limit_filesize:

src/program/services/post_processing/__init__.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from datetime import datetime
22

33
from loguru import logger
4-
from subliminal import Movie
54

65
from program.db.db import db
76
from program.db.db_functions import clear_streams
8-
from program.media.item import MediaItem, Movie, Show
7+
from program.media.item import MediaItem
98
from program.media.state import States
109
from program.services.post_processing.subliminal import Subliminal
1110
from program.settings.manager import settings_manager
@@ -42,12 +41,12 @@ def notify(item: MediaItem):
4241
with db.Session() as session:
4342
show = session.merge(show)
4443
show.store_state()
44+
if show.last_state == States.Completed:
45+
_notify(show)
4546
session.commit()
46-
if show == States.Completed:
47-
_notify(show)
4847

49-
def _notify(_item: Show | Movie):
50-
duration = round((datetime.now() - _item.requested_at).total_seconds())
51-
logger.success(f"{_item.log_string} has been completed in {duration} seconds.")
48+
def _notify(item: MediaItem):
49+
duration = round((datetime.now() - item.requested_at).total_seconds())
50+
logger.success(f"{item.log_string} has been completed in {duration} seconds.")
5251
if settings_manager.settings.notifications.enabled:
53-
notify_on_complete(_item)
52+
notify_on_complete(item)

src/program/utils/notifications.py

+6-26
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from apprise import Apprise
55
from loguru import logger
66

7-
from program.media.item import MediaItem
7+
from program.media.item import MediaItem, Stream
88
from program.settings.manager import settings_manager
99
from program.settings.models import NotificationsModel
1010
from program.utils import root_dir
@@ -39,36 +39,16 @@ def notification(title: str, body: str) -> None:
3939

4040
def _build_discord_notification(item: MediaItem) -> str:
4141
"""Build a discord notification for the given item using markdown that lists the files completed."""
42-
notification_message = f"[{item.type.title()}] **{item.log_string}**\n"
43-
44-
if item.type == "movie":
45-
notification_message += f" - File: {item.file}\n"
46-
47-
elif item.type == "show":
48-
for season in item.seasons:
49-
notification_message += f"- [Season {season.number}] **Season {season.number}**\n"
50-
for episode in season.episodes:
51-
notification_message += f" - [Episode {episode.number}] **{episode.log_string}**\n"
52-
notification_message += f" - File: {episode.file}\n"
53-
54-
elif item.type == "season":
55-
notification_message += f"- [Season {item.number}] **Season {item.number}**\n"
56-
for episode in item.episodes:
57-
notification_message += f" - [Episode {episode.number}] **{episode.log_string}**\n"
58-
notification_message += f" - File: {episode.file}\n"
59-
60-
elif item.type == "episode":
61-
notification_message += f" - [Episode {item.number}] **{item.log_string}**\n"
62-
notification_message += f" - File: {item.file}\n"
63-
42+
notification_message = f"### [{item.type.title()}] **{item.log_string}** ({item.aired_at.year})\n"
43+
stream: Stream = next((stream for stream in item.streams if stream.infohash == item.active_stream.get("infohash")), None)
44+
notification_message += f"- {stream.raw_title}\n"
6445
return notification_message
6546

66-
6747
def notify_on_complete(item: MediaItem) -> None:
6848
"""Send notifications to all services in settings."""
6949
if item.type not in on_item_type:
7050
return
71-
51+
7252
title = "Riven completed something!" if not settings.title else settings.title
7353
body = _build_discord_notification(item)
74-
notification(title, body)
54+
notification(title, body)

src/routers/secure/items.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ async def unpause_items(request: Request, ids: str) -> PauseResponse:
592592
for media_item in db_functions.get_items_by_ids(ids):
593593
try:
594594
if media_item.last_state == States.Paused:
595-
media_item.store_state(None) # recheck the last state
595+
media_item.store_state(States.Requested)
596596
session.merge(media_item)
597597
session.commit()
598598
request.app.program.em.add_event(Event("RetryItem", media_item.id))

0 commit comments

Comments
 (0)