-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimdb.py
74 lines (66 loc) · 2.83 KB
/
imdb.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
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
# import requests
# from bs4 import BeautifulSoup
# url = "https://www.imdb.com/find/?q=The%20Matrix"
# headers = {
# 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
# }
# response = requests.get(url, headers=headers)
# soup = BeautifulSoup(response.content, 'html.parser')
# print(soup.find('a', class_='ipc-metadata-list-summary-item__t', href=True)['href'])
# import requests
# import requests
# url = "https://api.themoviedb.org/3/movie/tt0133093?language=en-US"
# headers = {
# "accept": "application/json",
# "Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI4YzA3ZTkwN2U0YWViM2M1ZDhkZTNhYmNmNzg3NWYwMyIsInN1YiI6IjY1NThlZGUyN2YwNTQwMThkNmYzYzgyMyIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.DNHiqLgWTsgtJS_h9S7NvURxAJR5Jf0FjQqFmMvm6UE"
# }
# response = requests.get(url, headers=headers)
# data = response.json()
# print(data['poster_path'])
import requests
from bs4 import BeautifulSoup
import re
import pandas as pd
from dotenv import load_dotenv
import os
load_dotenv()
tmdb_token = os.getenv("TMDB_KEY")
def get_info(name):
df = pd.read_csv("all_titles.csv")
# check if movie or series
if df[df.title == name].type.values[0] == "Movie":
url1 = "https://www.imdb.com/find/?q={}".format(name)
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
}
response = requests.get(url1, headers=headers)
soup = BeautifulSoup(response.content, "html.parser")
id = soup.find("a", class_="ipc-metadata-list-summary-item__t", href=True)[
"href"
]
id = re.findall(r"tt\d+", id)[0]
url = "https://api.themoviedb.org/3/movie/{}?language=en-US".format(id)
headers = {
"accept": "application/json",
"Authorization": "Bearer {}".format(tmdb_token),
}
response = requests.get(url, headers=headers)
data = response.json()
return data
else:
url = "https://www.themoviedb.org/search?query={}".format(name.lower())
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, "html.parser")
id = soup.find("div", class_="title").find("a", href=True)["href"]
id = re.findall(r"\d+", id)[0]
url = "https://api.themoviedb.org/3/tv/{}?language=en-US".format(id)
headers = {
"accept": "application/json",
"Authorization": "Bearer {}".format(tmdb_token),
}
response = requests.get(url, headers=headers)
data = response.json()
return data