Skip to content

Commit

Permalink
+ Added Test for Matroska
Browse files Browse the repository at this point in the history
+ Added debug for Visual Studio
  • Loading branch information
Starwer committed Jul 5, 2017
1 parent df9babf commit ec8a4a0
Show file tree
Hide file tree
Showing 12 changed files with 362 additions and 15 deletions.
49 changes: 49 additions & 0 deletions debug/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.IO;

namespace debug
{
class Program
{
public static readonly string Samples = Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(Program)).Location) + @"\..\..\..\tests\samples\";

/// <summary>
/// Ouput message on the console and on the Visual Studio Output
/// </summary>
/// <param name="str"></param>
static void log(string str)
{
Console.WriteLine(str);
System.Diagnostics.Debug.WriteLine(str);
}


static void Main(string[] args)
{
log("--------------------");
log("* Start : Samples directory: " + Samples);
log("");

foreach (var fname in args) {
var fpath = Samples + fname;

log("+ File : " + fpath);
if(!File.Exists(fpath))
{
log(" # File not found: " + fpath);
continue;
}


var file = TagLib.File.Create(fpath);

log(" Title : " + file.Tag.Title);

log("");
}

log("* End");
}

}
}
36 changes: 36 additions & 0 deletions debug/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("debug")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("debug")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ad739881-60f3-4165-9c4e-3b5cd95469f1")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
65 changes: 65 additions & 0 deletions debug/debug.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AD739881-60F3-4165-9C4E-3B5CD95469F1}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>debug</RootNamespace>
<AssemblyName>debug</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\taglib-sharp.csproj">
<Project>{6b143a39-c7b2-4743-9917-92262c60e9a6}</Project>
<Name>taglib-sharp</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
6 changes: 6 additions & 0 deletions debug/debug.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartArguments>"Turning Lime.mkv" "Alice Au Pays Des Merveilles.mkv"</StartArguments>
</PropertyGroup>
</Project>
80 changes: 80 additions & 0 deletions src/TagLib/Matroska/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//
// Author:
// Julien Moutte <julien@fluendo.com>
// Sebastien Mouy <starwer@laposte.net>
//
// Copyright (C) 2011 FLUENDO S.A.
//
Expand All @@ -23,6 +24,7 @@

using System.Collections.Generic;
using System;
using System.Linq;

namespace TagLib.Matroska
{
Expand Down Expand Up @@ -384,6 +386,9 @@ private void ReadSegment (EBMLElement element)
case MatroskaID.MatroskaTags:
ReadTags (child);
break;
case MatroskaID.MatroskaAttachments:
ReadAttachments(child);
break;
case MatroskaID.MatroskaCluster:
// Get out of here when we reach the clusters for now.
return;
Expand Down Expand Up @@ -416,6 +421,7 @@ private void ReadTags (EBMLElement element)
}
}


private void ReadTag (EBMLElement element)
{
ulong i = 0;
Expand Down Expand Up @@ -480,6 +486,80 @@ private void ReadSimpleTag (EBMLElement element)
}
}

private void ReadAttachments(EBMLElement element)
{
ulong i = 0;

while (i < element.DataSize)
{
EBMLElement child = new EBMLElement(this, element.DataOffset + i);

MatroskaID matroska_id = (MatroskaID)child.ID;

switch (matroska_id)
{
case MatroskaID.MatroskaAttachedFile:
ReadAttachedFile(child);
break;
default:
break;
}

i += child.Size;
}
}

private void ReadAttachedFile(EBMLElement element)
{
ulong i = 0;
#pragma warning disable 219 // Assigned, never read
string file_name = null, file_mime = null, file_desc = null;
ByteVector file_data = null;
#pragma warning restore 219

while (i < element.DataSize)
{
EBMLElement child = new EBMLElement(this, element.DataOffset + i);

MatroskaID matroska_id = (MatroskaID)child.ID;

switch (matroska_id)
{
case MatroskaID.MatroskaFileName:
file_name = child.ReadString();
break;
case MatroskaID.MatroskaFileMimeType:
file_mime = child.ReadString();
break;
case MatroskaID.MatroskaFileDescription:
file_desc = child.ReadString();
break;
case MatroskaID.MatroskaFileData:
file_data = child.ReadBytes();
break;
default:
break;
}

i += child.Size;
}

if (file_mime != null && file_name!=null && file_data!=null && file_mime.StartsWith("image/"))
{
List<IPicture> pictures = tag.Pictures.ToList();

var pic = new Picture(file_data);
pic.Description = file_name;
pic.MimeType = file_mime;
//pic.Description = file_desc;
pic.Type = PictureType.FrontCover;

pictures.Add(pic);
tag.Pictures = pictures.ToArray();
}

}

private void ReadSegmentInfo (EBMLElement element)
{
ulong i = 0;
Expand Down
34 changes: 33 additions & 1 deletion src/TagLib/Matroska/MatroskaIDs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,39 @@ public enum MatroskaID
/// <summary>
/// Indicate a Matroska Tag Binary EBML element.
/// </summary>
MatroskaTagBinary = 0x4485
MatroskaTagBinary = 0x4485,

/* in the Attachments master */

/// <summary>
/// Indicate a Matroska attached file.
/// </summary>
MatroskaAttachedFile = 0x61A7,

/// <summary>
/// Indicate a Matroska human-friendly name for the attached file.
/// </summary>
MatroskaFileDescription = 0x467E,

/// <summary>
/// Indicate a Matroska Filename of the attached file.
/// </summary>
MatroskaFileName = 0x466E,

/// <summary>
/// Indicate a Matroska MIME type of the file.
/// </summary>
MatroskaFileMimeType = 0x4660,

/// <summary>
/// Indicate a Matroska data of the file.
/// </summary>
MatroskaFileData = 0x465C,

/// <summary>
/// Indicate a Matroska Unique ID representing the file, as random as possible.
/// </summary>
MatroskaFileUID = 0x46AE

}
}
19 changes: 14 additions & 5 deletions src/TagLib/Matroska/Tag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class Tag : TagLib.Tag
private string comments;
private string genres;
private string copyright;
private IPicture[] pictures = new Picture[0];

#endregion

Expand Down Expand Up @@ -644,12 +645,20 @@ public override IPicture [] Pictures
{
get
{
List<IPicture> l = new List<IPicture> ();


return l.ToArray ();
return pictures;
}
set
{
if (value==null && pictures.Length>0)
{
pictures = new Picture[0];
}
else
{
pictures = value;
}

}
set { }
}

/// <summary>
Expand Down
Loading

0 comments on commit ec8a4a0

Please sign in to comment.