Exemplo n.º 1
0
        private void AddMusic(string[] strTemp, string strTitle, string strFileName, string strFilePath)
        {
            bool isFolder      = false;
            bool isEmptyFolder = false;

            FileInfo  file     = new FileInfo(Path.Combine(strFilePath, strFileName));
            Hashtable tags     = new Hashtable();
            Media     objMedia = MediaServices.Get(_strMediaName.Trim(), _mediaType, _path, _cleanTitle, _entityType, _patternType, _useSubFolder, _bGetImage, _bParseNfo, true);

            if (file.Exists == false && string.IsNullOrWhiteSpace(file.Extension))
            {
                if (Directory.Exists(file.FullName))
                {
                    DirectoryInfo folder = new DirectoryInfo(file.FullName);

                    FileInfo[] files = folder.GetFiles("*.mp3", SearchOption.TopDirectoryOnly);
                    files = files.Concat(folder.GetFiles("*.flc", SearchOption.TopDirectoryOnly)).ToArray();
                    files = files.Concat(folder.GetFiles("*.flac", SearchOption.TopDirectoryOnly)).ToArray();

                    if (files.Any())
                    {
                        file     = files[0];
                        isFolder = true;
                    }
                    else
                    {
                        isEmptyFolder = true;
                    }
                }
            }

            if (isEmptyFolder == false)
            {
                if (Dal.GetInstance.GetMusics(objMedia.Name, strFilePath, strFileName) == null)
                {
                    switch (file.Extension)
                    {
                    case ".mp3":
                        IID3v2 objMp3Tag = ID3v2Helper.CreateID3v2(file.FullName);

                        tags.Add("Title", objMp3Tag.Title);


                        if (string.IsNullOrWhiteSpace(objMp3Tag.Album) == false)
                        {
                            tags.Add("Album", objMp3Tag.Album);
                        }

                        if (isFolder == false && objMp3Tag.LengthMilliseconds != null)
                        {
                            tags.Add("Length", objMp3Tag.LengthMilliseconds);
                        }

                        if (objMp3Tag.PictureList.Count > 0)
                        {
                            tags.Add("Cover", objMp3Tag.PictureList[0].PictureData);
                        }

                        tags.Add("Genre", objMp3Tag.Genre);
                        tags.Add("Artist", objMp3Tag.Artist);
                        break;

                    case ".flac":
                    case ".flc":
                        try
                        {
                            FlacTagger objFlacTag = new FlacTagger(file.FullName);

                            tags.Add("Title", objFlacTag.Title);

                            if (string.IsNullOrWhiteSpace(objFlacTag.Album) == false)
                            {
                                tags.Add("Album", objFlacTag.Album);
                            }

                            if (isFolder == false)
                            {
                                tags.Add("Length", objFlacTag.Length);
                            }

                            if (objFlacTag.Arts.Count > 0)
                            {
                                tags.Add("Cover", objFlacTag.Arts[0].PictureData);
                            }

                            tags.Add("Genre", objFlacTag.Genre);
                            tags.Add("Artist", objFlacTag.Artist);
                            break;
                        }
                        //FIX 2.8.9.0
                        catch (FileFormatException)
                        {
                            break;
                        }
                    }

                    #region Title

                    if (tags.ContainsKey("Title") == false)
                    {
                        if (string.IsNullOrEmpty(strTitle) == false)
                        {
                            strTitle = strTitle.Replace('_', ' ');
                            strTitle = strTitle.Replace(".MP3", "");
                            strTitle = strTitle.Replace(".Mp3", "");
                            strTitle = strTitle.Replace(".flac", "");
                            strTitle = strTitle.Trim();
                            strTitle = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(strTitle);
                            tags.Add("Title", strTitle);
                        }
                    }

                    #endregion

                    Music objMusic = new Music();
                    objMusic.Ressources = new List <Ressource>();
                    objMusic.Genres     = new List <Genre>();
                    objMusic.Title      = strTitle;
                    objMusic.AddedDate  = DateTime.Now;
                    objMusic.FileName   = strFileName;
                    objMusic.FilePath   = strFilePath;

                    if (tags.ContainsKey("Album"))
                    {
                        objMusic.Album = tags["Album"].ToString();
                        if (isFolder == true && string.IsNullOrWhiteSpace(tags["Album"].ToString()) == false)
                        {
                            objMusic.Title = tags["Album"].ToString();
                        }
                    }

                    if (tags.ContainsKey("Length"))
                    {
                        objMusic.Runtime = tags["Length"] as int?;
                    }

                    objMusic.Media = objMedia;

                    #region Cover

                    if (_bGetImage == true)
                    {
                        RessourcesServices.AddImage(Util.GetLocalImage(objMusic.FilePath, objMusic.FileName, _bFile), objMusic,
                                                    true);
                    }
                    else
                    {
                        RessourcesServices.AddImage(tags["Cover"] as byte[], objMusic, true);
                    }

                    #endregion

                    bool bExist = false;
                    if (Dal.GetInstance.GetMusics(objMusic.Media.Name, objMusic.FilePath, objMusic.FileName) != null)
                    {
                        bExist = true;
                    }

                    if (bExist == false)
                    {
                        #region ParseNfo

                        if (_bParseNfo == true)
                        {
                            string errorMessage;
                            MusicServices.ParseNfo(objMusic, out errorMessage);
                        }
                        #endregion
                        #region Artist
                        string strArtistFullName = string.Empty;
                        if (tags.ContainsKey("Artist") == true)
                        {
                            if (tags["Artist"] == null)
                            {
                                if (_mapping != null)
                                {
                                    strArtistFullName = Util.ConstructString(strTemp, (string[])_mapping["Artist"], _nbrBaseParsing);
                                }
                            }
                            else
                            {
                                strArtistFullName = tags["Artist"] as string;
                            }
                        }
                        #endregion
                        Dal.GetInstance.AddMusic(objMusic);
                        if (tags.ContainsKey("Genre"))
                        {
                            GenreServices.AddGenres(new[] { tags["Genre"] as string }, objMusic, true);
                        }
                        if (strArtistFullName != null && string.IsNullOrWhiteSpace(strArtistFullName.Trim()) == false)
                        {
                            ArtistServices.AddArtist(strArtistFullName, objMusic);
                        }

                        _intAddedItem++;
                    }
                    else
                    {
                        _intNotAddedItem++;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void worker_DoWork_XML(object sender, DoWorkEventArgs e)
        {
            try
            {
                Total = _selectedItems.Length;

                foreach (XElement node in _selectedItems)
                {
                    //exit if the user cancels
                    if (_isCancelationPending == true)
                    {
                        return;
                    }

                    Movie movie = new Movie();
                    movie.Title         = Util.GetElementValue(node, "Title");
                    movie.OriginalTitle = Util.GetElementValue(node, "OriginalTitle");
                    movie.BarCode       = Util.GetElementValue(node, "BarCode");
                    movie.Comments      = Util.GetElementValue(node, "Comments");
                    movie.Description   = Util.GetElementValue(node, "Description");
                    movie.FileName      = Util.GetElementValue(node, "FileName");
                    movie.FilePath      = Util.GetElementValue(node, "FilePath");
                    movie.Country       = Util.GetElementValue(node, "Country");
                    movie.AlloCine      = Util.GetElementValue(node, "AlloCine");
                    movie.Imdb          = Util.GetElementValue(node, "Imdb");
                    movie.Tagline       = Util.GetElementValue(node, "Tagline");

                    DateTime dateValue;

                    if (DateTime.TryParse(Util.GetElementValue(node, "AddedDate"), out dateValue) == true)
                    {
                        movie.AddedDate = dateValue;
                    }

                    if (DateTime.TryParse(Util.GetElementValue(node, "ReleaseDate"), out dateValue) == true)
                    {
                        movie.ReleaseDate = dateValue;
                    }

                    #region Bool
                    bool boolValue;

                    if (bool.TryParse(Util.GetElementValue(node, "IsComplete"), out boolValue) == true)
                    {
                        movie.IsComplete = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsDeleted"), out boolValue) == true)
                    {
                        movie.IsDeleted = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "Seen"), out boolValue) == true)
                    {
                        movie.Watched = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "IsWhish"), out boolValue) == true)
                    {
                        movie.IsWhish = boolValue;
                    }

                    if (bool.TryParse(Util.GetElementValue(node, "ToBeDeleted"), out boolValue) == true)
                    {
                        movie.ToBeDeleted = boolValue;
                    }
                    #endregion
                    #region Int
                    int intValue;

                    if (int.TryParse(Util.GetElementValue(node, "Rated"), out intValue) == true)
                    {
                        movie.Rated = intValue.ToString(CultureInfo.InvariantCulture);
                    }

                    if (int.TryParse(Util.GetElementValue(node, "Rating"), out intValue) == true)
                    {
                        movie.MyRating = intValue;
                    }

                    if (int.TryParse(Util.GetElementValue(node, "Runtime"), out intValue) == true)
                    {
                        movie.Runtime = intValue;
                    }
                    #endregion
                    #region Media
                    var query = from item in node.Descendants("Media")
                                select item;

                    XElement[] movieNode = query.ToArray();

                    foreach (XElement media in movieNode)
                    {
                        Media newMedia = MediaServices.Get(Util.GetElementValue(media, "Name"), true);
                        newMedia.Path = Util.GetElementValue(media, "Path");
                        movie.Media   = newMedia;
                    }
                    #endregion
                    #region AspectRatio
                    query = from item in node.Descendants("AspectRatio")
                            select item;

                    movieNode = query.ToArray();

                    foreach (XElement aspectRatio in movieNode)
                    {
                        movie.AspectRatio = MovieServices.GetAspectRatio(Util.GetElementValue(aspectRatio, "Name"));
                    }
                    #endregion
                    #region FileFormat
                    query = from item in node.Descendants("FileFormat")
                            select item;

                    movieNode = query.ToArray();

                    foreach (XElement format in movieNode)
                    {
                        movie.FileFormat = MovieServices.GetFormat(Util.GetElementValue(format, "Name"));
                    }
                    #endregion
                    #region Studio
                    query = from item in node.Descendants("Studio")
                            select item;

                    movieNode = query.ToArray();

                    foreach (XElement studio in movieNode)
                    {
                        bool isNew;
                        movie.Publisher = PublisherServices.GetPublisher(Util.GetElementValue(studio, "Name"), out isNew, "Movie_Studio");
                        if (isNew == true)
                        {
                            Dal.GetInstance.AddPublisher("Movie_Studio", movie.Publisher);
                        }
                    }
                    #endregion
                    #region Links
                    query = from item in node.Descendants("Link")
                            select item;

                    movieNode = query.ToArray();

                    foreach (XElement link in movieNode)
                    {
                        LinksServices.AddLinks(Util.GetElementValue(link, "Path"), movie, true);
                    }

                    #endregion
                    #region Types
                    query = from item in node.Descendants("Type")
                            select item;

                    movieNode = query.ToArray();

                    foreach (XElement type in movieNode)
                    {
                        MovieServices.AddTypes(Util.GetElementValue(type, "RealName"), movie);
                    }
                    #endregion
                    #region Image
                    query = from item in node.Descendants("Ressource")
                            select item;

                    movieNode = query.ToArray();

                    foreach (XElement images in movieNode)
                    {
                        if (Util.GetElementValue(images, "ResourcesType") == "Image")
                        {
                            bool   isDefault = bool.Parse(Util.GetElementValue(images, "IsDefault"));
                            byte[] cover     = Convert.FromBase64String(Util.GetElementValue(images, "Value"));

                            if (cover.Length > 0)
                            {
                                RessourcesServices.AddImage(cover, movie, isDefault);
                            }
                        }
                        if (Util.GetElementValue(images, "ResourcesType") == "Background")
                        {
                            byte[] cover = Convert.FromBase64String(Util.GetElementValue(images, "Value"));

                            if (cover.Length > 0)
                            {
                                RessourcesServices.AddBackground(cover, movie);
                            }
                        }
                    }
                    #endregion
                    #region Artist
                    query = from item in node.Descendants("Artist")
                            select item;

                    XElement[] artistNode = query.ToArray();

                    foreach (XElement artist in artistNode)
                    {
                        bool   isNew;
                        string fullname  = Util.GetElementValue(artist, "FulleName");
                        Artist newArtist = ArtistServices.Get(fullname, out isNew);

                        if (string.IsNullOrWhiteSpace(newArtist.Aka))
                        {
                            newArtist.Aka = Util.GetElementValue(artist, "Aka");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.Bio))
                        {
                            newArtist.Bio = Util.GetElementValue(artist, "Bio");
                        }

                        if (newArtist.BirthDay == null && DateTime.TryParse(Util.GetElementValue(artist, "BirthDay"), out dateValue) == true)
                        {
                            newArtist.BirthDay = dateValue;
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.Breast))
                        {
                            newArtist.Breast = Util.GetElementValue(artist, "Breast");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.Ethnicity))
                        {
                            newArtist.Ethnicity = Util.GetElementValue(artist, "Ethnicity");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.FirstName))
                        {
                            newArtist.FirstName = Util.GetElementValue(artist, "FirstName");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.LastName))
                        {
                            newArtist.LastName = Util.GetElementValue(artist, "LastName");
                        }

                        if (newArtist.Picture == null)
                        {
                            newArtist.Picture = Convert.FromBase64String(Util.GetElementValue(artist, "Picture"));
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.PlaceBirth))
                        {
                            newArtist.PlaceBirth = Util.GetElementValue(artist, "PlaceBirth");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.WebSite))
                        {
                            newArtist.WebSite = Util.GetElementValue(artist, "WebSite");
                        }

                        if (string.IsNullOrWhiteSpace(newArtist.YearsActive))
                        {
                            newArtist.YearsActive = Util.GetElementValue(artist, "YearsActive");
                        }

                        query = from item in artist.Descendants("Credit")
                                select item;

                        XElement[] creditsNode = query.ToArray();

                        foreach (XElement artistCredit in creditsNode)
                        {
                            ArtistCredits artistCredits = new ArtistCredits();

                            artistCredits.Title      = Util.GetElementValue(artistCredit, "Title");
                            artistCredits.BuyLink    = Util.GetElementValue(artistCredit, "BuyLink");
                            artistCredits.EntityType = EntityType.Movie;
                            artistCredits.Notes      = Util.GetElementValue(artistCredit, "Notes");

                            DateTime releaseDate;
                            if (DateTime.TryParse(Util.GetElementValue(artistCredit, "ReleaseDate"), out releaseDate) == true)
                            {
                                artistCredits.ReleaseDate = releaseDate;
                            }

                            if (string.IsNullOrWhiteSpace(artistCredits.Title) == false && string.IsNullOrWhiteSpace(newArtist.FulleName) == false)
                            {
                                if (Dal.GetInstance.GetArtistCredit(artistCredits.Title, newArtist.FulleName) == null)
                                {
                                    newArtist.ArtistCredits.Add(artistCredits);
                                }
                            }
                        }

                        ArtistServices.AddArtist(new[] { newArtist }, movie);
                    }


                    #endregion

                    Dal.GetInstance.AddMovie(movie);
                    _intAddedItem++;

                    Current++;
                }
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
            }
        }
Exemplo n.º 3
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                Total = _selectedItems.Count;

                foreach (string item in _selectedItems)
                {
                    //exit if the user cancels
                    if (_isCancelationPending == true)
                    {
                        return;
                    }


                    if (string.IsNullOrWhiteSpace(item) == false)
                    {
                        string[] attributes = item.Split(';');

                        if (string.IsNullOrWhiteSpace(attributes[1]) == false)
                        {
                            Music music = new Music();
                            music.Title     = attributes[1];
                            music.Media     = new Media();
                            music.Media.Id  = _mediaId;
                            music.AddedDate = DateTime.Now;

                            ArtistServices.AddArtist(attributes[0], music);
                            GenreServices.AddGenres(new List <string> {
                                attributes[2]
                            }, music, true);

                            music.Comments = attributes[4];

                            List <string> tracks = new List <string>();
                            for (int i = 5; i < attributes.Length; i++)
                            {
                                if (string.IsNullOrWhiteSpace(attributes[i]) == false)
                                {
                                    tracks.Add(attributes[i]);
                                }
                            }

                            MusicServices.AddTracks(tracks, music);

                            Music bExist = null;
                            if (music.Artists != null && music.Artists.Count > 0)
                            {
                                bExist = Dal.GetInstance.GetMusics(_mediaName, music.Title, music.Artists.First().FirstName, music.Artists.First().LastName);
                            }

                            if (bExist == null)
                            {
                                Dal.GetInstance.AddMusic(music);
                                _intAddedItem++;
                            }
                            else
                            {
                                _intNotAddedItem++;
                            }
                        }
                    }
                    Current++;
                }
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
            }
        }