#! /bin/ruby require 'json' require 'open-uri' # tmdb [movie_path] [db_path] n = ARGV.size mpath = n.positive? ? ARGV.shift : File.dirname(__FILE__) dbpath = n > 1 ? ARGV.shift : File.join(mpath, 'db') puts " movies : #{mpath}\n db : #{dbpath}" API_KEY = JSON.parse(File.read(File.expand_path('~/.tmdb.json')))['apikey'] API_URL = 'https://api.themoviedb.org/3'.freeze SEARCH_M = "#{API_URL}/search/movie?api_key=#{API_KEY}&language=en-US&page=1&include_adult=true&".freeze SEARCH_T = SEARCH_M.sub(%r{/movie}, '/tv').freeze FETCH_M = "#{API_URL}/movie/ID?api_key=#{API_KEY}".freeze FETCH_T = FETCH_M.sub(%r{/movie}, '/tv').freeze FETCH_CM = "#{API_URL}/movie/ID/credits?api_key=#{API_KEY}".freeze FETCH_CT = FETCH_CM.sub(%r{/movie}, '/tv').freeze URL_M = 'https://www.themoviedb.org/movie/'.freeze URL_T = URL_M.sub(%r{/movie}, '/tv').freeze URL_A = 'https://www.themoviedb.org/person/'.freeze URL_I = 'https://www.themoviedb.org/t/p/original/'.freeze ACTORS_N = 6 ASZ = 150 MSZ = 350 BLANK = 'blank.png'.freeze DB = File.join(dbpath, 'db.json') FIX = File.join(dbpath, 'fix.json') FAIL = File.join(dbpath, 'failed.json') DBA = File.join(dbpath, 'a') DBM = File.join(dbpath, 'm') HTML_I = File.join(dbpath, 'index.html') HTML_M = File.join(dbpath, 'movies.html') HTML_A = File.join(dbpath, 'actors.html') HTML_F = File.join(dbpath, 'failed.html') HTML_N = File.join(dbpath, 'new.html') Dir.mkdir(dbpath) unless Dir.exist?(dbpath) Dir.mkdir(DBA) unless Dir.exist?(DBA) Dir.mkdir(DBM) unless Dir.exist?(DBM) def write_db(next_db) puts "write #{DB}" File.open(DB, 'w') { |f| f << next_db.to_json } end def num ('1'..'9').inject('') { |r, i| "#{r}
" } end def alpha ('A'..'Z').inject('') { |r, i| "#{r}" } end def menu(*links) t = ' ' end def prelude(title) f = "#{m['title']}#{' - TV' if m['is_tv']} | \n" f << "#{m['release_date'][0..3]} |