python - os.path.expanduser("~") 不在heroku上工作
问题描述
我在 django 中遇到 youtube_dl 路径配置问题。基于以下配置,它在开发模式下可以正常工作,但是当托管在 heroku 上时,无法在任何地方跟踪下载的资源。
# Download view
def download(request):
details = []
if request.method == 'POST':
v_url = CreateURL(request.POST)
if v_url.is_valid():
video_url = v_url.cleaned_data['url']
#path configured
homedir = os.path.expanduser("~/Downloads/%(title)s.%(ext)s")
try:
ydl = youtube_dl.YoutubeDL( {
'-f best': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best',
'-o': f'{homedir}',
# 'progress_hooks': [my_hook],
})
with ydl:
result = ydl.extract_info(
video_url,
download=True # We just want to extract the info
)
if 'entries' in result:
# Can be a playlist or a list of videos
video = result['entries'][0]
else:
` # Just a video`
video = result
video_data= {
'resolution':video['thumbnails'][3]['resolution'],
'title':video['title'],
'ext':video['ext'],
}
details.append(video_data)
except:
messages.warning(request,"Error in downloading the video, please check your network connection and try again!")
else:
messages.success(request, 'Downloaded successfully, check your download folder for details!')
context={
'details':details
}
return render(request, 'download.html', context )
任何帮助将不胜感激。谢谢
解决方案
推荐阅读
- r - R:如何在R中的第一个点之前提取字符串
- database - 如何从旧安装访问 MongoDB 数据?
- android - Android - 如何为 TextView 中的不同字符添加不同的间距?
- java - 如何返回未使用的空间数组?
- email - 如何代表来自不同域的其他人发送电子邮件
- angularjs - 使用angularjs提交表单时如何动态获取表格格式的数据
- mysql - Mysql 时差不起作用 MySQL 客户端版本:3.23.49
- c# - 如何从 TextBox 中获取 txt 并将其转换为数学函数?
- css - 如何设置此 div 以显示内联?
- javascript - jQuery - jquery-3.4.1.min.js:2 Uncaught ReferenceError: filter is not defined