-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutube.cpp
95 lines (89 loc) · 2.14 KB
/
youtube.cpp
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
#include <iostream>
#include <string>
#include <format>
#include <regex>
#include <fstream>
// #include <chrono>
#include "youtube.h"
using namespace std;
// TODO: Get latest video from youtube rss
string url2id (string url) {
string::difference_type count = std::count(url.begin(), url.end(), '/');
while (count != 0) {
if (url[0] == '/') {
count--;
}
url.erase(0,1);
}
return url;
}
string getChannelId (string customurl) {
// Filter URL with ID from file
string query = "(\"https://www.youtube.com/channel/)(.*?)([\"?])";
ifstream channel;
channel.open(format("/tmp/rissa/{}", customurl));
string line;
string id;
while (getline(channel, line) && id.empty()) {
// Make regex query
regex rgx(query);
// Hold matches
smatch url;
// Search file
regex_search(line, url, rgx);
// Get url id from query
if (url[0] != "") {
id = url[0];
id.erase(0,1);
id.erase(id.size() - 1, 1);
}
}
return url2id(id);
}
int getStartTime(string fullTime) {
string startTime = "";
for (unsigned int i = 0; i < fullTime.size(); i++) {
if (isdigit(fullTime[i])) {
startTime.push_back(fullTime[i]);
}
}
if (startTime == "") {
return 0;
}
return stoi(startTime);
}
int getNextLive(string fileName) {
string query = "(\"startTime\")(.*?)(\",\")";
ifstream file;
file.open(format("/tmp/rissa/{}", fileName));
string line;
string startTime;
while (getline(file, line) && startTime.empty()) {
regex rgx(query);
smatch utime;
regex_search(line, utime, rgx);
if (utime[0] != "") {
startTime = utime[0];
}
}
if (getStartTime(startTime) == 0) {
return 0;
}
int TZ = -14400; // SET UTC TIMEZONE OFFSET HERE
return getStartTime(startTime)+TZ;
}
/*
int main (int argc, char** argv) {
if (argc == 1) {
throw std::invalid_argument("No ID Given");
} else { // Turn into function later
if (argv[1][0] == '@') { // If personalized URL is provided
string purl = argv[1];
// Not sure how to guarentee script is in $PATH
system((format("./wgetchannel.sh {}", purl)).c_str());
// cout << getChannelId(purl) << endl; // Print channel ID
cout << chrono::sys_seconds{chrono::seconds(getNextLive(purl))} << endl;
}
}
}
*/