mirror of
https://github.com/SinTan1729/TvTimeToTrakt.git
synced 2025-04-19 09:30:01 -05:00
Cleanup
This commit is contained in:
parent
85cb57d3af
commit
0945a489c5
1 changed files with 20 additions and 20 deletions
|
@ -110,7 +110,7 @@ def getYearFromTitle(title):
|
||||||
return ex
|
return ex
|
||||||
|
|
||||||
|
|
||||||
# Shows in TV Time are often different to Trakt.TV - in order to improve results and automation,
|
# Movies in TV Time are often different to Trakt.TV - in order to improve results and automation,
|
||||||
# calculate how many words are in the title, and return true if more than 50% of the title is a match,
|
# calculate how many words are in the title, and return true if more than 50% of the title is a match,
|
||||||
# It seems to improve automation, and reduce manual selection....
|
# It seems to improve automation, and reduce manual selection....
|
||||||
|
|
||||||
|
@ -140,12 +140,12 @@ def checkTitleNameMatch(tvTimeTitle, traktTitle):
|
||||||
return percentage > 50
|
return percentage > 50
|
||||||
|
|
||||||
|
|
||||||
# Using TV Time data (Name of Show, Season No and Episode) - find the corresponding show
|
# Using TV Time data (Name of Movie) - find the corresponding movie
|
||||||
# in Trakt.TV either by automation, or asking the user to confirm.
|
# in Trakt.TV either by automation, or asking the user to confirm.
|
||||||
|
|
||||||
|
|
||||||
def getMovieByName(name):
|
def getMovieByName(name):
|
||||||
# Parse the TV Show's name for year, if one is present in the string
|
# Parse the Movie's name for year, if one is present in the string
|
||||||
titleObj = getYearFromTitle(name)
|
titleObj = getYearFromTitle(name)
|
||||||
|
|
||||||
# Create a boolean to indicate if the title contains a year,
|
# Create a boolean to indicate if the title contains a year,
|
||||||
|
@ -160,7 +160,7 @@ def getMovieByName(name):
|
||||||
# Request the Trakt API for search results, using the name
|
# Request the Trakt API for search results, using the name
|
||||||
movieSearch = Movie.search(name)
|
movieSearch = Movie.search(name)
|
||||||
|
|
||||||
# Create an array of shows which have been matched
|
# Create an array of movies which have been matched
|
||||||
moviesWithSameName = []
|
moviesWithSameName = []
|
||||||
|
|
||||||
# Go through each result from the search
|
# Go through each result from the search
|
||||||
|
@ -168,16 +168,16 @@ def getMovieByName(name):
|
||||||
# Check if the title is a match, based on our conditions (e.g over 50% of words match)
|
# Check if the title is a match, based on our conditions (e.g over 50% of words match)
|
||||||
if checkTitleNameMatch(name, movie.title):
|
if checkTitleNameMatch(name, movie.title):
|
||||||
# If the title included the year of broadcast, then we can be more picky in the results
|
# If the title included the year of broadcast, then we can be more picky in the results
|
||||||
# to look for a show with a broadcast year that matches
|
# to look for a movie with a broadcast year that matches
|
||||||
if doesTitleIncludeYear:
|
if doesTitleIncludeYear:
|
||||||
# If the show title is a 1:1 match, with the same broadcast year, then bingo!
|
# If the movie title is a 1:1 match, with the same broadcast year, then bingo!
|
||||||
if (name == movie.title) and (movie.year == titleObj.yearValue):
|
if (name == movie.title) and (movie.year == titleObj.yearValue):
|
||||||
# Clear previous results, and only use this one
|
# Clear previous results, and only use this one
|
||||||
moviesWithSameName = []
|
moviesWithSameName = []
|
||||||
moviesWithSameName.append(movie)
|
moviesWithSameName.append(movie)
|
||||||
break
|
break
|
||||||
|
|
||||||
# Otherwise, only add the show if the broadcast year matches
|
# Otherwise, only add the movie if the broadcast year matches
|
||||||
if movie.year == titleObj.yearValue:
|
if movie.year == titleObj.yearValue:
|
||||||
moviesWithSameName.append(movie)
|
moviesWithSameName.append(movie)
|
||||||
# If the program doesn't have the broadcast year, then add all the results
|
# If the program doesn't have the broadcast year, then add all the results
|
||||||
|
@ -195,7 +195,7 @@ def getMovieByName(name):
|
||||||
if len(completeMatchNames) == 1:
|
if len(completeMatchNames) == 1:
|
||||||
moviesWithSameName = completeMatchNames
|
moviesWithSameName = completeMatchNames
|
||||||
|
|
||||||
# If the search contains multiple results, then we need to confirm with the user which show
|
# If the search contains multiple results, then we need to confirm with the user which movie
|
||||||
# the script should use, or access the local database to see if the user has already provided
|
# the script should use, or access the local database to see if the user has already provided
|
||||||
# a manual selection
|
# a manual selection
|
||||||
if len(moviesWithSameName) > 1:
|
if len(moviesWithSameName) > 1:
|
||||||
|
@ -212,14 +212,14 @@ def getMovieByName(name):
|
||||||
firstMatch = queryResult[0]
|
firstMatch = queryResult[0]
|
||||||
# Get the value contains the selection index
|
# Get the value contains the selection index
|
||||||
firstMatchSelectedIndex = int(firstMatch.get("UserSelectedIndex"))
|
firstMatchSelectedIndex = int(firstMatch.get("UserSelectedIndex"))
|
||||||
# Check if the user previously requested to skip the show
|
# Check if the user previously requested to skip the movie
|
||||||
skipMovie = firstMatch.get("SkipMovie")
|
skipMovie = firstMatch.get("SkipMovie")
|
||||||
# If the user did not skip, but provided an index selection, get the
|
# If the user did not skip, but provided an index selection, get the
|
||||||
# matching show
|
# matching movie
|
||||||
if not skipMovie:
|
if not skipMovie:
|
||||||
return moviesWithSameName[firstMatchSelectedIndex]
|
return moviesWithSameName[firstMatchSelectedIndex]
|
||||||
# Otherwise, return None, which will trigger the script to skip
|
# Otherwise, return None, which will trigger the script to skip
|
||||||
# and move onto the next show
|
# and move onto the next movie
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
# If the user has not provided a manual selection already in the process
|
# If the user has not provided a manual selection already in the process
|
||||||
|
@ -229,9 +229,9 @@ def getMovieByName(name):
|
||||||
f"INFO - MANUAL INPUT REQUIRED: The TV Time data for Movie '{name}' has {len(moviesWithSameName)} matching Trakt movies with the same name."
|
f"INFO - MANUAL INPUT REQUIRED: The TV Time data for Movie '{name}' has {len(moviesWithSameName)} matching Trakt movies with the same name."
|
||||||
)
|
)
|
||||||
|
|
||||||
# Output each show for manual selection
|
# Output each movie for manual selection
|
||||||
for idx, item in enumerate(moviesWithSameName):
|
for idx, item in enumerate(moviesWithSameName):
|
||||||
# Display the show's title, broadcast year, amount of seasons and a link to the Trakt page.
|
# Display the movie's title, broadcast year, amount of seasons and a link to the Trakt page.
|
||||||
# This will provide the user with enough information to make a selection.
|
# This will provide the user with enough information to make a selection.
|
||||||
print(
|
print(
|
||||||
f" ({idx + 1}) {item.title} - {item.year} - More Info: https://trakt.tv/{item.ext}"
|
f" ({idx + 1}) {item.title} - {item.year} - More Info: https://trakt.tv/{item.ext}"
|
||||||
|
@ -264,7 +264,7 @@ def getMovieByName(name):
|
||||||
# If the user entered 'SKIP', then exit from the loop with no selection, which
|
# If the user entered 'SKIP', then exit from the loop with no selection, which
|
||||||
# will trigger the program to move onto the next episode
|
# will trigger the program to move onto the next episode
|
||||||
if indexSelected == "SKIP":
|
if indexSelected == "SKIP":
|
||||||
# Record that the user has skipped the TV Show for import, so that
|
# Record that the user has skipped the Movie for import, so that
|
||||||
# manual input isn't required everytime
|
# manual input isn't required everytime
|
||||||
userMatchedMoviesTable.insert(
|
userMatchedMoviesTable.insert(
|
||||||
{"movie_name": name, "UserSelectedIndex": 0, "SkipMovie": True}
|
{"movie_name": name, "UserSelectedIndex": 0, "SkipMovie": True}
|
||||||
|
@ -279,7 +279,7 @@ def getMovieByName(name):
|
||||||
{
|
{
|
||||||
"movie_name": name,
|
"movie_name": name,
|
||||||
"UserSelectedIndex": indexSelected,
|
"UserSelectedIndex": indexSelected,
|
||||||
"SkipShow": False,
|
"SkipMovie": False,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ def getMovieByName(name):
|
||||||
else:
|
else:
|
||||||
if len(moviesWithSameName) > 0:
|
if len(moviesWithSameName) > 0:
|
||||||
# If the search returned only one result, then awesome!
|
# If the search returned only one result, then awesome!
|
||||||
# Return the show, so the import automation can continue.
|
# Return the movie, so the import automation can continue.
|
||||||
return moviesWithSameName[0]
|
return moviesWithSameName[0]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
@ -321,7 +321,7 @@ def processMovies():
|
||||||
for rowsCount, row in enumerate(movieReader):
|
for rowsCount, row in enumerate(movieReader):
|
||||||
# Get the name of the Movie
|
# Get the name of the Movie
|
||||||
movieName = row["movie_name"]
|
movieName = row["movie_name"]
|
||||||
# Get the date which the show was marked 'watched' in TV Time
|
# Get the date which the movie was marked 'watched' in TV Time
|
||||||
activityType = row["type"]
|
activityType = row["type"]
|
||||||
movieDateWatched = row["updated_at"]
|
movieDateWatched = row["updated_at"]
|
||||||
# Parse the watched date value into a Python type
|
# Parse the watched date value into a Python type
|
||||||
|
@ -364,7 +364,7 @@ def processMovies():
|
||||||
# This is required to remain within the API rate limit, and use the API server fairly.
|
# This is required to remain within the API rate limit, and use the API server fairly.
|
||||||
# Other developers share the service, for free - so be considerate of your usage.
|
# Other developers share the service, for free - so be considerate of your usage.
|
||||||
time.sleep(DELAY_BETWEEN_EPISODES_IN_SECONDS)
|
time.sleep(DELAY_BETWEEN_EPISODES_IN_SECONDS)
|
||||||
# Search Trakt for the TV show matching TV Time's title value
|
# Search Trakt for the Movie matching TV Time's title value
|
||||||
traktMovieObj = getMovieByName(movieName)
|
traktMovieObj = getMovieByName(movieName)
|
||||||
# If the method returned 'None', then this is an indication to skip the episode, and
|
# If the method returned 'None', then this is an indication to skip the episode, and
|
||||||
# move onto the next one
|
# move onto the next one
|
||||||
|
@ -395,7 +395,7 @@ def processMovies():
|
||||||
errorStreak = 0
|
errorStreak = 0
|
||||||
break
|
break
|
||||||
# Catch errors which occur because of an incorrect array index. This occurs when
|
# Catch errors which occur because of an incorrect array index. This occurs when
|
||||||
# an incorrect Trakt show has been selected, with season/episodes which don't match TV Time.
|
# an incorrect Trakt movie has been selected, with season/episodes which don't match TV Time.
|
||||||
# It can also occur due to a bug in Trakt Py, whereby some seasons contain an empty array of episodes.
|
# It can also occur due to a bug in Trakt Py, whereby some seasons contain an empty array of episodes.
|
||||||
except IndexError:
|
except IndexError:
|
||||||
movieSlug = traktMovieObj.to_json()["movies"][0]["ids"]["ids"][
|
movieSlug = traktMovieObj.to_json()["movies"][0]["ids"]["ids"][
|
||||||
|
@ -405,7 +405,7 @@ def processMovies():
|
||||||
f"({rowsCount}/{rowsTotal}) - {movieName} does not exist in Trakt! (https://trakt.tv/movies/{movieSlug}/)"
|
f"({rowsCount}/{rowsTotal}) - {movieName} does not exist in Trakt! (https://trakt.tv/movies/{movieSlug}/)"
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
# Catch any errors which are raised because a show could not be found in Trakt
|
# Catch any errors which are raised because a movie could not be found in Trakt
|
||||||
except trakt.errors.NotFoundException:
|
except trakt.errors.NotFoundException:
|
||||||
logging.warning(
|
logging.warning(
|
||||||
f"({rowsCount}/{rowsTotal}) - {movieName} does not exist (search) in Trakt!"
|
f"({rowsCount}/{rowsTotal}) - {movieName} does not exist (search) in Trakt!"
|
||||||
|
|
Loading…
Reference in a new issue