first!
This commit is contained in:
commit
34972c7262
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
venv
|
||||
.venv
|
||||
__pycache__
|
38
app.py
Normal file
38
app.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
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)
|
Loading…
Reference in New Issue
Block a user