Skip to content

Commit

Permalink
Merge pull request #17 from TowarzyszFatCat/skip-feature
Browse files Browse the repository at this point in the history
Skip feature
  • Loading branch information
TowarzyszFatCat authored Oct 18, 2024
2 parents 4169046 + a5ce4af commit b90a739
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 27 deletions.
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ CLI do oglądania anime z <a href="https://docchi.pl/">docchi.pl</a>
</h1>

<h2 align="center">
[ UPDATE v2.9 ]
[ UPDATE v2.10 ]

Dodano funkcję automatycznego pomijania intr i outr w ustawieniach!

Dodano wsparcie mega.nz!
</h2>

---
Expand All @@ -26,19 +27,21 @@ Dodano wsparcie mega.nz!
<tr>
<td>

- Lista anime do obejrzenia
- Historia oglądania
- Funkcja następny/poprzedni odcinek
- Szybka wyszukiwarka
- Wznawianie oglądania
- Możliwość ustawienia własnego statusu na discordzie
- Statystyki
- Podgląd okładki
- Lista anime do obejrzenia,
- Historia oglądania,
- Funkcja następny/poprzedni odcinek,
- Szybka wyszukiwarka,
- Wznawianie oglądania,
- Możliwość ustawienia własnego statusu na discordzie,
- Statystyki,
- Podgląd okładki,
- Pomijanie intr/outr.

</td>
<td>

- Wsparcie większej ilości źródeł
- Wsparcie większej ilości źródeł,
- Wyświetlanie markerów intr i outr w odtwarzaczu.

</td>
</tr>
Expand Down Expand Up @@ -121,5 +124,5 @@ doccli

---

### Using mpv player: <a href="https://github.com/mpv-player/mpv">mpv</a>
### Using: <a href="https://github.com/mpv-player/mpv">mpv</a>, <a href="https://api.aniskip.com/api-docs">aniskip-api</a>
### Inspired by: <a href="https://github.com/pystardust/ani-cli">ani-cli</a>
29 changes: 27 additions & 2 deletions api_connector.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from requests import get


### DOCCHI
### DOCCHI API

# Get list of players for episode
def get_players_list(SLUG, NUMBER):
Expand Down Expand Up @@ -45,4 +45,29 @@ def get_details_for_serie(SLUG):
if request.status_code == 200:
return request.json()
else:
return request.status_code
return request.status_code


### AniSkip API
def get_skip_times(MALID, EP):
# OPS OPE ENS ENE
skip_times = [-1, -1, -1, -1]

request = get(f'https://api.aniskip.com/v2/skip-times/{MALID}/{EP}?types=op&types=ed&types=mixed-op&types=mixed-ed&types=recap&episodeLength=0')
if request.status_code == 200:
ans = request.json()

if ans['found'] == True:
for i in ans['results']:
# Handle openings
if i['skipType'] == 'op':
times = i['interval']
skip_times[0] = times['startTime']
skip_times[1] = times['endTime']
# Handle endings
if i['skipType'] == 'ed':
times = i['interval']
skip_times[2] = times['startTime']
skip_times[3] = times['endTime']

return skip_times
12 changes: 6 additions & 6 deletions doccli-skip.lua → doccli_skip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
local mpv = require('mp')
local mpv_options = require("mp.options")

local options = { opening_start = 0, opening_end = 0, ending_start = 0, ending_end = 0 }
mpv_options.read_options(options, "skip")
local options = { opening_start = -1, opening_end = -1, ending_start = -1, ending_end = -1 }
mpv_options.read_options(options, "doccli_skip")


local function skip()
Expand All @@ -17,12 +17,12 @@ local function skip()
return
end

if current_time >= options.opening_start + 2 and current_time < options.opening_start + 3 then
mp.set_property_number("time-pos", options.opening_end - 2)
if current_time >= options.opening_start + 2 and current_time < options.opening_start + 3 and options.opening_end ~= -1 then
mp.set_property_number("time-pos", options.opening_end - 3)
end

if current_time >= options.ending_start + 2 and current_time < options.ending_start + 3 then
mp.set_property_number("time-pos", options.ending_end)
if current_time >= options.ending_start + 2 and current_time < options.ending_start + 3 and options.ending_end ~= -1 then
mp.set_property_number("time-pos", options.ending_end - 3)
end
end

Expand Down
2 changes: 2 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
sudo chmod +x doccli/doccli
sudo mv doccli/doccli /usr/local/bin

mkdir -p ~/.config/mpv/scripts
sudo mv doccli_skip.lua ~/.config/mpv/scripts
sudo mv doccli ~/.doccli_src

sudo chmod 777 ~/.doccli_src
Expand Down
52 changes: 46 additions & 6 deletions main_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from InquirerPy import inquirer, prompt
import os
from os import system
from api_connector import get_series_list, get_episodes_count_for_serie, get_players_list, get_details_for_serie
from api_connector import get_series_list, get_episodes_count_for_serie, get_players_list, get_details_for_serie, get_skip_times
from subprocess import Popen, DEVNULL
from termcolor import colored
import webbrowser
Expand Down Expand Up @@ -106,6 +106,22 @@ def m_welcome():
sys.exit()

def m_settings():
choices = [{
"type": "list",
"message": "Czy chcesz aby openingi i endingi były automatycznie pomijane?",
"choices": ["Tak", "Nie"],
}]

skip = prompt(questions=choices)

if skip[0] == "Tak":
settings[2] = True
save()
elif skip[0] == "Nie":
settings[2] = False
save()


choices = [{
"type": "list",
"message": "Czy chcesz aby znajomi na discordzie widzieli co oglądasz?",
Expand Down Expand Up @@ -394,8 +410,13 @@ def w_players(SLUG, NUMBER, err=''):

ans_index = players[ans_index_in_choices]

process = mpv_play(ans_index[1])
skip_times = [-1, -1, -1, -1]

if settings[2]:
details = get_details_for_serie(SLUG)
skip_times = get_skip_times(details['mal_id'], NUMBER)

process = mpv_play(ans_index[1], SKIP_TIMES=skip_times)


# Wait 3 sec and check if started playing
Expand All @@ -407,7 +428,7 @@ def w_players(SLUG, NUMBER, err=''):
w_default(SLUG, NUMBER, process)


def mpv_play(URL):
def mpv_play(URL, SKIP_TIMES):
if shutil.which('mpv') is None:
print(colored("[BŁĄD]", "red"), colored("Aby program działał wymagana jest instalacja", "white"), colored("mpv", "green"), '\n')
sys.exit()
Expand Down Expand Up @@ -437,14 +458,28 @@ def mpv_play(URL):
video_files = [file for file in new_files if file.lower().endswith(tuple(video_extensions))]

try:
process = Popen(args=['mpv', "--save-position-on-quit", f'/tmp/{video_files[0]}'], shell=False, stdout=DEVNULL, stderr=DEVNULL)
process = Popen(args=['mpv',
"--save-position-on-quit",
"--chapters-file=/tmp/doccli_chapters",
f"--script-opts=doccli_skip-opening_start={SKIP_TIMES[0]},doccli_skip-opening_end={SKIP_TIMES[1]},doccli_skip-ending_start={SKIP_TIMES[2]},doccli_skip-ending_end={SKIP_TIMES[3]}",
f'/tmp/{video_files[0]}'],
shell=False,
stdout=DEVNULL,
stderr=DEVNULL)
return process
except IndexError:
return


else:
process = Popen(args=['mpv', "--save-position-on-quit", URL], shell=False, stdout=DEVNULL, stderr=DEVNULL)
process = Popen(args=['mpv',
"--save-position-on-quit",
"--chapters-file=/tmp/doccli_chapters",
f"--script-opts=doccli_skip-opening_start={SKIP_TIMES[0]},doccli_skip-opening_end={SKIP_TIMES[1]},doccli_skip-ending_start={SKIP_TIMES[2]},doccli_skip-ending_end={SKIP_TIMES[3]}",
URL],
shell=False,
stdout=DEVNULL,
stderr=DEVNULL)
return process


Expand Down Expand Up @@ -528,7 +563,7 @@ def load():
if not os.path.exists(PATH_settings):
with open(PATH_settings, 'w') as file:
global settings
settings = [True, "Używa doccli!"]
settings = [True, "Używa doccli!", True]
json.dump(settings, file, indent=4)
if not os.path.exists(PATH_history):
with open(PATH_history, 'w') as file:
Expand All @@ -547,6 +582,11 @@ def load():
loaded_data = json.load(json_file)
settings = loaded_data

# New update bypass
if len(settings) != 3:
settings.append(True)
save()

with open(PATH_history, 'r') as json_file:
loaded_data = json.load(json_file)
global history
Expand Down
6 changes: 5 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import time

from main_module import m_welcome
from requests import get
from termcolor import colored
import threading
from discord_integration import start_rpc, set_running

VERSION = "v2.9"
from api_connector import get_skip_times

VERSION = "v2.10"

def check_update() -> None:

Expand Down

0 comments on commit b90a739

Please sign in to comment.