mirror of
https://github.com/mmjee/Piped-Material.git
synced 2024-12-06 19:26:36 +01:00
Add watched videos to a playlist
This commit is contained in:
@@ -16,6 +16,7 @@ Vue.config.productionTip = false
|
||||
Promise.all([
|
||||
store.dispatch('prefs/loadState'),
|
||||
store.dispatch('auth/initializeAuth'),
|
||||
store.dispatch('plHistory/resolvePlaylistID'),
|
||||
i18nInitialized
|
||||
]).then(() => {
|
||||
new Vue({
|
||||
|
||||
@@ -383,14 +383,14 @@ export default {
|
||||
.replaceAll('\n', '<br>')
|
||||
)
|
||||
try {
|
||||
if (!this.$store.getters['prefs/getPreference']('disableDuplicateHistoryEntries', false)) {
|
||||
this.dbID = await addWatchedVideo(video)
|
||||
if (!this.$store.getters['prefs/getPreference']('disableDuplicateHistoryEntries', false) && false) {
|
||||
this.dbID = await addWatchedVideo(this.$store, video)
|
||||
this.lastWatch = await findLastWatch(this.videoId)
|
||||
} else {
|
||||
let dbObj = await findLastWatch(this.videoId)
|
||||
|
||||
if (dbObj == null) {
|
||||
this.dbID = await addWatchedVideo(video)
|
||||
this.dbID = await addWatchedVideo(this.$store, video)
|
||||
dbObj = await findLastWatch(this.videoId)
|
||||
} else {
|
||||
this.dbID = dbObj.id
|
||||
@@ -415,7 +415,7 @@ export default {
|
||||
if (this.dbID == null || !this.$refs.player) {
|
||||
return
|
||||
}
|
||||
return updateWatchedVideoProgress(this.dbID, this.$refs.player.getCurrentTime(), this.video.duration)
|
||||
return updateWatchedVideoProgress(this.$store, this.dbID, this.$refs.player.getCurrentTime(), this.video.duration)
|
||||
}, 500)
|
||||
},
|
||||
computed: {
|
||||
|
||||
+3
-1
@@ -3,6 +3,7 @@ import Vuex from 'vuex'
|
||||
|
||||
import { PrefsStore, initializePrefEvents } from '@/store/prefs-store'
|
||||
import { AuthenticationStore, initializeAuthEvents } from '@/store/authentication-store'
|
||||
import { WatchedVideosPlaylist } from '@/store/watched-videos-playlist'
|
||||
import { i18nStore } from '@/store/i18n-store'
|
||||
|
||||
Vue.use(Vuex)
|
||||
@@ -11,7 +12,8 @@ const store = new Vuex.Store({
|
||||
modules: {
|
||||
prefs: PrefsStore,
|
||||
auth: AuthenticationStore,
|
||||
i18n: i18nStore
|
||||
i18n: i18nStore,
|
||||
plHistory: WatchedVideosPlaylist
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ PMDB.version(3).stores({
|
||||
watchedVideos: '++id,videoId,progressPcnt,timestamp'
|
||||
})
|
||||
|
||||
export async function addWatchedVideo (videoObj) {
|
||||
export async function addWatchedVideo (store, videoObj) {
|
||||
await store.dispatch('plHistory/addVideo', videoObj.videoId)
|
||||
return PMDB.watchedVideos.add({
|
||||
videoId: videoObj.videoId,
|
||||
video: videoObj,
|
||||
@@ -16,7 +17,7 @@ export async function addWatchedVideo (videoObj) {
|
||||
})
|
||||
}
|
||||
|
||||
export function updateWatchedVideoProgress (videoID, prog, dur) {
|
||||
export function updateWatchedVideoProgress (_, videoID, prog, dur) {
|
||||
return PMDB.watchedVideos.update(videoID, {
|
||||
progress: prog,
|
||||
progressPcnt: Math.min((prog / dur) * 100, 100)
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
const WATCHED_HISTORY_PLAYLIST_UNIQID = '5d0615c7-b6a7-4bd5-8450-fa740cd92df7'
|
||||
|
||||
export const WatchedVideosPlaylist = {
|
||||
namespaced: true,
|
||||
state: () => ({
|
||||
playlistID: ''
|
||||
}),
|
||||
mutations: {
|
||||
replaceID (state, nextID) {
|
||||
state.playlistID = nextID
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async resolvePlaylistID ({ dispatch, commit }) {
|
||||
const playlists = await dispatch('auth/makeRequest', {
|
||||
method: 'GET',
|
||||
path: '/user/playlists'
|
||||
}, {
|
||||
root: true
|
||||
})
|
||||
let found = false; let pl
|
||||
for (const _pl of playlists) {
|
||||
const sdp = _pl.shortDescription ?? ''
|
||||
if (sdp.includes(WATCHED_HISTORY_PLAYLIST_UNIQID) || _pl.name === 'Watch History') {
|
||||
found = true
|
||||
pl = _pl
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
const { playlistId } = await dispatch('auth/makeRequest', {
|
||||
method: 'POST',
|
||||
path: '/user/playlists/create',
|
||||
data: {
|
||||
name: 'Watch History',
|
||||
shortDescription: WATCHED_HISTORY_PLAYLIST_UNIQID
|
||||
}
|
||||
}, {
|
||||
root: true
|
||||
})
|
||||
pl = {
|
||||
id: playlistId
|
||||
}
|
||||
}
|
||||
commit('replaceID', pl.id)
|
||||
},
|
||||
async addVideo ({ state, dispatch }, videoID) {
|
||||
await dispatch('auth/makeRequest', {
|
||||
method: 'POST',
|
||||
path: '/user/playlists/add',
|
||||
data: {
|
||||
playlistId: state.playlistID,
|
||||
videoId: videoID
|
||||
}
|
||||
}, {
|
||||
root: true
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,8 @@
|
||||
"remove_video": "Remove this video from the playlist",
|
||||
"delete_self": "Delete",
|
||||
"rename_self": "Rename",
|
||||
"new_name_msg": "What do you want the new name to be?"
|
||||
"new_name_msg": "What do you want the new name to be?",
|
||||
"watched_history_playlist_name": "Watched History"
|
||||
},
|
||||
"misc": {
|
||||
"searchBarLabel": "What are you looking for?",
|
||||
|
||||
Reference in New Issue
Block a user