Skip to content

Commit

Permalink
Merge remote-tracking branch 'SickRage/develop' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	sickbeard/network_timezones.py
#	sickbeard/webserve.py
  • Loading branch information
labrys committed Feb 28, 2016
2 parents 99c4013 + 56bcece commit b6d0586
Show file tree
Hide file tree
Showing 21 changed files with 61 additions and 56 deletions.
File renamed without changes
8 changes: 7 additions & 1 deletion sickbeard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
# pylint: disable=too-many-lines

import webbrowser
import datetime
import socket
import os
Expand Down Expand Up @@ -2177,6 +2176,13 @@ def save_config(): # pylint: disable=too-many-statements, too-many-branches


def launchBrowser(protocol='http', startPort=None, web_root='/'):

try:
import webbrowser
except ImportError:
logger.log(u"Unable to load the webbrowser module, cannot launch the browser.", logger.WARNING)
return

if not startPort:
startPort = WEB_PORT

Expand Down
4 changes: 2 additions & 2 deletions sickbeard/clients/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from base64 import b16encode, b32decode

import sickbeard
from sickbeard import logger
from sickbeard import logger, helpers
from bencode import bencode, bdecode
import requests
import cookielib
Expand All @@ -27,7 +27,7 @@ def __init__(self, name, host=None, username=None, password=None):
self.response = None
self.auth = None
self.last_time = time.time()
self.session = requests.Session()
self.session = helpers.make_session()
self.session.auth = (self.username, self.password)
self.session.cookies = cookielib.CookieJar()

Expand Down
15 changes: 11 additions & 4 deletions sickbeard/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
from sickrage.helper.exceptions import ex
from sickrage.show.Show import Show
from cachecontrol import CacheControl
# from httpcache import CachingHTTPAdapter

from itertools import izip, cycle

import shutil
Expand Down Expand Up @@ -1381,6 +1383,14 @@ def _getTempDir():
return ek(os.path.join, tempfile.gettempdir(), "sickrage-%s" % uid)


def make_session():
session = requests.Session()
# session.mount('http://', CachingHTTPAdapter())
# session.mount('http://', CachingHTTPAdapter())
session = CacheControl(sess=session, cache_etags=True)
return session


def _setUpSession(session, headers):
"""
Returns a session initialized with default cache and parameter settings
Expand All @@ -1390,9 +1400,6 @@ def _setUpSession(session, headers):
:return: session object
"""

# request session
session = CacheControl(sess=session, cache_etags=True)

# request session clear residual referer
# pylint: disable=superfluous-parens
# These extra parens are necessary!
Expand Down Expand Up @@ -1760,7 +1767,7 @@ def getDiskSpaceUsage(diskPath=None):

def getTVDBFromID(indexer_id, indexer): # pylint:disable=too-many-return-statements

session = requests.Session()
session = make_session()
tvdb_id = ''
if indexer == 'IMDB':
url = "http://www.thetvdb.com/api/GetSeriesByRemoteID.php?imdbid=%s" % indexer_id
Expand Down
3 changes: 1 addition & 2 deletions sickbeard/imdbPopular.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import re
import os
import posixpath
import requests
from bs4 import BeautifulSoup
from datetime import date

Expand All @@ -25,7 +24,7 @@ def __init__(self):
'year': '%s,%s' % (date.today().year - 1, date.today().year + 1)
}

self.session = requests.Session()
self.session = helpers.make_session()

def fetch_popular_shows(self):
"""Get popular show information from IMDB"""
Expand Down
31 changes: 17 additions & 14 deletions sickbeard/indexers/indexer_config.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# coding=utf-8

from tvdb_api.tvdb_api import Tvdb
import requests
from sickbeard import helpers

initConfig = {
'valid_languages': ["da", "fi", "nl", "de", "it", "es", "fr", "pl", "hu", "el", "tr",
"ru", "he", "ja", "pt", "zh", "cs", "sl", "hr", "ko", "en", "sv", "no"
],
'langabbv_to_id': {'el': 20, 'en': 7, 'zh': 27,
'it': 15, 'cs': 28, 'es': 16, 'ru': 22, 'nl': 13, 'pt': 26, 'no': 9,
'tr': 21, 'pl': 18, 'fr': 17, 'hr': 31, 'de': 14, 'da': 10, 'fi': 11,
'hu': 19, 'ja': 25, 'he': 24, 'ko': 32, 'sv': 8, 'sl': 30
}
'valid_languages': [
"da", "fi", "nl", "de", "it", "es", "fr", "pl", "hu", "el", "tr",
"ru", "he", "ja", "pt", "zh", "cs", "sl", "hr", "ko", "en", "sv", "no"
],
'langabbv_to_id': {
'el': 20, 'en': 7, 'zh': 27,
'it': 15, 'cs': 28, 'es': 16, 'ru': 22, 'nl': 13, 'pt': 26, 'no': 9,
'tr': 21, 'pl': 18, 'fr': 17, 'hr': 31, 'de': 14, 'da': 10, 'fi': 11,
'hu': 19, 'ja': 25, 'he': 24, 'ko': 32, 'sv': 8, 'sl': 30
}
}

