[Android] Remote access: allow download of video groups and video folders

Nicolas Pomepuy git at videolan.org
Wed Feb 28 10:33:47 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Feb 28 09:07:50 2024 +0100| [b843e7cb307384643f2f83b4e7988723c4d97714] | committer: Nicolas Pomepuy

Remote access: allow download of video groups and video folders

> https://code.videolan.org/videolan/vlc-android/commit/b843e7cb307384643f2f83b4e7988723c4d97714
---

 .../videolan/vlc/webserver/RemoteAccessRouting.kt  | 12 ++++++++
 .../videolan/vlc/webserver/utils/MediaZipUtils.kt  | 32 ++++++++++++++++++++++
 .../network-sharing-server/src/pages/VideoList.vue |  4 +--
 3 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt
index df667e47b0..f64af9d2dd 100644
--- a/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt
+++ b/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt
@@ -888,6 +888,18 @@ fun Route.setupRouting(appContext: Context, scope: CoroutineScope) {
                         call.respondText(dst)
                         return at get
                     }
+                    "video-group" -> {
+                        val videoGroup = appContext.getFromMl { getVideoGroup(id.toLong()) }
+                        val dst = MediaZipUtils.generateVideoGroupZip(videoGroup, RemoteAccessServer.getInstance(appContext).downloadFolder)
+                        call.respondText(dst)
+                        return at get
+                    }
+                    "video-folder" -> {
+                        val videoFolder = appContext.getFromMl { getFolder(Folder.TYPE_FOLDER_VIDEO, id.toLong()) }
+                        val dst = MediaZipUtils.generateVideoGroupZip(videoFolder, RemoteAccessServer.getInstance(appContext).downloadFolder)
+                        call.respondText(dst)
+                        return at get
+                    }
                     else -> {
                         //simple media. It's a direct download
                         appContext.getFromMl { getMedia(id.toLong()) }?.let { media ->
diff --git a/application/webserver/src/main/java/org/videolan/vlc/webserver/utils/MediaZipUtils.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/utils/MediaZipUtils.kt
index f64ce642a8..3f3abf6595 100644
--- a/application/webserver/src/main/java/org/videolan/vlc/webserver/utils/MediaZipUtils.kt
+++ b/application/webserver/src/main/java/org/videolan/vlc/webserver/utils/MediaZipUtils.kt
@@ -24,6 +24,7 @@
 
 package org.videolan.vlc.webserver.utils
 
+import org.videolan.medialibrary.interfaces.Medialibrary
 import org.videolan.medialibrary.interfaces.media.*
 import org.videolan.vlc.util.FileUtils
 import org.videolan.vlc.util.slugify
@@ -60,6 +61,37 @@ object MediaZipUtils {
         return filename
     }
 
+    /**
+     * Generate a zip file for a [VideoGroup]
+     *
+     * @param videoGroup the video group to zip
+     * @return the filename
+     */
+    fun generateVideoGroupZip(videoGroup: VideoGroup, folder:String): String {
+        val files = videoGroup.media(Medialibrary.SORT_DEFAULT, false, false, false, videoGroup.mediaCount(), 0).mapNotNull { prepareTrackForZip(it, -1) }
+
+        val filename = "${videoGroup.title.slugify("_")}.zip"
+        val dst = File("$folder/$filename")
+        FileUtils.zipWithName(files.toTypedArray(), dst.path)
+        return filename
+    }
+
+    /**
+     * Generate a zip file for a [Folder]
+     *
+     * @param videoFolder the video folder to zip
+     * @return the filename
+     */
+    fun generateVideoGroupZip(videoFolder: Folder, folder:String): String {
+        val files = videoFolder.media(Folder.TYPE_FOLDER_VIDEO, Medialibrary.SORT_DEFAULT, false, false, false, videoFolder.mediaCount(Folder.TYPE_FOLDER_VIDEO), 0).mapNotNull { prepareTrackForZip(it, -1) }
+
+
+        val filename = "${videoFolder.title.slugify("_")}.zip"
+        val dst = File("$folder/$filename")
+        FileUtils.zipWithName(files.toTypedArray(), dst.path)
+        return filename
+    }
+
     /**
      * Generate a zip file for a [Artist]
      *
diff --git a/buildsystem/network-sharing-server/src/pages/VideoList.vue b/buildsystem/network-sharing-server/src/pages/VideoList.vue
index 7f1abca5cc..b9a76e5548 100644
--- a/buildsystem/network-sharing-server/src/pages/VideoList.vue
+++ b/buildsystem/network-sharing-server/src/pages/VideoList.vue
@@ -2,12 +2,12 @@
     <div v-if="loaded && this.videos.length !== 0" class="container">
         <div v-if="this.appStore.displayType[this.$route.name]" class="row gx-3 gy-3 media-list">
             <template v-for="video in videos" :key="video.id">
-                <MediaItem :isCard="false" :media="video" :downloadable="true" :mediaType="getMediaType(video)" />
+                <MediaItem :isCard="false" :media="video" :downloadable="getMediaType(video) == 'video'" :mediaType="getMediaType(video)" />
             </template>
         </div>
         <div v-else class="row gx-3 gy-3 media-content">
             <div class="col-md-3 col-sm-4 col-6" v-for="video in videos" :key="video.id">
-                <MediaItem :isCard="true" :media="video" :downloadable="true" :mediaType="getMediaType(video)" />
+                <MediaItem :isCard="true" :media="video" :downloadable="getMediaType(video) == 'video'" :mediaType="getMediaType(video)" />
             </div>
         </div>
     </div>



More information about the Android mailing list