phonocast 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26f52ab35c4f9e89e7defccaa2f36245df45f03b
4
+ data.tar.gz: 56555baf255b8d7529b3edfe342a00f791800740
5
+ SHA512:
6
+ metadata.gz: 3e410449e26d29500072088e4ee0ca200aa5abd75282826a4f0ea9204724118280a1de68d0aa5d528f63d4ebd66df25caade21b45ed2a1d2696990eb39d9c348
7
+ data.tar.gz: 6429f9701033727a1ec35c9aab6cd4b4e82bfb8b3c7c76b63186c8b9fdf5057ce7553370bc703357f62ba1b7a37885e38862aa5d2d04161b2be23baac042847e
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Alex Blom
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Phonocast
2
+
3
+ Phonocast is a gem to convert local audio files to a podcast feed, which
4
+ can then be deployed on your own server or even Dropbox.
5
+
6
+ *Motivation:*
7
+ [http://dancarlin.com/product/hardcore-history-compilation-episodes-1-39](http://dancarlin.com/product/hardcore-history-compilation-episodes-1-39) with [https://overcast.fm](https://overcast.fm)'s 2x speed.
8
+
9
+ ## Installation
10
+
11
+ gem install #TODO
12
+
13
+ ## Usage
14
+
15
+ ### Generating an RSS Feed:
16
+
17
+ ``
18
+ phonocast create_feed
19
+ ``
20
+
21
+ ### Setup Yaml Config
22
+
23
+ Instead of passing the same arguments to the CLI each time, you can
24
+ store them ina YAML file. The YAML file also provides configuration
25
+ options not available by the CLI.
26
+
27
+ To generate the YAML file:
28
+ ``
29
+ phonocast setup
30
+ ``
31
+
32
+ ## Feed Config Options.
33
+
34
+ Options can be set by YAML or CLI arguments. The order of
35
+ precedence is:
36
+
37
+ DEFAULTS -> YAML -> CLI Arguments.
38
+
39
+ So if you have YAML.title = "Title 1" and CLI.title = "Title 2", the
40
+ title used will be "Title 2". Generally speaking, store your config in YAML and use CLI arguments for
41
+ one off overrides.
42
+
43
+ All itunes\_ tags correspond to iTunes RSS spec.
44
+
45
+ | Name | CLI | YAML | Desc |
46
+ | ------------- | --- | ---- | ---------------- |
47
+ | base_url | Y | Y | Url where audio files are hosted, e.g. myserver.com/podcasts or mypublicdropbox.com. Defaults to link. |
48
+ | rss_path | Y | Y | Location and name of generated rss file. Default: ./phonocast.rss |
49
+ | file_path | Y | Y | Where are local audio files? Default: ./ |
50
+ | image_path | N | Y | Podcast log. base_url/image_path. Channel level. |
51
+ | title | Y | Y | Title of Podcast |
52
+ | link | Y | Y | Channel level link (e.g. mypodcast.com) |
53
+ | yaml_path | Y | Y | Location of YAML file for config. Default: ./phonocast.yaml |
54
+ | copyright | N | Y | Channel level |
55
+ | language | N | Y | Channel level |
56
+ | description | N | Y | Channel level |
57
+ | author | N | Y | Channel level |
58
+ | itunes_block | N | Y | Channel level |
59
+ | itunes_explicit | N | Y | Channel level |
60
+ | itunes_keywords | N | Y | Channel level |
61
+ | itunes_subtitle | N | Y | Defaults to description. |
62
+ | itunes_summary | N | Y | Defaults to description. |
63
+
64
+ ## Deployment
65
+
66
+ ### Private Server:
67
+ ``
68
+ scp -r . server:/path
69
+ ``
70
+
71
+ ### Dropbox:
72
+ Drag and drop to Dropbox Public folder and set base_url appropriately.
73
+
74
+ ## Contributing
75
+
76
+ Contributions welcome. Please open pull requests and include tests.
77
+
78
+ Need contribution ideas?
79
+
80
+ ``
81
+ grep -rni todo lib/
82
+ ``
83
+
84
+ ## Copyright
85
+
86
+ Copyright (c) 2015 Alex Blom. See LICENSE for further details.
data/bin/phonocast ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thor'
4
+ require 'phonocast'
5
+
6
+ class PhonocastCLI < Thor
7
+
8
+ desc "setup", "Init phonocast.yaml file"
9
+ long_desc <<-LONGDESC
10
+ Description:
11
+ Creates ./phonocast.yaml file, which can store values if you re-generate your feed.
12
+ LONGDESC
13
+ def setup_yaml
14
+ client = Phonocast::Client.new
15
+ client.setup_yaml
16
+ end
17
+
18
+ desc "create_feed", "Generate RSS Feed"
19
+ long_desc <<-LONGDESC
20
+ Create phonocast.rss file for podcast.
21
+
22
+ Config will load from DEFAULTS -> yaml_path -> CLI
23
+
24
+ Not all YAML keys are configurable by the CLI
25
+ LONGDESC
26
+ option :base_url, :required => false,
27
+ :description => 'where are files hosted? (e.g. myserver.com/data)'
28
+
29
+ option :target, :required => false,
30
+ :description => "set rss file target"
31
+
32
+ option :file_path, :required => false,
33
+ :description => "where are local files"
34
+
35
+ option :title, :required => false,
36
+ :description => "Title of Podcast Channel"
37
+
38
+ option :link, :required => false,
39
+ :description => "Channel level link"
40
+
41
+ option :yaml_path, :required => false,
42
+ :description => "Location of phonocast.yaml. Use if you don't want to repeat CLI commands"
43
+ def create_feed
44
+ client = Phonocast::Client.new(options.to_h)
45
+ client.create_feed
46
+ end
47
+ end
48
+
49
+ PhonocastCLI.start
data/lib/phonocast.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+
3
+ module Phonocast
4
+ require 'phonocast/client'
5
+ require 'phonocast/channel'
6
+ require 'phonocast/item'
7
+ require 'phonocast/configuration'
8
+
9
+ VERSION = "0.1.1"
10
+ end
@@ -0,0 +1,112 @@
1
+ require 'rss/2.0'
2
+ require 'rss/itunes'
3
+
4
+ class Phonocast::Channel
5
+
6
+ #A Channel represents a Podcast Channel
7
+ # (e.g. Hardcore History)
8
+ #
9
+ #A channel has many items (shows)
10
+
11
+ attr_accessor :title,
12
+ :file_path,
13
+ :rss_path,
14
+ :description,
15
+ :link,
16
+ :image_url,
17
+ :base_url,
18
+ :copyright,
19
+ :items,
20
+ :language,
21
+ :author,
22
+ :itunes_block,
23
+ :itunes_explicit,
24
+ :itunes_keywords,
25
+ :itunes_subtitle,
26
+ :itunes_summary
27
+
28
+ ALLOWED_EXTENSIONS = ['*.m4a',
29
+ '*.mp3' ,
30
+ '*.mov',
31
+ '*.mp4',
32
+ '*.m4v',
33
+ '*.pdf',
34
+ '*.epub']
35
+
36
+ def initialize(config)
37
+ validate_config(config)
38
+
39
+ @title = config.title
40
+ @file_path = config.file_path
41
+ @rss_path = config.rss_path
42
+ @description = config.description
43
+ @link = config.link
44
+ @base_url = config.base_url || @link
45
+ @copyright = config.copyright
46
+ @author = config.author
47
+ @itunes_subtitle = config.itunes_subtitle
48
+ @itunes_summary = config.itunes_summary
49
+ @language = config.language
50
+ @itunes_block = config.itunes_block
51
+
52
+ @image_url = "#{@base_url}/#{config.image_path}" if config.image_path
53
+
54
+ @items = []
55
+ init_items
56
+ end
57
+
58
+ #title, link & description req for rss output
59
+ def rss
60
+ rss = RSS::Rss.new("2.0")
61
+ channel = RSS::Rss::Channel.new
62
+
63
+ channel.title = @title
64
+ channel.link = @link
65
+ channel.description = @description
66
+ channel.generator = "Phonocast #{Phonocast::VERSION}"
67
+ #channel.author = @author
68
+ channel.itunes_image = RSS::ITunesChannelModel::ITunesImage.new(@image_url)
69
+ channel.itunes_subtitle = @itunes_subtitle
70
+ channel.itunes_summary = @itunes_summary
71
+
72
+ @items.each do |item|
73
+ channel.items << item.rss
74
+ end
75
+
76
+ rss.channel = channel
77
+
78
+ return rss.to_s
79
+ end
80
+
81
+ private
82
+ def validate_config(config)
83
+ if !config.base_url
84
+ warn "Warning: No base_url. Download links probably won't work"
85
+ end
86
+
87
+ [config.description,
88
+ config.title,
89
+ config.link].each do |key|
90
+ if !key || key.length < 1
91
+ raise ArgumentError.new("#{key} must be >1 char")
92
+ end
93
+ end
94
+ end
95
+
96
+ def init_items
97
+ podcast_files = collect_podcast_files(@file_path)
98
+ podcast_files.each do |file_name|
99
+ path = File.join(@file_path, file_name)
100
+ @items.push(Phonocast::Item.new(path, @base_url))
101
+ end
102
+ end
103
+
104
+ def collect_podcast_files(file_path)
105
+ podcast_files = []
106
+ Dir.chdir(file_path) do
107
+ podcast_files = Dir.glob(ALLOWED_EXTENSIONS)
108
+ end
109
+
110
+ return podcast_files
111
+ end
112
+ end
@@ -0,0 +1,40 @@
1
+ class Phonocast::Client
2
+
3
+ #A Client is how you interact with Phonocast
4
+ # (via CLI in 99% of cases)
5
+ #
6
+ #Pass a Client configuration opts
7
+ # Phonocast::Client.new(configuration)
8
+
9
+ attr_accessor :configuration, :channel
10
+
11
+ def initialize(opts={})
12
+ configuration(opts)
13
+ end
14
+
15
+ def configuration(opts={})
16
+ @configuration ||= Phonocast::Configuration.new(opts)
17
+ end
18
+
19
+ def configuration=(opts={})
20
+ @configuration = Phonocast::Configuration.new(opts)
21
+ end
22
+
23
+ def channel
24
+ @channel ||= Phonocast::Channel.new(configuration)
25
+ @channel
26
+ end
27
+
28
+ def setup_yaml
29
+ File.open('phonocast.yaml', 'w') do |f|
30
+ f.write(Phonocast::Configuration::DEFAULTS.to_yaml)
31
+ end
32
+ end
33
+
34
+ def create_feed
35
+ File.open(channel.rss_path, "w") do |f|
36
+ f.write(channel.rss.to_s)
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,66 @@
1
+ require 'yaml'
2
+
3
+ class Phonocast::Configuration
4
+
5
+ CONFIGURABLE_KEYS = %i( base_url
6
+ file_path
7
+ rss_path
8
+ image_path
9
+ title
10
+ link
11
+ copyright
12
+ language
13
+ description
14
+ author
15
+ itunes_block
16
+ itunes_explicit
17
+ itunes_keywords
18
+ itunes_subtitle
19
+ itunes_summary )
20
+
21
+ DEFAULTS = {
22
+ title: 'Phonocast Powered Podcast',
23
+ link: 'https://github.com/alexblom/phonocast',
24
+ file_path: './',
25
+ description: " ",
26
+ rss_path: "./phonocast.rss"
27
+ }
28
+
29
+ def initialize(opts={})
30
+ #attr_accessor for each CONFIGURABLE_KEY
31
+ setup_attr_accessors
32
+
33
+ #Start with a default config
34
+ config = DEFAULTS.clone
35
+
36
+ #YAML takes precedence to DEFAULTS
37
+ yaml_path = opts.delete(:yaml_path) || 'phonocast.yaml'
38
+ if File.exists?(yaml_path)
39
+
40
+ yaml = YAML.load_file(yaml_path)
41
+ yaml.keys.each do |key|
42
+ yaml[(key.to_sym rescue key) || key] = yaml.delete(key)
43
+ end
44
+
45
+ config.merge!(yaml)
46
+ end
47
+
48
+ #opts take precedence to YAML
49
+ config.merge!(opts)
50
+
51
+ set_instance_variables(config)
52
+ end
53
+
54
+ private
55
+ def setup_attr_accessors
56
+ CONFIGURABLE_KEYS.each do |key|
57
+ self.class.__send__(:attr_accessor, key)
58
+ end
59
+ end
60
+
61
+ def set_instance_variables(config)
62
+ CONFIGURABLE_KEYS.each do |key|
63
+ instance_variable_set("@#{key.to_s}", config[key])
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,47 @@
1
+ require 'mp3info'
2
+
3
+ require 'rss/2.0'
4
+ require 'rss/itunes'
5
+
6
+ class Phonocast::Item
7
+
8
+ attr_accessor :title,
9
+ :published,
10
+ :link,
11
+ :author,
12
+ :file_size,
13
+ :itunes_duration
14
+
15
+ def initialize(path, base_url, author_override=nil)
16
+ mp3 = Mp3Info.open(path)
17
+ file = File.open(path)
18
+ file_name = File.basename path
19
+
20
+ @itunes_duration = mp3.length
21
+ @file_size = file.size
22
+ @link = "#{base_url}/#{file_name}"
23
+
24
+ mp3.tag.title ? @title = mp3.tag.title : @title = file_name
25
+ author_override ? @author = author_override : @author = mp3.tag.artist
26
+ mp3.tag2["TDR"] ? @published = mp3.tag2["TDR"] : @published = file.mtime
27
+ end
28
+
29
+ def rss
30
+ item = RSS::Rss::Channel::Item.new
31
+
32
+ item.title = @title
33
+ item.author = @author
34
+ item.pubDate = @published
35
+
36
+ item.guid = RSS::Rss::Channel::Item::Guid.new
37
+ item.guid.content = @link
38
+ item.guid.isPermaLink = true
39
+
40
+ item.enclosure = RSS::Rss::Channel::Item::Enclosure.new
41
+ item.enclosure.url = @link
42
+ item.enclosure.type = "audio/mp3"
43
+ item.enclosure.length = @file_size
44
+
45
+ return item
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phonocast
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Blom
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-mp3info
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: libxml-ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Create a Podcast feed from mp3 files
84
+ email: alex@alexblom.com
85
+ executables:
86
+ - phonocast
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE
91
+ - README.md
92
+ - bin/phonocast
93
+ - lib/phonocast.rb
94
+ - lib/phonocast/channel.rb
95
+ - lib/phonocast/client.rb
96
+ - lib/phonocast/configuration.rb
97
+ - lib/phonocast/item.rb
98
+ homepage: https://github.com/AlexBlom/phonocast
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.2.2
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Create a Podcast Feed from mp3 files
122
+ test_files: []
123
+ has_rdoc: