Skip to content

Commit 9605090

Browse files
authored
Merge pull request #263 from ukdtom/dev-2.4
Dev 2.4
2 parents 2686b7b + 64b90db commit 9605090

30 files changed

+667
-177
lines changed
690 Bytes
Binary file not shown.

Contents/Code/__init__.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
13
######################################################################################################################
24
# WebTools bundle for Plex
35
#
@@ -19,16 +21,16 @@
1921
from random import randint #Used for Cookie generation
2022
import uuid #Used for secrectKey
2123
import time
24+
import socket
2225
from consts import DEBUGMODE, VERSION, PREFIX, NAME, ICON
2326

2427
#********** Initialize *********
2528
def Start():
2629
global SECRETKEY
27-
30+
runningLocale = locale.getdefaultlocale()
2831
if DEBUGMODE:
29-
print("******** Started %s on %s at %s **********" %(NAME + ' V' + VERSION, Platform.OS, time.strftime("%Y-%m-%d %H:%M")))
30-
Log.Debug("******* Started %s on %s at %s ***********" %(NAME + ' V' + VERSION, Platform.OS, time.strftime("%Y-%m-%d %H:%M")))
31-
Log.Debug('Locale is: ' + str(locale.getdefaultlocale()))
32+
print("******** Started %s on %s at %s with locale set to %s **********" %(NAME + ' V' + VERSION, Platform.OS, time.strftime("%Y-%m-%d %H:%M"), runningLocale))
33+
Log.Debug("******* Started %s on %s at %s with locale set to %s ***********" %(NAME + ' V' + VERSION, Platform.OS, time.strftime("%Y-%m-%d %H:%M"), runningLocale))
3234
# TODO: Nasty workaround for issue 189
3335
if (Platform.OS == 'Windows' and locale.getpreferredencoding() == 'cp1251'):
3436
sys.setdefaultencoding("cp1251")
@@ -64,6 +66,9 @@ def makeSettings():
6466
if Dict['options_hide_integrated'] == None:
6567
Dict['options_hide_integrated'] = 'false'
6668
# Set default value for http part, if run for the first time
69+
if Dict['options_hide_withoutsubs'] == None:
70+
Dict['options_hide_withoutsubs'] = 'false'
71+
# Set default value for http part, if run for the first time
6772
if Dict['options_hide_local'] == None:
6873
Dict['options_hide_local'] = 'false'
6974
# Set default value for http part, if run for the first time

Contents/Code/consts.py

100644100755
+28-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
######################################################################################################################
2-
# Plex2CSV module unit
2+
# WebTools module unit
33
#
44
# Author: dane22, a Plex Community member
55
#
@@ -19,6 +19,7 @@
1919
NAME = 'WebTools'
2020
ICON = 'WebTools.png'
2121
JSONTIMESTAMP = 0 # timestamp for json export
22+
WTURL = 'https://api.github.com/repos/ukdtom/WebTools.bundle/releases/latest' # URL to latest WebTools
2223

2324

2425
class consts(object):
@@ -33,9 +34,13 @@ def __init__(self):
3334
global JSONTIMESTAMP
3435

3536
# Grap version number from the version file
36-
versionFile = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, NAME + '.bundle', 'VERSION')
37-
with io.open(versionFile, "rb") as version_file:
38-
VERSION = version_file.read().replace('\n','')
37+
try:
38+
versionFile = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, NAME + '.bundle', 'VERSION')
39+
with io.open(versionFile, "rb") as version_file:
40+
VERSION = version_file.read().splitlines()[0]
41+
except:
42+
if not self.isCorrectPath():
43+
VERSION = '*** WRONG INSTALL PATH!!!!....Correct path is: ' + Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, NAME + '.bundle' + '***')
3944

4045
# Switch to debug mode if needed
4146
debugFile = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, NAME + '.bundle', 'debug')
@@ -70,6 +75,25 @@ def __init__(self):
7075
else:
7176
DEBUGMODE = False
7277

78+
# Verify install path
79+
def isCorrectPath(self):
80+
installedPlugInPath, skipStr = abspath(getsourcefile(lambda:0)).upper().split(str(NAME).upper() + '.BUNDLE',1)
81+
targetPath = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name).upper()
82+
if installedPlugInPath[:-1] != targetPath:
83+
Log.Debug('************************************************')
84+
Log.Debug('Wrong installation path detected!!!!')
85+
Log.Debug('')
86+
Log.Debug('Correct path is:')
87+
Log.Debug(Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, NAME + '.bundle'))
88+
Log.Debug('************************************************')
89+
installedPlugInPath, skipStr = abspath(getsourcefile(lambda:0)).split('/Contents',1)
90+
return False
91+
else:
92+
Log.Info('Verified a correct install path as: ' + targetPath)
93+
return True
94+
95+
96+
7397
consts = consts()
7498

