Compare commits

...

1 Commits
main ... main

Author SHA1 Message Date
paxt82 a9c92b850a Upload files to 'paxt002' 3 months ago
  1. 109
      paxt002/findLyrics.js
  2. 224
      paxt002/findVideo.js
  3. 40
      paxt002/guessTrackFromString.js
  4. 2395
      paxt002/index.js
  5. 211
      paxt002/test.js

109
paxt002/findLyrics.js

@ -0,0 +1,109 @@
const expect = require('chai').expect;
const alltomp3 = require('..');
const _ = require('lodash');
/**
* Lyrics uses 5 or 6 different websites,
* and the first to answer is the one chosen.
* So it is absolutely non determinist, and
* these tests are repeated 5 times.
* Moreover lyrics varies depending on the website,
* and can sometimes be wrong...
*/
describe('findLyrics', () => {
for (let i = 0; i < 5; i += 1) {
it('should find lyrics for Imagine Dragons - On Top of the World', (done) => {
alltomp3.findLyrics('On Top of the World', 'Imagine Dragons').then((lyrics) => {
lyrics = _.kebabCase(lyrics);
expect(lyrics).to.match(/^if-you-love-somebody-better-tell-them-while-theyre-here/);
expect(lyrics).to.match(/(when-you-hit-the-ground-get-up-now-get-up-get-up-now)|(i-can-been-dreaming-of-this-since-a-child-im-on-top-of-the-world)$/);
done();
});
});
it('should find lyrics for Pauline Croze - T\'es Beau', (done) => {
alltomp3.findLyrics('T\'es beau', 'Pauline Croze').then((lyrics) => {
lyrics = _.kebabCase(lyrics);
expect(lyrics).to.match(/tes-beau-parce-que-tes-courageux-de-regarder-dans-le-fond-des-yeux-celui-qui-te-defie-detre-heureux/);
expect(lyrics).to.match(/jai-peur-doublier-jai-peur-daccepter-jai-peur-des-vivants-a-present-tes-beau$/);
done();
});
});
it('should find lyrics for M - Mama Sam', (done) => {
alltomp3.findLyrics('Mama Sam', 'M').then((lyrics) => {
lyrics = _.kebabCase(lyrics);
expect(lyrics).to.match(/^quand-je-te-revois-mama-sam-je-retrouve-les-vraies-valeurs/);
expect(lyrics).to.match(/non-je-ne-connais-pas-l-afrique-aigrie-est-ma-couleur-de-peau-la-vie-est-une-machine-a-fric-ou-les-affreux-non(t?)-pas-dafro$/);
done();
});
});
it('should find lyrics for Coldplay - Viva la Vida', (done) => {
alltomp3.findLyrics('Viva la Vida', 'Coldplay').then((lyrics) => {
lyrics = _.kebabCase(lyrics);
expect(lyrics).to.match(/^i-used-to-rule-the-world-seas-would-rise-when-i-gave-the-word/);
expect(lyrics).to.match(/for-some-reason-i-cant-explain-i-know-saint-peter-wont-call-my-name-never-an-honest-word-but-that-was-when-i-ruled-the-world/);
done();
});
});
it('should find lyrics for HYPHEN HYPHEN - Cause I Got A Chance', (done) => {
alltomp3.findLyrics('Cause I Got A Chance', 'HYPHEN HYPHEN').then((lyrics) => {
lyrics = _.kebabCase(lyrics);
expect(lyrics).to.match(/^tonight-i-dont-wanna-cry-tonight-i-want-you-to-dance-with-me-tonight/);
expect(lyrics).to.match(/ive-been-waiting-for-so-long-knew-you-always-thought-about-always-thought-about-me$/);
done();
});
});
it('should find lyrics for Calvin Harris - The Rain', (done) => {
alltomp3.findLyrics('The Rain', 'Calvin Harris').then((lyrics) => {
lyrics = _.kebabCase(lyrics);
expect(lyrics).to.match(/^shes-the-type-of-girl-that-makes-you-feel-better/);
expect(lyrics).to.match(/these-are-the-good-times-in-your-life-so-put-on-a-smile-and-itll-be-((alright)|(all-right))/);
done();
});
});
it('should find lyrics for Sam Smith - Writing\'s on the Wall', (done) => {
alltomp3.findLyrics('Writing\'s on the Wall', 'Sam Smith').then((lyrics) => {
lyrics = _.kebabCase(lyrics);
expect(lyrics).to.match(/^ive-been-here-before-but-always-hit-the-floor-ive-spent-a-lifetime-running-and-i-always-get-away/);
expect(lyrics).to.match(/where-i-give-it-all-up-for-you-i-have-to-risk-it-all-cause-the-writings-on-the-wall$/);
done();
});
});
it('should find lyrics for C2C - Down The Road', (done) => {
alltomp3.findLyrics('Down The Road', 'C2C').then((lyrics) => {
lyrics = _.kebabCase(lyrics);
expect(lyrics).to.match(/have-no-place-to-go-have-no-place-to-go-darling/);
expect(lyrics).to.match(/when-that-train-rolls-up-and-i-come-walking-out/);
done();
});
});
it('should find lyrics for Galantis - Runaway (U & I)', (done) => {
alltomp3.findLyrics('Runaway (U & I)', 'Galantis').then((lyrics) => {
lyrics = _.kebabCase(lyrics);
expect(lyrics).to.match(/think-i-can-fly-think-i-can-fly-when-im-with-u/);
expect(lyrics).to.match(/i-know-that-im-rich-enough-for-pride-i-see-a-billion-dollars-in-your-eyes-even-if-were-strangers/);
done();
});
});
it('should find lyrics for Mika - Elle me dit', (done) => {
alltomp3.findLyrics('Elle me dit', 'Mika').then((lyrics) => {
lyrics = _.kebabCase(lyrics);
expect(lyrics).to.match(/elle-me-dit-ecris-une-chanson-contente-pas-une-chanson-deprimante-une-chanson-que-tout-l((e-)?)monde-aime/);
expect(lyrics).to.match(/pourquoi-tu-gaches-ta-vie-pourquoi-tu-gaches-ta-vie/);
expect(lyrics).to.match(/regarde-un-peu-tes-amis-quest-c((e-)?)quils-vont-faire-de-leur-vie/);
done();
});
});
}
});

224
paxt002/findVideo.js

@ -0,0 +1,224 @@
const expect = require('chai').expect;
const alltomp3 = require('..');
const _ = require('lodash');
function testTracks(tracks, artistName) {
let queries = [];
_.forEach(tracks, t => {
t.song.artistName = artistName;
let q = alltomp3.findVideoForSong(t.song).then(v => {
if (t.videos.indexOf(v[0].url) === -1) {
console.log(t.song.title, v);
}
expect(t.videos).to.include(v[0].url);
});
queries.push(q);
});
return Promise.all(queries);
}
describe('findVideo', function() {
it('should find YouTube videos for Broken Back by Broken Back', function () {
this.timeout(20000);
let artistName = "Broken Back";
let tracks = [
{
song: {
title: "Excuses",
duration: 224
},
videos: ['https://www.youtube.com/watch?v=aBp7s6BpmrM', 'https://www.youtube.com/watch?v=Ogsfvvwu-wU', 'https://www.youtube.com/watch?v=upUWTD6x3dw']
},
{
song: {
title: "Halcyon Birds (Radio Edit)",
duration: 197
},
videos: ['https://www.youtube.com/watch?v=xWlXEGIol9E', 'https://www.youtube.com/watch?v=EGSqjTixIyk', 'https://www.youtube.com/watch?v=gzZ43IEJ8S0', 'https://www.youtube.com/watch?v=2Ggu0m0a8WA', 'https://www.youtube.com/watch?v=5eS1WxW4GM4']
},
{
song: {
title: "Better Run",
duration: 176
},
videos: ['https://www.youtube.com/watch?v=oEugd8BV_Bs', 'https://www.youtube.com/watch?v=5QP8K42-wA8'],
},
{
song: {
title: "Happiest Man on Earth (Radio Edit)",
duration: 183
},
videos: ['https://www.youtube.com/watch?v=j01T8N7wVK0', 'https://www.youtube.com/watch?v=TqpM_0_H6Qc'],
},
{
song: {
title: "Got to Go",
duration: 218
},
videos: ['https://www.youtube.com/watch?v=A2iBEZBxT3s', 'https://www.youtube.com/watch?v=MXABmCs5Fkc']
},
// This last one is currently too hard
// {
// title: "Young Souls (Album Edit) - Broken Back",
// videos: ['https://www.youtube.com/watch?v=LT9kwbunzWc']
// }
];
return testTracks(tracks, artistName);
});
it('should find YouTube videos for Night Visions by Imagine Dragons', function () {
this.timeout(20000);
let artistName = "Imagine Dragons";
let tracks = [
{
"song": {
"title": "Radioactive",
"duration": 186
},
"videos": ['https://www.youtube.com/watch?v=ktvTqknDobU', 'https://www.youtube.com/watch?v=iO_WxYC34eM', 'https://www.youtube.com/watch?v=Thbsg9i2mZ0', 'https://www.youtube.com/watch?v=y_8Mgn30xRU']
},
{
"song": {
"title": "Tiptoe",
"duration": 194
},
"videos": ['https://www.youtube.com/watch?v=ajjj4pLnjz8', 'https://www.youtube.com/watch?v=UB96k1arlTk', 'https://www.youtube.com/watch?v=211bk6ctXM4', 'https://www.youtube.com/watch?v=zmKv2Aok1Mw']
},
{
"song": {
"title": "It's Time",
"duration": 240
},
"videos": ['https://www.youtube.com/watch?v=sENM2wA_FTg', 'https://www.youtube.com/watch?v=IOatp-OCw3E', 'https://www.youtube.com/watch?v=qFqMy0ewYFQ']
},
{
"song": {
"title": "Demons",
"duration": 177
},
"videos": ['https://www.youtube.com/watch?v=mWRsgZuwf_8', 'https://www.youtube.com/watch?v=GFQYaoiIFh8', 'https://www.youtube.com/watch?v=LqI78S14Wgg', 'https://www.youtube.com/watch?v=lxUXvOUKM_Q']
},
{
"song": {
"title": "On Top Of The World",
"duration": 192
},
"videos": ['https://www.youtube.com/watch?v=w5tWYmIOWGk', 'https://www.youtube.com/watch?v=g8PrTzLaLHc', 'https://www.youtube.com/watch?v=Nwvil057g-g', 'https://www.youtube.com/watch?v=e74VMNgARvY']
},
{
"song": {
"title": "Amsterdam",
"duration": 241
},
"videos": ['https://www.youtube.com/watch?v=TKtPXO5iEnA', 'https://www.youtube.com/watch?v=s6Nc4qEI3k4', 'https://www.youtube.com/watch?v=dboQYGddEC8', 'https://www.youtube.com/watch?v=j-tfNaBcyes']
},
{
"song": {
"title": "Hear Me",
"duration": 235
},
"videos": ['https://www.youtube.com/watch?v=1Yr683VLxes', 'https://www.youtube.com/watch?v=EkB2eJfF3W8', 'https://www.youtube.com/watch?v=u0Q3r4ywA34']
},
{
"song": {
"title": "Every Night",
"duration": 217
},
"videos": ['https://www.youtube.com/watch?v=6RVxzeBiBJU', 'https://www.youtube.com/watch?v=kuijhOvKyYg', 'https://www.youtube.com/watch?v=f6CQ3ATP_6Y', 'https://www.youtube.com/watch?v=k4ESylzBW4M']
},
{
"song": {
"title": "Bleeding Out",
"duration": 223
},
"videos": ['https://www.youtube.com/watch?v=jNFgynmVmx0', 'https://www.youtube.com/watch?v=gJEoxeW7JvQ', 'https://www.youtube.com/watch?v=Hq6kn87NpKw', 'https://www.youtube.com/watch?v=Tyjt1Ff4m7k']
},
{
"song": {
"title": "Underdog",
"duration": 209
},
"videos": ['https://www.youtube.com/watch?v=JCUV43T7HZ0', 'https://www.youtube.com/watch?v=USeEyhodZqk', 'https://www.youtube.com/watch?v=KoX80w5b8ps', 'https://www.youtube.com/watch?v=m4SBGLtJvPo', 'https://www.youtube.com/watch?v=2RQRoTvXXiw']
},
{
"song": {
"title": "Nothing Left To Say / Rocks (Medley)",
"duration": 537
},
"videos": ['https://www.youtube.com/watch?v=Bn7eYibzmTs', 'https://www.youtube.com/watch?v=bSBkYqbdOKc', 'https://www.youtube.com/watch?v=B4z7loNm_kw', 'https://www.youtube.com/watch?v=Q6zqH6qKaTU', 'https://www.youtube.com/watch?v=zCqHNBleR6M']
},
{
"song": {
"title": "Cha-Ching (Till We Grow Older)",
"duration": 249
},
"videos": ['https://www.youtube.com/watch?v=rmqyXQf8jkU', 'https://www.youtube.com/watch?v=vhSvfxtlUQc', 'https://www.youtube.com/watch?v=wO0ohGn-x3E', 'https://www.youtube.com/watch?v=IgC8yZpMRqc', 'https://www.youtube.com/watch?v=zTingWDAAts']
},
{
"song": {
"title": "Working Man",
"duration": 235
},
"videos": ['https://www.youtube.com/watch?v=m4SBGLtJvPo', 'https://www.youtube.com/watch?v=2d-GIw-pBMs', 'https://www.youtube.com/watch?v=NARf6QW3KYA', 'https://www.youtube.com/watch?v=31YTMhD4NYs', 'https://www.youtube.com/watch?v=mhXoXYbmCz4', 'https://www.youtube.com/watch?v=2d-GIw-pBMs', 'https://www.youtube.com/watch?v=aW8_7M8e5CQ']
}
];
return testTracks(tracks, artistName);
});
// Failed, but the videos it finds are unavailable
// Should update testTracks() so it checks if the video is available or not
// it('should find YouTube videos for Night Shift (Original Mix) by Overwerk', function () {
// this.timeout(10000);
//
// let artistName = "Overwerk";
// let tracks = [
// {
// song: {
// title: "Night Shift (Original Mix)",
// duration: 541
// },
// videos: ['https://www.youtube.com/watch?v=SI2wnEvrepM', 'https://www.youtube.com/watch?v=87bCbQHez9k', 'https://www.youtube.com/watch?v=dtq9NNLa1O8']
// },
// {
// song: {
// title: "Last Call (Original Mix)",
// duration: 600
// },
// videos: ['https://www.youtube.com/watch?v=4C9LACMJFT4', 'https://www.youtube.com/watch?v=eQMXBaB0Ehs', 'https://www.youtube.com/watch?v=RzKCHDgQZ9g']
// }
// ];
//
// return testTracks(tracks, artistName);
// });
it('should find YouTube videos for single letter artist M', function () {
this.timeout(10000);
// It's a French song
alltomp3.regionCode = 'FR';
let artistName = "M";
let tracks = [
{
song: {
title: "Je dis aime",
duration: 236
},
videos: ['https://www.youtube.com/watch?v=6hV-UnrC9tU', 'https://www.youtube.com/watch?v=QYWV67qgHvg', 'https://www.youtube.com/watch?v=ORam68OtcmY']
},
{
song: {
title: "Mama Sam",
duration: 195
},
videos: ['https://www.youtube.com/watch?v=avZTCTR6e9k', 'https://www.youtube.com/watch?v=HRez3YiXxJw']
}
];
return testTracks(tracks, artistName);
});
});

