aboutsummaryrefslogtreecommitdiff
path: root/pl/local_episodes.pl
blob: 5eaf6b7f72635ac215a7647b667dcae67240c3fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
:- 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).

local_episode_prefix --> string(_), "Detective_Conan_-_".
local_episode_prefix --> string(_), "Detective Conan - ".
local_episode_prefix --> string(_), "Detective-Conan-".
local_episode_prefix --> string(_), "detective_conan_".

local_episode -->
	local_episode(_).
local_episode(N) -->
	local_episode_prefix, integer(N), string(_).
local_episode(N) -->
	local_episode_prefix, integer(First), "-", integer(Last), string(_),
	{ Second is First + 1, between(Second, Last, 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),
	(   nonvar(N)
	->  include(atom_phrase(local_episode(N)), F1, [F|_])
	;   include(atom_phrase(local_episode), F1, F2),
	    member(F, F2),
	    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).

open_episode(N) :- episode_file(N, F), !, win_shell(open, F).
open_episode(N) :- atom_phrase(episode_url(N), U), win_shell(open, U).