|
222 | 222 | $scope.updatedWithDelay = () => { |
223 | 223 | $timeout.cancel(validateTimeOut); |
224 | 224 | validateTimeOut = $timeout(() => { |
225 | | - ContentHome.validateRssLink(); |
| 225 | + ContentHome.fixChannelIdURL(); |
226 | 226 | }, 700); |
227 | 227 | }; |
228 | 228 |
|
| 229 | + ContentHome.fixChannelIdURL = function(){ |
| 230 | + if(ContentHome.rssLink){ |
| 231 | + Utils.fixChannelIdURL(ContentHome.rssLink, (err,res)=>{ |
| 232 | + if(err) console.error(err); |
| 233 | + if(res) return ContentHome.validateRssLink(res); |
| 234 | + |
| 235 | + return ContentHome.validateRssLink(ContentHome.rssLink); |
| 236 | + }); |
| 237 | + }; |
| 238 | + }; |
| 239 | + |
229 | 240 | // Function to validate youtube rss feed link entered by user. |
230 | 241 |
|
231 | | - ContentHome.validateRssLink = function() { |
232 | | - let isChannel = Utils.extractChannelId(ContentHome.rssLink); |
233 | | - let isVideo = Utils.extractSingleVideoId(ContentHome.rssLink); |
234 | | - let isPlaylist = Utils.extractPlaylistId(ContentHome.rssLink); |
| 242 | + ContentHome.validateRssLink = function(youtubeUrl){ |
| 243 | + if(!youtubeUrl) return ContentHome.fixChannelIdURL(); |
| 244 | + let isChannel = Utils.extractChannelId(youtubeUrl); |
| 245 | + let isVideo = Utils.extractSingleVideoId(youtubeUrl); |
| 246 | + let isPlaylist = Utils.extractPlaylistId(youtubeUrl); |
235 | 247 |
|
236 | 248 | if (isChannel) { |
237 | 249 | ContentHome.contentType = CONTENT_TYPE.CHANNEL_FEED; |
|
257 | 269 |
|
258 | 270 | switch (ContentHome.contentType) { |
259 | 271 | case CONTENT_TYPE.SINGLE_VIDEO: |
260 | | - var videoID = Utils.extractSingleVideoId(ContentHome.rssLink); |
| 272 | + var videoID = Utils.extractSingleVideoId(youtubeUrl); |
261 | 273 | if (videoID) { |
262 | 274 | $http |
263 | 275 | .get( |
|
302 | 314 | if (!$scope.$$phase) $scope.$apply(); |
303 | 315 | }); |
304 | 316 | } else { |
305 | | - if (Utils.extractChannelId(ContentHome.rssLink)) { |
| 317 | + if (Utils.extractChannelId(youtubeUrl)) { |
306 | 318 | ContentHome.failureMessage = |
307 | 319 | "Seems like you have entered feed url. Please choose correct option to validate url."; |
308 | 320 | } |
|
318 | 330 | } |
319 | 331 | break; |
320 | 332 | case CONTENT_TYPE.CHANNEL_FEED: |
321 | | - var feedIdAndType = Utils.extractChannelId(ContentHome.rssLink); |
| 333 | + var feedIdAndType = Utils.extractChannelId(youtubeUrl); |
322 | 334 | var feedApiUrl = null; |
323 | 335 | if (feedIdAndType) { |
324 | 336 | if (feedIdAndType.channel) |
|
377 | 389 | if (!$scope.$$phase) $scope.$apply(); |
378 | 390 | }); |
379 | 391 | } else { |
380 | | - if (Utils.extractSingleVideoId(ContentHome.rssLink)) { |
| 392 | + if (Utils.extractSingleVideoId(youtubeUrl)) { |
381 | 393 | ContentHome.failureMessage = |
382 | 394 | "Seems like you have entered single video url. Please choose correct option to validate url."; |
383 | 395 | } |
|
393 | 405 | } |
394 | 406 | break; |
395 | 407 | case CONTENT_TYPE.PLAYLIST_FEED: |
396 | | - var playlistId = Utils.extractPlaylistId(ContentHome.rssLink); |
| 408 | + var playlistId = Utils.extractPlaylistId(youtubeUrl); |
397 | 409 | if (playlistId) { |
398 | 410 | $http |
399 | 411 | .post(PROXY_SERVER.serverUrl + "/videos", { |
|
437 | 449 | if (!$scope.$$phase) $scope.$apply(); |
438 | 450 | }); |
439 | 451 | } else { |
440 | | - if (Utils.extractSingleVideoId(ContentHome.rssLink)) { |
| 452 | + if (Utils.extractSingleVideoId(youtubeUrl)) { |
441 | 453 | ContentHome.failureMessage = |
442 | 454 | "Seems like you have entered single video url. Please choose correct option to validate url."; |
443 | 455 | } |
|
0 commit comments