Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Dependences
- local theAPIKey = "22d0ec249a4fc94d281f0155f8fd77bc"
- function startScript()
- print('---------------------------------------------')
- 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. ')
- print('---------------------------------------------')
- require "luacurl"
- require "json"
- c = curl.new()
- print('What is the name of your show?')
- local showName = curl.escape(io.read())
- local sResults = search(2, showName)
- print('---------------------------------------------')
- print('---------------------------------------------')
- print('There is '..tostring(#sResults)..' results! Please type in the appropriate answer.')
- for i, v in ipairs(sResults) do
- print(tostring(i)..'] '..(v[1] or 'Unknown')..' ('..(type(v[2]) == 'string' and v[2] or 'Unknown')..')')
- end
- print('Please type in the number which relates to your show:')
- local indexNo = tonumber(io.read())
- if sResults[indexNo] then
- print('You have chosen: '..sResults[indexNo][1]..' ('..sResults[indexNo][2]..')')
- else
- print('Incorrect option! Start again.')
- startScript()
- end
- end
- function search(sType, sQuery) -- sType ( 1 ) == movie, sType ( 2 ) == tv show
- local returnResults = { }
- if sType == 1 then
- local sResults = GET("http://api.themoviedb.org/3/search/movie?api_key=" .. theAPIKey .. "&query=" .. sQuery)
- local theResults = 0
- for index, value in pairs(json.decode(sResults)['results']) do
- print(value['title'])
- table.insert(returnResults, {value['title'], value['release_date'], value['id']})
- end
- elseif sType == 2 then
- local sResults = GET("http://api.themoviedb.org/3/search/tv?api_key=" .. theAPIKey .. "&query=" .. sQuery)
- for index, value in pairs(json.decode(sResults)['results']) do
- table.insert(returnResults, {value['name'], value['first_air_date'], value['id']})
- end
- end
- return returnResults
- end
- function getEpisodesFromSeason(theShowID, theSeason)
- local sResults = GET("http://api.themoviedb.org/3/search/tv?api_key=" .. theAPIKey .. "&query=" .. sQuery)
- end
- function GET(url)
- c:setopt(curl.OPT_URL, url)
- local t = {} -- this will collect resulting chunks
- c:setopt(curl.OPT_WRITEFUNCTION, function (param, buf)
- table.insert(t, buf) -- store a chunk of data received
- return #buf
- end)
- c:setopt(curl.OPT_PROGRESSFUNCTION, function(param, dltotal, dlnow)
- end)
- c:setopt(curl.OPT_NOPROGRESS, false) -- use this to activate progress
- assert(c:perform())
- return table.concat(t) -- return the whole data as a string
- end
- startScript()
Advertisement
Add Comment
Please, Sign In to add comment