Skip to content

Commit

Permalink
Merge pull request #132 from ukdtom/tommy-work
Browse files Browse the repository at this point in the history
V2.0.0.10
  • Loading branch information
ukdtom authored May 20, 2020
2 parents 3abb679 + ee6b870 commit 45fd75e
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 19 deletions.
69 changes: 56 additions & 13 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from consts import NAME, VERSION, PREFIX, ICON, ART, PLAYLIST, APPNAME
from consts import CONTAINERSIZEMOVIES, PMSTIMEOUT, CONTAINERSIZETV
from consts import CONTAINERSIZEEPISODES, CONTAINERSIZEPHOTO
from consts import CONTAINERSIZEAUDIO, PLAYCOUNTEXCLUDE
from consts import CONTAINERSIZEAUDIO, PLAYCOUNTEXCLUDE, IOENCODING


import output
Expand Down Expand Up @@ -137,7 +137,7 @@ def restart():
HTTP.Request(
misc.GetLoopBack() + '/:/plugins/com.plexapp.system/restart',
immediate=True)
except:
except Exception, e:
pass


Expand All @@ -148,8 +148,12 @@ def sectionList():
Core.app_support_path,
Core.config.bundles_dir_name,
APPNAME + '.bundle', 'Contents', 'DefaultPrefs.json')
with io.open(prefsFile) as json_file:
data = json.load(json_file)
try:
with io.open(prefsFile) as json_file:
data = json.load(json_file)
except Exception, e:
with io.open(prefsFile, encoding='utf8') as json_file:
data = json.load(json_file)
# Get list of libraries
SectionsURL = misc.GetLoopBack() + '/library/sections'
SectionList = XML.ElementFromURL(SectionsURL).xpath('//Directory')
Expand All @@ -173,9 +177,12 @@ def sectionList():
if item['id'] == 'Playlists':
item['values'] = PlayListValues
break

with io.open(prefsFile, 'wb') as outfile:
json.dump(data, outfile, indent=4)
try:
with io.open(prefsFile, 'wb') as outfile:
json.dump(data, outfile, indent=4)
except Exception, e:
with io.open(prefsFile, 'wb', encoding='utf8') as outfile:
json.dump(data, outfile, indent=4)
restart()
return

Expand Down Expand Up @@ -292,12 +299,34 @@ def Start():
' and file system encoding is % s' % str(sys.getfilesystemencoding()),
' **********'
))
IOENCODING = str(sys.getfilesystemencoding())

if DEBUGMODE:
try:
print strLog
except:
except Exception, e:
pass
Log.Debug(strLog)
try:
Log.Debug('Platform is %s' % (
os.environ['PLEX_MEDIA_SERVER_INFO_VENDOR']))
except Exception, e:
pass
try:
Log.Debug('Device is %s' % (
os.environ['PLEX_MEDIA_SERVER_INFO_DEVICE']))
except Exception, e:
pass
try:
Log.Debug('Model is %s' % (
os.environ['PLEX_MEDIA_SERVER_INFO_MODEL']))
except Exception, e:
pass
try:
Log.Debug('OS Version is %s' % (
os.environ['PLEX_MEDIA_SERVER_INFO_PLATFORM_VERSION']))
except Exception, e:
pass
Plugin.AddPrefixHandler(PREFIX, launch, NAME, ICON, ART)
Plugin.AddViewGroup('List', viewMode='List', mediaType='items')
Plugin.AddViewGroup("Details", viewMode="InfoList", mediaType="items")
Expand Down Expand Up @@ -365,7 +394,7 @@ def MainMenu(random=0):
oc.add(DirectoryObject(
key=Callback(MainMenu, random=time.clock()),
title="Select Preferences to set the export path"))
except:
except Exception, e:
Log.Critical("Exception happened in MainMenu")
raise
oc.add(PrefsObject(title='Preferences', thumb=R(ICON)))
Expand Down Expand Up @@ -715,7 +744,7 @@ def backgroundScan(title='', key='', sectiontype='', random=0, statusCheck=0):
title="*** Unknown status from scanner ***",
summary=summary))
bScanStatus = 0
except:
except Exception, e:
Log.Critical("Detected an exception in backgroundScan")
raise
Log.Debug("******* Ending backgroundScan ***********")
Expand Down Expand Up @@ -867,6 +896,11 @@ def scanMovieDB(myMediaURL, outFile, level=None):
break
if bScanStatus == 3:
break
# Keep Alive ping to PMS
HTTP.Request(
misc.GetLoopBack() + PREFIX + '/:/prefs',
cacheTime=0,
immediate=True)
output.closefile()
except ValueError, Argument:
Log.Critical('Unknown error in scanMovieDb %s' % Argument)
Expand Down Expand Up @@ -1072,6 +1106,11 @@ def scanShowDB(myMediaURL, outFile, level=None, key=None):
episodeCounter += CONTAINERSIZEEPISODES
if episodeCounter > int(episodeTotalSize):
break
# KeepAlive ping to PMS
HTTP.Request(
misc.GetLoopBack() + PREFIX + '/:/prefs',
cacheTime=0,
immediate=True)
# Got to the end of the line?
if int(partMedias.get('size')) == 0:
break
Expand Down Expand Up @@ -1112,7 +1151,7 @@ def selectPList():
title = playlist.get('title')
try:
thumb = misc.GetLoopBack() + playlist.get('composite')
except:
except Exception, e:
pass
playListType = playlist.get('playlistType')
if playListType in ['video', 'audio', 'photo']:
Expand Down Expand Up @@ -1181,7 +1220,7 @@ def scanPList(key, outFile, level=None):
level=level)
output.writerow(myRow)
output.closefile()
except:
except Exception, e:
Log.Critical("Detected an exception in scanPList")
bScanStatus = 99
# Dumps the error so you can see what the problem is
Expand Down Expand Up @@ -1254,6 +1293,10 @@ def scanArtistDB(myMediaURL, outFile, level=None):
timeout=float(PMSTIMEOUT)).xpath('//Track')[0]
audio.getAudioInfo(track, myRow, level=level)
output.writerow(myRow)
HTTP.Request(
misc.GetLoopBack() + PREFIX + '/:/prefs',
cacheTime=0,
immediate=True)
output.closefile()
except Exception, e:
Log.Exception("Detected an exception in scanArtistDB as: %s" % str(e))
Expand Down Expand Up @@ -1303,7 +1346,7 @@ def scanPhotoDB(myMediaURL, outFile, level=None):
getPhotoItems(medias=medias, bExtraInfo=bExtraInfo, level=level)
iLocalCounter += int(CONTAINERSIZEPHOTO)
output.closefile()
except:
except Exception, e:
Log.Critical("Detected an exception in scanPhotoDB")
bScanStatus = 99
# Dumps the error so you can see what the problem is
Expand Down
3 changes: 2 additions & 1 deletion Contents/Code/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
########################################################################

# APP specific stuff
VERSION = ' V2.0.0.9'
VERSION = ' V2.0.0.10'
APPNAME = 'ExportTools'
NAME = APPNAME + VERSION
DESCRIPTION = 'Export Plex libraries to csv-files or xlsx-files'
Expand All @@ -14,6 +14,7 @@
APPGUID = '7608cf36-742b-11e4-8b39-00af17210b2'
PLAYLIST = 'playlist.png'
DEFAULT = 'N/A'
IOENCODING = ''

# How many items we ask for each time, when accessing a section
CONTAINERSIZEMOVIES = 30
Expand Down
21 changes: 16 additions & 5 deletions Contents/Code/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ def setMax(Max):
iCurrent = 0
global CurStatusFile
CurStatusFile = getStatusFileName()
io.open(CurStatusFile, 'a').close()
try:
io.open(CurStatusFile, 'a').close()
except Exception, e:
# Failback to utf8 if encoding cant be found
io.open(CurStatusFile, 'a', encoding='utf8').close()


def getOutFileName(title, skipts, level, playlist):
Expand Down Expand Up @@ -187,7 +191,7 @@ def createFile(sectionKey, sectionType, title, skipts=False, level=None):
"Level 2",
"Special Level 1"
]:
doPosters = True
doPosters = True
if doPosters:
posterDir = os.path.join(os.path.dirname(outFile), 'posters')
if not os.path.exists(posterDir):
Expand Down Expand Up @@ -228,7 +232,10 @@ def createHeader(outFile, sectionType, playListType='', level=None):
playListType, level)
# Do we have an csv output here?
if extension == '.csv':
targetfile = io.open(outFile, 'wb')
try:
targetfile = io.open(outFile, 'wb')
except Exception, e:
targetfile = io.open(outFile, 'wb', encoding='utf8')
# Create output file, and print the header
writer = csv.DictWriter(
targetfile,
Expand Down Expand Up @@ -400,8 +407,12 @@ def writerow(rowentry):
try:
thumbFile = os.path.join(posterDir, rowentry['Media ID'] + '.jpg')
thumb = HTTP.Request(posterUrl).content
with io.open(thumbFile, 'wb') as handler:
handler.write(thumb)
try:
with io.open(thumbFile, 'wb') as handler:
handler.write(thumb)
except Exception, e:
with io.open(thumbFile, 'wb', encoding='utf8') as handler:
handler.write(thumb)
except Exception, e:
Log.Exception('Exception was %s' % str(e))

Expand Down
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
V2.0.0.10:
- New:
- #131 Additional device logging
- Bug:
- #130 PMS Timeout kills ET after 30 min.
- #128 Shield fails badly

V2.0.0.9:
- Bug:
- #126 Chapter count
Expand Down

0 comments on commit 45fd75e

Please sign in to comment.