from flask import Flask, request, render_template_string
import re
app = Flask(__name__)
# Ana sayfa (YouTube URL formunu alır)
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "POST":
youtube_url = request.form.get("youtube_url")
# Geçerli bir YouTube URL'si olup olmadığını kontrol et
youtube_pattern = r"(https?:\/\/)?(www\.)?(youtube|youtu|youtube-nocookie)\.(com|be)\/(watch\?v=|embed\/|v\/|e\/)([a-zA-Z0-9_-]{11})"
match = re.match(youtube_pattern, youtube_url)
if match:
video_id = match.group(6)
# Embed kodu oluştur
embed_code = f'<iframe width="560" height="315" src="https://www.youtube.com/embed/{video_id}&quot; frameborder="0" allowfullscreen></iframe>'
return render_template_string("""
<h2>Video Başarıyla Yüklendi!</h2>
<div>{{ embed_code | safe }}</div>
<br>
<a href="/">Başka bir video yükle</a>
""", embed_code=embed_code)
else:
error_message = "Geçersiz YouTube URL'si."
return render_template_string("""
<h2>{{ error_message }}</h2>
<form method="POST">
<label for="youtube_url">YouTube Video URL'sini Girin:</label>
<input type="text" name="youtube_url" id="youtube_url" required>
<button type="submit">Paylaş</button>
</form>
""", error_message=error_message)
return render_template_string("""
<h2>YouTube Video Gömme Uygulaması</h2>
<form method="POST">
<label for="youtube_url">YouTube Video URL'sini Girin:</label>
<input type="text" name="youtube_url" id="youtube_url" required>
<button type="submit">Paylaş</button>
</form>
""")
if __name__ == "__main__":
app.run(debug=True)
Yanıtlar