-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm.py
More file actions
210 lines (161 loc) · 7.6 KB
/
m.py
File metadata and controls
210 lines (161 loc) · 7.6 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
from telegram.ext import Updater
from subprocess import check_output
import subprocess
from telegram import (ReplyKeyboardMarkup, ReplyKeyboardRemove)
from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, RegexHandler,
ConversationHandler)
import unidecode
import requests
from bs4 import BeautifulSoup
from datetime import datetime,timedelta
today = datetime.now().date()
yesterday=(datetime.now()-timedelta(1)).date()
def session_get_to_soup_wrapper(url,session):
r = session.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
while True:
try:
if soup.find("").__len__():
break
r = session.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
except AttributeError:
r = session.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
# print(soup.find("a"))
return soup
def page_to_tg(update,soup):
print('page_to_tg')
comment_url = 'http://uj3wazyk5u4hnvtk.onion/static/img/icon_comment.gif'
res= "-------- TORRENT LIST --------\n\n\n"
count=0
for torrent in soup.select("table > tr"):
try:
temp_metadata = unidecode.unidecode(torrent.find(class_="detDesc").get_text())
except AttributeError:
continue
turl = 'http://uj3wazyk5u4hnvtk.onion' + torrent.find(class_="detLink").get('href')
#print(turl)
tname=torrent.find(class_="detLink").get_text()
try:
magnet=torrent.find(title="Download this torrent using magnet").get('href')
except Exception as e:
magnet='NOT AVAILABLE'
try:
uname = unidecode.unidecode(torrent.select("font > a")[0].get_text())
except IndexError:
uname = 'Anonymous'
uploaded=temp_metadata.partition(',')[0][9:]
uploaded_param=uploaded.partition(' ')
if(uploaded_param[0]=='Today' or uploaded_param[2][0:4]=='mins'):
uploaded=today
elif uploaded_param[0]=='Y-day':
uploaded = yesterday
elif uploaded_param[2].__len__()==4:
uploaded=uploaded_param[2]+'-'+uploaded_param[0]
else:
uploaded='2018'+'-'+uploaded_param[0]
seeders=torrent.select("td:nth-of-type(3)")[0].get_text()
leechers=torrent.select("td:nth-of-type(4)")[0].get_text()
try:
comments=torrent.find(src=comment_url).get('alt')[17:].partition(' ')[0]
except AttributeError:
comments=0
tsize = temp_metadata.partition(',')[2].partition(',')[0][6:]
tsize=tsize.__str__()
if torrent.find_all(alt='Trusted').__len__()==1:
ranku = 'Trusted'
elif torrent.find_all(alt='VIP').__len__()==1:
ranku='VIP'
else:
ranku='NO RANK'
print(tname+uname+tsize+ranku+uploaded)
count = count + 1
if count % 5 == 0:
update.message.reply_text(res)
res="'\n"
res+='Name: '+ tname + '\n'+ 'Uploader: '+ uname+' Rank: '+ranku +'\n'+ 'size: '+tsize+ '\n'+'Uploaded: '+uploaded+'\n'+'Seeders: '+seeders+' Leechers: '+leechers+'\n'+ magnet + '\n\n\n'
update.message.reply_text(res)
CATEGORY, MOVIE, MOVIE_D, TV_SHOW,TV_SHOW_D, MUSIC,MUSIC_D = range(7)
def tpb(bot,update):
reply_keyboard = [['Movie', 'TV_Show', 'Music']]
update.message.text
update.message.reply_text(
'Welcome to MGB, please chose a category',
reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True))
return CATEGORY
def goToMovie(bot,update):
update.message.reply_text('enter the title')
return MOVIE
def goToTVShow(bot,update):
update.message.reply_text('enter the title')
return TV_SHOW
def goToMusic(bot,update):
update.message.reply_text('enter the title')
return MUSIC
def getMovies(bot,update):
print(update.message.text)
page_url="http://uj3wazyk5u4hnvtk.onion/search/"+update.message.text+"/0/99/201"
session = requests.session()
session.proxies['http'] = 'socks5h://localhost:9050'
session.proxies['https'] = 'socks5h://localhost:9050'
soup=session_get_to_soup_wrapper(page_url,session)
page_to_tg(update,soup)
update.message.reply_text('Enter a valid magnet')
return MOVIE_D
def getTVShows(bot,update):
print(update.message.text)
page_url="http://uj3wazyk5u4hnvtk.onion/search/"+update.message.text+"/0/99/205"
session = requests.session()
session.proxies['http'] = 'socks5h://localhost:9050'
session.proxies['https'] = 'socks5h://localhost:9050'
soup=session_get_to_soup_wrapper(page_url,session)
page_to_tg(update,soup)
update.message.reply_text('Enter a valid magnet')
return TV_SHOW_D
def getMusics(bot,update):
print(update.message.text)
page_url="http://uj3wazyk5u4hnvtk.onion/search/"+update.message.text+"/0/99/101"
session = requests.session()
session.proxies['http'] = 'socks5h://localhost:9050'
session.proxies['https'] = 'socks5h://localhost:9050'
soup=session_get_to_soup_wrapper(page_url,session)
page_to_tg(update,soup)
update.message.reply_text('Enter a valid magnet')
return MUSIC_D
def download_movie_from_magnet(bot,update):
update.message.reply_text('DL started')
cmd="transmission-remote localhost:1234 --auth=user:passwords -w '/home/username/download/movies' -a "+ update.message.text
bot.send_message(chat_id=update.message.chat_id, text=check_output(cmd, stderr=subprocess.STDOUT, shell=True))
return ConversationHandler.END
def download_TVShow_from_magnet(bot,update):
update.message.reply_text('DL started')
cmd="transmission-remote localhost:1234 --auth=user:password -w '/home/username/download/series' -a "+ update.message.text
bot.send_message(chat_id=update.message.chat_id, text=check_output(cmd, stderr=subprocess.STDOUT, shell=True))
return ConversationHandler.END
def download_Music_from_magnet(bot,update):
update.message.reply_text('DL started')
cmd="transmission-remote localhost:1234 --auth=user:password -w '/home/username/download/Music' -a "+ update.message.text
bot.send_message(chat_id=update.message.chat_id, text=check_output(cmd, stderr=subprocess.STDOUT, shell=True))
return ConversationHandler.END
def cancel(bot,udpate):
return ConversationHandler.END
updater = Updater(token='')
dispatcher = updater.dispatcher
tpb_handler = ConversationHandler(
entry_points=[CommandHandler('tpb', tpb)],
states={
CATEGORY: [RegexHandler('^(Movie)$', goToMovie),
RegexHandler('^(TV_Show)$', goToTVShow),
RegexHandler('^(Music)$', goToMusic)],
MOVIE: [MessageHandler(Filters.text, getMovies)],
MOVIE_D: [RegexHandler('^(magnet:?)', download_movie_from_magnet)],
TV_SHOW: [MessageHandler(Filters.text, getTVShows)],
TV_SHOW_D: [RegexHandler('^(magnet:?)', download_TVShow_from_magnet)],
MUSIC: [MessageHandler(Filters.text, getMusics)],
MUSIC_D: [RegexHandler('^(magnet:?)', download_Music_from_magnet)]
},
fallbacks=[CommandHandler('cancel', cancel)]
)
dispatcher.add_handler(tpb_handler)
updater.start_polling()