tabcast 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/tabcast +58 -0
  3. data/lib/tabcast.rb +56 -0
  4. metadata +77 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 512c6ceae62e8c3f6d4f1f844911a6358fc1797c
4
+ data.tar.gz: 20ea730b89ad0ac9ccaaf3c6231c0cdbd7fe765a
5
+ SHA512:
6
+ metadata.gz: 93c4cd8945868a4b9ab1797f65cedaeec8d6fa45206fd8a332f3c63b7a2dacc0d1fab8424c32d3ace49af0add2c396ffe5e4b47c7cca6f34d38d3ac654f8ae41
7
+ data.tar.gz: 30eff9794c387dceb94cc5377485e33e6a3945f75616a2be657ad01a8e3190351f872353e995b216630b93c7b8bd0d0b8f3a572e2302d32d97b42e13fff079c5
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/ruby
2
+ require 'rss'
3
+ require 'open-uri'
4
+ require 'optparse'
5
+ require 'liquid'
6
+ require 'cgi'
7
+ require 'digest/md5'
8
+ require 'digest/sha1'
9
+ require 'tabcast'
10
+
11
+ options = {}
12
+
13
+ optparse = OptionParser.new do|opts|
14
+ #set default
15
+ options[:format] = '{{utime}}\t{{title | spaces_to_underscores}}\t{{enclosure_url}}\n'
16
+
17
+ opts.banner = "Usage: tabcast [-f FORMATSTRING] file1 file2 ...\n(FORMATSTRING is assumed to be '#{options[:format]}' unless specified)
18
+
19
+ FORMATSTRING is a Liquid template (http://liquidmarkup.org/) that will be rendered once for each feed item.
20
+
21
+ The following variables are available to the template:
22
+ {{ utime }} -> The pubDate time of the feed item as a Unix timestamp.
23
+ {{ title }} -> The title of the feed item with new lines removed.
24
+ {{ enclosure_url}} -> The full URL of the feed item's
25
+ {{ author }}, {{ itunes_author }} -> Just what it says on the tin.
26
+
27
+ The following filters are available to the template:
28
+ `whitespace_to_underscores` does exactly what it sounds like.
29
+ `md5` `and sha1` likewise.
30
+ `urlencode` is pretty self-explanatory too.
31
+
32
+ In addition, the following sequences are escaped to the equivalent literal characters:" +
33
+ '
34
+ `\t` -> literal tab
35
+ `\n` -> literal newline
36
+
37
+ '
38
+
39
+ opts.on( '-f', '--format FORMATSTRING', 'Output lines with FORMATSTRING' ) do |format|
40
+ options[:format] = format
41
+ end
42
+
43
+ opts.on( '-d', '--delimiter DELIMITER', 'Use some other than tabs as the field delimiter' ) do |delimiter|
44
+ options[:format] = "{{utime}}#{delimiter}{{title | spaces_to_underscores}}#{delimiter}{{enclosure_url}}" + '\n';
45
+ end
46
+
47
+ opts.on( '-h', '--help', 'Show usage.' ) do
48
+ puts opts
49
+ exit
50
+ end
51
+ end
52
+
53
+ optparse.parse!
54
+
55
+ ARGV.each do |url|
56
+ feed = TabCastFeed.new(url, options[:format])
57
+ puts feed.formatted
58
+ end
@@ -0,0 +1,56 @@
1
+ module Tabcast
2
+ VERSION = "0.1"
3
+
4
+ module TextFilter
5
+ def spaces_to_underscores(input)
6
+ input.gsub(/\s/, '_')
7
+ end
8
+
9
+ def urlencode(input)
10
+ CGI::escape(input)
11
+ end
12
+
13
+ def md5(input)
14
+ Digest::MD5.hexdigest(input)
15
+ end
16
+
17
+ def sha1(input)
18
+ Digest::SHA1.hexdigest(input)
19
+ end
20
+ end
21
+
22
+ Liquid::Template.register_filter(TextFilter)
23
+
24
+ class TabCastFeed
25
+ attr_reader :url, :feed, :template
26
+
27
+ def initialize(url, format)
28
+ @url = url
29
+ @items = RSS::Parser.parse(url, false).items
30
+ @template = Liquid::Template.parse(unescape(format))
31
+ end
32
+
33
+ def formatted
34
+ string = ""
35
+ @items.each do |i|
36
+ vars = Hash.new
37
+ vars['utime'] = i.pubDate.strftime('%s') if i.pubDate
38
+ vars['title'] = i.title.chomp if i.title
39
+ vars['enclosure_url'] = i.enclosure.url if i.enclosure && i.enclosure.url
40
+ vars['itunes_author'] = i.itunes_author if i.itunes_author
41
+ vars['author'] = i.author if i.author
42
+
43
+ string += @template.render(vars)
44
+ end
45
+ string
46
+ end
47
+
48
+ private
49
+
50
+ def unescape(string)
51
+ string.gsub!('\t', "\t")
52
+ string.gsub!('\n', "\n")
53
+ string
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tabcast
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Cameron Tindall
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: tabcast is a command that will take a podcast feed and format it's data
42
+ in a more shell-friendly format, by default into a tab-delimited list. It's powered
43
+ by the Liquid templating enging to make it very flexible.
44
+ email:
45
+ - ctindall@gmail.com
46
+ executables:
47
+ - tabcast
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - bin/tabcast
52
+ - lib/tabcast.rb
53
+ homepage: http://github.com/ctindall/tabcast
54
+ licenses:
55
+ - ''
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.2.2
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: A small command to help munge podcast feeds in shell scripts.
77
+ test_files: []