6

A cool bash shell script to download (cut) a portion of video from youtube. It depends on youtube-dl and avconv/ffmpeg tools which can be installed from the distribution.

Bash Shell Script (can be named as ytcut):
Note: No error handing implemented

#!/bin/bash
#set -x

_yt_id="$1"
_yt_start_time="$2"
_yt_end_time="$3"

#_yt_format_id="bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio"
# use youtube-dl -F <video id> to get the list of formats available
# Using format id as 22 as the above one didn't work.
_yt_format_id=22

_yt_time_selection_opts="-ss ${_yt_start_time}"
_yt_time_selection_opts="${_yt_time_selection_opts} -to ${_yt_end_time}"

_yt_url=$(youtube-dl -f ${_yt_format_id} -g "${_yt_id}")
_yt_filename=$(youtube-dl --get-filename --restrict-filenames -f ${_yt_format_id} "${_yt_id}")

avconv -y -nostats -loglevel 0 -i "${_yt_url}" ${_yt_time_selection_opts} -codec copy "file:${_yt_filename}"

Example Usage:
ytcut 3dWrKNrWbWQ 0:40 1:40

Comments
Add Comment