internal static void AddFileToSection
            (out IMLItem item, IMLSection section,
            string itemName, string itemLocation,
            string externalID)
        {
            //TODO: Implement option to not update the Media Section on each imported item.

            if (Settings.UpdateMediaSectionOnEachImportedItem)
            {
                section.BeginUpdate();
            }


            item = section.AddNewItem
                       (itemName, itemLocation);

            item.ExternalID = externalID;
            item.SaveTags();



            if (Settings.UpdateMediaSectionOnEachImportedItem)
            {
                section.EndUpdate();
            }
        }
        private static bool TryToPerfrormMediaSectionUpdate(IMLSection section, string pluginPath, 
            string[] videoExtensions,
            string[] videoExtensionsCommon,
            int totalSectionItems)
        {
            try
            {

                int currentSectionItem = 1;
                section.BeginUpdate();
                Helpers.LogMessageToFile
                    ("Section update was started.");

                if (section.GetAllItemIDs().Any
                    (id => !SingleMovieItemUpdater.UpdateSectionItem
                        (id, section, pluginPath, ref currentSectionItem,
                         totalSectionItems, videoExtensions,
                         videoExtensionsCommon)))
                {
                    return false;
                }

                section.EndUpdate();
                Helpers.LogMessageToFile
                    ("Section update is complete.");

            }
            catch (Exception e)
            {
                AcknowledgeMediaSectionUpdaterErrorAndTerminateImportSequence(e);
            }

            return true;
        }
        public static void ReplaceTag(string tagName, string[] searchStrings, IMLSection section)
        {

            foreach (string searchReplaceString in searchStrings)
            {
                MessageBox.Show(searchReplaceString);
                string[] replaces = searchReplaceString.Split('|');
                string searchString = replaces[0];
                string replaceString = replaces[1];
                MessageBox.Show(@"Will replace with: " +  replaceString);

                IMLItemList itemList = section.SearchByTag(tagName, searchString);

                section.BeginUpdate();
                

                foreach (IMLItem t in itemList)
                {
                    MessageBox.Show(tagName);
                    t.Tags[tagName] = replaceString;
                    MessageBox.Show((string)t.Tags[tagName]);
                    t.SaveTags();
                }

                section.EndUpdate();

            }


        }
