Add multiple player basics and IINA support (#690)
parent
913e6bc842
commit
34ba40e1de
|
@ -10,7 +10,7 @@ import re
|
||||||
|
|
||||||
from anime_downloader import util
|
from anime_downloader import util
|
||||||
from anime_downloader.__version__ import __version__
|
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 import watch as _watch
|
||||||
from anime_downloader.config import Config
|
from anime_downloader.config import Config
|
||||||
from anime_downloader.sites import get_anime_class, ALL_ANIME_SITES
|
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':
|
elif inp == 'watch':
|
||||||
anime.quality = quality
|
anime.quality = quality
|
||||||
watch_anime(watcher, anime, quality, download_dir)
|
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'):
|
elif inp.startswith('download'):
|
||||||
# You can use download 3:10 for selected episodes
|
# 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)
|
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']
|
autoplay = Config['watch']['autoplay_next']
|
||||||
to_watch = anime[anime.episodes_done:]
|
to_watch = anime[anime.episodes_done:]
|
||||||
logger.debug('Sliced episodes: {}'.format(to_watch._episode_urls))
|
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)
|
'Playing episode {}'.format(episode.ep_no)
|
||||||
)
|
)
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
anime.episodes_done -= 1
|
anime.episodes_done -= 1
|
||||||
watcher.update(anime)
|
watcher.update(anime)
|
||||||
logger.error(str(e))
|
logger.error(str(e))
|
||||||
sys.exit(1)
|
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
|
|
||||||
|
|
|
@ -39,7 +39,9 @@ DEFAULT_CONFIG = {
|
||||||
'log_level': 'INFO',
|
'log_level': 'INFO',
|
||||||
'provider': 'twist.moe',
|
'provider': 'twist.moe',
|
||||||
'autoplay_next': True,
|
'autoplay_next': True,
|
||||||
'mpv_arguments': ''
|
'mpv_arguments': '',
|
||||||
|
'iina_arguments': '',
|
||||||
|
'default_player': 'mpv'
|
||||||
},
|
},
|
||||||
'gui': {
|
'gui': {
|
||||||
'player': 'mpv'
|
'player': 'mpv'
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
from anime_downloader.players.mpv import mpv
|
||||||
|
from anime_downloader.players.iina import iina
|
||||||
|
|
||||||
|
Players = {
|
||||||
|
'mpv': mpv,
|
||||||
|
'iina': iina
|
||||||
|
}
|
|
@ -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]
|
||||||
|
|
Loading…
Reference in New Issue