gpt4 book ai didi

bash - Youtube-dl下载脚本调试

转载 作者:行者123 更新时间:2023-12-03 06:06:19 29 4
gpt4 key购买 nike

弃用更新此帖子的想法很糟糕。此脚本的新位置:
https://gist.github.com/Wogol/66e9936b6d49cc5fecca59eaeca1ca2e

我试图创建一个使用简单的Youtube-dl的.command macOS脚本(也应该在GNU / Linux下工作)。我已经修复,所以它可以下载描述,缩略图,字幕,json,创建文件夹结构,还可以保存视频ID,上传者和上传日期。

主要脚本的问题:

  • 固定(8月13日)我遇到的问题是音频和视频或仅音频的选项。由于某些原因,脚本中只能使用音频。视频和音频的下载脚本不起作用,但是如果我在终端窗口中粘贴相​​同的命令行(“DEBUG输出行”),它将起作用。挠我的头。
    Youtube-dl给了我这个信息:
    错误:请求的格式不可用
  • 固定(8月31日)获取视频工作的最大分辨率。找到了强制mp4或最大分辨率的信息,但未将它们组合在一起。

  • 带有信息文件的 问题:
    还创建一个带有标题, channel 名称,发行日期,描述的信息文件。我现在正努力从.json和youtube-dl获取视频信息以导出到info.txt文件中。
  • 修复(9月5日) textfile =“” $ folder“info.txt”不起作用。出现此错误:(我要在其中添加youtube-dl文件夹。
  •     ytdl.command: line 104: ~/Downloads/ytdl/dog_vids/info.txt: No such file or directory
  • 修复(9月5日)找到youtube-dl文件夹并使其与grep一起使用。
    像这样:
  •    youtube-dl --simulate --SHOW_THE_OUTPUT_PATH -o $folder'/%(title)s/%(title)s - (%(id)s) - %(uploader)s - %(upload_date)s.%(ext)s' https://www.youtube.com/watch?v=dQw4w9WgXcQ
  • (固定)(9月5日)我用grep命令将json文件命名为“* .json”,因为每个目录只有一个,但是我不喜欢这种解决方案。 (可以通过以上几点回答)
  • 固定(9月5日)如何使grep不要抓取“?”现在将它们添加在所有内容的前后。
  • 固定(9月5日)如何从json文件中获取标签信息?标签看起来像这样:
  •     "tags": ["music", "video", "classic"]
  • 已修复(9月5日)在下载视频的后台运行脚本的信息文件部分的创建吗?

  • 正在尝试使用最新版本
    (8月12日)
        textfile=""$folder"info.txt"

    echo TITLE >> ~/Downloads/ytdl/dog_vids/info.txt
    youtube-dl -e $url >> ~/Downloads/ytdl/dog_vids/info.txt
    echo \ >> ~/Downloads/ytdl/dog_vids/info.txt

    echo CHANNEL >> $textfile
    echo \ >> $textfile

    echo CHANNEL URL >> $textfile
    echo \ >> $textfile

    echo UPLOAD DATE >> $textfile
    echo \ >> $textfile

    echo URL >> $textfile
    echo $url >> $textfile
    echo \ >> $textfile

    echo TAGS >> $textfile
    echo \ >> $textfile

    echo DESCRIPTION >> $textfile
    youtube-dl --get-description $url >> $textfile

    实验 future 版本-从JSON文件中提取信息
    这不是工作脚本。通过$ textfile,$ ytdlfolder和$ jsonfile显示我想要的方式。
        url=https://www.youtube.com/watch?v=dQw4w9WgXcQ

    textfile=""$folder""$YOUTUBE-DL_PATH"info.txt"
    ytdlfolder="$folder""$YOUTUBE-DL_PATH"
    jsonfile="$folder""$YOUTUBE-DL_JSON-FILE"

    Echo TITLE >> $textfile
    grep -o '"title": *"[^"]*"' $jsonfile | grep -o '"[^"]*"$' >> $textfile
    Echo \ >> $textfile

    Echo CHANNEL >> $textfile
    grep -o '"uploader": *"[^"]*"' $jsonfile | grep -o '"[^"]*"$' >> $textfile
    Echo \ >> $textfile

    Echo CHANNEL URL >> $textfile
    grep -o '"uploader_url": *"[^"]*"' *.json | grep -o '"[^"]*"$' >> $textfile
    Echo \ >> $textfile

    Echo UPLOAD DATE >> $textfile
    grep -o '"upload_date": *"[^"]*"' *.json | grep -o '"[^"]*"$' >> $textfile
    Echo \ >> $textfile

    Echo TAGS >> $textfile
    grep -o '"tags": *"[^"]*"' *.json | grep -o '"[^"]*"$' >> $textfile
    Echo \ >> $textfile

    echo URL >> $textfile
    echo $url >> $textfile
    echo \ >> $textfile

    Echo DESCRIPTION >> $textfile
    youtube-dl --get-description $url >> $textfile

    脚本:
    8月12日。
  • 将网址移到顶部,因此当用户粘贴网址时,他们会获得视频标题。这样用户就知道他们得到了正确的视频。
  • 添加了最大分辨率1920x1080。 (不工作)

  • 8月13日。
  • 下载音频和视频作品。

  • 8月31日
  • 固定力mp4,最大高度为1080。

  • 9月5日。
  • 最后可以运行的脚本。在此处了解更多信息(或向下滚动):
    Youtube-dl download script debug

  • 2020-09-17
  • 文件夹现在可以在其中包含空格。

  • 2020-09-22
  • 选择菜单现在是一列。
  • 次要修复。
  • 现在,所有错误已修复。剩下的问题只是优化。
  •     #! /bin/bash
    ################################################################################
    # Script Name: Youtube-dl Easy Download Script
    # Description: Easy to use script to download YouTube videos with a couple of
    # options.
    #
    # What this script do:
    # - Downloads video in MP4 with highest quality and max resolution 1920x1080.
    # - Downloads thumbnail and subtitles.
    # - Gives user option where to download the video and video or only audio.
    # - Creates a folder with same name as video title and puts all files there.
    # - Creates a .txt file with information about the video.
    #
    #
    # Author: Wogol - Stackoverflow.com, Github.com
    # License: The GNU General Public License v3.0 - GNU GPL-3
    #
    #
    # Big thanks to the people at youtube-dl GitHub and Stack Overflow. Without
    # their help this would never ever been possible for me.
    #
    # Special thanks to:
    # Reino @ Stack Overflow
    #
    # #####
    #
    # Software required: youtube-dl, xidel, printf
    #
    # macOS: 1. Install Homebrew: https://brew.sh
    # 2. Terminal command: brew install youtube-dl xidel
    #
    # Linux: Depends on package manager your distribution use.
    #
    # #####
    #
    # Version history:
    # 2020-09-22
    # - Select menus is now one column.
    # - Minor fixes.
    # - Now all the bugs is fixed. Issues left is only optimizations.
    #
    # 2020-09-17
    # - Folders can now have spaces in them.
    #
    # 2020-09-05
    # - First working version.
    #
    # #####
    #
    # Issues left:
    # - In the beginning there is a confirmation that show the title of the
    # video so user know they got the correct video. It takes youtube-dl a
    # couple of seconds. To speed up the script it is DISABLED by default.
    #
    # - Have found out that the script dont need xidel to get json information
    # but youtube-dl can get it. Dont know how to use youtube-dl --dump-json
    # to get the same result.
    #
    # - To get the path to the .txt file script use youtube-dl. This gives the
    # script a pause for a few seconds. Best would get to get the path some how
    # without connecting to YouTube again but use the output from youtube-dl
    # some how. ... or run it in the background when video is downloading.
    #
    ################################################################################



    clear



    # - WELCOME MESSAGE -

    echo

    COLUMNS=$(tput cols)
    title="-= Youtube-dl Easy Download Script =-"
    printf "%*s\n" $(((${#title}+$COLUMNS)/2)) "$title"



    # - PASTE URL -

    echo -e "\n*** - Paste URL address and hit RETURN. Example:\nhttps://www.youtube.com/watch?v=dQw4w9WgXcQ --OR-- https://youtu.be/dQw4w9WgXcQ\n"

    read url



    # - VIDEO TITLE -

    # So users know they have the correct URL.

    #echo -e "\nThe video is: (This takes 3-4 seconds, or more ...)"
    #youtube-dl -e $url
    #echo



    # - DOWNLOAD LOCATION -


    # DIRECTORY MUST END WITH SLASH: /


    echo -e "\n\n*** - Choose download folder:\n"

    COLUMNS=0
    PS3='Choose: '
    select directory in "~/Downloads/ytdl/Rick Astley/" "~/Downloads/ytdl/Never Gonna Give You Up/" "~/Downloads/ytdl/Other Rick Videos/" ; do
    echo -e "\nOption $REPLY selected. Download directory is:\n $directory"



    # - AUDIO/VIDEO SETTINGS -

    echo -e "\n\n*** - Choose download settings:\n"

    COLUMNS=0
    PS3='Choose: '
    options=("Audio & Video" "Audio only")
    select settingsopt in "${options[@]}"
    do
    case $settingsopt in

    "Audio & Video")
    av="-f bestvideo[ext=mp4][height<=1080]+bestaudio[ext=m4a]/best[ext=mp4]/best --merge-output-format mp4"

    ;;

    "Audio only")
    av="-f bestaudio[ext=m4a]/bestaudio"

    ;;

    esac

    echo -e "\nOption $REPLY selected:\n $settingsopt"



    # - THE DOWNLOAD SCRIPT -

    echo -e "\n\n*** - Starting download:\n"
    youtube-dl $av --write-thumbnail --all-subs --restrict-filenames -o "$directory%(title)s/%(title)s.%(ext)s" $url



    # - INFORMATION FILE -

    textfile=$(youtube-dl --get-filename --restrict-filenames -o "$directory%(title)s/%(title)s.txt" $url)

    xidel -s "$url" -e '
    let $json:=json(
    //script/extract(.,"ytplayer.config = (.+?\});",1)[.]
    )/args,
    $a:=json($json/player_response)/videoDetails,
    $b:=json($json/player_response)/microformat
    return (
    "- TITLE -",
    $a/title,"",
    "- CHANNEL -",
    $a/author,"",
    "- CHANNEL URL -",
    $b//ownerProfileUrl,"",
    "- UPLOAD DATE -",
    $b//publishDate,"",
    "- URL -",
    $json/loaderUrl,"",
    "- TAGS -",
    $a/keywords,"",
    "- DESCRIPTION -",
    $a/shortDescription
    )
    ' --printed-json-format=compact >> "$textfile"



    # - THE END -

    echo
    COLUMNS=$(tput cols)
    ending="Download Complete!"
    printf "%*s\n\n" $(((${#ending}+$COLUMNS)/2)) "$ending"

    exit

    done
    done

    最佳答案

    我已修复,现在可以下载音频和视频。问题出在AV行中。删除了它们,现在工作正常。还针对youtube-dl从手册中更新了影音线。
    无法运作:

        av="-f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4"
    加工:
        av="-f bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best --merge-output-format mp4"

    关于bash - Youtube-dl下载脚本调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63336809/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com