csmit195

Auto Tv Show Namer V2.0 (incomplete)

Mar 1st, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.70 KB | None | 0 0
  1. -- Dependences
  2. local theAPIKey = "22d0ec249a4fc94d281f0155f8fd77bc"
  3.  
  4. function startScript()
  5.     print('---------------------------------------------')
  6.     print('Welcome to Auto TV Show Namer - V2 (csmit195)! We will now run you through a wizard to determine which files need to be named! The script is now loading! Please standby for further instructions. ')
  7.     print('---------------------------------------------')
  8.     require "luacurl"
  9.     require "json"
  10.     c = curl.new()
  11.    
  12.     print('What is the name of your show?')
  13.     local showName = curl.escape(io.read())
  14.     local sResults = search(2, showName)
  15.    
  16.     print('---------------------------------------------')
  17.     print('---------------------------------------------')
  18.     print('There is '..tostring(#sResults)..' results! Please type in the appropriate answer.')
  19.     for i, v in ipairs(sResults) do
  20.         print(tostring(i)..'] '..(v[1] or 'Unknown')..' ('..(type(v[2]) == 'string' and v[2] or 'Unknown')..')')
  21.     end
  22.    
  23.     print('Please type in the number which relates to your show:')
  24.     local indexNo = tonumber(io.read())
  25.     if sResults[indexNo] then
  26.         print('You have chosen: '..sResults[indexNo][1]..' ('..sResults[indexNo][2]..')')
  27.        
  28.     else
  29.         print('Incorrect option! Start again.')
  30.         startScript()
  31.     end
  32. end
  33.  
  34. function search(sType, sQuery) -- sType ( 1 ) == movie, sType ( 2 ) == tv show
  35.     local returnResults = { }
  36.     if sType == 1 then
  37.         local sResults = GET("http://api.themoviedb.org/3/search/movie?api_key=" .. theAPIKey .. "&query=" .. sQuery)
  38.        
  39.         local theResults = 0
  40.         for index, value in pairs(json.decode(sResults)['results']) do
  41.             print(value['title'])
  42.             table.insert(returnResults, {value['title'], value['release_date'], value['id']})
  43.         end
  44.        
  45.     elseif sType == 2 then
  46.         local sResults = GET("http://api.themoviedb.org/3/search/tv?api_key=" .. theAPIKey .. "&query=" .. sQuery)
  47.        
  48.         for index, value in pairs(json.decode(sResults)['results']) do
  49.             table.insert(returnResults, {value['name'], value['first_air_date'], value['id']})
  50.         end
  51.     end
  52.     return returnResults
  53. end
  54.  
  55.  
  56. function getEpisodesFromSeason(theShowID, theSeason)
  57.     local sResults = GET("http://api.themoviedb.org/3/search/tv?api_key=" .. theAPIKey .. "&query=" .. sQuery)
  58. end
  59.  
  60. function GET(url)
  61.     c:setopt(curl.OPT_URL, url)
  62.     local t = {} -- this will collect resulting chunks
  63.     c:setopt(curl.OPT_WRITEFUNCTION, function (param, buf)
  64.         table.insert(t, buf) -- store a chunk of data received
  65.         return #buf
  66.     end)
  67.     c:setopt(curl.OPT_PROGRESSFUNCTION, function(param, dltotal, dlnow)
  68.        
  69.     end)
  70.     c:setopt(curl.OPT_NOPROGRESS, false) -- use this to activate progress
  71.     assert(c:perform())
  72.     return table.concat(t) -- return the whole data as a string
  73. end
  74.  
  75. startScript()
Advertisement
Add Comment
Please, Sign In to add comment