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

Commit

Permalink
Now extracts Videos Subtitles
Browse files Browse the repository at this point in the history
  • Loading branch information
nhCoder committed Jan 24, 2020
1 parent cd0ddf0 commit 6d87dc5
Show file tree
Hide file tree
Showing 66 changed files with 8,644 additions and 2,310 deletions.
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
YouTubeExtractor
**YouTubeExtractor**

A Youtube urls extractor for java & android for streaming and downloading purpose.

Expand All @@ -12,12 +12,12 @@ I made this on my Android Device using AIDE(IDE), So i cant update gradle, so do
- Extracts Live Videos Urls(hls)
- Extracts video info(title,author,description,view,etc)
- Extracts Age restricted videos (Uses Cookie from a Google account)
- Extracts YouTube Video Captions

Usage
### Usage

Copy the classes or compile project.
`Copy the classes or compile project.`

.jar will be available soon

## Dependencies Used
- Gson
Expand All @@ -27,15 +27,26 @@ Copy the classes or compile project.
Usage

```Java
new YoutubeStreamExtractor(new YoutubeStreamExtractor.ExtractorListner(){
@Override
public void onExtractionDone(List adativeStream, final List muxedStream, YoutubeMeta meta) {

new YoutubeStreamExtractor(new YoutubeStreamExtractor.ExtractorListner(){
@Override
public void onExtractionDone(List<YTMedia> adativeStream, final List<YTMedia> muxedStream,List<YTSubtitles> subtitles, YoutubeMeta meta) {
//url to get subtitle
String subUrl=subtitles.get(0).getBaseUrl();
for (YTMedia media:adativeStream) {
if(media.isVideo()){
//is video
}else{
//is audio
}
}
}
@Override
public void onExtractionGoesWrong(final ExtractorException e) {
public void onExtractionGoesWrong(final ExtractorException e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
}).Extract(YOUTUBE_ID / LINK);
}).useDefaultLogin().Extract(URL/YOUTUBE_ID);
//use .useDefaultLogin() to extract age restricted videos

```


Expand Down
Binary file modified 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 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/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.

6,220 changes: 6,220 additions & 0 deletions YoutubeExtractor/app/build/gen/com/avery/subtitle/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 @@ -6,24 +6,23 @@
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.naveed.ytextractor.model.YTMedia;
import com.naveed.ytextractor.model.YTSubtitles;
import com.naveed.ytextractor.model.YoutubeMeta;
import com.naveed.ytextractor.utils.ContextUtils;
import com.naveed.ytextractor.utils.LogUtils;
import com.naveed.ytextractor.utils.Utils;
import com.universalvideoview.UniversalMediaController;
import com.universalvideoview.UniversalVideoView;
import java.util.List;
import android.widget.ListAdapter;
import java.util.ArrayList;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView;
import android.widget.Adapter;
import com.naveed.ytextractor.utils.Utils;
import java.util.List;

