def main(): tmpdir = os.path.dirname(os.path.abspath(__file__)) + '/tmp' os.chdir(tmpdir) lines = open('outtiny.m3u8', 'r').read() llen = len(lines)+64 wh = math.ceil(llen/3) print('文本大小:%s,图片尺寸:%s' % (llen, wh)) new_img_file_name = new_image(wh, wh, 'out', show_image=False) print('生成图片:%s' % (new_img_file_name)) in_img = cv2.imread(new_img_file_name) steg = LSBSteg(in_img) done = base64.b64encode(lines.encode('utf-8')) done = zlib.compress(done) res = steg.encode_binary(done) cv2.imwrite('outtiny.png', res) m3u8url = uploader().handle('outtiny.png') if _('PROXY') == 'YES': m3u8url = str(base64.b64encode(m3u8url.encode('utf-8')),'utf8') print('This video\'s m3u8 has been published to: %s/p/%s' % (_('APIURL'),m3u8url)) else: print('This video\'s m3u8 has been published to: %s/p/%s' % (_('APIURL'),m3u8url))
def encrypt(code): if _('ENCRYPTION_VERSION') == 'V1': print('ENCRYPTION_VERSION:%s' % _('ENCRYPTION_VERSION')) head = read_bytes('../dangdai-32x32.png') head1 = head[0:-12] head2 = head[-12:] tmpdir = os.getcwd()+'/tmp' if not os.path.exists(tmpdir): os.mkdir(tmpdir) os.chdir(tmpdir) for file in tsfiles(code): portion = os.path.splitext(file) if portion[1] == ".ts": newName = portion[0] + ".png" if os.path.isfile(newName): code = code.replace(file, newName) continue segment = read_bytes('../' + file) segment = zlib.compress(segment) done_segments = head1 + segment + head2 open(newName, 'wb').write(done_segments) code = code.replace(file, newName) #break #os.chdir('../') if _('ENCRYPTION_VERSION') == 'V2': print('ENCRYPTION_VERSION:%s' % _('ENCRYPTION_VERSION')) tmpdir = os.getcwd()+'/tmp' if not os.path.exists(tmpdir): os.mkdir(tmpdir) os.chdir(tmpdir) for file in tsfiles(code): # 1,获取切片大小 filesize = os.path.getsize('../' +file)+64 wh=math.ceil(math.sqrt(filesize/3))*4 # wh=math.ceil(math.sqrt(filesize*3)) print('切片大小:%s,图片尺寸:%s' % (filesize,wh)) data = open('../' + file, "rb").read() data = zlib.compress(data) print('压缩后切片大小:%s' % (len(data))) portion = os.path.splitext(file) newName = portion[0] + ".png" if os.path.isfile(newName): code = code.replace(file, newName) continue # 2,生成图片 new_img_file_name = new_image(wh, wh, portion[0], show_image=False) print('生成图片:%s' % (new_img_file_name)) # 3,隐写 in_img = cv2.imread(new_img_file_name) steg = LSBSteg(in_img) starttime = time.time() res = steg.encode_binary(data) duration = time.time()-starttime print('隐写完成时间:%s' % (duration)) cv2.imwrite(newName, res) print('隐写完成:%s' % (newName)) # embed(new_img_file_name, '../' + file) # 4,替换 code = code.replace(file, newName) """ # 1,获取切片大小 filesize = os.path.getsize('../' + file) + 64 wh = math.ceil(math.sqrt(filesize / 3)) print('切片大小:%s,图片尺寸:%s' % (filesize, wh)) data = open('../' + file, "rb").read() new_img_file_name = r'%s_%s_%s.png' % (wh, wh, md5(data)) if os.path.isfile('out' + new_img_file_name): code = code.replace(file, 'out' + new_img_file_name) continue # 2,生成图片 new_image(wh, wh, md5(data), show_image=False) print('生成图片:%s' % (new_img_file_name)) # 3,隐写 in_img = cv2.imread(new_img_file_name) steg = LSBSteg(in_img) starttime = time.time() res = steg.encode_binary(data) duration = time.time() - starttime print('隐写完成时间:%s' % (duration)) cv2.imwrite('out' + new_img_file_name, res) print('隐写完成:%s' % ('out' + new_img_file_name)) # embed(new_img_file_name, '../' + file) # 4,替换 code = code.replace(file, 'out' + new_img_file_name) """ if not _('ENCRYPTION') == 'YES': return code for file in tsfiles(code): if file.startswith('enc.'): continue print('Encrypting %s to enc.%s ... ' % (file, file), end='') key = exec(['openssl','rand','16']).hex() iv = execstr(['openssl','rand','-hex','16']) exec(['openssl','aes-128-cbc','-e','-in',file,'-out','enc.%s' % file,'-p','-nosalt','-iv',iv,'-K',key]) key_id = api('POST', 'key', data={'iv': iv, 'key': key}) if not key_id: print('failed') open('out.m3u8', 'w').write(code) exit() print('done') code = re.sub('(#EXTINF:.+$[\\r\\n]+^%s$)' % file, '#EXT-X-KEY:METHOD=AES-128,URI="%s/play/%s.key",IV=0x%s\n\\1' % (_('APIURL'), key_id, iv), code, 1, re.M) code = code.replace(file, 'enc.%s' % file) open('out.m3u8', 'w').write(code) return code
def main(): title = argv[2] if argv[2] else os.path.splitext(os.path.basename(argv[1]))[0] tmpdir = os.path.dirname(os.path.abspath(__file__)) + '/tmp' command = command_generator(os.path.abspath(argv[1])) print('commend:%s'%command) if sameparams(tmpdir, command): os.chdir(tmpdir) else: os.mkdir(tmpdir) os.chdir(tmpdir) os.system(command) open('command.sh', 'w').write(command) lines = checker(encrypt(open('out.m3u8', 'r').read())) #return # failures, completions = 0, 0 # executor = ThreadPoolExecutor(max_workers=15) # futures = {executor.submit(uploader().handle, chunk): chunk for chunk in pngfiles(lines)} # # for future in as_completed(futures): # completions += 1 # result = future.result() # # if not result: # failures += 1 # print('[%s/%s] Uploaded failed: %s' % (completions, len(futures), futures[future])) # continue # # lines = lines.replace(futures[future], result) # print('[%s/%s] Uploaded %s to %s' % (completions, len(futures), futures[future], result)) # 上传 lines = upload(lines, pngfiles(lines)) """ head = read_bytes(os.path.dirname(os.path.abspath(__file__)) + '/dangdai-32x32.png') head1 = head[0:-12] head2 = head[-12:] done = base64.b64encode(lines.encode('utf-8')) done = zlib.compress(done) open('out.png', 'wb').write(head1 + done+head2) """ llen = len(lines)+64 wh = math.ceil(llen/3) print('文本大小:%s,图片尺寸:%s' % (llen, wh)) new_img_file_name = new_image(wh, wh, 'out', show_image=False) print('生成图片:%s' % (new_img_file_name)) in_img = cv2.imread(new_img_file_name) steg = LSBSteg(in_img) done = base64.b64encode(lines.encode('utf-8')) done = zlib.compress(done) res = steg.encode_binary(done) cv2.imwrite('out.png', res) m3u8url = uploader().handle('out.png') if _('PROXY') == 'YES': m3u8url = str(base64.b64encode(m3u8url.encode('utf-8')), 'utf8') print('This video\'s m3u8 has been published to: %s/p/%s' % (_('APIURL'),m3u8url)) else: print('This video\'s m3u8 has been published to: %s/p/%s' % (_('APIURL'),m3u8url)) publish(lines, title)