-
Notifications
You must be signed in to change notification settings - Fork 0
/
nani
executable file
·745 lines (680 loc) · 31.1 KB
/
nani
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
#!/usr/bin/env bash
set -e
##########################################################################
# Copyright (C) 2016 welpo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
##########################################################################
# Get the script name
script_name="${0##*/}"
# Try to import settings from ~/.config/nani/nanirc or /etc/nanirc
# use -r to see if the file is readable
if [[ -r "$HOME/.config/$script_name/${script_name}rc" ]]; then
source "$HOME/.config/$script_name/${script_name}rc"
elif [[ -r "/etc/${script_name}rc" ]]; then
source "/etc/${script_name}rc"
else
# if neither exists, use the config stored in the script
############################# BEGIN CONFIGURATION #############################
# Local directory where files will be stored (should be inside your public_html folder):
# Do NOT use a trailing slash
local_directory="$HOME/www/$(whoami).$(hostname -f)/public_html/$script_name"
# URL format (example: https://yoursite.com/nani)
# Do NOT use a trailing slash
url_format="https://$(hostname -f)/$(whoami)/$script_name"
# Create hard links instead of new copies? Default is 1 (Yes)
# Can be reverted by using the -a, --alias flag.
hard_link=1
# Create symbolic links instead of new copies? Default is 0 (No)
# This is useful if your output dir is on a different mount
# Can be forced using the -y, --symbolic flag
symbolic=0
# Create symbolic links for everything except directories
# Useful when output dir is in a different mount, (e.g. SSHFS)
sshfs=0
# Minimum number of characters for the output name. Default is 5.
# Can be overriden by using the -l X or --length=X flag.
minimum_length=5
# Maximum number of extra characters the length will have.
# The final length will be a number between length and length+random_length
# Will be ignored if the -s or --string flag is used.
# Can be left empty if you don't wish to randomise the length.
random_length=2
# Be quiet. If set to 1 it will only output the link. Default is 1 (be quiet).
# You will want this to be set to 1 to integrate it with other software/scripts
# Can be reversed using the -q or --quiet flag
quiet=1
# Do you want to add .txt to files with no extension? Default is 1 (Yes).
add_txt=1
# Do you want to change the extension of files storing text (.php, .html, .tex...) to .txt? Default is 1 (Yes).
modify_text=1
# Do you want to transcode flac to MP3 V0? Default is 1 (Yes). Requires metaflac, flac and lame.
# Setting can be reversed by using the -t or --transcode flag
transcode=1
# Use xclip to get the URL to your local clipboard if xclip is set up and you ran SSH with the -X flag. Default is 1 (Enabled).
# You will want this to be set to 0 to integrate it with other software/scripts
# Setting can be reversed by using the -x or --xclip flag
xclip=1
# Post-process COPIED files (not hard links nor system links)
# Optimise png, tiff etc. files and remove EXIF data from pictures
# Dependencies: exiftool (http://owl.phy.queensu.ca/~phil/exiftool/) and optipng (http://optipng.sourceforge.net/)
post_process=1
# Send a notification using notify-send when nani is done
# Makes sense when used in a desktop (using SSHFS as the output, for example)
notify=1
# Do you want to use push notifications?
# Using the -p or --push flag will force them.
# Remember to set the service's tokens/keys below for them to work.
push=0
# Your Pushbullet access token https://www.pushbullet.com/account Leave empty if you don't want to use Pushbullet.
pushbullet_token=''
# Your Pushover key https://pushover.net/ Leave empty if you don't want to use Pushover.
pushover_key=''
############################## END CONFIGURATION ##############################
fi
# Create random string of characters (upper and lowercase + numbers) for the output filename
random ()
{
# Set the final string length if random_length is set and setlength is not (the latter will be =1 when -s or --string flag is used)
if [[ -n "$random_length" && -z "$setlength" ]]; then
add_length=$(( ( RANDOM % $random_length ) + 1 ))
length=$(($add_length + $minimum_length))
else
length="$minimum_length"
fi
# Set length to use X to make it work with mktemp
printf -v letters '%*s' $length ' ' ; letters="${letters// /X}"
# If we want a random name...
if [[ -z "$preserve_name" ]]; then
output_name="$(mktemp "$local_directory"/"$letters""$extension")" || continue
output_name="${output_name##*/}"
output_name="${output_name%.*}"
else
# If we don't want a random name, check output_name isn't set (-n, -o)
if [ -z "$output_name" ]; then
# Store basename
file_basename=$(basename "$input")
if [[ -d "$input" || -h "$input" ]]; then
# Keep the whole thing if it is a directory
output_name="$file_basename"
else
# Only keep name, not extension, when it's not a directory. handle dotfiles
if [[ "$output_name" == "${file_basename%.*}" ]]; then
output_name="$file_basename"
else
output_name="${file_basename%.*}"
fi
fi
fi
# If -n, --name, -o or --original were used check output name doesn't exist on /nani/
# If it does exist, prepend a random string of 5 characters (default, can be changed by adding or removing X's in the mktemp line)
if [[ -e "$local_directory"/"${output_name// /_}""$extension" || -z "$output_name" ]]; then
output_name="$(mktemp "$local_directory"/XXXXX_"$output_name""$extension")" || continue
output_name="${output_name##*/}"
output_name="${output_name%.*}"
fi
# Truncate spaces for underscores
output_name="${output_name// /_}"
fi
}
post_process ()
{
if [[ "$quiet" == 1 ]]; then
post_process_quiet="-q"
fi
# Remove metadata
if hash exiftool 2>/dev/null && [[ "$file_mime_type" == *@(pdf|gif|jpeg|mp4|psd|tiff|png|mov)* ]]; then
exiftool $post_process_quiet -overwrite_original -all= "$full_output_path"
fi
# Optimise png, bmp, gif...
if hash optipng 2>/dev/null && [[ "$file_mime_type" == *@(png|bmp|gif|pnm|tiff)* ]]; then
optipng $post_process_quiet "$full_output_path"
fi
}
# Creates copy (hard link, symbolic link or just cp) to input file in /nani/
copy ()
{
if [[ "$hard_link" == 1 ]]; then
hard_link_arg="l"
fi
# -l to save space (hard link) and -f to overwrite the mktemp file
# symbolic link when using SSHFS or cp -l errors out (different mounts)
if [[ "$symbolic" == "1" || "$sshfs" == "1" ]]; then
ln -sf -- "$(realpath "$input")" "$local_directory"/"$output_name""$extension"
else
cp -f$hard_link_arg -- "$input" "$local_directory"/"$output_name""$extension"
# When creating new copies, process the files (if set)
if [[ -z "$hard_link_arg" && "$post_process" == "1" ]]; then
full_output_path="$local_directory/$output_name$extension"
post_process
fi
fi
}
# Provides URL to output file
share ()
{
url="$url_format"/"$output_name""$extension"
# Add trailing slash to URL if it created a symbolic link and is missing
if [[ "$file_mime_type" == *"directory"* && "$symbolic" = "1" && "$url" != */ ]]; then
url="$url"/
fi
# Send URL to push notification services
if [ "$push" = 1 ]; then
if [[ -n "$pushbullet_token" ]]; then
curl -s --header 'Authorization: Bearer '$pushbullet_token'' -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "link", "title": "'"$input"\ \("$output_name""$extension"\)'", "body": "'"$url"'", "url": "'"$url"'"}' > /dev/null
fi
if [[ -n "$pushover_key" ]]; then
curl -s \
--form-string "token=ajcRHNs9uX3wv2AQiypwcw8sKamrYH" \
--form-string "user=$pushover_key" \
--form-string "message=$input ($output_name$extension)" \
--form-string "url=$url" \
--form-string "url_title=$output_name$extension" \
https://api.pushover.net/1/messages.json > /dev/null
fi
fi
echo "$url"
# Add url to array to send it to clipboard at the end
urllist+=( "$url" )
}
notify ()
{
if [[ "${#urllist[@]}" -le 1 ]]; then
notify-send ' File uploaded' "$url" --icon=face-wink
else
notify-send " ${#urllist[@]} files uploaded" --icon=face-wink
# Sound notifications, uncomment three lines below
# if hash paplay 2>/dev/null && [[ -f /usr/share/sounds/gnome/default/alerts/glass.ogg ]]; then
# paplay '/usr/share/sounds/gnome/default/alerts/glass.ogg'
# fi
fi
}
clipboard ()
{
# Get links to clipboard depending on the OS
system="$(uname -s)"
# Try to use primary clipboard with xsel
if hash xsel 2>/dev/null; then
{ IFS=$'\n'; printf %s "${urllist[*]}"; } | xsel --input --primary
fi
# If xclip is installed, and you started ssh with "-X", the following line would get the URL on your local clipboard
if [[ "$xclip" == 1 ]] && [[ -n "$DISPLAY" ]] && hash xclip 2>/dev/null; then
{ IFS=$'\n'; printf %s "${urllist[*]}"; } | xclip -selection c
fi
# Windows running Cygwin
if [[ "$system" == *"CYGWIN"* ]]; then
{ IFS=$'\n'; printf %s "${urllist[*]}"; } > /dev/clipboard
fi
# For OSX
if [[ "$system" == *"Darwin"* ]]; then
{ IFS=$'\n'; printf %s "${urllist[*]}"; } | pbcopy
fi
if [[ "$notify" == "1" ]]; then
notify
fi
}
# Remove all files on /nani/ except index.html and the /k/ directory (permanent nani)
cleanup ()
{
find "$local_directory"/ -mindepth 1 ! -name "index.html" ! -name "k" ! -path '*/k/*' -delete
}
# Reset variables. Necessary for when it handles more than 1 file as argument
cleanvar ()
{
add_length=''
extension=''
file_basename=''
file_inode=''
inode_match=''
output_name="$chosen_name"
}
# Display help
showhelp ()
{
echo
echo "Usage: $script_name [options] <infile>"
echo "Provides public URL from input."
echo
echo "Input handling:"
echo " Directory Will be stored using zip (or symbolic link)"
echo " FLAC Can be transcoded to MP3"
echo " Text (html, php...) Extension can be set to .txt"
echo " Other files New copy/hard link/symbolic link at output directory"
echo " URL to video (e.g: youtube) Downloaded using yt-dlp"
echo " Other URLs Downloaded using wget"
echo
echo "Modify the first lines of the script to change how $script_name behaves: quiet mode,"
echo "enabling/disabling transcoding, length of the string, extension truncation..."
echo
echo "Settings and options:"
echo " -a, --alias Revert the hard link setting"
echo " -c, --cleanup Remove all files on /$script_name/ except index.html"
echo " -h, --help Display this help and exit"
echo " -i, --insert Open nano to enter text. Saved in output directory as .txt"
echo " -k, --keep Output dir becomes /$script_name/k/, to set different cleanup rules"
echo " -l, --list List files in output directory /$script_name/"
echo " -n, --name Use custom name (e.g. $script_name -n DesiredName <file>)"
echo " -N, --notify Revert the notify option"
echo " -o, --original Preserve original file name"
echo " -p, --push Send push notification"
echo " -q, --quiet Revert the quiet setting"
echo " -s, --string Force a certain string length (e.g. $script_name -s 32 <file>)"
echo " -t, --transcode Revert the transcode setting"
echo " -x, --xclip Revert the xclip setting"
echo " -y, --symbolic Create a symbolic link for files and directories"
echo
}
while :; do
case $1 in
-a|--alias)
hard_link=$((!hard_link))
;;
-c|--cleanup)
echo "Cleaning up..."
cleanup
echo Done.
exit
;;
-h|-\?|--help) # Call a "showhelp" function to display a synopsis, then exit.
showhelp
exit
;;
-i|--insert)
insert_mode="1"
;;
-k|--keep)
local_directory+="/k"
url_format+="/k"
shift 1
continue
;;
-l|--list)
printf "Files in $local_directory/:\n\n"
ls --color=auto "$local_directory"
extension=".zip"
printf "\nRun $script_name -c or $script_name --cleanup to remove all files except index.html\n"
exit
;;
--name=?*)
output_name=${1#*=} # Delete everything up to "=" and assign the remainder.
chosen_name=${1#*=} # Delete everything up to "=" and assign the remainder.
preserve_name=1
;;
--name=) # Handle the case of an empty --name=
printf 'ERROR: "--name" requires a non-empty option argument.\n' >&2
exit 1
;;
-n|--name) # Takes an option argument, ensuring it has been specified.
if [[ -n "$2" ]]; then
output_name=$2
chosen_name=$2
preserve_name=1
shift 2
continue
else
printf 'ERROR: "-n" requires a non-empty option argument.\n' >&2
exit 1
fi
;;
-N|--notify)
notify=$((!notify))
;;
-o|--original)
preserve_name=1
;;
-p|--push)
push=1
;;
-q|--quiet)
quiet=$((!quiet))
;;
-s|--string) # Takes an option argument, ensuring it has been specified.
if [[ -n "$2" ]]; then
setlength=1
minimum_length="$2"
shift 2
continue
else
printf 'ERROR: "-s" requires a non-empty option argument.\n' >&2
exit 1
fi
;;
--string=?*)
minimum_length=${1#*=} # Delete everything up to "=" and assign the remainder.
setlength=1
;;
--string=) # Handle the case of an empty --length=
printf 'ERROR: "--string" requires a non-empty option argument.\n' >&2
exit 1
;;
-t|--transcode)
transcode=$((!transcode))
;;
-x|--xclip)
xclip=$((!xclip))
;;
-y|--symbolic)
symbolic=1
;;
-?*) # This below allows for grouped options, example: nani -xot File1
if [[ "${#1}" -ge "3" && ${1:1:1} != "-" ]]; then
for (( i=1; i<${#1}; i++ )); do
case ${1:$i:1} in
a)
hard_link=$((!hard_link))
;;
i)
insert_mode="1"
;;
k)
local_directory+="/k"
url_format+="/k"
;;
N)
notify=$((!notify))
;;
o)
preserve_name=1
;;
p)
push=1
;;
q)
quiet=$((!quiet))
;;
t)
transcode=$((!transcode))
;;
x)
xclip=$((!xclip))
;;
y)
symbolic=1
continue
;;
?*)
ignored_options="$ignored_options""${1:$i:1}"
;;
*)
break
esac
done
if [[ -n "$ignored_options" ]]; then
printf 'WARN: Unknown options (ignored): %s\n' "$ignored_options" >&2
fi
else
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
fi
shift 1
continue
;;
--) # End of all options.
shift
break
;;
*) # Default case: If no more options then break out of the loop.
break
esac
shift
done
# Create the directory where the files will go, in your public folder
mkdir -p -- "$local_directory" || exit
# Create index.html in the output folder, to avoid directory listing
if ! [[ -a "$local_directory"/index.html ]]; then
#touch "$local_directory"/index.html
echo '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>nani - Easily Share Remote Files</title><style>body,html{margin:0;padding:0;height:100%;font-family:Roboto,sans-serif;background-color:#f0f0f0;display:flex;justify-content:center;align-items:center}.container{max-width:800px;margin:0 auto;padding:2rem;text-align:center}a{color:#3399d0;text-decoration:none;border-bottom:2px solid #3399d0;padding:2px}a:hover{background-color:#3399d0;color:#fff}</style></head><body><div class="container"><h1>nani - Easily Share Remote Files</h1><p>nani is a Bash script that allows you to easily share files on your server. Create public URLs from files or text on remote servers with a simple command.</p><p><a href="https://github.com/welpo/nani" target="_blank">View the Project on GitHub — welpo/nani</a></p></div></body></html>' > "$local_directory/index.html"
fi
# Check settings have valid values
# Checking $length is an integer and is between 1 and 250
if ! [[ "$minimum_length" =~ ^[0-9]+$ ]]; then
echo "length value is \"$length\", which is not an integer."
echo "Fix it and try again."
exit 1
fi
if ! [[ "$minimum_length" -ge 1 && "$length" -le 250 ]]; then
echo "The value set for length is not valid."
echo "It must be a number between 1 and 250."
exit 1
fi
# Checking $random_length is an integer and is between 1 and 250
if [[ -n "$random_length" ]]; then
if ! [[ "$random_length" =~ ^[0-9]+$ ]]; then
echo "random_length value is \"$random_length\", which is not an integer."
echo "Fix it and try again."
exit 1
fi
if ! [[ "$random_length" -ge 1 && "$random_length" -le 250 ]]; then
echo "The value set for random_length is not valid."
echo "It must be a number between 1 and 250."
exit 1
fi
fi
# Checking if $pushbulletkey is valid
if [[ -n "$pushbulletkey" ]]; then
if ! [[ "$pushbulletkey" =~ ^[a-zA-Z0-9]+$ ]]; then
echo "The value set for \$pushbulletkey is not valid. Fix it or leave it empty."
exit 1
fi
fi
# Checking if $pushover_key is valid
if [[ -n "$pushover_key" ]]; then
if ! [[ "$pushover_key" =~ ^[a-zA-Z0-9]+$ ]]; then
echo "The value set for \$pushover_key is not valid. Fix it or leave it empty."
exit 1
fi
fi
# Checking if $quiet is either 0 or 1
if [[ $quiet != [01] ]]; then
echo "The value set for quiet is not valid. It must be either 1 or 0."
exit 1
fi
# Checking if $add_txt is an integer and either 0 or 1
if [[ $add_txt != [01] ]]; then
echo "The value set for add_txt is not valid. It must be either 1 or 0"
exit 1
fi
# Checking if $modify_text is an integer and either 0 or 1
if [[ $modify_text != [01] ]]; then
echo "The value set for modify_text is not valid. It must be either 1 or 0."
exit 1
fi
# Checking if $transcode is an integer and either 0 or 1
if [[ $transcode != [01] ]]; then
echo "The value set for \$transcode is not valid. It must be either 0 or 1."
exit 1
fi
# Checking if $xclip is an integer and either 0 or 1
if [[ $xclip != [01] ]]; then
echo "The value set for \$xclip is not valid. It must be either 0 or 1."
exit 1
fi
# Set notify to 0 if notify-send is not installed
if ! hash notify-send 2>/dev/null; then
notify=0
fi
# Insert mode:
if [[ "$insert_mode" == 1 ]]; then
extension=.txt
random
nano -t -- "$local_directory"/"$output_name""$extension" || exit
# Check file contains something (meaning nano wasn't closed immediately without inputting text)
if [[ ! -s "$local_directory/$output_name$extension" ]]; then
rm "$local_directory/$output_name$extension" && exit
fi
# vim "$local_directory"/"$output_name""$extension"
# cat > "$local_directory"/"$output_name""$extension"
# Check output actually exists, just in case nano is closed before entering text
sleep 10
[[ ! -f "$local_directory"/"$output_name""$extension" ]] && exit 1
share
clipboard
exit
fi
# Check if input comes from stdin, if so, just cat input to /nani/
if ! [[ -t 0 ]]; then
# Store file somewhere first to check its extension
cat_mktemp=$(mktemp)
cat > "$cat_mktemp"
# Set the extension reading the --mime-type and comparing it to /etc/mime.types
extension=.$(grep "$(file -b --mime-type $cat_mktemp)" /etc/mime.types | awk '{print $2}' | cut -d$'\n' -f1)
# Handle some exceptions
if [[ "$extension" == "." ]]; then printf '%s\n' "Nothing to do." && exit 1; fi
if [[ "$extension" == ".mpga" ]]; then extension=.mp3; fi
if [[ "$extension" == ".asc" ]]; then extension=.txt; fi
if [[ "$extension" == ".plain" ]]; then extension=.txt; fi
random
cp -f -- "$cat_mktemp" "$local_directory/$output_name$extension"
rm -- "$cat_mktemp"
share
clipboard
exit
elif [[ "$#" -lt 1 ]]; then
printf "Usage:\n $script_name [options] <infile>\n\nFor more information try\n $script_name --help\n"
exit 1
fi
for input in "$@"; do
# Start with clean variables
cleanvar
# Check if input is valid (file/directory exists). If it doesn't, is it a URL?
if [[ ! -e "$input" ]]; then
if [[ "$input" == http?(s)://* ]]; then
# Chek if URL is from a site supported by yt-dlp, if it is, grab the file and output it to /nani/
if [[ "$input" == *@(abc.|abc7news.|academicearth.|acast.|addanime.|adobetv.|adultswim.|aftenposten.|aftonbladet.|airmozilla.|aljazeera.|alphaporno.|anitube.|anysex.|aol.|allocine.|aparat.|appleconnect.|appletrailers.|archiveorg.|ard.|arte.|atresplayer.|atttechchannel.|audimedia.|audiomack.|azubu.|baidu.|bambuser.|bandcamp.|bbc.|beeg.|behindkink.|beatportpro.|bet.|bild.|bilibili.|blinkx.|bliptv.|bloomberg.|bpb.|br.|breakcom.|brightcove.|buzzfeed.|byutv.|c56.|camdemy.|canal13cl.|canalplus.|canalc2.|cbs.|cbsnews.|cbssports.|ccc.|ceskatelevize.|channel9.|chaturbate.|chilloutzone.|chirbit.|cinchcast.|cinemassacre.|clipfish.|cliphunter.|clipsyndicate.|cloudy.|clubic.|clyp.|cmt.|cnet.|cnn.|collegehumor.|collegerama.|comedycentral.|comcarcoff.|commonmistakes.|condenast.|cracked.|criterion.|crooksandliars.|crunchyroll.|cspan.|ctsnews.|dailymotion.|daum.|dbtv.|dcn.|dctp.|deezer.|democracynow.|dfb.|dhm.|dotsub.|douyutv.|dplay.|dramafever.|dreisat.|drbonanza.|drtuber.|drtv.|dvtv.|dump.|dumpert.|defense.|discovery.|dropbox.|eagleplatform.|ebaumsworld.|echomsk.|ehow.|eighttracks.|einthusan.|eitb.|ellentv.|elpais.|embedly.|engadget.|eporner.|eroprofile.|escapist.|espn.|esri.|europa.|everyonesmixtape.|exfm.|expotv.|extremetube.|facebook.|faz.|fc2.|fczenit.|firstpost.|firsttv.|fivemin.|fivetv.|fktv.|flickr.|folketinget.|footyroom.|fourtube.|foxgay.|foxnews.|foxsports.|franceculture.|franceinter.|francetv.|freesound.|freespeech.|freevideo.|funimation.|funnyordie.|gameinformer.|gamekings.|gameone.|gamersyde.|gamespot.|gamestar.|gametrailers.|gazeta.|gdcvault.|generic.|gfycat.|giantbomb.|gyfcat.|giga.|glide.|globo.|godtube.|goldenmoustache.|golem.|googleplus.|googlesearch.|goshgay.|groupon.|hark.|hearthisat.|heise.|hellporno.|helsinki.|hentaistigma.|historicfilms.|history.|hitbox.|hornbunny.|hotnewhiphop.|howcast.|howstuffworks.|huffpost.|hypem.|iconosquare.|ign.|imdb.|imgur.|ina.|indavideo.|infoq.|instagram.|internetvideoarchive.|iprima.|iqiyi.|ir90tv.|itunes.apple|ivi.|izlesene.|jadorecettepub.|jeuxvideo.|jove.|jukebox.|jpopsukitv.|kaltura.|kanalplay.|kankan.|karaoketv.|karrierevideos.|keezmovies.|khanacademy.|kickstarter.|keek.|kontrtube.|krasview.|ku6.|kuwo.|la7.|laola1tv.|lecture2go.|letv.|libsyn.|lifenews.|limelight.|liveleak.|livestream.|lnkgo.|lrt.|lynda.|m6.|macgamestore.|mailru.|malemotion.|mdr.|metacafe.|metacritic.|mgoon.|minhateca.|ministrygrid.|miomio.|mit.|mitele.|mixcloud.|mlb.|mpora.|moevideo.|mofosex.|mojvideo.|moniker.|mooshare.|morningstar.|motherless.|motorsport.|movieclips.|moviezine.|mtv.|muenchentv.|musicplayon.|muzu.|mwave.|myspace.|myspass.|myvi.|myvideo.|myvidster.|nationalgeographic.|naver.|nba.|nbc.|ndr.|ndtv.|netzkino.|nerdcubed.|nerdist.|neteasemusic.|newgrounds.|newstube.|nextmedia.|nfb.|nfl.|nhl.|niconico.|ninegag.|noco.|normalboots.|nosvideo.|nova.|novamov.|nowness.|nowtv.|npo.|nrk.|ntvde.|ntvru.|nytimes.|nuvid.|odnoklassniki.|oktoberfesttv.|onionstudios.|ooyala.|orf.|parliamentliveuk.|patreon.|pbs.|periscope.|philharmoniedeparis.|phoenix.|photobucket.|pinkbike.|planetaplay.|pladform.|played.|playfm.|playtvak.|playvid.|playwire.|pluralsight.|podomatic.|porn91.|pornhd.|pornhub.|pornotube.|pornovoisines.|pornoxo.|primesharetv.|promptfile.|prosiebensat1.|puls4.|pyvideo.|qqmusic.|quickvid.|r7.|radiode.|radiojavan.|radiobremen.|radiofrance.|rai.|rbmaradio.|rds.|redtube.|restudy.|reverbnation.|ringtv.|ro220.|rottentomatoes.|roxwel.|rtbf.|rte.|rtlnl.|rtl2.|rtp.|rts.|rtve.|rtvnh.|ruhd.|rutube.|rutv.|ruutu.|sandia.|safari.|sapo.|savemport SaveFromIE.|sbs.|scivee.|screencast.|screencastomatic.|screenwavemedia.|senateisvp.|servingsys.|sexu.|sexykarma.|shahid.|shared.|sharesix.|sina.|skynewsarabia.|slideshare.|slutload.|smotri.|snagfilms.|snotr.|sohu.|soompi.|soundcloud.|soundgasm.|southpark.|space.|spankbang.|spankwire.|spiegel.|spiegeltv.|spike.|stitcher.|sport5.|sportbox.|sportdeutschland.|srf.|srmediathek.|ssa.|stanfordoc.|steam.|streamcloud.|streamcz.|streetvoice.|sunporno.|svt.|swrmediathek.|syfy.|sztvhu.|tagesschau.|tapely.|tass.|teachertube.|teachingchannel.|teamcoco.|techtalks.|ted.|telebruxelles.|telecinco.|telegraaf.|telemb.|teletask.|tenplay.|testurl.|testtube.|tf1.|theonion.|theplatform.|thesixtyone.|thisamericanlife.|thisav.|tinypic.|tlc.|tmz.|tnaflix.|thvideo.|toutv.|toypics.|traileraddict.|trilulilu.|trutube.|tube8.|tubitv.|tudou.|tumblr.|tunein.|turbo.|tutv.|tv2.|tv4.|tvc.|tvigle.|tvp.|tvplay.|tweakers.|twentyfourvideo.|twentytwotracks.|twitch.|twitter.|ubu.|udemy.|udn.|ultimedia.|unistra.|urort.|ustream.|varzesh3.|vbox7.|veehd.|veoh.|vessel.|vesti.|vevo.|vgtv.|vh1.|vice.|viddler.|videodetective.|videofyme.|videomega.|videopremium.|videott.|vidme.|vidzi.|vier.|viewster.|viidea.|vimeo.|vimple.|vine.|viki.|vk.|vlive.|vodlocker.|voicerepublic.|vporn.|vrt.|vube.|vuclip.|vulture.|walla.|washingtonpost.|wat.|wayofthemaster.|wdr.|webofstories.|weibo.|wimp.|wistia.|worldstarhiphop.|wrzuta.|wsj.|xbef.|xboxclips.|xfileshare.|xhamster.|xminus.|xnxx.|xstream.|xtube.|xuite.|xvideos.|xxxymovies.|yahoo.|yam.|yandexmusic.|yesjapan.|yinyuetai.|ynet.|youjizz.|youku.|youporn.|yourupload.|youtu.be|youtube.|zapiks.|zdf.|zingmp3.)* ]]; then
ytfn=$(yt-dlp --get-filename "$input") || continue
extension=".${ytfn##*.}"
if [[ -n "$preserve_name" ]]; then
output_name="${ytfn%.*}"
output_name="${output_name// /_}"
else
random
fi
if [[ "$quiet" == 1 ]]; then
ytquiet="q"
fi
yt-dlp -"$ytquiet"o - "$input" > "$local_directory"/"$output_name""$extension" || continue
share
continue
fi
mapfile -t http < <(wget --spider -S --quiet "$input" 2>&1)
# Check HTTP status is 200 OK.
if ! [[ "${http[*]}" == *@(1.1 200|302 Found|1.1 302 Moved Temporarily)* ]]; then echo Something went wrong. Check your link and try again.; continue; fi
for i in "${http[@]}"; do if [[ $i = *"Content-Type: "* ]]; then file_mime_type="${i##*/}"; break; fi; done
if [[ "$file_mime_type" == *";"* ]]; then
extension=.${file_mime_type%%;*}
else
extension=."$file_mime_type"
fi
random
if [[ $quiet == 1 ]]; then
wgetquiet="q"
fi
wget --no-use-server-timestamps -"$wgetquiet"O "$local_directory"/"$output_name""$extension" "$input"
share
continue
fi
echo "File doesn't exist! Skipping."
continue
fi
# Check if /nani/ already contains a hard link to input to provide URL directly
if [[ -z "$output_name" ]]; then
file_inode=$(ls -id -- "$input" | cut -f1 -d " ")
inode_match=$(find "$local_directory" -maxdepth 1 -mindepth 1 -type f -inum "$file_inode" -exec basename {} \; -quit)
if [[ -n "$inode_match" ]]; then
# When using -n or -o, ignore the inode match unless name is the same
if [[ -z "$preserve_name" || "$inode_match" == $(basename -- "$input") ]]; then
output_name="$inode_match"
extension=''
share
continue
fi
fi
fi
# Store filename, the mime-type and extension
# Only store extension if input is not a directory
if ! [ -d "$input" ]; then
extension=".${input##*.}"
fi
file_mime_type="$(file --mime-type "$input")"
file_mime_type="${file_mime_type##* }"
if [[ ."$input" == "$extension" ]]; then
extension=""
fi
# If file has no extension and enabled on the settings, use .txt
if [[ "$extension" == "" && "$add_txt" == 1 && ! "$file_mime_type" == *@(directory|symlink)* ]]; then
extension=".txt"
fi
# If filetype contains text and enabled on the settings (and is not already .txt), use .txt as extension
if [[ "$file_mime_type" == *"text"* && "$modify_text" = "1" && "$extension" != ".txt" ]]; then
extension=".txt"
fi
# Check if it's a directory. If so, send arguments to zip or create symbolic link
# Note it will use -0 as argument, which will not compress the data
if [[ "$file_mime_type" == *@(directory|symlink)* ]]; then
if [[ "$symbolic" != "1" ]]; then
# Check if zip is installed
hash zip 2>/dev/null || { echo >&2 "zip is not installed. Use symbolic links or install it. Aborting."; continue; }
extension=".zip"
random
if [[ "$quiet" == 1 ]]; then
zq=" -q"
fi
# cd into the directory to avoid copying the entire structure
cd "$input"
# Remove trailing slashes to avoid problems with zip and parameter expansion
if [[ "${input: -1}" == "/" ]]; then
input=$(echo "$input" | rev | cut -c 2- | rev)
fi
zip -r0$zq - -- "../${input##*/}" > "$local_directory"/"$output_name""$extension" || continue
cd - > /dev/null
else
extension=""
random
ln -fs -- "$PWD"/"$input" "$local_directory"/"$output_name"
fi
share
continue
fi
if [[ "$file_mime_type" == *"flac"* && "$transcode" = "1" ]]; then
# Check for dependencies metaflac, flac and lame
hash metaflac 2>/dev/null || { echo >&2 "Transcoding requires metaflac but it's not installed. Aborting."; continue; }
hash flac 2>/dev/null || { echo >&2 "Transcoding requires flac but it's not installed. Aborting."; continue; }
hash lame 2>/dev/null || { echo >&2 "Transcoding requires lame but it's not installed. Aborting."; continue; }
extension=".mp3"
random
# Get the tags
ARTIST=$(metaflac "$input" --show-tag=ARTIST | sed s/.*=//g)
TITLE=$(metaflac "$input" --show-tag=TITLE | sed s/.*=//g)
ALBUM=$(metaflac "$input" --show-tag=ALBUM | sed s/.*=//g)
GENRE=$(metaflac "$input" --show-tag=GENRE | sed s/.*=//g)
TRACKNUMBER=$(metaflac "$input" --show-tag=TRACKNUMBER | sed s/.*=//g)
DATE=$(metaflac "$input" --show-tag=DATE | sed s/.*=//g)
# Stream flac into the lame encoder, using -s and --quiet for the arguments if quiet mode is enabled:
if [[ "$quiet" == 1 ]]; then
qf="-s"
ql="--quiet "
fi
flac -c -d "$qf" -- "$input" | lame -V0 --vbr-new --add-id3v2 --pad-id3v2 $ql--ignore-tag-errors\
--ta "$ARTIST" --tt "$TITLE" --tl "$ALBUM" --tg "${GENRE:-12}" \
--tn "${TRACKNUMBER:-0}" --ty "$DATE" - "$local_directory"/"$output_name""$extension" || continue
share
continue
else
random
copy
share
fi
done
if [[ -n "$urllist" ]]; then
clipboard
fi