Soyez le premier à donner votre avis sur cette source.
Vue 17 587 fois - Téléchargée 1 272 fois
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using System.Web; using System.Net; using System.Xml; namespace movieJacket { public partial class Form1 : Form { public Form1() { InitializeComponent(); } passvariable pvar; private void button1_Click(object sender, EventArgs e) { pvar = new passvariable(); listBox1.Items.Clear(); listBox2.Items.Clear(); listBox3.Items.Clear(); if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { textBox1.Text = folderBrowserDialog1.SelectedPath; } else { return; } DirSearch(textBox1.Text,"*.avi"); DirSearch(textBox1.Text, "*.mkv"); makeMovieName(); System.Threading.Thread.Sleep(1000); if(MessageBox.Show("Start get All posters?","Get All Posters",MessageBoxButtons.OKCancel,MessageBoxIcon.Question)== System.Windows.Forms.DialogResult.OK) { searchMovie(); } } private void DirSearch(string sDir,string pattern) { try { foreach (string f in Directory.GetFiles(sDir, pattern)) { bool skipFile = false; foreach (string item in listBox6.Items) { if (f.ToUpper().IndexOf(item.ToUpper()) != -1) { skipFile = true; } } if (!skipFile) { listBox2.Items.Add(f.Substring(0, f.LastIndexOf(".")) + ".jpg"); listBox1.Items.Add(f.Substring(f.LastIndexOf("\\") + 1)); } } foreach (string d in Directory.GetDirectories(sDir)) { DirSearch(d, pattern); } } catch (System.Exception excpt) { MessageBox.Show(excpt.Message); } } private void makeMovieName() { string newName = null; int myIndex = 0; foreach (string file in listBox1.Items) { newName = file.ToUpper(); newName = newName.Replace(".AVI", ""); newName = newName.Replace(".MKV", ""); foreach (string item in listBox4.Items) { if (newName.IndexOf(item) != -1) { int discriminator = newName.IndexOf(item); newName = newName.Substring(0, discriminator); } } foreach (string item in listBox5.Items) { newName = newName.Replace(item, ""); } newName = newName.Replace(".", " "); newName = newName.Replace("-", " "); newName = newName.Replace("_", " "); listBox3.Items.Add(newName); if (File.Exists(listBox2.Items[myIndex].ToString())) { checkedListBox1.Items.Add(newName, true); } else { checkedListBox1.Items.Add(newName, false); } myIndex++; } } private void searchMovie() { int myIndex = 0; XmlDocument myXmlMovieInfo; XmlElement myXmlElement; XmlNodeList myXmlNodes; progressBar1.Maximum = checkedListBox1.Items.Count - checkedListBox1.CheckedItems.Count; int myCheckedItem = 1; foreach (string movie in listBox3.Items) { if(!checkedListBox1.GetItemChecked(myIndex)) { myXmlMovieInfo = new XmlDocument(); myXmlMovieInfo.LoadXml(getAllocineInfo(movie)); pvar.xmlDoc = myXmlMovieInfo; myXmlElement = myXmlMovieInfo.DocumentElement; myXmlNodes = myXmlElement.GetElementsByTagName("movie"); pvar.movieName = movie; string movieNum= null; if (myXmlNodes.Count >= 2) { Form askMovieForm = new askMovie(pvar); if (askMovieForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { movieNum = askMovieForm.Text; foreach (XmlNode node in myXmlNodes) { string myImageUrl = null; if (node.Attributes["code"].InnerText == movieNum) { try { myImageUrl = node["poster"].Attributes["href"].InnerText; } catch { myImageUrl = node["picture"].Attributes["href"].InnerText; } WebClient urlGrabber = new WebClient(); byte[] data = urlGrabber.DownloadData(myImageUrl); FileStream fileStream = new FileStream(listBox2.Items[myIndex].ToString(), FileMode.Create); fileStream.Write(data, 0, data.Length); fileStream.Close(); checkedListBox1.SetItemChecked(myIndex,true); } } } } else { foreach (XmlNode node in myXmlNodes) { string myImageUrl = null; try { myImageUrl = node["poster"].Attributes["href"].InnerText; WebClient urlGrabber = new WebClient(); byte[] data = urlGrabber.DownloadData(myImageUrl); FileStream fileStream = new FileStream(listBox2.Items[myIndex].ToString(), FileMode.Create); fileStream.Write(data, 0, data.Length); fileStream.Close(); checkedListBox1.SetItemChecked(myIndex, true); } catch { } } } progressBar1.Value = myCheckedItem; myCheckedItem++; } myIndex++; } MessageBox.Show("Telechargement des Jaquettes Completé"); } private string getAllocineInfo(string movie) { string alloCineUrl = "http://api.allocine.fr/xml/search?partner=4&q="+movie; // used to build entire input StringBuilder sb = new StringBuilder(); // used on each read operation byte[] buf = new byte[8192]; // prepare the web page we will be asking for HttpWebRequest request = (HttpWebRequest) WebRequest.Create(alloCineUrl); // execute the request HttpWebResponse response = (HttpWebResponse) request.GetResponse(); // we will read data via the response stream Stream resStream = response.GetResponseStream(); string tempString = null; int count = 0; do { // fill the buffer with data count = resStream.Read(buf, 0, buf.Length); // make sure we read some data if (count != 0) { // translate from bytes to ASCII text tempString = Encoding.ASCII.GetString(buf, 0, count); // continue building the string sb.Append(tempString); } } while (count > 0); // any more data to read? // print out page source return sb.ToString(); } private void Form1_Load(object sender, EventArgs e) { List<string> lines = new List<string>(); // 2 // Use using StreamReader for disposing. using (StreamReader r = new StreamReader(Application.StartupPath+"\\list1.txt")) { // 3 // Use while != null pattern for loop string line; while ((line = r.ReadLine()) != null) { listBox4.Items.Add(line); } } using (StreamReader r = new StreamReader(Application.StartupPath + "\\list2.txt")) { // 3 // Use while != null pattern for loop string line; while ((line = r.ReadLine()) != null) { listBox5.Items.Add(line); } } using (StreamReader r = new StreamReader(Application.StartupPath + "\\list3.txt")) { // 3 // Use while != null pattern for loop string line; while ((line = r.ReadLine()) != null) { listBox6.Items.Add(line); } } } } }
14 déc. 2012 à 11:01
Quelqu'un aurai le code déjà compilé en exe? je n'ai pas les outils ni la connaissance pour le réaliser.
Merci d'avance
15 août 2013 à 20:05
24 juil. 2012 à 11:37
18 juin 2012 à 21:19
PS: Ayant étudié à fond les codes sources, je vous dis bravo car il s'agit d'un excellent début.
12 mai 2012 à 20:36
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.