コード例 #1
0
ファイル: cmbConv.cs プロジェクト: ErwinKomen/subtiel
        /// <summary>
        /// addToCsv -- add one Harvest object to the CSV
        /// </summary>
        /// <param name="oThis"></param>
        /// <returns></returns>
        private bool addToCsv(Harvest oThis)
        {
            try {
                // Create a string with the harvest output
                String sLine = oThis.name + "\t" + oThis.cmdi + "\t" + oThis.movieGenres + "\t" + oThis.movieId + "\t" +
                               oThis.movieImdbId + "\t" + oThis.movieKind + "\t" + oThis.movieLanguage + "\t" + oThis.movieName + "\t" +
                               oThis.movieRating + "\t" + oThis.movieVotes + "\t" + oThis.movieYear + "\t" + oThis.releaseName + "\t" +
                               oThis.stDate + "\t" + oThis.stId + "\t" + oThis.stLanguage + "\t" + oThis.stLicType + "\t" +
                               oThis.stLink + "\t" + oThis.stLng + "\t" + oThis.stSentences + "\t" + oThis.stStatus + "\t" +
                               oThis.stUserClass + "\t" + oThis.stUserId + "\t" + oThis.stUserPseudo + "\t" + oThis.stWords + "\n";
                File.AppendAllText(this.sCsvFile, sLine, Encoding.UTF8);

                // Return positively
                return(true);
            } catch (Exception ex) {
                errHandle.DoError("cmdConv/addToCsv", ex);
                return(false);
            }
        }
コード例 #2
0
ファイル: cmbConv.cs プロジェクト: ErwinKomen/subtiel
        /* -------------------------------------------------------------------------------------
        * Name:        harvestSaveXml
        * Goal:        Save the harvested information to an XML file
        * History:
        * 14/mar/2016 ERK Created
        *  ------------------------------------------------------------------------------------- */
        public bool harvestSaveXml(String sFile)
        {
            try {
                // Make sure the output file name is in order
                String sFileOut = Path.GetFullPath(sFile);
                // Create an XmlDocument with some structure
                XmlDocument pdxOut = new XmlDocument();
                pdxOut.LoadXml("<subtielInfo>" +
                               " <Creation>" + DateTime.Today.ToLongDateString() + "</Creation>" +
                               " <InfoList></InfoList>" +
                               "</subtielInfo>");
                XmlNode ndxInfoList = pdxOut.SelectSingleNode("./descendant::InfoList");
                oTools.SetXmlDocument(pdxOut);
                if (ndxInfoList != null)
                {
                    // Add all lines from the list
                    for (int i = 0; i < this.lstHarvest.Count; i++)
                    {
                        // Access this list item
                        Harvest oThis = lstHarvest[i];
                        // Create one item here
                        oTools.AddXmlChild(ndxInfoList, "Info",
                                           "name", oThis.name, "attribute",
                                           "cmdi", ((oThis.cmdi) ? "true" : "false"), "attribute",
                                           "movieGenres", oThis.movieGenres, "attribute",
                                           "movieId", oThis.movieId, "attribute",
                                           "movieImdbId", oThis.movieImdbId, "attribute",
                                           "movieKind", oThis.movieKind, "attribute",
                                           "movieLanguage", oThis.movieLanguage, "attribute",
                                           "movieName", oThis.movieName, "attribute",
                                           "movieRating", oThis.movieRating, "attribute",
                                           "movieVotes", oThis.movieVotes, "attribute",
                                           "movieYear", oThis.movieYear, "attribute",
                                           "releaseName", oThis.releaseName, "attribute",
                                           "stDate", oThis.stDate, "attribute",
                                           "stId", oThis.stId, "attribute",
                                           "stLanguage", oThis.stLanguage, "attribute",
                                           "stLicenseType", oThis.stLicType, "attribute",
                                           "stLink", oThis.stLink, "attribute",
                                           "stLngAvailable", oThis.stLng, "attribute",
                                           "stSentences", oThis.stSentences, "attribute",
                                           "stStatus", oThis.stStatus, "attribute",
                                           "stUserClass", oThis.stUserClass, "attribute",
                                           "stUserId", oThis.stUserId, "attribute",
                                           "stUserPseudo", oThis.stUserPseudo, "attribute",
                                           "stWords", oThis.stWords, "attribute");

                        /*
                         * String sLine = oThis.name + "\t" + oThis.cmdi + "\t" + oThis.movieGenres + "\t" + oThis.movieId + "\t" +
                         * oThis.movieImdbId + "\t" + oThis.movieKind + "\t" + oThis.movieLanguage + "\t" + oThis.movieName + "\t" +
                         * oThis.movieRating + "\t" + oThis.movieVotes + "\t" + oThis.movieYear + "\t" + oThis.releaseName + "\t" +
                         * oThis.stDate + "\t" + oThis.stId + "\t" + oThis.stLanguage + "\t" + oThis.stLicType + "\t" +
                         * oThis.stLink + "\t" + oThis.stLng + "\t" + oThis.stSentences + "\t" + oThis.stStatus + "\t" +
                         * oThis.stUserClass + "\t" + oThis.stUserId + "\t" + oThis.stUserPseudo + "\t" + oThis.stWords + "\n";
                         */
                    }
                }
                // Write the XML
                pdxOut.Save(sFileOut);

                return(true);
            } catch (Exception ex) {
                errHandle.DoError("cmdConv/harvestOneFolia", ex);
                return(false);
            }
        }
