def run(): # {"title": tmp_data["title"], "id": video_id, "av": _["av"]} work = GetPlayList.get_work_list() logger = tool.getLogger() account = tool.QRLogin() for i in work: logger.debug(json.dumps(i)) logger.info("start: vid[{}], 1080P[{}], Multipart[{}]".format( i["id"], i["hd"], i["multipart"])) vmer = getVideo.VideoManager(i["id"], i["hd"]) data = vmer.getVideo() if data[0]: if i["multipart"]: success, res, upos_uri = Upload.uploadWithOldBvid( account.getCookies(), i, data[1]) else: success, res, upos_uri = Upload.uploadWithNewBvid( account.getCookies(), i, data[1]) if not success: continue upos_uri = upos_uri.split(".")[0] res = json.loads(res) if res["code"] != 0: logger.error(res["message"]) continue with tool.getDB() as db: db.execute( "insert into data(vid,bvid,title,filename) values(?,?,?,?);", (i["id"], res["data"]["bvid"], i["title"], upos_uri)) db.commit() logger.info(f"finished, bvid[{res['data']['bvid']}]") vmer.deleteFile() else: logger.error("download failed")
def __consume(): account = tool.AccountManager("Anki") logger = tool.getLogger() logger.debug("start video Consumer") while True: i = buffer.get(block=True) logger.debug(json.dumps(i)) logger.info("start: vid[{}], 1080P[{}], Multipart[{}]".format( i["id"], i["hd"], i["multipart"])) vmer = getVideo.VideoManager(i["id"], i["hd"]) data = vmer.getVideo() if data[0]: if i["multipart"]: success, res, upos_uri = Upload.uploadWithOldBvid( account.getCookies(), i, data[1]) else: success, res, upos_uri = Upload.uploadWithNewBvid( account.getCookies(), i, data[1]) if not success: continue upos_uri = upos_uri.split(".")[0] res = json.loads(res) if res["code"] != 0: logger.error(res["message"]) continue with tool.getDB() as db: db.execute( "insert into data(vid,bvid,title,filename) values(?,?,?,?);", (i["id"], res["data"]["bvid"], i["title"], upos_uri)) db.commit() logger.info(f"finished, bvid[{res['data']['bvid']}]") vmer.deleteFile() else: logger.error("download failed")
def __consume(): account = tool.QRLogin() logger = tool.getLogger() logger.debug("start video Consumer") proxy = tool.settingConf["Proxy"] while True: i = buffer.get(block=True) channelInfo = i.channelParam logger.debug(json.dumps(channelInfo)) logger.info("start: vid[{}], Multipart[{}]".format( channelInfo["id"], channelInfo["multipart"])) # vmer = getVideo.VideoManager(i["id"], i["hd"]) data = i.download(proxy) if data: fpath = i.path() if len(fpath) <= 0: continue if channelInfo["multipart"]: success, res, upos_uri = Upload.uploadWithOldBvid( account.getCookies(), channelInfo, fpath) else: success, res, upos_uri = Upload.uploadWithNewBvid( account.getCookies(), channelInfo, fpath) if not success: continue upos_uri = upos_uri.split(".")[0] res = json.loads(res) if res["code"] != 0: logger.error(res["message"]) continue with tool.getDB() as db: db.execute( "insert into data(vid,bvid,title,filename) values(?,?,?,?);", (channelInfo["id"], res["data"]["bvid"], channelInfo["title"], upos_uri)) db.commit() logger.info(f"finished, bvid[{res['data']['bvid']}]") i.deleteFile() else: logger.error("download failed")
def extractElements(self, path=[], include_submit=0, include_button=0): ''' Pull a form's elements out of the document given the path to the form. For most elements, the returned dictionary has a key:value pair holding the input elements name and value. For radio, checkboxes and selects, the value is a dictionary holding: value or name: 'selected' (note: not 'checked') where the value of the input/option is used but if not present then the name is used. ''' form = self for name, element in path: form = form.getByName(name)[element] elements = {} submits = 0 buttons = 0 for input in form.getByName('input'): if not hasattr(input, 'type'): elements[input.name] = input.getattr('value', '') elif input.type == 'image': continue elif input.type == 'button' and not include_button: continue elif input.type == 'submit' and not include_submit: continue elif input.type == 'file': elements[input.name] = Upload('') elif input.type in ['checkbox', 'radio']: l = elements.setdefault(input.name, {}) key = input.hasattr('value') and input.value or input.name if input.hasattr('checked'): l[key] = 'selected' else: l[key] = '' elif input.type == 'submit': name = input.getattr('name', 'submit') if name == 'submit': name = 'submit%s' % str(submits) submits = submits + 1 elements[name] = input.getattr('value', '') elif input.type == 'button': name = input.getattr('name', 'button') if name == 'button': name = 'button%s' % str(buttons) buttons = buttons + 1 elements[name] = input.getattr('value', '') else: elements[input.name] = input.getattr('value', '') for textarea in form.getByName('textarea'): if len(textarea): elements[textarea.name] = textarea.getContentString() else: elements[textarea.name] = '' for input in form.getByName('select'): options = input.getByName('option') d = elements[input.name] = {} selected = first = None for option in options: if option.hasattr('value'): key = option.value elif len(option) > 0: key = option[0] else: continue if first is None: first = key if option.hasattr('selected'): d[key] = 'selected' selected = 1 else: d[key] = '' if ((not input.hasattr('size') or input.size == 1) and selected is None and first is not None): d[first] = 'selected' return elements
def extractElements(self, path=[], include_submit=0, include_button=0): '''Pull a form's elements out of the document given the path to the form. ''' form = self for name, element in path: form = form.getByName(name)[element] elements = {} submits = 0 buttons = 0 for input in form.getByName('input'): if not hasattr(input, 'type'): elements[input.name] = input.getattr('value', '') elif input.type == 'image': continue elif input.type == 'button' and not include_button: continue elif input.type == 'submit' and not include_submit: continue elif input.type == 'file': elements[input.name] = Upload('') elif input.type == 'checkbox': l = elements.setdefault(input.name, []) l.append(input.getattr('value', '')) elif input.type == 'radio': l = elements.setdefault(input.name, []) l.append(input.getattr('value', '')) elif input.type == 'submit': name = input.getattr('name', 'submit') if name == 'submit': name = 'submit%s'%str(submits) submits = submits + 1 elements[name] = input.getattr('value', '') elif input.type == 'button': name = input.getattr('name', 'button') if name == 'button': name = 'button%s'%str(buttons) buttons = buttons + 1 elements[name] = input.getattr('value', '') else: elements[input.name] = input.getattr('value', '') for textarea in form.getByName('textarea'): if len(textarea): elements[textarea.name] = textarea.getContentString() else: elements[textarea.name] = '' for input in form.getByName('select'): options = input.getByName('option') for option in options: if option.hasattr('selected'): l = elements.setdefault(input.name, []) if option.hasattr('value'): l.append(option.value) elif len(option) > 0: l.append(option[0]) else: l.append('') if not elements.has_key(input.name) and len(options): option = options[0] if option.hasattr('value'): elements[input.name] = option.value else: elements[input.name] = option[0] return elements