--- mediatomb-0.12.1.orig/src/youtube_video_url.cc 2013-12-17 22:46:24.272442249 +0000 +++ mediatomb-0.12.1/src/youtube_video_url.cc 2013-12-17 22:57:25.968039083 +0000 @@ -117,89 +117,68 @@ String YouTubeVideoURL::getVideoURL(Stri watch = _(YOUTUBE_URL_WATCH) + video_id; - Ref url(new URL(YOUTUBE_PAGESIZE)); + /* + * NOTE ON PATCH: + * + * The original code does not seem to work anymore. + * + * I have commented-out all the original code, and instead + * replaced it with a call/exec to youtube-dl (this is a separate/stand-alone python script). + * + * Available at http://rg3.github.io/youtube-dl/ + * + * + * The current code works on a/my samsung TV. I have not tested it further on other devices. + * (I needed a quick fix, because I wanted to watch some video's. :) ) + * + * I thought I would share the results. + * + * Suggestions / feedback -> bas-patch@tcfaa.nl + * + * Regards, Bas Nedermeijer + */ + + int pipefd[2]; + pipe(pipefd); + + if (fork() == 0) + { + // close reading end in the child + close(pipefd[0]); + + // send stdout to the pipe + dup2(pipefd[1], 1); + // send stderr to the pipe + dup2(pipefd[1], 2); - Ref buffer = url->download(watch, &retcode, curl_handle, - false, verbose, true); - if (retcode != 200) - { - throw _Exception(_("Failed to get URL for video with id ") - + watch + _("HTTP response code: ") + - String::from(retcode)); - } + // this descriptor is no longer needed + close(pipefd[1]); - log_debug("------> GOT BUFFER %s\n", buffer->toString().c_str()); - - Ref matcher = reVideoURLParams->matcher(buffer->toString()); - String params; - if (matcher->next()) - { -// params = trim_string(matcher->group(1)); - params = trim_string( matcher->group( 0 ) ); - /* - int brace = params.index( '{' ); - if ( brace > 0 ) - params = params.substring( brace ); - brace = params.index( '}' ); - if ( brace > 0 ) - params = params.substring( 0, brace + 1 ); - */ - Ref m2 = param_t->matcher(params); - if (m2->next()) - { - String hmm = m2->group(1); - if (string_ok(hmm)) - params = hmm; - else - { - throw _Exception(_("Could not retrieve \"t\" parameter.")); - } - } + // This code assumes youtube-dl is available for usage. + execl("/usr/bin/youtube-dl", "/usr/bin/youtube-dl","-g",watch.c_str(),NULL); } else { - throw _Exception(_("Failed to get URL for video with id (step 1)") + video_id); - } + // parent + char buffery[8192]; + memset(&buffery[0], 0, sizeof(buffery)); - params = _(YOUTUBE_URL_GET) + YOUTUBE_URL_PARAM_VIDEO_ID + '=' + - video_id + '&' + YOUTUBE_URL_PARAM_T + '=' + params; + close(pipefd[1]); // close the write end of the pipe in the parent - if (mp4) - { - String format = _("&fmt=18"); - - if (hd) + // Hopefully the read is never called twice, otherwise the buffer will become corrupt. + while (read(pipefd[0], buffery, sizeof(buffery)) != 0) { - matcher = HD->matcher(buffer->toString()); - if (matcher->next()) - { - if (trim_string(matcher->group(1)) == "true") - format = _("&fmt=22"); - } } - - params = params + format; - } - buffer = url->download(params, &retcode, curl_handle, true, verbose, true); + log_debug("------> GOT BUFFER %s\n", buffery); + String result = _(buffery); - matcher = redirectLocation->matcher(buffer->toString()); - if (matcher->next()) - { - if (string_ok(trim_string(matcher->group(1)))) - return trim_string(matcher->group(1)); - else - throw _Exception(_("Failed to get URL for video with id (step 2)")+ - video_id); - } + result = trim_string(result); - if (retcode != 303) - { - throw _Exception(_("Unexpected reply from YouTube: ") + - String::from(retcode)); - } + log_debug("------> GOT BUFFER (after trimming) %s\n", result.c_str()); - throw _Exception(_("Could not retrieve YouTube video URL")); + return result; + } } #endif//YOUTUBE