Youtube-dl下载脚本调试 [英] Youtube-dl download script debug

查看:98
本文介绍了Youtube-dl下载脚本调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

放弃更新这篇文章的坏主意.此脚本的新位置: https://gist.github.com/Wogol/66e9936b6d49cc5fecca59eaeca1ca2e

Dumping very bad idea of updating this post. New place for this script: https://gist.github.com/Wogol/66e9936b6d49cc5fecca59eaeca1ca2e

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

Im trying to create a .command macOS script (Should also work under GNU/Linux) that use Youtube-dl that is simple to use. I have fixed so it downloads description, thumbnail, subtitles, json, creates folder structure and also saves video ID, uploader and upload date.

主要脚本的问题:

  • 已修复(8月13日)我遇到的问题是Audio&仅视频或音频.由于某些原因,脚本中只能使用音频.视频和音频的下载脚本不起作用,但是如果我在终端窗口中粘贴相​​同的命令行("DEBUG输出行"),它将起作用.挠我的头.Youtube-dl给了我这个信息:错误:请求的格式不可用

  • FIXED (13th august) Problem I struggle with is the option of Audio & Video or Audio only. For some reason only audio works in the script. The download script for the video&audio dont work but if I paste that same command line ("The DEBUG output line") in a terminal window it works. Scratching my head. Youtube-dl gives me this message: ERROR: requested format not available

已修复(8月31日)获得视频工作的最大分辨率.找到了强制mp4或最大分辨率的信息,但未将它们组合在一起.

FIXED (31th august) Get max resolution of video working. Have found information to force mp4 or max resolution but not combined them.

带有信息文件的问题:

还要创建一个带有标题,频道名称,发行日期,描述的信息文件.我现在正努力从.json和youtube-dl获取视频信息以将其导出到info.txt文件中.

Also creating a info file with title, channel name, release date, description. Im now struggling with getting video information from .json and youtube-dl to be exported into the info.txt file.

  • 已修复(9月5日) textfile =""$ folder" info.txt不工作.出现此错误:(我要在其中添加youtube-dl文件夹.
  • FIXED (5th september) textfile=""$folder"info.txt" not working. Gives this error: (There I want to add youtube-dl folder.
    ytdl.command: line 104: ~/Downloads/ytdl/dog_vids/info.txt: No such file or directory

  • 已修复(9月5日).找到youtube-dl文件夹并将其与grep配合使用.像这样:
    • FIXED (5th september) Find youtube-dl folder and get it to work with grep. Something like this:
    •    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".因为每个目录只有一个,但是我不喜欢这种解决方案.(可以用以上几点回答)

        • FIXED (5th september) With grep command i named the json file "*.json" because there will only be one per directory but I dont like that solution. (Could be answered with point above)

          已修复(9月5日)如何使grep不抓取" ;?现在,它将在所有内容之前和之后添加它们.

          FIXED (5th september) How to make so grep dont grab "? It now adds them before and after everything.

          已修复(9月5日)如何从json文件中获取标签信息?标签看起来像这样:

          FIXED (5th september) How to get the tags information from json file? Tags look like this:

              "tags": ["music", "video", "classic"]
          

          • 已修复(9月5日)在下载视频的后台运行脚本的信息文件部分的创建吗?
            • FIXED (5th september) Run the creation of info file part of the script in the background of downloading the video?
            • 正在尝试使用当前版本进行操作

              (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
              


              实验未来版本-从JSON文件中提取信息

              这不是工作脚本.通过$ textfile,$ ytdlfolder和$ jsonfile显示我想要的方式.

              This isnt a working script. Showing how I want it with $textfile, $ytdlfolder and $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日.

              2020-09-17

              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
              

              推荐答案

              最后使脚本正常工作.

              得到了很多人的很多帮助,但是非常感谢Reino在此主题中的帮助: Grep命令问题-程序输出中的Grep文本?

              Have got a lot of help from many people but big thanks to Reino with his help in this thread: Grep command questions - Grep text from program output?

              该脚本有问题,可以对其进行优化,但我不知道如何解决.这是我创建的第一个bash脚本.

              The script has issues and it can be optimized but I dont know how to fix them. This is the first bash script I have created.

              此目标是创建一个脚本,该脚本:

              The goals with this was to create a script that:

              • 简单易用.
              • 没有终端命令.
              • 在不同目录中的初始排序.
              • 视频或仅音频.
              • 最大分辨率为1920x1080的MP4,因为所有内容都支持开箱即用.
              • 带有有关视频的其他信息的文本文件.

              这些是我在Downie(macOS)和Clipgrab等程序中缺少的功能.

              These are features I miss in programs like Downie (macOS) and Clipgrab.

              为了让其他人使用此脚本和将来的修复程序,我尝试创建一个Github页面...可以这么说,而不是我的一杯茶.

              For other people to use this script and future fixing I tried to create a Github page... not my cup of tea so to say.

              脚本在此页的第一篇文章中.

              Script is in the first post on this page.

              Youtube-dl下载脚本调试

              这篇关于Youtube-dl下载脚本调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