aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--c/common.c3
-rw-r--r--c/listview.c1
-rw-r--r--pl/episode_data.pl53
4 files changed, 43 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index f6daea5..85873c0 100644
--- a/Makefile
+++ b/Makefile
@@ -11,7 +11,7 @@ LDFLAGS += -lcomctl32 -luxtheme
ifeq ($(BUILD_MODE),debug)
CFLAGS += -g
else
- CFLAGS += -O2 -ld-options,-mwindows
+ CFLAGS += -O -ld-options,-mwindows
endif
all: EpisodeBrowser.exe
diff --git a/c/common.c b/c/common.c
index 6f7772c..a4ac7d2 100644
--- a/c/common.c
+++ b/c/common.c
@@ -4,8 +4,7 @@
#include "resource.h"
#include "defs.h"
-/* Convert zero-terminated non-wide (multi-byte) string to
- * zero-terminated wide/non-wide string depending on UNICODE. */
+/* Convert normal string to TSTR using given codepage. */
TCHAR *
TszFromSz(const char *sz, int iCp)
{
diff --git a/c/listview.c b/c/listview.c
index 40c3108..971c4e9 100644
--- a/c/listview.c
+++ b/c/listview.c
@@ -70,6 +70,7 @@ LvProc(HWND hLv, UINT uMsg, WPARAM wParam, LPARAM lParam)
return CallWindowProc(LvPrevProc, hLv, uMsg, wParam, lParam);
}
+/* Enable/disable non-classic list view theme. */
void
LvSetTheme(HWND hLv, int bUseTheme)
{
diff --git a/pl/episode_data.pl b/pl/episode_data.pl
index a1b3a25..c6a5f3a 100644
--- a/pl/episode_data.pl
+++ b/pl/episode_data.pl
@@ -19,37 +19,64 @@ attach :-
detach :-
db_detach.
+% Interface.
+
+lookup_episode(Ep, Name, Data) :- lookup_episode_local(Ep, Name, Data), !.
+lookup_episode(Ep, Name, Data) :- lookup_episode_remote(Ep, Name, Data).
+
+lookup_episode_local(Ep, Name, Data) :-
+ episode_name_data(Ep, Name, Data).
+lookup_episode_remote(Ep, Name, Data) :-
+ update, !,
+ episode_name_data(Ep, Name, Data).
+
+
retract_episode(Ep) :-
( episode_name_data(Ep, _, _)
-> retractall_episode_name_data(Ep, _, _)
; true
).
+% Parsing.
+
padding(Ep) --> { Ep < 10 }, "00".
padding(Ep) --> { Ep >= 10, Ep < 100 }, "0".
padding(Ep) --> { Ep >= 100 }.
episode_number(Ep) --> padding(Ep), integer(Ep).
-lookup_episode(Ep, Name, Data) :- lookup_episode_local(Ep, Name, Data), !.
-lookup_episode(Ep, Name, Data) :- lookup_episode_remote(Ep, Name, Data).
+% Database updating.
-lookup_episode_local(Ep, Name, Data) :-
- episode_name_data(Ep, Name, Data).
+update :-
+ remote(R0), !,
+ findall(Ep-Name-Data, (xpath(R0, //tr, R),
+ remote_episode(R, Ep),
+ remote_episode_name_data(R, Ep, Name, Data)),
+ ENDs), !,
+ maplist(update, ENDs).
-lookup_episode_remote(Ep, Name, Data) :-
+update(Ep-Name-Data) :- episode_name_data(Ep, Name, Data), !.
+update(Ep-Name-Data) :- assert_episode_name_data(Ep, Name, Data).
+
+% Remote retrieval.
+
+remote(R) :-
catch(http_load_html(
'https://www.detectiveconanworld.com/wiki/Next_Conan%27s_Hint',
- D),
+ R),
_,
- fail),
- xpath(D, //tr, D1),
- xpath(D1, td(index(1),text), T),
+ fail).
+
+remote_episode(R, Ep) :-
+ xpath(R, td(index(1),text), T),
+ atom_number(T, Ep).
+
+remote_episode_name_data(R, Ep, Name, Data) :-
+ xpath(R, td(index(1),text), T),
atom_phrase(episode_number(Ep), T),
- xpath(D1, td(index(2),text), Name),
- xpath(D1, td(index(3),text), Hint),
- Data = ['Hint'(Hint)],
- assert_episode_name_data(Ep, Name, Data).
+ xpath(R, td(index(2),text), Name),
+ xpath(R, td(index(3),text), Hint),
+ Data = ['Hint'(Hint)].
http_load_html(URL, DOM) :-
setup_call_cleanup(http_open(URL, In,