const express       = require('express')
const google        = require('googleapis')
const router        = express.Router()
const youtube       = google.youtube('v3')
const defaultConfig = require('../config')
const featured      = require('../data/featured_playlists.js')

router.get('/:id', (req, res) => {
  const videos = []
  var title, description, player

  if (featured.indexOf(req.params.id) == -1) {
    return 'Error'
  }

  // Get config object ready for this request
  var config = Object.assign({
    part: 'snippet,contentDetails',
    playlistId: req.params.id,
    maxResults: 20
  }, defaultConfig)

  youtube.playlists.list(config, (err, playlists) => {
    const series = playlists.items.filter((item) => {
      return item.id == req.params.id
    })

    title = series[0].snippet.title
    description = series[0].snippet.description

    youtube.playlistItems.list(config, (err, playlist) => {
      playlist.items.map((item) => {
        videos.push({
          id: item.contentDetails.videoId,
          title: item.snippet.title,
          description: item.snippet.description
        })
      })

      // Get config object ready for this request
      config = Object.assign({
        id: videos[0].id,
        part: 'player'
      }, defaultConfig)

      youtube.videos.list(config, (err, vids) => {
        player = vids.items.map((video) => {
          return video.player.embedHtml
        })

        res.render('playlist', {
          title: 'Nodecasts',
          message: title,
          videos: videos,
          description: description,
          player: player
        })
      })
    })
  })
})

module.exports = router

@@ -206,71 +206,8 @@
 ig')
-%0Aconst featured      = require('../data/featured_playlists.js')
 %0A%0Aro
@@ -297,79 +297,8 @@
 er%0A%0A
-  if (featured.indexOf(req.params.id) == -1) %7B%0A    return 'Error'%0A  %7D%0A%0A
   //

fix bug from playlists