-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmusicFilesApp.cpp
More file actions
160 lines (157 loc) · 4.75 KB
/
musicFilesApp.cpp
File metadata and controls
160 lines (157 loc) · 4.75 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <cctype>
//--------------------------------------------------------------------------------------------------
// Name:
// searcher
//
// Arguments:
// data = a string consisting of the data from the xml file
// pname = name of the playlist the user wants to have copied to a single directory
//
//
//
// About: parses each file path in the playlist and copies each file to a folder on the user's desktop
//
//
// Name: main
//
// About: gets name from user in order to go to their desktop directory and get to their iTunes XML file
// and asks for the name of the playlist to copy to folder on desktop
//
//
// Additional Note: requires that user has checked off option in iTunes to have XML file generated by iTunes.
//
//
//--------------------------------------------------------------------------------------------------
void searcher(std::string data, std::string pname, std::string dek)
{
dek.erase(0, 6);
size_t pstart;
pstart = data.find("Playlist ID"); // go to the beginning of the playlist in the file
while ((data.find(pname, pstart) - pstart) > 500) // loop to find correct playlist
{
pstart = data.find("Playlist ID", pstart);
pstart += 12;
}
pstart = data.find(pname, pstart); // then get to the name
size_t endOfPlay = data.find("</array>", pstart); // find the end so you can stop there
size_t pathloc = 0; // index for where to start reading from in data file
std::string path = ""; // for file path of the file to be copied
std::string cpcmd = ""; // for copy command
std::string driveLetter = ""; // drive letter to copy from
std::string currentNum = ""; // another index pointer
while (data.find("Track ID", pstart) != std::string::npos &&
data.find("Track ID", pstart) < endOfPlay)
{
currentNum = "";
driveLetter = "";
path = "";
cpcmd = " copy ";
pstart = data.find("Track ID", pstart);
pstart = data.find("<integer>", pstart);
pstart += 9;
while (data[pstart] != '<') // get track id
{
currentNum += data[pstart];
pstart++;
}
pathloc = data.find("<key>" + currentNum);
pathloc = data.find("localhost", pathloc);
pathloc += 10;
while (data[pathloc] != '/') // get drive letter
{
driveLetter += data[pathloc];
pathloc++;
}
path += driveLetter + "\\";
while (data[pathloc] != '<') // get file path
{
path += data[pathloc];
pathloc++;
}
cpcmd += "\"" + path + "\"" + " " + "\"" + dek + "\""; // form command to cp file
if (cpcmd.find("\/") != std::string::npos)
cpcmd.replace(cpcmd.find("\/"), 1, "");
size_t temp;
while (cpcmd.find('/') != std::string::npos)
{
temp = cpcmd.find('/');
cpcmd.replace(cpcmd.find('/'), 1, "");
cpcmd.insert(temp, "\\");
}
while (cpcmd.find('%') != std::string::npos || cpcmd.find('#') != std::string::npos) // remove extra chars added by xml
{
size_t spot = cpcmd.find('%');
size_t spot1 = cpcmd.find('#');
if (spot1 != std::string::npos)
{
cpcmd[spot1] = '~';
spot1++;
while (isdigit(cpcmd[spot1]))
{
cpcmd[spot1] = '~';
spot1++;
}
if (cpcmd[spot1] == ';')
cpcmd[spot1] = '~';
}
if (spot != std::string::npos)
{
cpcmd[spot] = ' ';
spot++;
while (isdigit(cpcmd[spot]))
{
cpcmd[spot] = '~';
spot++;
}
}
while (cpcmd.find('~') != std::string::npos)
cpcmd.replace(cpcmd.find('~'), 1, "");
}
system(cpcmd.c_str());
}
}
int main()
{
std::string data = "", answer = "", uname = "", line = "", pname = "", fd = ""; // fd is for the path of the xml
// dek is desktop path
int begin = 0, end = 0; //of main file
std::ifstream file;
std::string dek = "mkdir C:\\Users\\";
std::cout << "What's your username?\n";
std::cin >> uname;
dek += uname;
fd += "C:\\Users\\";
fd += uname;
fd += "\\Music\\iTunes\\iTunes Music Library.xml";
dek += "\\Desktop\\";
do
{
std::cout << "what's the name of the playlist that you want to do?\n";
std::cin >> pname;
dek += pname;
system(dek.c_str()); // making folder on desktop to copy files to
std::cout << "Thanks working on copying the files over to the folder I made before\n";
file.open(fd); // trying to open itunes file
if (!file)
{
std::cout << "couldn't open file";
return 1;
}
while (std::getline(file, line))
{
data += line; // read and store data of entire file
}
file.close();
size_t point = data.find("Playlist ID");
if (data.find(pname, point) == std::string::npos)
std::cout << "playlist not found";
else
searcher(data, pname, dek);
std::cout << "would you like to make another playlist?\n";
std::cin >> answer;
} while (answer == "yes");
}