Skip to content

Commit

Permalink
Fixes issue with pictures in latest version of NodeTagLibSharp
Browse files Browse the repository at this point in the history
  • Loading branch information
digimezzo committed Jan 14, 2024
1 parent f9987c0 commit e8c9323
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"moment": "2.29.4",
"node-fetch": "2.6.11",
"node-html-parser": "6.1.11",
"node-taglib-sharp": "5.2.2",
"node-taglib-sharp": "5.2.3",
"sanitize-filename": "1.6.3",
"tinycolor2": "1.6.0",
"tslib": "2.0.0",
Expand Down
20 changes: 14 additions & 6 deletions src/app/common/metadata/tag-lib-file-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { File, Id3v2FrameClassType, Id3v2FrameIdentifiers, Id3v2PopularimeterFrame, Id3v2Tag, TagTypes } from 'node-taglib-sharp';
import {
File,
Id3v2FrameClassType,
Id3v2FrameIdentifiers,
Id3v2PopularimeterFrame,
Id3v2Tag,
PictureType,
TagTypes,
} from 'node-taglib-sharp';
import { IFileMetadata } from './i-file-metadata';
import { RatingConverter } from './rating-converter';

Expand Down Expand Up @@ -108,7 +116,7 @@ export class TagLibFileMetadata implements IFileMetadata {
if (tagLibFile.tag.pictures != undefined && tagLibFile.tag.pictures.length > 0) {
let couldGetPicture: boolean = false;

for (const picture of tagLibFile.tag.pictures) {
for (const picture of tagLibFile.tag.pictures.filter((x) => x.type !== PictureType.NotAPicture)) {
if (!couldGetPicture) {
try {
this.picture = Buffer.from(picture.data.toBase64String(), 'base64');
Expand Down Expand Up @@ -147,15 +155,15 @@ export class TagLibFileMetadata implements IFileMetadata {
private readRatingFromFile(tagLibFile: File): number {
const id3v2Tag: Id3v2Tag = <Id3v2Tag>tagLibFile.getTag(TagTypes.Id3v2, true);
const allPopularimeterFrames: Id3v2PopularimeterFrame[] = id3v2Tag.getFramesByClassType<Id3v2PopularimeterFrame>(
Id3v2FrameClassType.PopularimeterFrame
Id3v2FrameClassType.PopularimeterFrame,
);

if (allPopularimeterFrames.length === 0) {
return 0;
}

const popularimeterFramesForWindowsUser: Id3v2PopularimeterFrame[] = allPopularimeterFrames.filter(
(x) => x.user === this.windowsPopMUser
(x) => x.user === this.windowsPopMUser,
);

if (popularimeterFramesForWindowsUser.length > 0) {
Expand All @@ -168,7 +176,7 @@ export class TagLibFileMetadata implements IFileMetadata {
private writeRatingToFile(tagLibFile: File, rating: number): void {
const id3v2Tag: Id3v2Tag = <Id3v2Tag>tagLibFile.getTag(TagTypes.Id3v2, true);
const allPopularimeterFrames: Id3v2PopularimeterFrame[] = id3v2Tag.getFramesByClassType<Id3v2PopularimeterFrame>(
Id3v2FrameClassType.PopularimeterFrame
Id3v2FrameClassType.PopularimeterFrame,
);

if (allPopularimeterFrames.length === 0) {
Expand All @@ -181,7 +189,7 @@ export class TagLibFileMetadata implements IFileMetadata {
}

const popularimeterFramesForWindowsUser: Id3v2PopularimeterFrame[] = allPopularimeterFrames.filter(
(x) => x.user === this.windowsPopMUser
(x) => x.user === this.windowsPopMUser,
);

if (popularimeterFramesForWindowsUser.length > 0) {
Expand Down

0 comments on commit e8c9323

Please sign in to comment.