1
// TorrentSearchAction.cs
3
//GNOME Do is the legal property of its developers. Please refer to the
4
//COPYRIGHT file distributed with this
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.
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.
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
24
using System.Collections.Generic;
28
using System.Text.RegularExpressions;
37
public class TorrentSearchAction : AbstractAction
40
public TorrentSearchAction()
45
public override string Name {
46
get { return "Search For Torrents"; }
49
public override string Description {
50
get { return "Search the internet for torrents"; }
53
public override string Icon {
54
get { return "gnome-searchtool"; }
57
public override Type[] SupportedItemTypes {
58
get { return new Type[] { typeof (ITextItem) }; }
62
public override IItem[] Perform (IItem[] items, IItem[] modItems)
65
outItems = new List<IItem> ();
67
search = HttpUtility.UrlEncode ((items[0] as ITextItem).Text);
69
search = "http://isohunt.com/js/rss/" + search;
71
WebClient client = new WebClient ();
72
Stream stream = client.OpenRead (search);
74
XmlDocument xdoc = new System.Xml.XmlDocument ();
78
nodes = xdoc.SelectNodes ("/rss/channel/item");
80
TorrentResultItem result;
83
string description, seeds, leeches, size;
84
foreach (XmlNode n in nodes) {
85
description = n.SelectSingleNode("description").InnerText;
87
mc = Regex.Matches (description, "Seeds: [0-9]*");
90
mc = Regex.Matches (description, "Leechers: [0-9]*");
91
leeches = mc[0].Value;
93
mc = Regex.Matches (description, "Size: [0-9]*.[0-9]* MB");
96
result = new TorrentResultItem (n.SelectSingleNode("title").InnerText);
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);
103
outItems.Add (result);
108
if (outItems.Count == 0) {
109
outItems.Add (new TextItem ("No Torrent Results Found For " +
110
(items[0] as ITextItem).Text));
113
return outItems.ToArray ();