Beispiel #1
0
        public async Task <string> DownloadFile(string url, FetchConfig config = null, string overrideFilenameHeader = null)
        {
            config = config ?? new FetchConfig
            {
                Headers = new Dictionary <string, string> {
                    { "accept", "image/png,image/webp,image/apng,*/*;q=0.8" },
                    { "accept-encoding", "gzip, deflate, br" },
                    { "cache-control", "no-cache" }
                },
                Credentials = CredentialsMode.Omit,
                Mode        = CorsMode.NoCors,
            };

            var response = await Fetch(url, config);

            if (response.Body is byte[] bytes)
            {
                var filename           = $"NOTSET_{Guid.NewGuid()}";
                var contentDisposition = response.Headers?.GetOrDefault("content-disposition", null);
                if (contentDisposition != null)
                {
                    var m = rxFileName.Match(contentDisposition);
                    if (m.Success)
                    {
                        filename = m.Groups["filename"].Value;
                    }
                }
                var path = Path.Combine(downloadFolderToCheck, overrideFilenameHeader ?? filename);
                await File.WriteAllBytesAsync(path, bytes);

                return(path);
            }
            return(response.Body.ToString());
        }
Beispiel #2
0
 protected override string GetLyric(SongInfo songInfo)
 {
     //Bilibi]li音乐频道目前不支持动态歌词格式,暂时先堆一起再说。
     try
     {
         FetchConfig fc = new FetchConfig
         {
             host    = API_HOST,
             path    = API_PATH + $"/music-service-c/web/song/info?sid={songInfo.Id}",
             referer = API_PROTOCOL + API_HOST + API_PATH,
             gzip    = true
         };
         string url = JObject.Parse(Fetch(fc))
                      .SelectToken("data.lyric")
                      ?.ToString();
         if (String.IsNullOrWhiteSpace(url))
         {
             return(String.Empty);
         }
         return("[00:00]" + Fetch(new FetchConfig(url)
         {
             referer = API_PROTOCOL + API_HOST + API_PATH
         })
                .Replace("\n", "    "));
     }
     catch (Exception ex)
     {
         Log($"歌词下载错误:{songInfo.Name}(ex:{ex.Message})");
         return(null);
     }
 }
Beispiel #3
0
 public FetchConfigFetchFunctionResolver(Uri projUri, FetchConfig fetchConfig, NameValueCollection constantQueryParams, string baseUrl)
     : base(projUri)
 {
     _fetchConfig         = fetchConfig;
     _constantQueryParams = constantQueryParams ?? new NameValueCollection();
     _baseUrl             = baseUrl;
 }
Beispiel #4
0
        /// <summary>
        /// Fetches the specified queue name.
        /// </summary>
        /// <param name="queueName">Name of the queue.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="configAction">The configuration action.</param>
        /// <returns></returns>
        public virtual IFluentRabbit Fetch(string queueName, Action <BasicGetResult> callback, Action <FetchConfig> configAction = null)
        {
            return(TryCatch_Trace(MethodBase.GetCurrentMethod(),
                                  () =>
            {
                var config = new FetchConfig();
                configAction?.Invoke(config);

                Fetch(queueName, callback, config);
            }));
        }
Beispiel #5
0
        public async Task <FetchResponse> Fetch(string url, FetchConfig config = null)
        {
            config = config ?? new FetchConfig();
            var isBinary = false;

            if (config.Headers == null || !config.Headers.TryGetValue("accept", out string acceptHeader))
            {
                acceptHeader = "";
            }

            var    additionalScripts = "";
            var    initialResultConversionFunction = "";
            var    bodyConversion = "body";
            string responseParsing;

            if (acceptHeader.Contains("application/json"))
            {
                initialResultConversionFunction = "json";
            }
            else if (acceptHeader.Contains("application/octet-stream") || acceptHeader.Contains("image/"))
            {
                isBinary = true;
                initialResultConversionFunction = "arrayBuffer";
                bodyConversion = "btoa(new Uint8Array(body).reduce((data,byte)=>(data.push(String.fromCharCode(byte)),data),[]).join(''))";
//				responseParsing = $@".then(response => response.arrayBuffer())
//.then(response => btoa(new Uint8Array(response).reduce((data,byte)=>(data.push(String.fromCharCode(byte)),data),[]).join('')))";
            }
            else
            {
                initialResultConversionFunction = "text";
            }

            responseParsing = $@".then(res => res.{initialResultConversionFunction}().then(body => ({{
headers: Array.from(res.headers.entries()), 
status: res.status, 
body: {bodyConversion}
}})))
";

            var body = config.Body == null ? null : JsonConvert.SerializeObject(config.Body);

            string NullOrQuoted(string str) => str == null ? "null" : $"'{str}'";

            var script = $@"{additionalScripts}
