Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Goodtv 성경소스 추가 #19

Merged
merged 2 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Bible2PPT/Bible2PPT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Compile Include="Bibles\Sources\GodpeopleBible.cs" />
<Compile Include="Bibles\Sources\GodpiaBible.cs" />
<Compile Include="Bibles\Sources\BibleSource.cs" />
<Compile Include="Bibles\Sources\GoodtvBible.cs" />
<Compile Include="BinaryConfig.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
Expand Down
1 change: 1 addition & 0 deletions Bible2PPT/Bibles/Sources/BibleSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ abstract class BibleSource
{
new GodpeopleBible { Id = 0 },
new GodpiaBible { Id = 1 },
new GoodtvBible { Id = 2 },
};

public int Id { get; set; }
Expand Down
85 changes: 85 additions & 0 deletions Bible2PPT/Bibles/Sources/GoodtvBible.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Bible2PPT.Bibles.Sources
{
class GoodtvBible : BibleSource
{
private const string BASE_URL = "http://goodtvbible.goodtv.co.kr";

private BetterWebClient client = new BetterWebClient
{
BaseAddress = BASE_URL,
Encoding = Encoding.UTF8,
};

public GoodtvBible()
{
Name = "GOODTV 성경";
}

protected override List<BibleVersion> GetBiblesOnline()
{
var data = client.DownloadString("/bible.asp");
var matches = Regex.Matches(data, @"bible_check"".+?value=""(\d+)""[\s\S]+?<span.+?>(.+?)<");
return matches.Cast<Match>().Select(i => new BibleVersion
{
OnlineId = i.Groups[1].Value,
Name = i.Groups[2].Value,
}).ToList();
}

protected override List<BibleBook> GetBooksOnline(BibleVersion bible)
{
var oldData = client.UploadValues("/bible_otnt_exc.asp", new System.Collections.Specialized.NameValueCollection
{
{ "bible_idx", "1" },
{ "otnt", "1" },
});
var newData = client.UploadValues("/bible_otnt_exc.asp", new System.Collections.Specialized.NameValueCollection
{
{ "bible_idx", "1" },
{ "otnt", "2" },
});
var data = Encoding.UTF8.GetString(oldData) + Encoding.UTF8.GetString(newData);
var matches = Regex.Matches(data, @"""idx"":(\d+).+?""bible_name"":""(.+?)"".+?""max_jang"":(\d+)");
return matches.Cast<Match>().Select(i => new BibleBook
{
OnlineId = i.Groups[1].Value,
Title = i.Groups[2].Value,
ChapterCount = int.Parse(i.Groups[3].Value),
}).ToList();
}

protected override List<BibleChapter> GetChaptersOnline(BibleBook book) =>
Enumerable.Range(1, book.ChapterCount)
.Select(i => new BibleChapter
{
Number = i,
}).ToList();
private static string StripHtmlTags(string s) => Regex.Replace(s, @"<.+?>", "", RegexOptions.Singleline);

protected override List<BibleVerse> GetVersesOnline(BibleChapter chapter)
{
var data = Encoding.UTF8.GetString(client.UploadValues("/bible.asp", new System.Collections.Specialized.NameValueCollection
{
{ "bible_idx", chapter.Book.OnlineId },
{ "jang_idx", chapter.Number.ToString() },
{ "bible_version_1", chapter.Book.Bible.OnlineId },
{ "bible_version_2", "0" },
{ "bible_version_3", "0" },
{ "count", "1" },
}));
data = Regex.Match(data, @"<p id=""one_jang""><b>([\s\S]+?)</b></p>").Groups[1].Value;
var matches = Regex.Matches(data, @"<b>(\d+).*?</b>(.*?)<br>");
return matches.Cast<Match>().Select(i => new BibleVerse
{
Number = int.Parse(i.Groups[1].Value),
Text = StripHtmlTags(i.Groups[2].Value),
}).ToList();
}
}
}