Advertisement
Guest User

XBMC.MyLibrary Runtime Filter Patch - AngryCamel

a guest
Aug 6th, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 13.32 KB | None | 0 0
  1. Index: utilities/Config.java
  2. ===================================================================
  3. --- utilities/Config.java   (revision 8)
  4. +++ utilities/Config.java   (working copy)
  5. @@ -146,10 +146,10 @@
  6.                  
  7.  
  8.           //populate charactes that we do not allow in file names
  9. -        char[] specialChars = {'<', '>', ':', '"', '/', '\\', '|', '?', '*', '*', '~', '’'};
  10. +        char[] specialChars = {'<', '>', ':', '"', '/', '\\', '|', '?', '*', '*', '~', '٧};
  11.          for(char c : specialChars) ILLEGAL_FILENAME_CHARS.put(new Integer((int) c), "illegal");
  12.  
  13. -        char[] uncommonChars = {'<', '>', ':', '"', '/', '\\', '|', '?', '*', '#', '$', '%', '^', '*', '!', '~','\'', '’', '=', '[' ,']', '(', ')', ';', '\\' ,',', '_'};
  14. +        char[] uncommonChars = {'<', '>', ':', '"', '/', '\\', '|', '?', '*', '#', '$', '%', '^', '*', '!', '~','\'', '٧, '=', '[' ,']', '(', ')', ';', '\\' ,',', '_'};
  15.          for(char c : uncommonChars) UNCOMMON_CHARS.put(new Integer((int) c), "illegal");
  16.  
  17.          //set up logs
  18. Index: utilities/Constants.java
  19. ===================================================================
  20. --- utilities/Constants.java    (revision 8)
  21. +++ utilities/Constants.java    (working copy)
  22. @@ -33,6 +33,9 @@
  23.      public final static String  MOVIE_SET = "MOVIE_SET";
  24.      public final static String  PREFIX = "PREFIX";
  25.      public final static String  SUFFIX = "SUFFIX";
  26. +  
  27. +   //AngryCamel - 20120805 2351
  28. +    public final static String  RUNTIME = "runtime";
  29.  
  30.      public final static String  FOLDERS_ONLY = "FOLDERS_ONLY";
  31.      public final static String  FILES_ONLY = "FILES_ONLY";
  32. Index: utilities/Filter.java
  33. ===================================================================
  34. --- utilities/Filter.java   (revision 8)
  35. +++ utilities/Filter.java   (working copy)
  36. @@ -7,7 +7,7 @@
  37.  
  38.  public class Filter
  39.  {
  40. -    public static boolean FilterMatch(String path, Map<String, List<String>> filters)
  41. +    public static boolean FilterMatch(String path, int runtime, Map<String, List<String>> filters)
  42.      {
  43.          if(filters == null || filters.isEmpty()) return true;//no filters to exclude on
  44.  
  45. @@ -32,6 +32,127 @@
  46.                      if(!path.toLowerCase().contains(filterString.toLowerCase()))
  47.                          return false;//this path does not contains this string, return false because all filters must match
  48.                  }
  49. +               //AngryCamel - 20120805 2351
  50. +               //  <runtime> - Matches if the runtime of the file fits the criteria specified in seconds along with the
  51. +               //   relational operator value. The format is "<relational_operator>|<runtime_seconds>". Posible relational
  52. +               //   operators are: EQ:Equal to, GT:Greater than, LT:Less than, NE:Not equal to, GE:Greater than or equal to,
  53. +               //   LE:Less than or equal to. Matches only on files and not directories.
  54. +               // Example:
  55. +               // <!-- (Recursive) Modern Marvels Episodes over 20 minutes long -->
  56. +               // <subfolder name="History Channel/Modern Marvels" type="episodes" >
  57. +               //      <filter>
  58. +               //          <runtime>GT|1200</runtime>             
  59. +               //      </filter>
  60. +               // </subfolder>
  61. +                else if(type.equalsIgnoreCase(Constants.RUNTIME))
  62. +                {
  63. +                   String[] splitFilterStr;
  64. +                   int runtimeFilter = 0;
  65. +                   String operator = "";
  66. +
  67. +                   Config.log(Config.DEBUG, "Checking runtime filter: "+ filterString);
  68. +                  
  69. +                   splitFilterStr = filterString.split(Pattern.quote("|"));
  70. +                   if(splitFilterStr.length < 2)
  71. +                       return false;//filter string format invalid
  72. +                  
  73. +                   operator = splitFilterStr[0];
  74. +                  
  75. +                   try{
  76. +                       runtimeFilter = Integer.parseInt(splitFilterStr[1]);
  77. +                   }catch (NumberFormatException e){
  78. +                       Config.log(Config.DEBUG, "Failed parsing the runtime filter time to an integer: "+ splitFilterStr[1]);
  79. +                       return false;//filter string format invalid
  80. +                   }
  81. +
  82. +                   Config.log(Config.DEBUG, "   Runtime Filter - operator: "+ operator);
  83. +                   Config.log(Config.DEBUG, "   Runtime Filter - runtime: "+ runtimeFilter);
  84. +                   Config.log(Config.DEBUG, "   Actual Runtime: "+ runtime);
  85. +                  
  86. +                   if(operator.equals("EQ"))
  87. +                   {
  88. +                       //Handle Equal To check here
  89. +                       if(runtime == runtimeFilter)
  90. +                       {
  91. +                           return true;
  92. +                       }
  93. +                       else
  94. +                       {
  95. +                           Config.log(Config.DEBUG, "   Failed: actual runtime is not equal to the filter runtime");
  96. +                           return false;
  97. +                       }
  98. +                   }
  99. +                   else if(operator.equals("GT"))
  100. +                   {
  101. +                       //Handle Greater Than check here
  102. +                       if(runtime > runtimeFilter)
  103. +                       {
  104. +                           return true;
  105. +                       }
  106. +                       else
  107. +                       {
  108. +                           Config.log(Config.DEBUG, "   Failed: actual runtime is not greater than the filter runtime");
  109. +                           return false;
  110. +                       }
  111. +                   }
  112. +                   else if(operator.equals("LT"))
  113. +                   {
  114. +                       //Handle Less Than check here
  115. +                       if(runtime < runtimeFilter)
  116. +                       {
  117. +                           return true;
  118. +                       }
  119. +                       else
  120. +                       {
  121. +                           Config.log(Config.DEBUG, "   Failed: actual runtime is not less than the filter runtime");
  122. +                           return false;
  123. +                       }
  124. +                   }
  125. +                   else if(operator.equals("NE"))
  126. +                   {
  127. +                       //Handle Not Equal To check here
  128. +                       if(runtime != runtimeFilter)
  129. +                       {
  130. +                           return true;
  131. +                       }
  132. +                       else
  133. +                       {
  134. +                           Config.log(Config.DEBUG, "   Failed: actual runtime is equal to the filter runtime");
  135. +                           return false;
  136. +                       }
  137. +                   }
  138. +                   else if(operator.equals("GE"))
  139. +                   {
  140. +                       //Handle Greater than or equal to check here
  141. +                       if(runtime >= runtimeFilter)
  142. +                       {
  143. +                           return true;
  144. +                       }
  145. +                       else
  146. +                       {
  147. +                           Config.log(Config.DEBUG, "   Failed: actual runtime is not greater than or equal to the filter runtime");
  148. +                           return false;
  149. +                       }
  150. +                   }
  151. +                   else if(operator.equals("LE"))
  152. +                   {
  153. +                       //Handle Less than or equal to check here
  154. +                       if(runtime <= runtimeFilter)
  155. +                       {
  156. +                           return true;
  157. +                       }
  158. +                       else
  159. +                       {
  160. +                           Config.log(Config.DEBUG, "   Failed: actual runtime is not less than or equal to the filter runtime");
  161. +                           return false;
  162. +                       }
  163. +                   }
  164. +                   else
  165. +                   {
  166. +                       Config.log(Config.DEBUG, "   Failed: unkown relational operator");
  167. +                       return false;//unknown relational operator
  168. +                   }
  169. +                }
  170.                  else
  171.                  {
  172.                       Config.log(Config.WARNING, "Unknown filter type: \""+type+"\"");
  173. Index: utilities/Subfolder.java
  174. ===================================================================
  175. --- utilities/Subfolder.java    (revision 8)
  176. +++ utilities/Subfolder.java    (working copy)
  177. @@ -341,14 +341,16 @@
  178.       * Returns true if it is allowed by ALL filters or filter matching is not used
  179.       * Returns false if this path should be skipped
  180.       */
  181. -    public boolean isAllowedByFilters(String path)
  182. +   //AngryCamel - 20120805 2351
  183. +    // public boolean isAllowedByFilters(String path)
  184. +   public boolean isAllowedByFilters(String path, int runtime)
  185.      {
  186.          path = Config.escapePath(path);
  187.         //check against filters
  188.         boolean shouldFilter = shouldFilter();
  189.         boolean filterMatch = true;//default
  190.         if(shouldFilter)
  191. -           filterMatch = Filter.FilterMatch(path, filters);
  192. +           filterMatch = Filter.FilterMatch(path, runtime, filters); //AngryCamel - 20120805 2351
  193.          if(!filterMatch)
  194.          {
  195.              Config.log(DEBUG, "Skipping this path because it doesn't match any filters: "+ path);
  196. Index: utilities/XBMCFile.java
  197. ===================================================================
  198. --- utilities/XBMCFile.java (revision 8)
  199. +++ utilities/XBMCFile.java (working copy)
  200. @@ -30,6 +30,9 @@
  201.      boolean hasBeenLookedUpOnTVDB = false;
  202.      String fileOrDir;
  203.      private boolean skippedBecauseAlreadyArchived = false;
  204. +  
  205. +   //AngryCamel - 20120805 2351
  206. +   int runtime=0;
  207.      
  208.      
  209.      ///for multi-file vidoes
  210. @@ -58,24 +61,36 @@
  211.          dest.setTVDBId(source.getTVDBId());
  212.          dest.setYear(source.getYear());
  213.      }
  214. -    public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail, String parentPath, Subfolder matchingSubfolder)
  215. +  
  216. +   //AngryCamel - 20120805 2351
  217. +    //public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail, String parentPath, Subfolder matchingSubfolder)
  218. +   public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail, int runtime, String parentPath, Subfolder matchingSubfolder)
  219.      {
  220.          this.fileOrDir = fileOrDir;
  221.          this.fanart = fanart;
  222.          this.file = file;
  223.          this.fileLabel = fileLabel;// == null ? null : fileLabel.replace("/", "-");
  224.          this.thumbnail = thumbnail;
  225. +      
  226. +       //AngryCamel - 20120805 2351
  227. +        this.runtime = runtime;
  228. +      
  229.          this.parentPath = parentPath;
  230.          this.subfolder = matchingSubfolder;
  231.      }
  232.      
  233. -    public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail)
  234. +    //AngryCamel - 20120805 2351
  235. +    //public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail)
  236. +   public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail, int runtime)
  237.      {
  238.          this.fileOrDir = fileOrDir;
  239.          this.fanart = fanart;
  240.          this.file = file;
  241.          this.fileLabel = fileLabel;// == null ? null : fileLabel.replace("/", "-");
  242.          this.thumbnail = thumbnail;
  243. +      
  244. +       //AngryCamel - 20120805 2351
  245. +        this.runtime = runtime;
  246.      }
  247.      
  248.      //limited constructor used in manual archiving
  249. @@ -266,6 +281,13 @@
  250.      {
  251.          this.episodeNumber = episodeNumber;
  252.      }
  253. +  
  254. +   //AngryCamel - 20120805 2351
  255. +    public void setRuntime(int runtime)
  256. +    {
  257. +        this.runtime = runtime;
  258. +    }
  259. +  
  260.      public int getSeasonNumber()
  261.      {
  262.          return seasonNumber;
  263. @@ -378,6 +400,12 @@
  264.      {
  265.          return parentPath;
  266.      }
  267. +  
  268. +   //AngryCamel - 20120805 2351
  269. +    public int getRuntime()
  270. +    {
  271. +        return runtime;
  272. +    }
  273.  
  274.      public String stripExtras(String source)
  275.      {
  276. Index: utilities/XbmcJsonRpc.java
  277. ===================================================================
  278. --- utilities/XbmcJsonRpc.java  (revision 8)
  279. +++ utilities/XbmcJsonRpc.java  (working copy)
  280. @@ -343,9 +343,10 @@
  281.              XBMCFile xbmcFile = new XBMCFile(
  282.                          fileOrDir,
  283.                          json.has("fanart") ? json.getString("fanart") : null,
  284. -                        json.has("file") ? json.getString("file") : null,
  285. +                        json.has("file") ? json.getString("file") : null,
  286.                          json.has("label") ? json.getString("label") : null,
  287. -                        json.has("thumbnail") ? json.getString("thumbnail") : null
  288. +                        json.has("thumbnail") ? json.getString("thumbnail") : null,
  289. +                       json.has("runtime") ? json.getInt("runtime") : 0 //AngryCamel - 20120805 2351
  290.                      );
  291.              return xbmcFile;
  292.          }
  293. @@ -416,8 +417,15 @@
  294.          params.put("directory",dir);
  295.          
  296.          final String mediaType = "files";//files should return everything after fix here: http://forum.xbmc.org/showthread.php?t=114921
  297. -        params.put("media", mediaType);        
  298. +        params.put("media", mediaType);  
  299.          
  300. +       //AngryCamel - 20120805 2351
  301. +       // -Added runtime for the runtime filter.
  302. +       // -You were referencing label (returned when title is specified in properties), thumbnail, and fanart when creating XBMCFile but
  303. +       //  they were not coming back in the JSON reponse, so I added those while I was at it.
  304. +        final String[] properties = {"runtime", "title", "thumbnail", "fanart"};//files should return everything after fix here: http://forum.xbmc.org/showthread.php?t=114921
  305. +        params.put("properties", properties);  
  306. +        
  307.          /*Sort testing
  308.           *
  309.          boolean sort = true;
  310. @@ -477,10 +485,11 @@
  311.                                      file.getString("file"), //required
  312.                                      file.getString("label"), //required
  313.                                      file.has("thumbnail") ? file.getString("thumbnail") : null,
  314. +                                   file.has("runtime") ? file.getInt("runtime") : 0, //AngryCamel - 20120805 2351
  315.                                      fullPathLabel,
  316.                                      subf);
  317.  
  318. -                           boolean allowed = subf.isAllowedByFilters(xbmcFile.getFullPathEscaped());
  319. +                           boolean allowed = subf.isAllowedByFilters(xbmcFile.getFullPathEscaped(), xbmcFile.getRuntime()); //AngryCamel - 20120805 2351
  320.                             if(!allowed) continue;
  321.  
  322.                             boolean excluded = subf.isExcluded(xbmcFile.getFullPathEscaped());
  323. @@ -521,6 +530,7 @@
  324.                                                  file, //required
  325.                                                  label, //required
  326.                                                  directory.has("thumbnail") ? directory.getString("thumbnail") : null,
  327. +                                               0, //AngryCamel - 20120805 2351
  328.                                                  fullPathLabel,
  329.                                                  subf);
  330.                                  filesAndDirsFound.put(xbmcFile);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement