mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Creating method that returns all Video files. Using this new method to delete the video files.
This commit is contained in:
parent
f655924c82
commit
8d3f65425a
1 changed files with 16 additions and 13 deletions
|
|
@ -2,7 +2,7 @@ import json
|
|||
import pathlib
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from typing import Optional, Generator
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Boolean, JSON, Date, ARRAY, ForeignKey, Computed
|
||||
from sqlalchemy.orm import relationship, Session, deferred
|
||||
|
|
@ -81,25 +81,28 @@ class Video(ModelHelper, Base):
|
|||
self.poster_path = None
|
||||
self.video_path = None
|
||||
|
||||
def my_paths(self) -> Generator[Path, None, None]:
|
||||
"""Return all paths of this Video. Returns nothing if all paths are None.""" # noqa
|
||||
if self.description_path: # noqa
|
||||
yield self.description_path.path
|
||||
if self.poster_path:
|
||||
yield self.poster_path.path
|
||||
if self.caption_path:
|
||||
yield self.caption_path.path
|
||||
if self.info_json_path:
|
||||
yield self.info_json_path.path
|
||||
if self.video_path:
|
||||
yield self.video_path.path
|
||||
|
||||
def delete(self):
|
||||
"""
|
||||
Remove all files related to this video. Add it to it's Channel's skip list.
|
||||
|
||||
Raises: UnknownFile if the video has no files.
|
||||
"""
|
||||
from modules.videos.common import get_absolute_video_files
|
||||
video_files = get_absolute_video_files(self)
|
||||
for path in video_files:
|
||||
try:
|
||||
path.path.unlink()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
for path in self.my_paths():
|
||||
path.unlink(missing_ok=True)
|
||||
|
||||
self._clear_paths()
|
||||
|
||||
if not video_files:
|
||||
raise UnknownFile('No video files were deleted')
|
||||
|
||||
needs_save = bool(self.favorite)
|
||||
|
||||
self.add_to_skip_list()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue