rmpv 0.0.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2487a11670195f3fabd534f591db039da2f8cbe3
4
- data.tar.gz: 124790e8faaaa875dac591e596eac4989d90a594
3
+ metadata.gz: 14cc0292b7e89738dd567e5f3d5ead179b58f41e
4
+ data.tar.gz: 87eee049d1d0b4e91e9d89ed55ff5e943dc45e77
5
5
  SHA512:
6
- metadata.gz: 6285a576b1893bc58b7cb59a03acc14f75608461e602c27c3fcd2f248a22e8921d50710e7255158d5000cd7d8267a8609e915403a361bc95e1329f5bae5b5437
7
- data.tar.gz: a9d559488ac547789bc35da11500c0a4ababdd99626fb76f41a58602ba658f0d05ef17c1eaad83b42629aba1f88d0296ec3164a5158a5f62b4fcfdc95228a3bb
6
+ metadata.gz: d46482ddee8fde0b9b1e956a39f1a35c849a95450526faaea843b25b2febca0bcb4b46a2dfee7d175229a1e6a1bd93fff039e5a0a8e2df480d42ec8ef7d45112
7
+ data.tar.gz: 864a9f3116a8643104aec6897496529c4fbc02baa1681e8c38440981119d557c5948fc02e18ac7199632fbbd5d2ebcd3587a1e9c6bfb60b639296dfdf42b2a23
data/README.md CHANGED
@@ -21,6 +21,23 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
+ First create a `.rmpvrc` file (which BTW is just a yaml file) in your home directory and add the following content:
25
+
26
+ ```yaml
27
+ trakt:
28
+ username: TRAKT_USERNAME
29
+ password: SHA1_HASH_OF_YOUR_PASSWORD
30
+ myanimelist:
31
+ username: MYANIMELIST_USERNAME
32
+ password: MYANIMELIST_PASSWORD
33
+ ```
34
+
35
+ You can use the following command to generate the SHA1 hash of your password:
36
+
37
+ ```sh
38
+ echo -n trakt_password | sha1sum | awk '{print toupper($1)}'
39
+ ```
40
+
24
41
  Usage: rmpv [options]
25
42
 
26
43
  -+, --vol=VOL increase volume by VOL
@@ -30,15 +47,12 @@ Or install it yourself as:
30
47
  -s, --size STR set size of the player
31
48
  -y, --youtube youtube mode
32
49
  -a, --audio audio mode
33
- -t, --trakt scrobble to trakt
50
+ -c, --scrobble STR scrobble 'movie' or 'show' to trakt or 'anime' to myanimelist
34
51
 
35
52
 
36
- TODO: Write usage instructions here
37
-
38
53
  ## Todo
39
54
 
40
55
  - Add myanimelist scrobble support
