Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #NoEnv
- ; youtube-dl binary path
- global ytdl := "D:\CLI\youtube-dl"
- /* ffmpeg
- ffmpeg must be accessible to youtube-dl for
- format conversions. The function expects it
- to be in the same level as the application.
- Example:
- D:\CLI\ffmpeg
- D:\CLI\youtube-dl
- To change, Use the option --ffmpeg-location
- */
- EnvGet UserProfile, USERPROFILE
- music := UserProfile "\Music"
- video := UserProfile "\Video"
- ^y::ytdl(music, 0) ; Audio
- +^y::ytdl(video, 1) ; Video
- ytdl(outDir, video := true)
- {
- if !url := getUrl(WinActive("A"))
- {
- MsgBox % 0x10|0x40000, Error, Couldn't retrieve URL.
- return
- }
- resource := "v" ; video
- outDir := RTrim(outDir, "\")
- if RegExMatch(url, "\blist=")
- {
- MsgBox % 0x4|0x20|0x40000, Playlist, Do you want to download the full playlist?
- IfMsgBox Yes
- resource := "list"
- , outDir .= "\%(playlist)s"
- }
- outDir .= "\%(title)s.%(ext)s"
- if !RegExMatch(url, resource "=(?<Id>[\w-]+)", resource)
- {
- MsgBox % 0x10|0x40000, Error, Cannot parse the URL.
- return
- }
- ; Order of the options:
- ; youtube-dl.exe --help
- cmd := "youtube-dl.exe"
- ; General Options
- . " --ignore-errors"
- . " --ignore-config"
- ; Network Options
- . " --force-ipv4"
- ; Geo restriction
- ; . " --geo-bypass"
- ; . " --geo-bypass-country US"
- . " --geo-bypass-ip-block 35.190.247.0/24" ; Google's
- ; Video Selection
- . " --yes-playlist"
- ; Download Options
- . " --hls-prefer-native"
- ; . " --hls-prefer-ffmpeg"
- ; Filesystem Options
- . " --output """ outDir """"
- . " --no-overwrites"
- . " --continue"
- . " --no-part"
- . " --cookies .\cache\cookies.txt"
- . " --cache-dir .\cache"
- ; Verbosity
- . " --no-warnings"
- . " --console-title"
- . " --no-call-home"
- ; Workarounds
- . " --no-check-certificate"
- . " --prefer-insecure"
- ; Mimic latest Firefox (as of Apr 27, 2021) when reloading the page without cache:
- . " --user-agent ""Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0"""
- . " --referer " StrReplace(url, "&", "^&")
- . " --add-header Accept-Encoding:identity"
- . " --add-header Accept-Language:en-US,en;q=0.5"
- . " --add-header Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
- . " --add-header Cache-Control:no-cache"
- . " --add-header Connection:keep-alive"
- . " --add-header DNT:1"
- . " --add-header Pragma:no-cache"
- . " --add-header TE:trailers"
- . " --add-header Upgrade-Insecure-Requests:1"
- . " --sleep-interval 0" ; Increase when changing 'geo-bypass'
- ; Video Format Options
- . " --youtube-skip-dash-manifest"
- . " --merge-output-format mkv"
- ; Subtitle Options
- ; Authentication Options
- ; Adobe Pass Options
- ; Post-processing Options
- . " --add-metadata"
- . " --ffmpeg-location ..\ffmpeg"
- if video ; Video in a Matroska container
- cmd .= " --embed-thumbnail"
- ; 8k = 4320
- ; 4k = 2160
- ; QHD = 1440
- ; FHD = 1080
- ; HD = 720
- . " --format bestvideo[height<=1080]+bestaudio"
- else ; AAC audio compatible with phones
- cmd .= " --format bestaudio[ext=m4a]"
- ; Other options by format code:
- ; https://voussoir.net/writing/youtubedl_formats
- RunWait % cmd " " resourceId, % ytdl
- }
- #Inlcude getUrl.ahk
- ; See:
- ; https://gist.github.com/anonymous1184/7cce378c9dfdaf733cb3ca6df345b140#geturl
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement