1
proc megauploadparseArgs { string_text } {
2
#element 1 from list = text to search
3
#element 2 from list = number of results to show
4
#element 3 from list = status (ok if everything is ok, else err)
6
#if string starts with " and ends with " there are no other args
7
#elseif string starts with " and has at least one more ". We might have aditional args!
8
#else string isn't well formatted.
9
if { [regexp -- {^".*"$} $string_text] } {
11
set string_text [string range $string_text 1 end]
13
set string_text [string range $string_text 0 [expr [string length $string_text] - 2]]
14
set arguments [list $string_text $::jake::config(nresultsmegaupload) "ok"]
15
} elseif { [regexp -- {^".*"} $string_text] } {
16
#search for the first index of "
17
set first_index [string first \" $string_text]
18
#search for the last index of "
19
set last_index [string last \" $string_text]
20
#get the number of results to show and remove spaces
21
set number_of_results [string range $string_text [expr $last_index + 1] [string length $string_text]]
22
regsub -all { +} $number_of_results {} number_of_results
23
#get the string between "
24
set string_text [string range $string_text 1 [expr $last_index - 1]]
25
#check if the string containing the number of results is integer
26
if { [string is integer -strict $number_of_results] } {
27
set arguments [list $string_text $number_of_results "ok"]
29
set arguments [list "" 0 "err"]
32
set arguments [list "" 0 "err"]
37
proc megauploadsearch { string_text number_of_results} {
45
while { $count <= $number_of_results } {
46
set query [httpformatQuery q $string_text page $page]
47
set token [::http::geturl http://4megaupload.com/index.php?$query -timeout 8000]
48
set ncode [::http::ncode $token]
49
set data [::http::data $token]
50
::http::cleanup $token
52
set matches [regexp -all -inline {<a href=\"download_file.*?</span><br></td>} $data]
53
foreach match $matches {
54
regexp {<a href=\"download_file.php?(.*?)\".*?title=\'(.*?)\'.*?>.*?>.*?>(.*?)</span>} $match => url title size
55
regsub -all {[ \r\t\n]+} $size "" size
56
regsub -all {/url\?q=} $url "" url
57
regsub -all { +} $url "" url
58
if { [info exists title] == 1 } {
61
if { $count <= $number_of_results && [info exists title] == 1 && [info exists url] == 1 } {
62
append results $count.\ $title " - " $size " - http://4megaupload.com/download_file.php" $url\n\n
64
if { [info exists results] == 0 } {
68
set results [string range $results 0 [expr [string length $results] - 3]]
b'\\ No newline at end of file'