Search in sources :

Example 1 with FeedHandlerResult

use of de.danoeh.antennapod.parser.feed.FeedHandlerResult in project AntennaPod by AntennaPod.

the class FeedSyncTask method run.

public boolean run() {
    FeedParserTask task = new FeedParserTask(request);
    FeedHandlerResult result = task.call();
    downloadStatus = task.getDownloadStatus();
    if (!task.isSuccessful()) {
        return false;
    }
    savedFeed = DBTasks.updateFeed(context, result.feed, false);
    // If loadAllPages=true, check if another page is available and queue it for download
    final boolean loadAllPages = request.getArguments().getBoolean(DownloadRequest.REQUEST_ARG_LOAD_ALL_PAGES);
    final Feed feed = result.feed;
    if (loadAllPages && feed.getNextPageLink() != null) {
        feed.setId(savedFeed.getId());
        DBTasks.loadNextPageOfFeed(context, feed, true);
    }
    return true;
}
Also used : FeedHandlerResult(de.danoeh.antennapod.parser.feed.FeedHandlerResult) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 2 with FeedHandlerResult

use of de.danoeh.antennapod.parser.feed.FeedHandlerResult in project AntennaPod by AntennaPod.

the class FeedParserTask method call.

@Override
public FeedHandlerResult call() {
    Feed feed = new Feed(request.getSource(), request.getLastModified());
    feed.setFile_url(request.getDestination());
    feed.setId(request.getFeedfileId());
    feed.setDownloaded(true);
    feed.setPreferences(new FeedPreferences(0, true, FeedPreferences.AutoDeleteAction.GLOBAL, VolumeAdaptionSetting.OFF, request.getUsername(), request.getPassword()));
    feed.setPageNr(request.getArguments().getInt(DownloadRequest.REQUEST_ARG_PAGE_NR, 0));
    DownloadError reason = null;
    String reasonDetailed = null;
    FeedHandler feedHandler = new FeedHandler();
    FeedHandlerResult result = null;
    try {
        result = feedHandler.parseFeed(feed);
        Log.d(TAG, feed.getTitle() + " parsed");
        checkFeedData(feed);
    } catch (SAXException | IOException | ParserConfigurationException e) {
        successful = false;
        e.printStackTrace();
        reason = DownloadError.ERROR_PARSER_EXCEPTION;
        reasonDetailed = e.getMessage();
    } catch (UnsupportedFeedtypeException e) {
        e.printStackTrace();
        successful = false;
        reason = DownloadError.ERROR_UNSUPPORTED_TYPE;
        if ("html".equalsIgnoreCase(e.getRootElement())) {
            reason = DownloadError.ERROR_UNSUPPORTED_TYPE_HTML;
        }
        reasonDetailed = e.getMessage();
    } catch (InvalidFeedException e) {
        e.printStackTrace();
        successful = false;
        reason = DownloadError.ERROR_PARSER_EXCEPTION;
        reasonDetailed = e.getMessage();
    } finally {
        File feedFile = new File(request.getDestination());
        if (feedFile.exists()) {
            boolean deleted = feedFile.delete();
            Log.d(TAG, "Deletion of file '" + feedFile.getAbsolutePath() + "' " + (deleted ? "successful" : "FAILED"));
        }
    }
    if (successful) {
        downloadStatus = new DownloadStatus(feed, feed.getHumanReadableIdentifier(), DownloadError.SUCCESS, successful, reasonDetailed, request.isInitiatedByUser());
        return result;
    } else {
        downloadStatus = new DownloadStatus(feed, feed.getTitle(), reason, successful, reasonDetailed, request.isInitiatedByUser());
        return null;
    }
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) InvalidFeedException(de.danoeh.antennapod.core.util.InvalidFeedException) UnsupportedFeedtypeException(de.danoeh.antennapod.parser.feed.UnsupportedFeedtypeException) FeedHandlerResult(de.danoeh.antennapod.parser.feed.FeedHandlerResult) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) DownloadError(de.danoeh.antennapod.core.util.DownloadError) FeedHandler(de.danoeh.antennapod.parser.feed.FeedHandler) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) Feed(de.danoeh.antennapod.model.feed.Feed)

Aggregations

Feed (de.danoeh.antennapod.model.feed.Feed)2 FeedHandlerResult (de.danoeh.antennapod.parser.feed.FeedHandlerResult)2 DownloadStatus (de.danoeh.antennapod.core.service.download.DownloadStatus)1 DownloadError (de.danoeh.antennapod.core.util.DownloadError)1 InvalidFeedException (de.danoeh.antennapod.core.util.InvalidFeedException)1 FeedPreferences (de.danoeh.antennapod.model.feed.FeedPreferences)1 FeedHandler (de.danoeh.antennapod.parser.feed.FeedHandler)1 UnsupportedFeedtypeException (de.danoeh.antennapod.parser.feed.UnsupportedFeedtypeException)1 File (java.io.File)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXException (org.xml.sax.SAXException)1