本文整理汇总了Python中channel.Channel.pre_channel方法的典型用法代码示例。如果您正苦于以下问题:Python Channel.pre_channel方法的具体用法?Python Channel.pre_channel怎么用?Python Channel.pre_channel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类channel.Channel
的用法示例。
在下文中一共展示了Channel.pre_channel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Client
# 需要导入模块: from channel import Channel [as 别名]
# 或者: from channel.Channel import pre_channel [as 别名]
class Client(object):
"""The client class that responds for the user input and menu print, as well as the main logics"""
def __init__(self):
self.url = 'http://douban.fm/j/mine/playlist?type=n&channel=%d&from=mainsite'
self.current_song = None
self.player = Player()
self.channel = Channel()
self.current_channel = self.channel.current_channel
self.view = View(self.channel)
self.update_current_song()
self.is_playing = False
self.seconds = 0
self.length = self.current_song.length
def update_current_song(self):
page_source = None
url = self.url % self.current_channel
try:
page_source = urllib.urlopen(url)
except urllib2.HTTPError:
print "Get current song information failed"
page_data = page_source.read()
json_data =json.loads(page_data)
new_json_data = json.dumps(json_data['song'], ensure_ascii=False)
song_data = json.loads(new_json_data)
self.current_song = Song(song_data[0])
self.player.update_current_song(self.current_song)
def print_helper(self):
self.view.print_helper()
def play(self):
self.is_playing = True
self.player.play_current_song()
def stop(self):
self.is_playing = False
self.seconds = 0
self.player.stop_playing_current_song()
def next(self):
self.view.print_loading_information()
self.player.stop_playing_current_song()
self.update_current_song()
self.play()
def pre_channel(self):
self.channel.pre_channel()
self.change_channel()
def next_channel(self):
self.channel.next_channel()
self.change_channel()
def change_channel(self):
new_channel = self.channel.current_channel
if new_channel != self.current_channel:
self.current_channel = new_channel
self.next()
def exit(self):
self.player.stop_playing_current_song()
self.view.print_exit_informaton()
sys.exit()
def display(self):
while True:
if self.is_playing == True:
self.seconds = self.seconds + 1
self.view.print_song_information(self.seconds, self.current_song.get_basic_information())
else:
self.view.print_pause_information()
break
time.sleep(1.0)
def start(self):
self.play()
while True:
self.display()
i = getch._Getch()
choice = i()
if choice == 'p' and self.is_playing == False:
self.play()
elif choice == 's' and self.is_playing == True:
self.stop()
elif choice == 'n':
self.next()
elif choice == 'i':
self.pre_channel()
elif choice == 'k':
self.next_channel()
elif choice == 'h':
self.print_helper()
elif choice == 'q':
self.exit()