File size: 5,974 Bytes
0116133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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

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.")

        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()