commit 48cfa93e5ca7cb7f69d65f9e839602b1c248a0fd Author: Victor Date: Tue Aug 29 09:19:28 2017 +0300 Ability to retrieve track info diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eec6d03 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.dub +docs.json +__dummy.html +*.o +*.obj +__test__*__ diff --git a/dub.json b/dub.json new file mode 100644 index 0000000..4ea9a01 --- /dev/null +++ b/dub.json @@ -0,0 +1,9 @@ +{ + "name" : "anmusic", + "authors" : [ + "aNNiMON" + ], + "description" : "aNMusic", + "copyright" : "Copyright © 2017, aNNiMON", + "license" : "free" +} diff --git a/source/aimpremote/aimpremote.d b/source/aimpremote/aimpremote.d new file mode 100644 index 0000000..f37116f --- /dev/null +++ b/source/aimpremote/aimpremote.d @@ -0,0 +1,119 @@ +module aimpremote; + +import core.sys.windows.windows; + +private const wstring AIMPRemoteAccessClass = "AIMP2_RemoteInfo"; +private const int AIMPRemoteAccessMapFileSize = 2048; + +align(1) +private struct AIMPRemoteFileInfo +{ + DWORD deprecated1; + BOOL active; + DWORD bitRate; + DWORD channels; + DWORD duration; + align(4) INT64 fileSize; + DWORD fileMark; + DWORD sampleRate; + DWORD trackNumber; + DWORD albumLength; + DWORD artistLength; + DWORD dateLength; + DWORD fileNameLength; + DWORD genreLength; + DWORD titleLength; + DWORD[6] deprecated2; +}; + +private enum TagItem { + Album, Artist, Date, FileName, Genre, Title +} + +public struct TrackInfo { + wstring artist; + wstring title; + wstring genre; +}; + +public static TrackInfo getInfo() { + import std.conv : to; + import std.traits : EnumMembers; + + auto haimp = OpenFileMapping(FILE_MAP_READ, 0, AIMPRemoteAccessClass.ptr); + const auto hfilemap = MapViewOfFile(haimp, FILE_MAP_READ, 0, 0, AIMPRemoteAccessMapFileSize); + + AIMPRemoteFileInfo* info = cast(AIMPRemoteFileInfo*) hfilemap; + auto bytes = (cast(ubyte*) hfilemap)[0 .. AIMPRemoteAccessMapFileSize]; + + const wcharsize = wchar.sizeof; + auto pbuff = AIMPRemoteFileInfo.sizeof; + + DWORD[TagItem] lengthInfo; + wstring[TagItem] trackInfo; + + lengthInfo[TagItem.Album] = info.albumLength; + lengthInfo[TagItem.Artist] = info.artistLength; + lengthInfo[TagItem.Date] = info.dateLength; + lengthInfo[TagItem.FileName] = info.fileNameLength; + lengthInfo[TagItem.Genre] = info.genreLength; + lengthInfo[TagItem.Title] = info.titleLength; + foreach (index, immutable item; [EnumMembers!TagItem]) { + auto key = to!TagItem(index); + auto length = lengthInfo[key]; + trackInfo[key] = cast(wstring)(bytes[pbuff .. (pbuff + length * wcharsize)]); + pbuff += length * wcharsize; + } + + TrackInfo result = { + artist: trackInfo[TagItem.Artist], + title: trackInfo[TagItem.Title], + genre: trackInfo[TagItem.Genre] + }; + return result; +} + +private static HWND findPlayerWindow() { + return FindWindow(AIMPRemoteAccessClass.ptr, null); +} + +/*void main() { + import std.stdio : writeln, write; + + auto haimp = OpenFileMapping(FILE_MAP_READ, 0, AIMPRemoteAccessClass.ptr); + auto hfilemap = MapViewOfFile(haimp, FILE_MAP_READ, 0, 0, AIMPRemoteAccessMapFileSize); + + AIMPRemoteFileInfo* info = cast(AIMPRemoteFileInfo*) hfilemap; + write("Bitrate: "); + writeln(info.bitRate); + write("Samplerate: "); + writeln(info.sampleRate); + write("fileSize: "); + writeln(info.fileSize); + + auto bytes = (cast(ubyte*) hfilemap)[0 .. AIMPRemoteAccessMapFileSize]; + writeln(bytes); + + + const wcharsize = wchar.sizeof; + auto pbuff = AIMPRemoteFileInfo.sizeof; + + DWORD[TagItem] lengthInfo; + wstring[TagItem] trackInfo; + + lengthInfo[TagItem.Album] = info.albumLength; + lengthInfo[TagItem.Artist] = info.artistLength; + lengthInfo[TagItem.Date] = info.dateLength; + lengthInfo[TagItem.FileName] = info.fileNameLength; + lengthInfo[TagItem.Genre] = info.genreLength; + lengthInfo[TagItem.Title] = info.titleLength; + foreach (key; TagItem.min .. TagItem.max) { + auto length = lengthInfo[key]; + trackInfo[key] = cast(wstring)(bytes[pbuff .. (pbuff + length * wcharsize)]); + pbuff += length * wcharsize; + } + + foreach (key, value; trackInfo) { + writeln(value); + } +}*/ diff --git a/source/app.d b/source/app.d new file mode 100644 index 0000000..c2a7f31 --- /dev/null +++ b/source/app.d @@ -0,0 +1,21 @@ +import std.stdio; +import std.net.curl; +import aimpremote; + + +void main() +{ + auto http = HTTP(); + // http.caInfo("cacert.pem"); + http.handle.set(CurlOption.ssl_verifypeer, 0); + + auto track = getInfo(); + + auto content = post("https://annimon.com/json/nowplay", [ + "login" : "test", + "token" : "5token", + "artist" : to!string(track.artist), + "title" : to!string(track.title), + "genre" : to!string(track.genre) + ], http); +}