Пример #1
0
 def __init__(self, output_dir: str, splits_dir: str, config: dict):
     super().__init__(config)
     self.output_dir = output_dir
     self.splits_dir = splits_dir
     self.uploader = BilibiliUploader()
     self.uploader.login(config['spec']['uploader']['account']['username'],
                         config['spec']['uploader']['account']['password'])
Пример #2
0
 def __init__(self, output_dir: str, splits_dir: str, config: dict):
     super().__init__(config)
     self.output_dir = output_dir
     self.splits_dir = splits_dir
     self.uploader = BilibiliUploader()
     self.uploader.login(config.get('spec', {}).get('uploader', {}).get('account', {}).get('username', ""),
                         config.get('spec', {}).get('uploader', {}).get('account', {}).get('password', ""))
Пример #3
0
 def __init__(self, output_dir: str, splits_dir: str, config: dict):
     super().__init__(config)
     self.output_dir = output_dir
     self.splits_dir = splits_dir
     self.uploader = BilibiliUploader()
     self.uploader.login(config['spec']['uploader']['account']['username'],
                         config['spec']['uploader']['account']['password'])
     logging.basicConfig(
         level=utils.get_log_level(config),
         format=
         '%(asctime)s %(thread)d %(threadName)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
         datefmt='%a, %d %b %Y %H:%M:%S',
         filename=os.path.join(
             config['root']['logger']['log_path'],
             datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') +
             '.log'),
         filemode='a')
Пример #4
0
def upload(uploader: BilibiliUploader,
           parts: list,
           cr: int,
           title: str,
           tid: int,
           tags: list,
           desc: str,
           source: str,
           thread_pool_workers: int = 1,
           max_retry: int = 3,
           upload_by_edit: bool = False) -> tuple:
    bvid = None
    if upload_by_edit:
        while bvid is None:
            avid, bvid = uploader.upload(
                parts=[parts[0]],
                copyright=cr,
                title=title,
                tid=tid,
                tag=",".join(tags),
                desc=desc,
                source=source,
                thread_pool_workers=thread_pool_workers,
                max_retry=max_retry,
            )
        for i in range(1, len(parts)):
            uploader.edit(bvid=bvid,
                          parts=[parts[i]],
                          max_retry=max_retry,
                          thread_pool_workers=thread_pool_workers)
    else:
        while bvid is None:
            avid, bvid = uploader.upload(
                parts=parts,
                copyright=cr,
                title=title,
                tid=tid,
                tag=",".join(tags),
                desc=desc,
                source=source,
                thread_pool_workers=thread_pool_workers,
                max_retry=max_retry,
            )
            print(avid, bvid)
    return avid, bvid
Пример #5
0
class Uploader(BiliLive):
    def __init__(self, output_dir: str, splits_dir: str, config: dict):
        super().__init__(config)
        self.output_dir = output_dir
        self.splits_dir = splits_dir
        self.uploader = BilibiliUploader()
        self.uploader.login(config['spec']['uploader']['account']['username'],
                            config['spec']['uploader']['account']['password'])
        logging.basicConfig(
            level=utils.get_log_level(config),
            format=
            '%(asctime)s %(thread)d %(threadName)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
            datefmt='%a, %d %b %Y %H:%M:%S',
            filename=os.path.join(
                config['root']['logger']['log_path'],
                datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') +
                '.log'),
            filemode='a')

    def upload(self, global_start: datetime.datetime) -> None:
        if self.config['spec']['uploader']['clips']['upload_clips']:
            output_parts = []
            datestr = datetime.datetime.strptime(
                global_start,
                '%Y-%m-%d_%H-%M-%S').strftime('%Y{y}%m{m}%d{d}').format(y='年',
                                                                        m='月',
                                                                        d='日')
            filelists = os.listdir(self.output_dir)
            for filename in filelists:
                if os.path.getsize(os.path.join(self.output_dir,
                                                filename)) < 1024 * 1024:
                    continue
                title = os.path.splitext(filename)[0].split("_")[-1]
                output_parts.append(
                    VideoPart(
                        path=os.path.join(self.output_dir, filename),
                        title=title,
                        desc=self.config['spec']['uploader']['clips']
                        ['desc'].format(date=datestr),
                    ))

            avid, bvid = self.uploader.upload(
                parts=output_parts,
                copyright=2,
                title=self.config['spec']['uploader']['clips']['title'].format(
                    date=datestr),
                tid=self.config['spec']['uploader']['clips']['tid'],
                tag=",".join(self.config['spec']['uploader']['clips']['tags']),
                desc=self.config['spec']['uploader']['clips']['desc'].format(
                    date=datestr),
                source="https://live.bilibili.com/" + self.room_id,
                thread_pool_workers=self.config['root']['uploader']
                ['thread_pool_workers'],
                max_retry=self.config['root']['uploader']['max_retry'],
            )
            print(avid, bvid)
        if self.config['spec']['uploader']['record']['upload_record']:
            splits_parts = []
            datestr = datetime.datetime.strptime(
                global_start,
                '%Y-%m-%d_%H-%M-%S').strftime('%Y{y}%m{m}%d{d}').format(y='年',
                                                                        m='月',
                                                                        d='日')
            filelists = os.listdir(self.splits_dir)
            for filename in filelists:
                if os.path.getsize(os.path.join(self.splits_dir,
                                                filename)) < 1024 * 1024:
                    continue
                title = filename
                splits_parts.append(
                    VideoPart(
                        path=os.path.join(self.splits_dir, filename),
                        title=title,
                        desc=self.config['spec']['uploader']['record']
                        ['desc'].format(date=datestr),
                    ))

            avid, bvid = self.uploader.upload(
                parts=splits_parts,
                copyright=2,
                title=self.config['spec']['uploader']['record']
                ['title'].format(date=datestr),
                tid=self.config['spec']['uploader']['record']['tid'],
                tag=",".join(
                    self.config['spec']['uploader']['record']['tags']),
                desc=self.config['spec']['uploader']['record']['desc'].format(
                    date=datestr),
                source="https://live.bilibili.com/" + self.room_id,
                thread_pool_workers=self.config['root']['uploader']
                ['thread_pool_workers'],
                max_retry=self.config['root']['uploader']['max_retry'],
            )
            print(avid, bvid)
