id3taginator 0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.idea/.gitignore +8 -0
- data/.idea/ID3Taginator.iml +73 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/.rspec +3 -0
- data/.rubocop.yml +26 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +408 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/id3taginator.gemspec +37 -0
- data/lib/id3taginator/audio_file.rb +136 -0
- data/lib/id3taginator/errors/id3_tag_error.rb +12 -0
- data/lib/id3taginator/extensions/argument_check.rb +88 -0
- data/lib/id3taginator/extensions/comparable.rb +28 -0
- data/lib/id3taginator/extensions/encodable.rb +215 -0
- data/lib/id3taginator/extensions/optionable.rb +73 -0
- data/lib/id3taginator/frames/buffer/entities/buffer.rb +26 -0
- data/lib/id3taginator/frames/buffer/rbuf_recommended_buffer_size_frame.rb +59 -0
- data/lib/id3taginator/frames/buffer_frames.rb +32 -0
- data/lib/id3taginator/frames/comment/comm_comment_frame.rb +56 -0
- data/lib/id3taginator/frames/comment/entities/comment.rb +26 -0
- data/lib/id3taginator/frames/comment_frames.rb +42 -0
- data/lib/id3taginator/frames/count/entities/popularimeter.rb +26 -0
- data/lib/id3taginator/frames/count/pcnt_play_counter_frame.rb +40 -0
- data/lib/id3taginator/frames/count/popm_popularimeter_frame.rb +52 -0
- data/lib/id3taginator/frames/count_frames.rb +51 -0
- data/lib/id3taginator/frames/custom_frame.rb +39 -0
- data/lib/id3taginator/frames/custom_frames.rb +54 -0
- data/lib/id3taginator/frames/encryption/aenc_audio_encryption.rb +54 -0
- data/lib/id3taginator/frames/encryption/encr_encryption_method_frame.rb +49 -0
- data/lib/id3taginator/frames/encryption/entities/audio_encryption.rb +28 -0
- data/lib/id3taginator/frames/encryption/entities/encryption_method.rb +26 -0
- data/lib/id3taginator/frames/encryption_frames.rb +77 -0
- data/lib/id3taginator/frames/frameable.rb +75 -0
- data/lib/id3taginator/frames/geo/entities/encapsulated_object.rb +28 -0
- data/lib/id3taginator/frames/geo/geob_general_encapsulated_object_frame.rb +59 -0
- data/lib/id3taginator/frames/geo_frames.rb +41 -0
- data/lib/id3taginator/frames/grouping/entities/group_identification.rb +26 -0
- data/lib/id3taginator/frames/grouping/grid_group_identification_frame.rb +49 -0
- data/lib/id3taginator/frames/grouping/grp1_grouping_frame.rb +40 -0
- data/lib/id3taginator/frames/grouping_frames.rb +61 -0
- data/lib/id3taginator/frames/has_id.rb +51 -0
- data/lib/id3taginator/frames/id3v23_frame_flags.rb +64 -0
- data/lib/id3taginator/frames/id3v24_frame_flags.rb +80 -0
- data/lib/id3taginator/frames/id3v2_frame.rb +249 -0
- data/lib/id3taginator/frames/id3v2_frame_factory.rb +98 -0
- data/lib/id3taginator/frames/ipl/entities/involved_person.rb +24 -0
- data/lib/id3taginator/frames/ipl/ipls_involved_people_frame.rb +48 -0
- data/lib/id3taginator/frames/ipl_frames.rb +31 -0
- data/lib/id3taginator/frames/lyrics/entities/unsync_lyrics.rb +26 -0
- data/lib/id3taginator/frames/lyrics/uslt_unsync_lyrics_frame.rb +56 -0
- data/lib/id3taginator/frames/lyrics_frames.rb +42 -0
- data/lib/id3taginator/frames/mcdi/mcdi_music_cd_identifier_frame.rb +40 -0
- data/lib/id3taginator/frames/mcdi_frames.rb +28 -0
- data/lib/id3taginator/frames/picture/apic_picture_frame.rb +106 -0
- data/lib/id3taginator/frames/picture/entities/picture.rb +32 -0
- data/lib/id3taginator/frames/picture_frames.rb +51 -0
- data/lib/id3taginator/frames/private/entities/private_frame.rb +24 -0
- data/lib/id3taginator/frames/private/priv_private_frame.rb +45 -0
- data/lib/id3taginator/frames/private_frames.rb +40 -0
- data/lib/id3taginator/frames/text/entities/copyright.rb +24 -0
- data/lib/id3taginator/frames/text/entities/date.rb +24 -0
- data/lib/id3taginator/frames/text/entities/part_of_set.rb +24 -0
- data/lib/id3taginator/frames/text/entities/time.rb +24 -0
- data/lib/id3taginator/frames/text/entities/track_number.rb +24 -0
- data/lib/id3taginator/frames/text/entities/user_info.rb +24 -0
- data/lib/id3taginator/frames/text/talb_album_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tbpm_bpm_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tcom_composer_frame.rb +42 -0
- data/lib/id3taginator/frames/text/tcon_genre_frame.rb +104 -0
- data/lib/id3taginator/frames/text/tcop_copyright_frame.rb +55 -0
- data/lib/id3taginator/frames/text/tdat_date_frame.rb +60 -0
- data/lib/id3taginator/frames/text/tdly_playlist_delay_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tenc_encoded_by_frame.rb +40 -0
- data/lib/id3taginator/frames/text/text_writers_frame.rb +43 -0
- data/lib/id3taginator/frames/text/tflt_file_type_frame.rb +71 -0
- data/lib/id3taginator/frames/text/time_time_frame.rb +60 -0
- data/lib/id3taginator/frames/text/tit1_content_group_description_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tit2_title_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tit3_subtitle_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tkey_initial_key_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tlan_language_frame.rb +48 -0
- data/lib/id3taginator/frames/text/tlen_length_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tmed_media_type_frame.rb +40 -0
- data/lib/id3taginator/frames/text/toal_original_album_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tofn_original_filename_frame.rb +40 -0
- data/lib/id3taginator/frames/text/toly_original_writers_frame.rb +43 -0
- data/lib/id3taginator/frames/text/tope_original_artists_frame.rb +43 -0
- data/lib/id3taginator/frames/text/tory_original_release_year_frame.rb +42 -0
- data/lib/id3taginator/frames/text/town_file_owner_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tpe1_artist_frame.rb +43 -0
- data/lib/id3taginator/frames/text/tpe2_album_artist_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tpe3_conductor_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tpe4_modified_by_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tpos_part_of_set_frame.rb +50 -0
- data/lib/id3taginator/frames/text/tpub_publisher_frame.rb +40 -0
- data/lib/id3taginator/frames/text/trck_track_number_frame.rb +50 -0
- data/lib/id3taginator/frames/text/trda_recording_dates_frame.rb +42 -0
- data/lib/id3taginator/frames/text/trsn_internet_radio_station_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tsiz_size_frame.rb +41 -0
- data/lib/id3taginator/frames/text/tsoa_album_sort_order_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tsop_performer_sort_order_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tsot_title_sort_order_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tsrc_isrc_frame.rb +40 -0
- data/lib/id3taginator/frames/text/tsse_encoder_frame.rb +40 -0
- data/lib/id3taginator/frames/text/txxx_user_text_info_frame.rb +51 -0
- data/lib/id3taginator/frames/text/tyer_year_frame.rb +42 -0
- data/lib/id3taginator/frames/text_frames.rb +840 -0
- data/lib/id3taginator/frames/tos/entities/ownership.rb +26 -0
- data/lib/id3taginator/frames/tos/entities/terms_of_use.rb +24 -0
- data/lib/id3taginator/frames/tos/owne_ownership_frame.rb +53 -0
- data/lib/id3taginator/frames/tos/user_terms_of_use_frame.rb +49 -0
- data/lib/id3taginator/frames/tos_frames.rb +54 -0
- data/lib/id3taginator/frames/ufid/entities/ufid_info.rb +24 -0
- data/lib/id3taginator/frames/ufid/ufid_unique_file_identifier_frame.rb +47 -0
- data/lib/id3taginator/frames/ufid_frames.rb +40 -0
- data/lib/id3taginator/frames/url/entities/user_info.rb +24 -0
- data/lib/id3taginator/frames/url/wcom_commercial_url_frame.rb +40 -0
- data/lib/id3taginator/frames/url/wcop_copyright_url_frame.rb +40 -0
- data/lib/id3taginator/frames/url/woaf_official_file_webpage_frame.rb +40 -0
- data/lib/id3taginator/frames/url/woar_official_artist_webpage_frame.rb +40 -0
- data/lib/id3taginator/frames/url/woas_official_source_webpage_frame.rb +40 -0
- data/lib/id3taginator/frames/url/wors_official_radio_station_homepage_frame.rb +40 -0
- data/lib/id3taginator/frames/url/wpay_payment_url_frame.rb +40 -0
- data/lib/id3taginator/frames/url/wpub_official_publisher_webpage_frame.rb +40 -0
- data/lib/id3taginator/frames/url/wxxx_user_url_link_frame.rb +50 -0
- data/lib/id3taginator/frames/url_frames.rb +195 -0
- data/lib/id3taginator/genres.rb +168 -0
- data/lib/id3taginator/header/id3v23_extended_header.rb +37 -0
- data/lib/id3taginator/header/id3v24_extended_header.rb +100 -0
- data/lib/id3taginator/header/id3v2_flags.rb +64 -0
- data/lib/id3taginator/id3v1_tag.rb +156 -0
- data/lib/id3taginator/id3v22_tag.rb +30 -0
- data/lib/id3taginator/id3v23_tag.rb +63 -0
- data/lib/id3taginator/id3v24_tag.rb +75 -0
- data/lib/id3taginator/id3v2_tag.rb +241 -0
- data/lib/id3taginator/options/options.rb +33 -0
- data/lib/id3taginator/util/compress_util.rb +25 -0
- data/lib/id3taginator/util/math_util.rb +68 -0
- data/lib/id3taginator/util/sync_util.rb +65 -0
- data/lib/id3taginator.rb +449 -0
- metadata +198 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Id3Taginator
|
4
|
+
module Util
|
5
|
+
module SyncUtil
|
6
|
+
# adds synchronization bytes to the given stream. 1111_1111 111X_XXXX will be changed to
|
7
|
+
# 1111_1111 0000_0000 111X_XXXX
|
8
|
+
# also 1111_1111 0000_0000 must be changed to 1111_1111 0000_0000 0000_0000
|
9
|
+
#
|
10
|
+
# @param stream [StringIO, IO, File] the stream to add synchronization
|
11
|
+
#
|
12
|
+
# @return [String] the result byte array represented as a string (str.bytes is the bytes array)
|
13
|
+
def self.add_synchronization(stream)
|
14
|
+
result = []
|
15
|
+
|
16
|
+
until stream.eof?
|
17
|
+
curr = stream.readbyte
|
18
|
+
result << curr
|
19
|
+
|
20
|
+
# curr is not FF > nothing to do
|
21
|
+
next if curr != 255
|
22
|
+
|
23
|
+
# if this is the end, add 00 for padding
|
24
|
+
if stream.eof?
|
25
|
+
result << 0
|
26
|
+
break
|
27
|
+
end
|
28
|
+
|
29
|
+
next_byte = stream.readbyte
|
30
|
+
# add 00 if next byte is 111x_xxxx or 00 (FF 00)
|
31
|
+
result << 0 if next_byte >= 224 || next_byte.zero?
|
32
|
+
stream.seek(-1, IO::SEEK_CUR)
|
33
|
+
end
|
34
|
+
|
35
|
+
result.pack('C*')
|
36
|
+
end
|
37
|
+
|
38
|
+
# undo synchroniation, means 1111_1111 0000_0000 111X_XXXX -> 1111_1111 111X_XXXX and
|
39
|
+
# 1111_1111 0000_0000 0000_0000 -> 1111_1111 0000_0000
|
40
|
+
#
|
41
|
+
# @param stream [StringIO, IO, File] the stream to remove synchronization
|
42
|
+
#
|
43
|
+
# @return [String] the result byte array represented as a string (str.bytes is the bytes array)
|
44
|
+
def self.undo_synchronization(stream)
|
45
|
+
result = []
|
46
|
+
|
47
|
+
until stream.eof?
|
48
|
+
curr = stream.readbyte
|
49
|
+
result << curr
|
50
|
+
|
51
|
+
# curr is not FF > nothing to do
|
52
|
+
next if curr != 255
|
53
|
+
|
54
|
+
# should never happen, since there should be a 00 padding, just in case catch the case if not
|
55
|
+
break if stream.eof?
|
56
|
+
|
57
|
+
next_byte = stream.readbyte
|
58
|
+
result << next_byte unless next_byte.zero?
|
59
|
+
end
|
60
|
+
|
61
|
+
result.pack('C*')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/id3taginator.rb
ADDED
@@ -0,0 +1,449 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
require 'zlib'
|
5
|
+
|
6
|
+
require 'id3taginator/util/math_util'
|
7
|
+
require 'id3taginator/util/sync_util'
|
8
|
+
require 'id3taginator/util/compress_util'
|
9
|
+
|
10
|
+
require 'id3taginator/errors/id3_tag_error'
|
11
|
+
|
12
|
+
require 'id3taginator/extensions/encodable'
|
13
|
+
require 'id3taginator/extensions/comparable'
|
14
|
+
require 'id3taginator/extensions/argument_check'
|
15
|
+
|
16
|
+
require 'id3taginator/genres'
|
17
|
+
|
18
|
+
require 'id3taginator/options/options'
|
19
|
+
require 'id3taginator/extensions/optionable'
|
20
|
+
|
21
|
+
require 'id3taginator/frames/has_id'
|
22
|
+
|
23
|
+
require 'id3taginator/header/id3v23_extended_header'
|
24
|
+
require 'id3taginator/header/id3v24_extended_header'
|
25
|
+
|
26
|
+
require 'id3taginator/frames/id3v23_frame_flags'
|
27
|
+
require 'id3taginator/frames/id3v24_frame_flags'
|
28
|
+
|
29
|
+
require 'id3taginator/frames/id3v2_frame'
|
30
|
+
|
31
|
+
require 'id3taginator/frames/buffer/entities/buffer'
|
32
|
+
|
33
|
+
require 'id3taginator/frames/count/entities/popularimeter'
|
34
|
+
|
35
|
+
require 'id3taginator/frames/geo/entities/encapsulated_object'
|
36
|
+
|
37
|
+
require 'id3taginator/frames/lyrics/entities/unsync_lyrics'
|
38
|
+
|
39
|
+
require 'id3taginator/frames/private/entities/private_frame'
|
40
|
+
|
41
|
+
require 'id3taginator/frames/tos/entities/ownership'
|
42
|
+
require 'id3taginator/frames/tos/entities/terms_of_use'
|
43
|
+
|
44
|
+
require 'id3taginator/frames/ufid/entities/ufid_info'
|
45
|
+
|
46
|
+
require 'id3taginator/frames/text/entities/copyright'
|
47
|
+
require 'id3taginator/frames/text/entities/date'
|
48
|
+
require 'id3taginator/frames/text/entities/part_of_set'
|
49
|
+
require 'id3taginator/frames/text/entities/time'
|
50
|
+
require 'id3taginator/frames/text/entities/track_number'
|
51
|
+
require 'id3taginator/frames/text/entities/user_info'
|
52
|
+
|
53
|
+
require 'id3taginator/frames/url/entities/user_info'
|
54
|
+
|
55
|
+
require 'id3taginator/frames/ipl/entities/involved_person'
|
56
|
+
|
57
|
+
require 'id3taginator/frames/comment/entities/comment'
|
58
|
+
|
59
|
+
require 'id3taginator/frames/picture/entities/picture'
|
60
|
+
|
61
|
+
require 'id3taginator/frames/ufid/ufid_unique_file_identifier_frame'
|
62
|
+
|
63
|
+
require 'id3taginator/frames/mcdi/mcdi_music_cd_identifier_frame'
|
64
|
+
|
65
|
+
require 'id3taginator/frames/encryption/entities/encryption_method'
|
66
|
+
require 'id3taginator/frames/encryption/entities/audio_encryption'
|
67
|
+
|
68
|
+
require 'id3taginator/frames/grouping/entities/group_identification'
|
69
|
+
|
70
|
+
require 'id3taginator/frames/text/talb_album_frame'
|
71
|
+
require 'id3taginator/frames/text/tpe1_artist_frame'
|
72
|
+
require 'id3taginator/frames/text/tpe2_album_artist_frame'
|
73
|
+
require 'id3taginator/frames/text/tpe3_conductor_frame'
|
74
|
+
require 'id3taginator/frames/text/tpe4_modified_by_frame'
|
75
|
+
require 'id3taginator/frames/text/tbpm_bpm_frame'
|
76
|
+
require 'id3taginator/frames/text/tcom_composer_frame'
|
77
|
+
require 'id3taginator/frames/text/tcon_genre_frame'
|
78
|
+
require 'id3taginator/frames/text/tcop_copyright_frame'
|
79
|
+
require 'id3taginator/frames/text/tdat_date_frame'
|
80
|
+
require 'id3taginator/frames/text/tdly_playlist_delay_frame'
|
81
|
+
require 'id3taginator/frames/text/tenc_encoded_by_frame'
|
82
|
+
require 'id3taginator/frames/text/text_writers_frame'
|
83
|
+
require 'id3taginator/frames/text/tflt_file_type_frame'
|
84
|
+
require 'id3taginator/frames/text/time_time_frame'
|
85
|
+
require 'id3taginator/frames/text/tit1_content_group_description_frame'
|
86
|
+
require 'id3taginator/frames/text/tit2_title_frame'
|
87
|
+
require 'id3taginator/frames/text/tit3_subtitle_frame'
|
88
|
+
require 'id3taginator/frames/text/tkey_initial_key_frame'
|
89
|
+
require 'id3taginator/frames/text/tlan_language_frame'
|
90
|
+
require 'id3taginator/frames/text/tlen_length_frame'
|
91
|
+
require 'id3taginator/frames/text/tmed_media_type_frame'
|
92
|
+
require 'id3taginator/frames/text/toal_original_album_frame'
|
93
|
+
require 'id3taginator/frames/text/tofn_original_filename_frame'
|
94
|
+
require 'id3taginator/frames/text/toly_original_writers_frame'
|
95
|
+
require 'id3taginator/frames/text/tope_original_artists_frame'
|
96
|
+
require 'id3taginator/frames/text/tory_original_release_year_frame'
|
97
|
+
require 'id3taginator/frames/text/town_file_owner_frame'
|
98
|
+
require 'id3taginator/frames/text/tpos_part_of_set_frame'
|
99
|
+
require 'id3taginator/frames/text/tpub_publisher_frame'
|
100
|
+
require 'id3taginator/frames/text/trck_track_number_frame'
|
101
|
+
require 'id3taginator/frames/text/trda_recording_dates_frame'
|
102
|
+
require 'id3taginator/frames/text/trsn_internet_radio_station_frame'
|
103
|
+
require 'id3taginator/frames/text/tsiz_size_frame'
|
104
|
+
require 'id3taginator/frames/text/tsoa_album_sort_order_frame'
|
105
|
+
require 'id3taginator/frames/text/tsop_performer_sort_order_frame'
|
106
|
+
require 'id3taginator/frames/text/tsot_title_sort_order_frame'
|
107
|
+
require 'id3taginator/frames/text/tsrc_isrc_frame'
|
108
|
+
require 'id3taginator/frames/text/tsse_encoder_frame'
|
109
|
+
require 'id3taginator/frames/text/tyer_year_frame'
|
110
|
+
require 'id3taginator/frames/text/txxx_user_text_info_frame'
|
111
|
+
|
112
|
+
require 'id3taginator/frames/url/wcom_commercial_url_frame'
|
113
|
+
require 'id3taginator/frames/url/wcop_copyright_url_frame'
|
114
|
+
require 'id3taginator/frames/url/woaf_official_file_webpage_frame'
|
115
|
+
require 'id3taginator/frames/url/woar_official_artist_webpage_frame'
|
116
|
+
require 'id3taginator/frames/url/woas_official_source_webpage_frame'
|
117
|
+
require 'id3taginator/frames/url/wors_official_radio_station_homepage_frame'
|
118
|
+
require 'id3taginator/frames/url/wpay_payment_url_frame'
|
119
|
+
require 'id3taginator/frames/url/wpub_official_publisher_webpage_frame'
|
120
|
+
require 'id3taginator/frames/url/wxxx_user_url_link_frame'
|
121
|
+
|
122
|
+
require 'id3taginator/frames/ipl/ipls_involved_people_frame'
|
123
|
+
|
124
|
+
require 'id3taginator/frames/lyrics/uslt_unsync_lyrics_frame'
|
125
|
+
|
126
|
+
require 'id3taginator/frames/comment/comm_comment_frame'
|
127
|
+
|
128
|
+
require 'id3taginator/frames/picture/apic_picture_frame'
|
129
|
+
|
130
|
+
require 'id3taginator/frames/geo/geob_general_encapsulated_object_frame'
|
131
|
+
|
132
|
+
require 'id3taginator/frames/count/pcnt_play_counter_frame'
|
133
|
+
require 'id3taginator/frames/count/popm_popularimeter_frame'
|
134
|
+
|
135
|
+
require 'id3taginator/frames/buffer/rbuf_recommended_buffer_size_frame'
|
136
|
+
|
137
|
+
require 'id3taginator/frames/tos/user_terms_of_use_frame'
|
138
|
+
require 'id3taginator/frames/tos/owne_ownership_frame'
|
139
|
+
|
140
|
+
require 'id3taginator/frames/encryption/aenc_audio_encryption'
|
141
|
+
require 'id3taginator/frames/encryption/encr_encryption_method_frame'
|
142
|
+
|
143
|
+
require 'id3taginator/frames/grouping/grid_group_identification_frame'
|
144
|
+
require 'id3taginator/frames/grouping/grp1_grouping_frame'
|
145
|
+
|
146
|
+
require 'id3taginator/frames/private/priv_private_frame'
|
147
|
+
|
148
|
+
require 'id3taginator/frames/custom_frame'
|
149
|
+
|
150
|
+
require 'id3taginator/frames/id3v2_frame_factory'
|
151
|
+
|
152
|
+
require 'id3taginator/frames/frameable'
|
153
|
+
require 'id3taginator/frames/text_frames'
|
154
|
+
require 'id3taginator/frames/url_frames'
|
155
|
+
require 'id3taginator/frames/ufid_frames'
|
156
|
+
require 'id3taginator/frames/ipl_frames'
|
157
|
+
require 'id3taginator/frames/mcdi_frames'
|
158
|
+
require 'id3taginator/frames/lyrics_frames'
|
159
|
+
require 'id3taginator/frames/comment_frames'
|
160
|
+
require 'id3taginator/frames/picture_frames'
|
161
|
+
require 'id3taginator/frames/geo_frames'
|
162
|
+
require 'id3taginator/frames/count_frames'
|
163
|
+
require 'id3taginator/frames/buffer_frames'
|
164
|
+
require 'id3taginator/frames/tos_frames'
|
165
|
+
require 'id3taginator/frames/encryption_frames'
|
166
|
+
require 'id3taginator/frames/grouping_frames'
|
167
|
+
require 'id3taginator/frames/private_frames'
|
168
|
+
require 'id3taginator/frames/custom_frames'
|
169
|
+
|
170
|
+
require 'id3taginator/id3v1_tag'
|
171
|
+
require 'id3taginator/header/id3v2_flags'
|
172
|
+
require 'id3taginator/id3v2_tag'
|
173
|
+
require 'id3taginator/id3v22_tag'
|
174
|
+
require 'id3taginator/id3v23_tag'
|
175
|
+
require 'id3taginator/id3v24_tag'
|
176
|
+
require 'id3taginator/audio_file'
|
177
|
+
|
178
|
+
module Id3Taginator
|
179
|
+
class Id3Taginator
|
180
|
+
include Extensions::Optionable
|
181
|
+
|
182
|
+
def initialize(options)
|
183
|
+
@options = options
|
184
|
+
end
|
185
|
+
|
186
|
+
# builds an audio file
|
187
|
+
#
|
188
|
+
# @param file [StringIO, IO, File] the file stream
|
189
|
+
# @param no_tag_parsing [Boolean] if true, no Id3v2 tag is parsed
|
190
|
+
#
|
191
|
+
# @return [Id3Taginator::AudioFile] the parsed audio file
|
192
|
+
def build_by_file(file, no_tag_parsing: false)
|
193
|
+
AudioFile.new(file, @options, no_tag_parsing: no_tag_parsing)
|
194
|
+
end
|
195
|
+
|
196
|
+
# builds an audio file
|
197
|
+
#
|
198
|
+
# @param path [String] path to the mp3 file
|
199
|
+
# @param no_tag_parsing [Boolean] if true, no Id3v2 tag is parsed
|
200
|
+
#
|
201
|
+
# @return [Id3Taginator::AudioFile] the parsed audio file
|
202
|
+
def build_by_path(path, no_tag_parsing: false)
|
203
|
+
AudioFile.new(File.new(path), @options, no_tag_parsing: no_tag_parsing)
|
204
|
+
end
|
205
|
+
|
206
|
+
# builds an audio file
|
207
|
+
#
|
208
|
+
# @param bytes [String] String representing the byte array of the file
|
209
|
+
# @param no_tag_parsing [Boolean] if true, no Id3v2 tag is parsed
|
210
|
+
#
|
211
|
+
# @return [Id3Taginator::AudioFile] the parsed audio file
|
212
|
+
def build_by_bytes(bytes, no_tag_parsing: false)
|
213
|
+
AudioFile.new(StringIO.new(bytes), @options, no_tag_parsing: no_tag_parsing)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
# creates an Id3Taginator instance and applies the options to all created audio files
|
218
|
+
#
|
219
|
+
# @return [Id3Taginator] instance to set global options to be applied to all new audio files
|
220
|
+
def self.global_options
|
221
|
+
Id3Taginator.new(Options::Options.new)
|
222
|
+
end
|
223
|
+
|
224
|
+
# builds an audio file
|
225
|
+
#
|
226
|
+
# @param path [String] path to the mp3 file
|
227
|
+
# @param no_tag_parsing [Boolean] if true, no Id3v2 tag is parsed
|
228
|
+
#
|
229
|
+
# @return [Id3Taginator::AudioFile] the parsed audio file
|
230
|
+
def self.build_by_path(path, options = Options::Options.new, no_tag_parsing: false)
|
231
|
+
AudioFile.new(File.new(path), options, no_tag_parsing: no_tag_parsing)
|
232
|
+
end
|
233
|
+
|
234
|
+
# builds an audio file
|
235
|
+
#
|
236
|
+
# @param file [StringIO, IO, File] the file stream
|
237
|
+
# @param no_tag_parsing [Boolean] if true, no Id3v2 tag is parsed
|
238
|
+
#
|
239
|
+
# @return [Id3Taginator::AudioFile] the parsed audio file
|
240
|
+
def self.build_by_file(file, options = Options::Options.new, no_tag_parsing: false)
|
241
|
+
AudioFile.new(file, options, no_tag_parsing: no_tag_parsing)
|
242
|
+
end
|
243
|
+
|
244
|
+
# builds an audio file
|
245
|
+
#
|
246
|
+
# @param bytes [String] String representing the byte array of the file
|
247
|
+
# @param no_tag_parsing [Boolean] if true, no Id3v2 tag is parsed
|
248
|
+
#
|
249
|
+
# @return [Id3Taginator::AudioFile] the parsed audio file
|
250
|
+
def self.build_by_bytes(bytes, options = Options::Options.new, no_tag_parsing: false)
|
251
|
+
AudioFile.new(StringIO.new(bytes), options, no_tag_parsing: no_tag_parsing)
|
252
|
+
end
|
253
|
+
|
254
|
+
# creates a Recommended Buffer Object
|
255
|
+
#
|
256
|
+
# @param buffer_size [Integer] the buffer size
|
257
|
+
# @param embedded_info_flag [Boolean] true if info embedded, else false
|
258
|
+
# @param offset_next_tag [Integer, nil] optional byte offset to the next tag
|
259
|
+
def self.create_buffer(buffer_size, embedded_info_flag, offset_next_tag)
|
260
|
+
Frames::Buffer::Entities::Buffer.new(buffer_size, embedded_info_flag, offset_next_tag)
|
261
|
+
end
|
262
|
+
|
263
|
+
# Creates a Comment Object
|
264
|
+
#
|
265
|
+
# @param language [String] 3 character language, like eng
|
266
|
+
# @param descriptor [String] comment description
|
267
|
+
# @param text [String] the comment
|
268
|
+
def self.create_comment(language, descriptor, text)
|
269
|
+
Frames::Comment::Entities::Comment.new(language, descriptor, text)
|
270
|
+
end
|
271
|
+
|
272
|
+
# creates a Popularimeter Object
|
273
|
+
#
|
274
|
+
# @param email [String] email for the rating
|
275
|
+
# @param rating [Integer] rating 0 - 255
|
276
|
+
# @param counter [Integer] the counter
|
277
|
+
def self.create_popularimeter(email, rating, counter)
|
278
|
+
Frames::Count::Entities::Popularimeter.new(email, rating, counter)
|
279
|
+
end
|
280
|
+
|
281
|
+
# creates Audio Encryption Object
|
282
|
+
#
|
283
|
+
# @param owner_id [String] the owner id
|
284
|
+
# @param preview_start [Integer] preview start in number of frames
|
285
|
+
# @param preview_length [Integer] length of preview in frames
|
286
|
+
# @param encryption_info [String] the encryption info
|
287
|
+
def self.create_audio_encryption(owner_id, preview_start, preview_length, encryption_info)
|
288
|
+
Frames::Encryption::Entities::AudioEncryption.new(owner_id, preview_start, preview_length, encryption_info)
|
289
|
+
end
|
290
|
+
|
291
|
+
# creates Encryption Method Object
|
292
|
+
#
|
293
|
+
# @param owner_id [String] the owner id
|
294
|
+
# @param method_symbol [Integer] a number between 0 and 255
|
295
|
+
# @param encryption_data [String] encryption data
|
296
|
+
def self.create_encryption_method(owner_id, method_symbol, encryption_data)
|
297
|
+
Frames::Encryption::Entities::EncryptionMethod.new(owner_id, method_symbol, encryption_data)
|
298
|
+
end
|
299
|
+
|
300
|
+
# create encapsulated object
|
301
|
+
#
|
302
|
+
# @param mime_type [String] the mime type e.g. application/json
|
303
|
+
# @param filename [String] the filename
|
304
|
+
# @param descriptor [String] description
|
305
|
+
# @param object_data [String] object data
|
306
|
+
def self.create_encapsulated_object(mime_type, filename, descriptor, object_data)
|
307
|
+
Frames::Geo::Entities::EncapsulatedObject.new(mime_type, filename, descriptor, object_data)
|
308
|
+
end
|
309
|
+
|
310
|
+
# create group identification object
|
311
|
+
#
|
312
|
+
# @param owner_id [String] the owner id
|
313
|
+
# @param group_symbol [Integer] between 0 and 255
|
314
|
+
# @param group_dependant_data [String] data
|
315
|
+
def self.create_group_identification(owner_id, group_symbol, group_dependant_data)
|
316
|
+
Frames::Grouping::Entities::GroupIdentification.new(owner_id, group_symbol, group_dependant_data)
|
317
|
+
end
|
318
|
+
|
319
|
+
# create involved person object
|
320
|
+
#
|
321
|
+
# @param involvement [String] the involvement
|
322
|
+
# @param involvee [String] the involvee
|
323
|
+
def self.create_involved_person(involvement, involvee)
|
324
|
+
Frames::Ipl::Entities::InvolvedPerson.new(involvement, involvee)
|
325
|
+
end
|
326
|
+
|
327
|
+
# create unsync lyrics
|
328
|
+
#
|
329
|
+
# @param language [String] 3 character language e.g. eng
|
330
|
+
# @param descriptor [String] the description
|
331
|
+
# @param lyrics [String] the lyrics
|
332
|
+
def self.create_unsync_lyrics(language, descriptor, lyrics)
|
333
|
+
Frames::Lyrics::Entities::UnsyncLyrics.new(language, descriptor, lyrics)
|
334
|
+
end
|
335
|
+
|
336
|
+
# creates a picture object using data as String
|
337
|
+
#
|
338
|
+
# @param mime_type [String] the mime type e.g. images/png, or --> if picture data is a link
|
339
|
+
# @param picture_type [Symbol] the picture type as symbol, e.g. :COVER_FRONT (check Picture::PictureType)
|
340
|
+
# @param descriptor [String] description
|
341
|
+
# @param picture_data [String] the picture data
|
342
|
+
# @return [Picture] the picture
|
343
|
+
def self.create_picture_from_data(mime_type, picture_type, descriptor, picture_data)
|
344
|
+
Frames::Picture::Entities::Picture.new(mime_type, picture_type, descriptor, picture_data)
|
345
|
+
end
|
346
|
+
|
347
|
+
# creates a picture object using data from a provided file path
|
348
|
+
#
|
349
|
+
# @param mime_type [String] the mime type e.g. images/png, or --> if picture data is a link
|
350
|
+
# @param picture_type [Symbol] the picture type as symbol, e.g. :COVER_FRONT (check Picture::PictureType)
|
351
|
+
# @param descriptor [String] description
|
352
|
+
# @param file_path [String] the path to the picture file
|
353
|
+
# @return [Picture] the picture
|
354
|
+
def self.create_picture_from_file(mime_type, picture_type, descriptor, file_path)
|
355
|
+
picture_data = File.new(file_path).read
|
356
|
+
raise ArgumentError, "Could not find a picture at #{file_path}" if picture_data.nil?
|
357
|
+
|
358
|
+
create_picture_from_data(mime_type, picture_type, descriptor, picture_data)
|
359
|
+
end
|
360
|
+
|
361
|
+
# the creates a private frame object
|
362
|
+
#
|
363
|
+
# @param owner_id [String] the owner id
|
364
|
+
# @param private_data [String] private data
|
365
|
+
def self.create_private_frame(owner_id, private_data)
|
366
|
+
Frames::Private::Entities::PrivateFrame.new(owner_id, private_data)
|
367
|
+
end
|
368
|
+
|
369
|
+
# creates an ownership object
|
370
|
+
#
|
371
|
+
# @param price_paid [String] the price e.g. $20.00
|
372
|
+
# @param date_of_purchase [String] date of purchase in the form YYYYMMDD
|
373
|
+
# @param seller [String] the seller
|
374
|
+
def self.create_ownership(price_paid, date_of_purchase, seller)
|
375
|
+
Frames::Tos::Entities::Ownership.new(price_paid, date_of_purchase, seller)
|
376
|
+
end
|
377
|
+
|
378
|
+
# creates a terms of use object
|
379
|
+
#
|
380
|
+
# @param language [String] the 3 character language, e.g. eng
|
381
|
+
# @param text [String] ToU text
|
382
|
+
def self.create_terms_of_use(language, text)
|
383
|
+
Frames::Tos::Entities::TermsOfUse.new(language, text)
|
384
|
+
end
|
385
|
+
|
386
|
+
# creates a Unique File Identifier object
|
387
|
+
#
|
388
|
+
# @param owner_id [String] the owner id
|
389
|
+
# @param identifier [String] the identifier
|
390
|
+
def self.create_unique_file_identifier(owner_id, identifier)
|
391
|
+
Frames::Ufid::Entities::UfidInfo.new(owner_id, identifier)
|
392
|
+
end
|
393
|
+
|
394
|
+
# creates a custom url link
|
395
|
+
#
|
396
|
+
# @param description [String] description
|
397
|
+
# @param url [String] the url
|
398
|
+
def self.create_custom_url_link(description, url)
|
399
|
+
Frames::Url::Entities::UserInfo.new(description, url)
|
400
|
+
end
|
401
|
+
|
402
|
+
# creates a Copyright Object
|
403
|
+
#
|
404
|
+
# @param year [String, Integer] the year
|
405
|
+
# @param holder [String] the copyright holder
|
406
|
+
def self.create_copyright(year, holder)
|
407
|
+
Frames::Text::Entities::Copyright.new(year.to_s, holder)
|
408
|
+
end
|
409
|
+
|
410
|
+
# creates a date object
|
411
|
+
#
|
412
|
+
# @param month [String, Integer] the month
|
413
|
+
# @param day [String, Integer] the day
|
414
|
+
def self.create_date(month, day)
|
415
|
+
Frames::Text::Entities::Date.new(month, day)
|
416
|
+
end
|
417
|
+
|
418
|
+
# creates a part of set, e.g. curr CD / max CD
|
419
|
+
#
|
420
|
+
# @param part [String, Integer] the part of in the set
|
421
|
+
# @param total [String, Integer, nil] the total number of parts, can be nil
|
422
|
+
def self.create_part_of_set(part, total)
|
423
|
+
Frames::Text::Entities::PartOfSet.new(part, total)
|
424
|
+
end
|
425
|
+
|
426
|
+
# creates a Time Object
|
427
|
+
#
|
428
|
+
# @param hours [String, Integer] hours
|
429
|
+
# @param minutes [String, Integer] minutes
|
430
|
+
def self.create_time(hours, minutes)
|
431
|
+
Frames::Text::Entities::Time.new(hours, minutes)
|
432
|
+
end
|
433
|
+
|
434
|
+
# creates a track number object
|
435
|
+
#
|
436
|
+
# @param track_number [String, Integer] the current track number
|
437
|
+
# @param total [Number|String, nil] the total number of tracks, can be nil
|
438
|
+
def self.create_track_number(track_number, total)
|
439
|
+
Frames::Text::Entities::TrackNumber.new(track_number, total)
|
440
|
+
end
|
441
|
+
|
442
|
+
# creates a custom user text info
|
443
|
+
#
|
444
|
+
# @param description [String] the description
|
445
|
+
# @param content [String] the content
|
446
|
+
def self.create_custom_user_text_info(description, content)
|
447
|
+
Frames::Text::Entities::UserInfo.new(description, content)
|
448
|
+
end
|
449
|
+
end
|