~ubuntu-branches/ubuntu/saucy/amsn/saucy

« back to all changes in this revision

Viewing changes to plugins/jake/megaupload.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2010-04-13 23:21:29 UTC
  • mfrom: (1.1.11 upstream) (3.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100413232129-vgpx20brdd2qavs7
Tags: 0.98.3-0ubuntu1
* Merge from Debian unstable (LP: #449072), remaining Ubuntu changes:
  - add 08_use_aplay_for_sound.dpatch patch by Festor Wailon Dacoba to use
    aplay to play sounds
  + debian/control:
    - modify iceweasel to firefox | abrowser in amsn Suggests field
    - add xdg-utils and gstreamer0.10-nice to amsn Depends field
    - mofify sox to alsa-utils in amsn Suggests field as we are now using
      aplay
* New upstream release (LP: #562619), tarball repacked according to
  debian/README.source.
* Fix missing-debian-source-format lintian warning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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) 
 
5
 
 
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] } {
 
10
        #remove first char
 
11
        set string_text [string range $string_text 1 end]
 
12
        #remove last char
 
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"]
 
28
        } else {
 
29
            set arguments [list "" 0 "err"]
 
30
        }
 
31
    } else {
 
32
        set arguments [list "" 0 "err"]
 
33
    }
 
34
    return $arguments
 
35
}
 
36
 
 
37
proc megauploadsearch { string_text number_of_results} {
 
38
    #we need this
 
39
    package require http
 
40
    set page 1
 
41
    set count 0
 
42
    set results ""
 
43
    set matches {}
 
44
    catch {
 
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
 
51
 
 
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 } {
 
59
                    incr count
 
60
                }
 
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
 
63
                } else {
 
64
                    if { [info exists results] == 0 } {
 
65
                        set results noresults
 
66
                    } else {
 
67
                        #remove the last \n\n
 
68
                        set results [string range $results 0 [expr [string length $results] - 3]]
 
69
                    }
 
70
                    return $results
 
71
                }
 
72
            }
 
73
            incr page
 
74
        }
 
75
    }
 
76
    return $results
 
77
}
 
 
b'\\ No newline at end of file'