Spaces:
Sleeping
Sleeping
File size: 2,482 Bytes
40c4f6f 61e87e6 edee679 16c32c6 14af27b e9950b1 885c383 931fdf3 74164ff 931fdf3 885c383 5836ff0 885c383 931fdf3 5d9535c 931fdf3 58cae0c 6e5ec17 40c4f6f 1d05f9c 14af27b 40c4f6f 1d05f9c 40c4f6f 6723e97 1d05f9c 40c4f6f b9df598 7ff616c 6d5cbcf 40c4f6f 7ff616c 14af27b 40c4f6f 14af27b 2138b6a 6d5cbcf f381854 5fa984e 9ede144 b9757a6 5fa984e 77bdeeb 5fa984e c535987 e976dab f18f04b c9f3409 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
from flask import Flask, request, render_template_string, send_from_directory, jsonify
from flask import render_template
import sqlite3
import os
import uuid
import yt_dlp
import json
import base64
import unittest
import requests
own_url = os.getenv('own_url')
key_d = os.getenv('gc_api')
gc_url = os.getenv('gc_url')
import json
from datetime import datetime
import whatsapp_api_webhook_server_python.webhooksHandler as handler
app = Flask(__name__, template_folder="./")
app.config['DEBUG'] = True
UPLOAD_FOLDER = 'static'
# Создание директории, если она не существует
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
@app.route('/upload', methods=['POST'])
def upload_file():
if 'file' not in request.files:
return "No file part", 400
file = request.files['file']
if file.filename == '':
return "No selected file", 400
# Генерация уникального имени файла
unique_filename = str(uuid.uuid4()) + os.path.splitext(file.filename)[1]
save_path = os.path.join(UPLOAD_FOLDER, unique_filename)
file.save(save_path)
# Возвращаем полный URL загруженного файла с протоколом https
full_url = request.url_root.replace('http://', 'https://') + 'uploads/' + unique_filename
return f"File uploaded successfully and saved to {full_url}", 200
@app.route('/uploads/<filename>', methods=['GET'])
def uploaded_file(filename):
return send_from_directory(UPLOAD_FOLDER, filename)
@app.route('/up_fa', methods=['GET'])
def up_fa():
return render_template('up_fa.html')
def get_video_url(video_url):
ydl_opts = {
'format': 'best', # Выбирает лучшее качество
'quiet': True, # Не выводить информацию в консоль
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info_dict = ydl.extract_info(video_url, download=False)
video_url = info_dict.get('url', None)
return video_url
@app.route('/tutub')
def index_tutub():
return render_template('tutub.html')
@app.route('/play', methods=['POST'])
def play():
video_url = request.form['video_url']
stream_url = get_video_url(video_url)
return render_template('player.html', stream_url=stream_url)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|