radio.py 文件源码

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

项目:radio-chan 作者: HanakiKaorin 项目源码 文件源码
def yt_queue(s, m):
    global prev, song, voice, player, yt

    ydl_opts = {
        'format': 'bestaudio/best',
        'noplaylist': True,
        'nocheckcertificate': True,
        'quiet': True,
        'outtmpl': ytDir + '%(id)s',
        'default_search': 'auto'
    }

    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        meta = ydl.extract_info(s, download=False)
    yt[meta['id']] = {
        'id': meta['id'],
        'title': meta['title'],
        'artist': meta['uploader'],
        'album': 'YouTube',
        'composer': None, # meta['view_count'] / meta['like_count'] / meta['dislike_count']
        'length': meta['duration'],
        'file': meta['id']
    }

    if (meta['id'] in prev):
        mainMessage = '[' + m.author.display_name + ']?The song [YT] _' + meta['title'] + '_ has already been played recently'
    elif (meta['id'] in queue):
        mainMessage = '[' + m.author.display_name + ']?The song [YT] _' + meta['title'] + '_ is already in the queue'
    elif (meta['duration'] > 900):
        mainMessage = '[' + m.author.display_name + ']?The song [YT] _' + meta['title'] + '_ is too long (max 15 minutes)'
    else:
        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            ydl.download([s])
        queue.append(meta['id'])
        dprint(Fore.MAGENTA + m.author.display_name + ' queued:' + Style.NORMAL + ' [YT] ' + meta['uploader'] + ' - ' +  meta['title'])
        mainMessage = '[' + m.author.display_name + ']?Queued [YT] _' + meta['title'] + '_'

    await client.send_message(m.channel, mainMessage)
    if (m.server): await client.delete_message(m)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号