-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_data.py
More file actions
130 lines (69 loc) · 2.73 KB
/
Copy pathsync_data.py
File metadata and controls
130 lines (69 loc) · 2.73 KB
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
import tmdbsimple as tmdb
tmdb.API_KEY = 'bf2db7d8063307bdcc241c3919c45564'
def search_movie_name(name):
""" Searches the tmdb for a movie from a user query """
search = tmdb.Search()
search.movie(query = name)
#Showing search results and letting you oselect a movie or tv show
#used a dictonary to store title as key and ID as value
search_hold = []
for s in search.results:
#Gathers general information about the movie
title = s["title"]
title_id = s["id"]
poster_path = s["poster_path"]
overview = s["overview"]
release_date = s['release_date']
#gets the trailer link and creates a youtube link to trailer
#if no trailer is found 'NaN' will be assigned to variable
movie = tmdb.Movies(title_id)
video_details = movie.videos()
youtube = 'https://www.youtube.com/watch?v='
try:
key = video_details['results'][0]['key'] #unique youtube key for video
youtube_key = youtube + key #creates the link
except:
youtube_key = 'NaN'
#creates a list with movie information
movie = [title_id,title,release_date,poster_path,youtube_key,overview]
#appends the movie info to the search list
search_hold.append(movie)
#returns a list of results
return search_hold
def get_similar(movie_id):
""" Gets similar movies based off a movie id in tmdb """
search = tmdb.Movies(movie_id)
similar = search.similar_movies()
try:
id_numbers = []
i = 0
while i <= len(similar['results']):
id_num = similar['results'][i]['id']
id_numbers.append(id_num)
print(id_num)
i += 1
except:
pass
return id_numbers
def get_movie_info(movie_id):
""" Searches tmdb for a movie by its id number and returns the movie info """
search = tmdb.Movies(movie_id)
similar = search.info()
#gets the basic movie information
title_id = similar['id']
title = similar['title']
poster_path = similar['poster_path']
overview = similar['overview']
release_date = similar['release_date']
#Gets the trailer link
movie = tmdb.Movies(movie_id)
video_details = movie.videos()
youtube = 'https://www.youtube.com/watch?v='
try:
key = video_details['results'][0]['key'] #unique youtube key for video
youtube_key = youtube + key #creates the link
except:
youtube_key = 'NaN'
return title_id,title,release_date,poster_path,overview,youtube_key
if __name__ == "__main__":
print(get_movie_info(674))