Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
Fixed where sometime failed to get urls
Browse files Browse the repository at this point in the history
  • Loading branch information
nhCoder committed Jan 4, 2020
1 parent 1df4b55 commit 65e2a0a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 21 deletions.
Binary file added YoutubeExtractor.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ public void onExtractionDone(List<YTMedia> adativeStream, final List<YTMedia> mu
}
//Toast.makeText(getApplicationContext(), meta.getTitle(), Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), meta.getAuthor(), Toast.LENGTH_LONG).show();

if (adativeStream.isEmpty()) {
LogUtils.log("null ha");
return;
}
if (muxedStream.isEmpty()) {
LogUtils.log("null ha");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected void onPostExecute(Void result) {
listener.onExtractionGoesWrong(Ex);
} else {
listener.onExtractionDone(adaptiveMedia, muxedMedia, ytmeta);
}
}
}

@Override
Expand Down Expand Up @@ -96,16 +96,25 @@ protected Void doInBackground(String[] ids) {
try {
String body = HTTPUtility.downloadPageSource("https://www.youtube.com/watch?v=" + Videoid + "&has_verified=1&bpctr=9999999999", Headers);
jsonBody = parsePlayerConfig(body);
//Utils.copyToBoard(jsonBody);

PlayerResponse playerResponse=parseJson(jsonBody);
ytmeta = playerResponse.getVideoDetails();
//Utils.copyToBoard(playerResponse.getStreamingData().);
if (playerResponse.getVideoDetails().getisLive()) {
parseLiveUrls(playerResponse.getStreamingData());
} else {
adaptiveMedia = parseUrls(playerResponse.getStreamingData().getAdaptiveFormats());
muxedMedia = parseUrls(playerResponse.getStreamingData().getFormats());
StreamingData sd=playerResponse.getStreamingData();
LogUtils.log("sizea= " + sd.getAdaptiveFormats().length);
LogUtils.log("sizem= " + sd.getFormats().length);

adaptiveMedia = parseUrls(sd.getAdaptiveFormats());
muxedMedia = parseUrls(sd.getFormats());
LogUtils.log("sizeXa= " + adaptiveMedia.size());
LogUtils.log("sizeXm= " + muxedMedia.size());

}
} catch (Exception e) {
}
catch (Exception e) {
LogUtils.log(Arrays.toString(e.getStackTrace()));// e.toString());
Ex = new ExtractorException("Error While getting Youtube Data:" + e.getMessage());
this.cancel(true);
Expand Down Expand Up @@ -143,34 +152,55 @@ private List<YTMedia> parseUrls(YTMedia[] rawMedia) {
try {
for (int x=0;x < rawMedia.length;x++) {
YTMedia media=rawMedia[x];
LogUtils.log(media.getCipher() != null ? media.getCipher(): "null cip");

if (media.useCipher()) {
String tempUrl=URLDecoder.decode(RegexUtils.matchGroup(regexUrl, media.getCipher()));
for (String url_part:tempUrl.split("&")) {
if (url_part.startsWith("s=")) {
String decodedSig=CipherManager.dechiperSig(URLDecoder.decode(url_part.replace("s=", "")), response.getAssets().getJs());
String FinalUrl;
if (tempUrl.contains("&lsig=")) {
FinalUrl = tempUrl + "&sig=" + decodedSig;
} else {
FinalUrl = tempUrl + "&signature=" + decodedSig;
String tempUrl = "";
String decodedSig = "";
for (String partCipher:media.getCipher().split("&")) {



if (partCipher.startsWith("s=")) {
decodedSig = CipherManager.dechiperSig(URLDecoder.decode(partCipher.replace("s=", "")), response.getAssets().getJs());
}

if (partCipher.startsWith("url=")) {
tempUrl=URLDecoder.decode(partCipher.replace("url=", ""));

for (String url_part:tempUrl.split("&")) {
if (url_part.startsWith("s=")) {
decodedSig = CipherManager.dechiperSig(URLDecoder.decode(url_part.replace("s=", "")), response.getAssets().getJs());
}
}
media.setUrl(FinalUrl);
links.add(media);
LogUtils.log(FinalUrl);
}
}
}else{

String FinalUrl;
if (tempUrl.contains("&lsig=")) {
FinalUrl = tempUrl + "&sig=" + decodedSig;
} else {
FinalUrl = tempUrl + "&signature=" + decodedSig;
}
media.setUrl(FinalUrl);
links.add(media);


} else {
links.add(media);
}
}

} catch (Exception e) {
}
catch (Exception e) {
Ex = new ExtractorException(e.getMessage());
this.cancel(true);
}
return links;
}





/*This funtion parse live youtube videos links from streaming data */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ public String getUrl()
}

public boolean useCipher(){
return cipher!=null && url==null;

return (cipher!=null && cipher.contains("s="));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;

public class Utils {

public static List<YTMedia> filterInvalidLinks(List<YTMedia> urls) {
List<YTMedia> workingLinks=new ArrayList<>();
for (YTMedia media:urls) {
Expand Down
Binary file removed app.apk
Binary file not shown.

0 comments on commit 65e2a0a

Please sign in to comment.