revert Upload files to "templates"
main
Anorak_1 2024-01-05 18:20:54 +00:00
parent a3ac0efb13
commit 2d19f4a361
2 changed files with 0 additions and 60 deletions

View File

@ -1,31 +0,0 @@
import requests
import re
from lxml import html, etree
def search_site(search_string: str):
search = search_string
search = search.replace(" ", "%20")
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
}
search_res = requests.get(f"https://prehrajto.cz/hledej/{search}", headers=headers)
tree = html.fromstring(search_res.content)
links = tree.xpath('.//a[contains(@class, "video video--small video--link")]')
if not links:
print("EMPTYYY")
x = []
for link in links:
title = link.get("title").replace("+", " ").replace("-", " ").replace(".", " ") # title of video
href = link.get("href") # link to video
thumbnail = link.xpath('.//img[contains(concat(" ", normalize-space(@class), " "), " thumb thumb1 ")]')[0].get("src") # link to thumbnail
x.append({'title': title,
'href': href,
'thumbnail': thumbnail})
return x
def get_video_url(href: str):
video_site = requests.get(f"https://prehrajto.cz/{href}")
x = re.search('(https:.{0,6}?storage.+?)\"', video_site.content.decode("utf-8")).groups()
return x[0]

View File

@ -1,29 +0,0 @@
from flask import Flask, render_template, request, redirect, url_for
from search import search_site, get_video_url
app = Flask(__name__)
app.config['SECRET_KEY'] = 'hjshjhdjah kjshkjdhjs'
@app.route('/')
def index():
return render_template('index.html', results=None)
@app.route('/search', methods=['GET', 'POST'])
def search():
if request.method == 'POST':
search_query = request.form['search_query']
print("Search Query:", search_query)
elif request.method == 'GET' and 'search_query' in request.args:
search_query = request.args['search_query']
results = search_site(search_query)
return render_template('index.html', results=results, query = search_query)
else:
return redirect(url_for('index'))
@app.route('/video/<path:href>')
def video(href):
return redirect(get_video_url(href))
if __name__ == "__main__":
app.run(host="0.0.0.0")