Skip to content
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

Update the string concat method. Edit some error messages for clarity #18

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 41 additions & 41 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ def setPrefs():
global tmdbGenreData

# Set Tvheadend authorization and verify connectivity to Tvheadend
tvhAuth = base64.b64encode('%s:%s' % (Prefs['tvhUser'], Prefs['tvhPass']))
tvhHeaders = {'Authorization': 'Basic %s' % tvhAuth}
tvhAuth = base64.b64encode('{}:{}'.format(Prefs['tvhUser'], Prefs['tvhPass']))
tvhHeaders = {'Authorization': 'Basic ' + str(tvhAuth)}
tvhAddress = Prefs['tvhAddress'].rstrip('/')
tvhServerInfoURL = '%s/api/serverinfo' % tvhAddress
tvhServerInfoURL = str(tvhAddress) + '/api/serverinfo'

try:
tvhInfoData = JSON.ObjectFromURL(url=tvhServerInfoURL, headers=tvhHeaders, values=None, cacheTime=1)
Expand All @@ -67,7 +67,7 @@ def setPrefs():
if tvhInfoData['api_version'] >= 15:
tvhReachable = True
else:
Log.Critical('Tvheadend version ' + tvhInfoData['sw_version'] + ' is unsupported.')
Log.Critical('Tvheadend version ' + tvhInfoData['sw_version'] + ' is not supported.')
return

except Exception as e:
Expand Down Expand Up @@ -100,7 +100,7 @@ def MainMenu():

# Request channel data from Tvheadend
tvhChannelsData = None
tvhChannelsURL = '%s/api/channel/grid?start=0&limit=100000' % tvhAddress
tvhChannelsURL = str(tvhAddress) + '/api/channel/grid?start=0&limit=100000'

if tvhReachable:
try:
Expand All @@ -120,7 +120,7 @@ def MainMenu():
tvhTagUUID_H264AAC = None
tvhTagUUID_MPEG2AC3 = None
tvhTagUUID_MPEG2 = None
tvhTagsURL = '%s/api/channeltag/grid?start=0&limit=100000' % tvhAddress
tvhTagsURL = str(tvhAddress) + '/api/channeltag/grid?start=0&limit=100000'

try:
tvhTagsData = JSON.ObjectFromURL(url=tvhTagsURL, headers=tvhHeaders, values=None, cacheTime=channelDataCacheTime)
Expand All @@ -142,7 +142,7 @@ def MainMenu():

# Request recordings from Tvheadend
tvhRecordingsData = None
tvhRecordingsURL = '%s/api/dvr/entry/grid_finished' % tvhAddress
tvhRecordingsURL = str(tvhAddress) + '/api/dvr/entry/grid_finished'

try:
tvhRecordingsData = JSON.ObjectFromURL(url=tvhRecordingsURL, headers=tvhHeaders, values=None, cacheTime=channelDataCacheTime)
Expand Down Expand Up @@ -172,7 +172,7 @@ def MainMenu():

while True:
try:
tvhEPGURL = '%s/api/epg/events/grid?start=0&limit=%s' % (tvhAddress,epgLoopLimit)
tvhEPGURL = str(tvhAddress) + '/api/epg/events/grid?start=0&limit=' + str(epgLoopLimit)

if epgUTF8Encoding:
epgEncoding = 'utf-8'
Expand All @@ -188,14 +188,14 @@ def MainMenu():
if 'Data of size' in str(e):
epgLoopLimit = epgLoopLimit - 1000
if epgLoopLimit > 0:
Log.Warn('Tvheadend EPG data exceeded the data size limit, reducing the request: ' + str(e))
Log.Warn('Tvheadend EPG data exceeded the data size limit. Reducing the request: ' + str(e))
else:
Log.Warn('Unable to retrieve Tvheadend EPG data within the data size limit.')
break

