Skip to content

Commit

Permalink
Merge pull request #19 from sunghwan2789/goodtv
Browse files Browse the repository at this point in the history
Goodtv 성경소스 추가
  • Loading branch information
sunghwan2789 authored Jun 18, 2019
2 parents 41266a9 + 6e85a9d commit 1923bf4
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
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();
}
}
}

0 comments on commit 1923bf4

Please sign in to comment.