From b31bceb280ee086808c2132c9b6bb4c9c83f67d4 Mon Sep 17 00:00:00 2001 From: nedko Date: Tue, 11 Jun 2024 15:01:58 +0300 Subject: [PATCH] Added code --- Makefile | 4 +++ main.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 Makefile create mode 100644 main.cpp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1283bee --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +all: + g++ -o youtube_playlist main.cpp + +.PHONY: all diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..aa242a7 --- /dev/null +++ b/main.cpp @@ -0,0 +1,94 @@ +#include +#include +#include +#include +#include + +using namespace std; + +int main(int argc, char** argv) +{ + ifstream file; + string curr_id; + int pos; + vector ids_array; + + if(argc < 2) + { + cout << "Usage: " << argv[0] << " [playlist]" << endl; + return -1; + } + + file.open(argv[1]); + if(!file.is_open()) + { + cout << "Unable to open file" << endl; + return -1; + } + + while(!file.eof()) + { + getline(file, curr_id); + + for (pos = 0; pos < curr_id.length(); ++pos) + { + if (0 != isspace(curr_id[pos])) + { + curr_id.erase(pos, 1); + --pos; + } + } + + // Delete everything after comment + pos = curr_id.find("/*"); + if (string::npos != pos) + { + curr_id.erase(pos); + } + + // Find beginning of parameters + pos = curr_id.find("?"); + if (string::npos == pos) + { + continue; + } + curr_id.erase(0, pos + 1); + + // Find beginning of video id + pos = curr_id.find("v="); + if (string::npos == pos) + { + continue; + } + curr_id.erase(0, pos + 2); + + // Delete everything after the id if exists + pos = curr_id.find("&"); + if (string::npos != pos) + { + curr_id.erase(pos); + } + + // Put it in array + if (!curr_id.empty()) + { + ids_array.push_back(curr_id); + } + } + + if(0 != ids_array.size()) + { + cout << "http://www.youtube.com/watch_videos?video_ids="; + cout << ids_array[0]; + for(vector::iterator it = ids_array.begin() + 1; it != ids_array.end(); ++it) + { + cout << "," << *it; + } + cout << endl; + } + else + { + cout << "No video links found. 'youtu.be' links are not supported" << endl; + } + return 0; +}