当前位置: 首页 > news >正文

佛山做网站找哪家好办公电脑租赁平台

佛山做网站找哪家好,办公电脑租赁平台,网站建设 网络科技,贵阳做网站公司排名2024最新YT-DLP使用demo网页端渲染 前提摘要1.使用python的fastapi库和jinjia2库进行前端渲染2.代码实现1#xff09;目录结构2#xff09;代码style.cssindex.htmlresult.htmlmain.pyrun.py 3#xff09;运行测试命令端运行 3.项目下载地址 前提摘要 2024最新python使用yt… 2024最新YT-DLP使用demo网页端渲染 前提摘要1.使用python的fastapi库和jinjia2库进行前端渲染2.代码实现1目录结构2代码style.cssindex.htmlresult.htmlmain.pyrun.py 3运行测试命令端运行 3.项目下载地址 前提摘要 2024最新python使用yt-dlp 1.使用python的fastapi库和jinjia2库进行前端渲染 需要下载下面对应的python第三方库 pip install fastapi uvicorn python-multipart jinja2 yt-dlp 功能如下 使用YT-DLP缓存文件到本地预览文件信息2.代码实现 1目录结构 2代码 style.css body {font-family: Arial, sans-serif;margin: 0;padding: 20px;background-color: #f0f0f0; }.container {max-width: 800px;margin: 0 auto;background-color: white;padding: 20px;border-radius: 8px;box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); }/* 添加 logo 相关样式 */ .logo {display: flex;justify-content: center;gap: 8px;margin-bottom: 20px; }.youtube-icon, .download-icon {width: 32px; /* 调整图标大小 */height: 32px; /* 调整图标大小 */ }.header {text-align: center;margin-bottom: 30px; }h1 {font-size: 24px;margin: 10px 0; }.subtitle {color: #666;margin-bottom: 20px; }form {margin: 20px 0; }.input-group {display: flex;gap: 10px; }input[typetext] {flex: 1;padding: 10px;border: 1px solid #ddd;border-radius: 4px; }button {background-color: #007bff;color: white;padding: 10px 20px;border: none;border-radius: 4px;cursor: pointer; }button:hover {background-color: #0056b3; }.disclaimer {text-align: center;color: #666;font-size: 14px;margin: 20px 0; }.info-icon {color: #007bff;cursor: help; }.footer {text-align: center;margin-top: 30px;color: #666;font-size: 14px; }index.html !DOCTYPE html html langzh headmeta charsetUTF-8meta nameviewport contentwidthdevice-width, initial-scale1.0titleYouTube 视频下载器/titlelink relstylesheet href{{ url_for(static, pathstyle.css) }} /head bodydiv classcontainerdiv classheaderdiv classlogosvg classyoutube-icon viewBox0 0 24 24path fill#FF0000 dM23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z//svgsvg classdownload-icon viewBox0 0 24 24path fill#4285f4 dM19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z//svg/divh1YT-DLP-DEMO/h1p classsubtitleYTDownload/p/divform action/download methodPOSTdiv classinput-groupinput typetext nameurl placeholderhttps://www.youtube.com/watch?v... requiredbutton typesubmit下载/button/div/formdiv classfooterp由 FastAPI 和 yt-dlp 提供技术支持/p/div/div /body /html result.html !DOCTYPE html html headtitleDownload Result/titlelink relstylesheet href{{ url_for(static, pathstyle.css) }} /head bodydiv classcontainer{% if success %}div classresult-infodiv classvideo-headerdiv classvideo-detailsh2{{ video_info.title }}/h2div classmeta-infopstrong作者:/strong {{ video_info.author }}/ppstrong时长:/strong {{ video_info.length }}/ppstrong观看次数:/strong {{ {:,}.format(video_info.views) }}/p/div/div/divdiv classdownload-sectionsdiv classpreview-sectionh3视频预览/h3div classpreview-containervideo controlssource src{{ video_path }} typevideo/mp4您的浏览器不支持视频标签。/video/diva href{{ video_path }} classdownload-button downloadspan classicon⭳/span 下载视频/a/divdiv classpreview-sectionh3音频预览/h3div classpreview-containeraudio controlssource src{{ audio_path }} typeaudio/mp4您的浏览器不支持音频标签。/audio/diva href{{ audio_path }} classdownload-button downloadspan classicon⭳/span 下载音频/a/div/div/div{% else %}div classerror-containerh2下载失败/h2p classerror-message{{ error }}/p/div{% endif %}a href/ classback-button返回首页/a/div /body /html main.py from fastapi import FastAPI, Request, Form from fastapi.templating import Jinja2Templates from fastapi.staticfiles import StaticFiles from fastapi.responses import FileResponse import yt_dlp from pathlib import Path import osapp FastAPI()# 配置静态文件和模板 app.mount(/static, StaticFiles(directorystatic), namestatic) templates Jinja2Templates(directorytemplates)# 配置下载目录 VIDEO_DIR Path(downloads/video) AUDIO_DIR Path(downloads/audio) VIDEO_DIR.mkdir(parentsTrue, exist_okTrue) AUDIO_DIR.mkdir(parentsTrue, exist_okTrue)def download_youtube_video(url):try:# yt-dlp 基础配置common_opts {cookiefile: rwww.youtube.com_cookies.txt,quiet: False,no_warnings: False,verbose: True,proxy: http://127.0.0.1:10809,socket_timeout: 30,retries: 3,nocheckcertificate: True,prefer_insecure: True}# 视频下载选项video_opts {**common_opts,format: best[extmp4][height720]/best[height720]/best,outtmpl: str(VIDEO_DIR / %(title)s.%(ext)s),}# 音频下载选项audio_opts {**common_opts,format: bestaudio[extm4a]/bestaudio,outtmpl: str(AUDIO_DIR / %(title)s.%(ext)s),}# 获取视频信息with yt_dlp.YoutubeDL(common_opts) as ydl:info ydl.extract_info(url, downloadFalse)title info[title]duration info[duration]thumbnail info[thumbnail]author info.get(uploader, Unknown)views info.get(view_count, 0)# 下载视频with yt_dlp.YoutubeDL(video_opts) as ydl:ydl.download([url])# 下载音频with yt_dlp.YoutubeDL(audio_opts) as ydl:ydl.download([url])# 获取下载后的文件路径video_file next(VIDEO_DIR.glob(f{title}.*))audio_file next(AUDIO_DIR.glob(f{title}.*))return {status: success,title: title,author: author,duration: f{duration // 60}:{duration % 60:02d},views: views,thumbnail: thumbnail,video_path: str(video_file.name),audio_path: str(audio_file.name)}except Exception as e:return {status: error, message: str(e)}app.get(/) async def home(request: Request):return templates.TemplateResponse(index.html, {request: request})app.post(/download) async def download_video_route(request: Request, url: str Form(...)):try:result download_youtube_video(url)if result[status] success:video_info {title: result[title],author: result[author],length: result[duration],views: result[views],thumbnail: result[thumbnail]}return templates.TemplateResponse(result.html, {request: request,video_info: video_info,video_path: f/downloads/video/{result[video_path]},audio_path: f/downloads/audio/{result[audio_path]},success: True})else:raise Exception(result[message])except Exception as e:return templates.TemplateResponse(result.html, {request: request,error: str(e),success: False})# 配置下载目录的静态文件服务 app.mount(/downloads, StaticFiles(directorydownloads), namedownloads) run.py import uvicorn import osdef check_directories():确保必要的目录存在directories [static,templates,downloads,downloads/video,downloads/audio]for directory in directories:if not os.path.exists(directory):os.makedirs(directory)print(fCreated directory: {directory})if __name__ __main__:# 检查并创建必要的目录check_directories()# 配置并启动服务器uvicorn.run(main:app, host127.0.0.1, port8000, reloadTrue,reload_dirs[templates, static],log_levelinfo) 3运行测试 命令端运行 pip install fastapi uvicorn python-multipart jinja2 yt-dlp python run.py 3.项目下载地址 https://github.com/unkownc/python_demo/tree/main
http://www.w-s-a.com/news/105762/

