This repository has been archived by the owner on Jul 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playlist.cxx
229 lines (175 loc) · 3.82 KB
/
playlist.cxx
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
Copyright (C) 2015, 2019 daltomi <daltomi@disroot.org>
This file is part of flvlc.
flvlc is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
flvlc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with flvlc. If not, see <http://www.gnu.org/licenses/>.
*/
#include "playlist.hpp"
Playlist::Playlist() : ipos(0) {}
Playlist::~Playlist() {}
bool Playlist::load(const char *path)
{
std::string filename(path);
filename += "playlist";
std::ifstream file(filename);
if (not file.is_open()) {
return false;
}
unsigned int index;
file >> index;
while (true) {
Item item{"", -1, false};
file >> item.position;
// - Elimina espacio en blanco que separa
// la posicion y el nombre del archivo.
file.ignore(1, ' ');
getline(file, item.name);
if (file.fail()) {
break;
}
item.b_watch = (item.position == -1) ? false : true;
append(item);
}
file.close();
if (items.size() == 0 or (index >= items.size())) {
return false;
}
ipos = index;
return true;
}
void Playlist::save(const char *path)
{
if (items.size() == 0) {
return;
}
std::string filename(path);
filename += "playlist";
std::ofstream file(filename, std::ios_base::trunc);
file << ipos << '\n'; // begin line
for (auto &item : items) {
(item.b_watch) ? file << item.position : file << "-1";
// - Espacio en blanco que separa
// la posicion y el nombre del archivo.
file << " ";
// - Elimina el prefijo file://
file << item.name.substr(7, item.name.size()) << '\n';
}
file.close();
}
void Playlist::clean()
{
const Item itmp = items[ipos];
items.clear();
items.push_back(itmp);
ipos = 0;
}
void Playlist::append(const int argc, const char *argv[])
{
// clear index from Playlist::load()
ipos = count();
for (int i = 0; i < argc; ++i) {
Item item{"", -1, false};
if (not FILES::make_name_file(item.name, argv[i])) {
continue;
}
items.push_back(item);
}
#ifdef DEBUG
print();
#endif
}
void Playlist::append(const char *name)
{
Item item{name, -1, false};
append(item);
}
// Nota: no avanza ipos, utilizar
// la func. position()
void Playlist::append(Item &item)
{
// Item item{"", -1, false};
if (FILES::make_name_file(item.name, item.name.c_str())) {
items.push_back(item);
}
}
const char *Playlist::current() const
{
return items.at(ipos).name.c_str();
}
const char *Playlist::prev()
{
--ipos;
return items.at(ipos).name.c_str();
}
const char *Playlist::next()
{
++ipos;
return items.at(ipos).name.c_str();
}
const unsigned int Playlist::count() const
{
return items.size();
}
bool Playlist::is_prev() const
{
return ((ipos - 1) != -1);
}
bool Playlist::is_next() const
{
return ((size_t)(ipos + 1) != count());
}
void Playlist::reset()
{
ipos = 0;
}
// Unicamente para el actual item.
const char *Playlist::title() const
{
return fl_filename_name(items[ipos].name.c_str());
}
bool Playlist::is_empty() const
{
return (count() == 0);
}
const unsigned int Playlist::position() const
{
return ipos + 1;
}
void Playlist::position(const unsigned int pos)
{
ipos = pos - 1;
}
void Playlist::watch(const float pos)
{
items.at(ipos).position = pos;
}
float Playlist::watch() const
{
return items.at(ipos).position;
}
bool Playlist::is_watch() const
{
if (!is_empty())
{
return (items.at(ipos).b_watch);
}
return false;
}
void Playlist::set_watch(bool val)
{
if (!is_empty()) {
items.at(ipos).b_watch = val;
}
}
const ITEMS &Playlist::get_items() const
{
return items;
}