List of usage examples for com.google.api.client.googleapis.media MediaHttpDownloader getDownloadState
public DownloadState getDownloadState()
From source file:api.Captions.java
License:Apache License
/** * Saves caption track to file. (Not permitted for most videos.) * * @param captionId id//w ww .j a v a 2 s.co m * @throws IOException (can be thrown by caption.download method) */ private static void downloadCaption(String captionId) throws IOException { Download captionDownload = yt.captions().download(captionId).setTfmt(SRT); MediaHttpDownloader downloader = captionDownload.getMediaHttpDownloader(); downloader.setDirectDownloadEnabled(false); MediaHttpDownloaderProgressListener downloadProgressListener = new MediaHttpDownloaderProgressListener() { public void progressChanged(MediaHttpDownloader downloader) throws IOException { switch (downloader.getDownloadState()) { case MEDIA_IN_PROGRESS: System.out.println("Download in progress"); System.out.println("Download percentage: " + downloader.getProgress()); break; // This value is set after the entire media file has // been successfully downloaded. case MEDIA_COMPLETE: System.out.println("Download Completed!"); break; // This value indicates that the download process has // not started yet. case NOT_STARTED: System.out.println("Download Not Started!"); break; } } }; downloader.setProgressListener(downloadProgressListener); OutputStream outputFile = new FileOutputStream("captionFile.srt"); captionDownload.executeAndDownloadTo(outputFile); }
From source file:au.com.tyo.services.android.google.FileDownloadProgressListener.java
License:Apache License
@Override public void progressChanged(MediaHttpDownloader downloader) { if (downloader.getDownloadState() == MediaHttpDownloader.DownloadState.MEDIA_IN_PROGRESS) { } else if (downloader.getDownloadState() == MediaHttpDownloader.DownloadState.MEDIA_COMPLETE) { }/* www . java 2 s .c o m*/ }
From source file:com.datafrog.mms.bak.FileDownloadProgressListener.java
License:Apache License
@Override public void progressChanged(final MediaHttpDownloader downloader) { switch (downloader.getDownloadState()) { case MEDIA_IN_PROGRESS: View.header2("Download is in progress: " + downloader.getProgress()); break;/* w w w . j a v a 2 s . c o m*/ case MEDIA_COMPLETE: View.header2("Download is Complete!"); break; } }
From source file:com.github.valentin.fedoskin.fb2me.desktop.drive.FileDownloadProgressListener.java
License:Apache License
@Override public void progressChanged(MediaHttpDownloader downloader) { switch (downloader.getDownloadState()) { case MEDIA_IN_PROGRESS: DriveView.header2("Download is in progress: " + downloader.getProgress()); break;//www .j a v a 2 s.c o m case MEDIA_COMPLETE: DriveView.header2("Download is Complete!"); break; } }
From source file:com.jiubang.go.backup.pro.net.sync.FileDownloadProgressListener.java
License:Apache License
@Override public void progressChanged(MediaHttpDownloader downloader) { switch (downloader.getDownloadState()) { case MEDIA_IN_PROGRESS: if (mListener != null) { mListener.onProgress(downloader.getNumBytesDownloaded(), mFile.getFileSize(), null); }// w w w . j av a 2s . c o m break; case MEDIA_COMPLETE: break; } }
From source file:com.mrmq.uyoutube.data.Captions.java
License:Apache License
/** * Downloads a caption track for a YouTube video. (captions.download) * * @param captionId The id parameter specifies the caption ID for the resource * that is being downloaded. In a caption resource, the id property specifies the * caption track's ID.//from w w w . j ava 2s .co m * @throws IOException */ private static void downloadCaption(String captionId) throws IOException { // Create an API request to the YouTube Data API's captions.download // method to download an existing caption track. Download captionDownload = youtube.captions().download(captionId).setTfmt(SRT); // Set the download type and add an event listener. MediaHttpDownloader downloader = captionDownload.getMediaHttpDownloader(); // Indicate whether direct media download is enabled. A value of // "True" indicates that direct media download is enabled and that // the entire media content will be downloaded in a single request. // A value of "False," which is the default, indicates that the // request will use the resumable media download protocol, which // supports the ability to resume a download operation after a // network interruption or other transmission failure, saving // time and bandwidth in the event of network failures. downloader.setDirectDownloadEnabled(false); // Set the download state for the caption track file. MediaHttpDownloaderProgressListener downloadProgressListener = new MediaHttpDownloaderProgressListener() { @Override public void progressChanged(MediaHttpDownloader downloader) throws IOException { switch (downloader.getDownloadState()) { case MEDIA_IN_PROGRESS: System.out.println("Download in progress"); System.out.println("Download percentage: " + downloader.getProgress()); break; // This value is set after the entire media file has // been successfully downloaded. case MEDIA_COMPLETE: System.out.println("Download Completed!"); break; // This value indicates that the download process has // not started yet. case NOT_STARTED: System.out.println("Download Not Started!"); break; } } }; downloader.setProgressListener(downloadProgressListener); OutputStream outputFile = new FileOutputStream("captionFile.srt"); // Download the caption track. captionDownload.executeAndDownloadTo(outputFile); }
From source file:de.jlo.talendcomp.google.drive.DriveHelper.java
License:Apache License
private void downloadByUrl(String fileDownloadUrl, String localFilePath, boolean createDirs) throws Exception { checkPrerequisits();//from w ww. j av a 2 s . c o m lastDownloadedFilePath = null; lastDownloadedFileSize = 0; File localFile = new File(localFilePath); if (createDirs && localFile.getParentFile().exists() == false) { if (localFile.getParentFile().mkdirs() == false) { throw new Exception("Unable to create parent directory: " + localFile.getParent()); } } OutputStream fileOut = new BufferedOutputStream(new FileOutputStream(localFile)); try { MediaHttpDownloader downloader = new MediaHttpDownloader(HTTP_TRANSPORT, driveService.getRequestFactory().getInitializer()); downloader.setDirectDownloadEnabled(false); downloader.setProgressListener(new MediaHttpDownloaderProgressListener() { @Override public void progressChanged(MediaHttpDownloader downloader) throws IOException { info("File status: " + downloader.getDownloadState()); info("Bytes downloaded:" + downloader.getNumBytesDownloaded()); } }); downloader.download(new GenericUrl(fileDownloadUrl), fileOut); if (fileOut != null) { fileOut.flush(); fileOut.close(); fileOut = null; } lastDownloadedFilePath = localFile.getAbsolutePath(); lastDownloadedFileSize = localFile.length(); } catch (Exception e) { if (fileOut != null) { fileOut.flush(); fileOut.close(); fileOut = null; } Thread.sleep(200); if (localFile.canWrite()) { System.err.println("Download failed. Remove incomplete file: " + localFile.getAbsolutePath()); localFile.delete(); } throw e; } }
From source file:Diary.FileDownloadProgressListener.java
License:Apache License
@Override public void progressChanged(MediaHttpDownloader downloader) { switch (downloader.getDownloadState()) { case MEDIA_IN_PROGRESS: //DriveSample.downloadstatus.setText("Download is in progress:"); View.header1("Download is in progress: " + downloader.getProgress()); break;/*from w w w . j a v a2 s .co m*/ case MEDIA_COMPLETE: //DriveSample.downloadstatus.setText("Download is Complete "); View.header1("Download is Complete "); break; } }
From source file:gnomezgrave.gsyncj.local.FileDownloadProgressListener.java
License:Apache License
@Override public void progressChanged(MediaHttpDownloader downloader) { switch (downloader.getDownloadState()) { case MEDIA_IN_PROGRESS: System.out.println("Download is in progress: " + downloader.getProgress()); break;/*ww w .j a v a 2s.co m*/ case MEDIA_COMPLETE: System.out.println("Download is Complete!"); break; } }
From source file:google.drive.example.v2.cmdline.FileDownloadProgressListener.java
License:Apache License
@Override public void progressChanged(MediaHttpDownloader downloader) { switch (downloader.getDownloadState()) { case MEDIA_IN_PROGRESS: View.header2("Download is in progress: " + downloader.getProgress()); break;/*from www. j a v a 2 s. c o m*/ case MEDIA_COMPLETE: View.header2("Download is Complete!"); break; } }