html view + .json for track/artist/release
This commit is contained in:
@@ -8,6 +8,7 @@ local models = autoload("models")
|
||||
|
||||
local function Artisthandler(self)
|
||||
local artist_id = self.params.artist
|
||||
local json = self.params.json or nil
|
||||
|
||||
-- find the artist
|
||||
local artist = models.Artists:find({ id = artist_id })
|
||||
@@ -28,7 +29,7 @@ local function Artisthandler(self)
|
||||
|
||||
-- find all tracks with this artist
|
||||
local tracks = db.query([[
|
||||
SELECT track.name AS track_name, track.id
|
||||
SELECT track.name AS track_name, track.id AS track_id, track.img_url
|
||||
FROM track_artists
|
||||
INNER JOIN
|
||||
tracks AS track ON (track_artists.track = track.id)
|
||||
@@ -43,21 +44,24 @@ local function Artisthandler(self)
|
||||
|
||||
for i, track in ipairs(tracks) do
|
||||
local track_airtimes = 0
|
||||
track["last_airtime"] = ""
|
||||
local airtimes = db.query([[
|
||||
SELECT airtime, station AS station_id
|
||||
SELECT airtime
|
||||
FROM airtimes
|
||||
WHERE track = ?
|
||||
]], track["id"])
|
||||
]], track["track_id"])
|
||||
|
||||
artist["tracks"][i]["airtimes"] = {}
|
||||
-- this can probably be done in SQL directly
|
||||
for j, airtime in ipairs(airtimes) do
|
||||
table.insert(artist["tracks"][i]["airtimes"], airtime)
|
||||
track_airtimes = track_airtimes + 1
|
||||
total_airtimes = total_airtimes + 1
|
||||
|
||||
if airtime.airtime > last_airtime then
|
||||
last_airtime = airtime.airtime
|
||||
end
|
||||
if airtime.airtime > track["last_airtime"] then
|
||||
track["last_airtime"] = airtime.airtime
|
||||
end
|
||||
end
|
||||
artist["tracks"][i]["track_airtimes"] = track_airtimes
|
||||
|
||||
@@ -68,7 +72,7 @@ local function Artisthandler(self)
|
||||
INNER JOIN
|
||||
releases AS release ON (track_releases.release = release.id)
|
||||
WHERE track = ?
|
||||
]], track["id"])
|
||||
]], track["track_id"])
|
||||
|
||||
artist["tracks"][i]["releases"] = {}
|
||||
for k, release in ipairs(releases) do
|
||||
@@ -79,7 +83,12 @@ local function Artisthandler(self)
|
||||
artist["total_airtimes"] = total_airtimes
|
||||
artist["last_airtime"] = last_airtime
|
||||
|
||||
return { json = artist }
|
||||
if json then
|
||||
return { json = artist }
|
||||
end
|
||||
|
||||
self.artist = artist
|
||||
return { render = "artist" }
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ local models = autoload("models")
|
||||
|
||||
local function Releasehandler(self)
|
||||
local release_id = self.params.release
|
||||
local json = self.params.json or nil
|
||||
|
||||
local release = models.releases:find({ id = release_id })
|
||||
if not release then
|
||||
@@ -27,7 +28,7 @@ local function Releasehandler(self)
|
||||
|
||||
-- get all tracks on this release
|
||||
local tracks = db.query([[
|
||||
SELECT track.name AS track_name, track.id, artist.name AS artist_name
|
||||
SELECT track.name AS track_name, track.id AS track_id, track.img_url, artist.name AS artist_name, artist.id AS artist_id
|
||||
FROM track_releases
|
||||
INNER JOIN
|
||||
tracks AS track ON (track_releases.track = track.id)
|
||||
@@ -46,28 +47,36 @@ local function Releasehandler(self)
|
||||
|
||||
for i, track in ipairs(tracks) do
|
||||
local track_airtimes = 0
|
||||
track["last_airtime"] = ""
|
||||
local airtimes = db.query([[
|
||||
SELECT airtime, station AS station_id
|
||||
FROM airtimes
|
||||
WHERE track = ?
|
||||
]], track["id"])
|
||||
]], track["track_id"])
|
||||
|
||||
release["tracks"][i]["airtimes"] = {}
|
||||
-- this can probably be done in SQL directly
|
||||
for j, airtime in ipairs(airtimes) do
|
||||
table.insert(release["tracks"][i]["airtimes"], airtime)
|
||||
track_airtimes = track_airtimes + 1
|
||||
total_airtimes = total_airtimes + 1
|
||||
|
||||
if airtime.airtime > last_airtime then
|
||||
last_airtime = airtime.airtime
|
||||
end
|
||||
if airtime.airtime > track["last_airtime"] then
|
||||
track["last_airtime"] = airtime.airtime
|
||||
end
|
||||
end
|
||||
release["tracks"][i]["track_airtimes"] = track_airtimes
|
||||
end
|
||||
release["total_airtimes"] = total_airtimes
|
||||
release["last_airtime"] = last_airtime
|
||||
|
||||
return { json = release }
|
||||
if json then
|
||||
return { json = release }
|
||||
end
|
||||
|
||||
self.release = release
|
||||
return { render = "release" }
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ local models = autoload("models")
|
||||
|
||||
local function Trackhandler(self)
|
||||
local track_id = self.params.track
|
||||
local json = self.params.json or nil
|
||||
|
||||
local track = models.Tracks:find({ id = track_id })
|
||||
if not track then
|
||||
@@ -27,23 +28,27 @@ local function Trackhandler(self)
|
||||
|
||||
-- find the artist for this track
|
||||
local artists = db.query([[
|
||||
SELECT artist.name AS artist_name
|
||||
SELECT artist.name AS artist_name, artist.id AS artist_id
|
||||
FROM track_artists
|
||||
INNER JOIN
|
||||
artists AS artist ON (track_artists.artist = artist.id)
|
||||
artists AS artist ON (track_artists.artist = artist.id)
|
||||
WHERE track_artists.track = ?
|
||||
]], track["id"])
|
||||
|
||||
track["artist"] = artists[1]["artist_name"]
|
||||
track["artist_id"] = artists[1]["artist_id"]
|
||||
|
||||
-- find all airtimes for this track
|
||||
local track_airtimes = 0
|
||||
local last_airtime = ""
|
||||
|
||||
local airtimes = db.query([[
|
||||
SELECT airtime, station AS station_id
|
||||
SELECT airtime, station.id AS station_id, station.name AS station_name
|
||||
FROM airtimes
|
||||
WHERE track = ?
|
||||
INNER JOIN
|
||||
stations AS station ON (airtimes.station = station.id)
|
||||
WHERE track = ?
|
||||
ORDER BY airtime DESC
|
||||
]], track["id"])
|
||||
|
||||
track["airtimes"] = {}
|
||||
@@ -72,7 +77,12 @@ local function Trackhandler(self)
|
||||
track["releases"][i] = release
|
||||
end
|
||||
|
||||
return { json = track }
|
||||
if json then
|
||||
return { json = track }
|
||||
end
|
||||
|
||||
self.track = track
|
||||
return { render = "track" }
|
||||
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user