mp3infp on C#

また例のごとくDLLをC#に読み込ませてみた。mp3infpというMP3のTagをいじるDLLを読み込んだ。タグ情報を一括で正規表現とか使って書き換えられたら良いなと思ってたから作ってみた。肝心の正規表現を良くわかっていないのはおいておいて…

ソースは続きへ

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace mp3infpsharp
{
    class mp3infpsharp
    {
        static void Main(string[] args)
        {
            write(GetVer().ToString());
            Load("Ballade no1.mp3");
            write(GetAudioType().ToString());
            string buf;
            GetValue(Value.MP3.V2.Name, out buf).ToString();
            write(buf);
            write(SetValue(Value.MP3.V2.Composer, "Liszt").ToString());
            Save("Ballade no1.mp3");

            pause();
        }
        static void write(string @string)
        { Console.WriteLine(@string); }

        static void pause()
        { Console.ReadKey(true); }

        public enum FileType
        {
            UNKNOWN = 0x00,
            MP3 = 0x01,
            WAV = 0x02,
            AVI = 0x03,
            VQF = 0x04,
            WMA = 0x05,
            OGG = 0x07,
            APE = 0x08,
            MP4 = 0x09,
        }
        public static class Value
        {
            public const string
                File = "FILE",
                Extexsion = "FEXT",
                Path = "PATH",
                Bytes = "SIZ1",
                KiloBytes = "SIZK",
                MegaBytes = "SIZM",
                Format = "AFMT",
                Time = "TIME"
                ;

            public static class MP3
            {
                public static class V1
                {
                    public const string
                        Name = "INAM_v1",
                        Artist = "IART_v1",
                        Album = "IPRD_v1",
                        Composer = "COMP_v1",
                        Genre = "IGNR_v1",
                        Track = "TRACK_v1"
                        ;
                }

                public static class V2
                {
                    public const string
                        Name = "INAM_v2",
                        Artist = "IART_v2",
                        Album = "IPRD_v2",
                        Composer = "COMP_v2",
                        Genre = "IGNR_v2",
                        Track = "TRACK_v1"
                        ;
                }
            }
            public static class Audio
            {
                public const string
                    Name = "INAM",
                    Artist = "IART",
                    Album = "IPRD",
                    Composer = "COMP",
                    Genre = "IGNR",
                    Track = "TRACK"
                    ;
            }
        }

        [DllImport("mp3infp.dll", EntryPoint = "mp3infp_GetVer")]
        public static extern uint GetVer();

        [DllImport("mp3infp.dll", EntryPoint = "mp3infp_Load")]
        public static extern bool Load(IntPtr hWnd, string szFileName);
        public static bool Load(string szFileName) { return Load(new IntPtr(), szFileName); }

        [DllImport("mp3infp.dll", EntryPoint = "mp3infp_GetType")]
        public static extern FileType GetAudioType();

        [DllImport("mp3infp.dll", EntryPoint = "mp3infp_GetValue")]
        public static extern bool GetValue(string szValueName, out string buf);

        [DllImport("mp3infp.dll", EntryPoint = "mp3infp_SetValue")]
        public static extern uint SetValue(string szValueName, string buf);

        [DllImport("mp3infp.dll", EntryPoint = "mp3infp_Save")]
        public static extern uint Save(string szValueName);

        public enum ID3Type
        {
            MP3_ID3V1 = 0x00000001,
            MP3_ID3V2 = 0x00000002,
            MP3_RIFFSIF = 0x00000004,
            MP3_ID3V1_0 = 0x00000008,	// v2.43〜
            MP3_ID3V1_1 = 0x00000010,	// v2.43〜
            MP3_ID3V2_2 = 0x00000020,	// v2.43〜
            MP3_ID3V2_3 = 0x00000040,	// v2.43〜
            MP3_ID3V2_4 = 0x00000080,	// v2.43〜
            MP3_APEV1 = 0x00000100,	// v2.47〜
            MP3_APEV2 = 0x00000200,	// v2.47〜
        }
        [DllImport("mp3infp.dll", EntryPoint = "mp3infp_mp3_GetTagType")]
        public static extern ID3Type GetID3Type();

        [DllImport("mp3infp.dll", EntryPoint = "mp3infp_mp3_MakeId3v1")]
        public static extern uint MakeID3v1(string szValueName);

        [DllImport("mp3infp.dll", EntryPoint = "mp3infp_mp3_DelId3v1")]
        public static extern uint DeleteID3v1(string szValueName);

        [DllImport("mp3infp.dll", EntryPoint = "mp3infp_mp3_MakeId3v2")]
        public static extern uint MakeID3v2(string szValueName);

        [DllImport("mp3infp.dll", EntryPoint = "mp3infp_mp3_DelId3v2")]
        public static extern uint DeleteID3v2(string szValueName);
    }
}

一部の関数しか読み込んでません。自分が必要だと思ったのだけ。
あと動作確認は…ごめんなさい。一部の関数しかしていません><
まぁ動くでしょう(笑)