summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2021-11-21 23:32:00 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2021-11-21 23:32:00 +0100
commitde055404be5dceaf58733872c078b7a5c4816a3c (patch)
treeaf1ac7d747fa382cf1eae0dbec5b919f1c896c54
parentb71d86a5f16169bc53f86b86381700dfb5de0494 (diff)
downloadbin-de055404be5dceaf58733872c078b7a5c4816a3c.zip
bin-de055404be5dceaf58733872c078b7a5c4816a3c.tar.gz
tmdb : improve search capability
-rwxr-xr-xtmdb.rb28
1 files changed, 16 insertions, 12 deletions
diff --git a/tmdb.rb b/tmdb.rb
index 5c3084a..df8770c 100755
--- a/tmdb.rb
+++ b/tmdb.rb
@@ -41,32 +41,35 @@ idx = prev_db.collect { |m| m['filename'] }
current_db = []
def search fn
+ fn = fn.downcase.tr('àáâäçèéêëìíîïòóôöùúûü','aaaaceeeeiiiioooouuuu')
b,e = fn.split '.'
ar = b.split '-'
- name = ar[0].gsub('_', ' ').downcase
+ name = ar[0].gsub('_', ' ')
if ar.size == 2
year = ar[1]
elsif ar.size == 3
- sequel = ar[1]
+ sequel = ar[1].gsub('_', ' ')
year = ar[2]
- else
- return nil
end
- puts "search : #{name} - #{year}"
+ puts "search : #{name} - #{year} - #{sequel}"
begin
- res = JSON.load URI.open(SEARCH_M+name).read
+ res = JSON.load URI.open(SEARCH_M+name.tr('&','')).read
rescue
return nil
end
return nil if res['total_results'] == 0
sel = res['results'].select { |r| (r['release_date']||'nope')[0..3] == year }
return nil if sel.size == 0
- if sel.size > 1
+ if sel.size == 1
+ puts " found '#{sel[0]['title']}'"
+ else
puts " found #{sel.map {|s| s['title'] + ' ' + s['release_date']||'?' }}"
- sel = sel.select { |r| r['title'].downcase == name }
- if sel.size != 1
- return nil
- end
+ s = sel.select { |r| r['title'].downcase == name }
+ sel = s if s.size > 0
+ s = sel.select { |r| r['title'].downcase.gsub(/[^ a-z]/, '') =~ /#{name.gsub(/[^ a-z]/, '')}/ } if sel.size != 1
+ sel = s if s.size > 0
+ sel = sel.select { |r| r['title'].downcase =~ /#{sequel}/ } if sel.size != 1
+ return nil if sel.size != 1
puts " choose '#{sel[0]['title']}'"
end
sel[0]
@@ -98,7 +101,7 @@ end
Dir.glob(File.join(mpath, '*')) do |fn|
next if File.directory? fn
next if fn =~ /\.srt/ or fn =~ /\.rb/ or fn =~ /\.sub/ or fn =~ /\.jpg/
- fn = fn.split('/')[1]
+ fn = fn.split('/')[-1]
id = fix[fn]
if not id.nil?
m = prev_db.find{ |i| i['id'] == id and i['filename'] == fn }
@@ -112,6 +115,7 @@ Dir.glob(File.join(mpath, '*')) do |fn|
end
m = search fn
if m.nil?
+ puts ' failed'
failed << fn
else
current_db << fetch(m['id'], fn, m)