website won't let me download anything unless I add a referer url, I did a dirty patch
I have not much idea on how to do a patch request, hopefully this is enough
diff --git a/subdivx/cli.py b/subdivx/cli.py
index 257b13a..d0aa6b0 100644
--- a/subdivx/cli.py
+++ b/subdivx/cli.py
@@ -129,7 +129,7 @@ def main():
continue
filename = os.path.basename(filepath)
-
+
try:
info = guessit(filename)
number = f"s{info['season']:02}e{info['episode']:02}" if info["type"] == "episode" else info["year"]
diff --git a/subdivx/lib.py b/subdivx/lib.py
index 95aa6e6..d6ad340 100644
--- a/subdivx/lib.py
+++ b/subdivx/lib.py
@@ -1,4 +1,4 @@
-import requests
+import requests
import logging
import logging.handlers
import os
@@ -19,6 +19,8 @@ SUBDIVX_DOWNLOAD_MATCHER = {'name':'a', 'rel':"nofollow", 'target': "new"}
LOGGER_LEVEL = logging.INFO
LOGGER_FORMATTER = logging.Formatter('%(asctime)-25s %(levelname)-8s %(name)-29s %(message)s', '%Y-%m-%d %H:%M:%S')
+s = requests.Session()
+
class NoResultsError(Exception):
pass
@@ -48,7 +50,7 @@ def get_subtitle_url(title, number, metadata, skip=0):
"oxdown": 1,
"buscar": buscar ,
}
- page = requests.get(SUBDIVX_SEARCH_URL, params=params).text
+ page = s.get(SUBDIVX_SEARCH_URL, params=params).text
soup = BeautifulSoup(page, 'html5lib')
titles = soup('div', id='menu_detalle_buscador')
@@ -84,7 +86,8 @@ def get_subtitle_url(title, number, metadata, skip=0):
# get subtitle page
url = results[0][0][1]
logger.info(f"Getting from {url}")
- page = requests.get(url).text
+ page = s.get(url).text
+ s.headers.update({"referer":url})
soup = BeautifulSoup(page, 'html5lib')
# get download link
return soup('a', {"class": "link1"})[0]["href"]
@@ -92,15 +95,15 @@ def get_subtitle_url(title, number, metadata, skip=0):
def get_subtitle(url, path):
temp_file = NamedTemporaryFile()
- temp_file.write(requests.get(url).content)
+ logger.info(f"downloading http://www.subdivx.com/{url}")
+ temp_file.write(s.get('http://www.subdivx.com/' + url).content)
temp_file.seek(0)
-
if is_zipfile(temp_file.name):
zip_file = ZipFile(temp_file)
- for name in zip_file.namelist():
+ for name in zip_file.infolist():
# don't unzip stub __MACOSX folders
- if '.srt' in name and '__MACOSX' not in name:
- logger.info(' '.join(['Unpacking zipped subtitle', name, 'to', os.path.dirname(path)]))
+ if '.srt' in name.filename and '__MACOSX' not in name.filename:
+ logger.info(' '.join(['Unpacking zipped subtitle', name.filename, 'to', os.path.dirname(path)]))
zip_file.extract(name, os.path.dirname(path))
zip_file.close()
@@ -121,4 +124,8 @@ def get_subtitle(url, path):
except OSError:
logger.info('Unpacking rared subtitle failed.'
'Please, install unrar to automate this step.')
+ else:
+ logger.info(f"unknown file type")
+
+
temp_file.close()
website won't let me download anything unless I add a referer url, I did a dirty patch I have not much idea on how to do a patch request, hopefully this is enough