Ejemplo n.º 1
0
        public FreeDBCDInfoDetail GetDiscDetailsFromXMCD(string[] xmcd)
        {
            XMCDParser         parser = new XMCDParser();
            FreeDBCDInfoDetail cdInfo = parser.Parse2(xmcd);

            return(cdInfo);
        }
Ejemplo n.º 2
0
        public FreeDBCDInfoDetail GetDiscDetails(string category, string discid)
        {
            string[]           content = GetInfo("cddb+read+" + category + "+" + discid);
            XMCDParser         parser  = new XMCDParser();
            FreeDBCDInfoDetail cdInfo  = parser.Parse2(content);

            return(cdInfo);
        }
Ejemplo n.º 3
0
        public override async Task <List <AlbumInfo> > SearchTrackAlbumAsync(AlbumInfo albumSearch, string language)
        {
            if (string.IsNullOrEmpty(albumSearch.CdDdId))
            {
                return(null);
            }

            //TODO: Split CDDB ID into disc id and genre?
            string           genre  = null;
            string           discId = null;
            List <AlbumInfo> albums = null;

            try
            {
                if (_freeDbHandler.Connect())
                {
                    string[] xmcds = await _freeDbHandler.GetDiscDetailsXMCDAsync(genre, discId).ConfigureAwait(false);

                    if (xmcds != null)
                    {
                        string fileName = GetCacheFilePath(discId, genre);
                        if (File.Exists(fileName) == false)
                        {
                            File.WriteAllLines(fileName, xmcds, Encoding.UTF8);
                        }

                        FreeDBCDInfoDetail discInfo = _freeDbHandler.GetDiscDetailsFromXMCD(xmcds);
                        if (discInfo != null)
                        {
                            if (albums == null)
                            {
                                albums = new List <AlbumInfo>();
                            }

                            AlbumInfo info = new AlbumInfo()
                            {
                                CdDdId        = albumSearch.CdDdId,
                                Album         = discInfo.Title,
                                Artists       = ConvertToPersons(discInfo.Artist, PersonAspect.OCCUPATION_ARTIST),
                                TotalTracks   = discInfo.Tracks.Count(),
                                ReleaseDate   = discInfo.Year > 0 ? new DateTime(discInfo.Year, 1, 1) : default(DateTime?),
                                DataProviders = new List <string>()
                                {
                                    _name
                                }
                            };
                            albums.Add(info);
                        }
                    }
                }
            }
            finally
            {
                _freeDbHandler.Disconnect();
            }

            return(albums);
        }
Ejemplo n.º 4
0
        public async Task <FreeDBCDInfoDetail> GetDiscDetailsAsync(string category, string discid)
        {
            string[] content = await GetInfoAsync("cddb+read+" + category + "+" + discid).ConfigureAwait(false);

            XMCDParser         parser = new XMCDParser();
            FreeDBCDInfoDetail cdInfo = parser.Parse2(content);

            return(cdInfo);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get cached disc info.
        /// </summary>
        /// <param name="cdDbId">The CDDB ID</param>
        /// <returns><c>true</c> if disc match</returns>
        public bool GetCachedDisc(string cdDbId, out FreeDBCDInfoDetail disc)
        {
            disc = null;
            string[] files = GetMatchingCacheFiles(cdDbId);
            if (files == null || files.Length == 0 || files.Length > 1)
            {
                return(false);
            }

            disc = _freeDbHandler.GetDiscDetailsFromXMCD(File.ReadAllLines(files[0], Encoding.UTF8));
            return(disc != null);
        }
Ejemplo n.º 6
0
        public override async Task <List <TrackInfo> > SearchTrackAsync(TrackInfo trackSearch, string language)
        {
            if (string.IsNullOrEmpty(trackSearch.AlbumCdDdId) || trackSearch.TrackNum == 0)
            {
                return(null);
            }

            //TODO: Split CDDB ID into disc id and genre?
            string           genre  = null;
            string           discId = null;
            List <TrackInfo> tracks = null;

            try
            {
                if (_freeDbHandler.Connect())
                {
                    string[] xmcds = await _freeDbHandler.GetDiscDetailsXMCDAsync(genre, discId).ConfigureAwait(false);

                    if (xmcds != null)
                    {
                        string fileName = GetCacheFilePath(discId, genre);
                        if (File.Exists(fileName) == false)
                        {
                            File.WriteAllLines(fileName, xmcds, Encoding.UTF8);
                        }

                        FreeDBCDInfoDetail discInfo = _freeDbHandler.GetDiscDetailsFromXMCD(xmcds);
                        if (discInfo != null)
                        {
                            FreeDBCDTrackDetail foundTrack = null;
                            foreach (FreeDBCDTrackDetail trackDetail in discInfo.Tracks)
                            {
                                if (trackDetail.TrackNumber == trackSearch.TrackNum)
                                {
                                    foundTrack = trackDetail;
                                    break;
                                }
                            }
                            if (foundTrack == null)
                            {
                                return(null);
                            }

                            if (tracks == null)
                            {
                                tracks = new List <TrackInfo>();
                            }

                            TrackInfo info = new TrackInfo()
                            {
                                AlbumCdDdId  = trackSearch.AlbumCdDdId,
                                Album        = discInfo.Title,
                                AlbumArtists = ConvertToPersons(discInfo.Artist, PersonAspect.OCCUPATION_ARTIST),
                                TotalTracks  = discInfo.Tracks.Count(),
                                ReleaseDate  = discInfo.Year > 0 ? new DateTime(discInfo.Year, 1, 1) : default(DateTime?),

                                TrackNum      = foundTrack.TrackNumber,
                                TrackName     = foundTrack.Title,
                                Artists       = ConvertToPersons(foundTrack.Artist, PersonAspect.OCCUPATION_ARTIST),
                                Duration      = foundTrack.Duration,
                                DataProviders = new List <string>()
                                {
                                    _name
                                }
                            };
                            tracks.Add(info);
                        }
                    }
                }
            }
            finally
            {
                _freeDbHandler.Disconnect();
            }

            return(tracks);
        }
Ejemplo n.º 7
0
        public static string createXMCD(FreeDBCDInfoDetail cdinfo)
        {
            string        newline = "\n";
            int           index   = 0;
            StringBuilder content = new StringBuilder(400);
            StringBuilder tracks  = new StringBuilder(100);
            StringBuilder extt    = new StringBuilder(100);

            content.Append("# xmcd");
            content.Append(newline);
            content.Append("#");
            content.Append(newline);

            // Track frame offsets
            content.Append("# Track frame offsets:");
            foreach (FreeDBCDTrackDetail track in cdinfo.Tracks)
            {
                content.Append(newline);
                content.Append("#\t");
                content.Append(track.Offset);

                // do the other info about track too...

                // track title
                tracks.Append(newline);
                tracks.Append("TTITLE");
                tracks.Append(index);
                tracks.Append("=");
                tracks.Append(track.Title);

                // track EXTT
                extt.Append(newline);
                extt.Append("EXTT");
                extt.Append(index);
                extt.Append("=");
                extt.Append(track.EXTT);

                index++;
            }

            // Disc Length
            content.Append(newline);
            content.Append("#");
            content.Append(newline);
            content.Append("# Disc length: ");
            content.Append(cdinfo.Duration);
            content.Append(" seconds");

            // Revision
            content.Append(newline);
            content.Append("#");
            content.Append(newline);
            content.Append("# Revision: 0");

            // App information
            content.Append(newline);
            content.Append("# Submitted via: ");
            content.Append(APPNAME);
            content.Append(" ");
            content.Append(APPVERSION);
            content.Append(newline);
            content.Append("#");
            content.Append(newline);

            // DISC ID
            content.Append("DISCID=");
            content.Append(cdinfo.DiscID);
            content.Append(newline);

            // Title = Artist / Title
            content.Append("DTITLE=");
            content.Append(cdinfo.Artist);
            content.Append(" / ");
            content.Append(cdinfo.Title);
            content.Append(newline);

            // Year
            content.Append("DYEAR=");
            content.Append(cdinfo.Year);
            content.Append(newline);

            // Genre
            content.Append("DGENRE=");
            content.Append(cdinfo.Genre);

            //track titles
            content.Append(tracks);

            // EXTD
            content.Append(newline);
            content.Append("EXTD=");
            content.Append(cdinfo.EXTD);

            // EXTT
            content.Append(extt);

            // EXTD
            content.Append(newline);
            content.Append("PLAYORDER=");
            int[] order = cdinfo.PlayOrder;
            for (int i = 0; i < order.Length; i++)
            {
                if (i != 0)
                {
                    content.Append(',');
                }
                content.Append(order[i]);
            }
            content.Append(newline);

            return(content.ToString());
        }