add radio support

This commit is contained in:
Thomas Amland
2020-09-07 18:43:22 +02:00
parent 4fca9f417b
commit c3a5136f0f
5 changed files with 127 additions and 0 deletions
+49
View File
@@ -52,6 +52,13 @@ export interface SearchResult {
tracks: Track[]
}
export interface RadioStation {
id: string
title: string
description: string
url: string
}
export class API {
readonly http: AxiosInstance;
readonly get: (path: string, params?: any) => Promise<any>;
@@ -274,6 +281,48 @@ export class API {
}
}
async getRadioStations(): Promise<RadioStation[]> {
const response = await this.get('rest/getInternetRadioStations')
return (response?.internetRadioStations?.internetRadioStation || [])
.map(this.normalizeRadioStation, this)
}
async addRadioStation(title: string, url: string): Promise<RadioStation> {
const params = {
name: title,
streamUrl: url,
}
return this
.get('rest/createInternetRadioStation', params)
.then(this.normalizeRadioStation)
}
async updateRadioStation(item: RadioStation): Promise<RadioStation> {
const params = {
id: item.id,
name: item.title,
streamUrl: item.url,
}
return this
.get('rest/updateInternetRadioStation', params)
.then(this.normalizeRadioStation)
}
async deleteRadioStation(id: string): Promise<void> {
return this.get('rest/deleteInternetRadioStation', { id })
}
private normalizeRadioStation(item: any): Track & RadioStation {
return {
id: `radio-${item.id}`,
title: item.name,
description: item.homePageUrl,
url: item.streamUrl,
duration: 0,
starred: false,
}
}
private normalizeTrack(item: any): Track {
return {
id: item.id,
+2
View File
@@ -5,6 +5,7 @@
import Vue from 'vue'
import {
BIcon,
BIconBroadcast,
BIconCardText,
BIconChevronCompactRight,
BIconMusicNoteList,
@@ -28,6 +29,7 @@
export default Vue.extend({
components: {
BIcon,
BIconBroadcast,
BIconCardText,
BIconChevronCompactRight,
BIconMusicNoteList,
+6
View File
@@ -10,6 +10,7 @@ import RandomSongs from '@/playlist/RandomSongs.vue'
import GenreDetails from '@/library/genre/GenreDetails.vue'
import GenreLibrary from '@/library/genre/GenreLibrary.vue'
import Starred from '@/library/starred/Starred.vue'
import RadioStations from '@/library/radio/RadioStations.vue'
import Playlist from '@/playlist/Playlist.vue'
import PlaylistList from '@/playlist/PlaylistList.vue'
import SearchResult from '@/search/SearchResult.vue'
@@ -78,6 +79,11 @@ export function setupRouter(auth: AuthService) {
path: '/starred',
component: Starred,
},
{
name: 'radio',
path: '/radio',
component: RadioStations,
},
{
name: 'playlists',
path: '/playlists',