Beispiel #1
0
        private void GetUrls_Loop(int pid, List <BaseItem> bis)
        {
            try
            {
                var jfp = JsonConvert.DeserializeObject <JsonData_Fantia_Post>(GetWebCode($"https://fantia.jp/api/v1/posts/{pid}"));
                if (null != jfp.post)
                {
                    FantiaItem fi = new FantiaItem()
                    {
                        FID   = jfp.post.id.ToString(),
                        Title = GlobalMethord.RemoveAllDot(GlobalMethord.ReplacePath(jfp.post.title)),
                    };
                    GlobalData.VM_MA.PostTitle = fi.Title;
                    if (DateTime.TryParse(jfp.post.posted_at, out DateTime dt))
                    {
                        fi.CreateDate = dt;
                    }
                    if (DateTime.TryParse(jfp.post.converted_at, out dt))
                    {
                        fi.UpdateDate = dt;
                    }

                    if (!string.IsNullOrEmpty(jfp.post.comment))
                    {
                        fi.Comments.Add(jfp.post.comment);
                        fi.Comments.Add(string.Empty);
                    }
                    if (null != jfp.post.thumb)
                    {
                        fi.CoverPic      = jfp.post.thumb.original;
                        fi.CoverPicThumb = jfp.post.thumb.ogp;
                    }
                    if (DateTime.TryParse(jfp.post.deadline, out dt))
                    {
                        fi.DeadDate = dt.ToString("yyyy/MM/dd HH:mm:ss");
                    }
                    else
                    {
                        fi.DeadDate = "---";
                    }

                    var contents = jfp.post.post_contents;
                    foreach (var ct in contents)
                    {
                        var fee = 0;
                        if (null != ct.plan)
                        {
                            fee = ct.plan.price;
                        }
                        var stitle = $"${fee}_{GlobalMethord.RemoveAllDot(GlobalMethord.ReplacePath(ct.title))}";
                        fi.Comments.Add("------------------------------------------------------------------------------------------");
                        fi.Comments.Add(stitle);
                        fi.Comments.Add(string.Empty);
                        if (ct.visible_status == "visible")
                        {
                            if (!string.IsNullOrEmpty(ct.comment))
                            {
                                fi.Comments.Add(ct.comment);
                                fi.Comments.Add(string.Empty);
                            }
                            if (ct.category == "photo_gallery")
                            {
                                var imgs = ct.post_content_photos;
                                foreach (var img in imgs)
                                {
                                    var imgUrl = img.url.original;

                                    if (!string.IsNullOrEmpty(img.comment))
                                    {
                                        fi.Comments.Add(img.comment);
                                    }
                                    var ffn = imgUrl.Substring(0, imgUrl.IndexOf("?Key"));
                                    var ext = ffn.Substring(ffn.LastIndexOf('.'));
                                    var fn  = $"{img.id}{ext}";
                                    fi.Comments.Add($"<{GlobalLanguage.Text_ImagePref} {fn}>");
                                    fi.FileNames.Add(fn);
                                    fi.ContentUrls.Add(imgUrl);
                                    fi.Fees.Add($"{fee}");
                                    fi.PTitles.Add(stitle);
                                }
                            }
                            else if (ct.category == "file")
                            {
                                fi.Comments.Add($"<{GlobalLanguage.Text_FilePref} {ct.filename}>");
                                fi.FileNames.Add(ct.filename);
                                fi.ContentUrls.Add($"https://fantia.jp{ct.download_uri}");
                                fi.Fees.Add($"{fee}");
                                fi.PTitles.Add(stitle);
                            }
                        }
                    }
                    bis.Add(fi);
                    GlobalData.VM_MA.PostCount++;
                    if (null != jfp.post.links && null != jfp.post.links.previous)
                    {
                        if (!DateTime.TryParse(jfp.post.links.previous.converted_at, out DateTime dtp))
                        {
                            if (!DateTime.TryParse(jfp.post.links.previous.posted_at, out dtp))
                            {
                                GetUrls_Loop(jfp.post.links.previous.id, bis);
                                return;
                            }
                        }
                        if (!GlobalMethord.OverTime(dtp))
                        {
                            GetUrls_Loop(jfp.post.links.previous.id, bis);
                        }
                    }
                }
            }
            catch
            {
                throw;
            }
        }
        public async override Task <ResultMessage> GetPostIDs(string uid)
        {
            try
            {
                string          ss  = ChangeUnicode(await GetAPI(string.Format(_postUrl, uid)));
                List <BaseItem> pis = new List <BaseItem>();
                while (true)
                {
                    var jpp = JsonConvert.DeserializeObject <JsonData_Patreon_Post>(ss);
                    if (null != jpp.data && null != jpp.included && null != jpp.meta)
                    {
                        var incll = jpp.included.ToList();
                        for (int i = 0; i < jpp.data.Length; i++)
                        {
                            if (DateTime.TryParse(jpp.data[i].attributes.published_at, out DateTime dt))
                            {
                                if (GlobalMethord.OverTime(dt))
                                {
                                    return(ResultHelper.NoError(pis));
                                }
                            }

                            PatreonItem pi = new PatreonItem()
                            {
                                CreateDate = dt,
                                UpdateDate = dt,
                                PID        = jpp.data[i].id,
                                Title      = GlobalMethord.RemoveAllDot(GlobalMethord.ReplacePath(jpp.data[i].attributes.title)),
                                IsLiked    = jpp.data[i].attributes.current_user_has_liked,
                                PLink      = jpp.data[i].attributes.url
                            };
                            GlobalData.VM_MA.PostTitle = pi.Title;
                            if (!string.IsNullOrEmpty(jpp.data[i].attributes.content))
                            {
                                pi.Comments.Add(_htmlImg.Replace(jpp.data[i].attributes.content, ""));
                            }
                            else if (!string.IsNullOrEmpty(jpp.data[i].attributes.content_teaser_text))
                            {
                                pi.Comments.Add(jpp.data[i].attributes.content_teaser_text);
                            }
                            if (jpp.data[i].attributes.current_user_can_view)
                            {
                                if (null != jpp.data[i].attributes.image)
                                {
                                    pi.CoverPicThumb = jpp.data[i].attributes.image.thumb_url;
                                }
                                if (null != jpp.data[i].attributes.embed)
                                {
                                    pi.Comments.Add($"<{GlobalLanguage.Text_LinkPref} {jpp.data[i].attributes.embed.url} >");
                                }

                                if (null != jpp.data[i].relationships.media)
                                {
                                    for (int j = 0; j < jpp.data[i].relationships.media.data.Length; j++)
                                    {
                                        var inclu = incll.Find(x => x.id == jpp.data[i].relationships.media.data[j].id);
                                        if (string.IsNullOrEmpty(inclu.attributes.file_name))
                                        {
                                            inclu.attributes.file_name = "default.";
                                            if (!string.IsNullOrEmpty(inclu.attributes.mimetype))
                                            {
                                                var tep = inclu.attributes.mimetype.Split('/');
                                                if (tep.Length == 2)
                                                {
                                                    inclu.attributes.file_name += tep[1];
                                                }
                                                else
                                                {
                                                    inclu.attributes.file_name += inclu.attributes.mimetype;
                                                }
                                            }
                                            else
                                            {
                                                inclu.attributes.file_name += "png";
                                            }
                                        }
                                        else if (inclu.attributes.file_name.StartsWith("https://"))
                                        {
                                            continue;
                                        }
                                        else if (inclu.attributes.file_name.Equals("jpg") || inclu.attributes.file_name.Equals("png"))
                                        {
                                            inclu.attributes.file_name = $"{inclu.id}.{inclu.attributes.file_name}";
                                        }
                                        pi.ContentUrls.Add(inclu.attributes.download_url);
                                        pi.FileNames.Add(inclu.attributes.file_name);
                                        pi.Comments.Add($"<{GlobalLanguage.Text_FilePref} {inclu.attributes.file_name}>");
                                    }
                                }
                            }
                            pis.Add(pi);
                            GlobalData.VM_MA.PostCount++;
                        }
                        if (null != jpp.meta.pagination.cursors)
                        {
                            ss = ChangeUnicode(await GetAPI(string.Format(_nextUrl, uid, jpp.meta.pagination.cursors.next)));
                            continue;
                        }
                        return(ResultHelper.NoError(pis));
                    }
                    return(ResultHelper.IOError());
                }
            }
            catch (Exception ex)
            {
                GlobalMethord.ErrorLog(ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + "-----------------------------------------------");
                return(ResultHelper.UnKnownError());
            }
        }