public class MainActivity extends Activity {

Expand Down Expand Up @@ -67,6 +66,7 @@ protected void onCreate(Bundle savedInstanceState) {
mMediaController = (UniversalMediaController) findViewById(R.id.media_controller);
mVideoView.setMediaController(mMediaController);
mVideoView.setAutoRotation(false);

mVideoView.setVideoViewCallback(new UniversalVideoView.VideoViewCallback() {

//private boolean isFullscreen;
Expand Down Expand Up @@ -99,8 +99,9 @@ public void onBufferingEnd(MediaPlayer mediaPlayer) {// steam end loading
});
edit = (EditText)findViewById(R.id.mainEditText1);
btn = (Button)findViewById(R.id.mainButton1);
edit.setText("https://youtu.be/4GuqB1BQVr4");
edit.setText("https://youtu.be/zjMtaw2mrrc");
edit.setHint("id or url");

btn.setOnClickListener((new OnClickListener(){

@Override
Expand All @@ -110,15 +111,22 @@ public void onClick(View p1) {
new YoutubeStreamExtractor(new YoutubeStreamExtractor.ExtractorListner(){

@Override
public void onExtractionDone(List<YTMedia> adativeStream, final List<YTMedia> muxedStream, YoutubeMeta meta) {
public void onExtractionDone(List<YTMedia> adativeStream, final List<YTMedia> muxedStream,List<YTSubtitles> subtitles, YoutubeMeta meta) {

//url to get subtitle
//String subUrl=subtitles.get(0).getBaseUrl();



urls_li.clear();
for (YTMedia c:muxedStream) {

urls_li.add(c.getUrl());
adapter.notifyDataSetChanged();
}
for (YTMedia c:adativeStream) {
urls_li.add(c.getUrl());
for (YTMedia media:adativeStream) {

urls_li.add(media.getUrl());
adapter.notifyDataSetChanged();
}
//Toast.makeText(getApplicationContext(), meta.getTitle(), Toast.LENGTH_LONG).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.naveed.ytextractor.model.YTSubtitles;

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


Map<String,String> Headers=new HashMap<>();
List<YTMedia> adaptiveMedia=new ArrayList<>();
List<YTMedia> muxedMedia=new ArrayList<>();
List<YTSubtitles> subtitle=new ArrayList<>();
String regexUrl=("(?<=url=).*");
String regexYtshortLink="(http|https)://(www\\.|)youtu.be/.*";
String regexPageLink = ("(http|https)://(www\\.|m.|)youtube\\.com/watch\\?v=(.+?)( |\\z|&)");
Expand Down Expand Up @@ -74,7 +76,7 @@ protected void onPostExecute(Void result) {
if (Ex != null) {
listener.onExtractionGoesWrong(Ex);
} else {
listener.onExtractionDone(adaptiveMedia, muxedMedia, ytmeta);
listener.onExtractionDone(adaptiveMedia, muxedMedia,subtitle, ytmeta);
}
}

Expand Down Expand Up @@ -106,6 +108,7 @@ protected Void doInBackground(String[] ids) {

PlayerResponse playerResponse=parseJson(jsonBody);
ytmeta = playerResponse.getVideoDetails();
subtitle=playerResponse.getCaptions().getPlayerCaptionsTracklistRenderer().getCaptionTracks();
//Utils.copyToBoard(jsonBody);
if (playerResponse.getVideoDetails().getisLive()) {
parseLiveUrls(playerResponse.getStreamingData());
Expand Down Expand Up @@ -246,8 +249,7 @@ private void parseLiveUrls(StreamingData streamData) throws Exception {

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

void onExtractionDone(List<YTMedia> adativeStream, List<YTMedia> muxedStream,List<YTSubtitles> subList, YoutubeMeta meta)
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package com.naveed.ytextractor.model;
import java.util.List;

public class PlayerResponse {
private PlayabilityStatus playabilityStatus;
private StreamingData streamingData;
private YoutubeMeta videoDetails;
private Captions captions;

public void setCaptions(Captions captions) {
this.captions = captions;
}

public Captions getCaptions() {
return captions;
}
public void setPlayabilityStatus(PlayabilityStatus playabilityStatus) {
this.playabilityStatus = playabilityStatus;
}
Expand Down Expand Up @@ -33,8 +42,36 @@ public YoutubeMeta getVideoDetails() {



public class Captions{
private PlayerCaptionsTracklistRenderer playerCaptionsTracklistRenderer;

public void setPlayerCaptionsTracklistRenderer(PlayerCaptionsTracklistRenderer playerCaptionsTracklistRenderer) {
this.playerCaptionsTracklistRenderer = playerCaptionsTracklistRenderer;
}

public PlayerCaptionsTracklistRenderer getPlayerCaptionsTracklistRenderer() {
return playerCaptionsTracklistRenderer;
}



public class PlayerCaptionsTracklistRenderer{
private List<YTSubtitles> captionTracks;



public void setCaptionTracks(List<YTSubtitles> captionTracks) {
this.captionTracks = captionTracks;
}

public List<YTSubtitles> getCaptionTracks() {
return captionTracks;
}
}
}



public class PlayabilityStatus{
private String status;
private boolean playableInEmbed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ public class YTMedia
String audioQuality;
String url;
int fps;
boolean isVideo;


public boolean isVideo() {
return getMimeType().contains("video");
}

public void setFps(int fps) {
this.fps = fps;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.naveed.ytextractor.model;

public class YTSubtitles{
String baseUrl;
SubtitleName name;
String languageCode;
boolean isTranslatable;

public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}

public String getBaseUrl() {
return baseUrl;
}

public void setName(SubtitleName name) {
this.name = name;
}

public SubtitleName getName() {
return name;
}

public void setLanguageCode(String languageCode) {
this.languageCode = languageCode;
}

public String getLanguageCode() {
return languageCode;
}

public void setIsTranslatable(boolean isTranslatable) {
this.isTranslatable = isTranslatable;
}

public boolean isTranslatable() {
return isTranslatable;
}
public class SubtitleName{
String simpleText;
public void setSimpleText(String simpleText) {
this.simpleText = simpleText;
}

public String getSimpleText() {
return simpleText;
}
}
}

0 comments on commit 6d87dc5

Please sign in to comment.