def comment(self, user, comment): if PlaylistEntry.objects.nowPlaying().song == self: cue = CueFile(settings.LOGIC_DIR + "/ices.cue") time = cue.getTime(self) else: time = 0 c = Comment(text=comment, user=user, song=self, time=time) c.save() return time #for API
def positionContextProcessor(request): cue = CueFile(settings.LOGIC_DIR + "/ices.cue") d = {} try: now_playing = PlaylistEntry.objects.nowPlaying().song except PlaylistEntry.DoesNotExist: d['song_position'] = d['song_progress'] = d['song_length'] = 0 else: d['song_position'] = cue.getTime(now_playing) d['song_progress'] = cue.getProgress()*100 #percentagise d['song_length'] = now_playing.length return d
def positionContextProcessor(request): if not request.user.is_authenticated(): return {} cue = CueFile(settings.LOGIC_DIR + "/ices.cue") d = {} try: now_playing = PlaylistEntry.objects.nowPlaying().song except PlaylistEntry.DoesNotExist: d['song_position'] = d['song_progress'] = d['song_length'] = 0 else: d['song_position'] = cue.getTime(now_playing) d['song_progress'] = cue.getProgress() * 100 #percentagise d['song_length'] = now_playing.length return d
def positionContextProcessor(request): if not request.user.is_authenticated(): return {} cue = CueFile(settings.LOGIC_DIR + "/ices.cue") d = {} try: now_playing = PlaylistEntry.objects.nowPlaying().song except PlaylistEntry.DoesNotExist: d["song_position"] = d["song_progress"] = d["song_length"] = 0 else: d["song_position"] = cue.getTime(now_playing) d["song_progress"] = cue.getProgress() * 100 # percentagise d["song_length"] = now_playing.length return d
def ajax(request): events = [] length_changed = False #True if any actions would have changed the playlist length #new removals last_removal = int(request.REQUEST.get('last_removal', -1)) if last_removal != -1: removals = RemovedEntry.objects.filter(id__gt=last_removal) removal_events = [] if removal_events: length_changed = True for removal in removals: removal_events.append(('removal', {"entryid": removal.oldid, "id": removal.id})) if len(removal_events) > MAX_EVENTS: removal_events = removal_events[:MAX_EVENTS] events.extend(removal_events) #get now playing track client_playing = int(request.REQUEST.get('now_playing', 0)) #always output as if this isn't given it's definitely needed server_playing = PlaylistEntry.objects.nowPlaying() #check for submitted comment if request.user.has_perm("playlist.can_comment"): try: comment = request.REQUEST['comment'] except KeyError: pass else: server_playing.song.comment(request.user, comment) #TODO: handle comment being too long gracefully #check for submitted vote if request.user.has_perm("playlist.can_rate"): try: vote = request.REQUEST['vote'] except KeyError: pass else: server_playing.song.rate(vote, request.user) if server_playing.id != client_playing: events.append(('now_playing', server_playing.id)) length_changed = True #new title needed try: events.append(('metadata', PlaylistEntry.objects.nowPlaying().song.metadataString())) linkedMetadata = render_to_string('linked_metadata.html', context_instance=RequestContext(request)) events.append(('linkedMetadata', linkedMetadata)) except PlaylistEntry.DoesNotExist: pass #new song length needed events.append(('songLength', PlaylistEntry.objects.nowPlaying().song.length)) #new comments needed events.append(('clearComments', '')) comments = server_playing.song.comments.all().order_by("time") #ensure oldest first - new comments are placed at top of update list for comment in comments: events.append(comment.ajaxEvent()) else: try: last_comment = int(request.REQUEST['last_comment']) except (ValueError, TypeError, KeyError): pass else: comments = server_playing.song.comments.all().order_by("datetime").filter(id__gt=last_comment) for comment in comments: events.append(comment.ajaxEvent()) #send user vote & song avg vote_count try: user_vote = server_playing.song.ratings.get(user=request.user).score except Rating.DoesNotExist: user_vote = 0 if server_playing.song.voteno == 1: score_str = "%.1f (%d vote)" % (server_playing.song.avgscore, server_playing.song.voteno) elif server_playing.song.voteno > 1: score_str = "%.1f (%d votes)" % (server_playing.song.avgscore, server_playing.song.voteno, ) else: score_str = "no votes" events.append(('userVote', int(user_vote))) events.append(('score', score_str)) #new adds try: last_add = int(request.REQUEST['last_add']) except (ValueError, TypeError, KeyError): pass else: accuracy = 1 #TODO: replace with user setting aug_playlist = Playlist(request.user).fromLastID(last_add) if len(aug_playlist) > 0: length_changed = True if len(aug_playlist) > MAX_EVENTS: aug_playlist = aug_playlist[:MAX_EVENTS] html = render_to_string('playlist_table.html', {'aug_playlist': aug_playlist, 'accuracy':accuracy}, context_instance=RequestContext(request)) events.append(("adds", html)) if length_changed: length = PlaylistEntry.objects.length() events.append(('pllength', render_to_string('pl_length.html', {'length':length}))) #handle cuefile stuff tolerance = 5 #tolerance in seconds between real and recieved time TODO: replace with internal setting position = request.REQUEST.get('position', None) if position: cue = CueFile(settings.LOGIC_DIR + "/ices.cue") now_playing = PlaylistEntry.objects.nowPlaying().song if abs(int(position) - cue.getTime(now_playing)) >= tolerance: events.append(('songPosition', cue.getTime(now_playing))) # Add the current listener count events.append(('listeners', ListenerCount())) return HttpResponse(json.dumps(events))
if resource == "metadata2": song = getSong(request) return HttpResponse(song.artist.name + "\n" + song.album.name + "\n" + song.title + "\n" + str(song.length)) if resource == "randid": randomid = randomdongid() return HttpResponse(int(randomid[0])) if resource == "listeners": return HttpResponse(ListenerCount()) if resource == "users": return HttpResponse(Users.objects.all().count()) if resource == "position": cue = CueFile(settings.LOGIC_DIR + "/ices.cue") d = {} now_playing = PlaylistEntry.objects.nowPlaying().song d['position'] = cue.getTime(now_playing) d['progress'] = cue.getProgress() d['length'] = now_playing.length return HttpResponse(json.dumps(d)) raise Http404 @login_required() def favourite(request, songid=0): try: song = Song.objects.get(id=songid) except Song.DoesNotExist: raise Http404
def ajax(request): events = [] length_changed = False #True if any actions would have changed the playlist length #new removals last_removal = int(request.GET.get('last_removal', -1)) if last_removal != -1: removals = RemovedEntry.objects.filter(id__gt=last_removal) removal_events = [] if removal_events: length_changed = True for removal in removals: removal_events.append(('removal', {"entryid": removal.oldid, "id": removal.id})) if len(removal_events) > MAX_EVENTS: removal_events = removal_events[:MAX_EVENTS] events.extend(removal_events) #get now playing track try: client_playing = int(request.GET.get('now_playing', 0)) except ValueError: client_playing = 0 #always output as if this isn't given it's definitely needed server_playing = PlaylistEntry.objects.nowPlaying() #check for submitted comment if request.user.has_perm("playlist.can_comment"): try: comment = request.GET['comment'] except KeyError: pass else: server_playing.song.comment(request.user, comment) #TODO: handle comment being too long gracefully #check for submitted vote if request.user.has_perm("playlist.can_rate"): try: vote = request.GET['vote'] except KeyError: pass else: server_playing.song.rate(vote, request.user) if server_playing.id != client_playing: events.append(('now_playing', server_playing.id)) length_changed = True #new title needed try: events.append(('metadata', PlaylistEntry.objects.nowPlaying().song.metadataString())) linkedMetadata = render_to_string('linked_metadata.html', request=request) events.append(('linkedMetadata', linkedMetadata)) except PlaylistEntry.DoesNotExist: pass #new song length needed events.append(('songLength', PlaylistEntry.objects.nowPlaying().song.length)) #new comments needed events.append(('clearComments', '')) comments = server_playing.song.comments.all().order_by("time") #ensure oldest first - new comments are placed at top of update list for comment in comments: events.append(comment.ajaxEvent()) else: try: last_comment = int(request.GET['last_comment']) except (ValueError, TypeError, KeyError): pass else: comments = server_playing.song.comments.all().order_by("datetime").filter(id__gt=last_comment) for comment in comments: events.append(comment.ajaxEvent()) #send user vote & song avg vote_count try: user_vote = server_playing.song.ratings.get(user=request.user).score except Rating.DoesNotExist: user_vote = 0 if server_playing.song.voteno == 1: score_str = "%.1f (%d vote)" % (server_playing.song.avgscore, server_playing.song.voteno) elif server_playing.song.voteno > 1: score_str = "%.1f (%d votes)" % (server_playing.song.avgscore, server_playing.song.voteno, ) else: score_str = "no votes" events.append(('userVote', int(user_vote))) events.append(('score', score_str)) #new adds try: last_add = int(request.GET['last_add']) except (ValueError, TypeError, KeyError): pass else: accuracy = 1 #TODO: replace with user setting aug_playlist = Playlist(request.user).fromLastID(last_add) if len(aug_playlist) > 0: length_changed = True if len(aug_playlist) > MAX_EVENTS: aug_playlist = aug_playlist[:MAX_EVENTS] html = render_to_string('playlist_table.html', {'aug_playlist': aug_playlist, 'accuracy':accuracy}, request=request) events.append(("adds", html)) if length_changed: length = PlaylistEntry.objects.length() events.append(('pllength', render_to_string('pl_length.html', {'length':length}))) #handle cuefile stuff tolerance = 5 #tolerance in seconds between real and recieved time TODO: replace with internal setting position = request.GET.get('position', None) if position: #cue = CueFile(settings.LOGIC_DIR + "/work/ices.cue") cue = CueFile("/remaining/ices2.cue") now_playing = PlaylistEntry.objects.nowPlaying().song if abs(int(position) - cue.getTime(now_playing)) >= tolerance: events.append(('songPosition', cue.getTime(now_playing))) return HttpResponse(json.dumps(events))
if resource == "plinfo": pldongid = request.GET.get('plid', 0) playlistinfo = plinfoq(pldongid) return HttpResponse(str(playlistinfo[0]) + "\n" + playlistinfo[2] + "\n" + playlistinfo[3] + "\n" + playlistinfo[1]) #return HttpResponse(playlistinfo) if resource == "listeners": return HttpResponse(gbsfmListenerCount()) if resource == "users": return HttpResponse(Users.objects.all().count()) if resource == "position": #cue = CueFile(settings.LOGIC_DIR + "/work/ices.cue") cue = CueFile("/remaining/ices2.cue") d = {} now_playing = PlaylistEntry.objects.nowPlaying().song d['position'] = cue.getTime(now_playing) d['progress'] = cue.getProgress() d['length'] = now_playing.length return HttpResponse(json.dumps(d)) raise Http404 @login_required() def favourite(request, songid=0): try: song = Song.objects.get(id=songid) except Song.DoesNotExist: raise Http404