Skip to content

Commit

Permalink
[desktop] yt parsing update.
Browse files Browse the repository at this point in the history
  • Loading branch information
gubatron committed Nov 10, 2015
1 parent 7c14484 commit dbea6c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,18 @@ private HashMap<Integer, String> getLinks(final String video, final boolean prem
fileNameFound = true;
}

String html5player = br.getRegex("(?s)(html5player\\-.+?\\.js)").getMatch(0);
YouTubeSig ytSig = getYouTubeSig("http://s.ytimg.com/yts/jsbin/" + html5player);
final String page = br.toString();
final String prefix = "<script src=\"//s.ytimg.com/yts/jsbin/player-";
final int startIndex = page.indexOf(prefix) + prefix.length();
final int endIndex = page.indexOf("/base.js\" name=\"player/base\"></script>", startIndex); //don't search from the start
final String playerId = page.substring(startIndex,
endIndex);
YouTubeSig ytSig = getYouTubeSig("http://s.ytimg.com/yts/jsbin/player-" + playerId + "/base.js");
currentYTSig = ytSig;

/* html5_fmt_map */
if (br.getRegex(FILENAME_PATTERN).count() != 0 && fileNameFound == false) {
filename = Encoding.htmlDecode(br.getRegex(FILENAME_PATTERN).getMatch(0).trim());
fileNameFound = true;
}

return parseLinks(br, video, filename, false, false, ytSig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private static JsObject extract_object(final JsContext ctx, String objname) {
}

private static LambdaN extract_function(final JsContext ctx, String funcname) {
String func_mRegex = String.format("(function %1$s|[\\{;]%1$s[ \\t\\n\\x0B\\f\\r]*=[ \\t\\n\\x0B\\f\\r]*function)", escape(funcname)) + "\\((?<args>[a-z,]+)\\)\\{(?<code>[^\\}]+)\\}";
String func_mRegex = String.format("(function %1$s|[\\{;][a-zA-Z0-9]+\\.%1$s[ \\t\\n\\x0B\\f\\r]*=[ \\t\\n\\x0B\\f\\r]*function)", escape(funcname)) + "\\((?<args>[a-z,]+)\\)\\{(?<code>[^\\}]+)\\}";
final Matcher func_m = Pattern.compile(func_mRegex).matcher(ctx.jscode);
if (!func_m.find()) {
throw new JsError("Could not find JS function " + funcname);
Expand Down

0 comments on commit dbea6c3

Please sign in to comment.