organo 0.3.0 → 0.3.2

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
  SHA256:
3
- metadata.gz: 07f88d3bafa6f79b66260174f984f415229f6f449da715b010df238d201c1eab
4
- data.tar.gz: 77efeae28ceefe926c10be6e6789ca5158fc49e1c405ea88c37932a087c40a5b
3
+ metadata.gz: 8691436aa9cdcb12c5de1da33b147103bcfa5d2459a3ad6b0ad868b4b49b2b44
4
+ data.tar.gz: 3f1b7419aaee87053d5b74f0227e6b9c5e4c36d783b672dafebbd6f3d1c07091
5
5
  SHA512:
6
- metadata.gz: f9cfb0f392479f25a6713525966805c30fd455403e2079f479337050b8722c2f9c5ddd294cbfab4992e20a691b3f09ef3695715feefa6b3fd9efa857f5bcbd87
7
- data.tar.gz: 637433a7ad969aeaab7cace448cea1b1a2b74a60891c384c8ab8ed2f48b0c46ec4506b0c003352c68b168d33a004b13f5da874800883958b824488f2b2291c0a
6
+ metadata.gz: 7e3e5e6c5e8898ab4552bd2b9cf108aef4de0075f13e5e1731cf4bda3917534cc19c88ecfc545ac41396d7f33e01311408d600b33e2331bbbfcd28a2f4decdad
7
+ data.tar.gz: 14046ec16b3a0986312e78567e226089346d1bba28a0d05b0c10996d7916e7c5a9787f9312ce567dcbf0f588f43485b17a57df2d0b526eb4ddacde29b9810bb7
@@ -9,17 +9,17 @@ module Organo
9
9
  module Add
10
10
 
11
11
  class AnimeEntry < Dry::CLI::Command
12
- desc "Add anime entry to files"
13
- argument :mal_id, type: :integer, required: true, desc: "MyAnimeList ID"
12
+ desc 'Add anime entry to files'
13
+ argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
14
14
 
15
15
  def call(mal_id:, **)
16
16
  json_obj = Query.get_anime_by_id(mal_id)
17
17
  show = SearchShow.new(json_obj['mal_id'], json_obj['title'], json_obj['images']['jpg']['image_url'])
18
18
  show_type = json_obj['type']
19
- file_name = (show_type == 'TV' ? "#{json_obj['year']}-#{json_obj['season']}" : show_type.downcase)
19
+ file_name = (show_type == 'TV' ? "#{json_obj['year']}_#{json_obj['season']}" : show_type.downcase)
20
20
  file_path = "#{Config::DEFAULT_DIR}/#{file_name}.json"
21
- show_list = File.exist?(file_path) ? Reader.read_file(file_path) : Array.new
22
- if (show_list.find_index { |s| s.id.to_s == mal_id.to_s }.nil?)
21
+ show_list = File.exist?(file_path) ? Reader.read_file(file_path) : []
22
+ if show_list.find_index { |s| s.id.to_s == mal_id.to_s }.nil?
23
23
  Writer.to_file(show_list.push(show).sort_by(&:title), file_path)
24
24
  puts "Added anime \"#{show.title}\" (#{mal_id})"
25
25
  else
@@ -9,7 +9,7 @@ module Organo
9
9
  module Add
10
10
 
11
11
  class SequelEntry < Dry::CLI::Command
12
- desc 'Add anime entry to files'
12
+ desc 'Add anime sequel entry to anime in file'
13
13
  argument :anime_mal_id, type: :integer, required: true, desc: 'Anime MyAnimeList ID'
14
14
  argument :sequel_mal_id, type: :integer, required: true, desc: 'Sequel MyAnimeList ID'
15
15
  argument :season_num, type: :integer, required: false, default: 0, desc: 'Season number'
@@ -23,13 +23,13 @@ module Organo
23
23
  show = shows_list.find { |s| s.id.to_s == anime_mal_id.to_s }
24
24
  next if show.nil?
25
25
 
26
- unless show.sequels.find { |s| s['id'].to_s == sequel_mal_id.to_s }
26
+ if show.sequels.find { |s| s['id'].to_s == sequel_mal_id.to_s }
27
+ puts 'Cannot add an already existing sequel.'
28
+ else
27
29
  sequel = Sequel.new(json_obj['mal_id'], json_obj['title'], json_obj['images']['jpg']['image_url'], season_num, type, type_num)
28
30
  show.sequels.push(sequel)
29
31
  Writer.to_file(shows_list, file_path)
30
32
  puts "Added sequel \"#{sequel.title}\" (#{sequel.id}) to anime."
31
- else
32
- puts 'Cannot add an already existing sequel.'
33
33
  end
34
34
  break
35
35
  end
@@ -8,11 +8,11 @@ module Organo
8
8
  module Get
9
9
 
10
10
  class BrokenLinks < Dry::CLI::Command
11
- desc "Get list of anime IDs that have broken links"
11
+ desc 'Get list of anime IDs that have broken links'
12
12
 
13
13
  def call(*)
14
14
  show_list = Reader.read_all_files
15
- broken_list = Array.new
15
+ broken_list = []
16
16
  show_list.each do |show|
17
17
  response = HTTParty.get(show.image_url)
18
18
  next unless response.code == 404
@@ -6,19 +6,19 @@ module Organo
6
6
  module Anime
7
7
 
8
8
  class Remove < Dry::CLI::Command
9
- desc "Remove anime entry from files"
10
- argument :mal_id, type: :integer, required: true, desc: "MyAnimeList ID"
9
+ desc 'Remove anime entry from files'
10
+ argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
11
11
 
12
12
  def call(mal_id:, **)
13
13
  Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
14
14
  shows_list = Reader.read_file(file_path)
15
15
  show_index = shows_list.find_index { |s| s.id.to_s == mal_id.to_s }
16
- if show_index >= 0
17
- show = shows_list.delete_at(show_index)
18
- Writer.to_file(shows_list, file_path)
19
- puts "Removed anime \"#{show.title}\" (#{mal_id})"
20
- break
21
- end
16
+ next unless show_index >= 0
17
+
18
+ show = shows_list.delete_at(show_index)
19
+ Writer.to_file(shows_list, file_path)
20
+ puts "Removed anime \"#{show.title}\" (#{mal_id})"
21
+ break
22
22
  end
23
23
  end
24
24
  end
@@ -6,11 +6,11 @@ module Organo
6
6
  module Anime
7
7
 
8
8
  class Search < Dry::CLI::Command
9
- desc "Search anime by query from files"
10
- argument :query, type: :string, required: true, desc: "Search query"
9
+ desc 'Search anime by query from files'
10
+ argument :query, type: :string, required: true, desc: 'Search query'
11
11
 
12
12
  def call(query:, **)
13
- found_list = Array.new
13
+ found_list = []
14
14
  Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
15
15
  shows_list = Reader.read_file(file_path)
16
16
  show = shows_list.find { |s| s.title.downcase.include? query }
@@ -6,17 +6,21 @@ module Organo
6
6
  module Anime
7
7
 
8
8
  class Show < Dry::CLI::Command
9
- desc "Show anime entry from files"
10
- argument :mal_id, type: :integer, required: true, desc: "MyAnimeList ID"
9
+ desc 'Show anime entry from files'
10
+ argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
11
11
 
12
12
  def call(mal_id:, **)
13
+ found = false
13
14
  Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
14
15
  shows_list = Reader.read_file(file_path)
15
16
  show = shows_list.find { |s| s.id.to_s == mal_id.to_s }
16
17
  next if show.nil?
17
18
 
19
+ found = true
18
20
  puts show.to_json
21
+ break
19
22
  end
23
+ puts 'Entry not found.' unless found
20
24
  end
21
25
  end
22
26
 
@@ -10,22 +10,35 @@ module Organo
10
10
  module Update
11
11
 
12
12
  class Image < Dry::CLI::Command
13
- desc "Update cover image for the specified anime"
14
- argument :mal_id_list, type: :array, required: true, desc: "MyAnimeList ID list"
13
+ desc 'Update cover image for the specified anime'
14
+ argument :mal_id_list, type: :array, required: true, desc: 'MyAnimeList ID list'
15
15
 
16
16
  def call(mal_id_list:, **)
17
+ found = false
17
18
  Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
18
19
  shows_list = Reader.read_file(file_path)
19
- mal_id_list.each do |mal_id|
20
+ mal_id_list.each_with_index do |mal_id, index|
20
21
  show = shows_list.find { |s| s.id.to_s == mal_id.to_s }
22
+ if show.nil?
23
+ shows_list.each do |s|
24
+ show = s.sequels.find { |ss| ss['id'].to_s == mal_id.to_s }
25
+ end
26
+ end
21
27
  next if show.nil?
22
28
 
23
- show.image_url = Query.get_anime_image(show.id)
29
+ found = true
30
+ if show.is_a?(Hash)
31
+ show['image_url'] = Query.get_anime_image(show['id'])
32
+ # puts show['image_url']
33
+ else
34
+ show.image_url = Query.get_anime_image(show.id)
35
+ # puts show.image_url
36
+ end
24
37
  Writer.to_file(shows_list, file_path)
25
- # puts show.image_url
38
+ sleep(1) if mal_id_list.size > 1 && index < (mal_id.size - 1)
26
39
  end
27
40
  end
28
- puts 'Cover image(s) has been updated.'
41
+ puts found ? 'Cover image(s) has been updated.' : 'Entry not found.'
29
42
  end
30
43
  end
31
44
 
@@ -9,9 +9,9 @@ module Organo
9
9
  module Update
10
10
 
11
11
  class SearchQuery < Dry::CLI::Command
12
- desc "Update search query for the specified anime"
13
- argument :mal_id, type: :integer, required: true, desc: "MyAnimeList ID"
14
- argument :search_query, type: :string, required: true, desc: "String query for Nyaa Torrents search"
12
+ desc 'Update search query for the specified anime'
13
+ argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
14
+ argument :search_query, type: :string, required: true, desc: 'String query for Nyaa Torrents search'
15
15
 
16
16
  def call(mal_id:, search_query:, **)
17
17
  Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
@@ -21,7 +21,7 @@ module Organo
21
21
 
22
22
  show.search_query = search_query
23
23
  Writer.to_file(shows_list, file_path)
24
- puts "Search query has been updated."
24
+ puts 'Search query has been updated.'
25
25
  end
26
26
  end
27
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Organo
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.2'
5
5
  end
data/lib/organo.rb CHANGED
@@ -29,32 +29,37 @@ module Organo
29
29
 
30
30
  register 'version', Version, aliases: %w[v -v --version]
31
31
  register 'init', Init
32
- register 'anime' do |prefix|
33
- prefix.register 'add', Anime::Add::AnimeEntry
34
- prefix.register 'add sequel', Anime::Add::SequelEntry
35
- prefix.register 'remove', Anime::Remove
36
- prefix.register 'show', Anime::Show
37
- prefix.register 'search', Anime::Search
38
- prefix.register 'update image', Anime::Update::Image
39
- prefix.register 'update search_query', Anime::Update::SearchQuery
40
- prefix.register 'get broken_links', Anime::Get::BrokenLinks
41
- end
42
- register 'api' do |prefix|
43
- prefix.register 'get anime', API::Get::Anime
44
- prefix.register 'get season', API::Get::Season
45
- prefix.register 'get sequels', API::Get::Sequels
46
- prefix.register 'search anime', API::Search::Anime
47
- end
48
- register 'merge', Merge
49
- register 'statistics', Statistics
50
- register 'remote' do |prefix|
51
- prefix.register 'add', Remote::Add
52
- prefix.register 'remove', Remote::Remove
53
- prefix.register 'download', Remote::Download
54
- prefix.register 'upload', Remote::Upload
55
- end
56
- register 'schedule' do |prefix|
57
- prefix.register 'create', Schedule::Create
32
+
33
+ if Dir.exist?('.organo')
34
+ register 'anime' do |prefix|
35
+ prefix.register 'add', Anime::Add::AnimeEntry
36
+ prefix.register 'add sequel', Anime::Add::SequelEntry
37
+ prefix.register 'remove', Anime::Remove
38
+ prefix.register 'show', Anime::Show
39
+ prefix.register 'search', Anime::Search
40
+ prefix.register 'update image', Anime::Update::Image
41
+ prefix.register 'update search_query', Anime::Update::SearchQuery
42
+ prefix.register 'get broken_links', Anime::Get::BrokenLinks
43
+ end
44
+ register 'api' do |prefix|
45
+ prefix.register 'get anime', API::Get::Anime
46
+ prefix.register 'get season', API::Get::Season
47
+ prefix.register 'get sequels', API::Get::Sequels
48
+ prefix.register 'search anime', API::Search::Anime
49
+ end
50
+ register 'merge', Merge
51
+ register 'statistics', Statistics
52
+ register 'remote' do |prefix|
53
+ prefix.register 'add', Remote::Add
54
+ prefix.register 'remove', Remote::Remove
55
+ prefix.register 'download', Remote::Download
56
+ prefix.register 'upload', Remote::Upload
57
+ end
58
+ register 'schedule' do |prefix|
59
+ prefix.register 'create', Schedule::Create
60
+ end
61
+ else
62
+ puts 'This directory has not been initialized.'
58
63
  end
59
64
  end
60
65
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: organo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Louis-Philippe Fortin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-05 00:00:00.000000000 Z
11
+ date: 2023-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli