-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathKickFlix.py
More file actions
166 lines (129 loc) · 6.71 KB
/
KickFlix.py
File metadata and controls
166 lines (129 loc) · 6.71 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import os
import time
import json
import requests
from argparse import ArgumentParser
class KickFlix():
def __init__(self):
print("""
██╗░░██╗██╗░█████╗░██╗░░██╗███████╗██╗░░░░░██╗██╗░░██╗
██║░██╔╝██║██╔══██╗██║░██╔╝██╔════╝██║░░░░░██║╚██╗██╔╝
█████═╝░██║██║░░╚═╝█████═╝░█████╗░░██║░░░░░██║░╚███╔╝░
██╔═██╗░██║██║░░██╗██╔═██╗░██╔══╝░░██║░░░░░██║░██╔██╗░
██║░╚██╗██║╚█████╔╝██║░╚██╗██║░░░░░███████╗██║██╔╝╚██╗
╚═╝░░╚═╝╚═╝░╚════╝░╚═╝░░╚═╝╚═╝░░░░░╚══════╝╚═╝╚═╝░░╚═╝
Minimal command line based torrent streaming client
""")
parser = ArgumentParser(description='KickFlix - Minimal torrent player')
parser.add_argument('-s', '--stream', type=str, help='Stream a torrent')
parser.add_argument('-d', '--download', help='Download a torrent')
parser.add_argument('-m', '--magnet', help='Get the magnet link of a torrent')
self.args = parser.parse_args()
self.API_SEARCH = "https://kickass-api-unofficial.herokuapp.com/search?torrent="
self.API_MAGNET = "https://kickass-api-unofficial.herokuapp.com/magnet?page_url="
def run(self):
""" Run the program """
if self.args.stream:
search_results = self.search_kickass(self.args.stream)
magnet = self.get_magnet(search_results["1"]['page_url'])
print("\nNow streaming:\n",search_results["1"]['title'])
time.sleep(0.7)
self.stream(magnet)
exit()
elif self.args.download:
search_results = self.search_kickass(self.args.download)
magnet = self.get_magnet(search_results["1"]['page_url'])
print("\nDownloading: \n",search_results["1"]['title'])
time.sleep(0.7)
self.download(magnet)
exit()
elif self.args.magnet:
search_results = self.search_kickass(self.args.magnet)
magnet = self.get_magnet(search_results["1"]['page_url'])
print("\nMagnet for : ",str(search_results["1"]['title'])+ "\n")
print(magnet)
exit()
else:
query = input('What do you want to search for (q) to quit: ').strip()
if query.lower() == "q":
exit()
else:
results = self.search_kickass(query)
for count in results.keys():
print(f"{count}. {results[count]['title']}\n")
while True:
try:
user_input = input('\nSelect a torrent(s/d/m) (q) to quit (r) to re-search: ').strip()
if user_input.lower() == "q":
exit()
elif user_input.lower() == "r":
print("\n-----------------#####-----------------\n")
self.run()
elif " " not in user_input and len(user_input)<=3:
if len(user_input) == 2:
index = user_input[0]
mode = user_input[1]
else:
index = user_input[0:2]
mode = user_input[-1]
magnet = self.get_magnet(results[index]['page_url'])
if mode == "s":
print("\nNow streaming: ",results[index]['title'])
time.sleep(0.7)
self.stream(magnet)
elif mode == "d":
print("\nDownloading: ",results[index]['title'])
time.sleep(0.7)
self.download(magnet)
elif mode == "m":
print("\nMagnet for : ",str(results[index]['title'])+ "\n")
print(magnet)
print("\n-----------------#####-----------------\n")
self.run()
elif len(user_input) > 2:
raise ValueError
except (IndexError,ValueError):
print("""
*****************************************************
Please retry entering mode with torrent selection
example: \"1s\" to stream first torrent
or \"1d\" to download first torrent
*****************************************************""")
def get_magnet(self,page_url) -> str:
""" Get magnet link of selected torrent """
resp = requests.get(self.API_MAGNET + page_url)
resp.close()
magnet = json.loads(resp.text)
return (magnet['magnet'])
def download(self,magnet):
""" Download a torrent """
os.system('webtorrent ' + magnet)
def stream(self,magnet):
""" Stream a torrent """
os.system('webtorrent ' + f"\"{magnet}\"" + ' --vlc')
def search_kickass(self,query) -> dict:
""" Search for torrents """
print(f"Searching for \"{query}\"")
resp = requests.get(self.API_SEARCH + query)
resp.close()
search_result = json.loads(resp.text)
if search_result == {}:
print("0 search results\n")
print("\n-----------------#####-----------------\n")
if self.args.stream == None and self.args.download == None:
self.run()
exit()
print(str(len(search_result)) + " search results found\n")
time.sleep(0.7)
return search_result
def main():
""" API check """
print("Checking API status...")
if requests.get("https://kickass-api-unofficial.herokuapp.com/").status_code == 200:
print("API is up and running :D")
kickflix = KickFlix()
kickflix.run()
else:
print("API is currently down :(")
print("report issues at github.com/janardonh/KickFlix")
main()