aboutsummaryrefslogtreecommitdiff
path: root/bash/youtube.sh
blob: 3c5b56e906dd62f15b9daca751ecc57c4ac5450d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env bash

export DEFAULT_PLAYLIST_END=15
export DEFAULT_INC_STEP=10
export YT_TEMPLATE="~/Downloads/yt-dl/%(uploader)s/%(upload_date)s %(title)s.%(ext)s"

# Always downloads video, doesn't look at the download-archive
yt-dl() {
  youtube-dl "$1" -o "$YT_TEMPLATE"
}
export -f yt-dl

download() {
  youtube-dl "$1" \
             --download-archive ~/Nextcloud/cache/youtube-dl-seen.conf \
             --prefer-free-formats \
             --playlist-end $2 \
             --output "$YT_TEMPLATE"
}
export -f download


download_user() {
  download "https://www.youtube.com/user/$1" ${2-$DEFAULT_PLAYLIST_END}
}
export -f download_user


download_channel() {
  download "https://www.youtube.com/channel/$1" ${2-$DEFAULT_PLAYLIST_END}
}
export -f download_channel


download_playlist() {
  download "https://www.youtube.com/playlist?list=$1" ${2-$DEFAULT_PLAYLIST_END}
}
export -f download_playlist


inc_download() {
  local fn="$1"
  local id="$2"
  local step="${3-$DEFAULT_INC_STEP}"

  local file="$HOME/.yt-db/$id"
  mkdir -p "$HOME/.yt-db"
  local n_count="$(cat $file 2> /dev/null || printf 10)"
  local n_count_new="$(($n_count + $step))"

  echo "$n_count_new" > "$file"

  "$fn" "$id" "$n_count"
}

export -f inc_download