at.huber.youtubeExtractor.YouTubeExtractor Java Examples
The following examples show how to use
at.huber.youtubeExtractor.YouTubeExtractor.
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: 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 #3
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 #4
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); }