var combinePlugins = require('../').combinePlugins
var mapArtistTitle = require('../').mapArtistTitle

var separators = [
  ' -- ',
  '--',
  ' - ',
  ' – ',
  ' — ',
  ' _ ',
  '-',
  '–',
  '—',
  ':',
  '|',
  '///',
  ' / ',
  '_',
  '/'
]

// Most of this is taken from the YouTube connector in David Šabata's Last.fm
// web scrobbler: https://github.com/david-sabata/web-scrobbler

// Remove various versions of "MV" and "PV" markers
function cleanMVPV (string) {
  return string
    .replace(/\s*\[\s*([PM]\/?V)\s*\]/, '') // [MV] or [M/V]
    .replace(/\s*\(\s*([PM]\/?V)\s*\)/, '') // (MV) or (M/V)
    .replace(/\s*【\s*([PM]\/?V)\s*】/, '') // 【MV】 or 【M/V】
    .replace(/[\s\-–_]+([PM]\/?V)\s*/, '') // MV or M/V at the end
    .replace(/([PM]\/?V)[\s\-–_]+/, '') // MV or M/V at the start
}

function cleanFluff (string) {
  return cleanMVPV(string)
    .replace(/\s*\[[^\]]+\]$/, '') // [whatever] at the end
    .replace(/^\s*\[[^\]]+\]\s*/, '') // [whatever] at the start
    .replace(/\s*\([^\)]*\bver(\.|sion)?\s*\)$/i, '') // (whatever version)
    .replace(/\s*[a-z]*\s*\bver(\.|sion)?$/i, '') // ver. and 1 word before (no parens)
    .replace(/\s*(of+icial\s*)?(music\s*)?video/i, '') // (official)? (music)? video
    .replace(/\s*(ALBUM TRACK\s*)?(album track\s*)/i, '') // (ALBUM TRACK)
    .replace(/\s*\(\s*of+icial\s*\)/i, '') // (official)
    .replace(/\s*\(\s*[0-9]{4}\s*\)/i, '') // (1999)
    .replace(/\s+\(\s*(HD|HQ)\s*\)$/, '') // HD (HQ)
    .replace(/[\s\-–_]+(HD|HQ)\s*$/, '') // HD (HQ)
}

function cleanTitle (title) {
  return cleanFluff(title.trim())
    .replace(/\s*\*+\s?\S+\s?\*+$/, '') // **NEW**
    .replace(/\s*video\s*clip/i, '') // video clip
    .replace(/\s+\(?live\)?$/i, '') // live
    .replace(/\(\s*\)/, '') // Leftovers after e.g. (official video)
    .replace(/\[\s*\]/, '') // Leftovers after e.g. [1080p]
    .replace(/【\s*】/, '') // Leftovers after e.g. 【MV】
    .replace(/^(|.*\s)"(.*)"(\s.*|)$/, '$2') // Artist - The new "Track title" featuring someone
    .replace(/^(|.*\s)'(.*)'(\s.*|)$/, '$2') // 'Track title'
    .replace(/^[\/\s,:;~\-–_\s"]+/, '') // trim starting white chars and dash
    .replace(/[\/\s,:;~\-–_\s"]+$/, '') // trim trailing white chars and dash
}

function cleanArtist (artist) {
  return cleanFluff(artist.trim())
    .replace(/\s*[0-1][0-9][0-1][0-9][0-3][0-9]\s*/, '') // date formats ex. 130624
    .replace(/^[\/\s,:;~\-–_\s"]+/, '') // trim starting white chars and dash
    .replace(/[\/\s,:;~\-–_\s"]+$/, '') // trim trailing white chars and dash
}

function splitArtistTitle (str) {
  for (var i = 0, l = separators.length; i < l; i++) {
    var sep = separators[i]
    var idx = str.indexOf(sep)
    if (idx > -1) {
      return [ str.slice(0, idx), str.slice(idx + sep.length) ]
    }
  }
}

exports.separators = separators
var plugin = combinePlugins([
  require('./remove-file-extension'),
  { before: cleanFluff,
    split: splitArtistTitle,
    after: mapArtistTitle(cleanArtist, cleanTitle) },
  require('./quoted-title'),
  require('./common-fluff')
])
exports.before = plugin.before
exports.split = plugin.split
exports.after = plugin.after

@@ -514,17 +514,16 @@
 %5C/?V)%5Cs*
-%5C
 %5D/, '') 
@@ -539,16 +539,16 @@
 r %5BM/V%5D%0A
+
     .rep
@@ -878,17 +878,16 @@
 %5C%5B%5B%5E%5C%5D%5D+
-%5C
 %5D$/, '')
@@ -938,17 +938,16 @@
 %5C%5B%5B%5E%5C%5D%5D+
-%5C
 %5D%5Cs*/, '
@@ -997,17 +997,16 @@
 /%5Cs*%5C(%5B%5E
-%5C
 )%5D*%5Cbver
@@ -1815,17 +1815,16 @@
 e(/%5C%5B%5Cs*
-%5C
 %5D/, '') 
@@ -2077,33 +2077,32 @@
     .replace(/%5E%5B
-%5C
 /%5Cs,:;~%5C-%E2%80%93_%5Cs%22%5D+
@@ -2153,33 +2153,32 @@
 %0A    .replace(/%5B
-%5C
 /%5Cs,:;~%5C-%E2%80%93_%5Cs%22%5D+
@@ -2393,17 +2393,16 @@
 lace(/%5E%5B
-%5C
 /%5Cs,:;~%5C
@@ -2469,17 +2469,16 @@
 place(/%5B
-%5C
 /%5Cs,:;~%5C

remove unnecessary escapes