From 21f76dbb6e8a9a3b09ab386d0212119a95af075f Mon Sep 17 00:00:00 2001 From: Markos Gogoulos Date: Sun, 9 Mar 2025 20:44:04 +0200 Subject: [PATCH] feat: playlist optimizations (#1216) --- files/models.py | 4 ++-- frontend/src/static/js/pages/PlaylistPage.js | 5 +++++ static/js/playlist.js | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/files/models.py b/files/models.py index bd77dfc4..bf897bb8 100644 --- a/files/models.py +++ b/files/models.py @@ -1312,7 +1312,7 @@ class Playlist(models.Model): @property def media_count(self): - return self.media.count() + return self.media.filter(listable=True).count() def get_absolute_url(self, api=False): if api: @@ -1359,7 +1359,7 @@ class Playlist(models.Model): @property def thumbnail_url(self): - pm = self.playlistmedia_set.first() + pm = self.playlistmedia_set.filter(media__listable=True).first() if pm and pm.media.thumbnail: return helpers.url_from_path(pm.media.thumbnail.path) return None diff --git a/frontend/src/static/js/pages/PlaylistPage.js b/frontend/src/static/js/pages/PlaylistPage.js index b5c12cb5..2410e187 100644 --- a/frontend/src/static/js/pages/PlaylistPage.js +++ b/frontend/src/static/js/pages/PlaylistPage.js @@ -46,6 +46,11 @@ if (window.MediaCMS.site.devEnv) { } function PlayAllLink(props) { + + if (!props.media || !props.media.length) { + return {props.children}; + } + let playAllUrl = props.media[0].url; if (window.MediaCMS.site.devEnv && -1 < playAllUrl.indexOf('view?')) { diff --git a/static/js/playlist.js b/static/js/playlist.js index 5b6fa697..ef523fa1 100644 --- a/static/js/playlist.js +++ b/static/js/playlist.js @@ -1 +1 @@ -!function(){"use strict";var e,t={96081:function(e,t,n){var a=n(92541),i=(n(62322),n(49268),n(79006),n(55090),n(13233),n(59808),n(54458),n(52004),n(28407),n(56394),n(38288),n(55677),n(92129),n(24655),n(20288),n(23675),n(25101),n(13080),n(35466)),l=n(20541),r=n(43613),o=n(62546),s=n(98578),u=n(84234),c=n(17642),d=n(52819),p=n(80473),f=n(3074),m=n.n(f),y=n(67777);function g(e){return i.createElement(y.s,{items:e.media,playlistId:e.playlistId,hidePlaylistOptions:e.hidePlaylistOptions,singleLinkContent:!0,hideDate:!0,hideViews:!0,hidePlaylistOrderNumber:!1,horizontalItemsOrientation:!0,itemsCountCallback:e.itemsCountCallback,itemsLoadCallback:e.itemsLoadCallback,pageItems:99999,inPlaylistPage:!0})}function v(e){return(v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function h(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,a=new Array(t);ne.length)&&(t=e.length);for(var n=0,a=new Array(t);n div");v&&(v.innerHTML=j.summary)}}function D(e){if(void 0!==e&&void 0!==e.type)switch(e.type){case"network":case"private":case"unavailable":l(e.type),g(void 0!==e.message?e.message:"Αn error occurred while loading the media's data")}}return null!==U&&(T=t.media+"/"+U),(0,a.useEffect)((function(){null!==T&&(0,u.getRequest)(T,!1,q,D)}),[]),S.length?a.createElement("div",{className:"video-player"},a.createElement(p.Y7,{siteId:n.id,siteUrl:n.url,info:_,sources:S,poster:h,previewSprite:A,subtitlesInfo:C,enableAutoplay:!1,inEmbed:!1,hasTheaterMode:!1,hasNextLink:!1,hasPreviousLink:!1,errorMessage:y})):null}g.propTypes={pageLink:l().string.isRequired}},20541:function(e,t,n){var a=this&&this.__createBinding||(Object.create?function(e,t,n,a){void 0===a&&(a=n),Object.defineProperty(e,a,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,a){void 0===a&&(a=n),e[a]=t[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),l=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&a(t,e,n);return i(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.VideoViewerActions=t.SearchFieldActions=t.ProfilePageActions=t.PlaylistViewActions=t.PlaylistPageActions=t.PageActions=t.MediaPageActions=void 0,t.MediaPageActions=l(n(20979)),t.PageActions=l(n(76613)),t.PlaylistPageActions=l(n(75880)),t.PlaylistViewActions=l(n(29660)),t.ProfilePageActions=l(n(22472)),t.SearchFieldActions=l(n(52600)),t.VideoViewerActions=l(n(25464))},98578:function(e,t,n){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.VideoViewerStore=t.SearchFieldStore=t.ProfilePageStore=t.PlaylistViewStore=t.PlaylistPageStore=t.PageStore=t.MediaPageStore=void 0;var i=a(n(70337));t.MediaPageStore=i.default;var l=a(n(7959));t.PageStore=l.default;var r=a(n(71566));t.PlaylistPageStore=r.default;var o=a(n(71439));t.PlaylistViewStore=o.default;var s=a(n(78024));t.ProfilePageStore=s.default;var u=a(n(47359));t.SearchFieldStore=u.default;var c=a(n(45641));t.VideoViewerStore=c.default}},n={};function a(e){var i=n[e];if(void 0!==i)return i.exports;var l=n[e]={exports:{}};return t[e].call(l.exports,l,l.exports,a),l.exports}a.m=t,e=[],a.O=function(t,n,i,l){if(!n){var r=1/0;for(u=0;u=l)&&Object.keys(a.O).every((function(e){return a.O[e](n[s])}))?n.splice(s--,1):(o=!1,l0&&e[u-1][2]>l;u--)e[u]=e[u-1];e[u]=[n,i,l]},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,{a:t}),t},a.d=function(e,t){for(var n in t)a.o(t,n)&&!a.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},a.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.j=449,function(){var e={449:0};a.O.j=function(t){return 0===e[t]};var t=function(t,n){var i,l,r=n[0],o=n[1],s=n[2],u=0;for(i in o)a.o(o,i)&&(a.m[i]=o[i]);if(s)var c=s(a);for(t&&t(n);ue.length)&&(t=e.length);for(var n=0,a=new Array(t);ne.length)&&(t=e.length);for(var n=0,a=new Array(t);n div");v&&(v.innerHTML=j.summary)}}function D(e){if(void 0!==e&&void 0!==e.type)switch(e.type){case"network":case"private":case"unavailable":l(e.type),g(void 0!==e.message?e.message:"Αn error occurred while loading the media's data")}}return null!==U&&(T=t.media+"/"+U),(0,a.useEffect)((function(){null!==T&&(0,u.getRequest)(T,!1,q,D)}),[]),S.length?a.createElement("div",{className:"video-player"},a.createElement(p.Y7,{siteId:n.id,siteUrl:n.url,info:_,sources:S,poster:h,previewSprite:A,subtitlesInfo:C,enableAutoplay:!1,inEmbed:!1,hasTheaterMode:!1,hasNextLink:!1,hasPreviousLink:!1,errorMessage:y})):null}g.propTypes={pageLink:l().string.isRequired}},20541:function(e,t,n){var a=this&&this.__createBinding||(Object.create?function(e,t,n,a){void 0===a&&(a=n),Object.defineProperty(e,a,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,a){void 0===a&&(a=n),e[a]=t[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),l=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&a(t,e,n);return i(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.VideoViewerActions=t.SearchFieldActions=t.ProfilePageActions=t.PlaylistViewActions=t.PlaylistPageActions=t.PageActions=t.MediaPageActions=void 0,t.MediaPageActions=l(n(20979)),t.PageActions=l(n(76613)),t.PlaylistPageActions=l(n(75880)),t.PlaylistViewActions=l(n(29660)),t.ProfilePageActions=l(n(22472)),t.SearchFieldActions=l(n(52600)),t.VideoViewerActions=l(n(25464))},98578:function(e,t,n){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.VideoViewerStore=t.SearchFieldStore=t.ProfilePageStore=t.PlaylistViewStore=t.PlaylistPageStore=t.PageStore=t.MediaPageStore=void 0;var i=a(n(70337));t.MediaPageStore=i.default;var l=a(n(7959));t.PageStore=l.default;var r=a(n(71566));t.PlaylistPageStore=r.default;var o=a(n(71439));t.PlaylistViewStore=o.default;var s=a(n(78024));t.ProfilePageStore=s.default;var u=a(n(47359));t.SearchFieldStore=u.default;var c=a(n(45641));t.VideoViewerStore=c.default}},n={};function a(e){var i=n[e];if(void 0!==i)return i.exports;var l=n[e]={exports:{}};return t[e].call(l.exports,l,l.exports,a),l.exports}a.m=t,e=[],a.O=function(t,n,i,l){if(!n){var r=1/0;for(u=0;u=l)&&Object.keys(a.O).every((function(e){return a.O[e](n[s])}))?n.splice(s--,1):(o=!1,l0&&e[u-1][2]>l;u--)e[u]=e[u-1];e[u]=[n,i,l]},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,{a:t}),t},a.d=function(e,t){for(var n in t)a.o(t,n)&&!a.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},a.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.j=449,function(){var e={449:0};a.O.j=function(t){return 0===e[t]};var t=function(t,n){var i,l,r=n[0],o=n[1],s=n[2],u=0;for(i in o)a.o(o,i)&&(a.m[i]=o[i]);if(s)var c=s(a);for(t&&t(n);u