desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'expose the api-builder template'
| @cherrypy.expose
def builder(self):
| t = webserve.PageTemplate(file='apiBuilder.tmpl')
def titler(x):
if (not x):
return x
if ((not x.lower().startswith('a to ')) and x.lower().startswith('a ')):
x = x[2:]
elif x.lower().startswith('an '):
x = x[3:]
elif x.lower().star... |
'set cherrypy response to json'
| def _out_as_json(self, dict):
| response = cherrypy.response
request = cherrypy.request
response.headers['Content-Type'] = 'application/json;charset=UTF-8'
try:
out = json.dumps(dict, indent=self.intent, sort_keys=True)
callback = (request.params.get('callback') or request.params.get('jsonp'))
if (callback is n... |
'validate api key and log result'
| def _grand_access(self, realKey, args, kwargs):
| remoteIp = cherrypy.request.remote.ip
apiKey = kwargs.get('apikey', None)
if (not apiKey):
if args:
apiKey = args[0]
args = args[1:]
else:
del kwargs['apikey']
if (sickbeard.USE_API is not True):
msg = ((u'API :: ' + remoteIp) + ' - SB A... |
'function to check passed params for the shorthand wrapper
and to detect missing/required param'
| def check_params(self, args, kwargs, key, default, required, type, allowedValues):
| missing = True
orgDefault = default
if (type == 'bool'):
allowedValues = [0, 1]
if args:
default = args[0]
missing = False
args = args[1:]
if kwargs.get(key):
default = kwargs.get(key)
missing = False
if required:
try:
self._mis... |
'checks if value can be converted / parsed to type
will raise an error on failure
or will convert it to type and return new converted value
can check for:
- int: will be converted into int
- bool: will be converted to False / True
- list: will always return a list
- string: will do nothing for now
- ignore: will ignore... | def _check_param_type(self, value, name, type):
| error = False
if (type == 'int'):
if _is_int(value):
value = int(value)
else:
error = True
elif (type == 'bool'):
if (value in ('0', '1')):
value = bool(int(value))
elif (value in ('true', 'True', 'TRUE')):
value = True
... |
'will check if value (or all values in it ) are in allowed values
will raise an exception if value is "out of range"
if bool(allowedValue) == False a check is not performed and all values are excepted'
| def _check_param_value(self, value, name, allowedValues):
| if allowedValues:
error = False
if isinstance(value, list):
for item in value:
if (not (item in allowedValues)):
error = True
elif (not (value in allowedValues)):
error = True
if error:
raise ApiError(((((((u"par... |
'internal function wrapper'
| def run(self):
| args = ((self.sid,) + self.origArgs)
if self.e:
return CMD_Episode(args, self.kwargs).run()
elif self.s:
return CMD_ShowSeasons(args, self.kwargs).run()
else:
return CMD_Show(args, self.kwargs).run()
|
'display help information for a given subject/command'
| def run(self):
| if (self.subject in _functionMaper):
out = _responds(RESULT_SUCCESS, _functionMaper.get(self.subject)((), {'help': 1}).run())
else:
out = _responds(RESULT_FAILURE, msg='No such cmd')
return out
|
'display the coming episodes'
| def run(self):
| today = datetime.date.today().toordinal()
next_week = (datetime.date.today() + datetime.timedelta(days=7)).toordinal()
recently = (datetime.date.today() - datetime.timedelta(days=3)).toordinal()
done_show_list = []
qualList = ((Quality.DOWNLOADED + Quality.SNATCHED) + [ARCHIVED, IGNORED])
myDB =... |
'display detailed info about an episode'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if (not showObj):
return _responds(RESULT_FAILURE, msg='Show not found')
myDB = db.DBConnection(row_type='dict')
sqlResults = myDB.select('SELECT name, description, airdate, status, location, ... |
'search for an episode'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if (not showObj):
return _responds(RESULT_FAILURE, msg='Show not found')
epObj = showObj.getEpisode(int(self.s), int(self.e))
if isinstance(epObj, str):
return _responds(RESULT_FAILURE, msg='Episode ... |
'set status of an episode or a season (when no ep is provided)'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if (not showObj):
return _responds(RESULT_FAILURE, msg='Show not found')
for status in statusStrings.statusStrings:
if (str(statusStrings[status]).lower() == str(self.status).lower()):
self.st... |
'display scene exceptions for all or a given show'
| def run(self):
| myDB = db.DBConnection('cache.db', row_type='dict')
if (self.tvdbid is None):
sqlResults = myDB.select("SELECT show_name, tvdb_id AS 'tvdbid' FROM scene_exceptions")
scene_exceptions = {}
for row in sqlResults:
tvdbid = row['tvdbid']
if (not (tvd... |
'display sickbeard downloaded/snatched history'
| def run(self):
| typeCodes = []
if (self.type == 'downloaded'):
self.type = 'Downloaded'
typeCodes = Quality.DOWNLOADED
elif (self.type == 'snatched'):
self.type = 'Snatched'
typeCodes = Quality.SNATCHED
else:
typeCodes = (Quality.SNATCHED + Quality.DOWNLOADED)
myDB = db.DBCon... |
'clear sickbeard\'s history'
| def run(self):
| myDB = db.DBConnection()
myDB.action('DELETE FROM history WHERE 1=1')
myDB.action('VACUUM')
myDB.connection.close()
return _responds(RESULT_SUCCESS, msg='History cleared')
|
'trim sickbeard\'s history'
| def run(self):
| myDB = db.DBConnection()
myDB.action(('DELETE FROM history WHERE date < ' + str((datetime.datetime.today() - datetime.timedelta(days=30)).strftime(history.dateFormat))))
myDB.action('VACUUM')
myDB.connection.close()
return _responds(RESULT_SUCCESS, msg='Removed history entrie... |
'view sickbeard\'s log'
| def run(self):
| minLevel = logger.reverseNames[str(self.min_level).upper()]
data = []
if os.path.isfile(logger.sb_log_instance.log_file_path):
with ek.ek(open, logger.sb_log_instance.log_file_path) as f:
data = f.readlines()
regex = '^(\\d\\d\\d\\d)\\-(\\d\\d)\\-(\\d\\d)\\s*(\\d\\d)\\:(\\d\\d):(\\d\... |
'Starts the postprocess'
| def run(self):
| pp_options = {}
if ((not self.path) and (not sickbeard.TV_DOWNLOAD_DIR)):
return _responds(RESULT_FAILURE, msg='You need to provide a path or set TV Download Dir')
if (not self.path):
self.path = sickbeard.TV_DOWNLOAD_DIR
if bool(self.force_replace):
... |
'display misc sickbeard related information'
| def run(self):
| data = {'sb_version': sickbeard.version.SICKBEARD_VERSION, 'api_version': Api.version, 'api_commands': sorted(_functionMaper.keys())}
return _responds(RESULT_SUCCESS, data)
|
'add a parent directory to sickbeard\'s config'
| def run(self):
| self.location = urllib.unquote_plus(self.location)
location_matched = 0
if (not ek.ek(os.path.isdir, self.location)):
return _responds(RESULT_FAILURE, msg='Location is invalid')
root_dirs = []
if (sickbeard.ROOT_DIRS == ''):
self.default = 1
else:
root_dirs = sickbe... |
'query the scheduler'
| def run(self):
| myDB = db.DBConnection()
sqlResults = myDB.select('SELECT last_backlog FROM info')
backlogPaused = sickbeard.searchQueueScheduler.action.is_backlog_paused()
backlogRunning = sickbeard.searchQueueScheduler.action.is_backlog_in_progress()
searchStatus = sickbeard.currentSearchScheduler.action... |
'delete a parent directory from sickbeard\'s config'
| def run(self):
| if (sickbeard.ROOT_DIRS == ''):
return _responds(RESULT_FAILURE, _getRootDirs(), msg='No root directories detected')
root_dirs_new = []
root_dirs = sickbeard.ROOT_DIRS.split('|')
index = int(root_dirs[0])
root_dirs.pop(0)
root_dirs = [urllib.unquote_plus(x) for x in root_dirs]
... |
'force the episode search early'
| def run(self):
| result = sickbeard.currentSearchScheduler.forceRun()
if result:
return _responds(RESULT_SUCCESS, msg='Episode search forced')
return _responds(RESULT_FAILURE, msg='Can not search for episode')
|
'get sickbeard user defaults'
| def run(self):
| (anyQualities, bestQualities) = _mapQuality(sickbeard.QUALITY_DEFAULT)
data = {'status': statusStrings[sickbeard.STATUS_DEFAULT].lower(), 'flatten_folders': int(sickbeard.FLATTEN_FOLDERS_DEFAULT), 'initial': anyQualities, 'archive': bestQualities, 'future_show_paused': int(sickbeard.COMING_EPS_DISPLAY_PAUSED)}
... |
'get the parent directories defined in sickbeard\'s config'
| def run(self):
| return _responds(RESULT_SUCCESS, _getRootDirs())
|
'pause the backlog search'
| def run(self):
| if (self.pause is True):
sickbeard.searchQueueScheduler.action.pause_backlog()
return _responds(RESULT_SUCCESS, msg='Backlog paused')
else:
sickbeard.searchQueueScheduler.action.unpause_backlog()
return _responds(RESULT_SUCCESS, msg='Backlog unpaused')
|
'check to see if sickbeard is running'
| def run(self):
| cherrypy.response.headers['Cache-Control'] = 'max-age=0,no-cache,no-store'
if sickbeard.started:
return _responds(RESULT_SUCCESS, {'pid': sickbeard.PID}, 'Pong')
else:
return _responds(RESULT_SUCCESS, msg='Pong')
|
'restart sickbeard'
| def run(self):
| threading.Timer(2, sickbeard.invoke_restart, [False]).start()
return _responds(RESULT_SUCCESS, msg='SickBeard is restarting...')
|
'search for show at tvdb with a given string and language'
| def run(self):
| if (self.name and (not self.tvdbid)):
baseURL = 'http://thetvdb.com/api/GetSeries.php?'
params = {'seriesname': str(self.name).encode('utf-8'), 'language': self.lang}
finalURL = (baseURL + urllib.urlencode(params))
urlData = sickbeard.helpers.getURL(finalURL)
if (urlData is N... |
'set sickbeard user defaults'
| def run(self):
| quality_map = {'sdtv': Quality.SDTV, 'sddvd': Quality.SDDVD, 'hdtv': Quality.HDTV, 'rawhdtv': Quality.RAWHDTV, 'fullhdtv': Quality.FULLHDTV, 'hdwebdl': Quality.HDWEBDL, 'fullhdwebdl': Quality.FULLHDWEBDL, 'hdbluray': Quality.HDBLURAY, 'fullhdbluray': Quality.FULLHDBLURAY, 'unknown': Quality.UNKNOWN}
iqualityID ... |
'shutdown sickbeard'
| def run(self):
| threading.Timer(2, sickbeard.invoke_shutdown).start()
return _responds(RESULT_SUCCESS, msg='SickBeard is shutting down...')
|
'display information for a given show'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if (not showObj):
return _responds(RESULT_FAILURE, msg='Show not found')
showDict = {}
showDict['season_list'] = CMD_ShowSeasonList((), {'tvdbid': self.tvdbid}).run()['data']
showDict['cache'] = CMD_ShowC... |
'add a show in sickbeard with an existing folder'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if showObj:
return _responds(RESULT_FAILURE, msg='An existing tvdbid already exists in the database')
if (not ek.ek(os.path.isdir, self.location)):
return _responds(RESULT_FAILURE, msg='Not... |
'add a show in sickbeard with an existing folder'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if showObj:
return _responds(RESULT_FAILURE, msg='An existing tvdbid already exists in database')
if (not self.location):
if (sickbeard.ROOT_DIRS != ''):
root_dirs = sickbeard.ROOT... |
'check sickbeard\'s cache to see if the banner or poster image for a show is valid'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if (not showObj):
return _responds(RESULT_FAILURE, msg='Show not found')
cache_obj = image_cache.ImageCache()
has_poster = 0
has_banner = 0
if ek.ek(os.path.isfile, cache_obj.poster_path(showObj.tvdbi... |
'delete a show in sickbeard'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if (not showObj):
return _responds(RESULT_FAILURE, msg='Show not found')
if (sickbeard.showQueueScheduler.action.isBeingAdded(showObj) or sickbeard.showQueueScheduler.action.isBeingUpdated(showObj)):
retu... |
'get quality setting for a show in sickbeard'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if (not showObj):
return _responds(RESULT_FAILURE, msg='Show not found')
(anyQualities, bestQualities) = _mapQuality(showObj.quality)
return _responds(RESULT_SUCCESS, {'initial': anyQualities, 'archive': best... |
'get the poster for a show in sickbeard'
| def run(self):
| return {'outputType': 'image', 'image': webserve.WebInterface().showPoster(self.tvdbid, 'poster')}
|
'get the banner for a show in sickbeard'
| def run(self):
| return {'outputType': 'image', 'image': webserve.WebInterface().showPoster(self.tvdbid, 'banner')}
|
'set a show\'s paused state in sickbeard'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if (not showObj):
return _responds(RESULT_FAILURE, msg='Show not found')
if (self.pause is True):
showObj.paused = 1
return _responds(RESULT_SUCCESS, msg=((u'' + showObj.name) + ' has been ... |
'refresh a show in sickbeard'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if (not showObj):
return _responds(RESULT_FAILURE, msg='Show not found')
try:
sickbeard.showQueueScheduler.action.refreshShow(showObj)
return _responds(RESULT_SUCCESS, msg=((u'' + showObj.name) + ... |
'display the season list for a given show'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if (not showObj):
return _responds(RESULT_FAILURE, msg='Show not found')
myDB = db.DBConnection(row_type='dict')
if (self.sort == 'asc'):
sqlResults = myDB.select('SELECT DISTINCT season FROM... |
'display a listing of episodes for all or a given show'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if (not showObj):
return _responds(RESULT_FAILURE, msg='Show not found')
myDB = db.DBConnection(row_type='dict')
if (self.season is None):
sqlResults = myDB.select('SELECT name, episode, aird... |
'set the quality for a show in sickbeard by taking in a deliminated
string of qualities, map to their value and combine for new values'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if (not showObj):
return _responds(RESULT_FAILURE, msg='Show not found')
quality_map = {'sdtv': Quality.SDTV, 'sddvd': Quality.SDDVD, 'hdtv': Quality.HDTV, 'rawhdtv': Quality.RAWHDTV, 'fullhdtv': Quality.FULLHDTV... |
'display episode statistics for a given show'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if (not showObj):
return _responds(RESULT_FAILURE, msg='Show not found')
episode_status_counts_total = {}
episode_status_counts_total['total'] = 0
for status in statusStrings.statusStrings.keys():
... |
'update a show in sickbeard'
| def run(self):
| showObj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(self.tvdbid))
if (not showObj):
return _responds(RESULT_FAILURE, msg='Show not found')
try:
sickbeard.showQueueScheduler.action.updateShow(showObj, True)
return _responds(RESULT_SUCCESS, msg=((u'' + showObj.nam... |
'display_is_int_multi( self.tvdbid )shows in sickbeard'
| def run(self):
| shows = {}
for curShow in sickbeard.showList:
nextAirdate = ''
nextEps = curShow.nextEpisode()
if (len(nextEps) != 0):
nextAirdate = _ordinal_to_dateForm(nextEps[0].airdate.toordinal())
if ((self.paused is not None) and (bool(self.paused) != bool(curShow.paused))):
... |
'display the global shows and episode stats'
| def run(self):
| stats = {}
myDB = db.DBConnection()
today = str(datetime.date.today().toordinal())
status_snatched = (('(' + ','.join([str(quality) for quality in (Quality.SNATCHED + Quality.SNATCHED_PROPER)])) + ')')
status_download = (('(' + ','.join([str(quality) for quality in (Quality.DOWNLOADED + [ARCHIVED])]... |
'Creates a new post processor with the given file path and optionally an NZB name.
file_path: The path to the file to be processed
nzb_name: The name of the NZB which resulted in this file being downloaded (optional)'
| def __init__(self, file_path, nzb_name=None, pp_options={}):
| self.folder_path = ek.ek(os.path.dirname, ek.ek(os.path.abspath, file_path))
self.file_path = file_path
self.file_name = ek.ek(os.path.basename, file_path)
self.folder_name = ek.ek(os.path.basename, self.folder_path)
self.nzb_name = nzb_name
self.force_replace = pp_options.get('force_replace', F... |
'A wrapper for the internal logger which also keeps track of messages and saves them to a string for later.
message: The string to log (unicode)
level: The log level to use (optional)'
| def _log(self, message, level=logger.MESSAGE):
| logger.log(message, level)
self.log += (message + '\n')
|
'Checks if a file exists already and if it does whether it\'s bigger or smaller than
the file we are post processing
existing_file: The file to compare to
Returns:
DOESNT_EXIST if the file doesn\'t exist
EXISTS_LARGER if the file exists and is larger than the file we are post processing
EXISTS_SMALLER if the file exist... | def _checkForExistingFile(self, existing_file):
| if (not existing_file):
self._log(u'There is no existing file', logger.DEBUG)
return PostProcessor.DOESNT_EXIST
if ek.ek(os.path.isfile, existing_file):
if (ek.ek(os.path.getsize, existing_file) > ek.ek(os.path.getsize, self.file_path)):
self._log((((u'File ' +... |
'Deletes the file and optionally all associated files.
file_path: The file to delete
associated_files: True to delete all files which differ only by extension, False to leave them'
| def _delete(self, file_path, associated_files=False):
| if (not file_path):
return
file_list = [file_path]
if associated_files:
file_list = (file_list + helpers.list_associated_files(file_path, base_name_only=True))
if (not file_list):
self._log(((u'There were no files associated with ' + file_path) + ', not de... |
'Performs a generic operation (move or copy) on a file. Can rename the file as well as change its location,
and optionally move associated files too.
file_path: The full path of the media file to act on
new_path: Destination path where we want to move/copy the file to
new_base_name: The base filename (no extension) to ... | def _combined_file_operation(self, file_path, new_path, new_base_name, associated_files=False, action=None):
| if (not action):
self._log(u'Must provide an action for the combined file operation', logger.ERROR)
return
file_list = [file_path]
if associated_files:
file_list = (file_list + helpers.list_associated_files(file_path, filter_ext=sickbeard.FILTER_ASSOCIATED_FIL... |
'file_path: The full path of the media file to move
new_path: Destination path where we want to move the file to
new_base_name: The base filename (no extension) to use during the move. Use None to keep the same name.
associated_files: Boolean, whether we should move similarly-named files too'
| def _move(self, file_path, new_path, new_base_name, associated_files=False):
| def _int_move(cur_file_path, new_file_path):
self._log((((u'Moving file from ' + cur_file_path) + ' to ') + new_file_path), logger.DEBUG)
try:
helpers.moveFile(cur_file_path, new_file_path)
helpers.chmodAsParent(new_file_path)
except (IOError, OSError) ... |
'file_path: The full path of the media file to copy
new_path: Destination path where we want to copy the file to
new_base_name: The base filename (no extension) to use during the copy. Use None to keep the same name.
associated_files: Boolean, whether we should copy similarly-named files too'
| def _copy(self, file_path, new_path, new_base_name, associated_files=False):
| def _int_copy(cur_file_path, new_file_path):
self._log((((u'Copying file from ' + cur_file_path) + ' to ') + new_file_path), logger.DEBUG)
try:
helpers.copyFile(cur_file_path, new_file_path)
helpers.chmodAsParent(new_file_path)
except (IOError, OSError)... |
'Look up the NZB name in the history and see if it contains a record for self.nzb_name
Returns a (tvdb_id, season, [], quality) tuple. tvdb_id, season, quality may be None and episodes may be [].'
| def _history_lookup(self):
| to_return = (None, None, [], None)
if ((not self.nzb_name) and (not self.folder_name)):
self.in_history = False
return to_return
names = []
if self.nzb_name:
names.append(self.nzb_name)
if ('.' in self.nzb_name):
names.append(self.nzb_name.rpartition('.')[0])
... |
'Takes a name and tries to figure out a show, season, and episode from it.
name: A string which we want to analyze to determine show info from (unicode)
Returns a (tvdb_id, season, [episodes], quality) tuple. tvdb_id, season, quality may be None and episodes may be [].
if none were found.'
| def _analyze_name(self, name, file_name=True):
| logger.log((u'Analyzing name ' + repr(name)))
to_return = (None, None, [], None)
if (not name):
return to_return
name = helpers.remove_non_release_groups(helpers.remove_extension(name))
np = NameParser(False)
parse_result = np.parse(name)
self._log((((u'Parsed ' + name) + ' ... |
'For a given file try to find the showid, season, and episode.'
| def _find_info(self):
| tvdb_id = season = quality = None
episodes = []
attempt_list = [self._history_lookup, (lambda : self._analyze_name(self.nzb_name)), (lambda : self._analyze_name(self.file_name)), (lambda : self._analyze_name(self.folder_name)), (lambda : self._analyze_name(self.file_path)), (lambda : self._analyze_name(((se... |
'Retrieve the TVEpisode object requested.
tvdb_id: The TVDBID of the show (int)
season: The season of the episode (int)
episodes: A list of episodes to find (list of ints)
If the episode(s) can be found then a TVEpisode object with the correct related eps will
be instantiated and returned. If the episode can\'t be foun... | def _get_ep_obj(self, tvdb_id, season, episodes):
| show_obj = None
self._log((u'Loading show object for tvdb_id ' + str(tvdb_id)), logger.DEBUG)
try:
show_obj = helpers.findCertainShow(sickbeard.showList, tvdb_id)
except exceptions.MultipleShowObjectsException:
raise
if (not show_obj):
error_msg = u"This sho... |
'Determines the quality of the file that is being post processed by parsing through the data available.
ep_obj: The TVEpisode object related to the file we are post processing
Returns: A quality value found in common.Quality'
| def _get_quality(self, ep_obj):
| ep_quality = common.Quality.UNKNOWN
name_list = [self.nzb_name, self.folder_name, self.file_name]
for cur_name in name_list:
if (not cur_name):
continue
ep_quality = common.Quality.nameQuality(cur_name)
self._log((((u'Looking up quality for name ' + cur_nam... |
'Executes any extra scripts defined in the config.
ep_obj: The object to use when calling the extra script'
| def _run_extra_scripts(self, ep_obj):
| for curScriptName in sickbeard.EXTRA_SCRIPTS:
try:
script_cmd = [piece for piece in re.split('( |\\".*?\\"|\'.*?\')', curScriptName) if piece.strip()]
script_cmd = (script_cmd + [ep_obj.location.encode(sickbeard.SYS_ENCODING), self.file_path.encode(sickbeard.SYS_ENCODING), str(ep_... |
'Determines if the new episode can safely replace old episode.
Episodes which are expected (snatched) or larger than the existing episode are priority, others are not.
ep_obj: The TVEpisode object in question
new_ep_quality: The quality of the episode that is being processed
Returns: True if the episode can safely repl... | def _safe_replace(self, ep_obj, new_ep_quality):
| if (ep_obj.status in (common.Quality.SNATCHED + common.Quality.SNATCHED_PROPER)):
self._log(u'Sick Beard snatched this episode, marking it safe to replace', logger.DEBUG)
return True
(old_ep_status, old_ep_quality) = common.Quality.splitCompositeStatus(ep_obj.status)
... |
'Post-process a given file'
| def process(self):
| self._log(((((u'Processing ' + self.file_path) + ' (') + str(self.nzb_name)) + ')'))
if ek.ek(os.path.isdir, self.file_path):
self._log(((u'File ' + self.file_path) + ' seems to be a directory'))
return False
self.in_history = False
(tvdb_id, season, episodes, qua... |
'Return a new randomized API_KEY'
| @cherrypy.expose
def generateKey(self):
| try:
from hashlib import md5
except ImportError:
from md5 import md5
t = str(time.time())
r = str(random.random())
m = md5(t)
m.update(r)
logger.log(u'New SB API key generated')
return m.hexdigest()
|
'Display the new show page which collects a tvdb id, folder, and extra options and
posts them to addNewShow'
| @cherrypy.expose
def newShow(self, show_to_add=None, other_shows=None):
| t = PageTemplate(file='home_newShow.tmpl')
t.submenu = HomeMenu()
(show_dir, tvdb_id, show_name) = self.split_extra_show(show_to_add)
if (tvdb_id and show_name):
use_provided_info = True
else:
use_provided_info = False
t.use_provided_info = use_provided_info
if (not show_dir)... |
'Receive tvdb id, dir, and other options and create a show from them. If extra show dirs are
provided then it forwards back to newShow, if not it goes to /home.'
| @cherrypy.expose
def addNewShow(self, whichSeries=None, tvdbLang='en', rootDir=None, defaultStatus=None, anyQualities=None, bestQualities=None, flatten_folders=None, fullShowPath=None, other_shows=None, skipShow=None):
| if (not other_shows):
other_shows = []
elif (type(other_shows) != list):
other_shows = [other_shows]
def finishAddShow():
if (not other_shows):
redirect('/home/')
next_show_dir = other_shows[0]
rest_of_show_dirs = other_shows[1:]
return self.newSho... |
'Prints out the page to add existing shows from a root dir'
| @cherrypy.expose
def existingShows(self):
| t = PageTemplate(file='home_addExistingShow.tmpl')
t.submenu = HomeMenu()
return _munge(t)
|
'Receives a dir list and add them. Adds the ones with given TVDB IDs first, then forwards
along to the newShow page.'
| @cherrypy.expose
def addExistingShows(self, shows_to_add=None, promptForSettings=None):
| if (not shows_to_add):
shows_to_add = []
elif (type(shows_to_add) != list):
shows_to_add = [shows_to_add]
shows_to_add = [urllib.unquote_plus(x) for x in shows_to_add]
promptForSettings = config.checkbox_to_value(promptForSettings)
tvdb_id_given = []
dirs_only = []
for cur_di... |
'Keep web crawlers out'
| @cherrypy.expose
def robots_txt(self):
| cherrypy.response.headers['Content-Type'] = 'text/plain'
return 'User-agent: *\nDisallow: /\n'
|
'Determines how this copy of SB was installed.
returns: type of installation. Possible values are:
\'win\': any compiled windows build
\'git\': running from source using git
\'source\': running from source without git'
| def find_install_type(self):
| if sickbeard.version.SICKBEARD_VERSION.startswith('build '):
install_type = 'win'
elif os.path.isdir(ek.ek(os.path.join, sickbeard.PROG_DIR, u'.git')):
install_type = 'git'
else:
install_type = 'source'
return install_type
|
'Checks the internet for a newer version.
returns: bool, True for new version or False for no new version.
force: if true the VERSION_NOTIFY setting will be ignored and a check will be forced'
| def check_for_new_version(self, force=False):
| if ((not sickbeard.VERSION_NOTIFY) and (not force)):
logger.log(u'Version checking is disabled, not checking for the newest version')
return False
logger.log(((u'Checking if ' + self.install_type) + ' needs an update'))
if (not self.updater.need_upda... |
'Checks git for the newest Windows binary build. Returns either the
build number or the entire build URL depending on whole_link\'s value.
whole_link: If True, returns the entire URL to the release. If False, it returns
only the build number. default: False'
| def _find_newest_version(self, whole_link=False):
| regex = '.*SickBeard\\-win32\\-alpha\\-build(\\d+)(?:\\.\\d+)?\\.zip'
version_url_data = helpers.getURL(self.version_url)
if (version_url_data is None):
return None
else:
for curLine in version_url_data.splitlines():
logger.log((u'checking line ' + curLine), logger.DEBU... |
'Attempts to find the currently installed version of Sick Beard.
Uses git show to get commit version.
Returns: True for success or False for failure'
| def _find_installed_version(self):
| (output, err, exit_status) = self._run_git(self._git_path, 'rev-parse HEAD')
if ((exit_status == 0) and output):
cur_commit_hash = output.strip()
if (not re.match('^[a-z0-9]+$', cur_commit_hash)):
logger.log(u"Output doesn't look like a hash, not using it",... |
'Uses git commands to check if there is a newer version that the provided
commit hash. If there is a newer version it sets _num_commits_behind.'
| def _check_github_for_update(self):
| self._newest_commit_hash = None
self._num_commits_behind = 0
self._num_commits_ahead = 0
(output, err, exit_status) = self._run_git(self._git_path, 'fetch origin')
if (not (exit_status == 0)):
logger.log(u"Unable to contact github, can't check for update", logger.ERRO... |
'Calls git pull origin <branch> in order to update Sick Beard. Returns a bool depending
on the call\'s success.'
| def update(self):
| (output, err, exit_status) = self._run_git(self._git_path, ('pull origin ' + self.branch))
if (exit_status == 0):
return True
else:
return False
return False
|
'Uses pygithub to ask github if there is a newer version that the provided
commit hash. If there is a newer version it sets Sick Beard\'s version text.
commit_hash: hash that we\'re checking against'
| def _check_github_for_update(self):
| self._num_commits_behind = 0
self._newest_commit_hash = None
gh = github.GitHub(self.github_repo_user, self.github_repo, self.branch)
if self._cur_commit_hash:
branch_compared = gh.compare(base=self.branch, head=self._cur_commit_hash)
if ('base_commit' in branch_compared):
se... |
'Downloads the latest source tarball from github and installs it over the existing version.'
| def update(self):
| base_url = ((('https://github.com/' + self.github_repo_user) + '/') + self.github_repo)
tar_download_url = ((base_url + '/tarball/') + self.branch)
version_path = ek.ek(os.path.join, sickbeard.PROG_DIR, u'version.txt')
try:
sb_update_dir = ek.ek(os.path.join, sickbeard.PROG_DIR, u'sb-update')
... |
'Builds up the full path to the image cache directory'
| def _cache_dir(self):
| return ek.ek(os.path.abspath, ek.ek(os.path.join, sickbeard.CACHE_DIR, 'images'))
|
'Builds up the path to a poster cache for a given tvdb id
returns: a full path to the cached poster file for the given tvdb id
tvdb_id: ID of the show to use in the file name'
| def poster_path(self, tvdb_id):
| poster_file_name = (str(tvdb_id) + '.poster.jpg')
return ek.ek(os.path.join, self._cache_dir(), poster_file_name)
|
'Builds up the path to a banner cache for a given tvdb id
returns: a full path to the cached banner file for the given tvdb id
tvdb_id: ID of the show to use in the file name'
| def banner_path(self, tvdb_id):
| banner_file_name = (str(tvdb_id) + '.banner.jpg')
return ek.ek(os.path.join, self._cache_dir(), banner_file_name)
|
'Returns true if a cached poster exists for the given tvdb id'
| def has_poster(self, tvdb_id):
| poster_path = self.poster_path(tvdb_id)
logger.log(((u'Checking if file ' + str(poster_path)) + ' exists'), logger.DEBUG)
return ek.ek(os.path.isfile, poster_path)
|
'Returns true if a cached banner exists for the given tvdb id'
| def has_banner(self, tvdb_id):
| banner_path = self.banner_path(tvdb_id)
logger.log(((u'Checking if file ' + str(banner_path)) + ' exists'), logger.DEBUG)
return ek.ek(os.path.isfile, banner_path)
|
'Analyzes the image provided and attempts to determine whether it is a poster or banner.
returns: BANNER, POSTER if it concluded one or the other, or None if the image was neither (or didn\'t exist)
path: full path to the image'
| def which_type(self, path):
| if (not ek.ek(os.path.isfile, path)):
logger.log(((u"Couldn't check the type of " + str(path)) + " cause it doesn't exist"), logger.WARNING)
return None
img_parser = createParser(path)
img_metadata = extractMetadata(img_parser)
if (not img_metadata):
lo... |
'Takes the image provided and copies it to the cache folder
returns: bool representing success
image_path: path to the image we\'re caching
img_type: BANNER or POSTER
tvdb_id: id of the show this image belongs to'
| def _cache_image_from_file(self, image_path, img_type, tvdb_id):
| if (img_type == self.POSTER):
dest_path = self.poster_path(tvdb_id)
elif (img_type == self.BANNER):
dest_path = self.banner_path(tvdb_id)
else:
logger.log((u'Invalid cache image type: ' + str(img_type)), logger.ERROR)
return False
if (not ek.ek(os.path.isdir, ... |
'Retrieves an image of the type specified from TVDB and saves it to the cache folder
returns: bool representing success
show_obj: TVShow object that we want to cache an image for
img_type: BANNER or POSTER'
| def _cache_image_from_tvdb(self, show_obj, img_type):
| if (img_type == self.POSTER):
img_type_name = 'poster'
dest_path = self.poster_path(show_obj.tvdbid)
elif (img_type == self.BANNER):
img_type_name = 'banner'
dest_path = self.banner_path(show_obj.tvdbid)
else:
logger.log((u'Invalid cache image type: ' + st... |
'Caches all images for the given show. Copies them from the show dir if possible, or
downloads them from TVDB if they aren\'t in the show dir.
show_obj: TVShow object to cache images for'
| def fill_cache(self, show_obj):
| logger.log((u'Checking if we need any cache images for show ' + str(show_obj.tvdbid)), logger.DEBUG)
need_images = {self.POSTER: (not self.has_poster(show_obj.tvdbid)), self.BANNER: (not self.has_banner(show_obj.tvdbid))}
if ((not need_images[self.POSTER]) and (not need_images[sel... |
'Returns the path where the episode thumbnail should be stored. Defaults to
the same path as the episode file but with a .tbn extension.
ep_obj: a TVEpisode instance for which to create the thumbnail'
| def get_episode_thumb_path(self, ep_obj):
| if ek.ek(os.path.isfile, ep_obj.location):
tbn_filename = helpers.replaceExtension(ep_obj.location, 'tbn')
else:
return None
return tbn_filename
|
'Returns the full path to the file for a given season poster.
show_obj: a TVShow instance for which to generate the path
season: a season number to be used for the path. Note that season 0
means specials.'
| def get_season_poster_path(self, show_obj, season):
| if (season == 0):
season_poster_filename = 'season-specials'
else:
season_poster_filename = ('season' + str(season).zfill(2))
return ek.ek(os.path.join, show_obj.location, (season_poster_filename + '.tbn'))
|
'Creates an elementTree XML structure for an XBMC-style tvshow.nfo and
returns the resulting data object.
show_obj: a TVShow instance to create the NFO for'
| def _show_data(self, show_obj):
| show_ID = show_obj.tvdbid
tvdb_lang = show_obj.lang
ltvdb_api_parms = sickbeard.TVDB_API_PARMS.copy()
if (tvdb_lang and (not (tvdb_lang == 'en'))):
ltvdb_api_parms['language'] = tvdb_lang
t = tvdb_api.Tvdb(actors=True, **ltvdb_api_parms)
tv_node = etree.Element('tvshow')
try:
... |
'Creates an elementTree XML structure for an XBMC-style episode.nfo and
returns the resulting data object.
show_obj: a TVEpisode instance to create the NFO for'
| def _ep_data(self, ep_obj):
| eps_to_write = ([ep_obj] + ep_obj.relatedEps)
tvdb_lang = ep_obj.show.lang
ltvdb_api_parms = sickbeard.TVDB_API_PARMS.copy()
if (tvdb_lang and (not (tvdb_lang == 'en'))):
ltvdb_api_parms['language'] = tvdb_lang
try:
t = tvdb_api.Tvdb(actors=True, **ltvdb_api_parms)
myShow = t... |
'Returns the path where the episode thumbnail should be stored. Defaults to
the same path as the episode file but with a .cover.jpg extension.
ep_obj: a TVEpisode instance for which to create the thumbnail'
| def get_episode_thumb_path(self, ep_obj):
| if ek.ek(os.path.isfile, ep_obj.location):
tbn_filename = (ep_obj.location + '.cover.jpg')
else:
return None
return tbn_filename
|
'Returns a full show dir/.meta/episode.txt path for Tivo
episode metadata files.
Note, that pyTivo requires the metadata filename to include the original extention.
ie If the episode name is foo.avi, the metadata name is foo.avi.txt
ep_obj: a TVEpisode object to get the path for'
| def get_episode_file_path(self, ep_obj):
| if ek.ek(os.path.isfile, ep_obj.location):
metadata_file_name = ((ek.ek(os.path.basename, ep_obj.location) + '.') + self._ep_nfo_extension)
metadata_dir_name = ek.ek(os.path.join, ek.ek(os.path.dirname, ep_obj.location), '.meta')
metadata_file_path = ek.ek(os.path.join, metadata_dir_name, me... |
'Creates a key value structure for a Tivo episode metadata file and
returns the resulting data object.
ep_obj: a TVEpisode instance to create the metadata file for.
Lookup the show in http://thetvdb.com/ using the python library:
https://github.com/dbr/tvdb_api/
The results are saved in the object myShow.
The key value... | def _ep_data(self, ep_obj):
| data = ''
eps_to_write = ([ep_obj] + ep_obj.relatedEps)
tvdb_lang = ep_obj.show.lang
try:
ltvdb_api_parms = sickbeard.TVDB_API_PARMS.copy()
if (tvdb_lang and (not (tvdb_lang == 'en'))):
ltvdb_api_parms['language'] = tvdb_lang
t = tvdb_api.Tvdb(actors=True, **ltvdb_api... |
'Generates and writes ep_obj\'s metadata under the given path with the
given filename root. Uses the episode\'s name with the extension in
_ep_nfo_extension.
ep_obj: TVEpisode object for which to create the metadata
file_name_path: The file name to use for this metadata. Note that the extension
will be automatically ad... | def write_ep_file(self, ep_obj):
| data = self._ep_data(ep_obj)
if (not data):
return False
nfo_file_path = self.get_episode_file_path(ep_obj)
nfo_file_dir = ek.ek(os.path.dirname, nfo_file_path)
try:
if (not ek.ek(os.path.isdir, nfo_file_dir)):
logger.log((u"Metadata dir didn't exist, creating... |
'Returns the path where the episode thumbnail should be stored.
ep_obj: a TVEpisode instance for which to create the thumbnail'
| def get_episode_thumb_path(self, ep_obj):
| if ek.ek(os.path.isfile, ep_obj.location):
tbn_filename = ep_obj.location.rpartition('.')
if (tbn_filename[0] == ''):
tbn_filename = (ep_obj.location + '-thumb.jpg')
else:
tbn_filename = (tbn_filename[0] + '-thumb.jpg')
else:
return None
return tbn_fil... |
'Returns the full path to the file for a given season poster.
show_obj: a TVShow instance for which to generate the path
season: a season number to be used for the path. Note that season 0
means specials.'
| def get_season_poster_path(self, show_obj, season):
| if (season == 0):
season_poster_filename = 'season-specials'
else:
season_poster_filename = ('season' + str(season).zfill(2))
return ek.ek(os.path.join, show_obj.location, (season_poster_filename + '-poster.jpg'))
|
'Returns the full path to the file for a given season banner.
show_obj: a TVShow instance for which to generate the path
season: a season number to be used for the path. Note that season 0
means specials.'
| def get_season_banner_path(self, show_obj, season):
| if (season == 0):
season_banner_filename = 'season-specials'
else:
season_banner_filename = ('season' + str(season).zfill(2))
return ek.ek(os.path.join, show_obj.location, (season_banner_filename + '-banner.jpg'))
|
'This should be overridden by the implementing class. It should
provide the content of the show metadata file.'
| def _show_data(self, show_obj):
| return None
|
'This should be overridden by the implementing class. It should
provide the content of the episode metadata file.'
| def _ep_data(self, ep_obj):
| return None
|
'Returns the URL to use for downloading an episode\'s thumbnail. Uses
theTVDB.com data.
ep_obj: a TVEpisode object for which to grab the thumb URL'
| def _get_episode_thumb_url(self, ep_obj):
| all_eps = ([ep_obj] + ep_obj.relatedEps)
tvdb_lang = ep_obj.show.lang
try:
ltvdb_api_parms = sickbeard.TVDB_API_PARMS.copy()
if (tvdb_lang and (not (tvdb_lang == 'en'))):
ltvdb_api_parms['language'] = tvdb_lang
t = tvdb_api.Tvdb(actors=True, **ltvdb_api_parms)
tvd... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.