Advertisement
Guest User

XBMC.MyLibrary Patch - AngryCamel - 20120817

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