Пример #4
0
                internal static void BeginUpdatingSections
                    (IMLSection section)
                {

                    section.BeginUpdate();
                                  
                }
        internal static void ImportMeePopupProviderField(IMLSection section)
        {

            if (!Settings.MeePopupProviderCompatibility)
                return;

            #region Process initialization feedback
            MainImportingEngine.ThisProgress.Progress(0, "Adding field meePopupProvider...");
            Thread.Sleep(300);
            #endregion

            section.AddNewTag("meePopupProvider");
      
            var itemsProcessed = 0; 

            section.BeginUpdate();
 
            #region Update Section items 
            foreach (var readOnlyItem in section.GetReadOnlyItems()) 
            { 
                string id = readOnlyItem.ID.ToString(CultureInfo.InvariantCulture);
 
                #region Calculate progress
                int percentComplete = (int)(itemsProcessed * (100.0 / section.ItemCount ) ); 
                if (percentComplete > 100) 
                    percentComplete = 100;

                itemsProcessed++;
 
                #endregion

                #region Poll for user cancellation request
                if (!MainImportingEngine.ThisProgress.Progress(percentComplete, "Processing Items")) 
                { 
                    section.CancelUpdate(); 
                    MainImportingEngine.ThisProgress.Progress(100, "Import Canceled");
                    return;
                }
                #endregion

                #region If field is populated, continue to next item
                if ( (string) readOnlyItem.Tags.Get("meePopupProvider", "") == id)
                    continue;
                #endregion

                #region Populate the item's field
                IMLItem item = section.FindItemByID(readOnlyItem.ID); 
                item.Tags["meePopupProvider"] = id; 
                item.SaveTags();
                #endregion

            } //endof foreach
            #endregion

            section.EndUpdate();
        } //endof function
        private static void DownloadRssFeedsAndPopulateFeedEntries
            (IMLSection newsSection, WebClient webClient)
        {

            newsSection.BeginUpdate();

            foreach (string url in Settings.RsSfeeds)
                DownloadRssFeedAndPopulateFeedEntries(newsSection,
                    url, webClient);

            newsSection.EndUpdate();
        
        }
        internal static void AddFileToSection(out IMLItem item, IMLSection section,
            string itemName, string itemLocation,
            string externalID)
        {
            //TODO: Implement option to not update the Media Section on each imported item.

             if (Settings.UpdateMediaSectionOnEachImportedItem)
                section.BeginUpdate();

            item = section.AddNewItem
                (itemName, itemLocation);

            item.ExternalID = externalID;
            item.SaveTags();

            if (Settings.UpdateMediaSectionOnEachImportedItem)
                section.EndUpdate();
        }
 internal static void BeginUpdatingSections(IMLSection section)
 {
     section.BeginUpdate();
 }
        internal static bool UpdateMoviesSection(string pluginpath,
             IBaseSystem iBaseSystem,
             IEnumerable<string> combinedSceneTags,
             IMLSection section)
        {
            if (section.ItemCount == 0)
                return true;

            Debugger.LogMessageToFile
                (Environment.NewLine
                + Environment.NewLine
                + "Film Updater is enabled.");

            #region Pre-Updating Operations

            Debugger.LogMessageToFile
                ("Initializing section variables...");

            int totalItems
                = section.ItemCount;

            int currentItem = 1;

            MainImportingEngine
                .CurrentProgress = 0;

            MainImportingEngine
                .GeneralStatus
                = "Updating Movies Section";

            MainImportingEngine
                .SpecialStatus = "";

            #endregion

            #region Main Updating Loop

            Debugger.LogMessageToFile
                ("Beginning to update" +
                 " Films section...");

            section.BeginUpdate();

            foreach (int id in section.GetAllItemIDs())
            {

                if (!SingleMovieItemUpdater
                    .UpdateFilmItem
                    (id, section,
                     pluginpath,
                     ref currentItem,
                     totalItems,
                    iBaseSystem,
                    combinedSceneTags))
                    return false;

            }

            section.EndUpdate();

            Debugger.LogMessageToFile
                ("Completing updating" +
                 " of Films section...");

            #endregion

            return true;
        }
