ios - Youtube dl 不是用 python 2 执行的
问题描述
我想执行 youtube dl 来下载视频。
这是我的代码:
struct YoutubeVideoInfo: Codable {
let fulltitle: String
let url: String
let thumbnail: String
let uploader: String
static func getVideoInfo(from url: String) -> YoutubeVideoInfo? {
guard let path = Bundle.main.path(forResource: "youtube-dl", ofType: ""),
let json = executeCommand(command: path, args: ["-f mp4/best", "--dump-json", url]),
let data = json.data(using: .utf8),
let info = try? JSONDecoder().decode(YoutubeVideoInfo.self, from: data) else {
return nil
}
return info
}
}
func executeCommand(command: String, args: [String]) -> String? {
let task = Process()
task.launchPath = command
task.arguments = args
let pipe = Pipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
guard let output = String(data: data, encoding: .utf8) else {
return nil
}
return output
}
但它显示错误:
回溯(最后一次调用):文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py”,第 174 行,在 _run_module_as_main “ main ”,fname,loader,pkg_name )文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py”,第72行,在run_globals文件中的_run_code执行代码“/Users/khuongpham/Library/Developer/Xcode /DerivedData/VideoDownloader-agkzwgefyogltjaxgreulgpacwbv/Build/Products/Debug/VideoDownloader.app/Contents/Resources/youtube-dl/ main .py”,第 16 行,在文件“/Users/khuongpham/Library/Developer/Xcode/DerivedData/VideoDownloader -agkzwgefyogltjaxgreulgpacwbv/Build/Products/Debug/VideoDownloader.app/Contents/Resources/youtube-dl/youtube_dl/ init.py”,第 15 行,在文件“/Users/khuongpham/Library/Developer/Xcode/DerivedData/VideoDownloader-agkzwgefyogltjaxgreulgpacwbv/Build/Products/Debug/VideoDownloader.app/Contents/Resources/youtube-dl/youtube_dl/options.py ”,第 8行,在文件“/Users/khuongpham/Library/Developer/Xcode/DerivedData/VideoDownloader-agkzwgefyogltjaxgreulgpacwbv/Build/Products/Debug/VideoDownloader.app/Contents/Resources/youtube-dl/youtube_dl/downloader/init.py”,第 3 行,在文件“/Users/khuongpham/Library/Developer/Xcode/DerivedData/VideoDownloader-agkzwgefyogltjaxgreulgpacwbv/Build/Products/Debug/VideoDownloader.app/Contents/Resources/youtube-dl/youtube_dl/downloader/common .py”,第 9 行,在文件“/Users/khuongpham/Library/Developer/Xcode/DerivedData/VideoDownloader-agkzwgefyogltjaxgreulgpacwbv/Build/Products/Debug/VideoDownloader.app/Contents/Resources/youtube-dl/youtube_dl/compat.py ",第 2359 行,在文件 "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/http/server.py",第 7 行,从 CGIHTTPServer 导入 * 文件 "/System/Library /Frameworks/Python.framework/Versions/2.7/lib/python2.7/CGIHTTPServer.py”,第 30 行,在导入 SimpleHTTPServer 文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SimpleHTTPServer.py”,第 28 行,在 SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler) 类中:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SimpleHTTPServer.py", line 219, in SimpleHTTPRequestHandler mimetypes.init() # try read system mime.types File "/System /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetypes.py”,第 358 行,在 init db.read(file) 文件中“/System/Library/Frameworks/Python.framework/Versions/ 2.7/lib/python2.7/mimetypes.py",第 202 行,使用 open(filename) 作为 fp 读取:IOError: [Errno 1] Operation not allowed: '/etc/apache2/mime.types'
解决方案
推荐阅读
- r - 带有 grid_arrange_shared_legend 的列表中的多面板 ggplot
- jquery - 如何忽略过滤器中的 null 或所有空格?
- vue.js - Vue.js add component option (prop) using custom directive
- django - /product/create/ 'icon' 处的 MultiValueDictKeyError
- c - 检索数组的元素
- python-3.x - 无法将大小为 64 的数组重塑为形状 (28,28)
- javascript - Mongoose ODM 在 MongoDB 集合中保存了错误的模型名称
- javascript - 如何从列表项中添加和删除类?
- java - 获取“空对象引用”
- python - 将大小为 (n,n,m) 的数组转换为 (None,n,n,m)