wbt5 / real-url

获取斗鱼&虎牙&哔哩哔哩&抖音&快手等 58 个直播平台的真实流媒体地址(直播源)和弹幕,直播源可在 PotPlayer、flv.js 等播放器中播放。
GNU General Public License v2.0
7.31k stars 1.54k forks source link

Feature request: Argparse and unified command #379

Closed ocfox closed 1 year ago

ocfox commented 2 years ago

If package real-url, use a unified command replace python xxx.py is a good way. E.g.: real-url douyu 12306, real-url bilibili 11111

Maybe using a python script with Argparse and a simple modification to the way other scripts pass in the live room number. I will try this, once that's done, I'll open a pull request.

ocfox commented 2 years ago

That's what I thought, but pattern match seems to be a new feature in python 3.10? Does anyone have a better idea?

#!/usr/bin/env python3
import argparse
import douyu
import bilibili
# others
parser = argparse.ArgumentParser()
parser.add_argument("platform", help="直播平台")
parser.add_argument("room", help="直播间号码")
args = parser.parse_args()

match args.platform:
    case "douyu":
        print(douyu.DouYu(args.room).get_real_url())
    case "bilibili":
        print(bilibili.get_real_url(args.room))
    #other case:

Using many cases is a bad way, maybe unified all scripts use {platform}.get_realurl(args.room)) is a good way.