youtube-dl.sh
d6817323
 #!/bin/bash
09cd128d
 ## This Shellscript downloads all fresh videos from a firefox bookmark folder. ##
98f81a9b
 
7d5b579a
 ##Variables to edit from the user##
09cd128d
 
7d5b579a
 #path to youtube-dl. If you dont know, use cli: "which youtube"#
 yot_dl_p="$HOME/bin/youtube-dl"
 # folder for the downkoaded Videos #
 dl_folder=~/Downloads/youtube-dl
 # load from "database" or "array".#
 loadfrom=database
 # If Loadfrom=database, save all your Youtube playlists in favdir example (amp3) #
09cd128d
 favdir="amp3"
7d5b579a
 
 ## Variables to edit carefully ##
 sleep 1
 zaehl=0
 # Firefox running ?#
11bae50a
 ffon=0; pgrep firefox && ffon=1
7d5b579a
 # Date= yesterday #
1bc42e08
 datum=$(date -d "1 day ago" '+%Y%m%d')
7d5b579a
 # Max. videos / datum to each playlist #
d6817323
 perday=4
7d5b579a
 # if aria2 is installed example : #
87b6c897
 # aria2='--external-downloader aria2c  --external-downloader-args "-j 8 -s 8 -x 8 -k 5M"'
850f3ee5
 aria2=''
7d5b579a
 # firefox database#
7a44b268
 sqltdata=places.sqlite
d6817323
 
09cd128d
 
850f3ee5
 
7d5b579a
 ## Update your youtube-dl ! ##
 $yot_dl_p -U 
 ## or 
 # pip install --upgrade youtube-dl
 
 
 
 ## Start ##
b7791fb4
 
 if [ $loadfrom == database ]
 then
 cd ~/.mozilla/firefox || exit
 #find ./ -maxdepth 1 -name "*default*" -type d
 ffdefault=$(find ./ -maxdepth 1 -name "*default*" -type d | wc -l)
 if [ "$ffdefault" -gt 1 ]
 then
 echo "There is more then 1 default Firefox profile ! You have to choose one at ~/.mozilla/firefox and edit this script for your need"
 find ./ -maxdepth 1 -name "*default*" -type d 
 exit
 elif [ "$ffdefault" == 0 ]
 then
 echo " There is no Firefox profile in your ~/.mozilla/firefox but it should. Script can't continue !"
 exit
 fi
 
 # If more then 1 FF profile  Edit here ! 
 # change *default*  to your profile. Example fdgsfdgfs43543.default.fdsgf 
 cd ./*default* || exit
 
7d5b579a
 # you cannot read from a running sqlite, but to copy is allowed#
b7791fb4
 if [ $ffon == 1 ]
850f3ee5
 then
 cp $sqltdata places2.sqlite
 sqltdata=places2.sqlite
 fi
b7791fb4
 fi
850f3ee5
 ## only edit dbarray test-content if you want to use it
353161a7
 
735ee710
 if [ $loadfrom == array ]
 then
  dbarray=(
  "https://www.youtube.com/user/GalileoOffiziell/videos"
  "https://www.youtube.com/user/BibisBeautyPalace/videos?sort=dd&shelf_id=1&view=0"
  "https://www.youtube.com/channel/UC53bIpnef1pwAx69ERmmOLA"
09cd128d
  )
 ##
850f3ee5
 ##--------------------Do not edit below this line ! -----------------------
 ##
  
 else
8bd4b3c1
  ## This line puts FF bookmarks from sqlite3 to an array ##
b7791fb4
 #oldschool#
7d5b579a
 #dbarray=( $(sqlite3 -list $sqltdata 'select url from moz_places where id in (select fk from moz_bookmarks where parent in ( select "id" from moz_bookmarks where title == "'$favdir'"))'; ))
b7791fb4
 #new V.bash4.0#
7d5b579a
 readarray -t dbarray < <(sqlite3 -list $sqltdata 'select url from moz_places where id in (select fk from moz_bookmarks where parent in ( select "id" from moz_bookmarks where title == "'$favdir'"))')
735ee710
 fi
850f3ee5
 cd  $dl_folder || exit
7a44b268
 
 ## Let youtube-dl do the work  and download brandnew videos ##
850f3ee5
 
 for i in "${dbarray[@]}"; do
09cd128d
 ((zaehl++))
7d5b579a
 $yot_dl_p $aria2 --download-archive $dl_folder/archive/archive-$zaehl.txt --dateafter "$datum" --playlist-end "$perday" --max-downloads "$perday" "$i"
850f3ee5
 # echo $i
 done
7d5b579a
 
850f3ee5