paradiso 0.1.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg/*
data/README.rdoc ADDED
@@ -0,0 +1,46 @@
1
+ = Paradiso
2
+
3
+ A small lightweight command line interface for mplayer.
4
+
5
+ == Install
6
+
7
+ sudo gem install paradiso
8
+
9
+ == Usage
10
+
11
+ To play files
12
+
13
+ paradiso file1 file2
14
+
15
+ To create a playlist
16
+
17
+ paradiso -pn playlist file1 file2 dir1
18
+
19
+ To play a playlist and remove the items that has been already played
20
+
21
+ paradiso -pd playlist
22
+
23
+ == Config file
24
+
25
+ Paradiso has some basic support for a config file
26
+
27
+ touch ~/.paradiso
28
+
29
+ Sample config file, in YAML
30
+
31
+ fullscreen : true
32
+ aspectratio : "16:10"
33
+
34
+ == TODO
35
+
36
+ * Handling rar-archives
37
+ * Better playlist support
38
+ * Other mediums then just avi et al(DVD, Bluray and so on)
39
+ * Handle meta-data
40
+ * Config stuff, file ratios and such.
41
+
42
+ == Copyright
43
+
44
+ Copyright (c) 2010 Victor Bergöö. See LICENSE for details.
45
+
46
+
data/Rakefile CHANGED
@@ -11,7 +11,6 @@ begin
11
11
  gem.homepage = "http://github.com/netfeed/paradiso"
12
12
  gem.authors = ["Victor Bergoo"]
13
13
  gem.add_dependency "popen4"
14
- gem.add_dependency "json"
15
14
  end
16
15
  Jeweler::GemcutterTasks.new
17
16
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.3.0
data/lib/paradiso/base.rb CHANGED
@@ -8,47 +8,41 @@ require 'paradiso/playlist'
8
8
  module Paradiso
9
9
  class Paradiso
10
10
  def initialize options, args
11
+ @playlist = []
11
12
  @options = options
12
- @pl_file = nil
13
13
  @pid = nil
14
+ @amount_played = 0
14
15
 
15
- if @options[:playlist] and args.size > 1 and not @options[:path]
16
- puts "Error: Can only handle one playlist"
17
- exit 1
18
- end
19
-
20
16
  if @options[:playlist] and not @options[:path]
21
- @pl_file = args.pop
22
- @playlist = Playlist.create_from_file @pl_file
17
+ args.each do |pl|
18
+ unless File.exist? pl
19
+ puts "Warning: playlist %s does not exist" % [pl]
20
+ next
21
+ end
22
+
23
+ @playlist << Playlist.create_from_file(pl)
24
+ end
23
25
  else
24
- @playlist = Playlist.new args
26
+ @playlist << Playlist.new(args, @options[:path])
25
27
  end
26
28
  end
27
29
 
28
30
  def run
29
- options_str = handle_options
30
- amount = 0
31
-
32
- @playlist.each do |item|
33
- if @options[:amount]
34
- break if amount == @options[:amount]
35
- amount += 1
36
- end
37
-
38
- puts "Playing #{item}"
39
-
40
- cmd = "mplayer #{options_str} \"#{item}\""
41
- POpen4::popen4(cmd) do |stdout, stderr, stdin, pid|
42
- @pid = pid
43
- end
31
+ @playlist.each do |pl|
32
+ break unless play? pl
44
33
  end
45
34
  rescue Interrupt
46
35
  Process.kill(9, @pid) if @pid
47
36
  puts "Exiting..."
48
37
  ensure
49
- if (@options[:path] or @options[:delete]) and @options[:playlist]
50
- file = @options[:path] ? @options[:path] : @pl_file
51
- @playlist.create file, @options[:delete]
38
+ @playlist.each do |pl|
39
+ if @options[:delete] and pl.empty?
40
+ pl.delete
41
+ end
42
+
43
+ if ((@options[:path] or @options[:delete]) and @options[:playlist]) and not pl.empty?
44
+ pl.create @options[:delete]
45
+ end
52
46
  end
53
47
  end
54
48
 
@@ -59,9 +53,7 @@ module Paradiso
59
53
  ratio = @options[:aspectratio]
60
54
 
61
55
  str += ['-monitoraspect', ratio, '-aspect', ratio]
62
- if @options[:fullscreen]
63
- str << "-fs"
64
- end
56
+ str << "-fs" if @options[:fullscreen]
65
57
 
66
58
  # more platforms needs to be added
67
59
  if RUBY_PLATFORM =~ /darwin10/
@@ -70,6 +62,26 @@ module Paradiso
70
62
 
71
63
  str.join " "
72
64
  end
65
+
66
+ def play? playlist
67
+ options_str = handle_options
68
+
69
+ playlist.each do |item|
70
+ unless @options[:amount].nil?
71
+ return false if @amount_played == @options[:amount]
72
+ @amount_played += 1
73
+ end
74
+
75
+ puts "Playing #{item}"
76
+
77
+ cmd = "mplayer #{options_str} \"#{item}\""
78
+ POpen4::popen4(cmd) do |stdout, stderr, stdin, pid|
79
+ @pid = pid
80
+ end
81
+ end
82
+
83
+ true
84
+ end
73
85
  end
74
86
  end
75
87
 
@@ -18,12 +18,13 @@ module Paradiso
18
18
  items << line.sub(/[\r\n]+/, '')
19
19
  end
20
20
 
21
- new items
21
+ new items, file
22
22
  end
23
23
  end
24
24
 
25
- def initialize files
25
+ def initialize files, path=nil
26
26
  @files = []
27
+ @path = path
27
28
  @current_idx = -1
28
29
 
29
30
  files.each do |file|
@@ -52,31 +53,39 @@ module Paradiso
52
53
 
53
54
  @files << other.files
54
55
  end
55
-
56
- def create path, delete=false
57
- # can this be made in a nicer way?
58
- start_point = case @current_idx
59
- when -1 then 0
60
- when 0 then 1
61
- else @current_idx + 1
62
- end
63
- start_point = 0 unless delete
64
-
65
- if (start_point >= @files.size) and delete
66
- File.delete path
67
- return
68
- end
56
+
57
+ def create delete=false
58
+ sp = delete ? start_point : 0
69
59
 
70
- File.open(path, 'w') do |f|
71
- @files[start_point..-1].each { |line| f.puts line }
60
+ File.open(@path, 'w') do |f|
61
+ @files[sp..-1].each { |line| f.puts line }
72
62
  end
73
63
  end
74
64
 
65
+ def delete
66
+ File.delete(@path) unless @path.nil?
67
+ end
68
+
75
69
  def each
76
70
  @files.each_index do |idx|
77
71
  yield @files[idx]
78
72
  @current_idx = idx
79
73
  end
80
74
  end
75
+
76
+ def empty?
77
+ start_point >= @files.size
78
+ end
79
+
80
+ private
81
+
82
+ def start_point
83
+ # can this be made in a nicer way?
84
+ case @current_idx
85
+ when -1 then 0
86
+ when 0 then 1
87
+ else @current_idx + 1
88
+ end
89
+ end
81
90
  end
82
91
  end
data/lib/paradiso.rb CHANGED
@@ -5,8 +5,9 @@
5
5
  dir = File.dirname(__FILE__)
6
6
  $LOAD_PATH.unshift(dir) unless $LOAD_PATH.include? dir
7
7
 
8
- require 'json'
9
8
  require 'optparse'
9
+ require 'yaml'
10
+
10
11
  require 'paradiso/base'
11
12
 
12
13
  module Paradiso
@@ -36,13 +37,9 @@ module Paradiso
36
37
 
37
38
  config_file = File.expand_path('~/.paradiso')
38
39
  if File.exist? config_file
39
- begin
40
- json = JSON.parse(File.open(config_file, 'r').read())
41
- json.each_pair do |key, value|
42
- options[key.to_sym] = value
43
- end
44
- rescue JSON::ParserError => e
45
- puts "Error: Parsing the config file failed, please check it"
40
+ yaml = YAML::load(File.open(config_file, 'r').read())
41
+ yaml.each_pair do |key, value|
42
+ options[key.to_sym] = value
46
43
  end
47
44
  end
48
45
 
@@ -53,7 +50,7 @@ module Paradiso
53
50
  args.options do |o|
54
51
  o.set_summary_indent ' '
55
52
  o.banner = "Usage: #{File.basename $0} [Options]"
56
- o.define_head "A simple mplayer CLI"
53
+ o.define_head "Paradiso #{VERSION}: A simple mplayer CLI"
57
54
 
58
55
  o.on_tail("-h", "--help", "Show this help message.") { puts o; exit }
59
56
  o.on_tail("-v", "--version", "Show version number") { puts "Paradiso %s" % [VERSION]; exit}
@@ -78,7 +75,7 @@ module Paradiso
78
75
  options[:path] = path
79
76
  }
80
77
 
81
- o.on("-p", "--playlist", "The argument is a playlist") {
78
+ o.on("-p", "--playlist", "The arguments is playlists") {
82
79
  options[:playlist] = true
83
80
  }
84
81
 
data/paradiso.gemspec CHANGED
@@ -5,22 +5,23 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{paradiso}
8
- s.version = "0.1.5"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Victor Bergoo"]
12
- s.date = %q{2010-10-04}
12
+ s.date = %q{2010-10-08}
13
13
  s.default_executable = %q{paradiso}
14
14
  s.description = %q{A simplified mplayer command line interface}
15
15
  s.email = %q{victor.bergoo@gmail.com}
16
16
  s.executables = ["paradiso"]
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE",
19
- "README.rst"
19
+ "README.rdoc"
20
20
  ]
21
21
  s.files = [
22
- "LICENSE",
23
- "README.rst",
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.rdoc",
24
25
  "Rakefile",
25
26
  "VERSION",
26
27
  "bin/paradiso",
@@ -41,14 +42,11 @@ Gem::Specification.new do |s|
41
42
 
42
43
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
44
  s.add_runtime_dependency(%q<popen4>, [">= 0"])
44
- s.add_runtime_dependency(%q<json>, [">= 0"])
45
45
  else
46
46
  s.add_dependency(%q<popen4>, [">= 0"])
47
- s.add_dependency(%q<json>, [">= 0"])
48
47
  end
49
48
  else
50
49
  s.add_dependency(%q<popen4>, [">= 0"])
51
- s.add_dependency(%q<json>, [">= 0"])
52
50
  end
53
51
  end
54
52
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paradiso
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 5
10
- version: 0.1.5
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Victor Bergoo
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-04 00:00:00 +02:00
18
+ date: 2010-10-08 00:00:00 +02:00
19
19
  default_executable: paradiso
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -32,20 +32,6 @@ dependencies:
32
32
  version: "0"
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: json
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
47
- type: :runtime
48
- version_requirements: *id002
49
35
  description: A simplified mplayer command line interface
50
36
  email: victor.bergoo@gmail.com
51
37
  executables:
@@ -54,10 +40,11 @@ extensions: []
54
40
 
55
41
  extra_rdoc_files:
56
42
  - LICENSE
57
- - README.rst
43
+ - README.rdoc
58
44
  files:
45
+ - .gitignore
59
46
  - LICENSE
60
- - README.rst
47
+ - README.rdoc
61
48
  - Rakefile
62
49
  - VERSION
63
50
  - bin/paradiso
data/README.rst DELETED
@@ -1,15 +0,0 @@
1
- Paradiso
2
- ========
3
-
4
- A small lightweight command line interface for mplayer_.
5
-
6
- TODO
7
- ----
8
-
9
- * Handling rar-archives(code already exists but doesn't work that great with OS X unrar)
10
- * Better playlist support
11
- * Other mediums then just avi et al(DVD, Bluray and so on)
12
- * Proper ID3 et al parsing
13
- * Config stuff, file ratios and such.
14
-
15
- .. _mplayer: http://www.mplayerhq.hu