Пример #6
0
room_id = int(getConfig('BilibiliLive', 'room_id'))
#读取用户名和密码,以及B站上传设置
username = getConfig('Bilibili', 'username')
password = getConfig('Bilibili', 'password')
title = getConfig('Bilibili', 'title')
tid = int(getConfig('Bilibili', 'tid'))
tag = getConfig('Bilibili', 'tag')
desc = getConfig('Bilibili', 'desc')
dynamtic = getConfig('Bilibili', 'dynamtic')
#log 读取的数据
logging.debug("Readed" + "path: " + path + ' type: ' + type + ' room_id: ' +
              str(room_id) + ' username: '******' password: '******' title: ' + title)
logging.debug("Readed" + "tid: " + str(tid) + ' tag: ' + str(tag) + ' desc: ' +
              desc + ' dynamtic: ' + dynamtic + ' From the config file')
uploader = BilibiliUploader()
try:
    uploader.login(username, password)
except:
    logging.debug("Login Failed")
else:
    logging.info("Login successful")

#暴力死循环
while (True):
    if LastUploadDate != time.strftime("%d", time.localtime()):
        print(" try uploading Stream" + LastUploadDate)
        files = os.listdir(path)
        #遍历录像目录
        for file in files:
            #寻找指定类型的录像文件
Пример #7
0
class Uploader(BiliLive):
    def __init__(self, output_dir: str, splits_dir: str, config: dict):
        super().__init__(config)
        self.output_dir = output_dir
        self.splits_dir = splits_dir
        self.uploader = BilibiliUploader()
        self.uploader.login(config['spec']['uploader']['account']['username'],
                            config['spec']['uploader']['account']['password'])

    def upload(self, global_start: datetime.datetime) -> dict:
        logging.basicConfig(
            level=utils.get_log_level(self.config),
            format=
            '%(asctime)s %(thread)d %(threadName)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
            datefmt='%a, %d %b %Y %H:%M:%S',
            filename=os.path.join(
                self.config['root']['logger']['log_path'], "Uploader_" +
                datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') +
                '.log'),
            filemode='a')
        return_dict = {}
        try:
            if self.config['spec']['uploader']['clips']['upload_clips']:
                output_parts = []
                datestr = global_start.strftime('%Y{y}%m{m}%d{d}').format(
                    y='年', m='月', d='日')
                filelists = os.listdir(self.output_dir)
                for filename in filelists:
                    if os.path.getsize(os.path.join(self.output_dir,
                                                    filename)) < 1024 * 1024:
                        continue
                    title = os.path.splitext(filename)[0].split("_")[-1]
                    output_parts.append(
                        VideoPart(
                            path=os.path.join(self.output_dir, filename),
                            title=title,
                            desc=self.config['spec']['uploader']['clips']
                            ['desc'].format(date=datestr),
                        ))

                avid, bvid = upload(
                    self.uploader,
                    output_parts,
                    title=self.config['spec']['uploader']['clips']
                    ['title'].format(date=datestr),
                    tid=self.config['spec']['uploader']['clips']['tid'],
                    tags=self.config['spec']['uploader']['clips']['tags'],
                    desc=self.config['spec']['uploader']['clips']
                    ['desc'].format(date=datestr),
                    source="https://live.bilibili.com/" + self.room_id,
                    thread_pool_workers=self.config['root']['uploader']
                    ['thread_pool_workers'],
                    max_retry=self.config['root']['uploader']['max_retry'],
                    upload_by_edit=self.config['root']['uploader']
                    ['upload_by_edit'])
                return_dict["clips"] = {"avid": avid, "bvid": bvid}
            if self.config['spec']['uploader']['record']['upload_record']:
                splits_parts = []
                datestr = global_start.strftime('%Y{y}%m{m}%d{d}').format(
                    y='年', m='月', d='日')
                filelists = os.listdir(self.splits_dir)
                for filename in filelists:
                    if os.path.getsize(os.path.join(self.splits_dir,
                                                    filename)) < 1024 * 1024:
                        continue
                    title = filename
                    splits_parts.append(
                        VideoPart(
                            path=os.path.join(self.splits_dir, filename),
                            title=title,
                            desc=self.config['spec']['uploader']['record']
                            ['desc'].format(date=datestr),
                        ))

                avid, bvid = upload(
                    self.uploader,
                    splits_parts,
                    title=self.config['spec']['uploader']['record']
                    ['title'].format(date=datestr),
                    tid=self.config['spec']['uploader']['record']['tid'],
                    tags=self.config['spec']['uploader']['record']['tags'],
                    desc=self.config['spec']['uploader']['record']
                    ['desc'].format(date=datestr),
                    source="https://live.bilibili.com/" + self.room_id,
                    thread_pool_workers=self.config['root']['uploader']
                    ['thread_pool_workers'],
                    max_retry=self.config['root']['uploader']['max_retry'],
                    upload_by_edit=self.config['root']['uploader']
                    ['upload_by_edit'])
                return_dict["record"] = {"avid": avid, "bvid": bvid}
        except Exception as e:
            logging.error(
                self.generate_log('Error while uploading:' + str(e) +
                                  traceback.format_exc()))
        return return_dict
