def track_search(keylist): track=[] for keyword in keylist: tmp= Track.select(Track.q.title.contains(keyword)) track.extend(tmp) track=set(track) return track
def on_moved(self, event): # a move is simple to handle, search for track # with src and modify it to dest # TODO(nikhil) handle directory move entries = list(Track.selectBy(url='file://' + event.src_path)) if entries: for entry in entries: entry.url = 'file://' + event.dest_path
def get_track(self, id): """ Get track meta-data given a track ID. Returns {} in case of failure """ try: track = Track.get(id) return track except sqlobject.main.SQLObjectNotFound: return None
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 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 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)
def requires_update(self, path): if self.full: return True stat_info = os.stat(path) if stat.S_ISDIR(stat_info.st_mode): if stat_info.st_mtime > self.last_shutdown_time: return True return False if stat.S_ISREG(stat_info.st_mode): # if file hasn't been catalogued before # index it anyway already_done = list(Track.select(Track.q.url == 'file://' + path)) if not already_done: return True if stat_info.st_mtime > self.last_shutdown_time: return True return False
def on_deleted(self, event): # instead of bothering with file/directory changes # we simply match path and drop all tracks. tracks = Track.select(Track.q.url.startswith('file://'+event.src_path)) [track.destroySelf() for track in tracks]
def find_existing(url, attrs): #TODO: improve return list(Track.select(Track.q.url == ('file://'+url)))
def playlist_entries(): if 'playlist' not in session: return [] return (Track.get(id) for id in session['playlist'])