unclekryon 0.4.9.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +34 -0
- data/Gemfile.lock +43 -0
- data/LICENSE +674 -0
- data/README.md +55 -0
- data/Rakefile +59 -0
- data/bin/unclekryon +30 -0
- data/iso/can_provs_terrs.yaml +54 -0
- data/iso/countries.yaml +3050 -0
- data/iso/iso.yaml +8 -0
- data/iso/languages.yaml +5641 -0
- data/iso/regions.yaml +42 -0
- data/iso/subregions.yaml +6 -0
- data/iso/usa_states.yaml +230 -0
- data/lib/unclekryon.rb +384 -0
- data/lib/unclekryon/data/album_data.rb +147 -0
- data/lib/unclekryon/data/artist_data.rb +109 -0
- data/lib/unclekryon/data/artist_data_data.rb +146 -0
- data/lib/unclekryon/data/aum_data.rb +75 -0
- data/lib/unclekryon/data/base_data.rb +79 -0
- data/lib/unclekryon/data/pic_data.rb +76 -0
- data/lib/unclekryon/data/release_data.rb +57 -0
- data/lib/unclekryon/data/social_data.rb +39 -0
- data/lib/unclekryon/data/timespan_data.rb +70 -0
- data/lib/unclekryon/dev_opts.rb +41 -0
- data/lib/unclekryon/hacker.rb +327 -0
- data/lib/unclekryon/iso.rb +341 -0
- data/lib/unclekryon/iso/base_iso.rb +196 -0
- data/lib/unclekryon/iso/can_prov_terr.rb +113 -0
- data/lib/unclekryon/iso/country.rb +133 -0
- data/lib/unclekryon/iso/language.rb +241 -0
- data/lib/unclekryon/iso/region.rb +53 -0
- data/lib/unclekryon/iso/subregion.rb +53 -0
- data/lib/unclekryon/iso/usa_state.rb +106 -0
- data/lib/unclekryon/jsoner.rb +124 -0
- data/lib/unclekryon/log.rb +111 -0
- data/lib/unclekryon/parsers/kryon_aum_year_album_parser.rb +499 -0
- data/lib/unclekryon/parsers/kryon_aum_year_parser.rb +413 -0
- data/lib/unclekryon/server.rb +29 -0
- data/lib/unclekryon/trainer.rb +231 -0
- data/lib/unclekryon/uploader.rb +29 -0
- data/lib/unclekryon/util.rb +228 -0
- data/lib/unclekryon/version.rb +26 -0
- data/unclekryon.gemspec +67 -0
- metadata +189 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
#--
|
6
|
+
# This file is part of UncleKryon-server.
|
7
|
+
# Copyright (c) 2018-2019 Jonathan Bradley Whited (@esotericpig)
|
8
|
+
#
|
9
|
+
# UncleKryon-server is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# UncleKryon-server is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with UncleKryon-server. If not, see <https://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
|
23
|
+
|
24
|
+
require 'date'
|
25
|
+
|
26
|
+
require 'unclekryon/util'
|
27
|
+
|
28
|
+
module UncleKryon
|
29
|
+
class BaseData
|
30
|
+
attr_accessor :updated_on
|
31
|
+
|
32
|
+
def initialize()
|
33
|
+
update()
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize_copy(original)
|
37
|
+
super(original)
|
38
|
+
|
39
|
+
@updated_on = @updated_on.clone()
|
40
|
+
end
|
41
|
+
|
42
|
+
def update()
|
43
|
+
@updated_on = Util.format_datetime(DateTime.now())
|
44
|
+
return @updated_on
|
45
|
+
end
|
46
|
+
|
47
|
+
def max_updated_on()
|
48
|
+
max = nil
|
49
|
+
|
50
|
+
instance_variables.each do |iv|
|
51
|
+
vuo = Util.parse_datetime_s(instance_variable_get(iv)) if iv.to_s() =~ /\A@updated_.+_on\z/
|
52
|
+
max = vuo if max.nil?() || vuo > max
|
53
|
+
end
|
54
|
+
|
55
|
+
return max
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.max_updated_on(data)
|
59
|
+
max = nil
|
60
|
+
|
61
|
+
if data.is_a?(Hash)
|
62
|
+
data.each() do |k,v|
|
63
|
+
vuo = Util.parse_datetime_s(v.updated_on)
|
64
|
+
max = vuo if max.nil?() || vuo > max
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
return max
|
69
|
+
end
|
70
|
+
|
71
|
+
def max_updated_on_s()
|
72
|
+
return Util.format_datetime(max_updated_on())
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.max_updated_on_s(data)
|
76
|
+
return Util.format_datetime(max_updated_on(data))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
#--
|
6
|
+
# This file is part of UncleKryon-server.
|
7
|
+
# Copyright (c) 2017-2019 Jonathan Bradley Whited (@esotericpig)
|
8
|
+
#
|
9
|
+
# UncleKryon-server is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# UncleKryon-server is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with UncleKryon-server. If not, see <https://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
|
23
|
+
|
24
|
+
require 'unclekryon/data/base_data'
|
25
|
+
|
26
|
+
module UncleKryon
|
27
|
+
class PicData < BaseData
|
28
|
+
attr_accessor :name
|
29
|
+
attr_accessor :filename
|
30
|
+
|
31
|
+
attr_accessor :alt
|
32
|
+
attr_accessor :caption
|
33
|
+
|
34
|
+
attr_accessor :url
|
35
|
+
attr_accessor :mirrors
|
36
|
+
|
37
|
+
def initialize()
|
38
|
+
super()
|
39
|
+
|
40
|
+
@name = ''
|
41
|
+
@filename = ''
|
42
|
+
|
43
|
+
@alt = ''
|
44
|
+
@caption = ''
|
45
|
+
|
46
|
+
@url = ''
|
47
|
+
@mirrors = {}
|
48
|
+
end
|
49
|
+
|
50
|
+
# Excludes @updated_on
|
51
|
+
def ==(y)
|
52
|
+
return @name == y.name &&
|
53
|
+
@filename == y.filename &&
|
54
|
+
@alt == y.alt &&
|
55
|
+
@caption == y.caption &&
|
56
|
+
@url == y.url &&
|
57
|
+
@mirrors == y.mirrors
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_s()
|
61
|
+
s = ''.dup()
|
62
|
+
|
63
|
+
if @name.empty?() || @name.strip().empty?()
|
64
|
+
s << ('%-100s' % [@url])
|
65
|
+
else
|
66
|
+
s << ('%-30s' % [@name])
|
67
|
+
s << (' | %30s' % [@filename]) unless @name == @filename
|
68
|
+
|
69
|
+
s << (' | %30s' % [@alt]) unless @name == @alt
|
70
|
+
s << (' | %60s' % [@caption])
|
71
|
+
end
|
72
|
+
|
73
|
+
return s
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
#--
|
6
|
+
# This file is part of UncleKryon-server.
|
7
|
+
# Copyright (c) 2017-2019 Jonathan Bradley Whited (@esotericpig)
|
8
|
+
#
|
9
|
+
# UncleKryon-server is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# UncleKryon-server is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with UncleKryon-server. If not, see <https://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
|
23
|
+
|
24
|
+
require 'unclekryon/data/base_data'
|
25
|
+
|
26
|
+
module UncleKryon
|
27
|
+
class ReleaseData < BaseData
|
28
|
+
attr_accessor :title
|
29
|
+
|
30
|
+
attr_accessor :url
|
31
|
+
attr_accessor :mirrors
|
32
|
+
|
33
|
+
attr_accessor :albums
|
34
|
+
|
35
|
+
def initialize()
|
36
|
+
super()
|
37
|
+
|
38
|
+
@title = ''
|
39
|
+
|
40
|
+
@url = ''
|
41
|
+
@mirrors = {}
|
42
|
+
|
43
|
+
@albums = []
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_mini_s()
|
47
|
+
return to_s(true)
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_s(mini=false)
|
51
|
+
s = ''
|
52
|
+
s << ('%-10s' % [@title])
|
53
|
+
s << (mini ? (' | %3d' % [@albums.length()]) : ("\n- " << @albums.join("\n- ")))
|
54
|
+
return s
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
#--
|
6
|
+
# This file is part of UncleKryon-server.
|
7
|
+
# Copyright (c) 2018-2019 Jonathan Bradley Whited (@esotericpig)
|
8
|
+
#
|
9
|
+
# UncleKryon-server is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# UncleKryon-server is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with UncleKryon-server. If not, see <https://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
|
23
|
+
|
24
|
+
##
|
25
|
+
# This should NOT extend BaseData/etc. It is basically just a container/struct.
|
26
|
+
##
|
27
|
+
module UncleKryon
|
28
|
+
class SocialData
|
29
|
+
attr_accessor :username
|
30
|
+
attr_accessor :url
|
31
|
+
|
32
|
+
def initialize()
|
33
|
+
super()
|
34
|
+
|
35
|
+
@username = ''
|
36
|
+
@url = ''
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
#--
|
6
|
+
# This file is part of UncleKryon-server.
|
7
|
+
# Copyright (c) 2017-2019 Jonathan Bradley Whited (@esotericpig)
|
8
|
+
#
|
9
|
+
# UncleKryon-server is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# UncleKryon-server is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with UncleKryon-server. If not, see <https://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
|
23
|
+
|
24
|
+
##
|
25
|
+
# This is for parsing/formatting mp3/etc. duration data.
|
26
|
+
# This should NOT extend BaseData/etc. It is basically just a String Util class.
|
27
|
+
##
|
28
|
+
module UncleKryon
|
29
|
+
class TimespanData
|
30
|
+
attr_accessor :hours
|
31
|
+
attr_accessor :mins
|
32
|
+
attr_accessor :secs
|
33
|
+
|
34
|
+
def initialize(time=nil)
|
35
|
+
@hours = 0
|
36
|
+
@mins = 0
|
37
|
+
@secs = 0
|
38
|
+
|
39
|
+
if !time.nil?() && !(time = time.strip()).empty?()
|
40
|
+
time = time.gsub(/\A[^\(]+\(/,'') # "One hour 6 minutes - (66 minutes)"
|
41
|
+
time = time.gsub(/[^[[:digit:]]\:\.]+/,'')
|
42
|
+
a = time.split(/[\:\.]/)
|
43
|
+
|
44
|
+
if a.length == 1
|
45
|
+
@mins = a[0].to_i()
|
46
|
+
elsif a.length == 2
|
47
|
+
@mins = a[0].to_i()
|
48
|
+
@secs = a[1].to_i()
|
49
|
+
elsif a.length >= 3
|
50
|
+
@hours = a[0].to_i()
|
51
|
+
@mins = a[1].to_i()
|
52
|
+
@secs = a[2].to_i()
|
53
|
+
end
|
54
|
+
|
55
|
+
if @secs >= 60
|
56
|
+
@mins += (@secs / 60)
|
57
|
+
@secs = @secs % 60
|
58
|
+
end
|
59
|
+
if @mins >= 60
|
60
|
+
@hours += (@mins / 60)
|
61
|
+
@mins = @mins % 60
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_s()
|
67
|
+
return "#{@hours}:#{@mins}:#{@secs}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
#--
|
6
|
+
# This file is part of UncleKryon-server.
|
7
|
+
# Copyright (c) 2018-2019 Jonathan Bradley Whited (@esotericpig)
|
8
|
+
#
|
9
|
+
# UncleKryon-server is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# UncleKryon-server is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with UncleKryon-server. If not, see <https://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
|
23
|
+
|
24
|
+
require 'singleton'
|
25
|
+
|
26
|
+
module UncleKryon
|
27
|
+
class DevOpts
|
28
|
+
include Singleton
|
29
|
+
|
30
|
+
attr_accessor :dev
|
31
|
+
attr_accessor :test
|
32
|
+
|
33
|
+
alias_method :dev?,:dev
|
34
|
+
alias_method :test?,:test
|
35
|
+
|
36
|
+
def initialize()
|
37
|
+
@dev = false
|
38
|
+
@test = false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,327 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
#--
|
6
|
+
# This file is part of UncleKryon-server.
|
7
|
+
# Copyright (c) 2017-2019 Jonathan Bradley Whited (@esotericpig)
|
8
|
+
#
|
9
|
+
# UncleKryon-server is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# UncleKryon-server is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with UncleKryon-server. If not, see <https://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
|
23
|
+
|
24
|
+
require 'bundler/setup'
|
25
|
+
|
26
|
+
require 'date'
|
27
|
+
|
28
|
+
require 'unclekryon/log'
|
29
|
+
require 'unclekryon/util'
|
30
|
+
|
31
|
+
require 'unclekryon/data/artist_data_data'
|
32
|
+
|
33
|
+
require 'unclekryon/parsers/kryon_aum_year_album_parser'
|
34
|
+
require 'unclekryon/parsers/kryon_aum_year_parser'
|
35
|
+
|
36
|
+
module UncleKryon
|
37
|
+
class Hacker
|
38
|
+
include Logging
|
39
|
+
|
40
|
+
HAX_DIRNAME = 'hax'
|
41
|
+
HAX_KRYON_FILENAME = 'kryon_<hax>_<release>.yaml'
|
42
|
+
|
43
|
+
TRAIN_DIRNAME = 'train'
|
44
|
+
TRAIN_KRYON_FILENAME = 'kryon.yaml'
|
45
|
+
|
46
|
+
attr_accessor :hax_dirname
|
47
|
+
attr_accessor :hax_kryon_filename
|
48
|
+
attr_accessor :no_clobber
|
49
|
+
attr_accessor :train_dirname
|
50
|
+
attr_accessor :train_kryon_filename
|
51
|
+
|
52
|
+
alias_method :no_clobber?,:no_clobber
|
53
|
+
|
54
|
+
def initialize(hax_dirname: HAX_DIRNAME,hax_kryon_filename: HAX_KRYON_FILENAME,no_clobber: false,
|
55
|
+
train_dirname: TRAIN_DIRNAME,train_kryon_filename: TRAIN_KRYON_FILENAME,**options)
|
56
|
+
@hax_dirname = hax_dirname
|
57
|
+
@hax_kryon_filename = hax_kryon_filename
|
58
|
+
@no_clobber = no_clobber
|
59
|
+
@train_dirname = train_dirname
|
60
|
+
@train_kryon_filename = train_kryon_filename
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_kryon_aum_year_album_parser(date,year=nil,index=nil)
|
64
|
+
pd = parse_date(date,year,index)
|
65
|
+
date = pd[:date]
|
66
|
+
index = pd[:index]
|
67
|
+
year = pd[:year]
|
68
|
+
|
69
|
+
# Try the yaml file
|
70
|
+
artist = ArtistDataData.load_file(get_hax_kryon_aums_filepath(year))
|
71
|
+
release = artist.releases[year]
|
72
|
+
|
73
|
+
if release.nil?()
|
74
|
+
# Try manually from the site
|
75
|
+
year_parser = create_kryon_aum_year_parser(year)
|
76
|
+
artist = year_parser.artist
|
77
|
+
release = year_parser.parse_site()
|
78
|
+
raise "Release[#{year}] does not exist" if release.nil?()
|
79
|
+
end
|
80
|
+
|
81
|
+
album = find_kryon_aum_year_album(artist,date,year,index)[0]
|
82
|
+
album_parser = KryonAumYearAlbumParser.new(artist,album.url)
|
83
|
+
|
84
|
+
album_parser.album = album
|
85
|
+
album_parser.trainers.filepath = get_train_kryon_filepath()
|
86
|
+
|
87
|
+
return album_parser
|
88
|
+
end
|
89
|
+
|
90
|
+
def create_kryon_aum_year_parser(year)
|
91
|
+
year_parser = KryonAumYearParser.new(year)
|
92
|
+
|
93
|
+
year_parser.trainers.filepath = get_train_kryon_filepath()
|
94
|
+
|
95
|
+
return year_parser
|
96
|
+
end
|
97
|
+
|
98
|
+
def find_kryon_aum_year_album(artist,date,year=nil,index=nil)
|
99
|
+
album = nil
|
100
|
+
albums = []
|
101
|
+
|
102
|
+
artist.albums.values.each_with_index do |a,i|
|
103
|
+
date_begin = Util.parse_date_s(a.date_begin)
|
104
|
+
date_end = Util.parse_date_s(a.date_end)
|
105
|
+
|
106
|
+
if (date_begin && ((date_end && date >= date_begin && date <= date_end) ||
|
107
|
+
(!date_end && date == date_begin)))
|
108
|
+
albums.push([a,i])
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
if !albums.empty?()
|
113
|
+
if index >= 0 && index < albums.length
|
114
|
+
album = albums[index]
|
115
|
+
else
|
116
|
+
raise "Invalid album ordinal number[#{index + 1}]"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
raise "Invalid album[#{date}]" if album.nil?()
|
121
|
+
|
122
|
+
return album
|
123
|
+
end
|
124
|
+
|
125
|
+
def parse_date(date,year=nil,index=nil)
|
126
|
+
if !date.is_a?(Date)
|
127
|
+
ds = date.split(':')
|
128
|
+
date = ds[0]
|
129
|
+
|
130
|
+
if index.nil?()
|
131
|
+
index = ds
|
132
|
+
index = (index.length <= 1) ? 0 : (index[1].to_i() - 1)
|
133
|
+
end
|
134
|
+
|
135
|
+
begin
|
136
|
+
new_date = Date.strptime(date,'%Y.%m.%d')
|
137
|
+
rescue ArgumentError
|
138
|
+
new_date = Date.strptime(date,'%m.%d')
|
139
|
+
|
140
|
+
if !year.nil?()
|
141
|
+
new_date = Date.new(year.to_i(),new_date.month,new_date.day)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
date = new_date
|
146
|
+
elsif index.nil?()
|
147
|
+
index = 0
|
148
|
+
end
|
149
|
+
|
150
|
+
if year.nil?()
|
151
|
+
# year is actually the release's title, so only override it if have to
|
152
|
+
year = date.year.to_s()
|
153
|
+
end
|
154
|
+
|
155
|
+
return {:date=>date,:index=>index,:year=>year}
|
156
|
+
end
|
157
|
+
|
158
|
+
def parse_kryon_aum_year(year)
|
159
|
+
year_parser = create_kryon_aum_year_parser(year)
|
160
|
+
release = year_parser.parse_site()
|
161
|
+
|
162
|
+
if @no_clobber
|
163
|
+
puts release.to_s()
|
164
|
+
else
|
165
|
+
year_parser.artist.save_to_file(get_hax_kryon_aums_filepath(year))
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def parse_kryon_aum_year_album(date,year=nil,index=nil)
|
170
|
+
pd = parse_date(date,year,index)
|
171
|
+
date = pd[:date]
|
172
|
+
index = pd[:index]
|
173
|
+
year = pd[:year]
|
174
|
+
|
175
|
+
album_parser = create_kryon_aum_year_album_parser(date,year,index)
|
176
|
+
album_parser.parse_site()
|
177
|
+
|
178
|
+
if @no_clobber
|
179
|
+
puts album_parser.album.to_s()
|
180
|
+
else
|
181
|
+
album_parser.artist.save_to_file(get_hax_kryon_aums_filepath(year))
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def parse_kryon_aum_year_albums(year,begin_album=nil)
|
186
|
+
if !begin_album.nil?()
|
187
|
+
pd = parse_date(begin_album,year)
|
188
|
+
begin_album = pd[:date]
|
189
|
+
index = pd[:index]
|
190
|
+
year = pd[:year]
|
191
|
+
end
|
192
|
+
|
193
|
+
# Try the yaml file
|
194
|
+
artist = ArtistDataData.load_file(get_hax_kryon_aums_filepath(year))
|
195
|
+
release = artist.releases[year]
|
196
|
+
updated_on = nil
|
197
|
+
|
198
|
+
if release.nil?()
|
199
|
+
# Try manually from the site
|
200
|
+
year_parser = create_kryon_aum_year_parser(year)
|
201
|
+
artist = year_parser.artist
|
202
|
+
release = year_parser.parse_site()
|
203
|
+
raise "Release[#{year}] does not exist" if release.nil?()
|
204
|
+
updated_on = release.updated_on
|
205
|
+
end
|
206
|
+
|
207
|
+
album_parser = KryonAumYearAlbumParser.new
|
208
|
+
album_parser.trainers.filepath = get_train_kryon_filepath()
|
209
|
+
album_parser.updated_on = updated_on unless updated_on.nil?()
|
210
|
+
|
211
|
+
albums = release.albums
|
212
|
+
|
213
|
+
if !begin_album.nil?()
|
214
|
+
album_index = find_kryon_aum_year_album(artist,begin_album,year,index)[1]
|
215
|
+
albums = albums[album_index..-1]
|
216
|
+
end
|
217
|
+
|
218
|
+
albums.each do |album_id|
|
219
|
+
album = artist.albums[album_id]
|
220
|
+
log.info("Hacking album[#{album.date_begin},#{album.date_end},#{album.title}]")
|
221
|
+
album = album_parser.parse_site(artist,album.url)
|
222
|
+
end
|
223
|
+
|
224
|
+
if @no_clobber
|
225
|
+
puts release.to_s()
|
226
|
+
else
|
227
|
+
artist.save_to_file(get_hax_kryon_aums_filepath(year))
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
def train_kryon_aum_year(year)
|
232
|
+
year_parser = create_kryon_aum_year_parser(year)
|
233
|
+
year_parser.training = true
|
234
|
+
year_parser.parse_site()
|
235
|
+
|
236
|
+
if @no_clobber
|
237
|
+
puts year_parser.trainers.to_s()
|
238
|
+
else
|
239
|
+
year_parser.trainers.save_to_file()
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def train_kryon_aum_year_album(date,year=nil,index=nil)
|
244
|
+
album_parser = create_kryon_aum_year_album_parser(date,year,index)
|
245
|
+
album_parser.training = true
|
246
|
+
album_parser.parse_site()
|
247
|
+
|
248
|
+
if @no_clobber
|
249
|
+
puts album_parser.trainers.to_s()
|
250
|
+
else
|
251
|
+
album_parser.trainers.save_to_file()
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def train_kryon_aum_year_albums(year,begin_album=nil)
|
256
|
+
if !begin_album.nil?()
|
257
|
+
pd = parse_date(begin_album,year)
|
258
|
+
begin_album = pd[:date]
|
259
|
+
index = pd[:index]
|
260
|
+
year = pd[:year]
|
261
|
+
end
|
262
|
+
|
263
|
+
# Try the yaml file
|
264
|
+
artist = ArtistDataData.load_file(get_hax_kryon_aums_filepath(year))
|
265
|
+
release = artist.releases[year]
|
266
|
+
|
267
|
+
if release.nil?()
|
268
|
+
# Try manually from the site
|
269
|
+
year_parser = create_kryon_aum_year_parser(year)
|
270
|
+
artist = year_parser.artist
|
271
|
+
release = year_parser.parse_site()
|
272
|
+
raise "Release[#{year}] does not exist" if release.nil?()
|
273
|
+
end
|
274
|
+
|
275
|
+
albums = release.albums
|
276
|
+
|
277
|
+
if !begin_album.nil?()
|
278
|
+
album_index = find_kryon_aum_year_album(artist,begin_album,year,index)[1]
|
279
|
+
albums = albums[album_index..-1]
|
280
|
+
end
|
281
|
+
|
282
|
+
albums.each do |album_id|
|
283
|
+
album = artist.albums[album_id]
|
284
|
+
|
285
|
+
album_parser = KryonAumYearAlbumParser.new
|
286
|
+
album_parser.album = album
|
287
|
+
album_parser.trainers.filepath = get_train_kryon_filepath()
|
288
|
+
album_parser.training = true
|
289
|
+
|
290
|
+
log.info("Training album[#{album.date_begin},#{album.date_end},#{album.title}]")
|
291
|
+
album = album_parser.parse_site(artist,album.url)
|
292
|
+
|
293
|
+
if @no_clobber
|
294
|
+
puts album_parser.trainers.to_s()
|
295
|
+
else
|
296
|
+
album_parser.trainers.save_to_file()
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
def get_hax_kryon_aums_filepath(release)
|
302
|
+
return get_hax_kryon_filepath('aums',release)
|
303
|
+
end
|
304
|
+
|
305
|
+
def get_hax_kryon_filepath(hax,release)
|
306
|
+
raise "Release (year) arg is nil" if release.nil?()
|
307
|
+
|
308
|
+
fn = @hax_kryon_filename.clone()
|
309
|
+
fn = fn.gsub('<hax>',hax)
|
310
|
+
fn = fn.gsub('<release>',release.to_s())
|
311
|
+
|
312
|
+
return File.join(@hax_dirname,fn)
|
313
|
+
end
|
314
|
+
|
315
|
+
def get_train_kryon_filepath()
|
316
|
+
return File.join(@train_dirname,@train_kryon_filename)
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
if $0 == __FILE__
|
322
|
+
hacker = UncleKryon::Hacker.new(no_clobber: true)
|
323
|
+
|
324
|
+
#hacker.parse_kryon_aum_year('2017')
|
325
|
+
#hacker.parse_kryon_aum_year_albums('2017')
|
326
|
+
hacker.train_kryon_aum_year_album('2.2','2017')
|
327
|
+
end
|