コード例 #1
0
    def play(self):
        """播放"""
        if len(self.current_playlist) == 0:
            # 初始化和之前各种行为_get_playlist 都没获取到歌曲才会进到这里
            if self.timeout > 0:
                self.next_song()
                self.timeout -= 1
            else:
                print 'timeout on loading playlist, exit'
                sys.exit(1)
            return 
        self.player.set_state(gst.STATE_PLAYING)
        current_song = self.current_song
        i_title = current_song.get('title')
        i_artist = current_song.get('artist')
        i_album = current_song.get('album')
        i_albumtitle = current_song.get('albumtitle')
        i_islike = int(current_song.get('like')) == 1
        i_url = 'http://{0}/?start={1}g{2}g{3}&cid={3}'.format(self.douban_fm_host,
                    current_song.get('sid'), 
                    current_song.get('ssid'), 
                    self.current_channel)
        i_cover_path = "/%s/cover.%s.jpg" % (self.tmp_dir,current_song.get('sid'))
        urllib.urlretrieve(current_song.get('picture'),i_cover_path)

        playing_info = '▶  %s - %s %s [%s](%s)' % (i_artist, i_title, '❤ '  if i_islike else '',i_albumtitle, i_url)
        terminal_title = "\x1b]2;▶  %s - %s\x07" % (i_artist,i_title)
        sns_info = '♪ 豆瓣FM#%s# %s - %s %s' % (self.douban_fm_channel_name.get(self.current_channel, 'DJ兆赫') ,
                i_artist, i_title, i_url)
        print playing_info
        print terminal_title
        notify(i_artist, i_title, i_cover_path)
        set_skype_status(sns_info)
コード例 #2
0


if __name__ == '__main__':
    argv = sys.argv
    url = None
    if len(argv) >= 2:
        url = argv[1]
    fm = DoubanFM(debug=False, url=url)
    hint = 'Command: Q[uit]\tn[ext]\tb[an]\tr[ed]\t[u]nred\tp[ause]\tP[lay]\th[elp]'
    print '😻  豆瓣FM'
    fm.play()
    while True:
        c = getch()
        if c == 'Q':
            set_skype_status('')
            break
        elif c == 'n':
            fm.pass_song()
        elif c == 'b':
            fm.ban_song()
        elif c == 'r':
            fm.red_song()
        elif c == 'u':
            fm.unred_song()
        elif c == 'p':
            fm.pause()
        elif c == 'P':
            fm.play()
        elif c == 'h':
            print hint