Exemple #1
0
        private async Task <Tuple <INetworkRandomAccessStream, HttpStatusCode> > GetNetworkStreamAsync(Song song)
        {
            GoogleMusicSongUrl songUrl = null;

            HttpStatusCode statusCode = HttpStatusCode.OK;

            try
            {
                songUrl = await this.songsWebService.GetSongUrlAsync(song);
            }
            catch (WebRequestException e)
            {
                statusCode = e.StatusCode;

                if (e.StatusCode == HttpStatusCode.Forbidden)
                {
                    this.logger.Debug("Forbidden: Exception while tried to get song url: {0}", e);
                }
                else if (e.StatusCode == HttpStatusCode.NotFound)
                {
                    this.logger.Debug("Not Found: Exception while tried to get song url: {0}", e);
                }
                else
                {
                    this.logger.Error(
                        new WebRequestException(string.Format("Cannot get network stream - {0}.", e.StatusCode), e.InnerException, e.StatusCode),
                        "Exception while tried to get song url.");
                }
            }
            catch (Exception e)
            {
                this.logger.Error(e, "Exception while tried to get song url.");
            }

            if (songUrl != null)
            {
                if (this.logger.IsDebugEnabled)
                {
                    this.logger.Debug("Getting stream by url '{0}'.", songUrl.Url);
                }

                try
                {
                    if (string.IsNullOrEmpty(songUrl.Url))
                    {
                        return(Tuple.Create(await this.mediaStreamDownloadService.GetStreamAsync(songUrl.Urls), statusCode));
                    }
                    else
                    {
                        return(Tuple.Create(await this.mediaStreamDownloadService.GetStreamAsync(songUrl.Url), statusCode));
                    }
                }
                catch (Exception exception)
                {
                    if (exception is TaskCanceledException)
                    {
                        this.logger.Debug("GetStreamAsync was cancelled.");
                    }
                    else
                    {
                        this.logger.Error(exception, "Exception while tried to get stream.");
                    }
                }
            }

            return(new Tuple <INetworkRandomAccessStream, HttpStatusCode>(null, statusCode));
        }
Exemple #2
0
 void api_OnGetSongURL(GoogleMusicSongUrl songurl)
 {
     new WebClient().DownloadFile(songurl.URL, "C:\\test.mp3");
 }