-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimdbinfo.py
More file actions
109 lines (79 loc) · 2.42 KB
/
imdbinfo.py
File metadata and controls
109 lines (79 loc) · 2.42 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
import secrets
from imdb import IMDb
from bs4 import BeautifulSoup
import requests
import os
import sys
import csv
from googlesearch import search
import urllib
# getting path
path = os.getcwd()
expath = path+'\movie_info.csv'
expath = expath.split("\\")
doc = '//'
expath = doc.join(expath)
# end of getting path
# create an instance of the IMDb class
ia = IMDb()
# for searching a movie
to_search = sys.argv[1:]
to_search = ' '.join(map(str, to_search))
movies = ia.search_movie(to_search)
# print(movies[0].movieID)
# print(movies[0]['cover url'])
# rating = movies[0].rating
movieid = movies[0].movieID
movie = ia.get_movie(movieid)
# infosets key willgive you alll the info about the movie
# print(movie.infoset2keys)
title = movie.get('title')
#trailer link from google
query = title+' trailer'
for result in search(query, stop=10):
trailer = result
trailer = trailer.replace('watch?v=','embed/')
break
# trailer = 'https://www.youtube.com/watch?v=x7Krla_UxRg'
# req format = https://www.youtube.com/embed/x7Krla_UxRg
# trailer find end
genre = str(movie.get('genres'))
genre = genre.replace("'", "''")
try:
runtime = (movie.get('runtime'))[0]
except TypeError:
runtime='50'
year = movie.get('year')
plot = str(movie.get('plot outline'))
plot = plot.replace("'", "''")
rating = movie.get('rating')
url = ia.get_imdbURL(movies[0])
source = requests.get(url).text
soup = BeautifulSoup(source, 'lxml')
image = soup.find('img', class_='ipc-image')
# images = image.split(' ')
images = image['srcset']
images = images.split(' ')
image = []
image.append(images[0])
image.append(images[2])
image.append(images[4])
images = str(image)
images = images.replace("'", "''")
kind = movie['kind']
if(kind=='tv series'):
ia.update(movie,'episodes')
totalSeason = len(movie['episodes'])
with open(expath, 'w' , encoding='utf-8') as f:
if(kind=='tv series'):
fieldnames = ['movieid','title','kind','season','year','genre','plot','runtime','rating','url','image','trailer']
write = csv.writer(f)
write.writerow(fieldnames)
row = [movieid,title,kind,totalSeason,year,genre,plot,runtime,rating,url,images,trailer]
write.writerow(row)
else:
fieldnames = ['movieid','title','kind','year','genre','plot','runtime','rating','url','image','trailer']
write = csv.writer(f)
write.writerow(fieldnames)
row = [movieid,title,kind,year,genre,plot,runtime,rating,url,images,trailer]
write.writerow(row)