Skip to content

Commit

Permalink
Version 1.6.9.4.1
Browse files Browse the repository at this point in the history
Expose `parse_args` and added `quit_on_empty_args` flag for use with some demos
  • Loading branch information
mos9527 committed Aug 10, 2023
1 parent 21177d0 commit 3eb261c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions demos/歌单同步.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pyncm.__main__ import parse_args,logger
from pyncm import GetCurrentSession,SetCurrentSession,LoadSessionFromString
from pyncm.utils.helper import UserHelper
args, _ = parse_args()
logger.info("读取登录信息 : %s" % args.load)
SetCurrentSession(LoadSessionFromString(open(args.load).read()))
logger.info("用户 : %s" % UserHelper(GetCurrentSession().uid).UserName)
2 changes: 1 addition & 1 deletion pyncm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# 注意事项
- (PR#11) 海外用户可能经历 460 "Cheating" 问题,可通过添加以下 Header 解决: `X-Real-IP = 118.88.88.88`
"""
__version__ = "1.6.9.4"
__version__ = "1.6.9.4.1"

from threading import current_thread
from typing import Text, Union
Expand Down
7 changes: 5 additions & 2 deletions pyncm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def parse_sharelink(url):

PLACEHOLDER_URL = "00000"

def parse_args():
def parse_args(quit_on_empty_args=True):
"""Setting up __main__ argparser"""
parser = argparse.ArgumentParser(
description=__desc__, formatter_class=argparse.RawTextHelpFormatter
Expand Down Expand Up @@ -612,7 +612,10 @@ def print_help_and_exit():
sys.argv.append("-h") # If using placeholder, no argument is really passed
sys.exit(__main__()) # In which case, print help and exit
if args.url == PLACEHOLDER_URL and not args.save:
print_help_and_exit()
if quit_on_empty_args:
print_help_and_exit()
else:
return args,[]
try:
return args , [parse_sharelink(url) for url in args.url]
except AssertionError:
Expand Down

0 comments on commit 3eb261c

Please sign in to comment.