mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
feat: implemented logic for track download with codec and bitrate definition
This commit is contained in:
parent
b160274859
commit
7c6faf66c1
2 changed files with 59 additions and 5 deletions
|
|
@ -10,6 +10,8 @@ import androidx.media3.common.MimeTypes;
|
|||
import androidx.media3.common.util.UnstableApi;
|
||||
|
||||
import com.cappielloantonio.tempo.App;
|
||||
import com.cappielloantonio.tempo.model.Download;
|
||||
import com.cappielloantonio.tempo.repository.DownloadRepository;
|
||||
import com.cappielloantonio.tempo.subsonic.models.Child;
|
||||
import com.cappielloantonio.tempo.subsonic.models.InternetRadioStation;
|
||||
import com.cappielloantonio.tempo.subsonic.models.PodcastEpisode;
|
||||
|
|
@ -115,11 +117,11 @@ public class MappingUtil {
|
|||
)
|
||||
.setRequestMetadata(
|
||||
new MediaItem.RequestMetadata.Builder()
|
||||
.setMediaUri(MusicUtil.getDownloadUri(media.getId()))
|
||||
.setMediaUri(Preferences.preferTranscodedDownload() ? MusicUtil.getTranscodedDownloadUri(media.getId()) : MusicUtil.getDownloadUri(media.getId()))
|
||||
.build()
|
||||
)
|
||||
.setMimeType(MimeTypes.BASE_TYPE_AUDIO)
|
||||
.setUri(MusicUtil.getDownloadUri(media.getId()))
|
||||
.setUri(Preferences.preferTranscodedDownload() ? MusicUtil.getTranscodedDownloadUri(media.getId()) : MusicUtil.getDownloadUri(media.getId()))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
@ -216,13 +218,18 @@ public class MappingUtil {
|
|||
|
||||
private static Uri getUri(Child media) {
|
||||
return DownloadUtil.getDownloadTracker(App.getContext()).isDownloaded(media.getId())
|
||||
? MusicUtil.getDownloadUri(media.getId())
|
||||
? getDownloadUri(media.getId())
|
||||
: MusicUtil.getStreamUri(media.getId());
|
||||
}
|
||||
|
||||
private static Uri getUri(PodcastEpisode podcastEpisode) {
|
||||
return DownloadUtil.getDownloadTracker(App.getContext()).isDownloaded(podcastEpisode.getId())
|
||||
? MusicUtil.getDownloadUri(podcastEpisode.getId())
|
||||
? getDownloadUri(podcastEpisode.getId())
|
||||
: MusicUtil.getStreamUri(podcastEpisode.getId());
|
||||
}
|
||||
|
||||
private static Uri getDownloadUri(String id) {
|
||||
Download download = new DownloadRepository().getDownload(id);
|
||||
return download != null && !download.getDownloadUri().isEmpty() ? Uri.parse(download.getDownloadUri()) : MusicUtil.getDownloadUri(id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,6 +90,40 @@ public class MusicUtil {
|
|||
return Uri.parse(uri.toString());
|
||||
}
|
||||
|
||||
public static Uri getTranscodedDownloadUri(String id) {
|
||||
Map<String, String> params = App.getSubsonicClientInstance(false).getParams();
|
||||
|
||||
StringBuilder uri = new StringBuilder();
|
||||
|
||||
uri.append(App.getSubsonicClientInstance(false).getUrl());
|
||||
uri.append("stream");
|
||||
|
||||
if (params.containsKey("u") && params.get("u") != null)
|
||||
uri.append("?u=").append(params.get("u"));
|
||||
if (params.containsKey("p") && params.get("p") != null)
|
||||
uri.append("&p=").append(params.get("p"));
|
||||
if (params.containsKey("s") && params.get("s") != null)
|
||||
uri.append("&s=").append(params.get("s"));
|
||||
if (params.containsKey("t") && params.get("t") != null)
|
||||
uri.append("&t=").append(params.get("t"));
|
||||
if (params.containsKey("v") && params.get("v") != null)
|
||||
uri.append("&v=").append(params.get("v"));
|
||||
if (params.containsKey("c") && params.get("c") != null)
|
||||
uri.append("&c=").append(params.get("c"));
|
||||
|
||||
if (!Preferences.isServerPrioritizedInTranscodedDownload())
|
||||
uri.append("&maxBitRate=").append(getBitratePreferenceForDownload());
|
||||
if (!Preferences.isServerPrioritizedInTranscodedDownload())
|
||||
uri.append("&format=").append(getTranscodingFormatPreferenceForDownload());
|
||||
|
||||
uri.append("&id=").append(id);
|
||||
|
||||
Log.d(TAG, "getTranscodedDownloadUri: " + uri);
|
||||
|
||||
return Uri.parse(uri.toString());
|
||||
}
|
||||
|
||||
|
||||
public static String getReadableDurationString(long duration, boolean millis) {
|
||||
long minutes;
|
||||
long seconds;
|
||||
|
|
@ -213,6 +247,19 @@ public class MusicUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static String getBitratePreferenceForDownload() {
|
||||
String audioTranscodeFormat = getTranscodingFormatPreferenceForDownload();
|
||||
|
||||
if (audioTranscodeFormat.equals("raw"))
|
||||
return "0";
|
||||
|
||||
return Preferences.getBitrateTranscodedDownload();
|
||||
}
|
||||
|
||||
public static String getTranscodingFormatPreferenceForDownload() {
|
||||
return Preferences.getAudioTranscodeFormatTranscodedDownload();
|
||||
}
|
||||
|
||||
public static List<Child> limitPlayableMedia(List<Child> toLimit, int position) {
|
||||
if (!toLimit.isEmpty() && toLimit.size() > Constants.PLAYABLE_MEDIA_LIMIT) {
|
||||
int from = position < Constants.PRE_PLAYABLE_MEDIA ? 0 : position - Constants.PRE_PLAYABLE_MEDIA;
|
||||
|
|
@ -225,7 +272,7 @@ public class MusicUtil {
|
|||
}
|
||||
|
||||
public static int getPlayableMediaPosition(int initialPosition) {
|
||||
return initialPosition > Constants.PLAYABLE_MEDIA_LIMIT ? Constants.PRE_PLAYABLE_MEDIA : initialPosition;
|
||||
return Math.min(initialPosition, Constants.PRE_PLAYABLE_MEDIA);
|
||||
}
|
||||
|
||||
private static ConnectivityManager getConnectivityManager() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue