Пример #1
0
        private string GetUrls(string jsondata, IList <BaseItem> bis)
        {
            var fd = JsonConvert.DeserializeObject <JsonData_Fanbox_Post>(jsondata);

            if (null != fd.body && null != fd.body.items)
            {
                foreach (var po in fd.body.items)
                {
                    var pi = new FanboxItem()
                    {
                        PID           = po.id,
                        Fee           = po.feeRequired.ToString(),
                        Title         = GlobalMethord.RemoveLastDot(GlobalMethord.ReplacePath(po.title)),
                        CoverPic      = po.coverImageUrl,
                        CoverPicThumb = po.coverImageUrl,
                        IsLiked       = po.isLiked
                    };
                    GlobalData.VM_MA.PostTitle = pi.Title;
                    if (DateTime.TryParse(po.publishedDatetime, out DateTime dt))
                    {
                        pi.CreateDate = dt;
                    }
                    if (DateTime.TryParse(po.updatedDatetime, out dt))
                    {
                        pi.UpdateDate = dt;
                    }
                    if (GlobalMethord.OverPayment(int.Parse(pi.Fee)) || GlobalMethord.OverTime(pi.UpdateDate))
                    {
                        pi.Skip = true;
                    }

                    if (null != po.body)
                    {
                        switch (po.type)
                        {
                        case "file":
                        {
                            if (!string.IsNullOrEmpty(po.body.text))
                            {
                                pi.Comments.Add(po.body.text);
                                pi.Comments.Add(string.Empty);
                            }
                            foreach (var finfo in po.body.files)
                            {
                                pi.ContentUrls.Add(finfo.url);
                                var fn = $"{finfo.name}.{finfo.extension}";
                                pi.FileNames.Add(fn);
                                pi.Comments.Add($"<{GlobalLanguage.Text_FilePref} {fn} ({GetSize(finfo.size)})>");
                            }
                        }
                        break;

                        case "image":
                        {
                            if (!string.IsNullOrEmpty(po.body.text))
                            {
                                pi.Comments.Add(po.body.text);
                                pi.Comments.Add(string.Empty);
                            }
                            int index = 1;
                            foreach (var iinfo in po.body.images)
                            {
                                pi.MediaUrls.Add(iinfo.originalUrl);
                                var fn = $"{index++}.{iinfo.extension}";
                                pi.MediaNames.Add(fn);
                                pi.Comments.Add($"<{GlobalLanguage.Text_ImagePref} {fn} ({iinfo.width}x{iinfo.height}px)>");
                            }
                        }
                        break;

                        case "article":
                        {
                            int index_pic = 1;
                            foreach (var binfo in po.body.blocks)
                            {
                                switch (binfo.type)
                                {
                                case "p":
                                    pi.Comments.Add(binfo.text);
                                    break;

                                case "file":
                                    if (null != po.body.fileMap && po.body.fileMap.TryGetValue(binfo.fileId, out FileItem fitem))
                                    {
                                        pi.ContentUrls.Add(fitem.url);
                                        var fn = $"{fitem.name}.{fitem.extension}";
                                        pi.FileNames.Add(fn);
                                        pi.Comments.Add($"<{GlobalLanguage.Text_FilePref} {fn} ({GetSize(fitem.size)})>");
                                    }
                                    break;

                                case "image":
                                    if (null != po.body.imageMap && po.body.imageMap.TryGetValue(binfo.imageId, out ImageItem iitem))
                                    {
                                        pi.MediaUrls.Add(iitem.originalUrl);
                                        var fn = $"{index_pic++}.{iitem.extension}";
                                        pi.MediaNames.Add(fn);
                                        pi.Comments.Add($"<{GlobalLanguage.Text_ImagePref} {fn} ({iitem.width}x{iitem.height}px)>");
                                    }
                                    break;

                                case "embed":
                                    if (null != po.body.embedMap && po.body.embedMap.TryGetValue(binfo.embedId, out EmbedItem eitem))
                                    {
                                        pi.Comments.Add(string.Empty);
                                        if (eitem.serviceProvider == "twitter" && !string.IsNullOrEmpty(GlobalData.VM_MA.Artist.Twitter))
                                        {
                                            pi.Comments.Add($"<{GlobalLanguage.Text_LinkPref} {GlobalData.VM_MA.Artist.Twitter}/{eitem.contentId} >");
                                        }
                                        else if (eitem.serviceProvider == "fanbox")
                                        {
                                            pi.Comments.Add($"<{GlobalLanguage.Text_LinkPref} {GlobalData.VM_MA.Artist.PostUrl}/posts/{eitem.contentId.Split('/').Last()} >");
                                        }
                                        else
                                        {
                                            pi.Comments.Add($"<{GlobalLanguage.Text_LinkPref} {eitem.serviceProvider} ({eitem.contentId})>");
                                        }
                                        pi.Comments.Add(string.Empty);
                                    }
                                    break;
                                }
                            }
                        }
                        break;

                        case "text":
                        {
                            if (!string.IsNullOrEmpty(po.body.text))
                            {
                                pi.Comments.Add(po.body.text);
                            }
                        }
                        break;
                        }
                    }
                    bis.Add(pi);
                    GlobalData.VM_MA.PostCount++;
                }
                return(fd.body.nextUrl ?? null);
            }
            return(null);
        }