Ok.
Here is a handy little application - fully working - that obtains information from IMDB.com.
Fundamentally you can go much further, but im releasing the code thus far so users can learn from the code and how its used.
useage: enter a movie URL into the textbox and click search.
Example: http://www.imdb.com/title/tt0892318/
Download Link (exe): http://www.coding.extremecoderz.com/IMDBGrabber.rar
Download Link (solution): http://www.coding.extremecoderz.com/IMDBsol.rar
Anyway. without further ado:
Form1.cs Source:
IMDB.cs Source:
Here is a handy little application - fully working - that obtains information from IMDB.com.
Fundamentally you can go much further, but im releasing the code thus far so users can learn from the code and how its used.
useage: enter a movie URL into the textbox and click search.
Example: http://www.imdb.com/title/tt0892318/
Download Link (exe): http://www.coding.extremecoderz.com/IMDBGrabber.rar
Download Link (solution): http://www.coding.extremecoderz.com/IMDBsol.rar
Anyway. without further ado:
Form1.cs Source:
PHP:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using IMDBGrabber;
namespace IMDBGrabber
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private delegate void DisplayStatus(string info, int progress, int maxProgress);
private void Status(string info, int progress, int maxProgress)
{
toolStripProgressBar1.Maximum = maxProgress;
toolStripProgressBar1.Value = progress;
toolStripStatusLabel1.Text = info;
}
private delegate void DisplayOutput(
string title,
string desc,
string rating,
string votes,
string releaseDate,
string tagLine
);
private void Output(
string title,
string desc,
string rating,
string votes,
string releaseDate,
string tagLine
)
{
title_tb.Text = title;
desc_tb.Text = desc;
rating_tb.Text = rating + " (" + votes + ")";
releaseDate_tb.Text = releaseDate;
tagLine_tb.Text = tagLine;
}
private delegate void displayCoverDelegate(string imageURL);
private void DisplayCoverImage(string imageURL)
{
pictureBox1.Image = IMDB.getCover(imageURL);
}
private void button1_Click(object sender, EventArgs e)
{
Thread myThread = new Thread(DoWork);
myThread.Start();
}
private void DoWork()
{
DisplayStatus DisplayStatus = new DisplayStatus(Status);
DisplayOutput DisplayOutput = new DisplayOutput(Output);
displayCoverDelegate displayCoverDelegate = new displayCoverDelegate(DisplayCoverImage);
Invoke(DisplayStatus, "Connecting...", 1, 3);
object[] returnValues = IMDB.getInfo(textBox1.Text);
Invoke(DisplayOutput,
returnValues[0].ToString(),
returnValues[1].ToString(),
returnValues[2].ToString(),
returnValues[3].ToString(),
returnValues[4].ToString(),
returnValues[5].ToString()
);
Invoke(DisplayStatus, "Getting Cover Image...", 2, 3);
Invoke(displayCoverDelegate, returnValues[6].ToString());
Invoke(DisplayStatus, "Ready.", 3, 3);
}
}
}
PHP:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Web;
using System.Drawing;
namespace IMDBGrabber
{
class IMDB
{
public static string[] GetStringInBetween(string strBegin, string strEnd, string strSource, bool includeBegin, bool includeEnd)
{
string[] result = { "", "" };
int iIndexOfBegin = strSource.IndexOf(strBegin);
if (iIndexOfBegin != -1)
{
if (includeBegin)
{ iIndexOfBegin -= strBegin.Length; }
strSource = strSource.Substring(iIndexOfBegin
+ strBegin.Length);
int iEnd = strSource.IndexOf(strEnd);
if (iEnd != -1)
{
if (includeEnd)
{ iEnd += strEnd.Length; }
result[0] = strSource.Substring(0, iEnd);
if (iEnd + strEnd.Length < strSource.Length)
{ result[1] = strSource.Substring(iEnd + strEnd.Length); }
}
}
else
{ result[1] = strSource; }
return result;
}
public static object[] getInfo(string url)
{
HttpWebRequest WebReq;
HttpWebResponse WebResp;
Stream Answer;
StreamReader _Answer;
string[] result;
string ResponseOutput;
WebReq = (HttpWebRequest)WebRequest.Create(url);
WebReq.KeepAlive = false;
WebReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4";
WebReq.Method = "GET";
WebReq.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
WebReq.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
using (WebResp = (HttpWebResponse)WebReq.GetResponse())
{
Answer = WebResp.GetResponseStream();
_Answer = new StreamReader(Answer);
ResponseOutput = _Answer.ReadToEnd();
}
string
title,
description,
rating,
votes,
releaseDate,
tagLine,
coverURL;
// rating (VOtes), Main Team. Plot, Main Release Date, Cast
// Director,Release Date,Genre,Tagline,Plot,Cast,Runtime,Country,Langu age, that will be awesome IMHO
result = GetStringInBetween("name=\"title\" content=\"", "\">", ResponseOutput, false, false);
title = HttpUtility.HtmlDecode(result[0]);
result = GetStringInBetween("name=\"description\" content=\"", "\">", ResponseOutput, false, false);
description = HttpUtility.HtmlDecode(result[0]);
result = GetStringInBetween(" <b>", "</b> ", ResponseOutput, false, false);
rating = HttpUtility.HtmlDecode(result[0]);
result = GetStringInBetween("class=\"tn15more\">", "</a>", ResponseOutput, false, false);
votes = HttpUtility.HtmlDecode(result[0]);
result = GetStringInBetween("<h5>Release Date:</h5>\n<div class=\"info-content\">\n", "<", ResponseOutput, false, false);
releaseDate = HttpUtility.HtmlDecode(result[0]);
result = GetStringInBetween("<h5>Tagline:</h5>\n<div class=\"info-content\">\n", "<", ResponseOutput, false, false);
tagLine = HttpUtility.HtmlDecode(result[0]);
result = GetStringInBetween("<link rel=\"image_src\" href=\"", "<", ResponseOutput, false, false);
coverURL = HttpUtility.HtmlDecode(result[0]);
return new object[]
{
title,
description,
rating,
votes,
releaseDate,
tagLine,
coverURL
};
}
public static Image getCover(string url)
{
HttpWebRequest WebReq;
HttpWebResponse WebResp;
Image tempImage = null;
WebReq = (HttpWebRequest)WebRequest.Create(url);
WebReq.KeepAlive = false;
WebReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4";
WebReq.Method = "GET";
WebReq.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
WebReq.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
using (WebResp = (HttpWebResponse)WebReq.GetResponse())
{
System.IO.Stream _WebStream = WebResp.GetResponseStream();
tempImage = Image.FromStream(_WebStream);
}
return tempImage;
}
}
}