7599

Contents/Code/findMedia.py

+85-52
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@
2828
excludeElements='Actor,Collection,Country,Director,Genre,Label,Mood,Producer,Role,Similar,Writer'
2929
excludeFields='summary,tagline'
3030

31+
DEFAULTPREFS = {
32+
'IGNORE_HIDDEN' : True,
33+
'IGNORED_DIRS' : [".@__thumb",".AppleDouble","lost+found"],
34+
'VALID_EXTENSIONS' : ['3g2', '3gp', 'asf', 'asx', 'avc', 'avi', 'avs', 'bivx', 'bup', 'divx', 'dv', 'dvr-ms', 'evo',
35+
'fli', 'flv', 'm2t', 'm2ts', 'm2v', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mts', 'nsv',
36+
'nuv', 'ogm', 'ogv', 'tp', 'pva', 'qt', 'rm', 'rmvb', 'sdp', 'svq3', 'strm', 'ts', 'ty', 'vdr',
37+
'viv', 'vob', 'vp3', 'wmv', 'wpl', 'wtv', 'xsp', 'xvid', 'webm']
38+
}
39+
3140

3241

3342
class findMedia(object):
@@ -37,26 +46,27 @@ class findMedia(object):
3746
# Defaults used by the rest of the class
3847
def __init__(self):
3948
global retMsg
40-
# Only init once during the lifetime of this
41-
if not findMedia.init_already:
42-
findMedia.init_already = True
43-
retMsg = ['WebTools']
44-
self.populatePrefs()
45-
Log.Debug('******* Starting findMedia *******')
46-
self.MediaChuncks = 40
47-
self.CoreUrl = 'http://127.0.0.1:32400/library/sections/'
49+
global MediaChuncks
50+
global CoreUrl
51+
try:
52+
# Only init once during the lifetime of this
53+
if not findMedia.init_already:
54+
findMedia.init_already = True
55+
retMsg = ['WebTools']
56+
self.populatePrefs()
57+
Log.Debug('******* Starting findMedia *******')
58+
Log.Debug('********* Prefs are ***********')
59+
Log.Debug(Dict['findMedia'])
60+
self.MediaChuncks = 40
61+
self.CoreUrl = misc.GetLoopBack() + '/library/sections/'
62+
except exception, e:
63+
Log.Critical('Exception in FM Init was %s' %(e))
64+
4865

4966
''' Populate the defaults, if not already there '''
5067
def populatePrefs(self):
5168
if Dict['findMedia'] == None:
52-
Dict['findMedia'] = {
53-
'IGNORE_HIDDEN' : True,
54-
'IGNORED_DIRS' : [".@__thumb",".AppleDouble","lost+found"],
55-
'VALID_EXTENSIONS' : ['3g2', '3gp', 'asf', 'asx', 'avc', 'avi', 'avs', 'bivx', 'bup', 'divx', 'dv', 'dvr-ms', 'evo',
56-
'fli', 'flv', 'm2t', 'm2ts', 'm2v', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mts', 'nsv',
57-
'nuv', 'ogm', 'ogv', 'tp', 'pva', 'qt', 'rm', 'rmvb', 'sdp', 'svq3', 'strm', 'ts', 'ty', 'vdr',
58-
'viv', 'vob', 'vp3', 'wmv', 'wpl', 'wtv', 'xsp', 'xvid', 'webm']
59-
}
69+
Dict['findMedia'] = DEFAULTPREFS
6070
Dict.Save()
6171

