Lines 41-47
Link Here
|
41 |
#include "youtube_video_url.h" |
41 |
#include "youtube_video_url.h" |
42 |
#include "tools.h" |
42 |
#include "tools.h" |
43 |
#include "url.h" |
43 |
#include "url.h" |
44 |
#include <unistd.h> |
|
|
45 |
|
44 |
|
46 |
using namespace zmm; |
45 |
using namespace zmm; |
47 |
|
46 |
|
Lines 118-154
Link Here
|
118 |
|
117 |
|
119 |
watch = _(YOUTUBE_URL_WATCH) + video_id; |
118 |
watch = _(YOUTUBE_URL_WATCH) + video_id; |
120 |
|
119 |
|
121 |
char *const parmList[] = {"/usr/bin/youtube-dl", "-g", watch, NULL}; |
120 |
/* |
|
|
121 |
* NOTE ON PATCH: |
122 |
* |
123 |
* The original code does not seem to work anymore. |
124 |
* |
125 |
* I have commented-out all the original code, and instead |
126 |
* replaced it with a call/exec to youtube-dl (this is a separate/stand-alone python script). |
127 |
* |
128 |
* Available at http://rg3.github.io/youtube-dl/ |
129 |
* |
130 |
* |
131 |
* The current code works on a/my samsung TV. I have not tested it further on other devices. |
132 |
* (I needed a quick fix, because I wanted to watch some video's. :) ) |
133 |
* |
134 |
* I thought I would share the results. |
135 |
* |
136 |
* Suggestions / feedback -> bas-patch@tcfaa.nl |
137 |
* |
138 |
* Regards, Bas Nedermeijer |
139 |
*/ |
122 |
|
140 |
|
123 |
int pipefd[2]; |
141 |
int pipefd[2]; |
124 |
pipe(pipefd); |
142 |
pipe(pipefd); |
125 |
|
143 |
|
126 |
if (fork() == 0) |
144 |
if (fork() == 0) |
127 |
{ |
145 |
{ |
128 |
close(pipefd[0]); // close reading end in the child |
146 |
close(pipefd[0]); |
129 |
|
147 |
|
130 |
dup2(pipefd[1], 1); // send stdout to the pipe |
148 |
dup2(pipefd[1], 1); |
131 |
dup2(pipefd[1], 2); // send stderr to the pipe |
149 |
dup2(pipefd[1], 2); |
132 |
|
150 |
|
133 |
close(pipefd[1]); // this descriptor is no longer needed |
151 |
close(pipefd[1]); |
134 |
|
152 |
|
135 |
execv("/usr/bin/youtube-dl") |
153 |
// This code assumes youtube-dl is available for usage. |
|
|
154 |
execl("/usr/bin/youtube-dl", "/usr/bin/youtube-dl","-g",watch.c_str(),NULL); |
136 |
} |
155 |
} |
137 |
else |
156 |
else |
138 |
{ |
157 |
{ |
139 |
// parent |
158 |
// parent |
140 |
// |
159 |
// |
141 |
char buffery[1024]; |
160 |
char buffery[8192]; |
|
|
161 |
memset(&buffery[0], 0, sizeof(buffery)); |
142 |
|
162 |
|
143 |
close(pipefd[1]); // close the write end of the pipe in the parent |
163 |
close(pipefd[1]); // close the write end of the pipe in the parent |
144 |
|
164 |
|
|
|
165 |
// Hopefully the read is never called twice, otherwise the buffer will become corrupt. |
145 |
while (read(pipefd[0], buffery, sizeof(buffery)) != 0) |
166 |
while (read(pipefd[0], buffery, sizeof(buffery)) != 0) |
146 |
{ |
167 |
{ |
147 |
} |
168 |
} |
148 |
|
169 |
|
149 |
String result = _(buffery) |
170 |
log_debug("------> GOT BUFFER %s\n", buffery); |
|
|
171 |
String result = _(buffery); |
150 |
|
172 |
|
151 |
return result |
173 |
result = trim_string(result); |
|
|
174 |
|
175 |
log_debug("------> GOT BUFFER (after trimming) %s\n", result.c_str()); |
176 |
|
177 |
return result; |
152 |
} |
178 |
} |
153 |
|
179 |
|
154 |
|
180 |
|
Lines 202-208
Link Here
|
202 |
params = _(YOUTUBE_URL_GET) + YOUTUBE_URL_PARAM_VIDEO_ID + '=' + |
228 |
params = _(YOUTUBE_URL_GET) + YOUTUBE_URL_PARAM_VIDEO_ID + '=' + |
203 |
video_id + '&' + YOUTUBE_URL_PARAM_T + '=' + params; |
229 |
video_id + '&' + YOUTUBE_URL_PARAM_T + '=' + params; |
204 |
|
230 |
|
205 |
#endif |
|
|
206 |
|
231 |
|
207 |
if (mp4) |
232 |
if (mp4) |
208 |
{ |
233 |
{ |
Lines 240-245
Link Here
|
240 |
} |
265 |
} |
241 |
|
266 |
|
242 |
throw _Exception(_("Could not retrieve YouTube video URL")); |
267 |
throw _Exception(_("Could not retrieve YouTube video URL")); |
|
|
268 |
#endif |
243 |
} |
269 |
} |
244 |
|
270 |
|
245 |
#endif//YOUTUBE |
271 |
#endif//YOUTUBE |