else:
if epgUTF8Encoding:
Log.Warn('Unable to retrieve Tvheadend EPG data as UTF-8, falling back to ISO-8859-1: ' + str(e))
Log.Warn('Unable to retrieve Tvheadend EPG data as UTF-8. Falling back to ISO-8859-1: ' + str(e))
epgUTF8Encoding = False
else:
Log.Warn('Error retrieving Tvheadend EPG data: ' + str(e))
Expand Down Expand Up @@ -227,7 +227,7 @@ def channels(startCount=0, art=ART):
title = str(tvhChannel['number'])

uuid = tvhChannel['uuid']
streamURL = '/stream/channel/%s' % uuid
streamURL = '/stream/channel/' + str(uuid)
streamCodec = None
thumb = None
fallbackThumb = None
Expand Down Expand Up @@ -420,10 +420,10 @@ def channels(startCount=0, art=ART):
# Use channel icons from Tvheadend if no other thumbnail is available
try:
if thumb is None and tvhChannel['icon_public_url'].startswith('imagecache'):
thumb = '%s/%s' % (tvhAddress, tvhChannel['icon_public_url'])
thumb = '{}/{}'.format(tvhAddress, tvhChannel['icon_public_url'])

if tvhChannel['icon_public_url'].startswith('imagecache'):
fallbackThumb ='%s/%s' % (tvhAddress, tvhChannel['icon_public_url'])
fallbackThumb ='{}/{}'.format(tvhAddress, tvhChannel['icon_public_url'])

except: pass

Expand Down Expand Up @@ -591,7 +591,7 @@ def image(url=None, fallback=None):
return None

if 'api.thetvdb.com' in url:
tvdbHeaders = {'Authorization' : 'Bearer %s' % tvdbToken}
tvdbHeaders = {'Authorization' : 'Bearer ' + str(tvdbToken)}
tvdbImageData = None

try:
Expand All @@ -614,7 +614,7 @@ def image(url=None, fallback=None):

if tvdbImageData:
for tvdbImageResult in tvdbImageData['data']:
url = 'http://thetvdb.com/banners/' + tvdbImageResult['fileName']
url = 'http://thetvdb.com/banners/' + str(tvdbImageResult['fileName'])
try:
imageContent = HTTP.Request(url, cacheTime=imageCacheTime, values=None).content
return DataObject(imageContent, 'image/jpeg')
Expand Down Expand Up @@ -648,22 +648,22 @@ def image(url=None, fallback=None):
def stream(streamURL):

# Add basic authentication info to the stream URL - Plex ignores the headers parameter in PartObject
tvhBasicAuth = '//%s:%s@' % (Prefs['tvhUser'], Prefs['tvhPass'])
tvhBasicAuth = '//{}:{}@'.format(Prefs['tvhUser'], Prefs['tvhPass'])
tvhAuthAddress = tvhAddress.replace('//', tvhBasicAuth)
playbackURL = '%s%s' % (tvhAuthAddress, streamURL)
playbackURL = '{}{}'.format(tvhAuthAddress, streamURL)

if Prefs['tvhProfile']:
playbackURL = playbackURL + '?profile=' + Prefs['tvhProfile']

# Verify the channel is available before returning it to PartObject
testURL = '%s%s' % (tvhAddress, streamURL)
testURL = '{}{}'.format(tvhAddress, streamURL)

try:
responseCode = HTTP.Request(testURL, headers=tvhHeaders, values=None, cacheTime=None, timeout=2).headers
return IndirectResponse(MovieObject, key=playbackURL)

except Exception as e:
Log.Warn('Tvheadend is not responding to this channel request - verify that there are available tuners: ' + repr(e))
Log.Warn('Tvheadend is not responding to this channel request. Verify that tuners are available: ' + repr(e))
raise Ex.MediaNotAvailable


