soooooongs
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -6,4 +6,7 @@ build/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
|
audio
|
||||||
|
challenges
|
||||||
92
src/main.cpp
92
src/main.cpp
@@ -1,31 +1,57 @@
|
|||||||
#include "stx-execpipe.h"
|
#include "stx-execpipe.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
static const std::vector<std::string> links = {
|
static const std::vector<std::string> links = {
|
||||||
"2gQ--SCEfmI"};
|
"2gQ--SCEfmI",
|
||||||
|
"9xBeLSXOvSY",
|
||||||
|
"gv7QwZqMFYc",
|
||||||
|
"tFRStkEkhbY",
|
||||||
|
"OecoHvuxkxY",
|
||||||
|
"7SVKgjhpTHY",
|
||||||
|
"KF63Z27NPTE",
|
||||||
|
"7fKPxTbFt88",
|
||||||
|
"ZccDikDUHmA",
|
||||||
|
"PjnHPuEUbjU"
|
||||||
|
};
|
||||||
|
|
||||||
static const std::string YTDLP_BINARY = "/usr/bin/yt-dlp";
|
static const std::string YTDLP_BINARY = "/home/simon/.local/bin/yt-dlp";
|
||||||
|
|
||||||
void DownloadFile()
|
std::string GetAudioPath(const std::string& id) {
|
||||||
|
return "audio/" + id + ".ogg";
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadFile(const std::string &id)
|
||||||
{
|
{
|
||||||
stx::ExecPipe ep;
|
stx::ExecPipe ep;
|
||||||
|
|
||||||
std::string link = "https://music.youtube.com/watch?v=" + links.front();
|
std::string link = "https://music.youtube.com/watch?v=" + id;
|
||||||
|
|
||||||
std::vector<std::string> args = {YTDLP_BINARY, link.c_str(), "--extract-audio", "--audio-format", "vorbis", "-o", "%(id)s.%(ext)s"};
|
std::vector<std::string> args = {YTDLP_BINARY, link.c_str(), "--extract-audio", "--audio-format", "vorbis", "--audio-quality", "10", "-o", "audio/%(id)s.%(ext)s"};
|
||||||
|
|
||||||
ep.add_exec(&args);
|
ep.add_exec(&args);
|
||||||
ep.run();
|
ep.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetDuration()
|
void DownloadFiles() {
|
||||||
|
for (const std::string& id : links) {
|
||||||
|
DownloadFile(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* std::vector<std::string> args = {"/usr/bin/ffmpeg", "-hide_banner", "-loglevel", "panic", "-i", "pipe:0", "-b:a", "32k", "-map",
|
||||||
|
"a", "-c:a", "libopus", "-f", "ogg", "-y", "pipe:1"};
|
||||||
|
*/
|
||||||
|
|
||||||
|
float GetDuration(const std::string &id)
|
||||||
{
|
{
|
||||||
stx::ExecPipe ep;
|
stx::ExecPipe ep;
|
||||||
|
|
||||||
std::string fileName = links.front() + ".ogg";
|
std::string fileName = GetAudioPath(id);
|
||||||
|
|
||||||
std::vector<std::string> args = {"/usr/bin/ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", fileName};
|
std::vector<std::string> args = {"/usr/bin/ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", fileName};
|
||||||
|
|
||||||
@@ -37,12 +63,54 @@ float GetDuration()
|
|||||||
return std::stof(output);
|
return std::stof(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Returns a random real number between min and max.
|
||||||
|
* \param min The minimum value.
|
||||||
|
* \param max The maximum value.
|
||||||
|
* \return A random real number between min and max.
|
||||||
|
*/
|
||||||
|
float GetRandomReal(float min, float max)
|
||||||
|
{
|
||||||
|
static std::random_device randomDevice;
|
||||||
|
static std::mt19937 generator(randomDevice());
|
||||||
|
std::uniform_real_distribution<float> distrib(min, max);
|
||||||
|
return distrib(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExtractAudio(const std::string &id, float begin, float end, const std::string& outputName)
|
||||||
|
{
|
||||||
|
stx::ExecPipe ep;
|
||||||
|
|
||||||
|
std::vector<std::string> args = {"/usr/bin/ffmpeg", "-y", "-loglevel", "panic", "-i", GetAudioPath(id), "-ss", std::to_string(begin), "-to", std::to_string(end), outputName};
|
||||||
|
|
||||||
|
ep.add_exec(&args);
|
||||||
|
ep.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetRandomLink() {
|
||||||
|
return links.at(rand() % links.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GenRandomChallenge() {
|
||||||
|
std::string randomLink = GetRandomLink();
|
||||||
|
float duration = GetDuration(randomLink);
|
||||||
|
|
||||||
|
float randomSeek = GetRandomReal(duration / 4.0f, duration * 3.0f / 4.0f);
|
||||||
|
|
||||||
|
ExtractAudio(randomLink, randomSeek, randomSeek + 0.5f, "challenges/1.ogg");
|
||||||
|
ExtractAudio(randomLink, randomSeek, randomSeek + 1.0f, "challenges/2.ogg");
|
||||||
|
ExtractAudio(randomLink, randomSeek, randomSeek + 1.5f, "challenges/3.ogg");
|
||||||
|
ExtractAudio(randomLink, randomSeek, randomSeek + 2.0f, "challenges/4.ogg");
|
||||||
|
|
||||||
|
std::cout << "Done !\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
srand(time(0));
|
||||||
float duration = GetDuration();
|
|
||||||
|
GenRandomChallenge();
|
||||||
std::cout << "Durée : " << duration << std::endl;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user