コード例 #3
0
ファイル: cmbConv.cs プロジェクト: ErwinKomen/subtiel
        /// <summary>
        /// addToCsv -- add one Harvest object to the CSV
        /// </summary>
        /// <param name="oThis"></param>
        /// <returns></returns>
        private bool addToCsv(Harvest oThis)
        {
            try {
            // Create a string with the harvest output
            String sLine = oThis.name + "\t" + oThis.cmdi + "\t" + oThis.movieGenres + "\t" + oThis.movieId + "\t" +
              oThis.movieImdbId + "\t" + oThis.movieKind + "\t" + oThis.movieLanguage + "\t" + oThis.movieName + "\t" +
              oThis.movieRating + "\t" + oThis.movieVotes + "\t" + oThis.movieYear + "\t" + oThis.releaseName + "\t" +
              oThis.stDate + "\t" + oThis.stId + "\t" + oThis.stLanguage + "\t" + oThis.stLicType + "\t" +
              oThis.stLink + "\t" + oThis.stLng + "\t" + oThis.stSentences + "\t" + oThis.stStatus + "\t" +
              oThis.stUserClass + "\t" + oThis.stUserId + "\t" + oThis.stUserPseudo + "\t" + oThis.stWords + "\n";
            File.AppendAllText(this.sCsvFile, sLine, Encoding.UTF8);

            // Return positively
            return true;
              } catch (Exception ex) {
            errHandle.DoError("cmdConv/addToCsv", ex);
            return false;
              }
        }
