我本人经常在PT站下载电影,为了放便做种,不方便修改文件名。于是会通过Total Commander给文件夹添加备注。但是自己一个一个输入也比较麻烦,于是就想到了从TMDB查找电影数据,自动备注。
这里是一个获取信息,并通过Gui列出信息的演示,具体怎么用可以自行探索。
1. TMDB 的 api_key 可自行申请,免费的。 https://www.themoviedb.org。确实觉得麻烦的可以付费查看我的api_key。
2. api.themoviedb.org 的访问可能会有问题,原因是DNS污染。可以自己测试下面的IP改一下hosts,我这里用的 13.224.166.59 延迟只有 40 毫秒。31.13.95.33,173.252.73.48,103.252.115.221,69.171.248.112,54.230.62.8,23.101.24.70,103.252.115.49,74.86.151.167,162.125.32.6,202.182.98.125,108.160.165.141,108.160.165.173,174.37.154.236,192.133.77.189,108.160.167.156,69.171.224.36,157.240.7.34,74.86.3.208,147.75.95.72,67.228.235.93,173.244.209.150,31.13.90.33,202.160.128.195,13.224.166.41,64.13.192.74,69.63.187.12,69.171.245.84,199.96.63.163,67.15.129.210,173.252.103.64,31.13.87.33,157.240.20.18,104.244.46.85,98.159.108.71,31.13.72.23,108.160.166.61,31.13.82.23,118.193.240.37,157.240.10.32,157.240.9.18,128.242.240.20,108.160.167.158,115.126.100.160,31.13.66.1,108.160.166.253,103.228.130.61,69.63.186.30,31.13.75.5,69.171.233.33,205.186.152.122,199.59.148.209,173.252.100.21,31.13.86.16,162.125.7.1,103.252.114.61,157.240.10.36,199.96.62.75,108.160.165.8,111.243.214.169,31.13.72.1,204.79.197.217,209.95.56.60,103.97.176.73,93.179.102.140,199.96.63.75,108.160.167.148,13.224.166.93,69.171.229.28,103.223.122.178,108.160.173.207,128.242.240.149,143.204.82.39,99.84.238.119,54.230.62.41,13.224.166.21,13.225.89.83,99.84.198.98,99.84.198.62,13.225.89.7,99.84.238.96,13.225.198.42,99.84.198.13,13.225.89.60,52.85.231.63,202.160.130.117,52.84.228.129,54.192.30.115,159.65.107.38,13.224.166.59,13.35.162.14,13.227.73.32,13.225.177.71,13.226.226.63
; TEST START ================================
api_key := "XXXXX"
tmdb := new tmdb(api_key)
inputbox, name, TMDB, 请输入要查找的电影名
; name := "Marvel's The Avengers 1-4 2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos"
name := regexreplace(name, ".", " ")
name := regexreplace(name, "'", "'")
name := regexreplace(name, "i)bd+pb", " ")
name := regexreplace(name, "i)Hybrid|REMUX|BluRay|AVC|TrueHD", " ")
while(strlen(name))
{
res := tmdb.search(name)
if(res.length())
break
name := regexreplace(name, " *S+$")
}
if(res.length() == 0)
{
msgbox 没有找到
exitapp
}
else
Show(res)
return
; TEST END ==================================
class tmdb{
__New(api_key)
{
this.scriptcontrol:=comobjcreate("scriptcontrol")
this.whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
this.scriptcontrol.language:="jscript"
this.api_key := api_key
this.url_genre_list := JS.urlencode(format("https://api.themoviedb.org/3/genre/movie/list?api_key={1:s}&language=zh", api_key))
this.genre_list := {28:"动作" ,12:"冒险" ,16:"动画" ,35:"喜剧" ,80:"犯罪" ,99:"纪录" ,18:"剧情" ,10751:"家庭" ,14:"奇幻" ,36:"历史" ,27:"恐怖" ,10402:"音乐" ,9648:"悬疑" ,10749:"爱情" ,878:"科幻" ,10770:"电视电影" ,53:"惊悚" ,10752:"战争" ,37:"西部"}
}
search(name)
{
whr := this.whr
genre_list := this.genre_list
url := this.urlencode(format("https://api.themoviedb.org/3/search/movie?api_key={1:s}&query={2:s}&language=zh", this.api_key, name))
whr.open("GET", url, true)
whr.send()
whr.WaitForResponse()
if (whr.status == 200)
{
responseJSON := this.json(whr.responseText)
return responseJSON.results
}
}
movie(movie_id){
whr := this.whr
url := format("https://api.themoviedb.org/3/movie/{2:s}?api_key={1:s}&language=zh", this.api_key, movie_id)
whr.open("GET", url, true)
whr.send()
whr.WaitForResponse()
if (whr.status == 200)
{
responseJSON := this.json(whr.responseText)
return responseJSON.results
}
}
json(s){
return this.scriptcontrol.eval("(" s ")")
}
urlencode(s){
return this.scriptcontrol.eval("encodeURI('" s "')")
}
close(){
exitapp
}
}
Show(arg){
baseurl := "https://www.themoviedb.org/t/p/w92"
file := a_temp . "tmdb.temp.html"
static WB
Gui Add, ActiveX, w980 h640 vWB, Shell.Explorer
html =
(
<!DOCTYPE html>
<html>
<head>
<style>
table {border-collapse:collapse;}
table,td,th { border:1px solid black;}
img {display:block}
</style>
</head>
<body>
<table border="1">
<tr><th>图片</ht><th>简介</ht><th>评分</ht></tr>
)
for k in arg
{
url := baseurl . k.poster_path
html .= "`n<tr>"
html .= format("<td><img src='{1:s}'></img></td>", url)
html .= format("<td>{1:s}({2:s}) tmdbid:{3:d}<br>{4:s}</td><td>{5:.2f}</td>", k.title, k.release_date, k.id, k.overview, k.vote_average)
html .= "</tr>"
}
filedelete, %file%
fileappend, %html%, %file%
WB.Navigate("file:///" . file)
Gui, Show
}
guiclose:
exitapp
?