~sivers/sive.rs

sive.rs/script/podcast-rss.rb -rwxr-xr-x 5.2 KiB
5fcf6634 — Derek Sivers cover and hardcover 19 hours ago
                                                                                
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env ruby
require_relative 'init.rb'
require 'time'
require 'xml'

def parse(fn)
  res = meta(fn)
  res[:pubdate] = File.basename(fn)  # file name is date
  res[:subtitle] = "transcript at sive.rs/#{res[:uri]}" unless res[:subtitle]
  res
end

files = Dir[ROOT + 'content/podcast/*'].sort.reverse
podcast = files.map {|fn| parse(fn)}

doc = XML::Document.new()
doc.root = XML::Node.new('rss')
rss = doc.root
rss['version'] = '2.0'
rss['xmlns:itunes'] = 'http://www.itunes.com/dtds/podcast-1.0.dtd'
rss['xmlns:atom'] = 'http://www.w3.org/2005/Atom'
rss['xmlns:content'] = 'http://purl.org/rss/1.0/modules/content/'
rss['xmlns:googleplay'] = 'https://www.google.com/schemas/play-podcasts/1.0/'
rss << channel = XML::Node.new('channel')
channel << title = XML::Node.new('title')
title << 'Derek Sivers'
channel << description = XML::Node.new('description')
description << 'sive.rs'
channel << managingEditor = XML::Node.new('managingEditor')
managingEditor << 'derek@sivers.org'
channel << copyright = XML::Node.new('copyright')
copyright << '© 2020 Derek Sivers'
channel << generator = XML::Node.new('generator')
generator << 'Derek Sivers'
channel << atomlink = XML::Node.new('atom:link')
atomlink['href'] = 'https://sive.rs/podcast.rss'
atomlink['rel'] = 'self'
atomlink['type'] = 'application/rss+xml'
channel << link = XML::Node.new('link')
link << 'https://sive.rs/'
channel << itunesnewfeed = XML::Node.new('itunes:new-feed-url')
itunesnewfeed << 'https://sive.rs/podcast.rss'
channel << itunesowner = XML::Node.new('itunes:owner')
itunesowner << itunesemail = XML::Node.new('itunes:email')
itunesemail << 'apple@q7r7.com'
itunesowner << itunesname = XML::Node.new('itunes:name')
itunesname << 'Derek Sivers'
channel << itunesauthor = XML::Node.new('itunes:author')
itunesauthor << 'Derek Sivers'
channel << itunessummary = XML::Node.new('itunes:summary')
itunessummary << 'Derek Sivers posts from sive.rs'
channel << itunessubtitle = XML::Node.new('itunes:subtitle')
itunessubtitle << 'Derek Sivers posts from sive.rs'
channel << language = XML::Node.new('language')
language << 'en'
channel << itunesexplicit = XML::Node.new('itunes:explicit')
itunesexplicit << 'no'
channel << cat1 = XML::Node.new('itunes:category')
cat1['text'] = 'Education'
cat1 << subcat1 = XML::Node.new('itunes:category')
subcat1['text'] = 'Self-Improvement'
channel << cat2 = XML::Node.new('itunes:category')
cat2['text'] = 'Society & Culture'
cat2 << subcat2 = XML::Node.new('itunes:category')
subcat2['text'] = 'Philosophy'
channel << cat3 = XML::Node.new('itunes:category')
cat3['text'] = 'Arts'
cat3 << subcat3 = XML::Node.new('itunes:category')
subcat3['text'] = 'Books'
channel << ituneskeywords = XML::Node.new('itunes:keywords')
ituneskeywords << 'Derek Sivers,sivers,sivers.org,sive.rs'
channel << itunestype = XML::Node.new('itunes:type')
itunestype << 'episodic'
channel << itunesimage = XML::Node.new('itunes:image')
itunesimage['href'] = 'https://sive.rs/images/DerekSivers-20141209a-1400.jpg'
channel << image = XML::Node.new('image')
image << image_url = XML::Node.new('url')
image_url << 'https://sive.rs/images/DerekSivers-20141209a-1400.jpg'
image << image_link = XML::Node.new('link')
image_link << 'https://sive.rs/'
image << image_title = XML::Node.new('title')
image_title << 'Derek Sivers'

# also writing M3U, unrelated, while we're at it
File.open(WEB_DIR + 'podcast.m3u', 'w') {|f| f.puts '#EXTM3U'}

podcast.each do |p|
  channel << item = XML::Node.new('item')
  item << item_link = XML::Node.new('link')
  item_link << "https://sive.rs/#{p[:uri]}"
  item << title = XML::Node.new('title')
  title << p[:title]
  item << itunestitle = XML::Node.new('itunes:title')
  itunestitle << p[:title]
  item << itunessubtitle = XML::Node.new('itunes:subtitle')
  itunessubtitle << p[:subtitle]
  item << itunesauthor = XML::Node.new('itunes:author')
  itunesauthor << 'Derek Sivers'
  item << description = XML::Node.new('description')
  description << XML::Node.new_cdata(p[:description])
  item << summary = XML::Node.new('itunes:summary')
  summary << XML::Node.new_cdata(p[:description])
  item << contente = XML::Node.new('content:encoded')
  contente << XML::Node.new_cdata(p[:description])
  item << season = XML::Node.new('itunes:season')
  season << p[:season]
  item << guid = XML::Node.new('guid')
  guid << "https://sive.rs/#{p[:uri]}"
  item << pubDate = XML::Node.new('pubDate')
  pubDate << Date.parse(p[:pubdate]).strftime('%a, %d %b %Y %H:%M:%S %z')
  item << itunesepisodeType = XML::Node.new('itunes:episodeType')
  itunesepisodeType << 'full'
  item << itunesexplicit = XML::Node.new('itunes:explicit')
  itunesexplicit << 'no'
  item << itunesimage = XML::Node.new('itunes:image')
  itunesimage['href'] = 'https://sive.rs/images/DerekSivers-20141209a-1400.jpg'
  item << itunesduration = XML::Node.new('itunes:duration')
  itunesduration << p[:duration]
  item << enclosure = XML::Node.new('enclosure')
  enclosure['url'] = "https://m.sive.rs/#{p[:audio]}"
  enclosure['type'] = 'audio/mpeg'
  enclosure['length'] = p[:length].to_s
  File.open(WEB_DIR + 'podcast.m3u', 'a') do |f|
    f.puts '#EXTINF:%d,%s' % [
      (Time.parse(p[:duration]).to_i - Time.parse('00:00:00').to_i),
      p[:title]]
    f.puts "https://m.sive.rs/#{p[:audio]}"
  end
end

doc.save(WEB_DIR + 'podcast.rss', indent: true, encoding: XML::Encoding::UTF_8)