def top_tracks(n): """ Returns the top n tracks """ try: top = [t.track for t in TrackStatistics.select(orderBy=DESC(TrackStatistics.q.play_count))[:10]] if len(top) < n: top = top + [track for track in Track.select()[:n-len(top)] if track not in top] return top except SQLObjectNotFound: return []
def recently_played(n): """ Returns n latest played tracks """ try: recent = [t.track for t in TrackStatistics.select(orderBy=DESC(TrackStatistics.q.last_played))[:10]] if len(recent) < n: recent = recent + [track for track in Track.select()[:n-len(recent)] if track not in recent] return recent except SQLObjectNotFound: return []
def index(id): try: track = Track.get(id) stats = list(TrackStatistics.select(TrackStatistics.q.track == track.id)) if len(stats) > 0: stats = stats[0] else: stats = None url = request.environ['HTTP_HOST'] pos = url.rfind(':' + request.environ['SERVER_PORT']) if pos != -1: url = url[:pos] # otherwise the host is just the host without a port, # which is just what we want return render_master_page("track.html", title='Muzicast: Track', track=track, url=url, port=STREAM_PORT, stats=stats) except SQLObjectNotFound: abort(404)