Skip to content

Commit

Permalink
Move songs to L&I
Browse files Browse the repository at this point in the history
  • Loading branch information
ioanlucut committed Sep 15, 2023
1 parent b4dbc62 commit ca7fe4d
Show file tree
Hide file tree
Showing 184 changed files with 380 additions and 47 deletions.
5 changes: 0 additions & 5 deletions .run/Run_ [Temp] sync authors from RC.run.xml

This file was deleted.

5 changes: 0 additions & 5 deletions .run/Run_ [Temp] sync rc id from RC.run.xml

This file was deleted.

2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const COMMA = ',';

export const COLON = ':';

export const SLASH = '/';

export const DOT = '.';

export const TXT_EXTENSION = '.txt';
Expand Down
78 changes: 78 additions & 0 deletions temp-runners/addSongsFromRc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import fs from 'fs';
import path from 'path';
import * as process from 'process';
import fsExtra from 'fs-extra';
import dotenv from 'dotenv';
import recursive from 'recursive-readdir';
import pMap from 'p-map';
import { parse } from '../src/songParser.js';
import { print } from '../src/songPrinter.js';
import {
logFileWithLinkInConsole,
logProcessingFile,
NEW_LINE,
} from '../src/index.js';
import { flatten } from 'lodash-es';

import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

dotenv.config();

const RC_BASE = '/Users/ilucut/WORK/BES/bes-lyrics-parser';
const RC_DIR = `${RC_BASE}/out/resurse_crestine`;
const CANDIDATES_DIR = `/Users/ilucut/WORK/BES/bes-lyrics/candidates`;

const rcAuthorPathsToProcess = fsExtra
.readFileSync(`${__dirname}/authors_to_process.txt`)
.toString()
.split(NEW_LINE)
.filter(Boolean);

const readFiles = async (dir: string) =>
(await recursive(dir)).map((filePath) => {
return {
contentAsString: fs.readFileSync(filePath).toString(),
fileName: path.basename(filePath),
filePath,
};
});

const runFor = async (songsDirs: string[]) => {
const allSongsInRepo = flatten(
await Promise.all(songsDirs.map(readFiles)),
).map(({ contentAsString }) => parse(contentAsString));
const allRcIds = allSongsInRepo.map(({ rcId }) => rcId).filter(Boolean);

await pMap(rcAuthorPathsToProcess, async (pathConfig) => {
const [counts, author, authorPath] = pathConfig.split(':');
const dirToImportFrom = `${RC_DIR}/${authorPath}`;
(await readFiles(dirToImportFrom)).forEach(
({ contentAsString, filePath, fileName }) => {
const rcSongAST = parse(contentAsString);
logProcessingFile(
fileName,
`Import from RC from ${author}; Counts: ${counts}.`,
);
logFileWithLinkInConsole(filePath);

if (allRcIds.includes(rcSongAST.rcId)) {
console.log(
`Skip processing the song with RC ID ${rcSongAST.rcId} as we have it in our system.`,
);
console.log(NEW_LINE);

return;
}

const authorDirTarget = `${CANDIDATES_DIR}/${rcSongAST.author}`;

fsExtra.ensureDirSync(authorDirTarget);
fs.writeFileSync(`${authorDirTarget}/${fileName}`, print(rcSongAST));
},
);
});
};

await runFor([process.env.VERIFIED_DIR, process.env.CANDIDATES_DIR]);
Empty file added temp-runners/manual_picks.txt
Empty file.
Empty file.
90 changes: 57 additions & 33 deletions temp-runners/moveExistingWorshipSongsToDir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import fsExtra from 'fs-extra';
import dotenv from 'dotenv';
import recursive from 'recursive-readdir';
import pMap from 'p-map';
import stringSimilarity from 'string-similarity';
import { parse } from '../src/songParser.js';
import { print } from '../src/songPrinter.js';
import {
logFileWithLinkInConsole,
logProcessingFile,
NEW_LINE,
SLASH,
} from '../src/index.js';
import { flatten } from 'lodash-es';
import { flatten, without } from 'lodash-es';

import { fileURLToPath } from 'url';

Expand All @@ -22,14 +24,17 @@ dotenv.config();

