add radio support
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user