41
- - Use trakt scrobble rather than trakt seen for scrobbling. (This requires that we add scrobble support to [traktr](https://github.com/joelanford/traktr)).
42
56
 
43
57
  ## Contributing
44
58
 
data/bin/rmpv CHANGED
@@ -5,43 +5,108 @@
5
5
  require "shellwords"
6
6
  require "to_name"
7
7
  require "rmpv"
8
+ require 'highline/import'
8
9
 
9
- options = {
10
- volume: 0,
11
- speed: 1.0,
12
- }
13
-
14
- cmd = ["mpv"]
15
-
16
- # save position on exit
17
- cmd << "--save-position-on-quit"
18
-
19
- pwd = Dir.pwd
10
+ def yesno(prompt = 'Continue?', default = true)
11
+ a = ''
12
+ s = default ? '[Y/n]' : '[y/N]'
13
+ d = default ? 'y' : 'n'
14
+ until %w[y n].include? a
15
+ a = ask("#{prompt} #{s} ") { |q| q.limit = 1; q.case = :downcase }
16
+ a = d if a.length == 0
17
+ end
18
+ a == 'y'
19
+ end
20
20
 
21
21
  # check if there is a .mp file in the current directory and add it as options
22
-
23
22
  if File.exists? ".mp"
24
23
  File.open(".mp", "r").each do |line|
25
24
  ARGV << line.chomp
26
25
  end
27
- end
26
+ end
28
27
 
29
28
  # parse options
30
- cmd, options = Rmpv::Option.parse(ARGV, cmd, options)
31
-
29
+ cmd, options = Rmpv::Option.parse(ARGV)
32
30
  cmd = Rmpv::Option.command(cmd, options)
33
31
 
34
32
  # begin execution
35
33
  file = Shellwords.shelljoin(ARGV)
36
-
37
34
  mpv = cmd.join(" ") + " " + file
38
-
39
35
  puts "running '#{mpv}'..."
40
- system mpv
36
+
37
+ progress = 0
38
+ time = 0
39
+
40
+ # set as watching
41
+ if options[:method] == 'show'
42
+ show = ToName.to_name(file)
43
+ @trak = Rmpv::Trakt.new
44
+ wat = Thread.new do
45
+ loop do
46
+ duration = @trak.watching(show, progress)
47
+ sleep(600) # wait for 10 minutes
48
+ time += 10
49
+ progress = time*100/duration
50
+ puts progress
51
+ end
52
+ end
53
+ end
54
+
55
+ if options[:method] == 'movie'
56
+ movie = ToName.to_name(file)
57
+ @trak = Rmpv::Trakt.new
58
+ wat = Thread.new do
59
+ loop do
60
+ duration = @trak.watching(movie, progress, 'movie')
61
+ sleep(900) # wait for 15 minutes
62
+ time += 10
63
+ progress = time*100/duration
64
+ puts progress
65
+ end
66
+ end
67
+ end
68
+
69
+
70
+ pid = spawn(mpv)
71
+ Process.wait(pid)
72
+
73
+ Thread.kill(wat)
41
74
 
42
75
  # mark as seen on trakt
43
- if options[:trakt]
76
+ if options[:method] == 'show'
44
77
  show = ToName.to_name(file)
45
- trak = Rmpv::Trakt.new
46
- trak.scrobble(show)
78
+ @trak = Rmpv::Trakt.new
79
+ puts progress
80
+ if progress>=50
81
+ @trak.scrobble(show, progress)
82
+ else
83
+ choice = yesno("Did not complete. Do you still want to scrobble?", false)
84
+ if choice == 'y'
85
+ @trak.scrobble(show, progress)
86
+ else
87
+ exit
88
+ end
89
+ end
90
+ end
91
+
92
+ if options[:method] == 'movie'
93
+ movie = ToName.to_name(file)
94
+ @trak = Rmpv::Trakt.new
95
+ puts progress
96
+ if progress>=50
97
+ @trak.scrobble(movie, progress, 'movie')
98
+ else
99
+ choice = yesno("Did not complete. Do you still want to scrobble?", false)
100
+ if choice == 'y'
101
+ @trak.scrobble(movie, progress, 'movie')
102
+ else
103
+ exit
104
+ end
105
+ end
106
+ end
107
+
108
+ if options[:method] == 'anime'
109
+ @anime = Rmpv::Myanimelist.new
110
+ ani, ep = Rmpv::Myanimelist.parse(file)
111
+ @anime.scrobble(ani, ep)
47
112
  end
@@ -0,0 +1,3 @@
1
+ module Rmpv
2
+ BUILD = "Dec 25 2013"
3
+ end
@@ -5,6 +5,57 @@
5
5
  #
6
6
  # Copyright rejuvyesh <mail@rejuvyesh.com>, 2013
7
7
 
8
+ require 'yaml'
9
+ require 'myanimelist'
10
+ require 'httparty'
11
+
8
12
  module Rmpv
9
-
13
+ class MALRequester
14
+ include HTTParty
15
+ base_uri 'myanimelist.net'
16
+ # headers 'User-Agent' => "api-team-f894427cc1c571f79da49605ef8b112f"
17
+ end
18
+
19
+ class Myanimelist
20
+ ##
21
+ # Initialize the Myanimelist client
22
+ def initialize
23
+ myanimeconfig = YAML.load File.open("#{Dir.home}/.rmpvrc")
24
+ MyAnimeList.configure do |config|
25
+ config.username = myanimeconfig["myanimelist"]["username"]
26
+ config.password = myanimeconfig["myanimelist"]["password"]
27
+ end
28
+ end
29
+
30
+ ##
31
+ # Parse the file names
32
+ #
33
+ # @param [String] file name
34
+ # @return [String, Fixnum] name of the show and episode number
35
+ def parse(file)
36
+ raw_name = file
37
+ raw_name = raw_name[0, raw_name.rindex(/\./)] # remove extension
38
+ raw_name = raw_name.gsub(/(\.|_|\-)/, '') # Chars used in filenames as a substitute for spaces
39
+ raw_name = raw_name.gsub(/\(.*?\)/, '') # Remove anything surrounded by paranthesis
40
+ raw_name = raw_name.gsub(/\[.*?\]/, '') # Remove anything surrounded by paranthesis
41
+ ep = /(\d+)/.match(raw_name)[1]
42
+ name = raw_name.gsub(/(\d+)/, '').strip!
43
+ episode = ep.nil? ? 1 : ep.to_i
44
+ return name, episode
45
+ end
46
+
47
+ def scrobble(anime, ep)
48
+ tries = 5
49
+ begin
50
+ info = MyAnimeList.search_anime(anime)
51
+ rescue Exception => e
52
+ tries -= 1
53
+ if tries > 0
54
+ retry
55
+ else
56
+ puts "Couldn't connect to Myanimelist servers: #{e}"
57
+ end
58
+ end
59
+ end
60
+ end
10
61
  end
@@ -15,20 +15,19 @@ module Rmpv
15
15
  ##
16
16
  # Parses the commandline options
17
17
  # args : the arguments to be passed
18
- # cmd : variable to which options are being added
19
- # options : value of the options
20
18
  #
21
19
  # returns the new cmd and options
22
-
23
- def self.parse args, cmd, options
20
+
21
+ def self.parse(args)
22
+ cmd = ['mpv']
23
+ options = { volume: 0, speed: 1.0, }
24
24
  begin
25
25
  OptionParser.new do |opts|
26
- opts.banner = "Usage: rmpv [options]"
26
+ opts.banner = 'Usage: rmpv [options]'
27
27
 
28
28
  opts.on("-+", "--vol=VOL", Integer, "increase volume by VOL") do |v|
29
29
  options[:volume] = v
30
30
  end
31
-
32
31
  opts.on("-l", "--top-left", "play in top-left corner of the screen") do |tl|
33
32
  options[:position] = :top_left
34
33
  end
@@ -38,56 +37,60 @@ module Rmpv
38
37
  opts.on("-x", "--speed SPEED", Float, "increase speed by SPEED") do |x|
39
38
  options[:speed] = x
40
39
  end
41
- opts.on("-s", "--size STR", "set size of the player") do |sa|
40
+ opts.on("-s", "--size STR", "set size of the player") do |sa|
42
41
  options[:size] = sa
43
42
  end
44
43
  opts.on("-y", "--youtube", "youtube mode") do |y|
44
+ options[:mode] = 'youtube'
45
45
  options[:speed] = 1.5
46
- cmd << "--cache-default=2048"
47
46
  end
48
47
  opts.on("-a", "--audio", "audio mode") do |a|
49
- cmd << "--audio-display=no --gapless-audio"
48
+ options[:mode] = 'audio'
50
49
  end
51
- opts.on("-t", "--trakt", "scrobble to trakt") do |t|
52
- options[:trakt] = true;
50
+ opts.on("-c", "--scrobble STR", "scrobble 'movie' or 'show' to trakt or 'anime' to myanimelist") do |sa|
51
+ options[:method] = sa.downcase
53
52
  end
54
53
  end.parse!
55
-
56
54
  rescue OptionParser::InvalidOption => e
57
- cmd << e.to_s.sub(/^invalid option:\s+/, "")
55
+ cmd << e.to_s.sub(/^invalid option:\s+/, '')
58
56
  end
59
-
60
57
  return cmd, options
61
58
  end
62
59
 
63
60
  ##
64
61
  # Adds options to the command to be passed to mpv
65
-
66
- def self.command cmd, options
62
+
63
+ def self.command(cmd, options)
64
+ ## Saner defaults
65
+ # save position on exit
66
+ cmd << '--save-position-on-quit'
67
+ # audio filter
68
+ # Remove chirping at higher speed
69
+ cmd << "--af=scaletempo"
70
+
67
71
  # size
68
- if options[:size]
69
- cmd << "--autofit='#{options[:size]}'"
70
- end
72
+ cmd << "--autofit='#{options[:size]}'" if options[:size]
71
73
 
74
+ # position
72
75
  if options[:position] == :top_left
73
76
  cmd << "--geometry='0:17'"
74
77
  elsif options[:position] == :bottom_right
75
78
  cmd << "--geometry='100%:97%'"
76
79
  end
77
80
 
78
- # audio filter
79
- # Remove chirping at higher speed
80
- cmd << "--af=scaletempo"
81
- if options[:volume].nonzero?
82
- cmd << "--af=volume=#{options[:volume]}"
83
- end
81
+ # audio
82
+ cmd << "--af=volume=#{options[:volume]}" if options[:volume].nonzero?
83
+
84
+ cmd << "--audio-display=no --gapless-audio" if options[:mode] == 'audio'
84
85
 
85
86
  # speed increase
86
- if options[:speed] != 1.0
87
- cmd << "--speed=#{options[:speed]}"
88
- end
87
+ cmd << "--speed=#{options[:speed]}" if options[:speed] != 1.0
88
+
89
+ # youtube mode
90
+
91
+ cmd << "--cache-default=2048" if options[:mode] == 'youtube'
89
92
 
90
- return cmd
93
+ cmd
91
94
  end
92
95
  end
93
96
  end
@@ -5,36 +5,73 @@
5
5
  #
6
6
  # Copyright rejuvyesh <mail@rejuvyesh.com>, 2013
7
7
 
8
- require "traktr"
9
- require "yaml"
8
+ require 'traktr'
9
+ require 'yaml'
10
+ require 'rmpv/version'
10
11
 
11
12
  module Rmpv
12
13
  class Trakt
13
14
 
14
15
  ##
15
16
  # Initialize the trakt client
16
-
17
+ TRAKTAPIKEY = '5d7b4164188a3974e0ff4f0c571058dcd3a06f47'
18
+
17
19
  def initialize
18
- traktconfig = YAML.load File.open("#{Dir.home}/.traktrc")
19
- @trakt = Traktr::Client.new(traktconfig["api_key"], traktconfig["username"], traktconfig["password"], true)
20
+ traktconfig = YAML.load File.open("#{Dir.home}/.rmpvrc")
21
+ @trakt = Traktr::Client.new(TRAKTAPIKEY, \
22
+ traktconfig["trakt"]["username"], \
23
+ traktconfig["trakt"]["password"], true)
24
+ end
25
+
26
+ ##
27
+ # Set as watching
28
+
29
+ def watching(show, progress, type='show')
30
+ tries = 5
31
+ begin
32
+ if type == 'show'
33
+ info = @trakt.search.shows(show.name)
34
+ res = @trakt.show.watching(info[0], show.series, show.episode, \
35
+ progress, Rmpv::VERSION, Rmpv::BUILD)
36
+ elsif type == 'movie'
37
+ info = @trakt.search.movies(show.name)
38
+ res = @trakt.movie.watching(info[0], progress, \
39
+ Rmpv::VERSION, Rmpv::BUILD)
40
+ end
41
+ puts "Watching to trakt (Y) - #{show.name}"
42
+ rescue Exception => e
43
+ tries -= 1
44
+ if tries > 0
45
+ retry
46
+ else
47
+ puts "Couldn't connect to trakt servers: #{e}, #{res}"
48
+ end
49
+ end
50
+ info[0].runtime # return duration
20
51
  end
21
52
 
22
53
  ##
23
54
  # Scrobble the show
24
-
25
- def scrobble show
55
+
56
+ def scrobble(show, progress, type='show')
26
57
  tries = 5
27
58
  begin
28
- info = @trakt.search.shows(show.name)
29
- @episodes = @trakt.show.season(info[0].title, show.series)
30
- res = @trakt.show.episode.seen(info[0], @episodes[show.episode-1..show.episode-1])
31
- puts "Scrobbled to trakt (Y)"
59
+ if type == 'show'
60
+ info = @trakt.search.shows(show.name)
61
+ res = @trakt.show.scrobble(info[0], show.series, show.episode,\
62
+ progress, Rmpv::VERSION, Rmpv::BUILD)
63
+ elsif type == 'movie'
64
+ info = @trakt.search.movies(show.name)
65
+ res = @trakt.movie.scrobble(info[0], progress, \
66
+ Rmpv::VERSION, Rmpv::BUILD)
67
+ end
68
+ puts "Scrobbled to trakt (Y) - #{show.name}"
32
69
  rescue Exception => e
33
70
  tries -= 1
34
71
  if tries > 0
35
72
  retry
36
73
  else
37
- puts "Couldn't connect to trakt servers: #{res}"
74
+ puts "Couldn't connect to trakt servers: #{e}, #{res}"
38
75
  end
39
76
  end
40
77
  end
@@ -1,3 +1,3 @@
1
1
  module Rmpv
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -13,16 +13,23 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "http://github.com/rejuvyesh/rmpv"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.rdoc_options = ['--charset=UTF-8']
16
+ spec.has_rdoc = 'yard'
17
17
  spec.extra_rdoc_files = %w[README.md]
18
+
18
19
  spec.files = `git ls-files`.split($/)
19
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
21
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
22
  spec.require_paths = ["lib"]
22
23
 
24
+ spec.post_install_message = 'Please report any issues at: ' \
25
+ 'https://github.com/rejuvyesh/rmpv/issues/new'
26
+
23
27
  spec.add_development_dependency "bundler", "~> 1.3"
24
28
  spec.add_development_dependency "rake"
25
-
29
+ spec.add_development_dependency "yard"
30
+
26
31
  spec.add_dependency "traktr"
32
+ spec.add_dependency "myanimelist"
27
33
  spec.add_dependency "toname"
34
+ spec.add_dependency "highline"
28
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmpv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - rejuvyesh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-20 00:00:00.000000000 Z
11
+ date: 2013-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
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'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: traktr
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: myanimelist
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: toname
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +94,20 @@ dependencies:
66
94
  - - ">="
67
95
  - !ruby/object:Gem::Version
68
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: highline
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
69
111
  description: Ruby wrapper for mpv
70
112
  email:
71
113
  - mail@rejuvyesh.com
@@ -82,6 +124,7 @@ files:
82
124
  - Rakefile
83
125
  - bin/rmpv
84
126
  - lib/rmpv.rb
127
+ - lib/rmpv/build.rb
85
128
  - lib/rmpv/myanimelist.rb
86
129
  - lib/rmpv/option.rb
87
130
  - lib/rmpv/trakt.rb
@@ -91,9 +134,8 @@ homepage: http://github.com/rejuvyesh/rmpv
91
134
  licenses:
92
135
  - MIT
93
136
  metadata: {}
94
- post_install_message:
95
- rdoc_options:
96
- - "--charset=UTF-8"
137
+ post_install_message: 'Please report any issues at: https://github.com/rejuvyesh/rmpv/issues/new'
138
+ rdoc_options: []
97
139
  require_paths:
98
140
  - lib
99
141
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -113,4 +155,4 @@ signing_key:
113
155
  specification_version: 4
114
156
  summary: A ruby wrapper around mpv with trakt and myanimelist scobble support
115
157
  test_files: []
116
- has_rdoc:
158
+ has_rdoc: yard