@@ -37,6 +37,69 @@ std::vector<std::string> M3u8Handler::split(const std::string &s, char delim) {
37
37
return result;
38
38
}
39
39
40
+ m3u_stream M3u8Handler::parseYT (const std::string &webUri) {
41
+ std::string useUriVideo;
42
+ std::string useUriAudio;
43
+
44
+ std::vector<std::string> callStr{
45
+ IptvConfig.GetYtdlpPath (), " --get-url" ,
46
+ " -f" , " (bv*[vcodec~='^((he|a)vc|h26[45])']+ba[ext=m4a]/b[ext=mp4])" , webUri
47
+ };
48
+
49
+ std::string newUri;
50
+ auto handler = new TinyProcessLib::Process (callStr, " " ,
51
+ [&newUri](const char *bytes, size_t n) {
52
+ std::string result = std::string (bytes, n);
53
+ debug1 (" yt-dlp found URL %s\n " , result.c_str ());
54
+ newUri = std::string (bytes, n);
55
+ },
56
+
57
+ [](const char *bytes, size_t n) {
58
+ std::string msg = std::string (bytes, n);
59
+ debug1 (" yt-dlp Error: %s\n " , msg.c_str ());
60
+ },
61
+
62
+ true
63
+ );
64
+
65
+ int exitStatus = handler->get_exit_status ();
66
+ if (exitStatus!=0 ) {
67
+ debug1 (" yt-dlp throws an error, abort\n " );
68
+ m3u_stream result;
69
+ result.width = result.height = 0 ;
70
+ return result;
71
+ }
72
+
73
+ // check if the uri contains video/audio URL or if it's a simple URL
74
+ auto m = newUri.find (' \n ' );
75
+ if (m == std::string::npos) {
76
+ // only video
77
+ useUriVideo = newUri;
78
+ useUriAudio = " " ;
79
+ } else {
80
+ // audio / video
81
+ useUriVideo = newUri.substr (0 , m);
82
+ useUriAudio = newUri.substr (m+1 );
83
+ }
84
+
85
+ // set dummy values
86
+ m3u_stream result;
87
+ result.width = 1920 ;
88
+ result.height = 1080 ;
89
+ result.url = useUriVideo;
90
+
91
+ if (!useUriAudio.empty ()) {
92
+ struct media audio;
93
+ audio.uri = useUriAudio;
94
+ audio.name = " audio" ;
95
+ audio.language = " C" ;
96
+
97
+ result.audio .emplace_back (audio);
98
+ }
99
+
100
+ return result;
101
+ }
102
+
40
103
m3u_stream M3u8Handler::parseM3u (const std::string &webUri, int useYtdlp) {
41
104
std::string useUri;
42
105
0 commit comments