Ejemplo n.º 1
0
        public async Task <AudioDbTrack> GetTrackByMbidAsync(string mbid, string language, bool cacheOnly)
        {
            AudioDbTracks audioDbTracks = null;
            string        cache         = CreateAndGetCacheName(mbid, "Track_mbId");

            if (!string.IsNullOrEmpty(cache) && File.Exists(cache))
            {
                audioDbTracks = await _downloader.ReadCacheAsync <AudioDbTracks>(cache).ConfigureAwait(false);
            }
            else
            {
                if (cacheOnly)
                {
                    return(null);
                }
                string url = GetUrl(URL_TRACK_BY_MBDB, mbid);
                audioDbTracks = await _downloader.DownloadAsync <AudioDbTracks>(url, cache).ConfigureAwait(false);
            }
            if (audioDbTracks.Tracks != null && audioDbTracks.Tracks.Count > 0)
            {
                AudioDbTrack track = audioDbTracks.Tracks.Where(t => t.TrackID > 0).FirstOrDefault();
                if (track != null)
                {
                    track.SetLanguage(language);
                }
                return(track);
            }
            return(null);
        }
Ejemplo n.º 2
0
        public AudioDbTrack GetTrack(long tadbTrackId, string language, bool cacheOnly)
        {
            AudioDbTracks audioDbTracks = null;
            string        cache         = CreateAndGetCacheName(tadbTrackId, "Track");

            if (!string.IsNullOrEmpty(cache) && File.Exists(cache))
            {
                audioDbTracks = _downloader.ReadCache <AudioDbTracks>(cache);
            }
            else
            {
                if (cacheOnly)
                {
                    return(null);
                }
                string url = GetUrl(URL_TRACK_BY_TADB, tadbTrackId);
                audioDbTracks = _downloader.Download <AudioDbTracks>(url, cache);
            }
            if (audioDbTracks.Tracks != null && audioDbTracks.Tracks.Count > 0)
            {
                AudioDbTrack track = audioDbTracks.Tracks.Where(t => t.TrackID > 0).FirstOrDefault();
                if (track != null)
                {
                    track.SetLanguage(language);
                }
                return(track);
            }
            return(null);
        }