build on raspberrypi
This commit is contained in:
parent
6061aff2ef
commit
7f2ac18d04
@ -1,3 +1,4 @@
|
|||||||
|
from fastapi.responses import JSONResponse
|
||||||
import os, yt_dlp, json, requests
|
import os, yt_dlp, json, requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
@ -11,6 +12,23 @@ class grab():
|
|||||||
seasons = [item.replace(url+'/season:', '') for item in option_values]
|
seasons = [item.replace(url+'/season:', '') for item in option_values]
|
||||||
return seasons
|
return seasons
|
||||||
|
|
||||||
|
def thumbnail(ydl,url,location):
|
||||||
|
# Extracting video information
|
||||||
|
video_info = ydl.extract_info(url, download=False)
|
||||||
|
thumbnail_url = video_info.get('thumbnail')
|
||||||
|
|
||||||
|
# Download the thumbnail image
|
||||||
|
if thumbnail_url:
|
||||||
|
try:
|
||||||
|
thumbnail_filename = os.path.join(location, f"{video_info['id']}.jpg")
|
||||||
|
with open(thumbnail_filename, 'wb') as thumbnail_file:
|
||||||
|
thumbnail_file.write(requests.get(thumbnail_url).content)
|
||||||
|
print("Downloaded MP4 and downloaded thumbnail successfully!")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error downloading thumbnail: {str(e)}")
|
||||||
|
else:
|
||||||
|
print("Downloaded MP4 but no thumbnail found.")
|
||||||
|
|
||||||
class dropout():
|
class dropout():
|
||||||
def show(show,season,episode):
|
def show(show,season,episode):
|
||||||
directory='/tv/'+show+'/Season '+season+'/'
|
directory='/tv/'+show+'/Season '+season+'/'
|
||||||
@ -38,7 +56,7 @@ class dropout():
|
|||||||
'temp': '/temp',
|
'temp': '/temp',
|
||||||
'home': directory
|
'home': directory
|
||||||
},
|
},
|
||||||
'cookiefile': 'cookies.txt',
|
'cookiefile': '/data/dropout_cookies.txt',
|
||||||
'reject_title': [
|
'reject_title': [
|
||||||
r'(?i).*behind.?the.?scenes.*', # Reject titles with "behind the scenes" (case-insensitive)
|
r'(?i).*behind.?the.?scenes.*', # Reject titles with "behind the scenes" (case-insensitive)
|
||||||
r'(?i).*trailer.*', # Reject titles with "trailer" (case-insensitive)
|
r'(?i).*trailer.*', # Reject titles with "trailer" (case-insensitive)
|
||||||
@ -51,8 +69,12 @@ class dropout():
|
|||||||
'writesubtitles': True, # Download subtitles
|
'writesubtitles': True, # Download subtitles
|
||||||
'subtitleslangs': ['en'] # Specify the language for subtitles (e.g., 'en' for English)
|
'subtitleslangs': ['en'] # Specify the language for subtitles (e.g., 'en' for English)
|
||||||
}
|
}
|
||||||
|
try:
|
||||||
with yt_dlp.YoutubeDL(dl_ops) as ydl:
|
with yt_dlp.YoutubeDL(dl_ops) as ydl:
|
||||||
ydl.download([url])
|
ydl.download([url])
|
||||||
|
return JSONResponse(status_code=200, content={"status": "success", "message": "Download completed."})
|
||||||
|
except Exception as e:
|
||||||
|
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
||||||
|
|
||||||
def series():
|
def series():
|
||||||
json_data=[]
|
json_data=[]
|
||||||
@ -78,6 +100,7 @@ class dropout():
|
|||||||
with open('/data/dropout.json', 'w') as json_file:
|
with open('/data/dropout.json', 'w') as json_file:
|
||||||
json.dump(sorted_json_data, json_file, indent=4)
|
json.dump(sorted_json_data, json_file, indent=4)
|
||||||
|
|
||||||
|
class youtube():
|
||||||
def ydl(url, location):
|
def ydl(url, location):
|
||||||
dl_ops = {'paths': {'temp': '/temp', 'home': location}, 'outtmpl': '%(uploader)s/%(title)s.%(ext)s'}
|
dl_ops = {'paths': {'temp': '/temp', 'home': location}, 'outtmpl': '%(uploader)s/%(title)s.%(ext)s'}
|
||||||
if location == "/podcasts":
|
if location == "/podcasts":
|
||||||
@ -100,31 +123,18 @@ def ydl(url, location):
|
|||||||
'key': 'FFmpegMetadata',
|
'key': 'FFmpegMetadata',
|
||||||
'add_metadata': True,
|
'add_metadata': True,
|
||||||
}]
|
}]
|
||||||
elif location == "/mnt/nsfw":
|
elif location == "/nsfw":
|
||||||
dl_ops['format'] = 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best'
|
dl_ops['format'] = 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
dl_ops = {
|
dl_ops = {
|
||||||
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best',
|
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best',
|
||||||
'cookiefile': 'yt-cookies.txt'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
with yt_dlp.YoutubeDL(dl_ops) as ydl:
|
|
||||||
ydl.download(url)
|
|
||||||
|
|
||||||
# Extracting video information
|
|
||||||
video_info = ydl.extract_info(url, download=False)
|
|
||||||
thumbnail_url = video_info.get('thumbnail')
|
|
||||||
|
|
||||||
# Download the thumbnail image
|
|
||||||
if thumbnail_url:
|
|
||||||
try:
|
try:
|
||||||
thumbnail_filename = os.path.join(location, f"{video_info['id']}.jpg")
|
with yt_dlp.YoutubeDL(dl_ops) as ydl:
|
||||||
with open(thumbnail_filename, 'wb') as thumbnail_file:
|
ydl.download([url])
|
||||||
thumbnail_file.write(requests.get(thumbnail_url).content)
|
# grab.thumbnail(ydl,url,location)
|
||||||
print("Downloaded MP4 and downloaded thumbnail successfully!")
|
return JSONResponse(status_code=200, content={"status": "success", "message": "Download completed."})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error downloading thumbnail: {str(e)}")
|
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
||||||
else:
|
|
||||||
print("Downloaded MP4 but no thumbnail found.")
|
|
||||||
@ -9,10 +9,10 @@ import json
|
|||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
# # Mount static files if needed (e.g. CSS, JS, images)
|
# # Mount static files if needed (e.g. CSS, JS, images)
|
||||||
app.mount("/static", StaticFiles(directory="app/static"), name="static")
|
app.mount("/static", StaticFiles(directory="/static"), name="static")
|
||||||
|
|
||||||
# # Jinja2 template directory
|
# # Jinja2 template directory
|
||||||
templates = Jinja2Templates(directory="app/templates")
|
templates = Jinja2Templates(directory="/templates")
|
||||||
|
|
||||||
|
|
||||||
# api
|
# api
|
||||||
@ -33,6 +33,10 @@ async def dropoutSeries():
|
|||||||
async def dropoutDownload(show: str, season: str, episode: str):
|
async def dropoutDownload(show: str, season: str, episode: str):
|
||||||
download.dropout.show(show,season,episode)
|
download.dropout.show(show,season,episode)
|
||||||
|
|
||||||
|
@app.get("/ydl")
|
||||||
|
async def ydl(url: str, location: str):
|
||||||
|
download.youtube.ydl(url,location)
|
||||||
|
|
||||||
# html
|
# html
|
||||||
@app.get("/", response_class=HTMLResponse)
|
@app.get("/", response_class=HTMLResponse)
|
||||||
async def read_root(request: Request):
|
async def read_root(request: Request):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user