add year parameter to database queries

This commit is contained in:
iou1name 2020-10-05 11:51:43 -04:00
parent 7e4c6f7da1
commit 9641a510e5
2 changed files with 15 additions and 6 deletions

View File

@ -25,13 +25,17 @@ async def select_album(request, ws, data):
"""Select an album.""" """Select an album."""
artist = data.get('artist', '') artist = data.get('artist', '')
album = data.get('album', '') album = data.get('album', '')
date = data.get('date', '')
async with request.app['pool'].acquire() as conn: async with request.app['pool'].acquire() as conn:
tracks = await conn.fetch( tracks = await conn.fetch(
"SELECT DISTINCT discnumber, tracknumber, title FROM track " "SELECT * FROM track "
"WHERE albumartist = $1 AND album = $2 " "WHERE albumartist = $1 AND album = $2 AND date = $3"
"ORDER BY discnumber ASC, tracknumber ASC", "ORDER BY discnumber ASC, tracknumber ASC",
artist, album) artist, album, date)
tracks = [dict(record) for record in tracks] tracks = [dict(record) for record in tracks]
for track in tracks:
track.pop('filepath')
track.pop('last_modified')
ret = {'event': 'album_tracks', 'ok': True, 'data': tracks} ret = {'event': 'album_tracks', 'ok': True, 'data': tracks}
await ws.send_json(ret) await ws.send_json(ret)
@ -40,14 +44,15 @@ async def select_track(request, ws, data):
"""Select a track.""" """Select a track."""
artist = data.get('artist', '') artist = data.get('artist', '')
album = data.get('album', '') album = data.get('album', '')
date = data.get('date', '')
discnumber = data.get('discnumber', '') discnumber = data.get('discnumber', '')
tracknumber = data.get('tracknumber', '') tracknumber = data.get('tracknumber', '')
async with request.app['pool'].acquire() as conn: async with request.app['pool'].acquire() as conn:
track = await conn.fetchrow( track = await conn.fetchrow(
"SELECT * FROM track " "SELECT * FROM track "
"WHERE albumartist = $1 AND album = $2 " "WHERE albumartist = $1 AND album = $2 AND date = $3 "
"AND discnumber = $3 AND tracknumber = $4", "AND discnumber = $4 AND tracknumber = $5",
artist, album, discnumber, tracknumber) artist, album, date, discnumber, tracknumber)
track = dict(track) track = dict(track)
fpath = track.pop('filepath') fpath = track.pop('filepath')
track.pop('last_modified') track.pop('last_modified')

View File

@ -72,6 +72,7 @@ function artist_albums_recv(data) {
let option = document.createElement('option'); let option = document.createElement('option');
option.value = album['album']; option.value = album['album'];
option.innerText = album['album']; option.innerText = album['album'];
option.dataset['date'] = album['date']
albums_list.appendChild(option); albums_list.appendChild(option);
} }
} }
@ -85,6 +86,7 @@ function album_tracks_recv(data) {
let option = document.createElement('option'); let option = document.createElement('option');
option.value = track['title']; option.value = track['title'];
option.innerText = track['discnumber'] + '.' + track['tracknumber'] + ' - ' + track['title']; option.innerText = track['discnumber'] + '.' + track['tracknumber'] + ' - ' + track['title'];
option.dataset['date'] = track['date']
option.dataset['discnumber'] = track['discnumber'] option.dataset['discnumber'] = track['discnumber']
option.dataset['tracknumber'] = track['tracknumber'] option.dataset['tracknumber'] = track['tracknumber']
track_list.appendChild(option); track_list.appendChild(option);
@ -115,6 +117,7 @@ function select_album(select) {
let data = { let data = {
'artist': document.querySelector('#artistList').value, 'artist': document.querySelector('#artistList').value,
'album': select.value, 'album': select.value,
'date': select.selectedOptions[0].dataset['date'],
}; };
ww_send_event('select_album', data); ww_send_event('select_album', data);
} }
@ -123,6 +126,7 @@ function select_track(select) {
let data = { let data = {
'artist': document.querySelector('#artistList').value, 'artist': document.querySelector('#artistList').value,
'album': document.querySelector('#albumList').value, 'album': document.querySelector('#albumList').value,
'date': select.selectedOptions[0].dataset['date'],
'discnumber': select.selectedOptions[0].dataset['discnumber'], 'discnumber': select.selectedOptions[0].dataset['discnumber'],
'tracknumber': select.selectedOptions[0].dataset['tracknumber'], 'tracknumber': select.selectedOptions[0].dataset['tracknumber'],
}; };