-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSongOperations.cpp
More file actions
127 lines (109 loc) · 3.07 KB
/
SongOperations.cpp
File metadata and controls
127 lines (109 loc) · 3.07 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "SongOperations.h"
#include <fileref.h>
#include <sstream>
#include <taglib/tpropertymap.h>
#include "FileHandler.h"
#include "Song.h"
#include <iostream>
#include <string>
std::vector<Song> importMusic(std::vector<fs::path> songpaths, std::string destinationFolderPath, std::string configstring)
{
{
std::vector<Song> songs;
for (int i = 0;i < songpaths.size();i++)
{
Song currentsong;
std::stringstream ss;
TagLib::FileRef fileRef(songpaths[i].string().c_str());
TagLib::Tag* tag = fileRef.tag();
if (fileRef.isNull()) {
std::cerr << "Error opening file." << std::endl;
}
else
{
//currentsong.title = tag->title();
//currentsong.artist = tag->artist();
//currentsong.album = tag->album();
//currentsong.albumArtist = fileRef.file()->properties()["ALBUMARTIST"].front();
//std::cout << currentsong.albumArtist << std::endl;
//std::cout << "year: " << currentsong.album << std::endl;
//currentsong.year = tag->year();
currentsong.oldpath = songpaths[i];
ss << destinationFolderPath << "\\" << convertConfigStringToSongString(configstring, fileRef);
/* if (currentsong.albumArtist.isEmpty())
{
ss << currentsong.artist;
}
else
{
ss << currentsong.albumArtist;
}*/
// ss << "\\" << currentsong.album << ' ' << '(' << currentsong.year << ')' << "\\";
currentsong.NewPath = ss.str();
songs.push_back(currentsong);
}
}
return songs;
}
}
void AttemptMove(std::vector<Song> songs)
{
{
fs::path oldpath;
for (int i = 0;i < songs.size();i++)
{
///weird bullshit if you have a ' it will become ↓
oldpath = songs[i].oldpath;
oldpath.replace_extension(".lrc");
if (fs::exists(oldpath))
{
moveFile(oldpath.string(), songs[i].NewPath.string());
}
moveFile(songs[i].oldpath.string(), songs[i].NewPath.string());
}
}
}
std::string convertConfigStringToSongString(std::string configstring, TagLib::FileRef& fileRef)
{
std::cout << fileRef.file()->tag()->title() << std::endl;
std::string songstring;
std::string newstring;
bool insidebracket = false;
std::stringstream ss(configstring);
///outside a $ $ bracket
while (std::getline(ss, songstring, '`'))
{
newstring.append(songstring);
if (!ss.eof()) {
///inside a $ $ bracket
std::getline(ss, songstring, '`');
std::string a;
TagLib::String b;
try {
///hardcoded cause who wants the whole date
if (songstring == "YEAR")
{
if (fileRef.file()->properties()["DATE"].isEmpty())
throw std::exception("Date is empty");
b = fileRef.file()->properties()["DATE"].front();
// Rest of the code when the property exists
std::stringstream ss(b.to8Bit());
std::getline(ss, a, '-');
}
else
{
if (fileRef.file()->properties()[songstring].isEmpty())
throw std::exception("Property is empty");
b = fileRef.file()->properties()[songstring].front();
a = b.to8Bit();
}
newstring.append(a);
}
catch (const std::exception& e) {
newstring.append("NA");
}
}
}
return newstring;
///inside a $ $ bracket
}