/
library_item.cpp
75 lines (69 loc) · 1.71 KB
/
library_item.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <vector>
#include <iostream>
#include "library_item.h"
LibraryItem::LibraryItem()
{
}
LibraryItem::LibraryItem(string _filename, map<string, string> _tags) {
filename = _filename;
tags = _tags;
}
LibraryItem::LibraryItem(DB_functions_t* deadbeef, DB_playItem_t* item) {
DB_playItem_t *it;
if (item == NULL)
{
it = deadbeef->streamer_get_playing_track ();
}
else
{
it = item;
}
vector<string> tag_names { "%a", "%t", "%b", "%B", "%n", "%l", "%y", "%g", "%c", "%r", "%T", "%f", "%F" };
char buffer[256];
for (string tag: tag_names) {
deadbeef->pl_format_title(it, -1, buffer, 256, -1, tag.c_str());
tags.insert(tags.begin(), pair<string, string>(tag, string(buffer)));
}
deadbeef->pl_format_title(it, -1, buffer, 256, -1, "%F");
filename = string(buffer);
}
bool LibraryItem::equal(const LibraryItem& item)
{
if (filename != item.filename)
{
return false;
}
for (pair<string, string> tagItem: tags)
{
if (item.tags.count(tagItem.first) == 0)
{
return false;
}
}
for (pair<string, string> tagItem: item.tags)
{
if (tags.count(tagItem.first) == 0)
{
return false;
}
}
for (pair<string, string> tagItem: item.tags)
{
string tag = tagItem.first;
string thisValue = tags.at(tag);
string otherValue = item.tags.at(tag);
if (thisValue != otherValue)
{
return false;
}
}
return true;
}
bool LibraryItem::operator==(const LibraryItem& item)
{
return equal(item);
}
bool LibraryItem::operator!=(const LibraryItem& item)
{
return !equal(item);
}