Fix Bug-13 - getStreamUrl produces a malformed URL; Cleanup logging if logfile is not defined

This commit is contained in:
Michael Shepanski 2015-06-04 10:43:50 -04:00
parent 527b0ee323
commit 69e0abd50c
2 changed files with 14 additions and 11 deletions

View file

@ -36,13 +36,14 @@ BASE_HEADERS = {
# Logging Configuration # Logging Configuration
log = logging.getLogger('plexapi') log = logging.getLogger('plexapi')
LOG_FILE = CONFIG.get('logging.path') logfile = CONFIG.get('logging.path')
if LOG_FILE: logformat = CONFIG.get('logging.format', '%(asctime)s %(module)12s:%(lineno)-4s %(levelname)-9s %(message)s')
LOG_BACKUPS = CONFIG.get('logging.backup_count', 3, int) loglevel = CONFIG.get('logging.level', 'INFO')
LOG_BYTES = CONFIG.get('logging.rotate_bytes', 512000, int) loghandler = logging.NullHandler()
LOG_FORMAT = CONFIG.get('logging.format', '%(asctime)s %(module)12s:%(lineno)-4s %(levelname)-9s %(message)s') if logfile:
LOG_LEVEL = CONFIG.get('logging.level', 'INFO') logbackups = CONFIG.get('logging.backup_count', 3, int)
filehandler = RotatingFileHandler(os.path.expanduser(LOG_FILE), 'a', LOG_BYTES, LOG_BACKUPS) logbytes = CONFIG.get('logging.rotate_bytes', 512000, int)
filehandler.setFormatter(logging.Formatter(LOG_FORMAT)) loghandler = RotatingFileHandler(os.path.expanduser(logfile), 'a', logbytes, logbackups)
log.addHandler(filehandler) loghandler.setFormatter(logging.Formatter(logformat))
log.setLevel(LOG_LEVEL) log.addHandler(loghandler)
log.setLevel(loglevel)

View file

@ -104,5 +104,7 @@ class PlexServer(object):
def url(self, path): def url(self, path):
url = 'http://%s:%s/%s' % (self.address, self.port, path.lstrip('/')) url = 'http://%s:%s/%s' % (self.address, self.port, path.lstrip('/'))
if self.token: url += '?X-Plex-Token=%s' % self.token if self.token:
delim = '&' if '?' in url else '?'
url += '%sX-Plex-Token=%s' % (delim, self.token)
return url return url