diff --git a/anime_downloader/commands/watch.py b/anime_downloader/commands/watch.py index 04fc616..b5e147c 100644 --- a/anime_downloader/commands/watch.py +++ b/anime_downloader/commands/watch.py @@ -10,7 +10,7 @@ import re from anime_downloader import util from anime_downloader.__version__ import __version__ -from anime_downloader.players.mpv import mpv +from anime_downloader.players import Players from anime_downloader import watch as _watch from anime_downloader.config import Config from anime_downloader.sites import get_anime_class, ALL_ANIME_SITES @@ -221,6 +221,9 @@ def list_animes(watcher, quality, download_dir, imp=None, _filter=None): elif inp == 'watch': anime.quality = quality watch_anime(watcher, anime, quality, download_dir) + elif inp.startswith('watch '): + anime.quality = quality + watch_anime(watcher, anime, quality, download_dir, player_class=inp.split('watch ')[-1]) elif inp.startswith('download'): # You can use download 3:10 for selected episodes @@ -299,7 +302,7 @@ def list_animes(watcher, quality, download_dir, imp=None, _filter=None): watcher.update(anime) -def watch_anime(watcher, anime, quality, download_dir): +def watch_anime(watcher, anime, quality, download_dir, player_name=Config['watch']['default_player']): autoplay = Config['watch']['autoplay_next'] to_watch = anime[anime.episodes_done:] logger.debug('Sliced episodes: {}'.format(to_watch._episode_urls)) @@ -313,30 +316,31 @@ def watch_anime(watcher, anime, quality, download_dir): 'Playing episode {}'.format(episode.ep_no) ) try: - player = mpv(episode) + player = Players[player_name](episode) + + returncode = player.play() + if returncode == player.STOP: + # Returns to watch. + return + + elif returncode == player.CONNECT_ERR: + logger.warning("Couldn't connect. Retrying. " + "Attempt #{}".format(tries + 1)) + continue + + elif returncode == player.PREV: + anime.episodes_done -= 2 + watcher.update(anime) + break + # If no other return codes, basically when the player finishes. + # Can't find the returncode for success. + elif autoplay: + break + else: + return except Exception as e: anime.episodes_done -= 1 watcher.update(anime) logger.error(str(e)) sys.exit(1) - returncode = player.play() - if returncode == player.STOP: - # Returns to watch. - return - - elif returncode == player.CONNECT_ERR: - logger.warning("Couldn't connect. Retrying. " - "Attempt #{}".format(tries + 1)) - continue - - elif returncode == player.PREV: - anime.episodes_done -= 2 - watcher.update(anime) - break - # If no other return codes, basically when the player finishes. - # Can't find the returncode for success. - elif autoplay: - break - else: - return diff --git a/anime_downloader/config.py b/anime_downloader/config.py index 6e5ee71..0cbe5cf 100644 --- a/anime_downloader/config.py +++ b/anime_downloader/config.py @@ -39,7 +39,9 @@ DEFAULT_CONFIG = { 'log_level': 'INFO', 'provider': 'twist.moe', 'autoplay_next': True, - 'mpv_arguments': '' + 'mpv_arguments': '', + 'iina_arguments': '', + 'default_player': 'mpv' }, 'gui': { 'player': 'mpv' diff --git a/anime_downloader/players/__init__.py b/anime_downloader/players/__init__.py index e69de29..ca06ff8 100644 --- a/anime_downloader/players/__init__.py +++ b/anime_downloader/players/__init__.py @@ -0,0 +1,7 @@ +from anime_downloader.players.mpv import mpv +from anime_downloader.players.iina import iina + +Players = { + 'mpv': mpv, + 'iina': iina +} diff --git a/anime_downloader/players/iina.py b/anime_downloader/players/iina.py new file mode 100644 index 0000000..c8a065f --- /dev/null +++ b/anime_downloader/players/iina.py @@ -0,0 +1,35 @@ +from anime_downloader.players.baseplayer import BasePlayer +from anime_downloader.players.mpv import get_mpv_configfile +from anime_downloader import config +from anime_downloader.config import Config + +import os + + +class iina(BasePlayer): + name = 'iina' + + STOP = 50 + NEXT = 51 + CONNECT_ERR = 2 + + def _get_executable_windows(self): + return 'iina.exe' + + def _get_executable_posix(self): + return 'iina' + + @property + def args(self): + # Doesnt use the referer if it's none + launchArgs = Config['watch']['iina_arguments'] + if self.episode.source().referer: + return ['--keep-running', + '--input-conf=' + get_mpv_configfile(), + '--http-header-fields=referer: ' + str(self.episode.source().referer), + self.episode.source().stream_url, launchArgs] + else: + return ['--keep-running', + '--input-conf=' + get_mpv_configfile(), + self.episode.source().stream_url, launchArgs] +