Skip to content

Commit

Permalink
fix build (#898)
Browse files Browse the repository at this point in the history
  • Loading branch information
kigawas authored Jan 3, 2021
1 parent 9fcaf11 commit cd91808
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 226 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/python-package.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package
name: Build

on:
push:
Expand All @@ -22,11 +22,21 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: abatilo/actions-poetry@v2.0.0
with:
poetry-version: 1.1.4
- uses: actions/cache@v2
with:
path: |
~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip poetry
poetry install
poetry build
- name: Test with pytest
run: |
poetry run pytest -s
run: poetry run pytest -s
- name: Run cli
run: poetry run musicbox -v
env:
TERM: xterm
16 changes: 4 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
repos:
- repo: https://github.com/ambv/black
rev: stable
rev: 20.8b1
hooks:
- id: black
exclude: venv

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v3.4.0
hooks:
- id: trailing-whitespace
- id: check-yaml

- repo: https://github.com/asottile/reorder_python_imports
rev: v2.3.5
rev: v2.3.6
hooks:
- id: reorder-python-imports
args: ["--py3-plus"]

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
rev: 3.8.4
hooks:
- id: flake8
# allow "imported but unused" for pre-commit, forbid it elsewhere e.g. in vscode
args: ["--config=setup.cfg", "--ignore=E402,F401"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.782
hooks:
- id: mypy
exclude: "migrations"
additional_dependencies:
["git+https://github.com/typeddjango/django-stubs.git"]
16 changes: 12 additions & 4 deletions NEMbox/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import _curses
import argparse
import curses
import sys
Expand All @@ -17,9 +18,13 @@ def start():
"-v", "--version", help="show this version and exit", action="store_true"
)
args = parser.parse_args()

if args.version:
latest = Menu().check_version()
curses.endwin()
try:
curses.endwin()
except _curses.error:
pass
print("NetEase-MusicBox installed version:" + version)
if latest != version:
print("NetEase-MusicBox latest version:" + str(latest))
Expand All @@ -30,9 +35,12 @@ def start():
nembox_menu.start_fork(version)
except (OSError, TypeError, ValueError, KeyError, IndexError):
# clean up terminal while failed
curses.echo()
curses.nocbreak()
curses.endwin()
try:
curses.echo()
curses.nocbreak()
curses.endwin()
except _curses.error:
pass
traceback.print_exc()


Expand Down
13 changes: 9 additions & 4 deletions NEMbox/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,12 @@ def login(self, username, password):
self.session.cookies.load()
if username.isdigit():
path = "/weapi/login/cellphone"
params = dict(phone=username, password=password, countrycode="86", rememberLogin="true")
params = dict(
phone=username,
password=password,
countrycode="86",
rememberLogin="true",
)
else:
# magic token for login
# see https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/router/login.js#L15
Expand All @@ -390,7 +395,7 @@ def login(self, username, password):
rememberLogin="true",
clientToken=client_token,
)
data = self.request("POST", path, params,custom_cookies={'os': 'pc'})
data = self.request("POST", path, params, custom_cookies={"os": "pc"})
self.session.cookies.save()
return data

Expand Down Expand Up @@ -562,12 +567,12 @@ def dig_info(self, data, dig_type):
if not data:
return []
if dig_type == "songs" or dig_type == "fmsongs":
sids = [x['id'] for x in data]
sids = [x["id"] for x in data]
urls = self.songs_url(sids)
i = 0
sds = []
while i < len(sids):
sds.extend(self.songs_detail(sids[i:i+500]))
sds.extend(self.songs_detail(sids[i : i + 500]))
i += 500
timestamp = time.time()
# api 返回的 urls 的 id 顺序和 data 的 id 顺序不一致
Expand Down
5 changes: 3 additions & 2 deletions NEMbox/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
from .cmd_parser import parse_keylist
from .config import Config
from .osdlyrics import pyqt_activity
from .osdlyrics import show_lyrics_new_process, stop_lyrics_process
from .osdlyrics import show_lyrics_new_process
from .osdlyrics import stop_lyrics_process
from .player import Player
from .storage import Storage
from .ui import Ui
Expand Down Expand Up @@ -674,7 +675,7 @@ def start(self):
# 退出并清除用户信息
elif C.keyname(key).decode("utf-8") == keyMap["quitClear"]:
if pyqt_activity:
stop_lyrics_process()
stop_lyrics_process()
self.api.logout()
break

Expand Down
32 changes: 16 additions & 16 deletions NEMbox/osdlyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
# osdlyrics.py --- desktop lyrics for musicbox
# Copyright (c) 2015-2016 omi & Contributors
import sys
import dbus
import dbus.service
import dbus.mainloop.glib
from multiprocessing import Process, set_start_method
from multiprocessing import Process
from multiprocessing import set_start_method

from . import logger
from .config import Config
Expand All @@ -17,6 +15,9 @@

try:
from qtpy import QtGui, QtCore, QtWidgets
import dbus
import dbus.service
import dbus.mainloop.glib

pyqt_activity = True
except ImportError:
Expand All @@ -25,14 +26,13 @@
log.warn("Osdlyrics Not Available.")

if pyqt_activity:

QWidget = QtWidgets.QWidget
QApplication = QtWidgets.QApplication

class Lyrics(QWidget):
def __init__(self):
super(Lyrics, self).__init__()
self.text = ''
self.text = ""
self.initUI()

def initUI(self):
Expand Down Expand Up @@ -104,14 +104,16 @@ def setText(self, text):

class LyricsAdapter(dbus.service.Object):
def __init__(self, name, session):
dbus.service.Object.__init__(self, name, session)
self.widget = Lyrics()
dbus.service.Object.__init__(self, name, session)
self.widget = Lyrics()

@dbus.service.method("local.musicbox.Lyrics", in_signature='s', out_signature='')
@dbus.service.method(
"local.musicbox.Lyrics", in_signature="s", out_signature=""
)
def refresh_lyrics(self, text):
self.widget.setText(text.replace("||", "\n"))

@dbus.service.method("local.musicbox.Lyrics", in_signature='', out_signature='')
@dbus.service.method("local.musicbox.Lyrics", in_signature="", out_signature="")
def exit(self):
QApplication.quit()

Expand All @@ -120,21 +122,19 @@ def show_lyrics():
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
session_bus = dbus.SessionBus()
name = dbus.service.BusName("org.musicbox.Bus", session_bus)
lyrics = LyricsAdapter(session_bus, '/')
lyrics = LyricsAdapter(session_bus, "/")
app.exec_()


def stop_lyrics_process():
try:
if pyqt_activity:
bus = dbus.SessionBus().get_object("org.musicbox.Bus", "/")
bus.exit(dbus_interface="local.musicbox.Lyrics")
except Exception as e:
log.error(e)
pass


def show_lyrics_new_process():
if pyqt_activity and config.get("osdlyrics"):
set_start_method('spawn')
set_start_method("spawn")
p = Process(target=show_lyrics)
p.daemon = True
p.start()
Loading

0 comments on commit cd91808

Please sign in to comment.