Exemplo n.º 1
0
def _download_m3u8_full(id,
                        info,
                        start_t,
                        duration,
                        thread_id,
                        audio_only=False):
    global THRET_VAL
    _fmt = _G.AudioFormat if audio_only else _G.VideoFormat
    filename = f"{_G.TestDataFolder}/{_G.StreamFilePrefix}_vod{id}.{_fmt}"
    _G.ensure_dir_exist(filename)
    if os.path.exists(filename):
        print(f"[Thread] video {id} already exists, skipping")
        THRET_VAL[thread_id] = [ERRNO_EXIST, filename]
        return ERRNO_EXIST
    target_m3u8 = info[2]
    cmd = ''
    if audio_only:
        target_m3u8 = [uri for uri in info if 'audio_only' in uri][0]
        cmd = _G.FFmpegAudioDownloadCmd.format(start_t, target_m3u8, duration,
                                               filename)
    else:
        cmd = _G.FFmpegStreamDownloadCmd.format(start_t, target_m3u8, duration,
                                                filename)
    print(f"Downloading {target_m3u8} to {filename}...")
    print(f">> {cmd}")
    os.system(cmd)
    THRET_VAL[thread_id] = [ERRNO_OK, filename]
    return ERRNO_OK
Exemplo n.º 2
0
def download_m3u8(id, slug, start_t, duration, _async=False, thread_id=0):
    _G.ensure_dir_exist(f"{_G.StreamFolder}/")
    info = get_m3u8_info(id)
    print(f"Downloading {id}")
    _th = Thread(target=_download_m3u8,
                 args=(id, slug, info, start_t, duration, thread_id))
    _th.start()
    if not _async:
        _th.join()
Exemplo n.º 3
0
def download_full_vod(id,
                      duration,
                      _async=False,
                      thread_id=0,
                      audio_only=False):
    _G.ensure_dir_exist(f"{_G.TestDataFolder}/")
    info = get_m3u8_info(id)
    print(f"Downloading {id}")
    _th = Thread(target=_download_m3u8_full,
                 args=(id, info, 0, duration, thread_id, audio_only))
    _th.start()
    if not _async:
        _th.join()
Exemplo n.º 4
0
def extandclip_video(vfilename, out_folder=None):
    if not out_folder:
        if _G.FLAG_POSITIVE_PROC:
            out_folder = _G.PositiveSamplePath
        elif _G.FLAG_NEGATIVE_PROC:
            out_folder = _G.NegativeSamplePath
        else:
            out_folder = _G.StreamAudioPath
    _G.VideoFilename = vfilename
    _G.ensure_dir_exist(f"{out_folder}/_.mp3")
    video = load_video(vfilename)
    _G.video_length = video.duration
    generate_audio_clips(video.audio, out_folder)
    video.close()
Exemplo n.º 5
0
def start_analyze():
    global data
    print(f"Analyzing stream file index of {_G.StreamFileIndex}")
    data = []

    if _G.FLAG_POSITIVE_PROC:
        print(f"Analyzing Positive Samples")
        _G.ensure_dir_exist(f"{_G.PositiveSamplePath}/.")
        _G.wait(1)
        files = _G.positive_audios()
        for i, file in enumerate(files):
            analyze_and_plot_audio(file, _G.positive_plot_filename(i), True)
            _G.dump_data(data, _G.make_positive_dataname(i))
    elif _G.FLAG_NEGATIVE_PROC:
        print(f"Analyzing Negative Samples")
        _G.ensure_dir_exist(f"{_G.NegativeSamplePath}/.")
        _G.wait(1)
        files = _G.negative_audios()
        for i, file in enumerate(files):
            analyze_and_plot_audio(file, _G.negative_plot_filename(i), True)
            _G.dump_data(data, _G.make_negative_dataname(i))
    else:
        _G.ensure_dir_exist(_G.plot_filename(0))
        files = get_audio_files(_G.StreamFilePrefix, _G.StreamFileSuffix)
        flen = len(files)
        for i, file in enumerate(files):
            print(f"Analyzing {i+1}/{flen}")
            analyze_and_plot_audio(file, _G.plot_filename(i), True)
            # if i >= 2:
            #   break
        _G.dump_data(data, _G.get_stream_adump_filename())
Exemplo n.º 6
0
def download_clip(id, slug):
    print("Refreshing Twitch API...")
    access_token = oauth.refresh_token()['access_token']
    APIHeader['Authorization'] = f"Bearer {access_token}"

    print("Waiting Twitch API...")
    data = get_helixclip_info(slug).json()
    data = data['data'][0]
    print(f"Retrived data: {data}")

    video_uri = f"{data['thumbnail_url'].split('-preview')[0]}.{_G.VideoFormat}"

    filename = f"{_G.PositiveSamplePath}/{slug}.{_G.VideoFormat}"
    _G.ensure_dir_exist(filename)

    if os.path.exists(filename):
        return ERRNO_EXIST, filename

    with open(filename, 'wb') as file:
        print(f"Downloading {video_uri} to {filename}...")
        file.write(requests.get(video_uri).content)
    return ERRNO_OK, filename