Skip to content

Commit

Permalink
Revert: semaphore protection (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu authored Dec 17, 2023
1 parent a14f27d commit 8e80187
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
15 changes: 1 addition & 14 deletions MetaTube.bundle/Contents/Code/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-

import threading
from base64 import urlsafe_b64encode
from random import choice

Expand Down Expand Up @@ -64,10 +63,6 @@ class MetaTubeAgent(Agent.Movies):
'com.plexapp.agents.xbmcnfo']
contributes_to = ['com.plexapp.agents.none']

# Workaround:
# - using a semaphore to prevent DB corruption
agent_global_semaphore = threading.Semaphore(1)

@staticmethod
def get_rating_image(rating):
return 'rottentomatoes://image.rating.ripe' \
Expand Down Expand Up @@ -148,12 +143,8 @@ def translate_reviews(reviews, lang):
review.comment = translate_text(review.comment, lang=lang,
fallback=review.comment)

def search(self, results, media, lang, manual=False):
with self.agent_global_semaphore:
return self.search_media(results, media, lang, manual)

# noinspection PyMethodMayBeStatic
def search_media(self, results, media, lang, manual=False):
def search(self, results, media, lang, manual=False):

position = None
search_results = []
Expand Down Expand Up @@ -218,10 +209,6 @@ def search_media(self, results, media, lang, manual=False):
return results

def update(self, metadata, media, lang, force=False):
with self.agent_global_semaphore:
return self.update_media(metadata, media, lang, force)

def update_media(self, metadata, media, lang, force=False):

if force:
Log.Debug('Force metadata refreshing')
Expand Down
19 changes: 6 additions & 13 deletions MetaTubeHelper.bundle/Contents/Code/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-

import threading

from localmedia import find_local_subtitles

# plex debugging
Expand All @@ -25,17 +23,12 @@ class MetaTubeHelper(Agent.Movies):
contributes_to = ['com.plexapp.agents.metatube',
'com.plexapp.agents.none']

helper_global_semaphore = threading.Semaphore(1)

def search(self, results, media, lang):
with self.helper_global_semaphore:
results.Append(MetadataSearchResult(id='null', score=100))
results.Append(MetadataSearchResult(id='null', score=100))

def update(self, metadata, media, lang):
with self.helper_global_semaphore:

# Look for subtitles
if Prefs['find_local_subtitles']:
for item in media.items:
for part in item.parts:
find_local_subtitles(part)
# Look for subtitles
if Prefs['find_local_subtitles']:
for item in media.items:
for part in item.parts:
find_local_subtitles(part)

0 comments on commit 8e80187

Please sign in to comment.