yuyutsu07 commited on
Commit
0116133
1 Parent(s): c115fe5

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +142 -0
app.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from imdb import IMDb
3
+ import requests
4
+ from PIL import Image
5
+ from io import BytesIO
6
+
7
+ # Function to search for movies/series
8
+ def search_movies(movie_name):
9
+ ia = IMDb()
10
+ search_results = ia.search_movie(movie_name)
11
+ return search_results
12
+
13
+ # Function to fetch image from URL
14
+ def fetch_image(url):
15
+ response = requests.get(url)
16
+ img = Image.open(BytesIO(response.content))
17
+ return img
18
+
19
+ # Function to get movie details
20
+ def get_movie_details(imdb_id):
21
+ ia = IMDb()
22
+ movie = ia.get_movie(imdb_id)
23
+ details = {
24
+ 'title': movie['title'],
25
+ 'year': movie.get('year'),
26
+ 'rating': movie.get('rating'),
27
+ 'genres': movie.get('genres'),
28
+ 'plot': movie.get('plot'),
29
+ 'poster_url': movie.get('full-size cover url'),
30
+ 'kind': movie.get('kind'),
31
+ 'episodes': movie.get('episodes') if movie.get('kind') == 'tv series' else None
32
+ }
33
+ return details
34
+
35
+ def main():
36
+ st.set_page_config(page_title="Yuyutsu MovieDrive", page_icon="🦇", layout="wide")
37
+ st.title("Yuyutsu MovieDrive")
38
+
39
+ # Initialize session state
40
+ if 'search_results' not in st.session_state:
41
+ st.session_state.search_results = None
42
+ if 'selected_movie' not in st.session_state:
43
+ st.session_state.selected_movie = None
44
+ if 'details' not in st.session_state:
45
+ st.session_state.details = None
46
+ if 'imdb_id' not in st.session_state:
47
+ st.session_state.imdb_id = None
48
+
49
+ movie_name = st.text_input("Enter the movie or series name:")
50
+ is_webseries = st.checkbox("This is a web series")
51
+
52
+ if movie_name and st.button("Search"):
53
+ st.session_state.search_results = search_movies(movie_name)
54
+ st.session_state.selected_movie = None
55
+ st.session_state.details = None
56
+ st.session_state.imdb_id = None
57
+
58
+ if st.session_state.search_results:
59
+ st.write(f"Found {len(st.session_state.search_results)} results. Select one:")
60
+ selected_movie = st.selectbox(
61
+ "Select a movie or series:",
62
+ options=[movie["title"] for movie in st.session_state.search_results],
63
+ key="movie_select"
64
+ )
65
+
66
+ if selected_movie != st.session_state.selected_movie:
67
+ st.session_state.selected_movie = selected_movie
68
+ movie_data = next(m for m in st.session_state.search_results if m['title'] == selected_movie)
69
+ st.session_state.imdb_id = movie_data.movieID
70
+ st.session_state.details = get_movie_details(st.session_state.imdb_id)
71
+
72
+ if st.session_state.details and st.session_state.imdb_id:
73
+ details = st.session_state.details
74
+ imdb_id = st.session_state.imdb_id
75
+
76
+ col1, col2 = st.columns([1, 2])
77
+ with col1:
78
+ if details.get('poster_url'):
79
+ poster = fetch_image(details['poster_url'])
80
+ st.image(poster, caption=details['title'], use_column_width=True)
81
+
82
+ with col2:
83
+ st.subheader(f"{details['title']} ({details.get('year', 'N/A')})")
84
+ st.write(f"**IMDb Rating:** {details.get('rating', 'Not rated')}")
85
+ st.write(f"**Genres:** {', '.join(details.get('genres', ['Not specified']))}")
86
+ st.write(f"**Plot:** {details.get('plot', 'No plot available')}")
87
+
88
+ st.subheader("Watch Options")
89
+
90
+ # VidSrc link
91
+ if is_webseries or details['kind'] == 'tv series':
92
+ vidsrc_url = f"https://vidsrc.xyz/embed/tv?imdb=tt{imdb_id}"
93
+ st.write(f"Click the link below to watch the web series on vidsrc:")
94
+ st.markdown(f"[Watch {details['title']} on vidsrc]({vidsrc_url})")
95
+ else:
96
+ vidsrc_url = f"https://vidsrc.xyz/embed/movie?imdb=tt{imdb_id}"
97
+ st.write(f"Click the link below to watch on vidsrc:")
98
+ st.markdown(f"[Watch {details['title']} on vidsrc]({vidsrc_url})")
99
+
100
+ # Autoembed link
101
+ if is_webseries or details['kind'] == 'tv series':
102
+ st.write("For TV Series, select season and episode:")
103
+
104
+ if details['episodes']:
105
+ seasons = sorted(details['episodes'].keys())
106
+ season = st.selectbox("Season", options=seasons)
107
+
108
+ if season:
109
+ episodes = sorted(details['episodes'][season].keys())
110
+ episode = st.selectbox("Episode", options=episodes)
111
+
112
+ if episode:
113
+ autoembed_url = f"https://player.autoembed.cc/embed/tv/tt{imdb_id}/{season}/{episode}"
114
+ st.markdown(f"[Watch {details['title']} S{season:02d}E{episode:02d} on autoembed]({autoembed_url})")
115
+ else:
116
+ st.write("Episode information is not available for this series.")
117
+ season = st.number_input("Enter season number:", min_value=1, value=1)
118
+ episode = st.number_input("Enter episode number:", min_value=1, value=1)
119
+ autoembed_url = f"https://player.autoembed.cc/embed/tv/tt{imdb_id}/{season}/{episode}"
120
+ st.markdown(f"[Watch {details['title']} S{season:02d}E{episode:02d} on autoembed]({autoembed_url})")
121
+
122
+ elif details['kind'] == 'movie':
123
+ autoembed_url = f"https://player.autoembed.cc/embed/movie/tt{imdb_id}"
124
+ st.write(f"Alternative link for movies:")
125
+ st.markdown(f"[Watch {details['title']} on autoembed]({autoembed_url})")
126
+ else:
127
+ st.write("Note: Alternative link is not available for this type of content.")
128
+
129
+ st.write("Note: These links will open in a new tab. Please ensure you have appropriate permissions to view the content.")
130
+
131
+ # Add a footer
132
+ st.markdown("---")
133
+ st.markdown(
134
+ "<h3 style='text-align: center;'>"
135
+ "Created with ❤️ by Yuyutsu<br>"
136
+ "<span style='color: #FF9933;'>जय श्री राम</span>"
137
+ "</h3>",
138
+ unsafe_allow_html=True
139
+ )
140
+
141
+ if __name__ == "__main__":
142
+ main()