Skip to content

Commit

Permalink
Fantia Error
Browse files Browse the repository at this point in the history
ImageUrl use "data:image" in Blog type
  • Loading branch information
EndlessMISAKA committed Feb 27, 2021
1 parent e6d394d commit 54079fd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
3 changes: 2 additions & 1 deletion AtelierMisaka/Global/GlobalEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public enum RegexType
FantiaIdName,
FantiaPlan,
FantiaPostId,
FantiaUrl
FantiaUrl,
FantiaDataImage
}
}
14 changes: 10 additions & 4 deletions AtelierMisaka/Global/GlobalRegex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class GlobalRegex
private static string _regex_FantiaPlan = string.Empty;
private static string _regex_FantiaPostId = string.Empty;
private static string _regex_FantiaUrl = string.Empty;
private static string _regex_FantiaDataImage = string.Empty;

private static Lazy<Regex> _re_RemoveLastDot = null;
private static Lazy<Regex> _re_ProxyString = null;
Expand All @@ -31,7 +32,7 @@ public static void Initialize()
{
Directory.CreateDirectory("Settings");
}
if (File.Exists("Settings\\RegexStr.ini"))
try
{
string[] regexs = File.ReadAllLines("Settings\\RegexStr.ini");
_regex_RemoveLastDot = regexs[0];
Expand All @@ -49,8 +50,9 @@ public static void Initialize()
_regex_FantiaPlan = regexs[9];
_regex_FantiaPostId = regexs[10];
_regex_FantiaUrl = regexs[11];
_regex_FantiaDataImage = regexs[12];
}
else
catch
{
_regex_RemoveLastDot = @"\.+$";
_regex_ProxyString = @"^\d+\.\d+\.\d+\.\d+:\d+$";
Expand All @@ -67,8 +69,9 @@ public static void Initialize()
_regex_FantiaPlan = @"\(((\d+\,)?\d+)円/月\)</strong";
_regex_FantiaPostId = @"block"" href=""/posts/(\d+)";
_regex_FantiaUrl = @"^https://fantia.jp/fanclubs/(\d+)$";
_regex_FantiaDataImage = @"^data:image/(\w+);base64,(.+)$";

File.AppendAllLines("Settings\\RegexStr.ini", new string[]
File.WriteAllLines("Settings\\RegexStr.ini", new string[]
{
_regex_RemoveLastDot,
_regex_ProxyString,
Expand All @@ -84,7 +87,8 @@ public static void Initialize()
_regex_FantiaIdName,
_regex_FantiaPlan,
_regex_FantiaPostId,
_regex_FantiaUrl
_regex_FantiaUrl,
_regex_FantiaDataImage
});
}
_re_RemoveLastDot = new Lazy<Regex>(() => new Regex(_regex_RemoveLastDot));
Expand Down Expand Up @@ -119,6 +123,8 @@ public static Regex GetRegex(RegexType rt)
return new Regex(_regex_FantiaPostId);
case RegexType.FantiaUrl:
return new Regex(_regex_FantiaUrl);
case RegexType.FantiaDataImage:
return new Regex(_regex_FantiaDataImage);
}
return null;
}
Expand Down
27 changes: 23 additions & 4 deletions AtelierMisaka/Utils/FantiaUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class FantiaUtils : BaseUtils
readonly Regex _artPlan = GlobalRegex.GetRegex(RegexType.FantiaPlan);
readonly Regex _artPost = GlobalRegex.GetRegex(RegexType.FantiaPostId);
readonly Regex _artUrl = GlobalRegex.GetRegex(RegexType.FantiaUrl);
readonly Regex _artDataImage = GlobalRegex.GetRegex(RegexType.FantiaDataImage);
readonly string _nextP = "fa fa-angle-right";
private HashSet<string> _pidList = null;

Expand Down Expand Up @@ -235,6 +236,7 @@ private IList<BaseItem> GetPostIDsFromWebCode(string uid, int index = 1)
try
{
var jfp = JsonConvert.DeserializeObject<JsonData_Fantia_Post>(GetWebCode($"https://fantia.jp/api/v1/posts/{pid}"));
//var jfp = JsonConvert.DeserializeObject<JsonData_Fantia_Post>(pid); for test
if (null != jfp.post)
{
FantiaItem fi = new FantiaItem();
Expand Down Expand Up @@ -337,10 +339,27 @@ private IList<BaseItem> GetPostIDsFromWebCode(string uid, int index = 1)
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}>");
string fn = string.Empty;
if (imgUrl.StartsWith("http"))
{
var ffn = imgUrl.Substring(0, imgUrl.IndexOf("?Key"));
var ext = ffn.Substring(ffn.LastIndexOf('.'));
fn = $"{stem.fantiaImage.id}{ext}";
fi.Comments.Add($"<{GlobalLanguage.Text_ImagePref} {fn}>");
}
else
{
Match ma = _artDataImage.Match(imgUrl);
if (ma.Success)
{
fn = $"{stem.fantiaImage.id}.{ma.Groups[1].Value}";
fi.Comments.Add($"<{GlobalLanguage.Text_ImagePref} {fn}>");
}
else
{
throw new Exception("Blog Image Type Error: " + imgUrl);
}
}
fi.FileNames.Add(fn);
fi.ContentUrls.Add($"https://fantia.jp{stem.fantiaImage.original_url}");
fi.Fees.Add($"{fee}");
Expand Down

0 comments on commit 54079fd

Please sign in to comment.