Пример #10
0
        internal static bool UpdateMoviesSection
            (string pluginpath,
            IBaseSystem iBaseSystem,
            IEnumerable <string> combinedSceneTags,
            IMLSection section)
        {
            if (section.ItemCount == 0)
            {
                return(true);
            }



            Debugger.LogMessageToFile
                (Environment.NewLine
                + Environment.NewLine
                + "Film Updater is enabled.");



            #region Pre-Updating Operations


            Debugger.LogMessageToFile
                ("Initializing section variables...");


            int totalItems
                = section.ItemCount;


            int currentItem = 1;


            MainImportingEngine
            .CurrentProgress = 0;


            MainImportingEngine
            .GeneralStatus
                = "Updating Movies Section";


            MainImportingEngine
            .SpecialStatus = "";


            #endregion



            #region Main Updating Loop


            Debugger.LogMessageToFile
                ("Beginning to update" +
                " Films section...");



            section.BeginUpdate();



            foreach (int id in section.GetAllItemIDs())
            {
                if (!SingleMovieItemUpdater
                    .UpdateFilmItem
                        (id, section,
                        pluginpath,
                        ref currentItem,
                        totalItems,
                        iBaseSystem,
                        combinedSceneTags))
                {
                    return(false);
                }
            }



            section.EndUpdate();


            Debugger.LogMessageToFile
                ("Completing updating" +
                " of Films section...");


            #endregion



            return(true);
        }
        private static void CleanEmptyFields(bool cleanEmptyFields, IMLSection section)
        {

            if (!cleanEmptyFields) 
                return;

            //Importer.CurrentProgress++;
            MainImportingEngine.ThisProgress.Progress
                (MainImportingEngine.CurrentProgress, 
                "Cleaning empty library fields...");
            //Thread.Sleep(800);

            string[] tagNames = section.GetTagNames();


            section.BeginUpdate();

            foreach (string tagName in tagNames)
            {
                bool allTagValuesAreEmpty = true;

                //Importer.thisProgress.Progress(100, TagName);
                //Thread.Sleep(1000);

                if (tagName == "ToDelete")
                {

                }

                if (section.GetTagValues(tagName) == null) continue;

                string[] TagValues = section.GetTagValues(tagName);

                foreach (string tagvalue in TagValues.Where(tagvalue => !String.IsNullOrEmpty(tagvalue)))
                    allTagValuesAreEmpty = false;


                if (allTagValuesAreEmpty)
                    section.DeleteTag(tagName);

            }
            section.EndUpdate();


            section.BeginUpdate();

            //Importer.CurrentProgress++;
            MainImportingEngine.ThisProgress.Progress
                (MainImportingEngine.CurrentProgress, 
                "Removing items marked for deletion...");
            
            Thread.Sleep(800);

            IMLItemList itemsToDelete = section.SearchByTag("ToDelete", "true");
            
            foreach (IMLItem t in itemsToDelete)
                section.DeleteItem(t);

            section.EndUpdate();

        }
        private static void DownloadNewReleasesFromSource
            (string RssSource, IMLSection MediaSection,
            IMLSection ReleasesSection,
            ConnectionResult connResult, 
            IEnumerable<string> combinedSceneTags)
        {




            WebClient client = new WebClient();
            XmlDocument xDoc = new XmlDocument();
            //Importer.thisProgress.Progress(Importer.CurrentProgress, "Scanning for new releases...");
            Helpers.UpdateProgress("Updating Downloads library" + MediaSection.Name + "Section", "Scanning for new releases..." , null);
            //WebResponse response = Helpers.TryDatabaseRequest(RssSource,MediaSection.Name, "Mininova",null );

            string xmlData = Downloaders.GetUrl(RssSource, null, true);
            if (String.IsNullOrEmpty(xmlData))
                return;

            StringReader reader = new StringReader(xmlData);

            //if (response == null)
            //{
            //MessageBox.Show("Unable to communicate with online source");
            //  return false;
            //}

            //Stream stream = response.GetResponseStream();

            #region try to load online xml stream
            try
            {
                xDoc.Load(reader);
            }
            catch (Exception e)
            {
                MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress, "An error occured while reading the rss document. Please try later.");
                Thread.Sleep(1500);
                MessageBox.Show(e.ToString());

                try
                {
                    xDoc.Load(reader);
                }
                catch (Exception)
                {
                    MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress, "An error occured while reading the rss document. Please try later.");
                    Thread.Sleep(1500);
                    return;
                }

            }
            #endregion


            //MessageBox.Show(xDoc.InnerXml);

            XmlNodeList torrents = xDoc.GetElementsByTagName("item");

            foreach (XmlNode torrent in torrents)
            {

                XmlNodeList tags = torrent.ChildNodes;
                string title = "";
                string year = "";
                string seeds = "";
                string leechers = "";
                string link = "";

                #region loop torrent tags and retrieve their values
                foreach (XmlNode tag in tags)
                {
                    #region retrieve url
                    if (tag.Name == "enclosure")
                    {
                        XmlAttributeCollection attributes = tag.Attributes;
                        foreach (XmlAttribute attribute in attributes)
                        {
                            if (attribute.Name == "url")
                            {
                                //MessageBox.Show("attrib innertext: " + attribute.InnerText);
                                link = attribute.InnerText;
                            }


                        }

                    }
                    #endregion

                    if (tag.Name == "title")
                    {
                        //MessageBox.Show(tag.InnerText);

                        #region parse release name and return film information
                        Regex regex = new Regex(".*?(?<Title>.*?)\\[(?<Year>.*?)\\].*?\\((?<Seeds>.*?)S/(?<Leechers>.*?)L");
                        MatchCollection matches = regex.Matches(tag.InnerText);

                        if (matches.Count == 0)
                        {
                            regex = new Regex("(?<Title>.*?)\\z");
                            matches = regex.Matches(tag.InnerText);

                            if (matches.Count == 0)
                                continue;
                        }


                        Match match = matches[0];

                        #region mine data from match

                        int i = 0;
                        foreach (Group group in match.Groups)
                        {
                            //Console.WriteLine(i);

                            #region retrieve item tags from regex captures
                            foreach (Capture captrue in @group.Captures)
                            {


                                #region extract title
                                if (i == 1) //this is the image's url
                                {
                                    title = captrue.Value;
                                    //MessageBox.Show("Title: " + captrue.Value);
                                }
                                #endregion


                                #region extract year
                                if (i == 2)
                                {
                                    year = captrue.Value;
                                    //MessageBox.Show("Year: " + captrue.Value);
                                }
                                #endregion

                                #region extract Seeds
                                if (i == 3)
                                {
                                    seeds = captrue.Value;
                                    //MessageBox.Show("Seeds: " + captrue.Value);
                                }
                                #endregion

                                #region extract Leechers
                                if (i == 4)
                                {
                                    leechers = captrue.Value;
                                    //MessageBox.Show("Leechers: " + captrue.Value);
                                }
                                #endregion


                            }
                            #endregion

                            i++;
                        }
                        #endregion


                        #endregion

                    }

                }
                #endregion

                #region check if torrent already exists
                IMLItemList items = ReleasesSection.SearchByLocation(link);
                if (items.Count != 0)
                    continue;
                #endregion

                #region add & identify films
                ReleasesSection.BeginUpdate();
                #region create new torrent item
                //MessageBox.Show(link);
                IMLItem Item = ReleasesSection.AddNewItem(title, link);
                Item.Tags["Title"] = title;
                Item.Tags["Year"] = year;
                Item.Tags["Seeds"] = seeds;
                Item.Tags["Peers"] = leechers;
                string imdbid = Helpers.GetTagValueFromItem(Item,"IMDbID");
                Item.SaveTags();
                #endregion

                //MessageBox.Show("Before: " + Item.Name);
                MovieFileMetadataExtractor.ExtractMetadataFromMovieFilename(Item, ref imdbid, combinedSceneTags);
                //MessageBox.Show("After: " + Item.Name);
                Item.Name = Item.Name.Replace('.', ' ');
                Item.Tags["Title"] = Item.Name;
                Item.SaveTags();


                if (Settings.FilmRatingMin != 0)
                {
                    IMDbOperations imdbOP = new IMDbOperations();
                    imdbOP._assistType = IMDbOperations.AssistType.Never;
                    connResult.OSDbIsOnline = false;
                    string tmp = "";
                    Helpers.IdentifyVideo(ref imdbid, ref tmp, ref imdbOP, Item, true, false, "", "", year , connResult, ReleasesSection);
                    tmp = null;


                    #region IMDb Detailer

                    string HasDetails = Helpers.GetTagValueFromItem(Item,"HasDetails");
                    if (HasDetails != "True")
                    {
                        ////MessageBox.Show("About to d/load film details from IMDB...");



                        #region ...now get film details using this iMDBiD...
                        //MessageBox.Show("imdbid before d/loading details is: " + imdbid);
                        //MessageBox.Show("imdbOP._imdbID before d/loading details is: " + imdbOP._imdbID);
                        if (imdbOP.ImdbId != "") imdbid = imdbOP.ImdbId;
                        if (imdbid != "") imdbOP.ImdbId = imdbid;


                        imdbOP.ImdbMovie = null;
                        if (!String.IsNullOrEmpty(imdbOP.ImdbId))
                        {
                            imdbid = imdbOP.ImdbId;
                            //imdbOP._imdbID = imdbid;
                            //////MessageBox.Show("imdbID before getting details is: " + imdbid );
                            //////MessageBox.Show("IMDbOP.imdbid is: " + imdbOP._imdbID);
                            #region ...get the film's details.
                            if (!imdbid.StartsWith("tt"))
                                imdbid = "tt" + imdbid;

                            // _progressText = "Grabbing IMDb ID: " + imdbOP._imdbID;
                            MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress, "Downloading details from IMDb for " + imdbOP.ImdbId + "...");
                            imdbOP.GetIMDbMovieDetails(imdbid, true);
                            #endregion
                        }
                        #endregion


                        #region ...finally if the movie struct is filled, save the film details in the item's fields.
                        if (!String.IsNullOrEmpty(imdbid))
                        {
                            //string Episode = imdbOP._imdbMovie.Episode;

                            //MessageBox.Show(Episode);

                            //MessageBox.Show("title before saving: " + imdbOP._imdbMovie.Title);



                            //MessageBox.Show("... movie struct is filled, about to save details in tags...");
                            imdbOP.SaveIMDbMovieDetails(Item, ReleasesSection , imdbOP);


                            if (Item.Name.StartsWith("\""))
                            {
                                MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress, "This item is a TV episode.");
                                Thread.Sleep(1000);

                                MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress, "Searching for episode information...");


                                imdbOP.SaveEpisodeInfo(imdbid, Item );


                            }



                            //////MessageBox.Show("Saved movie details. continuing to cover art...");
                            //Item.Tags["HasDetails"] = "True";
                            //Item.SaveTags();
                        }
                        #endregion

                    }

                    #endregion
                }
                ReleasesSection.EndUpdate();


                #endregion

                #region Get torrent destination
                string location = Item.Location;
                string destination = "";

                if (String.IsNullOrEmpty(Settings.TorrentsFolder))
                    destination = Debugger.GetPluginPath() + "test.torrent";
                else
                {
                    destination = Settings.TorrentsFolder + title + ".torrent";
                }
                #endregion

                #region check if Title already exists in Releases section
                string Title = Helpers.GetTagValueFromItem(Item,"Title");
                IMLItemList itemsb = ReleasesSection.SearchByTag("Title", Title);
                if (itemsb.Count > 1)
                    continue;
                #endregion

                #region check if Title already exists in Movies section
                IMLItemList itemsc = MediaSection.SearchByTag("Title", Title);
                if (itemsc.Count != 0)
                    continue;
                #endregion

                #region Donwload the torrent
                double review = Convert.ToDouble(Helpers.GetTagValueFromItem(Item,"Review"));

                if (review > Settings.FilmRatingMin || Settings.FilmRatingMin == 0)
                {
                    //MessageBox.Show("destination: " + destination);
                    //MessageBox.Show("location: " + location);
                    #region Download torrent
                    try
                    {
                        client.DownloadFile(location, destination);
                    }
                    catch (Exception e)
                    {
                        Debugger.LogMessageToFile("[RSS torrent downloader] The torrent '" + location + "' could not be downloaded. The erros was: " + e.ToString() );
                    }
                    #endregion

                    #region Start torrent
                    //if (String.IsNullOrEmpty(Importer.TorrentsFolder))
                    //{
                    #region start torrent directly
                    Process p = new Process();
                    p.StartInfo.FileName = destination;

                    p.Start();

                    //while (!p.HasExited)
                    //{
                    //    Application.DoEvents();
                    //    Thread.Sleep(50);
                    //}
                    Thread.Sleep(5000);

                    try
                    {
                        File.Delete(destination);
                    }
                    catch { }
                    #endregion
                    //}
                    #endregion

                }
                #endregion

            }


        }
        public void SaveIMDbMovieDetails(IMLItem item, IMLSection section, IMDbOperations imdbOp)
        {

            ImdbMovie = imdbOp.ImdbMovie;

            if (ImdbMovie == null)
                return;

            SetFieldNames();


            try
            {

                section.BeginUpdate();

                SavePrimaryIMDbDetails(item);
                SaveAdittionalIMDbDetails(item);

                item.SaveTags();
                section.EndUpdate();


            }
            catch (Exception e)
            {
                Debugger.LogMessageToFile("An unexpected error occured trying to save film details from IMDb to library. The error was: " + e );
                StatusForm.statusForm.TrayIcon.ShowBalloonTip(5000, "Error trying to save film details to library", "MediaFairy encountered an error trying to save the details of a film to library. Please see Debug.log for details.", ToolTipIcon.Error);
                MainImportingEngine.GeneralStatus = "Updating Movies section...";
                MainImportingEngine.SpecialStatus = "An error occured trying to save film details from IMDb to library.";
                Helpers.UpdateProgress(MainImportingEngine.GeneralStatus, MainImportingEngine.SpecialStatus, null);
                Thread.Sleep(5000);
                return;
            }

            return;
        }
        private static void CleanUserFields
            (IMLSection section, bool cleanSelectedFields, string selectedFieldsToClean)
        {

            if (!cleanSelectedFields) 
                return;

            //Importer.CurrentProgress++;
            MainImportingEngine.ThisProgress.Progress
                (MainImportingEngine.CurrentProgress, 
                "Cleaning user-specified library fields...");
            
            Thread.Sleep(800);


            section.BeginUpdate();

            string[] fieldsToClean = selectedFieldsToClean.Split(',');

            foreach (string fieldtoclean in fieldsToClean)
                section.DeleteTag(fieldtoclean.Trim());

            section.EndUpdate();

        }
        public static void SynchronizeITunesIpod(IMLSection MusicSection)
        {


            Importer.CurrentProgress = 0;
            Importer.GeneralStatus = "Synchronizing iTunes...";
            Importer.SpecialStatus = String.Empty;

            #region iTunes % iPod


            if (Settings.WantItunesSync && Settings.WantToUpdateMusicSection && MusicSection != null)
            {
                try
                {

                    iTunesLib.IiTunes iTunesApp;
                    iTunesLib.IITLibraryPlaylist playlist;
                    iTunesLib.IITTrackCollection TrackCollection;

                    #region Launch itunes
                    //Importer.CurrentProgress++;
                    Importer.ThisProgress.Progress(Importer.CurrentProgress, "Launching iTunes...");
                    iTunesApp = new iTunesLib.iTunesAppClass();

                    Thread.Sleep(5000);

                    iTunesLib.IITWindowCollection windows = iTunesApp.Windows;
                    foreach (iTunesLib.IITWindow window in windows)
                    {

                        if (window.Name == "iTunes")
                        {
                            window.Minimized = true;
                        }

                    }

                    #endregion


                    #region iTunes Synchronizer




                    #region sync libraries


                    playlist = iTunesApp.LibraryPlaylist;
                    TrackCollection = playlist.Tracks;



                    MusicSection.BeginUpdate();
                    try
                    {

                        foreach (iTunesLib.IITTrack track in TrackCollection)
                        {

                            if (track.Kind == iTunesLib.ITTrackKind.ITTrackKindFile)
                            {
                                iTunesLib.IITPlaylist trackPlaylist = track.Playlist;
                                //MessageBox.Show(trackPlaylist.Name);
                                //iTunesLib.IITPlaylist track_playlist = track.Playlist;
                                //MessageBox.Show("Track playlist: " + track_playlist.Name);
                                iTunesLib.IITFileOrCDTrack file = (iTunesLib.IITFileOrCDTrack)track;

                                if (file.Location != "" && file.Location != null)
                                {

                                    FileInfo fiB = new FileInfo(file.Location);

                                    //MessageBox.Show(fiB.Extension);

                                    #region check to make sure that the file is not video...
                                    if (fiB.Extension != ".m4v")
                                    {

                                        IMLItem Item = MusicSection.FindItemByLocation(file.Location);

                                        if (Item == null && file.Podcast == false)
                                        {

                                            Importer.ThisProgress.Progress(Importer.CurrentProgress, "Adding audio track " + track.Name + " to music library...");
                                            Item = MusicSection.AddNewItem(track.Name, file.Location);


                                            #region write item tags

                                            Item.Tags["Artist"] = track.Artist;
                                            Item.Tags["Album"] = track.Album;
                                            Item.Tags["Title"] = track.Name;

                                            Item.Tags["Genre"] = track.Genre;
                                            if (track.TrackNumber != 0)
                                                Item.Tags["Track"] = track.TrackNumber;
                                            if (track.Year != 0)
                                                Item.Tags["Year"] = track.Year;

                                            try
                                            {
                                                if (file.Lyrics != null && file.Lyrics != "")
                                                    Item.Tags["Lyrics"] = file.Lyrics;
                                            }
                                            catch (Exception)
                                            { }


                                            if (track.Rating != 0)
                                                Item.Tags["Rating"] = Convert.ToString(track.Rating);
                                            if (track.SampleRate != 0)
                                                Item.Tags["SampleRate"] = track.SampleRate;
                                            if (track.BitRate != 0)
                                                Item.Tags["BitRate"] = track.BitRate;
                                            if (track.Duration != 0)
                                                Item.Tags["Duration"] = track.Duration;

                                            #endregion


                                            #region save artwork to file and add to imagefield

                                            try
                                            {
                                                iTunesLib.IITArtworkCollection artworks = track.Artwork;
                                                foreach (iTunesLib.IITArtwork artwork in artworks)
                                                {
                                                    FileInfo fi = new FileInfo(file.Location);
                                                    DirectoryInfo di = fi.Directory;
                                                    string trackDirectory = di.FullName;

                                                    string artworkPath = trackDirectory + @"\" + "folder.jpg";
                                                    //MessageBox.Show(artworkPath);
                                                    artwork.SaveArtworkToFile(artworkPath);
                                                    Item.ImageFile = artworkPath;
                                                }
                                            }
                                            catch (Exception)
                                            { }

                                            #endregion

                                            Item.SaveTags();
                                        }

                                    }
                                    #endregion

                                }

                            }

                        }


                    }
                    catch (Exception e)
                    {
                        MusicSection.EndUpdate();
                        MessageBox.Show(e.ToString());
                    }

                    MusicSection.EndUpdate();

                    #endregion


                    #endregion



                    #region manage and Update iPod

                    //iTunesApp.UpdateIPod();



                    iTunesLib.IITSourceCollection sources = iTunesApp.Sources;

                    foreach (iTunesLib.IITSource source in sources)
                    {

                        //MessageBox.Show(source.Name);


                        if (source.Kind == iTunesLib.ITSourceKind.ITSourceKindIPod)
                        {
                            object iSource = source;

                            //iTunesLib.IITLibraryPlaylist MyPlaylist =(iTunesLib.IITLibraryPlaylist) iTunesApp.CreatePlaylistInSource("MyPlaylist", ref iSource);


                            //MyPlaylist.AddFile("D:\test.mp3");



                            //iTunesLib.IITPlaylistCollection iPodPlaylists = source.Playlists;

                            //foreach (iTunesLib.IITPlaylist ipodPlaylist in iPodPlaylists)
                            //{
                            //    //MessageBox.Show("iPod library name:" + ipodlibrary.Name);
                            //    //MessageBox.Show("Duration: " + Convert.ToString(ipodlibrary.Duration));

                            //    if (ipodPlaylist.Kind == iTunesLib.ITPlaylistKind.ITPlaylistKindLibrary)
                            //    {
                            //        iTunesLib.IITLibraryPlaylist iPodLibrary = (iTunesLib.IITLibraryPlaylist)ipodPlaylist;


                            //        iPodLibrary.AddFile("D:\test.mp3");

                            //    }

                            //}


                        }


                        //foreach (iTunesLib.IITLibraryPlaylist ipodlibrary in ipodPlaylists)
                        //{
                        //    MessageBox.Show("Passed 4");
                        //    MessageBox.Show(Convert.ToString(ipodlibrary.Duration));
                        //}


                    }

                    #endregion

                }
                catch (Exception)
                {

                }

            }


            #endregion





        }
        internal static void MoveToTvSection(IMLSection section, IMLSection tvSection,
            IMLItem item, bool ranFromTvSection, string seasonNumber,
            string episodeNumber, string seriesName)
        {

            if (tvSection == null) return;

            bool moveSeriesToTvSection = !ranFromTvSection;

            if (!moveSeriesToTvSection) return;

            Debugger.LogMessageToFile("Moving episode " + item.Name + " to TvEpisodes section...");

            tvSection.BeginUpdate();

            IMLItem tvItem = tvSection.AddNewItem(item.Name, item.Location);
            tvItem.Tags["SeasonNumber"] = seasonNumber;
            tvItem.Tags["EpisodeNumber"] = episodeNumber;
            tvItem.Tags["SeriesName"] = seriesName;
            tvItem.SaveTags();

            tvSection.EndUpdate();

            section.DeleteItem(item);

        }
        internal static void ImportPcGames(IMLImportProgress progress, IMLSection gamesSection)
        {

            if ((!Settings.EnableGamesUpdater && !Settings.EnableGamesImporter))
                return;
                            
            if (String.IsNullOrEmpty(Settings.GameShortcutsLocation) )
                return;

            if ( !File.Exists(Settings.GameShortcutsLocation) )
            return;


            Importer.ThisProgress = progress;
            //Importer.GeneralStatus = "Updating Games Section";
            Importer.SpecialStatus = String.Empty;
            Importer.ThisProgress.Progress(Importer.CurrentProgress, "Updating Games Section...");

            DirectoryInfo pcGamesFolder = new DirectoryInfo(Settings.GameShortcutsLocation);
            FileInfo[] shortcuts = pcGamesFolder.GetFiles("*.lnk", SearchOption.AllDirectories);
            //IMLSection GamesSection = Importer.library.FindSection("Games", true);

            #region Man importing engine

            int itemCounter = 0;
            WshShell shell = new WshShellClass();

            gamesSection.BeginUpdate();

            foreach (FileInfo shortcut in shortcuts)
            {
                int progressStep = 100 / shortcuts.Length;
                Importer.CurrentProgress = 100 - (progressStep * (shortcuts.Length - itemCounter));

                ImportPcGame(shell, shortcut.FullName, gamesSection);
                itemCounter++;
            }

            gamesSection.EndUpdate();

            #endregion

            #region Update

            if (!Settings.EnableGamesUpdater) return;


           

            gamesSection.BeginUpdate();
            itemCounter = 0;
            int[] allItemIDs = gamesSection.GetAllItemIDs();

            foreach (int id in allItemIDs)
            {
                IMLItem item = gamesSection.FindItemByID(id);
                int progressStep = 100 / allItemIDs.Length;
                Importer.CurrentProgress = 100 - (progressStep * (allItemIDs.Length - itemCounter));
                Downloaders.DownloadGameDetailsFromMobyGames(item);

                Helpers.UserCancels(Importer.SpecialStatus, item);

                itemCounter++;
            }

            gamesSection.EndUpdate();
            
            

            #endregion

        } //endof function
        internal static void AddFileToSection(out IMLItem item, IMLSection section,
            string itemName, string itemLocation, string externalID)
        {


            //TODO: Implement option to not update the Media Section on each imported item.

            if (Settings.UpdateMediaSectionOnEachImportedItem)
                section.BeginUpdate();


            item = section.AddNewItem(itemName, itemLocation);
            item.ExternalID = externalID;
            item.SaveTags();


            //BUG: Enabling this function makes importer unable to inport files!

            //MediaSectionPopulatorHelpers.ImportDates(item, externalID);


            if (Settings.UpdateMediaSectionOnEachImportedItem)
                section.EndUpdate();


      
        }
        public bool Import(IMLSection Section, IMLImportProgress Progress)
        {
            XmlDocument IceCastDirectoryXml = new XmlDocument();

            WebClient client = new WebClient();

            const string iceCastDirectoryURL = "http://dir.xiph.org/yp.xml";

            Console.WriteLine("Downloading xml data...");

            Progress.Progress(0, "Loading IceCast station directory...");

            byte[] data = client.DownloadData(iceCastDirectoryURL);

            Stream stream = new MemoryStream(data);

            IceCastDirectoryXml.Load(stream);

            XmlNode directoryNode = IceCastDirectoryXml.ChildNodes[1];

            Console.WriteLine(directoryNode.Name);

            XmlNodeList directoryEntries = directoryNode.ChildNodes;

            Section.BeginUpdate();

            foreach (XmlNode radioStation in directoryEntries)
            {

                XmlNodeList stationProperties = radioStation.ChildNodes;

                string itemName = String.Empty;
                string itemLocation = String.Empty;
                string itemBitrate = String.Empty;
                string itemGenre = String.Empty;

                foreach (XmlNode stationProperty in stationProperties)
                {

                    if (stationProperty.Name == "server_name")
                    {
                        itemName = stationProperty.InnerText;

                    }

                    if (stationProperty.Name == "listen_url")
                    {
                        itemLocation = stationProperty.InnerText;

                    }

                    if (stationProperty.Name == "bitrate")
                    {
                        itemBitrate = stationProperty.InnerText;

                    }

                    if (stationProperty.Name == "genre")
                    {
                        itemGenre = stationProperty.InnerText;

                    }

                }

                if (String.IsNullOrEmpty(itemName))
                    continue;

                if (String.IsNullOrEmpty(itemLocation))
                    continue;

                IMLItem item
                    = Section.AddNewItem
                    (itemName, itemLocation);

                item.Tags["BitRate"] = itemBitrate;
                item.Tags["Genre"] = itemGenre;

                item.SaveTags();

            }

            Section.EndUpdate();

            Progress.Progress(100, "RadioActive completed succesfully!");

            return true;
        }