2#include "AudioSource.h"
20template <
class ClientType>
24 AudioSourceFTP(FTPClient<ClientType>& client,
const char* path,
const char* ext,
27 timeout_auto_next_value = 5000;
28 if (path) p_path = path;
24 AudioSourceFTP(FTPClient<ClientType>& client,
const char* path,
const char* ext, {
…}
48 int tmp_idx = idx + offset;
49 if (!isValidIdx(tmp_idx))
return nullptr;
59 if (!isValidIdx(
index))
return nullptr;
64 file = p_client->open(files[idx].name());
69 int index()
override {
return idx; }
91 if (p_client ==
nullptr)
return false;
92 FTPFile dir = p_client->open(path);
98 size_t size() {
return files.size(); }
101 std::vector<FTPFile> files;
102 FTPClient<ClientType>* p_client =
nullptr;
105 size_t max_files = 0;
106 const char* p_ext =
nullptr;
107 const char* p_path =
"/";
108 bool is_first =
true;
112 if (!endsWith(dir.name(), p_ext)) {
113 LOGI(
"adding file %s", dir.name());
114 files.push_back(std::move(dir));
116 for (
const auto& file : p_client->ls(dir.name())) {
117 if (endsWith(file.name(), p_ext)) {
118 LOGI(
"adding file %s", file.name());
119 files.push_back(std::move(file));
121 if (max_files > 0 && files.size() >= max_files) {
122 LOGI(
"max files reached: %d", max_files);
129 bool isValidIdx(
int index) {
130 if (
index < 0)
return false;
131 if (
index >= files.size()) {
132 LOGE(
"index %d is out of range (size: %d)",
index, files.size());
138 bool endsWith(
const char* file,
const char* ext) {
139 if (file ==
nullptr)
return false;
140 if (p_ext ==
nullptr)
return true;
141 return (StrView(file).endsWith(ext));