Skip to content

Commit

Permalink
v0.4.5b2
Browse files Browse the repository at this point in the history
 - Added search by release-group ID
 - Added back in initial delay on search, and reordered message
 - Avoid potential infinite loop on abort
  • Loading branch information
kbuffington committed Feb 22, 2020
1 parent 7fc53e6 commit 8282c91
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 18 deletions.
Binary file modified src/Release/foo_musicbrainz/foo_musicbrainz.pdb
Binary file not shown.
62 changes: 58 additions & 4 deletions src/contextmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

namespace mb
{
static constexpr std::array<const GUID, 4> context_guids =
static constexpr std::array<const GUID, 5> context_guids =
{
0x3ca8395b, 0x694e, 0x4845, { 0xb5, 0xea, 0x56, 0x30, 0x5e, 0x7c, 0x24, 0x48 },
0x77f1f5cd, 0xf295, 0x4ef4, { 0xba, 0x7b, 0xc7, 0x70, 0xaa, 0xc6, 0xd0, 0x1e },
0xf453e537, 0x01e9, 0x4f2d, { 0x89, 0xdc, 0x42, 0x4d, 0x0e, 0xe5, 0x72, 0xfb },
0xd74ebc1b, 0x7529, 0x4c68, { 0xb8, 0x85, 0xbf, 0xb1, 0x34, 0x8c, 0xed, 0xc8 },
0x4d5e632c, 0x34f3, 0x4fda, { 0x8f, 0x71, 0x35, 0xa4, 0xb2, 0x5b, 0xea, 0x94 }
};

Expand All @@ -20,6 +21,7 @@ namespace mb
{ "Get tags from MusicBrainz (by TOC)", "Queries MusicBrainz server for tags for a complete CD using TOC." },
{ "Get tags from MusicBrainz (by artist & album)","Queries MusicBrainz server for tags for a complete CD using Artist/Album." },
{ "Get tags from MusicBrainz (by MusicBrainz album ID)","Queries MusicBrainz server for tags for a complete CD using MusicBrainz Album ID." },
{ "Get tags from MusicBrainz (by MusicBrainz release ID)","Queries MusicBrainz server for tags for a complete CD using MusicBrainz Release ID." },
{ "Add TOC to MusicBrainz", "Opens MusicBrainz TOC lookup page." }
};

