Esempio n. 1
0
 def prev(self):
     if rds.get("playing_media") == "music":
         print "prev"
         index = self.get_music_playing_order(rds.get("playing_songid"))
         if index != -1:
             if index == 0:
                 playlist_len = len(self.playing_playlist)
                 prev_index = playlist_len - 1
             else:
                 prev_index = index - 1
             song_id = self.playing_playlist[prev_index]['song_id']
             rds.set("playing_songid", song_id)
             if not self.playmusic(song_id):
                 self.prev()
     elif rds.get("playing_media") == 'movie':
         print "prev movie"
         try:
             movielist = json.loads(rds.get("playing_movie_list"))
             order = movielist.index(rds.get("playing_moviename"))
             if order == 0:
                 prev_idx = len(movielist) - 1
             else:
                 prev_idx = order - 1
             if not self.playmovie(movielist[prev_idx]):
                 self.prev()
         except Exception, e:
             print Exception, e
Esempio n. 2
0
 def next(self):
     if rds.get("playing_media") == "music":
         print "next"
         index = self.get_music_playing_order(rds.get("playing_songid"))
         if index != -1:
             if index == len(self.playing_playlist) - 1:
                 next_index = 0
             else:
                 next_index = index + 1
             song_id = self.playing_playlist[next_index]['song_id']
             rds.set("playing_songid", song_id)
             if not self.playmusic(song_id):
                 self.next()
             self.callback.getStatus()
     elif rds.get("playing_media") == 'movie':
         print "next movie"
         try:
             movielist = json.loads(rds.get("playing_movie_list"))
             order = movielist.index(rds.get("playing_moviename"))
             if order == len(movielist) - 1:
                 prev_idx = 0
             else:
                 prev_idx = order + 1
             if not self.playmovie(movielist[prev_idx]):
                 self.next()
         except Exception, e:
             print Exception, e
Esempio n. 3
0
 def togglePause(self):
     if rds.get("playing_media") == "music":
         print "pause"
         try:
             self.popen_handler.stdin.write(b'P\n')
             self.popen_handler.stdin.flush()
             if rds.get("playing_status") == "playing":
                 rds.set("playing_status", "paused")
             elif rds.get("playing_status") == "paused":
                 rds.set("playing_status", "playing")
         except Exception, e:
             print Exception, ":", e
             print "pause music error"
             self.playmusic(rds.get("playing_songid"))
Esempio n. 4
0
 def changePlayinglist(self, media):
     if media == 'music':
         rds.delete("playing_playlist")
         print "deleted"
         rds.set('playing_media', "music")
         displaylist_dumps = rds.get("displaying_playlist")
         print "dump success"
         rds.set("playing_playlist", displaylist_dumps)
         print "restore success"
         self.playing_playlist = json.loads(rds.get("playing_playlist"),
                                            encoding='utf-8',
                                            cls=None,
                                            object_hook=None,
                                            parse_float=None,
                                            parse_int=None,
                                            parse_constant=None,
                                            object_pairs_hook=None)
Esempio n. 5
0
 def __init__(self):
     try:
         self.popens = []
         print "enter pc"
         rds.set("playing_status", "paused")
         self.playing_playlist = json.loads(rds.get("playing_playlist"),
                                            encoding='utf-8')
     except:
         print "error playcontrol init"
Esempio n. 6
0
 def get(self):
     get_playing = self.get_argument('playing')
     print "get_playing", get_playing
     img_url, musics = ne.playlist_detail(
         rds.get("playing_playlist_id" if get_playing ==
                 'true' else "displaying_playlist_id"))
     pc.setDisplayingPlaylist(img_url, musics)
     dicts = {"img_url": img_url, "musics": musics}
     response = json.dumps(dicts)
     mc.playlist_image_url = img_url
     mc.playlist_songs = musics
     self.write(response)
Esempio n. 7
0
 def mainHandle(self, day):
     city = rds.get("current_city")
     city_name = city[0:len(city) - 3]
     print "len city", len(city)
     print "city", city
     print "city_name", city_name
     code_uri = "http://php.weather.sina.com.cn/xml.php?" + urllib.urlencode(
         {'city': city_name.encode('gb2312')
          }) + "&password=DJOYnieT8234jlsK&day=" + day
     uri = code_uri
     print uri
     url = urllib2.urlopen(uri).read().decode('utf-8')
     return url
Esempio n. 8
0
 def get(self):
     try:
         playlist_id = self.get_argument("playlist_id", default="")
         playing = self.get_argument("playing", default="true")
         if playlist_id == "":
             print "Playlist_id is None"
             class_name = rds.get("displaying_playlist_class")
             print class_name
             playlist = json.dumps(music.ne.top_playlists(class_name))
             self.write(playlist)
         else:
             rds.set("displaying_playlist_id", playlist_id)
             self.write("ok")
     except Exception, e:
         print Exception, ":", e
