forked from prp-e/leetflix-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleetflix.py
123 lines (104 loc) · 3.96 KB
/
leetflix.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
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
import json
from tkinter import messagebox
from tkinter.messagebox import *
import requests
import subprocess
from tkinter import *
from tkinter import ttk
from threading import *
from tkinter import filedialog
import base64, urllib.request
#api
API_URL = "https://leetflix.haghiri75.com"
#lists
idMovies = []
magnetLinks = {}
#position app
def geo(window,x,y):
scr_width, scr_height = window.winfo_screenwidth(), window.winfo_screenheight()
scr_x, scr_y = (scr_width/2) - (x/2), (scr_height/2) - (y/2)
x = "%dx%d+%d+%d" % (x, y, scr_x, scr_y)
return x
#get from api
def getData():
movielist_table.delete(*movielist_table.get_children())
movielist_table.insert('', END)
response = requests.post(API_URL, data=json.dumps({"keyword" : movieName_entry.get()}), headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0', 'content-type': 'application/json'})
response = json.loads(response.text)
return response
#command button find
def findButton_Command():
def work():
movielist_table.delete(*movielist_table.get_children())
magnetLinks.clear()
data = getData()
if len(data) == 0:
return showerror('Error!', 'Nothing found!')
index = 1
for result in data:
movielist_table.insert('', END, text='', values=(index, f"""{result["title"]}"""))
magnetLinks[index]=result['magnet']
index += 1
messagebox.showwarning('!', 'DONT CLOSE APP!')
thWork = Thread(target=work)
thWork.start()
#get data of selected row
def getSelected(e):
try:
idMovies.clear()
curItem = movielist_table.focus()
itm = movielist_table.item(curItem)
valitm = itm.get('values')
idMovies.append(valitm[0])
except:
pass
#download button command
def downloadButton_command():
try:
folder_selected = filedialog.askdirectory()
messagebox.showwarning('Do not close.', 'If the application is closed, downloading and playback will stop.')
def work():
subprocess.run(execution_array, shell=True)
execution_array = """webtorrent "{}" --vlc -o "{}" """.format(magnetLinks[idMovies[0]], folder_selected)
thWork = Thread(target=work)
thWork.start()
except Exception as e:
print(e)
messagebox.showerror('Nothing selected!', 'Please select your desired movie.')
#window
win = Tk()
win.title('LEETFLIX')
win.geometry(geo(win, 350, 420))
win.resizable(0, 0)
raw_data = urllib.request.urlopen("https://8pic.ir/uploads/LEETFLIX_579c4.png").read()
b64_data = base64.b64encode(raw_data)
image = PhotoImage(data=b64_data)
win.call('wm', 'iconphoto', win._w, image)
#frame
rootFrame = Frame(win)
rootFrame.pack(padx=37, pady=(13,0))
#enter movie name
movieName_label = Label(rootFrame, text='Movie name (or Keywords)', font=('',9))
movieName_entry = Entry(rootFrame, width=30, font=('',13), justify=CENTER)
movieName_label.pack(pady=(0,10), anchor=NW)
movieName_entry.pack(pady=(0,10), ipady=2)
#button Find!
findMovie_button = Button(rootFrame ,text='Find', width=38, command=findButton_Command)
findMovie_button.pack(pady=(0,14))
#table for movie list
tableFrame = Frame(rootFrame)
movielist_table = ttk.Treeview(tableFrame, show='headings', columns=('id','name'))
verscrlbar = Scrollbar(tableFrame, orient = HORIZONTAL, command = movielist_table.xview)
movielist_table.configure(xscrollcommand = verscrlbar.set)
verscrlbar.pack(side = 'bottom', fill = X)
movielist_table.pack()
tableFrame.pack()
movielist_table.column('id', width=20, anchor=W, stretch=FALSE)
movielist_table.column('name', width = 415, anchor=W, stretch=FALSE)
movielist_table.heading('id', text='ID', anchor=CENTER)
movielist_table.heading('name', text='Movie Name', anchor=W)
movielist_table.bind('<ButtonRelease-1>', getSelected)
#download button
downloadButton = Button(rootFrame, text='Download', width=38, command=downloadButton_command)
downloadButton.pack(pady=(13,0))
win.mainloop()