def get(self): movies = [] for parent, dirnames, filenames in os.walk(movies_path): for filename in filenames: #filename = filename.split('.')[0] print parent if not os.path.exists("./thumb_imgs/" + filename + ".jpg"): vc = cv2.VideoCapture(movies_path + filename) #读入视频文件 if vc.isOpened(): #判断是否正常打开 for i in range(100): rval, frame = vc.read() shape = frame.shape wid = int(50 * ((shape[1] * 1.0) / (shape[0] * 1.0))) print wid frame = cv2.resize(frame, (wid, 50)) print frame.shape width_st = wid / 2 - 25 print width_st frame = frame[:, width_st:width_st + 50] print frame.shape cv2.imwrite('./thumb_imgs/' + filename + '.jpg', frame) movies.append(filename) movies.sort() movies.reverse() response = json.dumps(movies) rds.set("playing_movie_list", response) self.write(response)
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"
def get(self): print "SelPlaylistHandler" playlist_class = self.get_argument("playlist_class", default="") print playlist_class if playlist_class == "": classes = music.ne.playlist_classes() self.write(json.dumps(classes)) else: rds.set("displaying_playlist_class", playlist_class) self.write("ok")
def getCity(): while True: try: ip = getip() city = get_ip_area(ip) print ip print "len", len(city) rds.set("current_ip", ip) rds.set("current_city", city) except: print "error getCity" time.sleep(600)
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
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
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
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
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)
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"))
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
def playmusic(self, songid): def newThread(): while True: strout = self.popen_handler.stdout.readline().decode('utf-8') if strout == "": break #print strout if re.match('^\@F.*$', strout): process_data = strout.split(' ') process_location = float(process_data[4]) continue elif strout == '@P 0\n': self.popen_handler.stdin.write(b'Q\n') self.popen_handler.stdin.flush() self.popen_handler.kill() self.next() break self.stop() print "start popen" try: para = ['mpg123', '-R'] self.popen_handler = subprocess.Popen(para, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) self.popen_handler.stdin.write(b'V ' + str(100).encode('utf-8') + b'\n') self.popens.append(self.popen_handler) rds.set("playing_songid", songid) song_info = self.get_music_playing_songinfo(songid) print "song_info:" print song_info if song_info: #print song_info['mp3_url'] new_url = music.ne.songs_detail_new_api([songid])[0]['url'] print new_url self.popen_handler.stdin.write(b'L ' + new_url.encode('utf-8') + b'\n') self.popen_handler.stdin.flush() rds.set("playing_songid", songid) rds.set("playing_media", "music") rds.set("playing_status", "playing") t = threading.Thread(target=newThread) t.start() return True except Exception, e: print Exception, ":", e if new_url is None: return False
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
def setDisplayingPlaylist(self, playlist_image_url, playlist): try: rds.set("displaying_list_image_url", playlist_image_url) rds.delete("displaying_playlist") print "displaying_playlist:" print json.dumps(playlist) rds.set("displaying_playlist", json.dumps(playlist)) except: print "set displaying_playlist failed"
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)
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
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 []
def playmovie(self, movie_filename): def newThread(): while True: strout = self.popen_handler.stdout.readline().decode('utf-8') print strout if strout == "": print "returned none so break" break if re.match('have a nice day*', strout): self.popen_handler.stdin.write(b'Q\n') self.popen_handler.stdin.flush() self.popen_handler.kill() self.next() break self.stop() print "start movie" print movie_filename para = [ 'omxplayer', '-o', 'local', "/home/pi/project/movies/" + movie_filename ] try: self.popen_handler = subprocess.Popen(para, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) self.popens.append(self.popen_handler) rds.set("playing_status", "playing") rds.set("playing_media", "movie") rds.set("playing_moviename", movie_filename) t = threading.Thread(target=newThread) t.start() return True except Exception, e: print Exception, e return False
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()
def __init__(self): self.userid = rds.get('music_userid') self.nickname = rds.get('music_nickname')
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)