Esempio n. 9
0
 def stop(self):
     #if rds.get("playing_media") == 'music':
     try:
         print len(self.popens)
         for op in self.popens:
             op.kill()
             print "terminated"
         self.popens = []
         if self.popen_handler:
             if rds.get("playing_media") == 'music':
                 self.popen_handler.stdin.write(b'Q\n')
             else:
                 self.popen_handler.stdin.write(b'q')
             self.popen_handler.stdin.flush()
             self.popen_handler.kill()
             os.system('sudo killall omxplayer.bin')
             print "stoped"
         time.sleep(0.01)
     except Exception, e:
         print Exception, ":", e
         return
Esempio n. 10
0
 def on_message(self, message):
     try:
         js = json.loads(message,
                         encoding='utf-8',
                         cls=None,
                         object_hook=None,
                         parse_float=None,
                         parse_int=None,
                         parse_constant=None,
                         object_pairs_hook=None)
         print "load success"
         cmd = js['cmd']
         if cmd == 'pause':
             pc.togglePause()
         elif cmd == 'prev':
             pc.prev()
         elif cmd == 'next':
             pc.next()
         elif cmd == 'play':
             media = js['data']['media']
             pc.changeToMedia(media)
             if media == 'music':
                 pc.changePlayinglist(media)
                 print "changed pl!"
                 if not pc.playmusic(js['data']['songid']):
                     pc.next()
                 print "playmusic success"
                 rds.set("playing_playlist_id",
                         rds.get("displaying_playlist_id"))
             elif media == 'movie':
                 movie_name = js['data']['filename']
                 if not pc.playmovie(movie_name):
                     pc.next()
         elif cmd == 'playlist_id':
             rds.set("displaying_playlist_id", js['data']['playlist_id'])
         self.getStatus()
     except Exception, e:
         print "on_message error, message is:"
         print message
         print Exception, e
Esempio n. 11
0
 def top_playlists(self, category='全部', order='hot', offset=0, limit=100):
     action = 'http://music.163.com/api/playlist/list?cat={}&order={}&offset={}&total={}&limit={}'.format(  # NOQA
         category, order, offset, 'true',limit
         )  # NOQA
     if category == "我的":
         data = self.user_playlist(rds.get("music_userid"))
     else:
         data = self.httpRequest('GET', action)
         data = data['playlists']
     try:
         temp = []
         for i in range(0, len(data)):
                 playlists_info = {
                     'playlist_id': data[i]['id'],
                     'playlists_name': data[i]['name'],
                     'creator_name': data[i]['creator']['nickname'],
                     'coverImgUrl':data[i]['coverImgUrl']
                 }
                 temp.append(playlists_info)
         return temp
     except Exception , e:
         print Exception , e
         return []
Esempio n. 12
0
 def status(self):
     try:
         dicts = {}
         playing_stat = rds.get("playing_status")
         if playing_stat is None:
             rds.set("playing_status", "stopped")
             playing_stat = rds.get("playing_status")
         dicts["playing_status"] = playing_stat
         playing_media = rds.get("playing_media")
         print "status  playing_media:", playing_media
         if playing_media is None:
             rds.set("playing_media", "none")
             playing_media = rds.get("playing_media")
         dicts["playing_media"] = playing_media
         if playing_media == "music":
             dicts["playing_songid"] = int(rds.get("playing_songid"))
         elif playing_media == "movie":
             dicts["playing_moviename"] = rds.get("playing_moviename")
     except Exception, e:
         print Exception, ":", e
Esempio n. 13
0
 def changeToMedia(self, media):
     playing_media = rds.get("playing_media")
     if media != playing_media:
         playing_status = rds.get("playing_status")
         if playing_status == 'playing':
             self.stop()
Esempio n. 14
0
    def togglePause(self):
        if rds.get("playing_media") == "music":
            print "pause"
            try:
                self.popen_handler.stdin.write(b'P\n')
                self.popen_handler.stdin.flush()
                if rds.get("playing_status") == "playing":
                    rds.set("playing_status", "paused")
                elif rds.get("playing_status") == "paused":
                    rds.set("playing_status", "playing")
            except Exception, e:
                print Exception, ":", e
                print "pause music error"
                self.playmusic(rds.get("playing_songid"))
        elif rds.get("playing_media") == "movie":
            print "pause movie"
            try:
                self.popen_handler.stdin.write(b'p')
                self.popen_handler.stdin.flush()
                if rds.get("playing_status") == "playing":
                    rds.set("playing_status", "paused")
                elif rds.get("playing_status") == "paused":
                    rds.set("playing_status", "playing")
            except Exception, e:
                print Exception, e
                self.playmovie(rds.get("playing_moviename"))

    def setDisplayingPlaylist(self, playlist_image_url, playlist):
        try:
            rds.set("displaying_list_image_url", playlist_image_url)
Esempio n. 15
0
 def __init__(self):
     self.userid = rds.get('music_userid')
     self.nickname = rds.get('music_nickname')