public void SetFile(string filepath)
        {
            originalTag = MatroskaLoader.ReadTag(filepath);
              if (ReferenceEquals(originalTag, null))
              {
            //clear textboxes
            txtXmlFilename.Text = string.Empty;
            dockXml.Visibility = Visibility.Collapsed;
            txtFilename.Text = filepath;

            textEditorOriginal.Text = string.Empty;
            ClearGUI();
              }
              else
              {
            txtXmlFilename.Text = string.Empty;
            dockXml.Visibility = Visibility.Collapsed;
            txtFilename.Text = filepath;

            textEditorOriginal.Text = MatroskaLoader.GetXML(originalTag);
            ClearGUI();
            UpdateGUI(originalTag);
              }
              saveButton.IsEnabled = false;
              UpdatePreview(null, null);
        }
Ejemplo n.º 2
0
        public static MatroskaTags ReadTagFromMatroska(string matroskaFile)
        {
            string tempFile = Path.GetTempFileName();

            ProcessStartInfo info = new ProcessStartInfo();

            info.FileName               = "mkvextract.exe";
            info.Arguments              = String.Format(" tags \"{0}\" --redirect-output \"{1}\"", matroskaFile, tempFile);
            info.UseShellExecute        = false;
            info.RedirectStandardInput  = true;
            info.RedirectStandardOutput = true;
            info.RedirectStandardError  = true;
            info.CreateNoWindow         = true;

            Process proc = Process.Start(info);

            proc.WaitForExit();

            MatroskaTags result = ReadTagFromXMLFile(tempFile);

            if (File.Exists(tempFile))
            {
                File.Delete(tempFile);
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static void WriteTags(MatroskaTags tags, string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("fileName");
            }

            //if (tagCache.ContainsKey(fileName))
            //  return tagCache[fileName];

            string extension = Path.GetExtension(fileName);

            if (extension == null)
            {
                throw new FileFormatException("File was not identified as XML or Matroska-file.");
            }

            if (extension.ToLower().Equals(".xml"))
            {
                // XML file
                WriteTagToXML(tags, fileName);
            }
            else if (MatroskaExtensions.Contains(extension.ToLower()))
            {
                // Matroska file
                WriteTagToMatroska(fileName, tags);
            }
            else
            {
                // Invalid file
                //throw new FileFormatException("File was not identified as XML or Matroska-file.");
                fileName = Path.ChangeExtension(fileName, ".xml");
                WriteTagToXML(tags, fileName);
            }
        }
Ejemplo n.º 4
0
        public void ReadTags(string filename)
        {
            MatroskaTags tags = MatroskaLoader.ReadTag(filename);

            if (tags != null)
            {
                TagList = tags.TagList;
            }
        }
Ejemplo n.º 5
0
        public static MatroskaTags Clone(MatroskaTags baseTag)
        {
            if (!ReferenceEquals(baseTag, null))
              {
            string xmlString = GetXML(baseTag);
            return ReadTagFromXML(xmlString);
              }

              return new MatroskaTags();
        }
Ejemplo n.º 6
0
        public static MatroskaTags Clone(MatroskaTags baseTag)
        {
            if (!ReferenceEquals(baseTag, null))
            {
                string xmlString = GetXML(baseTag);
                return(ReadTagFromXML(xmlString));
            }

            return(new MatroskaTags());
        }
Ejemplo n.º 7
0
        public static void WriteTagToXML(MatroskaTags tags, string xmlFile)
        {
            XmlSerializerNamespaces noNamespaces = new XmlSerializerNamespaces();

            noNamespaces.Add(string.Empty, string.Empty);

            XmlSerializer serializer = new XmlSerializer(typeof(MatroskaTags));
            TextWriter    textWriter = new StreamWriter(xmlFile);

            serializer.Serialize(textWriter, tags, noNamespaces);
            textWriter.Close();
        }
Ejemplo n.º 8
0
        public static int WriteTagToMatroska(string matroskaFile, MatroskaTags tags)
        {
            int    exitCode;
            string tempFile = Path.GetTempFileName();

            WriteTagToXML(tags, tempFile);
            exitCode = WriteTagToMatroska(matroskaFile, tempFile);

            File.Delete(tempFile);

            return(exitCode);
        }
Ejemplo n.º 9
0
        public static string GetXML(MatroskaTags tags)
        {
            using (StringWriter textWriter = new StringWriter())
              {
            XmlSerializerNamespaces noNamespaces = new XmlSerializerNamespaces();
            noNamespaces.Add(string.Empty, string.Empty);

            XmlSerializer serializer = new XmlSerializer(typeof(MatroskaTags));
            serializer.Serialize(textWriter, tags, noNamespaces);
            textWriter.Close();
            return textWriter.ToString();
              }
        }
Ejemplo n.º 10
0
        public static string GetXML(MatroskaTags tags)
        {
            using (StringWriter textWriter = new StringWriter())
            {
                XmlSerializerNamespaces noNamespaces = new XmlSerializerNamespaces();
                noNamespaces.Add(string.Empty, string.Empty);

                XmlSerializer serializer = new XmlSerializer(typeof(MatroskaTags));
                serializer.Serialize(textWriter, tags, noNamespaces);
                textWriter.Close();
                return(textWriter.ToString());
            }
        }
Ejemplo n.º 11
0
        public static void WriteTagToXML(MatroskaTags tags, string xmlFile)
        {
            XmlSerializerNamespaces noNamespaces = new XmlSerializerNamespaces();
              noNamespaces.Add(string.Empty, string.Empty);

              XmlSerializer serializer = new XmlSerializer(typeof(MatroskaTags));
              TextWriter textWriter = new StreamWriter(xmlFile);
              serializer.Serialize(textWriter, tags, noNamespaces);
              textWriter.Close();
        }
Ejemplo n.º 12
0
        public static int WriteTagToMatroska(string matroskaFile, MatroskaTags tags)
        {
            int exitCode;
              string tempFile = Path.GetTempFileName();

              WriteTagToXML(tags, tempFile);
              exitCode = WriteTagToMatroska(matroskaFile, tempFile);

              File.Delete(tempFile);

              return exitCode;
        }
Ejemplo n.º 13
0
        public static void WriteTags(MatroskaTags tags, string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            throw new ArgumentNullException("fileName");

              //if (tagCache.ContainsKey(fileName))
              //  return tagCache[fileName];

              string extension = Path.GetExtension(fileName);
              if (extension == null)
            throw new FileFormatException("File was not identified as XML or Matroska-file.");

              if (extension.ToLower().Equals(".xml"))
              {
            // XML file
            WriteTagToXML(tags, fileName);
              }
              else if (MatroskaExtensions.Contains(extension.ToLower()))
              {
            // Matroska file
            WriteTagToMatroska(fileName, tags);
              }
              else
              {
            // Invalid file
            //throw new FileFormatException("File was not identified as XML or Matroska-file.");
            fileName = Path.ChangeExtension(fileName, ".xml");
            WriteTagToXML(tags,fileName);
              }
        }
Ejemplo n.º 14
0
 public SeriesTag(MatroskaTags tags)
 {
     _matroskaTags = tags;
 }
Ejemplo n.º 15
0
 public MusicVideoTag(MatroskaTags tags)
 {
     _matroskaTags = tags;
 }
Ejemplo n.º 16
0
 public SeriesTag(MatroskaTags tags)
 {
     _matroskaTags = tags;
 }
        private void UpdatePreview(object sender, TextChangedEventArgs e)
        {
            textEditorNew.Text = string.Empty;

              MatroskaTags tag;
              if (!ReferenceEquals(originalTag, null))
              {
            string xmlString = MatroskaLoader.GetXML(originalTag);
            tag = MatroskaLoader.ReadTagFromXML(xmlString);
              }
              else
            tag = new MatroskaTags();

              #region Album

              if (!string.IsNullOrEmpty(albumArtist.Value))
            tag.MusicVideo.AlbumArtist = albumArtist.Value;

              if (!string.IsNullOrEmpty(albumTitle.Value))
            tag.MusicVideo.AlbumTitle = albumTitle.Value;

              if (!string.IsNullOrEmpty(albumReleaseDate.Value))
            tag.MusicVideo.AlbumReleaseDate = albumReleaseDate.Value;

              //if (albumReleaseDate.Value.HasValue)
              //{
              //  tag.MusicVideo.AlbumReleaseDate = albumReleaseDate.Value.Value;
              //}

              #endregion Album

              #region Track

              if (!string.IsNullOrEmpty(trackArtist.Value))
            tag.MusicVideo.TrackArtist = trackArtist.Value;

              if (!string.IsNullOrEmpty(trackTitle.Value))
            tag.MusicVideo.TrackTitle = trackTitle.Value;

              if (!string.IsNullOrEmpty(trackNumber.Value))
              {
            int index;
            if (int.TryParse(trackNumber.Value, out index))
              tag.MusicVideo.TrackNumber = index;
              }

              if (!string.IsNullOrEmpty(trackReleaseDate.Value))
            tag.MusicVideo.TrackReleaseDate = trackReleaseDate.Value;

              if (trackGenre.Value.Count > 0)
            tag.MusicVideo.GenreList = trackGenre.Value;

              #endregion Track

              textEditorNew.Text = MatroskaLoader.GetXML(tag);
              saveButton.IsEnabled = true;
        }
Ejemplo n.º 18
0
        internal static bool TryExtractTagFromMatroska(string matroskaFile, out MatroskaTags tags)
        {
            tags = ReadTagFromMatroska(matroskaFile);

            return(!ReferenceEquals(tags, null));
        }
Ejemplo n.º 19
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();
        }
        private void UpdateGUI(MatroskaTags tags)
        {
            #region Album

              if (!ReferenceEquals(tags.MusicVideo.AlbumArtist, null))
            albumArtist.Value = tags.MusicVideo.AlbumArtist;

              if (!ReferenceEquals(tags.MusicVideo.AlbumTitle, null))
            albumTitle.Value = tags.MusicVideo.AlbumTitle;

              //if (!ReferenceEquals(tags.MusicVideo.AlbumReleaseDate, null))
              //  albumReleaseDate.Value = tags.MusicVideo.AlbumReleaseDate.Value;

              if (!ReferenceEquals(tags.MusicVideo.AlbumReleaseDate, null))
            albumReleaseDate.Value = tags.MusicVideo.AlbumReleaseDate;

              #endregion Album

              #region Track

              if (!ReferenceEquals(tags.MusicVideo.TrackArtist, null))
            trackArtist.Value = tags.MusicVideo.TrackArtist;

              if (!ReferenceEquals(tags.MusicVideo.TrackTitle, null))
            trackTitle.Value = tags.MusicVideo.TrackTitle;

              if (!ReferenceEquals(tags.MusicVideo.TrackReleaseDate, null))
            trackReleaseDate.Value = tags.MusicVideo.TrackReleaseDate;

              trackGenre.Value = tags.MusicVideo.GenreList;

              #endregion Track
        }
Ejemplo n.º 21
0
        internal static bool TryExtractTagFromMatroska(string matroskaFile, out MatroskaTags tags)
        {
            tags = ReadTagFromMatroska(matroskaFile);

              return !ReferenceEquals(tags, null);
        }
Ejemplo n.º 22
0
 public MusicVideoTag(MatroskaTags tags)
 {
     _matroskaTags = tags;
 }
Ejemplo n.º 23
0
 public MovieTag(MatroskaTags tags)
 {
     _matroskaTags = tags;
 }
Ejemplo n.º 24
0
 public MovieTag(MatroskaTags tags)
 {
   _matroskaTags = tags;
 }
Ejemplo n.º 25
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();
        }