Exemplo n.º 1
0
def main_onsen_hibiki():
    Onsen = onsen.onsen(keywords, SAVEROOT)
    Hibiki = hibiki.hibiki(keywords, SAVEROOT)
    while(True):
        now = DT.datetime.now()
        if (now.hour == 7 and now.minute <= 5 and Onsen.reload_date != DT.date.today()):
            titles = Onsen.rec()
            titles.extend(Hibiki.rec())
            if (bool(titles)):
                f.recording_successful_toline("、".join(titles))
            else:
                print("in onsen, hibiki. there aren't new title.")
        time.sleep(300)
Exemplo n.º 2
0
def rec(data):
    program_data = data[0]
    wait_start_time = data[1]
    AuthToken = data[2]
    SAVEROOT = data[3]
    #ディレクトリの作成
    dir_path = SAVEROOT + "/" + program_data["title"].replace(" ", "_")
    f.createSaveDir(dir_path)
    #保存先パスの作成
    file_path = dir_path + "/" + program_data["title"] + "_" + program_data[
        "ft"][:12]
    file_path = file_path.replace(" ", "_")
    #stream urlの取得
    url = 'http://f-radiko.smartstream.ne.jp/%s/_definst_/simul-stream.stream/playlist.m3u8' % program_data[
        "station"]
    m3u8 = gen_temp_chunk_m3u8_url(url, AuthToken)
    #コマンドの実行
    time.sleep(wait_start_time)
    cwd = (
        'ffmpeg -loglevel error -headers "X-Radiko-AuthToken: %s" -i "%s" -acodec copy  "%s.m4a"'
        % (AuthToken, m3u8, file_path))
    p1 = subprocess.Popen(cwd,
                          stdin=subprocess.PIPE,
                          stdout=subprocess.DEVNULL,
                          shell=True)
    print("sleep for " + str(program_data["dur"] - 10))
    time.sleep(program_data["dur"] - 10)
    print("STOP SIGNAL......")
    p1.communicate(b'q')
    time.sleep(10)
    if (f.is_recording_succeeded(file_path)):
        f.recording_successful_toline(program_data["title"])
        # fs = open(file_path+".m4a", "rb")
        # f.DropBox.upload(program_data["title"], program_data["ft"], fs.read())
        url = f.Swift.upload_file(filePath=file_path + ".m4a")
        f.Mysql.insert(title=program_data["title"].replace(" ", "_"),
                       pfm=program_data["pfm"],
                       timestamp=program_data["ft"],
                       station=program_data["station"],
                       uri=url,
                       path=file_path + ".m4a",
                       info=program_data["info"])
        if (f.Swift.hadInit):
            cmd = 'rm "%s"' % (file_path + ".m4a")
            subprocess.run(cmd, shell=True)
        # fs.close()
    else:
        f.recording_failure_toline(program_data["title"])
Exemplo n.º 3
0
    def rec(self, data):
        program_data = data[0]
        wait_start_time = data[1]
        SAVEROOT = data[2]

        # print(program_data["title"])

        dir_name = program_data["title"].replace(" ", "_")
        dir_path = SAVEROOT + "/" + dir_name
        f.createSaveDir(dir_path)

        file_path = dir_path + "/" + program_data["title"].replace(" ", "_") + "_" + program_data["ft"][:12]
        cwd  = ('rtmpdump -r rtmp://fms-base1.mitene.ad.jp/agqr/aandg1 ')
        cwd += ('--stop %s ' % str(program_data["dur"]*60))
        cwd += ('--live -o "%s.flv"' % (file_path))
        time.sleep(wait_start_time)
        #rtmpdumpは時間指定の終了ができるので以下を同期処理にする
        subprocess.run(cwd, shell=True)
        #変換をする
        cwd2 = ('ffmpeg -loglevel error -i "%s.flv" -vn -c:a aac -b:a 256k "%s.m4a"' % (file_path, file_path))
        subprocess.run(cwd2.split())
        print("agqr: finished!")
        if (f.is_recording_succeeded(file_path)):
            f.recording_successful_toline(program_data["title"])
            # dropbox
            # fs = open(file_path+".m4a", "rb")
            # f.DropBox.upload(program_data["title"], program_data["ft"], fs.read())
            # fs.close()
            
            # rclone
            f.Rclone.upload(dir_path, dir_name)
            #object storage
            url = f.Swift.upload_file(filePath=file_path+".m4a")
            f.Mysql.insert(
                title= program_data["title"].replace(" ", "_"),
                pfm= program_data["pfm"],
                timestamp= program_data["ft"] + "00",
                station= "AGQR",
                uri= url
            )
            if (f.Swift.hadInit):
                cmd = 'rm "%s"' % (file_path + ".m4a")
                subprocess.run(cmd, shell=True)
        else:
            f.recording_failure_toline(program_data["title"])
        os.remove(file_path + ".flv")
Exemplo n.º 4
0
def rec(data):
    program_data = data[0]
    wait_start_time = data[1]
    AuthToken = data[2]
    SAVEROOT = data[3]
    dbx = data[4]
    #ディレクトリの作成
    dir_path = SAVEROOT + "/" + program_data["title"].replace(" ", "_")
    f.createSaveDir(dir_path)
    dbx_path = "/radio/" + program_data["title"]
    res = dbx.files_list_folder('/radio')
    db_list = [d.name for d in res.entries]
    if not program_data["title"] in db_list:
        dbx.files_create_folder(dbx_path)
    #保存先パスの作成
    file_path = dir_path + "/" + program_data["title"] + "_" + program_data[
        "ft"][:12]
    file_path = file_path.replace(" ", "_")
    dbx_path += "/" + program_data["title"] + "_" + program_data[
        "ft"][:12] + ".m4a"
    #print(program_data["title"])
    #stream urlの取得
    url = 'http://f-radiko.smartstream.ne.jp/%s/_definst_/simul-stream.stream/playlist.m3u8' % program_data[
        "station"]
    m3u8 = gen_temp_chunk_m3u8_url(url, AuthToken)
    #コマンドの実行
    time.sleep(wait_start_time)
    cwd = (
        'ffmpeg -loglevel error -headers "X-Radiko-AuthToken: %s" -i "%s" -acodec copy  "%s.m4a"'
        % (AuthToken, m3u8, file_path))
    p1 = subprocess.Popen(cwd,
                          stdin=subprocess.PIPE,
                          stdout=subprocess.DEVNULL,
                          shell=True)
    print("sleep for " + str(program_data["dur"] - 10))
    time.sleep(program_data["dur"] - 10)
    print("STOP SIGNAL......")
    p1.communicate(b'q')
    time.sleep(10)
    if (f.is_recording_succeeded(file_path)):
        f.recording_successful_toline(program_data["title"])
        fs = open(file_path + ".m4a", "rb")
        dbx.files_upload(fs.read(), dbx_path)
        fs.close()
    else:
        f.recording_failure_toline(program_data["title"])
Exemplo n.º 5
0
    def rec(self, data):
        program_data = data[0]
        #print(program_data)
        wait_start_time = data[1]
        SAVEROOT = data[2]
        dbx = data[3]
        dir_path = SAVEROOT + "/" + program_data["title"].replace(" ", "_")
        f.createSaveDir(dir_path)
        dbx_path = "/radio/" + program_data["title"]
        res = dbx.files_list_folder('/radio')
        db_list = [d.name for d in res.entries]
        if not program_data["title"] in db_list:
            dbx.files_create_folder(dbx_path)
        dbx_path += "/" + program_data["title"] + "_" + program_data[
            "ft"][:12] + ".m4a"

        file_path = dir_path + "/" + program_data["title"].replace(
            " ", "_") + "_" + program_data["ft"][:12]
        cwd = ('rtmpdump -r rtmp://fms-base1.mitene.ad.jp/agqr/aandg1b ')
        cwd += ('--stop %s ' % str(program_data["dur"] * 60))
        cwd += ('--live -o "%s.flv"' % (file_path))
        time.sleep(wait_start_time)
        #rtmpdumpは時間指定の終了ができるので以下を同期処理にする
        subprocess.run(cwd, shell=True)
        #変換をする
        cwd2 = (
            'ffmpeg -loglevel error -i "%s.flv" -vn -acodec copy "%s.m4a"' %
            (file_path, file_path))
        subprocess.run(cwd2, shell=True)
        print("agqr finish!")
        if (f.is_recording_succeeded(file_path)):
            f.recording_successful_toline(program_data["title"])
            fs = open(file_path + ".m4a", "rb")
            dbx.files_upload(fs.read(), dbx_path)
            fs.close()
        else:
            f.recording_failure_toline(program_data["title"])
        os.remove(file_path + ".flv")