Exemplo n.º 1
0
        protected YandexTrackDownloadInfo GetDownloadTrackInfo(string storageDir)
        {
            var fileName          = GetDownloadTrackInfoFileName(storageDir);
            var request           = GetRequest(_settings.GetDownloadTrackInfoURL(storageDir, fileName));
            var trackDownloadInfo = new YandexTrackDownloadInfo();

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                using (var stream = response.GetResponseStream())
                {
                    var reader     = new StreamReader(stream);
                    var sourceText = reader.ReadToEnd();

                    var xElem    = XDocument.Parse(sourceText).Root;
                    var elements = new Dictionary <string, string>();
                    for (var x = (XElement)xElem.FirstNode; x != null; x = (XElement)x.NextNode)
                    {
                        elements.Add(x.Name.LocalName, x.Value);
                    }
                    _cookies.Add(response.Cookies);

                    trackDownloadInfo.Host   = elements["host"];
                    trackDownloadInfo.Path   = elements["path"];
                    trackDownloadInfo.Ts     = elements["ts"];
                    trackDownloadInfo.Region = elements["region"];
                    trackDownloadInfo.S      = elements["s"];
                }
            }

            return(trackDownloadInfo);
        }
Exemplo n.º 2
0
        public Uri GetURLDownloadTrack(YandexTrack track, YandexTrackDownloadInfo downloadInfo)
        {
            var key = ""; //downloadInfo.Path.Substring(1, downloadInfo.Path.Length - 1) + downloadInfo.S;

            using (var md5 = MD5.Create())
            {
                key = GetMdHesh(md5,
                                $"XGRlBW9FXlekgbPrRHuSiA{downloadInfo.Path.Substring(1, downloadInfo.Path.Length - 1)}{downloadInfo.S}");
            }

            var trackDownloadUrl =
                String.Format("http://{0}/get-mp3/{1}/{2}{3}?track-id={4}&region=225&from=service-search",
                              downloadInfo.Host,
                              key,
                              downloadInfo.Ts,
                              downloadInfo.Path,
                              track.Id);

            return(new Uri(trackDownloadUrl));
        }