Skip to content

Commit

Permalink
Merge pull request #289 from lardbit/manual-unprocessed-path
Browse files Browse the repository at this point in the history
Manually downloaded torrents should be sent to the "unprocessed" dir
  • Loading branch information
lardbit committed Jun 18, 2024
2 parents b10232e + 212a7c7 commit 6e1d0fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/nefarious/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ def post(self, request):
)
watch_media.save()
download_dir = os.path.join(
transmission_session.download_dir, nefarious_settings.transmission_movie_download_dir.lstrip('/'))
transmission_session.download_dir,
settings.UNPROCESSED_PATH,
nefarious_settings.transmission_movie_download_dir.lstrip('/'),
)
result['watch_movie'] = WatchMovieSerializer(watch_media).data
else:
tmdb_request = tmdb.TV(tmdb_media['id'])
Expand Down Expand Up @@ -302,7 +305,10 @@ def post(self, request):
result['watch_tv_season_request'] = WatchTVSeasonRequestSerializer(watch_tv_season_request).data

download_dir = os.path.join(
transmission_session.download_dir, nefarious_settings.transmission_tv_download_dir.lstrip('/'))
transmission_session.download_dir,
settings.UNPROCESSED_PATH,
nefarious_settings.transmission_tv_download_dir.lstrip('/'),
)

torrent = transmission_client.add_torrent(
torrent_url,
Expand Down
10 changes: 10 additions & 0 deletions src/nefarious/video_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class VideoDetect:
read_interval: int

def __init__(self, video_path: str):
logger_background.debug(f'VideoDetect: Initializing video capture {video_path}')
# video capture
self.video_path = video_path
self.video_capture = cv2.VideoCapture(self.video_path)
Expand All @@ -46,28 +47,37 @@ def has_valid_video_in_path(cls, path: str):
else: # individual file
files_to_verify = [path]

logger_background.info(f'[VIDEO_DETECTION] files to verify: {", ".join(files_to_verify)}')

for file_path in files_to_verify:
file_extension_match = ParserBase.file_extension_regex.search(file_path)
# skip sample videos
if ParserBase.sample_file_regex.search(file_path):
logger_background.info(f'[VIDEO_DETECTION] skipping "sample" file for {file_path}')
continue
# skip files that don't have extensions
if not file_extension_match:
logger_background.info(f'[VIDEO_DETECTION] skipping non-file-extension-match for {file_path}')
continue
file_extension = file_extension_match.group()
# skip files that don't look like videos
if file_extension not in video_extensions():
logger_background.info(f'[VIDEO_DETECTION] skipping bad video_extension for {file_path}')
continue
detection = cls(file_path)
detection.process_similarity()
if not detection.is_too_similar():
return True
else:
logger_background.info(f'[VIDEO_DETECTION] too similar for {file_path}')
logger_background.warning(f'[VIDEO_DETECTION] no valid files found in {path}')
return False

def is_correct_length(self, expected_duration: float):
return abs(self.duration - expected_duration) / expected_duration < self.MAX_VIDEO_DURATION_DIFFERENCE_RATIO

def is_too_similar(self):
logger_background.info(f'[VIDEO_DETECTION] video_similarity_std {self.video_similarity_std=}, {self.MIN_VIDEO_SIMILARITY_STD=}, {self.video_path=}')
return self.video_similarity_std <= self.MIN_VIDEO_SIMILARITY_STD

def process_similarity(self):
Expand Down

0 comments on commit 6e1d0fb

Please sign in to comment.