Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tagtoname

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tagtoname - npm Package Compare versions

Comparing version 5.0.0 to 5.1.0

48

index.js
const {
constants,
promises: { access, rename },
promises: { access, mkdir, rename },
} = require("fs");

@@ -15,4 +15,10 @@ const { basename, dirname, extname, join } = require("path");

const renameWithLock = (oldPath, newPath) => {
const lockFile = join(dirname(newPath), `${basename(newPath)}.lock`);
const dir = dirname(newPath);
const lockFile = join(dir, `${basename(newPath)}.lock`);
return lockPromise(lockFile)
.catch((error) =>
error.code === "ENOENT"
? mkdir(dir, { recursive: true })
: Promise.reject(error)
)
.then(() => rename(oldPath, newPath))

@@ -22,13 +28,4 @@ .then(() => unlockPromise(lockFile));

const name = (metadataTags, tags, separator) =>
tags
.map((tag) => {
const value = metadataTags[tag];
return typeof value === "object" ? Object.values(value)[0] : value;
})
.filter((element) => element != null)
.join(separator);
/**
* Renames an audio file using its metadata tags.
* Renames an audio file using its metadata tags. Resolves with the new path.
*

@@ -47,4 +44,2 @@ * The first argument is the `path` of the file to be renamed.

* defaults to `["artist", "title"]`
*
* Resolves with the new path.
*/

@@ -60,7 +55,22 @@ module.exports = function (

) {
return parseFile(path).then(({ common: metadataTags }) => {
const newPath = join(
dirname(path),
slugify(name(metadataTags, tags, separator), { keepCase }) + extname(path)
);
return parseFile(path).then(({ common }) => {
const name = tags
.reduce((tags, key) => {
const value = common[key];
const tag = typeof value === "object" ? Object.values(value)[0] : value;
if (tag != null) {
tags.push(slugify(String(tag), { keepCase }));
}
return tags;
}, [])
.join(separator);
if (name === "") {
return Promise.reject(
Error(`Failed because '${path}' is missing all tags`)
);
}
const newPath = join(dirname(path), name + extname(path));
return path === newPath

@@ -67,0 +77,0 @@ ? newPath

{
"name": "tagtoname",
"version": "5.0.0",
"version": "5.1.0",
"description": "Renames audio files using the metadata tags",

@@ -40,12 +40,12 @@ "keywords": [

"lockfile": "1.0.4",
"music-metadata": "7.0.0",
"music-metadata": "7.4.0",
"standard-slugify": "3.0.0"
},
"devDependencies": {
"eslint": "7.5.0",
"eslint-config-pretty-strict": "6.1.1",
"eslint": "7.9.0",
"eslint-config-pretty-strict": "7.0.0",
"eslint-plugin-prettier": "3.1.4",
"husky": "4.2.5",
"husky": "4.3.0",
"nyc": "15.1.0",
"prettier": "2.0.5",
"prettier": "2.1.2",
"tape": "5.0.1"

@@ -52,0 +52,0 @@ },

@@ -60,5 +60,6 @@ # tagtoname

# Rename a file using a custom separator.
# For example, if the file has the "artist" tag "Debussy", and the "title" tag
# "Reverie", it will be renamed to "debussy_reverie.mp3".
tagtoname -s _ file.mp3
# For example, if the file has the "artist" tag "Debussy" and the "title" tag
# "Reverie", the file will be renamed to "debussy/reverie.mp3" (since the
# separator is "/", the folder "debussy" is created if needed).
tagtoname -s / file.mp3

@@ -75,3 +76,3 @@ # Rename a file using specific tags.

Renames an audio file using its metadata tags.
Renames an audio file using its metadata tags. Resolves with the new path.

@@ -87,4 +88,2 @@ The first argument is the `path` of the file to be renamed.

Resolves with the new path.
### Examples

@@ -105,6 +104,7 @@

// Rename "/file.mp3" using "_" as a separator
// Rename "/file.mp3" using "/" as a separator
// assuming the artist tag is "Queen" and the title tag is "Bohemian Rhapsody"
tagtoname("/file.mp3", { separator: "_" }).then(console.log);
// => /queen_bohemian-rhapsody.mp3
// (since the separator is "/", the folder "queen" is created if needed).
tagtoname("/file.mp3", { separator: "/" }).then(console.log);
// => /queen/bohemian-rhapsody.mp3

@@ -111,0 +111,0 @@ // Rename "/file.mp3" using the "year" and "title" tags

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc