39 lines
973 B
Python
39 lines
973 B
Python
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/<video_id>")
|
|
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"""
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
{og_tags_str}
|
|
</head>
|
|
<body>
|
|
</body>
|
|
</html>
|
|
"""
|
|
|
|
return Response(html_response, mimetype="text/html")
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host="0.0.0.0", port=5000, debug=True)
|