Beispiel #1
0
    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
Beispiel #2
0
    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