相关文章:

  • 华强北 做网站互联网服务平台入口
  • vi设计案例网站微信导航网站 dedecms
  • 青浦区做网站设计图片手绘图片
  • 做网站的基本功制作网站公司推荐
  • 阿里云快速建站教程个人网站 费用
  • 广东购物网站建设微信公众号制作模板免费
  • 阿里国际站韩语网站怎么做让移动网站
  • 北京外包做网站如何报价中国几大网络推广公司
  • 中国建设部网站关于资质wordpress 建app
  • 程序员找工作的网站哈尔滨建设信息网站
  • 公司 网站 方案高考写作网站
  • 网站后台如何登陆网站开发需求逻辑图
  • 市级档案网站建设情况分析server2008做DNS与网站
  • 公积金门户网站建设方案网站建设代理平台怎么做
  • 网站建设知识论文抖音开放平台是干什么的
  • 网站建设期末试卷大气简洁网站
  • 电子商务网站建设报告范文单位做网站怎么做
  • 优质的外国网站qq小程序在哪里打开
  • 商务网站建设与推广实训报告免费素材网站无水印
  • 外贸站seoapp开发公司历程概述
  • 沈阳网站推广¥做下拉去118cr陶瓷企业 瓷砖地板公司网站建设
  • 医院网站官方微信精神文明建设我做服装设计师的 求推荐资源网站
  • 微信网站建设需要那些资料昆明cms模板建站
  • 安庆网站建设兼职中企动力是500强吗
  • 网站排名优化技巧基于网站的网络营销方法有哪些
  • 摄影素材网站做知识问答的网站
  • 中小企业网站建设济南兴田德润电话门店管理系统软件排行
  • 昆明工程建设信息网站柳州网站建设公司哪家好
  • 如何分析网站关键词北京门户网站网址
  • 做网站与做游戏那个好网站域名怎么起