summaryrefslogtreecommitdiff
path: root/music.rb
blob: de6a7edc6d2dafbd27a1b037fbd30e4b464d086e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env ruby

require_relative 'lib'

music = Dir[File.join(MEDIA_DIR, 'music', '20*')].sort.reverse
html = File.read(File.join(SNIPPETS, 'head.html'))
html += nav 'music'
music.each do |dir|
  date = File.basename(dir).split('_')[0]
  html += "<section id='#{date}'>"
  title = File.basename(dir).split('_')[1..-1].join(' ')
  html += "<h1>#{title}</h1>"
  html += File.read(File.join(dir, 'README')).chomp.gsub("\n\n", '<p>').gsub("\n", '<br>') # + '<p>'
  cover = File.join(MEDIA_URL, dir.sub(MEDIA_DIR, ''), 'cover.webp')
  alt = File.read(File.join(dir, 'cover.txt')).chomp
  w, h = `identify -format "%w %h" #{cover}`.chomp.split(' ')
  html += "<img class='cover' loading='lazy' width='#{w}' height='#{h}' src='#{cover}' alt='#{alt}'>"
  html += '<table>'
  copyrights_file = File.join(dir, 'copyrights')
  copyrights = File.readlines(copyrights_file).collect { |l| l.chomp } if File.exist? copyrights_file
  Dir[File.join(dir, '*mp3')].each do |mp3|
    mp3 = File.join(MEDIA_URL, mp3.sub(MEDIA_DIR, ''))
    name = File.basename(mp3, '.mp3')[3..-1].gsub('_', ' ')
    html += '<tr>'
    html += "<td>#{name}</td>"
    html += "<td>
        <audio preload='none' controls>
          <source src='#{mp3}' type='audio/mpeg'>
          <a href=#{mp3}>#{mp3}</a>
        </audio>
        </td>"
    html += '</tr>'
  end
  html += '</table>'
  ia = "https://archive.org/details/pdp8_#{title.gsub(' ', '_')}"
  html += "<p>Internet Archive: <a href='#{ia}'>#{ia}</a>"
  bc = if File.exist?(File.join(dir, 'bandcamp'))
         File.read(File.join(dir, 'bandcamp')).chomp
       else
         "https://pdp8.bandcamp.com/album/#{title.gsub(' ', '-')}"
       end
  html += "<p>Bandcamp: <a href='#{bc}'>#{bc}</a>"
  html += '</section>'
end
html += File.read(File.join(SNIPPETS, 'tail.html'))
print_html 'music', html