~cszikszoy/do-plugins/fix-confluence

« back to all changes in this revision

Viewing changes to Riptide/src/TorrentSearchAction.cs

Start cleanup of WindowManager
Add riptide plugin.  Downloads dem torrents!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// TorrentSearchAction.cs
 
2
//
 
3
//GNOME Do is the legal property of its developers. Please refer to the
 
4
//COPYRIGHT file distributed with this
 
5
//source distribution.
 
6
//
 
7
// This program is free software; you can redistribute it and/or modify
 
8
// it under the terms of the GNU General Public License as published by
 
9
// the Free Software Foundation; either version 2 of the License, or
 
10
// (at your option) any later version.
 
11
//
 
12
// This program is distributed in the hope that it will be useful,
 
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
15
// GNU General Public License for more details.
 
16
// 
 
17
// You should have received a copy of the GNU General Public License
 
18
// along with this program; if not, write to the Free Software
 
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
20
//
 
21
//
 
22
 
 
23
using System;
 
24
using System.Collections.Generic;
 
25
using System.IO;
 
26
using System.Web;
 
27
using System.Net;
 
28
using System.Text.RegularExpressions;
 
29
using System.Xml;
 
30
 
 
31
using Do.Universe;
 
32
 
 
33
namespace Do.Riptide
 
34
{
 
35
        
 
36
        
 
37
        public class TorrentSearchAction : AbstractAction
 
38
        {
 
39
                
 
40
                public TorrentSearchAction()
 
41
                {
 
42
 
 
43
                }
 
44
                
 
45
                public override string Name {
 
46
                        get { return "Search For Torrents"; }
 
47
                }
 
48
 
 
49
                public override string Description {
 
50
                        get { return "Search the internet for torrents"; }
 
51
                }
 
52
                
 
53
                public override string Icon {
 
54
                        get { return "gnome-searchtool"; }
 
55
                }
 
56
 
 
57
                public override Type[] SupportedItemTypes {
 
58
                        get { return new Type[] { typeof (ITextItem) }; }
 
59
                }
 
60
 
 
61
                
 
62
                public override IItem[] Perform (IItem[] items, IItem[] modItems)
 
63
                {
 
64
                        List<IItem> outItems;
 
65
                        outItems = new List<IItem> ();
 
66
                        string search;
 
67
                        search = HttpUtility.UrlEncode ((items[0] as ITextItem).Text);
 
68
                        
 
69
                        search = "http://isohunt.com/js/rss/" + search;
 
70
                        
 
71
                        WebClient client = new WebClient ();
 
72
                        Stream stream = client.OpenRead (search);
 
73
                        
 
74
                        XmlDocument xdoc = new System.Xml.XmlDocument ();
 
75
                        xdoc.Load (stream);
 
76
                        
 
77
                        XmlNodeList nodes;
 
78
                        nodes = xdoc.SelectNodes ("/rss/channel/item");
 
79
                        
 
80
                        TorrentResultItem result;
 
81
                        Regex regx;
 
82
                        MatchCollection mc;
 
83
                        string description, seeds, leeches, size;
 
84
                        foreach (XmlNode n in nodes) {
 
85
                                description = n.SelectSingleNode("description").InnerText;
 
86
                                
 
87
                                mc = Regex.Matches (description, "Seeds: [0-9]*");
 
88
                                seeds = mc[0].Value;
 
89
                                
 
90
                                mc = Regex.Matches (description, "Leechers: [0-9]*");
 
91
                                leeches = mc[0].Value;
 
92
                                
 
93
                                mc = Regex.Matches (description, "Size: [0-9]*.[0-9]* MB");
 
94
                                size = mc[0].Value;
 
95
                                
 
96
                                result = new TorrentResultItem (n.SelectSingleNode("title").InnerText);
 
97
                                
 
98
                                result.URL = n.SelectSingleNode("enclosure").Attributes[0].InnerText;
 
99
                                result.Seeds    = Convert.ToInt32 (seeds.Substring (7));
 
100
                                result.Leechers = Convert.ToInt32 (leeches.Substring (10));
 
101
                                result.Size     = size.Substring (6);
 
102
                                
 
103
                                outItems.Add (result);
 
104
                        }
 
105
                        
 
106
                        outItems.Sort ();
 
107
                        
 
108
                        if (outItems.Count == 0) {
 
109
                                outItems.Add (new TextItem ("No Torrent Results Found For " + 
 
110
                                                            (items[0] as ITextItem).Text));
 
111
                        }
 
112
                        
 
113
                        return outItems.ToArray ();
 
114
                }
 
115
 
 
116
        }
 
117
}
 
118
 
 
119
 
 
120
 
 
121
 
 
122
 
 
123
 
 
124
 
 
125
 
 
126
 
 
127
 
 
128