Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: db/ArchivedFilesDB.java
- ===================================================================
- --- db/ArchivedFilesDB.java (revision 11)
- +++ db/ArchivedFilesDB.java (working copy)
- @@ -105,9 +105,16 @@
- {
- video.setArtist(rs.getString("artist"));
- }
- + //AngryCamel - 20120817 1620 - Added generic
- + else if(video.isGeneric())
- + {
- + video.setSeries(rs.getString("series"));
- + video.setArtist(rs.getString("artist"));
- + video.setEpisodeNumber(rs.getInt("episode_number"));
- + }
- else
- {
- - Config.log(WARNING, "Video type (TV/Movie/Music Video) cannot be determined using: "+preparedStmtSQL);
- + Config.log(WARNING, "Video type (TV/Movie/Music Video/Generic) cannot be determined using: "+preparedStmtSQL);
- return null;
- }
- String dropboxLocation = rs.getString("dropbox_location");//always a .strm out of the database
- Index: db/Database.java
- ===================================================================
- --- db/Database.java (revision 11)
- +++ db/Database.java (working copy)
- @@ -190,7 +190,7 @@
- stmt.setObject(i, p.param);//nulls may not work here depending on database
- }
- }
- - Config.log(DEBUG, "Set param "+ i +" to "+ p.param);
- + //Config.log(DEBUG, "Set param "+ i +" to "+ p.param);
- i++;
- }
- }
- Index: mylibrary/importer.java
- ===================================================================
- --- mylibrary/importer.java (revision 11)
- +++ mylibrary/importer.java (working copy)
- @@ -731,6 +731,12 @@
- return false;
- }
- }
- + //AngryCamel - 20120817 1620 - Added generic
- + else if(video.isGeneric())
- + {
- + log(WARNING, "Cannot generate .nfo files for generic videos.");
- + return false;
- + }
- return false;
- }
- Index: utilities/Archiver.java
- ===================================================================
- --- utilities/Archiver.java (revision 11)
- +++ utilities/Archiver.java (working copy)
- @@ -4,6 +4,7 @@
- import java.util.*;
- import java.util.concurrent.*;
- import java.util.regex.*;
- +
- import org.apache.commons.io.FileUtils;
- public class Archiver implements Runnable, Constants
- @@ -53,8 +54,8 @@
- public Map<File,String> videosSkippedBecauseAlreadyArchived = new LinkedHashMap<File,String>();
- public Map<File,String> filesArchived = new HashMap<File,String>();
- - public int tvSuccess = 0, tvFail = 0, musicVideoSuccess = 0, musicVideoFail = 0, movieSuccess = 0, movieFail = 0,archiveSuccess = 0, archiveFail = 0, archiveSkip =0, newArchivedCount = 0, updatedCount = 0;
- - public static int globaltvSuccess = 0, globaltvFail = 0, globalmusicVideoSuccess = 0, globalmusicVideoFail = 0, globalmovieSuccess = 0, globalmovieFail = 0, globalarchiveSuccess = 0, globalarchiveFail = 0, globalarchiveSkip =0, globalnewArchivedCount = 0, globalupdatedCount = 0;
- + public int tvSuccess = 0, tvFail = 0, musicVideoSuccess = 0, musicVideoFail = 0, movieSuccess = 0, movieFail = 0, genericSuccess = 0, genericFail = 0,archiveSuccess = 0, archiveFail = 0, archiveSkip =0, newArchivedCount = 0, updatedCount = 0;
- + public static int globaltvSuccess = 0, globaltvFail = 0, globalmusicVideoSuccess = 0, globalmusicVideoFail = 0, globalgenericSuccess = 0, globalgenericFail = 0, globalmovieSuccess = 0, globalmovieFail = 0, globalarchiveSuccess = 0, globalarchiveFail = 0, globalarchiveSkip =0, globalnewArchivedCount = 0, globalupdatedCount = 0;
- Source source;
- Set<File> filesArchivedFromThisSource;
- public Archiver(Source source)
- @@ -129,6 +130,7 @@
- tvSuccess, tvFail,
- movieSuccess, movieFail,
- musicVideoSuccess, musicVideoFail,
- + genericSuccess, genericFail,
- newArchivedCount, updatedCount, archiveSuccess, archiveSkip, archiveFail);
- }
- @@ -142,9 +144,10 @@
- }
- }
- + //AngryCamel - 20120817 1620 - Added generic
- private static void summarize(String subfName, int tvSuccess, int tvFail, int movieSuccess, int movieFail,
- - int musicVideoSuccess, int musicVideoFail, int newArchivedCount, int updatedCount, int archiveSuccess,
- - int archiveSkip, int archiveFail)
- + int musicVideoSuccess, int musicVideoFail, int genericSuccess, int genericFail, int newArchivedCount,
- + int updatedCount, int archiveSuccess, int archiveSkip, int archiveFail)
- {
- //try{subfName = subfName.substring(0, subfName.indexOf("/"));}catch(Exception ignored){}//try to trim to only the source name
- setShortLogDesc("Summary:"+subfName);
- @@ -152,6 +155,10 @@
- log(NOTICE, "TV Success: "+ tvSuccess+", TV Fail: "+ tvFail);
- log(NOTICE, "Movie Success: "+ movieSuccess+", Movie Fail: "+ movieFail);
- log(NOTICE, "Music Video Success: "+ musicVideoSuccess+", Music Video Fail: "+ musicVideoFail);
- +
- + //AngryCamel - 20120817 1620 - Added generic
- + log(NOTICE, "Generic Success: "+ genericSuccess+", Generic Fail: "+ genericFail);
- +
- log(NOTICE, "New videos archived: "+ newArchivedCount +", existing videos updated: "+ updatedCount);
- log(NOTICE, "Overall: Success: "+ archiveSuccess+", Skip: "+ archiveSkip +", Fail: "+ archiveFail);
- setShortLogDesc("");
- @@ -168,6 +175,11 @@
- globalmovieSuccess += movieSuccess;
- globalmusicVideoFail += musicVideoFail;
- globalmusicVideoSuccess += musicVideoSuccess;
- +
- + //AngryCamel - 20120817 1620 - Added generic
- + globalgenericFail += musicVideoFail;
- + globalgenericSuccess += genericSuccess;
- +
- globaltvFail += tvFail;
- globaltvSuccess += tvSuccess;
- }
- @@ -176,7 +188,8 @@
- final static String GLOBAL_SUMMARY_NAME = "---Overall---";
- public static void globalSummary()
- {
- - summarize(GLOBAL_SUMMARY_NAME, globaltvSuccess, globaltvFail, globalmovieSuccess, globalmovieFail, globalmusicVideoSuccess, globalmusicVideoFail, globalnewArchivedCount, globalupdatedCount, globalarchiveSuccess, globalarchiveSkip, globalarchiveFail);
- + summarize(GLOBAL_SUMMARY_NAME, globaltvSuccess, globaltvFail, globalmovieSuccess, globalmovieFail, globalmusicVideoSuccess, globalmusicVideoFail,
- + globalgenericSuccess, globalgenericFail, globalnewArchivedCount, globalupdatedCount, globalarchiveSuccess, globalarchiveSkip, globalarchiveFail);
- }
- public void archiveVideo(XBMCFile video)
- @@ -309,6 +322,9 @@
- else if(video.isMovie()) if(success) movieSuccess++; else movieFail++;
- else if(video.isMusicVideo()) if(success) musicVideoSuccess++; else musicVideoFail++;
- + //AngryCamel - 20120817 1620 - Added generic
- + else if(video.isGeneric()) if(success) genericSuccess++; else genericFail++;
- +
- if(success && !video.isDuplicate())
- {
- subf.addVideo(video);//increase total video count for this subf (also increases series count if video is tv show);
- @@ -460,6 +476,14 @@
- log(DEBUG, "Attempting to parse movie title using default settings. Setting movie title to \""+video.getFileLabel()+"\"");
- video.setTitle(video.getFileLabel());
- }
- + //AngryCamel - 20120817 1620 - Added generic
- + else if(video.isGeneric())
- + {
- + log(DEBUG, "Attempting to parse generic video using default settings. Setting video title to \""+video.getFileLabel()+"\"");
- + video.setTitle(video.getFileLabel());
- + //AngryCamel - 20120817 1620 - Added generic
- + applyCustomParser(video);
- + }
- else//not yet supported
- {
- setShortLogDesc("Archive:Skip");
- @@ -550,10 +574,10 @@
- public static String getDroboxDestNoExt(XBMCFile file)
- {
- - return getDroboxDestNoExt(Config.DROPBOX, file);//default dropbox
- + return getDropboxDestNoExt(Config.DROPBOX, file);//default dropbox
- }
- - public static String getDroboxDestNoExt(String dropbox, XBMCFile file)
- + public static String getDropboxDestNoExt(String dropbox, XBMCFile file)
- {
- //determine new location, make sure directory structure is there
- @@ -621,6 +645,30 @@
- }
- return musicVideoDir+SEP+ tools.safeFileName(file.getArtist() + " - "+ file.getTitle());
- }
- + //AngryCamel - 20120817 1620 - Added generic
- + else if(file.isGeneric())
- + {
- + //create the directory structure, if needed
- + File genericDir = new File(dropbox+SEP+"Generic");
- + if(!genericDir.isDirectory())
- + {
- + log(INFO, "Creating base Generic directory at: " + genericDir);
- + genericDir.mkdir();
- + }
- +
- + File seriesDir = new File(genericDir+SEP+tools.spacesToDots(tools.safeFileName(file.getSeries())));//safe name replaces spaces with periods
- + if(!seriesDir.isDirectory())
- + {
- + log(DEBUG, "Creating series directory at " + seriesDir);
- + seriesDir.mkdir();
- + }
- +
- + //final file location
- + String baseDestination = seriesDir +SEP+ tools.safeFileName(file.getSeries());
- + if(valid(file.getTitle())) baseDestination += " - "+ tools.safeFileName(file.getTitle());
- +
- + return baseDestination;
- + }
- else
- {
- log(ERROR, "Unknown video type: \""+ file.getType()+"\"");
- @@ -729,9 +777,10 @@
- return false;//assume its not alrady archived
- }
- }
- - else if(file.isMovie() || file.isMusicVideo())
- + //AngryCamel - 20120817 1620 - Added generic
- + else if(file.isMovie() || file.isMusicVideo() || file.isGeneric())
- {
- - return false;//dont have a good identifier (like SxxExx) for movies/music vids, so alwasy allow these to be archived/updated
- + return false;//dont have a good identifier (like SxxExx) for movies/music/generic vids, so alwasy allow these to be archived/updated
- }
- else
- {
- @@ -796,14 +845,21 @@
- }
- else//try secondary method, lookingup on TheTVDB.com
- {
- - //check if the series and title are both in the file label
- - if(getSeriesAndTitleFromFileLabel(video))
- + //AngryCamel - 20120817 1620 - Added generic
- + if(applyCustomParser(video))
- + {
- + log(DEBUG, "Found series \""+video.getSeries() +"\", and title \""+video.getTitle()+"\", from file label \""+video.getFileLabel()+"\" using a custom parser. "
- + + "Will use this info to look up on the TVDB.com");
- + return TVDB.lookupTVShow(video);
- + }
- +
- + if(getSeriesAndTitleFromFileLabel(video)) //check if the series and title are both in the file label
- {
- log(DEBUG, "Found series \""+video.getSeries() +"\", and title \""+video.getTitle()+"\", from file label \""+video.getFileLabel()+"\". "
- + "Will use this info to look up on the TVDB.com");
- return TVDB.lookupTVShow(video);
- }
- - else//assume that the file label is the episode title
- + else //assume that the file label is the episode title
- {
- video.setTitle(video.getFileLabel());
- log(DEBUG, "Assuming that the file label is the episode title: \""+video.getTitle()+"\", finding Series by looking at parent folder(s)");
- @@ -821,6 +877,52 @@
- }
- }
- + //AngryCamel - 20120815 2246
- + // If a custom parser is not present, then continue on to default parsing.
- + // If it was present but doesn't find a match (it will return out if it does),
- + // then continue on to default parsing.
- + // Expected XML format of the config section for this is:
- + // <!--Parse the series name then the title of the episode -->
- + // <parser>
- + // <regexp>([\w\s*'-]*):([\w\s*'-]*)</regexp> <!-- ex: "Show Name: Title of the Episode" -->
- + // </parser>
- + public boolean applyCustomParser(XBMCFile video)
- + {
- +
- + if(video.getSubfolder().shouldApplyParser())
- + {
- + log(DEBUG, "Found custom series and title parser.");
- + //Info: Structure of parsers = {"regexp":["pattern1","pattern2"]}
- + for(Map.Entry<String,List<String>> entry : video.getSubfolder().parsers.entrySet())
- + {
- + String type = entry.getKey();
- + if(type==null) continue;//skip
- + List<String> parserStrings = entry.getValue();
- + for(String parserString : parserStrings)
- + {
- + if(type.equalsIgnoreCase(Constants.REGEXP))
- + {
- + log(DEBUG, "Custom series and title parser regex: "+parserString);
- + Pattern p = Pattern.compile(parserString, Pattern.CASE_INSENSITIVE);
- + Matcher m = p.matcher(video.getFileLabel());
- + if(m.find())
- + {
- + if (m.groupCount() == 2)
- + {
- + //First group is assumed to be the series
- + video.setSeries(m.group(1).trim());
- + //Second group is assumed to be the title
- + video.setTitle(m.group(2).trim());
- + return true;
- + }
- + }
- + }
- + }
- + }
- + }
- + return false;
- + }
- +
- public static boolean addTVMetaDataFromSxxExx(XBMCFile video, String seasonEpisodeNaming)
- {
- //parse season/episode numbers
- Index: utilities/Config.java
- ===================================================================
- --- utilities/Config.java (revision 11)
- +++ utilities/Config.java (working copy)
- @@ -147,10 +147,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
- @@ -631,7 +631,6 @@
- log(DEBUG, "Comskip edl type set to: "+ EDL_TYPE);
- }
- */
- -
- //get SearchFilters
- Element searchFilters = root.getChild("SearchFilters");
- @@ -729,6 +728,13 @@
- String suffix = (inherit("suffix", sourceElement, subfolder));
- int level_deep = Integer.parseInt(subfolder.getAttributeValue("level_deep"));
- //String compression = (inherit("compression", sourceElement, subfolder));
- +
- + //AngryCamel - 20120817 1620
- + //force_series will override any parsed series name with the value specified
- + //The reason this was developed was for TED talks. I did not spend much time
- + // thinking about it's possible usage outside of that particular use
- + // case, but I'm sure someone will find another reason to use it.
- + String force_series = (inherit("force_series", sourceElement, subfolder));
- Subfolder subf = new Subfolder(src, subfolderName);
- subf.setRecursive(recursive);
- @@ -745,13 +751,16 @@
- subf.setLevelDeep(level_deep);
- //subf.setCompression(compression);
- + //AngryCamel - 20120817 1620
- + subf.setForceSeries(force_series);
- +
- String indent = "";
- for(int i=subf.getLevelDeep(); i>=0; i--)indent+="\t";
- Config.log(INFO, indent+"Next Subfolder: name="+subf.getFullName()+", recursive="+subf.isRecursive()
- +", type="+subf.getType()+", max_series="+subf.getMaxSeries()+", "
- + "max_videos="+subf.getMaxVideos()+", movie_set="+subf.getMovieSet()+", prefix="+subf.getPrefix()+", suffix="+subf.getSuffix()+
- - /*", download="+download+", compression="+(valid(compression) ? compression:"")+*/", multi_part="+containsMultiPartVideos);
- + /*", download="+download+", compression="+(valid(compression) ? compression:"")+*/", multi_part="+containsMultiPartVideos +", force_series="+subf.getForceSeries());
- //check for excludes/filters at the subfolder level
- //inherit any excludes/filters from parent subfolders
- @@ -785,6 +794,26 @@
- }
- }
- }
- +
- + //AngryCamel - 20120815 2246
- + //Parsers override the default series and title parser in Archiver.addTVMetaData()
- + //If multiple parsers are supplied, the order that they are read
- + // from the XML is the priority order they will be processed in
- + // until one finds a match.
- + for(Element nextSubf : subfolderAndParents)
- + {
- + Element parserElem = nextSubf.getChild("parser");
- + if(parserElem != null)
- + {
- + List<Element> parsers = parserElem.getChildren();
- + for(Element parser : parsers)
- + {
- + subf.addParser(parser.getName(), parser.getText());
- + log(DEBUG, indent+"\tAdded subfolder Parser: type="+parser.getName()+", value="+parser.getText());
- + }
- + }
- + }
- +
- src.addSubfolder(subf);
- }//end subfolders
- }//end top subfolders
- Index: utilities/Constants.java
- ===================================================================
- --- utilities/Constants.java (revision 11)
- +++ utilities/Constants.java (working copy)
- @@ -36,7 +36,13 @@
- //AngryCamel - 20120805 2351
- public final static String RUNTIME = "runtime";
- +
- + //AngryCamel - 20120815 2246
- + public final static String FORCE_SERIES = "force_series";
- + //AngryCamel - 20120817 1620
- + public final static String GENERIC = "generic";
- +
- public final static String FOLDERS_ONLY = "FOLDERS_ONLY";
- public final static String FILES_ONLY = "FILES_ONLY";
- public final static String FOLDERS_AND_FILES = "FOLDERS_AND_FILES";
- Index: utilities/Filter.java
- ===================================================================
- --- utilities/Filter.java (revision 11)
- +++ utilities/Filter.java (working copy)
- @@ -50,7 +50,7 @@
- int runtimeFilter = 0;
- String operator = "";
- - splitFilterStr = filterString.toLowerCase().split("|");
- + splitFilterStr = filterString.toLowerCase().split("\\|");
- if(splitFilterStr.length < 2)
- return false;//filter string format invalid
- @@ -62,7 +62,7 @@
- return false;//filter string format invalid
- }
- - if(operator.equals("EQ"))
- + if(operator.equals("eq"))
- {
- //Handle Equal To check here
- if(runtime == runtimeFilter)
- @@ -74,7 +74,7 @@
- return false;
- }
- }
- - else if(operator.equals("GT"))
- + else if(operator.equals("gt"))
- {
- //Handle Greater Than check here
- if(runtime > runtimeFilter)
- @@ -86,7 +86,7 @@
- return false;
- }
- }
- - else if(operator.equals("LT"))
- + else if(operator.equals("lt"))
- {
- //Handle Less Than check here
- if(runtime < runtimeFilter)
- @@ -98,7 +98,7 @@
- return false;
- }
- }
- - else if(operator.equals("NE"))
- + else if(operator.equals("ne"))
- {
- //Handle Not Equal To check here
- if(runtime != runtimeFilter)
- @@ -110,7 +110,7 @@
- return false;
- }
- }
- - else if(operator.equals("GE"))
- + else if(operator.equals("ge"))
- {
- //Handle Greater than or equal to check here
- if(runtime >= runtimeFilter)
- @@ -122,7 +122,7 @@
- return false;
- }
- }
- - else if(operator.equals("LE"))
- + else if(operator.equals("le"))
- {
- //Handle Less than or equal to check here
- if(runtime <= runtimeFilter)
- Index: utilities/Subfolder.java
- ===================================================================
- --- utilities/Subfolder.java (revision 11)
- +++ utilities/Subfolder.java (working copy)
- @@ -13,6 +13,11 @@
- int numberofVideos = 0;
- public Map<String,List<String>> excludes = new LinkedHashMap<String,List<String>>();
- public Map<String,List<String>> filters = new LinkedHashMap<String,List<String>>();
- +
- + //AngryCamel - 20120815 2246
- + public Map<String,List<String>> parsers = new LinkedHashMap<String,List<String>>();
- + String force_series = null;
- +
- Source source;
- String regexMatchingName = null;//if the name is a regex, this will be set to what the regex matches
- boolean canContainMultiPartVideos = false;
- @@ -28,6 +33,16 @@
- this.source = source;
- }
- + //AngryCamel - 20120815 2246
- + public void setForceSeries(String series)
- + {
- + this.force_series = series;
- + }
- + public String getForceSeries()
- + {
- + return force_series;
- + }
- +
- public void setLevelDeep(int level)
- {
- this.level_deep = level;
- @@ -137,6 +152,11 @@
- {
- return !filters.isEmpty();
- }
- + //AngryCamel - 20120815 2246
- + public boolean shouldApplyParser()
- + {
- + return !parsers.isEmpty();
- + }
- public void addExclude(String type, String value)
- {
- List<String> values = excludes.get(type);
- @@ -151,6 +171,14 @@
- values.add(value);
- filters.put(type, values);
- }
- + //AngryCamel - 20120815 2246
- + public void addParser(String type, String value)
- + {
- + List<String> values = parsers.get(type);
- + if(values == null) values = new ArrayList<String>();
- + values.add(value);
- + parsers.put(type, values);
- + }
- public void setMovieSet(String movieSet)
- {
- this.movie_set = movieSet;
- @@ -336,13 +364,12 @@
- return false;//no match
- }
- - /*
- + /*
- * Checks the path against the filters.
- * Returns true if it is allowed by ALL filters or filter matching is not used
- * Returns false if this path should be skipped
- */
- //AngryCamel - 20120805 2351
- - // public boolean isAllowedByFilters(String path)
- public boolean isAllowedByFilters(String path, int runtime)
- {
- path = Config.escapePath(path);
- Index: utilities/tools.java
- ===================================================================
- --- utilities/tools.java (revision 11)
- +++ utilities/tools.java (working copy)
- @@ -494,6 +494,12 @@
- table = "musicvideo";
- idField = "idMVideo";
- }
- + //AngryCamel - 20120817 1620 - Added generic
- + else if(videoType.equals(GENERIC))
- + {
- + Config.log(WARNING,"Generic video type does not update meta data");
- + return false;
- + }
- else
- {
- Config.log(WARNING,"Unknown video type: \""+ videoType+"\", will not update meta data");
- @@ -612,6 +618,10 @@
- changed = video.getYear() != currentlyArchivedFile.year;
- else if(video.isMusicVideo())
- changed = !video.getArtist().equals(currentlyArchivedFile.artist);
- + //AngryCamel - 20120817 1620 - Added generic
- + else if(video.isGeneric())
- + changed = !video.getSeries().equals(currentlyArchivedFile.series)
- + || !video.getTitle().equals(currentlyArchivedFile.title);
- }
- }
- if(!changed)
- Index: utilities/XBMCFile.java
- ===================================================================
- --- utilities/XBMCFile.java (revision 11)
- +++ utilities/XBMCFile.java (working copy)
- @@ -62,8 +62,7 @@
- dest.setYear(source.getYear());
- }
- - //AngryCamel - 20120805 2351
- - //public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail, String parentPath, Subfolder matchingSubfolder)
- + //AngryCamel - 20120805 2351 - Added runtime
- public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail, int runtime, String parentPath, Subfolder matchingSubfolder)
- {
- this.fileOrDir = fileOrDir;
- @@ -79,8 +78,7 @@
- this.subfolder = matchingSubfolder;
- }
- - //AngryCamel - 20120805 2351
- - //public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail)
- + //AngryCamel - 20120805 2351 - Added runtime
- public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail, int runtime)
- {
- this.fileOrDir = fileOrDir;
- @@ -215,6 +213,10 @@
- if(isMovie() && tools.valid(getTitle())) return true;
- if(isTvShow() && tools.valid(getSeries()) && getSeasonNumber() > -1 && getEpisodeNumber() > -1) return true;//title not required
- if(isMusicVideo() && tools.valid(getTitle()) && tools.valid(getArtist())) return true;
- +
- + //AngryCamel - 20120817 1620 - Added generic
- + if(isGeneric() && tools.valid(getSeries()) && tools.valid(getTitle())) return true;
- +
- return false;
- }
- public void setArtist(String artist)
- @@ -258,7 +260,20 @@
- }
- public void setSeries(String series)
- {
- - this.series = stripExtras(series);
- + //AngryCamel - 20120817 1620
- + // Check if there is a forced series in the subfolder config and apply it instead of whatever was passed.
- + try {
- + if(tools.valid(this.getSubfolder().getForceSeries()))
- + {
- + this.series = stripExtras(this.getSubfolder().getForceSeries());
- + }
- + else
- + {
- + this.series = stripExtras(series);
- + }
- + } catch (Exception e) {
- + this.series = stripExtras(series);
- + }
- }
- public String getSeries()
- @@ -306,7 +321,8 @@
- }
- public boolean knownType()
- {
- - return isMovie() || isTvShow() || isMusicVideo();
- + //AngryCamel - 20120817 1620 - added isGeneric
- + return isMovie() || isTvShow() || isMusicVideo() || isGeneric();
- }
- public boolean isTvShow()
- {
- @@ -320,6 +336,13 @@
- {
- return MUSIC_VIDEO.equals(type);
- }
- +
- + //AngryCamel - 20120817 1620 - added isGeneric
- + public boolean isGeneric()
- + {
- + return GENERIC.equals(type);
- + }
- +
- public String getFanart()
- {
- return fanart;
- Index: utilities/XbmcJsonRpc.java
- ===================================================================
- --- utilities/XbmcJsonRpc.java (revision 11)
- +++ 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,13 +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("label") ? json.getString("label") : null,
- json.has("thumbnail") ? json.getString("thumbnail") : null,
- - json.has("runtime") ? json.getInt("runtime") : null //AngryCamel - 20120805 2351
- + runtime //AngryCamel - 20120806 2206
- );
- return xbmcFile;
- }
- @@ -423,7 +430,7 @@
- // -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
- + 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
- @@ -478,14 +485,18 @@
- 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,
- - file.has("runtime") ? file.getInt("runtime") : null, //AngryCamel - 20120805 2351
- + runtime, //AngryCamel - 20120806 2206
- fullPathLabel,
- subf);
- @@ -597,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