Browse code

firefox auto detect and sqlite management

dewomser authored on30/10/2018 21:16:42
Showing1 changed files

... ...
@@ -1,46 +1,41 @@
1 1
 #!/bin/bash
2 2
 ## This Shellscript downloads all fresh videos from afirefox favorite folder. ##
3 3
 
4
-## Config ##
5
-
6
-## update youtube-dl ##
7
-## "youtube-dl -U" or "pip youtube-dl install" ##
4
+## update your youtube-dl ##
5
+# "youtube-dl -U" 
6
+## or 
8 7
 # pip install --upgrade youtube-dl
9 8
 # sleep 3
10 9
 
11
-## If Firefox is already running AND Sqlite bookmarks are used, this script will not do without action: ##
12
-## Firefox manages bookmarks from a locked database.
13
-
14
-## 1.) All Firefox instances must be killed. Manualy or uncomment next Line
15
-# killall -9 firefox; sleep 3
16
-## OR
17
-## 2.) copy database and query there. Uncomment line 22 ; read line 60  
18
-
19
-## from Firefox bookmarks ##
20
-## change *default* if you have other profiles than default. ##
21
-cd ~/.mozilla/firefox/*default* || exit
22
-# cp places.sqlite places2.sqlite
23
-
24 10
 ## Variables ##
25 11
 
26 12
 ## save all your Youtube playlists in $favdir ##
27 13
 favdir="bestof"
14
+## firefox running ?
15
+ffon=0; ps -ef|grep firefox|grep -v grep && ffon=1
28 16
 ## Download folder ##
29 17
 dl_folder="/home/foo/Downloads/youtube-dl/"
30 18
 ## Date= yesterday ##
31 19
 datum=$(date -d "1 day ago" '+%Y%m%d')
32
-## Videos per day in each playlist##
20
+## Videos per day on each playlist##
33 21
 perday=4
34 22
 ## if aria2 is installed example : ##
35 23
 # aria2='--external-downloader aria2c  --external-downloader-args "-j 8 -s 8 -x 8 -k 5M"'
36 24
 aria2=''
37 25
 ## load from database or array
38 26
 loadfrom=database
27
+## firefox database
28
+sqltdata=places.sqlite
39 29
 
40 30
 ## Start ##
41 31
 
42
-# echo $favdir
43
-# echo  $dl_folder
32
+cd ~/.mozilla/firefox/*default* || exit
33
+
34
+if (( ffon == 1 && loadfrom == database ))
35
+then
36
+cp $sqltdata places2.sqlite
37
+sqltdata=places2.sqlite
38
+fi
44 39
 
45 40
 ## only edit dbarray content if you want to use it
46 41
 
... ...
@@ -56,13 +51,14 @@ then
56 51
 ##
57 52
  
58 53
 else
59
- ## this line puts FF favourites from sqlite3 to an array ##
60
- ## edit "places" to "places2 in next line"
61
- dbarray=( $(sqlite3 -list places.sqlite 'select url from moz_places where id in (select fk from moz_bookmarks where parent in ( select "id" from moz_bookmarks where title == "'$favdir'"))'; ))
54
+ ## This line puts FF favourites from sqlite3 to an array ##
55
+ ## Only if 2.) Next line edit "places" to "places2"
56
+ 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'"))'; ))
62 57
 fi
63 58
 cd  $dl_folder || exit
64
-## let youtube-dl do the work  and download brandnew videos##
65
-# 
59
+
60
+## Let youtube-dl do the work  and download brandnew videos ##
61
+
66 62
 for i in "${dbarray[@]}"; do
67 63
 youtube-dl $aria2 --dateafter "$datum" --playlist-end "$perday" --max-downloads "$perday" "$i"
68 64
 # echo $i