INDEXER_TVDB = 1
Expand All @@ -22,11 +24,12 @@
'id': INDEXER_TVDB,
'name': 'theTVDB',
'module': Tvdb,
'api_params': {'apikey': 'F9C450E78D99172E',
'language': 'en',
'useZip': True,
},
'session': requests.Session(),
'api_params': {
'apikey': 'F9C450E78D99172E',
'language': 'en',
'useZip': True,
},
'session': helpers.make_session(),
'trakt_id': 'tvdb_id',
'xem_origin': 'tvdb',
'icon': 'thetvdb16.png',
Expand Down
3 changes: 1 addition & 2 deletions sickbeard/metadata/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@

from sickbeard import helpers
from sickbeard import logger
import requests

meta_session = requests.Session()
meta_session = helpers.make_session()


def getShowImage(url, imgNum=None):
Expand Down
5 changes: 2 additions & 3 deletions sickbeard/network_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import re
import datetime
import requests
from dateutil import tz

from sickbeard import db
Expand All @@ -39,8 +38,8 @@
def update_network_dict():
"""Update timezone information from SR repositories"""

url = 'https://raw.githubusercontent.com/pymedusa/sickrage.github.io/master/sb_network_timezones/network_timezones.txt'
url_data = helpers.getURL(url, session=requests.Session(), returns='text')
url = 'http://raw.githubusercontent.com/pymedusa/sickrage.github.io/master/sb_network_timezones/network_timezones.txt'
url_data = helpers.getURL(url, session=helpers.make_session(), returns='text')
if not url_data:
logger.log(u'Updating network timezones failed, this can happen from time to time. URL: %s' % url, logger.WARNING)
load_network_dict()
Expand Down
5 changes: 2 additions & 3 deletions sickbeard/notifiers/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.

import re
import requests
try:
import xml.etree.cElementTree as etree
except ImportError:
import xml.etree.ElementTree as etree

import sickbeard
from sickbeard import logger, common
from sickbeard.helpers import getURL
from sickbeard.helpers import getURL, make_session

from sickrage.helper.exceptions import ex

Expand All @@ -40,7 +39,7 @@ def __init__(self):
'X-Plex-Client-Identifier': sickbeard.common.USER_AGENT,
'X-Plex-Version': '2016.02.10'
}
self.session = requests.Session()
self.session = make_session()

@staticmethod
def _notify_pht(message, title='SickRage', host=None, username=None, password=None, force=False): # pylint: disable=too-many-arguments
Expand Down
5 changes: 2 additions & 3 deletions sickbeard/notifiers/pushbullet.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.

import json
import requests
import traceback

import sickbeard
from sickbeard import logger
from sickbeard import logger, helpers
from sickbeard.common import notifyStrings
from sickbeard.common import NOTIFY_SNATCH
from sickbeard.common import NOTIFY_DOWNLOAD
Expand All @@ -35,7 +34,7 @@


class Notifier(object):
session = requests.Session()
session = helpers.make_session()
TEST_EVENT = 'Test'

def __init__(self):
Expand Down
3 changes: 1 addition & 2 deletions sickbeard/nzbSplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

# pylint: disable=line-too-long

import requests # pylint: disable=import-error
import re

