コード例 #1
0
ファイル: osrMovie.cs プロジェクト: ErwinKomen/subtiel
 // ==================== METHODS ============================================
 public bool getInformation(String sId, ref XmlNodeList ndList, ref XmlNode ndMovie)
 {
     try {
         // Check if we currently have information on this movie
         if (sId != this.idMovie)
         {
             int iWaitTime = 1; // Number of seconds to wait
             // Try get information
             String sUrl     = sBaseUrl + "idmovie-" + sId + "/xml";
             String sContent = WebRequestGetData(sUrl);
             while (!sContent.StartsWith("<"))
             {
                 // Try again
                 sContent = WebRequestGetData(sUrl);
                 // Check what we receive back
                 if (sContent == null)
                 {
                     // Indicate that this is a premature end
                     errHandle.Status("getInformation: webrequest time-out");
                     return(false);
                 }
             }
             // Read as XmlDocument
             pdxMovie.LoadXml(sContent);
             // Set the currnet idmovie
             this.idMovie = sId;
         }
         // Set the list of nodes for this move
         ndList  = pdxMovie.SelectNodes("./descendant::subtitle");
         ndMovie = pdxMovie.SelectSingleNode("./descendant::Movie");
         return(true);
     } catch (Exception ex) {
         errHandle.DoError("osrMoview/getInformation", ex);
         return(false);
     }
 }
コード例 #2
0
ファイル: osrMain.cs プロジェクト: ErwinKomen/subtiel
        // Command-line entry point + argument handling
        static void Main(string[] args)
        {
            String sInput    = "";                     // Input file or dir
            String sOutput   = "/scratch/ekomen/out/"; // Output directory, if specified
            String sLanguage = "dut";                  // This is the language abbreviation used in [osrMovie.cs] for sBaseUrl
            String sDict     = "";                     // Movie dictionary
            bool   bIsDebug  = false;                  // Debugging
            bool   bForce    = false;                  // Force
            bool   bOview    = false;                  // Make overview or not
            bool   bSkip     = false;                  // Skip everything that has *not* been made
            String sAction   = "cmdi";                 // Type of action to be taken

            try {
                // Check command-line options
                for (int i = 0; i < args.Length; i++)
                {
                    // get this argument
                    String sArg = args[i].Trim();
                    if (sArg.StartsWith("-"))
                    {
                        errHandle.Status("Processing argument [" + sArg + "]");
                        // Check out the arguments
                        switch (sArg.Substring(1))
                        {
                        case "i": // Input file or directory with .folia.xml files
                            sInput = args[++i];
                            break;

                        case "f": // Force
                            bForce = true;
                            break;

                        case "s": // Skip
                            bSkip = true;
                            break;

                        case "m": // Movie dictionary   -- Tab-separated list from opensubtitles.org
                            sDict = args[++i];
                            break;

                        case "o": // Output directory
                            sOutput = args[++i];
                            break;

                        case "h": // Calculate hashes and add them to existing .cmdi.xml files
                            sAction = "hash";
                            break;

                        case "v": // Make an overview
                            bOview = true;
                            break;

                        case "d": // Debugging
                            bIsDebug = true;
                            break;

                        case "l": // Language (three letter code)
                            sLanguage = args[++i];
                            break;
                        }
                    }
                    else if (sArg == "" || sArg == "\r")
                    {
                        // Do nothing
                    }
                    else
                    {
                        // Throw syntax error and leave
                        SyntaxError("1 - i=" + i + " args=" + args.Length + " argCurrent=[" + sArg + "]"); return;
                    }
                }
                // Check presence of input/output
                if (sInput == "")
                {
                    SyntaxError("2"); return;
                }

                // Initialize the main entry point for the conversion
                oprConv  objConv  = new oprConv(errHandle);
                osrMovie objMovie = new osrMovie(errHandle, sLanguage);
                omdbapi  objOmdb  = new omdbapi(errHandle);

                // Set directory for conversion
                objConv.dirRoot(sOutput);

                // Load the movie dictionary
                if (!objConv.loadMovieDictionary(sDict))
                {
                    errHandle.DoError("Main", "Could not load movie dictionary from [" + sDict + "]");
                    return;
                }

                // Initialise the Treebank Xpath functions, which may make use of tb:matches()
                util.XPathFunctions.conTb.AddNamespace("tb", util.XPathFunctions.TREEBANK_EXTENSIONS);

                // Check if the input is a directory or file
                if (Directory.Exists(sInput))
                {
                    WalkDirectoryTree(sInput, "*.folia.xml.gz", sInput, bForce, bSkip, bIsDebug, sAction,
                                      ref objConv, ref objMovie);
                }
                else
                {
                    // Show we don't have input file
                    errHandle.DoError("Main", "Cannot find input file(s) in: " + sInput);
                }
                // Calculate for each file which others are close to it
                // - try to determine the license information for the best matching .cmdi.xml files
                // - add some more meta-information to the .cmdi.xml files
                objConv.findDuplicates(ref lSubInst, 3, ref objOmdb);

                // Create an overview - if required
                if (bOview)
                {
                    String sOview = objConv.getDistanceOview();
                    // Save it in a standard file
                    String sFileCsv = Path.GetDirectoryName(sInput) + "/oview.csv";
                    File.WriteAllText(sFileCsv, sOview);
                }
                // Exit the program
                Console.WriteLine("Ready");
            } catch (Exception ex) {
                errHandle.DoError("Main", ex); // Provide standard error message
                throw;
            }
        }