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

Commit

Permalink
Bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
nhCoder committed Nov 1, 2020
1 parent 74127fe commit 18d5e56
Show file tree
Hide file tree
Showing 45 changed files with 2,513 additions and 2,385 deletions.
2 changes: 1 addition & 1 deletion YoutubeExtractor/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ android {
dependencies {
compile 'com.google.code.gson:gson:2.8.5'
compile 'com.linsea:universalvideoview:1.1.0@aar'
compile 'org.mozilla:rhino:1.7R4'
compile 'org.mozilla:rhino:1.7.10'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
72 changes: 72 additions & 0 deletions YoutubeExtractor/app/build/bin/aapt_rules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# view res/layout/abc_alert_dialog_material.xml #generated:130
-keep class android.support.v4.widget.Space { <init>(...); }

# view res/layout/abc_action_menu_item_layout.xml #generated:17
-keep class android.support.v7.internal.view.menu.ActionMenuItemView { <init>(...); }

# view res/layout/abc_expanded_menu_layout.xml #generated:17
-keep class android.support.v7.internal.view.menu.ExpandedMenuView { <init>(...); }

# view res/layout/abc_list_menu_item_layout.xml #generated:17
# view res/layout/abc_popup_menu_item_layout.xml #generated:17
-keep class android.support.v7.internal.view.menu.ListMenuItemView { <init>(...); }

# view res/layout/abc_screen_toolbar.xml #generated:27
-keep class android.support.v7.internal.widget.ActionBarContainer { <init>(...); }

# view res/layout/abc_action_mode_bar.xml #generated:19
# view res/layout/abc_screen_toolbar.xml #generated:43
-keep class android.support.v7.internal.widget.ActionBarContextView { <init>(...); }

# view res/layout/abc_screen_toolbar.xml #generated:17
-keep class android.support.v7.internal.widget.ActionBarOverlayLayout { <init>(...); }

# view res/layout/abc_activity_chooser_view.xml #generated:19
-keep class android.support.v7.internal.widget.ActivityChooserView$InnerLayout { <init>(...); }

# view res/layout/abc_screen_content_include.xml #generated:19
-keep class android.support.v7.internal.widget.ContentFrameLayout { <init>(...); }

# view res/layout/abc_alert_dialog_material.xml #generated:48
-keep class android.support.v7.internal.widget.DialogTitle { <init>(...); }

# view res/layout/abc_screen_simple_overlay_action_mode.xml #generated:23
-keep class android.support.v7.internal.widget.FitWindowsFrameLayout { <init>(...); }

# view res/layout/abc_dialog_title_material.xml #generated:22
# view res/layout/abc_screen_simple.xml #generated:17
-keep class android.support.v7.internal.widget.FitWindowsLinearLayout { <init>(...); }

# view res/layout/abc_action_mode_close_item_material.xml #generated:17
# view res/layout/abc_search_dropdown_item_icons_2line.xml #generated:27
# view res/layout/abc_search_dropdown_item_icons_2line.xml #generated:37
# view res/layout/abc_search_dropdown_item_icons_2line.xml #generated:48
# view res/layout/abc_search_view.xml #generated:116
# view res/layout/abc_search_view.xml #generated:128
# view res/layout/abc_search_view.xml #generated:38
# view res/layout/abc_search_view.xml #generated:60
# view res/layout/abc_search_view.xml #generated:97
-keep class android.support.v7.internal.widget.TintImageView { <init>(...); }

# view res/layout/abc_screen_simple.xml #generated:25
# view res/layout/abc_screen_simple_overlay_action_mode.xml #generated:32
-keep class android.support.v7.internal.widget.ViewStubCompat { <init>(...); }

# view res/layout/abc_action_menu_layout.xml #generated:17
-keep class android.support.v7.widget.ActionMenuView { <init>(...); }

# view res/layout/abc_search_view.xml #generated:78
-keep class android.support.v7.widget.SearchView$SearchAutoComplete { <init>(...); }

# view res/layout/abc_screen_toolbar.xml #generated:36
-keep class android.support.v7.widget.Toolbar { <init>(...); }

# view AndroidManifest.xml #generated:19
-keep class com.naveed.ytextractor.MainActivity { <init>(...); }

# view res/layout/main.xml #generated:43
-keep class com.universalvideoview.UniversalMediaController { <init>(...); }

# view res/layout/main.xml #generated:35
-keep class com.universalvideoview.UniversalVideoView { <init>(...); }

Binary file removed YoutubeExtractor/app/build/bin/app.apk
Binary file not shown.
Binary file modified YoutubeExtractor/app/build/bin/classes.dex
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified YoutubeExtractor/app/build/bin/jardex/gson-2.8.5.jar.dex
Binary file not shown.
Binary file not shown.
Binary file modified YoutubeExtractor/app/build/bin/resources.ap_
Binary file not shown.
1,524 changes: 762 additions & 762 deletions YoutubeExtractor/app/build/gen/android/support/v7/appcompat/R.java

Large diffs are not rendered by default.

1,524 changes: 762 additions & 762 deletions YoutubeExtractor/app/build/gen/com/naveed/ytextractor/R.java

Large diffs are not rendered by default.

1,524 changes: 762 additions & 762 deletions YoutubeExtractor/app/build/gen/com/universalvideoview/R.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import java.util.Map;
import com.naveed.ytextractor.model.YTSubtitles;

public class YoutubeStreamExtractor extends AsyncTask<String,Void,Void> {
public class YoutubeStreamExtractor extends AsyncTask<String,Void,Void>
{


Map<String,String> Headers=new HashMap<>();
Expand All @@ -34,6 +35,7 @@ public class YoutubeStreamExtractor extends AsyncTask<String,Void,Void> {
String regexPageLink = ("(http|https)://(www\\.|m.|)youtube\\.com/watch\\?v=(.+?)( |\\z|&)");
String regexFindReason="(?<=(class=\"message\">)).*?(?=<)";
String regexPlayerJson="(?<=ytplayer.config\\s=).*?((\\}(\n|)\\}(\n|))|(\\}))(?=;)";
String PlayerBaseRegex="(?<=PLAYER_JS_URL\":\").*?(?=\")";
ExtractorListner listener;
private ExtractorException Ex;
List<String> reasonUnavialable=Arrays.asList(new String[]{"This video is unavailable on this device.","Content Warning","who has blocked it on copyright grounds."});
Expand All @@ -46,73 +48,92 @@ public class YoutubeStreamExtractor extends AsyncTask<String,Void,Void> {



public YoutubeStreamExtractor(ExtractorListner EL) {
public YoutubeStreamExtractor(ExtractorListner EL)
{
this.listener = EL;
Headers.put("Accept-Language", "en");
}

public YoutubeStreamExtractor setHeaders(Map<String, String> headers) {
public YoutubeStreamExtractor setHeaders(Map<String, String> headers)
{
Headers = headers;
return this;
}

public YoutubeStreamExtractor useDefaultLogin() {
public YoutubeStreamExtractor useDefaultLogin()
{
Headers.put("Cookie", Utils.loginCookie);
return setHeaders(Headers);
}

public Map<String, String> getHeaders() {
public Map<String, String> getHeaders()
{
return Headers;
}

public void Extract(String VideoId) {
public void Extract(String VideoId)
{
this.execute(VideoId);
}



@Override
protected void onPostExecute(Void result) {
if (Ex != null) {
protected void onPostExecute(Void result)
{
if (Ex != null)
{
listener.onExtractionGoesWrong(Ex);
} else {
listener.onExtractionDone(adaptiveMedia, muxedMedia,subtitle, ytmeta);
}
else
{
listener.onExtractionDone(adaptiveMedia, muxedMedia, subtitle, ytmeta);
}
}

@Override
protected void onPreExecute() {
protected void onPreExecute()
{
Ex = null;
adaptiveMedia.clear();
muxedMedia.clear();

}

@Override
protected void onCancelled() {
if (Ex != null) {
protected void onCancelled()
{
if (Ex != null)
{
listener.onExtractionGoesWrong(Ex);
}
}



@Override
protected Void doInBackground(String[] ids) {
protected Void doInBackground(String[] ids)
{

String Videoid=Utils.extractVideoID(ids[0]);
String jsonBody = null;
try {
try
{
String body = HTTPUtility.downloadPageSource("https://www.youtube.com/watch?v=" + Videoid + "&has_verified=1&bpctr=9999999999", Headers);
jsonBody = parsePlayerConfig(body);


PlayerResponse playerResponse=parseJson(jsonBody);
response.setPlayerJs(RegexUtils.matchGroup(PlayerBaseRegex, body));
ytmeta = playerResponse.getVideoDetails();
subtitle=playerResponse.getCaptions() !=null ? playerResponse .getCaptions().getPlayerCaptionsTracklistRenderer().getCaptionTracks(): null;
subtitle = playerResponse.getCaptions() != null ? playerResponse .getCaptions().getPlayerCaptionsTracklistRenderer().getCaptionTracks(): null;
//Utils.copyToBoard(jsonBody);
if (playerResponse.getVideoDetails().getisLive()) {
if (playerResponse.getVideoDetails().getisLive())
{
parseLiveUrls(playerResponse.getStreamingData());
} else {
}
else
{
StreamingData sd=playerResponse.getStreamingData();
LogUtils.log("sizea= " + sd.getAdaptiveFormats().length);
LogUtils.log("sizem= " + sd.getFormats().length);
Expand All @@ -124,7 +145,8 @@ protected Void doInBackground(String[] ids) {

}
}
catch (Exception e) {
catch (Exception e)
{
LogUtils.log(Arrays.toString(e.getStackTrace()));
Ex = new ExtractorException("Error While getting Youtube Data:" + e.getMessage());
this.cancel(true);
Expand All @@ -133,21 +155,27 @@ protected Void doInBackground(String[] ids) {
}

/*this function creates Json models using Gson*/
private PlayerResponse parseJson(String body) throws Exception {
private PlayerResponse parseJson(String body) throws Exception
{
JsonParser parser=new JsonParser();
response = new GsonBuilder().serializeNulls().create().fromJson(parser.parse(body), Response.class);
return new GsonBuilder().serializeNulls().create().fromJson(response.getArgs().getPlayerResponse(), PlayerResponse.class);
}

/*This function is used to check if webpage contain steam data and then gets the Json part of from the page using regex*/
private String parsePlayerConfig(String body) throws ExtractorException {
private String parsePlayerConfig(String body) throws ExtractorException
{

if (Utils.isListContain(reasonUnavialable, RegexUtils.matchGroup(regexFindReason, body))) {
if (Utils.isListContain(reasonUnavialable, RegexUtils.matchGroup(regexFindReason, body)))
{
throw new ExtractorException(RegexUtils.matchGroup(regexFindReason, body));
}
if (body.contains("ytplayer.config")) {
if (body.contains("ytplayer.config"))
{
return RegexUtils.matchGroup(regexPlayerJson, body);
} else {
}
else
{
throw new ExtractorException("This Video is unavialable");
}
}
Expand All @@ -157,48 +185,60 @@ private String parsePlayerConfig(String body) throws ExtractorException {

/*independent function Used to parse urls for adaptive & muxed stream with cipher protection*/

private List<YTMedia> parseUrls(YTMedia[] rawMedia) {
private List<YTMedia> parseUrls(YTMedia[] rawMedia)
{
List<YTMedia> links=new ArrayList<>();
try {
for (int x=0;x < rawMedia.length;x++) {
try
{
for (int x=0;x < rawMedia.length;x++)
{
YTMedia media=rawMedia[x];
LogUtils.log(media.getCipher() != null ? media.getCipher(): "null cip");
LogUtils.log(media.getSignatureCipher() != null ? media.getSignatureCipher(): "null cip");

if (media.useCipher()) {
if (media.useCipher())
{
String tempUrl = "";
String decodedSig = "";
for (String partCipher:media.getCipher().split("&")) {
for (String partCipher:media.getSignatureCipher().split("&"))
{



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

if (partCipher.startsWith("url=")) {
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());

for (String url_part:tempUrl.split("&"))
{
if (url_part.startsWith("s="))
{
decodedSig = CipherManager.dechiperSig(URLDecoder.decode(url_part.replace("s=", "")), response.getPlayerJs());
}
}
}
}

String FinalUrl= tempUrl + "&sig=" + decodedSig;

media.setUrl(FinalUrl);
links.add(media);


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

}
catch (Exception e) {
catch (Exception e)
{
Ex = new ExtractorException(e.getMessage());
this.cancel(true);
}
Expand All @@ -211,29 +251,37 @@ private List<YTMedia> parseUrls(YTMedia[] rawMedia) {

/*This funtion parse live youtube videos links from streaming data */

private void parseLiveUrls(StreamingData streamData) throws Exception {
if (streamData.getHlsManifestUrl() == null) {
private void parseLiveUrls(StreamingData streamData) throws Exception
{
if (streamData.getHlsManifestUrl() == null)
{
throw new ExtractorException("No link for hls video");
}
String hlsPageSource=HTTPUtility.downloadPageSource(streamData.getHlsManifestUrl());
String regexhlsLinks="(#EXT-X-STREAM-INF).*?(index.m3u8)";
List<String> rawData= RegexUtils.getAllMatches(regexhlsLinks, hlsPageSource);
for (String data:rawData) {
for (String data:rawData)
{
YTMedia media=new YTMedia();
String[] info_list=RegexUtils.matchGroup("(#).*?(?=https)", data).split(",");
String live_url=RegexUtils.matchGroup("(https:).*?(index.m3u8)", data);
media.setUrl(live_url);
for (String info:info_list) {
if (info.startsWith("BANDWIDTH")) {
for (String info:info_list)
{
if (info.startsWith("BANDWIDTH"))
{
media.setBitrate(Integer.valueOf(info.replace("BANDWIDTH=", "")));
}
if (info.startsWith("CODECS")) {
if (info.startsWith("CODECS"))
{
media.setMimeType((info.replace("CODECS=", "").replace("\"", "")));
}
if (info.startsWith("FRAME-RATE")) {
if (info.startsWith("FRAME-RATE"))
{
media.setFps(Integer.valueOf((info.replace("FRAME-RATE=", ""))));
}
if (info.startsWith("RESOLUTION")) {
if (info.startsWith("RESOLUTION"))
{
String[] RESOLUTION= info.replace("RESOLUTION=", "").split("x");
media.setWidth(Integer.valueOf(RESOLUTION[0]));
media.setHeight(Integer.valueOf(RESOLUTION[1]));
Expand All @@ -247,9 +295,10 @@ private void parseLiveUrls(StreamingData streamData) throws Exception {

}

public interface ExtractorListner {
public interface ExtractorListner
{
void onExtractionGoesWrong(ExtractorException e)
void onExtractionDone(List<YTMedia> adativeStream, List<YTMedia> muxedStream,List<YTSubtitles> subList, YoutubeMeta meta)
void onExtractionDone(List<YTMedia> adativeStream, List<YTMedia> muxedStream, List<YTSubtitles> subList, YoutubeMeta meta)
}

}
Loading

0 comments on commit 18d5e56

Please sign in to comment.