-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathderpiget.sh
executable file
·1477 lines (1319 loc) · 42.5 KB
/
derpiget.sh
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#Mass download Derpibooru link list for Shimmie2's Bulk Add CSV Extention
#
#By Christian "Krissy" Silvermoon
scriptversion="v17.7.11-git by Christian \"Krissy\" Silvermoon"
function help_message {
echo "USAGE: derpiget [ARGUMENTS]
ARGUMENTS
--shimmie Download posts, create shimmie2 bulkadd CSV
--csvfix Repair a shimmie2 CSV (if dl_list.txt is unchanged)
--linksnoop Generate dl_list.txt by stalking your clipboard
--auto Run in non-interactive mode
--search Generate dl_list.txt containing ALL search results
--changelog Display a Changelog
--genbashcomplete Output a BASH Completion script to file
--config Use Alternate Config File
--mkconf Generate default config @ './derpiget.conf'
--clear Clear data/files from previous runs
--about Display information about features
--version Display version information
--help Display this message
-? Display this message
" | sed 's/^ //g'
if [ "$(command -v ponysay)" != "" ]; then
echo -e " You have super \e[1mPony Power\e[0m!"
fi
}
function derpitag_port {
#Usage derpitag_port "tags"
taglist="$1"
#Replace HTML Codes with their actual characters
taglist=$(echo "$taglist" | sed "s/'/\'/g")
if [ -a "derpibooru_strainer.csv" ]; then
echo -n ""
else
touch "derpibooru_strainer.csv"
echo "# Lines starting with \"#\" are commented" >> "derpibooru_strainer.csv"
echo "#" >> "derpibooru_strainer.csv"
echo "# Syntax Example" >> "derpibooru_strainer.csv"
echo "# \" fluttershy \",\" character:Fluttershy \"" >> "derpibooru_strainer.csv"
echo "# \" earth_pony \",\" species:earth_pony \"" >> "derpibooru_strainer.csv"
echo "#" >> "derpibooru_strainer.csv"
echo "# For more info see" >> "derpibooru_strainer.csv"
echo "# derpiget --about \"derpibooru_strainer.csv\"" >> "derpibooru_strainer.csv"
fi
#Handle Initial Reformating from Derpibooru Format
taglist=$(echo "$taglist" | sed 's/, /!/g' | sed 's/ /_/g' | sed 's/!/ /g')
taglist=$(echo " $taglist")
#Alter tags based on derpibooru_strainer.csv
strainercount=$(cat derpibooru_strainer.csv | grep -v "^#" | wc -l)
strainercount=$(echo "$strainercount + 1" | bc)
strainercurrent="1"
while [ "$strainercurrent" != "$strainercount" ]; do
tmp_original=$(cat "derpibooru_strainer.csv" | grep -v "^#" | sed 's/\"//g' | head -$strainercurrent | tail -1 | cut -d',' -f 1)
tmp_replace=$(cat "derpibooru_strainer.csv" | grep -v "^#" | sed 's/\"//g' | head -$strainercurrent | tail -1 | cut -d',' -f 2)
taglist=$(echo "$taglist" | sed "s/$tmp_original/$tmp_replace/g")
strainercurrent=$(echo "$strainercurrent + 1" | bc)
done
#Tag GIF if mimetype is GIF
if [ "$mimetype" = "gif" ]; then
echo -n "GIF "
fi
echo "$taglist DerpiGet"
}
function tag_filter {
#Filter tags using tag_filter.csv
#Function not implemented
echo -n ""
}
function check_dlist {
if [ -a "dl_list.txt" ]; then
if [ "$robomode" != "true" ]; then
echo -n "Found Download List... "
fi
else
echo "Error, No List"
echo "Please paste 1 Derpibooru post link per line in the file: "
echo "dl_list.txt"
echo
exit 1
fi
}
function derpiget_normal {
#Donwload images from dl_list only
check_dlist
if [ "$robomode" != "true" ]; then
echo "Any files located in $dlpath/ will be deleted (rm -rf)"
echo ""
echo -n "Continue? [Y/N] "
read option
else
option="y"
fi
if [ "$option" = "y" -o "$option" = "Y" ]; then
#Clear img/
rm -rf "$dlpath"/* > /dev/null 2>&1
#Read dl_list.txt for count
dloadlinkcount=$(cat dl_list.txt | wc -l)
dloadlinkcount=$(echo "$dloadlinkcount + 1" | bc)
current="1"
if [ "$robomode" != "true" ]; then
if [ "$dloadlinkcount" -gt "$dlcap" ]&&[ "$dlcap" != "0" ]; then
echo -e "\nThe number of links in the download list exceeds your"
echo "set download cap of $dlcap by $(echo "$dloadlinkcount - $dlcap" | bc) posts!"
echo "What to do?"
echo "1 - Download only the first $dlcap images"
echo "2 - Continue and ignore the Download cap"
echo ""
echo "Press any other key to Abort"
read -rsn1 option
if [ "$option" = "1" ]; then
dl_policy="partial"
elif [ "$option" = "2" ]; then
dl_policy="full"
else
echo "Aborted."
exit
fi
fi
echo "$( echo "$dloadlinkcount -1" | bc) Link(s) to fetch"
else
dl_policy="full"
fi
#Adjust $dlcap to account for offset
dlcap=$(echo "$dlcap + 1 " | bc)
while [ "$current" != "$dloadlinkcount" ]; do
#Display Counter
#read dl_list.txt for current URL
url=$(cat dl_list.txt | head -$current | tail -1)
#Download web page to variable, insert line breaks at tag closing '>' symbol
html="$(wget -q -O- "$(cat dl_list.txt | head -$current | tail -1)" | sed 's/>/>\n/g')"
if [ "$robomode" != "true" ]; then
echo -n "$current/$(echo "$dloadlinkcount - 1" | bc): "
echo -n "Got HTML... "
fi
#Save image as artist_1 artist_2 artist_3 - tag_1 tag_2 tag_3 (PostID)
#Get Tags
tags=$(echo "$html" | grep "tag dropdown" | sed 's/\" /\"\n/g' | grep "data-tag-name=" | cut -d"=" -f 2 | sed 's/\"//g' | tr '\n' ',' | sed 's/,/, /g')
#echo "TAGS ripped from HTML: $tags"
tags=$(echo "$tags" | sed 's/, /,/g' | sed 's/ /_/g' | sed 's/:/_/g' | sed 's/,/ /g')
#Prepare file name
endname=$(
if [ "$(echo "$tags" | tr ' ' '\n' | grep "artist_" | sed 's/artist_//g' | head -3 | tr '\n' ' ')" = "" ]; then
echo -n "Unknown_Artist "
else
echo "$tags" | tr ' ' '\n' | grep "artist_" | sed 's/artist_//g' | head -3 | tr '\n' ' '
fi
echo -n "- "
echo "$tags" | tr ' ' '\n' | grep -v "artist_" | grep -v "comic_" | head -3 | tr '\n' ' '
echo -n "("
#Get Post ID
echo -n "$html" | head -10 | tr ' ' '\n' | grep "#" | tr -d '#' | tr -d '\n'
echo -n ")"
)
if [ "$robomode" != "true" ]; then
echo -n "Got Tags... "
fi
#Get Image File
wget -q -O "$dlpath/$current" $(echo "$html" | grep "View this image at full res with a short filename" | sed 's/\" /\"\n/g' | sed 's/href=\"/http:/g' | sed 's/\">//g' | grep "http:" | sed 's/http:/https:/g')
if [ "$robomode" != "true" ]; then
echo "Got Image... "
fi
#Set correct file extention
mimetype=$(derpiget_idfiletype "$dlpath/$current")
imgname=$(echo -n "$endname"; echo ".$mimetype")
mv "$dlpath/$current" "$dlpath/$imgname"
#add to counter
current=$(echo "$current + 1" | bc)
#Alter counter based on $dl_policy
if [ "$dl_policy" = "partial" ]; then
if [ "$current" = "$dlcap" ]; then
echo "Downlaod Cap Reached, Stopped."
current="$dloadlinkcount"
fi
fi
done
if [ "$robomode" != "true" ]; then
echo -e "Fetched From Derpibooru\n-----------------------\n$(ls $dlpath/ -1)" | less
fi
else
echo "Aborted"
fi
}
function derpiget_shimmie {
check_dlist
#Remove Existing Files
if [ "$1" = "--csvfix" ]; then
if [ -a "list.csv" ]; then
if [ "$robomode" != "true" ]; then
echo -n "Overwrite list.csv? [Y/N] "
read option
else
option="y"
fi
if [ "$option" = "y" -o "$option" = "Y" ]; then
echo -n ""
else
echo "Aborted"
exit
fi
fi
echo -n ""
else
if [ "$robomode" != "true" ]; then
echo "Any files located in $dlpath/ will be deleted"
echo "If list.csv exists, it will be overwritten"
echo ""
echo -n "Continue? [Y/N] "
read option
else
option="y"
fi
if [ "$option" = "y" -o "$option" = "Y" ]; then
#Clear img/
rm -rf "$dlpath"/* > /dev/null 2>&1
else
echo "Aborted"
exit
fi
fi
echo -n "" > ./list.csv
dloadlinkcount=$(cat dl_list.txt | wc -l)
dloadlinkcount=$(echo "$dloadlinkcount + 1" | bc)
current="1"
if [ "$robomode" != "true" ]; then
if [ "$dloadlinkcount" -gt "$dlcap" ]&&[ "$dlcap" != "0" ]; then
echo -e "\nThe number of links in the download list exceeds your"
echo "set download cap of $dlcap by $(echo "$dloadlinkcount - $dlcap" | bc) posts!"
echo "What to do?"
echo "1 - Download only the first $dlcap images"
echo "2 - Continue and ignore the Download cap"
echo ""
echo "Press any other key to Abort"
read -rsn1 option
if [ "$option" = "1" ]; then
dl_policy="partial"
elif [ "$option" = "2" ]; then
dl_policy="full"
else
echo "Aborted."
exit
fi
fi
echo "$( echo "$dloadlinkcount -1" | bc) Link(s) to fetch"
else
dl_policy="full"
fi
#Adjust $dlcap for offset
dlcap=$(echo "$dlcap + 1" | bc)
while [ "$current" != "$dloadlinkcount" ]; do
url=$(cat dl_list.txt | head -$current | tail -1)
#Download web page to variable, insert line breaks at tag closing '>' symbol
html="$(wget -q -O- "$(cat dl_list.txt | head -$current | tail -1)" | sed 's/>/>\n/g')"
if [ "$robomode" != "true" ]; then
echo -n "$current/$(echo "$dloadlinkcount - 1" | bc): "
echo -n "Got HTML... "
fi
#Get Image File
if [ "$1" = "--csvfix" ]; then
echo -n ""
else
wget -q -O "$dlpath/$current" $(echo "$html" | grep "View this image at full res with a short filename" | sed 's/\" /\"\n/g' | sed 's/href=\"/http:/g' | sed 's/\">//g' | grep "http:" | sed 's/http:/https:/g')
if [ "$robomode" != "true" ]; then
echo -n "Got Image... "
#echo "bulkaddcsv/$current"
#echo ""
fi
fi
#CSV Fix, is image missing?
if [ "$1" = "--csvfix" ]; then
if [ -a "$dlpath/$current.*" ]; then
echo -n ""
else
wget -q -O "$dlpath/$current" $(echo "$html" | grep "View this image at full res with a short filename" | sed 's/\" /\"\n/g' | sed 's/href=\"/http:/g' | sed 's/\">//g' | grep "http:" | sed 's/http:/https:/g')
if [ "$robomode" != "true" ]; then
echo -n "Got Missing Image... "
#echo "bulkaddcsv/$current"
#echo ""
fi
mimetype=$(derpiget_idfiletype "$dlpath/$current")
imgname=$(echo -n "$current"; echo ".$mimetype")
mv "$dlpath/$current" "$dlpath/$imgname"
fi
fi
#Set correct file extention
if [ "$1" = "--csvfix" ]; then
#If not donwloading images, get mimetype from existing file
mimetype=$(derpiget_idfiletype "$dlpath/$current")
else
mimetype=$(derpiget_idfiletype "$dlpath/$current")
dbgmsg "Mimetype: $mimetype"
fi
imgname=$(echo -n "$current"; echo ".$mimetype")
dbgmsg "Image Name: $imgname"
if [ "$1" != "--csvfix" ]; then
mv "$dlpath/$current" "$dlpath/$imgname"
fi
#Get Tags
tags=$(echo "$html" | grep "tag dropdown" | sed 's/\" /\"\n/g' | grep "data-tag-name=" | cut -d"=" -f 2 | sed 's/\"//g' | tr '\n' ',' | sed 's/,/, /g')
#echo "TAGS ripped from HTML: $tags"
tags=$(derpitag_port "$tags")
if [ "$robomode" != "true" ]; then
echo -n "Got Tags... "
#echo "$tags"
#echo ""
fi
#Get Source
source=$(echo "$html" | grep "dc:source" | sed 's/\" /\"\n/g' | grep "href=" | sed 's/href=\"//g' | sed 's/\">//g')
if [ "$robomode" != "true" ]; then
echo -n "Got Source... "
#echo "$source"
#echo ""
fi
if [ "$source" = "" ]; then
source="$url"
fi
#Update CSV
#CSV format: "/path/to/image.jpg","spaced tags","source","rating s/q/e","/path/thumbnail.jpg"
if [ "$robomode" != "true" ]; then
echo "CSV Updated!"
fi
echo "\"$serverimgpath/$imgname\",\"$tags\",\"$source\",\"\",\"\"" >> list.csv
#add to counter
current=$(echo "$current + 1" | bc)
#Alter counter based on $dl_policy
if [ "$dl_policy" = "partial" ]; then
if [ "$current" = "$dlcap" ]; then
echo "Downlaod Cap Reached, Stopped."
current="$dloadlinkcount"
fi
fi
done
if [ "$robomode" != "true" ]; then
echo ""
fi
}
function derpiget_linksnoop {
if [ -a "dl_list.txt" ]; then
echo -n "Overwrite dl_list.txt? [Y/N] "
read option
if [ "$option" = "y" -o "$option" = "Y" ]; then
echo -n "" > dl_list.txt
else
echo ""
echo -n "Append instead? [Y/N] "
read option
if [ "$option" = "Y" -o "$option" = "y" ]; then
echo ""
else
echo "Aborted"
exit
fi
fi
fi
if [ "$(command -v beep)" != "" ]; then
echo "It looks like you have 'beep' installed."
echo -n "Beep the PC Speaker on link record? [Y/N] "
read -rsn1 option
if [ "$option" = "y" -o "$option" = "Y" ]; then
echo "Beep Enabled"
savebeep="true"
else
echo "Beep NOT enabled"
fi
else
echo "If 'beep' were available, DerpiGET could (optionally)"
echo "beep your PC Speaker to notify you that a link has been saved"
fi
echo ""
echo "Copy a Derpibooru Post Link to begin!"
while true; do
#Get Link From Clipboard
currentlink=$(xclip -o selection | grep "derpibooru.org/[0-9]" | cut -d'?' -f 1)
#If Current Link is the same, do nothing
if [ "$currentlink" = "$oldlink" ]; then
echo -n ""
else
clear
#Display Link Counter
echo "DerpiGET Link Snoop. (CTRL+C to stop at any time)"
echo -n "Link Count: "
echo "$(cat dl_list.txt | wc -l) + 1 " | bc
#Display Clipboard Contents
echo -n "Clipboard: "
if [ "$(echo $currentlink | grep -E "^(http|https)://derpibooru.org/[0-9]")" = "" ]; then
echo -e "\e[31m$(xclip -o selection)\e[0m"
echo ""
else
echo -e "\e[32m$currentlink\e[0m"
echo ""
#Store link to dl_list.txt if it's a Derpibooru Post link
#But only if it's not already in dl_list.txt
if [ "$(cat dl_list.txt | grep "$currentlink")" = "" ]; then
echo "$currentlink" >> dl_list.txt
if [ "$savebeep" = "true" ]; then
beep -f 400 -l 20
fi
fi
fi
echo "15 Most Recent (Bottom to Top)"
cat -n dl_list.txt | tail -15 | cut -d"?" -f 1 | sed 's/^ *//g'
oldlink="$currentlink"
fi
sleep .05s
done
}
function derpiget_search {
#Generate dl_list.txt based on ALL search results
#URL Encode Search
dbgmsg "--function: derpiget_search--"
if [ "$robomode" != "true" ]; then
if [ "$1" = "" ]; then
echo "What are you searching for?"
echo ""
echo "Example of Proper Argument Usage"
echo "deripget --search=\"dashie, hugging\""
echo ""
echo "Use Derpibooru Search Syntax!"
exit
else
echo -n ""
fi
echo "Be very cautious before using the generated dl_list.txt"
echo "It will contain a link to EVERY search result"
echo "The purpose of this option is for mass downloading"
echo "The results of a FINE TUNED search"
echo
echo "Please review your search before unintentionally"
echo "Downloading over 1000 posts or something!"
echo ""
dbgmsg "--Check existance of Cookies File--"
if [ -a "$cookies" ]; then
echo -n ""
else
echo "Image Results are limited to the default filter"
echo "You can use cookies.txt to use other filters."
echo "For more info use"
echo "derpiget --about \"cookies.txt\""
echo -n "" > "$cookies"
fi
echo "Search: $1"
fi
search=$(echo "$1" |
sed 's/ /%20/g' |
sed 's/!/%21/g' |
sed 's/#/%23/g' |
sed 's/\$/%24/g' |
sed 's/&/%26/g' |
tr "'" '!' |
sed 's/!/%27/g' |
sed 's/(/%28/g' |
sed 's/)/%29/g' |
sed 's/*/%2A/g' |
sed 's/+/%2B/g' |
sed 's/,/%2C/g' |
sed 's/\//%2F/g' |
sed 's/:/%3A/g' |
sed 's/;/%3B/g' |
sed 's/=/%3D/g' |
sed 's/?/%3F/g' |
sed 's/@/%40/g' |
sed 's/\[/%5B/g' |
sed 's/\]/%5D/g')
page=1
url="https://derpibooru.org/search?page=$page&utf8=%E2%9C%93&sbq=$search"
if [ "$robomode" != "true" ]; then
echo "Search URL: $url"
dbgmsg "\$cookies=$cookies"
echo -n "Results: "
resultcount=$(wget --load-cookies="$cookies" -q -O- "$url" | sed 's/of <strong>/\nResults:/g' | sed 's/>/>\n/g' | sed 's/</\n</g' | grep "Results:" | cut -d':' -f "2")
if [ "$resultcount" = "" ]; then
echo -e "\e[31m0\e[0m"
echo ""
echo "I'm affraid these are not the ponies you are looking for."
echo "AKA yor search returned no results... sorry..."
echo ""
echo "Did you form your search correctly?"
echo "For help: https://derpibooru.org/search/syntax"
exit
fi
echo "$resultcount"
echo ""
echo -n "Continue? [Y/N] "
read option
if [ "$option" = "y" -o "$option" = "Y" ]; then
echo -n ""
else
echo "Aborted"
exit
fi
if [ -a "dl_list.txt" ]; then
echo -n "Overwrite dl_list.txt? [Y/N] "
read option
if [ "$option" = "y" -o "$option" = "Y" ]; then
echo -n "" > dl_list.txt
else
echo ""
echo -n "Append instead? [Y/N] "
read option
if [ "$option" = "Y" -o "$option" = "y" ]; then
echo ""
else
echo "Aborted"
exit
fi
fi
fi
fi
nextpagetest=true
until [ "$nextpagetest" = "false" ]; do
#GET HTML
html=$(wget --load-cookies="$cookies" -q -O- "$url" | sed 's/>/>\n/g')
dbgmsg "Extracted Posts from Page: $page of search results"
#Extract list of post links
echo "$html" | grep "Tagged:" | sed 's/title/\ntitle/g' | grep "<a href" | cut -d'?' -f 1 | tr -d '=' | tr -d '<' | tr -d '"' | sed 's/a href/https:\/\/derpibooru.org/g' >> dl_list.txt
#Test for next page
if [ "$(echo "$html" | grep "Next Page")" = "" ]; then
nextpagetest="false"
else
page=$(echo "$page + 1" | bc)
url="https://derpibooru.org/search?page=$page&utf8=%E2%9C%93&sbq=$search"
fi
done
cat dl_list.txt | wc -l
exit
}
function derpiget_clear {
#Clean up excess files, etc.
loop=true
clearimgdir="false"
clearcsv="false"
clearcookies="false"
cleardlist="false"
while [ "$loop" = "true" ]; do
clear
echo "Clear what?"
echo -e "(Press Any Listed Key)\n"
echo -e "\e[1m# - Item Status\e[0m"
echo -n "1 - Cookies "
if [ "$clearcookies" = "false" ]; then
echo -en "\e[31m"
else
echo -en "\e[32m"
fi
echo -e "$clearcookies\e[0m"
echo -n "2 - dl_list.txt "
if [ "$cleardlist" = "false" ]; then
echo -en "\e[31m"
else
echo -en "\e[32m"
fi
echo -e "$cleardlist\e[0m"
echo -n "3 - list.csv "
if [ "$clearcsv" = "false" ]; then
echo -en "\e[31m"
else
echo -en "\e[32m"
fi
echo -e "$clearcsv\e[0m"
echo -n "4 - Image Folder "
if [ "$clearimgdir" = "false" ]; then
echo -en "\e[31m"
else
echo -en "\e[32m"
fi
echo -e "$clearimgdir\e[0m"
echo ""
echo "C - Continue & Clear"
echo "Q - Quit Without Clearing"
echo ""
read -rsn1 option
if [ "$option" = "1" ]; then
if [ "$clearcookies" = "false" ]; then
clearcookies="true"
else
clearcookies="false"
fi
elif [ "$option" = "2" ]; then
if [ "$cleardlist" = "false" ]; then
cleardlist="true"
else
cleardlist="false"
fi
elif [ "$option" = "3" ]; then
if [ "$clearcsv" = "false" ]; then
clearcsv="true"
else
clearcsv="false"
fi
elif [ "$option" = "4" ]; then
if [ "$clearimgdir" = "false" ]; then
clearimgdir="true"
else
clearimgdir="false"
fi
elif [ "$option" = "C" -o "$option" = "c" ]; then
echo -n "Are you sure? [Y/N] "
read -rsn1 option
if [ "$option" = "y" -o "$option" = "Y" ]; then
loop=false
echo ""
fi
elif [ "$option" = "Q" -o "$option" = "q" ]; then
echo -n "Abort? [Y/N] "
read -rsn1 option
if [ "$option" = "y" -o "$option" = "Y" ]; then
echo -e "\n\nAborted"
exit
fi
fi
done
if [ "$clearcookies" = "true" ]; then
echo -n "" > "$cookies"
echo "Cleared Cookies"
fi
if [ "$clearcsv" = "true" ]; then
echo -n "" > list.csv
echo "Cleared list.csv"
fi
if [ "$clearimgdir" = "true" ]; then
rm -rf "$dlpath"/*
echo "Cleared Image Directory"
fi
if [ "$cleardlist" = "true" ]; then
echo -n "" > dl_list.txt
echo "Cleared dl_list.txt"
fi
echo ""
echo "Finished Clearing."
}
function derpiget_about {
if [ "$1" = "" ]; then
echo -e "You must specify a topic\n"
echo "Example"
echo " derpiget --about=\"topic\""
echo ""
echo "Topics"
echo " derpiget This script in general"
echo " derpibooru The site the script was made for"
echo " cookies.txt Cookies used by wget"
echo " dl_list.txt List of posts to download"
echo " list.csv Post Information for Shimmie2"
echo " derpibooru_strainer.csv Tag filtering information"
echo " robomode Details about non-intarctive mode"
echo " shimmie Image Board"
echo " genbashcomplete Output bash completion script to file"
ecoh " debugging How to get more info?"
elif [ "$1" = "derpiget" ]; then
echo "DerpiGET"
echo " Script for mass downloading posts from"
echo " http://derpibooru.org"
echo ""
echo " Written by Christian \"Krissy\" Silvermoon"
elif [ "$1" = "derpibooru" ]; then
echo "Derpibooru"
echo " A My Little Pony: Friendship is Magic fandom image board"
echo ""
echo " See Below for more details"
echo " http://derpibooru.org/about"
elif [ "$1" = "cookies.txt" ]; then
echo "cookies.txt"
echo " Contains cookies used by wget"
echo ""
echo " You can export your Derpibooru Cookies"
echo " from a web browser for use with"
echo " DerpiGET. In order to use a filter other"
echo " than \"Default\""
echo ""
echo " Unless you're SPECIFICALLY trying to use"
echo " a filter that requires access to your account"
echo " avoid using ANY login cookies, as this may put"
echo " your user account at risk if your cookies.txt"
echo " should somehow fall into the wrong hooves!"
echo ""
echo " Mozilla Firefox addon for exporting cookies"
echo " https://addons.mozilla.org/en-US/firefox/addon/export-cookies/?src=api"
echo ""
echo " To remove cookies unrelated to Derpibooru, use this command"
echo " cat cookies.txt | grep \"derpibooru\" > newcookies.txt"
elif [ "$1" = "dl_list.txt" ]; then
echo "dl_list.txt"
echo " Download list for DerpiGET"
echo ""
echo " When downloading images from"
echo " Derpibooru, DerpiGET will download"
echo " each post one after anoher starting"
echo " at the top of the list and working it's"
echo " way to the bottom"
echo ""
echo " You should place one post link per line, like so:"
echo " https://derpibooru.org/1"
echo " https://derpibooru.org/2"
echo " https://derpibooru.org/3"
echo ""
echo " Alternatively \"--search\" and \"--linksnoop\" can handle"
echo " The creation of a dl_list.txt file for you."
elif [ "$1" = "list.csv" ]; then
echo "list.csv"
echo " Comma Seperated Value file for Shimmie2"
echo ""
echo " This is for use with a Shimmie2 Image Board's"
echo " bulkaddcsv extention for mass uploads along with"
echo " tagging information, etc. for all posts."
echo ""
echo " When DerpiGET was first created, downloading images"
echo " and creation of this file from Derpibooru's tags"
echo " was it's only function."
echo ""
echo " This script assumes that images are located in"
echo " http://example.com/bulkaddcsv/img"
echo ""
echo " When stored and used on a server, DerpiGET was originally"
echo " intended to be ran from the \"/bulkaddcsv/\" directory"
echo " of a webserver."
elif [ "$1" = "derpibooru_strainer.csv" ]; then
echo "derpibooru_strainer.csv"
echo " Comma Seperated Value file for tag filtering"
echo " Yes, the name IS a joke about kitchen strainers"
echo " A more fitting solution would be to use Shimmie's"
echo " aliases, but if for whatever reason you don't want to"
echo " use this instead."
echo ""
echo " This file is used when to alter tags durring saving"
echo " of images. when --shimmie or --csvfix is used."
echo ""
echo " File Syntax"
echo " #Commented Line"
echo " \" to_be_replaced \",\" tag_to_replace_with \""
echo ""
echo " Important"
echo " Do not add comments at the end of lines"
echo " Do not leave uncommented blank lines"
echo " Insert spaces at the beginning and end of"
echo " Your tags, always, unless specifically targeting"
echo " a portion of a tag like 'oc:character'"
echo " which you can use"
echo ""
echo " \" oc:\",\" character:oc:\""
echo ""
echo " to replace. If a character must be escaped for"
echo " sed to use it, then it MUST be escaped here."
echo " Remember to seperate tags with spaces, not commas,"
echo " as by this point, derpibooru's tags have been changed from"
echo " \"safe, artist:this dude, example\" to"
echo " \"safe artist:this_dude example\""
elif [ "$1" = "shimmie" ]; then
echo "Shimmie"
echo " A pretty neat GPLv2 booru-style Image Board"
echo ""
echo " For more details, see"
echo " https://github.com/shish/shimmie2"
echo " https://code.shishnet.org/shimmie2/"
elif [ "$1" = "robomode" ]; then
echo "Robomode"
echo " Noninteractive use of DerpiGET"
echo " It is mostly silent and will NOT prompt"
echo " you before deleting or altering files!"
echo ""
echo " This can done in one of the two following ways"
echo ""
echo " derpiget --auto [Arguments]"
echo " OR"
echo " robomode=\"true\" derpiget [Arguments]"
echo ""
echo " NOT all options work in Robomode"
echo " These, however do"
echo ""
echo " derpiget --auto --search=\"example\""
echo " (Appends ONLY. Outputs number of links in dl_list.csv to stdout)"
echo ""
echo " derpiget --auto"
echo " derpiget --auto --shimmie"
echo " derpiget --auto --csvfix"
elif [ "$1" = "genbashcomplete" ]; then
echo "genbashcomplete
creates derpiget_completion.sh
A short, simple shell script to make use
of bash-completion in order to fill in
DerpiGET's arguments
Please Note, the completion script is currently
in it's infancy and will only fill in arguments
DerpiGET's arguments are 'order sensitive' and
the completion script does NOT account for this." | sed 's/ //g'
elif [ "$1" = "debugging" ]; then
echo "debugging"
echo -e " How to see more details about DerpiGET's runs\n"
echo -e " This is controled by the environement variable: \$SILVERMOON_DEBUG"
echo -e " When \$SILVERMOON_DEBUG is NOT empty, DerpiGET will display debug messages.\n"
echo " Example uses:"
echo -e " SILVERMOON_DEBUG=1 ./derpiget.sh\n export SILVERMOON_DEBUG=1; derpiget.sh"
else
echo "Topic \"$1\" does not exist."
fi
}
function derpiget_splash {
#Output a Ditzy "Derpy Hooves" Doo quote based on the clock
#Special thanks to http://mlp.wikia.com/wiki/Derpy for the quotes
if [ "$(date +%S)" -lt "10" ]; then
echo "Muffin?"
elif [ "$(date +%S)" -lt "20" ]; then
echo "I just don't know what went wrong..!"
elif [ "$(date +%S)" -lt "30" ]; then
echo "Nice work, Rainbow Dash!"
elif [ "$(date +%S)" -lt "40" ]; then
echo "You okay, Rainbow Dash? Anything I can do to help?"
elif [ "$(date +%S)" -lt "50" ]; then
echo "Mr. Cake! Do you have any muffins today?"
elif [ "$(date +%S)" -lt "60" ]; then
echo "Mmm, muffins..."
fi
}
function derpiget_automode {
#For scripting
#Added at the suggestion of Pouar
robomode="true"
if [ "$1" = "" ]; then
derpiget_normal
elif [ "$1" = "--shimmie" ]; then
derpiget_shimmie
elif [ "$1" = "--csvfix" ]; then
derpiget_shimmie --csvfix
elif [ "$1" = "--search" ]; then
derpiget_search "$2"
else
echo -e "\e[31mInvalid Argument OR cannot be automated\e[0m"
exit 1
fi
}
function derpiget_csvomit {
#Remove certain posts from list.csv
loop=true
end=$(cat list.csv | wc -l)
if [ "$1" = "" ]; then
line="1"
else
line="$1"
fi
while [ "$loop" = "true" ]; do
clear
echo "List.csv, Post: $line of $end."
echo ""
echo "File: $(cat list.csv | head -$line | tail -1 | cut -d"," -f 1 | sed 's/\"//g')"
echo -n "Artist(s): "
cat list.csv | head -$line | tail -1 | cut -d"," -f 2 | sed 's/\"//g' | tr ' ' '\n' | grep "artist:" | sed 's/artist://g' | head -3 | tr '\n' ' '
echo -ne "\nTag(s): "
cat list.csv | head -$line | tail -1 | cut -d"," -f 2 | sed 's/\"//g' | tr ' ' '\n' | grep -v "artist:" | head -4 | tr '\n' ' ' | sed 's/^ //g'
echo ""
echo -n "Source: "
cat list.csv | head -$line | tail -1 | cut -d"," -f 3 | sed 's/\"//g'
echo -e "\nw - Scroll Up d - Scroll Down j - Jump To r - remove from list"
echo "q - Quit"
read -rsn1 KeyboardInput
echo ""
if [ "$KeyboardInput" = "w" ]; then
if [ "$line" != "1" ]; then
line=$(echo "$line - 1 " | bc)
else
line="$end"
fi
elif [ "$KeyboardInput" = "s" ]; then
if [ "$line" != "$end" ]; then
line=$(echo "$line + 1 " | bc)
else
line="1"
fi
elif [ "$KeyboardInput" = "j" ]; then
echo -n "Jump to post: "
read jumpto
if [ "$jumpto" != "" ]; then
if [ "$jumpto" -le "$end" ]&&[ "$jumpto" -gt "0" ]; then
line="$jumpto"
fi
fi
elif [ "$KeyboardInput" = "r" ]; then
echo -n "Remove For sure? [Y/N] "
read -rsn1 option
if [ "$option" = "y" -o "$option" = "Y" ]; then
tmpcsvrm=$(cat list.csv | head -$line | tail -1)
tmpcsv=$(cat list.csv | grep -v "$tmpcsvrm")
echo "$tmpcsv" > list.csv
tmpfile=$(echo "$tmpcsvrm" | cut -d"," -f 1 | tr -d '"')
fi
elif [ "$KeyboardInput" = "q" ]; then
echo -n "Are you sure? [Y/N] "
read -rsn1 option
if [ "$option" = "y" -o "$option" = "Y" ]; then
exit
fi
fi
done
}