Beispiel #1
0
def start_full_process():
    global THRET_VAL
    st_time = timeit.default_timer()

    vodid = _G.StreamFileIndex
    data = get_video_info(vodid)
    print(f"Retrieved vod data: {data}")
    data = data.json()['data'][0]
    print(f"VodId: {vodid}\n{data}")

    _G.StreamFilePrefix = data['user_name'].upper()
    _G.FLAG_POSITIVE_PROC = False
    _G.init()
    duration = hms2sec(data['duration'])
    print(f"Duration: {data['duration']} ({duration})")

    download_full_vod(vodid, duration)
    errno, stream_filename = None, ''
    while True:
        try:
            errno, stream_filename = THRET_VAL[0]
            break
        except Exception:
            _G.wait(0.3)

    inp = ''
    if _G.FLAG_ALWAYS_YES:
        inp = 'Y'
    elif _G.FLAG_ALWAYS_NO:
        inp = 'N'

    if errno == ERRNO_EXIST:
        while inp != 'Y' and inp != 'N':
            inp = input("Stream video already exists, process anyway? (Y/N): "
                        ).upper()

    if errno == ERRNO_OK or inp == 'Y':
        _G.wait(1)
        clip.spawn_extracting_proc(_G.StreamFileIndex, None,
                                   _G.StreamFilePrefix, _G.PROC_FULL)
        _G.wait(1)
        analyzer.spawn_analyze_proc(_G.StreamFileIndex, None,
                                    _G.StreamFilePrefix, _G.PROC_FULL)

    print("Complete, time taken: ", timeit.default_timer() - st_time)
Beispiel #2
0
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestRegressor
from collections import defaultdict
from pprint import pprint

VERBOSE = 1
N_JOBS = 1
GRID_CV = 5
Category = 'zcr'
TRAIN_SVM = True
TRAIN_KNN = True
TRAIN_RFR = True

if __name__ == "__main__":
    argv_parse.init()
    _G.init()
    N_JOBS = -1


# parts: splited path of the origin data
#        used to locate postive label file path
def load_postive_label(parts):
    broardcaster = parts[1]
    episode = parts[2]
    filename = f"{_G.PositiveSampleFolder}/{broardcaster}/{episode}/{_G.PostiveLabelFilename}"
    ret = {}
    with open(filename, 'r') as fp:
        sam_datas = json.load(fp)
        for sdata in sam_datas:
            slug = sdata['slug']
            st = sdata['start_t']
def start_sample_process():
    global THRET_VAL

    st_time = timeit.default_timer()

    slug = _G.ClipName
    data = None
    _cnt = 0

    while not data and _cnt < 3:
        _cnt += 1
        data = getkarkan_clip_info(slug).json()
        if not data:
            print(f"Failed to get clip data ({data})...retry({_cnt})")
            time.sleep(1)
    if not data['vod']:
        print("Source unavailable, throwing")
        raise RuntimeError("Source VOD unavailable")

    id = get_id_from_data(data)
    start_t = get_ori_timestamp(data)

    _G.StreamFileIndex = int(id)
    _G.StreamFilePrefix = data['broadcaster']['name'].upper()
    _G.FLAG_POSITIVE_PROC = True
    _G.init()

    errno, clip_fname = download_clip(id, slug)

    inp = ''
    if _G.FLAG_ALWAYS_YES:
        inp = 'Y'
    elif _G.FLAG_ALWAYS_NO:
        inp = 'N'

    if errno == ERRNO_EXIST:
        print(f"{clip_fname} already downloaded, skip")
        while inp != 'Y' and inp != 'N':
            inp = input("Process clip anyway? (Y/N): ").upper()

    if errno == ERRNO_OK or inp == 'Y':
        print("Generating labels...")
        generate_label(clip_fname, slug, start_t)

        print("Extracting clips audio")
        _G.wait(1)
        clip.spawn_extracting_proc(_G.StreamFileIndex, slug,
                                   _G.StreamFilePrefix, _G.PROC_SAMPLE_POS)

        print("Analyzing clip...")
        _G.wait(1)
        analyzer.spawn_analyze_proc(_G.StreamFileIndex, slug,
                                    _G.StreamFilePrefix, _G.PROC_SAMPLE_POS)

    ori_st, duration = _G.get_download_timeinfo(start_t)
    print(f"Ori. start time/duraiton: ", ori_st, duration)
    THRET_VAL = {}
    download_m3u8(id, slug, ori_st, duration)

    errno, stream_filename = None, ''
    while True:
        try:
            errno, stream_filename = THRET_VAL[0]
            break
        except Exception:
            _G.wait(0.3)

    inp = ''
    if _G.FLAG_ALWAYS_YES:
        inp = 'Y'
    elif _G.FLAG_ALWAYS_NO:
        inp = 'N'

    if errno == ERRNO_EXIST:
        while inp != 'Y' and inp != 'N':
            inp = input("Stream video already exists, process anyway? (Y/N): "
                        ).upper()

    if errno == ERRNO_OK or inp == 'Y':
        _G.wait(1)
        clip.spawn_extracting_proc(_G.StreamFileIndex, slug,
                                   _G.StreamFilePrefix, False)
        _G.wait(1)
        analyzer.spawn_analyze_proc(_G.StreamFileIndex, slug,
                                    _G.StreamFilePrefix, False)

    print("Complete, time taken: ", timeit.default_timer() - st_time)