示例#1
0
    public static MatroskaTagInfo Fetch(string filename)
    {
      MatroskaTagInfo info = new MatroskaTagInfo();
      try
      {
        if (!File.Exists(filename))
        {
          return null;
        }

        XmlDocument doc = new XmlDocument();
        doc.Load(filename);
        XmlNodeList simpleTags = doc.SelectNodes("/tags/tag/SimpleTag");
        foreach (XmlNode simpleTag in simpleTags)
        {
          string tagName = simpleTag.ChildNodes[0].InnerText;
          switch (tagName)
          {
            case "TITLE":
              info.Title = simpleTag.ChildNodes[1].InnerText;
              break;
            case "COMMENT":
              info.Description = simpleTag.ChildNodes[1].InnerText;
              break;
            case "GENRE":
              info.Genre = simpleTag.ChildNodes[1].InnerText;
              break;
            case "CHANNEL_NAME":
              info.ChannelName = simpleTag.ChildNodes[1].InnerText;
              break;
            case "EPISODE_NAME":
              info.EpisodeName = simpleTag.ChildNodes[1].InnerText;
              break;
            case "START_TIME":
              info.StartTime = new DateTime(long.Parse(simpleTag.ChildNodes[1].InnerText));
              break;
            case "END_TIME":
              info.EndTime = new DateTime(long.Parse(simpleTag.ChildNodes[1].InnerText));
              break;
          }
        }
      }
      catch (Exception) { } // loading the XML doc could fail
      return info;
    }
示例#2
0
    public static void Persist(string filename, MatroskaTagInfo taginfo)
    {
      try
      {
        if (!Directory.Exists(Path.GetDirectoryName(filename)))
        {
          Directory.CreateDirectory(Path.GetDirectoryName(filename));
        }

        XmlDocument doc = new XmlDocument();
        XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
        XmlNode tagsNode = doc.CreateElement("tags");
        XmlNode tagNode = doc.CreateElement("tag");
        tagNode.AppendChild(AddSimpleTag("TITLE", taginfo.Title, doc));
        tagNode.AppendChild(AddSimpleTag("COMMENT", taginfo.Description, doc));
        tagNode.AppendChild(AddSimpleTag("GENRE", taginfo.Genre, doc));
        tagNode.AppendChild(AddSimpleTag("CHANNEL_NAME", taginfo.ChannelName, doc));
        tagNode.AppendChild(AddSimpleTag("EPISODE_NAME", taginfo.EpisodeName, doc));
        tagNode.AppendChild(AddSimpleTag("START_TIME", taginfo.StartTime.Ticks.ToString(), doc));
        tagNode.AppendChild(AddSimpleTag("END_TIME", taginfo.EndTime.Ticks.ToString(), doc));
        tagsNode.AppendChild(tagNode);
        doc.AppendChild(tagsNode);
        doc.InsertBefore(xmldecl, tagsNode);
        doc.Save(filename);
      }
      catch (Exception) { }
    }