-
Notifications
You must be signed in to change notification settings - Fork 24
/
play.py
61 lines (51 loc) · 1.75 KB
/
play.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
import requests
import subprocess
import sys
title_art = r""" _____ ______ _ _
|_ _| | ___| (_)
| | ___ _ __ _ __| |_ | |___ __
| |/ _ \| '__| '__| _| | | \ \/ /
| | (_) | | | | | | | | |> <
\_/\___/|_| |_| \_| |_|_/_/\_\
"""
print(title_art+'\n')
def main():
movie_name = input("Enter the movie name:\n")
print(f"Searching for {movie_name}")
base_url = f"https://api.sumanjay.cf/torrent/?query={movie_name}"
torrent_results = requests.get(url=base_url).json()
index = 1
magnet = []
for result in torrent_results:
if 'movie' in result['type'].lower():
print(index, ") ", result['name'], "-->", result['size'])
index += 1
magnet.append(result['magnet'])
if magnet:
choice = int(
input("Enter the index of the movie which you want to stream\n"))
try:
magnet_link = magnet[choice-1]
download = False # Default is streaming
stream_choice = int(
input("Press 1 to stream or Press 2 to download the movie\n"))
if stream_choice == 2:
download = True
webtorrent_stream(magnet_link, download)
except IndexError:
print("Incorrect Index entered")
else:
print(f"No results found for {movie_name}")
# Handle Streaming
def webtorrent_stream(magnet_link: str, download: bool):
cmd = []
cmd.append("webtorrent")
cmd.append(magnet_link)
if not download:
cmd.append('--vlc')
if sys.platform.startswith('linux'):
subprocess.call(cmd)
elif sys.platform.startswith('win32'):
subprocess.call(cmd, shell=True)
if __name__ == "__main__":
main()