コード例 #1
0
ファイル: views.py プロジェクト: kmill/squidmusic
class JSRPC_Playlist(RPCServable) :
    def init_ssc(self, playerid) :
        self.speaker = SquidSpeaker.objects.filter(id=playerid)[0]
        self.ssc = SquidSpeakerClient(self.speaker.speaker_server,
                                      self.speaker.speaker_port,
                                      self.speaker.speaker_password)
    @rpcmethod
    def prev(self, playerid) :
        self.init_ssc(playerid)
        self.ssc.prev()
    @rpcmethod
    def pause(self, playerid) :
        self.init_ssc(playerid)
        self.ssc.pause()
    @rpcmethod
    def play(self, playerid) :
        self.init_ssc(playerid)
        self.ssc.play()
    @rpcmethod
    def stop(self, playerid) :
        self.init_ssc(playerid)
        self.ssc.stop()
    @rpcmethod
    def next(self, playerid) :
        self.init_ssc(playerid)
        self.ssc.next()
コード例 #2
0
ファイル: views.py プロジェクト: kmill/squidmusic
def playlist(request, playerid = None) :
    if playerid == None :
        playerid = request.session.get("playerid", None)
        if playerid == None :
            return players(request, "<p>You haven't set a default player.  Please set one first.</p>")
    command = request.GET.get("command", None)
    speaker = SquidSpeaker.objects.filter(id=playerid)[0]
    ssc = SquidSpeakerClient(speaker.speaker_server, speaker.speaker_port, speaker.speaker_password)

    if command == "prev" :
        ssc.prev()
    elif command == "pause" :
        ssc.pause()
    elif command == "play" :
        ssc.play()
    elif command == "stop" :
        ssc.stop()
    elif command == "next" :
        ssc.next()
    elif command == "queue" :
        try :
            puid = int(request.GET.get("puid", None))
            number = int(request.GET.get("number", None))
            ssc.queue(puid, number)
        except :
            pass
    elif command == "set" :
        try :
            puid = int(request.GET.get("puid", None))
            ssc.set(puid)
        except :
            pass
    elif command == "loop" :
        state = request.GET.get("value", False) == "True"
        ssc.loop(state)
    elif command == "shuffle" :
        state = request.GET.get("value", False) == "True"
        ssc.shuffle(state)
    elif command == "clear" :
        ssc.clear()
    elif command == "clean" :
        ssc.clean()
    elif command == "add" :
        songid = request.GET["id"]
        song = Song.objects.filter(id=songid)[0]
#        t = Template("{% url squidmusicweb.views.song songid=song.id %}")
#        url = t.render(Context({"song" : song}))
        # use django.core.urlresolvers.reverse?
        #url = "http://kmill.mit.edu:8000/song/" + str(song.id)
        url = URL_ROOT_PATH+reverse('squidmusicweb.views.song', kwargs={"songid": song.id})
        s = song.toDict()
        s["filename"] = url+"?download"
        s["infolink"] = url
        ssc.add([s])
    elif command == "addalbum" :
        albumid = request.GET["id"]
        songs = Song.objects.filter(song_album__id=albumid).order_by('song_album__album_name',
                                                                     'song_discnum',
                                                                     'song_tracknum')
#        t = Template("{% url squidmusicweb.views.song songid=song.id %}")
        ss = []
        for song in songs :
 #           url = t.render(Context({"song" : song}))
            url = URL_ROOT_PATH+reverse('squidmusicweb.views.song', kwargs={"songid": song.id})
            s = song.toDict()
            s["filename"] = url+"?download"
            s["infolink"] = url
            ss.append(s)
        ssc.add(ss)
    elif command == "addgroup" :
        albumid = request.GET["albumid"]
        grouping = request.GET["group"]
        songs = Song.objects.filter(song_album__id=albumid, song_grouping=grouping).order_by('song_album__album_name',
                                                                                             'song_discnum',
                                                                                             'song_tracknum')
#        t = Template("{% url squidmusicweb.views.song songid=song.id %}")
        ss = []
        for song in songs :
 #           url = t.render(Context({"song" : song}))
            url = URL_ROOT_PATH+reverse('squidmusicweb.views.song', kwargs={"songid": song.id})
            s = song.toDict()
            s["filename"] = url+"?download"
            s["infolink"] = url
            ss.append(s)
        ssc.add(ss)
    elif command == "movesong" :
        puid = int(request.GET["puid"])
        index = int(request.GET["index"])
        ssc.move(puid, index)
    elif command == "delete" :
        songid = int(request.GET["puid"])
        ssc.delete([songid])
    elif command == "raiseVolume" :
        ssc.raiseVolume()
    elif command == "lowerVolume" :
        ssc.lowerVolume()
    elif command == "seek" :
        seconds = float(request.GET["time"])
        ssc.setPosition(seconds);

    if request.is_ajax() and command != "playlist" and command != None :
        return HttpResponse("done.")
    else :
        playlist = ssc.playlist()
        
        if playlist["volume"] != None :
            try :
                playlist["volume"] = int(float(playlist["volume"]))
            except :
                playlist["volume"] = False
        else :
            playlist["volume"] = False
        if playlist["isPlaying"] :
            playlist["msecsonglength"] = playlist["playing"]["time"]
            try :
                playlist["msecsonglocation"] = int(float(playlist["position"])*1000)
            except :
                playlist["msecsonglocation"] = 0
        
        for song in playlist["playlist"] :
            i = 0
            song["isqueued"] = False
            for q in playlist["queued"] :
                if song["puid"] == q :
                    song["queued"] = i
                    song["isqueued"] = True
                    break
                i += 1
        if request.is_ajax() or command == "playlist" :
            playlist["speakerid"] = speaker.id
            return HttpResponse(json.dumps(playlist), "application/javascript")
        elif command == "m3u" :
#            resp = "#EXTM3U\n"
            resp = ""
            for song in playlist["playlist"] :
#                resp += "#EXTINF:"+str(int(song["time"])//1000)+","+song["artist"]+","+song["name"]+" ("+song["album"]+")\n"
                resp += song["filename"] + "\n"
            return HttpResponse(resp)
        else :
            try :
                playlist["formattedPosition"] = msec_to_string(int(float(playlist["position"])*1000))
                playlist["formattedPositionLeft"] = msec_to_string(int(playlist["playing"]["time"])-int(float(playlist["position"])*1000))
            except :
                # position wasn't formattable.  oops.
                playlist["formattedPosition"] = "Unknown"
                playlist["formattedPositionLeft"] = "Unknown"
            playlist["speaker"] = speaker
            return render_to_response("player_control.html", playlist)
コード例 #3
0
ファイル: views.py プロジェクト: kmill/squidmusic
 def init_ssc(self, playerid) :
     self.speaker = SquidSpeaker.objects.filter(id=playerid)[0]
     self.ssc = SquidSpeakerClient(self.speaker.speaker_server,
                                   self.speaker.speaker_port,
                                   self.speaker.speaker_password)