Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions dist/assets/index-1987eb7b.js

This file was deleted.

7 changes: 7 additions & 0 deletions dist/assets/index-235a7946.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>spotDL</title>
<script type="module" crossorigin src="/assets/index-1987eb7b.js"></script>
<link rel="stylesheet" href="/assets/index-8ce425b2.css">
<script type="module" crossorigin src="/assets/index-235a7946.js"></script>
<link rel="stylesheet" href="/assets/index-ae0bb08c.css">
</head>
<body>
<div id="app"></div>
Expand Down
21 changes: 10 additions & 11 deletions src/components/Hero.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<SearchInput />
<div class="alert alert-info shadow-lg my-4">
<div>
<!-- <svg
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
Expand All @@ -60,17 +60,13 @@
stroke-width="2"
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
></path>
</svg> -->
<Icon
icon="clarity:info-circle-line"
class="swap-off fill-current h-6 w-6"
/>
</svg>
<span
>This web interface currently downloads only songs. <br />
Album, Artist, Playlist and Show links will not work.</span
>
>NEW!: This interface now can download Song, Album, Artist and Playlist. <br />
<span v-if="version < 4001012000">This version is not compatible with lists, you need to download a new spotDL version</span>
</span>
</div>
</div>
</div>
</div>
</div>
</template>
Expand All @@ -90,7 +86,10 @@ export default {
newDarkAlias: 'spotdl-dark',
})

return { themeMgr }
return {
themeMgr,
version: localStorage.getItem("version")
}
},
}
</script>
Expand Down
6 changes: 5 additions & 1 deletion src/components/SearchInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
v-model="searchTerm"
@keyup.enter="lookUp(searchTerm)"
/>
<button class="btn btn-square btn-primary" @click="lookUp(searchTerm)">
<button v-if="loading" class="btn btn-square btn-primary loading">

</button>
<button v-else class="btn btn-square btn-primary" @click="lookUp(searchTerm)">
<!-- zero-width space - this btn class style breaks with only a svg inside -->
&#8203;
<Icon
Expand Down Expand Up @@ -75,6 +78,7 @@ export default {
searchTerm: sm.searchTerm,
isValidURL: sm.isValidURL,
placeHolder,
loading: dm.loading
}
},
}
Expand Down
49 changes: 46 additions & 3 deletions src/model/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,64 @@ const API = axios.create({
const sessionID = uuidv4()
console.log('session ID: ', sessionID)

getVersion()

const wsConnection = new WebSocket(
`${config.WS_PROTOCOL}//${config.BACKEND}${
config.PORT !== '' ? ':' + config.PORT : ''
`${config.WS_PROTOCOL}//${config.BACKEND}${config.PORT !== '' ? ':' + config.PORT : ''
}${config.BASEURL}/api/ws?client_id=${sessionID}`
)

wsConnection.onopen = (event) => {
console.log('websocket connection opened', event)
}

function getVersion() {

API.get("/api/version")
.then(res => {
const prevItem = localStorage.getItem("version")
console.log("Backend version: ", res.data)
localStorage.setItem("version", versionToNumber(res.data))
console.log("Using numerical version: ", versionToNumber(res.data))
if(prevItem != versionToNumber(res.data)) {
location.reload()
}
})
.catch(error => {
console.error(error)
console.log("Error getting version, using 0")
localStorage.setItem("version", 0)
})

}

function versionToNumber(versionStr) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually compare version strings without converting them to numbers. "4.1.11" < "4.1.12" returns true

/*
* This function converts a version in format w.x.y.z to a number.
* Each position has its value * 1000 ^ (3-position)
*/
if (!versionStr) return 0
const tokens = versionStr.split(".")
let n = 0
const tokensLengthOrFixed = tokens.length > 4 ? 4 : tokens.length
for (let i = 0; i < tokensLengthOrFixed; i++) {
n += Number(tokens[i]) * Math.pow(1000, 3 - i)
}

return n
}

function search(query) {
return API.get('/api/songs/search', { params: { query } })
}

function open(songURL) {
return API.get('/api/song/url', { params: { url: songURL } })
//4.2
if (localStorage.getItem("version") >= 4001012000) {
return API.get('/api/url', { params: { url: songURL } })
} else {
return API.get('/api/song/url', { params: { url: songURL } })
}
}

function download(songURL) {
Expand Down Expand Up @@ -78,4 +120,5 @@ export default {
check_for_update,
ws_onmessage,
ws_onerror,
getVersion
}
19 changes: 15 additions & 4 deletions src/model/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,31 @@ API.ws_onerror((event) => {
})

function useDownloadManager() {
const loading = ref(false)
function fromURL(url) {
API.open(url)
loading.value = true
return API.open(url)
.then((res) => {
console.log('Received Response:', res)
if (res.status === 200) {
let song = res.data
console.log('Opened Song:', song)
queue(song)
const songs = res.data
if (Array.isArray(songs)) {
for (const song of songs) {
console.log('Opened Song:', song)
queue(song)
}
} else {
console.log('Opened Song:', songs)
queue(songs)
}
} else {
console.log('Error:', res)
}
})
.catch((err) => {
console.log('Other Error:', err.message)
})
.finally(() => {loading.value = false})
}

function download(song) {
Expand Down Expand Up @@ -149,6 +159,7 @@ function useDownloadManager() {
download,
queue,
remove,
loading
}
}

Expand Down
16 changes: 13 additions & 3 deletions src/model/search.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ref, computed } from 'vue'

import API from '/src/model/api'
import api from './api'

const searchTerm = ref('')
const results = ref()
Expand All @@ -15,8 +16,8 @@ function useSearchManager() {
function isValidSearch(str) {
if (
str === '' ||
str.includes('://open.spotify.com/playlist/') ||
str.includes('://open.spotify.com/album/') ||
str.includes('://open.spotify.com/playlist/') ||
str.includes('://open.spotify.com/show/') ||
str.includes('://open.spotify.com/artist/')
) {
Expand All @@ -25,7 +26,16 @@ function useSearchManager() {
return true
}
function isValidURL(str) {
if (str.includes('://open.spotify.com/track/')) {
if ((str.includes('://open.spotify.com/track/') ||
str.includes('://open.spotify.com/album/') ||
str.includes('://open.spotify.com/playlist/') ||
str.includes('://open.spotify.com/artist/')) &&
localStorage.getItem("version") >= 4001012000
) {
return true
} else if(
str.includes('://open.spotify.com/track/')
) {
return true
}
return false
Expand Down Expand Up @@ -68,7 +78,7 @@ function useSearchManager() {
searchFor,
isValid,
isValidSearch,
isValidURL,
isValidURL
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/views/Front.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export default {
setup() {
onMounted(() => {
window.scroll(0, 0)
API.check_for_update().then((resp) => {
/*API.check_for_update().then((resp) => {
if (Boolean(resp.data) === true) {
alert("This version is no longer supported, please update https://github.com/spotDL/spotify-downloader")
}
}).catch((error) => {
alert("This version is no longer supported, please update https://github.com/spotDL/spotify-downloader")
})
})*/
})
return {}
},
Expand Down