poddb_client 0.1.0
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.
- data/NOTES +10 -0
- data/README.markdown +6 -0
- data/Rakefile +70 -0
- data/bin/poddb +5 -0
- data/lib/interactive.vim +233 -0
- data/lib/poddb_client.rb +179 -0
- data/lib/poddb_client/downloading.rb +55 -0
- data/lib/poddb_client/version.rb +3 -0
- data/poddb_client.gemspec +28 -0
- metadata +68 -0
data/NOTES
ADDED
data/README.markdown
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'bundler'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
|
7
|
+
|
8
|
+
desc "release and build and push new website"
|
9
|
+
task :push => [:release, :web]
|
10
|
+
|
11
|
+
desc "Bumps version number up one and git commits"
|
12
|
+
task :bump do
|
13
|
+
basefile = "lib/poddb_client/version.rb"
|
14
|
+
file = File.read(basefile)
|
15
|
+
oldver = file[/VERSION = '(\d.\d.\d)'/, 1]
|
16
|
+
newver_i = oldver.gsub(".", '').to_i + 1
|
17
|
+
newver = ("%.3d" % newver_i).split(//).join('.')
|
18
|
+
puts oldver
|
19
|
+
puts newver
|
20
|
+
puts "Bumping version: #{oldver} => #{newver}"
|
21
|
+
newfile = file.gsub("VERSION = '#{oldver}'", "VERSION = '#{newver}'")
|
22
|
+
File.open(basefile, 'w') {|f| f.write newfile}
|
23
|
+
`git commit -am 'Bump'`
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "build and push website"
|
27
|
+
task :web => :build_webpage do
|
28
|
+
puts "Building and pushing website"
|
29
|
+
Dir.chdir "../project-webpages" do
|
30
|
+
`scp out/poddb_client.html zoe2@instantwatcher.com:~/danielchoi.com/public/software/`
|
31
|
+
`rsync -avz out/images-poddb_client zoe2@instantwatcher.com:~/danielchoi.com/public/software/`
|
32
|
+
`rsync -avz out/stylesheets zoe2@instantwatcher.com:~/danielchoi.com/public/software/`
|
33
|
+
`rsync -avz out/lightbox2 zoe2@instantwatcher.com:~/danielchoi.com/public/software/`
|
34
|
+
end
|
35
|
+
#`open http://danielchoi.com/software/poddb_client.html`
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "build webpage"
|
39
|
+
task :build_webpage do
|
40
|
+
`cp README.markdown ../project-webpages/src/poddb_client.README.markdown`
|
41
|
+
`cp coverage.markdown ../project-webpages/src/poddb_client.coverage.markdown`
|
42
|
+
Dir.chdir "../project-webpages" do
|
43
|
+
puts `ruby gen.rb poddb_client #{ViTunes::VERSION}`
|
44
|
+
`open out/poddb_client.html`
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
desc "git push and rake release bumped version"
|
50
|
+
task :bumped do
|
51
|
+
puts `git push && rake release`
|
52
|
+
Rake::Task["web"].execute
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "Run tests"
|
56
|
+
task :test do
|
57
|
+
$:.unshift File.expand_path("test")
|
58
|
+
require 'test_helper'
|
59
|
+
Dir.chdir("test") do
|
60
|
+
Dir['*_test.rb'].each do |x|
|
61
|
+
puts "requiring #{x}"
|
62
|
+
require x
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
MiniTest::Unit.autorun
|
67
|
+
end
|
68
|
+
|
69
|
+
task :default => :test
|
70
|
+
|
data/bin/poddb
ADDED
data/lib/interactive.vim
ADDED
@@ -0,0 +1,233 @@
|
|
1
|
+
let s:client_cmd = "ruby -Ilib bin/poddb"
|
2
|
+
let s:base_url = "http://localhost:3000"
|
3
|
+
|
4
|
+
let s:download_and_play_cmd = s:client_cmd." --download-and-play "
|
5
|
+
|
6
|
+
let s:poddb_cache_dir = $HOME."/.poddb/cache"
|
7
|
+
call system("mkdir -p ".s:poddb_cache_dir)
|
8
|
+
let s:favorite_podcasts_list = $HOME."/.poddb/favorites"
|
9
|
+
|
10
|
+
let s:download_list = []
|
11
|
+
|
12
|
+
autocmd VimLeave * :call <SID>write_download_list()<CR>
|
13
|
+
|
14
|
+
function! PoddbStatusLine()
|
15
|
+
return "%<%f\ | Press ".g:mapleader."? for help. "."%r%=%-14.(%l,%c%V%)\ %P"
|
16
|
+
endfunction
|
17
|
+
|
18
|
+
" main_window() is a list of items, shown from search and by show_podcast_items()
|
19
|
+
function! s:main_window()
|
20
|
+
let s:listbufnr = bufnr('')
|
21
|
+
setlocal cursorline
|
22
|
+
setlocal nowrap
|
23
|
+
setlocal textwidth=0
|
24
|
+
setlocal nomodifiable
|
25
|
+
setlocal statusline=%!PoddbStatusLine()
|
26
|
+
noremap <buffer> <cr> :call <SID>show_item()<cr>
|
27
|
+
noremap <buffer> l :call <SID>show_item()<cr>
|
28
|
+
noremap <buffer> d :call <SID>mark_for_download()<cr>
|
29
|
+
noremap <buffer> D :call <SID>download_and_play()<cr>
|
30
|
+
noremap <buffer> p :call <SID>show_podcast_items('')<cr>
|
31
|
+
noremap <buffer> <c-j> :call <SID>show_next_item(0)<CR>
|
32
|
+
noremap <buffer> <c-k> :call <SID>show_next_item(1)<CR>
|
33
|
+
noremap <buffer> f :call <SID>favorite_this_podcast()<CR>
|
34
|
+
autocmd BufEnter <buffer> :setlocal nowrap
|
35
|
+
noremap <buffer> <Leader>? :call <SID>help()<CR>
|
36
|
+
endfunction
|
37
|
+
|
38
|
+
function! s:item_window()
|
39
|
+
rightbelow split poddb-item-window
|
40
|
+
let s:itembufnr = bufnr('%')
|
41
|
+
setlocal buftype=nofile
|
42
|
+
noremap <buffer> <c-j> :call <SID>show_next_item(0)<CR>
|
43
|
+
noremap <buffer> <c-k> :call <SID>show_next_item(1)<CR>
|
44
|
+
noremap <buffer> d :call <SID>mark_for_download()<cr>
|
45
|
+
close
|
46
|
+
endfunction
|
47
|
+
|
48
|
+
function! s:show_item()
|
49
|
+
if s:is_podcast_list()
|
50
|
+
let podcastId = matchstr( matchstr(getline(line('.')), '\d\+\s*$'), '\d\+' )
|
51
|
+
call s:show_podcast_items(podcastId)
|
52
|
+
return
|
53
|
+
else
|
54
|
+
let itemId = matchstr(getline(line('.')), '\d\+$')
|
55
|
+
endif
|
56
|
+
if (itemId == '')
|
57
|
+
return
|
58
|
+
endif
|
59
|
+
let command = "curl -s '".s:base_url."/item/".itemId."'"
|
60
|
+
let res = system(command)
|
61
|
+
call s:focus_window(s:itembufnr)
|
62
|
+
silent! 1,$delete
|
63
|
+
silent! put! =res
|
64
|
+
normal 1G
|
65
|
+
wincmd p
|
66
|
+
endfunc
|
67
|
+
|
68
|
+
function! s:mark_for_download() range
|
69
|
+
if s:is_podcast_list()
|
70
|
+
return
|
71
|
+
end
|
72
|
+
call s:focus_window(s:listbufnr)
|
73
|
+
let itemId = matchstr( matchstr(getline(line('.')), '\d\+\s*$'), '\d\+' )
|
74
|
+
if itemId == ''
|
75
|
+
return
|
76
|
+
endif
|
77
|
+
setlocal modifiable
|
78
|
+
let lnum = a:firstline
|
79
|
+
while lnum <= a:lastline
|
80
|
+
let line = getline(lnum)
|
81
|
+
if (match(line, "^*") != -1)
|
82
|
+
let newline = substitute(line, '^*', ' ', '')
|
83
|
+
call filter(s:download_list, 'v:val == itemId')
|
84
|
+
else
|
85
|
+
let newline = substitute(line, '^.', '*', '')
|
86
|
+
call add(s:download_list, itemId)
|
87
|
+
endif
|
88
|
+
call setline(lnum, newline)
|
89
|
+
let lnum += 1
|
90
|
+
endwhile
|
91
|
+
setlocal nomodifiable
|
92
|
+
write
|
93
|
+
redraw
|
94
|
+
endfunc
|
95
|
+
|
96
|
+
function! s:write_download_list()
|
97
|
+
let outfile = s:poddb_cache_dir . "/download_list"
|
98
|
+
echo s:download_list
|
99
|
+
" sleep 1
|
100
|
+
call writefile(s:download_list, outfile)
|
101
|
+
endfunc
|
102
|
+
|
103
|
+
function! s:show_podcast_items(podcastId)
|
104
|
+
" Let user use p key from podcastlist and itemlist
|
105
|
+
" If p is pressed in podcastlist, podcastId will be blank, and we'll reuse
|
106
|
+
" s:show_item() to extract podcastId and call this method again.
|
107
|
+
if s:is_podcast_list() && a:podcastId == ''
|
108
|
+
call s:show_item()
|
109
|
+
return
|
110
|
+
end
|
111
|
+
if a:podcastId != ''
|
112
|
+
let podcastId = a:podcastId
|
113
|
+
else
|
114
|
+
let podcastId = matchstr( matchstr(getline(line('.')), '\d\+ |\s*\d\+$'), '\d\+' )
|
115
|
+
end
|
116
|
+
if (podcastId == '')
|
117
|
+
return
|
118
|
+
endif
|
119
|
+
let command = "curl -s '".s:base_url."/podcast/".podcastId."/items'"
|
120
|
+
let contents = system(command)
|
121
|
+
if contents =~ 'No matches\c'
|
122
|
+
echom "No items!"
|
123
|
+
return
|
124
|
+
endif
|
125
|
+
call s:focus_window(s:itembufnr)
|
126
|
+
close!
|
127
|
+
let outfile = s:poddb_cache_dir . "/podcast-" . podcastId . "-itemlist"
|
128
|
+
call writefile(split(contents, "\n"), outfile)
|
129
|
+
exec "e+3 ".outfile
|
130
|
+
call s:main_window()
|
131
|
+
endfunc
|
132
|
+
|
133
|
+
function! s:is_podcast_list()
|
134
|
+
let top_line = getline(1)
|
135
|
+
return top_line =~ "xml_url"
|
136
|
+
endfunct
|
137
|
+
|
138
|
+
function! s:favorite_this_podcast()
|
139
|
+
let is_podcast_list = s:is_podcast_list()
|
140
|
+
if is_podcast_list
|
141
|
+
let podcastId = matchstr( matchstr(getline(line('.')), '\d\+\s*$'), '\d\+' )
|
142
|
+
else
|
143
|
+
let podcastId = matchstr( matchstr(getline(line('.')), '\d\+ |\s*\d\+$'), '\d\+' )
|
144
|
+
endif
|
145
|
+
if (podcastId == '')
|
146
|
+
return
|
147
|
+
endif
|
148
|
+
if !is_podcast_list
|
149
|
+
call system("grep '^".podcastId."$' ".s:favorite_podcasts_list." || echo ".podcastId." >> ".s:favorite_podcasts_list)
|
150
|
+
echom "Added this podcast to favorites"
|
151
|
+
return
|
152
|
+
end
|
153
|
+
let line = getline('.')
|
154
|
+
if (match(line, "^@") != -1)
|
155
|
+
let newline = substitute(line, '^@', ' ', '')
|
156
|
+
let tmp = tempname()
|
157
|
+
" alter favorites file
|
158
|
+
call system("grep -v '^".podcastId."$' ".s:favorite_podcasts_list." | uniq > ".tmp." && mv ".tmp." ".s:favorite_podcasts_list)
|
159
|
+
else
|
160
|
+
let newline = substitute(line, '^ ', '@', '')
|
161
|
+
" append to favorites file
|
162
|
+
call system("echo ".podcastId." >> ".s:favorite_podcasts_list)
|
163
|
+
endif
|
164
|
+
setlocal modifiable
|
165
|
+
call setline(line('.'), newline)
|
166
|
+
setlocal nomodifiable
|
167
|
+
write!
|
168
|
+
normal 0
|
169
|
+
endfunc
|
170
|
+
|
171
|
+
function! s:download_and_play()
|
172
|
+
let itemId = matchstr( matchstr(getline(line('.')), '\d\+\s*$'), '\d\+' )
|
173
|
+
let outfile = s:poddb_cache_dir . "/download_and_play"
|
174
|
+
call system("echo ".itemId." > ".outfile)
|
175
|
+
call writefile(itemId, outfile)
|
176
|
+
qa!
|
177
|
+
endfunc
|
178
|
+
|
179
|
+
function! s:focus_window(target_bufnr)
|
180
|
+
if bufwinnr(a:target_bufnr) == winnr()
|
181
|
+
return
|
182
|
+
end
|
183
|
+
let winnr = bufwinnr(a:target_bufnr)
|
184
|
+
if winnr == -1
|
185
|
+
if a:target_bufnr == s:listbufnr
|
186
|
+
leftabove split
|
187
|
+
else
|
188
|
+
rightbelow split
|
189
|
+
endif
|
190
|
+
exec "buffer" . a:target_bufnr
|
191
|
+
else
|
192
|
+
exec winnr . "wincmd w"
|
193
|
+
endif
|
194
|
+
endfunction
|
195
|
+
|
196
|
+
function! s:show_next_item(previous)
|
197
|
+
if s:is_podcast_list()
|
198
|
+
return
|
199
|
+
end
|
200
|
+
let origbufnr = bufnr('%')
|
201
|
+
let fullscreen = (bufwinnr(s:listbufnr) == -1) " we're in full screen message mode
|
202
|
+
if fullscreen
|
203
|
+
split
|
204
|
+
exec 'b'. s:listbufnr
|
205
|
+
else
|
206
|
+
call s:focus_window(s:listbufnr)
|
207
|
+
end
|
208
|
+
if a:previous
|
209
|
+
normal k
|
210
|
+
else
|
211
|
+
normal j
|
212
|
+
endif
|
213
|
+
call s:show_item()
|
214
|
+
normal zz
|
215
|
+
if origbufnr == s:itembufnr
|
216
|
+
wincmd p
|
217
|
+
endif
|
218
|
+
normal 0
|
219
|
+
redraw
|
220
|
+
endfunction
|
221
|
+
|
222
|
+
function! s:help()
|
223
|
+
" This just displays the README
|
224
|
+
let res = system(s:client_cmd." --key-mappings")
|
225
|
+
echo res
|
226
|
+
endfunction
|
227
|
+
|
228
|
+
|
229
|
+
call s:main_window()
|
230
|
+
call s:item_window()
|
231
|
+
|
232
|
+
normal 3G
|
233
|
+
|
data/lib/poddb_client.rb
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
require 'poddb_client/downloading'
|
2
|
+
require 'cgi'
|
3
|
+
require 'optparse'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
class PoddbClient
|
7
|
+
|
8
|
+
# TODO: change to poddb.com
|
9
|
+
SERVER = "http://localhost:3000"
|
10
|
+
|
11
|
+
PODDB_DIR = "%s/.poddb" % ENV['HOME']
|
12
|
+
CACHE_DIR = "%s/.poddb/cache" % ENV['HOME']
|
13
|
+
`mkdir -p #{CACHE_DIR}`
|
14
|
+
|
15
|
+
VIMSCRIPT = "lib/interactive.vim"
|
16
|
+
ITEM_LIST_OUTFILE = "#{CACHE_DIR}/main.itemlist"
|
17
|
+
PODCAST_LIST_OUTFILE = "#{CACHE_DIR}/main.podcastlist"
|
18
|
+
FAVORITE_PODCASTS_FILE = "#{PODDB_DIR}/favorites"
|
19
|
+
DOWNLOAD_AND_PLAY_FILE = "#{CACHE_DIR}/download_and_play"
|
20
|
+
|
21
|
+
include PoddbClient::Downloading
|
22
|
+
|
23
|
+
def initialize(args)
|
24
|
+
@args = args
|
25
|
+
@options = {}
|
26
|
+
@outfile = ITEM_LIST_OUTFILE # changed only for podcast list
|
27
|
+
parse_options
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_options
|
31
|
+
OptionParser.new do |opts|
|
32
|
+
opts.banner = "Usage: poddb [options] [query]"
|
33
|
+
opts.separator ""
|
34
|
+
opts.on("-f", "--from-favorites", "Show all recent items from favorite podcasts") do
|
35
|
+
if ! File.size?(FAVORITE_PODCASTS_FILE)
|
36
|
+
puts "No podcasts found in #{FAVORITE_PODCASTS_FILE}"
|
37
|
+
exit
|
38
|
+
end
|
39
|
+
@items_from_favorites = true
|
40
|
+
end
|
41
|
+
opts.on("-a", "--add PODCAST_URL", "Add podcast with PODCAST_URL to the poddb database") do |podcast_url|
|
42
|
+
@add_podcast = podcast_url
|
43
|
+
end
|
44
|
+
opts.on("-l", "--list", "List all podcasts in the poddb database", "(If query is supplied, will return matching podcasts)") do
|
45
|
+
@list_podcasts = true
|
46
|
+
end
|
47
|
+
opts.on("-F", "--favorite-podcasts", "Show favorite podcasts") do
|
48
|
+
if ! File.size?(FAVORITE_PODCASTS_FILE)
|
49
|
+
puts "No podcasts found in #{FAVORITE_PODCASTS_FILE}"
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
@list_favorite_podcasts = true
|
53
|
+
end
|
54
|
+
opts.on("-t", "--type MEDIA_TYPE", "Return items of MEDIA_TYPE only (audio,video)") do |media_type|
|
55
|
+
@media_type_param = "&media_type=#{media_type}"
|
56
|
+
end
|
57
|
+
opts.on("--download-and-play ITEM_ID", "Download item and play with PODDB_MEDIA_PLAYER") do |item_id|
|
58
|
+
puts "Download and play #{item_id}"
|
59
|
+
end
|
60
|
+
opts.on("--key-mappings", "Show key mappings for Vim navigation interface") do
|
61
|
+
puts "KEYMAPPINGS"
|
62
|
+
exit
|
63
|
+
end
|
64
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
65
|
+
puts opts
|
66
|
+
exit
|
67
|
+
end
|
68
|
+
opts.on_tail("-v", "--version", "Show version number") do
|
69
|
+
require 'poddb_client/version'
|
70
|
+
puts "poddb #{VERSION}"
|
71
|
+
exit
|
72
|
+
end
|
73
|
+
end.parse!(@args)
|
74
|
+
@query = CGI::escape(@args.join(' ').strip)
|
75
|
+
end
|
76
|
+
|
77
|
+
def run
|
78
|
+
cleanup
|
79
|
+
if @add_podcast
|
80
|
+
add_podcast
|
81
|
+
elsif @list_podcasts || @list_favorite_podcasts
|
82
|
+
list_podcasts
|
83
|
+
interactive
|
84
|
+
elsif @items_from_favorites
|
85
|
+
items_from_favorites
|
86
|
+
interactive
|
87
|
+
else
|
88
|
+
search
|
89
|
+
interactive
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def add_podcast
|
94
|
+
puts "Adding podcast..."
|
95
|
+
res = Net::HTTP.post_form(URI.parse("#{SERVER}/podcasts"),
|
96
|
+
'url' => @add_podcast)
|
97
|
+
# TODO improve response
|
98
|
+
puts res.body
|
99
|
+
end
|
100
|
+
|
101
|
+
def interactive
|
102
|
+
if !STDOUT.tty?
|
103
|
+
puts @output
|
104
|
+
exit
|
105
|
+
end
|
106
|
+
if @output =~ /^No matches/i
|
107
|
+
puts @output
|
108
|
+
exit
|
109
|
+
end
|
110
|
+
|
111
|
+
File.open(@outfile, 'w') {|f| f.puts @output }
|
112
|
+
cmd = "vim -S #{VIMSCRIPT} #{@outfile} #{@poddb_env}"
|
113
|
+
puts cmd
|
114
|
+
system(cmd)
|
115
|
+
if download_and_play?
|
116
|
+
download_and_play
|
117
|
+
else
|
118
|
+
download_marked_items
|
119
|
+
end
|
120
|
+
cleanup
|
121
|
+
end
|
122
|
+
|
123
|
+
def list_podcasts
|
124
|
+
@outfile = PODCAST_LIST_OUTFILE
|
125
|
+
@output = if @list_podcasts
|
126
|
+
`curl -s #{SERVER}/podcasts?q=#{@query}`
|
127
|
+
elsif @list_favorite_podcasts
|
128
|
+
`curl -s #{SERVER}/podcasts?podcast_ids=#{favorite_podcast_ids.join(',')}`
|
129
|
+
end
|
130
|
+
if File.size?(FAVORITE_PODCASTS_FILE)
|
131
|
+
@output = @output.split("\n").map {|line|
|
132
|
+
# podcast_ids here are strings
|
133
|
+
if (podcast_id = line[/\d+$/,0]) && favorite_podcast_ids.include?(podcast_id)
|
134
|
+
line.sub(/^ /, "@")
|
135
|
+
else
|
136
|
+
line
|
137
|
+
end
|
138
|
+
}.join("\n")
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def items_from_favorites
|
143
|
+
@output = `curl -s '#{SERVER}/items?podcast_ids=#{favorite_podcast_ids.join(',')}#{@media_type_param}'`
|
144
|
+
mark_already_downloaded
|
145
|
+
end
|
146
|
+
|
147
|
+
def search
|
148
|
+
@output = `curl -s '#{SERVER}/search?q=#{@query}#{@media_type_param}'`
|
149
|
+
mark_already_downloaded
|
150
|
+
end
|
151
|
+
|
152
|
+
def cleanup
|
153
|
+
`rm -rf #{CACHE_DIR}/*`
|
154
|
+
end
|
155
|
+
|
156
|
+
private
|
157
|
+
|
158
|
+
def favorite_podcast_ids
|
159
|
+
if File.size?(FAVORITE_PODCASTS_FILE)
|
160
|
+
File.readlines(FAVORITE_PODCASTS_FILE).map(&:strip).select {|x| x != ''}
|
161
|
+
else
|
162
|
+
[]
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def mark_already_downloaded
|
167
|
+
@downloaded_item_ids = Dir['*poddb*'].map { |f| f[/poddb(\d+)/,1] }.compact
|
168
|
+
@output = @output.split(/\n/).map {|line|
|
169
|
+
item_id = line[/\d+$/,0]
|
170
|
+
if @downloaded_item_ids.include?(item_id)
|
171
|
+
line.sub(/^ /, 'D')
|
172
|
+
else
|
173
|
+
line
|
174
|
+
end
|
175
|
+
}.join("\n")
|
176
|
+
end
|
177
|
+
|
178
|
+
|
179
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
class PoddbClient
|
5
|
+
module Downloading
|
6
|
+
|
7
|
+
|
8
|
+
def titleize(s, maxlength=20)
|
9
|
+
s.gsub(/\W+/, '-')[0,maxlength].sub(/-$/, '')
|
10
|
+
end
|
11
|
+
|
12
|
+
def download(item_id)
|
13
|
+
response = `curl -s #{SERVER}/item/#{item_id}/download`
|
14
|
+
data = YAML::load(response)
|
15
|
+
item = data[:item]
|
16
|
+
podcast = data[:podcast]
|
17
|
+
enclosure_url = item[:enclosure_url]
|
18
|
+
title_fragment = titleize item[:title], 50
|
19
|
+
podcast_fragment = titleize podcast[:title], 40
|
20
|
+
|
21
|
+
filename_suffix = File.extname(URI.parse(enclosure_url).path)
|
22
|
+
|
23
|
+
@filename = "%s.%s.poddb%s%s" % [podcast_fragment, title_fragment, item_id.to_s, filename_suffix]
|
24
|
+
puts "Downloading #{enclosure_url} as #{@filename}"
|
25
|
+
cmd = "wget -O #{@filename} '#{enclosure_url}' && touch #{@filename}"
|
26
|
+
`#{cmd}`
|
27
|
+
end
|
28
|
+
|
29
|
+
def download_marked_items
|
30
|
+
download_list_file = "#{CACHE_DIR}/download_list"
|
31
|
+
return unless File.size?(download_list_file)
|
32
|
+
item_ids = File.readlines(download_list_file).
|
33
|
+
map {|line| line[/(\d+)\s*$/, 1]}.
|
34
|
+
compact.map {|x| x.to_i}
|
35
|
+
item_ids.each do |item_id|
|
36
|
+
download item_id
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def download_and_play?
|
42
|
+
File.size? DOWNLOAD_AND_PLAY_FILE
|
43
|
+
end
|
44
|
+
|
45
|
+
def download_and_play
|
46
|
+
item_id = File.read(DOWNLOAD_AND_PLAY_FILE).strip
|
47
|
+
abort("No item id found") if item_id !~ /\d/
|
48
|
+
download item_id
|
49
|
+
media_player_cmd = ENV['PODDB_MEDIA_PLAYER'] || 'mplayer'
|
50
|
+
exec("#{media_player_cmd} #@filename")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "poddb_client/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "poddb_client"
|
7
|
+
s.version = PoddbClient::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.required_ruby_version = '>= 1.8.6'
|
10
|
+
|
11
|
+
s.authors = ["Daniel Choi"]
|
12
|
+
s.email = ["dhchoi@gmail.com"]
|
13
|
+
s.homepage = "http://danielchoi.com/software/poddb_client.html"
|
14
|
+
s.summary = %q{Podcast aggregation from the command line}
|
15
|
+
s.description = %q{Podcast aggregation from the command line}
|
16
|
+
|
17
|
+
s.rubyforge_project = "poddb_client"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
|
24
|
+
message = "** Now please run poddb_client-install to install the Vim plugin **"
|
25
|
+
divider = "*" * message.length
|
26
|
+
s.post_install_message = [divider, message, divider].join("\n")
|
27
|
+
end
|
28
|
+
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: poddb_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Daniel Choi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-09-13 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Podcast aggregation from the command line
|
18
|
+
email:
|
19
|
+
- dhchoi@gmail.com
|
20
|
+
executables:
|
21
|
+
- poddb
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- NOTES
|
28
|
+
- README.markdown
|
29
|
+
- Rakefile
|
30
|
+
- bin/poddb
|
31
|
+
- lib/interactive.vim
|
32
|
+
- lib/poddb_client.rb
|
33
|
+
- lib/poddb_client/downloading.rb
|
34
|
+
- lib/poddb_client/version.rb
|
35
|
+
- poddb_client.gemspec
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://danielchoi.com/software/poddb_client.html
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message: |-
|
41
|
+
*******************************************************************
|
42
|
+
** Now please run poddb_client-install to install the Vim plugin **
|
43
|
+
*******************************************************************
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.8.6
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project: poddb_client
|
63
|
+
rubygems_version: 1.6.1
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Podcast aggregation from the command line
|
67
|
+
test_files: []
|
68
|
+
|