为了账号安全,请及时绑定邮箱和手机立即绑定

从/ r / listenToThis解析歌曲标题以获取IFTTT小程序

从/ r / listenToThis解析歌曲标题以获取IFTTT小程序

拉丁的传说 2021-05-10 12:13:09
我有一系列的歌曲名称,来自这个subreddit,看起来像这样:[  "Lophelia -- MYTCH [Acoustic Prog-Rock/Jazz] (2019)",  "Julia Jacklin - Pressure to Party [Rock] (2019)",  "The Homeless Gospel Choir - I'm Going Home [Folk-Punk] (2019) cover of Pat the Bunny | A Fistful of Vinyl",  "Lea Salonga and Simon Bowman - The last night of the world [musical] (1990)",  "$uicideboy$ - Death",  "SNFU -- Joni Mitchell Tapes [Punk/Alternative] (1993)",  "Blab - afdosafhsd (2000)",  "Something strange and badly formatted without any artist [Classical]",  "シロとクロ「ミッドナイトにグッドナイト」(Goodnight to Midnight - Shirotokuro) - (Official Music Video) [Indie/Alternative]",  "Victor Love - Irrationality (feat. Spiritual Front) [Industrial Rock/Cyberpunk]"  ...]我正在尝试从他们那里解析标题和艺术家,但是我真的在正则表达式方面苦苦挣扎。我尝试使用来拆分它,"-"但是仅在之后获得艺术家真的很烦人。我也尝试过使用正则表达式,但实际上无法正常工作。这就是我给艺术家的东西:/(?<= -{1,2} )[\S ]*(?= \[|\( )/i 和标题:的东西/[\S ]*(?= -{1,2} )/i。每个条目都是一首歌的标题。在歌曲标题之前,可能是歌曲的艺术家,然后是一两个(或三个)破折号。然后,可以在方括号中添加类型,在括号中添加发行日期。我不期望完美的准确性,某些格式可能很奇怪,在那种情况下,我宁愿artist是未定义的,而不是一些奇怪的解析。举个例子:[  { title: "MYTCH", artist: "Lophelia" },  { title: "Pressure to Party", artist: "Julia Jacklin" },  { title: "I'm Going Home", artist: "The homeless Gospel Choir" },  { title: "The last night of the world", artist: "Lea Salonga and Simon Bowman" },  { title: "Death", artist: "$uicideboy$" },  { title: "Joni Mitchell Tapes", artist: "SNFU" },  { title: "afdosafhsd", artist: "Blab" },  { title: "Something strange and badly formatted without any artist" },  { title: "Goodnight to midnight", artist: "shirotokuro" }, // Probably impossible with some kind of AI  { title: "Irrationality" artist: "Victor Love" }]
查看完整描述

2 回答

?
慕尼黑5688855

TA贡献1848条经验 获得超2个赞

您可以执行以下操作:


const songs = [

  "Lophelia -- MYTCH [Acoustic Prog-Rock/Jazz] (2019)",

  "Julia Jacklin - Pressure to Party [Rock] (2019)",

  "The Homeless Gospel Choir - I'm Going Home [Folk-Punk] (2019) cover of Pat the Bunny | A Fistful of Vinyl",

  "Lea Salonga and Simon Bowman - The last night of the world [musical] (1990)",

  "Lophelia -- MYTCH [Acoustic Prog-Rock/Jazz]",

  "Death - $uicideboy$",

  "SNFU -- Joni Mitchell Tapes [Punk/Alternative] (1993)",

  "Title - Aritst (2000)",

  "Something strange and badly formatted without any artist [Classical]",

];


const trailingRgx = /\s*((\[[^\]]+\])|(\(\d+\))).*$/;


const details = songs.map(song => {

  const splitted = song.split(/\s+\-+\s+/);

  let title = splitted[0];

  let artist = splitted[1];

  if (splitted.length >= 2) {

    artist = artist.replace(trailingRgx, '');

  } else {

    title = title.replace(trailingRgx, '');

  }

  return {

    title,

    artist

  }

});

console.log(details);


查看完整回答
反对 回复 2021-05-27
  • 2 回答
  • 0 关注
  • 163 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信