package utils

import (
	"fmt"
	"net/url"
	"strings"
)

// LinkVideo 链接视频，解析链接，网络文件会下载到临时目录并返回本地路径
func LinkVideo(link string) (path string, local bool, err error) {
	if link == "" {
		return
	}
	u, err := url.Parse(link)
	if err != nil {
		err = fmt.Errorf("URL 解析错误: %v", err)
	} else {
		if u.Scheme == "file" {
			local = true
			path, _ = strings.CutPrefix(link, "file://")
		} else if u.Scheme == "http" || u.Scheme == "https" {
			local = false
			path = link
		} else {
			err = fmt.Errorf("不支持的链接协议: %v", u.String())
		}
	}
	return
}
