aboutsummaryrefslogtreecommitdiff
path: root/_plugins/generate-torrent.rb
diff options
context:
space:
mode:
Diffstat (limited to '_plugins/generate-torrent.rb')
-rw-r--r--_plugins/generate-torrent.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/_plugins/generate-torrent.rb b/_plugins/generate-torrent.rb
new file mode 100644
index 0000000..1c642f4
--- /dev/null
+++ b/_plugins/generate-torrent.rb
@@ -0,0 +1,32 @@
+TRACKERS = '-a udp://tracker.coppersurfer.tk:6969/announce -a udp://tracker.ccc.de:80/announce -a udp://tracker.publicbt.com:80 -a udp://tracker.istole.it:80 -a http://tracker.openbittorrent.com:80/announce -a http://tracker.ipv6tracker.org:80/announce'
+
+module Jekyll
+ class TorrentGenerator < Generator
+ safe true
+
+ MEDIA_EXTENSION = {
+ 'podcasts' => 'ogg',
+ 'screencasts' => 'mkv'
+ }
+
+ def generate(site)
+ site.collections.each do |name, collection|
+ if ['podcasts', 'screencasts'].include? name
+ collection.docs.each do |document|
+ date = document.data['date'].strftime('%Y-%m-%d')
+ slug = document.data['slug']
+ extension = MEDIA_EXTENSION[name]
+ file = "#{date}-#{slug}.#{extension}"
+ media = "resources/#{name}/#{file}"
+ torrent = "#{media}.torrent"
+ webseed = "#{site.config['url']}/#{media}"
+ unless File.exist? torrent then
+ puts "Missing '#{torrent}' file, generating..."
+ puts `mktorrent #{TRACKERS} -f -v -d -c '#{document.content}' -n #{file} -w #{webseed} -o #{torrent} #{media}`
+ end
+ end
+ end
+ end
+ end
+ end
+end