]> gitweb.factorcode.org Git - factor.git/commitdiff
bittorrent: Add a magnet tuple.
authorDoug Coleman <doug.coleman@gmail.com>
Mon, 23 Nov 2020 01:13:50 +0000 (19:13 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 23 Nov 2020 01:13:50 +0000 (19:13 -0600)
extra/bittorrent/bittorrent.factor

index 1b4f6ff95fa090b8c8089208964886a9ef542e57..3f606fb43f880a3ba2bdba31076ae5e2db0cbf11 100644 (file)
@@ -7,7 +7,8 @@ io.pathnames io.sockets io.streams.byte-array io.streams.duplex
 kernel literals locals make math math.bitwise math.functions
 math.order math.parser math.ranges multiline namespaces
 prettyprint random sequences splitting strings timers
-tools.annotations ui ui.gadgets.panes ui.tools.listener urls ;
+tools.annotations ui ui.gadgets.panes ui.tools.listener urls
+urls.encoding ;
 
 IN: bittorrent
 
@@ -99,6 +100,24 @@ M: string load-metainfo
         ]
     } cleave ;
 
+TUPLE: magnet display-name exact-length exact-topic
+web-seed acceptable-source exact-source keyword-topic
+manifest-topic address-tracker ;
+
+: magnet-link>magnet ( url -- magnet-url )
+    [ magnet new ] dip
+    >url query>> {
+        [ "dn" of >>display-name ]
+        [ "xl" of >>exact-length ]
+        [ "xt" of >>exact-topic ]
+        [ "ws" of >>web-seed ]
+        [ "as" of >>acceptable-source ]
+        [ "xs" of >>exact-source ]
+        [ "kt" of >>keyword-topic ]
+        [ "mt" of >>manifest-topic ]
+        [ "tr" of >>address-tracker ]
+    } cleave ;
+
 : parse-peer4 ( peerbin -- inet4 )
     4 cut [
         [ number>string ] { } map-as "." join