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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 867b1321f63eb7766bd461c247f7d44a786e10fd
4
- data.tar.gz: eddbd5dfdd5d2a89bc31af3d9812423a85b6e549
3
+ metadata.gz: 936cd7653a16e5add58ca0680e893175f7da7fbc
4
+ data.tar.gz: 82e8c580a94acefed48af4dce426cbc06dc0a13a
5
5
  SHA512:
6
- metadata.gz: 9d6579bbd0910fbe35deb8f1ecea724e0c010e73347f5cc7499bcd4093c65679349b5bb0509814a167f490b65f56dfe34e5f66b1e233ecb27e60d6219b6e2aea
7
- data.tar.gz: aba99cae44fa37c9be4acdc32916f9a543094920d0058bdac22fc83100edd1ad041810c457112e1854bfeecee870b1db8dc4fbd0d8e95f6358259cee53d834af
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, :false => true, :type => :string
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
 
@@ -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,file=params['local_file'])
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 don't need to use supplied data.
39
- file_metadata = {}
40
- TagLib::FileRef.open(file) do |fileref|
41
- tag = fileref.tag
42
- file_metadata.update({
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,file=params['local_file'])
61
- remote = URI.escape("#{params['host']}/#{File.basename(file)}")
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
- TagLib::FileRef.open(file) do |fileref|
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
- item.pubDate = Date.parse(params['episode_pubdate']).rfc822 unless params['episode_pubdate'].nil?
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
- item.enclosure = RSS::Rss::Channel::Item::Enclosure.new(remote, properties.length, MIME::Types.type_for(file).first)
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
- rss.items << item
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
@@ -1,3 +1,3 @@
1
1
  module Podtergeist
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: podtergeist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Coleman