コード例 #1
0
        private MusicTag GetTrackTag(MusicDatabase dbs, string strFile, bool useID3, string title, string artist)
        {
            MusicTag tag;
            var      song   = new Song();
            var      bFound = dbs.GetSongByFileName(strFile, ref song);

            if (!bFound)
            {
                // Track information already available
                if (!string.IsNullOrEmpty(title) && !string.IsNullOrEmpty(artist))
                {
                    song.Title  = title;
                    song.Artist = artist;
                    song.Album  = string.Empty;
                    tag         = song.ToMusicTag();
                    return(tag);
                }

                // If allowed, read tag from file
                if (useID3)
                {
                    tag = TagReader.ReadTag(strFile);
                    if (tag != null && !string.IsNullOrEmpty(tag.Title) && !string.IsNullOrEmpty(tag.Artist))
                    {
                        return(tag);
                    }
                }

                // tagreader failed or not using it and no available track information
                song.Title  = Path.GetFileNameWithoutExtension(strFile);
                song.Artist = string.Empty;
                song.Album  = string.Empty;
            }
            tag = song.ToMusicTag();
            return(tag);
        }
コード例 #2
0
        private void GetCoverArtList(string folderPath, ref int albumCount, ref int curCount, bool skipIfCoverartExist,
                                     ref List <Song> songs)
        {
            DirectoryInfo dirInfo = new DirectoryInfo(folderPath);

            FileSystemInfo[] fsInfos = dirInfo.GetFileSystemInfos();
            bool             foundTrackForThisDir = false;
            bool             skippingAlbum        = false;

            foreach (FileSystemInfo fsi in fsInfos)
            {
                try
                {
                    CheckForAppShutdown();

                    if (_Abort || _AbortedByUser || GUICoverArtGrabberResults.CancelledByUser)
                    {
                        break;
                    }

                    // Is it a DirectoryInfo object...
                    if (fsi is DirectoryInfo)
                    {
                        //curCount++;
                        foundTrackForThisDir = false;

                        // Iterate through all sub-directories.
                        GetCoverArtList(fsi.FullName, ref albumCount, ref curCount, skipIfCoverartExist, ref songs);
                    }

                    // ...or a FileInfo object?
                    else if (fsi is FileInfo)
                    {
                        // Have we already processed a track for this folder
                        // and if so, is it an audio file?
                        if (foundTrackForThisDir || !Util.Utils.IsAudio(fsi.FullName))
                        {
                            continue;
                        }

                        string        path  = Path.GetDirectoryName(fsi.FullName);
                        DirectoryInfo di    = new DirectoryInfo(path);
                        FileInfo[]    files = null;

                        if (di != null)
                        {
                            files = di.GetFiles();
                        }

                        string artist              = string.Empty;
                        bool   isCompilation       = false;
                        int    difArtistCount      = 0;
                        int    foundAudioFileCount = 0;

                        MusicTag tag  = null;
                        Song     song = null;

                        for (int i = 0; i < files.Length; i++)
                        {
                            if (foundAudioFileCount > 0)
                            {
                                break;
                            }

                            song = null;
                            tag  = null;

                            string curTrackPath = files[i].FullName;

                            if (!Util.Utils.IsAudio(curTrackPath))
                            {
                                continue;
                            }

                            foundAudioFileCount++;
                            song = new Song();
                            if (_MusicDatabase.GetSongByFileName(curTrackPath, ref song))
                            {
                                // Make sure the the returned song has a valid file path
                                if (song.FileName.Length == 0)
                                {
                                    song.FileName = curTrackPath;
                                }

                                if (artist == string.Empty)
                                {
                                    artist = song.Artist;
                                    continue;
                                }

                                if (artist.ToLower().CompareTo(song.Artist.ToLower()) != 0)
                                {
                                    difArtistCount++;
                                }
                            }

                            else
                            {
                                song = null;
                                tag  = TagReader.TagReader.ReadTag(curTrackPath);

                                if (tag != null)
                                {
                                    if (artist == string.Empty)
                                    {
                                        artist = tag.Artist;
                                        continue;
                                    }

                                    if (artist.ToLower().CompareTo(tag.Artist.ToLower()) != 0)
                                    {
                                        difArtistCount++;
                                    }
                                }
                            }
                        }

                        if (difArtistCount > 0)
                        {
                            isCompilation = true;
                        }

                        if (song == null)
                        {
                            if (tag != null)
                            {
                                song          = new Song();
                                song.FileName = fsi.FullName;
                                song.Album    = tag.Album;

                                if (isCompilation)
                                {
                                    song.Artist = "";
                                }

                                song.Artist = tag.Artist;
                                song.Title  = tag.Title;
                                song.Track  = tag.Track;
                            }
                        }

                        if (song != null)
                        {
                            curCount++;

                            //Log.Info("Cover art grabber:updating status for {0}", song.Album);
                            UpdateAlbumScanProgress(song.Album, albumCount, curCount);
                            foundTrackForThisDir = true;

                            if (_SkipIfCoverArtExists &&
                                GUIMusicBaseWindow.CoverArtExists(song.Artist, song.Album, song.FileName, _SaveImageToAlbumFolder))
                            {
                                continue;
                            }

                            if (skippingAlbum)
                            {
                                continue;
                            }

                            songs.Add(song);
                        }
                    }
                }

                catch (Exception ex)
                {
                    Log.Info("Cover art grabber exception:{0}", ex.ToString());
                    continue;
                }
            }
        }
