Added main.py and initial grab of sqlite DB
This commit is contained in:
parent
1e570a3485
commit
4e24f5df9c
Binary file not shown.
|
|
@ -0,0 +1,83 @@
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
|
||||||
|
connection = sqlite3.connect("YIFY.db")
|
||||||
|
cursor = connection.cursor()
|
||||||
|
testMovie = "Nightmare on Elm Street"
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
cursor.execute("CREATE TABLE Movies (ID INTEGER UNIQUE, Title TEXT, IMDB_Code TEXT, Rating INTEGER, YT_Trailer TEXT, Description TEXT, Language TEXT,Cover TEXT)")
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
print("Table Movies Exists")
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
cursor.execute("CREATE TABLE Hashes (ID INTEGER UNIQUE, hash_720 TEXT, hash_1080 TEXT, hash_2160 TEXT, hash_3D TEXT)")
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
print("Table Hashes Exists")
|
||||||
|
pass
|
||||||
|
|
||||||
|
def movieSearch(movieName):
|
||||||
|
movie = requests.get("https://yts.mx/api/v2/list_movies.json?query_term=" + str(movieName))
|
||||||
|
movieInfo = json.loads(movie.content)
|
||||||
|
return movieInfo
|
||||||
|
|
||||||
|
|
||||||
|
def movieDetails(movie):
|
||||||
|
movieDetails = requests.get("https://yts.mx/api/v2/movie_details.json?movie_id=" + str(movie[0]))
|
||||||
|
try:
|
||||||
|
movieInfo = json.loads(movieDetails.content)
|
||||||
|
except json.decoder.JSONDecodeError:
|
||||||
|
movieInfo = movieDetails.content
|
||||||
|
return movieInfo
|
||||||
|
|
||||||
|
|
||||||
|
def addMovie(query):
|
||||||
|
sql = "insert or replace into Movies (ID, Title, IMDB_Code, Rating, YT_Trailer, Description, Language,Cover) values (?,?,?,?,?,?,?,?)"
|
||||||
|
cursor.execute(sql, query)
|
||||||
|
|
||||||
|
def addHashes(query):
|
||||||
|
sql = "insert or replace into Hashes (ID, hash_720, hash_1080, hash_2160, hash_3D) values (?,?,?,?,?)"
|
||||||
|
cursor.execute(sql, query)
|
||||||
|
|
||||||
|
|
||||||
|
results = movieSearch(testMovie)
|
||||||
|
latest3D = requests.get("https://yts.mx/api/v2/list_movies.json?quality=3D")
|
||||||
|
|
||||||
|
cleanLatest3D = json.loads(latest3D.content)
|
||||||
|
for Dmovie in cleanLatest3D['data']['movies']:
|
||||||
|
query = (Dmovie['id'], Dmovie['title'], Dmovie['imdb_code'], Dmovie['rating'], Dmovie['yt_trailer_code'], Dmovie['summary'], Dmovie['language'], Dmovie['large_cover_image'])
|
||||||
|
addMovie(query)
|
||||||
|
|
||||||
|
for movie in results['data']['movies']:
|
||||||
|
query = (movie['id'], movie['title'], movie['imdb_code'],movie['rating'],movie['yt_trailer_code'],movie['summary'],movie['language'],movie['large_cover_image'])
|
||||||
|
addMovie(query)
|
||||||
|
|
||||||
|
IDs = cursor.execute("SELECT ID FROM Movies").fetchall()
|
||||||
|
|
||||||
|
for ID in IDs:
|
||||||
|
hashObject = {}
|
||||||
|
hashObject['ID'] = ID[0]
|
||||||
|
hashObject['720'] = ""
|
||||||
|
hashObject['1080'] = ""
|
||||||
|
hashObject['2160'] = ""
|
||||||
|
hashObject['3D'] = ""
|
||||||
|
movieObject = movieDetails(ID)
|
||||||
|
for torrent in movieObject['data']['movie']['torrents']:
|
||||||
|
if torrent['quality'] == '720p':
|
||||||
|
hashObject['720'] = torrent['hash']
|
||||||
|
elif torrent['quality'] == '1080p':
|
||||||
|
hashObject['1080'] = torrent['hash']
|
||||||
|
elif torrent['quality'] == '2160p':
|
||||||
|
hashObject['2160'] = torrent['hash']
|
||||||
|
elif torrent['quality'] == '3D':
|
||||||
|
hashObject['3D'] = torrent['hash']
|
||||||
|
query = (str(hashObject['ID']), str(hashObject['720']), str(hashObject['1080']), str(hashObject['2160']), str(hashObject['3D']))
|
||||||
|
addHashes(query)
|
||||||
|
|
||||||
|
connection.commit()
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue