muzik 0.2.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eda1f09112cb4b20c59737e2a78bc34282673658313e4aa0a5218c9817e36366
4
- data.tar.gz: 23e559027996fc118af38d35d04702feff15d5b5cdecd1fe1a40174eac0a9ae6
3
+ metadata.gz: 250ee7b2c77575472dee61fe444ea5efa339394eb9568155a07ff1fe407b77a2
4
+ data.tar.gz: 8df12728541a2717296aa850ef2915fa2326f7a21a2d4944f5caac71936d7b2d
5
5
  SHA512:
6
- metadata.gz: 820b90c198f055c24876579b153bbbe24d0e99c4c76aa56002783bf37bc8e4c43d2475d2b71d22579dcc7e1d72dd43df10edcdea36283410a40c08930ad83ce9
7
- data.tar.gz: 4476b71689009650cc5a61420fdc24a4e8c1fdf41611880faa5e7c04b074e2045454ca515c1b7cc4de4ced71886eddb13b7863582c34bd0dd0947e8ebf120f4c
6
+ metadata.gz: 52740be7c889dbdafbda9812a2ad76f98a37c69fbba876a385ddfd3d63e46efc0e711252a720b1a6e0420e705f6c461ee6d259ed43f0b43c2cd30dfb94a7e721
7
+ data.tar.gz: b88a110716a61d7fae02cacd7df68ab69bb081f12e27a714d1c923514cce0365fc4de15e1b61f303d20c19c7d7a5a0e3d84383c53cbbc0c53ddb08f035f008ae
data/bin/muzik CHANGED
@@ -4,24 +4,27 @@ if ARGV.empty?
4
4
  puts('Available commands:')
5
5
  [
6
6
  'sync [external PATH]',
7
- 'upload',
7
+ 'upload [nogithub]',
8
8
  'tag',
9
9
  'download',
10
10
  'stage',
11
11
  'init',
12
12
  'config [FIELD=VALUE...]',
13
+ 'patch',
13
14
  'refresh [cloud|local|external PATH]',
14
15
  'setup [cloud|local|external PATH]'
15
16
  ].each { |command| puts(" #{command}") }
16
17
  exit(true)
17
18
  end
18
19
 
20
+ base_path = "~/muzik#{'-debug' if ARGV.last == '-d'}"
21
+
19
22
  if ARGV.first == 'init'
20
23
  create_dir = lambda do |name|
21
24
  Dir.mkdir(name) unless Dir.exist?(name)
22
25
  end
23
26
 
24
- directory = File.expand_path('~/muzik')
27
+ directory = File.expand_path(base_path)
25
28
  create_dir.call(directory)
26
29
  create_dir.call("#{directory}/download")
27
30
  create_dir.call("#{directory}/upload")
@@ -37,7 +40,7 @@ def boom(message)
37
40
  exit(false)
38
41
  end
39
42
 
40
- location = File.expand_path('~/muzik/config.json')
43
+ location = File.expand_path("#{base_path}/config.json")
41
44
  boom('No config file found. Run `muzik init` to initialize it.') unless File.exists?(location)
42
45
 
43
46
  require 'json'
@@ -48,7 +51,7 @@ rescue StandardError
48
51
  boom('Error parsing config file.')
49
52
  end
50
53
 
51
- def instantiate(cloud: true, external: nil)
54
+ def instantiate(cloud: true, external: nil, github: true)
52
55
  require 'muzik'
53
56
 
54
57
  options = {
@@ -62,18 +65,22 @@ def instantiate(cloud: true, external: nil)
62
65
  else
63
66
  options.merge!(
64
67
  apple_music: CONFIG['apple_music'],
65
- github_access_token: CONFIG['github_access_token'],
66
- github_repo: CONFIG['github_repo'],
67
68
  local_path: CONFIG['local_path'],
68
69
  upload_path: CONFIG['upload_path']
69
70
  )
71
+ if github
72
+ options.merge!(
73
+ github_access_token: CONFIG['github_access_token'],
74
+ github_repo: CONFIG['github_repo']
75
+ )
76
+ end
70
77
  end
71
78
 
72
79
  Muzik::Client.new(**options)
73
80
  end
74
81
 
75
82
  def get_external_path(value)
76
- boom('No external path provided') unless value
83
+ boom('No external path provided') unless value && value != '-d'
77
84
 
78
85
  path = File.expand_path(value.to_s)
79
86
  boom("Invalid external path: #{value}") unless File.exists?(path)
@@ -85,7 +92,7 @@ begin
85
92
  case ARGV.first
86
93
  when 'sync'
87
94
  case ARGV[1]
88
- when nil
95
+ when nil, '-d'
89
96
  instantiate.sync
90
97
  when 'external'
91
98
  instantiate(external: get_external_path(ARGV[2])).sync
@@ -93,12 +100,19 @@ begin
93
100
  boom("Unknown sync option: #{ARGV[1]}")
94
101
  end
95
102
  when 'upload'
96
- instantiate.upload
103
+ case ARGV[1]
104
+ when nil, '-d'
105
+ instantiate.upload
106
+ when 'nogithub'
107
+ instantiate(github: false).upload
108
+ else
109
+ boom("Unknown upload option: #{ARGV[1]}")
110
+ end
97
111
  when 'tag'
98
112
  system('open', CONFIG['download_path'], '-a', CONFIG['tagging_app'])
99
113
  when 'download'
100
114
  system(
101
- 'youtube-dl',
115
+ 'yt-dlp',
102
116
  '-x',
103
117
  '--audio-format',
104
118
  'mp3',
@@ -115,6 +129,39 @@ begin
115
129
  end
116
130
 
117
131
  puts("#{file_count} file#{file_count == 1 ? '' : 's'} staged for upload.".green)
132
+ when 'auth'
133
+ location = CONFIG['google_drive_config_location']
134
+ require 'google_drive'
135
+ begin
136
+ GoogleDrive::Session.from_config(location)
137
+ puts('Google Drive authentication is working properly.'.green)
138
+ rescue Signet::AuthorizationError
139
+ begin
140
+ google_drive_config = JSON.parse(File.read(location))
141
+ rescue StandardError
142
+ boom('Error parsing Google Drive config file.')
143
+ end
144
+
145
+ google_drive_config = google_drive_config.slice('client_id', 'client_secret')
146
+ File.write(location, JSON.pretty_generate(google_drive_config))
147
+ GoogleDrive::Session.from_config(location)
148
+ puts('Google Drive authentication updated successfully.'.green)
149
+ end
150
+ when 'patch'
151
+ instantiate(github: false).upload
152
+ instantiate.refresh_cloud
153
+ when 'refresh'
154
+ case ARGV[1]
155
+ when 'cloud'
156
+ instantiate.refresh_cloud
157
+ when 'local'
158
+ instantiate.refresh_local
159
+ when 'external'
160
+ instantiate(external: get_external_path(ARGV[2])).refresh_local
161
+ else
162
+ unknown_refresh_type = ARGV[1] == '-d' ? '' : ARGV[1]
163
+ boom("Unknown refresh type: #{unknown_refresh_type}")
164
+ end
118
165
  when 'config'
119
166
  begin
120
167
  args = ARGV[1..].map { |arg| arg.split('=', 2) }.to_h
@@ -138,7 +185,7 @@ begin
138
185
  args.each { |arg, _| boom("Unkown argument: #{arg}") unless valid_args.include?(arg) }
139
186
  args = CONFIG.merge(args)
140
187
 
141
- directory = File.expand_path('~/muzik')
188
+ directory = File.expand_path(base_path)
142
189
  args['upload_path'] ||= File.expand_path("#{directory}/upload")
143
190
  args['download_path'] ||= File.expand_path("#{directory}/download")
144
191
  args['trash_path'] ||= File.expand_path("#{directory}/trash")
@@ -147,17 +194,6 @@ begin
147
194
  args['tagging_app'] ||= 'Mp3Tag'
148
195
 
149
196
  File.write("#{directory}/config.json", JSON.pretty_generate(args))
150
- when 'refresh'
151
- case ARGV[1]
152
- when 'cloud'
153
- instantiate.refresh_cloud
154
- when 'local'
155
- instantiate.refresh_local
156
- when 'external'
157
- instantiate(external: get_external_path(ARGV[2])).refresh_local
158
- else
159
- boom("Unknown refresh type: #{ARGV[1]}")
160
- end
161
197
  when 'setup'
162
198
  case ARGV[1]
163
199
  when 'cloud'
@@ -167,25 +203,8 @@ begin
167
203
  when 'external'
168
204
  instantiate(cloud: false, external: get_external_path(ARGV[2])).setup_local
169
205
  else
170
- boom("Unknown setup type: #{ARGV[1]}")
171
- end
172
- when 'auth'
173
- location = CONFIG['google_drive_config_location']
174
- require 'google_drive'
175
- begin
176
- GoogleDrive::Session.from_config(location)
177
- puts('Google Drive authentication is working properly.'.green)
178
- rescue Signet::AuthorizationError
179
- begin
180
- google_drive_config = JSON.parse(File.read(location))
181
- rescue StandardError
182
- boom('Error parsing Google Drive config file.')
183
- end
184
-
185
- google_drive_config = google_drive_config.slice('client_id', 'client_secret')
186
- File.write(location, JSON.pretty_generate(google_drive_config))
187
- GoogleDrive::Session.from_config(location)
188
- puts('Google Drive authentication updated successfully.'.green)
206
+ unknown_setup_type = ARGV[1] == '-d' ? '' : ARGV[1]
207
+ boom("Unknown setup type: #{unknown_setup_type}")
189
208
  end
190
209
  else
191
210
  boom("Unknown command: #{ARGV.first}")
data/lib/muzik/client.rb CHANGED
@@ -308,13 +308,15 @@ module Muzik
308
308
 
309
309
  unless directories[artist]
310
310
  directories[artist] =
311
- cloud_directory.subfolders(q: ['name = ? and trashed = false', artist]).first ||
312
- cloud_directory.create_subfolder(artist)
311
+ cloud_directory.subfolders(q: ['name = ? and trashed = false', artist]).first
312
+ if directories[artist].nil? || directories[artist].title != artist
313
+ directories[artist] = cloud_directory.create_subfolder(artist)
314
+ end
313
315
  end
314
316
 
315
317
  new_file_name = "#{title}.mp3".tr('/?#', '_')
316
318
  file = directories[artist].files(q: ['name = ? and trashed = false', new_file_name]).first
317
- if file && !file.trashed?
319
+ if file && !file.trashed? && file.title == new_file_name
318
320
  file.update_from_file(file_name)
319
321
  file = google_drive.file_by_id(file.id)
320
322
  else
data/lib/muzik/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Muzik
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muzik
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Russoniello
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-19 00:00:00.000000000 Z
11
+ date: 2025-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit