kenmills69

Untitled

May 17th, 2021 (edited)
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | None | 0 0
  1. if not no_sources:
  2. # start reading sources.xml and build SQL statements to exclude these sources from any cleaning
  3. try:
  4. display_list =[]
  5. for video in root.findall('video'):
  6. dbglog('Contents of sources.xml file')
  7.  
  8. for sources in video.findall('source'):
  9. for path_name in sources.findall('name'):
  10. the_path_name = path_name.text
  11. for paths in sources.findall('path'):
  12. the_path = paths.text.replace("'","''")
  13. display_list.append(the_path)
  14. dbglog('%s - %s' % (the_path_name, the_path))
  15. if first_time:
  16. first_time = False
  17. my_command = "strPath NOT LIKE '" + the_path + "%'"
  18. our_source_list = 'Keeping files in ' + the_path
  19. else:
  20. my_command = my_command + " AND strPath NOT LIKE '" + the_path + "%'"
  21. our_source_list = our_source_list + ', ' + the_path
  22. if path_name == '':
  23. no_sources = True
  24. dbglog('******* WARNING *******')
  25. dbglog('local sources.xml specified in settings')
  26. dbglog('But no sources found in sources.xml file')
  27. dbglog('Defaulting to alternate method for cleaning')
  28. except:
  29. log('Error parsing sources.xml file')
  30. xbmcgui.Dialog().ok(addonname, 'Error parsing sources.xml file - script aborted')
  31. exit_on_error()
  32.  
  33. if is_pvr:
  34. my_command = my_command + " AND strPath NOT LIKE 'pvr://%'"
  35. our_source_list = our_source_list + 'Keeping PVR info '
  36. if excluding:
  37. my_command = my_command + exclude_command
  38. our_source_list = our_source_list + 'Keeping items from excludes.xml '
  39. if bookmarks:
  40. my_command = my_command + ' AND idFile NOT IN (SELECT idFile FROM bookmark)'
  41. our_source_list = our_source_list + 'Keeping bookmarked files '
  42. # construct the full SQL query
  43.  
  44. sql = \
  45. """DELETE FROM files WHERE idPath IN(SELECT idPath FROM path where (""" + my_command + """));"""
  46. if no_sources:
  47. my_command = ''
  48. our_source_list = 'NO SOURCES FOUND - REMOVING rtmp(e), plugin and http info '
  49. dbglog('Not using sources.xml')
  50. if is_pvr:
  51. my_command = my_command + "strPath NOT LIKE 'pvr://%'"
  52. our_source_list = our_source_list + 'Keeping PVR info '
  53. if bookmarks:
  54. if my_command:
  55. my_command = my_command + ' AND idFile NOT IN (SELECT idFile FROM bookmark)'
  56. else:
  57. my_command = my_command + ' idFile NOT IN (SELECT idFile FROM bookmark)'
  58. our_source_list = our_source_list + 'Keeping bookmarked files '
  59. if excluding:
  60. if my_command:
  61. my_command = my_command + exclude_command
  62. else:
  63. my_command = my_command + exclude_command.replace('AND','',1)
  64. our_source_list = our_source_list + 'Keeping items from excludes.xml '
  65.  
  66. # Build SQL query
  67.  
  68. if not no_sources: # this is SQL for no sources
  69. sql = """DELETE FROM files WHERE idPath IN ( SELECT idPath FROM path WHERE ((""" + my_command + """)));"""
  70. # sql2="""DELETE FROM path WHERE idPath IN (SELECT * FROM( SELECT idPath FROM path WHERE ((strPath LIKE 'rtmp://%' OR strPath Like 'rtmpe:%' OR strPath LIKE 'plugin:%' OR strPath LIKE 'http://%') AND (""" + my_command +"""))) as pathsub);"""
  71. else:
  72. sql = """DELETE FROM files WHERE idPath IN (SELECT idPath FROM path WHERE ((strPath LIKE 'rtmp://%' OR strPath LIKE 'rtmpe:%' OR strPath LIKE 'plugin:%' OR strPath LIKE 'http://%' OR strPath LIKE 'https://%') AND (""" + my_command + """)));"""
  73. # sql2= """DELETE FROM path WHERE idPath IN (SELECT * FROM( SELECT idPath FROM path WHERE (strPath LIKE 'rtmp://%' OR strPath Like 'rtmpe:%' OR strPath LIKE 'plugin:%' OR strPath LIKE 'http://%') as pathsub);"""
  74. if my_command == "":
  75. sql=sql.replace('((strPath','(strPath').replace(' AND ()))',')')
  76. dbglog('SQL command is %s' % sql)
  77. if not specificpath and not replacepath:
  78. dbglog (our_source_list)
  79. our_select = sql.replace('DELETE FROM files','SELECT strPath FROM path',1)
  80. if bookmarks: # have to delete from paths table rather than files as there is a conflicting trigger on the files table
  81. our_select = sql.replace('DELETE FROM files', 'SELECT strPath FROM path WHERE idPath in (SELECT idPath FROM files', 1)
  82. our_select = our_select.replace('bookmark)', 'bookmark))',1)
  83. sql = sql.replace('DELETE FROM files','DELETE FROM path',1)
  84. dbglog('Select Command is %s' % our_select)
  85. elif not replacepath and specificpath: # cleaning a specific path
  86. if specific_path_to_remove != '':
  87. sql = """delete from path where idPath in(select * from (SELECT idPath FROM path WHERE (strPath LIKE '""" + specific_path_to_remove +"""%')) as temptable)"""
  88. our_select = "SELECT strPath FROM path WHERE idPath IN (SELECT idPath FROM path WHERE (strPath LIKE'" + specific_path_to_remove + "%'))"
  89. dbglog('Select Command is %s' % our_select)
  90. else:
  91. xbmcgui.Dialog().ok(addonname,'Error - Specific path selected but no path defined. Script aborted')
  92. dbglog("Error - Specific path selected with no path defined")
  93. exit_on_error()
  94. else: # must be replacing a path at this point
  95. if old_path != '' and new_path != '':
  96. our_select = "SELECT strPath from path WHERE strPath Like '" + old_path + "%'"
  97. else:
  98. xbmcgui.Dialog().ok(addonname,'Error - Replace path selected but one or more paths are not defined. Script aborted')
  99. dbglog('Error - Missing path for replacement')
  100. exit_on_error()
  101. xbmc.sleep(500)
  102.  
  103. if promptdelete:
  104. cleaner_log_file(our_select, False)
  105. mydisplay = MyClass('cleaner-window.xml', addonpath, 'Default', '1080i')
  106. mydisplay.doModal()
  107. del mydisplay
  108. if flag == 1:
  109. i = True
  110. else:
  111. i = False
  112.  
  113. else:
  114. i = True
Add Comment
Please, Sign In to add comment