-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsbt.py
94 lines (85 loc) · 2.68 KB
/
sbt.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
#!/usr/bin/env python
#PD_SubsRETR : Fetch Movies Subtitles with One click!
#Creator / Developer Name : Priyadharshan Saba
#Script : Shell Script, Python, Apple Scripts
#Python Dependencis: mechanize : https://pypi.python.org/pypi/mechanize/
# BeautifulSoup4 : https://pypi.python.org/pypi/beautifulsoup4
#Runtime : Python 2
#OS Requirements: Mac OSX , macOS
import imp
import sys
import os
def name():
i=0
mname=""
nam=""
row_count=0
for x in sys.argv:
x=x.split(" ")
for i in x:
if row_count>=1:
mname=mname+str(i)+" "
row_count+=1
mname=nam+mname
mname=mname.strip()
return mname
def openBots(name):
try:
sys.path.append("/usr/local/lib/python2.7/site-packages")
import mechanize
from bs4 import BeautifulSoup
except:
sys.exit()
name=name.strip().lower()
name=name.split('.')
name=name[0]
try:
br = mechanize.Browser()
br.set_handle_robots(False)
op=br.open("http://www.yifysubtitles.com")
br.select_form(nr=0)
br.form['q']=name
sub = br.submit()
soup = BeautifulSoup(sub.read(),"lxml")
row_count=0
for div in soup.findAll('div',{'class':'col-sm-12'}):
row_count+=1
if row_count==1:
dd=div.find('div',{'class':'media-body'})
di=dd.find('a')
fnam = di.text.strip().lower().split("\n")
link=di['href']
elif row_count>1:
break
op=br.open(link)
soup = BeautifulSoup(op.read(),"lxml")
row_count=0
for table in soup.findAll('table',{'class':'table other-subs'}):
for td in table.findAll('td',{'class':'flag-cell'}):
row_count+=1
if td.text.lower().strip() == "english":
break
for table in soup.findAll('table',{'class':'table other-subs'}):
rc=0
row_count= (row_count*3) - 3
for a in table.findAll('a'):
if rc==row_count:
link1 = a['href']
break
else:
rc+=1
op=br.open(link1)
soup = BeautifulSoup(op.read(),"lxml")
row_count=0
for div in soup.findAll('div',{'class':'col-xs-12'}):
if row_count==2:
x= div.text.split('\n')
fnam = x[1].strip()+".srt"
row_count+=1
for a in soup.findAll('a',{'class':'btn-icon download-subtitle'}):
down_link= a['href']
br.retrieve(down_link,fnam)
except:
sys.exit()
mname=name()
openBots(mname)