Skip to content

Commit

Permalink
Improve: add parse_filename_without_ext
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu committed Dec 15, 2023
1 parent 2b598b0 commit a8831ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
21 changes: 6 additions & 15 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
# -*- coding: utf-8 -*-

import threading
from base64 import urlsafe_b64encode
from random import choice

import utils
from api_client import api
from constants import *
from provider_id import ProviderID
from translator import translate_text

try: # Python 2
from urllib import unquote
except ImportError: # Python 3
from urllib.parse import unquote
finally:
import threading
from base64 import urlsafe_b64encode
from os.path import basename
from random import choice

# plex debugging
try:
import plexhints # noqa: F401
Expand Down Expand Up @@ -74,10 +68,6 @@ class MetaTubeAgent(Agent.Movies):
# - using a semaphore to prevent DB corruption
agent_global_semaphore = threading.Semaphore(1)

@staticmethod
def parse_filename(filename):
return basename(unquote(filename))

@staticmethod
def get_rating_image(rating):
return 'rottentomatoes://image.rating.ripe' \
Expand Down Expand Up @@ -162,6 +152,7 @@ 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):

position = None
Expand All @@ -171,7 +162,7 @@ def search_media(self, results, media, lang, manual=False):
if (not manual or media.openSubtitlesHash) \
and media.filename:
search_results = api.search_movie(
q=self.parse_filename(media.filename))
q=utils.parse_filename_without_ext(media.filename))
else:
try: # exact match by provider and id
if not media.year or \
Expand Down
13 changes: 13 additions & 0 deletions Contents/Code/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

from constants import *

try: # Python 2
from urllib import unquote
except ImportError: # Python 3
from urllib.parse import unquote


def average(a):
x = 0.0
Expand All @@ -16,6 +21,14 @@ def average(a):
return x / len(a)


def parse_filename(filename):
return os.path.basename(unquote(filename))


def parse_filename_without_ext(filename):
return os.path.splitext(parse_filename(filename))[0]


def parse_date(s):
# noinspection PyBroadException
try:
Expand Down

0 comments on commit a8831ea

Please sign in to comment.