try:
Expand Down Expand Up @@ -150,7 +149,7 @@ def split_result(obj):
:param obj: to search for results
:return: a list of episode objects or an empty list
"""
url_data = helpers.getURL(obj.url, session=requests.Session(), returns='content')
url_data = helpers.getURL(obj.url, session=helpers.make_session(), returns='content')
if url_data is None:
logger.log(u"Unable to load url " + obj.url + ", can't download season NZB", logger.ERROR)
return []
Expand Down
2 changes: 1 addition & 1 deletion sickbeard/postProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def _int_copy(cur_file_path, new_file_path):
helpers.copyFile(cur_file_path, new_file_path)
helpers.chmodAsParent(new_file_path)
except (IOError, OSError) as e:
logger.log(u"Unable to copy file " + cur_file_path + " to " + new_file_path + ": " + ex(e), logger.ERROR)
self._log(u"Unable to copy file " + cur_file_path + " to " + new_file_path + ": " + ex(e), logger.ERROR)
raise

self._combined_file_operation(file_path, new_path, new_base_name, associated_files, action=_int_copy,
Expand Down
4 changes: 1 addition & 3 deletions sickbeard/scene_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ def _anidb_exceptions_fetcher():
setLastRefresh('anidb')
return anidb_exception_dict


xem_session = requests.Session()

xem_session = helpers.make_session()

def _xem_exceptions_fetcher():
if shouldRefresh('xem'):
Expand Down
2 changes: 1 addition & 1 deletion sickbeard/showUpdater.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self):
self.lock = threading.Lock()
self.amActive = False

self.session = requests.Session()
self.session = helpers.make_session()

def run(self, force=False): # pylint: disable=unused-argument, too-many-locals, too-many-branches, too-many-statements

Expand Down
5 changes: 2 additions & 3 deletions sickbeard/versionChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import traceback
import time
import datetime
import requests
import shutil
import shutil_custom

Expand Down Expand Up @@ -58,7 +57,7 @@ def __init__(self):
elif self.install_type == 'source':
self.updater = SourceUpdateManager()

self.session = requests.Session()
self.session = helpers.make_session()

def run(self, force=False):

Expand Down Expand Up @@ -701,7 +700,7 @@ def __init__(self):
self._newest_commit_hash = None
self._num_commits_behind = 0

self.session = requests.Session()
self.session = helpers.make_session()

@staticmethod
def _find_installed_branch():
Expand Down
4 changes: 2 additions & 2 deletions sickbeard/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ def getDBcompare():
def displayShow(self, show=None):
# todo: add more comprehensive show validation
try:
show = int(show) # fails if show id ends in a period PyMedusa/SickRage-issues#65
show = int(show) # fails if show id ends in a period SickRage/sickrage-issues#65
showObj = Show.find(sickbeard.showList, show)
except (ValueError, TypeError):
return self._genericMessage("Error", "Invalid show ID: %s" % str(show))
Expand Down Expand Up @@ -2241,7 +2241,7 @@ def index(self):
changes = helpers.getURL('https://api.pymedusa.com/changelog.md', session=requests.Session(), returns='text')
except Exception:
logger.log(u'Could not load changes from repo, giving a link!', logger.DEBUG)
changes = 'Could not load changes from the repo. [Click here for CHANGES.md](https://raw.githubusercontent.com/pymedusa/sickrage.github.io/master/sickrage-news/CHANGES.md)'
changes = 'Could not load changes from the repo. [Click here for CHANGES.md](https://api.pymedusa.com/CHANGES.md)'

t = PageTemplate(rh=self, filename="markdown.mako")
data = markdown2.markdown(changes if changes else "The was a problem connecting to github, please refresh and try again", extras=['header-ids'])
Expand Down
7 changes: 4 additions & 3 deletions sickrage/show/recommendations/anidb.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# coding=utf-8
import requests
from anidbhttp import anidbquery
from anidbhttp.query import QUERY_HOT
from sickbeard import helpers
from sickrage.helper.common import try_int

from recommended import RecommendedShow


class AnidbPopular(object):
def __init__(self):
self.cache_subfolder = __name__.split('.')[-1] if '.' in __name__ else __name__
self.session = requests.Session()
self.session = helpers.make_session()

def fetch_latest_hot_shows(self):
"""Get popular show information from IMDB"""
Expand All @@ -21,7 +22,7 @@ def fetch_latest_hot_shows(self):
for show in shows:
try:
recommended_show = RecommendedShow(show.id, show.titles['x-jat'][0], 1, show.tvdbid, cache_subfolder=self.cache_subfolder,
rating=str(show.ratings['temporary']['rating']), votes=str(try_int(show.ratings['temporary']['count'],0)), image_href=show.url)
rating=str(show.ratings['temporary']['rating']), votes=str(try_int(show.ratings['temporary']['count'], 0)), image_href=show.url)

# Check cache or get and save image
recommended_show.cache_image("http://img7.anidb.net/pics/anime/{0}".format(show.image_path))
Expand Down
3 changes: 1 addition & 2 deletions sickrage/show/recommendations/imdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import re
import os
import posixpath
import requests
from bs4 import BeautifulSoup
from datetime import date

Expand All @@ -25,7 +24,7 @@ def __init__(self):
'year': '%s,%s' % (date.today().year - 1, date.today().year + 1)
}

self.session = requests.Session()
self.session = helpers.make_session()

def fetch_popular_shows(self):
"""Get popular show information from IMDB"""
Expand Down
3 changes: 1 addition & 2 deletions sickrage/show/recommendations/recommended.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import os
import posixpath
import requests

import sickbeard
from sickbeard import helpers
Expand Down Expand Up @@ -62,7 +61,7 @@ def __init__(self, show_id, title, indexer, indexer_id, cache_subfolder=u'recomm

# Check if the show is currently already in the db
self.show_in_list = self.indexer_id in {show.indexerid for show in sickbeard.showList if show.indexerid}
self.session = requests.Session()
self.session = helpers.make_session()

def cache_image(self, image_url):
"""
Expand Down
5 changes: 2 additions & 3 deletions tests/torrent_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from bs4 import BeautifulSoup
from sickbeard.helpers import getURL
from sickbeard.helpers import getURL, make_session
from sickbeard.providers.bitcannon import BitCannonProvider
from sickbeard.tv import TVEpisode, TVShow
import requests # pylint: disable=import-error
import tests.test_lib as test
import urlparse

Expand Down Expand Up @@ -81,7 +80,7 @@ def test_search(): # pylint: disable=too-many-locals
url = 'http://kickass.to/'
search_url = 'http://kickass.to/usearch/American%20Dad%21%20S08%20-S08E%20category%3Atv/?field=seeders&sorder=desc'

html = getURL(search_url, session=requests.Session(), returns='text')
html = getURL(search_url, session=make_session(), returns='text')
if not html:
return

Expand Down

0 comments on commit b6d0586

Please sign in to comment.