def upload_f(uploader, video_path=None, v_title=None, v_desc=None, v_cover=None, v_tag=None, v_url=None): for i in range(len(v_tag)): if(len(v_tag[i]) > 19): v_tag[i] = v_tag[i][:19] if(len(v_tag) < 1): v_tag = ['studing'] print(v_tag) if(len(v_title) >=80): v_title = v_title[:80] # processing video file parts = [] parts.append(VideoPart( path=video_path, title=v_title, desc=v_title )) ''' parts.append(VideoPart( path="C:/Users/xxx/Videos/2.mp4", title="", desc="" )) ''' # upload # copyright =2 move, =1 selfmade # tid = category avid, bvid = uploader.upload( parts=parts, copyright=2, title=v_title, tid=208, tag=",".join(v_tag), desc=v_title, source=v_url, cover=v_cover, thread_pool_workers=1, )
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)
if LastUploadDate != time.strftime("%d", time.localtime()): print(" try uploading Stream" + LastUploadDate) files = os.listdir(path) #遍历录像目录 for file in files: #寻找指定类型的录像文件 if file.endswith(type): #检测录像文件体积编号 tmpsizeA = os.path.getsize(path + '/' + file) time.sleep(10) tmpsizeB = os.path.getsize(path + '/' + file) #如果录像体积无变化,开始上传 if tmpsizeA == tmpsizeB: VideoPartList.append( VideoPart( path=path + '/' + file, title=file, )) UploadingFile.append(file) else: print( "This video file is writing while streaming, do nothing" ) if len(VideoPartList) > 0: UploadFile(VideoPartList) logging.info("Upload " + LastUploadDate + " steam successful, list of Uploaded file:") LastUploadDate = time.strftime("%d", time.localtime()) for file in UploadingFile: logging.info("Uploaded " + file + "delete it") os.remove(path + '/' + file) VideoPartList = []
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
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