From aecf1f38638be69af4e53e732646fa54fc0ef80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Conrad=20H=C3=BCbler?= Date: Thu, 26 Dec 2024 17:32:14 +0100 Subject: [PATCH] make playlist external qml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Conrad Hübler --- qml/components/PlaylistManager.qml | 266 +++++++++++++++++++------ qml/harbour-tidalplayer.qml | 303 +++-------------------------- qml/pages/Search.qml | 3 + qml/pages/TrackList.qml | 3 + qml/playlistmanager.py | 1 + 5 files changed, 239 insertions(+), 337 deletions(-) diff --git a/qml/components/PlaylistManager.qml b/qml/components/PlaylistManager.qml index f37bb93..3ba6635 100644 --- a/qml/components/PlaylistManager.qml +++ b/qml/components/PlaylistManager.qml @@ -1,10 +1,20 @@ +// PlaylistManager.qml import QtQuick 2.0 import io.thp.pyotherside 1.5 Item { - id: root + id: playlistManager - // Signals + property var currentPlaylist: [] + property int currentIndex: -1 + property bool canNext: currentPlaylist.length > 0 && currentIndex < currentPlaylist.length - 1 + property bool canPrev: currentIndex > 0 + property int size: currentPlaylist.length + property int current_track: -1 + + signal currentTrackChanged(var track) + signal playlistChanged() + signal trackInformation(int id, int index, string title, string album, string artist, string image, int duration) signal currentId(int id) signal currentPosition(int position) signal containsTrack(int id) @@ -12,66 +22,203 @@ Item { signal currentTrack(int position) signal playListFinished() signal playListChanged() - signal trackInformation(int id, int index, string title, string album, string artist, string image, int duration) - // Properties - property bool canNext: true - property bool canPrev: true - property int size: 0 - property int current_track: 0 - - // Python Interface Python { - id: playlistPython - - Component.onCompleted: { - setHandler('printConsole', function(string) { - console.log("playlistManager::printConsole" + string) - }) - - setHandler('currentTrack', function(id, position) { - root.currentId(id) - root.currentTrack(position) - }) - - setHandler('clearList', function() { - root.clearList() - }) - - setHandler('containsTrack', function(id) { - root.containsTrack(id) - }) - - setHandler('playlistFinished', function() { - root.canNext = false - }) - setHandler('playlistUnFinished', function() { - root.canNext = true - }) + property bool canNext : true + property bool canPrev : true + property int size: 0 + property int current_track : 0 + + property string playlist_track + property string playlist_artist + property string playlist_album + property string playlist_image + property int playlist_duration + property int playlist_track_id + + id: playlistPython + + Component.onCompleted: { + + setHandler('printConsole', function(string) + { + console.log("playlistManager::printConsole" + string) + }); + + setHandler('currentTrack', function(id, position) { + console.log("Current track in playlist is", id, position) + playlistManager.currentId(id); + currentTrack(position) + }); + + setHandler('clearList', function() { + playlistManager.clearList(); + }); + + setHandler('containsTrack', function(id) { + console.log(id) + playlistManager.containsTrack(id); + }); + + setHandler('playlistFinished', function() { + console.log("Playlist Finished") + canNext = false + }); + + setHandler('playlistUnFinished', function() { + console.log("Playlist unfinished") + canNext = true + }); + + importModule('playlistmanager', function () {}); + } + + function appendTrack(id) { + console.log("PlaylistMagaer.appendTrack", id) + + call('playlistmanager.PL.AppendTrack', [id], {}); + canNext = true + } + + function currentTrackIndex() + { + call("playlistmanager.PL.PlaylistIndex", [], function(index){ + current_track = index + }); + } + + function getSize() + { + call("playlistmanager.PL.size", [], function(name){ + tracks = name + }); + } + + function requestPlaylistItem(index) + { + console.log("Request PlaylistTrack", index) + call("playlistmanager.PL.TidalId", [index], function(id){ + var track = pythonApi.getTrackInfo(id) + trackInformation(id, index, track[1], track[2], track[3], track[4], track[5]) + }); + } + + function playAlbum(id) + { + console.log("playalbum", id) + playlistManager.clearPlayList() + currentTrackIndex() + pythonApi.playAlbumTracks(id) + } + + function playAlbumFromTrack(id) + { + playlistManager.clearPlayList() + pythonApi.playAlbumFromTrack(id) + currentTrackIndex() + } + + function playTrack(id) { + mediaPlayer.blockAutoNext = true + console.log("PythonQMLQMP", id); + call('playlistmanager.PL.PlayTrack', [id], {}); + currentTrackIndex() + } + + function playPosition(id) { + console.log(id) + playlistPython.canNext = false + mediaPlayer.blockAutoNext = true + call('playlistmanager.PL.PlayPosition', [id], {}); + currentTrackIndex() + } + + function insertTrack(id) { + console.log("PlaylistMagaer.insertTrack", id) + + call('playlistmanager.PL.InsertTrack', [id], {}); + currentTrackIndex() + } + + + function nextTrack() { + console.log("Next track called") + if(mediaPlayer.playbackState !== 1 ) + { + playlistPython.canNext = false + call('playlistmanager.PL.NextTrack', function() {}); + } + currentTrackIndex() + } + + function nextTrackClicked() { + console.log("Next track called") + mediaPlayer.blockAutoNext = true + + playlistPython.canNext = false + call('playlistmanager.PL.NextTrack', function() {}); + currentTrackIndex() + } + + function restartTrack(id) { + console.log(id) + + call('playlistmanager.PL.RestartTrack', function() {}); + currentTrackIndex() + } + + function previousTrack() { + playlistPython.canNext = false + call('playlistmanager.PL.PreviousTrack', function() {}); + currentTrackIndex() + } + + function previousTrackClicked() { + playlistPython.canNext = false + mediaPlayer.blockAutoNext = true + call('playlistmanager.PL.PreviousTrack', function() {}); + currentTrackIndex() + } + + function generateList() + { + + console.log("Playlist changed from main.qml") + call("playlistmanager.PL.size", [], function(tracks){ + console.log("got ", tracks, " as name") + size = tracks + playlistManager.playListChanged(); + }); + } + + function clearPlayList() + { + call('playlistmanager.PL.clearList', function() {}); + } +} - importModule('playlistmanager', function() {}) - } + function clearPlayList() + { + playlistPython.call('playlistmanager.PL.clearList', function() {}); } - - // Public Functions function appendTrack(id) { console.log("PlaylistMagaer.appendTrack", id) - call('playlistmanager.PL.AppendTrack', [id], {}); + playlistPython.call('playlistmanager.PL.AppendTrack', [id], {}); canNext = true } function currentTrackIndex() { - call("playlistmanager.PL.PlaylistIndex", [], function(index){ + playlistPython.call("playlistmanager.PL.PlaylistIndex", [], function(index){ current_track = index }); } function getSize() { - call("playlistmanager.PL.size", [], function(name){ + playlistPython.call("playlistmanager.PL.size", [], function(name){ tracks = name }); } @@ -79,7 +226,7 @@ Item { function requestPlaylistItem(index) { console.log("Request PlaylistTrack", index) - call("playlistmanager.PL.TidalId", [index], function(id){ + playlistPython.call("playlistmanager.PL.TidalId", [index], function(id){ var track = pythonApi.getTrackInfo(id) trackInformation(id, index, track[1], track[2], track[3], track[4], track[5]) }); @@ -88,27 +235,28 @@ Item { function playAlbum(id) { console.log("playalbum", id) - playlistManager.clearPlayList() + clearPlayList() currentTrackIndex() pythonApi.playAlbumTracks(id) } function playAlbumFromTrack(id) { - playlistManager.clearPlayList() + clearPlayList() pythonApi.playAlbumFromTrack(id) currentTrackIndex() } function playTrack(id) { + console.log("Playlistmanager::playtrack", id) mediaPlayer.blockAutoNext = true - call('playlistmanager.PL.PlayTrack', [id], {}); + playlistPython.playTrack(id)//call('playlistmanager.PL.PlayTrack', [id], {}); currentTrackIndex() } function playPosition(id) { console.log(id) - playlistManager.canNext = false + playlistPython.canNext = false mediaPlayer.blockAutoNext = true call('playlistmanager.PL.PlayPosition', [id], {}); currentTrackIndex() @@ -126,7 +274,7 @@ Item { console.log("Next track called") if(mediaPlayer.playbackState !== 1 ) { - playlistManager.canNext = false + playlistPython.canNext = false call('playlistmanager.PL.NextTrack', function() {}); } currentTrackIndex() @@ -136,28 +284,28 @@ Item { console.log("Next track called") mediaPlayer.blockAutoNext = true - playlistManager.canNext = false - call('playlistmanager.PL.NextTrack', function() {}); + playlistPython.canNext = false + playlistPython.call('playlistmanager.PL.NextTrack', function() {}); currentTrackIndex() } function restartTrack(id) { console.log(id) - call('playlistmanager.PL.RestartTrack', function() {}); + playlistPython.call('playlistmanager.PL.RestartTrack', function() {}); currentTrackIndex() } function previousTrack() { - playlistManager.canNext = false - call('playlistmanager.PL.PreviousTrack', function() {}); + playlistPython.canNext = false + playlistPython.call('playlistmanager.PL.PreviousTrack', function() {}); currentTrackIndex() } function previousTrackClicked() { - playlistManager.canNext = false + playlistPython.canNext = false mediaPlayer.blockAutoNext = true - call('playlistmanager.PL.PreviousTrack', function() {}); + playlistPython.call('playlistmanager.PL.PreviousTrack', function() {}); currentTrackIndex() } @@ -165,15 +313,11 @@ Item { { console.log("Playlist changed from main.qml") - call("playlistmanager.PL.size", [], function(tracks){ + playlistPython.call("playlistmanager.PL.size", [], function(tracks){ console.log("got", tracks, " as name") size = tracks playlistManager.playListChanged(); }); } - function clearPlayList() - { - call('playlistmanager.PL.clearList', function() {}); - } } diff --git a/qml/harbour-tidalplayer.qml b/qml/harbour-tidalplayer.qml index 4fced82..3cfb47d 100644 --- a/qml/harbour-tidalplayer.qml +++ b/qml/harbour-tidalplayer.qml @@ -17,29 +17,6 @@ ApplicationWindow property var locale: Qt.locale() property date currentDate: new Date() property MiniPlayer minPlayerPanel : miniPlayerPanel -/* - ConfigurationValue { - id: token_type - key:"/token_type" - } - - ConfigurationValue { - id: access_token - key:"/access_token" - value:"" - } - - ConfigurationValue { - id: refresh_token - key:"/refresh_token" - } - - ConfigurationValue { - id: expiry_time - key:"/expiry_time" - } -*/ - MprisPlayer{ id: mprisPlayer @@ -69,6 +46,16 @@ ApplicationWindow } + PlaylistManager { + id: playlistManager + onCurrentTrackChanged: { + if (track) { + pythonApi.playTrackId(track.id) + console.log("playlistmanager call id", track) + } + } + } + MediaPlayer { id: mediaPlayer autoLoad: true @@ -132,188 +119,6 @@ ApplicationWindow } } - Python { - signal currentId(int id) - signal currentPosition(int position) - signal containsTrack(int id) - signal clearList() - signal currentTrack(int position) - signal playListFinished() - signal playListChanged() - signal trackInformation(int id, int index, string title, string album, string artist, string image, int duration) - - property bool canNext : true - property bool canPrev : true - property int size: 0 - property int current_track : 0 - - property string playlist_track - property string playlist_artist - property string playlist_album - property string playlist_image - property int playlist_duration - property int playlist_track_id - - id: playlistManager - - Component.onCompleted: { - - setHandler('printConsole', function(string) - { - console.log("playlistManager::printConsole" + string) - }); - - setHandler('currentTrack', function(id, position) { - console.log(id, position) - playlistManager.currentId(id); - playlistManager.currentTrack(position) - }); - - setHandler('clearList', function() { - playlistManager.clearList(); - }); - - setHandler('containsTrack', function(id) { - console.log(id) - playlistManager.containsTrack(id); - }); - - setHandler('playlistFinished', function() { - console.log("Playlist Finished") - canNext = false - }); - - setHandler('playlistUnFinished', function() { - console.log("Playlist unfinished") - canNext = true - }); - - importModule('playlistmanager', function () {}); - } - - function appendTrack(id) { - console.log("PlaylistMagaer.appendTrack", id) - - call('playlistmanager.PL.AppendTrack', [id], {}); - canNext = true - } - - function currentTrackIndex() - { - call("playlistmanager.PL.PlaylistIndex", [], function(index){ - current_track = index - }); - } - - function getSize() - { - call("playlistmanager.PL.size", [], function(name){ - tracks = name - }); - } - - function requestPlaylistItem(index) - { - console.log("Request PlaylistTrack", index) - call("playlistmanager.PL.TidalId", [index], function(id){ - var track = pythonApi.getTrackInfo(id) - trackInformation(id, index, track[1], track[2], track[3], track[4], track[5]) - }); - } - - function playAlbum(id) - { - console.log("playalbum", id) - playlistManager.clearPlayList() - currentTrackIndex() - pythonApi.playAlbumTracks(id) - } - - function playAlbumFromTrack(id) - { - playlistManager.clearPlayList() - pythonApi.playAlbumFromTrack(id) - currentTrackIndex() - } - - function playTrack(id) { - mediaPlayer.blockAutoNext = true - call('playlistmanager.PL.PlayTrack', [id], {}); - currentTrackIndex() - } - - function playPosition(id) { - console.log(id) - playlistManager.canNext = false - mediaPlayer.blockAutoNext = true - call('playlistmanager.PL.PlayPosition', [id], {}); - currentTrackIndex() - } - - function insertTrack(id) { - console.log("PlaylistMagaer.insertTrack", id) - - call('playlistmanager.PL.InsertTrack', [id], {}); - currentTrackIndex() - } - - - function nextTrack() { - console.log("Next track called") - if(mediaPlayer.playbackState !== 1 ) - { - playlistManager.canNext = false - call('playlistmanager.PL.NextTrack', function() {}); - } - currentTrackIndex() - } - - function nextTrackClicked() { - console.log("Next track called") - mediaPlayer.blockAutoNext = true - - playlistManager.canNext = false - call('playlistmanager.PL.NextTrack', function() {}); - currentTrackIndex() - } - - function restartTrack(id) { - console.log(id) - - call('playlistmanager.PL.RestartTrack', function() {}); - currentTrackIndex() - } - - function previousTrack() { - playlistManager.canNext = false - call('playlistmanager.PL.PreviousTrack', function() {}); - currentTrackIndex() - } - - function previousTrackClicked() { - playlistManager.canNext = false - mediaPlayer.blockAutoNext = true - call('playlistmanager.PL.PreviousTrack', function() {}); - currentTrackIndex() - } - - function generateList() - { - - console.log("Playlist changed from main.qml") - call("playlistmanager.PL.size", [], function(tracks){ - console.log("got", tracks, " as name") - size = tracks - playlistManager.playListChanged(); - }); - } - - function clearPlayList() - { - call('playlistmanager.PL.clearList', function() {}); - } - } - Python { signal authUrl(string url) signal loginSuccess() @@ -414,46 +219,7 @@ ApplicationWindow setHandler('albumsSearchFinished', function() { pythonApi.albumSearchFinished() }); -/* - setHandler('oauth_success', function() { - pythonApi.loginIn() - }); - - setHandler('oauth_login_success', function() { - loginTrue = true - console.log("Login Successful") - pythonApi.loginSuccess() - }); - - setHandler('oauth_login_failed', function() { - loginTrue = false - pythonApi.loginFailed() - }); - - setHandler('get_token', function(type, token, rtoken, date) { - token_type.value = type - access_token.value = token - - refresh_token.value = rtoken - expiry_time.value = date - console.log(expiry_time) - loginTrue = true - pythonApi.loginSuccess() - pythonApi.loginIn() - - }); - - setHandler('oauth_updated', function(type, token, rtoken, date) { - token_type.value = type - access_token.value = token - refresh_token.value = rtoken - expiry_time.value = date - pythonApi.loginSuccess() - pythonApi.loginIn() - - }); - */ setHandler('oauth_failed',function() { pythonApi.loginFailed() }); @@ -499,36 +265,6 @@ ApplicationWindow } - function printLogin() - { - console.log(token_type.value+ "\n" + access_token.value + "\n" + refresh_token.value + "\n" + expiry_time.value) - } - - function getOAuth() { - call('tidal.Tidaler.request_oauth', function() {}); - } - - function loginIn() { - console.log("Want login now") - console.log(expiry_time.value) - console.log(currentDate.toLocaleString(locale, "yyyy-MM-ddThh:mm:ss")) - print(Date.fromLocaleString(locale, expiry_time.value, "yyyy-MM-ddThh:mm:ss")); - console.log(Date.fromLocaleString(locale, expiry_time.value, "yyyy-MM-ddThh:mm:ss") < currentDate) - if(Date.fromLocaleString(locale, expiry_time.value, "yyyy-MM-ddThh:mm:ss") > currentDate) - { - console.log("Valid login time"); - //console.log(token_type.value, access_token.value, refresh_token.value, expiry_time.value); - call('tidal.Tidaler.login', [token_type.value, access_token.value, refresh_token.value, expiry_time.value], {}); - } - else - { - console.log("inValid login time"); - //console.log(token_type.value, refresh_token.value, refresh_token.value, expiry_time.value); - call('tidal.Tidaler.login', [token_type.value, refresh_token.value, refresh_token.value, expiry_time.value], {}); - console.log("Need to renew login") - } - - } function genericSearch(text) { call("tidal.Tidaler.genericSearch", [text], {}); @@ -631,19 +367,33 @@ ApplicationWindow loginTrue = false authManager.clearTokens() } + // Neue Handler für Tracks + onTrackAdded: { + // Wenn ein Track aus der Suche hinzugefügt wird + console.log("TidalApi: Track added signal", id, title) + playlistManager.appendTrack({ + id: id, + title: title, + album: album, + artist: artist, + image: image, + duration: duration + }) + } } Component.onCompleted: { authManager.checkAndLogin() mprisPlayer.setCanControl(true) + importModule('playlistmanager', function () { + console.log("Playlist module imported successfully") + }); } - // Neue Connections für TidalApi Connections { target: tidalApi onOAuthSuccess: { - // Diese Funktion wird aufgerufen, wenn neue Tokens empfangen werden authManager.updateTokens(type, token, rtoken, date) } onLoginFailed: { @@ -657,6 +407,7 @@ ApplicationWindow target: playlistManager onCurrentId: { + console.log("From playlistmanager") pythonApi.playTrackId(id) } } diff --git a/qml/pages/Search.qml b/qml/pages/Search.qml index 1158e21..871fd57 100644 --- a/qml/pages/Search.qml +++ b/qml/pages/Search.qml @@ -220,7 +220,10 @@ Item { onClicked: { console.log(listModel.get(model.index).type) if(listModel.get(model.index).type === 1) + { + console.log("play track ", listModel.get(model.index).id) playlistManager.playTrack(listModel.get(model.index).id) + } else if(listModel.get(model.index).type === 2) playlistManager.playAlbum(listModel.get(model.index).id) else if(listModel.get(model.index).type === 4) diff --git a/qml/pages/TrackList.qml b/qml/pages/TrackList.qml index 059072e..ad713f3 100644 --- a/qml/pages/TrackList.qml +++ b/qml/pages/TrackList.qml @@ -186,7 +186,10 @@ SilicaListView { onClicked: { console.log(listModel.get(model.index).type) if(listModel.get(model.index).type === 1) + { + console.log("play track ", listModel.get(model.index).id) playlistManager.playTrack(listModel.get(model.index).id) + } else if(listModel.get(model.index).type === 2) playlistManager.playAlbum(listModel.get(model.index).id) highlight_index = model.index diff --git a/qml/playlistmanager.py b/qml/playlistmanager.py index 4e8c9fb..c0522da 100644 --- a/qml/playlistmanager.py +++ b/qml/playlistmanager.py @@ -18,6 +18,7 @@ def _notify_playlist_state(self): def _notify_current_track(self): """Benachrichtigt über den aktuellen Track""" + if 0 <= self.current_index < len(self.playlist): pyotherside.send("currentTrack", self.playlist[self.current_index],