Пример #1
0
        /// <summary>
        /// Gets the stream URL from a given song
        /// </summary>
        /// <param name="song">Song to stream</param>
        /// <returns></returns>
        public async Task <String> GetStreamURL(GoogleMusicSong song)
        {
            Uri reqUrl = null;

            // Looks like it's a preview song
            if (song.Preview != null)
            {
                reqUrl = new Uri(String.Format("https://play.google.com/music/playpreview?u=0&mode=streaming&preview={0}&tid={1}&pt=e",
                                               song.Preview.PreviewToken, song.Preview.TrackID));
            }
            // Shared song
            else if (song.Share != null)
            {
                reqUrl = new Uri(String.Format("https://play.google.com/music/playpreview?u=0&mode=streaming&preview={0}&tid={1}&postid={2}pt=e",
                                               song.Preview.PreviewToken, song.Preview.TrackID, song.Share.PostID));
            }
            // Normal song
            else
            {
                reqUrl = new Uri(String.Format("https://play.google.com/music/play?u=0&songid={0}", song.ID));
            }

            GoogleMusicSongUrl songUrl = null;

            try{
                songUrl = await client.GET <GoogleMusicSongUrl>(reqUrl);
            }
            catch {
            }

            return((songUrl != null) ? songUrl.URL : String.Empty);
        }
Пример #2
0
        /// <summary>
        /// Get song share url
        /// </summary>
        /// <param name="song">song to share</param>
        /// <returns></returns>
        public async Task <String> GetShareableURL(GoogleMusicSong song)
        {
            // Not all songs can be shared, licensing prolly
            if (song.StoreID == null)
            {
                return(null);
            }

            String jsonString = "{\"trackId\":\"" + song.StoreID + "\"}";

            HttpContent content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("json", jsonString),
            });


            GoogleMusicSongUrl url = await client.POST <GoogleMusicSongUrl>(new Uri("https://play.google.com/music/services/shareprepurchasepreview"), content);

            return(url.URL);
        }