Expand All @@ -46,9 +48,10 @@ namespace mb
break;
case 1:
case 2:
case 3:
result = true;
break;
case 3:
case 4:
result = check_count(handles) && check_lossless(handles);
break;
}
Expand Down Expand Up @@ -188,10 +191,10 @@ namespace mb
if (scope.can_create())
{
scope.initialize(wnd);
dialog_mbid dlg(album_id);
dialog_mbid dlg(album_id, "MusicBrainz Album ID");
if (dlg.DoModal(wnd) == IDOK)
{
auto q = std::make_unique<query>("release", dlg.m_albumid_str);
auto q = std::make_unique<query>("release", dlg.m_mbid_str);
q->add_param("inc", "artists+labels+recordings+release-groups+artist-credits+isrcs");
auto cb = fb2k::service_new<request_thread>(request_thread::types::albumid, std::move(q), handles);
threaded_process::get()->run_modeless(cb, flags, wnd, "Querying data from MusicBrainz");
Expand All @@ -200,6 +203,57 @@ namespace mb
}
break;
case 3:
{
str8 relgroup_id;
for (size_t i = 0; i < count; i++)
{
const file_info_impl info = handles.get_item(i)->get_info_ref()->info();

auto current_relgroup_id = info.meta_get("MUSICBRAINZ_RELEASEGROUPID", 0);
if (current_relgroup_id == nullptr) current_relgroup_id = info.meta_get("MUSICBRAINZ RELEASEGROUPID", 0);

if (current_relgroup_id == nullptr)
{
relgroup_id.reset();
break;
}
else
{
if (i == 0)
{
if (is_uuid(current_relgroup_id))
{
relgroup_id = current_relgroup_id;
}
else
{
break;
}
}
else if (strcmp(relgroup_id, current_relgroup_id) != 0)
{
relgroup_id.reset();
break;
}
}
}

modal_dialog_scope scope;
if (scope.can_create())
{
scope.initialize(wnd);
dialog_mbid dlg(relgroup_id, "MusicBrainz Release Group ID");
if (dlg.DoModal(wnd) == IDOK)
{
auto q = std::make_unique<query>("release-group", dlg.m_mbid_str);
q->add_param("inc", "releases+media");
auto cb = fb2k::service_new<request_thread>(request_thread::types::search, std::move(q), handles);
threaded_process::get()->run_modeless(cb, flags, wnd, "Querying data from MusicBrainz");
}
}
}
break;
case 4:
{
if (!check_count(handles)) return popup_message::g_show("Please select no more than 99 tracks.", component_title, popup_message::icon_error);
if (!check_lossless(handles)) return popup_message::g_show("Only lossless files with a sample rate of 44100Hz may be used for TOC submissions. Also, the number of samples must match CD frame boundaries.", component_title, popup_message::icon_error);
Expand Down
21 changes: 13 additions & 8 deletions src/dialog_mbid.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace mb
class dialog_mbid : public CDialogImpl<dialog_mbid>
{
public:
dialog_mbid(pfc::stringp albumid_str) : m_albumid_str(albumid_str) {}
dialog_mbid(pfc::stringp albumid_str, str8 group_title_str)
: m_mbid_str(albumid_str)
, m_group_title_str(group_title_str) {}

BEGIN_MSG_MAP_EX(dialog_mbid)
MSG_WM_INITDIALOG(OnInitDialog)
Expand All @@ -18,38 +20,41 @@ namespace mb
BOOL OnInitDialog(CWindow, LPARAM)
{
m_ok = GetDlgItem(IDOK);
m_albumid_edit = GetDlgItem(IDC_EDIT_MBID);
m_mbid_edit = GetDlgItem(IDC_EDIT_MBID);
CEdit m_mbid_title = GetDlgItem(IDC_STATIC);

uSetWindowText(m_albumid_edit, m_albumid_str);
uSetWindowText(m_mbid_edit, m_mbid_str);
uSetWindowText(m_mbid_title, m_group_title_str);
CenterWindow();
return TRUE;
}

void OnCloseCmd(UINT, int nID, CWindow)
{
uGetWindowText(m_albumid_edit, m_albumid_str);
uGetWindowText(m_mbid_edit, m_mbid_str);
EndDialog(nID);
}

void OnUpdate(UINT, int, CWindow)
{
str8 t;
uGetWindowText(m_albumid_edit, t);
uGetWindowText(m_mbid_edit, t);
str8 u = prefs::get_server();
u << "/release/";
const size_t l = u.get_length();
if (strncmp(t, u, l) == 0)
{
t.replace_string(u, "");
uSetWindowText(m_albumid_edit, t);
uSetWindowText(m_mbid_edit, t);
return;
}

m_ok.EnableWindow(is_uuid(t.get_ptr()));
}

CButton m_ok;
CEdit m_albumid_edit;
str8 m_albumid_str;
CEdit m_mbid_edit;
str8 m_mbid_str;
str8 m_group_title_str;
};
}
2 changes: 1 addition & 1 deletion src/foo_musicbrainz.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace mb
{
static constexpr const char* component_title = "MusicBrainz Tagger";
static constexpr const char* component_dll_name = "foo_musicbrainz.dll";
static constexpr const char* component_version = "0.4.5b1";
static constexpr const char* component_version = "0.4.5b2";
static constexpr const char* component_info = "Copyright (C) 2009-2012 Dremora\nCopyright (C) 2015-2020 marc2003\nCopyright (C) 2020 MordredKLB\n\nBuild: " __TIME__ ", " __DATE__;
}
4 changes: 4 additions & 0 deletions src/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ namespace mb
{
url << "&" << param << "=" << value;
}

str8 query::get_url() {
return url;
}
}
1 change: 1 addition & 0 deletions src/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace mb

json lookup(abort_callback& abort);
void add_param(pfc::stringp param, pfc::stringp value);
str8 get_url();

private:
str8 url;
Expand Down
11 changes: 6 additions & 5 deletions src/request_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ namespace mb
const size_t handle_count = m_handles.get_count();

json j = m_query->lookup(abort);
#ifdef DEBUG
FB2K_console_formatter() << component_title << ": " << m_query->get_url();
#endif
if (!j.is_object())
{
m_failed = true;
Expand Down Expand Up @@ -124,11 +127,9 @@ namespace mb

for (size_t i = 0; i < count; ++i)
{
Sleep(1000);
status.set_title(PFC_string_formatter() << "Fetching release " << (i + 1) << " of " << count);
status.set_progress(i + 1, count);
status.set_title(PFC_string_formatter() << "Fetching " << (i + 1) << " of " << count);
if (i > 0) {
Sleep(1000);
}

/**
* this was pre-existing logic which would abort when we didn't receive anything back
Expand All @@ -146,7 +147,7 @@ namespace mb
if (!simple_thread_pool::instance().enqueue(task)) delete task;
}
Sleep(10); // wait for last thread to start
while (m_release_list.size() < thread_counter) {
while (m_release_list.size() < thread_counter && !abort.is_aborting()) {
// Is there a better way to wait for all the threads to complete?
Sleep(10);
}
Expand Down

0 comments on commit 8282c91

Please sign in to comment.