from flask import Flask, Response import requests from bs4 import BeautifulSoup app = Flask(__name__) s = requests.Session() s.headers.update({ "User-Agent": "Twitterbot/1.0" }) @app.route("/watch/") def proxy(video_id): real_url = f"https://www.nicovideo.jp/watch/{video_id}" try: r = s.get(real_url, timeout=10) except requests.RequestException as e: return Response(f"Error fetching the page: {e}", status=500) soup = BeautifulSoup(r.text, "html.parser") og_tags = soup.find_all("meta", property=lambda x: x) og_tags_str = "\n".join(str(tag) for tag in og_tags) html_response = f""" {og_tags_str} """ return Response(html_response, mimetype="text/html") if __name__ == "__main__": app.run(host="0.0.0.0", port=5000, debug=True)