nehm 1.5.6.2 → 1.6.1

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: 2a98659a7401715be66c19d94584b6b4cf61a6ee
4
- data.tar.gz: 4894022da20fef8bb3d91ab7725da2d6dd0c950c
3
+ metadata.gz: 0aa2bd91903adaec7cb6b378a83d169944a23e3a
4
+ data.tar.gz: 6fcea548ac666b3bef9ea038f0de23f1992d9eb4
5
5
  SHA512:
6
- metadata.gz: d102f1031a4224852a677e43074a72ebd5887c92089e6d0dae37fc3236784d7bcd454972537768c872b0de062ee08dd5b0f81237910d62f3141bd7da9fd5456e
7
- data.tar.gz: 6baaf1609ac27cbace77a748037c497b34c8161364f5446ca56ee51d131049b7e059d87e2166bb81607051a7e747355e3eaff79004b12f52e72d0f5655351fe2
6
+ metadata.gz: c5d5e134ee8b62dcb0ee356e5b4fcca17b64652c1581090f552bdb5f303f9d96e5f8a0c012f4617c2b1efca7973b7de5e2372e8422f955d3d9ca412ec2a72f9c
7
+ data.tar.gz: 1de3a085d88651abb6a3a8f16fd6d17116f3ee1ef8c7ba7baf1f4026eeca4203d43fe3cb79908dff1229e409a6ac145902a71c4d84d5c889792de0665083da9c
data/.gitignore CHANGED
@@ -8,3 +8,5 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .DS_Store
11
+ *.swp
12
+ *.gem
@@ -1,5 +1,13 @@
1
1
  # nehm change log
2
2
 
3
+ ## 1.6.1
4
+ * Fix nehm's fails when download tracks from url
5
+
6
+ ## 1.6
7
+ * Rewritten about 90% of code to make it more comfortable to read (improve code climate from 2.9 to 3.6)
8
+ * Add newlines before and after downloading track
9
+ * Clearer 'help' command
10
+
3
11
  ## 1.5.6.2
4
12
  * Excluding space and dash from removing in track's file name
5
13
 
data/README.md CHANGED
@@ -8,6 +8,11 @@
8
8
  [![Dependency Status](https://gemnasium.com/bogem/nehm.svg)](https://gemnasium.com/bogem/nehm)
9
9
  [![Code Climate](https://codeclimate.com/github/bogem/nehm/badges/gpa.svg)](https://codeclimate.com/github/bogem/nehm)
10
10
 
11
+ ## DISCLAIMER
12
+ ***For personal use only***
13
+
14
+ ***Nehm developer doesn't responsible for any illegal usage of this program***
15
+
11
16
  ## Installation
12
17
 
13
18
  **1. Install `taglib` library**
@@ -71,9 +76,7 @@ Enter path to desirable download directory (press enter to set it to ...
71
76
 
72
77
  * Get tracks to another directory
73
78
 
74
- `nehm get post from nasa to ~/Downloads` or `nehm dl like from bogem to current`
75
-
76
- *(if you type `to current`, `nehm` will get track to current working directory)*
79
+ `nehm get post to ~/Downloads` or `nehm dl like from bogem to .`
77
80
 
78
81
  * Get tracks to another iTunes playlist
79
82
 
@@ -95,10 +98,6 @@ Enter path to desirable download directory (press enter to set it to ...
95
98
 
96
99
  `nehm help`
97
100
 
98
- ## TODO
99
-
100
- * Getting/downloading playlists from posts
101
-
102
101
  ##FAQ
103
102
 
104
103
  **Q: What is permalink?**
data/bin/nehm CHANGED
@@ -3,8 +3,13 @@ nehm_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  $LOAD_PATH.unshift(nehm_dir) unless $LOAD_PATH.include?(nehm_dir)
4
4
  require 'nehm'
5
5
 
6
+ $stderr = STDOUT
7
+
6
8
  begin
7
- Nehm::App.do(ARGV)
9
+ Nehm.start(ARGV)
8
10
  rescue Interrupt # SIGINT
9
11
  puts "\nGoodbye!"
12
+ Nehm::UI.term
13
+ rescue StandardError, Timeout::Error => ex
14
+ Nehm::UI.term "While executing nehm ... (#{ex.class})\n #{ex}"
10
15
  end
@@ -1,67 +1,50 @@
1
+ require 'colored'
1
2
  require 'highline'
2
- require 'paint'
3
3
 
4
- require 'nehm/applescript'
5
- require 'nehm/artwork'
6
- require 'nehm/cfg'
7
- require 'nehm/configure'
8
4
  require 'nehm/client'
9
- require 'nehm/get'
10
- require 'nehm/help'
11
- require 'nehm/os'
5
+ require 'nehm/cfg'
6
+ require 'nehm/command_manager'
12
7
  require 'nehm/path_manager'
13
- require 'nehm/playlist'
14
8
  require 'nehm/playlist_manager'
15
- require 'nehm/track'
16
- require 'nehm/user'
9
+ require 'nehm/ui'
17
10
  require 'nehm/user_manager'
18
- require 'nehm/version'
19
11
 
20
12
  module Nehm
21
- module App
22
- def self.do(args)
23
- init unless initialized?
24
13
 
25
- command = args.shift
26
- case command
27
- when 'get'
28
- Get[:get, args]
29
- when 'dl'
30
- Get[:dl, args]
31
- when 'configure'
32
- Configure.menu
33
- when 'version'
34
- puts Nehm::VERSION
35
- when 'help', nil
36
- Help.show(args.first)
37
- else
38
- puts Paint["Invalid command '#{command}'", :red]
39
- puts "Input #{Paint['nehm help', :yellow]} for all avalaible commands"
40
- end
41
- end
14
+ # TODO: add rake tests
15
+ # TODO: add search command
16
+ # TODO: add select command
42
17
 
43
- module_function
18
+ def self.start(args)
19
+ init unless initialized?
44
20
 
45
- def init
46
- puts Paint['Hello!', :green]
47
- puts 'Before using the nehm, you should set it up:'
48
- Cfg.create unless Cfg.exist?
21
+ CommandManager.run(args)
22
+ end
49
23
 
50
- PathManager.set_dl_path
51
- puts "\n"
24
+ module_function
52
25
 
53
- unless OS.linux?
54
- PlaylistManager.set_playlist
55
- puts "\n"
56
- end
26
+ def init
27
+ UI.success 'Hello!'
28
+ UI.say 'Before using the nehm, you should set it up:'
29
+ Cfg.create unless Cfg.exist?
57
30
 
58
- UserManager.log_in
31
+ PathManager.set_dl_path
32
+ UI.newline
59
33
 
60
- puts Paint["Now you can use nehm!\n", :green]
34
+ unless OS.linux?
35
+ PlaylistManager.set_playlist
36
+ UI.newline
61
37
  end
62
38
 
63
- def initialized?
64
- File.exist?(Cfg::FILE_PATH)
65
- end
39
+ UserManager.set_uid
40
+ UI.newline
41
+
42
+ UI.success "Now you can use nehm!\n"
43
+ sleep(1)
44
+ end
45
+
46
+ def initialized?
47
+ File.exist?(Cfg::FILE_PATH)
66
48
  end
49
+
67
50
  end
@@ -1,6 +1,10 @@
1
1
  module Nehm
2
- # Module which works with AppleScript scripts
2
+
3
+ ##
4
+ # AppleScript module calls all AppleScript scripts and returns results
5
+
3
6
  module AppleScript
7
+
4
8
  def self.add_track_to_playlist(track_path, playlist_name)
5
9
  `osascript \"#{script_path(:add_track_to_playlist)}\" \"#{track_path}\" \"#{playlist_name}\" > /dev/null`
6
10
  end
@@ -18,7 +22,8 @@ module Nehm
18
22
 
19
23
  def script_path(script_name)
20
24
  applescripts_path = File.expand_path(File.join(File.dirname(__FILE__), 'applescripts'))
21
- File.join(applescripts_path, "#{script_name.to_s}.applescript")
25
+ File.join(applescripts_path, "#{script_name}.applescript")
22
26
  end
27
+
23
28
  end
24
29
  end
@@ -1,6 +1,10 @@
1
1
  module Nehm
2
- # Artwork objects contains all needed information of track's artwork
2
+
3
+ ##
4
+ # Artwork objects contains all information of track's artwork
5
+
3
6
  class Artwork
7
+
4
8
  def initialize(track)
5
9
  @track = track
6
10
  end
@@ -9,11 +13,6 @@ module Nehm
9
13
  File.join('/tmp', "#{@track.id}.jpg")
10
14
  end
11
15
 
12
- # Use in Get.dl
13
- def name
14
- 'artwork'
15
- end
16
-
17
16
  def suicide
18
17
  File.delete(file_path)
19
18
  end
@@ -28,5 +27,6 @@ module Nehm
28
27
  end
29
28
  url.sub('large', 't500x500')
30
29
  end
30
+
31
31
  end
32
32
  end
@@ -1,9 +1,12 @@
1
1
  require 'bogy'
2
2
 
3
-
4
3
  module Nehm
4
+
5
+ ##
5
6
  # Cfg module manipulates with nehm's config file (~/.nehmconfig)
7
+
6
8
  module Cfg
9
+
7
10
  FILE_PATH = File.join(ENV['HOME'], '.nehmconfig')
8
11
  CONFIG_FILE = Bogy.new(file: FILE_PATH)
9
12
 
@@ -26,5 +29,6 @@ module Nehm
26
29
  def self.key?(key)
27
30
  CONFIG_FILE.to_h.key?(key.to_s)
28
31
  end
32
+
29
33
  end
30
34
  end
@@ -1,23 +1,95 @@
1
1
  require 'certifi'
2
+ require 'faraday'
3
+ require 'json'
2
4
  require 'soundcloud'
3
5
 
4
6
  module Nehm
5
- # Soundcloud API client.
7
+
8
+ ##
9
+ # Client module contains all SC API interaction methods
10
+
6
11
  module Client
7
- # Set a SSL certificate file path for SC API
12
+
13
+ ##
14
+ # SSL certificate file path for SC API
15
+
8
16
  ENV['SSL_CERT_FILE'] = Certifi.where
9
17
 
18
+ ##
10
19
  # SoundCloud API client ID
20
+
11
21
  CLIENT_ID = '11a37feb6ccc034d5975f3f803928a32'
12
22
 
13
- def self.get(*args)
14
- sc_client.get(*args)
23
+ ##
24
+ # SoundCloud client object
25
+
26
+ SC_CLIENT = Soundcloud.new(client_id: CLIENT_ID)
27
+
28
+ ##
29
+ # Max limit of tracks for correct SoundCloud requests
30
+
31
+ TRACKS_LIMIT = 200
32
+
33
+ ##
34
+ # Returns raw array of likes or posts (depends on argument 'type')
35
+
36
+ def self.tracks(count, type, uid)
37
+ UI.term "Invalid number of #{type}" if count == 0
38
+
39
+ iterations = count.to_f / TRACKS_LIMIT
40
+ iterations = iterations.ceil
41
+
42
+ tracks = []
43
+ iterations.times do |i|
44
+ limit = count < TRACKS_LIMIT ? count : TRACKS_LIMIT
45
+ count -= TRACKS_LIMIT
46
+
47
+ tracks +=
48
+ case type
49
+ when :likes
50
+ likes(limit, i * TRACKS_LIMIT, uid)
51
+ when :posts
52
+ posts(limit, i * TRACKS_LIMIT, uid)
53
+ end
54
+ end
55
+ tracks
56
+ end
57
+
58
+ ##
59
+ # Returns user hash from SoundCloud or nil if user doesn't exist
60
+
61
+ def self.user(permalink)
62
+ SC_CLIENT.get('/resolve', url: "https://soundcloud.com/#{permalink}")
63
+ rescue SoundCloud::ResponseError => e
64
+ return nil if e.message =~ /404/
65
+ end
66
+
67
+ ##
68
+ # Returns track hash from SoundCloud by specified url
69
+
70
+ def self.track(url)
71
+ SC_CLIENT.get('/resolve', url: url)
15
72
  end
16
73
 
17
74
  module_function
18
75
 
19
- def sc_client
20
- @client ||= Soundcloud.new(client_id: CLIENT_ID)
76
+ def likes(limit, offset, uid)
77
+ SC_CLIENT.get("/users/#{uid}/favorites?limit=#{limit}&offset=#{offset}")
78
+ end
79
+
80
+ ##
81
+ # Stantard SoundCloud Ruby wrapper doesn't support reposts if user
82
+ # isn't authorized
83
+ # But api-v2.soundcloud.com supports it
84
+
85
+ # TODO: use net/http instead of Faraday
86
+
87
+ def posts(limit, offset, uid)
88
+ conn = Faraday.new(url: 'https://api-v2.soundcloud.com/')
89
+ response = conn.get("/profile/soundcloud:users:#{uid}?limit=#{limit}&offset=#{offset}")
90
+ parsed = JSON.parse(response.body)
91
+ parsed['collection']
21
92
  end
93
+
22
94
  end
23
95
  end
@@ -0,0 +1,123 @@
1
+ require 'nehm/option_parser'
2
+
3
+ module Nehm
4
+
5
+ ##
6
+ # Base class for all Nehm commands. When creating a new nehm command, define
7
+ # #initialize, #execute, #arguments, #program_name, #summary and #usage
8
+ # (as appropriate).
9
+ # See the above mentioned methods for details.
10
+
11
+ class Command
12
+
13
+ ##
14
+ # Hash with options of the command.
15
+
16
+ attr_accessor :options
17
+
18
+ ##
19
+ # Hash with descriptions of each options.
20
+
21
+ attr_accessor :options_descs
22
+
23
+ ##
24
+ # In 'initialize' should be defined all options by method 'add_option'.
25
+ #
26
+ # See get_command.rb as example.
27
+
28
+ def initialize
29
+ @options = {}
30
+ end
31
+
32
+ ##
33
+ # Invoke the command with the given list of arguments.
34
+
35
+ def invoke(args)
36
+ handle_options(args)
37
+ execute
38
+ end
39
+
40
+ ##
41
+ # Handle the given list of arguments by parsing them and recording the
42
+ # results.
43
+
44
+ def handle_options(args)
45
+ parser = OptionParser.new(args, self)
46
+ parser.parse
47
+ end
48
+
49
+ ##
50
+ # Override to provide command handling.
51
+ #
52
+ # #options will be filled in with your parsed options, unparsed options will
53
+ # be left in #options[:args].
54
+
55
+ def execute
56
+ end
57
+
58
+ ##
59
+ # Override to provide details of the arguments a command takes.
60
+ #
61
+ # For example:
62
+ #
63
+ # def usage
64
+ # "#{program_name} COMMAND"
65
+ # end
66
+ #
67
+ # def arguments
68
+ # ['COMMAND', 'name of command to show help']
69
+ # end
70
+
71
+ def arguments
72
+ {}
73
+ end
74
+
75
+ ##
76
+ # The name of the command for command-line invocation.
77
+
78
+ def program_name
79
+ end
80
+
81
+ ##
82
+ # Override to display a short description of what this command does.
83
+
84
+ def summary
85
+ end
86
+
87
+ ##
88
+ # Override to display the usage for an individual nehm command.
89
+ #
90
+ # The text "[options]" is automatically appended to the usage text.
91
+
92
+ def usage
93
+ end
94
+
95
+ ##
96
+ # Add a command-line option.
97
+ #
98
+ # Nehm don't use options with dashes to be more user-friendly.
99
+ #
100
+ # See 'get_command.rb' as example.
101
+
102
+ def add_option(option, usage, desc)
103
+ @options_descs ||= {}
104
+
105
+ @options[option] = nil
106
+ @options_descs[usage] = desc
107
+ end
108
+
109
+ HELP = <<-EOF
110
+ #{'nehm'.green} is a console tool, which downloads, sets IDv3 tags and adds to your iTunes library your SoundCloud posts or likes in convenient way
111
+
112
+ #{'Avalaible nehm commands:'.yellow}
113
+ #{'get'.green} Download, set tags and add to your iTunes library last post or like from your profile
114
+ #{'dl'.green} Download and set tags last post or like from your profile
115
+ #{'configure'.green} Configure application
116
+ #{'help'.green} Show help for specified command
117
+ #{'version'.green} Show version of installed nehm
118
+
119
+ See #{'nehm help [command]'.yellow} to read about a specific subcommand
120
+ EOF
121
+
122
+ end
123
+ end