Beispiel #3
0
        public FantiaItem GetUrls(string pid)
        {
            try
            {
                var jfp = JsonConvert.DeserializeObject <JsonData_Fantia_Post>(GetWebCode($"https://fantia.jp/api/v1/posts/{pid}"));
                if (null != jfp.post)
                {
                    FantiaItem fi = new FantiaItem();
                    if (DateTime.TryParse(jfp.post.posted_at, out DateTime dt))
                    {
                        fi.CreateDate = dt;
                    }
                    if (DateTime.TryParse(jfp.post.converted_at, out dt))
                    {
                        fi.UpdateDate = dt;
                    }

                    fi.FID   = jfp.post.id.ToString();
                    fi.Title = GlobalMethord.RemoveAllDot(GlobalMethord.ReplacePath(jfp.post.title));
                    GlobalData.VM_MA.PostTitle = fi.Title;
                    if (!string.IsNullOrEmpty(jfp.post.comment))
                    {
                        fi.Comments.Add(jfp.post.comment);
                        fi.Comments.Add(string.Empty);
                    }
                    if (null != jfp.post.thumb)
                    {
                        fi.CoverPic      = jfp.post.thumb.original;
                        fi.CoverPicThumb = jfp.post.thumb.ogp;
                    }
                    if (DateTime.TryParse(jfp.post.deadline, out dt))
                    {
                        fi.DeadDate = dt.ToString("yyyy/MM/dd HH:mm:ss");
                    }
                    else
                    {
                        fi.DeadDate = "---";
                    }

                    foreach (var ct in jfp.post.post_contents)
                    {
                        var fee = 0;
                        if (null != ct.plan)
                        {
                            fee = ct.plan.price;
                        }
                        var stitle = $"${fee}_{GlobalMethord.RemoveAllDot(GlobalMethord.ReplacePath(ct.title))}";
                        fi.Comments.Add("------------------------------------------------------------------------------------------");
                        fi.Comments.Add(stitle);
                        fi.Comments.Add(string.Empty);
                        if (ct.visible_status == "visible")
                        {
                            if (ct.category != "blog" && !string.IsNullOrEmpty(ct.comment))
                            {
                                fi.Comments.Add(ct.comment);
                                fi.Comments.Add(string.Empty);
                            }
                            if (ct.category == "photo_gallery")
                            {
                                var imgs = ct.post_content_photos;
                                foreach (var img in imgs)
                                {
                                    var imgUrl = img.url.original;
                                    if (!string.IsNullOrEmpty(img.comment))
                                    {
                                        fi.Comments.Add(img.comment);
                                    }
                                    var ffn = imgUrl.Substring(0, imgUrl.IndexOf("?Key"));
                                    var ext = ffn.Substring(ffn.LastIndexOf('.'));
                                    var fn  = $"{img.id}{ext}";
                                    fi.Comments.Add($"<{GlobalLanguage.Text_ImagePref} {fn}>");
                                    fi.FileNames.Add(fn);
                                    fi.ContentUrls.Add(imgUrl);
                                    fi.Fees.Add($"{fee}");
                                    fi.PTitles.Add(stitle);
                                }
                            }
                            else if (ct.category == "file")
                            {
                                fi.Comments.Add($"<{GlobalLanguage.Text_FilePref} {ct.filename}>");
                                fi.FileNames.Add(ct.filename);
                                fi.ContentUrls.Add($"https://fantia.jp{ct.download_uri}");
                                fi.Fees.Add($"{fee}");
                                fi.PTitles.Add(stitle);
                            }
                            else if (ct.category == "blog")
                            {
                                try
                                {
                                    JObject dd = JsonConvert.DeserializeObject(ct.comment) as JObject;
                                    JArray  ja = JArray.Parse(dd["ops"].ToString());

                                    foreach (var js in ja)
                                    {
                                        var     ss   = js.SelectToken("insert");
                                        dynamic stem = ss;
                                        if (ss.Type == JTokenType.String)
                                        {
                                            fi.Comments.Add(stem.Value.Replace("\\n", Environment.NewLine));
                                        }
                                        else if (ss.Type == JTokenType.Object)
                                        {
                                            string imgUrl = stem.fantiaImage.url;
                                            var    ffn    = imgUrl.Substring(0, imgUrl.IndexOf("?Key"));
                                            var    ext    = ffn.Substring(ffn.LastIndexOf('.'));
                                            var    fn     = $"{stem.fantiaImage.id}{ext}";
                                            fi.Comments.Add($"<{GlobalLanguage.Text_ImagePref} {fn}>");
                                            fi.FileNames.Add(fn);
                                            fi.ContentUrls.Add($"https://fantia.jp{stem.fantiaImage.original_url}");
                                            fi.Fees.Add($"{fee}");
                                            fi.PTitles.Add(stitle);
                                        }
                                        else
                                        {
                                            throw new Exception("Blog type unknown: " + ss.Type.ToString());
                                        }
                                    }
                                }
                                catch
                                {
                                    throw;
                                }
                            }
                        }
                    }
                    return(fi);
                }
                return(null);
            }
            catch
            {
                throw;
            }
        }
Beispiel #4
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.RemoveAllDot(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);
        }