Expand All @@ -675,7 +675,7 @@ def recordings(tvhTagUUID_H264AAC, tvhTagUUID_MPEG2AC3, tvhTagUUID_MPEG2, startC

# Request recordings from Tvheadend
tvhRecordingsData = None
tvhRecordingsURL = '%s/api/dvr/entry/grid_finished' % tvhAddress
tvhRecordingsURL = str(tvhAddress) + '/api/dvr/entry/grid_finished'

try:
tvhRecordingsData = JSON.ObjectFromURL(url=tvhRecordingsURL, headers=tvhHeaders, values=None, cacheTime=channelDataCacheTime)
Expand All @@ -684,7 +684,7 @@ def recordings(tvhTagUUID_H264AAC, tvhTagUUID_MPEG2AC3, tvhTagUUID_MPEG2, startC

# Request channel data from Tvheadend
tvhChannelsData = None
tvhChannelsURL = '%s/api/channel/grid?start=0&limit=100000' % tvhAddress
tvhChannelsURL = str(tvhAddress) + '/api/channel/grid?start=0&limit=100000'

try:
tvhChannelsData = JSON.ObjectFromURL(url=tvhChannelsURL, headers=tvhHeaders, values=None, cacheTime=channelDataCacheTime)
Expand Down Expand Up @@ -802,10 +802,10 @@ def recordings(tvhTagUUID_H264AAC, tvhTagUUID_MPEG2AC3, tvhTagUUID_MPEG2, startC
# Use channel icons from Tvheadend as a fallback
try:
if thumb is None and tvhRecording['channel_icon'].startswith('imagecache'):
thumb = '%s/%s' % (tvhAddress, tvhRecording['channel_icon'])
thumb = '{}/{}'.format(tvhAddress, tvhRecording['channel_icon'])

if tvhRecording['channel_icon'].startswith('imagecache'):
fallbackThumb ='%s/%s' % (tvhAddress, tvhRecording['channel_icon'])
fallbackThumb ='{}/{}'.format(tvhAddress, tvhRecording['channel_icon'])

except: pass

Expand Down Expand Up @@ -930,19 +930,19 @@ def tvdb(title, zap2itID, zap2itMissingID=None):
d, h = divmod(h, 24)
if d != 0:
if d == 1:
Log.Info('theTVDB previously had no results for ' + title + ', will try again after 1 day, %sh.' % h)
Log.Info('Could not find theTVDB results for ' + title + '. LiveTVH will try again after 1d, {}h.'.format(h))
else:
Log.Info('theTVDB previously had no results for ' + title + ', will try again after %s days.' % d)
Log.Info('Could not find theTVDB results for ' + title + '. LiveTVH will try again after {} days.'.format(d))
elif h != 0:
if h == 1:
Log.Info('theTVDB previously had no results for ' + title + ', will try again after 1 hour, %sm.' % m)
Log.Info('Could not find theTVDB results for ' + title + '. LiveTVH will try again after 1h, {}m.'.format(m))
else:
Log.Info('theTVDB previously had no results for ' + title + ', will try again after %s hours.' % h)
Log.Info('Could not find theTVDB results for ' + title + '. LiveTVH will try again after {} hours.'.format(h))
else:
if m == 1:
Log.Info('theTVDB previously had no results for ' + title + ', will try again after 1m, %ss.' % s)
Log.Info('Could not find theTVDB results for ' + title + '. LiveTVH will try again after 1m, {}s.'.format(s))
else:
Log.Info('theTVDB previously had no results for ' + title + ', will try again after %s minutes.' % m)
Log.Info('Could not find theTVDB results for ' + title + '. LiveTVH will try again after {} minutes.'.format(m))
return None

# Request an authorization token if it doesn't exist
Expand All @@ -959,9 +959,9 @@ def tvdb(title, zap2itID, zap2itMissingID=None):
tvdbHeaders = {'Authorization' : 'Bearer %s' % tvdbToken}

if zap2itID:
tvdbSearchURL = 'https://api.thetvdb.com/search/series?zap2itId=%s' % String.Quote(zap2itID)
tvdbSearchURL = 'https://api.thetvdb.com/search/series?zap2itId={}'.format(String.Quote(zap2itID))
else:
tvdbSearchURL = 'https://api.thetvdb.com/search/series?name=%s' % String.Quote(title)
tvdbSearchURL = 'https://api.thetvdb.com/search/series?name={}'.format(String.Quote(title))

try:
tvdbData = JSON.ObjectFromURL(url=tvdbSearchURL, headers=tvdbHeaders, values=None, cacheTime=imageCacheTime)
Expand All @@ -975,13 +975,13 @@ def tvdb(title, zap2itID, zap2itMissingID=None):
tvdbID = tvdbResult['id']
if zap2itMissingID:
Log.Info('Found ' + title + ' at http://thetvdb.com/?tab=series&id=' + str(tvdbID)
+ ' by name but not by zap2it ID ' + zap2itMissingID
+ ' - if this match is correct, consider adding the zap2it ID to theTVDB.com to improve search results.')
+ ' by name but not by zap2it ID ' + str(zap2itMissingID)
+ '. If this match is correct, consider adding the zap2it ID to theTVDB.com to improve search results.')
break

except Ex.HTTPError as e:
if e.code == 401:
Log.Info('theTVDB authorization token is invalid, requesting a new one.')
Log.Info('theTVDB authorization token is not valid. Requesting a new token.')
tvdbAuth()
return tvdb(title, zap2itID)

Expand All @@ -996,19 +996,19 @@ def tvdb(title, zap2itID, zap2itMissingID=None):
Dict[title] = time.time() + tvdbRetryInterval
h, m = divmod(int(tvdbRetryInterval), 3600)
d, h = divmod(h, 24)
Log.Info('No results from theTVDB for ' + title + ', skipping lookup for %s days.' % d)
Log.Info('No results from theTVDB for ' + title + '. Skipping lookup for {} days.'.format(d))
return None

else:
Log.Warn('Error while searching theTVDB: ' + str(e))
return None

if tvdbID:
tvdbPosterSearchURL = 'https://api.thetvdb.com/series/%s/images/query?keyType=poster' % tvdbID
tvdbFanartSearchURL = 'https://api.thetvdb.com/series/%s/images/query?keyType=fanart' % tvdbID
tvdbPosterSearchURL = 'https://api.thetvdb.com/series/{}/images/query?keyType=poster'.format(tvdbID)
tvdbFanartSearchURL = 'https://api.thetvdb.com/series/{}/images/query?keyType=fanart'.format(tvdbID)

# Search for metadata
tvdbMetadataSearchURL = 'https://api.thetvdb.com/series/%s' % tvdbID
tvdbMetadataSearchURL = 'https://api.thetvdb.com/series/' + str(tvdbID)
tvdbMetadata = None

try:
Expand All @@ -1032,9 +1032,9 @@ def tvdb(title, zap2itID, zap2itMissingID=None):
h, m = divmod(int(tvdbRetryInterval), 3600)
d, h = divmod(h, 24)
if d == 1:
Log.Info('No results from theTVDB for ' + title + ', skipping lookup for 1 day, %sh.' % h)
Log.Info('No results from theTVDB for ' + title + '. Skipping lookup for 1d, {}h.'.format(h))
else:
Log.Info('No results from theTVDB for ' + title + ', skipping lookup for %s days.' % d)
Log.Info('No results from theTVDB for ' + title + '. Skipping lookup for {} days.'.format(d))

return None

Expand All @@ -1055,7 +1055,7 @@ def tmdb(title):
tmdbBackdrop = None
tmdbYear = None
tmdbVoteAverage = 0.0
tmdbSearchURL = 'https://api.themoviedb.org/3/search/multi?api_key=0fd2136e80c47d0e371ee1af87eaedde&query=%s' % String.Quote(title)
tmdbSearchURL = 'https://api.themoviedb.org/3/search/multi?api_key=0fd2136e80c47d0e371ee1af87eaedde&query={}'.format(String.Quote(title))
tmdbGenres = None

# Search
Expand Down