Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: utilities/Config.java
- ===================================================================
- --- utilities/Config.java (revision 8)
- +++ utilities/Config.java (working copy)
- @@ -146,10 +146,10 @@
- //populate charactes that we do not allow in file names
- - char[] specialChars = {'<', '>', ':', '"', '/', '\\', '|', '?', '*', '*', '~', '’'};
- + char[] specialChars = {'<', '>', ':', '"', '/', '\\', '|', '?', '*', '*', '~', '٧};
- for(char c : specialChars) ILLEGAL_FILENAME_CHARS.put(new Integer((int) c), "illegal");
- - char[] uncommonChars = {'<', '>', ':', '"', '/', '\\', '|', '?', '*', '#', '$', '%', '^', '*', '!', '~','\'', '’', '=', '[' ,']', '(', ')', ';', '\\' ,',', '_'};
- + char[] uncommonChars = {'<', '>', ':', '"', '/', '\\', '|', '?', '*', '#', '$', '%', '^', '*', '!', '~','\'', '٧, '=', '[' ,']', '(', ')', ';', '\\' ,',', '_'};
- for(char c : uncommonChars) UNCOMMON_CHARS.put(new Integer((int) c), "illegal");
- //set up logs
- Index: utilities/Constants.java
- ===================================================================
- --- utilities/Constants.java (revision 8)
- +++ utilities/Constants.java (working copy)
- @@ -33,6 +33,9 @@
- public final static String MOVIE_SET = "MOVIE_SET";
- public final static String PREFIX = "PREFIX";
- public final static String SUFFIX = "SUFFIX";
- +
- + //AngryCamel - 20120805 2351
- + public final static String RUNTIME = "runtime";
- public final static String FOLDERS_ONLY = "FOLDERS_ONLY";
- public final static String FILES_ONLY = "FILES_ONLY";
- Index: utilities/Filter.java
- ===================================================================
- --- utilities/Filter.java (revision 8)
- +++ utilities/Filter.java (working copy)
- @@ -7,7 +7,7 @@
- public class Filter
- {
- - public static boolean FilterMatch(String path, Map<String, List<String>> filters)
- + public static boolean FilterMatch(String path, int runtime, Map<String, List<String>> filters)
- {
- if(filters == null || filters.isEmpty()) return true;//no filters to exclude on
- @@ -32,6 +32,127 @@
- if(!path.toLowerCase().contains(filterString.toLowerCase()))
- return false;//this path does not contains this string, return false because all filters must match
- }
- + //AngryCamel - 20120805 2351
- + // <runtime> - Matches if the runtime of the file fits the criteria specified in seconds along with the
- + // relational operator value. The format is "<relational_operator>|<runtime_seconds>". Posible relational
- + // operators are: EQ:Equal to, GT:Greater than, LT:Less than, NE:Not equal to, GE:Greater than or equal to,
- + // LE:Less than or equal to. Matches only on files and not directories.
- + // Example:
- + // <!-- (Recursive) Modern Marvels Episodes over 20 minutes long -->
- + // <subfolder name="History Channel/Modern Marvels" type="episodes" >
- + // <filter>
- + // <runtime>GT|1200</runtime>
- + // </filter>
- + // </subfolder>
- + else if(type.equalsIgnoreCase(Constants.RUNTIME))
- + {
- + String[] splitFilterStr;
- + int runtimeFilter = 0;
- + String operator = "";
- +
- + Config.log(Config.DEBUG, "Checking runtime filter: "+ filterString);
- +
- + splitFilterStr = filterString.split(Pattern.quote("|"));
- + if(splitFilterStr.length < 2)
- + return false;//filter string format invalid
- +
- + operator = splitFilterStr[0];
- +
- + try{
- + runtimeFilter = Integer.parseInt(splitFilterStr[1]);
- + }catch (NumberFormatException e){
- + Config.log(Config.DEBUG, "Failed parsing the runtime filter time to an integer: "+ splitFilterStr[1]);
- + return false;//filter string format invalid
- + }
- +
- + Config.log(Config.DEBUG, " Runtime Filter - operator: "+ operator);
- + Config.log(Config.DEBUG, " Runtime Filter - runtime: "+ runtimeFilter);
- + Config.log(Config.DEBUG, " Actual Runtime: "+ runtime);
- +
- + if(operator.equals("EQ"))
- + {
- + //Handle Equal To check here
- + if(runtime == runtimeFilter)
- + {
- + return true;
- + }
- + else
- + {
- + Config.log(Config.DEBUG, " Failed: actual runtime is not equal to the filter runtime");
- + return false;
- + }
- + }
- + else if(operator.equals("GT"))
- + {
- + //Handle Greater Than check here
- + if(runtime > runtimeFilter)
- + {
- + return true;
- + }
- + else
- + {
- + Config.log(Config.DEBUG, " Failed: actual runtime is not greater than the filter runtime");
- + return false;
- + }
- + }
- + else if(operator.equals("LT"))
- + {
- + //Handle Less Than check here
- + if(runtime < runtimeFilter)
- + {
- + return true;
- + }
- + else
- + {
- + Config.log(Config.DEBUG, " Failed: actual runtime is not less than the filter runtime");
- + return false;
- + }
- + }
- + else if(operator.equals("NE"))
- + {
- + //Handle Not Equal To check here
- + if(runtime != runtimeFilter)
- + {
- + return true;
- + }
- + else
- + {
- + Config.log(Config.DEBUG, " Failed: actual runtime is equal to the filter runtime");
- + return false;
- + }
- + }
- + else if(operator.equals("GE"))
- + {
- + //Handle Greater than or equal to check here
- + if(runtime >= runtimeFilter)
- + {
- + return true;
- + }
- + else
- + {
- + Config.log(Config.DEBUG, " Failed: actual runtime is not greater than or equal to the filter runtime");
- + return false;
- + }
- + }
- + else if(operator.equals("LE"))
- + {
- + //Handle Less than or equal to check here
- + if(runtime <= runtimeFilter)
- + {
- + return true;
- + }
- + else
- + {
- + Config.log(Config.DEBUG, " Failed: actual runtime is not less than or equal to the filter runtime");
- + return false;
- + }
- + }
- + else
- + {
- + Config.log(Config.DEBUG, " Failed: unkown relational operator");
- + return false;//unknown relational operator
- + }
- + }
- else
- {
- Config.log(Config.WARNING, "Unknown filter type: \""+type+"\"");
- Index: utilities/Subfolder.java
- ===================================================================
- --- utilities/Subfolder.java (revision 8)
- +++ utilities/Subfolder.java (working copy)
- @@ -341,14 +341,16 @@
- * Returns true if it is allowed by ALL filters or filter matching is not used
- * Returns false if this path should be skipped
- */
- - public boolean isAllowedByFilters(String path)
- + //AngryCamel - 20120805 2351
- + // public boolean isAllowedByFilters(String path)
- + public boolean isAllowedByFilters(String path, int runtime)
- {
- path = Config.escapePath(path);
- //check against filters
- boolean shouldFilter = shouldFilter();
- boolean filterMatch = true;//default
- if(shouldFilter)
- - filterMatch = Filter.FilterMatch(path, filters);
- + filterMatch = Filter.FilterMatch(path, runtime, filters); //AngryCamel - 20120805 2351
- if(!filterMatch)
- {
- Config.log(DEBUG, "Skipping this path because it doesn't match any filters: "+ path);
- Index: utilities/XBMCFile.java
- ===================================================================
- --- utilities/XBMCFile.java (revision 8)
- +++ utilities/XBMCFile.java (working copy)
- @@ -30,6 +30,9 @@
- boolean hasBeenLookedUpOnTVDB = false;
- String fileOrDir;
- private boolean skippedBecauseAlreadyArchived = false;
- +
- + //AngryCamel - 20120805 2351
- + int runtime=0;
- ///for multi-file vidoes
- @@ -58,24 +61,36 @@
- dest.setTVDBId(source.getTVDBId());
- dest.setYear(source.getYear());
- }
- - public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail, String parentPath, Subfolder matchingSubfolder)
- +
- + //AngryCamel - 20120805 2351
- + //public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail, String parentPath, Subfolder matchingSubfolder)
- + public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail, int runtime, String parentPath, Subfolder matchingSubfolder)
- {
- this.fileOrDir = fileOrDir;
- this.fanart = fanart;
- this.file = file;
- this.fileLabel = fileLabel;// == null ? null : fileLabel.replace("/", "-");
- this.thumbnail = thumbnail;
- +
- + //AngryCamel - 20120805 2351
- + this.runtime = runtime;
- +
- this.parentPath = parentPath;
- this.subfolder = matchingSubfolder;
- }
- - public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail)
- + //AngryCamel - 20120805 2351
- + //public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail)
- + public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail, int runtime)
- {
- this.fileOrDir = fileOrDir;
- this.fanart = fanart;
- this.file = file;
- this.fileLabel = fileLabel;// == null ? null : fileLabel.replace("/", "-");
- this.thumbnail = thumbnail;
- +
- + //AngryCamel - 20120805 2351
- + this.runtime = runtime;
- }
- //limited constructor used in manual archiving
- @@ -266,6 +281,13 @@
- {
- this.episodeNumber = episodeNumber;
- }
- +
- + //AngryCamel - 20120805 2351
- + public void setRuntime(int runtime)
- + {
- + this.runtime = runtime;
- + }
- +
- public int getSeasonNumber()
- {
- return seasonNumber;
- @@ -378,6 +400,12 @@
- {
- return parentPath;
- }
- +
- + //AngryCamel - 20120805 2351
- + public int getRuntime()
- + {
- + return runtime;
- + }
- public String stripExtras(String source)
- {
- Index: utilities/XbmcJsonRpc.java
- ===================================================================
- --- utilities/XbmcJsonRpc.java (revision 8)
- +++ utilities/XbmcJsonRpc.java (working copy)
- @@ -5,6 +5,9 @@
- import java.net.SocketException;
- import java.util.*;
- import java.util.concurrent.*;
- +import java.util.regex.Matcher;
- +import java.util.regex.Pattern;
- +
- import org.json.*;
- public class XbmcJsonRpc implements Runnable, Constants
- @@ -340,12 +343,17 @@
- public static XBMCFile getXBMCFile(String fileOrDir, JSONObject json)
- {
- try {
- + //AngryCamel - 20120806 2206
- + String runtimeStr = json.has("runtime") ? json.getString("runtime") : "";
- + int runtime = parseRuntime(runtimeStr);
- +
- XBMCFile xbmcFile = new XBMCFile(
- fileOrDir,
- json.has("fanart") ? json.getString("fanart") : null,
- - json.has("file") ? json.getString("file") : null,
- + json.has("file") ? json.getString("file") : null,
- json.has("label") ? json.getString("label") : null,
- - json.has("thumbnail") ? json.getString("thumbnail") : null
- + json.has("thumbnail") ? json.getString("thumbnail") : null,
- + runtime //AngryCamel - 20120806 2206
- );
- return xbmcFile;
- }
- @@ -416,8 +424,15 @@
- params.put("directory",dir);
- final String mediaType = "files";//files should return everything after fix here: http://forum.xbmc.org/showthread.php?t=114921
- - params.put("media", mediaType);
- + params.put("media", mediaType);
- + //AngryCamel - 20120805 2351
- + // -Added runtime for the runtime filter.
- + // -You were referencing label (returned when title is specified in properties), thumbnail, and fanart when creating XBMCFile but
- + // they were not coming back in the JSON reponse, so I added those while I was at it.
- + final String[] properties = {"runtime", "title", "thumbnail", "fanart"};//files should return everything after fix here: http://forum.xbmc.org/showthread.php?t=114921
- + params.put("properties", properties);
- +
- /*Sort testing
- *
- boolean sort = true;
- @@ -470,17 +485,22 @@
- if(!files.isEmpty())
- {
- for(JSONObject file : files)
- - {
- - XBMCFile xbmcFile = new XBMCFile(
- + {
- + //AngryCamel - 20120806 2206
- + String runtimeStr = file.has("runtime") ? file.getString("runtime") : "";
- + int runtime = parseRuntime(runtimeStr);
- +
- + XBMCFile xbmcFile = new XBMCFile(
- FILE,
- file.has("fanart") ? file.getString("fanart") : null,
- file.getString("file"), //required
- file.getString("label"), //required
- file.has("thumbnail") ? file.getString("thumbnail") : null,
- + runtime, //AngryCamel - 20120806 2206
- fullPathLabel,
- subf);
- - boolean allowed = subf.isAllowedByFilters(xbmcFile.getFullPathEscaped());
- + boolean allowed = subf.isAllowedByFilters(xbmcFile.getFullPathEscaped(), xbmcFile.getRuntime()); //AngryCamel - 20120805 2351
- if(!allowed) continue;
- boolean excluded = subf.isExcluded(xbmcFile.getFullPathEscaped());
- @@ -521,6 +541,7 @@
- file, //required
- label, //required
- directory.has("thumbnail") ? directory.getString("thumbnail") : null,
- + 0, //AngryCamel - 20120805 2351
- fullPathLabel,
- subf);
- filesAndDirsFound.put(xbmcFile);
- @@ -587,7 +608,111 @@
- }
- }//end if valid json returned
- }
- +
- + //AngryCamel - 20120806 214700
- + // -Added runtime parsing to detect the format and if necessary translate to a number of minutes as an integer
- + public static int parseRuntime(String runtimeStr)
- + {
- + if(runtimeStr.equals(""))
- + return 0;
- +
- + int runTime = 0;
- +
- + //HH:MM:SS Pattern matches any of the following:
- + //39:10, 31:46, 1:39:58, 9:13, 69:58:06
- + String hhmmssPattern = "(\\d*):?(\\d*)?:([0-5][0-9])";
- +
- + // Compile and use regular expression
- + Pattern pattern = Pattern.compile(hhmmssPattern);
- + Matcher matcher = pattern.matcher(runtimeStr);
- + boolean matchFound = matcher.find();
- + if (matchFound) {
- + int hours = 0, mins = 0, secs = 0;
- + /*
- + String groupStr = "";
- + for (int i=0; i<=matcher.groupCount(); i++) {
- + groupStr += " Group("+i+"): "+matcher.group(i);
- + }
- + Config.log(Config.DEBUG, "Match:"+ groupStr);
- + */
- +
- + if(matcher.groupCount()==3)
- + {
- + //For patterns without an hour segment, the minute will go into group 1 and the seconds into group 3. Group 2 will be empty
- + //For patterns with an hour segment (total of 4), the hour will go into group 1, minute into group 2, and the seconds into group 3
- + if(matcher.group(2).length() < 1)
- + {
- + //This is a MM:SS match
- + //Config.log(Config.DEBUG, "Matched on MM:SS pattern: "+ runtimeStr);
- +
- + //Parse the minutes
- + if(matcher.group(1).length()>0)
- + {
- + try{
- + mins = Integer.parseInt(matcher.group(1));
- + }catch (NumberFormatException e){}
- + }
- + //Config.log(Config.DEBUG, " Mins: "+ mins);
- +
- + //Parse the seconds
- + if(matcher.group(3).length()>0)
- + {
- + try{
- + secs = Integer.parseInt(matcher.group(3));
- + }catch (NumberFormatException e){}
- + }
- + //Config.log(Config.DEBUG, " Secs: "+ secs);
- + }
- + else
- + {
- + //This is a HH:MM:SS match
- + //Config.log(Config.DEBUG, "Matched on HH:MM:SS pattern: "+ runtimeStr);
- +
- + //Parse the hours
- + if(matcher.group(1).length()>0)
- + {
- + try{
- + hours = Integer.parseInt(matcher.group(1));
- + }catch (NumberFormatException e){}
- + }
- + //Config.log(Config.DEBUG, " Hours: "+ hours);
- +
- + //Parse the minutes
- + if(matcher.group(2).length()>0)
- + {
- + try{
- + mins = Integer.parseInt(matcher.group(2));
- + }catch (NumberFormatException e){}
- + }
- + //Config.log(Config.DEBUG, " Mins: "+ mins);
- +
- + //Parse the seconds
- + if(matcher.group(3).length()>0)
- + {
- + try{
- + secs = Integer.parseInt(matcher.group(3));
- + }catch (NumberFormatException e){}
- + }
- + //Config.log(Config.DEBUG, " Secs: "+ secs);
- + }
- + }
- + //Now add it all up
- + runTime = (60*60*hours) + (60*mins) + secs;
- + }
- + else
- + {
- + //Format did not match HH:MM:SS format; try to parse as int
- + //Config.log(Config.DEBUG, "Runtime format has no pattern (parsing as int): "+ runtimeStr);
- + try{
- + runTime = Integer.parseInt(runtimeStr);
- + }catch (NumberFormatException e){}
- + }
- +
- + Config.log(Config.DEBUG, "Parsed " + runtimeStr + " to " + runTime + " mins");
- + return runTime;
- + }
- +
- Socket jsonRPCSocket = null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement