Zugriff auf Metadaten von Dvr-MS Dateien

  • VB6

Es gibt 7 Antworten in diesem Thema. Der letzte Beitrag () ist von Mad Andy.

    Zugriff auf Metadaten von Dvr-MS Dateien

    ich habe gesucht und gesucht, aber leider noch nicht einmal einen
    Lösungsansatz zu meinem Problem gefunden.
    Zu allem überfluss bin ich auch noch ein relativer Neuling... :)

    Vielleicht kann mir ja einer von Euch helfen.


    Ich würde gerne die Metadaten einer DVR-MS Datei auslesen und in
    entsprechende Variablen (zur weiterverarbeitung) speichern.


    Hat einer von Euch eine Idee, wie man das bewerkstelligen kann?

    (Ich nutze VB 2005)

    Grüße
    Dominic
    Hi,

    sorry, also:

    DVR-MS Dateien sind MPEG2-Dateien, die in einer "Microsofthülle" gefangen sind. Sinn und zweck ist es, zu der MPEG2 Datei auch noch erweiterte Daten zu sichern (z.B. Fernsehsender, Genre, Titel etc.). Das DVR-MS Format wird u.a. von MEdiaportal und dem WIndows Mediacenter genutzt, bzw. insbesondere diese Anwendungen erstellen DVR-MS Dateien.

    Hilft Dir das erst mal weiter? :)
    Ich hab gegoogelt und gegoogelt, aber nichts anständiges gefunden (kann aber auch an meinem mäßigen Englisch liegen :( ).

    Grüße
    Dominic
    Hi,
    hab ein C# Programm von Stephen Toub gefunden.

    Leider verstehe ich den SourceCode nicht wirklich.

    Vielleicht kannst Du mir ja helfen:

    Quellcode

    1. // Stephen Toub
    2. // [EMAIL]stoub@microsoft.com[/EMAIL]
    3. using System;
    4. using System.IO;
    5. using System.Data;
    6. using System.Text;
    7. using System.Collections;
    8. using System.Runtime.InteropServices;
    9. using Toub.MediaCenter.Dvrms.Conversion;
    10. namespace Toub.MediaCenter.Dvrms.Metadata
    11. {
    12. /// <summary>The type of a metadata attribute value.</summary>
    13. public enum MetadataItemType
    14. {
    15. /// <summary>DWORD</summary>
    16. Dword = 0,
    17. /// <summary>String</summary>
    18. String = 1,
    19. /// <summary>Binary</summary>
    20. Binary = 2,
    21. /// <summary>Boolean</summary>
    22. Boolean = 3,
    23. /// <summary>QWORD</summary>
    24. Qword = 4,
    25. /// <summary>WORD</summary>
    26. Word = 5,
    27. /// <summary>Guid</summary>
    28. Guid = 6,
    29. }
    30. /// <summary>Represents a metadata attribute.</summary>
    31. public class MetadataItem : ICloneable
    32. {
    33. /// <summary>The name of the attribute.</summary>
    34. private string _name;
    35. /// <summary>The value of the attribute.</summary>
    36. private object _value;
    37. /// <summary>The type of the attribute value.</summary>
    38. private MetadataItemType _type;
    39. /// <summary>Initializes the metadata item.</summary>
    40. /// <param name="name">The name of the attribute.</param>
    41. /// <param name="value">The value of the attribute.</param>
    42. /// <param name="type">The type of the attribute value.</param>
    43. internal MetadataItem(string name, object value, MetadataItemType type)
    44. {
    45. Name = name;
    46. Value = value;
    47. Type = type;
    48. }
    49. /// <summary>Gets or sets the name of the attribute.</summary>
    50. public string Name { get { return _name; } set { _name = value; } }
    51. /// <summary>Gets or sets the value of the attribute.</summary>
    52. public object Value { get { return _value; } set { _value = value; } }
    53. /// <summary>Gets or sets the type of the attribute value.</summary>
    54. public MetadataItemType Type { get { return _type; } set { _type = value; } }
    55. /// <summary>Clones the attribute item.</summary>
    56. /// <returns>A shallow copy of the attribute.</returns>
    57. public MetadataItem Clone() { return (MetadataItem)MemberwiseClone(); }
    58. /// <summary>Clones the attribute item.</summary>
    59. /// <returns>A shallow copy of the attribute.</returns>
    60. object ICloneable.Clone() { return Clone(); }
    61. }
    62. /// <summary>Metadata editor for ASF files, including WMA, WMV, and DVR-MS files.</summary>
    63. public abstract class MetadataEditor : IDisposable
    64. {
    65. /// <summary>The Title attribute contains the title of the content in the file.</summary>
    66. public const string Title = "Title";
    67. /// <summary>The WM/SubTitle attribute contains the subtitle of the content.</summary>
    68. public const string Subtitle = "WM/SubTitle";
    69. /// <summary>The Description attribute contains a description of the content of the file.</summary>
    70. public const string Description = "Description";
    71. /// <summary>The WM/SubTitleDescription attribute contains a description of the content of the file.</summary>
    72. public const string SubtitleDescription = "WM/SubTitleDescription";
    73. /// <summary>The WM/MediaCredits attribute contains a list of those involved in the production of the content of the file.</summary>
    74. public const string Credits = "WM/MediaCredits";
    75. /// <summary>The Author attribute contains the name of a media artist or actor associated with the content.</summary>
    76. public const string Author = "Author";
    77. /// <summary>The WM/AlbumArtist attribute contains the name of the primary artist for the album.</summary>
    78. public const string AlbumArtist = "WM/AlbumArtist";
    79. /// <summary>The WM/AlbumTitle attribute contains the title of the album on which the content was originally released.</summary>
    80. public const string AlbumTitle = "WM/AlbumTitle";
    81. /// <summary>The WM/MediaStationName attribute contains the title of the station that aired the content was originally released.</summary>
    82. public const string StationName = "WM/MediaStationName";
    83. /// <summary>The WM/Composer attribute contains the name of the music composer.</summary>
    84. public const string Composer = "WM/Composer";
    85. /// <summary>The WM/ParentalRating attribute contains the parental rating of the content.</summary>
    86. public const string ParentalRating = "WM/ParentalRating";
    87. /// <summary>The WM/ParentalRating attribute contains the reason for the parental rating of the content.</summary>
    88. public const string ParentalRatingReason = "WM/ParentalRatingReason";
    89. /// <summary>The WM/MediaOriginalBroadcastDateTime attribute contains the original broadcast date and time of the content.</summary>
    90. public const string MediaOriginalBroadcastDateTime = "WM/MediaOriginalBroadcastDateTime";
    91. /// <summary>The WM/Mood attribute contains a category name for the mood of the content.</summary>
    92. public const string Mood = "WM/Mood";
    93. /// <summary>The WM/Genre attribute contains the genre of the content.</summary>
    94. public const string Genre = "WM/Genre";
    95. /// <summary>The WM/Language attribute contains the language of the stream.</summary>
    96. public const string Language = "WM/Language";
    97. /// <summary>The WM/Lyrics attribute contains the lyrics as a simple string.</summary>
    98. public const string Lyrics = "WM/Lyrics";
    99. /// <summary>The WM/Lyrics_Synchronised attribute contains lyrics synchronized to times in the file.</summary>
    100. public const string SynchronizedLyrics = "WM/Lyrics_Synchronised";
    101. /// <summary>The Duration attribute contains the length of the file in hundreds of nanoseconds.</summary>
    102. public const string Duration = "Duration";
    103. /// <summary>The WM/ContentGroupDescription attribute contains a content group description.</summary>
    104. public const string ContentGroupDescription = "WM/ContentGroupDescription";
    105. /// <summary>The WM/PartOfSet attribute contains the set grouping for this content.</summary>
    106. public const string PartOfSet = "WM/PartOfSet";
    107. /// <summary>Initialize the editor.</summary>
    108. protected MetadataEditor() {}
    109. /// <summary>Releases all of the resources for the editor.</summary>
    110. void IDisposable.Dispose()
    111. {
    112. Dispose(true);
    113. GC.SuppressFinalize(this);
    114. }
    115. /// <summary>Releases all of the resources for the editor.</summary>
    116. /// <param name="disposing">Whether the object is currently being disposed (rather than finalized).</param>
    117. protected virtual void Dispose(bool disposing)
    118. {
    119. }
    120. /// <summary>Releases all of the resources for the editor.</summary>
    121. ~MetadataEditor() { Dispose(false); }
    122. /// <summary>Retrieves the string value of a metadata item.</summary>
    123. /// <param name="items">The collection of metadata items containing the item to be retrieved.</param>
    124. /// <param name="name">The name of the attribute value to be retrieved.</param>
    125. /// <returns>The attribute value as a string.</returns>
    126. public static string GetMetadataItemAsString(IDictionary items, string name)
    127. {
    128. MetadataItem item = (MetadataItem)items[name];
    129. if (item == null || item.Value == null) return string.Empty;
    130. return item.Value.ToString().Trim();
    131. }
    132. /// <summary>Sets the value of a string attribute.</summary>
    133. /// <param name="items">The metadata items collection.</param>
    134. /// <param name="name">The name of the attribute.</param>
    135. /// <param name="value">The new value of the attribute.</param>
    136. public static void SetMetadataItemAsString(IDictionary items, string name, string value)
    137. {
    138. items[name] = new MetadataItem(name, value, MetadataItemType.String);
    139. }
    140. /// <summary>Copies a metadata item from one collection under one name to another collection under another name.</summary>
    141. /// <param name="source">The source collection.</param>
    142. /// <param name="sourceName">The source name.</param>
    143. /// <param name="destination">The destination collection.</param>
    144. /// <param name="destinationName">The destination name.</param>
    145. private static void CopyMetadataItem(IDictionary source, string sourceName, IDictionary destination, string destinationName)
    146. {
    147. // Gets the source item
    148. MetadataItem item = (MetadataItem)source[sourceName];
    149. // Clone the item and copy it to the destination
    150. if (item != null)
    151. {
    152. item = item.Clone();
    153. item.Name = destinationName;
    154. destination[destinationName] = item;
    155. }
    156. }
    157. /// <summary>Migrate the metadata from one file to another.</summary>
    158. /// <param name="source">The source editor.></param>
    159. /// <param name="destination">The destination editor.</param>
    160. /// <returns>The migrated collection.</returns>
    161. public static IDictionary MigrateMetadata(MetadataEditor source, MetadataEditor destination)
    162. {
    163. return MigrateMetadata(source, destination, false);
    164. }
    165. /// <summary>Migrate the metadata from one file to another.</summary>
    166. /// <param name="source">The source editor.></param>
    167. /// <param name="destination">The destination editor.</param>
    168. /// <param name="augmentMetadata">Whether to augment the metadata for WMP and MCE.</param>
    169. /// <returns>The migrated collection.</returns>
    170. public static IDictionary MigrateMetadata(MetadataEditor source, MetadataEditor destination, bool augmentMetadata)
    171. {
    172. IDictionary metadata = source.GetAttributes();
    173. // Augment the metadata to provide a better experience in both WMP and MCE
    174. if (augmentMetadata)
    175. {
    176. string title = GetMetadataItemAsString(metadata, MetadataEditor.Title);
    177. string subTitle = GetMetadataItemAsString(metadata, MetadataEditor.Subtitle);
    178. if (!title.EndsWith(subTitle))
    179. {
    180. title += (title.Length > 0 && subTitle.Length > 0 ? " - " : string.Empty) + subTitle;
    181. }
    182. SetMetadataItemAsString(metadata, MetadataEditor.Title, title);
    183. CopyMetadataItem(metadata, MetadataEditor.SubtitleDescription, metadata, MetadataEditor.Description);
    184. CopyMetadataItem(metadata, MetadataEditor.Credits, metadata, MetadataEditor.Author);
    185. CopyMetadataItem(metadata, MetadataEditor.Title, metadata, MetadataEditor.AlbumTitle);
    186. CopyMetadataItem(metadata, MetadataEditor.StationName, metadata, MetadataEditor.Composer);
    187. CopyMetadataItem(metadata, MetadataEditor.ParentalRating, metadata, MetadataEditor.ContentGroupDescription);
    188. CopyMetadataItem(metadata, MetadataEditor.MediaOriginalBroadcastDateTime, metadata, MetadataEditor.PartOfSet);
    189. CopyMetadataItem(metadata, MetadataEditor.ParentalRating, metadata, MetadataEditor.Mood);
    190. }
    191. // Set the metadata onto the destination file
    192. destination.SetAttributes(metadata);
    193. return metadata;
    194. }
    195. /// <summary>Converts a value to the target type and gets its byte representation.</summary>
    196. /// <param name="item">The item whose value is to be translated.</param>
    197. /// <param name="valueData">The output byte array.</param>
    198. protected static bool TranslateAttributeToByteArray(MetadataItem item, out byte [] valueData)
    199. {
    200. int valueLength;
    201. switch(item.Type)
    202. {
    203. case MetadataItemType.Dword:
    204. valueData = BitConverter.GetBytes((int)item.Value);
    205. return true;
    206. case MetadataItemType.Word:
    207. valueData = BitConverter.GetBytes((short)item.Value);
    208. return true;
    209. case MetadataItemType.Qword:
    210. valueData = BitConverter.GetBytes((long)item.Value);
    211. return true;
    212. case MetadataItemType.Boolean:
    213. valueData = BitConverter.GetBytes(((bool)item.Value) ? 1 : 0 );
    214. return true;
    215. case MetadataItemType.String:
    216. string strValue = item.Value.ToString();
    217. valueLength = (strValue.Length + 1) * 2; // plus 1 for null-term, times 2 for unicode
    218. valueData = new byte[valueLength];
    219. Buffer.BlockCopy(strValue.ToCharArray(), 0, valueData, 0, strValue.Length * 2);
    220. valueData[valueLength - 2] = 0;
    221. valueData[valueLength - 1] = 0;
    222. return true;
    223. default:
    224. valueData = null;
    225. return false;
    226. }
    227. }
    228. /// <summary>Sets the collection of string attributes onto the specified file and stream.</summary>
    229. /// <param name="propsToSet">The properties to set on the file.</param>
    230. public abstract void SetAttributes(IDictionary propsToSet);
    231. /// <summary>Gets the value of the specified attribute.</summary>
    232. /// <param name="itemType">The type of the attribute.</param>
    233. /// <param name="valueData">The byte array to be parsed.</param>
    234. protected static object ParseAttributeValue(MetadataItemType itemType, byte[] valueData)
    235. {
    236. if (!Enum.IsDefined(typeof(MetadataItemType), itemType))
    237. throw new ArgumentOutOfRangeException("itemType");
    238. if (valueData == null) throw new ArgumentNullException("valueData");
    239. // Convert the attribute value to a byte array based on the item type.
    240. switch(itemType)
    241. {
    242. case MetadataItemType.String:
    243. StringBuilder sb = new StringBuilder(valueData.Length);
    244. for (int i = 0; i < valueData.Length - 2; i += 2)
    245. {
    246. sb.Append(Convert.ToString(BitConverter.ToChar(valueData, i)));
    247. }
    248. string result = sb.ToString();
    249. if (result.EndsWith("\\0")) result = result.Substring(0, result.Length-2);
    250. return result;
    251. case MetadataItemType.Boolean: return BitConverter.ToBoolean(valueData, 0);
    252. case MetadataItemType.Dword: return BitConverter.ToInt32(valueData, 0);
    253. case MetadataItemType.Qword: return BitConverter.ToInt64(valueData, 0);
    254. case MetadataItemType.Word: return BitConverter.ToInt16(valueData, 0);
    255. case MetadataItemType.Guid: return new Guid(valueData);
    256. case MetadataItemType.Binary: return valueData;
    257. default: throw new ArgumentOutOfRangeException("itemType");
    258. }
    259. }
    260. /// <summary>Gets all of the attributes on a file.</summary>
    261. /// <returns>A collection of the attributes from the file.</returns>
    262. public abstract IDictionary GetAttributes();
    263. }
    264. }