diff --git a/.travis.yml b/.travis.yml index 907c25a..f34980d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,9 @@ jobs: branch: master branches: - only: [master, develop] + only: + - master + - /^v\d+\.\d+\.\d+.*$/ # Incremental pub cache and builds. cache: diff --git a/CHANGELOG.md b/CHANGELOG.md index 72e7fe2..e9278bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 4e7fad5..2c6ab6f 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,11 @@ 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 @@ -24,21 +29,6 @@ project under MIT [license](LICENSE) * 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 @@ -46,7 +36,7 @@ add dependency in pubsec.yaml ``` yaml dependencies: - dart_tags: ^0.3.1 + dart_tags: ^0.4.0 ``` ## Usage @@ -59,9 +49,9 @@ import 'dart:io'; import 'package:dart_tags/dart_tags.dart'; main(List 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))); } diff --git a/analysis_options.yaml b/analysis_options.yaml index 36bdda4..8cb0247 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -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: @@ -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 @@ -68,4 +66,3 @@ linter: - prefer_single_quotes - package_api_docs # - public_member_api_docs - \ No newline at end of file diff --git a/lib/src/convert/utf16.dart b/lib/src/convert/utf16.dart index b63e518..4f913e3 100644 --- a/lib/src/convert/utf16.dart +++ b/lib/src/convert/utf16.dart @@ -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 get bom; @@ -37,14 +37,14 @@ class _UTF16LEDecoder extends Converter, String> { @override String convert(List input) { final decoder = utf.Utf16leBytesToCodeUnitsDecoder(input); - return String.fromCharCodes(decoder.decodeRest()); + return String.fromCharCodes(decoder.decodeRest().cast()); } } class _UTF16LEEncoder extends Converter> { @override List convert(String input) { - return utf.encodeUtf16le(input, true); + return utf.encodeUtf16le(input, true) as List; } } @@ -66,13 +66,13 @@ class _UTF16BEDecoder extends Converter, String> { @override String convert(List input) { final decoder = utf.Utf16beBytesToCodeUnitsDecoder(input); - return String.fromCharCodes(decoder.decodeRest()); + return String.fromCharCodes(decoder.decodeRest().cast()); } } class _UTF16BEEncoder extends Converter> { @override List convert(String input) { - return utf.encodeUtf16be(input, true); + return utf.encodeUtf16be(input, true) as List; } } diff --git a/lib/src/frames/frame.dart b/lib/src/frames/frame.dart index 55653a0..4bb2dc9 100644 --- a/lib/src/frames/frame.dart +++ b/lib/src/frames/frame.dart @@ -12,19 +12,19 @@ import 'id3v2/default_frame.dart'; /// Abstract implementation of id3v2 frame abstract class Frame { /// Encode [key] tag with [value] to bytearray - List encode(T value, [String key]); + List encode(T value, [String? key]); /// Decode byte [data] to frame data map - MapEntry decode(List data); + MapEntry? decode(List data); } -class FrameFactory { +class FrameFactory { 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]); @@ -40,7 +40,7 @@ class FrameFactory { return FrameFactory._internal('0', (v) => null); } - T getFrame(entry) => _frameGetter(entry); + Frame? getFrame(entry) => _frameGetter(entry); } class FramesID3V23 extends FramesID3V24 { @@ -55,7 +55,8 @@ class FramesID3V23 extends FramesID3V24 { @override Frame _getFrame(String tag) { - return _frames[tag] ?? DefaultFrame(tag, version: 3); + return _frames[tag] as Frame? ?? + DefaultFrame(tag, version: 3) as Frame; } } @@ -69,16 +70,18 @@ class FramesID3V24 { }; Frame _getFrame(String tag) { - return _frames[tag] ?? DefaultFrame(tag); + return _frames[tag] as Frame? ?? DefaultFrame(tag) as Frame; } 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 getFrame(data) { + Frame? getFrame(data) { assert(data is List || data is String); if (data is List) { diff --git a/lib/src/frames/id3v2/apic_frame.dart b/lib/src/frames/id3v2/apic_frame.dart index 871bf56..8285f15 100644 --- a/lib/src/frames/id3v2/apic_frame.dart +++ b/lib/src/frames/id3v2/apic_frame.dart @@ -83,14 +83,14 @@ class ApicFrame extends ID3V2Frame { 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 encode(AttachedPicture value, [String key]) { + List encode(AttachedPicture value, [String? key]) { final mimeEncoded = latin1.encode(value.mime); final descEncoded = utf8.encode(value.description); diff --git a/lib/src/frames/id3v2/comm_frame.dart b/lib/src/frames/id3v2/comm_frame.dart index 5ad6f80..8f85070 100644 --- a/lib/src/frames/id3v2/comm_frame.dart +++ b/lib/src/frames/id3v2/comm_frame.dart @@ -42,7 +42,7 @@ class COMMFrame extends ID3V2Frame { } @override - List encode(Comment value, [String key]) { + List encode(Comment value, [String? key]) { final enc = header?.encoding ?? utf8; return [ diff --git a/lib/src/frames/id3v2/default_frame.dart b/lib/src/frames/id3v2/default_frame.dart index 697697a..71d395c 100644 --- a/lib/src/frames/id3v2/default_frame.dart +++ b/lib/src/frames/id3v2/default_frame.dart @@ -13,7 +13,7 @@ class DefaultFrame extends ID3V2Frame { } @override - List encode(String value, [String key]) { + List encode(String value, [String? key]) { final tag = getTagByPseudonym(frameTag); final vBytes = utf8.encode(value); diff --git a/lib/src/frames/id3v2/id3v2_frame.dart b/lib/src/frames/id3v2/id3v2_frame.dart index c890992..65cdd51 100644 --- a/lib/src/frames/id3v2/id3v2_frame.dart +++ b/lib/src/frames/id3v2/id3v2_frame.dart @@ -25,13 +25,13 @@ abstract class ID3V2Frame implements Frame { final int _version; - ID3V2FrameHeader _header; - ID3V2FrameHeader get header => _header; + ID3V2FrameHeader? _header; + ID3V2FrameHeader? get header => _header; ID3V2Frame(this._version); @override - MapEntry decode(List data) { + MapEntry? decode(List data) { final tag = latin1.decode(data.sublist(0, 4)); if (!consts.framesHeaders.keys.contains(tag)) { return null; @@ -46,27 +46,27 @@ abstract class ID3V2Frame implements Frame { _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( - getTagPseudonym(_header.tag), decodeBody(body, encoding)); + getTagPseudonym(_header!.tag), decodeBody(body, encoding)); } T decodeBody(List data, Encoding enc); @override - List encode(T value, [String key]); + List encode(T value, [String? key]); /// Returns size of frame in bytes List frameSizeInBytes(int value) { assert(value <= 16777216); - final block = List(4); + final block = List.filled(4, 0); final sevenBitMask = 0x7f; block[0] = (value >> 21) & sevenBitMask; @@ -79,13 +79,13 @@ abstract class ID3V2Frame implements Frame { 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; } @@ -133,7 +133,7 @@ abstract class ID3V2Frame implements Frame { int indexOfSplitPattern(List list, List 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); @@ -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)); diff --git a/lib/src/frames/id3v2/txxx_frame.dart b/lib/src/frames/id3v2/txxx_frame.dart index e201765..3c52059 100644 --- a/lib/src/frames/id3v2/txxx_frame.dart +++ b/lib/src/frames/id3v2/txxx_frame.dart @@ -42,11 +42,11 @@ class TXXXFrame extends ID3V2Frame { @override String get frameTag => 'TXXX'; - String _customTagName; + String? _customTagName; @override MapEntry decode(List data) { - final entry = super.decode(data); + final entry = super.decode(data)!; return MapEntry(_customTagName ?? frameTag, entry.value); } @@ -64,7 +64,7 @@ class TXXXFrame extends ID3V2Frame { } @override - List encode(String value, [String key]) { + List encode(String value, [String? key]) { final body = utf8.encode('$key${utf8.decode([0x00])}$value'); return [ ...utf8.encode(frameTag), diff --git a/lib/src/frames/id3v2/uslt_frame.dart b/lib/src/frames/id3v2/uslt_frame.dart index 1c60789..7de342c 100644 --- a/lib/src/frames/id3v2/uslt_frame.dart +++ b/lib/src/frames/id3v2/uslt_frame.dart @@ -43,7 +43,7 @@ class USLTFrame extends ID3V2Frame { } @override - List encode(UnSyncLyric value, [String key]) { + List encode(UnSyncLyric value, [String? key]) { final enc = header?.encoding ?? utf8; return [ diff --git a/lib/src/frames/id3v2/wxxx_frame.dart b/lib/src/frames/id3v2/wxxx_frame.dart index 999d7e5..64b4e89 100644 --- a/lib/src/frames/id3v2/wxxx_frame.dart +++ b/lib/src/frames/id3v2/wxxx_frame.dart @@ -41,7 +41,7 @@ class WXXXFrame extends ID3V2Frame { String get frameTag => 'WXXX'; @override - List encode(WURL value, [String key]) { + List encode(WURL value, [String? key]) { final vBytes = [ ...utf8.encode('${value.description}${utf8.decode([0x00])}'), ...latin1.encode(value.url) diff --git a/lib/src/model/attached_picture.dart b/lib/src/model/attached_picture.dart index 5c8fc2e..731f463 100644 --- a/lib/src/model/attached_picture.dart +++ b/lib/src/model/attached_picture.dart @@ -1,3 +1,5 @@ +// ignore_for_file: unnecessary_overrides + import 'dart:convert'; import 'key_entity.dart'; @@ -50,7 +52,7 @@ class AttachedPicture implements KeyEntity { /// Returns [String] representation of image type. /// /// eg. 'Band/Orchestra' or 'Cover (front)' etc... - String get imageType => _picturesType[imageTypeCode ?? 0x00]; + String get imageType => _picturesType[imageTypeCode]; AttachedPicture( this.mime, this.imageTypeCode, this.description, this.imageData); @@ -68,6 +70,9 @@ class AttachedPicture implements KeyEntity { @override bool operator ==(other) { + if (other is! AttachedPicture) { + return false; + } if (imageTypeCode != other.imageTypeCode) { return false; } @@ -77,9 +82,6 @@ class AttachedPicture implements KeyEntity { if (description != other.description) { return false; } - if (imageData == null && other.imageData == null) { - return true; - } if (imageData.length != other.imageData.length) { return false; } diff --git a/lib/src/model/comment.dart b/lib/src/model/comment.dart index cae61a5..b136f38 100644 --- a/lib/src/model/comment.dart +++ b/lib/src/model/comment.dart @@ -1,3 +1,5 @@ +// ignore_for_file: unnecessary_overrides + import 'key_entity.dart'; /// Class describes comment entity from ID3 v2.x tags @@ -23,6 +25,9 @@ class Comment implements KeyEntity { @override bool operator ==(other) { + if (other is! Comment) { + return false; + } if (lang != other.lang) { return false; } diff --git a/lib/src/model/consts.dart b/lib/src/model/consts.dart index 051a54d..f85745a 100644 --- a/lib/src/model/consts.dart +++ b/lib/src/model/consts.dart @@ -1,5 +1,7 @@ /// Generes constants from id3v1.1 specification -final id3v1generes = const [ +// ignore_for_file: constant_identifier_names + +const List id3v1generes = [ 'Blues', 'Classic Rock', 'Country', @@ -130,7 +132,7 @@ final id3v1generes = const [ ]; // v2.3+ frames -final framesHeaders = const { +const framesHeaders = { 'AENC': 'Audio encryption', 'APIC': 'Attached picture', 'COMM': 'Comments', @@ -228,7 +230,7 @@ final framesHeaders = const { 'TSST': 'Set subtitle' }; -final framesV23_V24 = const { +const framesV23_V24 = { 'EQUA': 'EQU2', 'IPLS': 'TIPL', 'RVAD': 'RVA2', @@ -239,7 +241,7 @@ final framesV23_V24 = const { 'TYER': 'TDRC' }; -final frameHeaderShortcutsID3V2_3 = const { +const frameHeaderShortcutsID3V2_3 = { 'TIT2': 'title', 'TPE1': 'artist', 'TALB': 'album', @@ -251,7 +253,7 @@ final frameHeaderShortcutsID3V2_3 = const { 'USLT': 'lyrics', }; -final frameHeaderShortcutsID3V2_3_Rev = const { +const frameHeaderShortcutsID3V2_3_Rev = { 'title': 'TIT2', 'artist': 'TPE1', 'album': 'TALB', @@ -265,7 +267,7 @@ final frameHeaderShortcutsID3V2_3_Rev = const { // todo support v2.2 // ignore: unused_field -final frameHeaderShortcutsID3V2_2 = const { +const frameHeaderShortcutsID3V2_2 = { 'TT2': 'title', 'TP1': 'artist', 'TAL': 'album', @@ -279,7 +281,7 @@ final frameHeaderShortcutsID3V2_2 = const { // todo support v2.2 // ignore: unused_field -final frameHeadersLegacy = const { +const frameHeadersLegacy = { 'BUF': 'RBUF', 'COM': 'COMM', 'CRA': 'AENC', diff --git a/lib/src/model/lyrics.dart b/lib/src/model/lyrics.dart index bac5f6c..24baf5c 100644 --- a/lib/src/model/lyrics.dart +++ b/lib/src/model/lyrics.dart @@ -1,3 +1,5 @@ +// ignore_for_file: unnecessary_overrides + import 'package:dart_tags/src/model/key_entity.dart'; /// Class describes unsynchronised lyrics entity from ID3 v2.x tags @@ -23,6 +25,9 @@ class UnSyncLyric implements KeyEntity { @override bool operator ==(other) { + if (other is! UnSyncLyric) { + return false; + } if (lang != other.lang) { return false; } diff --git a/lib/src/model/tag.dart b/lib/src/model/tag.dart index edb67a3..b636fcd 100644 --- a/lib/src/model/tag.dart +++ b/lib/src/model/tag.dart @@ -1,16 +1,21 @@ /// Class describes tag +// ignore_for_file: unnecessary_overrides + class Tag { /// Type of tag. At this time supports 'id3' - String type; + String? type; /// Version of tag. eg. '2.4.0' or '1.1' - String version; + String? version; /// The map of tags. Values are dynamic because it can be not only String. - Map tags; + late Map tags; @override bool operator ==(other) { + if (other is! Tag) { + return false; + } if (type != other.type) { return false; } diff --git a/lib/src/model/wurl.dart b/lib/src/model/wurl.dart index 095be4f..b5b4da7 100644 --- a/lib/src/model/wurl.dart +++ b/lib/src/model/wurl.dart @@ -1,3 +1,5 @@ +// ignore_for_file: unnecessary_overrides + import 'key_entity.dart'; /// Class describes url from WXXX tag @@ -20,6 +22,9 @@ class WURL implements KeyEntity { @override bool operator ==(other) { + if (other is! WURL) { + return false; + } if (description != other.description) { return false; } diff --git a/lib/src/readers/id3v2.dart b/lib/src/readers/id3v2.dart index ac102cd..7ee956f 100644 --- a/lib/src/readers/id3v2.dart +++ b/lib/src/readers/id3v2.dart @@ -1,3 +1,5 @@ +// ignore_for_file: non_constant_identifier_names + import 'dart:async'; import 'dart:convert'; @@ -67,23 +69,23 @@ class ID3V2Reader extends Reader { while (contin) { final fr = bytes.sublist(offset); - final frame = ff.getFrame(fr); + final frame = ff.getFrame(fr)! as ID3V2Frame; final m = frame.decode(fr); if (m?.key != null && m?.value != null) { if (m?.value is KeyEntity) { - if (tags[m.key] == null) { + if (tags[m!.key] == null) { tags[m.key] = {m.value.key: m.value}; } else { tags[m.key][m.value.key] = m.value; } } else { - tags[m.key] = m.value; + tags[m!.key] = m.value; } } - offset = offset + _headerLength + (frame?.header?.length ?? 0); - contin = offset < size && (frame?.header?.length ?? 0) != 0; + offset = offset + _headerLength + (frame.header?.length ?? 0); + contin = offset < size && (frame.header?.length ?? 0) != 0; } return tags; diff --git a/lib/src/tag_processor.dart b/lib/src/tag_processor.dart index 2a634ce..4b514c0 100644 --- a/lib/src/tag_processor.dart +++ b/lib/src/tag_processor.dart @@ -15,7 +15,7 @@ class ParsingException implements Exception { static const byteDataNull = 'Byte data can\'t be null'; static const byteArrayNull = 'Byte array can\'t be null'; - final cause; + final dynamic cause; ParsingException(this.cause); @override @@ -33,9 +33,9 @@ class TagProcessor { TagType.id3v2: ID3V2Writer(), }; - static TagType getTagType(String type, String version) { + static TagType getTagType(String type, String? version) { if (type.toLowerCase() == 'id3') { - switch (version.substring(0, 1)) { + switch (version!.substring(0, 1)) { case '1': return TagType.id3v1; case '2': @@ -48,8 +48,8 @@ class TagProcessor { } /// Returns the tags from the byte array - Future> getTagsFromByteArray(Future> bytes, - [List types]) async { + Future> getTagsFromByteArray(Future>? bytes, + [List? types]) async { if (await bytes == null) { throw ParsingException(ParsingException.byteArrayNull); } @@ -61,15 +61,15 @@ class TagProcessor { } for (var t in types) { - tags.add(await _readers[t].read(bytes)); + tags.add(await _readers[t]!.read(bytes!.then((value) => value))); } return tags; } /// Returns the tags from the ByteData - Future> getTagsFromByteData(ByteData bytes, - [List types]) async { + Future> getTagsFromByteData(ByteData? bytes, + [List? types]) async { if (bytes == null) { throw ParsingException(ParsingException.byteDataNull); } @@ -83,18 +83,18 @@ class TagProcessor { } for (var t in types) { - tags.add(await _readers[t].read(c.future)); + tags.add(await _readers[t]!.read(c.future)); } return tags; } - Future> putTagsToByteArray(Future> bytes, - [List tags]) async { + Future> putTagsToByteArray(Future?> bytes, + [List? tags]) async { if (await bytes == null) { throw ParsingException(ParsingException.byteArrayNull); } - var b = await bytes; + var b = (await bytes)!; if (tags == null || tags.isEmpty) { for (var w in _writers.values) { @@ -105,7 +105,7 @@ class TagProcessor { } for (var t in tags) { - final w = _writers[getTagType(t.type, t.version)]; + final w = _writers[getTagType(t.type!, t.version)]!; b = await w.write(b, t); } diff --git a/lib/src/writers/id3v2.dart b/lib/src/writers/id3v2.dart index d7c4dd9..f64b910 100644 --- a/lib/src/writers/id3v2.dart +++ b/lib/src/writers/id3v2.dart @@ -1,9 +1,9 @@ import 'dart:async'; import 'dart:convert'; +import 'package:dart_tags/src/frames/frame.dart'; import 'package:dart_tags/src/model/tag.dart'; import 'package:dart_tags/src/writers/writer.dart'; -import 'package:dart_tags/src/frames/frame.dart'; class ID3V2Writer extends Writer { ID3V2Writer() : super('ID3', '2.4'); @@ -15,19 +15,17 @@ class ID3V2Writer extends Writer { final ff = FrameFactory('ID3', '2.4.0'); tag.tags.forEach((k, v) { - if (k != null) { - final frame = ff.getFrame(k); - if (v is List) { - v.forEach((element) { - tagsF.addAll(frame?.encode(element, k)); - }); - } else if (v is Map) { - v.values.forEach((element) { - tagsF.addAll(frame?.encode(element, k)); - }); - } else { - tagsF.addAll(frame?.encode(v, k)); + final frame = ff.getFrame(k)!; + if (v is List) { + for (var element in v) { + tagsF.addAll(frame.encode(element, k)); + } + } else if (v is Map) { + for (var element in v.values) { + tagsF.addAll(frame.encode(element, k)); } + } else { + tagsF.addAll(frame.encode(v, k)); } }); @@ -46,7 +44,7 @@ class ID3V2Writer extends Writer { static List frameSizeInBytes(int value) { assert(value <= 16777216); - final block = List(4); + final block = List.filled(4, 0); final sevenBitMask = 0x7f; block[0] = (value >> 21) & sevenBitMask; diff --git a/pubspec.yaml b/pubspec.yaml index 2aa86aa..f8c3e88 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,16 +1,16 @@ name: dart_tags description: The library for work with music tags like ID3. Written on pure Dart. It can be used in flutter, web, and vm projects. -version: 0.3.1 +version: 0.4.0 homepage: https://github.com/NiKoTron/dart-tags environment: - sdk: '>=2.3.0 <3.0.0' + sdk: ">=2.12.0 <3.0.0" dependencies: - utf: ^0.9.0+5 - collection: ^1.14.13 - convert: ^2.1.1 + utf_convert: ^0.10.0+1 + collection: ^1.15.0 + convert: ^3.0.1 dev_dependencies: - pedantic: ^1.9.2 - test: ^1.15.3 + lints: ^1.0.1 + test: ^1.19.1 diff --git a/test/dart_tags_test.dart b/test/dart_tags_test.dart index 9e2ab29..5b898f3 100644 --- a/test/dart_tags_test.dart +++ b/test/dart_tags_test.dart @@ -5,7 +5,6 @@ import 'dart:typed_data'; import 'package:dart_tags/dart_tags.dart'; import 'package:collection/collection.dart' as collection; import 'package:dart_tags/src/frames/id3v2/comm_frame.dart'; -import 'package:dart_tags/src/model/comment.dart'; import 'package:dart_tags/src/readers/id3v1.dart'; import 'package:dart_tags/src/readers/id3v2.dart'; import 'package:dart_tags/src/utils/image_extractor.dart'; @@ -14,11 +13,11 @@ import 'package:dart_tags/src/writers/id3v2.dart'; import 'package:test/test.dart'; void main() { - File file1; - File file2; - File file3; - File filev23USLT; - File picture; + late File file1; + late File file2; + late File file3; + late File filev23USLT; + late File picture; const outputDir = 'test/output'; @@ -117,7 +116,7 @@ void main() { 0x72 ]; - final decodeList = COMMFrame().decode(data); + final decodeList = COMMFrame().decode(data)!; expect(decodeList.value.comment, equals('commentador')); expect(decodeList.value.description, equals('dessu')); @@ -227,7 +226,7 @@ void main() { ]), [tag1, tag2]); - final _fr = () async => foo; + Future> _fr() async => foo; final rdr1 = ID3V1Reader(); final t1 = await rdr1.read(_fr()); @@ -407,7 +406,7 @@ void main() { ]), [tag2]); - final _fr = () async => foo; + Future> _fr() async => foo; final rdr2 = ID3V2Reader(); final t2 = await rdr2.read(_fr()); @@ -474,7 +473,7 @@ void main() { final f = await r.read(blocks); // ignore: avoid_as - final AttachedPicture pic = (f.tags['picture'] as Map)['Other']; + final AttachedPicture? pic = (f.tags['picture'] as Map)['Other']; expect(pic, equals(pic1)); }); @@ -487,7 +486,6 @@ void main() { .getTagsFromByteArray(file.readAsBytes(), [TagType.id3v2]); expect(tags.length, 1); - expect(tags[0] != null, true); expect(tags[0].type, 'ID3'); expect(tags[0].version, '2.3.0'); expect(tags[0].tags.isNotEmpty, true); diff --git a/tool/assets/dart-tags-logo.svg b/tool/assets/dart-tags-logo.svg new file mode 100644 index 0000000..f2103a4 --- /dev/null +++ b/tool/assets/dart-tags-logo.svg @@ -0,0 +1,176 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + tags + + diff --git a/tool/travis/swag.sh b/tool/travis/swag.sh index 697a9e2..0e7251d 100755 --- a/tool/travis/swag.sh +++ b/tool/travis/swag.sh @@ -3,7 +3,7 @@ pub get || exit $ EXIT_CODE=0 -dartfmt -n --set-exit-if-changed . || EXIT_CODE=$? +dart format --fix --set-exit-if-changed . || EXIT_CODE=$? dartanalyzer --fatal-infos --fatal-warnings . || EXIT_CODE=$? exit $EXIT_CODE