「Flask+ツイキャスAPI、VRChatでライブ配信を見る」の記事で使うプログラムになります。 https://qiita.com/meihei/items/8dda62f510b8f8c9a15b
Last active
December 19, 2018 17:22
-
-
Save meihei3/a0942934846faeda7b0d4ab6b77307c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
from flask import Flask, redirect | |
from config import BASE64_ENCODED_STRING | |
app = Flask(__name__) | |
BASE_URL = "https://apiv2.twitcasting.tv" | |
SEARCH_URL = BASE_URL + "/search/lives" | |
HEADER = {"X-Api-Version": "2.0", "Authorization": "Basic %s" % BASE64_ENCODED_STRING.decode("utf-8")} | |
def get_hls_url(sub_categorie): | |
# TwitCastingのSearch APIを叩く | |
res = requests.get(SEARCH_URL+"?limit=25&type=category&context=%s&lang=ja" % sub_categorie, headers=HEADER) | |
if res.status_code != 200: | |
return res.content | |
# 結果からmovieオブジェクトのlistを取り出す | |
movies = json.loads(res.text)['movies'] | |
# 最もトータルの視聴者数の多い配信を選択 | |
best_movie = sorted(movies, reverse=True, key=lambda m: m['movie']['total_view_count'])[0] | |
return best_movie['movie']['hls_url'] | |
@app.route('/') | |
def index(): | |
return "Hello World" | |
@app.route('/api') | |
def tc2vrc_api(): | |
# カテゴリー -> 音楽:弾き語り(女性Vo) | |
url = get_hls_url(sub_categorie="music_recite_girls_jp") | |
return redirect(url) | |
if __name__ == '__main__': | |
app.run(debug=True, host='0.0.0.0') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
ClientID = "your client ID" | |
ClientSecret = "your client secret" | |
BASE64_ENCODED_STRING = base64.b64encode(("%s:%s" % (ClientID, ClientSecret)).encode("utf-8")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment