Spaces:
Sleeping
Sleeping
import streamlit as st | |
from imdb import IMDb | |
import requests | |
from PIL import Image | |
from io import BytesIO | |
# Function to search for movies/series | |
def search_movies(movie_name): | |
ia = IMDb() | |
search_results = ia.search_movie(movie_name) | |
return search_results | |
# Function to fetch image from URL | |
def fetch_image(url): | |
response = requests.get(url) | |
img = Image.open(BytesIO(response.content)) | |
return img | |
# Function to get movie details | |
def get_movie_details(imdb_id): | |
ia = IMDb() | |
movie = ia.get_movie(imdb_id) | |
details = { | |
'title': movie['title'], | |
'year': movie.get('year'), | |
'rating': movie.get('rating'), | |
'genres': movie.get('genres'), | |
'plot': movie.get('plot'), | |
'poster_url': movie.get('full-size cover url'), | |
'kind': movie.get('kind'), | |
'episodes': movie.get('episodes') if movie.get('kind') == 'tv series' else None | |
} | |
return details | |
# Function to get SuperEmbed URL | |
def get_vidsrcpro_url(imdb_id, season=None, episode=None): | |
base_url = "https://vidsrc.pro/embed/movie/" | |
if season is None or episode is None: | |
return f"{base_url}?video_id={imdb_id}" | |
else: | |
return f"{base_url}?video_id={imdb_id}&s={season}&e={episode}" | |
def main(): | |
st.set_page_config(page_title="Yuyutsu MovieDrive", page_icon="🦇", layout="wide") | |
st.title("Yuyutsu MovieDrive") | |
# Initialize session state | |
if 'search_results' not in st.session_state: | |
st.session_state.search_results = None | |
if 'selected_movie' not in st.session_state: | |
st.session_state.selected_movie = None | |
if 'details' not in st.session_state: | |
st.session_state.details = None | |
if 'imdb_id' not in st.session_state: | |
st.session_state.imdb_id = None | |
movie_name = st.text_input("Enter the movie or series name:") | |
is_webseries = st.checkbox("This is a web series") | |
if movie_name and st.button("Search"): | |
st.session_state.search_results = search_movies(movie_name) | |
st.session_state.selected_movie = None | |
st.session_state.details = None | |
st.session_state.imdb_id = None | |
if st.session_state.search_results: | |
st.write(f"Found {len(st.session_state.search_results)} results. Select one:") | |
selected_movie = st.selectbox( | |
"Select a movie or series:", | |
options=[movie["title"] for movie in st.session_state.search_results], | |
key="movie_select" | |
) | |
if selected_movie != st.session_state.selected_movie: | |
st.session_state.selected_movie = selected_movie | |
movie_data = next(m for m in st.session_state.search_results if m['title'] == selected_movie) | |
st.session_state.imdb_id = movie_data.movieID | |
st.session_state.details = get_movie_details(st.session_state.imdb_id) | |
if st.session_state.details and st.session_state.imdb_id: | |
details = st.session_state.details | |
imdb_id = st.session_state.imdb_id | |
col1, col2 = st.columns([1, 2]) | |
with col1: | |
if details.get('poster_url'): | |
poster = fetch_image(details['poster_url']) | |
st.image(poster, caption=details['title'], use_column_width=True) | |
with col2: | |
st.subheader(f"{details['title']} ({details.get('year', 'N/A')})") | |
st.write(f"**IMDb Rating:** {details.get('rating', 'Not rated')}") | |
st.write(f"**Genres:** {', '.join(details.get('genres', ['Not specified']))}") | |
st.write(f"**Plot:** {details.get('plot', 'No plot available')}") | |
st.subheader("Watch Options") | |
# VidSrc link | |
if is_webseries or details['kind'] == 'tv series': | |
vidsrc_url = f"https://vidsrc.xyz/embed/tv?imdb=tt{imdb_id}" | |
st.write(f"Click the link below to watch the web series on vidsrc:") | |
st.markdown(f"[Watch {details['title']} on vidsrc]({vidsrc_url})") | |
else: | |
vidsrc_url = f"https://vidsrc.xyz/embed/movie?imdb=tt{imdb_id}" | |
st.write(f"Click the link below to watch on vidsrc:") | |
st.markdown(f"[Watch {details['title']} on vidsrc]({vidsrc_url})") | |
# Autoembed link | |
if is_webseries or details['kind'] == 'tv series': | |
st.write("For TV Series, select season and episode:") | |
if details['episodes']: | |
seasons = sorted(details['episodes'].keys()) | |
season = st.selectbox("Season", options=seasons) | |
if season: | |
episodes = sorted(details['episodes'][season].keys()) | |
episode = st.selectbox("Episode", options=episodes) | |
if episode: | |
autoembed_url = f"https://player.autoembed.cc/embed/tv/tt{imdb_id}/{season}/{episode}" | |
st.markdown(f"[Watch {details['title']} S{season:02d}E{episode:02d} on autoembed]({autoembed_url})") | |
else: | |
st.write("Episode information is not available for this series.") | |
season = st.number_input("Enter season number:", min_value=1, value=1) | |
episode = st.number_input("Enter episode number:", min_value=1, value=1) | |
autoembed_url = f"https://player.autoembed.cc/embed/tv/tt{imdb_id}/{season}/{episode}" | |
st.markdown(f"[Watch {details['title']} S{season:02d}E{episode:02d} on autoembed]({autoembed_url})") | |
elif details['kind'] == 'movie': | |
autoembed_url = f"https://player.autoembed.cc/embed/movie/tt{imdb_id}" | |
st.write(f"Alternative link for movies:") | |
st.markdown(f"[Watch {details['title']} on autoembed]({autoembed_url})") | |
else: | |
st.write("Note: Alternative link is not available for this type of content.") | |
# SuperEmbed link | |
st.write("VidSrcPro streaming option:") | |
if is_webseries or details['kind'] == 'tv series': | |
if details['episodes']: | |
seasons = sorted(details['episodes'].keys()) | |
season = st.selectbox("Season (SuperEmbed)", options=seasons, key="superembed_season") | |
if season: | |
episodes = sorted(details['episodes'][season].keys()) | |
episode = st.selectbox("Episode (SuperEmbed)", options=episodes, key="superembed_episode") | |
if episode: | |
superembed_url = get_vidsrcpro_url(imdb_id, season, episode) | |
st.markdown(f"[Watch {details['title']} S{season:02d}E{episode:02d} on SuperEmbed]({superembed_url})") | |
else: | |
st.write("Episode information is not available for this series.") | |
season = st.number_input("Enter season number (SuperEmbed):", min_value=1, value=1, key="superembed_season_input") | |
episode = st.number_input("Enter episode number (SuperEmbed):", min_value=1, value=1, key="superembed_episode_input") | |
superembed_url = get_superembed_url(imdb_id, season, episode) | |
st.markdown(f"[Watch {details['title']} S{season:02d}E{episode:02d} on SuperEmbed]({superembed_url})") | |
else: | |
superembed_url = get_superembed_url(imdb_id) | |
st.markdown(f"[Watch {details['title']} on SuperEmbed]({superembed_url})") | |
st.write("Note: These links will open in a new tab. Please ensure you have appropriate permissions to view the content.") | |
# Add a footer | |
st.markdown("---") | |
st.markdown( | |
"<h3 style='text-align: center;'>" | |
"Created with ❤️ by Yuyutsu<br>" | |
"<span style='color: #FF9933;'>जय श्री राम</span>" | |
"</h3>", | |
unsafe_allow_html=True | |
) | |
if __name__ == "__main__": | |
main() |