Skip to content

Commit

Permalink
new years changes
Browse files Browse the repository at this point in the history
Signed-off-by: Conrad Hübler <Conrad.Huebler@gmx.net>
  • Loading branch information
conradhuebler committed Jan 1, 2025
1 parent 9b1922e commit 13e43f3
Show file tree
Hide file tree
Showing 9 changed files with 666 additions and 111 deletions.
29 changes: 29 additions & 0 deletions qml/components/TidalApi.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Item {
signal cacheTrack(var track_info)
signal cacheAlbum(var album_info)
signal cacheArtist(var artist_info)
signal albumofArtist(var album_info)
signal topTracksofArtist(var track_info)
signal similarArtist(var artist_info)
signal noSimilarArtists()

signal playlistTrackAdded(var track_info)
signal albumTrackAdded(var track_info)
Expand Down Expand Up @@ -117,6 +121,21 @@ Item {
tidalApi.cacheAlbum(album_info)
})

setHandler('TopTrackofArtist', function(track_info) {
tidalApi.topTracksofArtist(track_info)
})

setHandler('AlbumofArtist', function(album_info) {
tidalApi.albumofArtist(album_info)
})

setHandler('SimilarArtist', function(artist_info) {
tidalApi.similarArtist(artist_info)
})

setHandler('noSimilarArtists', function() {
tidalApi.noSimilarArtists()
})

// Search Handler
setHandler('addTrack', function(id, title, album, artist, image, duration) {
Expand Down Expand Up @@ -374,7 +393,17 @@ Item {
pythonTidal.call('tidal.Tidaler.get_favorite_tracks', [])
}

function getAlbumsofArtist(artistid) {
pythonTidal.call('tidal.Tidaler.getAlbumsofArtist', [artistid])
}

function getTopTracksofArtist(artistid) {
pythonTidal.call('tidal.Tidaler.getTopTracksofArtist', [artistid])
}

function getSimiliarArtist(artistid) {
pythonTidal.call('tidal.Tidaler.getSimiliarArtist', [artistid])
}
}


126 changes: 103 additions & 23 deletions qml/components/TidalCache.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ id: root
target: tidalApi

// Bestehende Connections
/*
onTrackChanged: {
// id, title, album, artist, image, duration
saveTrackToCache({
id: id,
trackid: trackid,
albumid: albumid,
artistid: artistid,
title: title,
album: album,
artist: artist,
Expand All @@ -35,9 +38,10 @@ id: root
onAlbumChanged: {
// id, title, artist, image
saveAlbumToCache({
id: id,
albumid: albumid,
title: title,
artist: artist,
artistid: artistid,
image: image,
timestamp: Date.now()
})
Expand All @@ -46,25 +50,27 @@ id: root
onArtistChanged: {
// id, name, img
saveArtistToCache({
id: id,
artistid: artistid,
name: name,
image: img,
timestamp: Date.now()
})
}

*/
// Neue Connections für Suchergebnisse

onCacheTrack: {
//track_info
saveTrackToCache({
id: track_info.id,
trackid: track_info.trackid,
title: track_info.title,
album: track_info.album,
artist: track_info.artist,
image: track_info.image,
duration: track_info.duration,
artistid:track_info.artistid,
album: track_info.album,
albumid: track_info.albumid,
duration: track_info.duration,
image: track_info.image,
track_num : track_info.track_num,
timestamp: Date.now(),
fromSearch: true // Optional: markiert Einträge aus der Suche
})
Expand All @@ -73,10 +79,10 @@ id: root
onCacheArtist: {
//artist_info
saveArtistToCache({
id: artist_info.id,
artistid: artist_info.artistid,
name: artist_info.name,
bio: artist_info.bio,
image: artist_info.image,
bio: artist_info.bio,
timestamp: Date.now(),
fromSearch: true // Optional: markiert Einträge aus der Suche
})
Expand All @@ -85,19 +91,25 @@ id: root
onCacheAlbum: {
//album_info
saveAlbumToCache({
id: album_info.id,
albumid: album_info.albumid,
title: album_info.title,
artist: album_info.artist,
artistid: album_info.artistid,
image: album_info.image,
duration: album_info.duration,
num_tracks : album_info.num_tracks,
year : album_info.year,
timestamp: Date.now(),
fromSearch: true // Optional: markiert Einträge aus der Suche
})
}
/*
onTrackAdded: {
// id, title, album, artist, image, duration
saveTrackToCache({
id: id,
trackid: trackid,
albumid: albumid,
artistid: artistid,
title: title,
album: album,
artist: artist,
Expand All @@ -111,7 +123,8 @@ id: root
onAlbumAdded: {
// id, title, artist, image, duration
saveAlbumToCache({
id: id,
albumid: albumid,
artistid: artistid,
title: title,
artist: artist,
image: image,
Expand All @@ -130,7 +143,7 @@ id: root
timestamp: Date.now(),
fromSearch: true
})
}
}*/
}

// Optional: Erweiterte Such-spezifische Funktionen
Expand All @@ -150,7 +163,7 @@ id: root
function addSearchTrack(id) {
if (!searchResults.tracks.includes(id)) {
searchResults.tracks.push(id)
}d, title, artist, image, duration
}
}

function addSearchAlbum(id) {
Expand Down Expand Up @@ -207,7 +220,9 @@ id: root
var result = tidalApi.getTrackInfo(id)
if (result) {
var trackData = {
id: id,
trackid: id,
albumid: result.albumid,
artistid: result.artistid,
title: result.title,
artist: result.artist,
album: result.album,
Expand All @@ -222,9 +237,73 @@ id: root
return null
}

function getAlbumInfo(id) {
// Erst im Cache nachsehen
var cachedTrack = getAlbum(id)
if (cachedTrack) {
if (Date.now() - cachedTrack.timestamp < maxCacheAge) {
return cachedTrack
} else {
console.log("Cache entry too old, refreshing...")
}
}

// Wenn nicht im Cache oder zu alt, von Python holen

var result = tidalApi.getAlbumInfo(id)
if (result) {
var trackData = {
albumid: id,
title: result.title,
artist: result.artist,
artistid: result.artistid,
image : result.image,
duration: result.duration,
num_tracks : result.num_tracks,
year : result.year,
timestamp: Date.now()
}

saveAlbumToCache(trackData)
return trackData
}

return null
}

function getArtistInfo(id) {
// Erst im Cache nachsehen
var cachedTrack = getArtist(id)
if (cachedTrack) {
if (Date.now() - cachedTrack.timestamp < maxCacheAge) {
return cachedTrack
} else {
console.log("Cache entry too old, refreshing...")
}
}

// Wenn nicht im Cache oder zu alt, von Python holen

var result = tidalApi.getArtistInfo(id)
if (result) {
var trackData = {
artistid: id,
name: result.name,
image : result.image,
bio : result.bio,
timestamp: Date.now()
}

saveAlbumToCache(trackData)
return trackData
}

return null
}

// Datenbank initialisieren
function initDatabase() {
db = LocalStorage.openDatabaseSync("TidalCache", "1.1", "Cache for Tidal data", 1000000)
db = LocalStorage.openDatabaseSync("TidalCache", "1.2", "Cache for Tidal data", 1000000)
db.transaction(function(tx) {
// Tracks Tabelle
tx.executeSql('CREATE TABLE IF NOT EXISTS tracks(id TEXT PRIMARY KEY, data TEXT, timestamp INTEGER)')
Expand Down Expand Up @@ -268,6 +347,7 @@ id: root
for(i = 0; i < rs.rows.length; i++) {
try {
artistCache[rs.rows.item(i).id] = JSON.parse(rs.rows.item(i).data)
//console.log(artistCache[rs.rows.item(i).id].artistid, artistCache[rs.rows.item(i).id].name)
} catch(e) {
console.error("Error parsing artist data:", e)
}
Expand All @@ -278,26 +358,26 @@ id: root

// Cache-Speicherfunktionen
function saveTrackToCache(trackData) {
trackCache[trackData.id] = trackData
trackCache[trackData.trackid] = trackData
db.transaction(function(tx) {
tx.executeSql('INSERT OR REPLACE INTO tracks(id, data, timestamp) VALUES(?, ?, ?)',
[trackData.id, JSON.stringify(trackData), trackData.timestamp])
[trackData.trackid, JSON.stringify(trackData), trackData.timestamp])
})
}

function saveAlbumToCache(albumData) {
albumCache[albumData.id] = albumData
albumCache[albumData.albumid] = albumData
db.transaction(function(tx) {
tx.executeSql('INSERT OR REPLACE INTO albums(id, data, timestamp) VALUES(?, ?, ?)',
[albumData.id, JSON.stringify(albumData), albumData.timestamp])
[albumData.albumid, JSON.stringify(albumData), albumData.timestamp])
})
}

function saveArtistToCache(artistData) {
artistCache[artistData.id] = artistData
artistCache[artistData.artistidid] = artistData
db.transaction(function(tx) {
tx.executeSql('INSERT OR REPLACE INTO artists(id, data, timestamp) VALUES(?, ?, ?)',
[artistData.id, JSON.stringify(artistData), artistData.timestamp])
[artistData.artistid, JSON.stringify(artistData), artistData.timestamp])
})
}

Expand Down
53 changes: 42 additions & 11 deletions qml/pages/AlbumPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,45 @@ Page {
spacing: Theme.paddingSmall
anchors.verticalCenter: parent.verticalCenter

Label {
id: artistName
width: parent.width
text: albumData ? albumData.artist : ""
truncationMode: TruncationMode.Fade
color: Theme.highlightColor
font.pixelSize: Theme.fontSizeLarge
}
BackgroundItem {
width: parent.width
height: artistRow.height + Theme.paddingMedium * 2

Rectangle {
anchors.fill: parent
color: Theme.rgba(Theme.highlightBackgroundColor, parent.pressed ? 0.3 : 0.1)
radius: Theme.paddingSmall
}

Row {
id: artistRow
anchors.centerIn: parent
spacing: Theme.paddingMedium

Image {
id: artistIcon
source: "image://theme/icon-s-person"
width: Theme.iconSizeSmall
height: width
anchors.verticalCenter: parent.verticalCenter
}

Label {
id: artistName
text: albumData ? albumData.artist : ""
truncationMode: TruncationMode.Fade
color: parent.parent.pressed ? Theme.highlightColor : Theme.primaryColor
font.pixelSize: Theme.fontSizeLarge
}
}

onClicked: {
if (albumData && albumData.artistid) {
pageStack.push(Qt.resolvedUrl("ArtistPage.qml"),
{ artistId: albumData.artistid })
}
}
}

Label {
width: parent.width
Expand All @@ -102,7 +133,7 @@ Page {

Label {
width: parent.width
text: albumData ? qsTr("Released: ") + albumData.releaseDate : ""
text: albumData ? qsTr("Released: ") + albumData.year : ""
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeSmall
opacity: isHeaderCollapsed ? 0.0 : 1.0
Expand All @@ -112,7 +143,7 @@ Page {

Label {
width: parent.width
text: albumData ? qsTr("Tracks: ") + albumData.numberOfTracks : ""
text: albumData ? qsTr("Tracks: ") + albumData.num_tracks : ""
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeSmall
opacity: isHeaderCollapsed ? 0.0 : 1.0
Expand Down Expand Up @@ -172,7 +203,7 @@ Page {
}

Label {
text: albumData ? qsTr("%n tracks", "", albumData.numberOfTracks) : ""
text: albumData ? qsTr("%n tracks", "", albumData.num_tracks) : ""
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeExtraSmall
anchors.verticalCenter: parent.verticalCenter
Expand Down
Loading

0 comments on commit 13e43f3

Please sign in to comment.