forked from MetaCubeX/mihomo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
adlyq
committed
Nov 5, 2022
1 parent
4c5853e
commit dcd2417
Showing
4 changed files
with
112 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package provider | ||
|
||
import ( | ||
"github.com/dlclark/regexp2" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
type SubscriptionInfo struct { | ||
Upload *int | ||
Download *int | ||
Total *int | ||
Expire *int | ||
} | ||
|
||
func NewSubscriptionInfo(str string) (si *SubscriptionInfo, err error) { | ||
si = &SubscriptionInfo{} | ||
str = strings.ToLower(str) | ||
reTraffic := regexp2.MustCompile("upload=(\\d+); download=(\\d+); total=(\\d+)", 0) | ||
reExpire := regexp2.MustCompile("expire=(\\d+)", 0) | ||
|
||
match, err := reTraffic.FindStringMatch(str) | ||
if err != nil || match == nil { | ||
return nil, err | ||
} | ||
group := match.Groups() | ||
tmp, err := strconv.Atoi(group[1].String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
si.Upload = &tmp | ||
tmp, err = strconv.Atoi(group[2].String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
si.Download = &tmp | ||
tmp, err = strconv.Atoi(group[3].String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
si.Total = &tmp | ||
|
||
match, _ = reExpire.FindStringMatch(str) | ||
if match != nil { | ||
group = match.Groups() | ||
tmp, err = strconv.Atoi(group[1].String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
si.Expire = &tmp | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters