slimshadow commited on
Commit
4f19de8
·
verified ·
1 Parent(s): 1181585

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -20
app.py CHANGED
@@ -40,6 +40,10 @@ query = st.text_input("Search IMDb", "Enter the name of a movie or TV show")
40
  ds_lang = st.text_input("Default subtitle language (Leave it empty if you do not want to use it)", "")
41
  sub_url = st.text_input("Subtitle URL (Leave it empty if you do not want to use it)", "")
42
 
 
 
 
 
43
  # Search and display results
44
  if st.button("Search"):
45
  if query:
@@ -48,8 +52,10 @@ if st.button("Search"):
48
 
49
  # Display search results
50
  if results:
51
- st.write(f"Found {len(results)} results. Displaying up to 20 results:")
52
- for idx, result in enumerate(results[:20]): # Limit to 20 results
 
 
53
  title = result.get('title', 'Unknown title')
54
  year = result.get('year', 'N/A')
55
  imdb_id = result.movieID
@@ -58,22 +64,24 @@ if st.button("Search"):
58
  ia.update(result, info=['main'])
59
  poster_url = result.get('full-size cover url', None)
60
 
61
- # Display poster, title, and year
62
- st.write(f"{idx + 1}. {title} ({year})")
63
- if poster_url:
64
- st.image(poster_url, width=150)
65
-
66
- # Generate embed URL based on search type
67
- if search_type == "Movie":
68
- embed_url = get_movie_embed(imdb_id, ds_lang, sub_url)
69
- else:
70
- embed_url = get_tv_embed(imdb_id, ds_lang=ds_lang, sub_url=sub_url)
71
-
72
- # Display the embed URL
73
- st.write("URL:")
74
- st.write(embed_url)
75
- st.write("---")
76
- else:
77
- st.write("No results found.")
78
  else:
79
- st.write("Please enter a search query.")
 
 
 
 
 
40
  ds_lang = st.text_input("Default subtitle language (Leave it empty if you do not want to use it)", "")
41
  sub_url = st.text_input("Subtitle URL (Leave it empty if you do not want to use it)", "")
42
 
43
+ # Initialize variables
44
+ results = []
45
+ selected_title = None
46
+
47
  # Search and display results
48
  if st.button("Search"):
49
  if query:
 
52
 
53
  # Display search results
54
  if results:
55
+ st.write(f"Found {len(results)} results. Displaying the top 5 results:")
56
+ titles = []
57
+ posters = []
58
+ for idx, result in enumerate(results[:5]): # Limit to 5 results
59
  title = result.get('title', 'Unknown title')
60
  year = result.get('year', 'N/A')
61
  imdb_id = result.movieID
 
64
  ia.update(result, info=['main'])
65
  poster_url = result.get('full-size cover url', None)
66
 
67
+ # Store title and poster for selection
68
+ titles.append(f"{title} ({year})")
69
+ posters.append(poster_url)
70
+
71
+ # Create a selection box for the titles
72
+ selected_title = st.selectbox("Select a title to play", titles)
73
+
74
+ # If a title is selected, find the corresponding embed URL and display it
75
+ if selected_title:
76
+ selected_index = titles.index(selected_title)
77
+ selected_result = results[selected_index]
78
+ imdb_id = selected_result.movieID
79
+
80
+ if search_type == "Movie":
81
+ embed_url = get_movie_embed(imdb_id, ds_lang, sub_url)
 
 
82
  else:
83
+ embed_url = get_tv_embed(imdb_id, ds_lang=ds_lang, sub_url=sub_url)
84
+
85
+ # Display the selected movie or TV show using an iframe
86
+ st.write("Playing:")
87
+ st.markdown(f'<iframe src="{embed_url}" width="700" height="400" frameborder="0" allowfullscreen></iframe>', unsafe_allow_html=True)