podtergeist 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/podtergeist +1 -1
- data/lib/podtergeist/feed.rb +41 -32
- data/lib/podtergeist/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 936cd7653a16e5add58ca0680e893175f7da7fbc
|
|
4
|
+
data.tar.gz: 82e8c580a94acefed48af4dce426cbc06dc0a13a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e327e77b2d841f8f79b0e3107a1ed79c1fa95c8363f57d7bbea5ff7eb28ea576da74af3275aa02e031b06f0e71b1d32055b00165fea6b4f03343ede2f9fb07f0
|
|
7
|
+
data.tar.gz: d027d15c2a566e97c95beea89e0e5c26f97259c4d580dd7bb70ba7b40fd09e2e1c7e854bb1f41401432872cdd560c9c68facf860a4ff79570d4c951521fa0b85
|
data/bin/podtergeist
CHANGED
|
@@ -10,7 +10,7 @@ class PodtergeistCLI < Thor
|
|
|
10
10
|
method_option :host, :required => true, :type => :string
|
|
11
11
|
method_option :show_title, :required => false, :type => :string
|
|
12
12
|
method_option :show_link, :required => true, :type => :string
|
|
13
|
-
method_option :show_description, :
|
|
13
|
+
method_option :show_description, :required => false, :type => :string
|
|
14
14
|
method_option :episode_link, :required => true, :type => :string
|
|
15
15
|
method_option :episode_pubdate, :required => true, :type => :string
|
|
16
16
|
|
data/lib/podtergeist/feed.rb
CHANGED
|
@@ -16,7 +16,6 @@ module Podtergeist
|
|
|
16
16
|
|
|
17
17
|
def existing(feed,params)
|
|
18
18
|
shows = Dir.glob("#{params['local_directory']}/*.{m4a,mp3}")
|
|
19
|
-
FileUtils.rm(feed) if feed_exists?(feed)
|
|
20
19
|
create_channel(feed,params,shows.first)
|
|
21
20
|
shows.each do |file|
|
|
22
21
|
append_item(feed,params,file)
|
|
@@ -31,47 +30,54 @@ module Podtergeist
|
|
|
31
30
|
end
|
|
32
31
|
|
|
33
32
|
# create
|
|
34
|
-
def create_channel(path,params,
|
|
33
|
+
def create_channel(path,params,local_file=params['local_file'])
|
|
35
34
|
rss = RSS::Rss.new('2.0')
|
|
36
35
|
channel = RSS::Rss::Channel.new
|
|
37
36
|
|
|
38
|
-
# If we have an existing file we
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
'show_title' => tag.album,
|
|
44
|
-
'show_description' => "#{tag.album} on #{tag.artist}"
|
|
45
|
-
})
|
|
46
|
-
end if file
|
|
47
|
-
|
|
48
|
-
channel.title = file_metadata['show_title'] || params['show_title']
|
|
49
|
-
channel.description = file_metadata['show_description'] || params['show_description']
|
|
50
|
-
channel.link = file_metadata['show_link'] || params['show_link']
|
|
37
|
+
# If we have an existing file we prefer it to improperly escaped supplied data.
|
|
38
|
+
metadata = retrieve_file_metadata(local_file)
|
|
39
|
+
channel.title = metadata['episode_title'] || params['show_title']
|
|
40
|
+
channel.description = metadata['show_description'] || params['show_description']
|
|
41
|
+
channel.link = metadata['show_link'] || params['show_link']
|
|
51
42
|
|
|
52
43
|
rss.channel = channel
|
|
53
|
-
|
|
54
|
-
file = File.new(path, 'w')
|
|
55
|
-
file.write(rss.to_s)
|
|
56
|
-
file.close
|
|
44
|
+
write_rss_file!(path, rss)
|
|
57
45
|
end
|
|
58
46
|
|
|
59
47
|
# add item
|
|
60
|
-
def append_item(path,params,
|
|
61
|
-
|
|
48
|
+
def append_item(path,params,local_file=params['local_file'])
|
|
49
|
+
rss = RSS::Parser.parse(File.new(path))
|
|
50
|
+
rss.items << rss_channel_item(local_file, params)
|
|
51
|
+
write_rss_file!(path, rss)
|
|
52
|
+
end
|
|
62
53
|
|
|
63
|
-
|
|
54
|
+
protected
|
|
55
|
+
def retrieve_file_metadata(file)
|
|
56
|
+
metadata = {}
|
|
57
|
+
if file
|
|
58
|
+
TagLib::FileRef.open(file) do |fileref|
|
|
59
|
+
tag = fileref.tag
|
|
60
|
+
metadata.update({
|
|
61
|
+
'episode_title' => tag.album,
|
|
62
|
+
'show_description' => "#{tag.album} on #{tag.artist}"
|
|
63
|
+
})
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
metadata
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def rss_channel_item(local_file, params)
|
|
70
|
+
TagLib::FileRef.open(local_file) do |fileref|
|
|
64
71
|
unless fileref.null?
|
|
65
72
|
tag = fileref.tag
|
|
66
73
|
properties = fileref.audio_properties
|
|
67
74
|
|
|
68
|
-
rss = RSS::Parser.parse(File.new(path))
|
|
69
|
-
|
|
70
75
|
item = RSS::Rss::Channel::Item.new
|
|
71
76
|
item.title = tag.title
|
|
72
77
|
item.link = params['episode_link'] unless params['episode_link'].nil?
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
if pub_date = params['episode_pubdate'] || pub_date = File.ctime(local_file).to_s
|
|
79
|
+
item.pubDate = Date.parse(pub_date).rfc822
|
|
80
|
+
end
|
|
75
81
|
|
|
76
82
|
item.guid = RSS::Rss::Channel::Item::Guid.new
|
|
77
83
|
item.guid.content = params['episode_link'] unless params['episode_link'].nil?
|
|
@@ -79,17 +85,20 @@ module Podtergeist
|
|
|
79
85
|
|
|
80
86
|
item.description = tag.comment
|
|
81
87
|
|
|
82
|
-
|
|
88
|
+
remote = URI.escape("#{params['host']}/#{File.basename(local_file)}")
|
|
89
|
+
item.enclosure = RSS::Rss::Channel::Item::Enclosure.new(
|
|
90
|
+
remote, properties.length, MIME::Types.type_for(local_file).first
|
|
91
|
+
)
|
|
83
92
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
file = File.new(path, 'w')
|
|
87
|
-
file.write(rss.to_s)
|
|
88
|
-
file.close
|
|
93
|
+
return item
|
|
89
94
|
end
|
|
90
95
|
end
|
|
91
96
|
end
|
|
92
97
|
|
|
98
|
+
def write_rss_file!(path, rss, mode = 'w')
|
|
99
|
+
File.open(path, mode) { |file| file.write(rss.to_s) }
|
|
100
|
+
end
|
|
101
|
+
|
|
93
102
|
end
|
|
94
103
|
end
|
|
95
104
|
end
|
data/lib/podtergeist/version.rb
CHANGED