Пример #8
0
class Uploader(BiliLive):
    def __init__(self, output_dir: str, splits_dir: str, config: dict):
        super().__init__(config)
        self.output_dir = output_dir
        self.splits_dir = splits_dir
        self.uploader = BilibiliUploader()
        self.uploader.login(
            config.get('spec', {}).get('uploader',
                                       {}).get('account',
                                               {}).get('username', ""),
            config.get('spec', {}).get('uploader',
                                       {}).get('account',
                                               {}).get('password', ""))

    def upload(self, global_start: datetime.datetime) -> dict:
        logging.basicConfig(
            level=utils.get_log_level(self.config),
            format=
            '%(asctime)s %(thread)d %(threadName)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
            datefmt='%a, %d %b %Y %H:%M:%S',
            filename=os.path.join(
                self.config.get('root', {}).get('logger',
                                                {}).get('log_path',
                                                        "./log"), "Uploader_" +
                datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') +
                '.log'),
            filemode='a')
        return_dict = {}
        datestr = global_start.strftime('%Y{y}%m{m}%d{d}').format(y='年',
                                                                  m='月',
                                                                  d='日')
        year = global_start.strftime('%Y')
        month = global_start.strftime('%m')
        day = global_start.strftime('%d')
        rough_time = {
            0: '凌晨',
            1: '上午',
            2: '下午',
            3: '晚上'
        }[int(global_start.hour / 6)]
        room_name = self.get_room_info()['roomname']
        area_name = self.get_room_info()['area_name']
        parent_area_name = self.get_room_info()['parent_area_name']
        try:
            if self.config.get('spec',
                               {}).get('uploader',
                                       {}).get('clips',
                                               {}).get('upload_clips', False):
                output_parts = []
                filelists = os.listdir(self.output_dir)
                for filename in filelists:
                    if os.path.getsize(os.path.join(self.output_dir,
                                                    filename)) < 1024 * 1024:
                        continue
                    title = os.path.splitext(filename)[0].split("_")[-1]
                    output_parts.append(
                        VideoPart(
                            path=os.path.join(self.output_dir, filename),
                            title=title,
                            desc=self.config.get('spec', {}).get(
                                'uploader',
                                {}).get('clips', {}).get('desc', "").format(
                                    date=datestr,
                                    year=year,
                                    month=month,
                                    day=day,
                                    rough_time=rough_time,
                                    room_name=room_name,
                                    area_name=area_name,
                                    parent_area_name=parent_area_name),
                        ))

                avid, bvid = upload(
                    self.uploader,
                    output_parts,
                    cr=self.config.get('spec', {}).get('uploader',
                                                       {}).get('copyright', 2),
                    title=self.config.get('spec', {}).get('uploader', {}).get(
                        'clips',
                        {}).get('title',
                                "").format(date=datestr,
                                           year=year,
                                           month=month,
                                           day=day,
                                           rough_time=rough_time,
                                           room_name=room_name,
                                           area_name=area_name,
                                           parent_area_name=parent_area_name),
                    tid=self.config.get('spec',
                                        {}).get('uploader',
                                                {}).get('clips',
                                                        {}).get('tid', 27),
                    tags=self.config.get('spec', {}).get('uploader', {}).get(
                        'clips',
                        {}).get('tags',
                                []).format(area_name=area_name,
                                           parent_area_name=parent_area_name),
                    desc=self.config.get('spec', {}).get('uploader', {}).get(
                        'clips',
                        {}).get('desc',
                                "").format(date=datestr,
                                           year=year,
                                           month=month,
                                           day=day,
                                           rough_time=rough_time,
                                           room_name=room_name,
                                           area_name=area_name,
                                           parent_area_name=parent_area_name),
                    source="https://live.bilibili.com/" + self.room_id,
                    thread_pool_workers=self.config.get('root', {}).get(
                        'uploader', {}).get('thread_pool_workers', 1),
                    max_retry=self.config.get('root',
                                              {}).get('uploader',
                                                      {}).get('max_retry', 10),
                    upload_by_edit=self.config.get('root', {}).get(
                        'uploader', {}).get('upload_by_edit', False))
                return_dict["clips"] = {"avid": avid, "bvid": bvid}
            if self.config.get('spec',
                               {}).get('uploader',
                                       {}).get('record',
                                               {}).get('upload_record', False):
                splits_parts = []
                filelists = os.listdir(self.splits_dir)
                for filename in filelists:
                    if os.path.getsize(os.path.join(self.splits_dir,
                                                    filename)) < 1024 * 1024:
                        continue
                    title = filename
                    splits_parts.append(
                        VideoPart(
                            path=os.path.join(self.splits_dir, filename),
                            title=title,
                            desc=self.config.get('spec', {}).get(
                                'uploader',
                                {}).get('record',
                                        {}).get('desc',
                                                "").format(date=datestr),
                        ))

                avid, bvid = upload(
                    self.uploader,
                    splits_parts,
                    cr=self.config.get('spec', {}).get('uploader',
                                                       {}).get('copyright', 2),
                    title=self.config.get('spec', {}).get('uploader', {}).get(
                        'record',
                        {}).get('title',
                                "").format(date=datestr,
                                           year=year,
                                           month=month,
                                           day=day,
                                           rough_time=rough_time,
                                           room_name=room_name,
                                           area_name=area_name,
                                           parent_area_name=parent_area_name),
                    tid=self.config.get('spec',
                                        {}).get('uploader',
                                                {}).get('record',
                                                        {}).get('tid', 27),
                    tags=self.config.get('spec', {}).get('uploader', {}).get(
                        'record',
                        {}).get('tags',
                                []).format(area_name=area_name,
                                           parent_area_name=parent_area_name),
                    desc=self.config.get('spec', {}).get('uploader', {}).get(
                        'record',
                        {}).get('desc',
                                "").format(date=datestr,
                                           year=year,
                                           month=month,
                                           day=day,
                                           rough_time=rough_time,
                                           room_name=room_name,
                                           area_name=area_name,
                                           parent_area_name=parent_area_name),
                    source="https://live.bilibili.com/" + self.room_id,
                    thread_pool_workers=self.config.get('root', {}).get(
                        'uploader', {}).get('thread_pool_workers', 1),
                    max_retry=self.config.get('root',
                                              {}).get('uploader',
                                                      {}).get('max_retry', 10),
                    upload_by_edit=self.config.get('root', {}).get(
                        'uploader', {}).get('upload_by_edit', False))
                return_dict["record"] = {"avid": avid, "bvid": bvid}
        except Exception as e:
            logging.error(
                self.generate_log('Error while uploading:' + str(e) +
                                  traceback.format_exc()))
        return return_dict
Пример #9
0
        copyright=2,
        title=v_title,
        tid=208,
        tag=",".join(v_tag),
        desc=v_title,
        source=v_url,
        cover=v_cover,
        thread_pool_workers=1,
    )
    # tmp = [video_path, v_title, v_desc, ",".join(v_tag), v_url]
    # print(tmp)
    

if __name__ == '__main__':

    uploader = BilibiliUploader()
    
    # login
    user_id = ''
    user_passwd = ''
    uploader.login(user_id, user_passwd)
    # uploader = None

    record_file = 'up_history.json'
    record_id_list = []
    record_title_list = []
    record_js = []

    if(os.path.exists(record_file)):
        record_js = json.load(open(record_file))
        for item in record_js: