-
Notifications
You must be signed in to change notification settings - Fork 6
/
entertainment_center.py
36 lines (28 loc) · 1.24 KB
/
entertainment_center.py
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
import media
import urllib.request
import urllib.parse
import json
import fresh_tomatoes
f = open('data.json',) # Open json file
movies = [] # To store all the instance variables
names = json.load(f) # Load json data
OMDBapikey = "" # Add your api key that is obtained from omdbapi
youtubeAPIkey = "" # Add your youtube api key
# A function to get the video id of youtube's trailer
def getTrailerID(title):
url = urllib.request.urlopen("https://www.googleapis.com/youtube/v3/search?part=id&maxResults=1&q="+ urllib.parse.quote(title+" trailer") +"&type=videoId&key="+youtubeAPIkey)
output = url.read().decode("utf-8")
loaded_json = json.loads(output)
id = loaded_json['items'][0]['id']['videoId']
return id
# return "https://www.youtube.com/watch?v="+id
# A function to get the IMDB details
def details(title):
detailsection = urllib.request.urlopen("http://www.omdbapi.com/?t="+urllib.parse.quote(title)+"&apikey="+OMDBapikey)
output = detailsection.read().decode("utf-8")
loaded_json = json.loads(output)
ID = getTrailerID(title)
movies.append(media.Movie(loaded_json['Title'],loaded_json['Plot'],loaded_json['Poster'],ID))
for name in names:
details(name.get('name'))
fresh_tomatoes.open_movies_page(movies)