@@ -2,6 +2,13 @@ var youmax_global_options = {};
22
33
44( function ( $ ) {
5+ prepareYoumax = function ( ) {
6+ $ ( '#youmax' ) . empty ( ) ;
7+ loadYoumax ( ) ;
8+ showLoader ( ) ;
9+ getUploads ( ) ;
10+ }
11+
512 loadYoumax = function ( ) {
613 ym = $ ( '#youmax' ) ;
714 youmaxWidgetWidth = ym . width ( ) ;
@@ -21,38 +28,6 @@ var youmax_global_options = {};
2128 $ ( '#youmax-lightbox' ) . hide ( ) ;
2229 } ,
2330
24- getChannelId = function ( apiUrl ) {
25-
26- $ . ajax ( {
27- url : apiUrl ,
28- type : "GET" ,
29- async : true ,
30- cache : true ,
31- dataType : 'jsonp' ,
32- success : function ( response ) {
33- youmaxChannelId = response . items [ 0 ] . id
34- getChannelDetails ( youmaxChannelId ) ;
35- } ,
36- error : function ( html ) { alert ( html ) ; } ,
37- beforeSend : setHeader
38- } ) ;
39- } ,
40-
41- getChannelDetails = function ( channelId ) {
42- var apiProfileURL = "https://www.googleapis.com/youtube/v3/channels?part=brandingSettings%2Csnippet%2Cstatistics%2CcontentDetails&id=" + channelId + "&key=" + youmax_global_options . apiKey ;
43-
44- $ . ajax ( {
45- url : apiProfileURL ,
46- type : "GET" ,
47- async : true ,
48- cache : true ,
49- dataType : 'jsonp' ,
50- success : function ( response ) { showInfo ( response ) ; } ,
51- error : function ( html ) { alert ( html ) ; } ,
52- beforeSend : setHeader
53- } ) ;
54- } ,
55-
5631 setHeader = function ( xhr ) {
5732 if ( xhr && xhr . overrideMimeType ) {
5833 xhr . overrideMimeType ( "application/j-son;charset=UTF-8" ) ;
@@ -99,16 +74,8 @@ var youmax_global_options = {};
9974
10075 } ,
10176
102- showUploads = function ( response , playlistTitle , loadMoreFlag ) {
103-
104- if ( ! loadMoreFlag ) {
105- $ ( '#youmax-video-list-div' ) . empty ( ) ;
106-
107- if ( playlistTitle ) {
108- $ ( '.youmax-tab-hover' ) . removeClass ( 'youmax-tab-hover' ) ;
109- $ ( '#youmax-video-list-div' ) . append ( '<span class="youmax-showing-title youmax-tab-hover" id="uploads_' + response . items [ 0 ] . snippet . playlistId + '" style="max-width:100%;"><span class="youmax-showing"> Showing playlist: </span>' + playlistTitle + '</span><br/>' ) ;
110- }
111- }
77+ showUploads = function ( response ) {
78+ $ ( '#youmax-video-list-div' ) . empty ( ) ;
11279
11380 var nextPageToken = response . nextPageToken ;
11481 var $youmaxLoadMoreDiv = $ ( '#youmax-load-more-div' ) ;
@@ -124,7 +91,7 @@ var youmax_global_options = {};
12491 var videoIdArray = [ ] ;
12592
12693 for ( var i = 0 ; i < uploadsArray . length ; i ++ ) {
127- videoId = uploadsArray [ i ] . snippet . resourceId . videoId ;
94+ videoId = uploadsArray [ i ] . id . videoId ;
12895 videoTitle = uploadsArray [ i ] . snippet . title ;
12996 videoUploaded = uploadsArray [ i ] . snippet . publishedAt ;
13097 videoThumbnail = uploadsArray [ i ] . snippet . thumbnails . medium . url ;
@@ -136,68 +103,22 @@ var youmax_global_options = {};
136103 youmax_global_options . youmaxItemCount += uploadsArray . length ;
137104 } ,
138105
139- getUploads = function ( youmaxTabId , playlistTitle , nextPageToken ) {
140- var pageTokenUrl = "" ;
141- var loadMoreFlag = false ;
142-
143- if ( null != nextPageToken ) {
144- pageTokenUrl = "&pageToken=" + nextPageToken ;
145- loadMoreFlag = true ;
146- }
147-
148- var uploadsPlaylistId = youmaxTabId . substring ( youmaxTabId . indexOf ( '_' ) + 1 ) ;
149- var apiUploadURL = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=" + uploadsPlaylistId + "&maxResults=" + youmax_global_options . maxResults + pageTokenUrl + "&key=" + youmax_global_options . apiKey ;
106+ getUploads = function ( ) {
107+ let channelId = youmax_global_options . youTubeChannelURL . split ( '/' ) . pop ( ) ;
108+ var apiUploadURL = "https://www.googleapis.com/youtube/v3/search?key=" + youmax_global_options . apiKey + "&channelId=" + channelId + "&part=snippet,id&order=date&maxResults=" + youmax_global_options . maxResults ;
150109
151110 $ . ajax ( {
152111 url : apiUploadURL ,
153112 type : "GET" ,
154113 async : true ,
155114 cache : true ,
156115 dataType : 'jsonp' ,
157- success : function ( response ) { showUploads ( response , playlistTitle , loadMoreFlag ) ; } ,
116+ success : function ( response ) { showUploads ( response ) ; } ,
158117 error : function ( html ) { alert ( html ) ; } ,
159118 beforeSend : setHeader
160119 } ) ;
161120 } ,
162121
163- prepareYoumax = function ( ) {
164- $ ( '#youmax' ) . empty ( ) ;
165- loadYoumax ( ) ;
166- showLoader ( ) ;
167-
168- $ ( '.youmax-tab' ) . click ( function ( ) {
169- $ ( '.youmax-tab-hover' ) . removeClass ( 'youmax-tab-hover' ) ;
170- $ ( this ) . addClass ( 'youmax-tab-hover' ) ;
171- youmaxTabId = this . id ;
172- showLoader ( ) ;
173- getUploads ( youmaxTabId ) ;
174- } ) ;
175-
176- youTubeChannelURL = youmax_global_options . youTubeChannelURL ;
177- console . log ( youTubeChannelURL ) ;
178-
179-
180- if ( youTubeChannelURL != null ) {
181- s = youTubeChannelURL . indexOf ( "/user/" ) ;
182- if ( s != - 1 ) {
183- userId = youTubeChannelURL . substring ( s + 6 ) ;
184- apiUrl = "https://www.googleapis.com/youtube/v3/channels?part=id&forUsername=" + userId + "&key=" + youmax_global_options . apiKey ;
185- getChannelId ( apiUrl ) ;
186- } else {
187- s = youTubeChannelURL . indexOf ( "/channel/" ) ;
188- if ( s != - 1 ) {
189- youmaxChannelId = youTubeChannelURL . substring ( s + 9 ) ;
190- youmax_global_options . youmaxChannelId = youmaxChannelId ;
191- getChannelDetails ( youmaxChannelId ) ;
192- } else {
193- alert ( "Could Not Find Channel.." ) ;
194- }
195- }
196- }
197-
198- }
199-
200-
201122 $ . fn . youmax = function ( options ) {
202123 //set local options
203124 youmax_global_options . apiKey = options . apiKey ;
@@ -213,6 +134,4 @@ var youmax_global_options = {};
213134 youmax_global_options . youtubeMqdefaultAspectRatio = 300 / 180 ;
214135 prepareYoumax ( ) ;
215136 } ;
216-
217-
218137} ( jQuery ) ) ;
0 commit comments