Search in sources :

Example 1 with HttpDownloader

use of de.danoeh.antennapod.core.service.download.HttpDownloader in project AntennaPod by AntennaPod.

the class HttpDownloaderTest method download.

private Downloader download(String url, String title, boolean expectedResult, boolean deleteExisting, String username, String password, boolean deleteOnFail) {
    FeedFile feedFile = setupFeedFile(url, title, deleteExisting);
    DownloadRequest request = new DownloadRequest(feedFile.getFile_url(), url, title, 0, feedFile.getTypeAsInt(), username, password, deleteOnFail, null, false);
    Downloader downloader = new HttpDownloader(request);
    downloader.call();
    DownloadStatus status = downloader.getResult();
    assertNotNull(status);
    assertEquals(expectedResult, status.isSuccessful());
    assertTrue(status.isDone());
    // the file should not exist if the download has failed and deleteExisting was true
    assertTrue(!deleteExisting || new File(feedFile.getFile_url()).exists() == expectedResult);
    return downloader;
}
Also used : HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) FeedFile(de.danoeh.antennapod.model.feed.FeedFile) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) Downloader(de.danoeh.antennapod.core.service.download.Downloader) HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) File(java.io.File) FeedFile(de.danoeh.antennapod.model.feed.FeedFile)

Example 2 with HttpDownloader

use of de.danoeh.antennapod.core.service.download.HttpDownloader in project AntennaPod by AntennaPod.

the class OnlineFeedViewActivity method startFeedDownload.

private void startFeedDownload(String url) {
    Log.d(TAG, "Starting feed download");
    url = URLChecker.prepareURL(url);
    feed = new Feed(url, null);
    String fileUrl = new File(getExternalCacheDir(), FileNameGenerator.generateFileName(feed.getDownload_url())).toString();
    feed.setFile_url(fileUrl);
    final DownloadRequest request = new DownloadRequest(feed.getFile_url(), feed.getDownload_url(), "OnlineFeed", 0, Feed.FEEDFILETYPE_FEED, username, password, true, null, true);
    download = Observable.fromCallable(() -> {
        feeds = DBReader.getFeedList();
        downloader = new HttpDownloader(request);
        downloader.call();
        return downloader.getResult();
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::checkDownloadResult, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Spannable(android.text.Spannable) DownloadRequestCreator(de.danoeh.antennapod.core.service.download.DownloadRequestCreator) FeedListUpdateEvent(de.danoeh.antennapod.event.FeedListUpdateEvent) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) StringUtils(org.apache.commons.lang3.StringUtils) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) FeedItemlistDescriptionAdapter(de.danoeh.antennapod.adapter.FeedItemlistDescriptionAdapter) FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) UnsupportedFeedtypeException(de.danoeh.antennapod.parser.feed.UnsupportedFeedtypeException) Map(java.util.Map) HtmlToPlainText(de.danoeh.antennapod.core.util.syndication.HtmlToPlainText) View(android.view.View) UiThread(androidx.annotation.UiThread) Schedulers(io.reactivex.schedulers.Schedulers) AdapterView(android.widget.AdapterView) ForegroundColorSpan(android.text.style.ForegroundColorSpan) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) Log(android.util.Log) OnlinefeedviewActivityBinding(de.danoeh.antennapod.databinding.OnlinefeedviewActivityBinding) CombinedSearcher(de.danoeh.antennapod.discovery.CombinedSearcher) PlaybackService(de.danoeh.antennapod.core.service.playback.PlaybackService) NavUtils(androidx.core.app.NavUtils) IntentUtils(de.danoeh.antennapod.core.util.IntentUtils) DownloadError(de.danoeh.antennapod.core.util.DownloadError) FileNameGenerator(de.danoeh.antennapod.core.util.FileNameGenerator) FeedDiscoverer(de.danoeh.antennapod.core.util.syndication.FeedDiscoverer) ThreadMode(org.greenrobot.eventbus.ThreadMode) ViewGroup(android.view.ViewGroup) FeedHandlerResult(de.danoeh.antennapod.parser.feed.FeedHandlerResult) FeedUrlNotFoundException(de.danoeh.antennapod.core.feed.FeedUrlNotFoundException) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) DownloadEvent(de.danoeh.antennapod.core.event.DownloadEvent) Snackbar(com.google.android.material.snackbar.Snackbar) Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) AuthenticationDialog(de.danoeh.antennapod.dialog.AuthenticationDialog) Maybe(io.reactivex.Maybe) Dialog(android.app.Dialog) Intent(android.content.Intent) ApGlideSettings(de.danoeh.antennapod.core.glide.ApGlideSettings) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) FastBlurTransformation(de.danoeh.antennapod.core.glide.FastBlurTransformation) Toast(android.widget.Toast) EventBus(org.greenrobot.eventbus.EventBus) StorageUtils(de.danoeh.antennapod.core.util.StorageUtils) Observable(io.reactivex.Observable) Feed(de.danoeh.antennapod.model.feed.Feed) DialogInterface(android.content.DialogInterface) Downloader(de.danoeh.antennapod.core.service.download.Downloader) RequestOptions(com.bumptech.glide.request.RequestOptions) SpannableString(android.text.SpannableString) R(de.danoeh.antennapod.R) PodcastSearcherRegistry(de.danoeh.antennapod.discovery.PodcastSearcherRegistry) TextUtils(android.text.TextUtils) IOException(java.io.IOException) LightingColorFilter(android.graphics.LightingColorFilter) File(java.io.File) ArrayAdapter(android.widget.ArrayAdapter) PodcastSearchResult(de.danoeh.antennapod.discovery.PodcastSearchResult) Glide(com.bumptech.glide.Glide) PlaybackPreferences(de.danoeh.antennapod.core.preferences.PlaybackPreferences) Subscribe(org.greenrobot.eventbus.Subscribe) SharedPreferences(android.content.SharedPreferences) DBWriter(de.danoeh.antennapod.core.storage.DBWriter) URLChecker(de.danoeh.antennapod.core.util.URLChecker) DisposableMaybeObserver(io.reactivex.observers.DisposableMaybeObserver) DBReader(de.danoeh.antennapod.core.storage.DBReader) RemoteMedia(de.danoeh.antennapod.model.playback.RemoteMedia) PlayerStatusEvent(de.danoeh.antennapod.event.PlayerStatusEvent) DownloadService(de.danoeh.antennapod.core.service.download.DownloadService) FeedHandler(de.danoeh.antennapod.parser.feed.FeedHandler) HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) SpannableString(android.text.SpannableString) File(java.io.File) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 3 with HttpDownloader

use of de.danoeh.antennapod.core.service.download.HttpDownloader in project AntennaPod by AntennaPod.

the class HttpDownloaderTest method testCancel.

@Test
public void testCancel() {
    final String url = httpServer.getBaseUrl() + "/delay/3";
    FeedFileImpl feedFile = setupFeedFile(url, "delay", true);
    final Downloader downloader = new HttpDownloader(new DownloadRequest(feedFile.getFile_url(), url, "delay", 0, feedFile.getTypeAsInt(), null, null, true, null, false));
    Thread t = new Thread() {

        @Override
        public void run() {
            downloader.call();
        }
    };
    t.start();
    downloader.cancel();
    try {
        t.join();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    DownloadStatus result = downloader.getResult();
    assertTrue(result.isDone());
    assertFalse(result.isSuccessful());
    assertTrue(result.isCancelled());
    assertFalse(new File(feedFile.getFile_url()).exists());
}
Also used : HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) Downloader(de.danoeh.antennapod.core.service.download.Downloader) HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) File(java.io.File) FeedFile(de.danoeh.antennapod.model.feed.FeedFile) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Aggregations

DownloadRequest (de.danoeh.antennapod.core.service.download.DownloadRequest)3 DownloadStatus (de.danoeh.antennapod.core.service.download.DownloadStatus)3 Downloader (de.danoeh.antennapod.core.service.download.Downloader)3 HttpDownloader (de.danoeh.antennapod.core.service.download.HttpDownloader)3 File (java.io.File)3 Dialog (android.app.Dialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 LightingColorFilter (android.graphics.LightingColorFilter)1 Bundle (android.os.Bundle)1 Spannable (android.text.Spannable)1 SpannableString (android.text.SpannableString)1 TextUtils (android.text.TextUtils)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 Log (android.util.Log)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1