Giter VIP home page Giter VIP logo

flaclibsharp's Introduction

Linux (.NET Core) Windows
Linux Build Status Windows Build Status

FlacLibSharp

A .NET library for reading and writing FLAC metadata.

Installation

PM> Install-Package FlacLibSharp

Or go to the nuget page: https://www.nuget.org/packages/FlacLibSharp

Platform support:

  • .NET Standard 1.3

Warning

If you use this for anything important, make sure your files are backed up. Since this was a hobby project I cannot guarantee anything in terms of quality.

Please evaluate carefully and report any issues you find here on GitHub.

Usage example

Reading Metadata

// Access to the StreamInfo class
using (FlacFile file = new FlacFile(@"Data\testfile1.flac"))
{
    Console.WriteLine("Flac audio length in seconds: {0}", file.StreamInfo.Duration);
}

// Access to the VorbisComment IF it exists in the file
using (FlacFile file = new FlacFile(@"Data\testfile1.flac"))
{
    var vorbisComment = file.VorbisComment;
    if (vorbisComment != null)
    {
        Console.WriteLine("Artist - Title: {0} - {1}", vorbisComment.Artist, vorbisComment.Title);
    }
}

// Access to the VorbisComment with multiple values for a single field
using (FlacFile file = new FlacFile(@"Data\testfile1.flac"))
{
    var vorbisComment = file.VorbisComment;
    if (vorbisComment != null)
    {
        foreach (var value in vorbisComment.Artist)
        {
            Console.WriteLine("Artist: {0}", value);
        }
    }
}

// Iterate through all VorbisComment tags
using (FlacFile file = new FlacFile(@"Data\testfile1.flac"))
{
    var vorbisComment = file.VorbisComment;
    if (vorbisComment != null)
    {
        foreach (var tag in vorbisComment)
        {
            Console.WriteLine("{0}: {1}", tag.Key, tag.Value);
        }
    }
}

// Get all other types of metdata blocks
using (FlacFile file = new FlacFile(@"Data\testfile1.flac"))
{
    var metadata = file.Metadata;
    foreach (MetadataBlock block in metadata) { 
        Console.WriteLine("{0} metadata block.", block.Header.Type);
    }
}

Writing Metadata

Modify a vorbis comment, create a vorbis block if none exists:

using (FlacFile flac = new FlacFile("example.flac"))
{
    // First get the existing VorbisComment (if any)
    var comment = flac.VorbisComment;
    if (comment == null)
    {
        // Create a new vorbis comment metadata block
        comment = new VorbisComment();
        // Add it to the flac file
        flac.Metadata.Add(comment);
    }
    
    // Update the fields
    comment.Artist.Value = "Aaron";
    comment.Title.Value = "Hello World";

    // Write the changes back to the FLAC file
    flac.Save();
}

Check out the tests in the source code for more examples.

Build and Test with .NET Core

$ git clone https://github.com/AaronLenoir/flaclibsharp.git
$ cd flaclibsharp/FlacLibSharp.Test.Core
$ dotnet test

Build and Test with Visual Studio

  • Open the solution in Visual Studio
  • Go to "Test Explorer"
  • Click "Run all"

Build NuGet Package

  • Open the solution in Visual Studio
  • Build project "FlacLibSharp"
  • The NuGet package can be found in bin\Release

flaclibsharp's People

Contributors

aaronlenoir avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.