Esempio n. 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('file', type=str, help='video file')
    parser.add_argument('title', type=str, nargs='?', help='post title')
    parser.add_argument('time',
                        type=int,
                        nargs='?',
                        help='time for pre segment',
                        default=0)
    parser.add_argument('-c, --config',
                        type=str,
                        dest='config',
                        help='change the configuration file path')
    args = parser.parse_args()

    load_dotenv(args.config)
    tmpdir = path.dirname(path.abspath(__file__)) + '/tmp'
    command = genslice(path.abspath(args.file), args.time)

    if sameparams(tmpdir, command):
        os.chdir(tmpdir)
    else:
        os.mkdir(tmpdir)
        os.chdir(tmpdir)
        os.system(command)
        open('command.sh', 'w').write(command)

    failures, completions = 0, 0
    lines = encrypt(repairer(open('out.m3u8', 'r').read()))
    executor = ThreadPoolExecutor(max_workers=15)
    futures = {
        executor.submit(uploader().handle, chunk): chunk
        for chunk in tsfiles(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))

    #Write to file
    open('out.m3u8', 'w').write(lines)
    open('params.json', 'w').write(json.dumps(uploader().params()))

    if failures:
        print('Partially successful: %d/%d' %
              (completions - failures, completions))
        print('You can re-execute this program with the same parameters')
        exit(2)

    publish(lines, args.title or path.splitext(path.basename(args.file))[0])
Esempio n. 2
0
File: up.py Progetto: pdool/free-hls
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]))

    if sameparams(tmpdir, command):
        os.chdir(tmpdir)
    else:
        os.mkdir(tmpdir)
        os.chdir(tmpdir)
        os.system(command)
        open('command.sh', 'w').write(command)

    failures, completions = 0, 0
    lines = encrypt(open('out.m3u8', 'r').read())

    #TODO
    for file in tsfiles(lines):
        if os.path.getsize(file) >= upload_limit[_('UPLOAD_DRIVE')]:
            print('file too large: %s' % file)
            exit(1)

    executor = ThreadPoolExecutor(max_workers=10)
    futures = {
        executor.submit(uploader(), chunk): chunk
        for chunk in tsfiles(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))

    print('\n')

    #Write to file
    open('out.m3u8', 'w').write(lines)

    if not failures:
        publish(lines, title)
    else:
        print('Partially successful: %d/%d' %
              (completions, completions - failures))
        print('You can re-execute this program with the same parameters')
Esempio n. 3
0
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)
Esempio n. 4
0
def main(video_path, video_title, segment_specify, repair=False):
    global upload_drive
    cwd = os.getcwd()
    upload_drive = importlib.import_module('uploader.' + _('UPLOAD_DRIVE'))
    title = video_title if video_title else os.path.splitext(
        os.path.basename(video_path))[0]
    tmpdir = os.path.dirname(os.path.abspath(__file__)) + '/tmp'
    segment_time = get_segment_time(os.path.abspath(video_path),
                                    segment_specify)
    command = command_generator(os.path.abspath(video_path), segment_time)
    if not os.path.exists(tmpdir):
        os.mkdir(tmpdir)
    if sameparams(tmpdir, command):
        os.chdir(tmpdir)
    else:
        os.chdir(tmpdir)
        try:
            os.system(command)
        except KeyboardInterrupt:
            return 1
        with open('command.sh', 'w') as f:
            f.write(command)
    failures, completions = 0, 0
    with open('out.m3u8', 'r') as f:
        lines = f.read()
    for tsfile in tsfiles(lines):
        if os.path.getsize(tsfile) >= upload_drive.UPLOAD_LIMIT:
            if repair:
                tmp = 'rep.%s' % tsfile
                os.system(genrepair(tsfile, tmp,
                                    upload_drive.UPLOAD_LIMIT * 8))
                os.rename(tsfile, 'old.%s' % tsfile)
                os.rename(tmp, tsfile)
            else:
                os.chdir(cwd)
                return 1
    executor = ThreadPoolExecutor(max_workers=10)
    futures = {
        executor.submit(uploader(), chunk): chunk
        for chunk in tsfiles(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))
    print('\n')
    # Write to file
    with open('out.m3u8', 'w') as f:
        f.write(lines)
    os.chdir(cwd)
    if not failures:
        shutil.copy2('./tmp/out.m3u8', f'./results/{int(time.time())}.m3u8')
        writefile(lines, title)
        shutil.rmtree(tmpdir)
        return 0
    else:
        print('Partially successful: %d/%d' %
              (completions, completions - failures))
        print('You can re-execute this program with the same parameters')
        return 2