forked from mcrapet/plowshare-modules-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
embedupload.sh
63 lines (53 loc) · 2.04 KB
/
embedupload.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
# Plowshare embedupload.com module
# Copyright (c) 2013 Plowshare team
#
# This file is part of Plowshare.
#
# Plowshare 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.
#
# Plowshare 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 Plowshare. If not, see <http://www.gnu.org/licenses/>.
MODULE_EMBEDUPLOAD_REGEXP_URL='http://\(www\.\)\?embedupload\.com/'
MODULE_EMBEDUPLOAD_LIST_OPTIONS=""
MODULE_EMBEDUPLOAD_LIST_HAS_SUBFOLDERS=no
# List links from an embedupload link
# $1: embedupload link
# $2: recurse subfolders (ignored here)
# stdout: list of links
embedupload_list() {
local URL=$1
local PAGE LINKS LINK NAME
local -r NOT_AUTHORIZED_PATTERN='not authorized'
if matchi 'embedupload.com/?d=' "$URL"; then
# Handle folders: get all URLs in there and resolve them
PAGE=$(curl "$URL") || return
LINKS=$(parse_all_attr 'class=.DownloadNow.' href <<< "$PAGE") || return
NAME=$(parse 'class=.form-title.' '^[[:space:]]*\([^<]\+\)' 1 <<< "$PAGE")
NAME=${NAME% }
# Sub-link
elif matchi 'embedupload.com/?[[:alpha:]][[:alpha:]]=' "$URL"; then
LINKS=$URL
NAME=$(parse_quiet . '?\(..\)=' <<< "$URL")
else
log_error 'Bad link format'
return $ERR_FATAL
fi
for URL in $LINKS; do
PAGE=$(curl "$URL" | strip_html_comments) || return
# You should click on the download link
LINK=$(parse_tag 'target=' a <<< "$PAGE") || continue
# Ignore URLs we are not authorized for
if ! matchi "$NOT_AUTHORIZED_PATTERN" "$LINK"; then
echo "$LINK"
echo "$NAME"
fi
done
}