downloads entire library in songs view
This commit is contained in:
parent
10dba24da2
commit
4e051eb97c
2 changed files with 55 additions and 12 deletions
|
@ -252,20 +252,27 @@
|
|||
</template>
|
||||
</transition>
|
||||
<!-- Library - Songs -->
|
||||
<transition name="wpfade" v-on:enter="getLibrarySongs()">
|
||||
<transition name="wpfade" v-on:enter="getLibrarySongsFull()">
|
||||
<template v-if="page == 'library-songs'">
|
||||
<div class="content-inner">
|
||||
<h1 class="header-text">Songs</h1>
|
||||
<div class="search-input-container" style="width:100%;margin: 16px 0px;">
|
||||
<div class="search-input--icon"></div>
|
||||
<input type="search"
|
||||
style="width:100%;"
|
||||
spellcheck="false"
|
||||
placeholder="Search..."
|
||||
class="search-input">
|
||||
</div>
|
||||
<mediaitem-list-item :item="item"
|
||||
v-for="item in library.songs.listing"></mediaitem-list-item>
|
||||
<template v-if="library.songs.downloadState == 1">
|
||||
<h1 style="text-align: center">Downloading...</h1>
|
||||
<h3 style="text-align: center">{{ library.songs.meta.progress }} / {{ library.songs.meta.total }}</h3>
|
||||
|
||||
</template>
|
||||
<template v-if="library.songs.downloadState == 2">
|
||||
<div class="search-input-container" style="width:100%;margin: 16px 0px;">
|
||||
<div class="search-input--icon"></div>
|
||||
<input type="search"
|
||||
style="width:100%;"
|
||||
spellcheck="false"
|
||||
placeholder="Search..."
|
||||
class="search-input">
|
||||
</div>
|
||||
<mediaitem-list-item :item="item"
|
||||
v-for="item in library.songs.listing"></mediaitem-list-item>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</transition>
|
||||
|
|
|
@ -107,7 +107,8 @@ const app = new Vue({
|
|||
library: {
|
||||
songs: {
|
||||
listing: [],
|
||||
meta: {total: 0}
|
||||
meta: {total: 0, progress: 0},
|
||||
downloadState: 0 // 0 = not started, 1 = in progress, 2 = complete
|
||||
},
|
||||
albums: {
|
||||
listing: [],
|
||||
|
@ -174,6 +175,41 @@ const app = new Vue({
|
|||
return await this.mkapi(method, library, term, params, params2, attempts + 1)
|
||||
}
|
||||
},
|
||||
async getLibrarySongsFull () {
|
||||
let self = this
|
||||
let library = []
|
||||
let downloaded = null;
|
||||
if(this.library.songs.downloadState == 2 || this.library.songs.downloadState == 1) {
|
||||
return
|
||||
}
|
||||
this.library.songs.downloadState = 1
|
||||
function downloadChunk () {
|
||||
if(downloaded == null) {
|
||||
app.mk.api.library.songs("", {limit: 100}, {includeResponseMeta: !0}).then((response)=>{
|
||||
processChunk(response)
|
||||
})
|
||||
}else{
|
||||
downloaded.next("", {limit: 100}, {includeResponseMeta: !0}).then((response)=>{
|
||||
processChunk(response)
|
||||
})
|
||||
}
|
||||
}
|
||||
function processChunk (response) {
|
||||
downloaded = response
|
||||
library = library.concat(downloaded.data)
|
||||
self.library.songs.meta.total = downloaded.meta.total
|
||||
self.library.songs.meta.progress = library.length
|
||||
if (downloaded.meta.total > library.length) {
|
||||
console.log(`downloading next chunk - ${library.length} songs so far`)
|
||||
downloadChunk()
|
||||
} else {
|
||||
self.library.songs.listing = library
|
||||
self.library.songs.downloadState = 2
|
||||
console.log(library)
|
||||
}
|
||||
}
|
||||
downloadChunk()
|
||||
},
|
||||
async getLibrarySongs() {
|
||||
var response = await this.mkapi("songs", true, "", {limit: 100}, {includeResponseMeta: !0})
|
||||
this.library.songs.listing = response.data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue