diff options
author | EuAndreh <eu@euandre.org> | 2020-12-24 21:20:05 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2020-12-25 03:36:24 -0300 |
commit | 998618daf80d2bb1d6848ff0309c0ef9b80d5827 (patch) | |
tree | 2879e695bec0ca783c295ad7d1b1ca5d222e05f7 /_plugins/generate-torrent.rb | |
parent | Don't run linter on generated files (diff) | |
download | euandre.org-998618daf80d2bb1d6848ff0309c0ef9b80d5827.tar.gz euandre.org-998618daf80d2bb1d6848ff0309c0ef9b80d5827.tar.xz |
Move torrent and media generators out of linter.rb
Diffstat (limited to '')
-rw-r--r-- | _plugins/generate-torrent.rb | 32 |
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 |