mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-02-02 19:56:59 +01:00
Merge pull request #993 from mfietz/issue/990-show-content-length
Get filesize from server
This commit is contained in:
commit
6c4d7aaef3
@ -172,7 +172,7 @@ public class FeedHandlerTest extends InstrumentationTestCase {
|
|||||||
"http://example.com/items/" + i, new Date(i*60000), FeedItem.UNPLAYED, feed);
|
"http://example.com/items/" + i, new Date(i*60000), FeedItem.UNPLAYED, feed);
|
||||||
feed.getItems().add(item);
|
feed.getItems().add(item);
|
||||||
if (withFeedMedia) {
|
if (withFeedMedia) {
|
||||||
item.setMedia(new FeedMedia(0, item, 4711, 0, 100, "audio/mp3", null, "http://example.com/media-" + i,
|
item.setMedia(new FeedMedia(0, item, 4711, 0, 1024*1024, "audio/mp3", null, "http://example.com/media-" + i,
|
||||||
false, null, 0));
|
false, null, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,8 @@ public class DBTasksTest extends InstrumentationTestCase {
|
|||||||
SharedPreferences.Editor prefEdit = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()).edit();
|
SharedPreferences.Editor prefEdit = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()).edit();
|
||||||
prefEdit.putString(UserPreferences.PREF_EPISODE_CACHE_SIZE, Integer.toString(EPISODE_CACHE_SIZE));
|
prefEdit.putString(UserPreferences.PREF_EPISODE_CACHE_SIZE, Integer.toString(EPISODE_CACHE_SIZE));
|
||||||
prefEdit.commit();
|
prefEdit.commit();
|
||||||
|
|
||||||
|
UserPreferences.init(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FlakyTest(tolerance = 3)
|
@FlakyTest(tolerance = 3)
|
||||||
@ -261,7 +263,7 @@ public class DBTasksTest extends InstrumentationTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = NUM_ITEMS_OLD; i < NUM_ITEMS_NEW + NUM_ITEMS_OLD; i++) {
|
for (int i = NUM_ITEMS_OLD; i < NUM_ITEMS_NEW + NUM_ITEMS_OLD; i++) {
|
||||||
feed.getItems().add(0, new FeedItem(0, "item " + i, "id " + i, "link " + i, new Date(i), FeedItem.PLAYED, feed));
|
feed.getItems().add(0, new FeedItem(0, "item " + i, "id " + i, "link " + i, new Date(i), FeedItem.UNPLAYED, feed));
|
||||||
}
|
}
|
||||||
|
|
||||||
final Feed newFeed = DBTasks.updateFeed(context, feed)[0];
|
final Feed newFeed = DBTasks.updateFeed(context, feed)[0];
|
||||||
@ -275,7 +277,6 @@ public class DBTasksTest extends InstrumentationTestCase {
|
|||||||
updatedFeedTest(feedFromDB, feedID, itemIDs, NUM_ITEMS_OLD, NUM_ITEMS_NEW);
|
updatedFeedTest(feedFromDB, feedID, itemIDs, NUM_ITEMS_OLD, NUM_ITEMS_NEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FlakyTest(tolerance = 3)
|
|
||||||
private void updatedFeedTest(final Feed newFeed, long feedID, List<Long> itemIDs, final int NUM_ITEMS_OLD, final int NUM_ITEMS_NEW) {
|
private void updatedFeedTest(final Feed newFeed, long feedID, List<Long> itemIDs, final int NUM_ITEMS_OLD, final int NUM_ITEMS_NEW) {
|
||||||
assertTrue(newFeed.getId() == feedID);
|
assertTrue(newFeed.getId() == feedID);
|
||||||
assertTrue(newFeed.getItems().size() == NUM_ITEMS_NEW + NUM_ITEMS_OLD);
|
assertTrue(newFeed.getItems().size() == NUM_ITEMS_NEW + NUM_ITEMS_OLD);
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package de.danoeh.antennapod;
|
package de.danoeh.antennapod;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.asynctask.PicassoProvider;
|
import de.danoeh.antennapod.core.asynctask.PicassoProvider;
|
||||||
import de.danoeh.antennapod.core.feed.EventDistributor;
|
import de.danoeh.antennapod.core.feed.EventDistributor;
|
||||||
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
|
import de.danoeh.antennapod.core.service.FeedMediaSizeService;
|
||||||
import de.danoeh.antennapod.spa.SPAUtil;
|
import de.danoeh.antennapod.spa.SPAUtil;
|
||||||
|
|
||||||
/** Main application class. */
|
/** Main application class. */
|
||||||
@ -43,6 +45,8 @@ public class PodcastApp extends Application {
|
|||||||
EventDistributor.getInstance();
|
EventDistributor.getInstance();
|
||||||
|
|
||||||
SPAUtil.sendSPAppsQueryFeedsIntent(this);
|
SPAUtil.sendSPAppsQueryFeedsIntent(this);
|
||||||
|
|
||||||
|
startService(new Intent(this, FeedMediaSizeService.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getLogicalDensity() {
|
public static float getLogicalDensity() {
|
||||||
|
@ -36,18 +36,19 @@ public class AdapterUtils {
|
|||||||
|| state == FeedItem.State.IN_PROGRESS) {
|
|| state == FeedItem.State.IN_PROGRESS) {
|
||||||
if (media.getDuration() > 0) {
|
if (media.getDuration() > 0) {
|
||||||
episodeProgress.setVisibility(View.VISIBLE);
|
episodeProgress.setVisibility(View.VISIBLE);
|
||||||
episodeProgress
|
episodeProgress.setProgress((int) (((double) media
|
||||||
.setProgress((int) (((double) media
|
|
||||||
.getPosition()) / media.getDuration() * 100));
|
.getPosition()) / media.getDuration() * 100));
|
||||||
txtvPos.setText(Converter
|
txtvPos.setText(Converter.getDurationStringLong(media.getDuration()
|
||||||
.getDurationStringLong(media.getDuration()
|
|
||||||
- media.getPosition()));
|
- media.getPosition()));
|
||||||
}
|
}
|
||||||
} else if (!media.isDownloaded()) {
|
} else if (!media.isDownloaded()) {
|
||||||
|
if(media.getSize() > 0) {
|
||||||
txtvPos.setText(Converter.byteToString(media.getSize()));
|
txtvPos.setText(Converter.byteToString(media.getSize()));
|
||||||
} else {
|
} else {
|
||||||
txtvPos.setText(Converter.getDurationStringLong(media
|
txtvPos.setText("");
|
||||||
.getDuration()));
|
}
|
||||||
|
} else {
|
||||||
|
txtvPos.setText(Converter.getDurationStringLong(media.getDuration()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,11 @@ public class QueueListAdapter extends BaseAdapter {
|
|||||||
holder.progressRight.setText(Converter.getDurationStringLong(media.getDuration()));
|
holder.progressRight.setText(Converter.getDurationStringLong(media.getDuration()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if(media.getSize() > 0) {
|
||||||
holder.progressLeft.setText(Converter.byteToString(media.getSize()));
|
holder.progressLeft.setText(Converter.byteToString(media.getSize()));
|
||||||
|
} else {
|
||||||
|
holder.progressLeft.setText("");
|
||||||
|
}
|
||||||
holder.progressRight.setText(Converter.getDurationStringLong(media.getDuration()));
|
holder.progressRight.setText(Converter.getDurationStringLong(media.getDuration()));
|
||||||
holder.progress.setVisibility(View.GONE);
|
holder.progress.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
<service
|
<service
|
||||||
android:name=".service.GpodnetSyncService"
|
android:name=".service.GpodnetSyncService"
|
||||||
android:enabled="true" />
|
android:enabled="true" />
|
||||||
|
<service
|
||||||
|
android:name=".service.FeedMediaSizeService"
|
||||||
|
android:enabled="true" />
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".receiver.MediaButtonReceiver"
|
android:name=".receiver.MediaButtonReceiver"
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
package de.danoeh.antennapod.core.event;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
|
|
||||||
|
public class FeedMediaEvent {
|
||||||
|
|
||||||
|
public enum Action {
|
||||||
|
UPDATE
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Action action;
|
||||||
|
public final FeedMedia media;
|
||||||
|
|
||||||
|
private FeedMediaEvent(Action action, FeedMedia media) {
|
||||||
|
this.action = action;
|
||||||
|
this.media = media;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FeedMediaEvent update(FeedMedia media) {
|
||||||
|
return new FeedMediaEvent(Action.UPDATE, media);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
package de.danoeh.antennapod.core.service;
|
||||||
|
|
||||||
|
import android.app.IntentService;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.event.FeedMediaEvent;
|
||||||
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
|
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||||
|
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||||
|
import de.greenrobot.event.EventBus;
|
||||||
|
|
||||||
|
public class FeedMediaSizeService extends IntentService {
|
||||||
|
|
||||||
|
private final static String TAG = "FeedMediaSizeService";
|
||||||
|
|
||||||
|
public FeedMediaSizeService() {
|
||||||
|
super(TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onHandleIntent(Intent intent) {
|
||||||
|
Log.d(TAG, "onHandleIntent()");
|
||||||
|
if(false == NetworkUtils.networkAvailable(this)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<FeedMedia> list = DBReader.getFeedMediaUnknownSize(this);
|
||||||
|
for (FeedMedia media : list) {
|
||||||
|
if(false == NetworkUtils.networkAvailable(this)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
long size = Integer.MIN_VALUE;
|
||||||
|
if(media.isDownloaded()) {
|
||||||
|
File mediaFile = new File(media.getLocalMediaUrl());
|
||||||
|
if(mediaFile.exists()) {
|
||||||
|
size = mediaFile.length();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
HttpURLConnection conn = null;
|
||||||
|
try {
|
||||||
|
URL url = new URL(media.getDownload_url());
|
||||||
|
conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setRequestProperty("Accept-Encoding", "");
|
||||||
|
conn.setRequestMethod("HEAD");
|
||||||
|
size = conn.getContentLength();
|
||||||
|
conn.disconnect();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.d(TAG, media.getDownload_url());
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (conn != null) {
|
||||||
|
conn.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
media.setSize(size);
|
||||||
|
DBWriter.setFeedMedia(this, media);
|
||||||
|
EventBus.getDefault().post(FeedMediaEvent.update(media));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -550,6 +550,28 @@ public final class DBReader {
|
|||||||
return itemIds;
|
return itemIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads FeedMedia whose file size is unknown
|
||||||
|
*
|
||||||
|
* @param context A context that is used for opening a database connection.
|
||||||
|
* @return A list of FeedMedia items whose size is 0 (unknown and never tried to
|
||||||
|
* determine the correct size)
|
||||||
|
*/
|
||||||
|
public static List<FeedMedia> getFeedMediaUnknownSize(Context context) {
|
||||||
|
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
|
adapter.open();
|
||||||
|
Cursor cursor = adapter.getFeedMediaUnknownSizeCursor();
|
||||||
|
List<FeedMedia> result = new ArrayList<>(cursor.getCount());
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
FeedMedia media = extractFeedMediaFromCursorRow(cursor);
|
||||||
|
result.add(media);
|
||||||
|
} while (cursor.moveToNext());
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a list of FeedItems sorted by pubDate in descending order.
|
* Loads a list of FeedItems sorted by pubDate in descending order.
|
||||||
|
@ -5,6 +5,9 @@ import android.content.Intent;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -29,6 +32,7 @@ import de.danoeh.antennapod.core.feed.FeedImage;
|
|||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
|
import de.danoeh.antennapod.core.service.FeedMediaSizeService;
|
||||||
import de.danoeh.antennapod.core.service.GpodnetSyncService;
|
import de.danoeh.antennapod.core.service.GpodnetSyncService;
|
||||||
import de.danoeh.antennapod.core.service.download.DownloadStatus;
|
import de.danoeh.antennapod.core.service.download.DownloadStatus;
|
||||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||||
@ -595,10 +599,9 @@ public final class DBTasks {
|
|||||||
item.getIdentifyingValue());
|
item.getIdentifyingValue());
|
||||||
if (oldItem == null) {
|
if (oldItem == null) {
|
||||||
// item is new
|
// item is new
|
||||||
final int i = idx;
|
|
||||||
item.setFeed(savedFeed);
|
item.setFeed(savedFeed);
|
||||||
item.setAutoDownload(savedFeed.getPreferences().getAutoDownload());
|
item.setAutoDownload(savedFeed.getPreferences().getAutoDownload());
|
||||||
savedFeed.getItems().add(i, item);
|
savedFeed.getItems().add(idx, item);
|
||||||
if (markNewItems) {
|
if (markNewItems) {
|
||||||
item.setNew();
|
item.setNew();
|
||||||
}
|
}
|
||||||
@ -629,6 +632,8 @@ public final class DBTasks {
|
|||||||
|
|
||||||
EventDistributor.getInstance().sendFeedUpdateBroadcast();
|
EventDistributor.getInstance().sendFeedUpdateBroadcast();
|
||||||
|
|
||||||
|
context.startService(new Intent(context, FeedMediaSizeService.class));
|
||||||
|
|
||||||
return resultFeeds;
|
return resultFeeds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1110,6 +1110,13 @@ public class PodDBAdapter {
|
|||||||
return db.rawQuery(query, null);
|
return db.rawQuery(query, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final Cursor getFeedMediaUnknownSizeCursor() {
|
||||||
|
final String query = "SELECT * "
|
||||||
|
+ " FROM " + TABLE_NAME_FEED_MEDIA
|
||||||
|
+ " WHERE " + KEY_SIZE + ">" + Integer.MIN_VALUE;
|
||||||
|
return db.rawQuery(query, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a cursor which contains all items of a feed that are considered new.
|
* Returns a cursor which contains all items of a feed that are considered new.
|
||||||
* The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection.
|
* The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection.
|
||||||
|
@ -57,6 +57,10 @@ public class NSRSS20 extends Namespace {
|
|||||||
long size = 0;
|
long size = 0;
|
||||||
try {
|
try {
|
||||||
size = Long.parseLong(attributes.getValue(ENC_LEN));
|
size = Long.parseLong(attributes.getValue(ENC_LEN));
|
||||||
|
if(size < 16384) {
|
||||||
|
// less than 16kb is suspicious, check manually
|
||||||
|
size = 0;
|
||||||
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
if (BuildConfig.DEBUG)
|
if (BuildConfig.DEBUG)
|
||||||
Log.d(TAG, "Length attribute could not be parsed.");
|
Log.d(TAG, "Length attribute could not be parsed.");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user