Advertisement
Guest User

XBMC.MyLibrary Patch - AngryCamel - 20120818

a guest
Aug 18th, 2012
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 39.24 KB | None | 0 0
  1. Index: db/ArchivedFilesDB.java
  2. ===================================================================
  3. --- db/ArchivedFilesDB.java (revision 11)
  4. +++ db/ArchivedFilesDB.java (working copy)
  5. @@ -105,9 +105,16 @@
  6.                  {
  7.                      video.setArtist(rs.getString("artist"));
  8.                  }
  9. +               //AngryCamel - 20120817 1620 - Added generic
  10. +                else if(video.isGeneric())
  11. +                {
  12. +                    video.setSeries(rs.getString("series"));
  13. +                    video.setArtist(rs.getString("artist"));
  14. +                    video.setEpisodeNumber(rs.getInt("episode_number"));
  15. +                }
  16.                  else
  17.                  {
  18. -                    Config.log(WARNING, "Video type (TV/Movie/Music Video) cannot be determined using: "+preparedStmtSQL);
  19. +                    Config.log(WARNING, "Video type (TV/Movie/Music Video/Generic) cannot be determined using: "+preparedStmtSQL);
  20.                      return null;
  21.                  }
  22.                  String dropboxLocation = rs.getString("dropbox_location");//always a .strm out of the database                                
  23. Index: db/Database.java
  24. ===================================================================
  25. --- db/Database.java    (revision 11)
  26. +++ db/Database.java    (working copy)
  27. @@ -190,7 +190,7 @@
  28.                          stmt.setObject(i, p.param);//nulls may not work here depending on database
  29.                      }
  30.                  }
  31. -                Config.log(DEBUG, "Set param "+ i +" to "+ p.param);
  32. +                //Config.log(DEBUG, "Set param "+ i +" to "+ p.param);
  33.                  i++;
  34.              }
  35.          }
  36. Index: mylibrary/importer.java
  37. ===================================================================
  38. --- mylibrary/importer.java (revision 11)
  39. +++ mylibrary/importer.java (working copy)
  40. @@ -278,7 +278,7 @@
  41.                  }
  42.                  finally
  43.                  {
  44. -                    archiver.canStop();//let it know that the queue is not being fed any more so the archive can finishe once it runs out of files to check
  45. +                    archiver.canStop();//let it know that the queue is not being fed any more so the archive can finish once it runs out of files to check
  46.                  }
  47.                  log(NOTICE, "Done retrieving files from JSON-RPC for subfolder: "+subf.getFullName());
  48.  
  49. @@ -731,6 +731,12 @@
  50.                  return false;
  51.              }
  52.          }
  53. +       //AngryCamel - 20120817 1620 - Added generic
  54. +        else if(video.isGeneric())
  55. +        {
  56. +            log(WARNING, "Cannot generate .nfo files for generic videos.");
  57. +            return false;
  58. +        }
  59.          return false;
  60.      }
  61.      
  62. Index: utilities/Archiver.java
  63. ===================================================================
  64. --- utilities/Archiver.java (revision 11)
  65. +++ utilities/Archiver.java (working copy)
  66. @@ -4,6 +4,7 @@
  67.  import java.util.*;
  68.  import java.util.concurrent.*;
  69.  import java.util.regex.*;
  70. +
  71.  import org.apache.commons.io.FileUtils;
  72.  
  73.  public class Archiver implements Runnable, Constants
  74. @@ -53,8 +54,8 @@
  75.      public Map<File,String> videosSkippedBecauseAlreadyArchived = new LinkedHashMap<File,String>();
  76.      public Map<File,String> filesArchived = new HashMap<File,String>();
  77.  
  78. -    public int tvSuccess = 0, tvFail = 0, musicVideoSuccess = 0, musicVideoFail = 0, movieSuccess = 0, movieFail = 0,archiveSuccess = 0, archiveFail = 0, archiveSkip =0, newArchivedCount = 0, updatedCount = 0;    
  79. -    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;
  80. +    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;    
  81. +    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;
  82.      Source source;
  83.      Set<File> filesArchivedFromThisSource;
  84.      public Archiver(Source source)
  85. @@ -129,6 +130,7 @@
  86.                      tvSuccess, tvFail,
  87.                      movieSuccess, movieFail,
  88.                      musicVideoSuccess, musicVideoFail,
  89. +                    genericSuccess, genericFail,
  90.                      newArchivedCount, updatedCount, archiveSuccess, archiveSkip, archiveFail);
  91.  
  92.          }
  93. @@ -142,9 +144,10 @@
  94.          }
  95.      }
  96.  
  97. +   //AngryCamel - 20120817 1620 - Added generic
  98.      private static void summarize(String subfName, int tvSuccess, int tvFail, int movieSuccess, int movieFail,
  99. -            int musicVideoSuccess, int musicVideoFail, int newArchivedCount, int updatedCount, int archiveSuccess,
  100. -            int archiveSkip, int archiveFail)
  101. +            int musicVideoSuccess, int musicVideoFail, int genericSuccess, int genericFail, int newArchivedCount,
  102. +            int updatedCount, int archiveSuccess, int archiveSkip, int archiveFail)
  103.      {
  104.          //try{subfName = subfName.substring(0, subfName.indexOf("/"));}catch(Exception ignored){}//try to trim to only the source name
  105.          setShortLogDesc("Summary:"+subfName);
  106. @@ -152,6 +155,10 @@
  107.          log(NOTICE, "TV Success: "+ tvSuccess+", TV Fail: "+ tvFail);
  108.          log(NOTICE, "Movie Success: "+ movieSuccess+", Movie Fail: "+ movieFail);
  109.          log(NOTICE, "Music Video Success: "+ musicVideoSuccess+", Music Video Fail: "+ musicVideoFail);
  110. +        
  111. +       //AngryCamel - 20120817 1620 - Added generic
  112. +        log(NOTICE, "Generic Success: "+ genericSuccess+", Generic Fail: "+ genericFail);
  113. +        
  114.          log(NOTICE, "New videos archived: "+ newArchivedCount +", existing videos updated: "+ updatedCount);
  115.          log(NOTICE, "Overall: Success: "+ archiveSuccess+", Skip: "+ archiveSkip +", Fail: "+ archiveFail);
  116.          setShortLogDesc("");
  117. @@ -168,6 +175,11 @@
  118.              globalmovieSuccess += movieSuccess;
  119.              globalmusicVideoFail += musicVideoFail;
  120.              globalmusicVideoSuccess += musicVideoSuccess;
  121. +
  122. +           //AngryCamel - 20120817 1620 - Added generic
  123. +            globalgenericFail += musicVideoFail;
  124. +            globalgenericSuccess += genericSuccess;
  125. +            
  126.              globaltvFail += tvFail;
  127.              globaltvSuccess += tvSuccess;
  128.          }
  129. @@ -176,7 +188,8 @@
  130.      final static String GLOBAL_SUMMARY_NAME = "---Overall---";
  131.      public static void globalSummary()
  132.      {
  133. -        summarize(GLOBAL_SUMMARY_NAME, globaltvSuccess, globaltvFail, globalmovieSuccess, globalmovieFail, globalmusicVideoSuccess, globalmusicVideoFail, globalnewArchivedCount, globalupdatedCount, globalarchiveSuccess, globalarchiveSkip, globalarchiveFail);
  134. +        summarize(GLOBAL_SUMMARY_NAME, globaltvSuccess, globaltvFail, globalmovieSuccess, globalmovieFail, globalmusicVideoSuccess, globalmusicVideoFail,
  135. +               globalgenericSuccess, globalgenericFail, globalnewArchivedCount, globalupdatedCount, globalarchiveSuccess, globalarchiveSkip, globalarchiveFail);
  136.      }
  137.  
  138.      public void archiveVideo(XBMCFile video)
  139. @@ -309,6 +322,9 @@
  140.          else if(video.isMovie()) if(success) movieSuccess++; else movieFail++;
  141.          else if(video.isMusicVideo()) if(success) musicVideoSuccess++; else musicVideoFail++;
  142.  
  143. +       //AngryCamel - 20120817 1620 - Added generic
  144. +        else if(video.isGeneric()) if(success) genericSuccess++; else genericFail++;
  145. +
  146.          if(success && !video.isDuplicate())
  147.          {
  148.              subf.addVideo(video);//increase total video count for this subf (also increases series count if video is tv show);
  149. @@ -460,6 +476,14 @@
  150.              log(DEBUG, "Attempting to parse movie title using default settings. Setting movie title to \""+video.getFileLabel()+"\"");
  151.              video.setTitle(video.getFileLabel());
  152.          }
  153. +       //AngryCamel - 20120817 1620 - Added generic
  154. +        else if(video.isGeneric())
  155. +        {
  156. +            log(DEBUG, "Attempting to parse generic video using default settings. Setting video title to \""+video.getFileLabel()+"\"");
  157. +            video.setTitle(video.getFileLabel());
  158. +           //AngryCamel - 20120817 1620 - Added generic
  159. +           applyCustomParser(video);
  160. +        }
  161.          else//not yet supported
  162.          {
  163.              setShortLogDesc("Archive:Skip");
  164. @@ -550,10 +574,10 @@
  165.  
  166.      public static String getDroboxDestNoExt(XBMCFile file)
  167.      {
  168. -        return getDroboxDestNoExt(Config.DROPBOX, file);//default dropbox
  169. +        return getDropboxDestNoExt(Config.DROPBOX, file);//default dropbox
  170.      }
  171.      
  172. -    public static String getDroboxDestNoExt(String dropbox, XBMCFile file)
  173. +    public static String getDropboxDestNoExt(String dropbox, XBMCFile file)
  174.      {
  175.          //determine new location, make sure directory structure is there
  176.  
  177. @@ -621,6 +645,30 @@
  178.              }
  179.              return musicVideoDir+SEP+ tools.safeFileName(file.getArtist() + " - "+ file.getTitle());
  180.          }
  181. +       //AngryCamel - 20120817 1620 - Added generic
  182. +        else if(file.isGeneric())
  183. +        {
  184. +            //create the directory structure, if needed
  185. +            File genericDir = new File(dropbox+SEP+"Generic");
  186. +            if(!genericDir.isDirectory())
  187. +            {
  188. +                log(INFO, "Creating base Generic directory at: " + genericDir);
  189. +                genericDir.mkdir();
  190. +            }
  191. +
  192. +            File seriesDir = new File(genericDir+SEP+tools.spacesToDots(tools.safeFileName(file.getSeries())));//safe name replaces spaces with periods
  193. +            if(!seriesDir.isDirectory())
  194. +            {
  195. +                log(DEBUG, "Creating series directory at " + seriesDir);
  196. +                seriesDir.mkdir();
  197. +            }
  198. +
  199. +            //final file location
  200. +            String baseDestination = seriesDir +SEP+ tools.safeFileName(file.getSeries());
  201. +            if(valid(file.getTitle())) baseDestination += " - "+ tools.safeFileName(file.getTitle());
  202. +
  203. +            return baseDestination;
  204. +        }
  205.          else
  206.          {
  207.               log(ERROR, "Unknown video type: \""+ file.getType()+"\"");
  208. @@ -729,9 +777,10 @@
  209.                  return false;//assume its not alrady archived
  210.              }
  211.          }
  212. -        else if(file.isMovie() || file.isMusicVideo())
  213. +       //AngryCamel - 20120817 1620 - Added generic
  214. +        else if(file.isMovie() || file.isMusicVideo() || file.isGeneric())
  215.          {
  216. -            return false;//dont have a good identifier (like SxxExx) for movies/music vids, so alwasy allow these to be archived/updated
  217. +            return false;//dont have a good identifier (like SxxExx) for movies/music/generic vids, so alwasy allow these to be archived/updated
  218.          }
  219.          else
  220.          {
  221. @@ -796,14 +845,21 @@
  222.          }
  223.          else//try secondary method, lookingup on TheTVDB.com
  224.          {
  225. -            //check if the series and title are both in the file label
  226. -            if(getSeriesAndTitleFromFileLabel(video))
  227. +           //AngryCamel - 20120817 1620 - Added generic
  228. +           if(applyCustomParser(video))
  229. +           {
  230. +               log(DEBUG, "Found series \""+video.getSeries() +"\", and title \""+video.getTitle()+"\", from file label \""+video.getFileLabel()+"\" using a custom parser. "
  231. +                               + "Will use this info to look up on the TVDB.com");
  232. +               return TVDB.lookupTVShow(video);
  233. +           }
  234. +          
  235. +           if(getSeriesAndTitleFromFileLabel(video)) //check if the series and title are both in the file label
  236.              {
  237.                  log(DEBUG, "Found series \""+video.getSeries() +"\", and title \""+video.getTitle()+"\", from file label \""+video.getFileLabel()+"\". "
  238.                          + "Will use this info to look up on the TVDB.com");
  239.                  return TVDB.lookupTVShow(video);
  240.              }
  241. -            else//assume that the file label is the episode title
  242. +            else //assume that the file label is the episode title
  243.              {
  244.                  video.setTitle(video.getFileLabel());
  245.                  log(DEBUG, "Assuming that the file label is the episode title: \""+video.getTitle()+"\", finding Series by looking at parent folder(s)");
  246. @@ -821,6 +877,52 @@
  247.          }
  248.      }
  249.  
  250. +   //AngryCamel - 20120815 2246
  251. +   //   If a custom parser is not present, then continue on to default parsing.
  252. +   //   If it was present but doesn't find a match (it will return out if it does),
  253. +   //     then continue on to default parsing.
  254. +   //   Expected XML format of the config section for this is:
  255. +   //     <!--Parse the series name then the title of the episode -->
  256. +   //     <parser>
  257. +   //         <regexp>([\w\s*'-]*):([\w\s*'-]*)</regexp> <!-- ex: "Show Name: Title of the Episode" -->
  258. +   //     </parser>
  259. +    public boolean applyCustomParser(XBMCFile video)
  260. +    {
  261. +
  262. +       if(video.getSubfolder().shouldApplyParser())
  263. +       {
  264. +             log(DEBUG, "Found custom series and title parser.");
  265. +           //Info: Structure of parsers = {"regexp":["pattern1","pattern2"]}
  266. +             for(Map.Entry<String,List<String>> entry : video.getSubfolder().parsers.entrySet())
  267. +             {
  268. +                 String type = entry.getKey();
  269. +                 if(type==null) continue;//skip
  270. +                 List<String> parserStrings = entry.getValue();
  271. +                 for(String parserString : parserStrings)
  272. +                 {
  273. +                     if(type.equalsIgnoreCase(Constants.REGEXP))
  274. +                     {
  275. +                         log(DEBUG, "Custom series and title parser regex: "+parserString);
  276. +                         Pattern p = Pattern.compile(parserString, Pattern.CASE_INSENSITIVE);
  277. +                         Matcher m = p.matcher(video.getFileLabel());
  278. +                         if(m.find())
  279. +                         {
  280. +                           if (m.groupCount() == 2)
  281. +                           {
  282. +                               //First group is assumed to be the series
  283. +                                 video.setSeries(m.group(1).trim());
  284. +                               //Second group is assumed to be the title
  285. +                                 video.setTitle(m.group(2).trim());
  286. +                                 return true;
  287. +                           }
  288. +                         }
  289. +                     }
  290. +                 }
  291. +           }
  292. +       }
  293. +       return false;
  294. +    }
  295. +
  296.      public static boolean addTVMetaDataFromSxxExx(XBMCFile video, String seasonEpisodeNaming)
  297.      {
  298.          //parse season/episode numbers        
  299. Index: utilities/Config.java
  300. ===================================================================
  301. --- utilities/Config.java   (revision 11)
  302. +++ utilities/Config.java   (working copy)
  303. @@ -147,10 +147,10 @@
  304.                  
  305.  
  306.           //populate charactes that we do not allow in file names
  307. -        char[] specialChars = {'<', '>', ':', '"', '/', '\\', '|', '?', '*', '*', '~', '’'};
  308. +        char[] specialChars = {'<', '>', ':', '"', '/', '\\', '|', '?', '*', '*', '~', 'â„¢'};
  309.          for(char c : specialChars) ILLEGAL_FILENAME_CHARS.put(new Integer((int) c), "illegal");
  310.  
  311. -        char[] uncommonChars = {'<', '>', ':', '"', '/', '\\', '|', '?', '*', '#', '$', '%', '^', '*', '!', '~','\'', '’', '=', '[' ,']', '(', ')', ';', '\\' ,',', '_'};
  312. +        char[] uncommonChars = {'<', '>', ':', '"', '/', '\\', '|', '?', '*', '#', '$', '%', '^', '*', '!', '~','\'', 'â„¢', '=', '[' ,']', '(', ')', ';', '\\' ,',', '_'};
  313.          for(char c : uncommonChars) UNCOMMON_CHARS.put(new Integer((int) c), "illegal");
  314.  
  315.          //set up logs
  316. @@ -631,7 +631,6 @@
  317.                  log(DEBUG, "Comskip edl type set to: "+ EDL_TYPE);
  318.              }            
  319.              */
  320. -
  321.              
  322.              //get SearchFilters
  323.              Element searchFilters = root.getChild("SearchFilters");
  324. @@ -729,6 +728,13 @@
  325.                          String suffix = (inherit("suffix", sourceElement, subfolder));
  326.                          int level_deep = Integer.parseInt(subfolder.getAttributeValue("level_deep"));
  327.                          //String compression = (inherit("compression", sourceElement, subfolder));
  328. +                        
  329. +                       //AngryCamel - 20120817 1620
  330. +                        //force_series will override any parsed series name with the value specified
  331. +                        //The reason this was developed was for TED talks. I did not spend much time
  332. +                        // thinking about it's possible usage outside of that particular use
  333. +                        // case, but I'm sure someone will find another reason to use it.
  334. +                        String force_series = (inherit("force_series", sourceElement, subfolder));
  335.  
  336.                          Subfolder subf = new Subfolder(src, subfolderName);
  337.                          subf.setRecursive(recursive);
  338. @@ -745,13 +751,16 @@
  339.                          subf.setLevelDeep(level_deep);
  340.                          //subf.setCompression(compression);
  341.  
  342. +                       //AngryCamel - 20120817 1620
  343. +                        subf.setForceSeries(force_series);
  344. +
  345.                          String indent = "";
  346.                          for(int i=subf.getLevelDeep(); i>=0; i--)indent+="\t";
  347.                              
  348.                          Config.log(INFO, indent+"Next Subfolder: name="+subf.getFullName()+", recursive="+subf.isRecursive()
  349.                                  +", type="+subf.getType()+", max_series="+subf.getMaxSeries()+", "
  350.                                  + "max_videos="+subf.getMaxVideos()+", movie_set="+subf.getMovieSet()+", prefix="+subf.getPrefix()+", suffix="+subf.getSuffix()+
  351. -                                /*", download="+download+", compression="+(valid(compression) ? compression:"")+*/", multi_part="+containsMultiPartVideos);
  352. +                                /*", download="+download+", compression="+(valid(compression) ? compression:"")+*/", multi_part="+containsMultiPartVideos +", force_series="+subf.getForceSeries());
  353.  
  354.                          //check for excludes/filters at the subfolder level
  355.                          //inherit any excludes/filters from parent subfolders
  356. @@ -785,6 +794,26 @@
  357.                                  }
  358.                              }
  359.                          }
  360. +                        
  361. +                       //AngryCamel - 20120815 2246
  362. +                        //Parsers override the default series and title parser in Archiver.addTVMetaData()
  363. +                        //If multiple parsers are supplied, the order that they are read
  364. +                        // from the XML is the priority order they will be processed in
  365. +                        // until one finds a match.
  366. +                        for(Element nextSubf : subfolderAndParents)
  367. +                        {
  368. +                            Element parserElem = nextSubf.getChild("parser");
  369. +                            if(parserElem != null)
  370. +                            {
  371. +                                List<Element> parsers = parserElem.getChildren();
  372. +                                for(Element parser : parsers)
  373. +                                {
  374. +                                    subf.addParser(parser.getName(), parser.getText());
  375. +                                    log(DEBUG, indent+"\tAdded subfolder Parser: type="+parser.getName()+", value="+parser.getText());
  376. +                                }
  377. +                            }
  378. +                        }
  379. +                        
  380.                          src.addSubfolder(subf);
  381.                      }//end subfolders
  382.                  }//end top subfolders              
  383. Index: utilities/Constants.java
  384. ===================================================================
  385. --- utilities/Constants.java    (revision 11)
  386. +++ utilities/Constants.java    (working copy)
  387. @@ -36,7 +36,13 @@
  388.    
  389.     //AngryCamel - 20120805 2351
  390.      public final static String  RUNTIME = "runtime";
  391. +    
  392. +   //AngryCamel - 20120815 2246
  393. +    public final static String  FORCE_SERIES = "force_series";
  394.  
  395. +   //AngryCamel - 20120817 1620
  396. +    public final static String  GENERIC = "generic";
  397. +
  398.      public final static String  FOLDERS_ONLY = "FOLDERS_ONLY";
  399.      public final static String  FILES_ONLY = "FILES_ONLY";
  400.      public final static String  FOLDERS_AND_FILES = "FOLDERS_AND_FILES";
  401. Index: utilities/Filter.java
  402. ===================================================================
  403. --- utilities/Filter.java   (revision 11)
  404. +++ utilities/Filter.java   (working copy)
  405. @@ -29,7 +29,28 @@
  406.                  }
  407.                  else if(type.equalsIgnoreCase(Constants.CONTAINS))
  408.                  {
  409. -                    if(!path.toLowerCase().contains(filterString.toLowerCase()))
  410. +                   //AngryCamel - 20120818 0201
  411. +                   //  "Only videos that match ALL filters will be included (unless it matched an exclude)" is
  412. +                   //    what the documentation states for the contains item. This however, does not provide any
  413. +                   //    way of specifying a logical operator OR to the filter. Because it must match ALL, it is
  414. +                   //    always performing an AND comparison for each "contains" item listed
  415. +                   //  This features keeps that AND behavior between each contains element but allows the text
  416. +                   //    of the element body to delimited by an OR operator "||". This double pipe OR operator
  417. +                   //    will be used as a delimiter to split the contains criteria and if any of them match, then
  418. +                   //    the filter will pass.
  419. +                   boolean orGroupMatch = false;
  420. +                   String[] orItems = filterString.toLowerCase().split("\\|\\|");
  421. +                    for(String orItem : orItems)
  422. +                    {
  423. +                        boolean match = path.toLowerCase().contains(orItem.trim());
  424. +                        if(match)
  425. +                        {
  426. +                           orGroupMatch = true;
  427. +                           break;
  428. +                        }
  429. +                    }
  430. +                    //Config.log(Config.DEBUG, "Include ? "+ orGroupMatch +" \""+path+"\" "+(!orGroupMatch ? "does not contain" : "contains")+"  \""+Arrays.toString(orItems)+"\"");
  431. +                    if(!orGroupMatch)
  432.                          return false;//this path does not contains this string, return false because all filters must match
  433.                  }
  434.                 //AngryCamel - 20120805 2351
  435. @@ -50,7 +71,7 @@
  436.                     int runtimeFilter = 0;
  437.                     String operator = "";
  438.                    
  439. -                   splitFilterStr = filterString.toLowerCase().split("|");
  440. +                   splitFilterStr = filterString.toLowerCase().split("\\|");
  441.                     if(splitFilterStr.length < 2)
  442.                         return false;//filter string format invalid
  443.                    
  444. @@ -62,72 +83,72 @@
  445.                         return false;//filter string format invalid
  446.                     }
  447.                    
  448. -                   if(operator.equals("EQ"))
  449. +                   if(operator.equals("eq"))
  450.                     {
  451.                         //Handle Equal To check here
  452.                         if(runtime == runtimeFilter)
  453.                         {
  454. -                           return true;
  455. +                           //return true;
  456.                         }
  457.                         else
  458.                         {
  459.                             return false;
  460.                         }
  461.                     }
  462. -                   else if(operator.equals("GT"))
  463. +                   else if(operator.equals("gt"))
  464.                     {
  465.                         //Handle Greater Than check here
  466.                         if(runtime > runtimeFilter)
  467.                         {
  468. -                           return true;
  469. +                           //return true;
  470.                         }
  471.                         else
  472.                         {
  473.                             return false;
  474.                         }
  475.                     }
  476. -                   else if(operator.equals("LT"))
  477. +                   else if(operator.equals("lt"))
  478.                     {
  479.                         //Handle Less Than check here
  480.                         if(runtime < runtimeFilter)
  481.                         {
  482. -                           return true;
  483. +                           //return true;
  484.                         }
  485.                         else
  486.                         {
  487.                             return false;
  488.                         }
  489.                     }
  490. -                   else if(operator.equals("NE"))
  491. +                   else if(operator.equals("ne"))
  492.                     {
  493.                         //Handle Not Equal To check here
  494.                         if(runtime != runtimeFilter)
  495.                         {
  496. -                           return true;
  497. +                           //return true;
  498.                         }
  499.                         else
  500.                         {
  501.                             return false;
  502.                         }
  503.                     }
  504. -                   else if(operator.equals("GE"))
  505. +                   else if(operator.equals("ge"))
  506.                     {
  507.                         //Handle Greater than or equal to check here
  508.                         if(runtime >= runtimeFilter)
  509.                         {
  510. -                           return true;
  511. +                           //return true;
  512.                         }
  513.                         else
  514.                         {
  515.                             return false;
  516.                         }
  517.                     }
  518. -                   else if(operator.equals("LE"))
  519. +                   else if(operator.equals("le"))
  520.                     {
  521.                         //Handle Less than or equal to check here
  522.                         if(runtime <= runtimeFilter)
  523.                         {
  524. -                           return true;
  525. +                           //return true;
  526.                         }
  527.                         else
  528.                         {
  529. Index: utilities/Subfolder.java
  530. ===================================================================
  531. --- utilities/Subfolder.java    (revision 11)
  532. +++ utilities/Subfolder.java    (working copy)
  533. @@ -13,6 +13,11 @@
  534.      int numberofVideos = 0;
  535.      public Map<String,List<String>> excludes = new LinkedHashMap<String,List<String>>();
  536.      public Map<String,List<String>> filters = new LinkedHashMap<String,List<String>>();
  537. +    
  538. +   //AngryCamel - 20120815 2246
  539. +    public Map<String,List<String>> parsers = new LinkedHashMap<String,List<String>>();
  540. +    String force_series = null;
  541. +    
  542.      Source source;
  543.      String regexMatchingName = null;//if the name is a regex, this will be set to what the regex matches
  544.      boolean canContainMultiPartVideos = false;
  545. @@ -28,6 +33,16 @@
  546.          this.source = source;
  547.      }
  548.  
  549. +   //AngryCamel - 20120815 2246
  550. +    public void setForceSeries(String series)
  551. +    {
  552. +        this.force_series = series;
  553. +    }
  554. +    public String getForceSeries()
  555. +    {
  556. +        return force_series;
  557. +    }
  558. +    
  559.      public void setLevelDeep(int level)
  560.      {
  561.          this.level_deep = level;
  562. @@ -137,6 +152,11 @@
  563.      {
  564.          return !filters.isEmpty();
  565.      }
  566. +   //AngryCamel - 20120815 2246
  567. +    public boolean shouldApplyParser()
  568. +    {
  569. +        return !parsers.isEmpty();
  570. +    }
  571.      public void addExclude(String type, String value)
  572.      {
  573.          List<String> values = excludes.get(type);
  574. @@ -151,6 +171,14 @@
  575.          values.add(value);
  576.          filters.put(type, values);
  577.      }
  578. +   //AngryCamel - 20120815 2246
  579. +    public void addParser(String type, String value)
  580. +    {
  581. +        List<String> values = parsers.get(type);
  582. +        if(values == null) values = new ArrayList<String>();
  583. +        values.add(value);
  584. +        parsers.put(type, values);
  585. +    }
  586.      public void setMovieSet(String movieSet)
  587.      {
  588.          this.movie_set = movieSet;
  589. @@ -336,13 +364,12 @@
  590.          return false;//no match
  591.      }
  592.  
  593. -       /*
  594. +     /*
  595.       * Checks the path against the filters.
  596.       * Returns true if it is allowed by ALL filters or filter matching is not used
  597.       * Returns false if this path should be skipped
  598.       */
  599.     //AngryCamel - 20120805 2351
  600. -    // public boolean isAllowedByFilters(String path)
  601.     public boolean isAllowedByFilters(String path, int runtime)
  602.      {
  603.          path = Config.escapePath(path);
  604. Index: utilities/tools.java
  605. ===================================================================
  606. --- utilities/tools.java    (revision 11)
  607. +++ utilities/tools.java    (working copy)
  608. @@ -494,6 +494,12 @@
  609.                                  table = "musicvideo";
  610.                                  idField = "idMVideo";
  611.                              }
  612. +                           //AngryCamel - 20120817 1620 - Added generic
  613. +                            else if(videoType.equals(GENERIC))
  614. +                            {
  615. +                                Config.log(WARNING,"Generic video type does not update meta data");
  616. +                                return false;
  617. +                            }
  618.                              else
  619.                              {
  620.                                  Config.log(WARNING,"Unknown video type: \""+ videoType+"\", will not update meta data");
  621. @@ -612,6 +618,10 @@
  622.                          changed = video.getYear() != currentlyArchivedFile.year;
  623.                      else if(video.isMusicVideo())
  624.                          changed = !video.getArtist().equals(currentlyArchivedFile.artist);
  625. +                   //AngryCamel - 20120817 1620 - Added generic
  626. +                    else if(video.isGeneric())
  627. +                        changed = !video.getSeries().equals(currentlyArchivedFile.series)
  628. +                               || !video.getTitle().equals(currentlyArchivedFile.title);
  629.                  }                    
  630.              }
  631.              if(!changed)
  632. @@ -1101,7 +1111,7 @@
  633.              return null;
  634.          }
  635.          
  636. -        Config.log(DEBUG, "Raw response from POST. Response Code = "+conn.getResponseCode()+" ("+conn.getResponseMessage()+"):\r\n"+ response);
  637. +        //Config.log(DEBUG, "Raw response from POST. Response Code = "+conn.getResponseCode()+" ("+conn.getResponseMessage()+"):\r\n"+ response);
  638.          return response.toString();
  639.      }
  640.      public static int getContentLength(String data) throws UnsupportedEncodingException{        
  641. Index: utilities/XBMCFile.java
  642. ===================================================================
  643. --- utilities/XBMCFile.java (revision 11)
  644. +++ utilities/XBMCFile.java (working copy)
  645. @@ -62,8 +62,7 @@
  646.          dest.setYear(source.getYear());
  647.      }
  648.    
  649. -   //AngryCamel - 20120805 2351
  650. -    //public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail, String parentPath, Subfolder matchingSubfolder)
  651. +   //AngryCamel - 20120805 2351 - Added runtime
  652.      public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail, int runtime, String parentPath, Subfolder matchingSubfolder)
  653.      {
  654.          this.fileOrDir = fileOrDir;
  655. @@ -79,8 +78,7 @@
  656.          this.subfolder = matchingSubfolder;
  657.      }
  658.      
  659. -    //AngryCamel - 20120805 2351
  660. -    //public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail)
  661. +    //AngryCamel - 20120805 2351 - Added runtime
  662.     public XBMCFile(String fileOrDir, String fanart, String file, String fileLabel, String thumbnail, int runtime)
  663.      {
  664.          this.fileOrDir = fileOrDir;
  665. @@ -215,6 +213,10 @@
  666.          if(isMovie() && tools.valid(getTitle())) return true;
  667.          if(isTvShow() && tools.valid(getSeries()) && getSeasonNumber() > -1 && getEpisodeNumber() > -1) return true;//title not required
  668.          if(isMusicVideo() && tools.valid(getTitle()) && tools.valid(getArtist())) return true;
  669. +
  670. +       //AngryCamel - 20120817 1620 - Added generic
  671. +        if(isGeneric() && tools.valid(getSeries()) && tools.valid(getTitle())) return true;
  672. +        
  673.          return false;
  674.      }
  675.      public void setArtist(String artist)
  676. @@ -258,7 +260,20 @@
  677.      }
  678.      public void setSeries(String series)
  679.      {                
  680. -        this.series = stripExtras(series);
  681. +       //AngryCamel - 20120817 1620
  682. +       //   Check if there is a forced series in the subfolder config and apply it instead of whatever was passed.
  683. +       try {
  684. +           if(tools.valid(this.getSubfolder().getForceSeries()))
  685. +           {
  686. +               this.series = stripExtras(this.getSubfolder().getForceSeries());
  687. +           }
  688. +           else
  689. +           {
  690. +               this.series = stripExtras(series);
  691. +           }
  692. +       } catch (Exception e) {
  693. +           this.series = stripExtras(series);
  694. +       }
  695.      }
  696.      
  697.      public String getSeries()
  698. @@ -306,7 +321,8 @@
  699.      }
  700.      public boolean knownType()
  701.      {
  702. -        return isMovie() || isTvShow() || isMusicVideo();
  703. +       //AngryCamel - 20120817 1620 - added isGeneric
  704. +        return isMovie() || isTvShow() || isMusicVideo() || isGeneric();
  705.      }
  706.      public boolean isTvShow()
  707.      {
  708. @@ -320,6 +336,13 @@
  709.      {
  710.          return MUSIC_VIDEO.equals(type);
  711.      }
  712. +    
  713. +   //AngryCamel - 20120817 1620 - added isGeneric
  714. +    public boolean isGeneric()
  715. +    {
  716. +        return GENERIC.equals(type);
  717. +    }
  718. +    
  719.      public String getFanart()
  720.      {
  721.          return fanart;
  722. Index: utilities/XbmcJsonRpc.java
  723. ===================================================================
  724. --- utilities/XbmcJsonRpc.java  (revision 11)
  725. +++ utilities/XbmcJsonRpc.java  (working copy)
  726. @@ -5,6 +5,9 @@
  727.  import java.net.SocketException;
  728.  import java.util.*;
  729.  import java.util.concurrent.*;
  730. +import java.util.regex.Matcher;
  731. +import java.util.regex.Pattern;
  732. +
  733.  import org.json.*;
  734.  
  735.  public class XbmcJsonRpc implements Runnable, Constants
  736. @@ -340,13 +343,17 @@
  737.      public static XBMCFile getXBMCFile(String fileOrDir, JSONObject json)
  738.      {
  739.          try {
  740. +           //AngryCamel - 20120806 2206
  741. +           String runtimeStr = json.has("runtime") ? json.getString("runtime") : "";
  742. +           int runtime = parseRuntime(runtimeStr);
  743. +          
  744.              XBMCFile xbmcFile = new XBMCFile(
  745.                          fileOrDir,
  746.                          json.has("fanart") ? json.getString("fanart") : null,
  747.                          json.has("file") ? json.getString("file") : null,
  748.                          json.has("label") ? json.getString("label") : null,
  749.                          json.has("thumbnail") ? json.getString("thumbnail") : null,
  750. -                       json.has("runtime") ? json.getInt("runtime") : null //AngryCamel - 20120805 2351
  751. +                       runtime //AngryCamel - 20120806 2206
  752.                      );
  753.              return xbmcFile;
  754.          }
  755. @@ -410,6 +417,7 @@
  756.                          BlockingQueue<XBMCFile> filesAndDirsFound//the list which all files/dirs will be added to                        
  757.                          )
  758.      {        
  759. +      
  760.          if(!subf.canAddAnotherVideo()) return;
  761.          Config.log(DEBUG, "Now looking in:" + Config.escapePath(fullPathLabel) + (Config.LOGGING_LEVEL == DEBUG ?" (" + dir+")" :""));
  762.  
  763. @@ -423,7 +431,7 @@
  764.         // -Added runtime for the runtime filter.
  765.         // -You were referencing label (returned when title is specified in properties), thumbnail, and fanart when creating XBMCFile but
  766.         //  they were not coming back in the JSON reponse, so I added those while I was at it.
  767. -        final String properties = "[\"runtime\", \"title\", \"thumbnail\", \"fanart\"]";//files should return everything after fix here: http://forum.xbmc.org/showthread.php?t=114921
  768. +        final String[] properties = {"runtime", "title", "thumbnail", "fanart"};//files should return everything after fix here: http://forum.xbmc.org/showthread.php?t=114921
  769.          params.put("properties", properties);  
  770.          
  771.          /*Sort testing
  772. @@ -478,14 +486,18 @@
  773.                      if(!files.isEmpty())
  774.                      {
  775.                          for(JSONObject file : files)
  776. -                        {                          
  777. -                           XBMCFile xbmcFile = new XBMCFile(
  778. +                        {
  779. +                           //AngryCamel - 20120806 2206
  780. +                           String runtimeStr = file.has("runtime") ? file.getString("runtime") : "";
  781. +                           int runtime = parseRuntime(runtimeStr);
  782. +                          
  783. +                           XBMCFile xbmcFile = new XBMCFile(
  784.                                      FILE,
  785.                                      file.has("fanart") ? file.getString("fanart") : null,
  786.                                      file.getString("file"), //required
  787.                                      file.getString("label"), //required
  788.                                      file.has("thumbnail") ? file.getString("thumbnail") : null,
  789. -                                   file.has("runtime") ? file.getInt("runtime") : null, //AngryCamel - 20120805 2351
  790. +                                    runtime, //AngryCamel - 20120806 2206
  791.                                      fullPathLabel,
  792.                                      subf);
  793.  
  794. @@ -597,7 +609,111 @@
  795.              }
  796.          }//end if valid json returned
  797.      }
  798. +    
  799. +    //AngryCamel - 20120806 214700
  800. +    //  -Added runtime parsing to detect the format and if necessary translate to a number of minutes as an integer
  801. +    public static int parseRuntime(String runtimeStr)
  802. +    {
  803. +       if(runtimeStr.equals(""))
  804. +           return 0;
  805. +      
  806. +       int runTime = 0;
  807. +      
  808. +       //HH:MM:SS Pattern matches any of the following:
  809. +       //39:10, 31:46, 1:39:58, 9:13, 69:58:06
  810. +       String hhmmssPattern = "(\\d*):?(\\d*)?:([0-5][0-9])";  
  811. +      
  812. +       // Compile and use regular expression
  813. +       Pattern pattern = Pattern.compile(hhmmssPattern);
  814. +       Matcher matcher = pattern.matcher(runtimeStr);
  815. +       boolean matchFound = matcher.find();
  816. +       if (matchFound) {
  817. +           int hours = 0, mins = 0, secs = 0;
  818.  
  819. +           /*
  820. +           String groupStr = "";
  821. +           for (int i=0; i<=matcher.groupCount(); i++) {
  822. +                groupStr += " Group("+i+"): "+matcher.group(i);
  823. +            }
  824. +           Config.log(Config.DEBUG, "Match:"+ groupStr);
  825. +           */
  826. +          
  827. +           if(matcher.groupCount()==3)
  828. +           {
  829. +               //For patterns without an hour segment, the minute will go into group 1 and the seconds into group 3. Group 2 will be empty
  830. +               //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
  831. +               if(matcher.group(2).length() < 1)
  832. +               {
  833. +                   //This is a MM:SS match
  834. +                   //Config.log(Config.DEBUG, "Matched on MM:SS pattern: "+ runtimeStr);
  835. +                  
  836. +                   //Parse the minutes
  837. +                   if(matcher.group(1).length()>0)
  838. +                   {
  839. +                       try{
  840. +                           mins = Integer.parseInt(matcher.group(1));
  841. +                       }catch (NumberFormatException e){}
  842. +                   }
  843. +                   //Config.log(Config.DEBUG, "   Mins: "+ mins);
  844. +                  
  845. +                   //Parse the seconds
  846. +                   if(matcher.group(3).length()>0)
  847. +                   {
  848. +                       try{
  849. +                           secs = Integer.parseInt(matcher.group(3));
  850. +                       }catch (NumberFormatException e){}
  851. +                   }
  852. +                   //Config.log(Config.DEBUG, "   Secs: "+ secs);
  853. +               }
  854. +               else
  855. +               {
  856. +                   //This is a HH:MM:SS match
  857. +                   //Config.log(Config.DEBUG, "Matched on HH:MM:SS pattern: "+ runtimeStr);
  858. +                  
  859. +                   //Parse the hours
  860. +                   if(matcher.group(1).length()>0)
  861. +                   {
  862. +                       try{
  863. +                           hours = Integer.parseInt(matcher.group(1));
  864. +                       }catch (NumberFormatException e){}
  865. +                   }
  866. +                   //Config.log(Config.DEBUG, "   Hours: "+ hours);
  867. +                  
  868. +                   //Parse the minutes
  869. +                   if(matcher.group(2).length()>0)
  870. +                   {
  871. +                       try{
  872. +                           mins = Integer.parseInt(matcher.group(2));
  873. +                       }catch (NumberFormatException e){}
  874. +                   }
  875. +                   //Config.log(Config.DEBUG, "   Mins: "+ mins);
  876. +                  
  877. +                   //Parse the seconds
  878. +                   if(matcher.group(3).length()>0)
  879. +                   {
  880. +                       try{
  881. +                           secs = Integer.parseInt(matcher.group(3));
  882. +                       }catch (NumberFormatException e){}
  883. +                   }
  884. +                   //Config.log(Config.DEBUG, "   Secs: "+ secs);
  885. +               }
  886. +           }
  887. +           //Now add it all up
  888. +           runTime = (60*60*hours) + (60*mins) + secs;
  889. +       }
  890. +       else
  891. +       {
  892. +           //Format did not match HH:MM:SS format; try to parse as int
  893. +           //Config.log(Config.DEBUG, "Runtime format has no pattern (parsing as int): "+ runtimeStr);
  894. +           try{
  895. +               runTime = Integer.parseInt(runtimeStr);
  896. +           }catch (NumberFormatException e){}
  897. +       }
  898. +
  899. +       //Config.log(Config.DEBUG, "Parsed " + runtimeStr + " to " + runTime + " mins");
  900. +        return runTime;
  901. +    }
  902. +
  903.  
  904.      
  905.      Socket jsonRPCSocket = null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement