Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
NiKoTron committed Jan 27, 2022
2 parents 2ce5455 + 04eb917 commit 7aaf933
Show file tree
Hide file tree
Showing 26 changed files with 321 additions and 126 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ jobs:
branch: master

branches:
only: [master, develop]
only:
- master
- /^v\d+\.\d+\.\d+.*$/

# Incremental pub cache and builds.
cache:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.4.0 (Null Safety)

* thanx for migrating to null safety to [@timekone](https://github.com/timekone) and this [PR](https://github.com/NiKoTron/dart-tags/pull/35)
* updated some dependencies

## 0.3.1

* implemented separate getting size of frame for id3 v2.3 and v2.4
Expand Down
26 changes: 8 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,26 @@ project under MIT [license](LICENSE)

[full changelog](CHANGELOG.md)

## 0.4.0 (Null Safety)

* thanx for migrating to null safety to [@timekone](https://github.com/timekone) and this [PR](https://github.com/NiKoTron/dart-tags/pull/35)
* updated some dependencies

## 0.3.1

* implemented separate getting size of frame for id3 v2.3 and v2.4
* added test case and asset
* fixed typos, thanx to [@algoshipda](https://github.com/algoshipda) and his [PR](https://github.com/NiKoTron/dart-tags/pull/17)
* fixed APIC picture type error, thanx to [@algoshipda](https://github.com/algoshipda) and his [PR](https://github.com/NiKoTron/dart-tags/pull/20)

## 0.3.0+1

* hotfix! missed exports for new tags was added

## 0.3.0 (BREAKING CHANGES)

* COMM, APIC, USLT, WXXX tags returns as a map
* WXXX frame returns WURL object
* various fixes
* added USLT tag
* added possibility to pass many COMM, APIC, USLT tags
* APIC processing was refactored
* hex encoder
* unrecognized encoding falls to hex encoder (removed unsupported encoding error)
* unsupported tags like PRIV will be printed just like raw binary data

## Instalation

add dependency in pubsec.yaml

``` yaml
dependencies:
dart_tags: ^0.3.1
dart_tags: ^0.4.0
```
## Usage
Expand All @@ -59,9 +49,9 @@ import 'dart:io';
import 'package:dart_tags/dart_tags.dart';

main(List<String> args) {
TagProcessor tp = new TagProcessor();
final tp = new TagProcessor();

File f = new File(args[0]);
final f = new File(args[0]);

tp.getTagsFromByteArray(f.readAsBytes()).then((l) => l.forEach((f) => print(f)));
}
Expand Down
5 changes: 1 addition & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Lint rules that uses google internaly also in pu i guess. https://github.com/dart-lang/pedantic/#enabled-lints
include: package:pedantic/analysis_options.yaml
include: package:lints/recommended.yaml

analyzer:
strong-mode:
Expand Down Expand Up @@ -48,7 +47,6 @@ linter:
- always_put_required_named_parameters_first
- always_require_non_null_named_parameters
- annotate_overrides
- avoid_as
- avoid_annotating_with_dynamic
- avoid_classes_with_only_static_members
- avoid_bool_literals_in_conditional_expressions
Expand All @@ -68,4 +66,3 @@ linter:
- prefer_single_quotes
- package_api_docs
# - public_member_api_docs

10 changes: 5 additions & 5 deletions lib/src/convert/utf16.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:convert';
import 'dart:core';

import 'package:utf/utf.dart' as utf;
import 'package:utf_convert/utf_convert.dart' as utf;

abstract class UTF16 extends Encoding {
List<int> get bom;
Expand Down Expand Up @@ -37,14 +37,14 @@ class _UTF16LEDecoder extends Converter<List<int>, String> {
@override
String convert(List<int> input) {
final decoder = utf.Utf16leBytesToCodeUnitsDecoder(input);
return String.fromCharCodes(decoder.decodeRest());
return String.fromCharCodes(decoder.decodeRest().cast<int>());
}
}

class _UTF16LEEncoder extends Converter<String, List<int>> {
@override
List<int> convert(String input) {
return utf.encodeUtf16le(input, true);
return utf.encodeUtf16le(input, true) as List<int>;
}
}

Expand All @@ -66,13 +66,13 @@ class _UTF16BEDecoder extends Converter<List<int>, String> {
@override
String convert(List<int> input) {
final decoder = utf.Utf16beBytesToCodeUnitsDecoder(input);
return String.fromCharCodes(decoder.decodeRest());
return String.fromCharCodes(decoder.decodeRest().cast<int>());
}
}

class _UTF16BEEncoder extends Converter<String, List<int>> {
@override
List<int> convert(String input) {
return utf.encodeUtf16be(input, true);
return utf.encodeUtf16be(input, true) as List<int>;
}
}
25 changes: 14 additions & 11 deletions lib/src/frames/frame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import 'id3v2/default_frame.dart';
/// Abstract implementation of id3v2 frame
abstract class Frame<T> {
/// Encode [key] tag with [value] to bytearray
List<int> encode(T value, [String key]);
List<int> encode(T value, [String? key]);

/// Decode byte [data] to frame data map
MapEntry<String, T> decode(List<int> data);
MapEntry<String, T>? decode(List<int> data);
}

class FrameFactory<T extends Frame> {
class FrameFactory<T extends Frame?> {
String version;

// ignore: avoid_annotating_with_dynamic
Frame Function(dynamic entry) _frameGetter;
Frame? Function(dynamic entry) _frameGetter;

Frame defaultFrame;
Frame? defaultFrame;

FrameFactory._internal(this.version, this._frameGetter, [this.defaultFrame]);

Expand All @@ -40,7 +40,7 @@ class FrameFactory<T extends Frame> {
return FrameFactory._internal('0', (v) => null);
}

T getFrame(entry) => _frameGetter(entry);
Frame? getFrame(entry) => _frameGetter(entry);
}

class FramesID3V23 extends FramesID3V24 {
Expand All @@ -55,7 +55,8 @@ class FramesID3V23 extends FramesID3V24 {

@override
Frame<T> _getFrame<T>(String tag) {
return _frames[tag] ?? DefaultFrame(tag, version: 3);
return _frames[tag] as Frame<T>? ??
DefaultFrame(tag, version: 3) as Frame<T>;
}
}

Expand All @@ -69,16 +70,18 @@ class FramesID3V24 {
};

Frame<T> _getFrame<T>(String tag) {
return _frames[tag] ?? DefaultFrame(tag);
return _frames[tag] as Frame<T>? ?? DefaultFrame(tag) as Frame<T>;
}

String getTagByPseudonym(String tag) {
return consts.frameHeaderShortcutsID3V2_3_Rev.containsKey(tag)
? consts.frameHeaderShortcutsID3V2_3_Rev[tag]
: consts.framesHeaders.containsKey(tag) ? tag : 'TXXX';
? consts.frameHeaderShortcutsID3V2_3_Rev[tag]!
: consts.framesHeaders.containsKey(tag)
? tag
: 'TXXX';
}

Frame<T> getFrame<T>(data) {
Frame<T>? getFrame<T>(data) {
assert(data is List<int> || data is String);

if (data is List<int>) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/frames/id3v2/apic_frame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ class ApicFrame extends ID3V2Frame<AttachedPicture> {
final imageData = data.sublist(startOfImageData);

final extractedImageData = _imageExtractors.containsKey(mime)
? _imageExtractors[mime]().parse(imageData)
? _imageExtractors[mime]!().parse(imageData)
: imageData;

return AttachedPicture(mime, imageType, description, extractedImageData);
}

@override
List<int> encode(AttachedPicture value, [String key]) {
List<int> encode(AttachedPicture value, [String? key]) {
final mimeEncoded = latin1.encode(value.mime);
final descEncoded = utf8.encode(value.description);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/frames/id3v2/comm_frame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class COMMFrame extends ID3V2Frame<Comment> {
}

@override
List<int> encode(Comment value, [String key]) {
List<int> encode(Comment value, [String? key]) {
final enc = header?.encoding ?? utf8;

return [
Expand Down
2 changes: 1 addition & 1 deletion lib/src/frames/id3v2/default_frame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DefaultFrame extends ID3V2Frame<String> {
}

@override
List<int> encode(String value, [String key]) {
List<int> encode(String value, [String? key]) {
final tag = getTagByPseudonym(frameTag);

final vBytes = utf8.encode(value);
Expand Down
26 changes: 13 additions & 13 deletions lib/src/frames/id3v2/id3v2_frame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ abstract class ID3V2Frame<T> implements Frame<T> {

final int _version;

ID3V2FrameHeader _header;
ID3V2FrameHeader get header => _header;
ID3V2FrameHeader? _header;
ID3V2FrameHeader? get header => _header;

ID3V2Frame(this._version);

@override
MapEntry<String, T> decode(List<int> data) {
MapEntry<String, T>? decode(List<int> data) {
final tag = latin1.decode(data.sublist(0, 4));
if (!consts.framesHeaders.keys.contains(tag)) {
return null;
Expand All @@ -46,27 +46,27 @@ abstract class ID3V2Frame<T> implements Frame<T> {

_header = ID3V2FrameHeader(tag, size, encoding: encoding);

if (data.length < headerLength + _header?.length) {
if (data.length < headerLength + _header!.length) {
_header =
ID3V2FrameHeader(tag, data.length - headerLength, encoding: encoding);
}

final body = data.sublist(headerLength + 1, headerLength + _header?.length);
final body = data.sublist(headerLength + 1, headerLength + _header!.length);

return MapEntry<String, T>(
getTagPseudonym(_header.tag), decodeBody(body, encoding));
getTagPseudonym(_header!.tag), decodeBody(body, encoding));
}

T decodeBody(List<int> data, Encoding enc);

@override
List<int> encode(T value, [String key]);
List<int> encode(T value, [String? key]);

/// Returns size of frame in bytes
List<int> frameSizeInBytes(int value) {
assert(value <= 16777216);

final block = List<int>(4);
final block = List<int>.filled(4, 0);
final sevenBitMask = 0x7f;

block[0] = (value >> 21) & sevenBitMask;
Expand All @@ -79,13 +79,13 @@ abstract class ID3V2Frame<T> implements Frame<T> {

String getTagByPseudonym(String tag) {
return consts.frameHeaderShortcutsID3V2_3_Rev.containsKey(tag)
? consts.frameHeaderShortcutsID3V2_3_Rev[tag]
? consts.frameHeaderShortcutsID3V2_3_Rev[tag]!
: tag;
}

String getTagPseudonym(String tag) {
return consts.frameHeaderShortcutsID3V2_3.containsKey(tag)
? consts.frameHeaderShortcutsID3V2_3[tag]
? consts.frameHeaderShortcutsID3V2_3[tag]!
: tag;
}

Expand Down Expand Up @@ -133,7 +133,7 @@ abstract class ID3V2Frame<T> implements Frame<T> {

int indexOfSplitPattern(List<int> list, List<int> pattern,
[int initialOffset = 0]) {
for (var i = initialOffset ?? 0;
for (var i = initialOffset;
i < list.length - pattern.length;
i += pattern.length) {
final l = list.sublist(i, i + pattern.length);
Expand Down Expand Up @@ -182,10 +182,10 @@ class ID3V2FrameHeader {
String tag;
int length;

Encoding encoding;
Encoding? encoding;

// todo: implement futher
int flags;
int? flags;

ID3V2FrameHeader(this.tag, this.length, {this.flags, this.encoding}) {
assert(consts.framesHeaders.keys.contains(tag));
Expand Down
6 changes: 3 additions & 3 deletions lib/src/frames/id3v2/txxx_frame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class TXXXFrame extends ID3V2Frame<String> {
@override
String get frameTag => 'TXXX';

String _customTagName;
String? _customTagName;

@override
MapEntry<String, String> decode(List<int> data) {
final entry = super.decode(data);
final entry = super.decode(data)!;
return MapEntry<String, String>(_customTagName ?? frameTag, entry.value);
}

Expand All @@ -64,7 +64,7 @@ class TXXXFrame extends ID3V2Frame<String> {
}

@override
List<int> encode(String value, [String key]) {
List<int> encode(String value, [String? key]) {
final body = utf8.encode('$key${utf8.decode([0x00])}$value');
return [
...utf8.encode(frameTag),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/frames/id3v2/uslt_frame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class USLTFrame extends ID3V2Frame<UnSyncLyric> {
}

@override
List<int> encode(UnSyncLyric value, [String key]) {
List<int> encode(UnSyncLyric value, [String? key]) {
final enc = header?.encoding ?? utf8;

return [
Expand Down
2 changes: 1 addition & 1 deletion lib/src/frames/id3v2/wxxx_frame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class WXXXFrame extends ID3V2Frame<WURL> {
String get frameTag => 'WXXX';

@override
List<int> encode(WURL value, [String key]) {
List<int> encode(WURL value, [String? key]) {
final vBytes = [
...utf8.encode('${value.description}${utf8.decode([0x00])}'),
...latin1.encode(value.url)
Expand Down
Loading

0 comments on commit 7aaf933

Please sign in to comment.