Skip to content

Commit

Permalink
Enabled previously commented out support for unsync lyrics/transcript…
Browse files Browse the repository at this point in the history
…ion frames (USLT) - fixes #3.
  • Loading branch information
tolo committed Aug 3, 2022
1 parent 2b07657 commit 578d1fa
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

##Version 0.2.0

### Features
* Enabled previously commented out support for unsync lyrics/transcription frames (USLT). Resolved with input from [pull request 3](https://github.com/tolo/id3tag/issues/3), added by @theckr96.

### Bug fixes
* Fixed incorrect parsing of tag size field (resolves [issue 1](https://github.com/tolo/id3tag/issues/1), reported by @VirtualAstronaut).
* Fixed incorrect parsing of tag size field. Resolves [issue 1](https://github.com/tolo/id3tag/issues/1), reported by @VirtualAstronaut.

##Version 0.1.0

Expand Down
1 change: 1 addition & 0 deletions lib/src/frames/frames.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export 'picture_frame.dart';
export 'text_information_frame.dart';
//export 'url_frame.dart';
export 'user_url_frame.dart';
export 'lyrics_frame.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import 'frame_parser.dart';
const String _frameName = 'USLT';


class Transcription extends Frame {
class Lyrics extends Frame {
@override String get frameName => _frameName;

final String language;
final String contentDescriptor;
final String lyrics;

Transcription({required this.language, required this.contentDescriptor, required this.lyrics});
Lyrics({required this.language, required this.contentDescriptor, required this.lyrics});

@override
Map<String, dynamic> toDictionary() {
Expand All @@ -29,25 +29,25 @@ class Transcription extends Frame {
}


class TranscriptionFrameParser extends FrameParser<Transcription> {
class TranscriptionFrameParser extends FrameParser<Lyrics> {
@override
List<String> get frameNames => [_frameName];

@override
Transcription? parseFrame(RawFrame rawFrame) {
Lyrics? parseFrame(RawFrame rawFrame) {
final frameContent = rawFrame.frameContent;
frameContent.readEncoding();
final language = latin1.decode(frameContent.readBytes(3));
var contentDescriptor = frameContent.readString(checkEncoding: false);
final lyrics = (frameContent.remainingBytes > 0)
? frameContent.readString(checkEncoding: false, terminatorMandatory: false)
: contentDescriptor;

// TODO: Review
if (frameContent.remainingBytes == 0) {
var lyrics = '';
if (frameContent.remainingBytes > 0) {
lyrics = frameContent.readString(checkEncoding: false, terminatorMandatory: false);
} else {
lyrics = contentDescriptor;
contentDescriptor = '';
}

return Transcription(language: language, contentDescriptor: contentDescriptor, lyrics: lyrics);
return Lyrics(language: language, contentDescriptor: contentDescriptor, lyrics: lyrics);
}
}
1 change: 1 addition & 0 deletions lib/src/id3_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class ID3Parser implements ID3TagReader {
addParser(TextInformationFrameParser());
//addParser(UrlFrameParser()); // TODO
addParser(UserUrlFrameParser());
addParser(TranscriptionFrameParser());

return parserMap;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/src/id3_tag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class ID3Tag {
return _chapters;
}

/// Gets the unsynchronized lyric/text transcription ('USLT') frame, represented as a [Lyrics] object.
List<Lyrics> get lyrics => framesWithTypeAndName<Lyrics>('USLT');


ID3Tag({required this.tagVersion, required this.tagFound, required this.frames});

Expand Down
7 changes: 7 additions & 0 deletions test/id3frames_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ void main() {
final frame = tag.frames.firstWhereOrNull((f) => f.frameName == 'APIC');
expect(frame, isNotNull);
});

test('Tag should contain lyrics', () {
final parser = ID3Parser(File('test/apic.mp3')); // apic test file also contains uslt
final tag = parser.readTagSync();
final frame = tag.frames.firstWhereOrNull((f) => f.frameName == 'USLT');
expect(frame, isNotNull);
});
}

0 comments on commit 578d1fa

Please sign in to comment.