Permalink
Browse files

Create magnet links from torrentz

  • Loading branch information...
1 parent 6f01a52 commit cd9792ff9b1755cf0f14d38262adf5e860a1c05b @sj26 committed Nov 28, 2012
Showing with 20 additions and 0 deletions.
  1. +20 −0 .js/torrentz.eu.coffee
View
@@ -0,0 +1,20 @@
+jQuery ($) ->
+ # Remove spammy sponsored link
+ $(".download dl:has(dd:contains('Sponsored Link'))").remove()
+
+ filename = $('.download h2:first span:first').text()
+ size = $('.files [title]:first').attr('title').replace(/[,b]/g, "")
+ hash = $('.trackers div:first').text().split(" ")[1]
+ trackers = $('.trackers dl:not(:contains("DHT")) dt').map -> $(@).text()
+
+ uri = "magnet:?xt=urn:btih:#{encodeURIComponent hash}&dn=#{encodeURIComponent filename}&xl=#{encodeURIComponent size}"
+
+ if trackers.length == 1
+ uri += "&tr=#{encodeURIComponent trackers[0]}"
+ else if trackers.length > 1
+ uri += "&" + $.map(trackers, (tracker, i) -> "tr.#{i + 1}=#{encodeURIComponent tracker}").join("&")
+
+ $("""<dl><dt><a rel="e" target="_blank"><span class="u">magnet</span><span class="n"></span></a></dt></dl>""")
+ .find('a').attr('href', uri).removeAttr('target').end()
+ .find('.n').text(filename).end()
+ .insertAfter('.download h2:first')

0 comments on commit cd9792f

Please sign in to comment.