Skip to content

Commit

Permalink
Fixed issue #189
Browse files Browse the repository at this point in the history
  • Loading branch information
ukdtom committed Jul 14, 2016
1 parent 32064e7 commit 5df58bf
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
SECRETKEY = ''

#********** Imports needed *********
import sys, locale
from webSrv import startWeb, stopWeb
from random import randint #Used for Cookie generation
import uuid #Used for secrectKey
Expand All @@ -27,6 +28,10 @@ def Start():
if DEBUGMODE:
print("******** Started %s on %s at %s **********" %(NAME + ' V' + VERSION, Platform.OS, time.strftime("%Y-%m-%d %H:%M")))
Log.Debug("******* Started %s on %s at %s ***********" %(NAME + ' V' + VERSION, Platform.OS, time.strftime("%Y-%m-%d %H:%M")))
# TODO: Nasty workaround for issue 189
if (Platform.OS == 'Windows' and locale.getpreferredencoding() == 'cp1251'):
sys.setdefaultencoding("cp1251")
Log.Debug("Default set to cp1251")
HTTP.CacheTime = 0
DirectoryObject.thumb = R(ICON)
ObjectContainer.title1 = NAME + ' V' + VERSION
Expand Down
84 changes: 84 additions & 0 deletions Contents/Code/nfoExporter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
######################################################################################################################
# NFO Exporter module for WebTools
#
# Author: dane22, a Plex Community member
#
######################################################################################################################

statusMsg = 'idle' # Response to getStatus
runningState = 0 # Internal tracker of where we are
bAbort = False # Flag to set if user wants to cancel

class nfoExporter(object):
init_already = False # Make sure init only run once
bResultPresent = False # Do we have a result to present

# Defaults used by the rest of the class
def __init__(self):
# Only init once during the lifetime of this
if not nfoExporter.init_already:
nfoExporter.init_already = True
self.populatePrefs()
Log.Debug('******* Starting nfoExporter *******')

''' Populate the defaults, if not already there '''
def populatePrefs(self):
if Dict['nfoExporter'] == None:
Dict['nfoExporter'] = {}
Dict.Save()


''' Grap the tornado req, and process it for a POST request'''
def reqprocessPost(self, req):
function = req.get_argument('function', 'missing')
if function == 'missing':
req.clear()
req.set_status(412)
req.finish("<html><body>Missing function parameter</body></html>")
elif function == 'export':
return self.export(req)
else:
req.clear()
req.set_status(412)
req.finish("<html><body>Unknown function call</body></html>")

def export(self, req):

''' Return the type of the section '''
def getSectionType(section):
url = 'http://127.0.0.1:32400/library/sections/' + section + '/all?X-Plex-Container-Start=1&X-Plex-Container-Size=0'
return XML.ElementFromURL(url).xpath('//MediaContainer/@viewGroup')[0]

def scanMovieSection(req, section):
print 'Ged1 scanMovieSection'

def scanShowSection(req, section):
print 'Ged1 scanShowSection'


# ********** Main function **************
Log.Info('nfo export called')
try:
section = req.get_argument('section', '_export_missing_')
if section == '_export_missing_':
req.clear()
req.set_status(412)
req.finish("<html><body>Missing section parameter</body></html>")
if getSectionType(section) == 'movie':
scanMovieSection(req, section)
elif getSectionType(section) == 'show':
scanShowSection(req, section)
else:
Log.debug('Unknown section type for section:' + section + ' type: ' + getSectionType(section))
req.clear()
req.set_status(404)
req.finish("Unknown sectiontype")
except Exception, e:
Log.Exception('Exception in nfo export' + str(e))







7 changes: 4 additions & 3 deletions Contents/Code/webSrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from tornado.escape import json_encode, xhtml_escape

import threading
import os, sys

# Migrated to new way
from plextvhelper import plexTV
Expand All @@ -30,9 +31,7 @@
from plex2csv import plex2csv
from wt import wt
from scheduler import scheduler


import os, sys
from nfoExporter import nfoExporter

# Below used to find path of this file
from inspect import getsourcefile
Expand Down Expand Up @@ -337,6 +336,8 @@ def post(self, **params):
self = wt().reqprocessPost(self)
elif module == 'scheduler':
self = scheduler().reqprocessPost(self)
elif module == 'nfoExporter':
self = nfoExporter().reqprocessPost(self)
else:
self.clear()
self.set_status(412)
Expand Down
1 change: 1 addition & 0 deletions http/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ V2.3 DEV:
#184 WT: Logging can fail on Mac OS
#134 UAS: Wrong time for Latest Update on Github
#187 UAS: Fix for correct sorting. Now sorts alphabetical without concerning about capital/lower case letters.
#189 WT: Fix for startup issue if on Windows and lang is set to CP1251

New:
#170 WT: Added a user guide from Trumpy81. URL is /manual/WebTools-User-Manual.pdf
Expand Down

0 comments on commit 5df58bf

Please sign in to comment.