<commit_before>import _ from 'lodash';
import ytdl from 'ytdl-core';

import MusicSourcePlugin from '../musicSources';
import * as Youtube from '../../rest/Youtube';

class YoutubePlugin extends MusicSourcePlugin {
  constructor() {
    super();
    this.name = 'Youtube Plugin';
    this.sourceName = 'Youtube';
    this.description = 'A plugin allowing Nuclear to search for music and play it from youtube';
  }

  search(terms) {
    return Youtube.trackSearch(terms)
      .then(results => results.json())
      .then(results => {
        let song = _.head(results.items);
        let id = song.id.videoId;
        return ytdl.getInfo(`http://www.youtube.com/watch?v=${id}`);
      })
      .then(videoInfo => {
        let formatInfo = _.head(videoInfo.formats.filter(e => e.itag === '140'));
        return {
          source: this.sourceName,
          id: videoInfo.video_id,
          stream: formatInfo.url,
          duration: videoInfo.length_seconds,
          title: videoInfo.title,
          thumbnail: videoInfo.thumbnail_url
        };
      });
  }

  getAlternateStream(terms, currentStream) {
    return Youtube.trackSearch(terms)
      .then(results => results.json())
      .then(results => {
        let song = _(results.items).find(item => {
          return item && item.id.videoId !== currentStream.id;
        });
        let id = song.id.videoId;
        return ytdl.getInfo(`http://www.youtube.com/watch?v=${id}`);
      })
      .then(videoInfo => {
        let formatInfo = _.head(videoInfo.formats.filter(e => e.itag=='140'));
        return {
          source: 'Youtube',
          id: videoInfo.video_id,
          stream: formatInfo.url,
          duration: videoInfo.length_seconds,
          title: videoInfo.title,
          thumbnail: videoInfo.thumbnail_url
        };<commit_msg>Code quality : == to ===<commit_after>import _ from 'lodash';
import ytdl from 'ytdl-core';

import MusicSourcePlugin from '../musicSources';
import * as Youtube from '../../rest/Youtube';

class YoutubePlugin extends MusicSourcePlugin {
  constructor() {
    super();
    this.name = 'Youtube Plugin';
    this.sourceName = 'Youtube';
    this.description = 'A plugin allowing Nuclear to search for music and play it from youtube';
  }

  search (terms) {
    return Youtube.trackSearch(terms)
      .then(results => results.json())
      .then(results => {
        let song = _.head(results.items);
        let id = song.id.videoId;
        return ytdl.getInfo(`http://www.youtube.com/watch?v=${id}`);
      })
      .then(videoInfo => {
        let formatInfo = _.head(videoInfo.formats.filter(e => e.itag === '140'));
        return {
          source: this.sourceName,
          id: videoInfo.video_id,
          stream: formatInfo.url,
          duration: videoInfo.length_seconds,
          title: videoInfo.title,
          thumbnail: videoInfo.thumbnail_url
        };
      });
  }

  getAlternateStream (terms, currentStream) {
    return Youtube.trackSearch(terms)
      .then(results => results.json())
      .then(results => {
        let song = _(results.items).find(item => {
          return item && item.id.videoId !== currentStream.id;
        });
        let id = song.id.videoId;
        return ytdl.getInfo(`http://www.youtube.com/watch?v=${id}`);
      })
      .then(videoInfo => {
        let formatInfo = _.head(videoInfo.formats.filter(e => e.itag === '140'));
        return {
          source: 'Youtube',
          id: videoInfo.video_id,
          stream: formatInfo.url,
          duration: videoInfo.length_seconds,
          title: videoInfo.title,
          thumbnail: videoInfo.thumbnail_url
        };
{'fraction_non_alphanumeric': 0.13860032804811373, 'fraction_numerical': 0.0032804811372334607, 'mean_word_length': 2.332422586520947, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5924398', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1076, 'n_words': 228}