def process_video(video_dict, user_config):
    """
    处理直播视频,包含bot的发送,视频下载,视频上传和存入数据库
    :param video_dict: 含有直播视频数据的dict
    :param user_config: 用户配置
    :return: None
    """
    assert 'bot_notice' in user_config
    assert 'download' in user_config
    bot(
        f"[直播提示] {video_dict['Provide']}{video_dict.get('Title')} 正在直播 链接: {video_dict['Target']} [CQ:at,qq=all]",
        user_config)
    ddir = get_ddir(user_config)
    check_ddir_is_exist(ddir)
    logger = logging.getLogger('run.precess_video')
    logger.info(f'{video_dict["Provide"]} Found A Live, starting downloader')
    video_dict['Title'] = AdjustFileName(video_dict['Title']).adjust(ddir)
    if video_dict["Provide"] == 'Youtube':
        downloader(r"https://www.youtube.com/watch?v=" + video_dict['Ref'],
                   video_dict['Title'], config['proxy'], ddir, user_config,
                   config['youtube']['quality'])
    else:
        downloader(video_dict['Ref'], video_dict['Title'], config['proxy'],
                   ddir, user_config)
    if config['enable_upload']:
        v = VideoUpload(video_dict, user_config)
        v.start()
def downloader(link, title, dl_proxy, ddir, user_config, quality='best'):
    try:
        is_download = user_config['download']
    except KeyError:
        is_download = True
    if is_download:
        logger = logging.getLogger('run.downloader')
        # co = ["streamlink", "--hls-live-restart", "--loglevel", "trace", "--force"]
        co = ["streamlink", "--hls-live-restart", "--force"]
        if config['enable_proxy']:
            co.append('--http-proxy')
            co.append(f'http://{dl_proxy}')
            co.append('--https-proxy')
            co.append(f'https://{dl_proxy}')
        co.append("-o")
        co.append(f"{ddir}/{title}")
        co.append(link)
        co.append(quality)
        subprocess.run(co)
        paths = f'{ddir}/{title}'
        if isfile(paths):
            logger.info(f'{title} has been downloaded.')
            bot(f"[下载提示] {title} 已下载完成,等待上传", user_config)
        else:
            logger.error(f'{title} Download error, link: {link}')
            raise RuntimeError(f'{title} Download error, link: {link}')
예제 #3
0
def upload_video(video_dict):
    share_url = bd_upload(video_dict['Title'])
    if share_url:
        if enable_db:
            db = Database('Video')
            db.insert(video_dict['Title'], share_url, video_dict['Date'])
        bot(f"[下载提示] {video_dict['Title']} 已上传, 请查看页面")
    else:
        raise RuntimeError(f'Upload {video_dict["Title"]} failed')
예제 #4
0
 def check(self, mid):
     self.old_video_num = self.API.get_video_num(mid)
     while True:
         video_num = self.API.get_video_num(mid)
         if video_num > self.old_video_num:
             self.logger.info('Found A new video')
             sleep(10)  # 需要增加延迟,反正B站API未即时更新,导致返回上一个视频
             video_info = self.API.get_video(mid)
             bot(f'[烤肉提示] [Bilibili]{video_info.get("Title")} 链接: {video_info.get("Ref")}')
             self.old_video_num = video_num
         else:
             self.logger.info(f'{mid}:{video_num} Not found new videos')
         sleep(sec)
예제 #5
0
def process_video(video_dict):
    """
    处理直播视频,包含bot的发送,视频下载,视频上传和存入数据库
    :param video_dict: 含有直播视频数据的dict
    :return: None
    """
    bot(f"[直播提示] {video_dict['Provide']}{video_dict.get('Title')} 正在直播 链接: {video_dict['Target']}"
        )

    logger = get_logger('Process Video')
    logger.info(f'{video_dict["Provide"]} Found A Live, starting downloader')
    video_dict['Title'] = AdjustFileName(video_dict['Title']).adjust()
    if video_dict["Provide"] == 'Youtube':
        downloader(r"https://www.youtube.com/watch?v=" + video_dict['Ref'],
                   video_dict['Title'], proxy, '720p')
    else:
        downloader(video_dict['Ref'], video_dict['Title'], proxy)
    upload_queue.put_nowait(video_dict)
예제 #6
0
def upload_video(video_dict):
    upload_way_dict = {'bd': BDUpload, 's3': S3Upload}
    upload_way = upload_way_dict.get(upload_by)
    uploader = upload_way()
    uploader.upload_item(f"{ddir}/{video_dict['Title']}", video_dict['Title'])
    if upload_by == 'bd':
        share_url = uploader.share_item(video_dict['Title'])
        if enable_db:
            db = Database('Video')
            db.insert(video_dict['Title'], share_url, video_dict['Date'])
    elif upload_by == 's3':
        if enable_db:
            db = Database('Video')
            db.insert(video_dict['Title'],
                      f"gets3/{quote(video_dict['Title'])}",
                      video_dict['Date'])
    else:
        raise RuntimeError(f'Upload {video_dict["Title"]} failed')
    bot(f"[下载提示] {video_dict['Title']} 已上传, 请查看页面")
예제 #7
0
def upload_video(video_dict, user_config):
    upload_way_dict = {'bd': BDUpload, 's3': S3Upload}
    upload_way = upload_way_dict.get(config['upload_by'])
    uploader = upload_way()
    ddir = get_ddir(user_config)
    uploader.upload_item(f"{ddir}/{video_dict['Title']}", video_dict['Title'])
    if config['upload_by'] == 'bd':
        share_url = uploader.share_item(video_dict['Title'])
        if config['enable_mongodb']:
            db = Database(user_map(video_dict['User']))
            db.insert(video_dict['Title'], share_url, video_dict['Date'])
    elif config['upload_by'] == 's3':
        if config['enable_mongodb']:
            db = Database(user_map(video_dict['User']))
            db.insert(video_dict['Title'],
                      f"gets3/{quote(video_dict['Title'])}",
                      video_dict['Date'])
    else:
        raise RuntimeError(f'Upload {video_dict["Title"]} failed')
    bot(f"[下载提示] {video_dict['Title']} 已上传, 请查看https://matsuri.design/",
        user_config)
예제 #8
0
def downloader(link, title, dl_proxy, quality='best'):
    logger = get_logger('Downloader')
    # co = ["streamlink", "--hls-live-restart", "--loglevel", "trace", "--force"]
    co = ["streamlink", "--hls-live-restart", "--force"]
    if enable_proxy:
        co.append('--http-proxy')
        co.append(f'http://{dl_proxy}')
        co.append('--https-proxy')
        co.append(f'https://{dl_proxy}')
    co.append("-o")
    co.append(f"{ddir}/{title}")
    co.append(link)
    co.append(quality)
    subprocess.run(co)
    paths = f'{ddir}/{title}'
    if isfile(paths):
        logger.info(f'{title} has been downloaded.')
        bot(f"[下载提示] {title} 已下载完成,等待上传")
    else:
        logger.error(f'{title} Download error, link: {link}')
        raise RuntimeError(f'{title} Download error, link: {link}')