aboutsummaryrefslogtreecommitdiff
path: root/meta/torrent.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-06-12 13:42:15 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-06-12 13:42:15 +0200
commit2e9b63801005f3fe9f08255e178ae266ae995b12 (patch)
tree8fab62485e730fc6b8920b4ca2ffd91e84ad26d1 /meta/torrent.go
parent21e5afb61c899cf7dd346807bbc3c025cb1e67f6 (diff)
Print rough info
Diffstat (limited to 'meta/torrent.go')
-rw-r--r--meta/torrent.go97
1 files changed, 96 insertions, 1 deletions
diff --git a/meta/torrent.go b/meta/torrent.go
index 3e8774a..bf57354 100644
--- a/meta/torrent.go
+++ b/meta/torrent.go
@@ -1,6 +1,10 @@
package meta
-import "time"
+import (
+ "fmt"
+ "path"
+ "time"
+)
type File struct {
Length int `bencode:"length"`
@@ -8,6 +12,10 @@ type File struct {
Path []string `bencode:"path"`
}
+func (f File) String() string {
+ return fmt.Sprintf("%s (%d)", path.Join(f.Path...), f.Length)
+}
+
type Info struct {
Length int `bencode:"length"`
MD5Sum []byte `bencode:"md5sum,optional"`
@@ -18,6 +26,15 @@ type Info struct {
Private bool `bencode:"private"`
}
+func (i Info) String() string {
+ var s string
+ for _, f := range i.Files {
+ s += fmt.Sprintln(f)
+ }
+ s += fmt.Sprintf("%s (%d)\n", i.Name, i.Length)
+ return s
+}
+
type Torrent struct {
Announce string `bencode:"announce"`
AnnounceList [][]string `bencode:"announce-list,optional"`
@@ -30,3 +47,81 @@ type Torrent struct {
URLList string `bencode:"url-list,optional"`
InfoHash []byte `bencode:"-"`
}
+
+func (t Torrent) String() string {
+ s := fmt.Sprintf("announce: %s\n", t.Announce)
+ s += fmt.Sprintf("comment: %s\n", t.Comment)
+ s += fmt.Sprintf("date: %s\n", t.CreationDate)
+ s += fmt.Sprintf("info: %v", t.Info)
+ s += fmt.Sprintf("info hash: %x", t.InfoHash)
+ return s
+}
+
+/*
+metainfo file.: OpenBSD_songs_ogg-2016-03-25-0127.torrent
+info hash.....: 1aa5af9f6f533961a65169bdeeb801e611724d32
+
+directory name: OpenBSD_songs_ogg
+files.........: 38
+ OpenBSD_songs_ogg/song30.ogg (2636244) 2.51 MB
+ OpenBSD_songs_ogg/song31.ogg (2381018) 2.27 MB
+ OpenBSD_songs_ogg/song32.ogg (2253880) 2.15 MB
+ OpenBSD_songs_ogg/song33.ogg (3238559) 3.09 MB
+ OpenBSD_songs_ogg/song34.ogg (5062603) 4.83 MB
+ OpenBSD_songs_ogg/song35.ogg (7191264) 6.86 MB
+ OpenBSD_songs_ogg/song36.ogg (5197630) 4.96 MB
+ OpenBSD_songs_ogg/song37.ogg (13937255) 13.29 MB
+ OpenBSD_songs_ogg/song38.ogg (5860681) 5.59 MB
+ OpenBSD_songs_ogg/song38b.ogg (5759105) 5.49 MB
+ OpenBSD_songs_ogg/song39.ogg (5954997) 5.68 MB
+ OpenBSD_songs_ogg/song40.ogg (3610740) 3.44 MB
+ OpenBSD_songs_ogg/song41.ogg (8382781) 7.99 MB
+ OpenBSD_songs_ogg/song42.ogg (6713047) 6.40 MB
+ OpenBSD_songs_ogg/song43.ogg (6834505) 6.52 MB
+ OpenBSD_songs_ogg/song44.ogg (4628329) 4.41 MB
+ OpenBSD_songs_ogg/song45.ogg (4737475) 4.52 MB
+ OpenBSD_songs_ogg/song46.ogg (3766867) 3.59 MB
+ OpenBSD_songs_ogg/song47.ogg (6586251) 6.28 MB
+ OpenBSD_songs_ogg/song48.ogg (3143847) 3.00 MB
+ OpenBSD_songs_ogg/song49.ogg (6006834) 5.73 MB
+ OpenBSD_songs_ogg/song50.ogg (4184951) 3.99 MB
+ OpenBSD_songs_ogg/song51.ogg (4216946) 4.02 MB
+ OpenBSD_songs_ogg/song52.ogg (4283099) 4.08 MB
+ OpenBSD_songs_ogg/song53.ogg (4635216) 4.42 MB
+ OpenBSD_songs_ogg/song54.ogg (3195265) 3.05 MB
+ OpenBSD_songs_ogg/song55.ogg (6160151) 5.87 MB
+ OpenBSD_songs_ogg/song56.ogg (5471902) 5.22 MB
+ OpenBSD_songs_ogg/song57.ogg (4057801) 3.87 MB
+ OpenBSD_songs_ogg/song58a.ogg (3252520) 3.10 MB
+ OpenBSD_songs_ogg/song58b.ogg (4376163) 4.17 MB
+ OpenBSD_songs_ogg/song58c.ogg (3595317) 3.43 MB
+ OpenBSD_songs_ogg/song58d.ogg (7013091) 6.69 MB
+ OpenBSD_songs_ogg/song59a.ogg (5766764) 5.50 MB
+ OpenBSD_songs_ogg/song59b.ogg (5317415) 5.07 MB
+ OpenBSD_songs_ogg/songsh.ogg (4890381) 4.66 MB
+ OpenBSD_songs_ogg/songsi.ogg (5694670) 5.43 MB
+ OpenBSD_songs_ogg/songty.ogg (6045645) 5.77 MB
+archive size..: 196041209 (747 * 262144 + 219641) 186.96 MB
+
+announce url..: http://OpenBSD.somedomain.net:6969/announce
+creation date.: Fri Mar 25 02:27:56 2016
+created by....: mktorrent 1.0
+comment.......: ogg files from OpenBSD/songs
+Created by andrew fresh (andrew@afresh1.com)
+http://OpenBSD.somedomain.net/
+*/
+
+/*
+metainfo file.: OpenBSD_5.9_amd64_install59.iso-2016-03-29-0449.torrent
+info hash.....: e840038dea1998c39614dcd28594501df02bd32d
+
+file name.....: OpenBSD_5.9_amd64_install59.iso
+file size.....: 233662464 (891 * 262144 + 92160) 222.84 MB
+
+announce url..: http://OpenBSD.somedomain.net:6969/announce
+creation date.: Tue Mar 29 06:49:18 2016
+created by....: mktorrent 1.0
+comment.......: OpenBSD/5.9/amd64/install59.iso
+Created by andrew fresh (andrew@afresh1.com)
+http://OpenBSD.somedomain.net/
+*/