diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-08-30 13:09:00 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-08-30 13:09:00 -0700 |
commit | 1a9bbcd97cafd8f5ba22f40a79f61abce440e47d (patch) | |
tree | 6025ccab5678eac2ec392863111112161f7b189e | |
parent | f7f5b5be1bbde0f6e4dfe95ce1f0e23950484450 (diff) | |
parent | 9481c877f3bcc35c21129466c0e5f3fa75a67899 (diff) | |
download | dsub-1a9bbcd97cafd8f5ba22f40a79f61abce440e47d.tar.gz dsub-1a9bbcd97cafd8f5ba22f40a79f61abce440e47d.tar.bz2 dsub-1a9bbcd97cafd8f5ba22f40a79f61abce440e47d.zip |
Merge branch 'master' of https://github.com/daneren2005/Subsonic into Ratings
9 files changed, 184 insertions, 82 deletions
diff --git a/src/github/daneren2005/dsub/domain/MusicDirectory.java b/src/github/daneren2005/dsub/domain/MusicDirectory.java index 3d199522..1caf77cf 100644 --- a/src/github/daneren2005/dsub/domain/MusicDirectory.java +++ b/src/github/daneren2005/dsub/domain/MusicDirectory.java @@ -107,6 +107,10 @@ public class MusicDirectory implements Serializable { } public static class Entry implements Serializable { + public static final int TYPE_SONG = 0; + public static final int TYPE_PODCAST = 1; + public static final int TYPE_AUDIO_BOOK = 2; + private String id; private String parent; private String grandParent; @@ -133,7 +137,7 @@ public class MusicDirectory implements Serializable { private boolean starred; private Integer rating; private Bookmark bookmark; - private int type; + private int type = 0; private int closeness; public void loadMetadata(File file) { @@ -409,6 +413,22 @@ public class MusicDirectory implements Serializable { public void setBookmark(Bookmark bookmark) { this.bookmark = bookmark; } + + public int getType() { + return type; + } + public void setType(int type) { + this.type = type; + } + public boolean isSong() { + return type == TYPE_SONG; + } + public boolean isPodcast() { + return this instanceof PodcastEpisode || type == TYPE_PODCAST; + } + public boolean isAudiBook() { + return type == TYPE_AUDIO_BOOK; + } public int getCloseness() { return closeness; diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 3bbc9fac..9e5d936b 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -1202,8 +1202,12 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR if(!entryExists(entry)) {
Util.toast(context, R.string.download_need_download);
} else {
+ DownloadFile check = new DownloadFile(context, entry, false);
+ File file = check.getCompleteFile();
+
Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.parse(entry.getPath()), "video/*");
+ intent.setDataAndType(Uri.fromFile(file), "video/*");
+ intent.putExtra(Intent.EXTRA_TITLE, entry.getTitle());
List<ResolveInfo> intents = context.getPackageManager()
.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
diff --git a/src/github/daneren2005/dsub/service/DownloadFile.java b/src/github/daneren2005/dsub/service/DownloadFile.java index 6ded4343..2a1306d5 100644 --- a/src/github/daneren2005/dsub/service/DownloadFile.java +++ b/src/github/daneren2005/dsub/service/DownloadFile.java @@ -75,7 +75,7 @@ public class DownloadFile implements BufferFile { this.song = song; this.save = save; saveFile = FileUtil.getSongFile(context, song); - bitRate = Util.getMaxBitrate(context); + bitRate = getActualBitrate(); partialFile = new File(saveFile.getParent(), FileUtil.getBaseName(saveFile.getName()) + ".partial." + FileUtil.getExtension(saveFile.getName())); completeFile = new File(saveFile.getParent(), FileUtil.getBaseName(saveFile.getName()) + diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index a21bbd91..e5495bc2 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -544,6 +544,8 @@ public class DownloadService extends Service { if(currentPlaying == downloadFile) { reset(); } + + currentPlayingIndex = downloadList.indexOf(currentPlaying); } } lifecycleSupport.serializeDownloadQueue(); @@ -1858,7 +1860,7 @@ public class DownloadService extends Service { int duration = getPlayerDuration(); // If song is podcast or long go ahead and auto add a bookmark - if(entry instanceof PodcastEpisode || duration > (10L * 60L * 1000L)) { + if(entry.isPodcast() || entry.isAudiBook() || duration > (10L * 60L * 1000L)) { final Context context = this; final int position = getPlayerPosition(); diff --git a/src/github/daneren2005/dsub/service/MediaStoreService.java b/src/github/daneren2005/dsub/service/MediaStoreService.java index d38a5686..b641a54f 100644 --- a/src/github/daneren2005/dsub/service/MediaStoreService.java +++ b/src/github/daneren2005/dsub/service/MediaStoreService.java @@ -29,74 +29,108 @@ import android.provider.MediaStore; import android.util.Log; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.util.FileUtil; +import github.daneren2005.dsub.util.Util; /** * @author Sindre Mehus */ public class MediaStoreService { - private static final String TAG = MediaStoreService.class.getSimpleName(); - private static final Uri ALBUM_ART_URI = Uri.parse("content://media/external/audio/albumart"); + private static final String TAG = MediaStoreService.class.getSimpleName(); + private static final Uri ALBUM_ART_URI = Uri.parse("content://media/external/audio/albumart"); - private final Context context; + private final Context context; - public MediaStoreService(Context context) { - this.context = context; - } + public MediaStoreService(Context context) { + this.context = context; + } - public void saveInMediaStore(DownloadFile downloadFile) { - MusicDirectory.Entry song = downloadFile.getSong(); - File songFile = downloadFile.getCompleteFile(); + public void saveInMediaStore(DownloadFile downloadFile) { + MusicDirectory.Entry song = downloadFile.getSong(); + File songFile = downloadFile.getCompleteFile(); - // Delete existing row in case the song has been downloaded before. - deleteFromMediaStore(downloadFile); + // Delete existing row in case the song has been downloaded before. + deleteFromMediaStore(downloadFile); - ContentResolver contentResolver = context.getContentResolver(); - ContentValues values = new ContentValues(); - values.put(MediaStore.MediaColumns.TITLE, song.getTitle()); - values.put(MediaStore.Audio.AudioColumns.ARTIST, song.getArtist()); - values.put(MediaStore.Audio.AudioColumns.ALBUM, song.getAlbum()); - values.put(MediaStore.MediaColumns.DATA, songFile.getAbsolutePath()); - if(song.getTranscodedContentType() != null) { - values.put(MediaStore.MediaColumns.MIME_TYPE, song.getTranscodedContentType()); + ContentResolver contentResolver = context.getContentResolver(); + ContentValues values = new ContentValues(); + if(!song.isVideo()) { + values.put(MediaStore.MediaColumns.TITLE, song.getTitle()); + values.put(MediaStore.MediaColumns.DATA, songFile.getAbsolutePath()); + values.put(MediaStore.Audio.AudioColumns.ARTIST, song.getArtist()); + values.put(MediaStore.Audio.AudioColumns.ALBUM, song.getAlbum()); + if (song.getDuration() != null) { + values.put(MediaStore.Audio.AudioColumns.DURATION, song.getDuration() * 1000L); + } + if (song.getTrack() != null) { + values.put(MediaStore.Audio.AudioColumns.TRACK, song.getTrack()); + } + if (song.getYear() != null) { + values.put(MediaStore.Audio.AudioColumns.YEAR, song.getYear()); + } + if(song.getTranscodedContentType() != null) { + values.put(MediaStore.MediaColumns.MIME_TYPE, song.getTranscodedContentType()); + } else { + values.put(MediaStore.MediaColumns.MIME_TYPE, song.getContentType()); + } + values.put(MediaStore.Audio.AudioColumns.IS_MUSIC, 1); + + Uri uri = contentResolver.insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values); + + // Look up album, and add cover art if found. + Cursor cursor = contentResolver.query(uri, new String[]{MediaStore.Audio.AudioColumns.ALBUM_ID}, null, null, null); + if (cursor.moveToFirst()) { + int albumId = cursor.getInt(0); + insertAlbumArt(albumId, downloadFile); + } + + cursor.close(); } else { - values.put(MediaStore.MediaColumns.MIME_TYPE, song.getContentType()); + values.put(MediaStore.Video.VideoColumns.TITLE, song.getTitle()); + values.put(MediaStore.Video.VideoColumns.DISPLAY_NAME, song.getTitle()); + values.put(MediaStore.Video.VideoColumns.ARTIST, song.getArtist()); + values.put(MediaStore.Video.VideoColumns.DATA, songFile.getAbsolutePath()); + if (song.getDuration() != null) { + values.put(MediaStore.Video.VideoColumns.DURATION, song.getDuration() * 1000L); + } + + String videoPlayerType = Util.getVideoPlayerType(context); + if("hls".equals(videoPlayerType)) { + // HLS should be able to transcode to mp4 automatically + values.put(MediaStore.MediaColumns.MIME_TYPE, "video/mpeg"); + } else if("raw".equals(videoPlayerType) || song.getTranscodedContentType() == null) { + // Download the original video without any transcoding + values.put(MediaStore.MediaColumns.MIME_TYPE, song.getContentType()); + } else { + values.put(MediaStore.MediaColumns.MIME_TYPE, song.getTranscodedContentType()); + } + + Uri uri = contentResolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values); + if(uri == null) { + Log.e(TAG, "Failed to insert"); + } } - if(song.getDuration() != null) { - values.put(MediaStore.Audio.AudioColumns.DURATION, song.getDuration() * 1000L); - } - if(song.getTrack() != null) { - values.put(MediaStore.Audio.AudioColumns.TRACK, song.getTrack()); + } + + public void deleteFromMediaStore(DownloadFile downloadFile) { + ContentResolver contentResolver = context.getContentResolver(); + MusicDirectory.Entry song = downloadFile.getSong(); + File file = downloadFile.getCompleteFile(); + + Uri uri; + if(song.isVideo()) { + uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; + } else { + uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } - if(song.getYear() != null) { - values.put(MediaStore.Audio.AudioColumns.YEAR, song.getYear()); + + int n = contentResolver.delete(uri, + MediaStore.MediaColumns.DATA + "=?", + new String[]{file.getAbsolutePath()}); + if (n > 0) { + Log.i(TAG, "Deleting media store row for " + song); } - values.put(MediaStore.Audio.AudioColumns.IS_MUSIC, 1); - - Uri uri = contentResolver.insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values); - - // Look up album, and add cover art if found. - Cursor cursor = contentResolver.query(uri, new String[]{MediaStore.Audio.AudioColumns.ALBUM_ID}, null, null, null); - if (cursor.moveToFirst()) { - int albumId = cursor.getInt(0); - insertAlbumArt(albumId, downloadFile); - } - cursor.close(); - } - - public void deleteFromMediaStore(DownloadFile downloadFile) { - ContentResolver contentResolver = context.getContentResolver(); - MusicDirectory.Entry song = downloadFile.getSong(); - File file = downloadFile.getCompleteFile(); - - int n = contentResolver.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, - MediaStore.Audio.AudioColumns.TITLE_KEY + "=? AND " + - MediaStore.MediaColumns.DATA + "=?", - new String[]{MediaStore.Audio.keyFor(song.getTitle()), file.getAbsolutePath()}); - if (n > 0) { - Log.i(TAG, "Deleting media store row for " + song); - } - } + } public void deleteFromMediaStore(File file) { ContentResolver contentResolver = context.getContentResolver(); @@ -124,23 +158,23 @@ public class MediaStoreService { } } - private void insertAlbumArt(int albumId, DownloadFile downloadFile) { - ContentResolver contentResolver = context.getContentResolver(); - - Cursor cursor = contentResolver.query(Uri.withAppendedPath(ALBUM_ART_URI, String.valueOf(albumId)), null, null, null, null); - if (!cursor.moveToFirst()) { - - // No album art found, add it. - File albumArtFile = FileUtil.getAlbumArtFile(context, downloadFile.getSong()); - if (albumArtFile.exists()) { - ContentValues values = new ContentValues(); - values.put(MediaStore.Audio.AlbumColumns.ALBUM_ID, albumId); - values.put(MediaStore.MediaColumns.DATA, albumArtFile.getPath()); - contentResolver.insert(ALBUM_ART_URI, values); - Log.i(TAG, "Added album art: " + albumArtFile); - } - } - cursor.close(); - } + private void insertAlbumArt(int albumId, DownloadFile downloadFile) { + ContentResolver contentResolver = context.getContentResolver(); + + Cursor cursor = contentResolver.query(Uri.withAppendedPath(ALBUM_ART_URI, String.valueOf(albumId)), null, null, null, null); + if (!cursor.moveToFirst()) { + + // No album art found, add it. + File albumArtFile = FileUtil.getAlbumArtFile(context, downloadFile.getSong()); + if (albumArtFile.exists()) { + ContentValues values = new ContentValues(); + values.put(MediaStore.Audio.AlbumColumns.ALBUM_ID, albumId); + values.put(MediaStore.MediaColumns.DATA, albumArtFile.getPath()); + contentResolver.insert(ALBUM_ART_URI, values); + Log.i(TAG, "Added album art: " + albumArtFile); + } + } + cursor.close(); + } } diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java index 025d07c5..d6715e8c 100644 --- a/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -667,8 +667,31 @@ public class RESTMusicService implements MusicService { if (offset > 0) { headers.add(new BasicHeader("Range", "bytes=" + offset + "-")); } - List<String> parameterNames = Arrays.asList("id", "maxBitRate"); - List<Object> parameterValues = Arrays.<Object>asList(song.getId(), maxBitrate); + + List<String> parameterNames = new ArrayList<String>(); + parameterNames.add("id"); + parameterNames.add("maxBitRate"); + + List<Object> parameterValues = new ArrayList<Object>(); + parameterValues.add(song.getId()); + parameterValues.add(maxBitrate); + + // If video specify what format to download + if(song.isVideo()) { + String videoPlayerType = Util.getVideoPlayerType(context); + if("hls".equals(videoPlayerType)) { + // HLS should be able to transcode to mp4 automatically + parameterNames.add("format"); + parameterValues.add("mp4"); + + parameterNames.add("hls"); + parameterValues.add("true"); + } else if("raw".equals(videoPlayerType)) { + // Download the original video without any transcoding + parameterNames.add("format"); + parameterValues.add("raw"); + } + } HttpResponse response = getResponseForURL(context, url, params, parameterNames, parameterValues, headers, null, task); // If content type is XML, an error occurred. Get it. diff --git a/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java b/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java index 67effc24..683f6857 100644 --- a/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java +++ b/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java @@ -66,6 +66,13 @@ public class MusicDirectoryEntryParser extends AbstractParser { if(bookmark != null) { entry.setBookmark(new Bookmark(bookmark)); } + + String type = get("type"); + if("podcast".equals(type)) { + entry.setType(MusicDirectory.Entry.TYPE_PODCAST); + } else if("audiobook".equals(type)) { + entry.setType(MusicDirectory.Entry.TYPE_AUDIO_BOOK); + } } else if(!"".equals(artist)) { entry.setPath(artist + "/" + entry.getTitle()); } diff --git a/src/github/daneren2005/dsub/service/parser/PodcastEntryParser.java b/src/github/daneren2005/dsub/service/parser/PodcastEntryParser.java index afd861f0..fe742819 100644 --- a/src/github/daneren2005/dsub/service/parser/PodcastEntryParser.java +++ b/src/github/daneren2005/dsub/service/parser/PodcastEntryParser.java @@ -93,6 +93,7 @@ public class PodcastEntryParser extends AbstractParser { if(bookmark != null) {
episode.setBookmark(new Bookmark(bookmark));
}
+ episode.setType(MusicDirectory.Entry.TYPE_PODCAST);
if(episode.getId() == null) {
episode.setId(String.valueOf(bogusId));
diff --git a/src/github/daneren2005/dsub/util/FileUtil.java b/src/github/daneren2005/dsub/util/FileUtil.java index 6c116dce..7371b46b 100644 --- a/src/github/daneren2005/dsub/util/FileUtil.java +++ b/src/github/daneren2005/dsub/util/FileUtil.java @@ -118,11 +118,22 @@ public class FileUtil { fileName.append(fileSystemSafe(song.getTitle())).append("."); - if (song.getTranscodedSuffix() != null) { - fileName.append(song.getTranscodedSuffix()); - } else { - fileName.append(song.getSuffix()); - } + if(song.isVideo()) { + String videoPlayerType = Util.getVideoPlayerType(context); + if("hls".equals(videoPlayerType)) { + // HLS should be able to transcode to mp4 automatically + fileName.append("mp4"); + } else if("raw".equals(videoPlayerType)) { + // Download the original video without any transcoding + fileName.append(song.getSuffix()); + } + } else { + if (song.getTranscodedSuffix() != null) { + fileName.append(song.getTranscodedSuffix()); + } else { + fileName.append(song.getSuffix()); + } + } return new File(dir, fileName.toString()); } |