def rec(self): api_base = "https://vcms-api.hibiki-radio.jp/api/v1/" headers = {"X-Requested-With": "XMLHttpRequest"} # 番組の取得 res = requests.get(api_base+"programs", headers=headers) prog_data = json.loads(res.text) returnData = [] for program in prog_data: episode = program.get("episode") if episode is None: continue title = program.get("name") personality = program.get("cast") if (self.keyword.search(title) or self.keyword.search(personality)): # フォルダの作成 dir_name = title.replace(" ", "_") dir_path = self.SAVEROOT + "/" + dir_name f.createSaveDir(dir_path) # ファイル重複チェック update_date = DT.datetime.strptime(episode["updated_at"].split(" ")[0], "%Y/%m/%d") file_name = title.replace(" ", "_").replace(",", "_") + "_" + update_date.strftime("%Y%m%d") + ".m4a" file_path = dir_path +"/"+ file_name if f.did_record_prog(file_path, title, update_date.strftime("%Y%m%d")): continue url2 = "https://vcms-api.hibiki-radio.jp/api/v1/programs/" + program.get("access_id") res2 = requests.get(url2, headers=headers) tmpjson = json.loads(res2.text) if (tmpjson.get("episode") is None) or (tmpjson["episode"].get("video") is None): continue video_url = api_base + "videos/play_check?video_id=" + str(tmpjson["episode"]["video"]["id"]) res2 = requests.get(video_url, headers=headers) tmpjson = json.loads(res2.text) print(title) if (tmpjson.get("playlist_url") is None): continue returnData.append(title) cwd = 'ffmpeg -loglevel error -i "%s" -acodec copy "%s"' % (tmpjson["playlist_url"], file_path) subprocess.run(cwd.split()) # dropbox # fs = open(file_path, "rb") # f.DropBox.upload(title, update_date.strftime("%Y%m%d"), fs.read()) # fs.close() #rclone f.Rclone.upload(dir_path, dir_name) #object storage url = f.Swift.upload_file(filePath=file_path) f.Mysql.insert( title= title, pfm= personality, timestamp= update_date.strftime("%Y%m%d"), station= "hibiki", uri= url, ) if (f.Swift.hadInit): cmd = 'rm "%s"' % (file_path) subprocess.run(cmd, shell=True) print("hibiki:finished") return returnData
def rec(self): self.reload_date = DT.date.today() res = requests.get( "http://www.onsen.ag/api/shownMovie/shownMovie.json") res.encoding = "utf-8" programs = json.loads(res.text) returnData = [] for program in programs["result"]: url = "http://www.onsen.ag/data/api/getMovieInfo/%s" % program res2 = requests.get(url) prog = json.loads(res2.text[9:len(res2.text) - 3]) title = prog.get("title") personality = prog.get("personality") update_DT = prog.get("update") count = prog.get("count") if (title is not None and personality is not None and update_DT != ""): if (self.keyword.search(title) or self.keyword.search(personality)): movie_url = prog["moviePath"]["pc"] if (movie_url == ""): continue # title の長さ title = title[:30] # フォルダの作成 dir_name = title.replace(" ", "_") dir_path = self.SAVEROOT + "/" + dir_name f.createSaveDir(dir_path) # ファイル重複チェック file_name = title.replace(" ", "_") + "#" + count + ".mp3" file_path = dir_path + "/" + file_name if (f.did_record_prog(file_path, title, update_DT)): continue # print(prog["update"], prog["title"], prog["personality"]) returnData.append(title) res3 = requests.get(movie_url) fs = open(file_path, "wb") fs.write(res3.content) fs.close() # dropbox # f.DropBox.upload_onsen(title, count, res3.content) # rclone f.Rclone.upload(dir_path, dir_name) # object storage url = f.Swift.upload_file(filePath=file_path) f.Mysql.insert(title=title, pfm=personality, timestamp=update_DT, station="onsen", uri=url) if (f.Swift.hadInit): cmd = 'rm "%s"' % (file_path) subprocess.run(cmd.split()) return returnData
def rec(self): api_base = "https://vcms-api.hibiki-radio.jp/api/v1/" headers = {"X-Requested-With": "XMLHttpRequest"} # 番組の取得 res = requests.get(api_base + "programs", headers=headers) prog_data = json.loads(res.text) returnData = [] for program in prog_data: episode = program.get("episode") if episode is None: continue title = program.get("name") personality = program.get("cast") if (self.keyword.search(title) or self.keyword.search(personality)): # フォルダの作成 dir_path = self.SAVEROOT + "/" + title.replace(" ", "_") f.createSaveDir(dir_path) # ファイル重複チェック update_date = DT.datetime.strptime( episode["updated_at"].split(" ")[0], "%Y/%m/%d") file_name = title.replace( " ", "_") + "_" + update_date.strftime("%Y%m%d") + ".m4a" file_path = dir_path + "/" + file_name if file_name in os.listdir(dir_path): continue url2 = "https://vcms-api.hibiki-radio.jp/api/v1/programs/" + program.get( "access_id") res2 = requests.get(url2, headers=headers) tmpjson = json.loads(res2.text) video_url = api_base + "videos/play_check?video_id=" + str( tmpjson["episode"]["video"]["id"]) res2 = requests.get(video_url, headers=headers) tmpjson = json.loads(res2.text) print(title) if (tmpjson.get("playlist_url") is None): continue returnData.append(title) cwd = 'ffmpeg -loglevel error -i "%s" -acodec copy "%s"' % ( tmpjson["playlist_url"], file_path) subprocess.run(cwd, shell=True) dbx_path = "/radio/" + title res = self.dbx.files_list_folder('/radio') db_list = [d.name for d in res.entries] if not title in db_list: self.dbx.files_create_folder(dbx_path) dbx_path += "/" + title + "_" + update_date.strftime( "%Y%m%d") + ".m4a" fs = open(file_path, "rb") self.dbx.files_upload(fs.read(), dbx_path) fs.close() print("finish") return returnData
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"])
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")
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"])
def rec(self): self.reload_date = DT.date.today() res = requests.get( "http://www.onsen.ag/api/shownMovie/shownMovie.json") res.encoding = "utf-8" programs = json.loads(res.text) returnData = [] for program in programs["result"]: url = "http://www.onsen.ag/data/api/getMovieInfo/%s" % program res2 = requests.get(url) prog = json.loads(res2.text[9:len(res2.text) - 3]) title = prog.get("title") personality = prog.get("personality") update_DT = prog.get("update") count = prog.get("count") if (title is not None and personality is not None and update_DT != ""): if (self.keyword.search(title) or self.keyword.search(personality)): movie_url = prog["moviePath"]["pc"] if (movie_url == ""): continue # title の長さ title = title[:30] # フォルダの作成 dir_path = self.SAVEROOT + "/" + title.replace(" ", "_") f.createSaveDir(dir_path) # ファイル重複チェック file_name = title.replace(" ", "_") + "#" + count + ".mp3" file_path = dir_path + "/" + file_name if not file_name in os.listdir(dir_path): print(prog["update"], prog["title"], prog["personality"]) returnData.append(title) res3 = requests.get(movie_url) fs = open(file_path, "wb") fs.write(res3.content) fs.close() dbx_path = "/radio/" + title res = self.dbx.files_list_folder('/radio') db_list = [d.name for d in res.entries] if not title in db_list: self.dbx.files_create_folder(dbx_path) dbx_path += "/" + title + "#" + count + ".mp3" self.dbx.files_upload(res3.content, dbx_path) return returnData
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")