コード例 #3
0
        private bool GetIsCompilationAlbum(string path, int numFilesToCheck)
        {
            MusicDatabase dbMusic = null;

            DirectoryInfo di = new DirectoryInfo(path);

            FileInfo[] files = null;

            if (di == null)
            {
                return(false);
            }

            files = di.GetFiles();

            if (files == null || files.Length == 0)
            {
                return(false);
            }

            dbMusic = MusicDatabase.Instance;

            string artist             = string.Empty;
            bool   IsCompilationAlbum = false;
            int    difArtistCount     = 0;

            int checkCount = 0;

            if (numFilesToCheck == -1)
            {
                checkCount = files.Length;
            }

            else
            {
                Math.Min(files.Length, numFilesToCheck);
            }

            MusicTag tag  = null;
            Song     song = null;

            for (int i = 0; i < checkCount; i++)
            {
                string curTrackPath = files[i].FullName;

                if (!Util.Utils.IsAudio(curTrackPath))
                {
                    continue;
                }

                song = new Song();

                if (dbMusic.GetSongByFileName(curTrackPath, ref song))
                {
                    if (artist == string.Empty)
                    {
                        artist = song.Artist;
                        continue;
                    }

                    if (artist.ToLower().CompareTo(song.Artist.ToLower()) != 0)
                    {
                        difArtistCount++;
                    }
                }

                else
                {
                    tag = TagReader.TagReader.ReadTag(curTrackPath);

                    if (tag != null)
                    {
                        if (artist == string.Empty)
                        {
                            artist = tag.Artist;
                            continue;
                        }

                        if (artist.ToLower().CompareTo(tag.Artist.ToLower()) != 0)
                        {
                            difArtistCount++;
                        }
                    }
                }
            }

            if (difArtistCount > 0)
            {
                IsCompilationAlbum = true;
            }

            return(IsCompilationAlbum);
        }
コード例 #4
0
        private void SetLevelForPlayback(string mediaType, string Level)
        {
            if ((previousLevel == "Play" || previousLevel == "Pause") && (Level == "Play") && (previousMediaType != mediaType))
            {
                previousLevel = "Stop";
            }

            Playback playback = new Playback()
            {
                Title        = string.Empty,
                LengthString = string.Empty,
                Genre        = string.Empty,
                FileName     = string.Empty,
                Poster       = string.Empty,
                Fanart       = string.Empty
            };

            if (!mediaType.Equals("Plugin"))
            {
                if (g_Player.IsDVD)
                {
                    if (DebugMode)
                    {
                        Logger.Debug("Length is Long (Media is DVD)");
                    }
                    playback.LengthString = "Long";
                }
                else if ((mediaType == g_Player.MediaType.Video.ToString()) || mediaType == g_Player.MediaType.Recording.ToString())
                {
                    if (g_Player.Duration < (setLevelForMediaDuration * 60))
                    {
                        if (DebugMode)
                        {
                            Logger.Debug("Length is Short");
                        }
                        playback.LengthString = "Short";
                    }
                    else
                    {
                        if (DebugMode)
                        {
                            Logger.Debug("Length is Long");
                        }
                        playback.LengthString = "Long";
                    }
                }

                if (Level == "Play")
                {
                    playback.FileName = g_Player.Player.CurrentFile;

                    if (g_Player.IsMusic)
                    {
                        Song          song          = new Song();
                        MusicDatabase musicDatabase = MusicDatabase.Instance;
                        musicDatabase.GetSongByFileName(playback.FileName, ref song);
                        if (song != null)
                        {
                            playback.Genre = song.Genre;
                            playback.Title = song.Artist + " - " + song.Album + " - " + song.Title;
                        }
                    }

                    if (g_Player.IsVideo)
                    {
                        if (!playback.FileName.StartsWith("http://localhost/")) // Online Video is not in DB so skip DB Search
                        {
                            LatestMediaHandler.MQTTItem item;
                            try
                            {
                                if (DebugMode)
                                {
                                    Logger.Debug("Check to see if the video is a mounted disc.");
                                }

                                string filename = playback.FileName;
                                filename          = MountHelper.CheckMount(ref filename);
                                playback.FileName = filename;
                            }
                            catch
                            {
                                Logger.Warning("Daemontools not installed/configured");
                            }

                            item = MyVideoHelper.CheckDB(playback.FileName);
                            if (!string.IsNullOrEmpty(item.Filename))
                            {
                                playback.Genre  = item.Genres;
                                playback.Title  = item.Title;
                                playback.Poster = item.Poster;
                                playback.Fanart = item.Fanart;
                            }
                            else // Movie not in MyVideo's DB
                            {
                                if (DebugMode)
                                {
                                    Logger.Debug("Video is not in MyVideos database.");
                                }
                                try
                                {
                                    item = TVSeriesHelper.CheckDB(playback.FileName);
                                    if (!string.IsNullOrEmpty(item.Filename))
                                    {
                                        playback.Genre  = item.Genres;
                                        playback.Title  = item.Title;
                                        playback.Poster = item.Poster;
                                        playback.Fanart = item.Fanart;
                                    }
                                }
                                catch
                                {
                                    Logger.Warning("Error while searching TVSeries Database, probaly not installed");
                                }

                                if (string.IsNullOrEmpty(item.Filename))
                                {
                                    try
                                    {
                                        item = MovingPicturesHelper.CheckDB(playback.FileName);
                                        if (!string.IsNullOrEmpty(item.Filename))
                                        {
                                            playback.Genre  = item.Genres;
                                            playback.Title  = item.Title;
                                            playback.Poster = item.Poster;
                                            playback.Fanart = item.Fanart;
                                        }
                                    }
                                    catch
                                    {
                                        Logger.Warning("Error while searching MovingPictures Database, probaly not installed");
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (DebugMode)
                            {
                                Logger.Debug("Media is OnlineVideo");
                            }
                        }
                    }
                }

                SendEvent("Player", new string[] { "type:" + mediaType, "state:" + Level });
            }

            playback.Genre = !string.IsNullOrEmpty(playback.Genre) ? playback.Genre.Trim('|').Replace("|", " / ") : "";
            if (DebugMode)
            {
                Logger.Debug("ACTION " + Level + " Media: " + mediaType);
                if (!string.IsNullOrEmpty(playback.Title))
                {
                    Logger.Debug("Title: " + playback.Title);
                }
                if (!string.IsNullOrEmpty(playback.FileName))
                {
                    Logger.Debug("Filename: " + playback.FileName);
                }
                if (!string.IsNullOrEmpty(playback.Genre))
                {
                    Logger.Debug("Genre: " + playback.Genre);
                }
                if (!string.IsNullOrEmpty(playback.LengthString))
                {
                    Logger.Debug("Length: " + playback.LengthString);
                }
            }

            if (Level.Equals("Play"))
            {
                SendEvent("Player/" + mediaType, new string[] { "action:" + Level,
                                                                "data:" + JsonConvert.SerializeObject(playback, Formatting.Indented, new JsonSerializerSettings {
                        ContractResolver = new Utils.LowercaseContractResolver()
                    }) });
            }
            else
            {
                SendEvent("Player/" + mediaType, "action:" + Level);
            }

            previousLevel     = Level;
            previousMediaType = mediaType;
        }