diff --git a/qml.qrc b/qml.qrc index 3b115e1..9b032ee 100755 --- a/qml.qrc +++ b/qml.qrc @@ -150,6 +150,8 @@ resources/covers/favorite-ru.svg resources/covers/downloads.svg resources/covers/downloads-ru.svg + resources/covers/my wave.svg + resources/covers/my wave-ru.svg resources/placeholders/playlist.svg diff --git a/resources/covers/my wave-ru.svg b/resources/covers/my wave-ru.svg new file mode 100644 index 0000000..9389588 --- /dev/null +++ b/resources/covers/my wave-ru.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/covers/my wave.svg b/resources/covers/my wave.svg new file mode 100644 index 0000000..2a78d39 --- /dev/null +++ b/resources/covers/my wave.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/api.nim b/src/api.nim index 17ef47e..1e611af 100644 --- a/src/api.nim +++ b/src/api.nim @@ -393,14 +393,17 @@ proc liked*(playlist: Playlist): Future[seq[bool]] {.async.} = proc toRadio*(track: Track): Future[Radio] {.async.} = case track.kind of yandex: - return Radio(kind: yandex, yandex: track.yandex.getRadioStation.toRadio.await) + return Radio(kind: yandex, yandex: yandexMusic.toRadio(track.yandex.getRadioStation).await) of yandexFromFile: - return Radio(kind: yandex, yandex: track.yandexFromFile.id.getRadioStation.toRadio.await) + return Radio(kind: yandex, yandex: yandexMusic.toRadio(track.yandexFromFile.id.getRadioStation).await) of yandexIdOnly: - return Radio(kind: yandex, yandex: track.yandexIdOnly.getRadioStation.toRadio.await) + return Radio(kind: yandex, yandex: yandexMusic.toRadio(track.yandexIdOnly.getRadioStation).await) else: raise ValueError.newException("can't convert this track to radio") +proc toRadio*(station: RadioStation): Future[Radio] {.async.} = + return Radio(kind: yandex, yandex: yandexMusic.toRadio(station).await) + proc next*(radio: Radio, totalPlayedSeconds: int) {.async.} = case radio.kind of yandex: diff --git a/src/gui/audio.nim b/src/gui/audio.nim index 8b8734f..0fbc9f4 100644 --- a/src/gui/audio.nim +++ b/src/gui/audio.nim @@ -2,7 +2,7 @@ import sequtils, strutils, options, times, math, random, algorithm, os import ../api, ../utils, ../async, ../taglib import qt, messages, configuration -import ../yandexMusic except Track, Radio +import ../yandexMusic except Track, Radio, toRadio {.experimental: "overloadableEnums".} @@ -11,10 +11,10 @@ randomize() type TrackSequence = ref object current: int + yandexId: (int, int) case isRadio: bool of false: tracks: seq[Track] - yandexId: (int, int) history: seq[int] shuffle, loop: bool of true: @@ -230,8 +230,8 @@ proc play*(tracks: seq[Track], yandexId = (0, 0), trackToStartFrom: int) {.async currentSequence.loop = config.loop == LoopMode.playlist await play currentSequence.curr -proc play*(radio: Radio) {.async.} = - currentSequence = TrackSequence(isRadio: true, radio: radio) +proc play*(radio: Radio, yandexId = (0, 0)) {.async.} = + currentSequence = TrackSequence(isRadio: true, radio: radio, yandexId: yandexId) await play currentSequence.curr @@ -374,21 +374,12 @@ qobject PlayingTrackInfo: property int playlistId: get: - if currentSequence.isRadio: - currentSequence.radio.current.id - else: - currentSequence.yandexId[0] + currentSequence.yandexId[0] notify infoChanged property int playlistOwner: get: - const yandexRadioOwner = -2 - if currentSequence.isRadio: - case currentSequence.radio.kind - of yandex: - yandexRadioOwner - else: - currentSequence.yandexId[1] + currentSequence.yandexId[1] notify infoChanged property bool canStartYandexRadio: @@ -575,6 +566,7 @@ qobject AudioPlayer: getTrackAudioProcess = doAsync: case id of 1: await play(downloadedYandexTracks(), (1, 0)) + of 2: await play(myWaveRadioStation().toRadio.await, (2, 0)) else: discard proc playDmPlaylist(id: int, trackToStartFrom: int) = @@ -582,6 +574,7 @@ qobject AudioPlayer: getTrackAudioProcess = doAsync: case id of 1: await play(downloadedYandexTracks(), (1, 0), trackToStartFrom) + of 2: await play(myWaveRadioStation().toRadio.await, (2, 0)) # todo else: discard proc addUserTrack(file, cover, title, comment, artists: string) = diff --git a/src/gui/yandexMusicQmlModule.nim b/src/gui/yandexMusicQmlModule.nim index 324631b..58ead14 100644 --- a/src/gui/yandexMusicQmlModule.nim +++ b/src/gui/yandexMusicQmlModule.nim @@ -122,11 +122,23 @@ proc getHomePlaylists: Future[seq[Playlist]] {.async.} = ownerId: currentUser().await.id, title: tr"Favorites" ) + result.insert Playlist( + id: 2, + ownerId: 0, + title: tr"My wave" + ), 1 proc cover(playlist: Playlist): Future[string] {.async.} = return - if playlist.id == 3: tr"qrc:/resources/covers/favorite.svg" - else: playlist.coverBase64(400).await + case playlist.ownerId + of 0: + case playlist.id + of 2: tr"qrc:/resources/covers/my wave.svg" + else: emptyCover + else: + case playlist.id + of 3: tr"qrc:/resources/covers/favorite.svg" + else: playlist.coverBase64(400).await qmodel HomePlaylistsModel: rows: self.result.len + 1 diff --git a/src/yandexMusic.nim b/src/yandexMusic.nim index 8882b4a..3564051 100644 --- a/src/yandexMusic.nim +++ b/src/yandexMusic.nim @@ -370,6 +370,11 @@ proc playlist*(user: Account, id: int): Future[Playlist] {.async.} = proc getRadioStation*(x: Track|TrackId): RadioStation = RadioStation(id: "track:" & $x.id, stationFrom: "track") + +proc myWaveRadioStation*: RadioStation = + RadioStation(id: "user:onyourwave", stationFrom: "user") + + proc getTracks*(x: RadioStation, prev: Track = Track()): Future[tuple[tracks: seq[Track], batchId: string]] {.async.} = var params = @{ "settings2": "true", diff --git a/translations/ru.json b/translations/ru.json index e8948e2..05e8dda 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -19,6 +19,9 @@ } }, "src/gui/yandexMusicQmlModule.nim": { + "My wave": { + "": "Моя волна" + }, "Downloads": { "": "Загружено" }, @@ -28,6 +31,9 @@ "Favorites": { "": "Нравится" }, + "qrc:/resources/covers/my wave.svg": { + "": "qrc:/resources/covers/my wave-ru.svg" + }, "qrc:/resources/covers/favorite.svg": { "": "qrc:/resources/covers/favorite-ru.svg" }