- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我最近花了一点时间尝试创建一个应用程序,它可以浏览大量电影收藏并下载与其相关的所有详细信息(标题、年份、评级、分类、运行时、情节摘要、类型)。
在上面花了一点时间,以及关于 SO 的无数问题之后,我得到了我想要的东西。为了向其他想要开发类似东西的人提供完整而详细的解释,您可以在下面找到我的代码。
在信用到期时给予信用,
祝你好运!
最佳答案
此项目需要以下具有相应值的控件:
代码如下:
Imports System.Net
Imports System.IO
Public Class Form1
Private moviedetails As String = Nothing
Private searchdir As String = Nothing
Private savedir As String = Nothing
Private errorlist As String = Nothing
Private successful As Integer = 0
Private total As Integer = 0
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles SelectSource.Click
Dim fb As New FolderBrowserDialog
fb.Description = "Select the Folder"
fb.RootFolder = Environment.SpecialFolder.MyComputer
Dim dlgResult As DialogResult = fb.ShowDialog()
If dlgResult = Windows.Forms.DialogResult.OK Then
searchdir = fb.SelectedPath
Dim di As New DirectoryInfo(searchdir)
Dim fiArr As FileInfo() = di.GetFiles()
NumberOfMovies.Text = "Number of movies in directory: " & fiArr.Count
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles StartScraping.Click
total = 0
successful = 0
moviedetails = Nothing
WriteConsolus("Initiating connection to database.")
If searchdir IsNot Nothing And savedir IsNot Nothing Then
Dim di As New DirectoryInfo(searchdir)
Dim fiArr As FileInfo() = di.GetFiles()
Dim fri As FileInfo
Dim classif As String = Nothing
Dim time As String = Nothing
Dim genre As String = Nothing
Dim plot As String = Nothing
Dim rating As String = Nothing
Dim mtitle() As String = New String() {"Nothing", "Nothing"}
Dim myear() As String = New String() {"Nothing", "Nothing"}
Dim dstring As String = "Nothing" & Chr(34) & "Nothing"
Dim dar As String() = dstring.Split(Chr(34))
Dim file As System.IO.File
Dim write As System.IO.StreamWriter
write = file.CreateText(savedir)
write.WriteLine("{\rtf1")
WriteConsolus("Starting read from " & searchdir)
ScrapeProgress.Maximum = fiArr.Count
ScrapeProgress.Value = 0
For Each fri In fiArr
Try
Dim fn As String = fri.Name
Dim fd As String = fri.Directory.Name
Dim webclient As New WebClient
WriteConsolus("")
WriteConsolus("--------------------------------------------------------------------------------")
WriteConsolus("~> " & fn & " <~")
fn = fn.Replace(fri.Extension.ToString, "")
fn = RemoveUnneededData(fn)
If fn.Contains("(") And fn.Contains(")") Then
mtitle = fn.Split("(")
myear = fn.Split("(")
myear = myear(1).Split(")")
mtitle(0).Replace(myear(0), "")
WriteConsolus(" + Accessing " & "http://www.omdbapi.com/?t=" & mtitle(0) & "&y=" & myear(0))
dstring = webclient.DownloadString("http://www.omdbapi.com/?t=" & mtitle(0) & "&y=" & myear(0))
dar = dstring.Split(Chr(34))
classif = dar(11)
time = dar(19)
genre = dar(23)
plot = dar(39)
rating = dar(47)
successful = successful + 1
Else
If fn.Contains("[") And fn.Contains("]") Then
mtitle = fn.Split("[")
myear = fn.Split("[")
myear = myear(1).Split("]")
mtitle(0).Replace(myear(0), "")
WriteConsolus(" + Accessing " & "http://www.omdbapi.com/?t=" & mtitle(0) & "&y=" & myear(0))
dstring = webclient.DownloadString("http://www.omdbapi.com/?t=" & mtitle(0) & "&y=" & myear(0))
dar = dstring.Split(Chr(34))
classif = dar(11)
time = dar(19)
genre = dar(23)
plot = dar(39)
rating = dar(47)
successful = successful + 1
Else
If System.Text.RegularExpressions.Regex.IsMatch(fn, "([0-9][0-9][0-9][0-9])") Then
Dim mtemp As String() = fn.Split(" ")
myear(0) = mtemp.Last
mtitle(0) = Nothing
For Each z As String In mtemp
If z IsNot mtemp.Last Then
mtitle(0) = mtitle(0) & z & " "
Else
Exit For
End If
Next
WriteConsolus(" + Accessing " & "http://www.omdbapi.com/?t=" & mtitle(0) & "&y=" & myear(0))
dstring = webclient.DownloadString("http://www.omdbapi.com/?t=" & mtitle(0) & "&y=" & myear(0))
dar = dstring.Split(Chr(34))
classif = dar(11)
time = dar(19)
genre = dar(23)
plot = dar(39)
rating = dar(47)
successful = successful + 1
Else
If IsNumeric(fd) OrElse fd.Length = 9 Then
mtitle = fn.Split(".")
Dim tdf As Integer
Dim tdf2 As Integer
If fd.Length <> 4 Then
tdf = CInt(fd.Substring(0, 4))
tdf2 = CInt(fd.Substring(5, 4))
WriteConsolus("Testing multiple year ranges...")
For c As Integer = tdf To tdf2
WriteConsolus(" + Testing " & c.ToString)
myear(0) = c
mtitle(0).Replace(myear(0), "")
WriteConsolus(" - Accessing " & "http://www.omdbapi.com/?t=" & mtitle(0) & "&y=" & myear(0))
dstring = webclient.DownloadString("http://www.omdbapi.com/?t=" & mtitle(0) & "&y=" & myear(0))
dar = dstring.Split(Chr(34))
classif = dar(11)
time = dar(19)
genre = dar(23)
plot = dar(39)
rating = dar(47)
Next
Else
myear(0) = fd
mtitle(0).Replace(myear(0), "")
WriteConsolus(" + Accessing " & "http://www.omdbapi.com/?t=" & mtitle(0) & "&y=" & myear(0))
dstring = webclient.DownloadString("http://www.omdbapi.com/?t=" & mtitle(0) & "&y=" & myear(0))
dar = dstring.Split(Chr(34))
classif = dar(11)
time = dar(19)
genre = dar(23)
plot = dar(39)
rating = dar(47)
End If
successful = successful + 1
Else
mtitle = fn.Split(".")
WriteConsolus(" + Accessing " & "http://www.omdbapi.com/?t=" & mtitle(0))
dstring = webclient.DownloadString("http://www.omdbapi.com/?t=" & mtitle(0))
dar = dstring.Split(Chr(34))
classif = dar(11)
time = dar(19)
genre = dar(23)
plot = dar(39)
rating = dar(47)
myear(0) = dar(15)
successful = successful + 1
End If
End If
End If
End If
write.WriteLine("Title: " & dar(3) & " Year: " & myear(0) & " Classification: " & classif)
write.WriteLine("\par")
write.WriteLine("Time: " & time & " Genre: " & genre & " IMDb Rating: " & rating & vbCrLf)
write.WriteLine("\par")
write.WriteLine("Plot Summary: " & plot & vbCrLf & vbCrLf)
write.WriteLine("\par")
write.WriteLine("\par")
WriteConsolus(" + Retrieved Data!")
Catch ex As Exception
Try
WriteConsolus(" + Movie not found in year. Attempting to search for just movie title.")
Dim fn As String = fri.Name
Dim fd As String = fri.Directory.Name
Dim webclient As New WebClient
myear(0) = Nothing
fn = fn.Replace(fri.Extension.ToString, "")
fn = RemoveUnneededData(fn)
If fn.Contains("(") And fn.Contains(")") Then
mtitle = fn.Split("(")
Else
If fn.Contains("[") And fn.Contains("]") Then
mtitle = fn.Split("[")
Else
If System.Text.RegularExpressions.Regex.IsMatch(fn, "([0-9][0-9][0-9][0-9])") Then
Dim mtemp As String() = fn.Split(" ")
myear(0) = mtemp.Last
mtitle(0) = Nothing
For Each z As String In mtemp
If z IsNot mtemp.Last Then
mtitle(0) = mtitle(0) & z & " "
Else
Exit For
End If
Next
Else
If IsNumeric(fd) Then
mtitle = fn.Split(".")
End If
End If
End If
End If
WriteConsolus(" + Accessing " & "http://www.omdbapi.com/?t=" & mtitle(0))
dstring = webclient.DownloadString("http://www.omdbapi.com/?t=" & mtitle(0))
dar = dstring.Split(Chr(34))
classif = dar(11)
time = dar(19)
genre = dar(23)
plot = dar(39)
rating = dar(47)
myear(0) = dar(15)
WriteConsolus(" + Title search successful!")
successful = successful + 1
write.WriteLine("Title: " & dar(3) & " Year: " & myear(0) & " Classification: " & classif)
write.WriteLine("\par")
write.WriteLine("Time: " & time & " Genre: " & genre & " IMDb Rating: " & rating & vbCrLf)
write.WriteLine("\par")
write.WriteLine("Plot Summary: " & plot & vbCrLf & vbCrLf)
write.WriteLine("\par")
write.WriteLine("SCRAPED USING AN AMBIGUOUS METHOD! MAY REQUIRE DOUBLE CHECKING!")
write.WriteLine("\par")
write.WriteLine("\par")
WriteConsolus(" + Retrieved Data!")
Catch ex2 As Exception
If dar(3) = False And dar(7) = "Movie not found!" Then
WriteConsolus(" + Movie was not found, please do a manual lookup by:")
WriteConsolus(" - Doing a manual search on IMDb.com")
WriteConsolus(" - Or searching on Google.com")
moviedetails = moviedetails & "Failed to read: " & fri.Name & " Location: " & fri.FullName & " Reason: Movie not found! Please do a manual lookup!" & "\par" & ex.Message & "\par" & " " & "\par" & " "
Else
WriteConsolus(ex.Message)
moviedetails = moviedetails & "Failed to read: " & fri.Name & " Location: " & fri.FullName & " Reason: " & ex.Message & "\par" & "Variables at time of failure: " & mtitle(0) & "[Title]" & myear(0) & "[Year]" & "\par" & " " & "\par" & " "
End If
'WriteConsolus("Movie was not found, please do a manual lookup! (Movie might have different name.)")
'moviedetails = moviedetails & "Failed to read: " & fri.Name & " Location: " & fri.FullName & " Reason: Movie not found! Please do a manual lookup!" & "\par" & ex.Message & "\par" & " " & "\par" & " "
End Try
End Try
WriteConsolus("--------------------------------------------------------------------------------")
total = total + 1
ScrapeProgress.Value += 1
PercentComplete.Text = Int(ScrapeProgress.Value / ScrapeProgress.Maximum * 100) & "%"
NumberOfSuccessful.Text = "Number of successful scrapes: " & successful.ToString & " of " & total.ToString
Next fri
write.WriteLine("}")
write.Close()
WriteConsolus("")
WriteConsolus("Finished! RTF File created at " & savedir)
If moviedetails IsNot Nothing Then
write = file.CreateText(errorlist)
write.WriteLine("{\rtf1")
moviedetails.Replace("\", "/")
write.Write(moviedetails)
write.Write("Please change the filename manually and rerun!")
write.WriteLine("}")
write.Close()
WriteConsolus("There were errors reading some files. Please check " & errorlist & " for details.")
Else
WriteConsolus("No errors reading filenames.")
End If
WriteConsolus("")
WriteConsolus(">>>>> DISCLAIMER <<<<<")
WriteConsolus("")
WriteConsolus("Please note that the results for these movies are NOT from IMDb!")
WriteConsolus("They are provided by OMDBAPI.com.")
WriteConsolus("Any likeness of results to persons deceased or living is coincidental!")
WriteConsolus("")
WriteConsolus("Distributed as open source by Asryael - http://stackoverflow.com/users/1808539/asryael.")
Else
WriteConsolus("No destination and source folders selected!!!")
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles SelectDestination.Click
Dim fb As New SaveFileDialog
fb.Filter = "RTF Files(*.rtf)|*.rtf|All files (*.*)|*.*"
fb.FilterIndex = 1
Dim dlgResult As DialogResult = fb.ShowDialog()
If dlgResult = Windows.Forms.DialogResult.OK Then
savedir = fb.FileName
errorlist = fb.FileName.Remove(fb.FileName.LastIndexOf(".")) & " - Failed Reads.rtf"
End If
End Sub
Private Sub WriteConsolus(text As String)
Consolus.AppendText(text & vbCrLf)
Consolus.SelectionStart = Consolus.Text.Length
Consolus.ScrollToCaret()
End Sub
Public Function RemoveUnneededData(text As String) As String
text = text.Replace(".", " ")
text = text.Replace("720p", "")
text = text.Replace("1080p", "")
text = text.Replace(" CD1", "")
text = text.Replace(" CD2", "")
text = text.Replace("-CD1", "")
text = text.Replace("-CD2", "")
text = text.Replace("CD1", "")
text = text.Replace("CD2", "")
text = text.Replace("-cd1", "")
text = text.Replace("-cd2", "")
text = text.Replace(" cd1", "")
text = text.Replace(" cd2", "")
text = text.Replace("cd1", "")
text = text.Replace("cd2", "")
text = text.Replace(" dvd1", "")
text = text.Replace(" dvd2", "")
text = text.Replace("-dvd1", "")
text = text.Replace("-dvd2", "")
text = text.Replace("dvd1", "")
text = text.Replace("dvd2", "")
Return text
End Function
End Class
就是这样。这就是它工作所需的全部。只需选择包含所有电影的源文件夹,然后选择目标文件并点击开始!请注意,它是同步
完成的,这意味着 UI 可能会有一些延迟。
欢迎对代码进行任何更新或更改!我一直想提高我的知识!
关于database - 从在线数据库中获取电影详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14066873/
我们使用 Azure 弹性池,生成多个客户端数据库和一个引用客户端数据库的主数据库。 我们已经拥有多个数据库,并且正在开发新版本的代码。我们使用 EF6 代码优先。当我们对模型进行更改(添加属性)时,
我们使用 Azure 弹性池,生成多个客户端数据库和一个引用客户端数据库的主数据库。 我们已经拥有多个数据库,并且正在开发新版本的代码。我们使用 EF6 代码优先。当我们对模型进行更改(添加属性)时,
我希望将一些信息分发到不同的机器上,以便在没有任何网络开销的情况下实现高效和极快的访问。数据存在于关系模式中,实体之间的关系是“加入”的要求,但根本不是写入数据库的要求(它会离线生成)。 我非常相信
我使用 GrapheneDB 来托管我的 neo4j 数据库 (db)。 问题 我有 N客户并且正在寻找自动分离他们的内容(他们独特的数据库)的方法,以便: 它不重叠数据 操作速度不受影响。 选项 1
当服务器开始工作(Tomcat)时,日志显示此错误: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid b
我在 Oracle 数据库实例中按以下方式创建了一个触发器。 CREATE OR REPLACE TRIGGER after_logon_on_database AFTER LOGON ON DATA
原谅我的无知,我是数据库约定的初学者。 这是我的 SQLite 代码:(由我的数据库浏览器自动生成) CREATE TABLE `ResearchItems` ( `ID` INTEGER NO
是的是的是的,我已经在整个互联网上搜索过这个问题。一些结果发现,甚至来自 Stackoverflow。但是他们中的大多数人说“你应该自动加载数据库”,或者“parent::__construct();
我正在创建一个 Mac 应用程序,它将一些数据保存到 SQLite 数据库中。问题是:当我关闭数据库并再次打开时,数据不存在了。这是我的代码: NSString *sql = [NSString st
我正在建立一个网站,我打算发布各种帖子,比如教程、文章等。我打算用 php 来管理它,但是当涉及到存储每个帖子的内容时,将要显示的文本,更好的选择是:使用单独的文本文件还是将其添加为数据库中的每个条目
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 3 年前。 Improve this qu
对不起,这个关键字对我来说没有任何意义...有人可以给我一个定义吗? 提前致谢... 最佳答案 这是一个品牌。 http://pervasive.com/这是他们的数据库产品的链接 http://ww
我已经在 docker 版本 1.10.1 的 docker 镜像中安装了 PostgreSQL 9.4.6。根据这张官方图片: https://github.com/docker-library/p
当我的 android 应用程序尝试读取 android 短信数据库时,我遇到了这个崩溃。读取android短信数据库的代码类似于下面的代码 fragment : String SMS_URI = "
我有一个 public kit repo,我推送了 v1.0.3 并具有以下结构 go -database --database.go --go.mod --go.sum 我需要它 require g
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 9 年前。 Improve this qu
我们正在使用MySQL数据库在Go中创建一个Web应用程序。我们的用户一次只能拥有一个活跃的客户端。就像Spotify一样,您一次只能在一台设备上听音乐。为此,我制作了一个映射,将用户ID和作为其值的
我已经尝试在 PostgreSQL 中创建数据库好几天了,遇到了几个问题,但似乎卡住了。 我在 PostgreSQL 中手动创建了一个名为 postgres_development 的数据库,因为 b
我正在创建一个 iMessage 应用程序,它需要连接到与我的常规应用程序相同的数据库。 我调用 FirebaseApp.configure() 并对用户进行身份验证,但出于某种原因,在所有 Data
就像std::unordered_map但所有数据都应存储在磁盘上而不是内存中。 按照我的理解,应该做两部分:索引和存储。我已经学习了一些关于索引的数据结构,比如 Linear-Hash 或 B-Tr
我是一名优秀的程序员,十分优秀!