Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

youtube-dl-cheetsheet

youtube-dlを使ってタスクを便利にこなすためのスニペット集

Pythonistaで使えるやつ

import youtube_dl, os, appex

url = ''
arg = appex.get_text()

if arg != None:
	url = arg
else:
	url = input('video or playlist url: ')

format = 'bestvideo[ext=mp4]' if input('output format (v/m): ') == 'v' else 'bestaudio[ext=m4a]'

opts = { 'format': format }

os.chdir('/private/var/mobile/Containers/Shared/AppGroup/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Pythonista3/Documents/Downloads')

with youtube_dl.YoutubeDL(opts) as ydl:
	ydl.download([url])

youtube-dlで480pのmp4をDLする

# single video
youtube-dl -f 'bestvideo[height<=720][ext=mp4]+bestaudio[ext=m4a]' --merge-output-format mp4 
youtube-dl -f 'bestvideo[height<=480][ext=mp4]+bestaudio[ext=m4a]' --merge-output-format mp4 
youtube-dl -f 'bestvideo[height<=360][ext=mp4]+bestaudio[ext=m4a]' --merge-output-format mp4 
# playlist
youtube-dl -f 'bestvideo[height<=720][ext=mp4]+bestaudio[ext=m4a]' --playlist-start 1 --playlist-end 20 --merge-output-format mp4 
youtube-dl -f 'bestvideo[height<=480][ext=mp4]+bestaudio[ext=m4a]' --playlist-start 1 --playlist-end 20 --merge-output-format mp4 
youtube-dl -f 'bestvideo[height<=360][ext=mp4]+bestaudio[ext=m4a]' --playlist-start 1 --playlist-end 20 --merge-output-format mp4 
# playlist latest
youtube-dl -f 'bestvideo[height<=720][ext=mp4]+bestaudio[ext=m4a]' --playlist-items 100-120 --merge-output-format mp4 
youtube-dl -f 'bestvideo[height<=480][ext=mp4]+bestaudio[ext=m4a]' --playlist-items 100-120 --merge-output-format mp4 
youtube-dl -f 'bestvideo[height<=360][ext=mp4]+bestaudio[ext=m4a]' --playlist-items 100-120 --merge-output-format mp4 
# SoundCloud weekly
youtube-dl -x --audio-format mp3 --embed-thumbnail —-add-metadata https://soundcloud.com/keisei_1092/sets/soundcloud-weekly

検索してDL

# coding: utf-8

# youtube-search-and-dl
# 実行するとキーワードを入力して検索結果を保存します。
# 画面がロックすると死ぬ気がする()

import youtube_dl, os, appex, sys, time

opts = { }

keyword = input('YouTubeで検索して上位10件を保存します。キーワードを入力してください: ')

os.chdir(os.path.expanduser('~/Documents/Downloads'))

dirname = keyword + '_' + time.strftime('%Y%m%d%H%M%S')
os.mkdir(dirname)

os.chdir(os.path.expanduser('~/Documents/Downloads') + '/' + dirname)

with youtube_dl.YoutubeDL(opts) as ydl:
  ydl.download(['ytsearch10:' + keyword])

リネーム

インストール

brew install rename

最後からn文字削る

rename 's/(.*).{12}(\.mp3)/$1$2/g' *

convert

wav to mp3

ffmpeg -i inputfile.wav -ab 320k outputfile.mp3

# batch
for i in *.wav; do ffmpeg -i "$i" -ab 320k "${i%.*}.mp3"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment