ServerX commited on
Commit
2d7a990
·
verified ·
1 Parent(s): fa074f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -2
app.py CHANGED
@@ -1,6 +1,22 @@
1
  import gradio as gr
2
  import requests, zipfile, os, shutil, json
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  # FILE DI CONFIGURAZIONE
5
  SETTINGS_FILE = "settings.json"
6
  DEFAULT_SETTINGS = {
@@ -45,6 +61,8 @@ def update_settings(videolibrarypath, folder_tvshows, folder_movies, videolibrar
45
  }
46
  return save_settings(new_settings)
47
 
 
 
48
  def get_branches():
49
  """
50
  Recupera la lista dei branch disponibili dal repository GitHub.
@@ -68,7 +86,7 @@ def update_from_zip(branch: str) -> str:
68
  """
69
  Scarica il file zip del branch selezionato da GitHub,
70
  lo estrae in una cartella target ("s4me_app") e restituisce un log delle operazioni.
71
- Questa funzione non utilizza alcuna dipendenza da Kodi.
72
  """
73
  log = []
74
  try:
@@ -117,6 +135,35 @@ def perform_update(selected_branch: str) -> str:
117
  """Funzione chiamata dal pulsante di aggiornamento nell’interfaccia."""
118
  return update_from_zip(selected_branch)
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  def build_interface():
121
  """Costruisce l’interfaccia completa utilizzando Gradio."""
122
  branches = get_branches()
@@ -150,7 +197,7 @@ def build_interface():
150
  """
151
 
152
  with gr.Blocks(css=css_custom, title="Stream4Me Update per Smart TV") as demo:
153
- gr.Markdown("# Stream4Me - Aggiornamento e Configurazione")
154
  gr.HTML(js_script) # Iniezione dello script JS per la navigazione con telecomando
155
  with gr.Tabs():
156
  with gr.TabItem("Aggiornamento"):
@@ -177,6 +224,13 @@ def build_interface():
177
  refresh_button = gr.Button("Ricarica Impostazioni")
178
  refresh_button.click(fn=get_current_settings, inputs=[], outputs=current_settings_box)
179
 
 
 
 
 
 
 
 
180
  with gr.TabItem("Informazioni"):
181
  gr.Markdown("## Informazioni sul Progetto")
182
  gr.Markdown("""
@@ -186,6 +240,7 @@ def build_interface():
186
  **Funzionalità:**
187
  - Aggiornamento automatico dal repository GitHub.
188
  - Configurazione personalizzata tramite interfaccia web.
 
189
  - Interfaccia responsive, con navigazione tramite telecomando.
190
 
191
  **Repository:** [Stream4Me su GitHub](https://github.com/Stream4me/addon)
 
1
  import gradio as gr
2
  import requests, zipfile, os, shutil, json
3
 
4
+ # -----------------------
5
+ # Free API keys (TMDb e OMDb) ottenute automaticamente
6
+ def get_free_keys():
7
+ """
8
+ Simula il comportamento del pacchetto 'freekeys'
9
+ Restituisce le free API keys per TMDb e OMDb.
10
+ """
11
+ return {
12
+ "tmdb_key": "e547e17d4e91f3e62a571655cd1ccaff",
13
+ "imdb_key": "966c4f4f"
14
+ }
15
+
16
+ free_keys = get_free_keys()
17
+ TMDB_API_KEY = free_keys["tmdb_key"]
18
+
19
+ # -----------------------
20
  # FILE DI CONFIGURAZIONE
21
  SETTINGS_FILE = "settings.json"
22
  DEFAULT_SETTINGS = {
 
61
  }
62
  return save_settings(new_settings)
63
 
64
+ # -----------------------
65
+ # FUNZIONALITÀ DI AGGIORNAMENTO DELL'APPLICAZIONE
66
  def get_branches():
67
  """
68
  Recupera la lista dei branch disponibili dal repository GitHub.
 
86
  """
87
  Scarica il file zip del branch selezionato da GitHub,
88
  lo estrae in una cartella target ("s4me_app") e restituisce un log delle operazioni.
89
+ Questa funzione è completamente stand-alone e non utilizza dipendenze da Kodi.
90
  """
91
  log = []
92
  try:
 
135
  """Funzione chiamata dal pulsante di aggiornamento nell’interfaccia."""
136
  return update_from_zip(selected_branch)
137
 
138
+ # -----------------------
139
+ # FUNZIONALITÀ DI RICERCA FILM
140
+ def search_movie(movie_title: str) -> str:
141
+ """
142
+ Cerca il film utilizzando l'API di TMDb e restituisce una lista formattata dei risultati.
143
+ Utilizza automaticamente la free API key ottenuta.
144
+ """
145
+ if not movie_title:
146
+ return "Inserisci il nome del film da cercare."
147
+ url = f"https://api.themoviedb.org/3/search/movie?api_key={TMDB_API_KEY}&query={movie_title}"
148
+ try:
149
+ response = requests.get(url)
150
+ response.raise_for_status()
151
+ data = response.json()
152
+ results = data.get("results", [])
153
+ if not results:
154
+ return "Nessun risultato trovato."
155
+ output = []
156
+ for movie in results:
157
+ title = movie.get("title", "Sconosciuto")
158
+ release_date = movie.get("release_date", "Data sconosciuta")
159
+ overview = movie.get("overview", "")
160
+ output.append(f"{title} ({release_date})\n{overview}\n")
161
+ return "\n".join(output)
162
+ except Exception as e:
163
+ return f"Errore durante la ricerca: {str(e)}"
164
+
165
+ # -----------------------
166
+ # COSTRUZIONE DELL'INTERFACCIA CON GRADIO
167
  def build_interface():
168
  """Costruisce l’interfaccia completa utilizzando Gradio."""
169
  branches = get_branches()
 
197
  """
198
 
199
  with gr.Blocks(css=css_custom, title="Stream4Me Update per Smart TV") as demo:
200
+ gr.Markdown("# Stream4Me - Aggiornamento, Configurazione e Ricerca Film")
201
  gr.HTML(js_script) # Iniezione dello script JS per la navigazione con telecomando
202
  with gr.Tabs():
203
  with gr.TabItem("Aggiornamento"):
 
224
  refresh_button = gr.Button("Ricarica Impostazioni")
225
  refresh_button.click(fn=get_current_settings, inputs=[], outputs=current_settings_box)
226
 
227
+ with gr.TabItem("Ricerca Film"):
228
+ gr.Markdown("## Cerca un Film")
229
+ film_input = gr.Textbox(placeholder="Inserisci il nome del film...", label="Nome del Film")
230
+ search_button = gr.Button("Cerca")
231
+ search_results = gr.Textbox(label="Risultati", lines=10)
232
+ search_button.click(fn=search_movie, inputs=film_input, outputs=search_results)
233
+
234
  with gr.TabItem("Informazioni"):
235
  gr.Markdown("## Informazioni sul Progetto")
236
  gr.Markdown("""
 
240
  **Funzionalità:**
241
  - Aggiornamento automatico dal repository GitHub.
242
  - Configurazione personalizzata tramite interfaccia web.
243
+ - Ricerca di film tramite l'API di TMDb con free API key automatica.
244
  - Interfaccia responsive, con navigazione tramite telecomando.
245
 
246
  **Repository:** [Stream4Me su GitHub](https://github.com/Stream4me/addon)