main.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:pyradio-nepal 作者: sandipbgt 项目源码 文件源码
def run():
    """
    starts the player
    """
    radio = utils.get_player()
    if not radio:
        logging.error("Player not available, exiting now!")
        sys.exit(0)

    stations = utils.get_stations()
    play = True
    current = None
    while play:
        user_input = input("Enter station number ({}) or type station name to search> ".format(current)).strip()

        if user_input == "exit":
            radio.close()
            play = False
            sys.exit(0)
        elif user_input == 'list':
            utils.pretty_print_stations(stations)
            continue
        try:
            num = int(user_input)
            if num > 0:
                try:
                    station = stations[num - 1]
                    radio.play(station['stream_url'])
                    print("Playing: {} @ {} MHz, {}".format(station['name'], station['frequency'], station['location']))
                    current = "{}. {}".format(station['count'], station['name'])
                except IndexError:
                    print("Invalid station number")
        except ValueError:
            utils.pretty_print_stations(stations, user_input)
            user_input = 0
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号