コード例 #4
0
ファイル: cmbConv.cs プロジェクト: ErwinKomen/subtiel
        /* -------------------------------------------------------------------------------------
        * Name:        harvestOneFolia
        * Goal:        Determine the status of this FoLiA file, and then:
        *              1) Store the harvest information in the list
        *              2) Copy the .folia.xml.gz file to the correct target
        *              3) Copy the .cmdi.xml file to the correct target
        * History:
        * 14/mar/2016 ERK Created
        *  ------------------------------------------------------------------------------------- */
        public bool harvestOneFolia(String sFileFolia)
        {
            String sTarget = ""; // Target file name

            try {
                // Validate
                if (!bInit)
                {
                    errHandle.DoError("cmdConv/harvestOneFolia", "The [output] has not been set"); return(false);
                }
                // Create a Harvest-log-item
                Harvest oLog = new Harvest(sFileFolia);
                // Look for the corresponsing .cmdi.xml file
                String sFileCmdi = Path.GetFileName(sFileFolia).Replace(".folia.xml.gz", ".cmdi.xml");
                if (getCmdi(ref sFileCmdi))
                {
                    // Indicate that we HAVE a cmdi file
                    oLog.cmdi = true;
                    // The .cmdi.xml file exists: load this as an XML file
                    pdxCmdi.Load(sFileCmdi);
                    nsCmdi = new XmlNamespaceManager(pdxCmdi.NameTable);
                    nsCmdi.AddNamespace("c", pdxCmdi.DocumentElement.NamespaceURI);
                    // Find a range of field values
                    oLog.movieGenres   = getFieldValue("Movie", "GenreList", "");
                    oLog.movieId       = getFieldValue("Movie", "MovieId", "");
                    oLog.movieImdbId   = getFieldValue("Movie", "ImdbId", "");
                    oLog.movieImdbId   = getFieldValue("Movie", "Kind", "");
                    oLog.movieLanguage = getFieldValue("Movie", "LanguageList", "");
                    oLog.movieName     = getFieldValue("Movie", "Name", "");
                    oLog.movieRating   = getFieldValue("Movie", "imdbRating", "");
                    oLog.movieVotes    = getFieldValue("Movie", "imdbVotes", "");
                    oLog.movieYear     = getFieldValue("Movie", "Year", "");
                    oLog.releaseName   = getFieldValue("Release", "Name", "");
                    oLog.stDate        = getFieldValue("Subtitle", "Date", "");
                    oLog.stId          = getFieldValue("Subtitle", "SubtitleId", "");
                    oLog.stLanguage    = getFieldValue("Subtitle", "languageCode", "");
                    oLog.stLicType     = getFieldValue("License", "LicenseType", "");
                    oLog.stLink        = getFieldValue("Subtitle", "StatusInfo", "link");
                    oLog.stLng         = getFieldValue("Subtitle", "languageAvailable", "");
                    oLog.stSentences   = getFieldValue("Subtitle", "nSentences", "");
                    if (oLog.stSentences == "")
                    {
                        oLog.stSentences = getFieldValue("Subtitle", "nSents", "");
                    }
                    oLog.stStatus     = getFieldValue("Subtitle", "StatusInfo", "status");
                    oLog.stUserClass  = getFieldValue("Author", "UserClass", "");
                    oLog.stUserId     = getFieldValue("Author", "UserID", "");
                    oLog.stUserPseudo = getFieldValue("Author", "Pseudonym", "");
                    oLog.stWords      = getFieldValue("Subtitle", "nWords", "");

                    String sYear = (oLog.movieYear == "") ? "" : "/" + oLog.movieYear;

                    // Logging of status
                    errHandle.Status("harvestOneFolia [" + sFileCmdi + "] status=[" + oLog.stStatus + "]");

                    // Action depends on the status we have
                    String sYearDir = "";
                    switch (oLog.stStatus)
                    {
                    case "copy": sYearDir = sDirCopy + sYear; break;   // This is a 'copy'

                    case "equal": sYearDir = sDirEqual + sYear; break; // Status is 'equal'

                    case "": sYearDir = sDirOther + sYear; break;      // Unknown status??

                    default: sYearDir = sDirFinal + sYear; break;      // Includes: unique, largest
                    }
                    // Check directory
                    if (!Directory.Exists(sYearDir))
                    {
                        Directory.CreateDirectory(sYearDir);
                    }
                    // Copy all to the 'final' directory
                    sTarget = Path.GetFullPath(sYearDir + "/" + oLog.name);
                    // Perform the correct copies
                    File.Copy(sFileFolia, sTarget + ".folia.xml.gz", true);
                    File.Copy(sFileCmdi, sTarget + ".cmdi.xml", true);
                }
                else
                {
                    // Indicate that there is NO CMDI of this file
                    oLog.cmdi = false;
                    String sYear = "/noyear";
                    // Check directory
                    if (!Directory.Exists(sDirNotUsed + sYear))
                    {
                        Directory.CreateDirectory(sDirNotUsed + sYear);
                    }
                    // Copy to the [not used] directory
                    sTarget = Path.GetFullPath(sDirNotUsed + sYear + "/" + oLog.name) + ".folia.xml.gz";
                    File.Copy(sFileFolia, sTarget, true);
                }
                // Add the log to the list
                this.lstHarvest.Add(oLog);
                // Log this entry to the CSV file
                addToCsv(oLog);
                // Show what we have been doing
                errHandle.Status("status=[" + oLog.stStatus + "]\t" + sTarget);
                // Return positively
                return(true);
            } catch (Exception ex) {
                errHandle.DoError("cmdConv/harvestOneFolia", ex);
                return(false);
            }
        }
