Skip to content

Commit

Permalink
Merge pull request #113 from se1exin/feat_multithreading_getdupes
Browse files Browse the repository at this point in the history
feat: multithreading get_dupes
  • Loading branch information
peter-mcconnell authored Nov 6, 2023
2 parents f537968 + f37df22 commit 8f7963c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
gidea
.env
.idea
venv
backend/db.json
53 changes: 27 additions & 26 deletions backend/plexwrapper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import urllib.parse
from concurrent.futures import ThreadPoolExecutor, as_completed

import requests
from plexapi.media import Media, MediaPart, MediaPartStream
Expand Down Expand Up @@ -57,36 +58,36 @@ def get_server_info(self):
def get_dupe_content(self, page=1):
logger.debug("START")
dupes = []
for section in self._get_sections():
logger.debug("SECTION: %s", section.title)
if section.type == "movie":
logger.debug("Section type is MOVIE")
# Recursively search movies
offset = (page - 1) * self.page_size
limit = offset + self.page_size
logger.debug("Get results from offset %s to limit %s", offset, limit)
results = section.search(duplicate=True, libtype='movie', container_start=offset, limit=limit)
if len(results) == 0:
continue
else:
with ThreadPoolExecutor() as executor:
futures = []
for section in self._get_sections():
logger.debug("SECTION: %s", section.title)
if section.type == "movie":
logger.debug("Section type is MOVIE")
# Recursively search movies
offset = (page - 1) * self.page_size
limit = offset + self.page_size
logger.debug("Get results from offset %s to limit %s", offset, limit)
results = section.search(duplicate=True, libtype='movie', container_start=offset, limit=limit)
for movie in results:
if len(movie.media) > 1:
logger.debug("Found media: %s", movie.guid)
dupes.append(self.movie_to_dict(movie, section.title))
elif section.type == "show":
logger.debug("Section type is SHOW")
# Recursively search TV
offset = (page - 1) * self.page_size
limit = offset + self.page_size
logger.debug("Get results from offset %s to limit %s", offset, limit)
results = section.search(duplicate=True, libtype='episode', container_start=offset, limit=limit)
if len(results) == 0:
continue
else:
future = executor.submit(self.movie_to_dict, movie, section.title)
futures.append(future)
elif section.type == "show":
logger.debug("Section type is SHOW")
# Recursively search TV
offset = (page - 1) * self.page_size
limit = offset + self.page_size
logger.debug("Get results from offset %s to limit %s", offset, limit)
results = section.search(duplicate=True, libtype='episode', container_start=offset, limit=limit)
for episode in results:
if len(episode.media) > 1:
logger.debug("Found media: %s", episode.guid)
dupes.append(self.episode_to_dict(episode, section.title))
future = executor.submit(self.episode_to_dict, episode, section.title)
futures.append(future)

for future in as_completed(futures):
dupes.append(future.result())

return dupes

def get_content_sample_files(self):
Expand Down

0 comments on commit 8f7963c

Please sign in to comment.