Skip to content

Commit

Permalink
getting stuck on the request movie...
Browse files Browse the repository at this point in the history
I think im making this more complicated that needs to be.
  • Loading branch information
mtrogman committed Oct 18, 2023
1 parent 23b7e69 commit 97a944d
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions regrabarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def getConfig(file):
return config


config_location = "/config/config.yml"
config_location = "config.yml"
config = getConfig(config_location)
bot_token = config['bot']['token']
radarr_api_key = config['radarr']['api_key']
Expand Down Expand Up @@ -48,9 +48,13 @@ def perform_request(method, url, data=None, headers=None):


class ConfirmButtonsMovie(View):
def __init__(self, interaction, movie_data):
def __init__(self, interaction, media_info):
super().__init__()
regrab_button = Button(style=discord.ButtonStyle.primary, label="Regrab")
if media_info.get('delete') == 'yes':
re_button = "Regrab"
else:
re_button = "Request"
regrab_button = Button(style=discord.ButtonStyle.primary, label={re_button})
regrab_button.callback = self.regrab_callback
self.add_item(regrab_button)

Expand All @@ -59,27 +63,24 @@ def __init__(self, interaction, movie_data):
self.add_item(cancel_button)

self.interaction = interaction
self.movie_data = movie_data
self.media_info = media_info

async def regrab_callback(self, button):
# Use self.movie_data to access movie details
movie_title = self.movie_data['title']
movie_year = self.movie_data['year']
movie_id = self.movie_data['id']
movie_tmdb = self.movie_data['tmdbId']
movie_title = self.media_info['title']
movie_year = self.media_info['year']
movie_id = self.media_info['id']
movie_tmdb = self.media_info['tmdbId']

if media_info['delete'] == "yes":

if media_info.get('delete') == 'yes':
await self.interaction.delete_original_response()

# Delete the movie
delete_url = f"{radarr_base_url}/movie/{movie_id}?deleteFiles=true&apikey={radarr_api_key}"
delete_response = perform_request('DELETE', delete_url)
logging.info(f"Deleted {movie_title} with a response of {delete_response}")
else:
# Check if movie exists?
# Check if movie is already downloaded

# Add the movie back (and search for it)
# Add the movie (and search for it)
add_url = f"{radarr_base_url}/movie?apikey={radarr_api_key}"
data = {
"tmdbId": movie_tmdb,
Expand Down Expand Up @@ -149,12 +150,12 @@ async def regrab_callback(self, button):
try:
search_response = requests.post(search_url, headers=headers, json=data)
search_response.raise_for_status() # Raise an exception for non-200 responses
logging.info(f"Searching for EpisodeID {media_info['episodeId']} with a response of {search_response.status_code}")
logging.info(f"Searching for EpisodeID {media_info['episodeNumber']} with a response of {search_response.status_code}")
except requests.exceptions.RequestException as e:
logging.error(f"Error searching for EpisodeID {media_info['episodeId']}: {e}")

await self.interaction.delete_original_response()
await self.interaction.followup.send(content=f"`{self.interaction.user.name} your request to (re)grab {media_info['series']}` Season {media_info['season']}) Episode {media_info['episode']} is being processed.")
await self.interaction.followup.send(content=f"`{self.interaction.user.name} your request to (re)grab {media_info['series']}` Season {media_info['seasonNumber']}) Episode {media_info['episodeNumber']} is being processed.")

# Cancel just responds with msg
async def cancel_callback(self, button):
Expand Down Expand Up @@ -184,14 +185,14 @@ def __init__(self, search_results, media_info):
super().__init__(placeholder="Please select a movie", options=options, min_values=1, max_values=1)

async def callback(self, interaction: discord.Interaction):
selected_movie_index = int(self.values[0])
selected_movie_index = int(list(self.values)[0])
selected_movie_data = self.search_results[selected_movie_index]
media_info['movieId'] = selected_movie_data.get('id', 'N/A')
media_info['title'] = selected_movie_data['title']
media_info['year'] = selected_movie_data['year']
media_info['overview'] = selected_movie_data['overview']

self.media_info['title'] = selected_movie_data['title']
self.media_info['year'] = selected_movie_data['year']
self.media_info['overview'] = selected_movie_data['overview']

if media_info['delete'] == "yes":
if media_info['delete']:
confirm_word = "regrab"
else:
confirm_word = "request"
Expand Down Expand Up @@ -360,7 +361,7 @@ def __init__(self, episodes_results, media_info):
super().__init__(placeholder="Please select an episode", options=options, min_values=1, max_values=1)

async def callback(self, interaction: discord.Interaction):
self.media_info['episodeNumber'] = int(self.values[0])
self.media_info['episodeArrayNumber'] = int(self.values[0])
await fetch_episode_details(self.episode_results, self.media_info)

# Construct the confirmation message with episode details
Expand Down Expand Up @@ -403,11 +404,12 @@ async def fetch_episodes(media_info):

# Call to get details of the episode selected to populate the confirmation button info
async def fetch_episode_details(episode_results, media_info):
episode_details = episode_results[media_info['episodeNumber']]
media_info['title'] = episode_details['title'],
media_info['overview'] = episode_details['overview'],
media_info['episodeFileId'] = episode_details['episodeFileId'],
media_info['id'] = episode_details['id'],
episode_details = episode_results[media_info['episodeArrayNumber']]
media_info['title'] = episode_details['title']
media_info['episodeNumber'] = episode_details['episodeNumber']
media_info['overview'] = episode_details['overview']
media_info['episodeFileId'] = episode_details['episodeFileId']
media_info['episodeId'] = episode_details['id']
media_info['airDate'] = episode_details['airDate']


Expand Down Expand Up @@ -435,7 +437,7 @@ async def regrab_movie(ctx, *, movie: str):
f"{ctx.user.name} no movie matching the following title was found: {movie}")
return
media_info['what'] = 'movie'
media_info['delete'] = 'yes'
media_info['delete'] = False
await ctx.response.send_message("Select a movie to regrab", view=MovieSelectorView(movie_results, media_info), ephemeral=True)


Expand All @@ -449,7 +451,7 @@ async def regrab_movie(ctx, *, movie: str):
f"{ctx.user.name} no movie matching the following title was found: {movie}")
return
media_info['what'] = 'movie'
media_info['delete'] = 'no'
media_info['delete'] = False
await ctx.response.send_message("Select a movie to request", view=MovieSelectorView(movie_results, media_info), ephemeral=True)


Expand All @@ -463,7 +465,7 @@ async def regrab_episode(ctx, *, series: str):
await ctx.response.send_message(f"No TV series matching the title: {series}")
return
media_info['what'] = 'series'
media_info['delete'] = 'yes'
media_info['delete'] = True
await ctx.response.send_message("Select a TV series to regrab", view=SeriesSelectorView(series_results, media_info), ephemeral=True)


Expand Down

0 comments on commit 97a944d

Please sign in to comment.