問題描述
有沒有辦法從YouTube搜索然後下載,我隻需要下載音頻,而不是視頻。
最佳回答
首先,安裝 youtube-dl
:
sudo apt-get install youtube-dl
然後下載並轉換 YouTube 視頻
youtube-dl http://www.youtube.com/watch?v=dQw4w9WgXcQ -x
-x
將其轉換為音頻。
更多音頻選項:
\\n
-x, --extract-audio convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)\\n--audio-format FORMAT "best", "aac", "vorbis", "mp3", "m4a", "opus", or "wav"; best by default\\n--audio-quality QUALITY ffmpeg/avconv audio quality specification, insert a value between 0 (better) and 9 (worse) for VBR or a specific bitrate like 128K (default 5)\\n
\\n
主頁:
次佳回答
您可以使用 youtube-dl 搜索和下載。您需要做的就是在鏈接中提供搜索詞,如下所示:
youtube-dl -f bestaudio 'https://www.youtube.com/results?search_sort=video_view_count&filters=video&search_query="SEARCH TERM(S) HERE"'
由於這會在標題或描述(或評論?)中顯示所有帶有搜索詞的視頻,您可以進一步限製下載僅在標題中帶有搜索詞(或任何其他詞)的視頻,然後使用 --match-title
像這樣:
youtube-dl -f bestaudio --match-title "<regex or caseless sub-string>" 'https://www.youtube.com/results?search_sort=video_view_count&filters=video&search_query="SEARCH TERM(S) HERE"'
您也可以像使用 --match-title
一樣使用 --reject-title
拒絕視頻,或者結合使用兩者。
順便說一下,我剛剛嘗試了這些搜索,youtube 的搜索工具中出現了錯誤。如果刪除字符串的 “search_sort=video_view_count” 部分,它會給出更多結果,其中一些沒有任何術語,盡管視頻是相關的,所以要小心。
更新\n以上答案並不完整。 Youtube-dl 具有用於 Google、Youtube 和 Yahoo 的 內置 搜索工具。對於這三個,您可以分別使用命令 'gvsearchX:TERMS'
、 'ytsearchX:TERMS'
和 'yvsearchX:TERMS'
,並將 ‘X’ 替換為您想要的結果數(顯然,將 ‘TERMS’ 替換為您的搜索詞)。
第三種回答
此處描述了 youtube-dl
的替代方法:New Command Line YouTube Player And Downloader With Local Playlists Support: mps-youtube。這篇文章非常詳細,但隻是引用與您的問題相關的內容:
\\n
mps-youtube is a new tool which, besides being able to download YouTube videos (either the whole video or just the audio), can also search and play YouTube videos and create local playlists, all from the command line.
\\n By default, this is basically a YouTube audio player (and downloader), but you can enable (external) video playback from its options.\\n
該程序需要 python-pip
和 mplayer
(兩者均可由 apt-get
安裝)。然後,運行 sudo pip install mps-youtube
就大功告成了。
您可以閱讀有關 mps-youtube here 的更多信息。
筆記
-
如果您願意,該程序隻下載音頻,從而節省帶寬:您隻下載音頻,而不是下載視頻然後在最後提取音頻。
-
如果您不想安裝
sudo apt-get install python-pip
建議的所有建議,請使用sudo apt-get install --no-install-recommends python-pip
。這同樣有效(用於安裝mps-youtube
的特定目的)。
第四種回答
這是可能的。安裝後 youtube-dl ( sudo apt-get install youtube-dl
) 簡單
youtube-dl --format bestaudio <link>
它將保存一個帶有視頻標題的 .m4a 文件。
色諾斯