6272
''' Grap the tornado req, and process it '''
@@ -276,44 +286,67 @@ def getFiles(filePath):
276286
runningState = -1
277287
Log.Debug("*********************** FileSystem scan Paths: *****************************************")
278288
bScanStatusCount = 0
279-
# Wondering why I do below. Part of find-unmatched, and forgot....SIGH
280-
files = str(filePath)[2:-2].replace("'", "").split(', ')
281289
#for filePath in files:
282-
for filePath in filePath:
290+
for Path in filePath:
283291
# Decode filePath
284292
bScanStatusCount += 1
285-
filePath2 = urllib.unquote(filePath).decode('utf8')
286-
filePath2 = misc().Unicodize(filePath2)
293+
filePath2 = urllib.unquote(Path).decode('utf8')
294+
filePath2 = misc.Unicodize(filePath2)
287295
Log.Debug("Handling filepath #%s: %s" %(bScanStatusCount, filePath2.encode('utf8', 'ignore')))
288-
for root, subdirs, files in os.walk(filePath2):
289-
# Need to check if directory in ignore list?
290-
if os.path.basename(root) in Dict['findMedia']['IGNORED_DIRS']:
291-
continue
292-
# Lets look at the file
293-
for file in files:
294-
file = misc().Unicodize(file).encode('utf8')
295-
if bAbort:
296-
Log.Info('Aborted in getFiles')
297-
raise ValueError('Aborted')
298-
if os.path.splitext(file)[1].lower()[1:] in Dict['findMedia']['VALID_EXTENSIONS']:
299-
# File has a valid extention
300-
if file.startswith('.') and Dict['findMedia']['IGNORE_HIDDEN']:
301-
continue
302-
# Filter out local extras
303-
if '-' in file:
304-
if os.path.splitext(os.path.basename(file))[0].rsplit('-', 1)[1].lower() in Extras:
296+
try:
297+
for root, subdirs, files in os.walk(filePath2):
298+
if DEBUGMODE:
299+
Log.Debug('Extreme root: ' + root)
300+
Log.Debug('Extreme subdirs: ' + str(subdirs))
301+
Log.Debug('Extreme files: ' + str(files))
302+
# Need to check if directory in ignore list?
303+
if os.path.basename(root) in Dict['findMedia']['IGNORED_DIRS']:
304+
if DEBUGMODE:
305+
Log.Debug('root in ignored dirs: ' + root)
306+
continue
307+
# Lets look at the file
308+
for file in files:
309+
file = misc.Unicodize(file).encode('utf8')
310+
if DEBUGMODE:
311+
Log.Debug('file in files: ' + file)
312+
if bAbort:
313+
Log.Info('Aborted in getFiles')
314+
raise ValueError('Aborted')
315+
if DEBUGMODE:
316+
Log.Debug('File extention is : ' + os.path.splitext(file)[1][1:].lower())
317+
if os.path.splitext(file)[1][1:].lower() in Dict['findMedia']['VALID_EXTENSIONS']:
318+
if DEBUGMODE:
319+
Log.Debug('File has valid extention, so checking it out')
320+
# File has a valid extention
321+
if file.startswith('.') and Dict['findMedia']['IGNORE_HIDDEN']:
322+
if DEBUGMODE:
323+
Log.Debug('File hidden, so ignore : ' + file)
305324
continue
306-
# filter out local extras directories
307-
if os.path.basename(os.path.normpath(root)).lower() in ExtrasDirs:
308-
continue
309-
composed_file = misc().Unicodize(Core.storage.join_path(root,file))
310-
if Platform.OS == 'Windows':
311-
# I hate windows
312-
pos = composed_file.find(':') -1
313-
#composed_file = composed_file[4:]
314-
composed_file = composed_file[pos:]
315-
mediasFromFileSystem.append(composed_file)
316-
statusMsg = 'Scanning file: ' + file
325+
# Filter out local extras
326+
if '-' in file:
327+
if os.path.splitext(os.path.basename(file))[0].rsplit('-', 1)[1].lower() in Extras:
328+
if DEBUGMODE:
329+
Log.Debug('Ignoring Extras file %s' %(os.path.basename(file)))
330+
continue
331+
# filter out local extras directories
332+
if os.path.basename(os.path.normpath(root)).lower() in ExtrasDirs:
333+
if DEBUGMODE:
334+
Log.Debug('Ignoring Extras dir %s' %(root))
335+
continue
336+
composed_file = misc.Unicodize(Core.storage.join_path(root,file))
337+
if Platform.OS == 'Windows':
338+
# I hate windows
339+
pos = composed_file.find(':') -1
340+
if pos != -2:
341+
# We dont got an UNC path here
342+
composed_file = composed_file[pos:]
343+
mediasFromFileSystem.append(composed_file)
344+
if DEBUGMODE:
345+
Log.Debug('Scanning file: ' + file)
346+
Log.Debug('appending file: ' + composed_file)
347+
statusMsg = 'Scanning file: ' + file
348+
except Exception, e:
349+
Log.Exception('Exception happened in FM scanning filesystem: ' + str(e))
317350
Log.Debug('***** Finished scanning filesystem *****')
318351
if DEBUGMODE:
319352
Log.Debug(mediasFromFileSystem)
@@ -355,7 +388,7 @@ def scanShowDB(sectionNumber=0):
355388
iCSeason = 0
356389
# Grap seasons
357390
while True:
358-
seasons = XML.ElementFromURL('http://127.0.0.1:32400' + show.get('key') + '?X-Plex-Container-Start=' + str(iCSeason) + '&X-Plex-Container-Size=' + str(self.MediaChuncks) + '&excludeElements=' + excludeElements + '&excludeFields=' + excludeFields).xpath('//Directory')
391+
seasons = XML.ElementFromURL(misc.GetLoopBack() + show.get('key') + '?X-Plex-Container-Start=' + str(iCSeason) + '&X-Plex-Container-Size=' + str(self.MediaChuncks) + '&excludeElements=' + excludeElements + '&excludeFields=' + excludeFields).xpath('//Directory')
359392
# Grap individual season
360393
for season in seasons:
361394
if season.get('title') == 'All episodes':
@@ -368,7 +401,7 @@ def scanShowDB(sectionNumber=0):
368401
iEpisode = 0
369402
iCEpisode = 0
370403
while True:
371-
episodes = XML.ElementFromURL('http://127.0.0.1:32400' + season.get('key') + '?X-Plex-Container-Start=' + str(iCEpisode) + '&X-Plex-Container-Size=' + str(self.MediaChuncks) + '&excludeElements=' + excludeElements + '&excludeFields=' + excludeFields).xpath('//Part')
404+
episodes = XML.ElementFromURL(misc.GetLoopBack() + season.get('key') + '?X-Plex-Container-Start=' + str(iCEpisode) + '&X-Plex-Container-Size=' + str(self.MediaChuncks) + '&excludeElements=' + excludeElements + '&excludeFields=' + excludeFields).xpath('//Part')
372405
for episode in episodes:
373406
if bAbort:
374407
raise ValueError('Aborted')
@@ -432,7 +465,7 @@ def scanMovieDb(sectionNumber=0):
432465
raise ValueError('Aborted')
433466
iCount += 1
434467
filename = part.get('file')
435-
filename = unicode(misc().Unicodize(part.get('file')).encode('utf8', 'ignore'))
468+
filename = unicode(misc.Unicodize(part.get('file')).encode('utf8', 'ignore'))
436469
mediasFromDB.append(filename)
437470
statusMsg = 'Scanning database: item %s of %s : Working' %(iCount, totalSize)
438471
iStart += self.MediaChuncks

Contents/Code/git.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import plistlib
1414
import pms
1515
import tempfile
16-
from consts import DEBUGMODE, UAS_URL, UAS_BRANCH, NAME
16+
from consts import DEBUGMODE, UAS_URL, UAS_BRANCH, NAME, WTURL
1717

1818
class git(object):
1919
init_already = False # Make sure part of init only run once
@@ -120,18 +120,20 @@ def removeEmptyFolders(path, removeRoot=True):
120120
# Reset dicts
121121
nukeSpecialDicts()
122122

123-
url= req.get_argument('debugURL', 'https://api.github.com/repos/dagalufh/WebTools.bundle/releases/latest')
123+
url= req.get_argument('debugURL', WTURL)
124124
bundleName = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, NAME + '.bundle')
125125
Log.Info('WT install dir is: ' + bundleName)
126126
try:
127-
if url == 'https://api.github.com/repos/dagalufh/WebTools.bundle/releases/latest':
127+
if 'https://api.github.com/repos/' in url:
128128
Log.Debug('Getting release info from url: ' + url)
129129
jsonReponse = JSON.ObjectFromURL(url)
130-
wtURL = jsonReponse['assets'][0]['browser_download_url']
130+
# Walk assets to find the one named WebTools.bundle.zip
131+
for asset in jsonReponse['assets']:
132+
if asset['name'] == 'WebTools.bundle.zip':
133+
wtURL = asset['browser_download_url']
131134
else:
132135
wtURL = url.replace('tree', 'archive') + '.zip'
133136
Log.Info('WT Download url detected as: ' + wtURL)
134-
135137
# Grap file from Github
136138
zipfile = Archive.ZipFromURL(wtURL)
137139
bError = True
@@ -241,12 +243,16 @@ def getUpdateList(self, req):
241243
gitTime = datetime.datetime.strptime(self.getLastUpdateTime(req, UAS=True, url=bundle), '%Y-%m-%d %H:%M:%S')
242244
sBundleTime = Dict['installed'][bundle]['date']
243245
bundleTime = datetime.datetime.strptime(sBundleTime, '%Y-%m-%d %H:%M:%S')
246+
# Fix for old stuff, where branch was empty
247+
if Dict['installed'][bundle]['branch'] == '':
248+
Dict['installed'][bundle]['branch'] = 'master'
249+
Dict.Save()
244250
if bundleTime < gitTime:
245251
gitInfo = Dict['installed'][bundle]
246252
gitInfo['gitHubTime'] = str(gitTime)
247253
result[bundle] = gitInfo
248254
else:
249-
# Let's get a CommitId stamped for future times
255+
# Let's get a CommitId stamped for future times
250256
updateInfo = self.getAtom_UpdateTime_Id(bundle, Dict['installed'][bundle]['branch'])
251257
Log.Info('Stamping %s with a commitId of %s for future ref' %(bundle, updateInfo['commitId']))
252258
Dict['installed'][bundle]['CommitId'] = updateInfo['commitId']

0 commit comments

Comments
 (0)