Mark video watched (#59)
* Mark video watched * Lint fix * return type * fix return type * Changelog --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
53f9249b9f
commit
82162d52c1
4 files changed
+40
-2
No files matched your search
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- Add watched videos to Invidious watch history
|
||||
|
||||
## [0.8.0] - 2023-03-02
|
||||
### Added
|
||||
- SponsorBlock notification
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import "pkg:/source/services/Invidious.bs"
|
||||
|
||||
@asynctask
|
||||
function MarkVideoWatchedTask(input as object) as object
|
||||
videoId = input.videoId
|
||||
|
||||
success = Invidious.MarkVideoWatched(videoId)
|
||||
return {
|
||||
success: success
|
||||
}
|
||||
end function
|
||||
@@ -1,6 +1,8 @@
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/source/services/Invidious.bs"
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
import "pkg:/components/SponsorBlockNotification/SponsorBlockNotificationManager.bs"
|
||||
import "pkg:/components/VideoPlayer/MarkVideoWatchedTask.bs"
|
||||
|
||||
function PlayVideo(videoId as string, args = invalid as object)
|
||||
sender = args?.sender
|
||||
@@ -35,6 +37,8 @@ function PlayVideo(videoId as string, args = invalid as object)
|
||||
if videoContainer.fullscreen
|
||||
videoContainer.videoPlayer.SetFocus(true)
|
||||
end if
|
||||
|
||||
StartAsyncTask(MarkVideoWatchedTask, { videoId: videoId })
|
||||
end function
|
||||
|
||||
function CloseVideo(setFocus = true as boolean)
|
||||
|
||||
@@ -13,11 +13,12 @@ namespace Invidious
|
||||
const STATS_ENDPOINT = "/api/v1/stats"
|
||||
|
||||
const VIDEOS_ENDPOINT = "/api/v1/videos"
|
||||
const HISTORY_ENDPOINT = "/api/v1/auth/history"
|
||||
|
||||
const SEARCH_SUGGEST_ENDPOINT = "/api/v1/search/suggestions"
|
||||
const SEARCH_ENDPOINT = "/api/v1/search"
|
||||
|
||||
const AUTH_SCOPE = "GET:feed,GET:playlists,POST:tokens/unregister"
|
||||
const AUTH_SCOPE = "GET:feed,GET:playlists,POST:tokens/unregister,POST:history*"
|
||||
const AUTH_FEED = "/api/v1/auth/feed"
|
||||
const AUTH_PLAYLISTS = "/api/v1/auth/playlists"
|
||||
const AUTH_TOKENS_UNREGISTER = "/api/v1/auth/tokens/unregister"
|
||||
@@ -66,6 +67,23 @@ namespace Invidious
|
||||
}
|
||||
end function
|
||||
|
||||
function MarkVideoWatched(videoId as string) as boolean
|
||||
authToken = InvidiousSettings.GetAuthToken()
|
||||
if authToken = invalid
|
||||
return false
|
||||
end if
|
||||
|
||||
url = `${authToken.instance}${Invidious.HISTORY_ENDPOINT}/${videoId}`
|
||||
headers = Invidious.GetAuthenticationHeaders(authToken.token)
|
||||
args = {
|
||||
headers: headers,
|
||||
parseJson: false
|
||||
}
|
||||
|
||||
response = Requests().post(url, args)
|
||||
return response.ok
|
||||
end function
|
||||
|
||||
function SearchSuggestions(q as string) as object 'SearchSuggestionResult
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
url = `${instance}${Invidious.SEARCH_SUGGEST_ENDPOINT}`
|
||||
@@ -127,7 +145,8 @@ namespace Invidious
|
||||
expire = TimeUtils.Now().AsSeconds() + 60 * 60 * 24 * 365 * 2 '2 years from now
|
||||
|
||||
callbackUrl = `http://${localIp}:${webServerPort}${Invidious.TOKEN_CALLBACK}?ref=${instance}`.EncodeUriComponent()
|
||||
return `${invidiousHost}/authorize_token?scopes=${Invidious.AUTH_SCOPE}&callback_url=${callbackUrl}&expire=${expire}`
|
||||
scope = `${Invidious.AUTH_SCOPE}`.EncodeUriComponent()
|
||||
return `${invidiousHost}/authorize_token?scopes=${scope}&callback_url=${callbackUrl}&expire=${expire}`
|
||||
end function
|
||||
|
||||
function GetAuthenticationHeaders(token as string) as object
|
||||
|
||||
Reference in new issue
Block a user