diff options
-rw-r--r-- | _plugins/generate-media-files.rb | 20 | ||||
-rw-r--r-- | _plugins/generate-torrent.rb | 32 | ||||
-rw-r--r-- | _plugins/linter.rb | 25 |
3 files changed, 54 insertions, 23 deletions
diff --git a/_plugins/generate-media-files.rb b/_plugins/generate-media-files.rb new file mode 100644 index 0000000..2ef92db --- /dev/null +++ b/_plugins/generate-media-files.rb @@ -0,0 +1,20 @@ +module Jekyll + class MediaFilesGenerator < Generator + safe true + priority :high + + def generate(site) + site.collections['podcasts'].docs.each do |document| + date = document.data['date'].strftime('%Y-%m-%d') + slug = document.data['slug'] + flac = "resources/podcasts/#{date}-#{slug}.flac" + ogg = "resources/podcasts/#{date}-#{slug}.ogg" + unless File.exist? ogg then + puts "Missing '#{ogg}' file, generating..." + puts `ffmpeg -i #{flac} -ar 48000 -vn -c:a libvorbis -b:a 320k #{ogg}` + site.static_files << Jekyll::StaticFile.new(site, site.source, '', ogg) + end + end + end + end +end 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 diff --git a/_plugins/linter.rb b/_plugins/linter.rb index ac1c6ed..d0329cc 100644 --- a/_plugins/linter.rb +++ b/_plugins/linter.rb @@ -2,11 +2,12 @@ require 'set' IGNORED_PAGES = Set['sitemap.xml'] LANGS = Set['en', 'pt', 'fr', 'eo'] # jp zh es de -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 Linter < Generator safe true + priority :high + @@known_ids = Set[] def insert_id(name, document) @@ -116,20 +117,6 @@ module Jekyll raise "Missing FLAC file '#{flac}'" end - file = "#{date}-#{slug}.ogg" - ogg = "resources/podcasts/#{date}-#{slug}.ogg" - unless File.exist? ogg then - puts "Missing '#{ogg}' file, generating..." - puts `ffmpeg -i #{flac} -ar 48000 -vn -c:a libvorbis -b:a 320k #{ogg}` - site.static_files << Jekyll::StaticFile.new(site, site.source, '', ogg) - end - - torrent = "#{ogg}.torrent" - unless File.exist? torrent then - webseed = "#{site.config['url']}/#{ogg}" - puts "Missing '#{torrent}' file, generating..." - puts `mktorrent #{TRACKERS} -f -v -d -c '#{document.content}' -n #{file} -w #{webseed} -o #{torrent} #{ogg}` - end end if name == 'screencasts' then @@ -137,14 +124,6 @@ module Jekyll unless File.exist? mkv then raise "Missing MKV file '#{mkv}'" end - - torrent = "#{mkv}.torrent" - unless File.exist? torrent then - webseed = "#{site.config['url']}/#{mkv}" - file = "#{date}-#{slug}.mkv" - puts "Missing '#{torrent}' file, generating..." - puts `mktorrent #{TRACKERS} -f -v -d -c '#{document.content}' -n #{file} -w #{webseed} -o #{torrent} #{mkv}` - end end end |