-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream.psm1
180 lines (123 loc) · 3.86 KB
/
stream.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
$global:playlist = import-clixml 'c:\ex-sys\xml\playlist.xml'
$completor ={
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
$playlist | Where-Object {$_.title -like "$wordTocomplete*"} | ForEach-Object {
$_.title
}
}
Register-ArgumentCompleter -commandname play-stream -parameterName name -scriptblock $completor
Register-ArgumentCompleter -commandname unsubscribe-playlist -parameterName name -scriptblock $completor
function subscribe-playlist {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]
$url,
# Parameter help description
[Parameter(Mandatory)]
[string]
$name
,
# Parameter help description
[Parameter()]
[string]
$platform = 'twitch'
)
$urlid =[int](( $playlist |Select-Object -Property urlid -last 1).urlid)+1
$newplaylist = New-Object PSObject -Property @{
'url' = $url
'title'= $name
'platform' = $platform
'urlid' = $urlID
'status' = $null
}
$newplaylist = $playlist + $newplaylist
$newplaylist | export-clixml 'c:\ex-sys\xml\playlist.xml'
}
function unsubscribe-playlist {
[CmdletBinding()]
param (
[Parameter()]
[string]
$name
)
$newplaylist = $playlist |Where-Object {$_.title -ne "*$name*"}
try {
$newplaylist | export-clixml 'c:\ex-sys\xml\playlist.xml'
}
catch {
'name dose not exist '
}
}
function play-stream{
[CmdletBinding()]
param (
[Parameter()]
[string]
$name
)
$url= (Import-Clixml 'c:\ex-sys\xml\playlist.xml'|Where-Object {$_.title -like "$name"}|Select-Object -Property url).url
$link = & "F:\streamlink\venvs\streamlink\Scripts\python.exe" $pshome\modules\stream\link.py --url $url
for ($i = 0; $i -lt 5) {
switch ($link) {
error { $link = & "F:\streamlink\venvs\streamlink\Scripts\python.exe" $pshome\modules\stream\link.py --url $url
$i++}
Default {
if ($url -like "*live.bilibili.com*") {
& "F:\program files\完美解码\Pure Codec\x64\PotPlayerMini64.exe" /url $url
}
else {
& "F:\program files\完美解码\Pure Codec\x64\PotPlayerMini64.exe" /url $link
}
$i = 5
}
"no play able stream" {
Write-Host 'no play able stream'
$i=5
}
}
if ($i -eq 5 -and $link -eq 'error') {
Write-Host ' Max retries fail ,please check the internet'
}
}
}
function list-subscribe {
[CmdletBinding()]
param (
[Parameter()]
[string]
$name
)
class newlist {
[string] $url
[string] $status
newlist([string] $url, [string] $status) {
$this.url = $url
$this.status = $status
}
}
class streamslist {
[string] $url
[string] $status
static [System.Collections.Generic.List[newlist]] $newlist
static [void] Initialize() { [streamslist]::Initialize($false) }
static [bool] Initialize([bool]$force) {
if ([streamsList]::newlist.Count -gt 0 -and -not $force) {
return $false
}
[streamsList]::newlist = [System.Collections.Generic.List[newlist]]::new()
return $true
}
static [void] Add([newlist]$newlist) {
[streamsList]::Initialize()
[streamslist]::newlist.Add($newlist)
}
}
$list = import-clixml 'c:\ex-sys\xml\playlist.xml'
$list| Where-Object {$_.title -like "*$name*"} | ForEach-Object {
$status = f:\streamlink\venvs\streamlink\Scripts\python.exe "$pshome\Modules\stream\live.py" --url $_.url
$newlist = [newlist]::new($_.url,$status)
[streamslist]::Add($newlist)
}
[streamslist]::newlist
}