40
paxt002/guessTrackFromString.js

@ -0,0 +1,40 @@
const expect = require('chai').expect;
const alltomp3 = require('..');
const _ = require('lodash');
describe('guessTrackFromString', function() {
it('should guess the right track', function () {
this.timeout(20000);
let queries = [
{
q: "Kungs vs Cookin’ on 3 Burners - This Girl",
title: "This Girl (Kungs Vs. Cookin' On 3 Burners)",
a: "Kungs"
},
{
q: "'City of Stars' (Duet ft. Ryan Gosling, Emma Stone) - La La Land Original Motion Picture Soundtrack",
t: "City of Stars",
a: "Piano Dreamers"
},
{
q: "Imagine Dragons - On Top Of The World (Official Music Video)",
t: "On Top Of The World",
a: "Imagine Dragons"
},
{
q: "Mika - Elle Me Dit (clip officiel)",
t: "Elle Me Dit",
a: "Mika"
}
];
let promises = [];
_.forEach(queries, q => {
let p = alltomp3.guessTrackFromString(q.q).then(a => {
expect(a.title).to.be(q.t);
expect(a.artistName).to.be(q.a);
});
promises.push(p);
});
return promises;
});
});

2395
paxt002/index.js

File diff suppressed because it is too large

211
paxt002/test.js

@ -0,0 +1,211 @@
const alltomp3 = require('.');
const util = require('util');
// alltomp3.spotifyToken().then(o => console.log(o)).catch(e => console.log(e));
// alltomp3.getPlaylistTitlesInfos('https://open.spotify.com/user/spotify_france/playlist/1h4ZB3lW7lD5RmfE6DIRRI').then(d => console.log(util.inspect(d, {depth: 2})));
// alltomp3.getSpotifyTrackInfos('1NOPjzkLIEUM6mwGxCm2mM').then(i => console.log(i));
// alltomp3.configEyeD3('/Users/ntag/Projets/alltomp3/alltomp3-app/bin/eyeD3/bin/eyeD3', '/Users/ntag/Projets/alltomp3/alltomp3-app/bin/eyeD3/build/lib');
// alltomp3.getInfosWithYoutubeDl('https://soundcloud.com/taylorythm/coda', function(infos) {
// console.log(infos);
// });
// alltomp3.getInfosWithYoutubeDl('https://www.youtube.com/watch?v=e74VMNgARvY', function(infos) {
// console.log(infos);
// });
// not working URL https://www.youtube.com/watch?v=yzi-7G2u89g
// var dl = alltomp3.findAndDownload("mika elle me dit", "./", () => {}, true);
// dl.on("download", function (infos) {
// process.stdout.cursorTo(0);
// process.stdout.clearLine(1);
// process.stdout.write(infos.progress + "%");
// });
// dl.on("download-end", function () {
// console.log("Download end");
// });
// dl.on("convert", function (infos) {
// process.stdout.cursorTo(0);
// process.stdout.clearLine(1);
// process.stdout.write(infos.progress + "%");
// });
// dl.on("error", function (e) {
// console.log("Error la la", util.inspect(e));
// });
// alltomp3.getInfosWithYoutubeDl('https://www.youtube.com/watch?v=sX9s-bSOYxk').then(console.log);
// const dl = alltomp3.downloadWithYoutubeDl('https://www.youtube.com/watch?v=sX9s-bSOYxk', 'test.mp3');
// dl.on('download-progress', console.log);
// dl.once('download-end', console.log);
// dl.on('error', console.error);
// alltomp3.guessTrackFromString('Imagine Dragons - On Top of the World - Lyrics', false, false, true);
// alltomp3.guessTrackFromString('C2C - Happy Ft. D.Martin', false, false, true);
// alltomp3.guessTrackFromString('David Guetta - Bang My Head (Official Video) feat Sia & Fetty Wap', false, false, true);
// alltomp3.guessTrackFromString('David Guetta - Hey Mama (Official Video) ft Nicki Minaj, Bebe Rexha & Afrojack', false, false, true);
// alltomp3.retrieveTrackInformations('On Top of the World', 'Imagine Dragons').then(function (infos) {
// console.log("Infos: ", infos);
// });
// alltomp3.guessTrackFromFile('./test.mp3').then(function (infos) {
// return alltomp3.retrieveTrackInformations(infos.title, infos.artistName);
// }).then(function (infos) {
// console.log(infos);
// alltomp3.tagFile('./test.mp3', infos);
// });
// alltomp3.downloadAndTagSingleURL(
// 'https://www.youtube.com/watch?v=sX9s-bSOYxk',
// './',
// function (infos) {
// console.log(infos);
// },
// undefined,
// true,
// );
// var title = "hide and seek imogen heap";
// alltomp3.findVideo(title).then(function(results) {
// var dl = alltomp3.downloadAndTagSingleURL(results[0].url, function(infos) {
// console.log("FINI ", infos);
// }, title);
// dl.on('download', function(infos) {
// process.stdout.cursorTo(0);
// process.stdout.clearLine(1);
// process.stdout.write(infos.progress + '%');
// });
// dl.on('download-end', function() {
// console.log('Download end');
// });
// dl.on('convert', function(infos) {
// process.stdout.cursorTo(0);
// process.stdout.clearLine(1);
// process.stdout.write(infos.progress + '%');
// });
// dl.on('convert-end', function() {
// console.log('Convert end');
// });
// dl.on('infos', function(infos) {
// console.log('Got infos: ', infos);
// });
// });
// var dl = alltomp3.downloadAndTagSingleURL("https://soundcloud.com/user-523607375/sets/john-legend-start-a-fire-la-la", 'mp3/', function(infos) {
// console.log("FINI ", infos);
// });
// dl.on('download', function(infos) {
// process.stdout.cursorTo(0);
// process.stdout.clearLine(1);
// process.stdout.write(infos.progress + '%');
// });
// dl.on('download-end', function() {
// console.log('Download end');
// });
// dl.on('convert', function(infos) {
// process.stdout.cursorTo(0);
// process.stdout.clearLine(1);
// process.stdout.write(infos.progress + '%');
// });
// dl.on('convert-end', function() {
// console.log('Convert end');
// });
// dl.on('infos', function(infos) {
// console.log('Got infos: ', infos);
// });
var dl = alltomp3.findAndDownload('imagine dragons on top of the world', './mp3/', function (infos) {
console.log("It's finished: ", infos);
});
dl.on('search-end', function () {
console.log('Search end');
});
dl.on('download', function (infos) {
process.stdout.cursorTo(0);
process.stdout.clearLine(1);
process.stdout.write(infos.progress + '%');
});
dl.on('download-end', function () {
console.log('', 'Download end');
});
dl.on('convert', function (infos) {
process.stdout.cursorTo(0);
process.stdout.clearLine(1);
process.stdout.write(infos.progress + '%');
});
dl.on('convert-end', function () {
console.log('', 'Convert end');
});
dl.on('infos', function (infos) {
console.log('New infos received: ', infos);
});
// alltomp3.guessTrackFromString('Imagine Dragons - On Top of the World - Lyrics').then(function(infos) {
// console.log(infos);
// });
// alltomp3.guessTrackFromString('C2C - Happy Ft. D.Martin').then(function(infos) {
// console.log(infos);
// });
// alltomp3.guessTrackFromString('David Guetta - Bang My Head (Official Video) feat Sia & Fetty Wap').then(function(infos) {
// console.log(infos);
// });
// alltomp3.guessTrackFromString('David Guetta - Hey Mama (Official Video) ft Nicki Minaj, Bebe Rexha & Afrojack').then(function(infos) {
// console.log(infos);
// });
// alltomp3.guessTrackFromString('hans zimmer no time for caution').then(function(infos) {
// console.log(infos);
// });
// alltomp3.findLyrics('Radioactive', 'Imagine Dragons').then(function (lyrics) {
// console.log(lyrics);
// }).catch(function() {
// console.log('No lyrics');
// });
// alltomp3.getURLsInPlaylist('https://soundcloud.com/20syl/sets/20syl-remixes-2016').then(function(items) {
// console.log(items);
// });
// alltomp3.getTracksInPlaylist('http://www.deezer.com/album/11111444').then(function(items) {
// console.log(items);
// });
// var urls;
// var dl = alltomp3.downloadPlaylist("https://open.spotify.com/album/2tVnLYqhc0iGdSCLxoaLjD", "./mp3/", function (urls) {
// console.log("It's finished: ", urls);
// }, 8);
// dl.on('search-end', function() {
// console.log('Search end');
// });
// dl.on('download', function(index) {
// process.stdout.cursorTo(0);
// process.stdout.clearLine(1);
// process.stdout.write(urls.items[index].progress.download.progress + '%');
// });
// dl.on('download-end', function() {
// console.log('', 'Download end');
// });
// dl.on('convert', function(index) {
// process.stdout.cursorTo(0);
// process.stdout.clearLine(1);
// process.stdout.write(urls.items[index].progress.convert.progress + '%');
// });
// dl.on('convert-end', function(index) {
// console.log('', 'Convert end');
// });
// dl.on('error', function(index) {
// console.log('', 'Error with ' + index);
// });
// dl.on('infos', function(index) {
// // console.log('New infos received: ', infos);
// });
// dl.on('playlist-infos', function(urlss) {
// urls = urlss;
// console.log('URLs received: ', urlss);
// });
// dl.on('begin-url', function(index) {
// console.log('Begin: ', index);
// });
// dl.on('end-url', function(index) {
// console.log('End: ', index);
// });
Loading…
Cancel
Save