This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVideoplayer.lua
214 lines (191 loc) · 6.54 KB
/
Videoplayer.lua
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
local UserInputService = game:GetService("UserInputService")
local InsertService = game:GetService("InsertService")
local HttpService = game:GetService("HttpService")
local RunService = game:GetService("RunService")
local CoreGui = game:GetService("CoreGui")
local AssetFolder = InsertService:LoadLocalAsset("rbxassetid://7563729664")
local Request = request or (http and http.request) or (syn and syn.request)
local GetAsset = getcustomasset or getsynasset
local RobloxPanel = CoreGui.ThemeProvider.TopBarFrame.LeftFrame
local PanelButton = AssetFolder.VideoButton
local Screen = AssetFolder.Videoplayer
local Window = Screen.Window
local ControlPanel = Window.ControlPanel
PanelButton.Name = HttpService:GenerateGUID(false)
PanelButton.Parent = RobloxPanel
Screen.Name = HttpService:GenerateGUID(false)
Screen.Parent = CoreGui
if not isfolder("videos") then
makefolder("videos")
end
local Settings = {
Playing = false,
Expand = false,
Size = Window.Size,
Position = Window.Position,
Domain = "https://parvus.fun/"
}
local function MakeDraggable(Dragger,Object,Callback)
local StartPosition,StartDrag = nil,nil
Dragger.InputBegan:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
StartPosition = UserInputService:GetMouseLocation()
StartDrag = Object.AbsolutePosition
end
end)
UserInputService.InputChanged:Connect(function(Input)
if StartDrag and Input.UserInputType == Enum.UserInputType.MouseMovement then
local Mouse = UserInputService:GetMouseLocation()
local Delta = Mouse - StartPosition
StartPosition = Mouse
Object.Position = Object.Position + UDim2.new(0,Delta.X,0,Delta.Y)
end
end)
Dragger.InputEnded:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
StartPosition,StartDrag = nil,nil
if Callback then
Callback(Object.Position)
end
end
end)
end
local function MakeResizeable(Dragger,Object,MinSize,Callback)
local StartPosition,StartSize = nil,nil
Dragger.InputBegan:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
StartPosition = UserInputService:GetMouseLocation()
StartSize = Object.AbsoluteSize
end
end)
UserInputService.InputChanged:Connect(function(Input)
if StartPosition and Input.UserInputType == Enum.UserInputType.MouseMovement then
local Mouse = UserInputService:GetMouseLocation()
local Delta = Mouse - StartPosition
local Size = StartSize + Delta
local SizeX = math.max(MinSize.X,Size.X)
local SizeY = math.max(MinSize.Y,Size.Y)
Object.Size = UDim2.fromOffset(SizeX,SizeY)
end
end)
Dragger.InputEnded:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
StartPosition,StartSize = nil,nil
if Callback then
Callback(Object.Size)
end
end
end)
end
local function RequestVideo(VideoId)
local Responce = Request({Method = "POST",
Url = Settings.Domain .. "yt/video?videoId=" .. VideoId,
})
if Responce.StatusCode == 404 then return false end
return Responce.Body
end
local function ChangeTimePosition()
local Length = Window.Video.TimeLength
local Size = UDim2.new(math.clamp((UserInputService:GetMouseLocation().X - Window.Playback.AbsolutePosition.X) / Window.Playback.AbsoluteSize.X,0,1),0,1,0)
local TimePosition = ((Size.X.Scale * Length) / Length) * (Length - 0) + 0
Window.Playback.Line.Size = Size
Window.Video.TimePosition = TimePosition
Settings.Playing = true
ControlPanel.Play.ImageRectOffset = Vector2.new(804,124)
Window.Video:Play()
end
local function UpdateTime()
local TimePosition = Window.Video.TimePosition
Window.Playback.Time.Text = string.format(
"%02i:%02i:%02i",
TimePosition/60^2,
TimePosition/60%60,
TimePosition%60
)
end
local function UpdateLength()
local TimeLength = Window.Video.TimeLength
Window.Playback.Length.Text = string.format(
"%02i:%02i:%02i",
TimeLength/60^2,
TimeLength/60%60,
TimeLength%60
)
end
local function UpdatePlayback()
local TimePosition = Window.Video.TimePosition
local TimeLength = Window.Video.TimeLength
local TimePercent = TimePosition / TimeLength
Window.Playback.Line.Size = UDim2.new(TimePercent,0,1,0)
end
local function PlayVideo(Toggle)
Settings.Playing = Toggle
if Settings.Playing then
ControlPanel.Play.ImageRectOffset = Vector2.new(804,124)
Window.Video:Play()
else
ControlPanel.Play.ImageRectOffset = Vector2.new(764,244)
Window.Video:Pause()
end
end
local function Expand()
if Window.Video.Resolution.X >= 300 and Window.Video.Resolution.Y >= 300 then
Settings.Expand = not Settings.Expand
if Settings.Expand then
Settings.DefaultSize = Window.Size
ControlPanel.Expand.ImageRectOffset = Vector2.new(244, 204)
Window.Size = UDim2.new(0,Window.Video.Resolution.X + 10,0,Window.Video.Resolution.Y + 110)
Window.Resize.Visible = false
else
ControlPanel.Expand.ImageRectOffset = Vector2.new(724, 204)
Window.Size = Settings.DefaultSize
Window.Resize.Visible = true
end
end
end
local function LoadVideo(Enter)
if Enter then
local VideoId = ControlPanel.LinkInput.Text
if not isfile("videos/" .. VideoId .. ".webm") then
ControlPanel.LinkInput.Text = ""
ControlPanel.LinkInput.PlaceholderText = "VideoID (Loading)"
local Video = RequestVideo(VideoId)
if Video then
writefile("videos/" .. VideoId .. ".webm", Video)
Window.Video.Video = GetAsset("videos/" .. VideoId .. ".webm")
Window.Title.Text = "Videoplayer - videos/" .. VideoId .. ".webm"
ControlPanel.LinkInput.PlaceholderText = "VideoID"
PlayVideo(true)
else
ControlPanel.LinkInput.PlaceholderText = "VideoID (Failed)"
Window.Title.Text = "Videoplayer"
Window.Video.Video = ""
PlayVideo(false)
end
else
ControlPanel.LinkInput.Text = ""
Window.Video.Video = GetAsset("videos/" .. VideoId .. ".webm")
Window.Title.Text = "Videoplayer - videos/" .. VideoId .. ".webm"
ControlPanel.LinkInput.PlaceholderText = "VideoID"
PlayVideo(true)
end
end
end
Window.Playback.Slider.MouseButton1Click:Connect(ChangeTimePosition)
ControlPanel.Expand.MouseButton1Click:Connect(Expand)
ControlPanel.LinkInput.FocusLost:Connect(LoadVideo)
ControlPanel.Play.MouseButton1Click:Connect(function()
PlayVideo(not Settings.Playing)
end)
Window.Video.Loaded:Connect(UpdateLength)
Window.Video.Ended:Connect(function()
PlayVideo(false) Window.Video.TimePosition = 0
end)
PanelButton.Icon.MouseButton1Click:Connect(function()
Window.Visible = not Window.Visible
end)
RunService.RenderStepped:Connect(function()
UpdateTime() UpdatePlayback()
end)
MakeDraggable(Window.Title,Window)
MakeResizeable(Window.Resize,Window,Vector2.new(310,400))