Skip to content
This repository has been archived by the owner on Jun 30, 2019. It is now read-only.

Commit

Permalink
Merge 7a0a0c0 into 162c905
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven authored Aug 6, 2018
2 parents 162c905 + 7a0a0c0 commit dc11c75
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 89 deletions.
3 changes: 0 additions & 3 deletions fuocore/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import logging
import logging.config

from fuocore.models import ModelType # noqa
from fuocore.player import (
MpvPlayer,
Expand Down
4 changes: 2 additions & 2 deletions fuocore/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from fuocore import MpvPlayer
from fuocore import LiveLyric
from fuocore.furi import parse_furi
from fuocore.protocol.parser import CmdParser
from fuocore.protocol.handlers import exec_cmd
from fuocore.protocol import CmdParser
from fuocore.protocol import exec_cmd

logger = logging.getLogger(__name__)

Expand Down
7 changes: 4 additions & 3 deletions fuocore/netease/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def _find_in_xiami(self):
)

def _find_in_local(self):
# TODO: make this a API in SongModel
path = os.path.join(MUSIC_LIBRARY_PATH, self.filename)
if os.path.exists(path):
logger.debug('find local file for {}'.format(self))
Expand All @@ -95,7 +96,7 @@ def url(self):
As netease song url will be expired after a period of time,
we can not use static url here. Currently, we assume that the
expiration time is 100 seconds, after the url expires, it
expiration time is 20 minutes, after the url expires, it
will be automaticly refreshed.
"""
local_path = self._find_in_local()
Expand All @@ -105,13 +106,13 @@ def url(self):
if not self._url:
self._refresh_url()
elif time.time() > self._expired_at:
logger.debug('song({}) url is expired, refresh...'.format(self))
logger.info('song({}) url is expired, refresh...'.format(self))
self._refresh_url()
return self._url

@url.setter
def url(self, value):
self._expired_at = time.time() + 60 * 60 * 1 # one hour
self._expired_at = time.time() + 60 * 20 * 1 # 20 minutes
self._url = value

@property
Expand Down
76 changes: 76 additions & 0 deletions fuocore/protocol/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import logging

from .handlers import (
HelpHandler,
SearchHandler,
PlayerHandler,
PlaylistHandler,
StatusHandler,
)

from .show import ShowHandler # noqa
from .parser import CmdParser # noqa


logger = logging.getLogger(__name__)


def exec_cmd(app, live_lyric, cmd):
# FIXME: 要么只传 app,要么把 player, live_lyric 等分别传进来
# 目前更使用 app 作为参数

logger.debug('EXEC_CMD: ' + str(cmd))

# 一些
if cmd.action in ('help', ):
handler = HelpHandler(app,
live_lyric=live_lyric)

elif cmd.action in ('show', ):
handler = ShowHandler(app,
live_lyric=live_lyric)

elif cmd.action in ('search', ):
handler = SearchHandler(app,
live_lyric=live_lyric)

# 播放器相关操作
elif cmd.action in (
'play', 'pause', 'resume', 'stop', 'toggle',
):
handler = PlayerHandler(app,
live_lyric=live_lyric)

# 播放列表相关命令
elif cmd.action in (
'add', 'remove', 'clear', 'list',
'next', 'previous',
):
"""
add/remove fuo://local:song:xxx
create xxx
set playback_mode=random
set volume=100
"""
handler = PlaylistHandler(app,
live_lyric=live_lyric)
elif cmd.action in ('status',):
handler = StatusHandler(app,
live_lyric=live_lyric)
else:
return 'Oops Command not found!\n'

rv = 'ACK {}'.format(cmd.action)
if cmd.args:
rv += ' {}'.format(' '.join(cmd.args))
try:
cmd_rv = handler.handle(cmd)
if cmd_rv:
rv += '\n' + cmd_rv
except Exception as e:
logger.exception('handle cmd({}) error'.format(cmd))
return '\nOops\n'
else:
rv = rv or ''
return rv + '\nOK\n'
Original file line number Diff line number Diff line change
@@ -1,87 +1,16 @@
import logging

from abc import ABC, abstractmethod
from collections import defaultdict
from urllib.parse import urlparse

import logging

from fuocore.player import PlaybackMode, State

from .helpers import show_songs, show_song


logger = logging.getLogger(__name__)


class CmdHandleException(Exception):
pass


class CmdNotFound(CmdHandleException):
pass


class InvalidFUri(CmdHandleException):
pass


def exec_cmd(app, live_lyric, cmd):
logger.debug('EXEC_CMD: ' + str(cmd))

# 一些
if cmd.action in ('help', ):
handler = HelpHandler(app,
live_lyric=live_lyric)

elif cmd.action in ('show', ):
handler = ShowHandler(app,
live_lyric=live_lyric)

elif cmd.action in ('search', ):
handler = SearchHandler(app,
live_lyric=live_lyric)

# 播放器相关操作
elif cmd.action in (
'play', 'pause', 'resume', 'stop', 'toggle',
):
handler = PlayerHandler(app,
live_lyric=live_lyric)

# 播放列表相关命令
elif cmd.action in (
'add', 'remove', 'clear', 'list',
'next', 'previous',
):
"""
add/remove fuo://local:song:xxx
create xxx
set playback_mode=random
set volume=100
"""
handler = PlaylistHandler(app,
live_lyric=live_lyric)
elif cmd.action in ('status',):
handler = StatusHandler(app,
live_lyric=live_lyric)
else:
return 'Oops Command not found!\n'

rv = 'ACK {}'.format(cmd.action)
if cmd.args:
rv += ' {}'.format(' '.join(cmd.args))
try:
cmd_rv = handler.handle(cmd)
if cmd_rv:
rv += '\n' + cmd_rv
except Exception as e:
logger.exception('handle cmd({}) error'.format(cmd))
return '\nOops\n'
else:
rv = rv or ''
return rv + '\nOK\n'


class AbstractHandler(ABC):
def __init__(self, app, live_lyric):
self.app = app
Expand Down Expand Up @@ -231,6 +160,3 @@ def handle(self, cmd):
echo "sub topic.live_lyric" | nc host 23334
"""


from .show import ShowHandler # noqa
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import re
from urllib.parse import urlparse

from . import AbstractHandler, CmdHandleException
from .handlers import AbstractHandler
from .helpers import (
show_songs, show_song, show_artist, show_album, show_user,
show_song, show_artist, show_album, show_user,
show_playlist
)

Expand Down Expand Up @@ -123,7 +123,8 @@ def handle(self, cmd):
try:
rule, params = match(path)
except NotFound as e:
raise CmdHandleException('uri 不能被正确识别')
# FIXME: 抛一个合理的异常
raise Exception('uri 不能被正确识别')
return dispatch(self, rule, params)


Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name='fuocore',
version='2.0.1',
version='2.0.2.dev',
description='feeluown core',
author='Cosven',
author_email='yinshaowen241@gmail.com',
Expand All @@ -26,7 +26,6 @@
'fuocore.netease',
'fuocore.qqmusic',
'fuocore.protocol',
'fuocore.protocol.handlers',
],
package_data={
'': []
Expand Down

0 comments on commit dc11c75

Please sign in to comment.