Skip to content

Commit

Permalink
Add KAT test
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbwlkr committed Jan 23, 2016
1 parent 66dc518 commit b769bb1
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 42 deletions.
25 changes: 25 additions & 0 deletions cmd/magopie/kickasstorrents.go
@@ -0,0 +1,25 @@
package main

import (
"io"

"github.com/gophergala2016/magopie"
)

var kickAssTorrents = site{
Site: magopie.Site{
ID: "kat",
Name: "Kick Ass Torrents",
URL: "https://kat.ph",
Enabled: true,
},
search: func(term string) ([]magopie.Torrent, error) {
// TODO make http request the pass body to katParse()
return nil, nil
},
}

func katParse(r io.Reader) ([]magopie.Torrent, error) {
// TODO implement
return nil, nil
}
62 changes: 62 additions & 0 deletions cmd/magopie/kickasstorrents_test.go
@@ -0,0 +1,62 @@
package main

import (
"os"
"reflect"
"testing"

mp "github.com/gophergala2016/magopie"
)

func TestKATParse(t *testing.T) {
data, err := os.Open("testdata/kat_ubuntu.xml")
if err != nil {
t.Fatal("Error opening fixture", err)
}
defer data.Close()

actual, err := katParse(data)

expected := []mp.Torrent{
{
ID: "0C5B427C2F833B09EA0E3DC7C624F6C187125267",
Title: "Ubuntu Linux Go from Beginner to Power User!",
FileURL: "https://torcache.net/torrent/0C5B427C2F833B09EA0E3DC7C624F6C187125267.torrent?title=[kat.cr]ubuntu.linux.go.from.beginner.to.power.user",
SiteID: "kat",
Size: 1137244499,
Seeders: 85,
Leechers: 105,
},
{
ID: "21236117B7A773639BD5C7C771E66A045BD51A8A",
Title: "Learning Ubuntu Linux Server",
FileURL: "https://torcache.net/torrent/21236117B7A773639BD5C7C771E66A045BD51A8A.torrent?title=[kat.cr]learning.ubuntu.linux.server",
SiteID: "kat",
Size: 581653341,
Seeders: 48,
Leechers: 12,
},
{
ID: "13DBA979D53F20E6A73D4EE939952D1C367B64C7",
Title: "CodeWeavers Crossover 15.0.1 with crack for ubuntu fedora linux",
FileURL: "https://torcache.net/torrent/13DBA979D53F20E6A73D4EE939952D1C367B64C7.torrent?title=[kat.cr]codeweavers.crossover.15.0.1.with.crack.for.ubuntu.fedora.linux",
SiteID: "kat",
Size: 240330669,
Seeders: 1,
Leechers: 1,
},
{
ID: "EB7B040141407F150E32FF366CD624403387B5C1",
Title: "Ubuntu 16.04 (Xenial Xerus) Alpha Desktop AMD64 (64-bit PC)",
FileURL: "https://torcache.net/torrent/EB7B040141407F150E32FF366CD624403387B5C1.torrent?title=[kat.cr]ubuntu.16.04.xenial.xerus.alpha.desktop.amd64.64.bit.pc",
SiteID: "kat",
Size: 1480048640,
Seeders: 1,
Leechers: 3,
},
}

if !reflect.DeepEqual(actual, expected) {
t.Errorf("tpbParse actual = %v\nexpected %v", actual, expected)
}
}
60 changes: 28 additions & 32 deletions cmd/magopie/main_test.go
Expand Up @@ -127,14 +127,13 @@ func TestGetTorrents(t *testing.T) {
termA = term
return []mp.Torrent{
{
ID: "torrent1",
Title: "ubuntu 1",
FileURL: "http://sitea/torrent1",
SiteID: "a",
Description: "torrent a",
Seeders: 10,
Leechers: 50,
Size: 1234567,
ID: "torrent1",
Title: "ubuntu 1",
FileURL: "http://sitea/torrent1",
SiteID: "a",
Seeders: 10,
Leechers: 50,
Size: 1234567,
},
}, nil
},
Expand All @@ -149,14 +148,13 @@ func TestGetTorrents(t *testing.T) {
termB = term
return []mp.Torrent{
{
ID: "torrentB",
Title: "ubuntu 2",
FileURL: "http://siteb/torrentB",
SiteID: "b",
Description: "torrent b",
Seeders: 20,
Leechers: 80,
Size: 7654321,
ID: "torrentB",
Title: "ubuntu 2",
FileURL: "http://siteb/torrentB",
SiteID: "b",
Seeders: 20,
Leechers: 80,
Size: 7654321,
},
}, nil
},
Expand Down Expand Up @@ -201,24 +199,22 @@ func TestGetTorrents(t *testing.T) {

expected := []map[string]interface{}{
{
"ID": "torrent1",
"Title": "ubuntu 1",
"FileURL": "http://sitea/torrent1",
"SiteID": "a",
"Description": "torrent a",
"Seeders": float64(10),
"Leechers": float64(50),
"Size": float64(1234567),
"ID": "torrent1",
"Title": "ubuntu 1",
"FileURL": "http://sitea/torrent1",
"SiteID": "a",
"Seeders": float64(10),
"Leechers": float64(50),
"Size": float64(1234567),
},
{
"ID": "torrentB",
"Title": "ubuntu 2",
"FileURL": "http://siteb/torrentB",
"SiteID": "b",
"Description": "torrent b",
"Seeders": float64(20),
"Leechers": float64(80),
"Size": float64(7654321),
"ID": "torrentB",
"Title": "ubuntu 2",
"FileURL": "http://siteb/torrentB",
"SiteID": "b",
"Seeders": float64(20),
"Leechers": float64(80),
"Size": float64(7654321),
},
}
if !reflect.DeepEqual(actual, expected) {
Expand Down
75 changes: 75 additions & 0 deletions cmd/magopie/testdata/kat_ubuntu.xml
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:torrent="//kastatic.com/xmlns/0.1/">
<channel>
<title>Torrents by keyword "ubuntu" - KickassTorrents</title>
<link>http://kat.cr/</link>
<description>Torrents by keyword "ubuntu"</description>
<item>
<title>Ubuntu Linux Go from Beginner to Power User!</title>

<category>Other - Tutorials</category>
<author>http://kat.cr/user/trancedude/</author>
<link>http://kat.cr/ubuntu-linux-go-from-beginner-to-power-user-t11946299.html</link>
<guid>http://kat.cr/ubuntu-linux-go-from-beginner-to-power-user-t11946299.html</guid>
<pubDate>Fri, 22 Jan 2016 12:01:18 +0000</pubDate>
<torrent:contentLength>1137244499</torrent:contentLength>
<torrent:infoHash>0C5B427C2F833B09EA0E3DC7C624F6C187125267</torrent:infoHash>
<torrent:magnetURI><![CDATA[magnet:?xt=urn:btih:0C5B427C2F833B09EA0E3DC7C624F6C187125267&dn=ubuntu+linux+go+from+beginner+to+power+user&tr=udp%3A%2F%2Ftracker.publicbt.com%2Fannounce&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce]]></torrent:magnetURI>
<torrent:seeds>85</torrent:seeds>
<torrent:peers>190</torrent:peers>
<torrent:verified>1</torrent:verified>
<torrent:fileName>ubuntu.linux.go.from.beginner.to.power.user.torrent</torrent:fileName>
<enclosure url="https://torcache.net/torrent/0C5B427C2F833B09EA0E3DC7C624F6C187125267.torrent?title=[kat.cr]ubuntu.linux.go.from.beginner.to.power.user" length="1137244499" type="application/x-bittorrent" />
</item>
<item>
<title>Learning Ubuntu Linux Server</title>

<category>Other - Tutorials</category>
<author>http://kat.cr/user/trancedude/</author>
<link>http://kat.cr/learning-ubuntu-linux-server-t11925363.html</link>
<guid>http://kat.cr/learning-ubuntu-linux-server-t11925363.html</guid>
<pubDate>Mon, 18 Jan 2016 14:41:29 +0000</pubDate>
<torrent:contentLength>581653341</torrent:contentLength>
<torrent:infoHash>21236117B7A773639BD5C7C771E66A045BD51A8A</torrent:infoHash>
<torrent:magnetURI><![CDATA[magnet:?xt=urn:btih:21236117B7A773639BD5C7C771E66A045BD51A8A&dn=learning+ubuntu+linux+server&tr=udp%3A%2F%2Ftracker.publicbt.com%2Fannounce&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce]]></torrent:magnetURI>
<torrent:seeds>48</torrent:seeds>
<torrent:peers>60</torrent:peers>
<torrent:verified>1</torrent:verified>
<torrent:fileName>learning.ubuntu.linux.server.torrent</torrent:fileName>
<enclosure url="https://torcache.net/torrent/21236117B7A773639BD5C7C771E66A045BD51A8A.torrent?title=[kat.cr]learning.ubuntu.linux.server" length="581653341" type="application/x-bittorrent" />
</item>
<item>
<title>CodeWeavers Crossover 15.0.1 with crack for ubuntu fedora linux</title>

<category>Applications - Linux</category>
<author>http://kat.cr/user/dawnchou/</author>
<link>http://kat.cr/codeweavers-crossover-15-0-1-with-crack-for-ubuntu-fedora-linux-t11906286.html</link>
<guid>http://kat.cr/codeweavers-crossover-15-0-1-with-crack-for-ubuntu-fedora-linux-t11906286.html</guid>
<pubDate>Thu, 14 Jan 2016 21:40:33 +0000</pubDate>
<torrent:contentLength>240330669</torrent:contentLength>
<torrent:infoHash>13DBA979D53F20E6A73D4EE939952D1C367B64C7</torrent:infoHash>
<torrent:magnetURI><![CDATA[magnet:?xt=urn:btih:13DBA979D53F20E6A73D4EE939952D1C367B64C7&dn=codeweavers+crossover+15+0+1+with+crack+for+ubuntu+fedora+linux&tr=udp%3A%2F%2Ftracker.publicbt.com%2Fannounce&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce]]></torrent:magnetURI>
<torrent:seeds>1</torrent:seeds>
<torrent:peers>2</torrent:peers>
<torrent:verified>0</torrent:verified>
<torrent:fileName>codeweavers.crossover.15.0.1.with.crack.for.ubuntu.fedora.linux.torrent</torrent:fileName>
<enclosure url="https://torcache.net/torrent/13DBA979D53F20E6A73D4EE939952D1C367B64C7.torrent?title=[kat.cr]codeweavers.crossover.15.0.1.with.crack.for.ubuntu.fedora.linux" length="240330669" type="application/x-bittorrent" />
</item>
<item>
<title>Ubuntu 16.04 (Xenial Xerus) Alpha Desktop AMD64 (64-bit PC)</title>

<category>Applications - Linux</category>
<author>http://kat.cr/user/hun7er/</author> <link>http://kat.cr/ubuntu-16-04-xenial-xerus-alpha-desktop-amd64-64-bit-pc-t11905044.html</link>
<guid>http://kat.cr/ubuntu-16-04-xenial-xerus-alpha-desktop-amd64-64-bit-pc-t11905044.html</guid>
<pubDate>Thu, 14 Jan 2016 16:33:46 +0000</pubDate>
<torrent:contentLength>1480048640</torrent:contentLength>
<torrent:infoHash>EB7B040141407F150E32FF366CD624403387B5C1</torrent:infoHash>
<torrent:magnetURI><![CDATA[magnet:?xt=urn:btih:EB7B040141407F150E32FF366CD624403387B5C1&dn=ubuntu+16+04+xenial+xerus+alpha+desktop+amd64+64+bit+pc&tr=udp%3A%2F%2Ftracker.publicbt.com%2Fannounce&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce]]></torrent:magnetURI>
<torrent:seeds>1</torrent:seeds>
<torrent:peers>4</torrent:peers>
<torrent:verified>0</torrent:verified>
<torrent:fileName>ubuntu.16.04.xenial.xerus.alpha.desktop.amd64.64.bit.pc.torrent</torrent:fileName>
<enclosure url="https://torcache.net/torrent/EB7B040141407F150E32FF366CD624403387B5C1.torrent?title=[kat.cr]ubuntu.16.04.xenial.xerus.alpha.desktop.amd64.64.bit.pc" length="1480048640" type="application/x-bittorrent" />
</item>
</channel>
</rss>
17 changes: 7 additions & 10 deletions torrent.go
Expand Up @@ -5,16 +5,13 @@ import "fmt"
// A Torrent is an individual result from a search operation representing a
// single torrent file.
type Torrent struct {
ID string
Title string
FileURL string
SiteID string

// Fields we hopefully can populate
Description string
Seeders int
Leechers int
Size int
ID string
Title string
FileURL string
SiteID string
Seeders int
Leechers int
Size int
}

// TorrentCollection is a collection of torrents because gomobile can't
Expand Down

0 comments on commit b769bb1

Please sign in to comment.