コード例 #5
0
ファイル: cmbConv.cs プロジェクト: ErwinKomen/subtiel
        /* -------------------------------------------------------------------------------------
         * Name:        harvestOneFolia
         * Goal:        Determine the status of this FoLiA file, and then:
         *              1) Store the harvest information in the list
         *              2) Copy the .folia.xml.gz file to the correct target
         *              3) Copy the .cmdi.xml file to the correct target
         * History:
         * 14/mar/2016 ERK Created
           ------------------------------------------------------------------------------------- */
        public bool harvestOneFolia(String sFileFolia)
        {
            String sTarget = "";  // Target file name

              try {
            // Validate
            if (!bInit) { errHandle.DoError("cmdConv/harvestOneFolia", "The [output] has not been set"); return false; }
            // Create a Harvest-log-item
            Harvest oLog = new Harvest(sFileFolia);
            // Look for the corresponsing .cmdi.xml file
            String sFileCmdi = Path.GetFileName(sFileFolia).Replace(".folia.xml.gz", ".cmdi.xml");
            if (getCmdi(ref sFileCmdi)) {
              // Indicate that we HAVE a cmdi file
              oLog.cmdi = true;
              // The .cmdi.xml file exists: load this as an XML file
              pdxCmdi.Load(sFileCmdi);
              nsCmdi = new XmlNamespaceManager(pdxCmdi.NameTable);
              nsCmdi.AddNamespace("c", pdxCmdi.DocumentElement.NamespaceURI);
              // Find a range of field values
              oLog.movieGenres = getFieldValue("Movie", "GenreList", "");
              oLog.movieId = getFieldValue("Movie", "MovieId", "");
              oLog.movieImdbId = getFieldValue("Movie", "ImdbId", "");
              oLog.movieImdbId = getFieldValue("Movie", "Kind", "");
              oLog.movieLanguage = getFieldValue("Movie", "LanguageList", "");
              oLog.movieName = getFieldValue("Movie", "Name", "");
              oLog.movieRating = getFieldValue("Movie", "imdbRating", "");
              oLog.movieVotes = getFieldValue("Movie", "imdbVotes", "");
              oLog.movieYear = getFieldValue("Movie", "Year", "");
              oLog.releaseName = getFieldValue("Release", "Name", "");
              oLog.stDate = getFieldValue("Subtitle", "Date", "");
              oLog.stId = getFieldValue("Subtitle", "SubtitleId", "");
              oLog.stLanguage = getFieldValue("Subtitle", "languageCode", "");
              oLog.stLicType = getFieldValue("License", "LicenseType", "");
              oLog.stLink = getFieldValue("Subtitle", "StatusInfo", "link");
              oLog.stLng = getFieldValue("Subtitle", "languageAvailable", "");
              oLog.stSentences = getFieldValue("Subtitle", "nSentences", "");
              if (oLog.stSentences == "") oLog.stSentences = getFieldValue("Subtitle", "nSents", "");
              oLog.stStatus = getFieldValue("Subtitle", "StatusInfo", "status");
              oLog.stUserClass = getFieldValue("Author", "UserClass", "");
              oLog.stUserId = getFieldValue("Author", "UserID", "");
              oLog.stUserPseudo = getFieldValue("Author", "Pseudonym", "");
              oLog.stWords = getFieldValue("Subtitle", "nWords", "");

              String sYear = (oLog.movieYear == "") ? "" : "/" + oLog.movieYear;

              // Logging of status
              errHandle.Status("harvestOneFolia [" + sFileCmdi + "] status=[" + oLog.stStatus + "]");

              // Action depends on the status we have
              String sYearDir = "";
              switch (oLog.stStatus) {
            case "copy": sYearDir = sDirCopy + sYear; break;    // This is a 'copy'
            case "equal": sYearDir = sDirEqual + sYear; break;  // Status is 'equal'
            case "": sYearDir = sDirOther + sYear; break;       // Unknown status??
            default: sYearDir = sDirFinal + sYear; break;       // Includes: unique, largest
              }
              // Check directory
              if (!Directory.Exists(sYearDir)) { Directory.CreateDirectory(sYearDir); }
              // Copy all to the 'final' directory
              sTarget = Path.GetFullPath(sYearDir + "/" + oLog.name);
              // Perform the correct copies
              File.Copy(sFileFolia, sTarget + ".folia.xml.gz", true);
              File.Copy(sFileCmdi, sTarget + ".cmdi.xml", true);
            } else {
              // Indicate that there is NO CMDI of this file
              oLog.cmdi = false;
              String sYear = "/noyear";
              // Check directory
              if (!Directory.Exists(sDirNotUsed + sYear)) { Directory.CreateDirectory(sDirNotUsed + sYear);}
              // Copy to the [not used] directory
              sTarget = Path.GetFullPath(sDirNotUsed + sYear + "/" + oLog.name) + ".folia.xml.gz";
              File.Copy(sFileFolia, sTarget, true);
            }
            // Add the log to the list
            this.lstHarvest.Add(oLog);
            // Log this entry to the CSV file
            addToCsv(oLog);
            // Show what we have been doing
            errHandle.Status("status=[" + oLog.stStatus + "]\t"+sTarget);
            // Return positively
            return true;
              } catch (Exception ex) {
            errHandle.DoError("cmdConv/harvestOneFolia", ex);
            return false;
              }
        }