Skip to content

Commit

Permalink
Added feature to change "added" info in Plex once subtitles are downl…
Browse files Browse the repository at this point in the history
…oaded
  • Loading branch information
destpstrzy authored Jan 23, 2025
1 parent 2fc8f10 commit fe7b224
Show file tree
Hide file tree
Showing 40 changed files with 16,963 additions and 1 deletion.
8 changes: 8 additions & 0 deletions bazarr/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ def check_parser_binary(value):
Validator('radarr.defer_search_signalr', must_exist=True, default=False, is_type_of=bool),
Validator('radarr.sync_only_monitored_movies', must_exist=True, default=False, is_type_of=bool),

# plex section
Validator('plex.ip', must_exist=True, default='127.0.0.1', is_type_of=str),
Validator('plex.port', must_exist=True, default=32400, is_type_of=int, gte=1, lte=65535),
Validator('plex.ssl', must_exist=True, default=False, is_type_of=bool),
Validator('plex.apikey', must_exist=True, default='', is_type_of=str),
Validator('plex.movie_library', must_exist=True, default='', is_type_of=str),
Validator('plex.set_added', must_exist=True, default=False, is_type_of=bool),

# proxy section
Validator('proxy.type', must_exist=True, default=None, is_type_of=(NoneType, str),
is_in=[None, 'socks5', 'http']),
Expand Down
1 change: 1 addition & 0 deletions bazarr/plex/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# coding=utf-8
27 changes: 27 additions & 0 deletions bazarr/plex/operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# coding=utf-8
from datetime import datetime
from app.config import settings
from plexapi.server import PlexServer
import logging

logger = logging.getLogger(__name__)


def plex_set_added_date_now(movie_metadata):
try:
if settings.plex.ssl:
protocol_plex = "https://"
else:
protocol_plex = "http://"

baseurl = f'{protocol_plex}{settings.plex.ip}:{settings.plex.port}'
token = settings.plex.apikey
plex = PlexServer(baseurl, token)
library = plex.library.section(settings.plex.movie_library)
video = library.getGuid(guid=movie_metadata.imdbId)
# Get the current date and time in the desired format
current_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
updates = {"addedAt.value": current_date}
video.edit(**updates)
except Exception as e:
logger.error(f"A Plex error occurred: {e}")
5 changes: 4 additions & 1 deletion bazarr/subtitles/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from utilities.analytics import event_tracker
from radarr.notify import notify_radarr
from sonarr.notify import notify_sonarr
from plex.operations import plex_set_added_date_now
from app.event_handler import event_stream

from .utils import _get_download_code3
Expand Down Expand Up @@ -95,7 +96,7 @@ def process_subtitle(subtitle, media_type, audio_language, path, max_score, is_u
sonarr_episode_id=episode_metadata.sonarrEpisodeId)
else:
movie_metadata = database.execute(
select(TableMovies.radarrId)
select(TableMovies.radarrId, TableMovies.imdbId)
.where(TableMovies.path == path_mappings.path_replace_reverse_movie(path)))\
.first()
if not movie_metadata:
Expand Down Expand Up @@ -145,6 +146,8 @@ def process_subtitle(subtitle, media_type, audio_language, path, max_score, is_u
reversed_subtitles_path = path_mappings.path_replace_reverse_movie(downloaded_path)
notify_radarr(movie_metadata.radarrId)
event_stream(type='movie-wanted', action='delete', payload=movie_metadata.radarrId)
if settings.plex.set_added is True:
plex_set_added_date_now(movie_metadata)

event_tracker.track_subtitles(provider=downloaded_provider, action=action, language=downloaded_language)

Expand Down
6 changes: 6 additions & 0 deletions frontend/src/Router/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import SeriesMassEditor from "@/pages/Series/Editor";
import SettingsGeneralView from "@/pages/Settings/General";
import SettingsLanguagesView from "@/pages/Settings/Languages";
import SettingsNotificationsView from "@/pages/Settings/Notifications";
import SettingsPlexView from "@/pages/Settings/Plex";
import SettingsProvidersView from "@/pages/Settings/Providers";
import SettingsRadarrView from "@/pages/Settings/Radarr";
import SettingsSchedulerView from "@/pages/Settings/Scheduler";
Expand Down Expand Up @@ -222,6 +223,11 @@ function useRoutes(): CustomRouteObject[] {
name: "Radarr",
element: <SettingsRadarrView></SettingsRadarrView>,
},
{
path: "plex",
name: "Plex",
element: <SettingsPlexView></SettingsPlexView>,
},
{
path: "notifications",
name: "Notifications",
Expand Down
46 changes: 46 additions & 0 deletions frontend/src/pages/Settings/Plex/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { FunctionComponent } from "react";
import {
Check,
CollapseBox,
Layout,
Message,
Number,
Section,
Text,
} from "@/pages/Settings/components";
import { plexEnabledKey } from "@/pages/Settings/keys";

const SettingsPlexView: FunctionComponent = () => {
return (
<Layout name="Interface">
<Section header="Use Plex integration">
<Check label="Enabled" settingKey={plexEnabledKey}></Check>
</Section>
<CollapseBox settingKey={plexEnabledKey}>
<Section header="Host">
<Text label="Address" settingKey="settings-plex-ip"></Text>
<Number
label="Port"
settingKey="settings-plex-port"
defaultValue={32400}
></Number>
<Message>Hostname or IPv4 Address</Message>
<Text label="API Token" settingKey="settings-plex-apikey"></Text>
<Check label="SSL" settingKey="settings-plex-ssl"></Check>
</Section>
<Section header="Movie editing">
<Text
label="Name of the library"
settingKey="settings-plex-movie_library"
></Text>
<Check
label="Set the movie as recently added after downloading the subtitles"
settingKey="settings-plex-set_added"
></Check>
</Section>
</CollapseBox>
</Layout>
);
};

export default SettingsPlexView;
1 change: 1 addition & 0 deletions frontend/src/pages/Settings/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export const pathMappingsMovieKey = "settings-general-path_mappings_movie";

export const seriesEnabledKey = "settings-general-use_sonarr";
export const moviesEnabledKey = "settings-general-use_radarr";
export const plexEnabledKey = "settings-general-use_plex";
9 changes: 9 additions & 0 deletions frontend/src/types/settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ declare namespace Settings {
excluded_tags: string[];
}

interface Plex {
ip: string;
port: number;
apikey?: string;
ssl?: boolean;
set_added?: boolean;
movie_library?: string;
}

interface Anticaptcha {
anti_captcha_key?: string;
}
Expand Down
7 changes: 7 additions & 0 deletions libs/PlexAPI-4.16.1.dist-info/AUTHORS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Authors and Contributors:
* Michael Shepanski (Primary Author)
* Hellowlol (Major Contributor)
* Nate Mara (Timeline)
* Goni Zahavy (Sync, Media Parts)
* Simon W. Jackson (Stream URL)
* Håvard Gulldahl (Plex Audio)
1 change: 1 addition & 0 deletions libs/PlexAPI-4.16.1.dist-info/INSTALLER
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip
25 changes: 25 additions & 0 deletions libs/PlexAPI-4.16.1.dist-info/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) 2010, Michael Shepanski
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name python-plexapi nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit fe7b224

Please sign in to comment.