fetch('{url}',
{{ 
	method: '{config.Method}',
	mode: '{config.Mode}',
	headers: {{ {(config.Headers == null ? "" : string.Join(", ", config.Headers.Select(item => $"'{item.Key}': '{item.Value}'")))} }},
Beispiel #6
0
 public Zen3()
 {
     monitoringConfigs     = new MonitoringConfig[12];
     monitoringConfigs[0]  = new BpuMonitoringConfig(this);
     monitoringConfigs[1]  = new FetchConfig(this);
     monitoringConfigs[2]  = new DCFillConfig(this);
     monitoringConfigs[3]  = new HwPrefetchConfig(this);
     monitoringConfigs[4]  = new SwPrefetchConfig(this);
     monitoringConfigs[5]  = new FlopsConfig(this);
     monitoringConfigs[6]  = new LocksConfig(this);
     monitoringConfigs[7]  = new DispatchStallConfig(this);
     monitoringConfigs[8]  = new DispatchStallConfig1(this);
     monitoringConfigs[9]  = new L2Config(this);
     monitoringConfigs[10] = new TopDown(this);
     monitoringConfigs[11] = new PmcMonitoringConfig(this);
     architectureName      = "Zen 3";
 }
Beispiel #7
0
        public async Task <object> GetMedia(Guid hash, string tag)
        {
            var headers = GetHeaders(new Dictionary <string, string> {
                { "accept", "image/webp,image/apng,image/*,*/*;q=0.8" },
                { "accept-encoding", "gzip, deflate, br" },
                { "cache-control", "no-cache" }
            });
            var config = new FetchConfig
            {
                Method         = MethodMode.Get,
                Mode           = CorsMode.Cors,
                Headers        = headers,
                Credentials    = CredentialsMode.Include,
                ReferrerPolicy = ReferrerPolicyMode.NoReferrerWhenDowngrade
            };

            return(await fetcher.DownloadFile(baseAddress + $"Rest/MediaService/image/{hash}/png/pages/1?tag={tag}",
                                              config, $"{hash}.png"));
        }
Beispiel #8
0
        private static string Fetch_exec(FetchConfig fc)
        {
            string address;

            if (GetDNSResult(fc.host, out string ip))
            {
                address = fc.prot + ip + fc.path;
            }
            else
            {
                address = fc.prot + fc.host + fc.path;
            }

            var request = (HttpWebRequest)WebRequest.Create(address);

            request.Timeout   = 4000;
            request.Host      = fc.host;
            request.UserAgent = "DMPlugin_DGJ/" + (BuildInfo.Appveyor ? BuildInfo.Version : "local") + " RoomId/" + RoomId.ToString();
            if (fc.referer != null)
            {
                request.Referer = fc.referer;
            }
            if (fc.cookie != null)
            {
                request.Headers.Add("Cookie", fc.cookie);
            }
            if (fc.data != null)
            {
                var postData = Encoding.UTF8.GetBytes(fc.data);
                request.Method        = "POST";
                request.ContentType   = "application/x-www-form-urlencoded";
                request.ContentLength = postData.Length;
                using (var stream = request.GetRequestStream())
                {
                    stream.Write(postData, 0, postData.Length);
                }
            }
            var response       = (HttpWebResponse)request.GetResponse();
            var stm            = fc.gzip ? new GZipStream(response.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress) : response.GetResponseStream();
            var responseString = new StreamReader(stm, Encoding.UTF8).ReadToEnd();

            return(responseString);
        }
Beispiel #9
0
        protected override List <SongInfo> GetPlaylist(string id)
        {
            try
            {
                FetchConfig fc = new FetchConfig
                {
                    prot    = "http://",
                    host    = "m.kugou.com",
                    path    = $"/plist/list/{id}?json=true",
                    referer = $"http://m.kugou.com/plist/list/{id}",
                    cookie  = COOKIES
                };
                var response = Fetch(fc);

                var json = JObject.Parse(response);
                return((json.SelectToken("list.list.info") as JArray)?.Select(song =>
                {
                    SongInfo songInfo;
                    try
                    {
                        string[] filename = song["filename"].ToString().Split(new char[3] {
                            ' ', '-', ' '
                        });
                        songInfo = new SongInfo(
                            this,
                            song["hash"].ToString(),
                            filename[0],
                            filename[1].Split('\u3001')
                            );
                        songInfo.SetInfo("albumid", song["album_id"].ToString());
                    }
                    catch (Exception ex)
                    { Log($"歌曲信息获取结果错误(ex:{ex.Message})"); return null; }

                    return songInfo;
                }).ToList());
            }
            catch (Exception ex)
            {
                Log($"歌单下载错误(ex:{ex.Message})");
                return(null);
            }
        }
        public BasePackFetchConnection(IPackTransport packTransport)
            : base(packTransport)
        {
            FetchConfig cfg = local.Config.get(FetchConfig.KEY);

            _includeTags   = transport.TagOpt != TagOpt.NO_TAGS;
            _thinPack      = transport.FetchThin;
            _allowOfsDelta = cfg.AllowOfsDelta;

            _walk             = new RevWalk.RevWalk(local);
            _reachableCommits = new RevCommitList <RevCommit>();
            REACHABLE         = _walk.newFlag("REACHABLE");
            COMMON            = _walk.newFlag("COMMON");
            ADVERTISED        = _walk.newFlag("ADVERTISED");

            _walk.carry(COMMON);
            _walk.carry(REACHABLE);
            _walk.carry(ADVERTISED);
        }
Beispiel #11
0
        protected static string Fetch(FetchConfig fc)
        {
            for (int retryCount = 0; retryCount < 4; retryCount++)
            {
                try
                {
                    return(Fetch_exec(fc));
                }
                catch (WebException)
                {
                    if (retryCount >= 3)
                    {
                        throw;
                    }

                    continue;
                }
            }

            return(null);
        }
Beispiel #12
0
        protected override List <SongInfo> GetPlaylist(string id)
        {
            try
            {
                FetchConfig fc = new FetchConfig
                {
                    host    = API_HOST,
                    path    = API_PATH + $"/music-service-c/web/song/of-menu?pn=1&ps=100&sid={id}",
                    referer = API_PROTOCOL + API_HOST + API_PATH,
                    gzip    = true
                };
                var json = JObject.Parse(Fetch(fc));
                return((json.SelectToken("data.data") as JArray)?.Select(song =>
                {
                    SongInfo songInfo;
                    try
                    {
                        songInfo = new SongInfo(
                            this,
                            song["id"].ToString(),
                            song["title"].ToString(),
                            song["author"].ToString().Split(new char[3] {
                            ' ', '·', ' '
                        })
                            );
                        songInfo.SetInfo("referer", API_PROTOCOL + API_HOST + API_PATH);
                    }
                    catch (Exception ex)
                    { Log($"歌曲信息获取结果错误(ex:{ex.Message})"); return null; }

                    return songInfo;
                }).ToList());
            }
            catch (Exception ex)
            {
                Log($"歌单下载错误(ex:{ex.Message})");
                return(null);
            }
        }
Beispiel #13
0
 protected override string GetDownloadUrl(SongItem songItem)
 {
     try
     {
         FetchConfig fc = new FetchConfig
         {
             host    = "wwwapi.kugou.com",
             path    = API_PATH + $"/index.php?r=play/getdata&hash={songItem.SongId}&album_id={songItem.GetInfo("albumid")}",
             referer = "https://www.kugou.com/",
             cookie  = COOKIES
         };
         string  resualt  = Fetch(fc);
         JObject dlurlobj = JObject.Parse(resualt);
         string  url      = dlurlobj.SelectToken("data.play_url")?.ToString();
         return(url);
     }
     catch (Exception ex)
     {
         Log($"歌曲不能下载:{songItem.SongName}(ex:{ex.Message})");
         return(null);
     }
 }
Beispiel #14
0
        public async Task <byte[]> GetPdf(Guid hash, long docId)
        {
            var headers = GetHeaders(new Dictionary <string, string> {
                { "accept", "application/pdf,*/*" },
                { "accept-encoding", "gzip, deflate, br" },
                { "cache-control", "no-cache" }
            });
            var config = new FetchConfig
            {
                Method         = MethodMode.Get,
                Mode           = CorsMode.Cors,
                Headers        = headers,
                Credentials    = CredentialsMode.Include,
                ReferrerPolicy = ReferrerPolicyMode.NoReferrerWhenDowngrade
            };

            var response = await fetcher.Fetch(
                baseAddress + $"Rest/MediaService/image/{hash}/pdf?docId={docId}&docType=Medius.ExpenseInvoice.Entities.ExpenseInvoice&tag=DocumentImage&download=application/pdf;base64",
                config);

            return((byte[])response.Body);
        }
Beispiel #15
0
        protected override string GetDownloadUrl(SongItem songItem)
        {
            try
            {
                FetchConfig fc = new FetchConfig
                {
                    host    = API_HOST,
                    path    = API_PATH + $"/music-service-c/web/url?sid={songItem.SongId}",
                    referer = API_PROTOCOL + API_HOST + API_PATH,
                    gzip    = true
                };
                string resualt = Fetch(fc);

                JObject dlurlobj = JObject.Parse(resualt);
                string  url      = dlurlobj.SelectToken("data.cdns[0]")?.ToString();
                return(url);
            }
            catch (Exception ex)
            {
                Log($"歌曲不能下载:{songItem.SongName}(ex:{ex.Message})");
                return(null);
            }
        }
Beispiel #16
0
        protected override string GetLyric(SongInfo songInfo)
        {
            try
            {
                FetchConfig fc = new FetchConfig
                {
                    host    = API_HOST,
                    path    = API_PATH + $"/index.php?r=play/getdata&hash={songInfo.Id}&album_id={songInfo.GetInfo("albumid")}",
                    referer = "https://www.kugou.com/",
                    cookie  = COOKIES
                };
                var response = Fetch(fc);

                var json  = JObject.Parse(response);
                var lyric = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(json.SelectToken("data.lyrics")?.ToString()));
                return(lyric);
            }
            catch (Exception ex)
            {
                Log($"歌词下载错误:{songInfo.Name}(ex:{ex.Message})");
                return(null);
            }
        }
Beispiel #17
0
        /// <summary>
        /// Fetches the specified queue name.
        /// </summary>
        /// <param name="queueName">Name of the queue.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="config">The configuration.</param>
        /// <returns></returns>
        public virtual IFluentRabbit Fetch(string queueName, Action <BasicGetResult> callback, FetchConfig config)
        {
            return(TryCatch_Trace(MethodBase.GetCurrentMethod(),
                                  () =>
            {
                //validation
                config.ThrowExceptionIfNull <ArgumentNullException>(nameof(config));
                RabbitMqClient.Model.ThrowExceptionIfNull <ModelIsNullException>();

                //execution
                var result = RabbitMqClient.Model.BasicGet(queueName, config.AutoAck);

                callback?.Invoke(result);
            }));
        }
 protected void GivenFetchConfig(FetchConfig fetchConfig)
 {
     ConfigOptions.FetchConfig = fetchConfig;
 }