如何從 Linux 命令列訂閱 YouTube feed?

如何從 Linux 命令列訂閱 YouTube feed?

我想訂閱 YouTube 頻道並自動將新影片下載到我的 Linux 機器上。

我知道我可以使用 miro 來做到這一點,但我不會使用 Miro 觀看視頻,想要選擇質量並希望將其作為 cronjob 運行。

它應該能夠:

  • 知道哪些提要條目是新的並且不下載舊條目
  • 從舊會話恢復(或至少重新下載)失敗/不完整的下載

有沒有完整的解決方案?

如果沒有的話,對我來說就足夠了(也許更好),只要有一個命令行 rss 閱讀器,它會記住哪些條目已經存在並寫入新的視頻網址(例如http://www.youtube.com/watch?v=FodYFMaI4vQ&feature=youtube_gdatahttp://gdata.youtube.com/feeds/api/users/tedxtalks/uploads)到一個文件中。然後我可以使用bash腳本和youtube-dl.

有哪些程式可用於此目的?

答案1

我最終使用這個腳本做到了bash

#!/bin/bash

conffile="$@"

if [ ! -f "$@" ] || [ 3 -ne $(wc -l "$@" | grep -o '^[0-9]*') ]; then
        echo "This script writes a list of new video ids into an output file."
        echo "Argument must be a file containing three lines:"
        echo "      line 1: Feed url"
        echo "      line 2: Output file "
        echo "      line 3: Newest id from last program call. Leave empty for first run."

        exit 1
fi

mapfile -t < "$conffile"
url="${MAPFILE[0]}"
outfile="${MAPFILE[1]}"
lastid="${MAPFILE[2]}"

echo "Processing $id:"

allids=$(wget -q -O- "$url" | sed 's,href,\nhref,g' | sed -n -e "s,^.*href='http://www.youtube.com/watch?v=\([A-Za-z0-9_-]*\).*$,\1,p")

for id in $allids; do
    if [ "$lastid" == "$id" ]; then echo "No new items left." >&2; break; fi
    echo "$id"
    echo "Adding $id" >&2
done | tac >> "$outfile"

newlastid=$(echo $allids | grep -o "^[A-Za-z0-9_-]*")

echo  "$url"       > "$conffile"
echo  "$outfile"   >> "$conffile"
echo  "$newlastid" >> "$conffile"

它從設定檔中讀取 feed url、輸出檔和最新的已知視頻,然後從 feed 中提取視頻 ID。然後將這些 id 與最新的已知 id 進行比較(最新的 feed 項目在前)。比這更新的項目將被添加到輸出文件中(現在首先是最舊的項目)。

這是一個設定檔範例youtube_tedx.conf

http://gdata.youtube.com/feeds/api/users/tedxtalks/uploads
~/Documents/Movies/tedx/list.all
VxKMeE-gTQY

可以透過調用來使用它./get_new_youtube.sh youtube_tedx.conf

然後可以使用諸如 之類的命令list.all來處理輸出檔 ( ) 。youtube-dlyoutube-dl -tca list.all && rm list.all

相關內容