Ejemplo n.º 1
0
        private void WriteXmlTags(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
              WorkerArgs args = e.Argument as WorkerArgs;

              var filteredfileNames = Directory.GetFiles(args.Directory, "*.*", SearchOption.AllDirectories);
              MPTVSeriesImporter importer = new MPTVSeriesImporter();
              importer.OpenConnection();

              int current = 0;
              int total = filteredfileNames.Count();
              foreach (var file in filteredfileNames)
              {
            if (worker.CancellationPending)
            {
              e.Cancel = true;
              break;
            }

            current++;
            worker.ReportProgress(100*current/total);

            // Check only video files
            if (!SupportedFiles.IsFileSupportedVideo(file))
              continue;

            // build xml file name
            string xmlFile = GetXmlFilename(file);

            // init document
            MatroskaTags tag = new MatroskaTags();

            // Read MKV tags, if existing should be reused
            if (App.Config.BasedOnExistingTags)
              tag = MatroskaLoader.ReadTag(file);

            // update tags from MP-TVSeries
            tag.Series = importer.UpdateTags(tag.Series, file);

            string logText = File.Exists(xmlFile) ? "XML updated: " : "XML created: ";
            MatroskaLoader.WriteTagToXML(tag, xmlFile);
            worker.ReportProgress(100 * current / total, new FileBasedLogEntry(xmlFile, logText));
              }

              importer.CloseConnection();
        }
Ejemplo n.º 2
0
        private void WriteMkvTags(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
              WorkerArgs args = e.Argument as WorkerArgs;
              DirectoryInfo di = new DirectoryInfo(args.Directory);
              List<FileInfo> mkvFiles = new List<FileInfo>();
              mkvFiles.AddRange(di.GetFiles("*.mkv", SearchOption.AllDirectories));
              mkvFiles.AddRange(di.GetFiles("*.mk3d", SearchOption.AllDirectories));

              MPTVSeriesImporter importer = new MPTVSeriesImporter();
              importer.OpenConnection();

              int current = 0;
              int total = mkvFiles.Count;
              foreach (FileInfo mkvFile in mkvFiles)
              {
            string file = mkvFile.FullName;
            if (worker.CancellationPending)
            {
              e.Cancel = true;
              break;
            }

            current++;
            worker.ReportProgress(100 * current / total);

            // init document
            MatroskaTags tag = new MatroskaTags();

            // Read MKV tags, if existing should be reused
            if (App.Config.BasedOnExistingTags)
              tag = MatroskaLoader.ReadTag(file);

            // update tags from MP-TVSeries
            tag.Series = importer.UpdateTags(tag.Series, file);

            try
            {
              int exitCode = MatroskaLoader.WriteTagToMatroska(mkvFile.FullName, tag);

              if (exitCode == 0)
              {
            worker.ReportProgress(100*current/total, new FileBasedLogEntry(mkvFile.FullName, "MKV updated: "));
            if (args.DeleteXmlAfterMkvUpdate)
            {
              // build xml file name
              string xmlFile = GetXmlFilename(file);
              File.Delete(xmlFile);
            }
              }
              else
            worker.ReportProgress(100*current/total,
                                  new FileBasedLogEntry(mkvFile.FullName,
                                                        string.Format(
                                                          "MKV updated with MKVPropEdit exit code = {0} file :",
                                                          exitCode)));
            }
            catch (Exception ex)
            {
              worker.ReportProgress(100*current/total, new FileBasedLogEntry(mkvFile.FullName, ex.Message));
            }
              }

              importer.CloseConnection();
        }