diff options
author | John Ankarström <john@ankarstrom.se> | 2022-04-05 02:37:58 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-04-05 02:37:58 +0200 |
commit | 9a48743eeba0f1bc4cf74f47fef96bdbcadfc98b (patch) | |
tree | f78c6062b2ec931f1c181d7726ee612c332b892b /pl | |
parent | 96f4b3a127e027364c77416f1ee8e5a471c5d783 (diff) | |
download | EpisodeBrowser-9a48743eeba0f1bc4cf74f47fef96bdbcadfc98b.tar.gz |
Move settings to registry.
Diffstat (limited to 'pl')
-rw-r--r-- | pl/cfg.pl | 33 | ||||
-rw-r--r-- | pl/local_episodes.pl | 14 |
2 files changed, 39 insertions, 8 deletions
diff --git a/pl/cfg.pl b/pl/cfg.pl new file mode 100644 index 0000000..f24e44e --- /dev/null +++ b/pl/cfg.pl @@ -0,0 +1,33 @@ +:- module(cfg, [set_glob/1, + get_glob/1, + set_root/1, + get_root/1, + set_url/1, + get_url/1]). + +:- use_module(library(registry)). + +set_key(Key, Value) :- + registry_set_key(current_user/software/'JohnAJ'/'EpisodeBrowser'/'Settings', Key, Value). +get_key(Key, Value) :- + catch(registry_get_key(current_user/software/'JohnAJ'/'EpisodeBrowser'/'Settings', Key, Value), + _, + fail). + +set_root(V) :- set_key('EpisodeRoot', V). +get_root(V) :- + get_key('EpisodeRoot', V0), + re_replace('\\\\', '/', V0, V1), + atom_string(V, V1). + +set_glob(V) :- set_key('EpisodeRoot', V). +get_glob(V) :- + ( get_key('EpisodeRoot', V) + ; V = '*/*.*' + ). + +set_url(V) :- set_key('UrlPrefix', V). +get_url(V) :- + ( get_key('UrlPrefix', V) + ; V = 'https://gogoanime.fi/detective-conan-episode-' + ). diff --git a/pl/local_episodes.pl b/pl/local_episodes.pl index 5eaf6b7..49d930c 100644 --- a/pl/local_episodes.pl +++ b/pl/local_episodes.pl @@ -1,10 +1,10 @@ :- module(local_episodes, [local_episode//1, episode_file/2, - sort_episode_file/2, open_episode/1]). :- use_module(library(dcg/basics)). :- use_module(atom_dcg). +:- use_module(cfg). local_episode_prefix --> string(_), "Detective_Conan_-_". local_episode_prefix --> string(_), "Detective Conan - ". @@ -22,7 +22,10 @@ local_episode(N) --> % Find episode on disk. episode_file(N, F) :- - expand_file_name('C:/Users/John/Nedladdningar/Detective Conan season 1 to season 22 + season 23(incomplete)/*/*.*', F1), + get_root(R), + get_glob(G), + atomic_list_concat([R, '/', G], G1), + expand_file_name(G1, F1), ( nonvar(N) -> include(atom_phrase(local_episode(N)), F1, [F|_]) ; include(atom_phrase(local_episode), F1, F2), @@ -30,13 +33,8 @@ episode_file(N, F) :- atom_phrase(local_episode(N), F) ). -sort_episode_file(N, F) :- - setof(N_-F_, episode_file(N_, F_), S), - member(N-F, S). - % Open episode. -episode_url(N) --> "https://gogoanime.fi/detective-conan-episode-", integer(N). - +episode_url(N) --> { with_codes(get_url(U)) }, string(U), integer(N). open_episode(N) :- episode_file(N, F), !, win_shell(open, F). open_episode(N) :- atom_phrase(episode_url(N), U), win_shell(open, U). |