Skip to content

Commit

Permalink
Merge pull request #66 from dreulavelle/GH-65
Browse files Browse the repository at this point in the history
Move mount settings to general settings, fix section updating
  • Loading branch information
Gaisberg authored Dec 18, 2023
2 parents c2abeff + 0ce381b commit 555d9b5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 37 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,14 @@ pip install -r requirements.txt
python backend/main.py
```

## Symlinking settings
"host_mount" should point to your rclone mount that has your torrents on your host, if you are using native webdav set webdav-url to "https://dav.real-debrid.com/torrents"

"container_mount" should point to the location of the mount in plex container

### Example:
Rclone is mounted to /iceberg/vfs on your host machine -> settings should have: "host_mount": "/iceberg/vfs"

Plex container volume configuration for rclone mount is "/iceberg/vfs:/media/vfs" -> settings should have: "container_mount": "/media/vfs"

Plex libraries you want to add to sections: movies -> /media/library/movies, shows -> /media/library/shows
2 changes: 0 additions & 2 deletions backend/program/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ class TorrentioConfig(BaseModel):
class Settings(BaseModel):
version: str
debug: bool
service_mode: bool
log: bool
menu_on_startup: bool
plex: PlexConfig
mdblist: MdblistConfig
overseerr: OverseerrConfig
Expand Down
33 changes: 7 additions & 26 deletions backend/program/libraries/plex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Plex library module"""
import os
import threading
import time
from typing import List, Optional
Expand Down Expand Up @@ -36,6 +37,7 @@ def __init__(self, media_items: MediaItemContainer):
while True:
try:
temp_settings = settings.get("plex")
self.library_path = os.path.abspath(os.path.join(settings.get("container_mount"), os.pardir, "library"))
self.plex = PlexServer(
temp_settings["url"], temp_settings["token"], timeout=15
)
Expand Down Expand Up @@ -69,7 +71,7 @@ def _update_items(self):
processed_sections = set()

for section in sections:
if section.key in processed_sections:
if section.key in processed_sections and not self._is_wanted_section(section):
continue

try:
Expand All @@ -95,6 +97,8 @@ def _update_items(self):
def _update_sections(self):
"""Update plex library section"""
for section in self.plex.library.sections():
if not self._is_wanted_section(section):
continue
movie_items = [
item
for item in self.media_items
Expand Down Expand Up @@ -189,31 +193,8 @@ def _update_item(self, item: MediaItem, library_item: MediaItem):
item.set("guid", library_item.guid)
item.set("key", library_item.key)

def _fix_match(self, library_item: MediaItem, item: MediaItem):
"""Internal method to use in match_items method.
It gets plex guid and checks if it matches with plex metadata
for given imdb_id. If it does, it will update the metadata of the plex item."""
section = next(
section
for section in self.plex.library.sections()
if section.type == item.type
)
dummy = section.search(maxresults=1)[0]

if dummy and not section.refreshing:
if item.imdb_id:
try:
match = dummy.matches(agent=section.agent, title=item.imdb_id)[0]
except ReadTimeout:
return False
except IndexError:
return False
if library_item.guid != match.guid:
item_to_update = self.plex.fetchItem(library_item.key)
item_to_update.fixMatch(match)
return True
return False

def _is_wanted_section(self, section):
return any(self.library_path in location for location in section.locations)

def _map_item_from_data(item, item_type):
"""Map Plex API data to MediaItemContainer."""
Expand Down
5 changes: 2 additions & 3 deletions backend/program/symlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ def __init__(self, media_items: MediaItemContainer):
self.running = False
self.media_items = media_items
self.cache = {}
self.settings = settings.get("symlink")
self.mount_path = os.path.abspath(self.settings["mount"])
self.host_path = os.path.abspath(self.settings["host_mount"])
self.mount_path = os.path.abspath(settings.get("container_mount"))
self.host_path = os.path.abspath(settings.get("host_mount"))
if os.path.exists(self.host_path):
self.symlink_path = os.path.join(self.host_path, os.pardir, "library")
if not os.path.exists(self.symlink_path):
Expand Down
8 changes: 2 additions & 6 deletions backend/utils/default_settings.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
{
"version": "0.2.1",
"debug": true,
"service_mode": false,
"log": true,
"menu_on_startup": true,
"host_mount": "",
"container_mount": "",
"plex": {
"user": "",
"token": "",
"url": "http://localhost:32400",
"watchlist": ""
},
"symlink": {
"host_mount": "",
"mount": ""
},
"mdblist": {
"lists": [""],
"api_key": "",
Expand Down

0 comments on commit 555d9b5

Please sign in to comment.