const RC_BASE = '/Users/ilucut/WORK/BES/bes-lyrics-parser';
const RC_DIR = `${RC_BASE}/out/resurse_crestine`;
const CANDIDATES_DIR = `/Users/ilucut/WORK/BES/bes-lyrics/candidates`;
const L_I_DIR = 'trupe_lauda_si_inchinare';
const L_AND_I = '/Users/ilucut/WORK/BES/bes-lyrics/verified/' + L_I_DIR;

const rcAuthorPathsToProcess = fsExtra
.readFileSync(`${__dirname}/authors_to_process.txt`)
const pickedPartialTitleSongs = fsExtra
.readFileSync(`${__dirname}/manual_picks.txt`)
.toString()
.split(NEW_LINE)
.filter(Boolean);

const getOneOrTwoMatches = (text: string) => text.split(' / ').filter(Boolean);

const readFiles = async (dir: string) =>
(await recursive(dir)).map((filePath) => {
return {
Expand All @@ -39,43 +44,62 @@ const readFiles = async (dir: string) =>
};
});

const runValidatorAndExitIfSimilar = async (songsDirs: string[]) => {
const allSongsInRepo = flatten(
await Promise.all(songsDirs.map(readFiles)),
).map(({ contentAsString }) => parse(contentAsString));
const allRcIds = allSongsInRepo.map(({ rcId }) => rcId).filter(Boolean);

await pMap(rcAuthorPathsToProcess, async (pathConfig) => {
const [counts, author, authorPath] = pathConfig.split(':');
const dirToImportFrom = `${RC_DIR}/${authorPath}`;
(await readFiles(dirToImportFrom)).forEach(
({ contentAsString, filePath, fileName }) => {
const rcSongAST = parse(contentAsString);
logProcessingFile(
fileName,
`Import from RC from ${author}; Counts: ${counts}.`,
);
logFileWithLinkInConsole(filePath);

if (allRcIds.includes(rcSongAST.rcId)) {
const runFor = async (songsDirs: string[]) => {
const lines = [] as string[];
const rawSongs = flatten(await Promise.all(songsDirs.map(readFiles)));

await pMap(pickedPartialTitleSongs, async (rawLine) => {
const [matchingTitle, maybeMatchingExtraText] = rawLine
.split(SLASH)
.filter(Boolean);

rawSongs.forEach(({ contentAsString, fileName, filePath }) => {
const { title, sectionsMap } = parse(contentAsString);

const isAGreatHit =
stringSimilarity.compareTwoStrings(
title.toLowerCase(),
matchingTitle.toLowerCase(),
) >= 0.9 ||
(!!maybeMatchingExtraText &&
stringSimilarity.compareTwoStrings(
title.toLowerCase(),
maybeMatchingExtraText.toLowerCase(),
) >= 0.9) ||
(!!maybeMatchingExtraText &&
sectionsMap[0]?.content &&
stringSimilarity.compareTwoStrings(
sectionsMap[0]?.content?.toLowerCase(),
maybeMatchingExtraText.toLowerCase(),
) >= 0.9);
const isAHit = title.includes(matchingTitle);

if (isAGreatHit || isAHit) {
lines.push(rawLine);

if (filePath.includes(L_I_DIR)) {
console.log(
`Skip processing the song with RC ID ${rcSongAST.rcId} as we have it in our system.`,
`Skipping ${fileName} as it is already in the target dir.`,
);
console.log(NEW_LINE);

return;
}

const authorDirTarget = `${CANDIDATES_DIR}/${rcSongAST.author}`;
console.log({
title,
matchingTitle,
isExactMatch: isAGreatHit,
contains: isAHit,
});
fsExtra.moveSync(filePath, `${L_AND_I}/${fileName}`);
}
});

fsExtra.ensureDirSync(authorDirTarget);
fs.writeFileSync(`${authorDirTarget}/${fileName}`, print(rcSongAST));
},
fs.writeFileSync(
`${__dirname}/manual_picks_rest.txt`,
without(pickedPartialTitleSongs, ...lines).join(NEW_LINE),
);
});
};

await runValidatorAndExitIfSimilar([
process.env.VERIFIED_DIR,
process.env.CANDIDATES_DIR,
]);
await runFor([process.env.VERIFIED_DIR]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[title]
Slava e a ta {author: {Adi Kovaci și Ema Repede}, contentHash: {0963c7}, id: {k7scbRYnuuQ5UvFMkKJSnN}, rcId: {201507}}

[sequence]
v1,c,v2,c,v3,c

[v1]
Ești necuprins, și gloria Ta,
Nimeni n-o pătrunde.
Dar te-ai jertfit, în locul meu,
Vrednic e-al Tău Nume.

[c]
Slava e a Ța,
Toată Gloria,
Numai Ție ne-închinăm.
Peste noi ești Domn,
Noi te înălțam,
Tu rămâi în veci pe tron.

[v2]
Acel ce ai fost,
Ești și vei fii,
Domn, în orice vreme.
În veci pe tron, cel înălțat
Sfânt doar Tu esti rege!

[v3]
/: Glorie în veci, ne închinăm!
Vrednic este Mielul Sfânt, aleluia! :/
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[title]
Dumnezeu peste toate - live session {author: {Alin}, contentHash: {7f6a3d}, id: {sH1WdMXswMAnvr38bkADJn}, rcId: {227447}}

[sequence]
v1,c,v2,c,e,c

[v1]
Ești vrednic
Puternic, al lumii Creator
Statornic
Din veci de veci Tu domnești pe tron
De-aceea Îți cânt
Cu-ntregul pământ
Natura declară măreția Ta

[c]
Tu ești Dumnezeu peste toate
Atotputernic Rege, ești inălțat
Nimic de Tine nu ne desparte
Prin Fiul Tău pe veci ne-ai răscumpărat
Fii Lăudat! Glorificat!

[v2]
Nu merit
Iertarea ce am primit-o-n dar
Iar pacea
Ce mă inundă prin al Tău har
Ma-ndeamnă sa-Ți cânt
Cu-ntregul pământ
Să stie oricine de iubirea Ta

[e]
/: Chiar de ar cădea
Zece mii la dreapta mea
Sunt în mâna Ta
Și de-a pururi eu voi declara: :/
39 changes: 39 additions & 0 deletions verified/trupe_lauda_si_inchinare/Anonim - Dati de veste.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[title]
Dati de veste {author: {Anonim}, contentHash: {ac48d2}, id: {3LEqtpDXFqjzzwgeFDm77T}, rcId: {157330}}

[sequence]
v1,c,v2,c,e

[v1]
Soarele-a apus ca-n orice zi
Dar neștiind lumea a adormit,
Era o noapte obișnuită
Pentru cei nepăsători
Însă cei ce-au așteptat de mult
Așa au auzit.

[c]
Dați de veste, îngerii cântă
Glorie, glorie, Rege s-a născut!
Dați de veste, îngerii cântă
Glorie Regelui de sus,
Glorie Regelui Isus.

[v2]
Vestea era purtată ca de vânt
Nu vă temeți, pace pe pământ!”
Bucurie mare aduce
S-a născut un Salvator,
Vestea bună-a mântuirii
Spuneți tuturor.

[e]
/: Să-I cântăm, glorie, glorie
Regelui, glorie, glorie!
Răspândiți peste tot
Isus s-a născut, e salvator
Să-I cântăm, glorie, glorie
Regelui, glorie, glorie!
Veniți cu toți să ne-nchinăm
Înaintea Lui, să-L adorăm. :/
42 changes: 42 additions & 0 deletions verified/trupe_lauda_si_inchinare/Anonim - Isus numai isus.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[title]
Isus numai Isus {author: {Anonim}, contentHash: {d81964}, id: {aFgvNJM5hnJgLf8JRB378m}, rcId: {166750}}

[sequence]
v1,v2,v3,v4,v5,v6

[v1]
Cine din morti poate-nvia?
Si de păcat poate ierta?
Speranta si dreptatea mea.
Isus, numai Isus.

[v2]
Cine da vederea iar?
Si lanturi cad prin al Său har
El a plătit sus la Calvar.
Isus, numai Isus.

[v3]
Sfânt si Domn puternic esti,.
Cântă ostile ceresti
Si noi ne închinăm doar Lui..
Isus, numai Isus.

[v4]
Cine e demn de lăudat?.
Numele cui e înăltat?
Ești uimitor, sunt copleșit..
Isus, numai Isus.

[v5]
Sfânt și Domn puternic ești,.
Cântă oștile cerești
Și noi ne închinăm doar Lui..
Isus, numai Isus.

[v6]
Tu vrednic ești să fii lăudat..
Numele Tău e înălțat...
Ești uimitor, sunt copleșit..
Isus, numai Isus.
Isus, numai Isus.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit ca7fe4d

Please sign in to comment.