Last active
July 26, 2018 19:36
-
-
Save LaPingvino/de7af0e66ea186397e765291a66d1e5f to your computer and use it in GitHub Desktop.
Quick script to create a magnet link out of an infohash, e.g. for use together with aria2c. Usage: commandname invokedcommand infohash [name [tracker1 [tracker2]]] ...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"os/exec" | |
"strings" | |
"net/url" | |
) | |
func main() { | |
var infohash, name, command string | |
trackers := "udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopentor.org%3A2710&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Ftracker.blackunicorn.xyz%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969" | |
if len(os.Args) > 4 { | |
trackersl := os.Args[4:] | |
for i, v := range trackersl { | |
trackersl[i] = url.QueryEscape(v) | |
} | |
trackers = strings.Join(trackersl, "&tr=") | |
} | |
if len(os.Args) > 3 { | |
name = os.Args[3] | |
} | |
if len(os.Args) > 2 { | |
command = os.Args[1] | |
infohash = os.Args[2] | |
} else if len(os.Args) > 1 { | |
infohash = os.Args[1] | |
} | |
link := fmt.Sprintf("magnet:?xt=urn:btih:%s&dn=%s&tr=%s", infohash, name, trackers) | |
fmt.Println(link) | |
if command != "" { | |
c := exec.Command(command, link) | |
c.Stdout = os.Stdout | |
c.Stderr = os.Stderr | |
err := c.Start() | |
if err != nil {panic(err)} | |
fmt.Println(c.Wait()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment