Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix subscene #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions periscope/plugins/SubScene.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with periscope; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

import zipfile, os, urllib2, urllib, logging, traceback, httplib
import zipfile, os, urllib2, urllib, logging, traceback, httplib, requests, sys
from BeautifulSoup import BeautifulSoup

import SubtitleDatabase
Expand Down Expand Up @@ -63,8 +63,7 @@ class SubScene(SubtitleDatabase.SubtitleDB):

def __init__(self, config, cache_folder_path):
super(SubScene, self).__init__(SS_LANGUAGES)
#http://subscene.com/s.aspx?subtitle=Dexter.S04E01.HDTV.XviD-NoTV
self.host = "http://subscene.com/s.aspx?subtitle="
self.host = "http://v2.subscene.com/s.aspx?subtitle="

def process(self, filepath, langs):
''' main method to call on the plugin, pass the filename and the wished
Expand Down Expand Up @@ -92,11 +91,12 @@ def createFile(self, subtitle):
soup = BeautifulSoup(page)

dlhref = soup.find("div", {"class" : "download"}).find("a")["href"]
subtitle["link"] = "http://subscene.com" + dlhref.split('"')[7]
subtitle["link"] = "http://subscene.com" + dlhref
format = "zip"
archivefilename = subtitle["filename"].rsplit(".", 1)[0] + '.'+ format
self.downloadFile(subtitle["link"], archivefilename)

archivefilename = self.downloadFile(subtitle["link"], None)
subtitlefilename = None
srtbasefilename = subtitle['release']

if zipfile.is_zipfile(archivefilename):
logging.debug("Unzipping file " + archivefilename)
Expand Down Expand Up @@ -134,7 +134,7 @@ def createFile(self, subtitle):
# exit
return subtitlefilename
except OSError, e:
logging.error("Execution failed: %s" %e)
logging.error("Execution failed: %s" %e)
return None

else:
Expand All @@ -143,20 +143,25 @@ def createFile(self, subtitle):

def downloadFile(self, url, filename):
''' Downloads the given url to the given filename '''
logging.info("Downloading file %s" %url)
req = urllib2.Request(url, headers={'Referer' : url, 'User-Agent' : 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3)'})

f = urllib2.urlopen(req, data=urllib.urlencode({'__EVENTTARGET' : 's$lc$bcr$downloadLink', '__EVENTARGUMENT' : '', '__VIEWSTATE' : '/wEPDwUHNzUxOTkwNWRk4wau5efPqhlBJJlOkKKHN8FIS04='}))
filename = 'subtitle.zip'
dump = open(filename, "wb")
try:
f.read(1000000)
except httplib.IncompleteRead, e:
dump.write(e.partial)
logging.warn('Incomplete read for %s ... Trying anyway to decompress.' %url)
dump.close()
f.close()

#SubtitleDatabase.SubtitleDB.downloadFile(self, req, filename)
response = requests.get(url, stream = True)
with open('subtitle.zip', 'wb') as out_file:
fsrc = response.raw
size = response.headers.get("content-length")
length = 16*1024
while True:
buf = fsrc.read(length)
if not buf:
break
out_file.write(buf)
sys.stdout.write("Downloaded " +
str(os.path.getsize(filename)/1024) + "kb of " + str(int(size)/1024) + " kb\r")
sys.stdout.flush()
print "\nDownload complete\nExtracting"
del response
return filename

def query(self, token, langs=None):
''' makes a query on subscene and returns info (link, lang) about found subtitles'''
Expand All @@ -173,7 +178,6 @@ def query(self, token, langs=None):
release_span = lang_span.findNext("span")
release = release_span.contents[0].strip().split(" (")[0]
sub_page = subs["href"]
#http://subscene.com//s-dlpath-260016/78348/rar.zipx
if release.startswith(token) and (not langs or lang in langs):
result = {}
result["release"] = release
Expand Down
3 changes: 1 addition & 2 deletions periscope/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@

#from SubtitleSource import SubtitleSource # require a key in the config file

# Not working anymore (download fails)
#from SubScene import SubScene
from SubScene import SubScene

# Don't want to be included
#from Addic7ed import Addic7ed
Expand Down
Loading