at.huber.youtubeExtractor.YtFile Java Examples
The following examples show how to use
at.huber.youtubeExtractor.YtFile.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DownloadSharedLinkActivity.java From YouTube-In-Background with MIT License | 7 votes |
private void getYoutubeDownloadUrl(String youtubeLink) { new YouTubeExtractor(this) { @Override public void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta vMeta) { mainProgressBar.setVisibility(View.GONE); if (ytFiles == null) { TextView tv = new TextView(getActivityContext()); tv.setText(R.string.app_update); tv.setMovementMethod(LinkMovementMethod.getInstance()); mainLayout.addView(tv); return; } formatsToShowList = new ArrayList<>(); for (int i = 0, itag; i < ytFiles.size(); i++) { itag = ytFiles.keyAt(i); YtFile ytFile = ytFiles.get(itag); if (ytFile.getFormat().getHeight() == -1 || ytFile.getFormat().getHeight() >= 360) { addFormatToList(ytFile, ytFiles); } } Collections.sort(formatsToShowList, new Comparator<YouTubeFragmentedVideo>() { @Override public int compare(YouTubeFragmentedVideo lhs, YouTubeFragmentedVideo rhs) { return lhs.height - rhs.height; } }); for (YouTubeFragmentedVideo files : formatsToShowList) { addButtonToMainLayout(vMeta.getTitle(), files); } } }.extract(youtubeLink, true, false); }
Example #2
Source File: Utils.java From YouTube-In-Background with MIT License | 5 votes |
/** * Get the best available audio stream * * @param ytFiles Array of available streams * @return Audio stream with highest bitrate */ public static YtFile getBestStream(SparseArray<YtFile> ytFiles) { // Log.e(TAG, "ytFiles: " + ytFiles); if (ytFiles.get(YOUTUBE_ITAG_141) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_141"); return ytFiles.get(YOUTUBE_ITAG_141); } else if (ytFiles.get(YOUTUBE_ITAG_140) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_140"); return ytFiles.get(YOUTUBE_ITAG_140); } else if (ytFiles.get(YOUTUBE_ITAG_251) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_251"); return ytFiles.get(YOUTUBE_ITAG_251); } else if (ytFiles.get(YOUTUBE_ITAG_250) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_250"); return ytFiles.get(YOUTUBE_ITAG_250); } else if (ytFiles.get(YOUTUBE_ITAG_249) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_249"); return ytFiles.get(YOUTUBE_ITAG_249); } else if (ytFiles.get(YOUTUBE_ITAG_171) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_171"); return ytFiles.get(YOUTUBE_ITAG_171); } else if (ytFiles.get(YOUTUBE_ITAG_18) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_18"); return ytFiles.get(YOUTUBE_ITAG_18); } else if (ytFiles.get(YOUTUBE_ITAG_22) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_22"); return ytFiles.get(YOUTUBE_ITAG_22); } else if (ytFiles.get(YOUTUBE_ITAG_43) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_43"); return ytFiles.get(YOUTUBE_ITAG_43); } else if (ytFiles.get(YOUTUBE_ITAG_36) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_36"); return ytFiles.get(YOUTUBE_ITAG_36); } LogHelper.e(TAG, " gets YOUTUBE_ITAG_17"); return ytFiles.get(YOUTUBE_ITAG_17); }
Example #3
Source File: DownloadActivity.java From YouTube-In-Background with MIT License | 5 votes |
private void getYoutubeDownloadUrl(String youtubeLink) { new YouTubeExtractor(this) { @Override public void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta vMeta) { mainProgressBar.setVisibility(View.GONE); if (ytFiles == null) { TextView tv = new TextView(getActivityContext()); tv.setText(R.string.app_update); tv.setMovementMethod(LinkMovementMethod.getInstance()); mainLayout.addView(tv); return; } formatsToShowList = new ArrayList<>(); for (int i = 0, itag; i < ytFiles.size(); i++) { itag = ytFiles.keyAt(i); YtFile ytFile = ytFiles.get(itag); if (ytFile.getFormat().getHeight() == -1 || ytFile.getFormat().getHeight() >= 360) { addFormatToList(ytFile, ytFiles); } } Collections.sort(formatsToShowList, new Comparator<YouTubeFragmentedVideo>() { @Override public int compare(YouTubeFragmentedVideo lhs, YouTubeFragmentedVideo rhs) { return lhs.height - rhs.height; } }); for (YouTubeFragmentedVideo files : formatsToShowList) { addButtonToMainLayout(vMeta.getTitle(), files); } } }.extract(youtubeLink, true, false); }
Example #4
Source File: BackgroundAudioService.java From YouTube-In-Background with MIT License | 5 votes |
/** * Get the best available audio stream * * @param ytFiles Array of available streams * @return Audio stream with highest bitrate */ private YtFile getBestStream(SparseArray<YtFile> ytFiles) { Log.e(TAG, "ytFiles: " + ytFiles); if (ytFiles.get(YOUTUBE_ITAG_141) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_141"); return ytFiles.get(YOUTUBE_ITAG_141); } else if (ytFiles.get(YOUTUBE_ITAG_140) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_140"); return ytFiles.get(YOUTUBE_ITAG_140); } else if (ytFiles.get(YOUTUBE_ITAG_251) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_251"); return ytFiles.get(YOUTUBE_ITAG_251); } else if (ytFiles.get(YOUTUBE_ITAG_250) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_250"); return ytFiles.get(YOUTUBE_ITAG_250); } else if (ytFiles.get(YOUTUBE_ITAG_249) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_249"); return ytFiles.get(YOUTUBE_ITAG_249); } else if (ytFiles.get(YOUTUBE_ITAG_171) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_171"); return ytFiles.get(YOUTUBE_ITAG_171); } else if (ytFiles.get(YOUTUBE_ITAG_18) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_18"); return ytFiles.get(YOUTUBE_ITAG_18); } else if (ytFiles.get(YOUTUBE_ITAG_22) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_22"); return ytFiles.get(YOUTUBE_ITAG_22); } else if (ytFiles.get(YOUTUBE_ITAG_43) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_43"); return ytFiles.get(YOUTUBE_ITAG_43); } else if (ytFiles.get(YOUTUBE_ITAG_36) != null) { LogHelper.e(TAG, " gets YOUTUBE_ITAG_36"); return ytFiles.get(YOUTUBE_ITAG_36); } LogHelper.e(TAG, " gets YOUTUBE_ITAG_17"); return ytFiles.get(YOUTUBE_ITAG_17); }
Example #5
Source File: YoutubeParserProxy.java From OneTapVideoDownload with GNU General Public License v3.0 | 5 votes |
public static void startParsing(final Context context, String param, final Invokable<Video, Integer> invokable) { YouTubeExtractor mYoutubeExtractor = new YouTubeExtractor(context) { @Override public void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta vMeta) { if (ytFiles != null) { YoutubeVideo video = new YoutubeVideo(vMeta.getTitle(), vMeta.getVideoId()); for(Pair p : YoutubeVideo.itagQualityMapping) { YtFile videoFormat = ytFiles.get(Integer.parseInt(p.first.toString())); if (videoFormat == null) { continue; } video.addFormat(videoFormat.getUrl(), Integer.parseInt(p.first.toString())); } try { invokable.invoke(video); } catch (java.lang.Exception e) { FirebaseCrash.report(e); e.printStackTrace(); } } else { Log.e(TAG, "URLs are empty"); } } }; Log.v(TAG, YOUTUBE_URL_PREFIX + param); mYoutubeExtractor.extract(YOUTUBE_URL_PREFIX + param, false, true); }
Example #6
Source File: BackgroundAudioService.java From YouTube-In-Background with MIT License | 4 votes |
/** * Extracts link from youtube video ID, so mediaPlayer can play it */ private void newExtractUrlAndPlay() { // LogHelper.e(TAG, "extractUrlAndPlay: extracting url for video id=" + currentVideo.getId()); final String youtubeLink = "https://youtube.com/watch?v=" + currentVideo.getId(); // LogHelper.e(TAG, youtubeLink); new YouTubeExtractor(this) { @Override public void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta videoMeta) { if (ytFiles == null) { Toast.makeText( getApplicationContext(), getResources().getString(R.string.toast_message_error_extracting, videoMeta.getTitle()), Toast.LENGTH_SHORT ).show(); return; } if (ytFiles != null) { YtFile ytFile = getBestStream(ytFiles); LogHelper.e(TAG, ytFile.getUrl()); if (ytFile != null && validateUrl(ytFile.getUrl())) { playOnFocusGain = true; currentPosition = 0; tryToGetAudioFocus(); registerAudioNoisyReceiver(); registerMediaButtonReceiver(); playState = PlaybackStateCompat.STATE_STOPPED; relaxResources(false); // release everything except MediaPlayer try { // LogHelper.e(TAG, "extractUrlAndPlay: Start playback"); createMediaPlayerIfNeeded(); playState = PlaybackStateCompat.STATE_BUFFERING; mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setDataSource(ytFile.getUrl()); mediaPlayer.setOnPreparedListener(backgroundAudioService); currentVideoTitle = videoMeta.getTitle(); // Starts preparing the media player in the background. When // it's done, it will call our OnPreparedListener (that is, // the onPrepared() method on this class, since we set the // listener to 'this'). Until the media player is prepared, // we *cannot* call start() on it! mediaPlayer.prepareAsync(); // If we are streaming from the internet, we want to hold a // Wifi lock, which prevents the Wifi radio from going to // sleep while the song is playing. wifiLock.acquire(); } catch (IOException io) { // LogHelper.e(TAG, io, "extractUrlAndPlay: Exception playing song"); io.printStackTrace(); } } else { // Log.e(TAG, "No Link found"); Toast.makeText( getApplicationContext(), getResources().getString(R.string.toast_message_error_playing_url, videoMeta.getTitle()), Toast.LENGTH_SHORT ).show(); } } } }.extract(youtubeLink, true, true); }
Example #7
Source File: BackgroundAudioService.java From YouTube-In-Background with MIT License | 4 votes |
/** * Extracts link from youtube video ID, so mediaPlayer can play it */ private void extractUrlAndPlay() { // LogHelper.e(TAG, "extractUrlAndPlay: extracting url for video id=" + currentVideo.getId()); final String youtubeLink = "http://youtube.com/watch?v=" + currentVideo.getId(); // LogHelper.e(TAG, youtubeLink); YouTubeUriExtractor ytEx = new YouTubeUriExtractor(this) { @Override public void onUrisAvailable(String videoId, final String videoTitle, SparseArray<YtFile> ytFiles) { if (ytFiles != null) { YtFile ytFile = getBestStream(ytFiles); playOnFocusGain = true; currentPosition = 0; tryToGetAudioFocus(); registerAudioNoisyReceiver(); playState = PlaybackStateCompat.STATE_STOPPED; relaxResources(false); // Release everything except MediaPlayer try { // LogHelper.e(TAG, ytFile.getUrl()); // LogHelper.e(TAG, "extractUrlAndPlay: Start playback"); createMediaPlayerIfNeeded(); playState = PlaybackStateCompat.STATE_BUFFERING; mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setDataSource(ytFile.getUrl()); mediaPlayer.setOnPreparedListener(backgroundAudioService); currentVideoTitle = videoTitle; // Starts preparing the media player in the background. When // it's done, it will call our OnPreparedListener (that is, // the onPrepared() method on this class, since we set the // listener to 'this'). Until the media player is prepared, // we *cannot* call start() on it! mediaPlayer.prepareAsync(); // If we are streaming from the internet, we want to hold a // Wifi lock, which prevents the Wifi radio from going to // sleep while the song is playing. wifiLock.acquire(); // mediaPlayer.start(); // if (callback != null) { // callback.onPlaybackStatusChanged(playState); // } } catch (IOException io) { // LogHelper.e(TAG, io, "extractUrlAndPlay: Exception playing song"); io.printStackTrace(); } } } }; // Ignore the webm container formatViewCount // ytEx.setIncludeWebM(false); // ytEx.setParseDashManifest(true); // Lets execute the request ytEx.execute(youtubeLink); }
Example #8
Source File: BackgroundAudioService.java From YouTube-In-Background with MIT License | 2 votes |
private void startPlayback(SparseArray<YtFile> ytFiles) { }