Start a new topic

Export tracks / albums with option to embed covers

Important: The two scripts use a library of free code to insert the covers in the archives. The taglib-sharp library must be stored in the directory Helium (C: \ Program Files (x86) \ Helium). You have to unlock the file from the properties (see indications at the end).


Export albums

Description: Export albums to a directory chosen by user. Create the directory structure Artist / Album. Save the cover image in the directory, and you can choose to embed the covers.


//css_reference taglib-sharp.dll;

using System;

using NeonScripting;

using System.Collections;

using System.Collections.Generic;

using System.IO;

using System.Text;

using System.Linq;

namespace Neon

{

    public class Script

    {

        public bool Run(INeonScriptHost host)

        {

           

   var auxAlbum = "";

   var pathCover = "";

   var preIdx = host.Tracks.Count();

     

   if (preIdx == 0)

   {

    host.RemoteCalls.ShowMessage("You have not selected any item.");

     return false;

   }

   else

   {

    ///warns if you have selected more than 5 items

                if (preIdx >= 6)

     if (!host.RemoteCalls.ConfirmationDialog("Do you want to export "+preIdx+" items?"))

      return false;

     

    //you can decide about covers

    var contents = new List<string>{

     "Only Albums",

     "Albums with file cover in directory",

     "Albums with file cover and embedded covers"

    };

    var cover = host.RemoteCalls.SelectItemFromList(contents, 0);

         

    if (string.IsNullOrEmpty(cover))

     return false;

    var outputFolder = host.RemoteCalls.SelectFolder();

    if (outputFolder == "")

     return false;

    var idx = 1;

    foreach(var track in host.Tracks)

    {

     var fileSource = Path.Combine(track.Path, track.Filename);

     var pathArtist = "";

     var strArtist = track.Artist;

     host.UpdateProgress(string.Format("Track: {0}", idx));

           

     //check illegal characters in Artist name

     if (track.Artist.IndexOf("/", StringComparison.OrdinalIgnoreCase) >= 0)

      strArtist = track.Artist.Replace("/", "_");

     if (track.Artist.IndexOf(":", StringComparison.OrdinalIgnoreCase) >= 0)

      strArtist = track.Artist.Replace(":", "_");

     if (track.Artist.IndexOf("*", StringComparison.OrdinalIgnoreCase) >= 0)

      strArtist = track.Artist.Replace("*", "");

     if (track.Artist.IndexOf("¿", StringComparison.OrdinalIgnoreCase) >= 0)

      strArtist = track.Artist.Replace("¿", "");

     if (track.Artist.IndexOf("?", StringComparison.OrdinalIgnoreCase) >= 0)

      strArtist = track.Artist.Replace("?", "");

     

     //change articles in Artist name

     bool auxThe = strArtist.StartsWith("The ");

     if (auxThe)

     {

      string auxStrThe = strArtist.Remove(0,4);

      pathArtist = Path.Combine(outputFolder, auxStrThe+", The");

     }

     else

     {

      bool auxEl = strArtist.StartsWith("El ");

      if (auxEl)

      {

       string auxStrEl = strArtist.Remove(0,3);

       pathArtist = Path.Combine(outputFolder, auxStrEl+", El");

      }

      else

      {

       bool auxLos = strArtist.StartsWith("Los ");

       if (auxLos)

       {

        string auxStrLos = strArtist.Remove(0,4);

        pathArtist = Path.Combine(outputFolder, auxStrLos+", Los");

       }

       else

       {

        bool auxLa = strArtist.StartsWith("La ");

        if (auxLa)

        {

         string auxStrLa = strArtist.Remove(0,3);

         pathArtist = Path.Combine(outputFolder, auxStrLa+", La");

        }

        else

        {

         bool auxLas = strArtist.StartsWith("Las ");

         if (auxLas)

         {

          string auxStrLas = strArtist.Remove(0,4);

          pathArtist = Path.Combine(outputFolder, auxStrLas+", Las");

         }

         else

          pathArtist = Path.Combine(outputFolder, strArtist);

        }

       }

      }

     }

           

     //create artist dir

     if (!Directory.Exists(pathArtist))

      Directory.CreateDirectory(pathArtist);

     

     var strAlbum = track.Album;

     //check illegal characters in Album name

     if (track.Album.IndexOf("/", StringComparison.OrdinalIgnoreCase) >= 0)

      strAlbum = track.Album.Replace("/", "_");

     if (track.Album.IndexOf(":", StringComparison.OrdinalIgnoreCase) >= 0)

      strAlbum = track.Album.Replace(":", "_");

     if (track.Album.IndexOf("*", StringComparison.OrdinalIgnoreCase) >= 0)

      strAlbum = track.Album.Replace("*", "");

     if (track.Album.IndexOf("¿", StringComparison.OrdinalIgnoreCase) >= 0)

      strAlbum = track.Album.Replace("¿", "");

     if (track.Album.IndexOf("?", StringComparison.OrdinalIgnoreCase) >= 0)

      strAlbum = track.Album.Replace("?", "");

     

     var pathAlbum = Path.Combine(pathArtist, strAlbum);

     

     //create album dir

     if (!Directory.Exists(pathAlbum))

      Directory.CreateDirectory(pathAlbum);

     

     //copy track

     var fileDestination = Path.Combine(pathAlbum, track.Filename);

     File.Copy(fileSource, fileDestination);

   

     if (cover=="Albums with file cover in directory" || cover=="Albums with file cover and embedded covers")

     {

      ////locates and copy the cover

      if (auxAlbum != track.Album)

      {

       foreach (var auxCover in Directory.GetFiles(track.Path, "*.*", SearchOption.AllDirectories))

       {

        var ext = Path.GetExtension(auxCover).ToLowerInvariant();

        if (ext == ".jpg" || ext == ".jpeg" || ext == ".png")

        {

         var fileCover = Path.GetFileName(auxCover);

         var coverDestination = pathAlbum+@"\"+fileCover;

         File.Copy(auxCover, coverDestination);

         pathCover = track.Path+@"\"+fileCover;

        }

       }

      auxAlbum=track.Album;

      }

     }

     

     if (cover=="Albums with file cover and embedded covers")

     {

      //define cover

      TagLib.File tagFile = TagLib.File.Create(fileDestination);

      TagLib.Id3v2.AttachedPictureFrame pic = new TagLib.Id3v2.AttachedPictureFrame();

      pic.TextEncoding = TagLib.StringType.Latin1;

      pic.MimeType = "image/jpeg";

      pic.Description  = track.Artist+" - "+track.Album;

      pic.Type = TagLib.PictureType.FrontCover;

      pic.Data = TagLib.ByteVector.FromPath(pathCover);

                                     

               //save cover to file

      tagFile.Tag.Pictures = new TagLib.IPicture[1] { pic };

      tagFile.Save();

     }

     

     idx++;

    }

   }

   

            return true;

        }

    }

}



Export tracks

Export tracks, with option to embed covers, to a directory chosen by user.


//css_reference taglib-sharp.dll;

using System;

using NeonScripting;

using System.Collections;

using System.Collections.Generic;

using System.IO;

using System.Text;

using System.Linq;

namespace Neon

{

 public class Script

 {

  public bool Run(INeonScriptHost host)

  {

   

   var auxAlbum = "";

   var pathCover = "";

   var preIdx = host.Tracks.Count();

   

   if (preIdx == 0)

   {

    host.RemoteCalls.ShowMessage("You have not selected any item.");

     return false;

   }

   else

   {

    ///warns if you have selected more than 5 items

    if (preIdx >= 6)

     if (!host.RemoteCalls.ConfirmationDialog("Do you want to export "+preIdx+" items?"))

      return false;

   

    //you can decide about covers

    var contents = new List<string>{

     "Only tracks",

     "Tracks and embedded covers"

    };

    var cover = host.RemoteCalls.SelectItemFromList(contents, 0);

         

    if (string.IsNullOrEmpty(cover))

     return false;

    var outputFolder = host.RemoteCalls.SelectFolder();

    if (outputFolder == "")

     return false;

    var idx = 1;

    foreach(var track in host.Tracks)

    {

     host.UpdateProgress(string.Format("Track: {0}", idx));

     var fileSource = Path.Combine(track.Path, track.Filename);

     var fileDestination = Path.Combine(outputFolder, track.Filename);

     File.Copy(fileSource, fileDestination);

     

     if (cover=="Tracks and embedded covers")

     {

      //locates the cover

      if (auxAlbum != track.Album)

      {

       foreach (var auxCover in Directory.GetFiles(track.Path, "*.*", SearchOption.AllDirectories))

       {

        var ext = Path.GetExtension(auxCover).ToLowerInvariant();

        if (ext == ".jpg" || ext == ".jpeg" || ext == ".png")

        {

         var fileCover = Path.GetFileName(auxCover);

         pathCover = track.Path+@"\"+fileCover;

        }

       }

       auxAlbum=track.Album;

      }

     

      //define cover

      TagLib.File tagFile = TagLib.File.Create(fileDestination);

      TagLib.Id3v2.AttachedPictureFrame pic = new TagLib.Id3v2.AttachedPictureFrame();

      pic.TextEncoding = TagLib.StringType.Latin1;

      pic.MimeType = "image/jpeg";

      pic.Description  = track.Artist+" - "+track.Album;

      pic.Type = TagLib.PictureType.FrontCover;

      pic.Data = TagLib.ByteVector.FromPath(pathCover);

                                     

               //save cover to file

      tagFile.Tag.Pictures = new TagLib.IPicture[1] { pic };

      tagFile.Save();

     }

     idx++;

    }

   }

   

   return true;

  }

 }

}



TagLib# (aka taglib-sharp) credits

Maintainer:  Gabriel Burt

Creator, past maintainer:  Brian Nickel

Source: http://github.com/mono/taglib-sharp


Unlock library:

Resultado de imagen

dll
json
(274 Bytes)
cs
json
(370 Bytes)
cs
Login or Signup to post a comment