-
-
Notifications
You must be signed in to change notification settings - Fork 311
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
0.7.x #404
0.7.x #404
Changes from 25 commits
3b832a4
e6dc714
14c7443
71d206a
73a4e5a
3b52a93
88a2cb9
4702284
1e9588e
827c75f
6cdf189
87aefa3
90d06e2
d635269
3c7634f
bc575ea
7fef3cf
e6bd704
d45e3b0
a25640b
3acbefb
6c28336
e45fe70
a86694d
1b7291e
c74aa01
16ddb8a
407cbe1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
beautifulsoup4>=4.3.2 | ||
guessit>=0.6.2,<0.7 | ||
guessit>=0.7,<0.10 | ||
requests>=2.0.1 | ||
enzyme>=0.4.0 | ||
html5lib>=0.99 | ||
dogpile.cache>=0.5.2 | ||
babelfish>=0.4.0,<0.5 | ||
babelfish>=0.5.0 | ||
charade>=1.0.3 | ||
pysrt>=0.5.0 |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,10 @@ | |
import charade | ||
import requests | ||
from . import Provider | ||
from . import IGNORED_CHARACTERS_RE | ||
from .. import __version__ | ||
from ..cache import region | ||
from ..api import RANDOM_USER_AGENT | ||
from ..exceptions import ProviderConfigurationError, ProviderNotAvailable, InvalidSubtitle | ||
from ..subtitle import Subtitle, is_valid_subtitle | ||
from ..video import Episode | ||
|
@@ -53,49 +55,21 @@ def compute_matches(self, video): | |
|
||
|
||
class Addic7edProvider(Provider): | ||
languages = {babelfish.Language('por', 'BR')} | {babelfish.Language(l) | ||
languages = set([babelfish.Language('por', 'BR')]) | set([babelfish.Language(l) | ||
for l in ['ara', 'aze', 'ben', 'bos', 'bul', 'cat', 'ces', 'dan', 'deu', 'ell', 'eng', 'eus', 'fas', | ||
'fin', 'fra', 'glg', 'heb', 'hrv', 'hun', 'hye', 'ind', 'ita', 'jpn', 'kor', 'mkd', 'msa', | ||
'nld', 'nor', 'pol', 'por', 'ron', 'rus', 'slk', 'slv', 'spa', 'sqi', 'srp', 'swe', 'tha', | ||
'tur', 'ukr', 'vie', 'zho']} | ||
'tur', 'ukr', 'vie', 'zho']]) | ||
video_types = (Episode,) | ||
server = 'http://www.addic7ed.com' | ||
|
||
def __init__(self, username=None, password=None): | ||
if username is not None and password is None or username is None and password is not None: | ||
raise ProviderConfigurationError('Username and password must be specified') | ||
self.username = username | ||
self.password = password | ||
self.logged_in = False | ||
|
||
def initialize(self): | ||
self.session = requests.Session() | ||
self.session.headers = {'User-Agent': 'Subliminal/%s' % __version__} | ||
# login | ||
if self.username is not None and self.password is not None: | ||
logger.debug('Logging in') | ||
data = {'username': self.username, 'password': self.password, 'Submit': 'Log in'} | ||
try: | ||
r = self.session.post(self.server + '/dologin.php', data, timeout=10, allow_redirects=False) | ||
except requests.Timeout: | ||
raise ProviderNotAvailable('Timeout after 10 seconds') | ||
if r.status_code == 302: | ||
logger.info('Logged in') | ||
self.logged_in = True | ||
else: | ||
logger.error('Failed to login') | ||
|
||
def terminate(self): | ||
# logout | ||
if self.logged_in: | ||
try: | ||
r = self.session.get(self.server + '/logout.php', timeout=10) | ||
logger.info('Logged out') | ||
except requests.Timeout: | ||
raise ProviderNotAvailable('Timeout after 10 seconds') | ||
if r.status_code != 200: | ||
raise ProviderNotAvailable('Request failed with status code %d' % r.status_code) | ||
self.session.close() | ||
#self.session.headers = {'User-Agent': 'Subliminal/%s' % __version__} | ||
self.session.headers = { | ||
'User-Agent': RANDOM_USER_AGENT, | ||
'Referer': self.server, | ||
} | ||
|
||
def get(self, url, params=None): | ||
"""Make a GET request on `url` with the given parameters | ||
|
@@ -108,7 +82,7 @@ def get(self, url, params=None): | |
|
||
""" | ||
try: | ||
r = self.session.get(self.server + url, params=params, timeout=10) | ||
r = self.session.get(self.server + url, params=params, timeout=30) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think 10s timeout is plenty, if the provider doesn't respond by then, they are experiencing serious trouble. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think i had a failure one day and got lazy and changed the value; i'll flip it back (in both cases you pointed out) |
||
except requests.Timeout: | ||
raise ProviderNotAvailable('Timeout after 10 seconds') | ||
if r.status_code != 200: | ||
|
@@ -126,7 +100,9 @@ def get_show_ids(self): | |
soup = self.get('/shows.php') | ||
show_ids = {} | ||
for html_show in soup.select('td.version > h3 > a[href^="/show/"]'): | ||
show_ids[html_show.string.lower()] = int(html_show['href'][6:]) | ||
show_ids[ | ||
IGNORED_CHARACTERS_RE.sub('', html_show.string).lower()] = \ | ||
int(html_show['href'][6:]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should rename |
||
return show_ids | ||
|
||
@region.cache_on_arguments() | ||
|
@@ -150,10 +126,11 @@ def find_show_id(self, series): | |
|
||
def query(self, series, season): | ||
show_ids = self.get_show_ids() | ||
if series.lower() in show_ids: | ||
show_id = show_ids[series.lower()] | ||
_series = IGNORED_CHARACTERS_RE.sub('', series).lower() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This name is confusing, please make this explicit such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense; i totally agree with the naming convention your suggestion. Will change (all references you pointed out) |
||
if _series in show_ids: | ||
show_id = show_ids[_series] | ||
else: | ||
show_id = self.find_show_id(series.lower()) | ||
show_id = self.find_show_id(_series) | ||
if show_id is None: | ||
return [] | ||
params = {'show_id': show_id, 'season': season} | ||
|
@@ -180,7 +157,7 @@ def list_subtitles(self, video, languages): | |
|
||
def download_subtitle(self, subtitle): | ||
try: | ||
r = self.session.get(self.server + subtitle.download_link, timeout=10, | ||
r = self.session.get(self.server + subtitle.download_link, timeout=30, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about the timeout here. |
||
headers={'Referer': self.server + subtitle.referer}) | ||
except requests.Timeout: | ||
raise ProviderNotAvailable('Timeout after 10 seconds') | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use a random user agent here? I'm generally against this because servers should be allowed to block subliminal activity. Although I don't want them too, it should be possible. We should contact the provider to know the reason why they would want to block us and have an agreement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree with you but Addic7ted has recently blocked all access their site 'unless' we do this. I even forked my nzbget-subliminal code into using the name nokarma and explain here why. It is part of my later commits to this branch.
In short, I've attempted to make contact with them and after a week (now it's been about 3) without hearing back from them; i just did this dirty move so we could still use the provider. I can roll this back if you want; it will break this provider though (see #428).