pika 0.0.4

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.
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ test
19
+ .idea
@@ -0,0 +1,14 @@
1
+ ## 0.0.4, release 2012-10-11
2
+ * Bugfix in remote playlist files management
3
+ * Improved download output
4
+ * Removed file size information download
5
+
6
+ ## 0.0.3, release 2012-10-10
7
+ * Support for local playlist files
8
+
9
+ ## 0.0.2, release 2012-10-10
10
+ * Fix file information retrieve method call
11
+ * Output formatting
12
+
13
+ ## 0.0.1, release 2012-10-10
14
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pika.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Davide Targa
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Pika
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'pika'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install pika
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path(File.join( __FILE__, '..', '..', 'lib'))
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'pika'
@@ -0,0 +1,14 @@
1
+ require 'thor'
2
+ require 'net/http'
3
+ require 'xspf'
4
+ require 'active_support/all'
5
+ require 'colored'
6
+ require 'terminal-table'
7
+
8
+ require 'pika/version'
9
+ require 'pika/app'
10
+ require 'pika/operator'
11
+
12
+ module Pika
13
+ App.start
14
+ end
@@ -0,0 +1,47 @@
1
+ require 'fileutils'
2
+
3
+ module Pika
4
+
5
+ class App < Thor
6
+
7
+ map %w{-V --version} => :version
8
+
9
+ desc "version", "Displays the program's version"
10
+
11
+ def version
12
+ say "Pika version #{VERSION}"
13
+ end
14
+
15
+ desc "sync", "Show the status of the current playlist and update it"
16
+
17
+ method_option :input,
18
+ :desc => "Pika config file",
19
+ :aliases => "-i",
20
+ :type => :string,
21
+ :default => File.join(Dir.pwd, "pika.conf")
22
+
23
+ method_option :local_playlist,
24
+ :desc => "Local playlist file",
25
+ :aliases => "-f",
26
+ :type => :string
27
+
28
+ def sync
29
+ config_file = options[:input]
30
+ playlist_file = options[:local_playlist]
31
+ # playlist_file has precedence over pika config file
32
+ if playlist_file and File.exists?(playlist_file)
33
+ Operator.new.status(File.open(playlist_file).read, true)
34
+ else
35
+ if File.exist? config_file
36
+ Operator.new.status(File.expand_path config_file)
37
+ else
38
+ abort "Couldn't find Pika config file '#{config_file}'"
39
+ end
40
+ end
41
+ end
42
+
43
+ default_task :sync
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,104 @@
1
+ module Pika
2
+
3
+ class Operator
4
+
5
+ attr_reader :remote_tracks_urls, :missing_files_names, :missing_files_urls, :config_file
6
+
7
+ def status(file, local = false)
8
+ @config_file = file
9
+ if local
10
+ puts "Using local playlist file"
11
+ else
12
+ puts "Using config file: #{config_file}"
13
+ @config_file = fetch_playlist
14
+ end
15
+ initialize_locals(config_file)
16
+ puts "#{pluralize(missing_files_names.length, "tracks")} to download".yellow
17
+ extract_missing_files_urls
18
+ if missing_files_urls
19
+ begin
20
+ print "Download missing files? [Yn]: "
21
+ input = STDIN.gets
22
+ end while not ["Y", "y", "N", "n"].include? input.chomp
23
+ if positive?(input.chomp)
24
+ puts "Fetching files information. This may take some time..."
25
+ puts
26
+ download_missing_files
27
+ end
28
+ else
29
+ puts "Nothing to do here.".green
30
+ puts "Terminating."
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def download_missing_files
37
+ puts "### DOWNLOADING FILES ###".green
38
+ puts
39
+ missing_files_urls.each_with_index do |file, idx|
40
+ filename = file.split("/").last
41
+ puts "(#{idx + 1}/#{missing_files_urls.length}) Downloading: " + file.green + " => " + filename.green + " - " + ("%5.2f" %estimate_file_size(URI(file))) + " MB"
42
+ `curl -# -o #{filename} "#{file}"`
43
+ puts
44
+ end
45
+ puts "Done.".green
46
+ end
47
+
48
+ def estimate_file_size(url)
49
+ response = nil
50
+ Net::HTTP.start(url.host, url.port) do |http|
51
+ response = http.head(url.path)
52
+ end
53
+ response['content-length'].to_i / 1024.0 / 1024
54
+ end
55
+
56
+ def fetch_playlist
57
+ url = URI.parse(File.open(config_file).read)
58
+ puts "Fetching playlist information from: #{url}"
59
+ response = Net::HTTP.new(url.host, url.port).start { |http| http.request(Net::HTTP::Get.new(url.path)) }
60
+ response.body.to_s
61
+ end
62
+
63
+ def initialize_locals(content = nil)
64
+ if content
65
+ x = XSPF.new(content)
66
+ else
67
+ x = XSPF.new(fetch_playlist)
68
+ end
69
+ pl = XSPF::Playlist.new(x)
70
+ tl = XSPF::Tracklist.new(pl)
71
+ print "#{pluralize(tl.tracks.count, "track")} found".green + ", "
72
+ tl.tracks.each do |track|
73
+ (@remote_tracks_urls ||= []) << track.location
74
+ end
75
+ @missing_files_names = @remote_tracks_urls.map { |track_url| URI(track_url).path.split("/").last } - files_in_current_directory
76
+ end
77
+
78
+ def positive?(string)
79
+ ["Y", "y"].include?(string) ? true : false
80
+ end
81
+
82
+ def negative?(string)
83
+ ["N", "n"].include?(string) ? true : false
84
+ end
85
+
86
+ def pluralize(count, singular, plural = nil)
87
+ "#{count || 0} " + ((count == 1 || count =~ /^1(\.0+)?$/) ? singular : (plural || singular.pluralize))
88
+ end
89
+
90
+ def files_in_current_directory
91
+ Dir['**/*']
92
+ end
93
+
94
+ def extract_missing_files_urls
95
+ return [] if missing_files_names.empty?
96
+ missing_files_names.each do |mf|
97
+ (@missing_files_urls ||= []) << remote_tracks_urls.select { |el| el.split("/").last == mf }
98
+ end
99
+ @missing_files_urls.flatten!
100
+ end
101
+
102
+ end
103
+
104
+ end
@@ -0,0 +1,3 @@
1
+ module Pika
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/pika/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Davide Targa"]
6
+ gem.email = ["davide.targa@gmail.com"]
7
+ gem.description = %q{Download files from xspf playlists}
8
+ gem.summary = %q{Download files from xspf playlists}
9
+ gem.homepage = "https://github.com/davide-targa/pika"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "pika"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Pika::VERSION
17
+
18
+ gem.add_dependency 'xspf'
19
+ gem.add_dependency 'activesupport'
20
+ gem.add_dependency 'colored'
21
+ gem.add_dependency 'ruby-progressbar'
22
+ gem.add_dependency 'terminal-table'
23
+ gem.add_runtime_dependency "thor"
24
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pika
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Davide Targa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: xspf
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: colored
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: ruby-progressbar
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: terminal-table
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: thor
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Download files from xspf playlists
111
+ email:
112
+ - davide.targa@gmail.com
113
+ executables:
114
+ - pika
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - CHANGELOG.md
120
+ - Gemfile
121
+ - LICENSE
122
+ - README.md
123
+ - Rakefile
124
+ - bin/pika
125
+ - lib/pika.rb
126
+ - lib/pika/app.rb
127
+ - lib/pika/operator.rb
128
+ - lib/pika/version.rb
129
+ - pika.gemspec
130
+ homepage: https://github.com/davide-targa/pika
131
+ licenses: []
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 1.8.24
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: Download files from xspf playlists
154
+ test_files: []