28
28
excludeElements = 'Actor,Collection,Country,Director,Genre,Label,Mood,Producer,Role,Similar,Writer'
29
29
excludeFields = 'summary,tagline'
30
30
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
+
31
40
32
41
33
42
class findMedia (object ):
@@ -37,26 +46,27 @@ class findMedia(object):
37
46
# Defaults used by the rest of the class
38
47
def __init__ (self ):
39
48
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
+
48
65
49
66
''' Populate the defaults, if not already there '''
50
67
def populatePrefs (self ):
51
68
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
60
70
Dict .Save ()
61
71
62
72
''' Grap the tornado req, and process it '''
@@ -276,44 +286,67 @@ def getFiles(filePath):
276
286
runningState = - 1
277
287
Log .Debug ("*********************** FileSystem scan Paths: *****************************************" )
278
288
bScanStatusCount = 0
279
- # Wondering why I do below. Part of find-unmatched, and forgot....SIGH
280
- files = str (filePath )[2 :- 2 ].replace ("'" , "" ).split (', ' )
281
289
#for filePath in files:
282
- for filePath in filePath :
290
+ for Path in filePath :
283
291
# Decode filePath
284
292
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 )
287
295
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 )
305
324
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 ))
317
350
Log .Debug ('***** Finished scanning filesystem *****' )
318
351
if DEBUGMODE :
319
352
Log .Debug (mediasFromFileSystem )
@@ -355,7 +388,7 @@ def scanShowDB(sectionNumber=0):
355
388
iCSeason = 0
356
389
# Grap seasons
357
390
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' )
359
392
# Grap individual season
360
393
for season in seasons :
361
394
if season .get ('title' ) == 'All episodes' :
@@ -368,7 +401,7 @@ def scanShowDB(sectionNumber=0):
368
401
iEpisode = 0
369
402
iCEpisode = 0
370
403
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' )
372
405
for episode in episodes :
373
406
if bAbort :
374
407
raise ValueError ('Aborted' )
@@ -432,7 +465,7 @@ def scanMovieDb(sectionNumber=0):
432
465
raise ValueError ('Aborted' )
433
466
iCount += 1
434
467
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' ))
436
469
mediasFromDB .append (filename )
437
470
statusMsg = 'Scanning database: item %s of %s : Working' % (iCount , totalSize )
438
471
iStart += self .MediaChuncks
0 commit comments