ruby-podcast 0.0.6
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 +15 -0
- data/bin/podcast +77 -0
- data/lib/podcast.rb +134 -0
- data/lib/podcast/version.rb +4 -0
- data/test/test_podcast.rb +58 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YWJjM2RiMWIzMDFhNWM0MjBmMDIyNGFkM2M4ZTZmNDA5ZmMyMDgzMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MzUyZGNmZjk1YWVkMWJhNTE3MjMxMzg1MmU2ZmQxYTJiYzM0MDE0Yw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDdjMTA0M2JjNGI2YTk5YjU5ZTRhNGNlN2Q5ODgwNjE0N2QwOTRmYmRmYTRl
|
10
|
+
Y2IzNDNmNjlkMWNkOWRlZTBmYmMwYzcyN2M0NmI2NmVlZDBlYjQzYzQ5M2Zj
|
11
|
+
N2JmNWUzNmJkY2YyYTg3NGE1NzVjYzZmOWU4NzVkZDE1NWY4Nzg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YWU1OGQwNTNlNjMxODE0NDU3N2RlMzNhZjIwYzgxY2I2MmViZGY4ZjlkNDQz
|
14
|
+
ZDc0MmUzM2QyNDk0MDUxNzA0MWRkMjg3ZmE5ZDJiZTUxZDY0NmQ5YTc1Y2Y1
|
15
|
+
OWVmZWM4NWMyYTViODM0MmY2ZmQ3NjIyNWI5YTM1YWJkNmUxOTc=
|
data/bin/podcast
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# == Synopsis
|
4
|
+
#
|
5
|
+
# Generate a podcast file from a directory of mp3 files. All subdirectories
|
6
|
+
# below indicated directory will be searched.
|
7
|
+
#
|
8
|
+
# == Usage
|
9
|
+
#
|
10
|
+
# podcast --dir my/mp3/dir --out podcast.rss --title "Title" --description "Description" --link http://mypodcastserver/
|
11
|
+
#
|
12
|
+
# == Author
|
13
|
+
# Ed Summers <ehs@pobox.com>
|
14
|
+
# Darren Greaves https://github.com/boncey
|
15
|
+
#
|
16
|
+
# == Copyright
|
17
|
+
# Copyright (c) 2004 Ed Summers.
|
18
|
+
# Licensed under the same terms as Ruby.
|
19
|
+
|
20
|
+
require 'optparse'
|
21
|
+
require 'rubygems'
|
22
|
+
require 'podcast'
|
23
|
+
|
24
|
+
def usage(opts)
|
25
|
+
puts 'podcast --dir my/mp3/dir --out podcast.rss --title "Title" --description "Description" --link http://mypodcastserver/'
|
26
|
+
puts "Version: #{Podcast::NAME}"
|
27
|
+
puts opts.help
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
# the location to look for mp3s
|
32
|
+
dir = ''
|
33
|
+
|
34
|
+
# the location to write the podcast file
|
35
|
+
podcast_file = nil
|
36
|
+
|
37
|
+
# the podcast parameters set by the user
|
38
|
+
version = nil
|
39
|
+
|
40
|
+
# create podcast object
|
41
|
+
podcast = Podcast::Feed.new()
|
42
|
+
|
43
|
+
# read options
|
44
|
+
opts = OptionParser.new
|
45
|
+
opts.on("-d", "--dir VAL", String) { |val| dir=val }
|
46
|
+
opts.on("-o", "--out VAL", String) { |val| podcast_file=val }
|
47
|
+
opts.on("-b", "--base VAL", String) { |val| podcast.base=val }
|
48
|
+
opts.on("-l", "--link VAL", String) { |val| podcast.link=val }
|
49
|
+
opts.on("-t", "--title VAL", String) { |val| podcast.title=val }
|
50
|
+
opts.on("-a", "--about VAL", String) { |val| podcast.about=val }
|
51
|
+
opts.on("-i", "--image VAL", String) { |val| podcast.image=val }
|
52
|
+
opts.on("-v", "--version VAL", String) { |val| version=val }
|
53
|
+
opts.on("-e", "--description VAL", String) { |val| podcast.description=val }
|
54
|
+
begin
|
55
|
+
opts.parse(ARGV)
|
56
|
+
rescue => e
|
57
|
+
usage(opts)
|
58
|
+
end
|
59
|
+
|
60
|
+
if dir == nil || !File.directory?(dir) || !podcast.valid?
|
61
|
+
usage(opts)
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
# add a directory
|
66
|
+
podcast.add_dir(dir)
|
67
|
+
podcast.version = version ? version : "0.9"
|
68
|
+
|
69
|
+
# write off the rss
|
70
|
+
if podcast_file
|
71
|
+
file = File.new(podcast_file, 'w')
|
72
|
+
file.write(podcast.get_rss())
|
73
|
+
file.close
|
74
|
+
else
|
75
|
+
puts "Outputting podcast"
|
76
|
+
puts podcast.get_rss()
|
77
|
+
end
|
data/lib/podcast.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'podcast/version'
|
3
|
+
require 'find'
|
4
|
+
require 'rss/0.9'
|
5
|
+
require 'mp3info'
|
6
|
+
require 'rss/maker'
|
7
|
+
require 'uri'
|
8
|
+
|
9
|
+
module Podcast
|
10
|
+
|
11
|
+
class Feed
|
12
|
+
|
13
|
+
attr_reader :title, :link, :description, :image, :base, :language, :version, :about
|
14
|
+
attr_writer :title, :link, :description, :image, :base, :language, :version, :about
|
15
|
+
|
16
|
+
include Enumerable
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@mp3s = []
|
20
|
+
@language = "en-us"
|
21
|
+
@about = "Made with #{NAME}"
|
22
|
+
@base = ''
|
23
|
+
end
|
24
|
+
|
25
|
+
# add an mp3 file to the podcast
|
26
|
+
def add_mp3(file)
|
27
|
+
begin
|
28
|
+
mp3 = Mp3File.new(file)
|
29
|
+
@mp3s.push(mp3)
|
30
|
+
rescue Mp3InfoError => e
|
31
|
+
puts "Skipping #{file} as it has a problem: #{e}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def valid?
|
36
|
+
title != nil && description != nil && link != nil
|
37
|
+
end
|
38
|
+
|
39
|
+
# add a directory location to the podcast
|
40
|
+
# the directory will be recursively search
|
41
|
+
# for mp3 files.
|
42
|
+
def add_dir(dir)
|
43
|
+
# we chdir into the directory so that file paths will be relative
|
44
|
+
pwd = Dir.pwd
|
45
|
+
Dir.chdir(dir)
|
46
|
+
Find.find('.') do |f|
|
47
|
+
if (f =~ /\.mp3$/ && File.size?(f))
|
48
|
+
f.sub!(%r{^./}, '') # remove leading './'
|
49
|
+
add_mp3(f)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
# go back to original directory
|
53
|
+
Dir.chdir(pwd)
|
54
|
+
end
|
55
|
+
|
56
|
+
# the total amount of files in the podcast
|
57
|
+
def size
|
58
|
+
@mp3s.size
|
59
|
+
end
|
60
|
+
|
61
|
+
# write the podcast file
|
62
|
+
def get_rss
|
63
|
+
#version = "1.0" # ["0.9", "1.0", "2.0"]
|
64
|
+
version = @version
|
65
|
+
|
66
|
+
content = RSS::Maker.make(@version) do |m|
|
67
|
+
m.channel.title = @title
|
68
|
+
m.channel.description = @description
|
69
|
+
m.channel.link = @link
|
70
|
+
m.channel.language = @language
|
71
|
+
m.channel.about = @about
|
72
|
+
m.items.do_sort = true # sort items by date
|
73
|
+
m.channel.updated = Time.now.to_s
|
74
|
+
m.channel.author = NAME
|
75
|
+
|
76
|
+
if @image != nil
|
77
|
+
m.image.url = @image
|
78
|
+
m.image.title = @title
|
79
|
+
end
|
80
|
+
|
81
|
+
for mp3 in @mp3s
|
82
|
+
item = m.items.new_item
|
83
|
+
item.title = mp3
|
84
|
+
## add a base url
|
85
|
+
if base != ''
|
86
|
+
link = base + '/' + URI::escape(mp3.path)
|
87
|
+
else
|
88
|
+
link = URI::escape(mp3.path)
|
89
|
+
end
|
90
|
+
item.link = link
|
91
|
+
item.date = mp3.mtime
|
92
|
+
item.enclosure.url = link
|
93
|
+
item.enclosure.length = mp3.length
|
94
|
+
item.enclosure.type = mp3.type
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
return content
|
99
|
+
end
|
100
|
+
|
101
|
+
def each
|
102
|
+
@songs.each do |s|
|
103
|
+
yield s
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
class Mp3File
|
110
|
+
|
111
|
+
attr_reader :artist, :album, :title, :file, :path, :length, :type, :mtime
|
112
|
+
attr_writer :artist, :album, :title, :file, :path, :length, :type, :mtime
|
113
|
+
|
114
|
+
def initialize(f)
|
115
|
+
file = File.new(f)
|
116
|
+
info = Mp3Info.open(f)
|
117
|
+
tag = info.tag()
|
118
|
+
@file = f
|
119
|
+
@artist = tag['artist']
|
120
|
+
@album = tag['album']
|
121
|
+
@title = tag['title']
|
122
|
+
@path = file.path()
|
123
|
+
@length = file.stat.size()
|
124
|
+
@mtime = file.stat.mtime()
|
125
|
+
@type = 'audio/mpeg'
|
126
|
+
end
|
127
|
+
|
128
|
+
def to_s
|
129
|
+
@title
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift('lib')
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'podcast'
|
7
|
+
|
8
|
+
class PodcastTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def test_constructor
|
11
|
+
p = Podcast::Feed.new
|
12
|
+
assert(p.class == Podcast::Feed)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_add_mp3
|
16
|
+
p = Podcast::Feed.new
|
17
|
+
p.add_mp3('test/test.mp3')
|
18
|
+
p.add_mp3('test/test.mp3')
|
19
|
+
p.add_mp3('test/test.mp3')
|
20
|
+
assert_equal(p.size(), 3)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_add_bad_mp3
|
24
|
+
p = Podcast::Feed.new
|
25
|
+
p.add_mp3('test/test.mp3')
|
26
|
+
p.add_mp3('test/test.mp3')
|
27
|
+
p.add_mp3('test/bad.mp3')
|
28
|
+
assert_equal(p.size(), 2)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_add_dir
|
32
|
+
p = Podcast::Feed.new
|
33
|
+
p.add_dir('.')
|
34
|
+
assert_equal(p.size(), 1)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_get_rss
|
38
|
+
p = Podcast::Feed.new
|
39
|
+
p.title = 'test podcast'
|
40
|
+
p.description = 'test podcast coming at ya'
|
41
|
+
p.link = 'http://www.example.org'
|
42
|
+
p.image = 'http://www.example.org/icon.png'
|
43
|
+
p.base = 'http://www.example.org/torrents'
|
44
|
+
## add using directory so we can confirm it is stripped
|
45
|
+
p.add_dir('test')
|
46
|
+
p.version = "0.9"
|
47
|
+
xml = p.get_rss().to_s
|
48
|
+
|
49
|
+
# parse the rss
|
50
|
+
parser = RSS::Parser.new('0.9')
|
51
|
+
rss = RSS::Parser.parse(xml)
|
52
|
+
items = rss.items()
|
53
|
+
assert(items.size == 1)
|
54
|
+
assert_equal(items[0].link, 'http://www.example.org/torrents/test.mp3')
|
55
|
+
assert_equal(rss.channel.title, p.title)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-podcast
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ed Summers
|
8
|
+
- Darren Greaves
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-07-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ruby-mp3info
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
description: Iterate over a directory of mp3 files and write out a podcast RSS file
|
29
|
+
email:
|
30
|
+
- github@djgreaves.org
|
31
|
+
executables:
|
32
|
+
- podcast
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- bin/podcast
|
37
|
+
- lib/podcast.rb
|
38
|
+
- lib/podcast/version.rb
|
39
|
+
- test/test_podcast.rb
|
40
|
+
homepage: https://github.com/boncey/ruby-podcast
|
41
|
+
licenses: []
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project: ruby-podcast
|
59
|
+
rubygems_version: 2.4.2
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Create podcasts from MP3 files
|
63
|
+
test_files:
|
64
|
+
- test/test_podcast.rb
|
65
|
+
has_rdoc:
|