From 263ea48c5b1661749b15495081c30e7f8ccac6bb Mon Sep 17 00:00:00 2001 From: Laravel Shift Date: Sun, 14 Feb 2021 02:39:15 +0000 Subject: [PATCH] Adopt Laravel coding style Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions. You may customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config file to your project root. Feel free to use [Shift's Laravel ruleset][2] to help you get started. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200 --- app/AlbumDownloader.php | 12 +- app/Commands/AddTrackToPlaylistCommand.php | 7 +- app/Commands/CommandBase.php | 2 +- app/Commands/CommandResponse.php | 6 +- app/Commands/CreateAlbumCommand.php | 8 +- app/Commands/CreateAnnouncementCommand.php | 5 +- app/Commands/CreateCommentCommand.php | 6 +- app/Commands/CreateGenreCommand.php | 10 +- app/Commands/CreatePlaylistCommand.php | 10 +- app/Commands/CreateShowSongCommand.php | 10 +- app/Commands/CreateUserCommand.php | 12 +- app/Commands/DeleteAlbumCommand.php | 4 +- app/Commands/DeleteGenreCommand.php | 8 +- app/Commands/DeletePlaylistCommand.php | 2 +- app/Commands/DeleteShowSongCommand.php | 8 +- app/Commands/DeleteTrackCommand.php | 6 +- app/Commands/EditAlbumCommand.php | 8 +- app/Commands/EditPlaylistCommand.php | 8 +- app/Commands/EditTrackCommand.php | 35 +- app/Commands/GenerateTrackFilesCommand.php | 30 +- app/Commands/MergeAccountsCommand.php | 8 +- app/Commands/ParseTrackTagsCommand.php | 56 +- .../RemoveTrackFromPlaylistCommand.php | 4 +- app/Commands/RenameGenreCommand.php | 11 +- app/Commands/RenameShowSongCommand.php | 11 +- app/Commands/SaveAccountSettingsCommand.php | 19 +- app/Commands/ToggleFavouriteCommand.php | 15 +- app/Commands/ToggleFollowingCommand.php | 4 +- app/Commands/UploadTrackCommand.php | 41 +- .../Commands/BootstrapLocalEnvironment.php | 3 +- app/Console/Commands/ClassifyMLPMA.php | 25 +- app/Console/Commands/ClearTrackCache.php | 11 +- app/Console/Commands/FixMLPMAImages.php | 15 +- app/Console/Commands/ImportEQBeats.php | 146 +- app/Console/Commands/MergeAccounts.php | 20 +- app/Console/Commands/MigrateOldData.php | 35 +- app/Console/Commands/PoniverseApiSetup.php | 8 +- app/Console/Commands/RebuildArtists.php | 5 +- app/Console/Commands/RebuildFilesizes.php | 7 +- app/Console/Commands/RebuildImages.php | 8 +- app/Console/Commands/RebuildSearchIndex.php | 18 +- app/Console/Commands/RebuildTags.php | 5 +- app/Console/Commands/RebuildTrack.php | 13 +- app/Console/Commands/RebuildTrackCache.php | 19 +- app/Console/Commands/RefreshCache.php | 17 +- .../Commands/SyncPoniverseAccounts.php | 24 +- app/Console/Commands/VersionFiles.php | 13 +- app/Console/Kernel.php | 2 +- app/Contracts/Commentable.php | 4 +- app/Contracts/Favouritable.php | 4 +- app/Contracts/GeneratesNotifications.php | 6 +- app/Contracts/NotificationHandler.php | 9 +- app/Contracts/Searchable.php | 3 +- app/Exceptions/Handler.php | 5 +- .../InvalidEncodeOptionsException.php | 2 +- app/Exceptions/TrackFileNotFoundException.php | 4 +- app/Facades/Notification.php | 2 +- app/Http/Controllers/AccountController.php | 2 +- app/Http/Controllers/AdminController.php | 2 +- app/Http/Controllers/AlbumsController.php | 12 +- .../Api/Mobile/TracksController.php | 6 +- .../Controllers/Api/V1/TracksController.php | 44 +- .../Controllers/Api/Web/AccountController.php | 22 +- .../Controllers/Api/Web/AlbumsController.php | 30 +- .../Controllers/Api/Web/AlexaController.php | 72 +- .../Api/Web/AnnouncementsController.php | 26 +- .../Controllers/Api/Web/ArtistsController.php | 43 +- .../Controllers/Api/Web/AuthController.php | 2 +- .../Api/Web/CommentsController.php | 4 +- .../Api/Web/DashboardController.php | 4 +- .../Api/Web/FavouritesController.php | 18 +- .../Controllers/Api/Web/FollowController.php | 2 +- .../Controllers/Api/Web/GenresController.php | 12 +- .../Controllers/Api/Web/ImagesController.php | 8 +- .../Api/Web/NotificationsController.php | 10 +- .../Api/Web/PlaylistsController.php | 31 +- .../Controllers/Api/Web/SearchController.php | 6 +- .../Api/Web/ShowSongsController.php | 12 +- .../Controllers/Api/Web/StatsController.php | 15 +- .../Api/Web/TaxonomiesController.php | 6 +- .../Controllers/Api/Web/TracksController.php | 51 +- app/Http/Controllers/ApiControllerBase.php | 6 +- app/Http/Controllers/ArtistsController.php | 6 +- app/Http/Controllers/AuthController.php | 19 +- app/Http/Controllers/ContentController.php | 2 +- app/Http/Controllers/Controller.php | 4 +- app/Http/Controllers/HomeController.php | 2 +- app/Http/Controllers/ImagesController.php | 8 +- .../Controllers/NotificationsController.php | 25 +- app/Http/Controllers/PlaylistsController.php | 10 +- app/Http/Controllers/StatsController.php | 2 +- app/Http/Controllers/TracksController.php | 30 +- app/Http/Controllers/UploaderController.php | 2 +- app/Http/Kernel.php | 4 +- app/Http/Middleware/Authenticate.php | 2 +- app/Http/Middleware/AuthenticateOAuth.php | 9 +- app/Http/Middleware/Authorize.php | 2 +- app/Http/Middleware/DisabledAccountCheck.php | 6 +- app/Http/Middleware/EncryptCookies.php | 2 +- app/Http/Middleware/JsonExceptions.php | 10 +- .../Middleware/RedirectIfAuthenticated.php | 3 +- app/Http/Middleware/VerifyCsrfToken.php | 4 +- app/Http/Requests/Request.php | 2 +- app/Jobs/DeleteGenre.php | 8 +- app/Jobs/DeleteShowSong.php | 8 +- app/Jobs/EncodeTrackFile.php | 26 +- app/Jobs/Job.php | 2 +- app/Jobs/SendNotifications.php | 6 +- app/Jobs/UpdateSearchIndexForEntity.php | 6 +- app/Jobs/UpdateTagsForRenamedGenre.php | 16 +- app/Jobs/UpdateTagsForRenamedShowSong.php | 16 +- app/Library/Assets.php | 30 +- app/Library/AudioCache.php | 3 +- app/Library/External.php | 6 +- app/Library/File.php | 5 +- app/Library/Gravatar.php | 7 +- app/Library/Helpers.php | 21 +- .../Notifications/Drivers/AbstractDriver.php | 6 +- .../Notifications/Drivers/NativeDriver.php | 17 +- .../Notifications/Drivers/PonyfmDriver.php | 33 +- .../Notifications/NotificationManager.php | 22 +- app/Library/Notifications/RecipientFinder.php | 34 +- app/Library/PfmValidator.php | 18 +- app/Library/Search.php | 26 +- app/Library/SerializesModels.php | 2 +- app/Library/ZipStream.php | 190 +- .../getid3/demos/demo.audioinfo.class.php | 468 +- app/Library/getid3/demos/demo.basic.php | 5 +- app/Library/getid3/demos/demo.browse.php | 988 +-- app/Library/getid3/demos/demo.cache.dbm.php | 4 +- app/Library/getid3/demos/demo.cache.mysql.php | 6 +- app/Library/getid3/demos/demo.joinmp3.php | 169 +- app/Library/getid3/demos/demo.mimeonly.php | 82 +- app/Library/getid3/demos/demo.mp3header.php | 5127 ++++++------ app/Library/getid3/demos/demo.mysql.php | 3928 +++++---- app/Library/getid3/demos/demo.simple.php | 34 +- .../getid3/demos/demo.simple.write.php | 45 +- app/Library/getid3/demos/demo.write.php | 414 +- app/Library/getid3/demos/demo.zip.php | 167 +- .../getid3/demos/getid3.demo.dirscan.php | 418 +- app/Library/getid3/demos/index.php | 10 +- .../getid3/getid3/extension.cache.dbm.php | 307 +- .../getid3/getid3/extension.cache.mysql.php | 295 +- .../getid3/getid3/extension.cache.mysqli.php | 290 +- .../getid3/getid3/extension.cache.sqlite3.php | 481 +- app/Library/getid3/getid3/getid3.lib.php | 2920 +++---- app/Library/getid3/getid3/getid3.php | 3455 ++++---- .../getid3/getid3/module.archive.gzip.php | 473 +- .../getid3/getid3/module.archive.rar.php | 54 +- .../getid3/getid3/module.archive.szip.php | 124 +- .../getid3/getid3/module.archive.tar.php | 306 +- .../getid3/getid3/module.archive.zip.php | 1000 +-- .../getid3/getid3/module.audio-video.asf.php | 3934 ++++----- .../getid3/getid3/module.audio-video.bink.php | 81 +- .../getid3/getid3/module.audio-video.flv.php | 1215 +-- .../getid3/module.audio-video.matroska.php | 3569 ++++---- .../getid3/getid3/module.audio-video.mpeg.php | 1081 +-- .../getid3/getid3/module.audio-video.nsv.php | 348 +- .../getid3/module.audio-video.quicktime.php | 4772 ++++++----- .../getid3/getid3/module.audio-video.real.php | 1005 ++- .../getid3/getid3/module.audio-video.riff.php | 4958 ++++++----- .../getid3/getid3/module.audio-video.swf.php | 193 +- .../getid3/getid3/module.audio-video.ts.php | 108 +- app/Library/getid3/getid3/module.audio.aa.php | 61 +- .../getid3/getid3/module.audio.aac.php | 989 +-- .../getid3/getid3/module.audio.ac3.php | 1333 +-- .../getid3/getid3/module.audio.amr.php | 132 +- app/Library/getid3/getid3/module.audio.au.php | 244 +- .../getid3/getid3/module.audio.avr.php | 187 +- .../getid3/getid3/module.audio.bonk.php | 357 +- .../getid3/getid3/module.audio.dsf.php | 197 +- .../getid3/getid3/module.audio.dss.php | 141 +- .../getid3/getid3/module.audio.dts.php | 497 +- .../getid3/getid3/module.audio.flac.php | 736 +- app/Library/getid3/getid3/module.audio.la.php | 336 +- .../getid3/getid3/module.audio.lpac.php | 185 +- .../getid3/getid3/module.audio.midi.php | 1006 ++- .../getid3/getid3/module.audio.mod.php | 141 +- .../getid3/getid3/module.audio.monkey.php | 336 +- .../getid3/getid3/module.audio.mp3.php | 3968 +++++---- .../getid3/getid3/module.audio.mpc.php | 997 +-- .../getid3/getid3/module.audio.ogg.php | 1511 ++-- .../getid3/getid3/module.audio.optimfrog.php | 809 +- .../getid3/getid3/module.audio.rkau.php | 118 +- .../getid3/getid3/module.audio.shorten.php | 274 +- .../getid3/getid3/module.audio.tta.php | 143 +- .../getid3/getid3/module.audio.voc.php | 310 +- .../getid3/getid3/module.audio.vqf.php | 245 +- .../getid3/getid3/module.audio.wavpack.php | 653 +- .../getid3/getid3/module.graphic.bmp.php | 1333 ++- .../getid3/getid3/module.graphic.efax.php | 49 +- .../getid3/getid3/module.graphic.gif.php | 272 +- .../getid3/getid3/module.graphic.jpg.php | 602 +- .../getid3/getid3/module.graphic.pcd.php | 192 +- .../getid3/getid3/module.graphic.png.php | 1010 ++- .../getid3/getid3/module.graphic.svg.php | 150 +- .../getid3/getid3/module.graphic.tiff.php | 355 +- app/Library/getid3/getid3/module.misc.cue.php | 485 +- app/Library/getid3/getid3/module.misc.exe.php | 64 +- app/Library/getid3/getid3/module.misc.iso.php | 635 +- .../getid3/getid3/module.misc.msoffice.php | 30 +- .../getid3/getid3/module.misc.par2.php | 17 +- app/Library/getid3/getid3/module.misc.pdf.php | 17 +- .../getid3/getid3/module.tag.apetag.php | 701 +- .../getid3/getid3/module.tag.id3v1.php | 678 +- .../getid3/getid3/module.tag.id3v2.php | 7322 ++++++++--------- .../getid3/getid3/module.tag.lyrics3.php | 468 +- app/Library/getid3/getid3/module.tag.xmp.php | 1295 ++- app/Library/getid3/getid3/write.apetag.php | 338 +- app/Library/getid3/getid3/write.id3v1.php | 223 +- app/Library/getid3/getid3/write.id3v2.php | 4207 +++++----- app/Library/getid3/getid3/write.lyrics3.php | 89 +- app/Library/getid3/getid3/write.metaflac.php | 228 +- app/Library/getid3/getid3/write.php | 1241 +-- app/Library/getid3/getid3/write.real.php | 444 +- .../getid3/getid3/write.vorbiscomment.php | 164 +- app/Mail/BaseNotification.php | 24 +- app/Mail/ContentFavourited.php | 4 +- app/Mail/NewComment.php | 6 +- app/Mail/NewFollower.php | 4 +- app/Mail/NewPlaylist.php | 4 +- app/Mail/NewTrack.php | 6 +- app/Models/Activity.php | 53 +- app/Models/Album.php | 85 +- app/Models/AlexaSession.php | 4 +- app/Models/Announcement.php | 13 +- app/Models/Comment.php | 25 +- app/Models/Email.php | 23 +- app/Models/EmailClick.php | 7 +- app/Models/EmailSubscription.php | 13 +- app/Models/Favourite.php | 16 +- app/Models/Follower.php | 13 +- app/Models/Genre.php | 12 +- app/Models/Image.php | 50 +- app/Models/License.php | 12 +- app/Models/Notification.php | 16 +- app/Models/PinnedPlaylist.php | 10 +- app/Models/Playlist.php | 74 +- app/Models/ResourceLogItem.php | 40 +- app/Models/ResourceUser.php | 30 +- app/Models/Role.php | 6 +- app/Models/ShowSong.php | 6 +- app/Models/Subscription.php | 10 +- app/Models/Track.php | 163 +- app/Models/TrackFile.php | 26 +- app/Models/TrackType.php | 6 +- app/Models/User.php | 97 +- app/PlaylistDownloader.php | 14 +- app/Policies/AlbumPolicy.php | 2 +- app/Policies/GenrePolicy.php | 2 +- app/Policies/TrackPolicy.php | 2 +- app/Policies/UserPolicy.php | 2 +- app/Providers/AppServiceProvider.php | 2 +- app/Providers/AuthServiceProvider.php | 16 +- app/Providers/BroadcastServiceProvider.php | 2 +- app/Providers/EventServiceProvider.php | 2 +- app/Providers/NotificationServiceProvider.php | 4 +- app/Providers/RouteServiceProvider.php | 10 +- app/Traits/IndexedInElasticsearchTrait.php | 14 +- app/Traits/SlugTrait.php | 6 +- app/Traits/TrackCollection.php | 37 +- config/app.php | 2 - config/cors.php | 1 + config/debugbar.php | 10 +- config/elasticsearch.php | 39 +- config/ide-helper.php | 7 +- config/poniverse.php | 1 + config/ponyfm.php | 4 +- database/factories/ModelFactory.php | 29 +- .../2013_06_07_003952_create_users_table.php | 2 +- .../2013_06_27_015259_create_tracks_table.php | 21 +- .../2013_07_26_230827_create_images_table.php | 2 +- .../2013_07_28_034328_create_songs_table.php | 196 +- .../2013_07_28_060804_create_albums.php | 2 +- .../2013_07_28_135136_create_playlists.php | 3 +- .../2013_08_01_051337_create_comments.php | 2 +- .../2013_08_18_041928_create_user_tables.php | 8 +- .../2013_08_18_045248_create_favourites.php | 2 +- .../2013_08_29_025516_create_followers.php | 2 +- .../2013_09_01_025031_oauth.php | 2 +- .../2013_09_01_232520_create_news_table.php | 3 +- ...2013_09_10_014644_create_latest_column.php | 2 +- .../2013_09_23_031316_create_track_hashes.php | 3 +- .../2013_09_24_055911_track_is_listed.php | 2 +- .../2014_05_28_071738_update_track_hash.php | 2 +- ...015_04_30_064436_add_remember_me_field.php | 2 +- ...5_20_155236_add_archived_profile_field.php | 4 +- ..._05_25_011121_create_track_files_table.php | 7 +- .../2015_09_04_160648_make_email_nullable.php | 6 +- .../2015_09_05_113647_add_new_indices.php | 4 +- .../2015_09_05_143300_create_mlpma_table.php | 6 +- ...2015_09_12_225021_create_session_table.php | 4 +- ...15_09_29_035228_AddAlphabeticalIndices.php | 4 +- ...6_192855_update_track_files_with_cache.php | 4 +- ...2015_10_26_231224_AddTrackSourceColumn.php | 8 +- ...8_162655_AddTrackFilesForDeletedTracks.php | 8 +- ...53827_update_track_files_with_filesize.php | 2 +- ..._11_05_004145_AddUnclassifiedTrackType.php | 6 +- ...20332_RenameUsernameAndIndexIsArchived.php | 8 +- ...15_11_24_025733_create_revisions_table.php | 2 +- ...1_24_182326_AddDeletedAtColumnToGenres.php | 8 +- ..._12_05_235108_create_failed_jobs_table.php | 2 +- ...nvert_track_file_in_progress_to_status.php | 6 +- ...015_12_24_151903_add_sensible_defaults.php | 8 +- .../2015_12_25_154727_add_more_defaults.php | 5 +- ...2015_12_25_155223_add_metadata_columns.php | 8 +- ..._29_152005_add_account_disabled_column.php | 8 +- ...0_update_model_namespaces_in_revisions.php | 4 +- ...2016_01_06_123513_add_genre_timestamps.php | 8 +- .../2016_01_14_021607_setup_elasticsearch.php | 20 +- ..._062640_EnforceUniqueTracksInPlaylists.php | 17 +- ..._06_152844_create_notifications_tables.php | 10 +- ...2016_06_05_193032_enforce_unique_slugs.php | 8 +- ...05_221208_add_timestamps_to_show_songs.php | 2 +- ...06_10_010314_create_subscription_table.php | 2 +- .../2016_06_15_075023_fix_cache_table.php | 4 +- .../2016_06_15_080045_fix_cache_table_2.php | 4 +- ...6_06_26_225535_create_activities_table.php | 57 +- .../2016_06_26_225535_create_albums_table.php | 71 +- .../2016_06_26_225535_create_cache_table.php | 51 +- ...016_06_26_225535_create_comments_table.php | 65 +- ...6_26_225535_create_failed_jobs_table_2.php | 57 +- ...6_06_26_225535_create_favourites_table.php | 57 +- ...16_06_26_225535_create_followers_table.php | 55 +- .../2016_06_26_225535_create_genres_table.php | 55 +- ...016_06_26_225535_create_images_table_2.php | 63 +- ...016_06_26_225535_create_licenses_table.php | 17 +- ...06_26_225535_create_mlpma_tracks_table.php | 61 +- .../2016_06_26_225535_create_news_table_2.php | 55 +- ...6_26_225535_create_notifications_table.php | 53 +- ...6_26_225535_create_oauth2_tokens_table.php | 61 +- ...6_225535_create_pinned_playlists_table.php | 53 +- ..._26_225535_create_playlist_track_table.php | 57 +- ...16_06_26_225535_create_playlists_table.php | 73 +- ...225535_create_resource_log_items_table.php | 63 +- ..._26_225535_create_resource_users_table.php | 71 +- ..._06_26_225535_create_revisions_table_2.php | 66 +- ...16_06_26_225535_create_role_user_table.php | 53 +- .../2016_06_26_225535_create_roles_table.php | 7 +- ...016_06_26_225535_create_sessions_table.php | 51 +- ...26_225535_create_show_song_track_table.php | 51 +- ...6_06_26_225535_create_show_songs_table.php | 57 +- ...6_26_225535_create_subscriptions_table.php | 57 +- ...6_26_225535_create_track_files_table_2.php | 65 +- ..._06_26_225535_create_track_types_table.php | 63 +- ...016_06_26_225535_create_tracks_table_2.php | 111 +- ...2016_06_26_225535_create_users_table_2.php | 81 +- ...25537_add_foreign_keys_to_albums_table.php | 56 +- ...537_add_foreign_keys_to_comments_table.php | 68 +- ...7_add_foreign_keys_to_favourites_table.php | 64 +- ...37_add_foreign_keys_to_followers_table.php | 60 +- ...25537_add_foreign_keys_to_images_table.php | 52 +- ...add_foreign_keys_to_mlpma_tracks_table.php | 52 +- ..._225537_add_foreign_keys_to_news_table.php | 52 +- ...dd_foreign_keys_to_notifications_table.php | 56 +- ...foreign_keys_to_pinned_playlists_table.php | 56 +- ...d_foreign_keys_to_playlist_track_table.php | 56 +- ...37_add_foreign_keys_to_playlists_table.php | 52 +- ...reign_keys_to_resource_log_items_table.php | 64 +- ...d_foreign_keys_to_resource_users_table.php | 68 +- ...37_add_foreign_keys_to_role_user_table.php | 56 +- ..._foreign_keys_to_show_song_track_table.php | 56 +- ...dd_foreign_keys_to_subscriptions_table.php | 52 +- ..._add_foreign_keys_to_track_files_table.php | 52 +- ...25537_add_foreign_keys_to_tracks_table.php | 72 +- ...225537_add_foreign_keys_to_users_table.php | 52 +- ...54_add_deleted_at_column_to_activities.php | 6 +- .../2016_07_14_154357_MysqlToPostgres.php | 9 +- ...dd_version_column_to_track_files_table.php | 4 +- ...625_add_version_column_to_tracks_table.php | 2 +- ...3_update_sessions_table_for_laravel_52.php | 6 +- ...2016_09_30_202330_create_alexa_session.php | 7 +- ...1_10_220126_create_announcements_table.php | 8 +- ...14829_create_email_notification_tables.php | 11 +- ...2_10_120107_create_failed_jobs_table_3.php | 6 +- ...2_24_133558_UpdateActivityDescriptions.php | 6 +- ..._12_30_193250_EnableEmailNotifications.php | 35 +- ...2017_02_08_233324_create_ponify_tracks.php | 13 +- .../2017_09_20_200156_AddRedirectToUsers.php | 4 +- ...7_09_20_225456_AddForeignKeyToRedirect.php | 8 +- .../2017_09_22_082723_CreateEQBeatsTracks.php | 13 +- .../2017_12_03_091509_Laravel55Upgrade.php | 4 +- database/seeds/DatabaseSeeder.php | 4 +- database/seeds/GenreTableSeeder.php | 71 +- database/seeds/ShowSongTableSeeder.php | 27 +- resources/lang/en/validation.php | 17 +- routes/web.php | 18 +- tests/ApiAuthTest.php | 4 +- tests/ApiTest.php | 49 +- tests/TestCase.php | 21 +- 390 files changed, 43866 insertions(+), 44115 deletions(-) diff --git a/app/AlbumDownloader.php b/app/AlbumDownloader.php index e0729a7b..d661e9a2 100644 --- a/app/AlbumDownloader.php +++ b/app/AlbumDownloader.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -45,8 +45,8 @@ class AlbumDownloader public function download() { // Check whether the format is lossless yet not all master files are lossless - $isLosslessFormatWithLossyTracks = in_array($this->_format, Track::$LosslessFormats) - && !$this->_album->hasLosslessTracksOnly() + $isLosslessFormatWithLossyTracks = in_array($this->_format, Track::$LosslessFormats) + && ! $this->_album->hasLosslessTracksOnly() && $this->_album->hasLosslessTracks(); $zip = new ZipStream($this->_album->user->display_name.' - '.$this->_album->title.'.zip'); @@ -71,7 +71,7 @@ class AlbumDownloader "\r\n"; foreach ($this->_album->tracks as $track) { - if (!$track->is_downloadable) { + if (! $track->is_downloadable) { continue; } @@ -79,12 +79,12 @@ class AlbumDownloader $masterFormatName = $track->getMasterFormatName(); $zip->addLargeFile( $track->getFileFor($masterFormatName), - $directory . $track->getDownloadFilenameFor($masterFormatName) + $directory.$track->getDownloadFilenameFor($masterFormatName) ); } else { $zip->addLargeFile( $track->getFileFor($this->_format), - $directory . $track->getDownloadFilenameFor($this->_format) + $directory.$track->getDownloadFilenameFor($this->_format) ); } diff --git a/app/Commands/AddTrackToPlaylistCommand.php b/app/Commands/AddTrackToPlaylistCommand.php index 48f43587..3d7c4bc4 100644 --- a/app/Commands/AddTrackToPlaylistCommand.php +++ b/app/Commands/AddTrackToPlaylistCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -59,20 +59,19 @@ class AddTrackToPlaylistCommand extends CommandBase // check if this track is already in the playlist $validator = Validator::make( ['track_id' => $this->_track->id], - ['track_id' => "unique:playlist_track,track_id,null,id,playlist_id,{$this->_playlist->id}", ] + ['track_id' => "unique:playlist_track,track_id,null,id,playlist_id,{$this->_playlist->id}"] ); if ($validator->fails()) { return CommandResponse::fail($validator); } - $songIndex = $this->_playlist->trackCount() + 1; $this->_playlist->tracks()->attach($this->_track, ['position' => $songIndex]); $this->_playlist->touch(); Playlist::where('id', $this->_playlist->id)->update([ - 'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$this->_playlist->id.')') + 'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$this->_playlist->id.')'), ]); return CommandResponse::succeed(['message' => 'Track added!']); diff --git a/app/Commands/CommandBase.php b/app/Commands/CommandBase.php index 471ef5bc..fcff885e 100644 --- a/app/Commands/CommandBase.php +++ b/app/Commands/CommandBase.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Commands/CommandResponse.php b/app/Commands/CommandResponse.php index a18b71e0..9d46d725 100644 --- a/app/Commands/CommandResponse.php +++ b/app/Commands/CommandResponse.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -37,7 +37,7 @@ class CommandResponse public static function fail($validatorOrMessages, int $statusCode = 400) { - $response = new CommandResponse(); + $response = new self(); $response->_didFail = true; $response->_statusCode = $statusCode; @@ -53,7 +53,7 @@ class CommandResponse public static function succeed($response = null, int $statusCode = 200) { - $cmdResponse = new CommandResponse(); + $cmdResponse = new self(); $cmdResponse->_didFail = false; $cmdResponse->_response = $response; $cmdResponse->_statusCode = $statusCode; diff --git a/app/Commands/CreateAlbumCommand.php b/app/Commands/CreateAlbumCommand.php index ce278f38..39276a5c 100644 --- a/app/Commands/CreateAlbumCommand.php +++ b/app/Commands/CreateAlbumCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,11 +20,11 @@ namespace App\Commands; -use Gate; use App\Models\Album; use App\Models\Image; -use Auth; use App\Models\User; +use Auth; +use Gate; use Validator; class CreateAlbumCommand extends CommandBase @@ -60,7 +60,7 @@ class CreateAlbumCommand extends CommandBase 'cover' => 'image|mimes:png|min_width:350|min_height:350', 'cover_id' => 'exists:images,id', 'track_ids' => 'exists:tracks,id', - 'user_id' => 'exists:users,id' + 'user_id' => 'exists:users,id', ]; $validator = Validator::make($this->_input, $rules); diff --git a/app/Commands/CreateAnnouncementCommand.php b/app/Commands/CreateAnnouncementCommand.php index 6868d866..a2b9fbc9 100644 --- a/app/Commands/CreateAnnouncementCommand.php +++ b/app/Commands/CreateAnnouncementCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Logic + * Copyright (C) 2016 Logic. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,8 +20,8 @@ namespace App\Commands; -use Gate; use App\Models\Announcement; +use Gate; use Validator; class CreateAnnouncementCommand extends CommandBase @@ -48,7 +48,6 @@ class CreateAnnouncementCommand extends CommandBase */ public function execute() { - $rules = [ 'name' => 'required|max:50', ]; diff --git a/app/Commands/CreateCommentCommand.php b/app/Commands/CreateCommentCommand.php index 90ad3218..718944a6 100644 --- a/app/Commands/CreateCommentCommand.php +++ b/app/Commands/CreateCommentCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,13 +20,13 @@ namespace App\Commands; -use Notification; use App\Models\Album; use App\Models\Comment; use App\Models\Playlist; use App\Models\Track; use App\Models\User; use Auth; +use Notification; use Validator; class CreateCommentCommand extends CommandBase @@ -112,7 +112,7 @@ class CreateCommentCommand extends CommandBase $entity->comment_count = Comment::where($column, $this->_id)->count(); $entity->save(); - + Notification::newComment($comment); return CommandResponse::succeed(Comment::mapPublic($comment)); diff --git a/app/Commands/CreateGenreCommand.php b/app/Commands/CreateGenreCommand.php index 0b8e725e..ac32e30f 100644 --- a/app/Commands/CreateGenreCommand.php +++ b/app/Commands/CreateGenreCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,9 +20,9 @@ namespace App\Commands; +use App\Models\Genre; use Gate; use Illuminate\Support\Str; -use App\Models\Genre; use Validator; class CreateGenreCommand extends CommandBase @@ -53,12 +53,12 @@ class CreateGenreCommand extends CommandBase $rules = [ 'name' => 'required|unique:genres,name,NULL,id,deleted_at,NULL|max:50', - 'slug' => 'required|unique:genres,slug,NULL,id,deleted_at,NULL' + 'slug' => 'required|unique:genres,slug,NULL,id,deleted_at,NULL', ]; $validator = Validator::make([ 'name' => $this->_genreName, - 'slug' => $slug + 'slug' => $slug, ], $rules); if ($validator->fails()) { @@ -67,7 +67,7 @@ class CreateGenreCommand extends CommandBase Genre::create([ 'name' => $this->_genreName, - 'slug' => $slug + 'slug' => $slug, ]); return CommandResponse::succeed(['message' => 'Genre created!']); diff --git a/app/Commands/CreatePlaylistCommand.php b/app/Commands/CreatePlaylistCommand.php index c1a96fbc..94dcac30 100644 --- a/app/Commands/CreatePlaylistCommand.php +++ b/app/Commands/CreatePlaylistCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,9 +20,9 @@ namespace App\Commands; -use Notification; use App\Models\Playlist; use Auth; +use Notification; use Validator; class CreatePlaylistCommand extends CommandBase @@ -53,7 +53,7 @@ class CreatePlaylistCommand extends CommandBase $rules = [ 'title' => 'required|min:3|max:50', 'is_public' => 'required', - 'is_pinned' => 'required' + 'is_pinned' => 'required', ]; $validator = Validator::make($this->_input, $rules); @@ -69,7 +69,7 @@ class CreatePlaylistCommand extends CommandBase $playlist->is_public = $this->_input['is_public'] == 'true'; $playlist->save(); - + Notification::publishedNewPlaylist($playlist); if ($this->_input['is_pinned'] == 'true') { @@ -84,7 +84,7 @@ class CreatePlaylistCommand extends CommandBase 'description' => $playlist->description, 'url' => $playlist->url, 'is_pinned' => $this->_input['is_pinned'] == 'true', - 'is_public' => $this->_input['is_public'] == 'true' + 'is_public' => $this->_input['is_public'] == 'true', ]); } } diff --git a/app/Commands/CreateShowSongCommand.php b/app/Commands/CreateShowSongCommand.php index 3994107e..086940b6 100644 --- a/app/Commands/CreateShowSongCommand.php +++ b/app/Commands/CreateShowSongCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Logic + * Copyright (C) 2016 Logic. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,9 +20,9 @@ namespace App\Commands; +use App\Models\ShowSong; use Gate; use Illuminate\Support\Str; -use App\Models\ShowSong; use Validator; class CreateShowSongCommand extends CommandBase @@ -53,12 +53,12 @@ class CreateShowSongCommand extends CommandBase $rules = [ 'title' => 'required|unique:show_songs,title,NULL,id,deleted_at,NULL|max:250', - 'slug' => 'required|unique:show_songs,slug,NULL,id,deleted_at,NULL' + 'slug' => 'required|unique:show_songs,slug,NULL,id,deleted_at,NULL', ]; $validator = Validator::make([ 'title' => $this->_songName, - 'slug' => $slug + 'slug' => $slug, ], $rules); if ($validator->fails()) { @@ -68,7 +68,7 @@ class CreateShowSongCommand extends CommandBase ShowSong::create([ 'title' => $this->_songName, 'slug' => $slug, - 'lyrics' => '' + 'lyrics' => '', ]); return CommandResponse::succeed(['message' => 'Song created!']); diff --git a/app/Commands/CreateUserCommand.php b/app/Commands/CreateUserCommand.php index 91b359dd..d1d91da9 100644 --- a/app/Commands/CreateUserCommand.php +++ b/app/Commands/CreateUserCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,8 +20,8 @@ namespace App\Commands; -use Gate; use App\Models\User; +use Gate; use Validator; class CreateUserCommand extends CommandBase @@ -30,7 +30,7 @@ class CreateUserCommand extends CommandBase private $displayName; private $email; private $createArchivedUser; - + public function __construct( string $username, string $displayName, @@ -72,7 +72,7 @@ class CreateUserCommand extends CommandBase if ($validator->fails()) { return CommandResponse::fail([ 'message' => $validator->getMessageBag()->first(), - 'user' => null + 'user' => null, ]); } @@ -81,12 +81,12 @@ class CreateUserCommand extends CommandBase if ($user->wasRecentlyCreated) { return CommandResponse::succeed([ 'message' => 'New user successfully created!', - 'user' => User::mapPublicUserSummary($user) + 'user' => User::mapPublicUserSummary($user), ], 201); } else { return CommandResponse::fail([ 'message' => 'A user with that username already exists.', - 'user' => User::mapPublicUserSummary($user) + 'user' => User::mapPublicUserSummary($user), ], 409); } } diff --git a/app/Commands/DeleteAlbumCommand.php b/app/Commands/DeleteAlbumCommand.php index eb9d6e31..6b4e6b46 100644 --- a/app/Commands/DeleteAlbumCommand.php +++ b/app/Commands/DeleteAlbumCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,9 +20,9 @@ namespace App\Commands; -use Gate; use App\Models\Album; use Auth; +use Gate; class DeleteAlbumCommand extends CommandBase { diff --git a/app/Commands/DeleteGenreCommand.php b/app/Commands/DeleteGenreCommand.php index de9091e8..a72e2065 100644 --- a/app/Commands/DeleteGenreCommand.php +++ b/app/Commands/DeleteGenreCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,17 +20,16 @@ namespace App\Commands; +use App\Jobs\DeleteGenre; +use App\Models\Genre; use Gate; use Illuminate\Foundation\Bus\DispatchesJobs; -use App\Models\Genre; -use App\Jobs\DeleteGenre; use Validator; class DeleteGenreCommand extends CommandBase { use DispatchesJobs; - /** @var Genre */ private $_genreToDelete; private $_destinationGenre; @@ -67,7 +66,6 @@ class DeleteGenreCommand extends CommandBase 'destination_genre' => $this->_destinationGenre, ], $rules); - if ($validator->fails()) { return CommandResponse::fail($validator); } diff --git a/app/Commands/DeletePlaylistCommand.php b/app/Commands/DeletePlaylistCommand.php index 92130289..4da07676 100644 --- a/app/Commands/DeletePlaylistCommand.php +++ b/app/Commands/DeletePlaylistCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Commands/DeleteShowSongCommand.php b/app/Commands/DeleteShowSongCommand.php index ea502e42..54911c7b 100644 --- a/app/Commands/DeleteShowSongCommand.php +++ b/app/Commands/DeleteShowSongCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Logic + * Copyright (C) 2016 Logic. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,17 +20,16 @@ namespace App\Commands; +use App\Jobs\DeleteShowSong; +use App\Models\ShowSong; use Gate; use Illuminate\Foundation\Bus\DispatchesJobs; -use App\Models\ShowSong; -use App\Jobs\DeleteShowSong; use Validator; class DeleteShowSongCommand extends CommandBase { use DispatchesJobs; - /** @var ShowSong */ private $_songToDelete; private $_destinationSong; @@ -67,7 +66,6 @@ class DeleteShowSongCommand extends CommandBase 'destination_song' => $this->_destinationSong, ], $rules); - if ($validator->fails()) { return CommandResponse::fail($validator); } diff --git a/app/Commands/DeleteTrackCommand.php b/app/Commands/DeleteTrackCommand.php index 08373304..eac152b7 100644 --- a/app/Commands/DeleteTrackCommand.php +++ b/app/Commands/DeleteTrackCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,12 +20,12 @@ namespace App\Commands; -use Gate; use App\Models\Track; +use Gate; class DeleteTrackCommand extends CommandBase { - /** @var int */ + /** @var int */ private $_trackId; /** @var Track */ diff --git a/app/Commands/EditAlbumCommand.php b/app/Commands/EditAlbumCommand.php index d4b613a6..0169cfb7 100644 --- a/app/Commands/EditAlbumCommand.php +++ b/app/Commands/EditAlbumCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -24,8 +24,8 @@ use App\Models\Album; use App\Models\Image; use App\Models\User; use Auth; -use Gate; use DB; +use Gate; use Validator; class EditAlbumCommand extends CommandBase @@ -63,7 +63,7 @@ class EditAlbumCommand extends CommandBase 'title' => 'required|min:3|max:50', 'cover' => 'image|mimes:png|min_width:350|min_height:350', 'cover_id' => 'exists:images,id', - 'username' => 'exists:users,username' + 'username' => 'exists:users,username', ]; $validator = Validator::make($this->_input, $rules); @@ -77,7 +77,7 @@ class EditAlbumCommand extends CommandBase $trackDbCount = DB::table('tracks')->whereIn('id', $trackIds)->count(); if ($trackDbCount != $trackIdsCount) { - return CommandResponse::fail("Track IDs invalid"); + return CommandResponse::fail('Track IDs invalid'); } $this->_album->title = $this->_input['title']; diff --git a/app/Commands/EditPlaylistCommand.php b/app/Commands/EditPlaylistCommand.php index b60d2bba..cb93346a 100644 --- a/app/Commands/EditPlaylistCommand.php +++ b/app/Commands/EditPlaylistCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -57,7 +57,7 @@ class EditPlaylistCommand extends CommandBase $rules = [ 'title' => 'required|min:3|max:50', 'is_public' => 'required', - 'is_pinned' => 'required' + 'is_pinned' => 'required', ]; $validator = Validator::make($this->_input, $rules); @@ -76,7 +76,7 @@ class EditPlaylistCommand extends CommandBase if ($pin && $this->_input['is_pinned'] != 'true') { $pin->delete(); } else { - if (!$pin && $this->_input['is_pinned'] == 'true') { + if (! $pin && $this->_input['is_pinned'] == 'true') { $this->_playlist->pin(Auth::user()->id); } } @@ -89,7 +89,7 @@ class EditPlaylistCommand extends CommandBase 'description' => $this->_playlist->description, 'url' => $this->_playlist->url, 'is_pinned' => $this->_input['is_pinned'] == 'true', - 'is_public' => $this->_input['is_public'] == 'true' + 'is_public' => $this->_input['is_public'] == 'true', ]); } } diff --git a/app/Commands/EditTrackCommand.php b/app/Commands/EditTrackCommand.php index 0ba0e267..398c6493 100644 --- a/app/Commands/EditTrackCommand.php +++ b/app/Commands/EditTrackCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,15 +20,15 @@ namespace App\Commands; -use Gate; -use Notification; use App\Models\Album; use App\Models\Image; +use App\Models\Playlist; use App\Models\Track; use App\Models\TrackType; use App\Models\User; -use App\Models\Playlist; use DB; +use Gate; +use Notification; class EditTrackCommand extends CommandBase { @@ -65,9 +65,9 @@ class EditTrackCommand extends CommandBase $rules = [ 'title' => 'required|min:3|max:80', - 'released_at' => 'before:' . - (date('Y-m-d', time() + (86400 * 2))) . ( - isset($this->_input['released_at']) && $this->_input['released_at'] != "" + 'released_at' => 'before:'. + (date('Y-m-d', time() + (86400 * 2))).( + isset($this->_input['released_at']) && $this->_input['released_at'] != '' ? '|date' : ''), 'license_id' => 'required|exists:licenses,id', @@ -76,7 +76,7 @@ class EditTrackCommand extends CommandBase 'track_type_id' => 'required|exists:track_types,id|not_in:'.TrackType::UNCLASSIFIED_TRACK, 'cover_id' => 'exists:images,id', 'album_id' => 'exists:albums,id', - 'username' => 'exists:users,username' + 'username' => 'exists:users,username', ]; if (isset($this->_input['track_type_id']) && $this->_input['track_type_id'] == TrackType::OFFICIAL_TRACK_REMIX) { @@ -92,7 +92,7 @@ class EditTrackCommand extends CommandBase $track = $this->_track; $track->title = $this->_input['title']; - $track->released_at = isset($this->_input['released_at']) && $this->_input['released_at'] != "" ? strtotime($this->_input['released_at']) : null; + $track->released_at = isset($this->_input['released_at']) && $this->_input['released_at'] != '' ? strtotime($this->_input['released_at']) : null; $track->description = isset($this->_input['description']) ? $this->_input['description'] : ''; $track->lyrics = isset($this->_input['lyrics']) ? $this->_input['lyrics'] : ''; $track->license_id = $this->_input['license_id']; @@ -163,26 +163,26 @@ class EditTrackCommand extends CommandBase $track->save(); User::whereId($this->_track->user_id)->update([ - 'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = ' . $this->_track->user_id . ')') + 'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = '.$this->_track->user_id.')'), ]); if ($oldid != null) { User::whereId($oldid)->update([ - 'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = ' . $oldid . ')') + 'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = '.$oldid.')'), ]); } - if (isset($this->_input['hwc_submit']) && new \DateTime() < new \DateTime("2016-12-20 23:59:59")) { + if (isset($this->_input['hwc_submit']) && new \DateTime() < new \DateTime('2016-12-20 23:59:59')) { $playlist = Playlist::where('user_id', 22549)->first(); if ($this->_input['hwc_submit'] == 'true') { - if (!$playlist->tracks()->get()->contains($track)) { + if (! $playlist->tracks()->get()->contains($track)) { $songIndex = $playlist->trackCount() + 1; $playlist->tracks()->attach($track, ['position' => $songIndex]); $playlist->touch(); Playlist::where('id', $playlist->id)->update([ - 'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$playlist->id.')') + 'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$playlist->id.')'), ]); } } else { @@ -190,11 +190,12 @@ class EditTrackCommand extends CommandBase $playlist->tracks()->detach($track); Playlist::whereId($playlist->id)->update([ - 'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$playlist->id.')') + 'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$playlist->id.')'), ]); } } } + return CommandResponse::succeed(['real_cover_url' => $track->getCoverUrl(Image::NORMAL)]); } @@ -215,7 +216,7 @@ class EditTrackCommand extends CommandBase } Album::whereId($album->id)->update([ - 'track_count' => DB::table('tracks')->where('album_id', '=', $album->id)->count() + 'track_count' => DB::table('tracks')->where('album_id', '=', $album->id)->count(), ]); } @@ -230,7 +231,7 @@ class EditTrackCommand extends CommandBase $track->save(); $album->update([ - 'track_count' => DB::table('tracks')->where('album_id', '=', $album->id)->count() + 'track_count' => DB::table('tracks')->where('album_id', '=', $album->id)->count(), ]); } } diff --git a/app/Commands/GenerateTrackFilesCommand.php b/app/Commands/GenerateTrackFilesCommand.php index 980a62db..cd675723 100644 --- a/app/Commands/GenerateTrackFilesCommand.php +++ b/app/Commands/GenerateTrackFilesCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,23 +20,21 @@ namespace App\Commands; +use App\Exceptions\InvalidEncodeOptionsException; +use App\Jobs\EncodeTrackFile; +use App\Models\Track; +use App\Models\TrackFile; use AudioCache; use FFmpegMovie; use File; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Support\Str; -use App\Exceptions\InvalidEncodeOptionsException; -use App\Jobs\EncodeTrackFile; -use App\Models\Track; -use App\Models\TrackFile; use SplFileInfo; /** * This command is the "second phase" of the upload process - once metadata has * been parsed and the track object is created, this generates the track's * corresponding TrackFile objects and ensures that all of them have been encoded. - * - * @package App\Commands */ class GenerateTrackFilesCommand extends CommandBase { @@ -53,7 +51,7 @@ class GenerateTrackFilesCommand extends CommandBase 'flac', 'pcm', 'adpcm', - 'alac' + 'alac', ]; public function __construct(Track $track, SplFileInfo $sourceFile, bool $autoPublish = false, bool $isForUpload = false, bool $isReplacingTrack = false, int $version = 1) @@ -78,25 +76,26 @@ class GenerateTrackFilesCommand extends CommandBase // Lossy uploads need to be identified and set as the master file // without being re-encoded. $audioObject = AudioCache::get($source); - $isLossyUpload = !$this->isLosslessFile($audioObject); + $isLossyUpload = ! $this->isLosslessFile($audioObject); $codecString = $audioObject->getAudioCodec(); if ($isLossyUpload) { if ($codecString === 'mp3') { $masterFormat = 'MP3'; - } else if (Str::startsWith($codecString, 'aac')) { + } elseif (Str::startsWith($codecString, 'aac')) { $masterFormat = 'AAC'; - } else if ($codecString === 'vorbis') { + } elseif ($codecString === 'vorbis') { $masterFormat = 'OGG Vorbis'; } else { $this->track->delete(); + return CommandResponse::fail(['track' => "The track does not contain audio in a known lossy format. The format read from the file is: {$codecString}"]); } // Sanity check: skip creating this TrackFile if it already exists. $trackFile = $this->trackFileExists($masterFormat); - if (!$trackFile) { + if (! $trackFile) { $trackFile = new TrackFile(); $trackFile->is_master = true; $trackFile->format = $masterFormat; @@ -109,7 +108,6 @@ class GenerateTrackFilesCommand extends CommandBase File::copy($source, $trackFile->getFile()); } - $trackFiles = []; foreach (Track::$Formats as $name => $format) { @@ -132,7 +130,7 @@ class GenerateTrackFilesCommand extends CommandBase $trackFile->status = TrackFile::STATUS_PROCESSING_PENDING; $trackFile->version = $this->version; - if (in_array($name, Track::$CacheableFormats) && !$trackFile->is_master) { + if (in_array($name, Track::$CacheableFormats) && ! $trackFile->is_master) { $trackFile->is_cacheable = true; } else { $trackFile->is_cacheable = false; @@ -148,7 +146,7 @@ class GenerateTrackFilesCommand extends CommandBase try { foreach ($trackFiles as $trackFile) { // Don't re-encode master files when replacing tracks with an already-uploaded version - if ($trackFile->is_master && !$this->isForUpload && $this->isReplacingTrack) { + if ($trackFile->is_master && ! $this->isForUpload && $this->isReplacingTrack) { continue; } $this->dispatch(new EncodeTrackFile($trackFile, false, false, $this->isForUpload, $this->isReplacingTrack)); @@ -161,6 +159,7 @@ class GenerateTrackFilesCommand extends CommandBase } else { $this->track->delete(); } + return CommandResponse::fail(['track' => [$e->getMessage()]]); } } catch (\Exception $e) { @@ -176,6 +175,7 @@ class GenerateTrackFilesCommand extends CommandBase // This ensures that any updates to the track record, like from parsed // tags, are reflected in the command's response. $this->track = $this->track->fresh(); + return CommandResponse::succeed([ 'id' => $this->track->id, 'name' => $this->track->name, diff --git a/app/Commands/MergeAccountsCommand.php b/app/Commands/MergeAccountsCommand.php index 61e22188..b1483381 100644 --- a/app/Commands/MergeAccountsCommand.php +++ b/app/Commands/MergeAccountsCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,8 +20,6 @@ namespace App\Commands; -use Carbon\Carbon; -use DB; use App\Models\Album; use App\Models\Comment; use App\Models\EmailSubscription; @@ -35,6 +33,8 @@ use App\Models\ResourceLogItem; use App\Models\ResourceUser; use App\Models\Track; use App\Models\User; +use Carbon\Carbon; +use DB; class MergeAccountsCommand extends CommandBase { @@ -117,7 +117,7 @@ class MergeAccountsCommand extends CommandBase } /** @var EmailSubscription $emailSubscription */ - foreach($this->sourceAccount->emailSubscriptions()->withTrashed()->get() as $emailSubscription) { + foreach ($this->sourceAccount->emailSubscriptions()->withTrashed()->get() as $emailSubscription) { // This keeps emails from being sent to disabled accounts. $emailSubscription->delete(); } diff --git a/app/Commands/ParseTrackTagsCommand.php b/app/Commands/ParseTrackTagsCommand.php index 9f5d4311..b1486c56 100755 --- a/app/Commands/ParseTrackTagsCommand.php +++ b/app/Commands/ParseTrackTagsCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,18 +20,18 @@ namespace App\Commands; -use Carbon\Carbon; -use Config; -use getID3; use App\Models\Album; use App\Models\Genre; use App\Models\Image; use App\Models\Track; -use AudioCache; -use File; -use Illuminate\Support\Str; use App\Models\TrackType; use App\Models\User; +use AudioCache; +use Carbon\Carbon; +use Config; +use File; +use getID3; +use Illuminate\Support\Str; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; @@ -58,15 +58,14 @@ class ParseTrackTagsCommand extends CommandBase list($parsedTags, $rawTags) = $this->parseOriginalTags($this->fileToParse, $this->track->user, $audio->getAudioCodec()); $this->track->original_tags = ['parsed_tags' => $parsedTags, 'raw_tags' => $rawTags]; - if ($this->input['cover'] !== null) { $this->track->cover_id = Image::upload($this->input['cover'], $this->track->user_id)->id; } else { $this->track->cover_id = $parsedTags['cover_id']; } - $this->track->title = $this->input['title'] ?? $parsedTags['title'] ?? $this->track->title; - $this->track->track_type_id = $this->input['track_type_id'] ?? TrackType::UNCLASSIFIED_TRACK; + $this->track->title = $this->input['title'] ?? $parsedTags['title'] ?? $this->track->title; + $this->track->track_type_id = $this->input['track_type_id'] ?? TrackType::UNCLASSIFIED_TRACK; $this->track->genre_id = isset($this->input['genre']) ? $this->getGenreId($this->input['genre']) @@ -89,26 +88,27 @@ class ParseTrackTagsCommand extends CommandBase ? Carbon::createFromFormat(Carbon::ISO8601, $this->input['released_at']) : $parsedTags['release_date']; - $this->track->description = $this->input['description'] ?? $parsedTags['comments']; - $this->track->lyrics = $this->input['lyrics'] ?? $parsedTags['lyrics']; + $this->track->description = $this->input['description'] ?? $parsedTags['comments']; + $this->track->lyrics = $this->input['lyrics'] ?? $parsedTags['lyrics']; - $this->track->is_vocal = $this->input['is_vocal'] ?? $parsedTags['is_vocal']; - $this->track->is_explicit = $this->input['is_explicit'] ?? false; + $this->track->is_vocal = $this->input['is_vocal'] ?? $parsedTags['is_vocal']; + $this->track->is_explicit = $this->input['is_explicit'] ?? false; $this->track->is_downloadable = $this->input['is_downloadable'] ?? true; - $this->track->is_listed = $this->input['is_listed'] ?? true; + $this->track->is_listed = $this->input['is_listed'] ?? true; $this->track = $this->unsetNullVariables($this->track); $this->track->save(); + return CommandResponse::succeed(); } /** - * If a value is null, remove it! Helps prevent weird SQL errors + * If a value is null, remove it! Helps prevent weird SQL errors. * * @param Track * @return Track - */ + */ private function unsetNullVariables($track) { $vars = $track->getAttributes(); @@ -138,7 +138,7 @@ class ParseTrackTagsCommand extends CommandBase return Genre::create([ 'name' => $genreName, - 'slug' => Str::slug($genreName) + 'slug' => Str::slug($genreName), ])->id; } else { // Exists in db, has it been deleted? @@ -150,6 +150,7 @@ class ParseTrackTagsCommand extends CommandBase // instead of creating a new one $existingGenre->restore(); + return $existingGenre->id; } else { // It's fine, just return the ID @@ -166,7 +167,7 @@ class ParseTrackTagsCommand extends CommandBase * * @param int $artistId * @param string|null $albumName - * @param integer|null $coverId + * @param int|null $coverId * @return int|null */ protected function getAlbumId(int $artistId, $albumName, $coverId = null) @@ -174,7 +175,7 @@ class ParseTrackTagsCommand extends CommandBase if (null !== $albumName) { $album = Album::firstOrNew([ 'user_id' => $artistId, - 'title' => $albumName + 'title' => $albumName, ]); if (null === $album->id) { @@ -249,7 +250,6 @@ class ParseTrackTagsCommand extends CommandBase //========================================================================================================== $parsedTags['is_vocal'] = $parsedTags['lyrics'] !== null; - //========================================================================================================== // Determine the genre. //========================================================================================================== @@ -294,7 +294,6 @@ class ParseTrackTagsCommand extends CommandBase $parsedTags['cover_id'] = $coverId; - //========================================================================================================== // Is this part of an album? //========================================================================================================== @@ -307,11 +306,9 @@ class ParseTrackTagsCommand extends CommandBase $parsedTags['album_id'] = $albumId; - return [$parsedTags, $rawTags]; } - /** * @param array $rawTags * @return array @@ -326,7 +323,6 @@ class ParseTrackTagsCommand extends CommandBase $tags = []; } - $comment = null; if (isset($tags['comment'])) { @@ -361,7 +357,7 @@ class ParseTrackTagsCommand extends CommandBase 'comments' => $comment, 'lyrics' => isset($tags['unsynchronised_lyric']) ? $tags['unsynchronised_lyric'][0] : null, ], - $tags + $tags, ]; } @@ -405,7 +401,7 @@ class ParseTrackTagsCommand extends CommandBase 'comments' => isset($tags['comments']) ? $tags['comments'][0] : null, 'lyrics' => isset($tags['lyrics']) ? $tags['lyrics'][0] : null, ], - $tags + $tags, ]; } @@ -441,7 +437,7 @@ class ParseTrackTagsCommand extends CommandBase 'comments' => isset($tags['comments']) ? $tags['comments'][0] : null, 'lyrics' => isset($tags['lyrics']) ? $tags['lyrics'][0] : null, ], - $tags + $tags, ]; } @@ -474,7 +470,7 @@ class ParseTrackTagsCommand extends CommandBase // YYYY-MM case 7: try { - return Carbon::createFromFormat('Y m', str_replace("-", " ", $dateString)) + return Carbon::createFromFormat('Y m', str_replace('-', ' ', $dateString)) ->day(1); } catch (\InvalidArgumentException $e) { return null; @@ -483,7 +479,7 @@ class ParseTrackTagsCommand extends CommandBase // YYYY-MM-DD case 10: try { - return Carbon::createFromFormat('Y m d', str_replace("-", " ", $dateString)); + return Carbon::createFromFormat('Y m d', str_replace('-', ' ', $dateString)); } catch (\InvalidArgumentException $e) { return null; } diff --git a/app/Commands/RemoveTrackFromPlaylistCommand.php b/app/Commands/RemoveTrackFromPlaylistCommand.php index 13a1ee04..3301b711 100644 --- a/app/Commands/RemoveTrackFromPlaylistCommand.php +++ b/app/Commands/RemoveTrackFromPlaylistCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -54,7 +54,7 @@ class RemoveTrackFromPlaylistCommand extends CommandBase { $this->_playlist->tracks()->detach($this->_track); Playlist::whereId($this->_playlist->id)->update([ - 'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$this->_playlist->id.')') + 'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = '.$this->_playlist->id.')'), ]); return CommandResponse::succeed(['message' => 'Track removed!']); diff --git a/app/Commands/RenameGenreCommand.php b/app/Commands/RenameGenreCommand.php index 37d879c9..2256eb5b 100644 --- a/app/Commands/RenameGenreCommand.php +++ b/app/Commands/RenameGenreCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,11 +20,11 @@ namespace App\Commands; +use App\Jobs\UpdateTagsForRenamedGenre; +use App\Models\Genre; use Gate; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Support\Str; -use App\Jobs\UpdateTagsForRenamedGenre; -use App\Models\Genre; use Validator; class RenameGenreCommand extends CommandBase @@ -59,15 +59,14 @@ class RenameGenreCommand extends CommandBase $rules = [ 'name' => 'required|unique:genres,name,'.$this->_genre->id.',id,deleted_at,NULL|max:50', - 'slug' => 'required|unique:genres,slug,'.$this->_genre->id.',id,deleted_at,NULL' + 'slug' => 'required|unique:genres,slug,'.$this->_genre->id.',id,deleted_at,NULL', ]; $validator = Validator::make([ 'name' => $this->_newName, - 'slug' => $slug + 'slug' => $slug, ], $rules); - if ($validator->fails()) { return CommandResponse::fail($validator); } diff --git a/app/Commands/RenameShowSongCommand.php b/app/Commands/RenameShowSongCommand.php index 98b922a2..7821aa80 100644 --- a/app/Commands/RenameShowSongCommand.php +++ b/app/Commands/RenameShowSongCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Logic + * Copyright (C) 2016 Logic. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,11 +20,11 @@ namespace App\Commands; +use App\Jobs\UpdateTagsForRenamedShowSong; +use App\Models\ShowSong; use Gate; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Support\Str; -use App\Jobs\UpdateTagsForRenamedShowSong; -use App\Models\ShowSong; use Validator; class RenameShowSongCommand extends CommandBase @@ -59,15 +59,14 @@ class RenameShowSongCommand extends CommandBase $rules = [ 'title' => 'required|unique:show_songs,title,'.$this->_song->id.',id|max:250', - 'slug' => 'required|unique:show_songs,slug,'.$this->_song->id.',id' + 'slug' => 'required|unique:show_songs,slug,'.$this->_song->id.',id', ]; $validator = Validator::make([ 'title' => $this->_newName, - 'slug' => $slug + 'slug' => $slug, ], $rules); - if ($validator->fails()) { return CommandResponse::fail($validator); } diff --git a/app/Commands/SaveAccountSettingsCommand.php b/app/Commands/SaveAccountSettingsCommand.php index c06b63a8..fe6359f2 100644 --- a/app/Commands/SaveAccountSettingsCommand.php +++ b/app/Commands/SaveAccountSettingsCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,9 +20,9 @@ namespace App\Commands; -use DB; use App\Models\Image; use App\Models\User; +use DB; use Gate; use Validator; @@ -63,7 +63,7 @@ class SaveAccountSettingsCommand extends CommandBase 'unique:users,slug,'.$this->_user->id, 'min:'.config('ponyfm.user_slug_minimum_length'), 'regex:/^[a-z\d-]+$/', - 'is_not_reserved_slug' + 'is_not_reserved_slug', ], 'notifications.*.activity_type' => 'required|exists:activity_types,activity_type', 'notifications.*.receive_emails' => 'present|boolean', @@ -77,21 +77,20 @@ class SaveAccountSettingsCommand extends CommandBase } $validator = Validator::make($this->_input, $rules, [ - 'slug.regex' => 'Slugs can only contain numbers, lowercase letters, and dashes.' + 'slug.regex' => 'Slugs can only contain numbers, lowercase letters, and dashes.', ]); if ($validator->fails()) { return CommandResponse::fail($validator); } - $this->_user->bio = $this->_input['bio']; $this->_user->display_name = $this->_input['display_name']; $this->_user->slug = $this->_input['slug']; $this->_user->can_see_explicit_content = $this->_input['can_see_explicit_content'] == 'true'; $this->_user->uses_gravatar = $this->_input['uses_gravatar'] == 'true'; - if ($this->_user->uses_gravatar && !empty($this->_input['gravatar'])) { + if ($this->_user->uses_gravatar && ! empty($this->_input['gravatar'])) { $this->_user->avatar_id = null; $this->_user->gravatar = $this->_input['gravatar']; } else { @@ -106,21 +105,19 @@ class SaveAccountSettingsCommand extends CommandBase } } - DB::transaction(function() { + DB::transaction(function () { $this->_user->save(); // Sync email subscriptions $emailSubscriptions = $this->_user->emailSubscriptions->keyBy('activity_type'); foreach ($this->_input['notifications'] as $notificationSetting) { - if ( $notificationSetting['receive_emails'] && - !$emailSubscriptions->offsetExists($notificationSetting['activity_type']) + ! $emailSubscriptions->offsetExists($notificationSetting['activity_type']) ) { $this->_user->emailSubscriptions()->create(['activity_type' => $notificationSetting['activity_type']]); - } elseif ( - !$notificationSetting['receive_emails'] && + ! $notificationSetting['receive_emails'] && $emailSubscriptions->offsetExists($notificationSetting['activity_type']) ) { $emailSubscriptions->get($notificationSetting['activity_type'])->delete(); diff --git a/app/Commands/ToggleFavouriteCommand.php b/app/Commands/ToggleFavouriteCommand.php index 0234683a..ab48d159 100644 --- a/app/Commands/ToggleFavouriteCommand.php +++ b/app/Commands/ToggleFavouriteCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,15 +20,15 @@ namespace App\Commands; -use Notification; use App\Contracts\Favouritable; -use App\Models\Favourite; -use App\Models\Track; use App\Models\Album; +use App\Models\Favourite; use App\Models\Playlist; use App\Models\ResourceUser; +use App\Models\Track; use Auth; use DB; +use Notification; class ToggleFavouriteCommand extends CommandBase { @@ -98,14 +98,13 @@ class ToggleFavouriteCommand extends CommandBase // for the same resource at the same time, the cached values will still be correct with this method. DB::table($resourceTable)->whereId($this->_resourceId)->update([ - 'favourite_count' => - DB::raw('( + 'favourite_count' => DB::raw('( SELECT COUNT(id) FROM favourites - WHERE ' . - $typeId.' = '.$this->_resourceId.')') + WHERE '. + $typeId.' = '.$this->_resourceId.')'), ]); return CommandResponse::succeed(['is_favourited' => $isFavourited]); diff --git a/app/Commands/ToggleFollowingCommand.php b/app/Commands/ToggleFollowingCommand.php index f879c4ab..d15eb9a9 100644 --- a/app/Commands/ToggleFollowingCommand.php +++ b/app/Commands/ToggleFollowingCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -52,7 +52,7 @@ class ToggleFollowingCommand extends CommandBase */ public function execute() { - $typeId = $this->_resourceType . '_id'; + $typeId = $this->_resourceType.'_id'; $existing = Follower::where($typeId, '=', $this->_resourceId)->whereUserId(Auth::user()->id)->first(); $isFollowed = false; diff --git a/app/Commands/UploadTrackCommand.php b/app/Commands/UploadTrackCommand.php index 19438c30..b1de3c63 100644 --- a/app/Commands/UploadTrackCommand.php +++ b/app/Commands/UploadTrackCommand.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,14 +20,14 @@ namespace App\Commands; +use App\Models\Track; +use App\Models\User; use Auth; use Carbon\Carbon; use Config; use Gate; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Support\Facades\Request; -use App\Models\Track; -use App\Models\User; use Validator; class UploadTrackCommand extends CommandBase @@ -106,7 +106,7 @@ class UploadTrackCommand extends CommandBase $trackFile = Request::file('track', null); } - if (!$this->_isReplacingTrack) { + if (! $this->_isReplacingTrack) { $coverFile = Request::file('cover', null); } @@ -115,12 +115,13 @@ class UploadTrackCommand extends CommandBase $this->_track->version_upload_status = Track::STATUS_ERROR; $this->_track->update(); } + return CommandResponse::fail(['track' => ['You must upload an audio file!']]); } $audio = \AudioCache::get($trackFile->getPathname()); - if (!$this->_isReplacingTrack) { + if (! $this->_isReplacingTrack) { $this->_track = new Track(); $this->_track->user_id = $this->_artist->id; // The title set here is a placeholder; it'll be replaced by ParseTrackTagsCommand @@ -133,34 +134,33 @@ class UploadTrackCommand extends CommandBase } $this->_track->ensureDirectoryExists(); - if (!is_dir(Config::get('ponyfm.files_directory').'/tmp')) { + if (! is_dir(Config::get('ponyfm.files_directory').'/tmp')) { mkdir(Config::get('ponyfm.files_directory').'/tmp', 0755, true); } - if (!is_dir(Config::get('ponyfm.files_directory').'/queued-tracks')) { + if (! is_dir(Config::get('ponyfm.files_directory').'/queued-tracks')) { mkdir(Config::get('ponyfm.files_directory').'/queued-tracks', 0755, true); } - $trackFile = $trackFile->move(Config::get('ponyfm.files_directory') . '/queued-tracks', $this->_track->id . 'v' . $this->_version); + $trackFile = $trackFile->move(Config::get('ponyfm.files_directory').'/queued-tracks', $this->_track->id.'v'.$this->_version); $input = Request::all(); $input['track'] = $trackFile; // Prevent the setting of the cover index for validation - if (!$this->_isReplacingTrack && isset($coverFile)) { + if (! $this->_isReplacingTrack && isset($coverFile)) { $input['cover'] = $coverFile; } $rules = [ - 'track' => - 'required|' - . ($this->_allowLossy + 'track' => 'required|' + .($this->_allowLossy ? 'audio_format:flac,alac,pcm,adpcm,aac,mp3,vorbis|' : 'audio_format:flac,alac,pcm,adpcm|') - . ($this->_allowShortTrack ? '' : 'min_duration:30|') - . 'audio_channels:1,2', + .($this->_allowShortTrack ? '' : 'min_duration:30|') + .'audio_channels:1,2', ]; - if (!$this->_isReplacingTrack) { + if (! $this->_isReplacingTrack) { array_merge($rules, [ 'cover' => 'image|mimes:png,jpeg|min_width:350|min_height:350', 'auto_publish' => 'boolean', @@ -176,7 +176,7 @@ class UploadTrackCommand extends CommandBase 'is_explicit' => 'boolean', 'is_downloadable' => 'boolean', 'is_listed' => 'boolean', - 'metadata' => 'json' + 'metadata' => 'json', ]); } $validator = \Validator::make($input, $rules); @@ -188,15 +188,16 @@ class UploadTrackCommand extends CommandBase } else { $this->_track->delete(); } + return CommandResponse::fail($validator); } - if (!$this->_isReplacingTrack) { + if (! $this->_isReplacingTrack) { // If json_decode() isn't called here, Laravel will surround the JSON // string with quotes when storing it in the database, which breaks things. $this->_track->metadata = json_decode(Request::get('metadata', null)); } - $autoPublish = (bool)($input['auto_publish'] ?? $this->_autoPublishByDefault); + $autoPublish = (bool) ($input['auto_publish'] ?? $this->_autoPublishByDefault); $this->_track->source = $this->_customTrackSource ?? $source; $this->_track->save(); @@ -206,7 +207,7 @@ class UploadTrackCommand extends CommandBase $input['cover'] = null; } - if (!$this->_isReplacingTrack) { + if (! $this->_isReplacingTrack) { // Parse any tags in the uploaded files. $parseTagsCommand = new ParseTrackTagsCommand($this->_track, $trackFile, $input); $result = $parseTagsCommand->execute(); @@ -215,11 +216,13 @@ class UploadTrackCommand extends CommandBase $this->_track->version_upload_status = Track::STATUS_ERROR; $this->_track->update(); } + return $result; } } $generateTrackFiles = new GenerateTrackFilesCommand($this->_track, $trackFile, $autoPublish, true, $this->_isReplacingTrack, $this->_version); + return $generateTrackFiles->execute(); } } diff --git a/app/Console/Commands/BootstrapLocalEnvironment.php b/app/Console/Commands/BootstrapLocalEnvironment.php index a4a90f37..0e4fbfb8 100644 --- a/app/Console/Commands/BootstrapLocalEnvironment.php +++ b/app/Console/Commands/BootstrapLocalEnvironment.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -40,7 +40,6 @@ class BootstrapLocalEnvironment extends Command /** * Create a new command instance. - * */ public function __construct() { diff --git a/app/Console/Commands/ClassifyMLPMA.php b/app/Console/Commands/ClassifyMLPMA.php index 08d1cc64..4a512b16 100644 --- a/app/Console/Commands/ClassifyMLPMA.php +++ b/app/Console/Commands/ClassifyMLPMA.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -53,7 +53,6 @@ class ClassifyMLPMA extends Command /** * Create a new command instance. - * */ public function __construct() { @@ -74,7 +73,7 @@ class ClassifyMLPMA extends Command $this->comment('Importing tracks...'); - $totalTracks = sizeof($tracks); + $totalTracks = count($tracks); $fileToStartAt = (int) $this->option('startAt') - 1; $this->comment("Skipping $fileToStartAt files...".PHP_EOL); @@ -88,7 +87,6 @@ class ClassifyMLPMA extends Command $parsedTags = json_decode($track->parsed_tags, true); - //========================================================================================================== // Original, show song remix, fan song remix, show audio remix, or ponified song? //========================================================================================================== @@ -103,7 +101,6 @@ class ClassifyMLPMA extends Command ") ->get(); - // If it has "Ingram" in the name, it's definitely an official song remix. if (Str::contains(Str::lower($track->filename), 'ingram')) { $this->info('This is an official song remix!'); @@ -115,8 +112,7 @@ class ClassifyMLPMA extends Command $parsedTags ); - - // If it has "remix" in the name, it's definitely a remix. + // If it has "remix" in the name, it's definitely a remix. } else { if (Str::contains(Str::lower($sanitizedTrackTitle), 'remix')) { $this->info('This is some kind of remix!'); @@ -128,7 +124,7 @@ class ClassifyMLPMA extends Command $parsedTags ); - // No idea what this is. Have the pony at the terminal figure it out! + // No idea what this is. Have the pony at the terminal figure it out! } else { list($trackType, $linkedSongIds) = $this->classifyTrack( $track->filename, @@ -139,7 +135,6 @@ class ClassifyMLPMA extends Command } } - //========================================================================================================== // Attach the data and publish the track! //========================================================================================================== @@ -150,7 +145,7 @@ class ClassifyMLPMA extends Command $track->published_at = $parsedTags['released_at']; $track->save(); - if (sizeof($linkedSongIds) > 0) { + if (count($linkedSongIds) > 0) { $track->showSongs()->sync($linkedSongIds); } @@ -167,24 +162,22 @@ class ClassifyMLPMA extends Command * @param bool|false $isRemixOfOfficialTrack * @return array */ - protected function classifyTrack($filename, $officialSongs, $isRemixOfOfficialTrack = false, $tags) + protected function classifyTrack($filename, $officialSongs, $isRemixOfOfficialTrack, $tags) { $trackTypeId = null; $linkedSongIds = []; - foreach ($officialSongs as $song) { $this->comment('=> Matched official song: ['.$song->id.'] '.$song->title); } - - if ($isRemixOfOfficialTrack && sizeof($officialSongs) === 1) { + if ($isRemixOfOfficialTrack && count($officialSongs) === 1) { $linkedSongIds = [$officialSongs[0]->id]; } else { - if ($isRemixOfOfficialTrack && sizeof($officialSongs) > 1) { + if ($isRemixOfOfficialTrack && count($officialSongs) > 1) { $this->question('Multiple official songs matched! Please enter the ID of the correct one.'); } else { - if (sizeof($officialSongs) > 0) { + if (count($officialSongs) > 0) { $this->question('This looks like a remix of an official song!'); $this->question('Press "r" if the match above is right!'); } else { diff --git a/app/Console/Commands/ClearTrackCache.php b/app/Console/Commands/ClearTrackCache.php index 9669594e..765e8ff8 100644 --- a/app/Console/Commands/ClearTrackCache.php +++ b/app/Console/Commands/ClearTrackCache.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Kelvin Zhang + * Copyright (C) 2015 Kelvin Zhang. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,10 +20,10 @@ namespace App\Console\Commands; +use App\Models\TrackFile; use Carbon\Carbon; use File; use Illuminate\Console\Command; -use App\Models\TrackFile; class ClearTrackCache extends Command { @@ -45,7 +45,6 @@ class ClearTrackCache extends Command /** * Create a new command instance. - * */ public function __construct() { @@ -76,7 +75,7 @@ class ClearTrackCache extends Command if (count($trackFiles) === 0) { $this->info('No tracks found. Exiting.'); } else { - if ($this->option('force') || $this->confirm(count($trackFiles) . ' cacheable track files found. Proceed to delete their files if they exist? [y|N]', false)) { + if ($this->option('force') || $this->confirm(count($trackFiles).' cacheable track files found. Proceed to delete their files if they exist? [y|N]', false)) { $count = 0; foreach ($trackFiles as $trackFile) { @@ -89,10 +88,10 @@ class ClearTrackCache extends Command $count++; File::delete($trackFile->getFile()); - $this->info('Deleted ' . $trackFile->getFile()); + $this->info('Deleted '.$trackFile->getFile()); } } - $this->info($count . ' files deleted. Deletion complete. Exiting.'); + $this->info($count.' files deleted. Deletion complete. Exiting.'); } else { $this->info('Deletion cancelled. Exiting.'); } diff --git a/app/Console/Commands/FixMLPMAImages.php b/app/Console/Commands/FixMLPMAImages.php index 7cc99c01..0b795395 100644 --- a/app/Console/Commands/FixMLPMAImages.php +++ b/app/Console/Commands/FixMLPMAImages.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,12 +20,12 @@ namespace App\Console\Commands; +use App\Models\Image; use Config; use DB; use File; use getID3; use Illuminate\Console\Command; -use App\Models\Image; use Symfony\Component\HttpFoundation\File\UploadedFile; class FixMLPMAImages extends Command @@ -47,7 +47,6 @@ class FixMLPMAImages extends Command /** * Create a new command instance. - * */ public function __construct() { @@ -56,7 +55,6 @@ class FixMLPMAImages extends Command protected $currentFile; - /** * File extensions to ignore when importing the archive. * @@ -69,7 +67,7 @@ class FixMLPMAImages extends Command 'txt', 'rtf', 'wma', - 'wmv' + 'wmv', ]; /** @@ -84,17 +82,16 @@ class FixMLPMAImages extends Command $this->comment('Enumerating MLP Music Archive source files...'); $files = File::allFiles($mlpmaPath); - $this->info(sizeof($files).' files found!'); + $this->info(count($files).' files found!'); $this->comment('Importing tracks...'); - $totalFiles = sizeof($files); + $totalFiles = count($files); $fileToStartAt = (int) $this->option('startAt') - 1; $this->comment("Skipping $fileToStartAt files...".PHP_EOL); $files = array_slice($files, $fileToStartAt); $this->currentFile = $fileToStartAt; - foreach ($files as $file) { $this->currentFile++; @@ -110,7 +107,6 @@ class FixMLPMAImages extends Command ->first(); $artistId = $importedTrack->user_id; - //========================================================================================================== // Extract the original tags. //========================================================================================================== @@ -119,7 +115,6 @@ class FixMLPMAImages extends Command // all tags read by getID3, including the cover art $allTags = $getId3->analyze($file->getPathname()); - //========================================================================================================== // Extract the cover art, if any exists. //========================================================================================================== diff --git a/app/Console/Commands/ImportEQBeats.php b/app/Console/Commands/ImportEQBeats.php index f1b7fc86..c4c69af6 100644 --- a/app/Console/Commands/ImportEQBeats.php +++ b/app/Console/Commands/ImportEQBeats.php @@ -2,21 +2,21 @@ namespace App\Console\Commands; +use App\Commands\UploadTrackCommand; +use App\Models\Album; +use App\Models\Genre; +use App\Models\Image; +use App\Models\Track; +use App\Models\User; use Auth; use Carbon\Carbon; use Config; use DB; use File; -use Input; use getID3; -use App\Models\Image; -use App\Models\Track; -use App\Models\User; -use App\Models\Genre; -use App\Models\Album; -use App\Commands\UploadTrackCommand; use Illuminate\Console\Command; use Illuminate\Support\Str; +use Input; use Symfony\Component\HttpFoundation\File\UploadedFile; class ImportEQBeats extends Command @@ -69,7 +69,7 @@ class ImportEQBeats extends Command public function handleInterrupt($signo) { $this->error('Import aborted!'); - $this->error('Resume it from here using: --startAt=' . $this->currentFile); + $this->error('Resume it from here using: --startAt='.$this->currentFile); $this->isInterrupted = true; } @@ -88,13 +88,13 @@ class ImportEQBeats extends Command $archivePath = $this->argument('archiveFolder'); $tmpPath = Config::get('ponyfm.files_directory').'/tmp'; - if (!File::exists($tmpPath)) { + if (! File::exists($tmpPath)) { File::makeDirectory($tmpPath); } $UNKNOWN_GENRE = Genre::firstOrCreate([ 'name' => 'Unknown', - 'slug' => 'unknown' + 'slug' => 'unknown', ]); //========================================================================================================== @@ -102,18 +102,18 @@ class ImportEQBeats extends Command //========================================================================================================== $this->comment('Enumerating files...'); $files = File::allFiles($archivePath); - $this->info(sizeof($files) . ' files found!'); + $this->info(count($files).' files found!'); $this->comment('Enumerating artists...'); $artists = File::directories($archivePath); - $this->info(sizeof($artists) . ' artists found!'); + $this->info(count($artists).' artists found!'); $this->comment('Importing tracks...'); - $totalFiles = sizeof($files); + $totalFiles = count($files); - $fileToStartAt = (int)$this->option('startAt') - 1; - $this->comment("Skipping $fileToStartAt files..." . PHP_EOL); + $fileToStartAt = (int) $this->option('startAt') - 1; + $this->comment("Skipping $fileToStartAt files...".PHP_EOL); $files = array_slice($files, $fileToStartAt); $this->currentFile = $fileToStartAt; @@ -127,20 +127,20 @@ class ImportEQBeats extends Command break; } - $this->comment('[' . $this->currentFile . '/' . $totalFiles . '] Importing track [' . $file->getFilename() . ']...'); + $this->comment('['.$this->currentFile.'/'.$totalFiles.'] Importing track ['.$file->getFilename().']...'); - if (!in_array($file->getExtension(), $this->allowedExtensions)) { - $this->comment('This is not an audio file! Skipping...' . PHP_EOL); + if (! in_array($file->getExtension(), $this->allowedExtensions)) { + $this->comment('This is not an audio file! Skipping...'.PHP_EOL); continue; } - $this->info('Path to file: ' . $file->getRelativePath()); + $this->info('Path to file: '.$file->getRelativePath()); $path_components = explode(DIRECTORY_SEPARATOR, $file->getRelativePath()); $artist_name = $path_components[0]; $album_name = array_key_exists(1, $path_components) ? $path_components[1] : null; - $this->info('Artist: ' . $artist_name); - $this->info('Album: ' . $album_name); + $this->info('Artist: '.$artist_name); + $this->info('Album: '.$album_name); //========================================================================================================== // Analyse the track so we can find the MIME type and album art @@ -170,7 +170,7 @@ class ImportEQBeats extends Command $parsedTags['title'] = substr($fileName, strpos($fileName, $hyphen) + strlen($hyphen)); } - $this->info('Title: ' . $parsedTags['title']); + $this->info('Title: '.$parsedTags['title']); //========================================================================================================== // Determine the release date. @@ -183,11 +183,9 @@ class ImportEQBeats extends Command if ($taggedYear !== null && $modifiedDate->year === $taggedYear) { $releasedAt = $modifiedDate; - - } else if ($taggedYear !== null && $modifiedDate->year !== $taggedYear) { + } elseif ($taggedYear !== null && $modifiedDate->year !== $taggedYear) { $this->warn('Release years don\'t match! Using the tagged year...'); $releasedAt = Carbon::create($taggedYear); - } else { // $taggedYear is null $this->warn('This track isn\'t tagged with its release year! Using the track\'s last modified date...'); @@ -215,7 +213,6 @@ class ImportEQBeats extends Command $genre->restore(); } $genreId = $genre->id; - } else { $genre = new Genre(); $genre->name = $genreName; @@ -224,10 +221,9 @@ class ImportEQBeats extends Command $genreId = $genre->id; $this->comment('Created a new genre!'); } - } else { $genreId = $UNKNOWN_GENRE->id; // "Unknown" genre ID - } + } //========================================================================================================== // Check to see if we have this track already, if so, compare hashes of the two files @@ -236,7 +232,7 @@ class ImportEQBeats extends Command $artist = User::where('display_name', '=', $artist_name)->first(); $artistId = null; - $this->comment("Checking for duplicates"); + $this->comment('Checking for duplicates'); if ($artist) { $artistId = $artist->id; @@ -254,7 +250,7 @@ class ImportEQBeats extends Command $importFormat = $this->getFormat($file->getExtension()); if ($importFormat == null) { // No idea what this is, skip file - $this->comment(sprintf("Not an audio file (%s), skipping...", $importFormat)); + $this->comment(sprintf('Not an audio file (%s), skipping...', $importFormat)); continue; } @@ -273,7 +269,7 @@ class ImportEQBeats extends Command // Source is lossless, is the existing track lossy? if ($existingFile->isMasterLossy()) { // Cool! Let's replace it - $this->comment('Replacing (' . $existingTrack->id . ') ' . $existingTrack->title); + $this->comment('Replacing ('.$existingTrack->id.') '.$existingTrack->title); $this->replaceTrack($file, $existingTrack, $artist, $allTags['mime_type']); @@ -282,16 +278,15 @@ class ImportEQBeats extends Command } continue; - } else { - $this->comment("Found existing file"); + $this->comment('Found existing file'); // Found a matching format, are they the same? // Before we check it, see if it came from MLPMA // We're only replacing tracks with the same format if they're archived $mlpmaTrack = DB::table('mlpma_tracks')->where('track_id', '=', $existingTrack->id)->first(); - if (!is_null($mlpmaTrack)) { + if (! is_null($mlpmaTrack)) { $getId3_source = new getID3; $getId3_source->option_md5_data = true; @@ -307,8 +302,8 @@ class ImportEQBeats extends Command $importHash = array_key_exists('md5_data_source', $sourceWithMd5) ? $sourceWithMd5['md5_data_source'] : $sourceWithMd5['md5_data']; $targetHash = array_key_exists('md5_data_source', $existingFileTags) ? $existingFileTags['md5_data_source'] : $existingFileTags['md5_data']; - $this->info("Archive hash: " . $importHash); - $this->info("Pony.fm hash: " . $targetHash); + $this->info('Archive hash: '.$importHash); + $this->info('Pony.fm hash: '.$targetHash); if ($importHash == $targetHash) { // Audio is identical, no need to reupload @@ -319,28 +314,30 @@ class ImportEQBeats extends Command if (strlen($existingTrack->description) < strlen($parsedTags['comments'])) { $existingTrack->description = $parsedTags['comments']; $changedMetadata = true; - $this->comment("Updated description"); + $this->comment('Updated description'); } if (strlen($existingTrack->lyrics) < strlen($parsedTags['lyrics'])) { $existingTrack->lyrics = $parsedTags['lyrics']; $changedMetadata = true; - $this->comment("Updated lyrics"); + $this->comment('Updated lyrics'); } - if ($changedMetadata) $existingTrack->save(); + if ($changedMetadata) { + $existingTrack->save(); + } continue; } else { // Audio is different, let's replace it - $this->comment('Replacing (' . $existingTrack->id . ') ' . $existingTrack->title); + $this->comment('Replacing ('.$existingTrack->id.') '.$existingTrack->title); $this->replaceTrack($file, $existingTrack, $artist, $allTags['mime_type']); continue; } } else { - $this->comment("Not replacing, user uploaded"); + $this->comment('Not replacing, user uploaded'); // We can update the metadata though $changedMetadata = false; @@ -348,28 +345,30 @@ class ImportEQBeats extends Command if (strlen($existingTrack->description) < strlen($parsedTags['comments'])) { $existingTrack->description = $parsedTags['comments']; $changedMetadata = true; - $this->comment("Updated description"); + $this->comment('Updated description'); } if (strlen($existingTrack->lyrics) < strlen($parsedTags['lyrics'])) { $existingTrack->lyrics = $parsedTags['lyrics']; $changedMetadata = true; - $this->comment("Updated lyrics"); + $this->comment('Updated lyrics'); } - if ($changedMetadata) $existingTrack->save(); + if ($changedMetadata) { + $existingTrack->save(); + } continue; } } } else { - $this->comment("No duplicates"); + $this->comment('No duplicates'); } //========================================================================================================== // Create new user for the artist if one doesn't exist //========================================================================================================== - if (!$artist) { + if (! $artist) { $artist = new User; $artist->display_name = $artist_name; $artist->email = null; @@ -379,8 +378,8 @@ class ImportEQBeats extends Command $slugExists = User::where('slug', '=', $artist->slug)->first(); if ($slugExists) { - $this->error('Horsefeathers! The slug ' . $artist->slug . ' is already taken!'); - $artist->slug = $artist->slug . '-' . Str::random(4); + $this->error('Horsefeathers! The slug '.$artist->slug.' is already taken!'); + $artist->slug = $artist->slug.'-'.Str::random(4); } $artist->save(); @@ -396,7 +395,7 @@ class ImportEQBeats extends Command if (array_key_exists('comments', $allTags) && array_key_exists('picture', $allTags['comments'])) { $image = $allTags['comments']['picture'][0]; - } else if (array_key_exists('id3v2', $allTags) && array_key_exists('APIC', $allTags['id3v2'])) { + } elseif (array_key_exists('id3v2', $allTags) && array_key_exists('APIC', $allTags['id3v2'])) { $image = $allTags['id3v2']['APIC'][0]; } @@ -415,8 +414,8 @@ class ImportEQBeats extends Command } } // write temporary image file - $imageFilename = $file->getFilename() . ".cover.$extension"; - $imageFilePath = "$tmpPath/" . $imageFilename; + $imageFilename = $file->getFilename().".cover.$extension"; + $imageFilePath = "$tmpPath/".$imageFilename; File::put($imageFilePath, $image['data']); $imageFile = new UploadedFile($imageFilePath, $imageFilename, $image['image_mime'], null, null, true); @@ -437,13 +436,13 @@ class ImportEQBeats extends Command ->where('title', '=', $albumName) ->first(); - if (!$album) { + if (! $album) { $album = new Album; $album->title = $albumName; $album->user_id = $artist->id; $album->cover_id = $coverId; - $album->description = ""; + $album->description = ''; $album->save(); } @@ -460,8 +459,8 @@ class ImportEQBeats extends Command $mime = $allTags['mime_type']; - File::copy($file->getPathname(), "$tmpPath/" . $file->getFilename()); - $trackFile = new UploadedFile("$tmpPath/" . $file->getFilename(), $file->getFilename(), $mime, null, null, true); + File::copy($file->getPathname(), "$tmpPath/".$file->getFilename()); + $trackFile = new UploadedFile("$tmpPath/".$file->getFilename(), $file->getFilename(), $mime, null, null, true); $upload = new UploadTrackCommand(true); $upload->_file = $trackFile; @@ -479,18 +478,18 @@ class ImportEQBeats extends Command $track->is_downloadable = true; $track->is_vocal = $isVocal; $track->license_id = 2; - $track->description = ""; - $track->lyrics = ""; + $track->description = ''; + $track->lyrics = ''; - if (!is_null($parsedTags['comments'])) { + if (! is_null($parsedTags['comments'])) { $track->description = $parsedTags['comments']; } - if (!is_null($parsedTags['lyrics'])) { + if (! is_null($parsedTags['lyrics'])) { $track->lyrics = $parsedTags['lyrics']; } - if (!is_null($parsedTags['title'])) { + if (! is_null($parsedTags['title'])) { $track->title = $parsedTags['title']; } @@ -501,7 +500,7 @@ class ImportEQBeats extends Command ->insert([ 'track_id' => $result->getResponse()['id'], 'path' => $file->getRelativePath(), - 'filename' => iconv("UTF-8", "ISO-8859-1//TRANSLIT", $file->getFilename()), + 'filename' => iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $file->getFilename()), 'extension' => $file->getExtension(), 'imported_at' => Carbon::now(), 'parsed_tags' => json_encode($parsedTags), @@ -509,18 +508,21 @@ class ImportEQBeats extends Command ]); } - echo PHP_EOL . PHP_EOL; + echo PHP_EOL.PHP_EOL; } } - protected function hashAudio($filepath) { + protected function hashAudio($filepath) + { $hash = hash_file('crc32b', $filepath); $array = unpack('N', pack('H*', $hash)); + return $array[1]; } - protected function getFormat($extension) { - foreach(Track::$Formats as $name => $format) { + protected function getFormat($extension) + { + foreach (Track::$Formats as $name => $format) { if ($format['extension'] == $extension) { return $name; } @@ -565,7 +567,6 @@ class ImportEQBeats extends Command $rawTags = []; } - return [$parsedTags, $rawTags]; } @@ -623,7 +624,7 @@ class ImportEQBeats extends Command 'comments' => $comment, 'lyrics' => isset($tags['unsynchronised_lyric']) ? $tags['unsynchronised_lyric'][0] : null, ], - $tags + $tags, ]; } @@ -667,7 +668,7 @@ class ImportEQBeats extends Command 'comments' => isset($tags['comments']) ? $tags['comments'][0] : null, 'lyrics' => isset($tags['lyrics']) ? $tags['lyrics'][0] : null, ], - $tags + $tags, ]; } @@ -703,7 +704,7 @@ class ImportEQBeats extends Command 'comments' => isset($tags['comments']) ? $tags['comments'][0] : null, 'lyrics' => isset($tags['lyrics']) ? $tags['lyrics'][0] : null, ], - $tags + $tags, ]; } @@ -736,7 +737,7 @@ class ImportEQBeats extends Command // YYYY-MM case 7: try { - return Carbon::createFromFormat('Y m', str_replace("-", " ", $dateString)) + return Carbon::createFromFormat('Y m', str_replace('-', ' ', $dateString)) ->day(1); } catch (\InvalidArgumentException $e) { return null; @@ -745,7 +746,7 @@ class ImportEQBeats extends Command // YYYY-MM-DD case 10: try { - return Carbon::createFromFormat('Y m d', str_replace("-", " ", $dateString)); + return Carbon::createFromFormat('Y m d', str_replace('-', ' ', $dateString)); } catch (\InvalidArgumentException $e) { return null; } @@ -762,7 +763,8 @@ class ImportEQBeats extends Command } } - protected function replaceTrack($toBeUploaded, $targetTrack, $artist, $mime) { + protected function replaceTrack($toBeUploaded, $targetTrack, $artist, $mime) + { Auth::loginUsingId($artist->id); $trackFile = new UploadedFile($toBeUploaded->getPathname(), $toBeUploaded->getFilename(), $mime, null, null, true); diff --git a/app/Console/Commands/MergeAccounts.php b/app/Console/Commands/MergeAccounts.php index aac39b29..7af3fe4b 100644 --- a/app/Console/Commands/MergeAccounts.php +++ b/app/Console/Commands/MergeAccounts.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,10 +20,6 @@ namespace App\Console\Commands; -use Carbon\Carbon; -use DB; -use Illuminate\Console\Command; -use Illuminate\Support\Collection; use App\Commands\MergeAccountsCommand; use App\Models\Album; use App\Models\Comment; @@ -36,6 +32,10 @@ use App\Models\ResourceLogItem; use App\Models\ResourceUser; use App\Models\Track; use App\Models\User; +use Carbon\Carbon; +use DB; +use Illuminate\Console\Command; +use Illuminate\Support\Collection; class MergeAccounts extends Command { @@ -57,7 +57,6 @@ class MergeAccounts extends Command /** * Create a new command instance. - * */ public function __construct() { @@ -81,9 +80,10 @@ class MergeAccounts extends Command if (null !== $sourceAccount->getAccessToken()) { $this->warn("WARNING: The source account (ID {$sourceAccountId}) is linked to a Poniverse account! Normally, the destination account should be the one that's linked to a Poniverse account as that's the one that the artist will be logging into."); $this->line(''); - $this->warn("If you continue with this merge, the Poniverse account linked to the source Pony.fm account will no longer be able to log into Pony.fm."); - if (!$this->confirm('Continue merging this set of source and destination accounts?')){ + $this->warn('If you continue with this merge, the Poniverse account linked to the source Pony.fm account will no longer be able to log into Pony.fm.'); + if (! $this->confirm('Continue merging this set of source and destination accounts?')) { $this->error('Merge aborted.'); + return 1; } } @@ -91,8 +91,9 @@ class MergeAccounts extends Command if (null === $destinationAccount->getAccessToken()) { $this->warn("WARNING: The destination account (ID {$destinationAccountId}) is not linked to a Poniverse account!"); $this->warn("This is normal if you're merging two archived profiles but not if you're helping an artist claim their profile."); - if (!$this->confirm('Continue merging this set of source and destination accounts?')){ + if (! $this->confirm('Continue merging this set of source and destination accounts?')) { $this->error('Merge aborted.'); + return 1; } } @@ -101,6 +102,7 @@ class MergeAccounts extends Command $command = new MergeAccountsCommand($sourceAccount, $destinationAccount); $command->execute(); + return 0; } } diff --git a/app/Console/Commands/MigrateOldData.php b/app/Console/Commands/MigrateOldData.php index aaab3a25..7887d065 100644 --- a/app/Console/Commands/MigrateOldData.php +++ b/app/Console/Commands/MigrateOldData.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -45,7 +45,6 @@ class MigrateOldData extends Command /** * Create a new command instance. - * */ public function __construct() { @@ -69,15 +68,15 @@ class MigrateOldData extends Command $this->info('Syncing Users'); foreach ($oldUsers as $user) { $displayName = $user->display_name; - if (!$displayName) { + if (! $displayName) { $displayName = $user->username; } - if (!$displayName) { + if (! $displayName) { $displayName = $user->username; } - if (!$displayName) { + if (! $displayName) { continue; } @@ -94,11 +93,11 @@ class MigrateOldData extends Command 'username' => $user->username, 'uses_gravatar' => $user->uses_gravatar, 'gravatar' => $user->gravatar, - 'avatar_id' => null + 'avatar_id' => null, ]); $coverId = null; - if (!$user->uses_gravatar) { + if (! $user->uses_gravatar) { try { $coverFile = $this->getIdDirectory('users', $user->id).'/'.$user->id.'_.png'; $coverId = Image::upload(new UploadedFile( @@ -119,7 +118,7 @@ class MigrateOldData extends Command DB::table('genres')->insert([ 'id' => $genre->id, 'name' => $genre->title, - 'slug' => $genre->slug + 'slug' => $genre->slug, ]); } @@ -139,7 +138,7 @@ class MigrateOldData extends Command 'id' => $playlist->id, 'user_id' => $playlist->user_id, 'view_count' => 0, - 'download_count' => 0 + 'download_count' => 0, ]); foreach ($logViews as $logItem) { @@ -164,7 +163,7 @@ class MigrateOldData extends Command 'album_id' => $logItem->album_id, 'created_at' => $logItem->created_at, 'ip_address' => $logItem->ip_address, - 'track_format_id' => $logItem->track_file_format_id - 1 + 'track_format_id' => $logItem->track_file_format_id - 1, ]); } catch (\Exception $e) { $this->error('Could insert log item for album '.$playlist->id.' because '.$e->getMessage()); @@ -219,7 +218,7 @@ class MigrateOldData extends Command 'duration' => $track->duration, 'view_count' => 0, 'play_count' => 0, - 'download_count' => 0 + 'download_count' => 0, ]); foreach ($trackLogViews as $logItem) { @@ -229,7 +228,7 @@ class MigrateOldData extends Command 'log_type' => ResourceLogItem::VIEW, 'track_id' => $logItem->track_id, 'created_at' => $logItem->created_at, - 'ip_address' => $logItem->ip_address + 'ip_address' => $logItem->ip_address, ]); } catch (\Exception $e) { $this->error('Could insert log item for track '.$track->id.' because '.$e->getMessage()); @@ -243,7 +242,7 @@ class MigrateOldData extends Command 'log_type' => ResourceLogItem::PLAY, 'track_id' => $logItem->track_id, 'created_at' => $logItem->created_at, - 'ip_address' => $logItem->ip_address + 'ip_address' => $logItem->ip_address, ]); } catch (\Exception $e) { $this->error('Could insert log item for track '.$track->id.' because '.$e->getMessage()); @@ -258,7 +257,7 @@ class MigrateOldData extends Command 'track_id' => $logItem->track_id, 'created_at' => $logItem->created_at, 'ip_address' => $logItem->ip_address, - 'track_format_id' => $logItem->track_file_format_id - 1 + 'track_format_id' => $logItem->track_file_format_id - 1, ]); } catch (\Exception $e) { $this->error('Could insert log item for track '.$track->id.' because '.$e->getMessage()); @@ -272,7 +271,7 @@ class MigrateOldData extends Command DB::table('show_song_track')->insert([ 'id' => $song->id, 'show_song_id' => $song->song_id, - 'track_id' => $song->track_id + 'track_id' => $song->track_id, ]); } catch (\Exception $e) { $this->error('Could insert show track item for '.$song->track_id.' because '.$e->getMessage()); @@ -321,7 +320,7 @@ class MigrateOldData extends Command 'playlist_id' => $logItem->playlist_id, 'created_at' => $logItem->created_at, 'ip_address' => $logItem->ip_address, - 'track_format_id' => $logItem->track_file_format_id - 1 + 'track_format_id' => $logItem->track_file_format_id - 1, ]); } catch (\Exception $e) { $this->error('Could insert log item for playlist '.$playlist->id.' because '.$e->getMessage()); @@ -338,7 +337,7 @@ class MigrateOldData extends Command 'updated_at' => $playlistTrack->updated_at, 'position' => $playlistTrack->position, 'playlist_id' => $playlistTrack->playlist_id, - 'track_id' => $playlistTrack->track_id + 'track_id' => $playlistTrack->track_id, ]); } @@ -356,7 +355,7 @@ class MigrateOldData extends Command 'track_id' => $comment->track_id, 'album_id' => $comment->album_id, 'playlist_id' => $comment->playlist_id, - 'profile_id' => $comment->profile_id + 'profile_id' => $comment->profile_id, ]); } catch (Exception $e) { $this->error('Could not sync comment '.$comment->id.' because '.$e->getMessage()); diff --git a/app/Console/Commands/PoniverseApiSetup.php b/app/Console/Commands/PoniverseApiSetup.php index af0f8b38..042057da 100644 --- a/app/Console/Commands/PoniverseApiSetup.php +++ b/app/Console/Commands/PoniverseApiSetup.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,9 +20,9 @@ namespace App\Console\Commands; +use GuzzleHttp\Client; use GuzzleHttp\Exception\ClientException; use Illuminate\Console\Command; -use GuzzleHttp\Client; use Symfony\Component\Console\Formatter\OutputFormatterStyle; class PoniverseApiSetup extends Command @@ -43,7 +43,6 @@ class PoniverseApiSetup extends Command /** * Create a new command instance. - * */ public function __construct() { @@ -74,7 +73,7 @@ class PoniverseApiSetup extends Command $response = $client->post('api-credentials', [ 'headers' => ['accept' => 'application/json'], 'auth' => [$username, $password], - 'query' => ['app' => 'Pony.fm'] + 'query' => ['app' => 'Pony.fm'], ]); } catch (ClientException $e) { if ($e->getResponse()->getStatusCode() === 401) { @@ -97,7 +96,6 @@ class PoniverseApiSetup extends Command $this->info('Client ID and secret set!'); } - protected function setEnvironmentVariable($key, $oldValue, $newValue) { $path = base_path('.env'); diff --git a/app/Console/Commands/RebuildArtists.php b/app/Console/Commands/RebuildArtists.php index 638d6000..2f3f56cf 100644 --- a/app/Console/Commands/RebuildArtists.php +++ b/app/Console/Commands/RebuildArtists.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,8 +20,8 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; use App\Models\User; +use Illuminate\Console\Command; class RebuildArtists extends Command { @@ -41,7 +41,6 @@ class RebuildArtists extends Command /** * Create a new command instance. - * */ public function __construct() { diff --git a/app/Console/Commands/RebuildFilesizes.php b/app/Console/Commands/RebuildFilesizes.php index 8fd75d23..16352bdc 100644 --- a/app/Console/Commands/RebuildFilesizes.php +++ b/app/Console/Commands/RebuildFilesizes.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Kelvin Zhang + * Copyright (C) 2015 Kelvin Zhang. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,9 +20,9 @@ namespace App\Console\Commands; +use App\Models\TrackFile; use File; use Illuminate\Console\Command; -use App\Models\TrackFile; class RebuildFilesizes extends Command { @@ -43,7 +43,6 @@ class RebuildFilesizes extends Command /** * Create a new command instance. - * */ public function __construct() { @@ -65,12 +64,10 @@ class RebuildFilesizes extends Command ) ) { TrackFile::chunk(200, function ($trackFiles) { - $this->info('========== Start Chunk =========='); foreach ($trackFiles as $trackFile) { /** @var TrackFile $trackFile */ - if (File::exists($trackFile->getFile())) { $size = $trackFile->updateFilesize(); $this->info('ID '.$trackFile->id.' processed - '.$size.' bytes'); diff --git a/app/Console/Commands/RebuildImages.php b/app/Console/Commands/RebuildImages.php index 8c257e6a..a6e7ed48 100644 --- a/app/Console/Commands/RebuildImages.php +++ b/app/Console/Commands/RebuildImages.php @@ -1,7 +1,7 @@ info("Regenerating Images"); + $this->info('Regenerating Images'); $progressBar = $this->output->createProgressBar(Image::count()); - Image::chunk(1000, function($images) use ($progressBar) { + Image::chunk(1000, function ($images) use ($progressBar) { foreach ($images as $image) { try { $image->buildCovers(); diff --git a/app/Console/Commands/RebuildSearchIndex.php b/app/Console/Commands/RebuildSearchIndex.php index d1702b0e..5abbf7c1 100644 --- a/app/Console/Commands/RebuildSearchIndex.php +++ b/app/Console/Commands/RebuildSearchIndex.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,12 +20,12 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; -use Illuminate\Database\Eloquent\Collection; use App\Models\Album; use App\Models\Playlist; use App\Models\Track; use App\Models\User; +use Illuminate\Console\Command; +use Illuminate\Database\Eloquent\Collection; class RebuildSearchIndex extends Command { @@ -45,7 +45,6 @@ class RebuildSearchIndex extends Command /** * Create a new command instance. - * */ public function __construct() { @@ -65,7 +64,7 @@ class RebuildSearchIndex extends Command $totalUsers = User::count(); $trackProgress = $this->output->createProgressBar($totalTracks); - $this->info("Processing tracks..."); + $this->info('Processing tracks...'); Track::withTrashed()->chunk(200, function (Collection $tracks) use ($trackProgress) { foreach ($tracks as $track) { /** @var Track $track */ @@ -76,9 +75,8 @@ class RebuildSearchIndex extends Command $trackProgress->finish(); $this->line(''); - $albumProgress = $this->output->createProgressBar($totalAlbums); - $this->info("Processing albums..."); + $this->info('Processing albums...'); Album::withTrashed()->chunk(200, function (Collection $albums) use ($albumProgress) { foreach ($albums as $album) { /** @var Album $album */ @@ -89,9 +87,8 @@ class RebuildSearchIndex extends Command $albumProgress->finish(); $this->line(''); - $playlistProgress = $this->output->createProgressBar($totalPlaylists); - $this->info("Processing playlists..."); + $this->info('Processing playlists...'); Playlist::withTrashed()->chunk(200, function (Collection $playlists) use ($playlistProgress) { foreach ($playlists as $playlist) { /** @var Playlist $playlist */ @@ -102,9 +99,8 @@ class RebuildSearchIndex extends Command $playlistProgress->finish(); $this->line(''); - $userProgress = $this->output->createProgressBar($totalUsers); - $this->info("Processing users..."); + $this->info('Processing users...'); User::chunk(200, function (Collection $users) use ($userProgress) { foreach ($users as $user) { /** @var User $user */ diff --git a/app/Console/Commands/RebuildTags.php b/app/Console/Commands/RebuildTags.php index 54e77352..8355aaab 100644 --- a/app/Console/Commands/RebuildTags.php +++ b/app/Console/Commands/RebuildTags.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -42,7 +42,6 @@ class RebuildTags extends Command /** * Create a new command instance. - * */ public function __construct() { @@ -63,7 +62,7 @@ class RebuildTags extends Command $tracks = Track::whereNotNull('published_at')->withTrashed()->orderBy('id', 'asc')->get(); } - $numberOfTracks = sizeof($tracks); + $numberOfTracks = count($tracks); $this->info("Updating tags for ${numberOfTracks} tracks..."); $bar = $this->output->createProgressBar($numberOfTracks); diff --git a/app/Console/Commands/RebuildTrack.php b/app/Console/Commands/RebuildTrack.php index ea139fba..a9ff88ba 100644 --- a/app/Console/Commands/RebuildTrack.php +++ b/app/Console/Commands/RebuildTrack.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,11 +20,11 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; -use Illuminate\Foundation\Bus\DispatchesJobs; use App\Commands\GenerateTrackFilesCommand; use App\Jobs\EncodeTrackFile; use App\Models\Track; +use Illuminate\Console\Command; +use Illuminate\Foundation\Bus\DispatchesJobs; class RebuildTrack extends Command { @@ -48,7 +48,6 @@ class RebuildTrack extends Command /** * Create a new command instance. - * */ public function __construct() { @@ -78,14 +77,14 @@ class RebuildTrack extends Command // The GenerateTrackFiles command will re-encode all TrackFiles. if ($result->didFail()) { - $this->error("Something went wrong!"); + $this->error('Something went wrong!'); print_r($result->getMessages()); } } else { $this->info("Re-encoding this track's files - there should be a line of output for each format!"); foreach ($track->trackFiles as $trackFile) { - if (!$trackFile->is_master) { + if (! $trackFile->is_master) { $this->info("Re-encoding this track's {$trackFile->format} file..."); $this->dispatch(new EncodeTrackFile($trackFile, true)); } @@ -95,7 +94,7 @@ class RebuildTrack extends Command private function printTrackInfo(Track $track) { - $this->comment("Track info:"); + $this->comment('Track info:'); $this->comment(" Title: {$track->title}"); $this->comment(" Uploaded at: {$track->created_at}"); $this->comment(" Artist: {$track->user->display_name} [User ID: {$track->user_id}]"); diff --git a/app/Console/Commands/RebuildTrackCache.php b/app/Console/Commands/RebuildTrackCache.php index 7fa7db48..af61ca1d 100644 --- a/app/Console/Commands/RebuildTrackCache.php +++ b/app/Console/Commands/RebuildTrackCache.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Kelvin Zhang + * Copyright (C) 2015 Kelvin Zhang. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,16 +20,15 @@ namespace App\Console\Commands; -use File; -use Illuminate\Console\Command; -use Illuminate\Foundation\Bus\DispatchesJobs; use App\Jobs\EncodeTrackFile; use App\Models\Track; use App\Models\TrackFile; +use File; +use Illuminate\Console\Command; +use Illuminate\Foundation\Bus\DispatchesJobs; class RebuildTrackCache extends Command { - use DispatchesJobs; /** @@ -49,7 +48,6 @@ class RebuildTrackCache extends Command /** * Create a new command instance. - * */ public function __construct() { @@ -172,7 +170,6 @@ class RebuildTrackCache extends Command $this->output->newLine(1); }); - $this->info('Format(s) set from cacheable to non-cacheable: '.implode(' ', array_unique($formats))); $this->info($trackFileCount.' cacheable track files set to non-cacheable.'); @@ -209,7 +206,6 @@ class RebuildTrackCache extends Command $this->output->newLine(1); }); - $this->info(sprintf('%d track files deleted out of %d track files. Continuing.', $count, $trackFileCount)); //========================================================================================================== @@ -228,17 +224,17 @@ class RebuildTrackCache extends Command $this->output->newLine(1); $this->info('---------- Start Chunk ----------'); - // Record the track files which do not exist (i.e., have not been encoded yet) + // Record the track files which do not exist (i.e., have not been encoded yet) $emptyTrackFiles = []; foreach ($trackFiles as $trackFile) { - if (!File::exists($trackFile->getFile())) { + if (! File::exists($trackFile->getFile())) { $count++; $emptyTrackFiles[] = $trackFile; } } - // Encode recorded track files + // Encode recorded track files foreach ($emptyTrackFiles as $emptyTrackFile) { $this->info("Started encoding track file ID {$emptyTrackFile->id}"); $this->dispatch(new EncodeTrackFile($emptyTrackFile, false)); @@ -248,7 +244,6 @@ class RebuildTrackCache extends Command $this->output->newLine(1); }); - $this->info($count.' track files encoded.'); $this->output->newLine(1); diff --git a/app/Console/Commands/RefreshCache.php b/app/Console/Commands/RefreshCache.php index 0b6e4611..289b342d 100644 --- a/app/Console/Commands/RefreshCache.php +++ b/app/Console/Commands/RefreshCache.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -42,7 +42,6 @@ class RefreshCache extends Command /** * Create a new command instance. - * */ public function __construct() { @@ -62,17 +61,17 @@ class RefreshCache extends Command DB::table('albums')->update([ 'comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.album_id = albums.id AND deleted_at IS NULL)'), - 'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE album_id = albums.id)') + 'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE album_id = albums.id)'), ]); DB::table('playlists')->update([ 'comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.playlist_id = playlists.id AND deleted_at IS NULL)'), - 'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = playlists.id)') + 'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = playlists.id)'), ]); DB::table('users')->update([ 'comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.profile_id = users.id AND deleted_at IS NULL)'), - 'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = users.id)') + 'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = users.id)'), ]); $users = DB::table('users')->get(); @@ -80,7 +79,7 @@ class RefreshCache extends Command $resources = [ 'album' => [], 'playlist' => [], - 'track' => [] + 'track' => [], ]; foreach ($users as $user) { @@ -206,7 +205,7 @@ class RefreshCache extends Command private function getCacheItem(&$resources, $type, $id) { - if (!isset($resources[$type][$id])) { + if (! isset($resources[$type][$id])) { $item = [ 'view_count' => 0, 'download_count' => 0, @@ -227,7 +226,7 @@ class RefreshCache extends Command private function getUserCacheItem(&$items, $userId, $type, $id) { - if (!isset($items[$userId][$type][$id])) { + if (! isset($items[$userId][$type][$id])) { $item = [ 'is_followed' => false, 'is_favourited' => false, @@ -235,7 +234,7 @@ class RefreshCache extends Command 'view_count' => 0, 'play_count' => 0, 'download_count' => 0, - 'user_id' => $userId + 'user_id' => $userId, ]; $item[$type.'_id'] = $id; diff --git a/app/Console/Commands/SyncPoniverseAccounts.php b/app/Console/Commands/SyncPoniverseAccounts.php index d508f05c..6a28402f 100644 --- a/app/Console/Commands/SyncPoniverseAccounts.php +++ b/app/Console/Commands/SyncPoniverseAccounts.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,10 +20,10 @@ namespace App\Console\Commands; +use App\Models\User; use Illuminate\Console\Command; use League\OAuth2\Client\Token\AccessToken; use Poniverse\Lib\Client; -use App\Models\User; class SyncPoniverseAccounts extends Command { @@ -72,24 +72,24 @@ class SyncPoniverseAccounts extends Command $usersToUpdate ->orderBy('id', 'ASC') - ->chunk(100, function($users) use ($progress) { - /** @var User $user */ - foreach ($users as $user) { - $progress->setMessage("Updating user ID {$user->id}..."); - $progress->advance(); + ->chunk(100, function ($users) use ($progress) { + /** @var User $user */ + foreach ($users as $user) { + $progress->setMessage("Updating user ID {$user->id}..."); + $progress->advance(); - $this->poniverse->poniverse()->meta() + $this->poniverse->poniverse()->meta() ->syncAccount( $user->getAccessToken()->getResourceOwnerId(), - function(AccessToken $accessTokenInfo) use ($user) { + function (AccessToken $accessTokenInfo) use ($user) { $user->setAccessToken($accessTokenInfo); }, - function(string $newEmailAddress) use ($user) { + function (string $newEmailAddress) use ($user) { $user->email = $newEmailAddress; $user->save(); }); - } - }); + } + }); $progress->finish(); $this->line(''); diff --git a/app/Console/Commands/VersionFiles.php b/app/Console/Commands/VersionFiles.php index 1129a0b3..66115e01 100644 --- a/app/Console/Commands/VersionFiles.php +++ b/app/Console/Commands/VersionFiles.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Kelvin Zhang + * Copyright (C) 2016 Kelvin Zhang. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,9 +20,9 @@ namespace App\Console\Commands; +use App\Models\TrackFile; use File; use Illuminate\Console\Command; -use App\Models\TrackFile; class VersionFiles extends Command { @@ -62,23 +62,22 @@ class VersionFiles extends Command if ($this->option('force') || $this->confirm('Are you sure you want to rename all unversioned track files? [y|N]', false)) { TrackFile::chunk(200, function ($trackFiles) { - $this->info('========== Start Chunk =========='); foreach ($trackFiles as $trackFile) { /** @var TrackFile $trackFile */ // Check whether the unversioned file exists - if (!File::exists($trackFile->getUnversionedFile())) { - $this->info('ID ' . $trackFile->id . ' skipped - file not found'); + if (! File::exists($trackFile->getUnversionedFile())) { + $this->info('ID '.$trackFile->id.' skipped - file not found'); continue; } // Version the file and check the outcome if (File::move($trackFile->getUnversionedFile(), $trackFile->getFile())) { - $this->info('ID ' . $trackFile->id . ' processed'); + $this->info('ID '.$trackFile->id.' processed'); } else { - $this->error('ID ' . $trackFile->id . ' was unable to be renamed'); + $this->error('ID '.$trackFile->id.' was unable to be renamed'); } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 7078cd8d..1db69ed7 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Contracts/Commentable.php b/app/Contracts/Commentable.php index a246f72d..3e52c07e 100644 --- a/app/Contracts/Commentable.php +++ b/app/Contracts/Commentable.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -25,8 +25,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany; /** * This interface is used for type safety when referring to entities that * are capable of accepting comments. - * - * @package App\Contracts */ interface Commentable extends GeneratesNotifications { diff --git a/app/Contracts/Favouritable.php b/app/Contracts/Favouritable.php index 31474eb0..8621dade 100644 --- a/app/Contracts/Favouritable.php +++ b/app/Contracts/Favouritable.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -25,8 +25,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany; /** * This interface is used for type safety when referring to entities that * are capable of being favourited. - * - * @package App\Contracts */ interface Favouritable extends GeneratesNotifications { diff --git a/app/Contracts/GeneratesNotifications.php b/app/Contracts/GeneratesNotifications.php index fea214fe..cb3423f7 100644 --- a/app/Contracts/GeneratesNotifications.php +++ b/app/Contracts/GeneratesNotifications.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,14 +20,12 @@ namespace App\Contracts; -use Illuminate\Database\Eloquent\Relations\MorphMany; use App\Models\User; +use Illuminate\Database\Eloquent\Relations\MorphMany; /** * This interface is used for type safety when referring to entities that can be * the "target resource" of a notification (ie. what the notification is about). - * - * @package App\Contracts */ interface GeneratesNotifications { diff --git a/app/Contracts/NotificationHandler.php b/app/Contracts/NotificationHandler.php index 16709358..2424481f 100644 --- a/app/Contracts/NotificationHandler.php +++ b/app/Contracts/NotificationHandler.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -26,12 +26,7 @@ use App\Models\Track; use App\Models\User; /** - * Interface NotificationHandler - * @package App\Contracts - * - * Each method in this interface represents a type of notification. To add a new - * type of notification, add a method for it to this interface and every class - * that implements it. Your IDE should be able to help with this. + * Interface NotificationHandler. */ interface NotificationHandler { diff --git a/app/Contracts/Searchable.php b/app/Contracts/Searchable.php index cb228e32..6a311d8a 100644 --- a/app/Contracts/Searchable.php +++ b/app/Contracts/Searchable.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -36,5 +36,6 @@ interface Searchable public function shouldBeIndexed():bool; public function updateElasticsearchEntry(); + public function updateElasticsearchEntrySynchronously(); } diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 0fc704a7..0cd0077a 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -21,8 +21,8 @@ namespace App\Exceptions; use Exception; -use Illuminate\Auth\AuthenticationException; use GrahamCampbell\Exceptions\ExceptionHandler; +use Illuminate\Auth\AuthenticationException; class Handler extends ExceptionHandler { @@ -45,7 +45,6 @@ class Handler extends ExceptionHandler 'password_confirmation', ]; - /** * Report or log an exception. * diff --git a/app/Exceptions/InvalidEncodeOptionsException.php b/app/Exceptions/InvalidEncodeOptionsException.php index 0e19e38b..be5fe183 100644 --- a/app/Exceptions/InvalidEncodeOptionsException.php +++ b/app/Exceptions/InvalidEncodeOptionsException.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Exceptions/TrackFileNotFoundException.php b/app/Exceptions/TrackFileNotFoundException.php index 2aeb3097..b0d50757 100644 --- a/app/Exceptions/TrackFileNotFoundException.php +++ b/app/Exceptions/TrackFileNotFoundException.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -23,7 +23,7 @@ namespace App\Exceptions; use Illuminate\Database\Eloquent\ModelNotFoundException; /** - * Class TrackFileNotFoundException + * Class TrackFileNotFoundException. * * This exception is used to indicate that the requested `TrackFile` object * does not exist. This is useful when dealing with albums or playlists that diff --git a/app/Facades/Notification.php b/app/Facades/Notification.php index 4fcefc6b..088af22a 100644 --- a/app/Facades/Notification.php +++ b/app/Facades/Notification.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index c39995aa..f2e72556 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 541cb5b8..63a72656 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Http/Controllers/AlbumsController.php b/app/Http/Controllers/AlbumsController.php index 32b1811d..611d8b7b 100644 --- a/app/Http/Controllers/AlbumsController.php +++ b/app/Http/Controllers/AlbumsController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,8 +20,8 @@ namespace App\Http\Controllers; -use App\AlbumDownloader; use App; +use App\AlbumDownloader; use App\Models\Album; use App\Models\ResourceLogItem; use App\Models\Track; @@ -38,7 +38,7 @@ class AlbumsController extends Controller public function getShow($id, $slug) { $album = Album::find($id); - if (!$album) { + if (! $album) { App::abort(404); } @@ -52,7 +52,7 @@ class AlbumsController extends Controller public function getShortlink($id) { $album = Album::find($id); - if (!$album) { + if (! $album) { App::abort(404); } @@ -62,7 +62,7 @@ class AlbumsController extends Controller public function getDownload($id, $extension) { $album = Album::with('tracks', 'tracks.trackFiles', 'user')->find($id); - if (!$album) { + if (! $album) { App::abort(404); } @@ -81,7 +81,7 @@ class AlbumsController extends Controller App::abort(404); } - if (!$album->hasLosslessTracks() && in_array($formatName, Track::$LosslessFormats)) { + if (! $album->hasLosslessTracks() && in_array($formatName, Track::$LosslessFormats)) { App::abort(404); } diff --git a/app/Http/Controllers/Api/Mobile/TracksController.php b/app/Http/Controllers/Api/Mobile/TracksController.php index 5bce6324..26288b2c 100644 --- a/app/Http/Controllers/Api/Mobile/TracksController.php +++ b/app/Http/Controllers/Api/Mobile/TracksController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -41,7 +41,7 @@ class TracksController extends Controller $json = [ 'total_tracks' => $tracks->count(), - 'tracks' => $tracks->toArray() + 'tracks' => $tracks->toArray(), ]; return Response::json($json, 200); @@ -53,7 +53,7 @@ class TracksController extends Controller $json = [ 'total_tracks' => $tracks->count(), - 'tracks' => $tracks->toArray() + 'tracks' => $tracks->toArray(), ]; return Response::json($json, 200); diff --git a/app/Http/Controllers/Api/V1/TracksController.php b/app/Http/Controllers/Api/V1/TracksController.php index f0e75f3a..6021c2df 100644 --- a/app/Http/Controllers/Api/V1/TracksController.php +++ b/app/Http/Controllers/Api/V1/TracksController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015-2017 Feld0 + * Copyright (C) 2015-2017 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -44,16 +44,16 @@ class TracksController extends ApiControllerBase 'status_url' => action('Api\V1\TracksController@getUploadStatus', ['id' => $commandData['id']]), 'track_url' => action('TracksController@getTrack', ['id' => $commandData['id'], 'slug' => $commandData['slug']]), 'message' => $commandData['autoPublish'] - ? "This track has been accepted for processing! Poll the status_url to know when it has been published. It will be published at the track_url." + ? 'This track has been accepted for processing! Poll the status_url to know when it has been published. It will be published at the track_url.' : "This track has been accepted for processing! Poll the status_url to know when it's ready to publish. It will be published at the track_url.", ]; $response->setData($data); $response->setStatusCode(202); + return $response; } - public function getUploadStatus($trackId) { $track = Track::findOrFail($trackId); @@ -67,7 +67,7 @@ class TracksController extends ApiControllerBase ? 'Processing complete! The track is live at the track_url. The artist can edit the track by visiting its edit_url.' : 'Processing complete! The artist must publish the track by visiting its edit_url.', 'edit_url' => action('ContentController@getTracks', ['id' => $trackId]), - 'track_url' => $track->url + 'track_url' => $track->url, ], 201); } else { // something went wrong @@ -83,14 +83,15 @@ class TracksController extends ApiControllerBase * @param int $id track ID * @return \Illuminate\Http\JsonResponse */ - public function getTrackDetails($id) { + public function getTrackDetails($id) + { /** @var Track|null $track */ $track = Track ::with('user', 'album', 'user.avatar', 'cover', 'genre') ->published() ->where('id', $id)->first(); - if (!$track) { + if (! $track) { return Response::json(['message' => 'Track not found.'], 404); } @@ -112,7 +113,7 @@ class TracksController extends ApiControllerBase ->published() ->where('hash', $hash)->first(); - if (!$track) { + if (! $track) { return Response::json(['message' => 'Track not found.'], 403); } @@ -126,7 +127,8 @@ class TracksController extends ApiControllerBase * @param bool $includeComments if true, includes the track's comments in the serialization * @return array serialized track */ - private static function trackToJson(Track $track, bool $includeComments, bool $includeStreamUrl) { + private static function trackToJson(Track $track, bool $includeComments, bool $includeStreamUrl) + { $trackResponse = [ 'id' => $track->id, 'title' => $track->title, @@ -139,41 +141,41 @@ class TracksController extends ApiControllerBase 'avatars' => [ 'thumbnail' => $track->user->getAvatarUrl(Image::THUMBNAIL), 'small' => $track->user->getAvatarUrl(Image::SMALL), - 'normal' => $track->user->getAvatarUrl(Image::NORMAL) - ] + 'normal' => $track->user->getAvatarUrl(Image::NORMAL), + ], ], 'stats' => [ 'views' => $track->view_count, 'plays' => $track->play_count, 'downloads' => $track->download_count, 'comments' => $track->comment_count, - 'favourites' => $track->favourite_count + 'favourites' => $track->favourite_count, ], 'url' => $track->url, - 'is_vocal' => !!$track->is_vocal, - 'is_explicit' => !!$track->is_explicit, - 'is_downloadable' => !!$track->is_downloadable, + 'is_vocal' => (bool) $track->is_vocal, + 'is_explicit' => (bool) $track->is_explicit, + 'is_downloadable' => (bool) $track->is_downloadable, 'published_at' => $track->published_at, 'duration' => $track->duration, 'genre' => $track->genre != null ? [ 'id' => $track->genre->id, - 'name' => $track->genre->name + 'name' => $track->genre->name, ] : null, 'type' => [ 'id' => $track->trackType->id, - 'name' => $track->trackType->title + 'name' => $track->trackType->title, ], 'covers' => [ 'thumbnail' => $track->getCoverUrl(Image::THUMBNAIL), 'small' => $track->getCoverUrl(Image::SMALL), - 'normal' => $track->getCoverUrl(Image::NORMAL) + 'normal' => $track->getCoverUrl(Image::NORMAL), ], // As of 2017-10-28, this should be expected to produce // "direct_upload", "mlpma", "ponify", or "eqbeats" for all tracks. - 'source' => $track->source + 'source' => $track->source, ]; if ($includeComments) { @@ -191,8 +193,8 @@ class TracksController extends ApiControllerBase 'normal' => $comment->user->getAvatarUrl(Image::NORMAL), 'thumbnail' => $comment->user->getAvatarUrl(Image::THUMBNAIL), 'small' => $comment->user->getAvatarUrl(Image::SMALL), - ] - ] + ], + ], ]; } @@ -204,7 +206,7 @@ class TracksController extends ApiControllerBase 'mp3' => [ 'url' => $track->getStreamUrl('MP3', session('api_client_id')), 'mime_type' => Track::$Formats['MP3']['mime_type'], - ] + ], ]; } diff --git a/app/Http/Controllers/Api/Web/AccountController.php b/app/Http/Controllers/Api/Web/AccountController.php index 475d56f1..a6543dd8 100644 --- a/app/Http/Controllers/Api/Web/AccountController.php +++ b/app/Http/Controllers/Api/Web/AccountController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,12 +20,12 @@ namespace App\Http\Controllers\Api\Web; -use App\Http\Controllers\ApiControllerBase; use App\Commands\SaveAccountSettingsCommand; -use App\Models\User; +use App\Http\Controllers\ApiControllerBase; use App\Models\Image; -use Gate; +use App\Models\User; use Auth; +use Gate; use Request; use Response; @@ -36,11 +36,12 @@ class AccountController extends ApiControllerBase $this->authorize('edit', $user); return Response::json([ - 'user' => $user->toArray() + 'user' => $user->toArray(), ]); } - public function getCurrentUser() { + public function getCurrentUser() + { $current_user = Auth::user(); if ($current_user != null) { @@ -58,9 +59,9 @@ class AccountController extends ApiControllerBase 'is_archived' => $user->is_archived, 'avatars' => [ 'small' => $user->getAvatarUrl(Image::SMALL), - 'normal' => $user->getAvatarUrl(Image::NORMAL) + 'normal' => $user->getAvatarUrl(Image::NORMAL), ], - 'created_at' => $user->created_at + 'created_at' => $user->created_at, ], 200); } else { return Response::json(['error' => 'You are not logged in'], 404); @@ -88,7 +89,6 @@ class AccountController extends ApiControllerBase } } - return Response::json([ 'id' => $user->id, 'bio' => $user->bio, @@ -97,10 +97,10 @@ class AccountController extends ApiControllerBase 'slug' => $user->slug, 'username' => $user->username, 'gravatar' => $user->gravatar ? $user->gravatar : $user->email, - 'avatar_url' => !$user->uses_gravatar ? $user->getAvatarUrl() : null, + 'avatar_url' => ! $user->uses_gravatar ? $user->getAvatarUrl() : null, 'uses_gravatar' => $user->uses_gravatar == 1, 'notification_email' => $user->email, - 'notifications' => $user->getNotificationSettings() + 'notifications' => $user->getNotificationSettings(), ], 200); } diff --git a/app/Http/Controllers/Api/Web/AlbumsController.php b/app/Http/Controllers/Api/Web/AlbumsController.php index 58a1a52d..6be5b060 100644 --- a/app/Http/Controllers/Api/Web/AlbumsController.php +++ b/app/Http/Controllers/Api/Web/AlbumsController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,20 +20,20 @@ namespace App\Http\Controllers\Api\Web; -use Illuminate\Database\Eloquent\ModelNotFoundException; -use App\Models\Album; use App\Commands\CreateAlbumCommand; use App\Commands\DeleteAlbumCommand; use App\Commands\EditAlbumCommand; use App\Http\Controllers\ApiControllerBase; +use App\Models\Album; use App\Models\Image; use App\Models\ResourceLogItem; +use App\Models\Track; +use App\Models\User; use Auth; use Gate; +use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Support\Facades\Request; -use App\Models\User; use Response; -use App\Models\Track; class AlbumsController extends ApiControllerBase { @@ -66,12 +66,12 @@ class AlbumsController extends ApiControllerBase 'user', 'user.avatar', 'comments', - 'comments.user' + 'comments.user', ]) ->userDetails() ->find($id); - if (!$album) { + if (! $album) { App::abort(404); } @@ -86,7 +86,7 @@ class AlbumsController extends ApiControllerBase } return Response::json([ - 'album' => $returned_album + 'album' => $returned_album, ], 200); } @@ -100,7 +100,7 @@ class AlbumsController extends ApiControllerBase return $this->notFound('Album not found!'); } - if (!in_array($format, Track::$CacheableFormats)) { + if (! in_array($format, Track::$CacheableFormats)) { return $this->notFound('Format not found!'); } @@ -144,7 +144,7 @@ class AlbumsController extends ApiControllerBase } return Response::json( - ["albums" => $albums, "current_page" => $page, "total_pages" => ceil($count / $perPage)], + ['albums' => $albums, 'current_page' => $page, 'total_pages' => ceil($count / $perPage)], 200 ); } @@ -167,8 +167,8 @@ class AlbumsController extends ApiControllerBase 'created_at' => $album->created_at->format('c'), 'covers' => [ 'small' => $album->getCoverUrl(Image::SMALL), - 'normal' => $album->getCoverUrl(Image::NORMAL) - ] + 'normal' => $album->getCoverUrl(Image::NORMAL), + ], ]; } @@ -178,7 +178,7 @@ class AlbumsController extends ApiControllerBase public function getEdit($id) { $album = Album::with('tracks')->find($id); - if (!$album) { + if (! $album) { return $this->notFound('Album '.$id.' not found!'); } @@ -190,7 +190,7 @@ class AlbumsController extends ApiControllerBase foreach ($album->tracks as $track) { $tracks[] = [ 'id' => $track->id, - 'title' => $track->title + 'title' => $track->title, ]; } @@ -205,7 +205,7 @@ class AlbumsController extends ApiControllerBase 'description' => $album->description, 'cover_url' => $album->hasCover() ? $album->getCoverUrl(Image::NORMAL) : null, 'real_cover_url' => $album->getCoverUrl(Image::NORMAL), - 'tracks' => $tracks + 'tracks' => $tracks, ], 200); } } diff --git a/app/Http/Controllers/Api/Web/AlexaController.php b/app/Http/Controllers/Api/Web/AlexaController.php index 876b1b47..557ff775 100644 --- a/app/Http/Controllers/Api/Web/AlexaController.php +++ b/app/Http/Controllers/Api/Web/AlexaController.php @@ -2,12 +2,12 @@ namespace App\Http\Controllers\Api\Web; -use Illuminate\Http\JsonResponse; -use Illuminate\Http\Request; -use Illuminate\Session\Store; use App\Http\Controllers\Controller; use App\Models\AlexaSession; use App\Models\Track; +use Illuminate\Http\JsonResponse; +use Illuminate\Http\Request; +use Illuminate\Session\Store; use Psr\Log\LoggerInterface; class AlexaController extends Controller @@ -27,7 +27,7 @@ class AlexaController extends Controller if ($sessId) { $this->session = AlexaSession::find($sessId); - if (!$this->session) { + if (! $this->session) { $this->session = new AlexaSession(); $this->session->id = $sessId; } @@ -35,11 +35,11 @@ class AlexaController extends Controller $logger->debug('Incoming Alexa Request', [ 'type' => $type, - 'intent' => $intent + 'intent' => $intent, ]); $logger->debug('Incoming Alexa Full Request', [ - 'json' => json_encode($request->json()->all(), JSON_PRETTY_PRINT) + 'json' => json_encode($request->json()->all(), JSON_PRETTY_PRINT), ]); /** @var JsonResponse $response */ @@ -63,7 +63,7 @@ class AlexaController extends Controller switch ($type) { case 'LaunchRequest': return $this->launch(); - case 'PlayAudio'; + case 'PlayAudio': return $this->play(); case 'AudioPlayer.PlaybackNearlyFinished': return $this->queueNextTrack(); @@ -99,11 +99,11 @@ class AlexaController extends Controller { return [ 'version' => '1.0', - 'sessionAttributes' => (object)[], + 'sessionAttributes' => (object) [], 'response' => [ - "outputSpeech" => [ - "type" => "SSML", - "ssml" => "If you want to play music, say 'Alexa, ask pony fm to play'" + 'outputSpeech' => [ + 'type' => 'SSML', + 'ssml' => "If you want to play music, say 'Alexa, ask pony fm to play'", ], 'shouldEndSession' => true, ], @@ -114,11 +114,11 @@ class AlexaController extends Controller { return [ 'version' => '1.0', - 'sessionAttributes' => (object)[], + 'sessionAttributes' => (object) [], 'response' => [ - "outputSpeech" => [ - "type" => "SSML", - "ssml" => "Sorry, I don't recognise that command." + 'outputSpeech' => [ + 'type' => 'SSML', + 'ssml' => "Sorry, I don't recognise that command.", ], 'shouldEndSession' => true, ], @@ -129,15 +129,15 @@ class AlexaController extends Controller { return [ 'version' => '1.0', - 'sessionAttributes' => (object)[], + 'sessionAttributes' => (object) [], 'response' => [ - "outputSpeech" => [ - "type" => "SSML", - "ssml" => " + 'outputSpeech' => [ + 'type' => 'SSML', + 'ssml' => ' Pony.fm was built by Pixel Wavelength for Viola to keep all her music in one place. - " + ', ], 'shouldEndSession' => true, ], @@ -153,7 +153,7 @@ class AlexaController extends Controller return [ 'version' => '1.0', - 'sessionAttributes' => (object)[], + 'sessionAttributes' => (object) [], 'response' => [ 'directives' => [ [ @@ -197,18 +197,18 @@ class AlexaController extends Controller if (count($playlist) === 0) { return [ 'version' => '1.0', - 'sessionAttributes' => (object)[], + 'sessionAttributes' => (object) [], 'response' => [ - "outputSpeech" => [ - "type" => "SSML", - "ssml" => " + 'outputSpeech' => [ + 'type' => 'SSML', + 'ssml' => " You've reached the end of the popular tracks today. To start from the beginning say 'Alexa, ask pony fm to play' - "], + ", ], 'directives' => [ [ - 'type' => 'AudioPlayer.Stop' + 'type' => 'AudioPlayer.Stop', ], ], 'shouldEndSession' => true, @@ -216,7 +216,7 @@ class AlexaController extends Controller ]; } - $track = $playlist[$position-1]; + $track = $playlist[$position - 1]; $trackHistory[] = $trackId; @@ -231,13 +231,13 @@ class AlexaController extends Controller 'offsetInMilliseconds' => 0, ]; - if (!$replace) { + if (! $replace) { $stream['expectedPreviousToken'] = $trackId; } return [ 'version' => '1.0', - 'sessionAttributes' => (object)[], + 'sessionAttributes' => (object) [], 'response' => [ 'directives' => [ [ @@ -247,7 +247,7 @@ class AlexaController extends Controller 'stream' => $stream, ], ], - ] + ], ], ]; } @@ -259,7 +259,7 @@ class AlexaController extends Controller $trackHistory = $this->session->get('track_history', []); $playlist = $this->session->get('playlist', []); - $track = $playlist[$position-2]; + $track = $playlist[$position - 2]; $trackHistory[] = $trackId; @@ -275,7 +275,7 @@ class AlexaController extends Controller return [ 'version' => '1.0', - 'sessionAttributes' => (object)[], + 'sessionAttributes' => (object) [], 'response' => [ 'directives' => [ [ @@ -285,7 +285,7 @@ class AlexaController extends Controller 'stream' => $stream, ], ], - ] + ], ], ]; } @@ -294,11 +294,11 @@ class AlexaController extends Controller { return [ 'version' => '1.0', - 'sessionAttributes' => (object)[], + 'sessionAttributes' => (object) [], 'response' => [ 'directives' => [ [ - 'type' => 'AudioPlayer.Stop' + 'type' => 'AudioPlayer.Stop', ], ], 'shouldEndSession' => true, diff --git a/app/Http/Controllers/Api/Web/AnnouncementsController.php b/app/Http/Controllers/Api/Web/AnnouncementsController.php index dfca3be5..19ef69a6 100644 --- a/app/Http/Controllers/Api/Web/AnnouncementsController.php +++ b/app/Http/Controllers/Api/Web/AnnouncementsController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Logic + * Copyright (C) 2016 Logic. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,15 +20,17 @@ namespace App\Http\Controllers\Api\Web; -use Carbon\Carbon; use App\Commands\CreateAnnouncementCommand; use App\Http\Controllers\Controller; use App\Models\Announcement; +use Carbon\Carbon; use Request; use Response; -class AnnouncementsController extends Controller { - public function getIndex() { +class AnnouncementsController extends Controller +{ + public function getIndex() + { $currentDate = Carbon::now(); $query = Announcement::whereNotNull('start_time') @@ -40,23 +42,25 @@ class AnnouncementsController extends Controller { $announcement = $query->first(); return Response::json( - ["announcement" => $announcement], + ['announcement' => $announcement], 200 ); } - public function getAdminIndex() { + public function getAdminIndex() + { $this->authorize('access-admin-area'); $announcements = Announcement::orderBy('start_time', 'desc') ->get(); return Response::json([ - 'announcements' => $announcements->toArray() + 'announcements' => $announcements->toArray(), ], 200); } - public function getItemById($genreId) { + public function getItemById($genreId) + { $this->authorize('access-admin-area'); $query = Announcement::where('id', '=', $genreId) @@ -65,13 +69,15 @@ class AnnouncementsController extends Controller { $announcement = $query->first(); return Response::json( - ["announcement" => $announcement], + ['announcement' => $announcement], 200 ); } - public function postCreate() { + public function postCreate() + { $command = new CreateAnnouncementCommand(Request::get('name')); + return $this->execute($command); } } diff --git a/app/Http/Controllers/Api/Web/ArtistsController.php b/app/Http/Controllers/Api/Web/ArtistsController.php index 38f1fd9e..794470ad 100644 --- a/app/Http/Controllers/Api/Web/ArtistsController.php +++ b/app/Http/Controllers/Api/Web/ArtistsController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,28 +20,28 @@ namespace App\Http\Controllers\Api\Web; -use Gate; +use App; use App\Commands\CreateUserCommand; +use App\Http\Controllers\ApiControllerBase; use App\Models\Album; use App\Models\Comment; use App\Models\Favourite; -use App\Http\Controllers\ApiControllerBase; +use App\Models\Follower; use App\Models\Image; use App\Models\Track; use App\Models\User; -use App\Models\Follower; -use App; +use ColorThief\ColorThief; +use Gate; +use Helpers; use Illuminate\Support\Facades\Request; use Response; -use ColorThief\ColorThief; -use Helpers; class ArtistsController extends ApiControllerBase { public function getFavourites($slug) { $user = User::where('slug', $slug)->whereNull('disabled_at')->first(); - if (!$user) { + if (! $user) { App::abort(404); } @@ -62,7 +62,7 @@ class ArtistsController extends ApiControllerBase }, 'album' => function ($query) { $query->userDetails(); - } + }, ])->get(); $tracks = []; @@ -80,14 +80,14 @@ class ArtistsController extends ApiControllerBase return Response::json([ 'tracks' => $tracks, - 'albums' => $albums + 'albums' => $albums, ], 200); } public function getContent($slug) { $user = User::where('slug', $slug)->whereNull('disabled_at')->first(); - if (!$user) { + if (! $user) { App::abort(404); } @@ -133,10 +133,10 @@ class ArtistsController extends ApiControllerBase ->with([ 'comments' => function ($query) { $query->with(['user', 'user.avatar']); - } + }, ]) ->first(); - if (!$user) { + if (! $user) { App::abort(404); } @@ -162,18 +162,18 @@ class ArtistsController extends ApiControllerBase } $userData = [ - 'is_following' => false + 'is_following' => false, ]; if ($user->users->count()) { $userRow = $user->users[0]; $userData = [ - 'is_following' => (bool) $userRow->is_followed + 'is_following' => (bool) $userRow->is_followed, ]; } $palette = ColorThief::getPalette($user->getAvatarUrlLocal(Image::SMALL), 2); - $formatted_palette = array_map("Helpers::rgb2hex", $palette); + $formatted_palette = array_map('Helpers::rgb2hex', $palette); $followers = Follower::where('artist_id', $user->id) ->count(); @@ -186,7 +186,7 @@ class ArtistsController extends ApiControllerBase 'is_archived' => (bool) $user->is_archived, 'avatars' => [ 'small' => $user->getAvatarUrl(Image::SMALL), - 'normal' => $user->getAvatarUrl(Image::NORMAL) + 'normal' => $user->getAvatarUrl(Image::NORMAL), ], 'avatar_colors' => $formatted_palette, 'created_at' => $user->created_at, @@ -199,10 +199,10 @@ class ArtistsController extends ApiControllerBase 'message_url' => $user->message_url, 'user_data' => $userData, 'permissions' => [ - 'edit' => Gate::allows('edit', $user) + 'edit' => Gate::allows('edit', $user), ], - 'isAdmin' => $user->hasRole('admin') - ] + 'isAdmin' => $user->hasRole('admin'), + ], ], 200); } @@ -228,7 +228,7 @@ class ArtistsController extends ApiControllerBase } return Response::json( - ["artists" => $users, "current_page" => $page, "total_pages" => ceil($count / $perPage)], + ['artists' => $users, 'current_page' => $page, 'total_pages' => ceil($count / $perPage)], 200 ); } @@ -236,6 +236,7 @@ class ArtistsController extends ApiControllerBase public function postIndex() { $name = Request::json('username'); + return $this->execute(new CreateUserCommand($name, $name, null, true)); } } diff --git a/app/Http/Controllers/Api/Web/AuthController.php b/app/Http/Controllers/Api/Web/AuthController.php index 25f5c070..fd664582 100644 --- a/app/Http/Controllers/Api/Web/AuthController.php +++ b/app/Http/Controllers/Api/Web/AuthController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Http/Controllers/Api/Web/CommentsController.php b/app/Http/Controllers/Api/Web/CommentsController.php index 857d4be1..0a9297d3 100644 --- a/app/Http/Controllers/Api/Web/CommentsController.php +++ b/app/Http/Controllers/Api/Web/CommentsController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -22,8 +22,8 @@ namespace App\Http\Controllers\Api\Web; use App; use App\Commands\CreateCommentCommand; -use App\Models\Comment; use App\Http\Controllers\ApiControllerBase; +use App\Models\Comment; use Illuminate\Support\Facades\Request; use Response; diff --git a/app/Http/Controllers/Api/Web/DashboardController.php b/app/Http/Controllers/Api/Web/DashboardController.php index 330a2ca6..5096d931 100644 --- a/app/Http/Controllers/Api/Web/DashboardController.php +++ b/app/Http/Controllers/Api/Web/DashboardController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -51,7 +51,7 @@ class DashboardController extends ApiControllerBase return Response::json([ 'recent_tracks' => $recentTracks, - 'popular_tracks' => Track::popular(30, Auth::check() && Auth::user()->can_see_explicit_content) + 'popular_tracks' => Track::popular(30, Auth::check() && Auth::user()->can_see_explicit_content), ], 200); } } diff --git a/app/Http/Controllers/Api/Web/FavouritesController.php b/app/Http/Controllers/Api/Web/FavouritesController.php index b5cb829f..965ba6be 100644 --- a/app/Http/Controllers/Api/Web/FavouritesController.php +++ b/app/Http/Controllers/Api/Web/FavouritesController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,10 +20,10 @@ namespace App\Http\Controllers\Api\Web; -use App\Models\Album; use App\Commands\ToggleFavouriteCommand; -use App\Models\Favourite; use App\Http\Controllers\ApiControllerBase; +use App\Models\Album; +use App\Models\Favourite; use App\Models\Playlist; use App\Models\Track; use Auth; @@ -52,7 +52,7 @@ class FavouritesController extends ApiControllerBase 'track.genre', 'track.cover', 'track.album', - 'track.album.user' + 'track.album.user', ]); $tracks = []; @@ -65,7 +65,7 @@ class FavouritesController extends ApiControllerBase $tracks[] = Track::mapPublicTrackSummary($fav->track); } - return Response::json(["tracks" => $tracks], 200); + return Response::json(['tracks' => $tracks], 200); } public function getAlbums() @@ -79,7 +79,7 @@ class FavouritesController extends ApiControllerBase }, 'album.user', 'album.user.avatar', - 'album.cover' + 'album.cover', ]); $albums = []; @@ -92,7 +92,7 @@ class FavouritesController extends ApiControllerBase $albums[] = Album::mapPublicAlbumSummary($fav->album); } - return Response::json(["albums" => $albums], 200); + return Response::json(['albums' => $albums], 200); } public function getPlaylist() @@ -107,7 +107,7 @@ class FavouritesController extends ApiControllerBase 'playlist.user', 'playlist.user.avatar', 'playlist.tracks', - 'playlist.tracks.cover' + 'playlist.tracks.cover', ]); $playlists = []; @@ -120,6 +120,6 @@ class FavouritesController extends ApiControllerBase $playlists[] = Playlist::mapPublicPlaylistSummary($fav->playlist); } - return Response::json(["playlists" => $playlists], 200); + return Response::json(['playlists' => $playlists], 200); } } diff --git a/app/Http/Controllers/Api/Web/FollowController.php b/app/Http/Controllers/Api/Web/FollowController.php index 1916382c..d89af2d6 100644 --- a/app/Http/Controllers/Api/Web/FollowController.php +++ b/app/Http/Controllers/Api/Web/FollowController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Http/Controllers/Api/Web/GenresController.php b/app/Http/Controllers/Api/Web/GenresController.php index 5fbdb597..754e38df 100644 --- a/app/Http/Controllers/Api/Web/GenresController.php +++ b/app/Http/Controllers/Api/Web/GenresController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,12 +20,12 @@ namespace App\Http\Controllers\Api\Web; -use Illuminate\Support\Facades\Request; use App\Commands\CreateGenreCommand; use App\Commands\DeleteGenreCommand; use App\Commands\RenameGenreCommand; -use App\Models\Genre; use App\Http\Controllers\ApiControllerBase; +use App\Models\Genre; +use Illuminate\Support\Facades\Request; use Response; class GenresController extends ApiControllerBase @@ -41,26 +41,28 @@ class GenresController extends ApiControllerBase ->get(); return Response::json([ - 'genres' => $genres->toArray() + 'genres' => $genres->toArray(), ], 200); } public function postCreate() { $command = new CreateGenreCommand(Request::get('name')); + return $this->execute($command); } public function putRename($genreId) { $command = new RenameGenreCommand($genreId, Request::get('name')); + return $this->execute($command); } - public function deleteGenre($genreId) { $command = new DeleteGenreCommand($genreId, Request::get('destination_genre_id')); + return $this->execute($command); } } diff --git a/app/Http/Controllers/Api/Web/ImagesController.php b/app/Http/Controllers/Api/Web/ImagesController.php index 0aeae788..5cf1fd2c 100644 --- a/app/Http/Controllers/Api/Web/ImagesController.php +++ b/app/Http/Controllers/Api/Web/ImagesController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,10 +20,10 @@ namespace App\Http\Controllers\Api\Web; -use Auth; use App\Http\Controllers\ApiControllerBase; use App\Models\Image; use App\Models\User; +use Auth; use Response; class ImagesController extends ApiControllerBase @@ -42,9 +42,9 @@ class ImagesController extends ApiControllerBase 'small' => $image->getUrl(Image::SMALL), 'normal' => $image->getUrl(Image::NORMAL), 'thumbnail' => $image->getUrl(Image::THUMBNAIL), - 'original' => $image->getUrl(Image::ORIGINAL) + 'original' => $image->getUrl(Image::ORIGINAL), ], - 'filename' => $image->filename + 'filename' => $image->filename, ]; } diff --git a/app/Http/Controllers/Api/Web/NotificationsController.php b/app/Http/Controllers/Api/Web/NotificationsController.php index 669bfdf5..dc310525 100644 --- a/app/Http/Controllers/Api/Web/NotificationsController.php +++ b/app/Http/Controllers/Api/Web/NotificationsController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,13 +20,13 @@ namespace App\Http\Controllers\Api\Web; -use Auth; -use Illuminate\Support\Facades\Request; use App\Http\Controllers\ApiControllerBase; use App\Models\Notification; use App\Models\Subscription; use App\Models\Track; use App\Models\User; +use Auth; +use Illuminate\Support\Facades\Request; use Minishlink\WebPush\WebPush; class NotificationsController extends ApiControllerBase @@ -85,7 +85,7 @@ class NotificationsController extends ApiControllerBase 'user_id' => Auth::user()->id, 'endpoint' => $input->endpoint, 'p256dh' => $input->keys->p256dh, - 'auth' => $input->keys->auth + 'auth' => $input->keys->auth, ]); return ['id' => $subscription->id]; @@ -98,7 +98,7 @@ class NotificationsController extends ApiControllerBase } /** - * Removes a user's notification subscription + * Removes a user's notification subscription. * * @return string */ diff --git a/app/Http/Controllers/Api/Web/PlaylistsController.php b/app/Http/Controllers/Api/Web/PlaylistsController.php index 345a9b36..01c07ce6 100644 --- a/app/Http/Controllers/Api/Web/PlaylistsController.php +++ b/app/Http/Controllers/Api/Web/PlaylistsController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,7 +20,6 @@ namespace App\Http\Controllers\Api\Web; -use Illuminate\Database\Eloquent\ModelNotFoundException; use App\Commands\AddTrackToPlaylistCommand; use App\Commands\CreatePlaylistCommand; use App\Commands\DeletePlaylistCommand; @@ -30,11 +29,12 @@ use App\Http\Controllers\ApiControllerBase; use App\Models\Image; use App\Models\Playlist; use App\Models\ResourceLogItem; -use Auth; -use Illuminate\Support\Facades\Request; -use App\Models\User; -use Response; use App\Models\Track; +use App\Models\User; +use Auth; +use Illuminate\Database\Eloquent\ModelNotFoundException; +use Illuminate\Support\Facades\Request; +use Response; class PlaylistsController extends ApiControllerBase { @@ -95,9 +95,9 @@ class PlaylistsController extends ApiControllerBase } return Response::json([ - "playlists" => $playlists, - "current_page" => $page, - "total_pages" => ceil($count / $perPage) + 'playlists' => $playlists, + 'current_page' => $page, + 'total_pages' => ceil($count / $perPage), ], 200); } @@ -113,9 +113,9 @@ class PlaylistsController extends ApiControllerBase }, 'tracks.trackFiles', 'comments', - 'comments.user' + 'comments.user', ])->userDetails()->find($id); - if (!$playlist || !$playlist->canView(Auth::user())) { + if (! $playlist || ! $playlist->canView(Auth::user())) { App::abort('404'); } @@ -137,11 +137,11 @@ class PlaylistsController extends ApiControllerBase return $this->notFound('Playlist not found!'); } - if ((!$playlist->is_public && !Auth::check()) || (!$playlist->is_public && ($playlist->user_id !== Auth::user()->id))) { + if ((! $playlist->is_public && ! Auth::check()) || (! $playlist->is_public && ($playlist->user_id !== Auth::user()->id))) { return $this->notFound('Playlist not found!'); } - if (!in_array($format, Track::$CacheableFormats)) { + if (! in_array($format, Track::$CacheableFormats)) { return $this->notFound('Format not found!'); } @@ -201,18 +201,17 @@ class PlaylistsController extends ApiControllerBase 'url' => $playlist->url, 'covers' => [ 'small' => $playlist->getCoverUrl(Image::SMALL), - 'normal' => $playlist->getCoverUrl(Image::NORMAL) + 'normal' => $playlist->getCoverUrl(Image::NORMAL), ], 'is_pinned' => $playlist->hasPinFor(Auth::user()->id), 'is_public' => $playlist->is_public == 1, - 'track_ids' => $playlist->tracks->pluck('id') + 'track_ids' => $playlist->tracks->pluck('id'), ]; } return Response::json($playlists, 200); } - /** * This function should not deal with anything other than applying order, * which is done after the query's total possible results are counted due diff --git a/app/Http/Controllers/Api/Web/SearchController.php b/app/Http/Controllers/Api/Web/SearchController.php index f73b5e4b..99ef341b 100644 --- a/app/Http/Controllers/Api/Web/SearchController.php +++ b/app/Http/Controllers/Api/Web/SearchController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,10 +20,10 @@ namespace App\Http\Controllers\Api\Web; -use Elasticsearch; use App\Http\Controllers\ApiControllerBase; -use Illuminate\Support\Facades\Request; use App\Library\Search; +use Elasticsearch; +use Illuminate\Support\Facades\Request; use Response; class SearchController extends ApiControllerBase diff --git a/app/Http/Controllers/Api/Web/ShowSongsController.php b/app/Http/Controllers/Api/Web/ShowSongsController.php index 0d51112a..f7cfd3ee 100644 --- a/app/Http/Controllers/Api/Web/ShowSongsController.php +++ b/app/Http/Controllers/Api/Web/ShowSongsController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Logic + * Copyright (C) 2016 Logic. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,12 +20,12 @@ namespace App\Http\Controllers\Api\Web; -use Illuminate\Support\Facades\Request; use App\Commands\CreateShowSongCommand; use App\Commands\DeleteShowSongCommand; use App\Commands\RenameShowSongCommand; -use App\Models\ShowSong; use App\Http\Controllers\ApiControllerBase; +use App\Models\ShowSong; +use Illuminate\Support\Facades\Request; use Response; class ShowSongsController extends ApiControllerBase @@ -42,26 +42,28 @@ class ShowSongsController extends ApiControllerBase ->get(); return Response::json([ - 'showsongs' => $songs->toArray() + 'showsongs' => $songs->toArray(), ], 200); } public function postCreate() { $command = new CreateShowSongCommand(Request::get('title')); + return $this->execute($command); } public function putRename($songId) { $command = new RenameShowSongCommand($songId, Request::get('title')); + return $this->execute($command); } - public function deleteSong($songId) { $command = new DeleteShowSongCommand($songId, Request::get('destination_song_id')); + return $this->execute($command); } } diff --git a/app/Http/Controllers/Api/Web/StatsController.php b/app/Http/Controllers/Api/Web/StatsController.php index e1c08203..bd248fc8 100644 --- a/app/Http/Controllers/Api/Web/StatsController.php +++ b/app/Http/Controllers/Api/Web/StatsController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Logic + * Copyright (C) 2016 Logic. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,15 +20,15 @@ namespace App\Http\Controllers\Api\Web; -use Illuminate\Database\Eloquent\ModelNotFoundException; use App\Http\Controllers\ApiControllerBase; use App\Models\ResourceLogItem; use App\Models\Track; use Auth; use Cache; -use DB; -use Response; use Carbon\Carbon; +use DB; +use Illuminate\Database\Eloquent\ModelNotFoundException; +use Response; class StatsController extends ApiControllerBase { @@ -88,12 +88,12 @@ class StatsController extends ApiControllerBase if ($hourly) { $set = [ 'hours' => $timeOffet.' '.str_plural('hour', $timeOffet), - 'plays' => $plays + 'plays' => $plays, ]; } else { $set = [ 'days' => $timeOffet.' '.str_plural('day', $timeOffet), - 'plays' => $plays + 'plays' => $plays, ]; } array_push($output, $set); @@ -116,7 +116,7 @@ class StatsController extends ApiControllerBase } // Do we have permission to view this track? - if (!$track->canView(Auth::user())) { + if (! $track->canView(Auth::user())) { return $this->notFound('Track not found!'); } @@ -134,6 +134,7 @@ class StatsController extends ApiControllerBase $statsData = $this->getStatsData($id, $hourly); $output = $this->sortTrackStatsArray($statsData, $hourly); + return $output; }); diff --git a/app/Http/Controllers/Api/Web/TaxonomiesController.php b/app/Http/Controllers/Api/Web/TaxonomiesController.php index 621e8767..b917c8c9 100644 --- a/app/Http/Controllers/Api/Web/TaxonomiesController.php +++ b/app/Http/Controllers/Api/Web/TaxonomiesController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,8 +20,8 @@ namespace App\Http\Controllers\Api\Web; -use App\Models\Genre; use App\Http\Controllers\ApiControllerBase; +use App\Models\Genre; use App\Models\License; use App\Models\ShowSong; use App\Models\TrackType; @@ -48,7 +48,7 @@ class TaxonomiesController extends ApiControllerBase 'id', 'slug', DB::raw('(SELECT COUNT(tracks.id) FROM show_song_track INNER JOIN tracks ON tracks.id = show_song_track.track_id WHERE show_song_track.show_song_id = show_songs.id AND tracks.published_at IS NOT NULL) AS track_count') - )->orderBy('title')->get()->toArray() + )->orderBy('title')->get()->toArray(), ], 200); } } diff --git a/app/Http/Controllers/Api/Web/TracksController.php b/app/Http/Controllers/Api/Web/TracksController.php index e090bdb7..485b72ff 100644 --- a/app/Http/Controllers/Api/Web/TracksController.php +++ b/app/Http/Controllers/Api/Web/TracksController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,10 +20,6 @@ namespace App\Http\Controllers\Api\Web; -use Auth; -use File; -use Illuminate\Database\Eloquent\ModelNotFoundException; -use Illuminate\Support\Facades\Request; use App\Commands\DeleteTrackCommand; use App\Commands\EditTrackCommand; use App\Commands\GenerateTrackFilesCommand; @@ -33,9 +29,13 @@ use App\Jobs\EncodeTrackFile; use App\Models\Genre; use App\Models\ResourceLogItem; use App\Models\Track; -use App\Models\TrackType; use App\Models\TrackFile; +use App\Models\TrackType; use App\Models\User; +use Auth; +use File; +use Illuminate\Database\Eloquent\ModelNotFoundException; +use Illuminate\Support\Facades\Request; use Response; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -78,13 +78,14 @@ class TracksController extends ApiControllerBase session_write_close(); $track = Track::find($trackId); - if (!$track) { + if (! $track) { return $this->notFound('Track not found!'); } $this->authorize('edit', $track); $track->version_upload_status = Track::STATUS_PROCESSING; $track->update(); + return $this->execute(new UploadTrackCommand(true, false, null, false, $track->getNextVersion(), $track)); } @@ -113,8 +114,8 @@ class TracksController extends ApiControllerBase foreach ($trackFiles as $trackFile) { $versions[] = [ 'version' => $trackFile->version, - 'url' => '/tracks/' . $track->id . '/version-change/' . $trackFile->version, - 'created_at' => $trackFile->created_at->timestamp + 'url' => '/tracks/'.$track->id.'/version-change/'.$trackFile->version, + 'created_at' => $trackFile->created_at->timestamp, ]; } @@ -124,26 +125,27 @@ class TracksController extends ApiControllerBase public function getChangeVersion($trackId, $newVersion) { $track = Track::find($trackId); - if (!$track) { + if (! $track) { return $this->notFound('Track not found!'); } $this->authorize('edit', $track); $masterTrackFile = $track->trackFilesForVersion($newVersion)->where('is_master', true)->first(); - if (!$masterTrackFile) { + if (! $masterTrackFile) { return $this->notFound('Version not found!'); } $track->version_upload_status = Track::STATUS_PROCESSING; $track->update(); $sourceFile = new UploadedFile($masterTrackFile->getFile(), $masterTrackFile->getFilename()); + return $this->execute(new GenerateTrackFilesCommand($track, $sourceFile, false, false, true, $newVersion)); } public function getShow($id) { $track = Track::userDetails()->withComments()->find($id); - if (!$track || !$track->canView(Auth::user())) { + if (! $track || ! $track->canView(Auth::user())) { return $this->notFound('Track not found!'); } @@ -169,15 +171,15 @@ class TracksController extends ApiControllerBase return $this->notFound('Track not found!'); } - if (!$track->canView(Auth::user())) { - return $this->notFound('Track not found!'); + if (! $track->canView(Auth::user())) { + return $this->notFound('Track not found!'); } if ($track->is_downloadable == false) { - return $this->notFound('Track not found!'); + return $this->notFound('Track not found!'); } - if (!in_array($format, Track::$CacheableFormats)) { + if (! in_array($format, Track::$CacheableFormats)) { return $this->notFound('Format not found!'); } @@ -239,21 +241,23 @@ class TracksController extends ApiControllerBase } return Response::json([ - "tracks" => $tracks, - "current_page" => $page, - "total_pages" => ceil($totalCount / $perPage) + 'tracks' => $tracks, + 'current_page' => $page, + 'total_pages' => ceil($totalCount / $perPage), ], 200); } public function getAllTracks() { $this->authorize('access-admin-area'); + return $this->getIndex(true); } public function getClassifierQueue() { $this->authorize('access-admin-area'); + return $this->getIndex(true, true); } @@ -272,7 +276,7 @@ class TracksController extends ApiControllerBase public function getEdit($id) { $track = Track::with('showSongs')->find($id); - if (!$track) { + if (! $track) { return $this->notFound('Track '.$id.' not found!'); } @@ -329,7 +333,7 @@ class TracksController extends ApiControllerBase $query->whereIn('genre_id', Request::get('genres')); } - if (Request::has('types') && !$unknown) { + if (Request::has('types') && ! $unknown) { $query->whereIn('track_type_id', Request::get('types')); } @@ -355,8 +359,9 @@ class TracksController extends ApiControllerBase $archives = ['mlpma', 'ponify', 'eqbeats']; $akey = array_search($archive, $archives); - if (!$akey) - $query->join($archive . '_tracks', 'tracks.id', '=', $archive . 'tracks.track_id'); + if (! $akey) { + $query->join($archive.'_tracks', 'tracks.id', '=', $archive.'tracks.track_id'); + } } if (Request::has('songs')) { diff --git a/app/Http/Controllers/ApiControllerBase.php b/app/Http/Controllers/ApiControllerBase.php index 59453b6c..8a97a9d0 100644 --- a/app/Http/Controllers/ApiControllerBase.php +++ b/app/Http/Controllers/ApiControllerBase.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -34,7 +34,7 @@ abstract class ApiControllerBase extends Controller */ protected function execute(CommandBase $command) { - if (!$command->authorize()) { + if (! $command->authorize()) { return $this->notAuthorized(); } @@ -42,7 +42,7 @@ abstract class ApiControllerBase extends Controller if ($result->didFail()) { return Response::json([ 'message' => 'Validation failed', - 'errors' => $result->getMessages() + 'errors' => $result->getMessages(), ], $result->getStatusCode()); } diff --git a/app/Http/Controllers/ArtistsController.php b/app/Http/Controllers/ArtistsController.php index 53e0e8e0..204e5769 100644 --- a/app/Http/Controllers/ArtistsController.php +++ b/app/Http/Controllers/ArtistsController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -22,8 +22,8 @@ namespace App\Http\Controllers; use App; use App\Models\User; -use View; use Redirect; +use View; class ArtistsController extends Controller { @@ -68,7 +68,7 @@ class ArtistsController extends Controller public function getShortlink($id) { $user = User::find($id); - if (!$user || $user->disabled_at !== null) { + if (! $user || $user->disabled_at !== null) { App::abort('404'); } diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index e14d6704..10809a89 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,18 +20,18 @@ namespace App\Http\Controllers; +use App\Models\Activity; +use App\Models\User; +use Auth; use Carbon\Carbon; +use DB; use Illuminate\Support\Facades\Input; use League\OAuth2\Client\Provider\Exception\IdentityProviderException; use League\OAuth2\Client\Token\AccessToken; use Log; use Poniverse\Lib\Client; -use App\Models\Activity; -use App\Models\User; -use Auth; -use DB; -use Request; use Redirect; +use Request; class AuthController extends Controller { @@ -57,6 +57,7 @@ class AuthController extends Controller public function postLogout() { Auth::logout(); + return Redirect::to('/'); } @@ -67,7 +68,7 @@ class AuthController extends Controller try { $accessToken = $oauthProvider->getAccessToken('authorization_code', [ 'code' => Request::query('code'), - 'redirect_uri' => action('AuthController@getOAuth') + 'redirect_uri' => action('AuthController@getOAuth'), ]); $this->poniverse->setAccessToken($accessToken); $resourceOwner = $oauthProvider->getResourceOwner($accessToken); @@ -94,13 +95,14 @@ class AuthController extends Controller 'type' => 'Bearer', ]; - if (!empty($accessToken->getRefreshToken())) { + if (! empty($accessToken->getRefreshToken())) { $setData['refresh_token'] = $accessToken->getRefreshToken(); } if ($token) { //User already exists, update access token and refresh token if provided. DB::table('oauth2_tokens')->where('id', '=', $token->id)->update($setData); + return $this->loginRedirect(User::find($token->user_id)); } @@ -120,7 +122,6 @@ class AuthController extends Controller } } - return $this->loginRedirect($user); } diff --git a/app/Http/Controllers/ContentController.php b/app/Http/Controllers/ContentController.php index be6d996e..eebac012 100644 --- a/app/Http/Controllers/ContentController.php +++ b/app/Http/Controllers/ContentController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index c111edce..e2471f79 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -22,8 +22,8 @@ namespace App\Http\Controllers; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Bus\DispatchesJobs; -use Illuminate\Routing\Controller as BaseController; use Illuminate\Foundation\Validation\ValidatesRequests; +use Illuminate\Routing\Controller as BaseController; class Controller extends BaseController { diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index fa8c0301..b2836df0 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Http/Controllers/ImagesController.php b/app/Http/Controllers/ImagesController.php index 615eacd5..fc93d29b 100644 --- a/app/Http/Controllers/ImagesController.php +++ b/app/Http/Controllers/ImagesController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,9 +20,9 @@ namespace App\Http\Controllers; +use App; use App\Models\Image; use Config; -use App; use Redirect; use Response; @@ -37,14 +37,14 @@ class ImagesController extends Controller } $image = Image::find($id); - if (!$image) { + if (! $image) { App::abort(404); } $response = Response::make('', 200); $filename = $image->getFile($coverType['id']); - if (!is_file($filename)) { + if (! is_file($filename)) { $redirect = url('/images/icons/profile_'.Image::$ImageTypes[$coverType['id']]['name'].'.png'); return Redirect::to($redirect); diff --git a/app/Http/Controllers/NotificationsController.php b/app/Http/Controllers/NotificationsController.php index ce7f18c0..83d1fa8a 100644 --- a/app/Http/Controllers/NotificationsController.php +++ b/app/Http/Controllers/NotificationsController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -21,23 +21,24 @@ namespace App\Http\Controllers; use App; -use Auth; -use DB; use App\Models\Email; use App\Models\EmailSubscription; +use Auth; +use DB; use View; - -class NotificationsController extends Controller { +class NotificationsController extends Controller +{ /** * @param $emailKey * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ - public function getEmailClick($emailKey) { + public function getEmailClick($emailKey) + { /** @var Email $email */ $email = Email::findOrFail($emailKey); - DB::transaction(function() use ($email) { + DB::transaction(function () use ($email) { $email->emailClicks()->create(['ip_address' => \Request::ip()]); $email->notification->is_read = true; $email->notification->save(); @@ -46,7 +47,8 @@ class NotificationsController extends Controller { return redirect($email->getActivity()->url); } - public function getEmailUnsubscribe($subscriptionKey) { + public function getEmailUnsubscribe($subscriptionKey) + { /** @var EmailSubscription $subscription */ $subscription = EmailSubscription::findOrFail($subscriptionKey); $subscription->delete(); @@ -54,17 +56,18 @@ class NotificationsController extends Controller { if (Auth::check() && $subscription->user->id === Auth::user()->id) { return redirect(route('account:settings', [ 'slug' => $subscription->user->slug, - 'unsubscribedMessageKey' => $subscription->activity_type + 'unsubscribedMessageKey' => $subscription->activity_type, ]), 303); } else { return redirect(route('email:confirm-unsubscribed', [ 'unsubscribedUser' => $subscription->user->display_name, - 'unsubscribedMessageKey' => $subscription->activity_type + 'unsubscribedMessageKey' => $subscription->activity_type, ]), 303); } } - public function getEmailUnsubscribePage() { + public function getEmailUnsubscribePage() + { return View::make('shared.null'); } } diff --git a/app/Http/Controllers/PlaylistsController.php b/app/Http/Controllers/PlaylistsController.php index 2dc28565..0d792fd7 100644 --- a/app/Http/Controllers/PlaylistsController.php +++ b/app/Http/Controllers/PlaylistsController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -39,7 +39,7 @@ class PlaylistsController extends Controller public function getPlaylist($id, $slug) { $playlist = Playlist::find($id); - if (!$playlist || !$playlist->canView(Auth::user())) { + if (! $playlist || ! $playlist->canView(Auth::user())) { App::abort(404); } @@ -53,7 +53,7 @@ class PlaylistsController extends Controller public function getShortlink($id) { $playlist = Playlist::find($id); - if (!$playlist || !$playlist->canView(Auth::user())) { + if (! $playlist || ! $playlist->canView(Auth::user())) { App::abort(404); } @@ -63,7 +63,7 @@ class PlaylistsController extends Controller public function getDownload($id, $extension) { $playlist = Playlist::with('tracks', 'tracks.trackFiles', 'user', 'tracks.album')->find($id); - if (!$playlist || !$playlist->canView(Auth::user())) { + if (! $playlist || ! $playlist->canView(Auth::user())) { App::abort(404); } @@ -82,7 +82,7 @@ class PlaylistsController extends Controller App::abort(404); } - if (!$playlist->hasLosslessTracks() && in_array($formatName, Track::$LosslessFormats)) { + if (! $playlist->hasLosslessTracks() && in_array($formatName, Track::$LosslessFormats)) { App::abort(404); } diff --git a/app/Http/Controllers/StatsController.php b/app/Http/Controllers/StatsController.php index 37269615..bb986372 100644 --- a/app/Http/Controllers/StatsController.php +++ b/app/Http/Controllers/StatsController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Logic + * Copyright (C) 2016 Logic. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Http/Controllers/TracksController.php b/app/Http/Controllers/TracksController.php index 048d43da..27fdeb70 100644 --- a/app/Http/Controllers/TracksController.php +++ b/app/Http/Controllers/TracksController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,13 +20,13 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; +use App; use App\Models\ResourceLogItem; use App\Models\Track; use App\Models\TrackFile; use Auth; use Config; -use App; +use Illuminate\Http\Request; use Redirect; use Response; use View; @@ -50,7 +50,7 @@ class TracksController extends Controller 'genre' )->first(); - if (!$track || !$track->canView(Auth::user())) { + if (! $track || ! $track->canView(Auth::user())) { App::abort(404); } @@ -58,9 +58,9 @@ class TracksController extends Controller 'stats' => [ 'views' => 0, 'plays' => 0, - 'downloads' => 0 + 'downloads' => 0, ], - 'is_favourited' => false + 'is_favourited' => false, ]; if ($track->users->count()) { @@ -71,7 +71,7 @@ class TracksController extends Controller 'plays' => $userRow->play_count, 'downloads' => $userRow->download_count, ], - 'is_favourited' => $userRow->is_favourited + 'is_favourited' => $userRow->is_favourited, ]; } @@ -80,7 +80,7 @@ class TracksController extends Controller public function getOembed(Request $request) { - if (!$request->filled('url')) { + if (! $request->filled('url')) { App::abort(404); } @@ -93,7 +93,7 @@ class TracksController extends Controller ->userDetails() ->first(); - if (!$track || !$track->canView(Auth::user())) { + if (! $track || ! $track->canView(Auth::user())) { App::abort(404); } @@ -107,7 +107,7 @@ class TracksController extends Controller 'title' => $track->title, 'author_name' => $track->user->display_name, 'author_url' => $track->user->url, - 'html' => '' + 'html' => '', ]; return Response::json($output); @@ -116,7 +116,7 @@ class TracksController extends Controller public function getTrack($id, $slug) { $track = Track::find($id); - if (!$track || !$track->canView(Auth::user())) { + if (! $track || ! $track->canView(Auth::user())) { App::abort(404); } @@ -135,7 +135,7 @@ class TracksController extends Controller public function getShortlink($id) { $track = Track::find($id); - if (!$track || !$track->canView(Auth::user())) { + if (! $track || ! $track->canView(Auth::user())) { App::abort(404); } @@ -145,7 +145,7 @@ class TracksController extends Controller public function getStream($id, $extension) { $track = Track::find($id); - if (!$track || !$track->canView(Auth::user())) { + if (! $track || ! $track->canView(Auth::user())) { App::abort(404); } @@ -154,7 +154,7 @@ class TracksController extends Controller $response = Response::make('', 200); $filename = $trackFile->getFile(); - if (!file_exists($filename)) { + if (! file_exists($filename)) { App::abort(418); } @@ -182,7 +182,7 @@ class TracksController extends Controller public function getDownload($id, $extension) { $track = Track::find($id); - if (!$track || !$track->canView(Auth::user())) { + if (! $track || ! $track->canView(Auth::user())) { App::abort(404); } diff --git a/app/Http/Controllers/UploaderController.php b/app/Http/Controllers/UploaderController.php index fc184447..1eed0e09 100644 --- a/app/Http/Controllers/UploaderController.php +++ b/app/Http/Controllers/UploaderController.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 564847f3..bdc9d3c8 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -42,7 +42,7 @@ class Kernel extends HttpKernel \Illuminate\Routing\Middleware\SubstituteBindings::class, \App\Http\Middleware\VerifyCsrfToken::class, \App\Http\Middleware\DisabledAccountCheck::class, - ] + ], ]; /** diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index d655273d..1f24849a 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Http/Middleware/AuthenticateOAuth.php b/app/Http/Middleware/AuthenticateOAuth.php index 9a5883f7..75abbfa8 100644 --- a/app/Http/Middleware/AuthenticateOAuth.php +++ b/app/Http/Middleware/AuthenticateOAuth.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,6 +20,7 @@ namespace App\Http\Middleware; +use App\Models\User; use Closure; use Illuminate\Contracts\Auth\Guard; use Illuminate\Http\Request; @@ -27,7 +28,6 @@ use Illuminate\Session\Store; use League\OAuth2\Client\Token\AccessToken; use Poniverse; use Poniverse\Lib\Client; -use App\Models\User; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; class AuthenticateOAuth @@ -71,11 +71,11 @@ class AuthenticateOAuth // check that access token is valid at Poniverse.net $accessTokenInfo = $this->poniverse->poniverse()->meta()->introspect($accessToken); - if (!$accessTokenInfo->getIsActive()) { + if (! $accessTokenInfo->getIsActive()) { throw new AccessDeniedHttpException('This access token is expired or invalid!'); } - if (!in_array($requiredScope, $accessTokenInfo->getScopes())) { + if (! in_array($requiredScope, $accessTokenInfo->getScopes())) { throw new AccessDeniedHttpException("This access token lacks the '${requiredScope}' scope!"); } @@ -92,7 +92,6 @@ class AuthenticateOAuth return $next($request); } - private function determineAccessToken(Request $request, $headerOnly = true) { $header = $request->header('Authorization'); diff --git a/app/Http/Middleware/Authorize.php b/app/Http/Middleware/Authorize.php index 898cb72f..bd899510 100644 --- a/app/Http/Middleware/Authorize.php +++ b/app/Http/Middleware/Authorize.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Http/Middleware/DisabledAccountCheck.php b/app/Http/Middleware/DisabledAccountCheck.php index b4bc8e72..c6703a99 100644 --- a/app/Http/Middleware/DisabledAccountCheck.php +++ b/app/Http/Middleware/DisabledAccountCheck.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -43,8 +43,6 @@ class DisabledAccountCheck $this->auth = $auth; } - - /** * Handle an incoming request. * @@ -59,7 +57,7 @@ class DisabledAccountCheck // something other than merged accounts. if ($this->auth->check() && $this->auth->user()->disabled_at !== null - && !($request->getMethod() === 'POST' && $request->getRequestUri() == '/auth/logout') + && ! ($request->getMethod() === 'POST' && $request->getRequestUri() == '/auth/logout') ) { Log::info("A login was attempted to a disabled account, user ID #{$this->auth->user()->id}."); $this->auth->logout(); diff --git a/app/Http/Middleware/EncryptCookies.php b/app/Http/Middleware/EncryptCookies.php index c4cf3cc1..bfb8fc71 100644 --- a/app/Http/Middleware/EncryptCookies.php +++ b/app/Http/Middleware/EncryptCookies.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Http/Middleware/JsonExceptions.php b/app/Http/Middleware/JsonExceptions.php index f508766f..6c625071 100644 --- a/app/Http/Middleware/JsonExceptions.php +++ b/app/Http/Middleware/JsonExceptions.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -24,11 +24,7 @@ use Closure; use Symfony\Component\HttpKernel\Exception\HttpException; /** - * Class JsonExceptions - * @package App\Http\Middleware - * - * This middleware turns any HTTP exceptions thrown during the request - * into a JSON response. To be used when implementing the API! + * Class JsonExceptions. */ class JsonExceptions { @@ -45,7 +41,7 @@ class JsonExceptions $response = $next($request); } catch (HttpException $e) { return \Response::json([ - 'message' => $e->getMessage() + 'message' => $e->getMessage(), ], $e->getStatusCode()); } diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index 9630047a..76e0d2d2 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -39,6 +39,7 @@ class RedirectIfAuthenticated if (Auth::guard($guard)->check()) { return redirect('/home'); } + return $next($request); } } diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index 8f3c1a90..d89e3f83 100644 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -31,6 +31,6 @@ class VerifyCsrfToken extends Middleware */ protected $except = [ 'api/*', - 'auth/poniverse-sync' + 'auth/poniverse-sync', ]; } diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php index 44e34722..d1d361e2 100644 --- a/app/Http/Requests/Request.php +++ b/app/Http/Requests/Request.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Jobs/DeleteGenre.php b/app/Jobs/DeleteGenre.php index ef030f01..646cda53 100644 --- a/app/Jobs/DeleteGenre.php +++ b/app/Jobs/DeleteGenre.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,12 +20,12 @@ namespace App\Jobs; +use App\Models\Genre; +use App\Models\Track; use Auth; use DB; -use App\Models\Genre; -use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -use App\Models\Track; +use Illuminate\Queue\InteractsWithQueue; use SerializesModels; class DeleteGenre extends Job implements ShouldQueue diff --git a/app/Jobs/DeleteShowSong.php b/app/Jobs/DeleteShowSong.php index 292e390a..35fc68f4 100644 --- a/app/Jobs/DeleteShowSong.php +++ b/app/Jobs/DeleteShowSong.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Logic + * Copyright (C) 2016 Logic. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,12 +20,12 @@ namespace App\Jobs; +use App\Models\ShowSong; +use App\Models\Track; use Auth; use DB; -use App\Models\ShowSong; -use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -use App\Models\Track; +use Illuminate\Queue\InteractsWithQueue; use SerializesModels; class DeleteShowSong extends Job implements ShouldQueue diff --git a/app/Jobs/EncodeTrackFile.php b/app/Jobs/EncodeTrackFile.php index 868b419d..a37eeb34 100644 --- a/app/Jobs/EncodeTrackFile.php +++ b/app/Jobs/EncodeTrackFile.php @@ -3,7 +3,7 @@ /** * Pony.fm - A community for pony fan music. * Copyright (C) 2015 Feld0 - * Copyright (C) 2015 Kelvin Zhang + * Copyright (C) 2015 Kelvin Zhang. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -21,6 +21,9 @@ namespace App\Jobs; +use App\Exceptions\InvalidEncodeOptionsException; +use App\Models\Track; +use App\Models\TrackFile; use Carbon\Carbon; use Config; use DB; @@ -29,9 +32,6 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Log; -use App\Exceptions\InvalidEncodeOptionsException; -use App\Models\Track; -use App\Models\TrackFile; use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\Process; @@ -69,8 +69,8 @@ class EncodeTrackFile extends Job implements ShouldQueue */ public function __construct(TrackFile $trackFile, $isExpirable, $autoPublish = false, $isForUpload = false, $isReplacingTrack = false) { - if ((!$isForUpload && $trackFile->is_master) || - ($isForUpload && $trackFile->is_master && !$trackFile->getFormat()['is_lossless']) + if ((! $isForUpload && $trackFile->is_master) || + ($isForUpload && $trackFile->is_master && ! $trackFile->getFormat()['is_lossless']) ) { throw new InvalidEncodeOptionsException("Master files cannot be encoded unless we're generating a lossless master file during the upload process."); } @@ -94,9 +94,11 @@ class EncodeTrackFile extends Job implements ShouldQueue // Sanity check: was this file just generated, or is it already being processed? if ($this->trackFile->status === TrackFile::STATUS_PROCESSING) { Log::warning('Track file #'.$this->trackFile->id.' (track #'.$this->trackFile->track_id.') is already being processed!'); + return; - } elseif (!$this->trackFile->is_expired && File::exists($this->trackFile->getFile())) { + } elseif (! $this->trackFile->is_expired && File::exists($this->trackFile->getFile())) { Log::warning('Track file #'.$this->trackFile->id.' (track #'.$this->trackFile->track_id.') is still valid! No need to re-encode it.'); + return; } @@ -122,17 +124,17 @@ class EncodeTrackFile extends Job implements ShouldQueue // Prepare the command $format = Track::$Formats[$this->trackFile->format]; $command = $format['command']; - $command = str_replace('{$source}', '"' . $source . '"', $command); - $command = str_replace('{$target}', '"' . $target . '"', $command); + $command = str_replace('{$source}', '"'.$source.'"', $command); + $command = str_replace('{$target}', '"'.$target.'"', $command); - Log::info('Encoding track file ' . $this->trackFile->id . ' into ' . $target); + Log::info('Encoding track file '.$this->trackFile->id.' into '.$target); // Start a synchronous process to encode the file $process = new Process($command); try { $process->mustRun(); } catch (ProcessFailedException $e) { - Log::error('An exception occured in the encoding process for track file ' . $this->trackFile->id . ' - ' . $e->getMessage()); + Log::error('An exception occured in the encoding process for track file '.$this->trackFile->id.' - '.$e->getMessage()); Log::info($process->getOutput()); // Ensure queue fails throw $e; @@ -155,7 +157,7 @@ class EncodeTrackFile extends Job implements ShouldQueue $this->trackFile->save(); if ($this->isForUpload || $this->isReplacingTrack) { - if (!$this->trackFile->is_master && $this->trackFile->is_cacheable) { + if (! $this->trackFile->is_master && $this->trackFile->is_cacheable) { File::delete($this->trackFile->getFile()); } diff --git a/app/Jobs/Job.php b/app/Jobs/Job.php index 337ae522..62378f68 100644 --- a/app/Jobs/Job.php +++ b/app/Jobs/Job.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Jobs/SendNotifications.php b/app/Jobs/SendNotifications.php index 342cb9db..49b76c8c 100644 --- a/app/Jobs/SendNotifications.php +++ b/app/Jobs/SendNotifications.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,14 +20,14 @@ namespace App\Jobs; -use Illuminate\Contracts\Queue\ShouldQueue; -use Illuminate\Queue\InteractsWithQueue; use App\Jobs\Job; use App\Library\Notifications\Drivers\AbstractDriver; use App\Library\Notifications\Drivers\EmailDriver; use App\Library\Notifications\Drivers\NativeDriver; use App\Library\Notifications\Drivers\PonyfmDriver; use App\Models\User; +use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Queue\InteractsWithQueue; use SerializesModels; class SendNotifications extends Job implements ShouldQueue diff --git a/app/Jobs/UpdateSearchIndexForEntity.php b/app/Jobs/UpdateSearchIndexForEntity.php index 0247e65b..d5bc2e82 100644 --- a/app/Jobs/UpdateSearchIndexForEntity.php +++ b/app/Jobs/UpdateSearchIndexForEntity.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,12 +20,12 @@ namespace App\Jobs; +use App\Contracts\Searchable; +use App\Jobs\Job; use DB; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Database\Eloquent\Model; use Illuminate\Queue\InteractsWithQueue; -use App\Contracts\Searchable; -use App\Jobs\Job; use SerializesModels; class UpdateSearchIndexForEntity extends Job implements ShouldQueue diff --git a/app/Jobs/UpdateTagsForRenamedGenre.php b/app/Jobs/UpdateTagsForRenamedGenre.php index 75257910..e9623856 100644 --- a/app/Jobs/UpdateTagsForRenamedGenre.php +++ b/app/Jobs/UpdateTagsForRenamedGenre.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,23 +20,21 @@ namespace App\Jobs; +use App\Models\Genre; +use App\Models\Track; use Auth; use Cache; use DB; -use Log; -use App\Models\Genre; -use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -use App\Models\Track; +use Illuminate\Queue\InteractsWithQueue; +use Log; use SerializesModels; /** - * Class RenameGenre + * Class RenameGenre. * * NOTE: It is assumed that the genre passed into this job has already been renamed! * All this job does is update the tags in that genre's tracks. - * - * @package App\Jobs */ class UpdateTagsForRenamedGenre extends Job implements ShouldQueue { @@ -75,12 +73,12 @@ class UpdateTagsForRenamedGenre extends Job implements ShouldQueue if (Cache::has($this->lockKey)) { Log::info("Tag updates for the \"{$this->genreThatWasRenamed->name}\" genre are currently in progress! Will try again in 30 seconds."); $this->release(30); + return; } else { Cache::forever($this->lockKey, true); } - $this->genreThatWasRenamed->tracks()->chunk(200, function ($tracks) { foreach ($tracks as $track) { /** @var Track $track */ diff --git a/app/Jobs/UpdateTagsForRenamedShowSong.php b/app/Jobs/UpdateTagsForRenamedShowSong.php index e178a401..42e90c36 100644 --- a/app/Jobs/UpdateTagsForRenamedShowSong.php +++ b/app/Jobs/UpdateTagsForRenamedShowSong.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Logic + * Copyright (C) 2016 Logic. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,22 +20,20 @@ namespace App\Jobs; +use App\Models\ShowSong; +use App\Models\Track; use Auth; use Cache; -use Log; -use App\Models\ShowSong; -use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -use App\Models\Track; +use Illuminate\Queue\InteractsWithQueue; +use Log; use SerializesModels; /** - * Class RenameGenre + * Class RenameGenre. * * NOTE: It is assumed that the genre passed into this job has already been renamed! * All this job does is update the tags in that genre's tracks. - * - * @package App\Jobs */ class UpdateTagsForRenamedShowSong extends Job implements ShouldQueue { @@ -74,12 +72,12 @@ class UpdateTagsForRenamedShowSong extends Job implements ShouldQueue if (Cache::has($this->lockKey)) { Log::info("Tag updates for the \"{$this->songThatWasRenamed->title}\" song are currently in progress! Will try again in 30 seconds."); $this->release(30); + return; } else { Cache::forever($this->lockKey, true); } - $this->songThatWasRenamed->tracks()->chunk(200, function ($tracks) { foreach ($tracks as $track) { /** @var Track $track */ diff --git a/app/Library/Assets.php b/app/Library/Assets.php index 5dad4301..180ec39b 100644 --- a/app/Library/Assets.php +++ b/app/Library/Assets.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - class Assets { public static function scriptIncludes(string $area) @@ -36,7 +35,7 @@ class Assets if (Config::get('app.debug') && $filename !== 'templates.js') { $scriptTags .= ""; } else { - $scriptTags .= ""; + $scriptTags .= ""; } } @@ -49,18 +48,18 @@ class Assets public static function styleIncludes($area = 'app') { - if (!Config::get("app.debug")) { - return ''; + .'" />\');'; } $styles = self::mergeGlobs(self::getStylesForArea($area)); - $retVal = ""; + $retVal = ''; foreach ($styles as $style) { - $filename = self::replaceExtensionWith($style, ".less", ".css"); - $retVal .= ""; + $filename = self::replaceExtensionWith($style, '.less', '.css'); + $retVal .= ""; } return $retVal; @@ -71,7 +70,7 @@ class Assets $fromLength = strlen($fromExtension); return substr($filename, -$fromLength) == $fromExtension - ? substr($filename, 0, strlen($filename) - $fromLength) . $toExtension + ? substr($filename, 0, strlen($filename) - $fromLength).$toExtension : $filename; } @@ -82,7 +81,7 @@ class Assets $files = []; $filesFound = []; foreach ($globs as $glob) { - foreach (glob("../resources/assets/" . $glob, GLOB_BRACE) as $file) { + foreach (glob('../resources/assets/'.$glob, GLOB_BRACE) as $file) { if (isset($filesFound[$file])) { continue; } @@ -91,6 +90,7 @@ class Assets $files[] = substr($file, 20); // chop off ../app/ } } + return $files; } @@ -98,14 +98,14 @@ class Assets { if ($area == 'app') { return [ - "styles/base/jquery-ui.css", - "styles/base/colorbox.css", - "styles/app.less", + 'styles/base/jquery-ui.css', + 'styles/base/colorbox.css', + 'styles/app.less', ]; } else { if ($area == 'embed') { return [ - "styles/embed.less" + 'styles/embed.less', ]; } } diff --git a/app/Library/AudioCache.php b/app/Library/AudioCache.php index 96c04801..72c99793 100644 --- a/app/Library/AudioCache.php +++ b/app/Library/AudioCache.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - class AudioCache { private static $_movieCache = []; diff --git a/app/Library/External.php b/app/Library/External.php index 448dec37..f3f94556 100644 --- a/app/Library/External.php +++ b/app/Library/External.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -27,8 +27,8 @@ class External $process = new Process($command); $process->run(); - if (!$process->isSuccessful()) { - Log::error('"' . $command . '" failed with "' . $process->getErrorOutput() . '"'); + if (! $process->isSuccessful()) { + Log::error('"'.$command.'" failed with "'.$process->getErrorOutput().'"'); } } } diff --git a/app/Library/File.php b/app/Library/File.php index a728f390..ff86de63 100644 --- a/app/Library/File.php +++ b/app/Library/File.php @@ -1,7 +1,7 @@ header('Content-Type', $mime); - $response->header('Content-Disposition', 'inline; filename="' . $name . '"'); + $response->header('Content-Disposition', 'inline; filename="'.$name.'"'); $response->header('Content-Transfer-Encoding', 'binary'); $response->header('Expires', 0); $response->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0'); diff --git a/app/Library/Gravatar.php b/app/Library/Gravatar.php index 676d6ce1..1ee5a2ff 100644 --- a/app/Library/Gravatar.php +++ b/app/Library/Gravatar.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - class Gravatar { public static function getUrl($email, $size = 80, $default = null, $rating = 'g') @@ -27,7 +26,7 @@ class Gravatar $url .= "?s=$size&r=$rating"; if ($default != null) { - $url .= "&d=" . $default; + $url .= '&d='.$default; } else { $size = 'normal'; if ($size == 50) { @@ -41,7 +40,7 @@ class Gravatar // Pony.fm's production URL is hardcoded here so Gravatar can // serve functioning default avatars in the dev environment, // which it won't be able to access. - $url .= "&d=" . urlencode(URL::to('https://pony.fm/images/icons/profile_' . $size . '.png')); + $url .= '&d='.urlencode(URL::to('https://pony.fm/images/icons/profile_'.$size.'.png')); } return $url; diff --git a/app/Library/Helpers.php b/app/Library/Helpers.php index ca42257a..c5ef0a56 100644 --- a/app/Library/Helpers.php +++ b/app/Library/Helpers.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - class Helpers { /** @@ -33,12 +32,12 @@ class Helpers public static function template($template) { - echo file_get_contents('templates/' . $template); + echo file_get_contents('templates/'.$template); } public static function angular($expression) { - return '{{' . $expression . '}}'; + return '{{'.$expression.'}}'; } public static function formatBytes($bytes, $precision = 2) @@ -55,7 +54,7 @@ class Helpers $bytes /= pow(1024, $pow); - return round($bytes, $precision) . ' ' . $units[$pow]; + return round($bytes, $precision).' '.$units[$pow]; } /** @@ -73,21 +72,21 @@ class Helpers $title = date('c', strtotime($timestamp)); $content = date('F j, Y \@ g:i:s a', strtotime($timestamp)); - return '' . $content . ''; + return ''.$content.''; } /** - * Converts an RGB array to a hex string + * Converts an RGB array to a hex string. * * @param array[int] $rgb RGB values in an array * @return string */ public static function rgb2hex($rgb) { - $hex = "#"; - $hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT); - $hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT); - $hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT); + $hex = '#'; + $hex .= str_pad(dechex($rgb[0]), 2, '0', STR_PAD_LEFT); + $hex .= str_pad(dechex($rgb[1]), 2, '0', STR_PAD_LEFT); + $hex .= str_pad(dechex($rgb[2]), 2, '0', STR_PAD_LEFT); return $hex; } diff --git a/app/Library/Notifications/Drivers/AbstractDriver.php b/app/Library/Notifications/Drivers/AbstractDriver.php index 60439a1c..32710d28 100644 --- a/app/Library/Notifications/Drivers/AbstractDriver.php +++ b/app/Library/Notifications/Drivers/AbstractDriver.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,10 +20,10 @@ namespace App\Library\Notifications\Drivers; -use ArrayAccess; use App\Contracts\NotificationHandler; use App\Library\Notifications\RecipientFinder; use App\Models\User; +use ArrayAccess; abstract class AbstractDriver implements NotificationHandler { @@ -39,7 +39,7 @@ abstract class AbstractDriver implements NotificationHandler $this->recipientFinder = new RecipientFinder(get_class($this)); break; default: - throw new \Exception("Invalid notification driver!"); + throw new \Exception('Invalid notification driver!'); } } diff --git a/app/Library/Notifications/Drivers/NativeDriver.php b/app/Library/Notifications/Drivers/NativeDriver.php index 51ae0cb8..ba0008ec 100644 --- a/app/Library/Notifications/Drivers/NativeDriver.php +++ b/app/Library/Notifications/Drivers/NativeDriver.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Logic + * Copyright (C) 2016 Logic. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,19 +20,19 @@ namespace App\Library\Notifications\Drivers; -use Config; use App\Contracts\Favouritable; use App\Models\Activity; use App\Models\Comment; use App\Models\Playlist; use App\Models\Track; use App\Models\User; +use Config; use Minishlink\WebPush\WebPush; class NativeDriver extends AbstractDriver { /** - * Method for sending notifications to devices + * Method for sending notifications to devices. * * @param Activity $activity * @param User[] $recipients collection of {@link User} objects @@ -51,7 +51,7 @@ class NativeDriver extends AbstractDriver 'text' => $activity->getTextAttribute(), 'title' => $activity->getTitleFromActivityType(), 'image' => $activity->getThumbnailUrlAttribute(), - 'url' => $activity->url + 'url' => $activity->url, ]; $jsonData = json_encode($data); @@ -70,7 +70,7 @@ class NativeDriver extends AbstractDriver } /** - * @inheritdoc + * {@inheritdoc} */ public function publishedNewTrack(Track $track) { @@ -79,12 +79,11 @@ class NativeDriver extends AbstractDriver ->where('resource_id', $track->id) ->get()[0]; - $this->pushNotifications($activity, $this->getRecipients(__FUNCTION__, func_get_args())); } /** - * @inheritdoc + * {@inheritdoc} */ public function publishedNewPlaylist(Playlist $playlist) { @@ -107,7 +106,7 @@ class NativeDriver extends AbstractDriver } /** - * @inheritdoc + * {@inheritdoc} */ public function newComment(Comment $comment) { @@ -120,7 +119,7 @@ class NativeDriver extends AbstractDriver } /** - * @inheritdoc + * {@inheritdoc} */ public function newFavourite(Favouritable $entityBeingFavourited, User $favouriter) { diff --git a/app/Library/Notifications/Drivers/PonyfmDriver.php b/app/Library/Notifications/Drivers/PonyfmDriver.php index 7b869344..faa9651c 100644 --- a/app/Library/Notifications/Drivers/PonyfmDriver.php +++ b/app/Library/Notifications/Drivers/PonyfmDriver.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,9 +20,6 @@ namespace App\Library\Notifications\Drivers; -use Carbon\Carbon; -use Log; -use Mail; use App\Contracts\Favouritable; use App\Mail\BaseNotification; use App\Models\Activity; @@ -32,6 +29,9 @@ use App\Models\Notification; use App\Models\Playlist; use App\Models\Track; use App\Models\User; +use Carbon\Carbon; +use Log; +use Mail; class PonyfmDriver extends AbstractDriver { @@ -47,7 +47,7 @@ class PonyfmDriver extends AbstractDriver foreach ($recipients as $recipient) { $notifications[] = [ 'activity_id' => $activity->id, - 'user_id' => $recipient->id + 'user_id' => $recipient->id, ]; } Notification::insert($notifications); @@ -59,7 +59,8 @@ class PonyfmDriver extends AbstractDriver * @param Activity $activity * @param User[] $recipients collection of {@link User} objects */ - private function sendEmails(Activity $activity, $recipients) { + private function sendEmails(Activity $activity, $recipients) + { foreach ($recipients as $recipient) { /** @var Notification $notification */ $notification = $activity->notifications->where('user_id', $recipient->id)->first(); @@ -72,7 +73,7 @@ class PonyfmDriver extends AbstractDriver } /** - * @inheritdoc + * {@inheritdoc} */ public function publishedNewTrack(Track $track) { @@ -90,14 +91,14 @@ class PonyfmDriver extends AbstractDriver ]); $recipientsQuery = $this->getRecipients(__FUNCTION__, func_get_args()); - if (NULL !== $recipientsQuery) { + if (null !== $recipientsQuery) { $this->insertNotifications($activity, $recipientsQuery->get()); $this->sendEmails($activity, $recipientsQuery->withEmailSubscriptionFor(Activity::TYPE_PUBLISHED_TRACK)->get()); } } /** - * @inheritdoc + * {@inheritdoc} */ public function publishedNewPlaylist(Playlist $playlist) { @@ -110,14 +111,14 @@ class PonyfmDriver extends AbstractDriver ]); $recipientsQuery = $this->getRecipients(__FUNCTION__, func_get_args()); - if (NULL !== $recipientsQuery) { + if (null !== $recipientsQuery) { $this->insertNotifications($activity, $recipientsQuery->get()); $this->sendEmails($activity, $recipientsQuery->withEmailSubscriptionFor(Activity::TYPE_PUBLISHED_PLAYLIST)->get()); } } /** - * @inheritdoc + * {@inheritdoc} */ public function newFollower(User $userBeingFollowed, User $follower) { @@ -130,14 +131,14 @@ class PonyfmDriver extends AbstractDriver ]); $recipientsQuery = $this->getRecipients(__FUNCTION__, func_get_args()); - if (NULL !== $recipientsQuery) { + if (null !== $recipientsQuery) { $this->insertNotifications($activity, $recipientsQuery->get()); $this->sendEmails($activity, $recipientsQuery->withEmailSubscriptionFor(Activity::TYPE_NEW_FOLLOWER)->get()); } } /** - * @inheritdoc + * {@inheritdoc} */ public function newComment(Comment $comment) { @@ -150,14 +151,14 @@ class PonyfmDriver extends AbstractDriver ]); $recipientsQuery = $this->getRecipients(__FUNCTION__, func_get_args()); - if (NULL !== $recipientsQuery) { + if (null !== $recipientsQuery) { $this->insertNotifications($activity, $recipientsQuery->get()); $this->sendEmails($activity, $recipientsQuery->withEmailSubscriptionFor(Activity::TYPE_NEW_COMMENT)->get()); } } /** - * @inheritdoc + * {@inheritdoc} */ public function newFavourite(Favouritable $entityBeingFavourited, User $favouriter) { @@ -170,7 +171,7 @@ class PonyfmDriver extends AbstractDriver ]); $recipientsQuery = $this->getRecipients(__FUNCTION__, func_get_args()); - if (NULL !== $recipientsQuery) { + if (null !== $recipientsQuery) { $this->insertNotifications($activity, $recipientsQuery->get()); $this->sendEmails($activity, $recipientsQuery->withEmailSubscriptionFor(Activity::TYPE_CONTENT_FAVOURITED)->get()); } diff --git a/app/Library/Notifications/NotificationManager.php b/app/Library/Notifications/NotificationManager.php index 6025ae26..19816485 100644 --- a/app/Library/Notifications/NotificationManager.php +++ b/app/Library/Notifications/NotificationManager.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,7 +20,6 @@ namespace App\Library\Notifications; -use Illuminate\Foundation\Bus\DispatchesJobs; use App\Contracts\Favouritable; use App\Contracts\NotificationHandler; use App\Jobs\SendNotifications; @@ -28,15 +27,10 @@ use App\Models\Comment; use App\Models\Playlist; use App\Models\Track; use App\Models\User; +use Illuminate\Foundation\Bus\DispatchesJobs; /** - * Class NotificationManager - * @package App\Library - * - * This class exists mostly to maintain type safety when sending notifications - * from around the Pony.fm codebase. There should be virtually zero logic here. - * All the heavy lifting happens asynchronously in the {@link SendNotifications} - * job and the notification drivers. + * Class NotificationManager. */ class NotificationManager implements NotificationHandler { @@ -48,7 +42,7 @@ class NotificationManager implements NotificationHandler } /** - * @inheritdoc + * {@inheritdoc} */ public function publishedNewTrack(Track $track) { @@ -56,7 +50,7 @@ class NotificationManager implements NotificationHandler } /** - * @inheritdoc + * {@inheritdoc} */ public function publishedNewPlaylist(Playlist $playlist) { @@ -64,7 +58,7 @@ class NotificationManager implements NotificationHandler } /** - * @inheritdoc + * {@inheritdoc} */ public function newFollower(User $userBeingFollowed, User $follower) { @@ -72,7 +66,7 @@ class NotificationManager implements NotificationHandler } /** - * @inheritdoc + * {@inheritdoc} */ public function newComment(Comment $comment) { @@ -80,7 +74,7 @@ class NotificationManager implements NotificationHandler } /** - * @inheritdoc + * {@inheritdoc} */ public function newFavourite(Favouritable $entityBeingFavourited, User $favouriter) { diff --git a/app/Library/Notifications/RecipientFinder.php b/app/Library/Notifications/RecipientFinder.php index aa8b8cec..a93e3ef6 100644 --- a/app/Library/Notifications/RecipientFinder.php +++ b/app/Library/Notifications/RecipientFinder.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,8 +20,6 @@ namespace App\Library\Notifications; -use Illuminate\Database\Eloquent\Builder; -use Illuminate\Foundation\Bus\DispatchesJobs; use App\Contracts\Favouritable; use App\Contracts\NotificationHandler; use App\Jobs\SendNotifications; @@ -33,14 +31,11 @@ use App\Models\Playlist; use App\Models\Subscription; use App\Models\Track; use App\Models\User; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Foundation\Bus\DispatchesJobs; /** - * Class RecipientFinder - * @package App\Library\Notifications - * - * This class returns a list of users who are to receive a particular notification. - * It is instantiated on a per-driver basis. Its methods return Eloquent query - * objects for the PonyfmDriver. + * Class RecipientFinder. */ class RecipientFinder implements NotificationHandler { @@ -48,7 +43,7 @@ class RecipientFinder implements NotificationHandler * @var string class name of a notification driver */ private $notificationDriver; - + public function __construct(string $notificationDriver) { $this->notificationDriver = $notificationDriver; @@ -60,7 +55,7 @@ class RecipientFinder implements NotificationHandler } /** - * @inheritdoc + * {@inheritdoc} */ public function publishedNewTrack(Track $track) { @@ -82,6 +77,7 @@ class RecipientFinder implements NotificationHandler } $targetIds = array_intersect($followerIds, $subIds); + return Subscription::whereIn('user_id', $targetIds)->get(); default: return $this->fail(); @@ -89,7 +85,7 @@ class RecipientFinder implements NotificationHandler } /** - * @inheritdoc + * {@inheritdoc} */ public function publishedNewPlaylist(Playlist $playlist) { @@ -111,6 +107,7 @@ class RecipientFinder implements NotificationHandler } $targetIds = array_intersect($followerIds, $subIds); + return Subscription::whereIn('user_id', $targetIds)->get(); default: return $this->fail(); @@ -118,7 +115,7 @@ class RecipientFinder implements NotificationHandler } /** - * @inheritdoc + * {@inheritdoc} */ public function newFollower(User $userBeingFollowed, User $follower) { @@ -134,7 +131,7 @@ class RecipientFinder implements NotificationHandler } /** - * @inheritdoc + * {@inheritdoc} */ public function newComment(Comment $comment) { @@ -142,7 +139,7 @@ class RecipientFinder implements NotificationHandler case PonyfmDriver::class: return $comment->user->id === $comment->resource->user->id - ? NULL + ? null : $this->queryForUser($comment->resource->user); case NativeDriver::class: return Subscription::where('user_id', '=', $comment->resource->user->id)->get(); @@ -152,7 +149,7 @@ class RecipientFinder implements NotificationHandler } /** - * @inheritdoc + * {@inheritdoc} */ public function newFavourite(Favouritable $entityBeingFavourited, User $favouriter) { @@ -160,7 +157,7 @@ class RecipientFinder implements NotificationHandler case PonyfmDriver::class: return $favouriter->id === $entityBeingFavourited->user->id - ? NULL + ? null : $this->queryForUser($entityBeingFavourited->user); case NativeDriver::class: return Subscription::where('user_id', '=', $entityBeingFavourited->user->id)->get(); @@ -176,7 +173,8 @@ class RecipientFinder implements NotificationHandler * @param User $user * @return \Eloquent|Builder */ - private function queryForUser(User $user):Builder { + private function queryForUser(User $user):Builder + { return User::where('id', '=', $user->id); } } diff --git a/app/Library/PfmValidator.php b/app/Library/PfmValidator.php index 5974a896..0041e41c 100644 --- a/app/Library/PfmValidator.php +++ b/app/Library/PfmValidator.php @@ -1,9 +1,10 @@ . */ - class PfmValidator extends Illuminate\Validation\Validator { private static $reservedNames = [ @@ -169,7 +169,6 @@ class PfmValidator extends Illuminate\Validation\Validator return in_array($file->getAudioCodec(), $parameters); } - /** * Validate the sample rate of the audio file. * @@ -188,7 +187,6 @@ class PfmValidator extends Illuminate\Validation\Validator return in_array($file->getAudioSampleRate(), $parameters); } - /** * Validate the number of channels in the audio file. * @@ -207,7 +205,6 @@ class PfmValidator extends Illuminate\Validation\Validator return in_array($file->getAudioChannels(), $parameters); } - /** * Validate the bit rate of the audio file. * @@ -226,7 +223,6 @@ class PfmValidator extends Illuminate\Validation\Validator return in_array($file->getAudioBitRate(), $parameters); } - /** * Validate the duration of the audio file, in seconds. * @@ -242,10 +238,9 @@ class PfmValidator extends Illuminate\Validation\Validator // parameters is an array containing one value: the minimum duration $file = AudioCache::get($value->getPathname()); - return $file->getDuration() >= (float)$parameters[0]; + return $file->getDuration() >= (float) $parameters[0]; } - /** * Require a field when the value of another field matches a certain value. * @@ -258,7 +253,7 @@ class PfmValidator extends Illuminate\Validation\Validator * public function validate_required_when($attribute, $value, $parameters) * { * if ( Request::get($parameters[0]) === $parameters[1] && static::required($attribute, $value) ){ - * return true; + * return true;. * * } else { * return false; @@ -276,7 +271,6 @@ class PfmValidator extends Illuminate\Validation\Validator return true; } - // custom image width validator public function validateMinWidth($attribute, $value, $parameters) { @@ -305,8 +299,8 @@ class PfmValidator extends Illuminate\Validation\Validator */ public function validateIsNotReservedSlug($attribute, $value, $parameters) { - return !array_key_exists($value, static::$reservedNames) && + return ! array_key_exists($value, static::$reservedNames) && // Pony.fm shortlinks are in the form: /{letter}{series of numbers} - !preg_match('/^[a-z]?\d+$/', $value); + ! preg_match('/^[a-z]?\d+$/', $value); } } diff --git a/app/Library/Search.php b/app/Library/Search.php index 2dc65fbe..bb146367 100644 --- a/app/Library/Search.php +++ b/app/Library/Search.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,14 +20,14 @@ namespace App\Library; -use DB; -use Elasticsearch\Client; -use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\Collection; use App\Models\Album; use App\Models\Playlist; use App\Models\Track; use App\Models\User; +use DB; +use Elasticsearch\Client; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; class Search { @@ -66,7 +66,7 @@ class Search 'tie_breaker' => 0.3, ], ], - 'size' => 13 + 'size' => 13, ], //===== Albums =====// @@ -83,7 +83,7 @@ class Search 'tie_breaker' => 0.3, ], ], - 'size' => 3 + 'size' => 3, ], //===== Playlists =====// @@ -100,7 +100,7 @@ class Search 'tie_breaker' => 0.3, ], ], - 'size' => 3 + 'size' => 3, ], //===== Users =====// @@ -116,9 +116,9 @@ class Search 'tie_breaker' => 0.3, ], ], - 'size' => 3 + 'size' => 3, ], - ] + ], ]); $tracks = $this->transformTracks($results['responses'][0]['hits']['hits']); @@ -130,7 +130,7 @@ class Search 'tracks' => $tracks, 'albums' => $albums, 'playlists' => $playlists, - 'users' => $users + 'users' => $users, ]; } @@ -140,6 +140,7 @@ class Search $tracks = $tracks->map(function (Track $track) { return Track::mapPublicTrackSummary($track); }); + return $tracks; } @@ -149,6 +150,7 @@ class Search $albums = $albums->map(function (Album $album) { return Album::mapPublicAlbumSummary($album); }); + return $albums; } @@ -158,6 +160,7 @@ class Search $playlists = $playlists->map(function (Playlist $playlist) { return Playlist::mapPublicPlaylistSummary($playlist); }); + return $playlists; } @@ -167,6 +170,7 @@ class Search $users = $users->map(function (User $user) { return User::mapPublicUserSummary($user); }); + return $users; } diff --git a/app/Library/SerializesModels.php b/app/Library/SerializesModels.php index 71272f1f..8bee1ea6 100644 --- a/app/Library/SerializesModels.php +++ b/app/Library/SerializesModels.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Library/ZipStream.php b/app/Library/ZipStream.php index 9696cdbc..f820d3e8 100644 --- a/app/Library/ZipStream.php +++ b/app/Library/ZipStream.php @@ -52,37 +52,37 @@ class ZipStream /** * Constructor. * - * @param String $archiveName Name to send to the HTTP client. - * @param String $contentType Content mime type. Optional, defaults to "application/zip". + * @param string $archiveName Name to send to the HTTP client. + * @param string $contentType Content mime type. Optional, defaults to "application/zip". */ - function __construct($archiveName = "", $contentType = "application/zip") + public function __construct($archiveName = '', $contentType = 'application/zip') { - if (!function_exists('sys_get_temp_dir')) { - die("ERROR: ZipStream " . self::VERSION . " requires PHP version 5.2.1 or above."); + if (! function_exists('sys_get_temp_dir')) { + die('ERROR: ZipStream '.self::VERSION.' requires PHP version 5.2.1 or above.'); } $headerFile = null; $headerLine = null; - if (!headers_sent($headerFile, $headerLine) or die("

Error: Unable to send file $archiveName. HTML Headers have already been sent from $headerFile in line $headerLine

")) { - if ((ob_get_contents() === false || ob_get_contents() == '') or die("\n

Error: Unable to send file $archiveName.epub. Output buffer contains the following text (typically warnings or errors):
" . ob_get_contents() . "

")) { + if (! headers_sent($headerFile, $headerLine) or die("

Error: Unable to send file $archiveName. HTML Headers have already been sent from $headerFile in line $headerLine

")) { + if ((ob_get_contents() === false || ob_get_contents() == '') or die("\n

Error: Unable to send file $archiveName.epub. Output buffer contains the following text (typically warnings or errors):
".ob_get_contents().'

')) { if (ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } header('Pragma: public'); - header("Last-Modified: " . gmdate("D, d M Y H:i:s T")); - header("Expires: 0"); - header("Accept-Ranges: bytes"); + header('Last-Modified: '.gmdate('D, d M Y H:i:s T')); + header('Expires: 0'); + header('Accept-Ranges: bytes'); //header("Connection: Keep-Alive"); - header("Content-Type: " . $contentType); - header('Content-Disposition: attachment; filename="' . $archiveName . '";'); - header("Content-Transfer-Encoding: binary"); + header('Content-Type: '.$contentType); + header('Content-Disposition: attachment; filename="'.$archiveName.'";'); + header('Content-Transfer-Encoding: binary'); flush(); } } } - function __destruct() + public function __destruct() { $this->isFinalized = true; $this->cdRec = null; @@ -95,7 +95,7 @@ class ZipStream * * @param bool $setExtraField TRUE (default) will enable adding of extra fields, anything else will disable it. */ - function setExtraField($setExtraField = true) + public function setExtraField($setExtraField = true) { $this->addExtraField = ($setExtraField === true); } @@ -131,13 +131,15 @@ class ZipStream return false; } - $directoryPath = str_replace("\\", "/", $directoryPath); - $directoryPath = rtrim($directoryPath, "/"); + $directoryPath = str_replace('\\', '/', $directoryPath); + $directoryPath = rtrim($directoryPath, '/'); if (strlen($directoryPath) > 0) { $this->buildZipEntry($directoryPath.'/', $fileComment, "\x00\x00", "\x00\x00", $timestamp, "\x00\x00\x00\x00", 0, 0, self::EXT_FILE_ATTR_DIR); + return true; } + return false; } @@ -156,15 +158,16 @@ class ZipStream return false; } - if (is_resource($data) && get_resource_type($data) == "stream") { + if (is_resource($data) && get_resource_type($data) == 'stream') { $this->addLargeFile($data, $filePath, $timestamp, $fileComment); + return false; } $gzType = "\x08\x00"; // Compression type 8 = deflate $gpFlags = "\x00\x00"; // General Purpose bit flags for compression type 8 it is: 0=Normal, 1=Maximum, 2=Fast, 3=super fast compression. $dataLength = strlen($data); - $fileCRC32 = pack("V", crc32($data)); + $fileCRC32 = pack('V', crc32($data)); $gzData = gzcompress($data); $gzData = substr(substr($gzData, 0, strlen($gzData) - 4), 2); // gzcompress adds a 2 byte header and 4 byte CRC we can't use. @@ -180,7 +183,7 @@ class ZipStream $this->buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, self::EXT_FILE_ATTR_FILE); - print ($gzData); + echo $gzData; return true; } @@ -191,8 +194,8 @@ class ZipStream * @author Adam Schmalhofer * @author A. Grandt * - * @param String $realPath Path on the file system. - * @param String $zipPath Filepath and name to be used in the archive. + * @param string $realPath Path on the file system. + * @param string $zipPath Filepath and name to be used in the archive. * @param bool $recursive Add content recursively, default is TRUE. * @param bool $followSymlinks Follow and add symbolic links, if they are accessible, default is TRUE. * @param array &$addedFiles Reference to the added files, this is used to prevent duplicates, efault is an empty array. @@ -201,7 +204,7 @@ class ZipStream */ public function addDirectoryContent($realPath, $zipPath, $recursive = true, $followSymlinks = true, &$addedFiles = []) { - if (file_exists($realPath) && !isset($addedFiles[realpath($realPath)])) { + if (file_exists($realPath) && ! isset($addedFiles[realpath($realPath)])) { if (is_dir($realPath)) { $this->addDirectory($zipPath); } @@ -216,11 +219,11 @@ class ZipStream $newRealPath = $file->getPathname(); $newZipPath = self::pathJoin($zipPath, $file->getFilename()); - if (file_exists($newRealPath) && ($followSymlinks === true || !is_link($newRealPath))) { + if (file_exists($newRealPath) && ($followSymlinks === true || ! is_link($newRealPath))) { if ($file->isFile()) { $addedFiles[realpath($newRealPath)] = $newZipPath; $this->addLargeFile($newRealPath, $newZipPath); - } else if ($recursive === true) { + } elseif ($recursive === true) { $this->addDirectoryContent($newRealPath, $newZipPath, $recursive); } else { $this->addDirectory($zipPath); @@ -247,15 +250,16 @@ class ZipStream if (is_string($dataFile) && is_file($dataFile)) { $this->processFile($dataFile, $filePath, $timestamp, $fileComment); - } else if (is_resource($dataFile) && get_resource_type($dataFile) == "stream") { + } elseif (is_resource($dataFile) && get_resource_type($dataFile) == 'stream') { $fh = $dataFile; $this->openStream($filePath, $timestamp, $fileComment); - while (!feof($fh)) { + while (! feof($fh)) { $this->addStreamData(fread($fh, $this->streamChunkSize)); } $this->closeStream($this->addExtraField); } + return true; } @@ -269,8 +273,8 @@ class ZipStream */ public function openStream($filePath, $timestamp = 0, $fileComment = null) { - if (!function_exists('sys_get_temp_dir')) { - die("ERROR: Zip " . self::VERSION . " requires PHP version 5.2.1 or above if large files are used."); + if (! function_exists('sys_get_temp_dir')) { + die('ERROR: Zip '.self::VERSION.' requires PHP version 5.2.1 or above if large files are used.'); } if ($this->isFinalized) { @@ -282,7 +286,7 @@ class ZipStream } $this->streamFile = tempnam(sys_get_temp_dir(), 'ZipStream'); - $this->streamData = fopen($this->streamFile, "wb"); + $this->streamData = fopen($this->streamFile, 'wb'); $this->streamFilePath = $filePath; $this->streamTimestamp = $timestamp; $this->streamFileComment = $fileComment; @@ -294,7 +298,7 @@ class ZipStream /** * Add data to the open stream. * - * @param String $data + * @param string $data * @return $length bytes added or FALSE if the archive is finalized or there are no open stream. */ public function addStreamData($data) @@ -356,9 +360,9 @@ class ZipStream $zip->close(); } - $file_handle = fopen($tempzip, "rb"); + $file_handle = fopen($tempzip, 'rb'); $stats = fstat($file_handle); - $eof = $stats['size']-72; + $eof = $stats['size'] - 72; fseek($file_handle, 6); @@ -366,9 +370,9 @@ class ZipStream $gzType = fread($file_handle, 2); fread($file_handle, 4); $fileCRC32 = fread($file_handle, 4); - $v = unpack("Vval", fread($file_handle, 4)); + $v = unpack('Vval', fread($file_handle, 4)); $gzLength = $v['val']; - $v = unpack("Vval", fread($file_handle, 4)); + $v = unpack('Vval', fread($file_handle, 4)); $dataLength = $v['val']; $this->buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, self::EXT_FILE_ATTR_FILE); @@ -376,10 +380,10 @@ class ZipStream fseek($file_handle, 34); $pos = 34; - while (!feof($file_handle) && $pos < $eof) { + while (! feof($file_handle) && $pos < $eof) { $datalen = $this->streamChunkSize; if ($pos + $this->streamChunkSize > $eof) { - $datalen = $eof-$pos; + $datalen = $eof - $pos; } echo fread($file_handle, $datalen); $pos += $datalen; @@ -397,23 +401,23 @@ class ZipStream */ public function finalize() { - if (!$this->isFinalized) { + if (! $this->isFinalized) { if (strlen($this->streamFilePath) > 0) { $this->closeStream(); } - $cdRecSize = pack("v", sizeof($this->cdRec)); + $cdRecSize = pack('v', count($this->cdRec)); - $cd = implode("", $this->cdRec); - print($cd); - print(self::ZIP_END_OF_CENTRAL_DIRECTORY); - print($cdRecSize.$cdRecSize); - print(pack("VV", strlen($cd), $this->offset)); - if (!empty($this->zipComment)) { - print(pack("v", strlen($this->zipComment))); - print($this->zipComment); + $cd = implode('', $this->cdRec); + echo $cd; + echo self::ZIP_END_OF_CENTRAL_DIRECTORY; + echo $cdRecSize.$cdRecSize; + echo pack('VV', strlen($cd), $this->offset); + if (! empty($this->zipComment)) { + echo pack('v', strlen($this->zipComment)); + echo $this->zipComment; } else { - print("\x00\x00"); + echo "\x00\x00"; } flush(); @@ -424,6 +428,7 @@ class ZipStream return true; } + return false; } @@ -435,90 +440,91 @@ class ZipStream */ private function getDosTime($timestamp = 0) { - $timestamp = (int)$timestamp; + $timestamp = (int) $timestamp; $oldTZ = @date_default_timezone_get(); date_default_timezone_set('UTC'); $date = ($timestamp == 0 ? getdate() : getdate($timestamp)); date_default_timezone_set($oldTZ); - if ($date["year"] >= 1980) { - return pack("V", (($date["mday"] + ($date["mon"] << 5) + (($date["year"]-1980) << 9)) << 16) | - (($date["seconds"] >> 1) + ($date["minutes"] << 5) + ($date["hours"] << 11))); + if ($date['year'] >= 1980) { + return pack('V', (($date['mday'] + ($date['mon'] << 5) + (($date['year'] - 1980) << 9)) << 16) | + (($date['seconds'] >> 1) + ($date['minutes'] << 5) + ($date['hours'] << 11))); } + return "\x00\x00\x00\x00"; } /** - * Build the Zip file structures + * Build the Zip file structures. * - * @param String $filePath - * @param String $fileComment - * @param String $gpFlags - * @param String $gzType + * @param string $filePath + * @param string $fileComment + * @param string $gpFlags + * @param string $gzType * @param int $timestamp * @param string $fileCRC32 * @param int $gzLength * @param int $dataLength - * @param integer $extFileAttr Use self::EXT_FILE_ATTR_FILE for files, self::EXT_FILE_ATTR_DIR for Directories. + * @param int $extFileAttr Use self::EXT_FILE_ATTR_FILE for files, self::EXT_FILE_ATTR_DIR for Directories. */ private function buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, $extFileAttr) { - $filePath = str_replace("\\", "/", $filePath); + $filePath = str_replace('\\', '/', $filePath); $fileCommentLength = (empty($fileComment) ? 0 : strlen($fileComment)); - $timestamp = (int)$timestamp; + $timestamp = (int) $timestamp; $timestamp = ($timestamp == 0 ? time() : $timestamp); $dosTime = $this->getDosTime($timestamp); - $tsPack = pack("V", $timestamp); + $tsPack = pack('V', $timestamp); $ux = "\x75\x78\x0B\x00\x01\x04\xE8\x03\x00\x00\x04\x00\x00\x00\x00"; - if (!isset($gpFlags) || strlen($gpFlags) != 2) { + if (! isset($gpFlags) || strlen($gpFlags) != 2) { $gpFlags = "\x00\x00"; } - $isFileUTF8 = mb_check_encoding($filePath, "UTF-8") && !mb_check_encoding($filePath, "ASCII"); - $isCommentUTF8 = !empty($fileComment) && mb_check_encoding($fileComment, "UTF-8") && !mb_check_encoding($fileComment, "ASCII"); + $isFileUTF8 = mb_check_encoding($filePath, 'UTF-8') && ! mb_check_encoding($filePath, 'ASCII'); + $isCommentUTF8 = ! empty($fileComment) && mb_check_encoding($fileComment, 'UTF-8') && ! mb_check_encoding($fileComment, 'ASCII'); if ($isFileUTF8 || $isCommentUTF8) { $flag = 0; - $gpFlagsV = unpack("vflags", $gpFlags); + $gpFlagsV = unpack('vflags', $gpFlags); if (isset($gpFlagsV['flags'])) { $flag = $gpFlagsV['flags']; } - $gpFlags = pack("v", $flag | (1 << 11)); + $gpFlags = pack('v', $flag | (1 << 11)); } - $header = $gpFlags . $gzType . $dosTime. $fileCRC32 - . pack("VVv", $gzLength, $dataLength, strlen($filePath)); // File name length + $header = $gpFlags.$gzType.$dosTime.$fileCRC32 + .pack('VVv', $gzLength, $dataLength, strlen($filePath)); // File name length - $zipEntry = self::ZIP_LOCAL_FILE_HEADER; + $zipEntry = self::ZIP_LOCAL_FILE_HEADER; $zipEntry .= self::ATTR_VERSION_TO_EXTRACT; $zipEntry .= $header; $zipEntry .= $this->addExtraField ? "\x1C\x00" : "\x00\x00"; // Extra field length $zipEntry .= $filePath; // FileName // Extra fields if ($this->addExtraField) { - $zipEntry .= "\x55\x54\x09\x00\x03" . $tsPack . $tsPack . $ux; + $zipEntry .= "\x55\x54\x09\x00\x03".$tsPack.$tsPack.$ux; } - print($zipEntry); + echo $zipEntry; - $cdEntry = self::ZIP_CENTRAL_FILE_HEADER; + $cdEntry = self::ZIP_CENTRAL_FILE_HEADER; $cdEntry .= self::ATTR_MADE_BY_VERSION; $cdEntry .= ($dataLength === 0 ? "\x0A\x00" : self::ATTR_VERSION_TO_EXTRACT); $cdEntry .= $header; $cdEntry .= $this->addExtraField ? "\x18\x00" : "\x00\x00"; // Extra field length - $cdEntry .= pack("v", $fileCommentLength); // File comment length + $cdEntry .= pack('v', $fileCommentLength); // File comment length $cdEntry .= "\x00\x00"; // Disk number start $cdEntry .= "\x00\x00"; // internal file attributes $cdEntry .= $extFileAttr; // External file attributes - $cdEntry .= pack("V", $this->offset); // Relative offset of local header + $cdEntry .= pack('V', $this->offset); // Relative offset of local header $cdEntry .= $filePath; // FileName // Extra fields if ($this->addExtraField) { - $cdEntry .= "\x55\x54\x05\x00\x03" . $tsPack . $ux; + $cdEntry .= "\x55\x54\x05\x00\x03".$tsPack.$ux; } - if (!empty($fileComment)) { + if (! empty($fileComment)) { $cdEntry .= $fileComment; // Comment } @@ -529,15 +535,16 @@ class ZipStream /** * Join $file to $dir path, and clean up any excess slashes. * - * @param String $dir - * @param String $file + * @param string $dir + * @param string $file */ public static function pathJoin($dir, $file) { if (empty($dir) || empty($file)) { - return self::getRelativePath($dir . $file); + return self::getRelativePath($dir.$file); } - return self::getRelativePath($dir . '/' . $file); + + return self::getRelativePath($dir.'/'.$file); } /** @@ -545,30 +552,30 @@ class ZipStream * If the path starts with a "/", it is deemed an absolute path and any /../ in the beginning is stripped off. * The returned path will not end in a "/". * - * @param String $path The path to clean up - * @return String the clean path + * @param string $path The path to clean up + * @return string the clean path */ public static function getRelativePath($path) { - $path = preg_replace("#/+\.?/+#", "/", str_replace("\\", "/", $path)); - $dirs = explode("/", rtrim(preg_replace('#^(?:\./)+#', '', $path), '/')); + $path = preg_replace("#/+\.?/+#", '/', str_replace('\\', '/', $path)); + $dirs = explode('/', rtrim(preg_replace('#^(?:\./)+#', '', $path), '/')); $offset = 0; $sub = 0; $subOffset = 0; - $root = ""; + $root = ''; if (empty($dirs[0])) { - $root = "/"; + $root = '/'; $dirs = array_splice($dirs, 1); - } else if (preg_match("#[A-Za-z]:#", $dirs[0])) { - $root = strtoupper($dirs[0]) . "/"; + } elseif (preg_match('#[A-Za-z]:#', $dirs[0])) { + $root = strtoupper($dirs[0]).'/'; $dirs = array_splice($dirs, 1); } $newDirs = []; foreach ($dirs as $dir) { - if ($dir !== "..") { + if ($dir !== '..') { $subOffset--; $newDirs[++$offset] = $dir; } else { @@ -583,8 +590,9 @@ class ZipStream } if (empty($root)) { - $root = str_repeat("../", $sub); + $root = str_repeat('../', $sub); } - return $root . implode("/", array_slice($newDirs, 0, $offset)); + + return $root.implode('/', array_slice($newDirs, 0, $offset)); } } diff --git a/app/Library/getid3/demos/demo.audioinfo.class.php b/app/Library/getid3/demos/demo.audioinfo.class.php index dc12a1ea..e22ec1d2 100644 --- a/app/Library/getid3/demos/demo.audioinfo.class.php +++ b/app/Library/getid3/demos/demo.audioinfo.class.php @@ -28,289 +28,191 @@ // +----------------------------------------------------------------------+ // - +/** + * getID3() settings. + */ +require_once '../getid3/getid3.php'; /** -* getID3() settings -*/ - -require_once('../getid3/getid3.php'); - - - - -/** -* Class for extracting information from audio files with getID3(). -*/ - -class AudioInfo { - - /** - * Private variables - */ - var $result = NULL; - var $info = NULL; - - - - - /** - * Constructor - */ - - function AudioInfo() { - - // Initialize getID3 engine - $this->getID3 = new getID3; - $this->getID3->option_md5_data = true; - $this->getID3->option_md5_data_source = true; - $this->getID3->encoding = 'UTF-8'; - } - - - - - /** - * Extract information - only public function - * - * @access public - * @param string file Audio file to extract info from. - */ - - function Info($file) { - - // Analyze file - $this->info = $this->getID3->analyze($file); - - // Exit here on error - if (isset($this->info['error'])) { - return array ('error' => $this->info['error']); - } - - // Init wrapper object - $this->result = array(); - $this->result['format_name'] = (isset($this->info['fileformat']) ? $this->info['fileformat'] : '').'/'.(isset($this->info['audio']['dataformat']) ? $this->info['audio']['dataformat'] : '').(isset($this->info['video']['dataformat']) ? '/'.$this->info['video']['dataformat'] : ''); - $this->result['encoder_version'] = (isset($this->info['audio']['encoder']) ? $this->info['audio']['encoder'] : ''); - $this->result['encoder_options'] = (isset($this->info['audio']['encoder_options']) ? $this->info['audio']['encoder_options'] : ''); - $this->result['bitrate_mode'] = (isset($this->info['audio']['bitrate_mode']) ? $this->info['audio']['bitrate_mode'] : ''); - $this->result['channels'] = (isset($this->info['audio']['channels']) ? $this->info['audio']['channels'] : ''); - $this->result['sample_rate'] = (isset($this->info['audio']['sample_rate']) ? $this->info['audio']['sample_rate'] : ''); - $this->result['bits_per_sample'] = (isset($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : ''); - $this->result['playing_time'] = (isset($this->info['playtime_seconds']) ? $this->info['playtime_seconds'] : ''); - $this->result['avg_bit_rate'] = (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : ''); - $this->result['tags'] = (isset($this->info['tags']) ? $this->info['tags'] : ''); - $this->result['comments'] = (isset($this->info['comments']) ? $this->info['comments'] : ''); - $this->result['warning'] = (isset($this->info['warning']) ? $this->info['warning'] : ''); - $this->result['md5'] = (isset($this->info['md5_data']) ? $this->info['md5_data'] : ''); - - // Post getID3() data handling based on file format - $method = (isset($this->info['fileformat']) ? $this->info['fileformat'] : '').'Info'; - if ($method && method_exists($this, $method)) { - $this->$method(); - } - - return $this->result; - } - - - - - /** - * post-getID3() data handling for AAC files. - * - * @access private - */ - - function aacInfo() { - $this->result['format_name'] = 'AAC'; - } - - - - - /** - * post-getID3() data handling for Wave files. - * - * @access private - */ - - function riffInfo() { - if ($this->info['audio']['dataformat'] == 'wav') { - - $this->result['format_name'] = 'Wave'; - - } elseif (preg_match('#^mp[1-3]$#', $this->info['audio']['dataformat'])) { - - $this->result['format_name'] = strtoupper($this->info['audio']['dataformat']); - - } else { - - $this->result['format_name'] = 'riff/'.$this->info['audio']['dataformat']; - - } - } - - - - - /** - * * post-getID3() data handling for FLAC files. - * - * @access private - */ - - function flacInfo() { - $this->result['format_name'] = 'FLAC'; - } - - - - - - /** - * post-getID3() data handling for Monkey's Audio files. - * - * @access private - */ - - function macInfo() { - $this->result['format_name'] = 'Monkey\'s Audio'; - } - - - - - - /** - * post-getID3() data handling for Lossless Audio files. - * - * @access private - */ - - function laInfo() { - $this->result['format_name'] = 'La'; - } - - - - - - /** - * post-getID3() data handling for Ogg Vorbis files. - * - * @access private - */ - - function oggInfo() { - if ($this->info['audio']['dataformat'] == 'vorbis') { - - $this->result['format_name'] = 'Ogg Vorbis'; - - } else if ($this->info['audio']['dataformat'] == 'flac') { - - $this->result['format_name'] = 'Ogg FLAC'; - - } else if ($this->info['audio']['dataformat'] == 'speex') { - - $this->result['format_name'] = 'Ogg Speex'; - - } else { - - $this->result['format_name'] = 'Ogg '.$this->info['audio']['dataformat']; - - } - } - - - - - /** - * post-getID3() data handling for Musepack files. - * - * @access private - */ - - function mpcInfo() { - $this->result['format_name'] = 'Musepack'; - } - - - - - /** - * post-getID3() data handling for MPEG files. - * - * @access private - */ - - function mp3Info() { - $this->result['format_name'] = 'MP3'; - } - - - - - /** - * post-getID3() data handling for MPEG files. - * - * @access private - */ - - function mp2Info() { - $this->result['format_name'] = 'MP2'; - } - - - - - - /** - * post-getID3() data handling for MPEG files. - * - * @access private - */ - - function mp1Info() { - $this->result['format_name'] = 'MP1'; - } - - - - - /** - * post-getID3() data handling for WMA files. - * - * @access private - */ - - function asfInfo() { - $this->result['format_name'] = strtoupper($this->info['audio']['dataformat']); - } - - - - /** - * post-getID3() data handling for Real files. - * - * @access private - */ - - function realInfo() { - $this->result['format_name'] = 'Real'; - } - - - - - - /** - * post-getID3() data handling for VQF files. - * - * @access private - */ - - function vqfInfo() { - $this->result['format_name'] = 'VQF'; - } - + * Class for extracting information from audio files with getID3(). + */ +class AudioInfo +{ + /** + * Private variables. + */ + public $result = null; + public $info = null; + + /** + * Constructor. + */ + public function AudioInfo() + { + + // Initialize getID3 engine + $this->getID3 = new getID3; + $this->getID3->option_md5_data = true; + $this->getID3->option_md5_data_source = true; + $this->getID3->encoding = 'UTF-8'; + } + + /** + * Extract information - only public function. + * + * @param string file Audio file to extract info from. + */ + public function Info($file) + { + + // Analyze file + $this->info = $this->getID3->analyze($file); + + // Exit here on error + if (isset($this->info['error'])) { + return ['error' => $this->info['error']]; + } + + // Init wrapper object + $this->result = []; + $this->result['format_name'] = (isset($this->info['fileformat']) ? $this->info['fileformat'] : '').'/'.(isset($this->info['audio']['dataformat']) ? $this->info['audio']['dataformat'] : '').(isset($this->info['video']['dataformat']) ? '/'.$this->info['video']['dataformat'] : ''); + $this->result['encoder_version'] = (isset($this->info['audio']['encoder']) ? $this->info['audio']['encoder'] : ''); + $this->result['encoder_options'] = (isset($this->info['audio']['encoder_options']) ? $this->info['audio']['encoder_options'] : ''); + $this->result['bitrate_mode'] = (isset($this->info['audio']['bitrate_mode']) ? $this->info['audio']['bitrate_mode'] : ''); + $this->result['channels'] = (isset($this->info['audio']['channels']) ? $this->info['audio']['channels'] : ''); + $this->result['sample_rate'] = (isset($this->info['audio']['sample_rate']) ? $this->info['audio']['sample_rate'] : ''); + $this->result['bits_per_sample'] = (isset($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : ''); + $this->result['playing_time'] = (isset($this->info['playtime_seconds']) ? $this->info['playtime_seconds'] : ''); + $this->result['avg_bit_rate'] = (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : ''); + $this->result['tags'] = (isset($this->info['tags']) ? $this->info['tags'] : ''); + $this->result['comments'] = (isset($this->info['comments']) ? $this->info['comments'] : ''); + $this->result['warning'] = (isset($this->info['warning']) ? $this->info['warning'] : ''); + $this->result['md5'] = (isset($this->info['md5_data']) ? $this->info['md5_data'] : ''); + + // Post getID3() data handling based on file format + $method = (isset($this->info['fileformat']) ? $this->info['fileformat'] : '').'Info'; + if ($method && method_exists($this, $method)) { + $this->$method(); + } + + return $this->result; + } + + /** + * post-getID3() data handling for AAC files. + */ + public function aacInfo() + { + $this->result['format_name'] = 'AAC'; + } + + /** + * post-getID3() data handling for Wave files. + */ + public function riffInfo() + { + if ($this->info['audio']['dataformat'] == 'wav') { + $this->result['format_name'] = 'Wave'; + } elseif (preg_match('#^mp[1-3]$#', $this->info['audio']['dataformat'])) { + $this->result['format_name'] = strtoupper($this->info['audio']['dataformat']); + } else { + $this->result['format_name'] = 'riff/'.$this->info['audio']['dataformat']; + } + } + + /** + * * post-getID3() data handling for FLAC files. + */ + public function flacInfo() + { + $this->result['format_name'] = 'FLAC'; + } + + /** + * post-getID3() data handling for Monkey's Audio files. + */ + public function macInfo() + { + $this->result['format_name'] = 'Monkey\'s Audio'; + } + + /** + * post-getID3() data handling for Lossless Audio files. + */ + public function laInfo() + { + $this->result['format_name'] = 'La'; + } + + /** + * post-getID3() data handling for Ogg Vorbis files. + */ + public function oggInfo() + { + if ($this->info['audio']['dataformat'] == 'vorbis') { + $this->result['format_name'] = 'Ogg Vorbis'; + } elseif ($this->info['audio']['dataformat'] == 'flac') { + $this->result['format_name'] = 'Ogg FLAC'; + } elseif ($this->info['audio']['dataformat'] == 'speex') { + $this->result['format_name'] = 'Ogg Speex'; + } else { + $this->result['format_name'] = 'Ogg '.$this->info['audio']['dataformat']; + } + } + + /** + * post-getID3() data handling for Musepack files. + */ + public function mpcInfo() + { + $this->result['format_name'] = 'Musepack'; + } + + /** + * post-getID3() data handling for MPEG files. + */ + public function mp3Info() + { + $this->result['format_name'] = 'MP3'; + } + + /** + * post-getID3() data handling for MPEG files. + */ + public function mp2Info() + { + $this->result['format_name'] = 'MP2'; + } + + /** + * post-getID3() data handling for MPEG files. + */ + public function mp1Info() + { + $this->result['format_name'] = 'MP1'; + } + + /** + * post-getID3() data handling for WMA files. + */ + public function asfInfo() + { + $this->result['format_name'] = strtoupper($this->info['audio']['dataformat']); + } + + /** + * post-getID3() data handling for Real files. + */ + public function realInfo() + { + $this->result['format_name'] = 'Real'; + } + + /** + * post-getID3() data handling for VQF files. + */ + public function vqfInfo() + { + $this->result['format_name'] = 'VQF'; + } } diff --git a/app/Library/getid3/demos/demo.basic.php b/app/Library/getid3/demos/demo.basic.php index 73628ead..f2c7ce8f 100644 --- a/app/Library/getid3/demos/demo.basic.php +++ b/app/Library/getid3/demos/demo.basic.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -15,7 +16,7 @@ die('Due to a security issue, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in '.$_SERVER['PHP_SELF']); // include getID3() library (can be in a different directory if full path is specified) -require_once('../getid3/getid3.php'); +require_once '../getid3/getid3.php'; // Initialize getID3 engine $getID3 = new getID3; @@ -50,5 +51,3 @@ getid3_lib::CopyTagsToComments($ThisFileInfo); /* if you want to see ALL the output, uncomment this line: */ //echo '
'.htmlentities(print_r($ThisFileInfo, true), ENT_SUBSTITUTE).'
'; - - diff --git a/app/Library/getid3/demos/demo.browse.php b/app/Library/getid3/demos/demo.browse.php index a5034038..992c3aa7 100644 --- a/app/Library/getid3/demos/demo.browse.php +++ b/app/Library/getid3/demos/demo.browse.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,17 +15,17 @@ ///////////////////////////////////////////////////////////////// die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__)); -define('GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK', false); +define('GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK', false); define('GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK', false); -define('GETID3_DEMO_BROWSE_ALLOW_MD5_LINK', false); +define('GETID3_DEMO_BROWSE_ALLOW_MD5_LINK', false); ///////////////////////////////////////////////////////////////// // die if magic_quotes_runtime or magic_quotes_gpc are set if (function_exists('get_magic_quotes_runtime') && get_magic_quotes_runtime()) { - die('magic_quotes_runtime is enabled, getID3 will not run.'); + die('magic_quotes_runtime is enabled, getID3 will not run.'); } if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { - die('magic_quotes_gpc is enabled, getID3 will not run.'); + die('magic_quotes_gpc is enabled, getID3 will not run.'); } ///////////////////////////////////////////////////////////////// @@ -32,27 +33,25 @@ $PageEncoding = 'UTF-8'; $writescriptfilename = 'demo.write.php'; -require_once('../getid3/getid3.php'); +require_once '../getid3/getid3.php'; // Needed for windows only. Leave commented-out to auto-detect, only define here if auto-detection does not work properly //define('GETID3_HELPERAPPSDIR', 'C:\\helperapps\\'); // Initialize getID3 engine $getID3 = new getID3; -$getID3->setOption(array('encoding' => $PageEncoding)); +$getID3->setOption(['encoding' => $PageEncoding]); -$getID3checkColor_Head = 'CCCCDD'; +$getID3checkColor_Head = 'CCCCDD'; $getID3checkColor_DirectoryLight = 'FFCCCC'; -$getID3checkColor_DirectoryDark = 'EEBBBB'; -$getID3checkColor_FileLight = 'EEEEEE'; -$getID3checkColor_FileDark = 'DDDDDD'; -$getID3checkColor_UnknownLight = 'CCCCFF'; -$getID3checkColor_UnknownDark = 'BBBBDD'; - +$getID3checkColor_DirectoryDark = 'EEBBBB'; +$getID3checkColor_FileLight = 'EEEEEE'; +$getID3checkColor_FileDark = 'DDDDDD'; +$getID3checkColor_UnknownLight = 'CCCCFF'; +$getID3checkColor_UnknownDark = 'BBBBDD'; /////////////////////////////////////////////////////////////////////////////// - header('Content-Type: text/html; charset='.$PageEncoding); echo ''; echo ''; @@ -62,548 +61,551 @@ echo ''.$deletefilemessage.'
'; - } else { - echo ''; - } + if (file_exists($_REQUEST['deletefile'])) { + if (unlink($_REQUEST['deletefile'])) { + $deletefilemessage = 'Successfully deleted '.addslashes($_REQUEST['deletefile']); + } else { + $deletefilemessage = 'FAILED to delete '.addslashes($_REQUEST['deletefile']).' - error deleting file'; + } + } else { + $deletefilemessage = 'FAILED to delete '.addslashes($_REQUEST['deletefile']).' - file does not exist'; + } + if (isset($_REQUEST['noalert'])) { + echo ''.$deletefilemessage.'
'; + } else { + echo ''; + } } - if (isset($_REQUEST['filename'])) { + if (! file_exists($_REQUEST['filename']) || ! is_file($_REQUEST['filename'])) { + die(getid3_lib::iconv_fallback('ISO-8859-1', $PageEncoding, $_REQUEST['filename'].' does not exist')); + } + $starttime = microtime(true); - if (!file_exists($_REQUEST['filename']) || !is_file($_REQUEST['filename'])) { - die(getid3_lib::iconv_fallback('ISO-8859-1', $PageEncoding, $_REQUEST['filename'].' does not exist')); - } - $starttime = microtime(true); + //$getID3->setOption(array( + // 'option_md5_data' => $AutoGetHashes, + // 'option_sha1_data' => $AutoGetHashes, + //)); + $ThisFileInfo = $getID3->analyze($_REQUEST['filename']); + $AutoGetHashes = (bool) (isset($ThisFileInfo['filesize']) && ($ThisFileInfo['filesize'] > 0) && ($ThisFileInfo['filesize'] < (50 * 1048576))); // auto-get md5_data, md5_file, sha1_data, sha1_file if filesize < 50MB, and NOT zero (which may indicate a file>2GB) + $AutoGetHashes = ($AutoGetHashes && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK); + if ($AutoGetHashes) { + $ThisFileInfo['md5_file'] = md5_file($_REQUEST['filename']); + $ThisFileInfo['sha1_file'] = sha1_file($_REQUEST['filename']); + } - //$getID3->setOption(array( - // 'option_md5_data' => $AutoGetHashes, - // 'option_sha1_data' => $AutoGetHashes, - //)); - $ThisFileInfo = $getID3->analyze($_REQUEST['filename']); - $AutoGetHashes = (bool) (isset($ThisFileInfo['filesize']) && ($ThisFileInfo['filesize'] > 0) && ($ThisFileInfo['filesize'] < (50 * 1048576))); // auto-get md5_data, md5_file, sha1_data, sha1_file if filesize < 50MB, and NOT zero (which may indicate a file>2GB) - $AutoGetHashes = ($AutoGetHashes && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK); - if ($AutoGetHashes) { - $ThisFileInfo['md5_file'] = md5_file($_REQUEST['filename']); - $ThisFileInfo['sha1_file'] = sha1_file($_REQUEST['filename']); - } + getid3_lib::CopyTagsToComments($ThisFileInfo); + $listdirectory = dirname($_REQUEST['filename']); + $listdirectory = realpath($listdirectory); // get rid of /../../ references - getid3_lib::CopyTagsToComments($ThisFileInfo); + if (GETID3_OS_ISWINDOWS) { + // this mostly just gives a consistant look to Windows and *nix filesystems + // (windows uses \ as directory seperator, *nix uses /) + $listdirectory = str_replace(DIRECTORY_SEPARATOR, '/', $listdirectory.'/'); + } - $listdirectory = dirname($_REQUEST['filename']); - $listdirectory = realpath($listdirectory); // get rid of /../../ references - - if (GETID3_OS_ISWINDOWS) { - // this mostly just gives a consistant look to Windows and *nix filesystems - // (windows uses \ as directory seperator, *nix uses /) - $listdirectory = str_replace(DIRECTORY_SEPARATOR, '/', $listdirectory.'/'); - } - - if (strstr($_REQUEST['filename'], 'http://') || strstr($_REQUEST['filename'], 'ftp://')) { - echo 'Cannot browse remote filesystems
'; - } else { - echo 'Browse: '.getid3_lib::iconv_fallback('ISO-8859-1', $PageEncoding, $listdirectory).'
'; - } - - getid3_lib::ksort_recursive($ThisFileInfo); - echo table_var_dump($ThisFileInfo, false, $PageEncoding); - $endtime = microtime(true); - echo 'File parsed in '.number_format($endtime - $starttime, 3).' seconds.
'; + if (strstr($_REQUEST['filename'], 'http://') || strstr($_REQUEST['filename'], 'ftp://')) { + echo 'Cannot browse remote filesystems
'; + } else { + echo 'Browse: '.getid3_lib::iconv_fallback('ISO-8859-1', $PageEncoding, $listdirectory).'
'; + } + getid3_lib::ksort_recursive($ThisFileInfo); + echo table_var_dump($ThisFileInfo, false, $PageEncoding); + $endtime = microtime(true); + echo 'File parsed in '.number_format($endtime - $starttime, 3).' seconds.
'; } else { + $listdirectory = (isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.'); + $listdirectory = realpath($listdirectory); // get rid of /../../ references + $currentfulldir = $listdirectory.'/'; - $listdirectory = (isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.'); - $listdirectory = realpath($listdirectory); // get rid of /../../ references - $currentfulldir = $listdirectory.'/'; + if (GETID3_OS_ISWINDOWS) { + // this mostly just gives a consistant look to Windows and *nix filesystems + // (windows uses \ as directory seperator, *nix uses /) + $currentfulldir = str_replace(DIRECTORY_SEPARATOR, '/', $listdirectory.'/'); + } - if (GETID3_OS_ISWINDOWS) { - // this mostly just gives a consistant look to Windows and *nix filesystems - // (windows uses \ as directory seperator, *nix uses /) - $currentfulldir = str_replace(DIRECTORY_SEPARATOR, '/', $listdirectory.'/'); - } + ob_start(); + if ($handle = opendir($listdirectory)) { + ob_end_clean(); + echo str_repeat(' ', 300); // IE buffers the first 300 or so chars, making this progressive display useless - fill the buffer with spaces + echo 'Processing'; - ob_start(); - if ($handle = opendir($listdirectory)) { + $starttime = microtime(true); - ob_end_clean(); - echo str_repeat(' ', 300); // IE buffers the first 300 or so chars, making this progressive display useless - fill the buffer with spaces - echo 'Processing'; + $TotalScannedUnknownFiles = 0; + $TotalScannedKnownFiles = 0; + $TotalScannedPlaytimeFiles = 0; + $TotalScannedBitrateFiles = 0; + $TotalScannedFilesize = 0; + $TotalScannedPlaytime = 0; + $TotalScannedBitrate = 0; + $FilesWithWarnings = 0; + $FilesWithErrors = 0; - $starttime = microtime(true); + while ($file = readdir($handle)) { + $currentfilename = $listdirectory.'/'.$file; + set_time_limit(30); // allocate another 30 seconds to process this file - should go much quicker than this unless intense processing (like bitrate histogram analysis) is enabled + echo ' .'; // progress indicator dot + flush(); // make sure the dot is shown, otherwise it's useless + switch ($file) { + case '..': + $ParentDir = realpath($file.'/..').'/'; + if (GETID3_OS_ISWINDOWS) { + $ParentDir = str_replace(DIRECTORY_SEPARATOR, '/', $ParentDir); + } + $DirectoryContents[$currentfulldir]['dir'][$file]['filename'] = $ParentDir; + continue 2; + break; - $TotalScannedUnknownFiles = 0; - $TotalScannedKnownFiles = 0; - $TotalScannedPlaytimeFiles = 0; - $TotalScannedBitrateFiles = 0; - $TotalScannedFilesize = 0; - $TotalScannedPlaytime = 0; - $TotalScannedBitrate = 0; - $FilesWithWarnings = 0; - $FilesWithErrors = 0; + case '.': + // ignore + continue 2; + break; + } + // symbolic-link-resolution enhancements by davidbullock×´ech-center*com + $TargetObject = realpath($currentfilename); // Find actual file path, resolve if it's a symbolic link + $TargetObjectType = filetype($TargetObject); // Check file type without examining extension - while ($file = readdir($handle)) { - $currentfilename = $listdirectory.'/'.$file; - set_time_limit(30); // allocate another 30 seconds to process this file - should go much quicker than this unless intense processing (like bitrate histogram analysis) is enabled - echo ' .'; // progress indicator dot - flush(); // make sure the dot is shown, otherwise it's useless - switch ($file) { - case '..': - $ParentDir = realpath($file.'/..').'/'; - if (GETID3_OS_ISWINDOWS) { - $ParentDir = str_replace(DIRECTORY_SEPARATOR, '/', $ParentDir); - } - $DirectoryContents[$currentfulldir]['dir'][$file]['filename'] = $ParentDir; - continue 2; - break; + if ($TargetObjectType == 'dir') { + $DirectoryContents[$currentfulldir]['dir'][$file]['filename'] = $file; + } elseif ($TargetObjectType == 'file') { + $getID3->setOption(['option_md5_data' => (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK)]); + $fileinformation = $getID3->analyze($currentfilename); - case '.': - // ignore - continue 2; - break; - } - // symbolic-link-resolution enhancements by davidbullock×´ech-center*com - $TargetObject = realpath($currentfilename); // Find actual file path, resolve if it's a symbolic link - $TargetObjectType = filetype($TargetObject); // Check file type without examining extension + getid3_lib::CopyTagsToComments($fileinformation); - if ($TargetObjectType == 'dir') { + $TotalScannedFilesize += (isset($fileinformation['filesize']) ? $fileinformation['filesize'] : 0); - $DirectoryContents[$currentfulldir]['dir'][$file]['filename'] = $file; + if (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK) { + $fileinformation['md5_file'] = md5_file($currentfilename); + } - } elseif ($TargetObjectType == 'file') { + if (! empty($fileinformation['fileformat'])) { + $DirectoryContents[$currentfulldir]['known'][$file] = $fileinformation; + $TotalScannedPlaytime += (isset($fileinformation['playtime_seconds']) ? $fileinformation['playtime_seconds'] : 0); + $TotalScannedBitrate += (isset($fileinformation['bitrate']) ? $fileinformation['bitrate'] : 0); + $TotalScannedKnownFiles++; + } else { + $DirectoryContents[$currentfulldir]['other'][$file] = $fileinformation; + $DirectoryContents[$currentfulldir]['other'][$file]['playtime_string'] = '-'; + $TotalScannedUnknownFiles++; + } + if (isset($fileinformation['playtime_seconds']) && ($fileinformation['playtime_seconds'] > 0)) { + $TotalScannedPlaytimeFiles++; + } + if (isset($fileinformation['bitrate']) && ($fileinformation['bitrate'] > 0)) { + $TotalScannedBitrateFiles++; + } + } + } + $endtime = microtime(true); + closedir($handle); + echo 'done
'; + echo 'Directory scanned in '.number_format($endtime - $starttime, 2).' seconds.
'; + flush(); - $getID3->setOption(array('option_md5_data' => (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK))); - $fileinformation = $getID3->analyze($currentfilename); + $columnsintable = 14; + echo ''; - getid3_lib::CopyTagsToComments($fileinformation); + echo ''; + $rowcounter = 0; + foreach ($DirectoryContents as $dirname => $val) { + if (isset($DirectoryContents[$dirname]['dir']) && is_array($DirectoryContents[$dirname]['dir'])) { + uksort($DirectoryContents[$dirname]['dir'], 'MoreNaturalSort'); + foreach ($DirectoryContents[$dirname]['dir'] as $filename => $fileinfo) { + echo ''; + if ($filename == '..') { + echo ''; + } else { + $escaped_filename = htmlentities($filename, ENT_SUBSTITUTE, $PageEncoding); // do filesystems always return filenames in ISO-8859-1? + $escaped_filename = ($escaped_filename ? $escaped_filename : rawurlencode($filename)); + echo ''; + } + echo ''; + } + } - $TotalScannedFilesize += (isset($fileinformation['filesize']) ? $fileinformation['filesize'] : 0); + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + if (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK) { + echo ''; + echo ''; + echo ''; + } else { + echo ''; + } + echo ''; + echo ''; + echo GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK ? '' : ''; + echo GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK ? '' : ''; + echo ''; - if (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK) { - $fileinformation['md5_file'] = md5_file($currentfilename); - } + if (isset($DirectoryContents[$dirname]['known']) && is_array($DirectoryContents[$dirname]['known'])) { + uksort($DirectoryContents[$dirname]['known'], 'MoreNaturalSort'); + foreach ($DirectoryContents[$dirname]['known'] as $filename => $fileinfo) { + echo ''; + $escaped_filename = htmlentities($filename, ENT_SUBSTITUTE, $PageEncoding); + $escaped_filename = ($escaped_filename ? $escaped_filename : rawurlencode($filename)); + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + if (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK) { + echo ''; + echo ''; + echo ''; + } else { + echo ''; + } + echo ''; - if (!empty($fileinformation['fileformat'])) { - $DirectoryContents[$currentfulldir]['known'][$file] = $fileinformation; - $TotalScannedPlaytime += (isset($fileinformation['playtime_seconds']) ? $fileinformation['playtime_seconds'] : 0); - $TotalScannedBitrate += (isset($fileinformation['bitrate']) ? $fileinformation['bitrate'] : 0); - $TotalScannedKnownFiles++; - } else { - $DirectoryContents[$currentfulldir]['other'][$file] = $fileinformation; - $DirectoryContents[$currentfulldir]['other'][$file]['playtime_string'] = '-'; - $TotalScannedUnknownFiles++; - } - if (isset($fileinformation['playtime_seconds']) && ($fileinformation['playtime_seconds'] > 0)) { - $TotalScannedPlaytimeFiles++; - } - if (isset($fileinformation['bitrate']) && ($fileinformation['bitrate'] > 0)) { - $TotalScannedBitrateFiles++; - } - } - } - $endtime = microtime(true); - closedir($handle); - echo 'done
'; - echo 'Directory scanned in '.number_format($endtime - $starttime, 2).' seconds.
'; - flush(); + echo ''; - $columnsintable = 14; - echo '
Files in '.getid3_lib::iconv_fallback('ISO-8859-1', $PageEncoding, $currentfulldir).'
'; + echo '
'; + echo 'Parent directory: '; + echo ' '; + echo '
'.$escaped_filename.'
FilenameFile SizeFormatPlaytimeBitrateArtistTitleMD5 File (File) (disable)MD5 Data (File) (disable)MD5 Data (Source) (disable)MD5 Data'.(GETID3_DEMO_BROWSE_ALLOW_MD5_LINK ? ' (enable)' : '').'TagsErrors & WarningsEditDelete
'.$escaped_filename.' '.number_format($fileinfo['filesize']).' '.NiceDisplayFiletypeFormat($fileinfo).' '.(isset($fileinfo['playtime_string']) ? $fileinfo['playtime_string'] : '-').' '.(isset($fileinfo['bitrate']) ? BitrateText($fileinfo['bitrate'] / 1000, 0, ((isset($fileinfo['audio']['bitrate_mode']) && ($fileinfo['audio']['bitrate_mode'] == 'vbr')) ? true : false)) : '-').' '.(isset($fileinfo['comments_html']['artist']) ? implode('
', $fileinfo['comments_html']['artist']) : ((isset($fileinfo['video']['resolution_x']) && isset($fileinfo['video']['resolution_y'])) ? $fileinfo['video']['resolution_x'].'x'.$fileinfo['video']['resolution_y'] : '')).'
 '.(isset($fileinfo['comments_html']['title']) ? implode('
', $fileinfo['comments_html']['title']) : (isset($fileinfo['video']['frame_rate']) ? number_format($fileinfo['video']['frame_rate'], 3).'fps' : '')).'
'.(isset($fileinfo['md5_file']) ? $fileinfo['md5_file'] : ' ').''.(isset($fileinfo['md5_data']) ? $fileinfo['md5_data'] : ' ').''.(isset($fileinfo['md5_data_source']) ? $fileinfo['md5_data_source'] : ' ').'- '.(! empty($fileinfo['tags']) ? implode(', ', array_keys($fileinfo['tags'])) : '').' '; + if (! empty($fileinfo['warning'])) { + $FilesWithWarnings++; + echo 'warning
'; + } + if (! empty($fileinfo['error'])) { + $FilesWithErrors++; + echo 'error
'; + } + echo '
'; + if (GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK) { + echo ''; + } + if (GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK) { + echo ''; + } + echo ''; + } + } - echo ''; - $rowcounter = 0; - foreach ($DirectoryContents as $dirname => $val) { - if (isset($DirectoryContents[$dirname]['dir']) && is_array($DirectoryContents[$dirname]['dir'])) { - uksort($DirectoryContents[$dirname]['dir'], 'MoreNaturalSort'); - foreach ($DirectoryContents[$dirname]['dir'] as $filename => $fileinfo) { - echo ''; - if ($filename == '..') { - echo ''; - } else { - $escaped_filename = htmlentities($filename, ENT_SUBSTITUTE, $PageEncoding); // do filesystems always return filenames in ISO-8859-1? - $escaped_filename = ($escaped_filename ? $escaped_filename : rawurlencode($filename)); - echo ''; - } - echo ''; - } - } + if (isset($DirectoryContents[$dirname]['other']) && is_array($DirectoryContents[$dirname]['other'])) { + uksort($DirectoryContents[$dirname]['other'], 'MoreNaturalSort'); + foreach ($DirectoryContents[$dirname]['other'] as $filename => $fileinfo) { + echo ''; + $escaped_filename = htmlentities($filename, ENT_SUBSTITUTE, $PageEncoding); + $escaped_filename = ($escaped_filename ? $escaped_filename : rawurlencode($filename)); + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; // Artist + echo ''; // Title + echo ''; // MD5_data + echo ''; // Tags - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - if (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK) { - echo ''; - echo ''; - echo ''; - } else { - echo ''; - } - echo ''; - echo ''; - echo (GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK ? '' : ''); - echo (GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK ? '' : ''); - echo ''; + //echo ''; // Warning/Error + echo ''; - if (isset($DirectoryContents[$dirname]['known']) && is_array($DirectoryContents[$dirname]['known'])) { - uksort($DirectoryContents[$dirname]['known'], 'MoreNaturalSort'); - foreach ($DirectoryContents[$dirname]['known'] as $filename => $fileinfo) { - echo ''; - $escaped_filename = htmlentities($filename, ENT_SUBSTITUTE, $PageEncoding); - $escaped_filename = ($escaped_filename ? $escaped_filename : rawurlencode($filename)); - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - if (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK) { - echo ''; - echo ''; - echo ''; - } else { - echo ''; - } - echo ''; + if (GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK) { + echo ''; // Edit + } + if (GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK) { + echo ''; + } + echo ''; + } + } - echo ''; - - if (GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK) { - echo ''; - } - if (GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK) { - echo ''; - } - echo ''; - } - } - - if (isset($DirectoryContents[$dirname]['other']) && is_array($DirectoryContents[$dirname]['other'])) { - uksort($DirectoryContents[$dirname]['other'], 'MoreNaturalSort'); - foreach ($DirectoryContents[$dirname]['other'] as $filename => $fileinfo) { - echo ''; - $escaped_filename = htmlentities($filename, ENT_SUBSTITUTE, $PageEncoding); - $escaped_filename = ($escaped_filename ? $escaped_filename : rawurlencode($filename)); - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; // Artist - echo ''; // Title - echo ''; // MD5_data - echo ''; // Tags - - //echo ''; // Warning/Error - echo ''; - - if (GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK) { - echo ''; // Edit - } - if (GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK) { - echo ''; - } - echo ''; - } - } - - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
 '; + $fileinfo['fileformat'] = (isset($fileinfo['fileformat']) ? $fileinfo['fileformat'] : ''); + switch ($fileinfo['fileformat']) { + case 'mp3': + case 'mp2': + case 'mp1': + case 'flac': + case 'mpc': + case 'real': + echo 'edit tags'; + break; + case 'ogg': + if (isset($fileinfo['audio']['dataformat']) && ($fileinfo['audio']['dataformat'] == 'vorbis')) { + echo 'edit tags'; + } + break; + default: + break; + } + echo ' delete
Files in '.getid3_lib::iconv_fallback('ISO-8859-1', $PageEncoding, $currentfulldir).'
'; - echo '
'; - echo 'Parent directory: '; - echo ' '; - echo '
'.$escaped_filename.'
'.$escaped_filename.' '.(isset($fileinfo['filesize']) ? number_format($fileinfo['filesize']) : '-').' '.NiceDisplayFiletypeFormat($fileinfo).' '.(isset($fileinfo['playtime_string']) ? $fileinfo['playtime_string'] : '-').' '.(isset($fileinfo['bitrate']) ? BitrateText($fileinfo['bitrate'] / 1000) : '-').'    
FilenameFile SizeFormatPlaytimeBitrateArtistTitleMD5 File (File) (disable)MD5 Data (File) (disable)MD5 Data (Source) (disable)MD5 Data'.(GETID3_DEMO_BROWSE_ALLOW_MD5_LINK ?' (enable)' : '').'TagsErrors & WarningsEditDelete
  '; + if (! empty($fileinfo['warning'])) { + $FilesWithWarnings++; + echo 'warning
'; + } + if (! empty($fileinfo['error'])) { + if ($fileinfo['error'][0] != 'unable to determine file format') { + $FilesWithErrors++; + echo 'error
'; + } + } + echo '
'.$escaped_filename.' '.number_format($fileinfo['filesize']).' '.NiceDisplayFiletypeFormat($fileinfo).' '.(isset($fileinfo['playtime_string']) ? $fileinfo['playtime_string'] : '-').' '.(isset($fileinfo['bitrate']) ? BitrateText($fileinfo['bitrate'] / 1000, 0, ((isset($fileinfo['audio']['bitrate_mode']) && ($fileinfo['audio']['bitrate_mode'] == 'vbr')) ? true : false)) : '-').' '.(isset($fileinfo['comments_html']['artist']) ? implode('
', $fileinfo['comments_html']['artist']) : ((isset($fileinfo['video']['resolution_x']) && isset($fileinfo['video']['resolution_y'])) ? $fileinfo['video']['resolution_x'].'x'.$fileinfo['video']['resolution_y'] : '')).'
 '.(isset($fileinfo['comments_html']['title']) ? implode('
', $fileinfo['comments_html']['title']) : (isset($fileinfo['video']['frame_rate']) ? number_format($fileinfo['video']['frame_rate'], 3).'fps' : '')).'
'.(isset($fileinfo['md5_file']) ? $fileinfo['md5_file'] : ' ').''.(isset($fileinfo['md5_data']) ? $fileinfo['md5_data'] : ' ').''.(isset($fileinfo['md5_data_source']) ? $fileinfo['md5_data_source'] : ' ').'- '.(!empty($fileinfo['tags']) ? implode(', ', array_keys($fileinfo['tags'])) : '').'  delete
 '; - if (!empty($fileinfo['warning'])) { - $FilesWithWarnings++; - echo 'warning
'; - } - if (!empty($fileinfo['error'])) { - $FilesWithErrors++; - echo 'error
'; - } - echo '
 '; - $fileinfo['fileformat'] = (isset($fileinfo['fileformat']) ? $fileinfo['fileformat'] : ''); - switch ($fileinfo['fileformat']) { - case 'mp3': - case 'mp2': - case 'mp1': - case 'flac': - case 'mpc': - case 'real': - echo 'edit tags'; - break; - case 'ogg': - if (isset($fileinfo['audio']['dataformat']) && ($fileinfo['audio']['dataformat'] == 'vorbis')) { - echo 'edit tags'; - } - break; - default: - break; - } - echo ' delete
'.$escaped_filename.' '.(isset($fileinfo['filesize']) ? number_format($fileinfo['filesize']) : '-').' '.NiceDisplayFiletypeFormat($fileinfo).' '.(isset($fileinfo['playtime_string']) ? $fileinfo['playtime_string'] : '-').' '.(isset($fileinfo['bitrate']) ? BitrateText($fileinfo['bitrate'] / 1000) : '-').'      '; - if (!empty($fileinfo['warning'])) { - $FilesWithWarnings++; - echo 'warning
'; - } - if (!empty($fileinfo['error'])) { - if ($fileinfo['error'][0] != 'unable to determine file format') { - $FilesWithErrors++; - echo 'error
'; - } - } - echo '
  delete
Average:'.number_format($TotalScannedFilesize / max($TotalScannedKnownFiles, 1)).' '.getid3_lib::PlaytimeString($TotalScannedPlaytime / max($TotalScannedPlaytimeFiles, 1)).''.BitrateText(round(($TotalScannedBitrate / 1000) / max($TotalScannedBitrateFiles, 1))).'
Identified Files:'.number_format($TotalScannedKnownFiles).'   Errors:'.number_format($FilesWithErrors).'
Unknown Files:'.number_format($TotalScannedUnknownFiles).'   Warnings:'.number_format($FilesWithWarnings).'
'; - echo '
Total:'.number_format($TotalScannedFilesize).' '.getid3_lib::PlaytimeString($TotalScannedPlaytime).' 
'; - } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - echo 'ERROR: Could not open directory: '.$currentfulldir.'
'; - } + echo ''; + echo 'Average:'; + echo ''.number_format($TotalScannedFilesize / max($TotalScannedKnownFiles, 1)).''; + echo ' '; + echo ''.getid3_lib::PlaytimeString($TotalScannedPlaytime / max($TotalScannedPlaytimeFiles, 1)).''; + echo ''.BitrateText(round(($TotalScannedBitrate / 1000) / max($TotalScannedBitrateFiles, 1))).''; + echo '
Identified Files:'.number_format($TotalScannedKnownFiles).'   Errors:'.number_format($FilesWithErrors).'
Unknown Files:'.number_format($TotalScannedUnknownFiles).'   Warnings:'.number_format($FilesWithWarnings).'
'; + echo ''; + echo ''; + echo 'Total:'; + echo ''.number_format($TotalScannedFilesize).''; + echo ' '; + echo ''.getid3_lib::PlaytimeString($TotalScannedPlaytime).''; + echo ' '; + echo ''; + } + echo ''; + } else { + $errormessage = ob_get_contents(); + ob_end_clean(); + echo 'ERROR: Could not open directory: '.$currentfulldir.'
'; + } } echo PoweredBygetID3().'
'; echo ''; - ///////////////////////////////////////////////////////////////// - -function RemoveAccents($string) { - // Revised version by markstewardרotmail*com - // Again revised by James Heinrich (19-June-2006) - return strtr( - strtr( - $string, - "\x8A\x8E\x9A\x9E\x9F\xC0\xC1\xC2\xC3\xC4\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFF", - 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy' - ), - array( - "\xDE" => 'TH', - "\xFE" => 'th', - "\xD0" => 'DH', - "\xF0" => 'dh', - "\xDF" => 'ss', - "\x8C" => 'OE', - "\x9C" => 'oe', - "\xC6" => 'AE', - "\xE6" => 'ae', - "\xB5" => 'u' - ) - ); +function RemoveAccents($string) +{ + // Revised version by markstewardרotmail*com + // Again revised by James Heinrich (19-June-2006) + return strtr( + strtr( + $string, + "\x8A\x8E\x9A\x9E\x9F\xC0\xC1\xC2\xC3\xC4\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFF", + 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy' + ), + [ + "\xDE" => 'TH', + "\xFE" => 'th', + "\xD0" => 'DH', + "\xF0" => 'dh', + "\xDF" => 'ss', + "\x8C" => 'OE', + "\x9C" => 'oe', + "\xC6" => 'AE', + "\xE6" => 'ae', + "\xB5" => 'u', + ] + ); } +function BitrateColor($bitrate, $BitrateMaxScale = 768) +{ + // $BitrateMaxScale is bitrate of maximum-quality color (bright green) + // below this is gradient, above is solid green -function BitrateColor($bitrate, $BitrateMaxScale=768) { - // $BitrateMaxScale is bitrate of maximum-quality color (bright green) - // below this is gradient, above is solid green + $bitrate *= (256 / $BitrateMaxScale); // scale from 1-[768]kbps to 1-256 + $bitrate = round(min(max($bitrate, 1), 256)); + $bitrate--; // scale from 1-256kbps to 0-255kbps - $bitrate *= (256 / $BitrateMaxScale); // scale from 1-[768]kbps to 1-256 - $bitrate = round(min(max($bitrate, 1), 256)); - $bitrate--; // scale from 1-256kbps to 0-255kbps + $Rcomponent = max(255 - ($bitrate * 2), 0); + $Gcomponent = max(($bitrate * 2) - 255, 0); + if ($bitrate > 127) { + $Bcomponent = max((255 - $bitrate) * 2, 0); + } else { + $Bcomponent = max($bitrate * 2, 0); + } - $Rcomponent = max(255 - ($bitrate * 2), 0); - $Gcomponent = max(($bitrate * 2) - 255, 0); - if ($bitrate > 127) { - $Bcomponent = max((255 - $bitrate) * 2, 0); - } else { - $Bcomponent = max($bitrate * 2, 0); - } - return str_pad(dechex($Rcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Gcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Bcomponent), 2, '0', STR_PAD_LEFT); + return str_pad(dechex($Rcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Gcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Bcomponent), 2, '0', STR_PAD_LEFT); } -function BitrateText($bitrate, $decimals=0, $vbr=false) { - return ''.number_format($bitrate, $decimals).' kbps'; +function BitrateText($bitrate, $decimals = 0, $vbr = false) +{ + return ''.number_format($bitrate, $decimals).' kbps'; } -function string_var_dump($variable) { - if (version_compare(PHP_VERSION, '4.3.0', '>=')) { - return print_r($variable, true); - } - ob_start(); - var_dump($variable); - $dumpedvariable = ob_get_contents(); - ob_end_clean(); - return $dumpedvariable; +function string_var_dump($variable) +{ + if (version_compare(PHP_VERSION, '4.3.0', '>=')) { + return print_r($variable, true); + } + ob_start(); + var_dump($variable); + $dumpedvariable = ob_get_contents(); + ob_end_clean(); + + return $dumpedvariable; } -function table_var_dump($variable, $wrap_in_td=false, $encoding='ISO-8859-1') { - $returnstring = ''; - switch (gettype($variable)) { - case 'array': - $returnstring .= ($wrap_in_td ? '' : ''); - $returnstring .= ''; - foreach ($variable as $key => $value) { - $returnstring .= ''."\n"; - $returnstring .= ''."\n".''."\n"; - } else { - $returnstring .= ''."\n".''."\n"; - } - } else { - $returnstring .= ''."\n".table_var_dump($value, true, $encoding).''."\n"; - } - } - $returnstring .= '
'.str_replace("\x00", ' ', $key).''.gettype($value); - if (is_array($value)) { - $returnstring .= ' ('.count($value).')'; - } elseif (is_string($value)) { - $returnstring .= ' ('.strlen($value).')'; - } - //if (($key == 'data') && isset($variable['image_mime']) && isset($variable['dataoffset'])) { - if (($key == 'data') && isset($variable['image_mime'])) { - $imageinfo = array(); - if ($imagechunkcheck = getid3_lib::GetDataImageSize($value, $imageinfo)) { - $returnstring .= '
invalid image data
'."\n"; - $returnstring .= ($wrap_in_td ? ''."\n" : ''); - break; +function table_var_dump($variable, $wrap_in_td = false, $encoding = 'ISO-8859-1') +{ + $returnstring = ''; + switch (gettype($variable)) { + case 'array': + $returnstring .= ($wrap_in_td ? '' : ''); + $returnstring .= ''; + foreach ($variable as $key => $value) { + $returnstring .= ''."\n"; + $returnstring .= ''."\n".''."\n"; + } else { + $returnstring .= ''."\n".''."\n"; + } + } else { + $returnstring .= ''."\n".table_var_dump($value, true, $encoding).''."\n"; + } + } + $returnstring .= '
'.str_replace("\x00", ' ', $key).''.gettype($value); + if (is_array($value)) { + $returnstring .= ' ('.count($value).')'; + } elseif (is_string($value)) { + $returnstring .= ' ('.strlen($value).')'; + } + //if (($key == 'data') && isset($variable['image_mime']) && isset($variable['dataoffset'])) { + if (($key == 'data') && isset($variable['image_mime'])) { + $imageinfo = []; + if ($imagechunkcheck = getid3_lib::GetDataImageSize($value, $imageinfo)) { + $returnstring .= '
invalid image data
'."\n"; + $returnstring .= ($wrap_in_td ? ''."\n" : ''); + break; - case 'boolean': - $returnstring .= ($wrap_in_td ? '' : '').($variable ? 'TRUE' : 'FALSE').($wrap_in_td ? ''."\n" : ''); - break; + case 'boolean': + $returnstring .= ($wrap_in_td ? '' : '').($variable ? 'TRUE' : 'FALSE').($wrap_in_td ? ''."\n" : ''); + break; - case 'integer': - $returnstring .= ($wrap_in_td ? '' : '').$variable.($wrap_in_td ? ''."\n" : ''); - break; + case 'integer': + $returnstring .= ($wrap_in_td ? '' : '').$variable.($wrap_in_td ? ''."\n" : ''); + break; - case 'double': - case 'float': - $returnstring .= ($wrap_in_td ? '' : '').$variable.($wrap_in_td ? ''."\n" : ''); - break; + case 'double': + case 'float': + $returnstring .= ($wrap_in_td ? '' : '').$variable.($wrap_in_td ? ''."\n" : ''); + break; - case 'object': - case 'null': - $returnstring .= ($wrap_in_td ? '' : '').string_var_dump($variable).($wrap_in_td ? ''."\n" : ''); - break; + case 'object': + case 'null': + $returnstring .= ($wrap_in_td ? '' : '').string_var_dump($variable).($wrap_in_td ? ''."\n" : ''); + break; - case 'string': - $returnstring = htmlentities($variable, ENT_QUOTES | ENT_SUBSTITUTE, $encoding); - $returnstring = ($wrap_in_td ? '' : '').nl2br($returnstring).($wrap_in_td ? ''."\n" : ''); - break; + case 'string': + $returnstring = htmlentities($variable, ENT_QUOTES | ENT_SUBSTITUTE, $encoding); + $returnstring = ($wrap_in_td ? '' : '').nl2br($returnstring).($wrap_in_td ? ''."\n" : ''); + break; - default: - $imageinfo = array(); - if (($imagechunkcheck = getid3_lib::GetDataImageSize($variable, $imageinfo)) && ($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) { - $returnstring .= ($wrap_in_td ? '' : ''); - $returnstring .= ''; - $returnstring .= ''."\n"; - $returnstring .= ''."\n"; - $returnstring .= ''."\n"; - $returnstring .= '
type'.getid3_lib::ImageTypesLookup($imagechunkcheck[2]).'
width'.number_format($imagechunkcheck[0]).' px
height'.number_format($imagechunkcheck[1]).' px
size'.number_format(strlen($variable)).' bytes
'."\n"; - $returnstring .= ($wrap_in_td ? ''."\n" : ''); - } else { - $returnstring .= ($wrap_in_td ? '' : '').nl2br(htmlspecialchars(str_replace("\x00", ' ', $variable))).($wrap_in_td ? ''."\n" : ''); - } - break; - } - return $returnstring; + default: + $imageinfo = []; + if (($imagechunkcheck = getid3_lib::GetDataImageSize($variable, $imageinfo)) && ($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) { + $returnstring .= ($wrap_in_td ? '' : ''); + $returnstring .= ''; + $returnstring .= ''."\n"; + $returnstring .= ''."\n"; + $returnstring .= ''."\n"; + $returnstring .= '
type'.getid3_lib::ImageTypesLookup($imagechunkcheck[2]).'
width'.number_format($imagechunkcheck[0]).' px
height'.number_format($imagechunkcheck[1]).' px
size'.number_format(strlen($variable)).' bytes
'."\n"; + $returnstring .= ($wrap_in_td ? ''."\n" : ''); + } else { + $returnstring .= ($wrap_in_td ? '' : '').nl2br(htmlspecialchars(str_replace("\x00", ' ', $variable))).($wrap_in_td ? ''."\n" : ''); + } + break; + } + + return $returnstring; } +function NiceDisplayFiletypeFormat(&$fileinfo) +{ + if (empty($fileinfo['fileformat'])) { + return '-'; + } -function NiceDisplayFiletypeFormat(&$fileinfo) { + $output = $fileinfo['fileformat']; + if (empty($fileinfo['video']['dataformat']) && empty($fileinfo['audio']['dataformat'])) { + return $output; // 'gif' + } + if (empty($fileinfo['video']['dataformat']) && ! empty($fileinfo['audio']['dataformat'])) { + if ($fileinfo['fileformat'] == $fileinfo['audio']['dataformat']) { + return $output; // 'mp3' + } + $output .= '.'.$fileinfo['audio']['dataformat']; // 'ogg.flac' - if (empty($fileinfo['fileformat'])) { - return '-'; - } + return $output; + } + if (! empty($fileinfo['video']['dataformat']) && empty($fileinfo['audio']['dataformat'])) { + if ($fileinfo['fileformat'] == $fileinfo['video']['dataformat']) { + return $output; // 'mpeg' + } + $output .= '.'.$fileinfo['video']['dataformat']; // 'riff.avi' - $output = $fileinfo['fileformat']; - if (empty($fileinfo['video']['dataformat']) && empty($fileinfo['audio']['dataformat'])) { - return $output; // 'gif' - } - if (empty($fileinfo['video']['dataformat']) && !empty($fileinfo['audio']['dataformat'])) { - if ($fileinfo['fileformat'] == $fileinfo['audio']['dataformat']) { - return $output; // 'mp3' - } - $output .= '.'.$fileinfo['audio']['dataformat']; // 'ogg.flac' - return $output; - } - if (!empty($fileinfo['video']['dataformat']) && empty($fileinfo['audio']['dataformat'])) { - if ($fileinfo['fileformat'] == $fileinfo['video']['dataformat']) { - return $output; // 'mpeg' - } - $output .= '.'.$fileinfo['video']['dataformat']; // 'riff.avi' - return $output; - } - if ($fileinfo['video']['dataformat'] == $fileinfo['audio']['dataformat']) { - if ($fileinfo['fileformat'] == $fileinfo['video']['dataformat']) { - return $output; // 'real' - } - $output .= '.'.$fileinfo['video']['dataformat']; // any examples? - return $output; - } - $output .= '.'.$fileinfo['video']['dataformat']; - $output .= '.'.$fileinfo['audio']['dataformat']; // asf.wmv.wma - return $output; + return $output; + } + if ($fileinfo['video']['dataformat'] == $fileinfo['audio']['dataformat']) { + if ($fileinfo['fileformat'] == $fileinfo['video']['dataformat']) { + return $output; // 'real' + } + $output .= '.'.$fileinfo['video']['dataformat']; // any examples? + return $output; + } + $output .= '.'.$fileinfo['video']['dataformat']; + $output .= '.'.$fileinfo['audio']['dataformat']; // asf.wmv.wma + + return $output; } -function MoreNaturalSort($ar1, $ar2) { - if ($ar1 === $ar2) { - return 0; - } - $len1 = strlen($ar1); - $len2 = strlen($ar2); - $shortest = min($len1, $len2); - if (substr($ar1, 0, $shortest) === substr($ar2, 0, $shortest)) { - // the shorter argument is the beginning of the longer one, like "str" and "string" - if ($len1 < $len2) { - return -1; - } elseif ($len1 > $len2) { - return 1; - } - return 0; - } - $ar1 = RemoveAccents(strtolower(trim($ar1))); - $ar2 = RemoveAccents(strtolower(trim($ar2))); - $translatearray = array('\''=>'', '"'=>'', '_'=>' ', '('=>'', ')'=>'', '-'=>' ', ' '=>' ', '.'=>'', ','=>''); - foreach ($translatearray as $key => $val) { - $ar1 = str_replace($key, $val, $ar1); - $ar2 = str_replace($key, $val, $ar2); - } +function MoreNaturalSort($ar1, $ar2) +{ + if ($ar1 === $ar2) { + return 0; + } + $len1 = strlen($ar1); + $len2 = strlen($ar2); + $shortest = min($len1, $len2); + if (substr($ar1, 0, $shortest) === substr($ar2, 0, $shortest)) { + // the shorter argument is the beginning of the longer one, like "str" and "string" + if ($len1 < $len2) { + return -1; + } elseif ($len1 > $len2) { + return 1; + } - if ($ar1 < $ar2) { - return -1; - } elseif ($ar1 > $ar2) { - return 1; - } - return 0; + return 0; + } + $ar1 = RemoveAccents(strtolower(trim($ar1))); + $ar2 = RemoveAccents(strtolower(trim($ar2))); + $translatearray = ['\''=>'', '"'=>'', '_'=>' ', '('=>'', ')'=>'', '-'=>' ', ' '=>' ', '.'=>'', ','=>'']; + foreach ($translatearray as $key => $val) { + $ar1 = str_replace($key, $val, $ar1); + $ar2 = str_replace($key, $val, $ar2); + } + + if ($ar1 < $ar2) { + return -1; + } elseif ($ar1 > $ar2) { + return 1; + } + + return 0; } -function PoweredBygetID3($string='') { - global $getID3; - if (!$string) { - $string = '
Powered by getID3() v
http://www.getid3.org/

Running on PHP v'.phpversion().' ('.(ceil(log(PHP_INT_MAX, 2)) + 1).'-bit)
'; - } - return str_replace('', $getID3->version(), $string); +function PoweredBygetID3($string = '') +{ + global $getID3; + if (! $string) { + $string = '
Powered by getID3() v
http://www.getid3.org/

Running on PHP v'.phpversion().' ('.(ceil(log(PHP_INT_MAX, 2)) + 1).'-bit)
'; + } + + return str_replace('', $getID3->version(), $string); } diff --git a/app/Library/getid3/demos/demo.cache.dbm.php b/app/Library/getid3/demos/demo.cache.dbm.php index 68523c99..095f0255 100644 --- a/app/Library/getid3/demos/demo.cache.dbm.php +++ b/app/Library/getid3/demos/demo.cache.dbm.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -15,8 +16,7 @@ die('Due to a security issue, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in '.$_SERVER['PHP_SELF']); - -require_once('../getid3/getid3.php'); +require_once '../getid3/getid3.php'; getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'extension.cache.dbm.php', __FILE__, true); $getID3 = new getID3_cached_dbm('db3', '/zimweb/test/test.dbm', '/zimweb/test/test.lock'); diff --git a/app/Library/getid3/demos/demo.cache.mysql.php b/app/Library/getid3/demos/demo.cache.mysql.php index e2ca9c9e..32423fd8 100644 --- a/app/Library/getid3/demos/demo.cache.mysql.php +++ b/app/Library/getid3/demos/demo.cache.mysql.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -15,9 +16,8 @@ die('Due to a security issue, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in '.$_SERVER['PHP_SELF']); - -require_once('../getid3/getid3.php'); -require_once('../getid3/getid3.lib.php'); +require_once '../getid3/getid3.php'; +require_once '../getid3/getid3.lib.php'; getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'extension.cache.mysql.php', __FILE__, true); $getID3 = new getID3_cached_mysql('localhost', 'database', 'username', 'password'); diff --git a/app/Library/getid3/demos/demo.joinmp3.php b/app/Library/getid3/demos/demo.joinmp3.php index b819e930..b979d4d7 100644 --- a/app/Library/getid3/demos/demo.joinmp3.php +++ b/app/Library/getid3/demos/demo.joinmp3.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,7 +15,6 @@ // /// ///////////////////////////////////////////////////////////////// - // sample usage: // $FilenameOut = 'combined.mp3'; // $FilenamesIn[] = 'first.mp3'; // filename with no start/length parameters @@ -32,104 +32,97 @@ // Could also be called like this to extract portion from single file: // CombineMultipleMP3sTo('sample.mp3', array(array('input.mp3', 0, 30))); // extract first 30 seconds of audio +function CombineMultipleMP3sTo($FilenameOut, $FilenamesIn) +{ + foreach ($FilenamesIn as $nextinputfilename) { + if (is_array($nextinputfilename)) { + $nextinputfilename = $nextinputfilename[0]; + } + if (! is_readable($nextinputfilename)) { + echo 'Cannot read "'.$nextinputfilename.'"
'; -function CombineMultipleMP3sTo($FilenameOut, $FilenamesIn) { + return false; + } + } + if ((file_exists($FilenameOut) && ! is_writable($FilenameOut)) || (! file_exists($FilenameOut) && ! is_writable(dirname($FilenameOut)))) { + echo 'Cannot write "'.$FilenameOut.'"
'; - foreach ($FilenamesIn as $nextinputfilename) { - if (is_array($nextinputfilename)) { - $nextinputfilename = $nextinputfilename[0]; - } - if (!is_readable($nextinputfilename)) { - echo 'Cannot read "'.$nextinputfilename.'"
'; - return false; - } - } - if ((file_exists($FilenameOut) && !is_writeable($FilenameOut)) || (!file_exists($FilenameOut) && !is_writeable(dirname($FilenameOut)))) { - echo 'Cannot write "'.$FilenameOut.'"
'; - return false; - } + return false; + } - require_once(dirname(__FILE__).'/../getid3/getid3.php'); - ob_start(); - if ($fp_output = fopen($FilenameOut, 'wb')) { + require_once dirname(__FILE__).'/../getid3/getid3.php'; + ob_start(); + if ($fp_output = fopen($FilenameOut, 'wb')) { + ob_end_clean(); + // Initialize getID3 engine + $getID3 = new getID3; + foreach ($FilenamesIn as $nextinputfilename) { + $startoffset = 0; + $length_seconds = 0; + if (is_array($nextinputfilename)) { + @list($nextinputfilename, $startoffset, $length_seconds) = $nextinputfilename; + } + $CurrentFileInfo = $getID3->analyze($nextinputfilename); + if ($CurrentFileInfo['fileformat'] == 'mp3') { + ob_start(); + if ($fp_source = fopen($nextinputfilename, 'rb')) { + ob_end_clean(); + $CurrentOutputPosition = ftell($fp_output); - ob_end_clean(); - // Initialize getID3 engine - $getID3 = new getID3; - foreach ($FilenamesIn as $nextinputfilename) { - $startoffset = 0; - $length_seconds = 0; - if (is_array($nextinputfilename)) { - @list($nextinputfilename, $startoffset, $length_seconds) = $nextinputfilename; - } - $CurrentFileInfo = $getID3->analyze($nextinputfilename); - if ($CurrentFileInfo['fileformat'] == 'mp3') { + // copy audio data from first file + $start_offset_bytes = $CurrentFileInfo['avdataoffset']; + if ($startoffset > 0) { // start X seconds from start of audio + $start_offset_bytes = $CurrentFileInfo['avdataoffset'] + round($CurrentFileInfo['bitrate'] / 8 * $startoffset); + } elseif ($startoffset < 0) { // start X seconds from end of audio + $start_offset_bytes = $CurrentFileInfo['avdataend'] + round($CurrentFileInfo['bitrate'] / 8 * $startoffset); + } + $start_offset_bytes = max($CurrentFileInfo['avdataoffset'], min($CurrentFileInfo['avdataend'], $start_offset_bytes)); - ob_start(); - if ($fp_source = fopen($nextinputfilename, 'rb')) { + $end_offset_bytes = $CurrentFileInfo['avdataend']; + if ($length_seconds > 0) { // seconds from start of audio + $end_offset_bytes = $start_offset_bytes + round($CurrentFileInfo['bitrate'] / 8 * $length_seconds); + } elseif ($length_seconds < 0) { // seconds from start of audio + $end_offset_bytes = $CurrentFileInfo['avdataend'] + round($CurrentFileInfo['bitrate'] / 8 * $startoffset); + } + $end_offset_bytes = max($CurrentFileInfo['avdataoffset'], min($CurrentFileInfo['avdataend'], $end_offset_bytes)); - ob_end_clean(); - $CurrentOutputPosition = ftell($fp_output); + if ($end_offset_bytes <= $start_offset_bytes) { + echo 'failed to copy '.$nextinputfilename.' from '.$startoffset.'-seconds start for '.$length_seconds.'-seconds length (not enough data)'; + fclose($fp_source); + fclose($fp_output); - // copy audio data from first file - $start_offset_bytes = $CurrentFileInfo['avdataoffset']; - if ($startoffset > 0) { // start X seconds from start of audio - $start_offset_bytes = $CurrentFileInfo['avdataoffset'] + round($CurrentFileInfo['bitrate'] / 8 * $startoffset); - } elseif ($startoffset < 0) { // start X seconds from end of audio - $start_offset_bytes = $CurrentFileInfo['avdataend'] + round($CurrentFileInfo['bitrate'] / 8 * $startoffset); - } - $start_offset_bytes = max($CurrentFileInfo['avdataoffset'], min($CurrentFileInfo['avdataend'], $start_offset_bytes)); + return false; + } - $end_offset_bytes = $CurrentFileInfo['avdataend']; - if ($length_seconds > 0) { // seconds from start of audio - $end_offset_bytes = $start_offset_bytes + round($CurrentFileInfo['bitrate'] / 8 * $length_seconds); - } elseif ($length_seconds < 0) { // seconds from start of audio - $end_offset_bytes = $CurrentFileInfo['avdataend'] + round($CurrentFileInfo['bitrate'] / 8 * $startoffset); - } - $end_offset_bytes = max($CurrentFileInfo['avdataoffset'], min($CurrentFileInfo['avdataend'], $end_offset_bytes)); + fseek($fp_source, $start_offset_bytes, SEEK_SET); + while (! feof($fp_source) && (ftell($fp_source) < $end_offset_bytes)) { + fwrite($fp_output, fread($fp_source, min(32768, $end_offset_bytes - ftell($fp_source)))); + } + fclose($fp_source); + } else { + $errormessage = ob_get_contents(); + ob_end_clean(); + echo 'failed to open '.$nextinputfilename.' for reading'; + fclose($fp_output); - if ($end_offset_bytes <= $start_offset_bytes) { - echo 'failed to copy '.$nextinputfilename.' from '.$startoffset.'-seconds start for '.$length_seconds.'-seconds length (not enough data)'; - fclose($fp_source); - fclose($fp_output); - return false; - } + return false; + } + } else { + echo $nextinputfilename.' is not MP3 format'; + fclose($fp_output); - fseek($fp_source, $start_offset_bytes, SEEK_SET); - while (!feof($fp_source) && (ftell($fp_source) < $end_offset_bytes)) { - fwrite($fp_output, fread($fp_source, min(32768, $end_offset_bytes - ftell($fp_source)))); - } - fclose($fp_source); + return false; + } + } + } else { + $errormessage = ob_get_contents(); + ob_end_clean(); + echo 'failed to open '.$FilenameOut.' for writing'; - } else { + return false; + } - $errormessage = ob_get_contents(); - ob_end_clean(); - echo 'failed to open '.$nextinputfilename.' for reading'; - fclose($fp_output); - return false; + fclose($fp_output); - } - - } else { - - echo $nextinputfilename.' is not MP3 format'; - fclose($fp_output); - return false; - - } - - } - - } else { - - $errormessage = ob_get_contents(); - ob_end_clean(); - echo 'failed to open '.$FilenameOut.' for writing'; - return false; - - } - - fclose($fp_output); - return true; + return true; } diff --git a/app/Library/getid3/demos/demo.mimeonly.php b/app/Library/getid3/demos/demo.mimeonly.php index 9a381780..ba58b35b 100644 --- a/app/Library/getid3/demos/demo.mimeonly.php +++ b/app/Library/getid3/demos/demo.mimeonly.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -15,60 +16,57 @@ die('Due to a security issue, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in '.$_SERVER['PHP_SELF']); - echo ''; echo 'getID3 demos - MIME type only'; -if (!empty($_REQUEST['filename'])) { - - echo 'The file "'.htmlentities($_REQUEST['filename']).'" has a MIME type of "'.htmlentities(GetMIMEtype($_REQUEST['filename'])).'"'; - +if (! empty($_REQUEST['filename'])) { + echo 'The file "'.htmlentities($_REQUEST['filename']).'" has a MIME type of "'.htmlentities(GetMIMEtype($_REQUEST['filename'])).'"'; } else { - - echo 'Usage: '.htmlentities($_SERVER['PHP_SELF']).'?filename=filename.ext'; - + echo 'Usage: '.htmlentities($_SERVER['PHP_SELF']).'?filename=filename.ext'; } +function GetMIMEtype($filename) +{ + $filename = realpath($filename); + if (! file_exists($filename)) { + echo 'File does not exist: "'.htmlentities($filename).'"
'; -function GetMIMEtype($filename) { - $filename = realpath($filename); - if (!file_exists($filename)) { - echo 'File does not exist: "'.htmlentities($filename).'"
'; - return ''; - } elseif (!is_readable($filename)) { - echo 'File is not readable: "'.htmlentities($filename).'"
'; - return ''; - } + return ''; + } elseif (! is_readable($filename)) { + echo 'File is not readable: "'.htmlentities($filename).'"
'; - // include getID3() library (can be in a different directory if full path is specified) - require_once('../getid3/getid3.php'); - // Initialize getID3 engine - $getID3 = new getID3; + return ''; + } - $DeterminedMIMEtype = ''; - if ($fp = fopen($filename, 'rb')) { - $getID3->openfile($filename); - if (empty($getID3->info['error'])) { + // include getID3() library (can be in a different directory if full path is specified) + require_once '../getid3/getid3.php'; + // Initialize getID3 engine + $getID3 = new getID3; - // ID3v2 is the only tag format that might be prepended in front of files, and it's non-trivial to skip, easier just to parse it and know where to skip to - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); - $getid3_id3v2 = new getid3_id3v2($getID3); - $getid3_id3v2->Analyze(); + $DeterminedMIMEtype = ''; + if ($fp = fopen($filename, 'rb')) { + $getID3->openfile($filename); + if (empty($getID3->info['error'])) { - fseek($fp, $getID3->info['avdataoffset'], SEEK_SET); - $formattest = fread($fp, 16); // 16 bytes is sufficient for any format except ISO CD-image - fclose($fp); + // ID3v2 is the only tag format that might be prepended in front of files, and it's non-trivial to skip, easier just to parse it and know where to skip to + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); + $getid3_id3v2 = new getid3_id3v2($getID3); + $getid3_id3v2->Analyze(); - $DeterminedFormatInfo = $getID3->GetFileFormat($formattest); - $DeterminedMIMEtype = $DeterminedFormatInfo['mime_type']; + fseek($fp, $getID3->info['avdataoffset'], SEEK_SET); + $formattest = fread($fp, 16); // 16 bytes is sufficient for any format except ISO CD-image + fclose($fp); - } else { - echo 'Failed to getID3->openfile "'.htmlentities($filename).'"
'; - } - } else { - echo 'Failed to fopen "'.htmlentities($filename).'"
'; - } - return $DeterminedMIMEtype; + $DeterminedFormatInfo = $getID3->GetFileFormat($formattest); + $DeterminedMIMEtype = $DeterminedFormatInfo['mime_type']; + } else { + echo 'Failed to getID3->openfile "'.htmlentities($filename).'"
'; + } + } else { + echo 'Failed to fopen "'.htmlentities($filename).'"
'; + } + + return $DeterminedMIMEtype; } -echo ''; \ No newline at end of file +echo ''; diff --git a/app/Library/getid3/demos/demo.mp3header.php b/app/Library/getid3/demos/demo.mp3header.php index ad5a3d8a..8d39c927 100644 --- a/app/Library/getid3/demos/demo.mp3header.php +++ b/app/Library/getid3/demos/demo.mp3header.php @@ -1,1349 +1,1449 @@ '; - foreach ($variable as $key => $value) { - $returnstring .= ''.str_replace(chr(0), ' ', $key).''; - $returnstring .= ''.gettype($value); - if (is_array($value)) { - $returnstring .= ' ('.count($value).')'; - } elseif (is_string($value)) { - $returnstring .= ' ('.strlen($value).')'; - } - if (($key == 'data') && isset($variable['image_mime']) && isset($variable['dataoffset'])) { - require_once(GETID3_INCLUDEPATH.'getid3.getimagesize.php'); - $imageinfo = array(); - if ($imagechunkcheck = GetDataImageSize($value, $imageinfo)) { - $DumpedImageSRC = (!empty($_REQUEST['filename']) ? $_REQUEST['filename'] : '.getid3').'.'.$variable['dataoffset'].'.'.ImageTypesLookup($imagechunkcheck[2]); - if ($tempimagefile = fopen($DumpedImageSRC, 'wb')) { - fwrite($tempimagefile, $value); - fclose($tempimagefile); - } - $returnstring .= ''; - } else { - $returnstring .= 'invalid image data'; - } - } else { - $returnstring .= ''.table_var_dump($value).''; - } - } - $returnstring .= ''; - break; +if (! function_exists('table_var_dump')) { + function table_var_dump($variable) + { + $returnstring = ''; + switch (gettype($variable)) { + case 'array': + $returnstring .= ''; + foreach ($variable as $key => $value) { + $returnstring .= ''; + $returnstring .= ''; + } else { + $returnstring .= ''; + } + } else { + $returnstring .= ''; + } + } + $returnstring .= '
'.str_replace(chr(0), ' ', $key).''.gettype($value); + if (is_array($value)) { + $returnstring .= ' ('.count($value).')'; + } elseif (is_string($value)) { + $returnstring .= ' ('.strlen($value).')'; + } + if (($key == 'data') && isset($variable['image_mime']) && isset($variable['dataoffset'])) { + require_once GETID3_INCLUDEPATH.'getid3.getimagesize.php'; + $imageinfo = []; + if ($imagechunkcheck = GetDataImageSize($value, $imageinfo)) { + $DumpedImageSRC = (! empty($_REQUEST['filename']) ? $_REQUEST['filename'] : '.getid3').'.'.$variable['dataoffset'].'.'.ImageTypesLookup($imagechunkcheck[2]); + if ($tempimagefile = fopen($DumpedImageSRC, 'wb')) { + fwrite($tempimagefile, $value); + fclose($tempimagefile); + } + $returnstring .= '
invalid image data
'.table_var_dump($value).'
'; + break; - case 'boolean': - $returnstring .= ($variable ? 'TRUE' : 'FALSE'); - break; + case 'boolean': + $returnstring .= ($variable ? 'TRUE' : 'FALSE'); + break; - case 'integer': - case 'double': - case 'float': - $returnstring .= $variable; - break; + case 'integer': + case 'double': + case 'float': + $returnstring .= $variable; + break; - case 'object': - case 'null': - $returnstring .= string_var_dump($variable); - break; + case 'object': + case 'null': + $returnstring .= string_var_dump($variable); + break; - case 'string': - $variable = str_replace(chr(0), ' ', $variable); - $varlen = strlen($variable); - for ($i = 0; $i < $varlen; $i++) { - if (preg_match('#['.chr(0x0A).chr(0x0D).' -;0-9A-Za-z]#', $variable{$i})) { - $returnstring .= $variable{$i}; - } else { - $returnstring .= '&#'.str_pad(ord($variable{$i}), 3, '0', STR_PAD_LEFT).';'; - } - } - $returnstring = nl2br($returnstring); - break; + case 'string': + $variable = str_replace(chr(0), ' ', $variable); + $varlen = strlen($variable); + for ($i = 0; $i < $varlen; $i++) { + if (preg_match('#['.chr(0x0A).chr(0x0D).' -;0-9A-Za-z]#', $variable[$i])) { + $returnstring .= $variable[$i]; + } else { + $returnstring .= '&#'.str_pad(ord($variable[$i]), 3, '0', STR_PAD_LEFT).';'; + } + } + $returnstring = nl2br($returnstring); + break; - default: - require_once(GETID3_INCLUDEPATH.'getid3.getimagesize.php'); - $imageinfo = array(); - if (($imagechunkcheck = GetDataImageSize(substr($variable, 0, 32768), $imageinfo)) && ($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) { - $returnstring .= ''; - $returnstring .= ''; - $returnstring .= ''; - $returnstring .= ''; - $returnstring .= '
type'.ImageTypesLookup($imagechunkcheck[2]).'
width'.number_format($imagechunkcheck[0]).' px
height'.number_format($imagechunkcheck[1]).' px
size'.number_format(strlen($variable)).' bytes
'; - } else { - $returnstring .= nl2br(htmlspecialchars(str_replace(chr(0), ' ', $variable))); - } - break; - } - return $returnstring; - } + default: + require_once GETID3_INCLUDEPATH.'getid3.getimagesize.php'; + $imageinfo = []; + if (($imagechunkcheck = GetDataImageSize(substr($variable, 0, 32768), $imageinfo)) && ($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) { + $returnstring .= ''; + $returnstring .= ''; + $returnstring .= ''; + $returnstring .= ''; + $returnstring .= '
type'.ImageTypesLookup($imagechunkcheck[2]).'
width'.number_format($imagechunkcheck[0]).' px
height'.number_format($imagechunkcheck[1]).' px
size'.number_format(strlen($variable)).' bytes
'; + } else { + $returnstring .= nl2br(htmlspecialchars(str_replace(chr(0), ' ', $variable))); + } + break; + } + + return $returnstring; + } } -if (!function_exists('string_var_dump')) { - function string_var_dump($variable) { - if (version_compare(PHP_VERSION, '4.3.0', '>=')) { - return print_r($variable, true); - } - ob_start(); - var_dump($variable); - $dumpedvariable = ob_get_contents(); - ob_end_clean(); - return $dumpedvariable; - } +if (! function_exists('string_var_dump')) { + function string_var_dump($variable) + { + if (version_compare(PHP_VERSION, '4.3.0', '>=')) { + return print_r($variable, true); + } + ob_start(); + var_dump($variable); + $dumpedvariable = ob_get_contents(); + ob_end_clean(); + + return $dumpedvariable; + } } -if (!function_exists('fileextension')) { - function fileextension($filename, $numextensions=1) { - if (strstr($filename, '.')) { - $reversedfilename = strrev($filename); - $offset = 0; - for ($i = 0; $i < $numextensions; $i++) { - $offset = strpos($reversedfilename, '.', $offset + 1); - if ($offset === false) { - return ''; - } - } - return strrev(substr($reversedfilename, 0, $offset)); - } - return ''; - } +if (! function_exists('fileextension')) { + function fileextension($filename, $numextensions = 1) + { + if (strstr($filename, '.')) { + $reversedfilename = strrev($filename); + $offset = 0; + for ($i = 0; $i < $numextensions; $i++) { + $offset = strpos($reversedfilename, '.', $offset + 1); + if ($offset === false) { + return ''; + } + } + + return strrev(substr($reversedfilename, 0, $offset)); + } + + return ''; + } } -if (!function_exists('RemoveAccents')) { - function RemoveAccents($string) { - // return strtr($string, 'ŠŒŽšœžŸ¥µÀÃÂÃÄÅÆÇÈÉÊËÌÃÃŽÃÃÑÒÓÔÕÖØÙÚÛÜÃßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ', 'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy'); - // Revised version by marksteward@hotmail.com - return strtr(strtr($string, 'ŠŽšžŸÀÃÂÃÄÅÇÈÉÊËÌÃÃŽÃÑÒÓÔÕÖØÙÚÛÜÃàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'), array('Þ' => 'TH', 'þ' => 'th', 'Ã' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'ÂŒ' => 'OE', 'Âœ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u')); - } +if (! function_exists('RemoveAccents')) { + function RemoveAccents($string) + { + // return strtr($string, 'ŠŒŽšœžŸ¥µÀÃÂÃÄÅÆÇÈÉÊËÌÃÃŽÃÃÑÒÓÔÕÖØÙÚÛÜÃßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ', 'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy'); + // Revised version by marksteward@hotmail.com + return strtr(strtr($string, 'ŠŽšžŸÀÃÂÃÄÅÇÈÉÊËÌÃÃŽÃÑÒÓÔÕÖØÙÚÛÜÃàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'), ['Þ' => 'TH', 'þ' => 'th', 'Ã' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'ÂŒ' => 'OE', 'Âœ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u']); + } } -if (!function_exists('MoreNaturalSort')) { - function MoreNaturalSort($ar1, $ar2) { - if ($ar1 === $ar2) { - return 0; - } - $len1 = strlen($ar1); - $len2 = strlen($ar2); - $shortest = min($len1, $len2); - if (substr($ar1, 0, $shortest) === substr($ar2, 0, $shortest)) { - // the shorter argument is the beginning of the longer one, like "str" and "string" - if ($len1 < $len2) { - return -1; - } elseif ($len1 > $len2) { - return 1; - } - return 0; - } - $ar1 = RemoveAccents(strtolower(trim($ar1))); - $ar2 = RemoveAccents(strtolower(trim($ar2))); - $translatearray = array('\''=>'', '"'=>'', '_'=>' ', '('=>'', ')'=>'', '-'=>' ', ' '=>' ', '.'=>'', ','=>''); - foreach ($translatearray as $key => $val) { - $ar1 = str_replace($key, $val, $ar1); - $ar2 = str_replace($key, $val, $ar2); - } +if (! function_exists('MoreNaturalSort')) { + function MoreNaturalSort($ar1, $ar2) + { + if ($ar1 === $ar2) { + return 0; + } + $len1 = strlen($ar1); + $len2 = strlen($ar2); + $shortest = min($len1, $len2); + if (substr($ar1, 0, $shortest) === substr($ar2, 0, $shortest)) { + // the shorter argument is the beginning of the longer one, like "str" and "string" + if ($len1 < $len2) { + return -1; + } elseif ($len1 > $len2) { + return 1; + } - if ($ar1 < $ar2) { - return -1; - } elseif ($ar1 > $ar2) { - return 1; - } - return 0; - } + return 0; + } + $ar1 = RemoveAccents(strtolower(trim($ar1))); + $ar2 = RemoveAccents(strtolower(trim($ar2))); + $translatearray = ['\''=>'', '"'=>'', '_'=>' ', '('=>'', ')'=>'', '-'=>' ', ' '=>' ', '.'=>'', ','=>'']; + foreach ($translatearray as $key => $val) { + $ar1 = str_replace($key, $val, $ar1); + $ar2 = str_replace($key, $val, $ar2); + } + + if ($ar1 < $ar2) { + return -1; + } elseif ($ar1 > $ar2) { + return 1; + } + + return 0; + } } -if (!function_exists('trunc')) { - function trunc($floatnumber) { - // truncates a floating-point number at the decimal point - // returns int (if possible, otherwise float) - if ($floatnumber >= 1) { - $truncatednumber = floor($floatnumber); - } elseif ($floatnumber <= -1) { - $truncatednumber = ceil($floatnumber); - } else { - $truncatednumber = 0; - } - if ($truncatednumber <= pow(2, 30)) { - $truncatednumber = (int) $truncatednumber; - } - return $truncatednumber; - } +if (! function_exists('trunc')) { + function trunc($floatnumber) + { + // truncates a floating-point number at the decimal point + // returns int (if possible, otherwise float) + if ($floatnumber >= 1) { + $truncatednumber = floor($floatnumber); + } elseif ($floatnumber <= -1) { + $truncatednumber = ceil($floatnumber); + } else { + $truncatednumber = 0; + } + if ($truncatednumber <= pow(2, 30)) { + $truncatednumber = (int) $truncatednumber; + } + + return $truncatednumber; + } } -if (!function_exists('CastAsInt')) { - function CastAsInt($floatnum) { - // convert to float if not already - $floatnum = (float) $floatnum; +if (! function_exists('CastAsInt')) { + function CastAsInt($floatnum) + { + // convert to float if not already + $floatnum = (float) $floatnum; - // convert a float to type int, only if possible - if (trunc($floatnum) == $floatnum) { - // it's not floating point - if ($floatnum <= pow(2, 30)) { - // it's within int range - $floatnum = (int) $floatnum; - } - } - return $floatnum; - } + // convert a float to type int, only if possible + if (trunc($floatnum) == $floatnum) { + // it's not floating point + if ($floatnum <= pow(2, 30)) { + // it's within int range + $floatnum = (int) $floatnum; + } + } + + return $floatnum; + } } -if (!function_exists('getmicrotime')) { - function getmicrotime() { - list($usec, $sec) = explode(' ', microtime()); - return ((float) $usec + (float) $sec); - } +if (! function_exists('getmicrotime')) { + function getmicrotime() + { + list($usec, $sec) = explode(' ', microtime()); + + return (float) $usec + (float) $sec; + } } -if (!function_exists('DecimalBinary2Float')) { - function DecimalBinary2Float($binarynumerator) { - $numerator = Bin2Dec($binarynumerator); - $denominator = Bin2Dec(str_repeat('1', strlen($binarynumerator))); - return ($numerator / $denominator); - } +if (! function_exists('DecimalBinary2Float')) { + function DecimalBinary2Float($binarynumerator) + { + $numerator = Bin2Dec($binarynumerator); + $denominator = Bin2Dec(str_repeat('1', strlen($binarynumerator))); + + return $numerator / $denominator; + } } -if (!function_exists('NormalizeBinaryPoint')) { - function NormalizeBinaryPoint($binarypointnumber, $maxbits=52) { - // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html - if (strpos($binarypointnumber, '.') === false) { - $binarypointnumber = '0.'.$binarypointnumber; - } elseif ($binarypointnumber{0} == '.') { - $binarypointnumber = '0'.$binarypointnumber; - } - $exponent = 0; - while (($binarypointnumber{0} != '1') || (substr($binarypointnumber, 1, 1) != '.')) { - if (substr($binarypointnumber, 1, 1) == '.') { - $exponent--; - $binarypointnumber = substr($binarypointnumber, 2, 1).'.'.substr($binarypointnumber, 3); - } else { - $pointpos = strpos($binarypointnumber, '.'); - $exponent += ($pointpos - 1); - $binarypointnumber = str_replace('.', '', $binarypointnumber); - $binarypointnumber = $binarypointnumber{0}.'.'.substr($binarypointnumber, 1); - } - } - $binarypointnumber = str_pad(substr($binarypointnumber, 0, $maxbits + 2), $maxbits + 2, '0', STR_PAD_RIGHT); - return array('normalized'=>$binarypointnumber, 'exponent'=>(int) $exponent); - } +if (! function_exists('NormalizeBinaryPoint')) { + function NormalizeBinaryPoint($binarypointnumber, $maxbits = 52) + { + // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html + if (strpos($binarypointnumber, '.') === false) { + $binarypointnumber = '0.'.$binarypointnumber; + } elseif ($binarypointnumber[0] == '.') { + $binarypointnumber = '0'.$binarypointnumber; + } + $exponent = 0; + while (($binarypointnumber[0] != '1') || (substr($binarypointnumber, 1, 1) != '.')) { + if (substr($binarypointnumber, 1, 1) == '.') { + $exponent--; + $binarypointnumber = substr($binarypointnumber, 2, 1).'.'.substr($binarypointnumber, 3); + } else { + $pointpos = strpos($binarypointnumber, '.'); + $exponent += ($pointpos - 1); + $binarypointnumber = str_replace('.', '', $binarypointnumber); + $binarypointnumber = $binarypointnumber[0].'.'.substr($binarypointnumber, 1); + } + } + $binarypointnumber = str_pad(substr($binarypointnumber, 0, $maxbits + 2), $maxbits + 2, '0', STR_PAD_RIGHT); + + return ['normalized'=>$binarypointnumber, 'exponent'=>(int) $exponent]; + } } -if (!function_exists('Float2BinaryDecimal')) { - function Float2BinaryDecimal($floatvalue) { - // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html - $maxbits = 128; // to how many bits of precision should the calculations be taken? - $intpart = trunc($floatvalue); - $floatpart = abs($floatvalue - $intpart); - $pointbitstring = ''; - while (($floatpart != 0) && (strlen($pointbitstring) < $maxbits)) { - $floatpart *= 2; - $pointbitstring .= (string) trunc($floatpart); - $floatpart -= trunc($floatpart); - } - $binarypointnumber = decbin($intpart).'.'.$pointbitstring; - return $binarypointnumber; - } +if (! function_exists('Float2BinaryDecimal')) { + function Float2BinaryDecimal($floatvalue) + { + // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html + $maxbits = 128; // to how many bits of precision should the calculations be taken? + $intpart = trunc($floatvalue); + $floatpart = abs($floatvalue - $intpart); + $pointbitstring = ''; + while (($floatpart != 0) && (strlen($pointbitstring) < $maxbits)) { + $floatpart *= 2; + $pointbitstring .= (string) trunc($floatpart); + $floatpart -= trunc($floatpart); + } + $binarypointnumber = decbin($intpart).'.'.$pointbitstring; + + return $binarypointnumber; + } } -if (!function_exists('Float2String')) { - function Float2String($floatvalue, $bits) { - // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html - switch ($bits) { - case 32: - $exponentbits = 8; - $fractionbits = 23; - break; +if (! function_exists('Float2String')) { + function Float2String($floatvalue, $bits) + { + // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html + switch ($bits) { + case 32: + $exponentbits = 8; + $fractionbits = 23; + break; - case 64: - $exponentbits = 11; - $fractionbits = 52; - break; + case 64: + $exponentbits = 11; + $fractionbits = 52; + break; - default: - return false; - break; - } - if ($floatvalue >= 0) { - $signbit = '0'; - } else { - $signbit = '1'; - } - $normalizedbinary = NormalizeBinaryPoint(Float2BinaryDecimal($floatvalue), $fractionbits); - $biasedexponent = pow(2, $exponentbits - 1) - 1 + $normalizedbinary['exponent']; // (127 or 1023) +/- exponent - $exponentbitstring = str_pad(decbin($biasedexponent), $exponentbits, '0', STR_PAD_LEFT); - $fractionbitstring = str_pad(substr($normalizedbinary['normalized'], 2), $fractionbits, '0', STR_PAD_RIGHT); + default: + return false; + break; + } + if ($floatvalue >= 0) { + $signbit = '0'; + } else { + $signbit = '1'; + } + $normalizedbinary = NormalizeBinaryPoint(Float2BinaryDecimal($floatvalue), $fractionbits); + $biasedexponent = pow(2, $exponentbits - 1) - 1 + $normalizedbinary['exponent']; // (127 or 1023) +/- exponent + $exponentbitstring = str_pad(decbin($biasedexponent), $exponentbits, '0', STR_PAD_LEFT); + $fractionbitstring = str_pad(substr($normalizedbinary['normalized'], 2), $fractionbits, '0', STR_PAD_RIGHT); - return BigEndian2String(Bin2Dec($signbit.$exponentbitstring.$fractionbitstring), $bits % 8, false); - } + return BigEndian2String(Bin2Dec($signbit.$exponentbitstring.$fractionbitstring), $bits % 8, false); + } } -if (!function_exists('LittleEndian2Float')) { - function LittleEndian2Float($byteword) { - return BigEndian2Float(strrev($byteword)); - } +if (! function_exists('LittleEndian2Float')) { + function LittleEndian2Float($byteword) + { + return BigEndian2Float(strrev($byteword)); + } } -if (!function_exists('BigEndian2Float')) { - function BigEndian2Float($byteword) { - // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic - // http://www.psc.edu/general/software/packages/ieee/ieee.html - // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html +if (! function_exists('BigEndian2Float')) { + function BigEndian2Float($byteword) + { + // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic + // http://www.psc.edu/general/software/packages/ieee/ieee.html + // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html - $bitword = BigEndian2Bin($byteword); - $signbit = $bitword{0}; + $bitword = BigEndian2Bin($byteword); + $signbit = $bitword[0]; - switch (strlen($byteword) * 8) { - case 32: - $exponentbits = 8; - $fractionbits = 23; - break; + switch (strlen($byteword) * 8) { + case 32: + $exponentbits = 8; + $fractionbits = 23; + break; - case 64: - $exponentbits = 11; - $fractionbits = 52; - break; + case 64: + $exponentbits = 11; + $fractionbits = 52; + break; - case 80: - $exponentbits = 16; - $fractionbits = 64; - break; + case 80: + $exponentbits = 16; + $fractionbits = 64; + break; - default: - return false; - break; - } - $exponentstring = substr($bitword, 1, $exponentbits - 1); - $fractionstring = substr($bitword, $exponentbits, $fractionbits); - $exponent = Bin2Dec($exponentstring); - $fraction = Bin2Dec($fractionstring); + default: + return false; + break; + } + $exponentstring = substr($bitword, 1, $exponentbits - 1); + $fractionstring = substr($bitword, $exponentbits, $fractionbits); + $exponent = Bin2Dec($exponentstring); + $fraction = Bin2Dec($fractionstring); - if (($exponentbits == 16) && ($fractionbits == 64)) { - // 80-bit - // As used in Apple AIFF for sample_rate - // A bit of a hack, but it works ;) - return pow(2, ($exponent - 16382)) * DecimalBinary2Float($fractionstring); - } + if (($exponentbits == 16) && ($fractionbits == 64)) { + // 80-bit + // As used in Apple AIFF for sample_rate + // A bit of a hack, but it works ;) + return pow(2, ($exponent - 16382)) * DecimalBinary2Float($fractionstring); + } + if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) { + // Not a Number + $floatvalue = false; + } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) { + if ($signbit == '1') { + $floatvalue = '-infinity'; + } else { + $floatvalue = '+infinity'; + } + } elseif (($exponent == 0) && ($fraction == 0)) { + if ($signbit == '1') { + $floatvalue = -0; + } else { + $floatvalue = 0; + } + $floatvalue = ($signbit ? 0 : -0); + } elseif (($exponent == 0) && ($fraction != 0)) { + // These are 'unnormalized' values + $floatvalue = pow(2, (-1 * (pow(2, $exponentbits - 1) - 2))) * DecimalBinary2Float($fractionstring); + if ($signbit == '1') { + $floatvalue *= -1; + } + } elseif ($exponent != 0) { + $floatvalue = pow(2, ($exponent - (pow(2, $exponentbits - 1) - 1))) * (1 + DecimalBinary2Float($fractionstring)); + if ($signbit == '1') { + $floatvalue *= -1; + } + } - if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) { - // Not a Number - $floatvalue = false; - } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) { - if ($signbit == '1') { - $floatvalue = '-infinity'; - } else { - $floatvalue = '+infinity'; - } - } elseif (($exponent == 0) && ($fraction == 0)) { - if ($signbit == '1') { - $floatvalue = -0; - } else { - $floatvalue = 0; - } - $floatvalue = ($signbit ? 0 : -0); - } elseif (($exponent == 0) && ($fraction != 0)) { - // These are 'unnormalized' values - $floatvalue = pow(2, (-1 * (pow(2, $exponentbits - 1) - 2))) * DecimalBinary2Float($fractionstring); - if ($signbit == '1') { - $floatvalue *= -1; - } - } elseif ($exponent != 0) { - $floatvalue = pow(2, ($exponent - (pow(2, $exponentbits - 1) - 1))) * (1 + DecimalBinary2Float($fractionstring)); - if ($signbit == '1') { - $floatvalue *= -1; - } - } - return (float) $floatvalue; - } + return (float) $floatvalue; + } } -if (!function_exists('BigEndian2Int')) { - function BigEndian2Int($byteword, $synchsafe=false, $signed=false) { - $intvalue = 0; - $bytewordlen = strlen($byteword); - for ($i = 0; $i < $bytewordlen; $i++) { - if ($synchsafe) { // disregard MSB, effectively 7-bit bytes - $intvalue = $intvalue | (ord($byteword{$i}) & 0x7F) << (($bytewordlen - 1 - $i) * 7); - } else { - $intvalue += ord($byteword{$i}) * pow(256, ($bytewordlen - 1 - $i)); - } - } - if ($signed && !$synchsafe) { - // synchsafe ints are not allowed to be signed - switch ($bytewordlen) { - case 1: - case 2: - case 3: - case 4: - $signmaskbit = 0x80 << (8 * ($bytewordlen - 1)); - if ($intvalue & $signmaskbit) { - $intvalue = 0 - ($intvalue & ($signmaskbit - 1)); - } - break; +if (! function_exists('BigEndian2Int')) { + function BigEndian2Int($byteword, $synchsafe = false, $signed = false) + { + $intvalue = 0; + $bytewordlen = strlen($byteword); + for ($i = 0; $i < $bytewordlen; $i++) { + if ($synchsafe) { // disregard MSB, effectively 7-bit bytes + $intvalue = $intvalue | (ord($byteword[$i]) & 0x7F) << (($bytewordlen - 1 - $i) * 7); + } else { + $intvalue += ord($byteword[$i]) * pow(256, ($bytewordlen - 1 - $i)); + } + } + if ($signed && ! $synchsafe) { + // synchsafe ints are not allowed to be signed + switch ($bytewordlen) { + case 1: + case 2: + case 3: + case 4: + $signmaskbit = 0x80 << (8 * ($bytewordlen - 1)); + if ($intvalue & $signmaskbit) { + $intvalue = 0 - ($intvalue & ($signmaskbit - 1)); + } + break; - default: - die('ERROR: Cannot have signed integers larger than 32-bits in BigEndian2Int()'); - break; - } - } - return CastAsInt($intvalue); - } + default: + die('ERROR: Cannot have signed integers larger than 32-bits in BigEndian2Int()'); + break; + } + } + + return CastAsInt($intvalue); + } } -if (!function_exists('LittleEndian2Int')) { - function LittleEndian2Int($byteword, $signed=false) { - return BigEndian2Int(strrev($byteword), false, $signed); - } +if (! function_exists('LittleEndian2Int')) { + function LittleEndian2Int($byteword, $signed = false) + { + return BigEndian2Int(strrev($byteword), false, $signed); + } } -if (!function_exists('BigEndian2Bin')) { - function BigEndian2Bin($byteword) { - $binvalue = ''; - $bytewordlen = strlen($byteword); - for ($i = 0; $i < $bytewordlen; $i++) { - $binvalue .= str_pad(decbin(ord($byteword{$i})), 8, '0', STR_PAD_LEFT); - } - return $binvalue; - } +if (! function_exists('BigEndian2Bin')) { + function BigEndian2Bin($byteword) + { + $binvalue = ''; + $bytewordlen = strlen($byteword); + for ($i = 0; $i < $bytewordlen; $i++) { + $binvalue .= str_pad(decbin(ord($byteword[$i])), 8, '0', STR_PAD_LEFT); + } + + return $binvalue; + } } -if (!function_exists('BigEndian2String')) { - function BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false) { - if ($number < 0) { - return false; - } - $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF); - $intstring = ''; - if ($signed) { - if ($minbytes > 4) { - die('ERROR: Cannot have signed integers larger than 32-bits in BigEndian2String()'); - } - $number = $number & (0x80 << (8 * ($minbytes - 1))); - } - while ($number != 0) { - $quotient = ($number / ($maskbyte + 1)); - $intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)).$intstring; - $number = floor($quotient); - } - return str_pad($intstring, $minbytes, chr(0), STR_PAD_LEFT); - } +if (! function_exists('BigEndian2String')) { + function BigEndian2String($number, $minbytes = 1, $synchsafe = false, $signed = false) + { + if ($number < 0) { + return false; + } + $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF); + $intstring = ''; + if ($signed) { + if ($minbytes > 4) { + die('ERROR: Cannot have signed integers larger than 32-bits in BigEndian2String()'); + } + $number = $number & (0x80 << (8 * ($minbytes - 1))); + } + while ($number != 0) { + $quotient = ($number / ($maskbyte + 1)); + $intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)).$intstring; + $number = floor($quotient); + } + + return str_pad($intstring, $minbytes, chr(0), STR_PAD_LEFT); + } } -if (!function_exists('Dec2Bin')) { - function Dec2Bin($number) { - while ($number >= 256) { - $bytes[] = (($number / 256) - (floor($number / 256))) * 256; - $number = floor($number / 256); - } - $bytes[] = $number; - $binstring = ''; - for ($i = 0; $i < count($bytes); $i++) { - $binstring = (($i == count($bytes) - 1) ? decbin($bytes[$i]) : str_pad(decbin($bytes[$i]), 8, '0', STR_PAD_LEFT)).$binstring; - } - return $binstring; - } +if (! function_exists('Dec2Bin')) { + function Dec2Bin($number) + { + while ($number >= 256) { + $bytes[] = (($number / 256) - (floor($number / 256))) * 256; + $number = floor($number / 256); + } + $bytes[] = $number; + $binstring = ''; + for ($i = 0; $i < count($bytes); $i++) { + $binstring = (($i == count($bytes) - 1) ? decbin($bytes[$i]) : str_pad(decbin($bytes[$i]), 8, '0', STR_PAD_LEFT)).$binstring; + } + + return $binstring; + } } -if (!function_exists('Bin2Dec')) { - function Bin2Dec($binstring) { - $decvalue = 0; - for ($i = 0; $i < strlen($binstring); $i++) { - $decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1, 1)) * pow(2, $i); - } - return CastAsInt($decvalue); - } +if (! function_exists('Bin2Dec')) { + function Bin2Dec($binstring) + { + $decvalue = 0; + for ($i = 0; $i < strlen($binstring); $i++) { + $decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1, 1)) * pow(2, $i); + } + + return CastAsInt($decvalue); + } } -if (!function_exists('Bin2String')) { - function Bin2String($binstring) { - // return 'hi' for input of '0110100001101001' - $string = ''; - $binstringreversed = strrev($binstring); - for ($i = 0; $i < strlen($binstringreversed); $i += 8) { - $string = chr(Bin2Dec(strrev(substr($binstringreversed, $i, 8)))).$string; - } - return $string; - } +if (! function_exists('Bin2String')) { + function Bin2String($binstring) + { + // return 'hi' for input of '0110100001101001' + $string = ''; + $binstringreversed = strrev($binstring); + for ($i = 0; $i < strlen($binstringreversed); $i += 8) { + $string = chr(Bin2Dec(strrev(substr($binstringreversed, $i, 8)))).$string; + } + + return $string; + } } -if (!function_exists('LittleEndian2String')) { - function LittleEndian2String($number, $minbytes=1, $synchsafe=false) { - $intstring = ''; - while ($number > 0) { - if ($synchsafe) { - $intstring = $intstring.chr($number & 127); - $number >>= 7; - } else { - $intstring = $intstring.chr($number & 255); - $number >>= 8; - } - } - return str_pad($intstring, $minbytes, chr(0), STR_PAD_RIGHT); - } +if (! function_exists('LittleEndian2String')) { + function LittleEndian2String($number, $minbytes = 1, $synchsafe = false) + { + $intstring = ''; + while ($number > 0) { + if ($synchsafe) { + $intstring = $intstring.chr($number & 127); + $number >>= 7; + } else { + $intstring = $intstring.chr($number & 255); + $number >>= 8; + } + } + + return str_pad($intstring, $minbytes, chr(0), STR_PAD_RIGHT); + } } -if (!function_exists('Bool2IntString')) { - function Bool2IntString($intvalue) { - return ($intvalue ? '1' : '0'); - } +if (! function_exists('Bool2IntString')) { + function Bool2IntString($intvalue) + { + return $intvalue ? '1' : '0'; + } } -if (!function_exists('IntString2Bool')) { - function IntString2Bool($char) { - if ($char == '1') { - return true; - } elseif ($char == '0') { - return false; - } - return null; - } +if (! function_exists('IntString2Bool')) { + function IntString2Bool($char) + { + if ($char == '1') { + return true; + } elseif ($char == '0') { + return false; + } + + return null; + } } -if (!function_exists('InverseBoolean')) { - function InverseBoolean($value) { - return ($value ? false : true); - } +if (! function_exists('InverseBoolean')) { + function InverseBoolean($value) + { + return $value ? false : true; + } } -if (!function_exists('DeUnSynchronise')) { - function DeUnSynchronise($data) { - return str_replace(chr(0xFF).chr(0x00), chr(0xFF), $data); - } +if (! function_exists('DeUnSynchronise')) { + function DeUnSynchronise($data) + { + return str_replace(chr(0xFF).chr(0x00), chr(0xFF), $data); + } } -if (!function_exists('Unsynchronise')) { - function Unsynchronise($data) { - // Whenever a false synchronisation is found within the tag, one zeroed - // byte is inserted after the first false synchronisation byte. The - // format of a correct sync that should be altered by ID3 encoders is as - // follows: - // %11111111 111xxxxx - // And should be replaced with: - // %11111111 00000000 111xxxxx - // This has the side effect that all $FF 00 combinations have to be - // altered, so they won't be affected by the decoding process. Therefore - // all the $FF 00 combinations have to be replaced with the $FF 00 00 - // combination during the unsynchronisation. +if (! function_exists('Unsynchronise')) { + function Unsynchronise($data) + { + // Whenever a false synchronisation is found within the tag, one zeroed + // byte is inserted after the first false synchronisation byte. The + // format of a correct sync that should be altered by ID3 encoders is as + // follows: + // %11111111 111xxxxx + // And should be replaced with: + // %11111111 00000000 111xxxxx + // This has the side effect that all $FF 00 combinations have to be + // altered, so they won't be affected by the decoding process. Therefore + // all the $FF 00 combinations have to be replaced with the $FF 00 00 + // combination during the unsynchronisation. - $data = str_replace(chr(0xFF).chr(0x00), chr(0xFF).chr(0x00).chr(0x00), $data); - $unsyncheddata = ''; - for ($i = 0; $i < strlen($data); $i++) { - $thischar = $data{$i}; - $unsyncheddata .= $thischar; - if ($thischar == chr(255)) { - $nextchar = ord(substr($data, $i + 1, 1)); - if (($nextchar | 0xE0) == 0xE0) { - // previous byte = 11111111, this byte = 111????? - $unsyncheddata .= chr(0); - } - } - } - return $unsyncheddata; - } + $data = str_replace(chr(0xFF).chr(0x00), chr(0xFF).chr(0x00).chr(0x00), $data); + $unsyncheddata = ''; + for ($i = 0; $i < strlen($data); $i++) { + $thischar = $data[$i]; + $unsyncheddata .= $thischar; + if ($thischar == chr(255)) { + $nextchar = ord(substr($data, $i + 1, 1)); + if (($nextchar | 0xE0) == 0xE0) { + // previous byte = 11111111, this byte = 111????? + $unsyncheddata .= chr(0); + } + } + } + + return $unsyncheddata; + } } -if (!function_exists('is_hash')) { - function is_hash($var) { - // written by dev-null@christophe.vg - // taken from http://www.php.net/manual/en/function.array-merge-recursive.php - if (is_array($var)) { - $keys = array_keys($var); - $all_num = true; - for ($i = 0; $i < count($keys); $i++) { - if (is_string($keys[$i])) { - return true; - } - } - } - return false; - } +if (! function_exists('is_hash')) { + function is_hash($var) + { + // written by dev-null@christophe.vg + // taken from http://www.php.net/manual/en/function.array-merge-recursive.php + if (is_array($var)) { + $keys = array_keys($var); + $all_num = true; + for ($i = 0; $i < count($keys); $i++) { + if (is_string($keys[$i])) { + return true; + } + } + } + + return false; + } } -if (!function_exists('array_join_merge')) { - function array_join_merge($arr1, $arr2) { - // written by dev-null@christophe.vg - // taken from http://www.php.net/manual/en/function.array-merge-recursive.php - if (is_array($arr1) && is_array($arr2)) { - // the same -> merge - $new_array = array(); +if (! function_exists('array_join_merge')) { + function array_join_merge($arr1, $arr2) + { + // written by dev-null@christophe.vg + // taken from http://www.php.net/manual/en/function.array-merge-recursive.php + if (is_array($arr1) && is_array($arr2)) { + // the same -> merge + $new_array = []; - if (is_hash($arr1) && is_hash($arr2)) { - // hashes -> merge based on keys - $keys = array_merge(array_keys($arr1), array_keys($arr2)); - foreach ($keys as $key) { - $arr1[$key] = (isset($arr1[$key]) ? $arr1[$key] : ''); - $arr2[$key] = (isset($arr2[$key]) ? $arr2[$key] : ''); - $new_array[$key] = array_join_merge($arr1[$key], $arr2[$key]); - } - } else { - // two real arrays -> merge - $new_array = array_reverse(array_unique(array_reverse(array_merge($arr1,$arr2)))); - } - return $new_array; - } else { - // not the same ... take new one if defined, else the old one stays - return $arr2 ? $arr2 : $arr1; - } - } + if (is_hash($arr1) && is_hash($arr2)) { + // hashes -> merge based on keys + $keys = array_merge(array_keys($arr1), array_keys($arr2)); + foreach ($keys as $key) { + $arr1[$key] = (isset($arr1[$key]) ? $arr1[$key] : ''); + $arr2[$key] = (isset($arr2[$key]) ? $arr2[$key] : ''); + $new_array[$key] = array_join_merge($arr1[$key], $arr2[$key]); + } + } else { + // two real arrays -> merge + $new_array = array_reverse(array_unique(array_reverse(array_merge($arr1, $arr2)))); + } + + return $new_array; + } else { + // not the same ... take new one if defined, else the old one stays + return $arr2 ? $arr2 : $arr1; + } + } } -if (!function_exists('array_merge_clobber')) { - function array_merge_clobber($array1, $array2) { - // written by kc@hireability.com - // taken from http://www.php.net/manual/en/function.array-merge-recursive.php - if (!is_array($array1) || !is_array($array2)) { - return false; - } - $newarray = $array1; - foreach ($array2 as $key => $val) { - if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { - $newarray[$key] = array_merge_clobber($newarray[$key], $val); - } else { - $newarray[$key] = $val; - } - } - return $newarray; - } +if (! function_exists('array_merge_clobber')) { + function array_merge_clobber($array1, $array2) + { + // written by kc@hireability.com + // taken from http://www.php.net/manual/en/function.array-merge-recursive.php + if (! is_array($array1) || ! is_array($array2)) { + return false; + } + $newarray = $array1; + foreach ($array2 as $key => $val) { + if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { + $newarray[$key] = array_merge_clobber($newarray[$key], $val); + } else { + $newarray[$key] = $val; + } + } + + return $newarray; + } } -if (!function_exists('array_merge_noclobber')) { - function array_merge_noclobber($array1, $array2) { - if (!is_array($array1) || !is_array($array2)) { - return false; - } - $newarray = $array1; - foreach ($array2 as $key => $val) { - if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { - $newarray[$key] = array_merge_noclobber($newarray[$key], $val); - } elseif (!isset($newarray[$key])) { - $newarray[$key] = $val; - } - } - return $newarray; - } +if (! function_exists('array_merge_noclobber')) { + function array_merge_noclobber($array1, $array2) + { + if (! is_array($array1) || ! is_array($array2)) { + return false; + } + $newarray = $array1; + foreach ($array2 as $key => $val) { + if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { + $newarray[$key] = array_merge_noclobber($newarray[$key], $val); + } elseif (! isset($newarray[$key])) { + $newarray[$key] = $val; + } + } + + return $newarray; + } } -if (!function_exists('RoughTranslateUnicodeToASCII')) { - function RoughTranslateUnicodeToASCII($rawdata, $frame_textencoding) { - // rough translation of data for application that can't handle Unicode data +if (! function_exists('RoughTranslateUnicodeToASCII')) { + function RoughTranslateUnicodeToASCII($rawdata, $frame_textencoding) + { + // rough translation of data for application that can't handle Unicode data - $tempstring = ''; - switch ($frame_textencoding) { - case 0: // ISO-8859-1. Terminated with $00. - $asciidata = $rawdata; - break; + $tempstring = ''; + switch ($frame_textencoding) { + case 0: // ISO-8859-1. Terminated with $00. + $asciidata = $rawdata; + break; - case 1: // UTF-16 encoded Unicode with BOM. Terminated with $00 00. - $asciidata = $rawdata; - if (substr($asciidata, 0, 2) == chr(0xFF).chr(0xFE)) { - // remove BOM, only if present (it should be, but...) - $asciidata = substr($asciidata, 2); - } - if (substr($asciidata, strlen($asciidata) - 2, 2) == chr(0).chr(0)) { - $asciidata = substr($asciidata, 0, strlen($asciidata) - 2); // remove terminator, only if present (it should be, but...) - } - for ($i = 0; $i < strlen($asciidata); $i += 2) { - if ((ord($asciidata{$i}) <= 0x7F) || (ord($asciidata{$i}) >= 0xA0)) { - $tempstring .= $asciidata{$i}; - } else { - $tempstring .= '?'; - } - } - $asciidata = $tempstring; - break; + case 1: // UTF-16 encoded Unicode with BOM. Terminated with $00 00. + $asciidata = $rawdata; + if (substr($asciidata, 0, 2) == chr(0xFF).chr(0xFE)) { + // remove BOM, only if present (it should be, but...) + $asciidata = substr($asciidata, 2); + } + if (substr($asciidata, strlen($asciidata) - 2, 2) == chr(0).chr(0)) { + $asciidata = substr($asciidata, 0, strlen($asciidata) - 2); // remove terminator, only if present (it should be, but...) + } + for ($i = 0; $i < strlen($asciidata); $i += 2) { + if ((ord($asciidata[$i]) <= 0x7F) || (ord($asciidata[$i]) >= 0xA0)) { + $tempstring .= $asciidata[$i]; + } else { + $tempstring .= '?'; + } + } + $asciidata = $tempstring; + break; - case 2: // UTF-16BE encoded Unicode without BOM. Terminated with $00 00. - $asciidata = $rawdata; - if (substr($asciidata, strlen($asciidata) - 2, 2) == chr(0).chr(0)) { - $asciidata = substr($asciidata, 0, strlen($asciidata) - 2); // remove terminator, only if present (it should be, but...) - } - for ($i = 0; $i < strlen($asciidata); $i += 2) { - if ((ord($asciidata{$i}) <= 0x7F) || (ord($asciidata{$i}) >= 0xA0)) { - $tempstring .= $asciidata{$i}; - } else { - $tempstring .= '?'; - } - } - $asciidata = $tempstring; - break; + case 2: // UTF-16BE encoded Unicode without BOM. Terminated with $00 00. + $asciidata = $rawdata; + if (substr($asciidata, strlen($asciidata) - 2, 2) == chr(0).chr(0)) { + $asciidata = substr($asciidata, 0, strlen($asciidata) - 2); // remove terminator, only if present (it should be, but...) + } + for ($i = 0; $i < strlen($asciidata); $i += 2) { + if ((ord($asciidata[$i]) <= 0x7F) || (ord($asciidata[$i]) >= 0xA0)) { + $tempstring .= $asciidata[$i]; + } else { + $tempstring .= '?'; + } + } + $asciidata = $tempstring; + break; - case 3: // UTF-8 encoded Unicode. Terminated with $00. - $asciidata = utf8_decode($rawdata); - break; + case 3: // UTF-8 encoded Unicode. Terminated with $00. + $asciidata = utf8_decode($rawdata); + break; - case 255: // Unicode, Big-Endian. Terminated with $00 00. - $asciidata = $rawdata; - if (substr($asciidata, strlen($asciidata) - 2, 2) == chr(0).chr(0)) { - $asciidata = substr($asciidata, 0, strlen($asciidata) - 2); // remove terminator, only if present (it should be, but...) - } - for ($i = 0; ($i + 1) < strlen($asciidata); $i += 2) { - if ((ord($asciidata{($i + 1)}) <= 0x7F) || (ord($asciidata{($i + 1)}) >= 0xA0)) { - $tempstring .= $asciidata{($i + 1)}; - } else { - $tempstring .= '?'; - } - } - $asciidata = $tempstring; - break; + case 255: // Unicode, Big-Endian. Terminated with $00 00. + $asciidata = $rawdata; + if (substr($asciidata, strlen($asciidata) - 2, 2) == chr(0).chr(0)) { + $asciidata = substr($asciidata, 0, strlen($asciidata) - 2); // remove terminator, only if present (it should be, but...) + } + for ($i = 0; ($i + 1) < strlen($asciidata); $i += 2) { + if ((ord($asciidata[($i + 1)]) <= 0x7F) || (ord($asciidata[($i + 1)]) >= 0xA0)) { + $tempstring .= $asciidata[($i + 1)]; + } else { + $tempstring .= '?'; + } + } + $asciidata = $tempstring; + break; + default: + // shouldn't happen, but in case $frame_textencoding is not 1 <= $frame_textencoding <= 4 + // just pass the data through unchanged. + $asciidata = $rawdata; + break; + } + if (substr($asciidata, strlen($asciidata) - 1, 1) == chr(0)) { + // remove null terminator, if present + $asciidata = NoNullString($asciidata); + } - default: - // shouldn't happen, but in case $frame_textencoding is not 1 <= $frame_textencoding <= 4 - // just pass the data through unchanged. - $asciidata = $rawdata; - break; - } - if (substr($asciidata, strlen($asciidata) - 1, 1) == chr(0)) { - // remove null terminator, if present - $asciidata = NoNullString($asciidata); - } - return $asciidata; - // return str_replace(chr(0), '', $asciidata); // just in case any nulls slipped through - } + return $asciidata; + // return str_replace(chr(0), '', $asciidata); // just in case any nulls slipped through + } } -if (!function_exists('PlaytimeString')) { - function PlaytimeString($playtimeseconds) { - $contentseconds = round((($playtimeseconds / 60) - floor($playtimeseconds / 60)) * 60); - $contentminutes = floor($playtimeseconds / 60); - if ($contentseconds >= 60) { - $contentseconds -= 60; - $contentminutes++; - } - return number_format($contentminutes).':'.str_pad($contentseconds, 2, 0, STR_PAD_LEFT); - } +if (! function_exists('PlaytimeString')) { + function PlaytimeString($playtimeseconds) + { + $contentseconds = round((($playtimeseconds / 60) - floor($playtimeseconds / 60)) * 60); + $contentminutes = floor($playtimeseconds / 60); + if ($contentseconds >= 60) { + $contentseconds -= 60; + $contentminutes++; + } + + return number_format($contentminutes).':'.str_pad($contentseconds, 2, 0, STR_PAD_LEFT); + } } -if (!function_exists('CloseMatch')) { - function CloseMatch($value1, $value2, $tolerance) { - return (abs($value1 - $value2) <= $tolerance); - } +if (! function_exists('CloseMatch')) { + function CloseMatch($value1, $value2, $tolerance) + { + return abs($value1 - $value2) <= $tolerance; + } } -if (!function_exists('ID3v1matchesID3v2')) { - function ID3v1matchesID3v2($id3v1, $id3v2) { +if (! function_exists('ID3v1matchesID3v2')) { + function ID3v1matchesID3v2($id3v1, $id3v2) + { + $requiredindices = ['title', 'artist', 'album', 'year', 'genre', 'comment']; + foreach ($requiredindices as $requiredindex) { + if (! isset($id3v1["$requiredindex"])) { + $id3v1["$requiredindex"] = ''; + } + if (! isset($id3v2["$requiredindex"])) { + $id3v2["$requiredindex"] = ''; + } + } - $requiredindices = array('title', 'artist', 'album', 'year', 'genre', 'comment'); - foreach ($requiredindices as $requiredindex) { - if (!isset($id3v1["$requiredindex"])) { - $id3v1["$requiredindex"] = ''; - } - if (!isset($id3v2["$requiredindex"])) { - $id3v2["$requiredindex"] = ''; - } - } + if (trim($id3v1['title']) != trim(substr($id3v2['title'], 0, 30))) { + return false; + } + if (trim($id3v1['artist']) != trim(substr($id3v2['artist'], 0, 30))) { + return false; + } + if (trim($id3v1['album']) != trim(substr($id3v2['album'], 0, 30))) { + return false; + } + if (trim($id3v1['year']) != trim(substr($id3v2['year'], 0, 4))) { + return false; + } + if (trim($id3v1['genre']) != trim($id3v2['genre'])) { + return false; + } + if (isset($id3v1['track'])) { + if (! isset($id3v1['track']) || (trim($id3v1['track']) != trim($id3v2['track']))) { + return false; + } + if (trim($id3v1['comment']) != trim(substr($id3v2['comment'], 0, 28))) { + return false; + } + } else { + if (trim($id3v1['comment']) != trim(substr($id3v2['comment'], 0, 30))) { + return false; + } + } - if (trim($id3v1['title']) != trim(substr($id3v2['title'], 0, 30))) { - return false; - } - if (trim($id3v1['artist']) != trim(substr($id3v2['artist'], 0, 30))) { - return false; - } - if (trim($id3v1['album']) != trim(substr($id3v2['album'], 0, 30))) { - return false; - } - if (trim($id3v1['year']) != trim(substr($id3v2['year'], 0, 4))) { - return false; - } - if (trim($id3v1['genre']) != trim($id3v2['genre'])) { - return false; - } - if (isset($id3v1['track'])) { - if (!isset($id3v1['track']) || (trim($id3v1['track']) != trim($id3v2['track']))) { - return false; - } - if (trim($id3v1['comment']) != trim(substr($id3v2['comment'], 0, 28))) { - return false; - } - } else { - if (trim($id3v1['comment']) != trim(substr($id3v2['comment'], 0, 30))) { - return false; - } - } - return true; - } + return true; + } } -if (!function_exists('FILETIMEtoUNIXtime')) { - function FILETIMEtoUNIXtime($FILETIME, $round=true) { - // FILETIME is a 64-bit unsigned integer representing - // the number of 100-nanosecond intervals since January 1, 1601 - // UNIX timestamp is number of seconds since January 1, 1970 - // 116444736000000000 = 10000000 * 60 * 60 * 24 * 365 * 369 + 89 leap days - if ($round) { - return round(($FILETIME - 116444736000000000) / 10000000); - } - return ($FILETIME - 116444736000000000) / 10000000; - } +if (! function_exists('FILETIMEtoUNIXtime')) { + function FILETIMEtoUNIXtime($FILETIME, $round = true) + { + // FILETIME is a 64-bit unsigned integer representing + // the number of 100-nanosecond intervals since January 1, 1601 + // UNIX timestamp is number of seconds since January 1, 1970 + // 116444736000000000 = 10000000 * 60 * 60 * 24 * 365 * 369 + 89 leap days + if ($round) { + return round(($FILETIME - 116444736000000000) / 10000000); + } + + return ($FILETIME - 116444736000000000) / 10000000; + } } -if (!function_exists('GUIDtoBytestring')) { - function GUIDtoBytestring($GUIDstring) { - // Microsoft defines these 16-byte (128-bit) GUIDs in the strangest way: - // first 4 bytes are in little-endian order - // next 2 bytes are appended in little-endian order - // next 2 bytes are appended in little-endian order - // next 2 bytes are appended in big-endian order - // next 6 bytes are appended in big-endian order +if (! function_exists('GUIDtoBytestring')) { + function GUIDtoBytestring($GUIDstring) + { + // Microsoft defines these 16-byte (128-bit) GUIDs in the strangest way: + // first 4 bytes are in little-endian order + // next 2 bytes are appended in little-endian order + // next 2 bytes are appended in little-endian order + // next 2 bytes are appended in big-endian order + // next 6 bytes are appended in big-endian order - // AaBbCcDd-EeFf-GgHh-IiJj-KkLlMmNnOoPp is stored as this 16-byte string: - // $Dd $Cc $Bb $Aa $Ff $Ee $Hh $Gg $Ii $Jj $Kk $Ll $Mm $Nn $Oo $Pp + // AaBbCcDd-EeFf-GgHh-IiJj-KkLlMmNnOoPp is stored as this 16-byte string: + // $Dd $Cc $Bb $Aa $Ff $Ee $Hh $Gg $Ii $Jj $Kk $Ll $Mm $Nn $Oo $Pp - $hexbytecharstring = chr(hexdec(substr($GUIDstring, 6, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 4, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 2, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 0, 2))); + $hexbytecharstring = chr(hexdec(substr($GUIDstring, 6, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 4, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 2, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 0, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 11, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 9, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 11, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 9, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 16, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 14, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 16, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 14, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 19, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 21, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 19, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 21, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 24, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 26, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 28, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 30, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 32, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 34, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 24, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 26, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 28, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 30, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 32, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 34, 2))); - return $hexbytecharstring; - } + return $hexbytecharstring; + } } -if (!function_exists('BytestringToGUID')) { - function BytestringToGUID($Bytestring) { - $GUIDstring = str_pad(dechex(ord($Bytestring{3})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{2})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{1})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{0})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= '-'; - $GUIDstring .= str_pad(dechex(ord($Bytestring{5})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{4})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= '-'; - $GUIDstring .= str_pad(dechex(ord($Bytestring{7})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{6})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= '-'; - $GUIDstring .= str_pad(dechex(ord($Bytestring{8})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{9})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= '-'; - $GUIDstring .= str_pad(dechex(ord($Bytestring{10})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{11})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{12})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{13})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{14})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{15})), 2, '0', STR_PAD_LEFT); +if (! function_exists('BytestringToGUID')) { + function BytestringToGUID($Bytestring) + { + $GUIDstring = str_pad(dechex(ord($Bytestring[3])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[2])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[1])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[0])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= '-'; + $GUIDstring .= str_pad(dechex(ord($Bytestring[5])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[4])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= '-'; + $GUIDstring .= str_pad(dechex(ord($Bytestring[7])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[6])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= '-'; + $GUIDstring .= str_pad(dechex(ord($Bytestring[8])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[9])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= '-'; + $GUIDstring .= str_pad(dechex(ord($Bytestring[10])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[11])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[12])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[13])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[14])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[15])), 2, '0', STR_PAD_LEFT); - return strtoupper($GUIDstring); - } + return strtoupper($GUIDstring); + } } -if (!function_exists('BitrateColor')) { - function BitrateColor($bitrate) { - $bitrate /= 3; // scale from 1-768kbps to 1-256kbps - $bitrate--; // scale from 1-256kbps to 0-255kbps - $bitrate = max($bitrate, 0); - $bitrate = min($bitrate, 255); - //$bitrate = max($bitrate, 32); - //$bitrate = min($bitrate, 143); - //$bitrate = ($bitrate * 2) - 32; +if (! function_exists('BitrateColor')) { + function BitrateColor($bitrate) + { + $bitrate /= 3; // scale from 1-768kbps to 1-256kbps + $bitrate--; // scale from 1-256kbps to 0-255kbps + $bitrate = max($bitrate, 0); + $bitrate = min($bitrate, 255); + //$bitrate = max($bitrate, 32); + //$bitrate = min($bitrate, 143); + //$bitrate = ($bitrate * 2) - 32; - $Rcomponent = max(255 - ($bitrate * 2), 0); - $Gcomponent = max(($bitrate * 2) - 255, 0); - if ($bitrate > 127) { - $Bcomponent = max((255 - $bitrate) * 2, 0); - } else { - $Bcomponent = max($bitrate * 2, 0); - } - return str_pad(dechex($Rcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Gcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Bcomponent), 2, '0', STR_PAD_LEFT); - } + $Rcomponent = max(255 - ($bitrate * 2), 0); + $Gcomponent = max(($bitrate * 2) - 255, 0); + if ($bitrate > 127) { + $Bcomponent = max((255 - $bitrate) * 2, 0); + } else { + $Bcomponent = max($bitrate * 2, 0); + } + + return str_pad(dechex($Rcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Gcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Bcomponent), 2, '0', STR_PAD_LEFT); + } } -if (!function_exists('BitrateText')) { - function BitrateText($bitrate) { - return ''.round($bitrate).' kbps'; - } +if (! function_exists('BitrateText')) { + function BitrateText($bitrate) + { + return ''.round($bitrate).' kbps'; + } } -if (!function_exists('image_type_to_mime_type')) { - function image_type_to_mime_type($imagetypeid) { - // only available in PHP v4.3.0+ - static $image_type_to_mime_type = array(); - if (empty($image_type_to_mime_type)) { - $image_type_to_mime_type[1] = 'image/gif'; // GIF - $image_type_to_mime_type[2] = 'image/jpeg'; // JPEG - $image_type_to_mime_type[3] = 'image/png'; // PNG - $image_type_to_mime_type[4] = 'application/x-shockwave-flash'; // Flash - $image_type_to_mime_type[5] = 'image/psd'; // PSD - $image_type_to_mime_type[6] = 'image/bmp'; // BMP - $image_type_to_mime_type[7] = 'image/tiff'; // TIFF: little-endian (Intel) - $image_type_to_mime_type[8] = 'image/tiff'; // TIFF: big-endian (Motorola) - //$image_type_to_mime_type[9] = 'image/jpc'; // JPC - //$image_type_to_mime_type[10] = 'image/jp2'; // JPC - //$image_type_to_mime_type[11] = 'image/jpx'; // JPC - //$image_type_to_mime_type[12] = 'image/jb2'; // JPC - $image_type_to_mime_type[13] = 'application/x-shockwave-flash'; // Shockwave - $image_type_to_mime_type[14] = 'image/iff'; // IFF - } - return (isset($image_type_to_mime_type[$imagetypeid]) ? $image_type_to_mime_type[$imagetypeid] : 'application/octet-stream'); - } +if (! function_exists('image_type_to_mime_type')) { + function image_type_to_mime_type($imagetypeid) + { + // only available in PHP v4.3.0+ + static $image_type_to_mime_type = []; + if (empty($image_type_to_mime_type)) { + $image_type_to_mime_type[1] = 'image/gif'; // GIF + $image_type_to_mime_type[2] = 'image/jpeg'; // JPEG + $image_type_to_mime_type[3] = 'image/png'; // PNG + $image_type_to_mime_type[4] = 'application/x-shockwave-flash'; // Flash + $image_type_to_mime_type[5] = 'image/psd'; // PSD + $image_type_to_mime_type[6] = 'image/bmp'; // BMP + $image_type_to_mime_type[7] = 'image/tiff'; // TIFF: little-endian (Intel) + $image_type_to_mime_type[8] = 'image/tiff'; // TIFF: big-endian (Motorola) + //$image_type_to_mime_type[9] = 'image/jpc'; // JPC + //$image_type_to_mime_type[10] = 'image/jp2'; // JPC + //$image_type_to_mime_type[11] = 'image/jpx'; // JPC + //$image_type_to_mime_type[12] = 'image/jb2'; // JPC + $image_type_to_mime_type[13] = 'application/x-shockwave-flash'; // Shockwave + $image_type_to_mime_type[14] = 'image/iff'; // IFF + } + + return isset($image_type_to_mime_type[$imagetypeid]) ? $image_type_to_mime_type[$imagetypeid] : 'application/octet-stream'; + } } -if (!function_exists('utf8_decode')) { - // PHP has this function built-in if it's configured with the --with-xml option - // This version of the function is only provided in case XML isn't installed - function utf8_decode($utf8text) { - // http://www.php.net/manual/en/function.utf8-encode.php - // bytes bits representation - // 1 7 0bbbbbbb - // 2 11 110bbbbb 10bbbbbb - // 3 16 1110bbbb 10bbbbbb 10bbbbbb - // 4 21 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb +if (! function_exists('utf8_decode')) { + // PHP has this function built-in if it's configured with the --with-xml option + // This version of the function is only provided in case XML isn't installed + function utf8_decode($utf8text) + { + // http://www.php.net/manual/en/function.utf8-encode.php + // bytes bits representation + // 1 7 0bbbbbbb + // 2 11 110bbbbb 10bbbbbb + // 3 16 1110bbbb 10bbbbbb 10bbbbbb + // 4 21 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb - $utf8length = strlen($utf8text); - $decodedtext = ''; - for ($i = 0; $i < $utf8length; $i++) { - if ((ord($utf8text{$i}) & 0x80) == 0) { - $decodedtext .= $utf8text{$i}; - } elseif ((ord($utf8text{$i}) & 0xF0) == 0xF0) { - $decodedtext .= '?'; - $i += 3; - } elseif ((ord($utf8text{$i}) & 0xE0) == 0xE0) { - $decodedtext .= '?'; - $i += 2; - } elseif ((ord($utf8text{$i}) & 0xC0) == 0xC0) { - // 2 11 110bbbbb 10bbbbbb - $decodedchar = Bin2Dec(substr(Dec2Bin(ord($utf8text{$i})), 3, 5).substr(Dec2Bin(ord($utf8text{($i + 1)})), 2, 6)); - if ($decodedchar <= 255) { - $decodedtext .= chr($decodedchar); - } else { - $decodedtext .= '?'; - } - $i += 1; - } - } - return $decodedtext; - } + $utf8length = strlen($utf8text); + $decodedtext = ''; + for ($i = 0; $i < $utf8length; $i++) { + if ((ord($utf8text[$i]) & 0x80) == 0) { + $decodedtext .= $utf8text[$i]; + } elseif ((ord($utf8text[$i]) & 0xF0) == 0xF0) { + $decodedtext .= '?'; + $i += 3; + } elseif ((ord($utf8text[$i]) & 0xE0) == 0xE0) { + $decodedtext .= '?'; + $i += 2; + } elseif ((ord($utf8text[$i]) & 0xC0) == 0xC0) { + // 2 11 110bbbbb 10bbbbbb + $decodedchar = Bin2Dec(substr(Dec2Bin(ord($utf8text[$i])), 3, 5).substr(Dec2Bin(ord($utf8text[($i + 1)])), 2, 6)); + if ($decodedchar <= 255) { + $decodedtext .= chr($decodedchar); + } else { + $decodedtext .= '?'; + } + $i += 1; + } + } + + return $decodedtext; + } } -if (!function_exists('DateMac2Unix')) { - function DateMac2Unix($macdate) { - // Macintosh timestamp: seconds since 00:00h January 1, 1904 - // UNIX timestamp: seconds since 00:00h January 1, 1970 - return CastAsInt($macdate - 2082844800); - } +if (! function_exists('DateMac2Unix')) { + function DateMac2Unix($macdate) + { + // Macintosh timestamp: seconds since 00:00h January 1, 1904 + // UNIX timestamp: seconds since 00:00h January 1, 1970 + return CastAsInt($macdate - 2082844800); + } } - -if (!function_exists('FixedPoint8_8')) { - function FixedPoint8_8($rawdata) { - return BigEndian2Int(substr($rawdata, 0, 1)) + (float) (BigEndian2Int(substr($rawdata, 1, 1)) / pow(2, 8)); - } +if (! function_exists('FixedPoint8_8')) { + function FixedPoint8_8($rawdata) + { + return BigEndian2Int(substr($rawdata, 0, 1)) + (float) (BigEndian2Int(substr($rawdata, 1, 1)) / pow(2, 8)); + } } - -if (!function_exists('FixedPoint16_16')) { - function FixedPoint16_16($rawdata) { - return BigEndian2Int(substr($rawdata, 0, 2)) + (float) (BigEndian2Int(substr($rawdata, 2, 2)) / pow(2, 16)); - } +if (! function_exists('FixedPoint16_16')) { + function FixedPoint16_16($rawdata) + { + return BigEndian2Int(substr($rawdata, 0, 2)) + (float) (BigEndian2Int(substr($rawdata, 2, 2)) / pow(2, 16)); + } } +if (! function_exists('FixedPoint2_30')) { + function FixedPoint2_30($rawdata) + { + $binarystring = BigEndian2Bin($rawdata); -if (!function_exists('FixedPoint2_30')) { - function FixedPoint2_30($rawdata) { - $binarystring = BigEndian2Bin($rawdata); - return Bin2Dec(substr($binarystring, 0, 2)) + (float) (Bin2Dec(substr($binarystring, 2, 30)) / pow(2, 30)); - } + return Bin2Dec(substr($binarystring, 0, 2)) + (float) (Bin2Dec(substr($binarystring, 2, 30)) / pow(2, 30)); + } } - -if (!function_exists('Pascal2String')) { - function Pascal2String($pascalstring) { - // Pascal strings have 1 byte at the beginning saying how many chars are in the string - return substr($pascalstring, 1); - } +if (! function_exists('Pascal2String')) { + function Pascal2String($pascalstring) + { + // Pascal strings have 1 byte at the beginning saying how many chars are in the string + return substr($pascalstring, 1); + } } -if (!function_exists('NoNullString')) { - function NoNullString($nullterminatedstring) { - // remove the single null terminator on null terminated strings - if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === chr(0)) { - return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1); - } - return $nullterminatedstring; - } +if (! function_exists('NoNullString')) { + function NoNullString($nullterminatedstring) + { + // remove the single null terminator on null terminated strings + if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === chr(0)) { + return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1); + } + + return $nullterminatedstring; + } } -if (!function_exists('FileSizeNiceDisplay')) { - function FileSizeNiceDisplay($filesize, $precision=2) { - if ($filesize < 1000) { - $sizeunit = 'bytes'; - $precision = 0; - } else { - $filesize /= 1024; - $sizeunit = 'kB'; - } - if ($filesize >= 1000) { - $filesize /= 1024; - $sizeunit = 'MB'; - } - if ($filesize >= 1000) { - $filesize /= 1024; - $sizeunit = 'GB'; - } - return number_format($filesize, $precision).' '.$sizeunit; - } +if (! function_exists('FileSizeNiceDisplay')) { + function FileSizeNiceDisplay($filesize, $precision = 2) + { + if ($filesize < 1000) { + $sizeunit = 'bytes'; + $precision = 0; + } else { + $filesize /= 1024; + $sizeunit = 'kB'; + } + if ($filesize >= 1000) { + $filesize /= 1024; + $sizeunit = 'MB'; + } + if ($filesize >= 1000) { + $filesize /= 1024; + $sizeunit = 'GB'; + } + + return number_format($filesize, $precision).' '.$sizeunit; + } } -if (!function_exists('DOStime2UNIXtime')) { - function DOStime2UNIXtime($DOSdate, $DOStime) { - // wFatDate - // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format: - // Bits Contents - // 0-4 Day of the month (1-31) - // 5-8 Month (1 = January, 2 = February, and so on) - // 9-15 Year offset from 1980 (add 1980 to get actual year) +if (! function_exists('DOStime2UNIXtime')) { + function DOStime2UNIXtime($DOSdate, $DOStime) + { + // wFatDate + // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format: + // Bits Contents + // 0-4 Day of the month (1-31) + // 5-8 Month (1 = January, 2 = February, and so on) + // 9-15 Year offset from 1980 (add 1980 to get actual year) - $UNIXday = ($DOSdate & 0x001F); - $UNIXmonth = (($DOSdate & 0x01E0) >> 5); - $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980; + $UNIXday = ($DOSdate & 0x001F); + $UNIXmonth = (($DOSdate & 0x01E0) >> 5); + $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980; - // wFatTime - // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format: - // Bits Contents - // 0-4 Second divided by 2 - // 5-10 Minute (0-59) - // 11-15 Hour (0-23 on a 24-hour clock) + // wFatTime + // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format: + // Bits Contents + // 0-4 Second divided by 2 + // 5-10 Minute (0-59) + // 11-15 Hour (0-23 on a 24-hour clock) - $UNIXsecond = ($DOStime & 0x001F) * 2; - $UNIXminute = (($DOStime & 0x07E0) >> 5); - $UNIXhour = (($DOStime & 0xF800) >> 11); + $UNIXsecond = ($DOStime & 0x001F) * 2; + $UNIXminute = (($DOStime & 0x07E0) >> 5); + $UNIXhour = (($DOStime & 0xF800) >> 11); - return mktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear); - } + return mktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear); + } } -if (!function_exists('CreateDeepArray')) { - function CreateDeepArray($ArrayPath, $Separator, $Value) { - // assigns $Value to a nested array path: - // $foo = CreateDeepArray('/path/to/my', '/', 'file.txt') - // is the same as: - // $foo = array('path'=>array('to'=>'array('my'=>array('file.txt')))); - // or - // $foo['path']['to']['my'] = 'file.txt'; - while ($ArrayPath{0} == $Separator) { - $ArrayPath = substr($ArrayPath, 1); - } - if (($pos = strpos($ArrayPath, $Separator)) !== false) { - $ReturnedArray[substr($ArrayPath, 0, $pos)] = CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value); - } else { - $ReturnedArray["$ArrayPath"] = $Value; - } - return $ReturnedArray; - } +if (! function_exists('CreateDeepArray')) { + function CreateDeepArray($ArrayPath, $Separator, $Value) + { + // assigns $Value to a nested array path: + // $foo = CreateDeepArray('/path/to/my', '/', 'file.txt') + // is the same as: + // $foo = array('path'=>array('to'=>'array('my'=>array('file.txt')))); + // or + // $foo['path']['to']['my'] = 'file.txt'; + while ($ArrayPath[0] == $Separator) { + $ArrayPath = substr($ArrayPath, 1); + } + if (($pos = strpos($ArrayPath, $Separator)) !== false) { + $ReturnedArray[substr($ArrayPath, 0, $pos)] = CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value); + } else { + $ReturnedArray["$ArrayPath"] = $Value; + } + + return $ReturnedArray; + } } -if (!function_exists('md5_file')) { - // Allan Hansen - // md5_file() exists in PHP 4.2.0. - // The following works under UNIX only, but dies on windows - function md5_file($file) { - if (substr(php_uname(), 0, 7) == 'Windows') { - die('PHP 4.2.0 or newer required for md5_file()'); - } +if (! function_exists('md5_file')) { + // Allan Hansen + // md5_file() exists in PHP 4.2.0. + // The following works under UNIX only, but dies on windows + function md5_file($file) + { + if (substr(php_uname(), 0, 7) == 'Windows') { + die('PHP 4.2.0 or newer required for md5_file()'); + } - $file = str_replace('`', '\\`', $file); - if (preg_match("#^([0-9a-f]{32})[ \t\n\r]#i", `md5sum "$file"`, $r)) { - return $r[1]; - } - return false; - } + $file = str_replace('`', '\\`', $file); + if (preg_match("#^([0-9a-f]{32})[ \t\n\r]#i", `md5sum "$file"`, $r)) { + return $r[1]; + } + + return false; + } } -if (!function_exists('md5_data')) { - // Allan Hansen - // md5_data() - returns md5sum for a file from startuing position to absolute end position +if (! function_exists('md5_data')) { + // Allan Hansen + // md5_data() - returns md5sum for a file from startuing position to absolute end position - function md5_data($file, $offset, $end, $invertsign=false) { - // first try and create a temporary file in the same directory as the file being scanned - if (($dataMD5filename = tempnam(dirname($file), preg_replace('#[^[:alnum:]]#i', '', basename($file)))) === false) { - // if that fails, create a temporary file in the system temp directory - if (($dataMD5filename = tempnam('/tmp', 'getID3')) === false) { - // if that fails, create a temporary file in the current directory - if (($dataMD5filename = tempnam('.', preg_replace('#[^[:alnum:]]#i', '', basename($file)))) === false) { - // can't find anywhere to create a temp file, just die - return false; - } - } - } - $md5 = false; - set_time_limit(max(filesize($file) / 1000000, 30)); + function md5_data($file, $offset, $end, $invertsign = false) + { + // first try and create a temporary file in the same directory as the file being scanned + if (($dataMD5filename = tempnam(dirname($file), preg_replace('#[^[:alnum:]]#i', '', basename($file)))) === false) { + // if that fails, create a temporary file in the system temp directory + if (($dataMD5filename = tempnam('/tmp', 'getID3')) === false) { + // if that fails, create a temporary file in the current directory + if (($dataMD5filename = tempnam('.', preg_replace('#[^[:alnum:]]#i', '', basename($file)))) === false) { + // can't find anywhere to create a temp file, just die + return false; + } + } + } + $md5 = false; + set_time_limit(max(filesize($file) / 1000000, 30)); - // copy parts of file - ob_start(); - if ($fp = fopen($file, 'rb')) { - ob_end_clean(); + // copy parts of file + ob_start(); + if ($fp = fopen($file, 'rb')) { + ob_end_clean(); - ob_start(); - if ($MD5fp = fopen($dataMD5filename, 'wb')) { + ob_start(); + if ($MD5fp = fopen($dataMD5filename, 'wb')) { + ob_end_clean(); + if ($invertsign) { + // Load conversion lookup strings for 8-bit unsigned->signed conversion below + $from = ''; + $to = ''; + for ($i = 0; $i < 128; $i++) { + $from .= chr($i); + $to .= chr($i + 128); + } + for ($i = 128; $i < 256; $i++) { + $from .= chr($i); + $to .= chr($i - 128); + } + } - ob_end_clean(); - if ($invertsign) { - // Load conversion lookup strings for 8-bit unsigned->signed conversion below - $from = ''; - $to = ''; - for ($i = 0; $i < 128; $i++) { - $from .= chr($i); - $to .= chr($i + 128); - } - for ($i = 128; $i < 256; $i++) { - $from .= chr($i); - $to .= chr($i - 128); - } - } + fseek($fp, $offset, SEEK_SET); + $byteslefttowrite = $end - $offset; + while (($byteslefttowrite > 0) && ($buffer = fread($fp, 32768))) { + if ($invertsign) { + // Possibly FLAC-specific (?) + // FLAC calculates the MD5sum of the source data of 8-bit files + // not on the actual byte values in the source file, but of those + // values converted from unsigned to signed, or more specifcally, + // with the MSB inverted. ex: 01 -> 81; F5 -> 75; etc - fseek($fp, $offset, SEEK_SET); - $byteslefttowrite = $end - $offset; - while (($byteslefttowrite > 0) && ($buffer = fread($fp, 32768))) { - if ($invertsign) { - // Possibly FLAC-specific (?) - // FLAC calculates the MD5sum of the source data of 8-bit files - // not on the actual byte values in the source file, but of those - // values converted from unsigned to signed, or more specifcally, - // with the MSB inverted. ex: 01 -> 81; F5 -> 75; etc + // Therefore, 8-bit WAV data has to be converted before getting the + // md5_data value so as to match the FLAC value - // Therefore, 8-bit WAV data has to be converted before getting the - // md5_data value so as to match the FLAC value + // Flip the MSB for each byte in the buffer before copying + $buffer = strtr($buffer, $from, $to); + } + $byteswritten = fwrite($MD5fp, $buffer, $byteslefttowrite); + $byteslefttowrite -= $byteswritten; + } + fclose($MD5fp); + $md5 = md5_file($dataMD5filename); + } else { + $errormessage = ob_get_contents(); + ob_end_clean(); + } + fclose($fp); + } else { + $errormessage = ob_get_contents(); + ob_end_clean(); + } + unlink($dataMD5filename); - // Flip the MSB for each byte in the buffer before copying - $buffer = strtr($buffer, $from, $to); - } - $byteswritten = fwrite($MD5fp, $buffer, $byteslefttowrite); - $byteslefttowrite -= $byteswritten; - } - fclose($MD5fp); - $md5 = md5_file($dataMD5filename); - - } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - } - fclose($fp); - - } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - } - unlink($dataMD5filename); - return $md5; - } + return $md5; + } } -if (!function_exists('TwosCompliment2Decimal')) { - function TwosCompliment2Decimal($BinaryValue) { - // http://sandbox.mc.edu/~bennet/cs110/tc/tctod.html - // First check if the number is negative or positive by looking at the sign bit. - // If it is positive, simply convert it to decimal. - // If it is negative, make it positive by inverting the bits and adding one. - // Then, convert the result to decimal. - // The negative of this number is the value of the original binary. +if (! function_exists('TwosCompliment2Decimal')) { + function TwosCompliment2Decimal($BinaryValue) + { + // http://sandbox.mc.edu/~bennet/cs110/tc/tctod.html + // First check if the number is negative or positive by looking at the sign bit. + // If it is positive, simply convert it to decimal. + // If it is negative, make it positive by inverting the bits and adding one. + // Then, convert the result to decimal. + // The negative of this number is the value of the original binary. - if ($BinaryValue & 0x80) { + if ($BinaryValue & 0x80) { - // negative number - return (0 - ((~$BinaryValue & 0xFF) + 1)); + // negative number + return 0 - ((~$BinaryValue & 0xFF) + 1); + } else { - } else { - - // positive number - return $BinaryValue; - - } - - } + // positive number + return $BinaryValue; + } + } } -if (!function_exists('LastArrayElement')) { - function LastArrayElement($MyArray) { - if (!is_array($MyArray)) { - return false; - } - if (empty($MyArray)) { - return null; - } - foreach ($MyArray as $key => $value) { - } - return $value; - } +if (! function_exists('LastArrayElement')) { + function LastArrayElement($MyArray) + { + if (! is_array($MyArray)) { + return false; + } + if (empty($MyArray)) { + return null; + } + foreach ($MyArray as $key => $value) { + } + + return $value; + } } -if (!function_exists('safe_inc')) { - function safe_inc(&$variable, $increment=1) { - if (isset($variable)) { - $variable += $increment; - } else { - $variable = $increment; - } - return true; - } +if (! function_exists('safe_inc')) { + function safe_inc(&$variable, $increment = 1) + { + if (isset($variable)) { + $variable += $increment; + } else { + $variable = $increment; + } + + return true; + } } -if (!function_exists('CalculateCompressionRatioVideo')) { - function CalculateCompressionRatioVideo(&$ThisFileInfo) { - if (empty($ThisFileInfo['video'])) { - return false; - } - if (empty($ThisFileInfo['video']['resolution_x']) || empty($ThisFileInfo['video']['resolution_y'])) { - return false; - } - if (empty($ThisFileInfo['video']['bits_per_sample'])) { - return false; - } +if (! function_exists('CalculateCompressionRatioVideo')) { + function CalculateCompressionRatioVideo(&$ThisFileInfo) + { + if (empty($ThisFileInfo['video'])) { + return false; + } + if (empty($ThisFileInfo['video']['resolution_x']) || empty($ThisFileInfo['video']['resolution_y'])) { + return false; + } + if (empty($ThisFileInfo['video']['bits_per_sample'])) { + return false; + } - switch ($ThisFileInfo['video']['dataformat']) { - case 'bmp': - case 'gif': - case 'jpeg': - case 'jpg': - case 'png': - case 'tiff': - $FrameRate = 1; - $PlaytimeSeconds = 1; - $BitrateCompressed = $ThisFileInfo['filesize'] * 8; - break; + switch ($ThisFileInfo['video']['dataformat']) { + case 'bmp': + case 'gif': + case 'jpeg': + case 'jpg': + case 'png': + case 'tiff': + $FrameRate = 1; + $PlaytimeSeconds = 1; + $BitrateCompressed = $ThisFileInfo['filesize'] * 8; + break; - default: - if (!empty($ThisFileInfo['video']['frame_rate'])) { - $FrameRate = $ThisFileInfo['video']['frame_rate']; - } else { - return false; - } - if (!empty($ThisFileInfo['playtime_seconds'])) { - $PlaytimeSeconds = $ThisFileInfo['playtime_seconds']; - } else { - return false; - } - if (!empty($ThisFileInfo['video']['bitrate'])) { - $BitrateCompressed = $ThisFileInfo['video']['bitrate']; - } else { - return false; - } - break; - } - $BitrateUncompressed = $ThisFileInfo['video']['resolution_x'] * $ThisFileInfo['video']['resolution_y'] * $ThisFileInfo['video']['bits_per_sample'] * $FrameRate; + default: + if (! empty($ThisFileInfo['video']['frame_rate'])) { + $FrameRate = $ThisFileInfo['video']['frame_rate']; + } else { + return false; + } + if (! empty($ThisFileInfo['playtime_seconds'])) { + $PlaytimeSeconds = $ThisFileInfo['playtime_seconds']; + } else { + return false; + } + if (! empty($ThisFileInfo['video']['bitrate'])) { + $BitrateCompressed = $ThisFileInfo['video']['bitrate']; + } else { + return false; + } + break; + } + $BitrateUncompressed = $ThisFileInfo['video']['resolution_x'] * $ThisFileInfo['video']['resolution_y'] * $ThisFileInfo['video']['bits_per_sample'] * $FrameRate; - $ThisFileInfo['video']['compression_ratio'] = $BitrateCompressed / $BitrateUncompressed; - return true; - } + $ThisFileInfo['video']['compression_ratio'] = $BitrateCompressed / $BitrateUncompressed; + + return true; + } } -if (!function_exists('CalculateCompressionRatioAudio')) { - function CalculateCompressionRatioAudio(&$ThisFileInfo) { - if (empty($ThisFileInfo['audio']['bitrate']) || empty($ThisFileInfo['audio']['channels']) || empty($ThisFileInfo['audio']['sample_rate']) || empty($ThisFileInfo['audio']['bits_per_sample'])) { - return false; - } - $ThisFileInfo['audio']['compression_ratio'] = $ThisFileInfo['audio']['bitrate'] / ($ThisFileInfo['audio']['channels'] * $ThisFileInfo['audio']['sample_rate'] * $ThisFileInfo['audio']['bits_per_sample']); - return true; - } +if (! function_exists('CalculateCompressionRatioAudio')) { + function CalculateCompressionRatioAudio(&$ThisFileInfo) + { + if (empty($ThisFileInfo['audio']['bitrate']) || empty($ThisFileInfo['audio']['channels']) || empty($ThisFileInfo['audio']['sample_rate']) || empty($ThisFileInfo['audio']['bits_per_sample'])) { + return false; + } + $ThisFileInfo['audio']['compression_ratio'] = $ThisFileInfo['audio']['bitrate'] / ($ThisFileInfo['audio']['channels'] * $ThisFileInfo['audio']['sample_rate'] * $ThisFileInfo['audio']['bits_per_sample']); + + return true; + } } -if (!function_exists('IsValidMIMEstring')) { - function IsValidMIMEstring($mimestring) { - if ((strlen($mimestring) >= 3) && (strpos($mimestring, '/') > 0) && (strpos($mimestring, '/') < (strlen($mimestring) - 1))) { - return true; - } - return false; - } +if (! function_exists('IsValidMIMEstring')) { + function IsValidMIMEstring($mimestring) + { + if ((strlen($mimestring) >= 3) && (strpos($mimestring, '/') > 0) && (strpos($mimestring, '/') < (strlen($mimestring) - 1))) { + return true; + } + + return false; + } } -if (!function_exists('IsWithinBitRange')) { - function IsWithinBitRange($number, $maxbits, $signed=false) { - if ($signed) { - if (($number > (0 - pow(2, $maxbits - 1))) && ($number <= pow(2, $maxbits - 1))) { - return true; - } - } else { - if (($number >= 0) && ($number <= pow(2, $maxbits))) { - return true; - } - } - return false; - } +if (! function_exists('IsWithinBitRange')) { + function IsWithinBitRange($number, $maxbits, $signed = false) + { + if ($signed) { + if (($number > (0 - pow(2, $maxbits - 1))) && ($number <= pow(2, $maxbits - 1))) { + return true; + } + } else { + if (($number >= 0) && ($number <= pow(2, $maxbits))) { + return true; + } + } + + return false; + } } -if (!function_exists('safe_parse_url')) { - function safe_parse_url($url) { - ob_start(); - $parts = parse_url($url); - $errormessage = ob_get_contents(); - ob_end_clean(); - $parts['scheme'] = (isset($parts['scheme']) ? $parts['scheme'] : ''); - $parts['host'] = (isset($parts['host']) ? $parts['host'] : ''); - $parts['user'] = (isset($parts['user']) ? $parts['user'] : ''); - $parts['pass'] = (isset($parts['pass']) ? $parts['pass'] : ''); - $parts['path'] = (isset($parts['path']) ? $parts['path'] : ''); - $parts['query'] = (isset($parts['query']) ? $parts['query'] : ''); - return $parts; - } +if (! function_exists('safe_parse_url')) { + function safe_parse_url($url) + { + ob_start(); + $parts = parse_url($url); + $errormessage = ob_get_contents(); + ob_end_clean(); + $parts['scheme'] = (isset($parts['scheme']) ? $parts['scheme'] : ''); + $parts['host'] = (isset($parts['host']) ? $parts['host'] : ''); + $parts['user'] = (isset($parts['user']) ? $parts['user'] : ''); + $parts['pass'] = (isset($parts['pass']) ? $parts['pass'] : ''); + $parts['path'] = (isset($parts['path']) ? $parts['path'] : ''); + $parts['query'] = (isset($parts['query']) ? $parts['query'] : ''); + + return $parts; + } } -if (!function_exists('IsValidURL')) { - function IsValidURL($url, $allowUserPass=false) { - if ($url == '') { - return false; - } - if ($allowUserPass !== true) { - if (strstr($url, '@')) { - // in the format http://user:pass@example.com or http://user@example.com - // but could easily be somebody incorrectly entering an email address in place of a URL - return false; - } - } - if ($parts = safe_parse_url($url)) { - if (($parts['scheme'] != 'http') && ($parts['scheme'] != 'https') && ($parts['scheme'] != 'ftp') && ($parts['scheme'] != 'gopher')) { - return false; - } elseif (!preg_match("#^[[:alnum:]]([-.]?[0-9a-z])*\.[a-z]{2,3}#i$", $parts['host'], $regs) && !preg_match('#^[0-9]{1,3}(\.[0-9]{1,3}){3}$#', $parts['host'])) { - return false; - } elseif (!preg_match("#^([[:alnum:]-]|[\_])*$#i", $parts['user'], $regs)) { - return false; - } elseif (!preg_match("#^([[:alnum:]-]|[\_])*$#i", $parts['pass'], $regs)) { - return false; - } elseif (!preg_match("#^[[:alnum:]/_\.@~-]*$#i", $parts['path'], $regs)) { - return false; - } elseif (!preg_match("#^[[:alnum:]?&=+:;_()%#/,\.-]*$#i", $parts['query'], $regs)) { - return false; - } else { - return true; - } - } - return false; - } +if (! function_exists('IsValidURL')) { + function IsValidURL($url, $allowUserPass = false) + { + if ($url == '') { + return false; + } + if ($allowUserPass !== true) { + if (strstr($url, '@')) { + // in the format http://user:pass@example.com or http://user@example.com + // but could easily be somebody incorrectly entering an email address in place of a URL + return false; + } + } + if ($parts = safe_parse_url($url)) { + if (($parts['scheme'] != 'http') && ($parts['scheme'] != 'https') && ($parts['scheme'] != 'ftp') && ($parts['scheme'] != 'gopher')) { + return false; + } elseif (! preg_match("#^[[:alnum:]]([-.]?[0-9a-z])*\.[a-z]{2,3}#i$", $parts['host'], $regs) && ! preg_match('#^[0-9]{1,3}(\.[0-9]{1,3}){3}$#', $parts['host'])) { + return false; + } elseif (! preg_match("#^([[:alnum:]-]|[\_])*$#i", $parts['user'], $regs)) { + return false; + } elseif (! preg_match("#^([[:alnum:]-]|[\_])*$#i", $parts['pass'], $regs)) { + return false; + } elseif (! preg_match("#^[[:alnum:]/_\.@~-]*$#i", $parts['path'], $regs)) { + return false; + } elseif (! preg_match("#^[[:alnum:]?&=+:;_()%#/,\.-]*$#i", $parts['query'], $regs)) { + return false; + } else { + return true; + } + } + + return false; + } } echo '
'; @@ -1356,217 +1456,224 @@ echo ''; -$MPEGgenerateValues = array( - 'version'=>array('1', '2', '2.5'), - 'layer'=>array('I', 'II', 'III'), - 'protection'=>array('Y', 'N'), - 'bitrate'=>array('free', '8', '16', '24', '32', '40', '48', '56', '64', '80', '96', '112', '128', '144', '160', '176', '192', '224', '256', '288', '320', '352', '384', '416', '448'), - 'frequency'=>array('8000', '11025', '12000', '16000', '22050', '24000', '32000', '44100', '48000'), - 'padding'=>array('Y', 'N'), - 'private'=>array('Y', 'N'), - 'channelmode'=>array('stereo', 'joint stereo', 'dual channel', 'mono'), - 'modeextension'=>array('none', 'IS', 'MS', 'IS+MS', '4-31', '8-31', '12-31', '16-31'), - 'copyright'=>array('Y', 'N'), - 'original'=>array('Y', 'N'), - 'emphasis'=>array('none', '50/15ms', 'CCIT J.17') - ); +$MPEGgenerateValues = [ + 'version'=>['1', '2', '2.5'], + 'layer'=>['I', 'II', 'III'], + 'protection'=>['Y', 'N'], + 'bitrate'=>['free', '8', '16', '24', '32', '40', '48', '56', '64', '80', '96', '112', '128', '144', '160', '176', '192', '224', '256', '288', '320', '352', '384', '416', '448'], + 'frequency'=>['8000', '11025', '12000', '16000', '22050', '24000', '32000', '44100', '48000'], + 'padding'=>['Y', 'N'], + 'private'=>['Y', 'N'], + 'channelmode'=>['stereo', 'joint stereo', 'dual channel', 'mono'], + 'modeextension'=>['none', 'IS', 'MS', 'IS+MS', '4-31', '8-31', '12-31', '16-31'], + 'copyright'=>['Y', 'N'], + 'original'=>['Y', 'N'], + 'emphasis'=>['none', '50/15ms', 'CCIT J.17'], + ]; foreach ($MPEGgenerateValues as $name => $dataarray) { - echo ''.$name.':'; + echo ''.$name.':'; } if (isset($_POST['bitrate'])) { - echo 'Frame Length:'.(int) MPEGaudioFrameLength($_POST['bitrate'], $_POST['version'], $_POST['layer'], (($_POST['padding'] == 'Y') ? '1' : '0'), $_POST['frequency']).''; + echo 'Frame Length:'.(int) MPEGaudioFrameLength($_POST['bitrate'], $_POST['version'], $_POST['layer'], (($_POST['padding'] == 'Y') ? '1' : '0'), $_POST['frequency']).''; } echo ''; echo '
'; echo '
'; - if (isset($_POST['Analyze']) && $_POST['HeaderHexBytes']) { + $headerbytearray = explode(' ', $_POST['HeaderHexBytes']); + if (count($headerbytearray) != 4) { + die('Invalid byte pattern'); + } + $headerstring = ''; + foreach ($headerbytearray as $textbyte) { + $headerstring .= chr(hexdec($textbyte)); + } - $headerbytearray = explode(' ', $_POST['HeaderHexBytes']); - if (count($headerbytearray) != 4) { - die('Invalid byte pattern'); - } - $headerstring = ''; - foreach ($headerbytearray as $textbyte) { - $headerstring .= chr(hexdec($textbyte)); - } + $MP3fileInfo['error'] = ''; - $MP3fileInfo['error'] = ''; + $MPEGheaderRawArray = MPEGaudioHeaderDecode(substr($headerstring, 0, 4)); - $MPEGheaderRawArray = MPEGaudioHeaderDecode(substr($headerstring, 0, 4)); + if (MPEGaudioHeaderValid($MPEGheaderRawArray, true)) { + $MP3fileInfo['raw'] = $MPEGheaderRawArray; - if (MPEGaudioHeaderValid($MPEGheaderRawArray, true)) { + $MP3fileInfo['version'] = MPEGaudioVersionLookup($MP3fileInfo['raw']['version']); + $MP3fileInfo['layer'] = MPEGaudioLayerLookup($MP3fileInfo['raw']['layer']); + $MP3fileInfo['protection'] = MPEGaudioCRCLookup($MP3fileInfo['raw']['protection']); + $MP3fileInfo['bitrate'] = MPEGaudioBitrateLookup($MP3fileInfo['version'], $MP3fileInfo['layer'], $MP3fileInfo['raw']['bitrate']); + $MP3fileInfo['frequency'] = MPEGaudioFrequencyLookup($MP3fileInfo['version'], $MP3fileInfo['raw']['sample_rate']); + $MP3fileInfo['padding'] = (bool) $MP3fileInfo['raw']['padding']; + $MP3fileInfo['private'] = (bool) $MP3fileInfo['raw']['private']; + $MP3fileInfo['channelmode'] = MPEGaudioChannelModeLookup($MP3fileInfo['raw']['channelmode']); + $MP3fileInfo['channels'] = (($MP3fileInfo['channelmode'] == 'mono') ? 1 : 2); + $MP3fileInfo['modeextension'] = MPEGaudioModeExtensionLookup($MP3fileInfo['layer'], $MP3fileInfo['raw']['modeextension']); + $MP3fileInfo['copyright'] = (bool) $MP3fileInfo['raw']['copyright']; + $MP3fileInfo['original'] = (bool) $MP3fileInfo['raw']['original']; + $MP3fileInfo['emphasis'] = MPEGaudioEmphasisLookup($MP3fileInfo['raw']['emphasis']); - $MP3fileInfo['raw'] = $MPEGheaderRawArray; + if ($MP3fileInfo['protection']) { + $MP3fileInfo['crc'] = BigEndian2Int(substr($headerstring, 4, 2)); + } - $MP3fileInfo['version'] = MPEGaudioVersionLookup($MP3fileInfo['raw']['version']); - $MP3fileInfo['layer'] = MPEGaudioLayerLookup($MP3fileInfo['raw']['layer']); - $MP3fileInfo['protection'] = MPEGaudioCRCLookup($MP3fileInfo['raw']['protection']); - $MP3fileInfo['bitrate'] = MPEGaudioBitrateLookup($MP3fileInfo['version'], $MP3fileInfo['layer'], $MP3fileInfo['raw']['bitrate']); - $MP3fileInfo['frequency'] = MPEGaudioFrequencyLookup($MP3fileInfo['version'], $MP3fileInfo['raw']['sample_rate']); - $MP3fileInfo['padding'] = (bool) $MP3fileInfo['raw']['padding']; - $MP3fileInfo['private'] = (bool) $MP3fileInfo['raw']['private']; - $MP3fileInfo['channelmode'] = MPEGaudioChannelModeLookup($MP3fileInfo['raw']['channelmode']); - $MP3fileInfo['channels'] = (($MP3fileInfo['channelmode'] == 'mono') ? 1 : 2); - $MP3fileInfo['modeextension'] = MPEGaudioModeExtensionLookup($MP3fileInfo['layer'], $MP3fileInfo['raw']['modeextension']); - $MP3fileInfo['copyright'] = (bool) $MP3fileInfo['raw']['copyright']; - $MP3fileInfo['original'] = (bool) $MP3fileInfo['raw']['original']; - $MP3fileInfo['emphasis'] = MPEGaudioEmphasisLookup($MP3fileInfo['raw']['emphasis']); + if ($MP3fileInfo['frequency'] > 0) { + $MP3fileInfo['framelength'] = MPEGaudioFrameLength($MP3fileInfo['bitrate'], $MP3fileInfo['version'], $MP3fileInfo['layer'], (int) $MP3fileInfo['padding'], $MP3fileInfo['frequency']); + } + if ($MP3fileInfo['bitrate'] != 'free') { + $MP3fileInfo['bitrate'] *= 1000; + } + } else { + $MP3fileInfo['error'] .= "\n".'Invalid MPEG audio header'; + } - if ($MP3fileInfo['protection']) { - $MP3fileInfo['crc'] = BigEndian2Int(substr($headerstring, 4, 2)); - } - - if ($MP3fileInfo['frequency'] > 0) { - $MP3fileInfo['framelength'] = MPEGaudioFrameLength($MP3fileInfo['bitrate'], $MP3fileInfo['version'], $MP3fileInfo['layer'], (int) $MP3fileInfo['padding'], $MP3fileInfo['frequency']); - } - if ($MP3fileInfo['bitrate'] != 'free') { - $MP3fileInfo['bitrate'] *= 1000; - } - - } else { - - $MP3fileInfo['error'] .= "\n".'Invalid MPEG audio header'; - - } - - if (!$MP3fileInfo['error']) { - unset($MP3fileInfo['error']); - } - - echo table_var_dump($MP3fileInfo); + if (! $MP3fileInfo['error']) { + unset($MP3fileInfo['error']); + } + echo table_var_dump($MP3fileInfo); } elseif (isset($_POST['Generate'])) { - // AAAA AAAA AAAB BCCD EEEE FFGH IIJJ KLMM + // AAAA AAAA AAAB BCCD EEEE FFGH IIJJ KLMM - $headerbitstream = '11111111111'; // A - Frame sync (all bits set) + $headerbitstream = '11111111111'; // A - Frame sync (all bits set) - $MPEGversionLookup = array('2.5'=>'00', '2'=>'10', '1'=>'11'); - $headerbitstream .= $MPEGversionLookup[$_POST['version']]; // B - MPEG Audio version ID + $MPEGversionLookup = ['2.5'=>'00', '2'=>'10', '1'=>'11']; + $headerbitstream .= $MPEGversionLookup[$_POST['version']]; // B - MPEG Audio version ID - $MPEGlayerLookup = array('III'=>'01', 'II'=>'10', 'I'=>'11'); - $headerbitstream .= $MPEGlayerLookup[$_POST['layer']]; // C - Layer description + $MPEGlayerLookup = ['III'=>'01', 'II'=>'10', 'I'=>'11']; + $headerbitstream .= $MPEGlayerLookup[$_POST['layer']]; // C - Layer description - $headerbitstream .= (($_POST['protection'] == 'Y') ? '0' : '1'); // D - Protection bit + $headerbitstream .= (($_POST['protection'] == 'Y') ? '0' : '1'); // D - Protection bit - $MPEGaudioBitrateLookup['1']['I'] = array('free'=>'0000', '32'=>'0001', '64'=>'0010', '96'=>'0011', '128'=>'0100', '160'=>'0101', '192'=>'0110', '224'=>'0111', '256'=>'1000', '288'=>'1001', '320'=>'1010', '352'=>'1011', '384'=>'1100', '416'=>'1101', '448'=>'1110'); - $MPEGaudioBitrateLookup['1']['II'] = array('free'=>'0000', '32'=>'0001', '48'=>'0010', '56'=>'0011', '64'=>'0100', '80'=>'0101', '96'=>'0110', '112'=>'0111', '128'=>'1000', '160'=>'1001', '192'=>'1010', '224'=>'1011', '256'=>'1100', '320'=>'1101', '384'=>'1110'); - $MPEGaudioBitrateLookup['1']['III'] = array('free'=>'0000', '32'=>'0001', '40'=>'0010', '48'=>'0011', '56'=>'0100', '64'=>'0101', '80'=>'0110', '96'=>'0111', '112'=>'1000', '128'=>'1001', '160'=>'1010', '192'=>'1011', '224'=>'1100', '256'=>'1101', '320'=>'1110'); - $MPEGaudioBitrateLookup['2']['I'] = array('free'=>'0000', '32'=>'0001', '48'=>'0010', '56'=>'0011', '64'=>'0100', '80'=>'0101', '96'=>'0110', '112'=>'0111', '128'=>'1000', '144'=>'1001', '160'=>'1010', '176'=>'1011', '192'=>'1100', '224'=>'1101', '256'=>'1110'); - $MPEGaudioBitrateLookup['2']['II'] = array('free'=>'0000', '8'=>'0001', '16'=>'0010', '24'=>'0011', '32'=>'0100', '40'=>'0101', '48'=>'0110', '56'=>'0111', '64'=>'1000', '80'=>'1001', '96'=>'1010', '112'=>'1011', '128'=>'1100', '144'=>'1101', '160'=>'1110'); - $MPEGaudioBitrateLookup['2']['III'] = $MPEGaudioBitrateLookup['2']['II']; - $MPEGaudioBitrateLookup['2.5']['I'] = $MPEGaudioBitrateLookup['2']['I']; - $MPEGaudioBitrateLookup['2.5']['II'] = $MPEGaudioBitrateLookup['2']['II']; - $MPEGaudioBitrateLookup['2.5']['III'] = $MPEGaudioBitrateLookup['2']['II']; - if (isset($MPEGaudioBitrateLookup[$_POST['version']][$_POST['layer']][$_POST['bitrate']])) { - $headerbitstream .= $MPEGaudioBitrateLookup[$_POST['version']][$_POST['layer']][$_POST['bitrate']]; // E - Bitrate index - } else { - die('Invalid Bitrate'); - } + $MPEGaudioBitrateLookup['1']['I'] = ['free'=>'0000', '32'=>'0001', '64'=>'0010', '96'=>'0011', '128'=>'0100', '160'=>'0101', '192'=>'0110', '224'=>'0111', '256'=>'1000', '288'=>'1001', '320'=>'1010', '352'=>'1011', '384'=>'1100', '416'=>'1101', '448'=>'1110']; + $MPEGaudioBitrateLookup['1']['II'] = ['free'=>'0000', '32'=>'0001', '48'=>'0010', '56'=>'0011', '64'=>'0100', '80'=>'0101', '96'=>'0110', '112'=>'0111', '128'=>'1000', '160'=>'1001', '192'=>'1010', '224'=>'1011', '256'=>'1100', '320'=>'1101', '384'=>'1110']; + $MPEGaudioBitrateLookup['1']['III'] = ['free'=>'0000', '32'=>'0001', '40'=>'0010', '48'=>'0011', '56'=>'0100', '64'=>'0101', '80'=>'0110', '96'=>'0111', '112'=>'1000', '128'=>'1001', '160'=>'1010', '192'=>'1011', '224'=>'1100', '256'=>'1101', '320'=>'1110']; + $MPEGaudioBitrateLookup['2']['I'] = ['free'=>'0000', '32'=>'0001', '48'=>'0010', '56'=>'0011', '64'=>'0100', '80'=>'0101', '96'=>'0110', '112'=>'0111', '128'=>'1000', '144'=>'1001', '160'=>'1010', '176'=>'1011', '192'=>'1100', '224'=>'1101', '256'=>'1110']; + $MPEGaudioBitrateLookup['2']['II'] = ['free'=>'0000', '8'=>'0001', '16'=>'0010', '24'=>'0011', '32'=>'0100', '40'=>'0101', '48'=>'0110', '56'=>'0111', '64'=>'1000', '80'=>'1001', '96'=>'1010', '112'=>'1011', '128'=>'1100', '144'=>'1101', '160'=>'1110']; + $MPEGaudioBitrateLookup['2']['III'] = $MPEGaudioBitrateLookup['2']['II']; + $MPEGaudioBitrateLookup['2.5']['I'] = $MPEGaudioBitrateLookup['2']['I']; + $MPEGaudioBitrateLookup['2.5']['II'] = $MPEGaudioBitrateLookup['2']['II']; + $MPEGaudioBitrateLookup['2.5']['III'] = $MPEGaudioBitrateLookup['2']['II']; + if (isset($MPEGaudioBitrateLookup[$_POST['version']][$_POST['layer']][$_POST['bitrate']])) { + $headerbitstream .= $MPEGaudioBitrateLookup[$_POST['version']][$_POST['layer']][$_POST['bitrate']]; // E - Bitrate index + } else { + die('Invalid Bitrate'); + } - $MPEGaudioFrequencyLookup['1'] = array('44100'=>'00', '48000'=>'01', '32000'=>'10'); - $MPEGaudioFrequencyLookup['2'] = array('22050'=>'00', '24000'=>'01', '16000'=>'10'); - $MPEGaudioFrequencyLookup['2.5'] = array('11025'=>'00', '12000'=>'01', '8000'=>'10'); - if (isset($MPEGaudioFrequencyLookup[$_POST['version']][$_POST['frequency']])) { - $headerbitstream .= $MPEGaudioFrequencyLookup[$_POST['version']][$_POST['frequency']]; // F - Sampling rate frequency index - } else { - die('Invalid Frequency'); - } + $MPEGaudioFrequencyLookup['1'] = ['44100'=>'00', '48000'=>'01', '32000'=>'10']; + $MPEGaudioFrequencyLookup['2'] = ['22050'=>'00', '24000'=>'01', '16000'=>'10']; + $MPEGaudioFrequencyLookup['2.5'] = ['11025'=>'00', '12000'=>'01', '8000'=>'10']; + if (isset($MPEGaudioFrequencyLookup[$_POST['version']][$_POST['frequency']])) { + $headerbitstream .= $MPEGaudioFrequencyLookup[$_POST['version']][$_POST['frequency']]; // F - Sampling rate frequency index + } else { + die('Invalid Frequency'); + } - $headerbitstream .= (($_POST['padding'] == 'Y') ? '1' : '0'); // G - Padding bit + $headerbitstream .= (($_POST['padding'] == 'Y') ? '1' : '0'); // G - Padding bit - $headerbitstream .= (($_POST['private'] == 'Y') ? '1' : '0'); // H - Private bit + $headerbitstream .= (($_POST['private'] == 'Y') ? '1' : '0'); // H - Private bit - $MPEGaudioChannelModeLookup = array('stereo'=>'00', 'joint stereo'=>'01', 'dual channel'=>'10', 'mono'=>'11'); - $headerbitstream .= $MPEGaudioChannelModeLookup[$_POST['channelmode']]; // I - Channel Mode + $MPEGaudioChannelModeLookup = ['stereo'=>'00', 'joint stereo'=>'01', 'dual channel'=>'10', 'mono'=>'11']; + $headerbitstream .= $MPEGaudioChannelModeLookup[$_POST['channelmode']]; // I - Channel Mode - $MPEGaudioModeExtensionLookup['I'] = array('4-31'=>'00', '8-31'=>'01', '12-31'=>'10', '16-31'=>'11'); - $MPEGaudioModeExtensionLookup['II'] = $MPEGaudioModeExtensionLookup['I']; - $MPEGaudioModeExtensionLookup['III'] = array('none'=>'00', 'IS'=>'01', 'MS'=>'10', 'IS+MS'=>'11'); - if ($_POST['channelmode'] != 'joint stereo') { - $headerbitstream .= '00'; - } elseif (isset($MPEGaudioModeExtensionLookup[$_POST['layer']][$_POST['modeextension']])) { - $headerbitstream .= $MPEGaudioModeExtensionLookup[$_POST['layer']][$_POST['modeextension']]; // J - Mode extension (Only if Joint stereo) - } else { - die('Invalid Mode Extension'); - } + $MPEGaudioModeExtensionLookup['I'] = ['4-31'=>'00', '8-31'=>'01', '12-31'=>'10', '16-31'=>'11']; + $MPEGaudioModeExtensionLookup['II'] = $MPEGaudioModeExtensionLookup['I']; + $MPEGaudioModeExtensionLookup['III'] = ['none'=>'00', 'IS'=>'01', 'MS'=>'10', 'IS+MS'=>'11']; + if ($_POST['channelmode'] != 'joint stereo') { + $headerbitstream .= '00'; + } elseif (isset($MPEGaudioModeExtensionLookup[$_POST['layer']][$_POST['modeextension']])) { + $headerbitstream .= $MPEGaudioModeExtensionLookup[$_POST['layer']][$_POST['modeextension']]; // J - Mode extension (Only if Joint stereo) + } else { + die('Invalid Mode Extension'); + } - $headerbitstream .= (($_POST['copyright'] == 'Y') ? '1' : '0'); // K - Copyright + $headerbitstream .= (($_POST['copyright'] == 'Y') ? '1' : '0'); // K - Copyright - $headerbitstream .= (($_POST['original'] == 'Y') ? '1' : '0'); // L - Original + $headerbitstream .= (($_POST['original'] == 'Y') ? '1' : '0'); // L - Original - $MPEGaudioEmphasisLookup = array('none'=>'00', '50/15ms'=>'01', 'CCIT J.17'=>'11'); - if (isset($MPEGaudioEmphasisLookup[$_POST['emphasis']])) { - $headerbitstream .= $MPEGaudioEmphasisLookup[$_POST['emphasis']]; // M - Emphasis - } else { - die('Invalid Emphasis'); - } - - echo strtoupper(str_pad(dechex(bindec(substr($headerbitstream, 0, 8))), 2, '0', STR_PAD_LEFT)).' '; - echo strtoupper(str_pad(dechex(bindec(substr($headerbitstream, 8, 8))), 2, '0', STR_PAD_LEFT)).' '; - echo strtoupper(str_pad(dechex(bindec(substr($headerbitstream, 16, 8))), 2, '0', STR_PAD_LEFT)).' '; - echo strtoupper(str_pad(dechex(bindec(substr($headerbitstream, 24, 8))), 2, '0', STR_PAD_LEFT)).'
'; + $MPEGaudioEmphasisLookup = ['none'=>'00', '50/15ms'=>'01', 'CCIT J.17'=>'11']; + if (isset($MPEGaudioEmphasisLookup[$_POST['emphasis']])) { + $headerbitstream .= $MPEGaudioEmphasisLookup[$_POST['emphasis']]; // M - Emphasis + } else { + die('Invalid Emphasis'); + } + echo strtoupper(str_pad(dechex(bindec(substr($headerbitstream, 0, 8))), 2, '0', STR_PAD_LEFT)).' '; + echo strtoupper(str_pad(dechex(bindec(substr($headerbitstream, 8, 8))), 2, '0', STR_PAD_LEFT)).' '; + echo strtoupper(str_pad(dechex(bindec(substr($headerbitstream, 16, 8))), 2, '0', STR_PAD_LEFT)).' '; + echo strtoupper(str_pad(dechex(bindec(substr($headerbitstream, 24, 8))), 2, '0', STR_PAD_LEFT)).'
'; } -function MPEGaudioVersionLookup($rawversion) { - $MPEGaudioVersionLookup = array('2.5', FALSE, '2', '1'); - return (isset($MPEGaudioVersionLookup["$rawversion"]) ? $MPEGaudioVersionLookup["$rawversion"] : FALSE); +function MPEGaudioVersionLookup($rawversion) +{ + $MPEGaudioVersionLookup = ['2.5', false, '2', '1']; + + return isset($MPEGaudioVersionLookup["$rawversion"]) ? $MPEGaudioVersionLookup["$rawversion"] : false; } -function MPEGaudioLayerLookup($rawlayer) { - $MPEGaudioLayerLookup = array(FALSE, 'III', 'II', 'I'); - return (isset($MPEGaudioLayerLookup["$rawlayer"]) ? $MPEGaudioLayerLookup["$rawlayer"] : FALSE); +function MPEGaudioLayerLookup($rawlayer) +{ + $MPEGaudioLayerLookup = [false, 'III', 'II', 'I']; + + return isset($MPEGaudioLayerLookup["$rawlayer"]) ? $MPEGaudioLayerLookup["$rawlayer"] : false; } -function MPEGaudioBitrateLookup($version, $layer, $rawbitrate) { - static $MPEGaudioBitrateLookup; - if (empty($MPEGaudioBitrateLookup)) { - $MPEGaudioBitrateLookup = MPEGaudioBitrateArray(); - } - return (isset($MPEGaudioBitrateLookup["$version"]["$layer"]["$rawbitrate"]) ? $MPEGaudioBitrateLookup["$version"]["$layer"]["$rawbitrate"] : FALSE); +function MPEGaudioBitrateLookup($version, $layer, $rawbitrate) +{ + static $MPEGaudioBitrateLookup; + if (empty($MPEGaudioBitrateLookup)) { + $MPEGaudioBitrateLookup = MPEGaudioBitrateArray(); + } + + return isset($MPEGaudioBitrateLookup["$version"]["$layer"]["$rawbitrate"]) ? $MPEGaudioBitrateLookup["$version"]["$layer"]["$rawbitrate"] : false; } -function MPEGaudioFrequencyLookup($version, $rawfrequency) { - static $MPEGaudioFrequencyLookup; - if (empty($MPEGaudioFrequencyLookup)) { - $MPEGaudioFrequencyLookup = MPEGaudioFrequencyArray(); - } - return (isset($MPEGaudioFrequencyLookup["$version"]["$rawfrequency"]) ? $MPEGaudioFrequencyLookup["$version"]["$rawfrequency"] : FALSE); +function MPEGaudioFrequencyLookup($version, $rawfrequency) +{ + static $MPEGaudioFrequencyLookup; + if (empty($MPEGaudioFrequencyLookup)) { + $MPEGaudioFrequencyLookup = MPEGaudioFrequencyArray(); + } + + return isset($MPEGaudioFrequencyLookup["$version"]["$rawfrequency"]) ? $MPEGaudioFrequencyLookup["$version"]["$rawfrequency"] : false; } -function MPEGaudioChannelModeLookup($rawchannelmode) { - $MPEGaudioChannelModeLookup = array('stereo', 'joint stereo', 'dual channel', 'mono'); - return (isset($MPEGaudioChannelModeLookup["$rawchannelmode"]) ? $MPEGaudioChannelModeLookup["$rawchannelmode"] : FALSE); +function MPEGaudioChannelModeLookup($rawchannelmode) +{ + $MPEGaudioChannelModeLookup = ['stereo', 'joint stereo', 'dual channel', 'mono']; + + return isset($MPEGaudioChannelModeLookup["$rawchannelmode"]) ? $MPEGaudioChannelModeLookup["$rawchannelmode"] : false; } -function MPEGaudioModeExtensionLookup($layer, $rawmodeextension) { - $MPEGaudioModeExtensionLookup['I'] = array('4-31', '8-31', '12-31', '16-31'); - $MPEGaudioModeExtensionLookup['II'] = array('4-31', '8-31', '12-31', '16-31'); - $MPEGaudioModeExtensionLookup['III'] = array('', 'IS', 'MS', 'IS+MS'); - return (isset($MPEGaudioModeExtensionLookup["$layer"]["$rawmodeextension"]) ? $MPEGaudioModeExtensionLookup["$layer"]["$rawmodeextension"] : FALSE); +function MPEGaudioModeExtensionLookup($layer, $rawmodeextension) +{ + $MPEGaudioModeExtensionLookup['I'] = ['4-31', '8-31', '12-31', '16-31']; + $MPEGaudioModeExtensionLookup['II'] = ['4-31', '8-31', '12-31', '16-31']; + $MPEGaudioModeExtensionLookup['III'] = ['', 'IS', 'MS', 'IS+MS']; + + return isset($MPEGaudioModeExtensionLookup["$layer"]["$rawmodeextension"]) ? $MPEGaudioModeExtensionLookup["$layer"]["$rawmodeextension"] : false; } -function MPEGaudioEmphasisLookup($rawemphasis) { - $MPEGaudioEmphasisLookup = array('none', '50/15ms', FALSE, 'CCIT J.17'); - return (isset($MPEGaudioEmphasisLookup["$rawemphasis"]) ? $MPEGaudioEmphasisLookup["$rawemphasis"] : FALSE); +function MPEGaudioEmphasisLookup($rawemphasis) +{ + $MPEGaudioEmphasisLookup = ['none', '50/15ms', false, 'CCIT J.17']; + + return isset($MPEGaudioEmphasisLookup["$rawemphasis"]) ? $MPEGaudioEmphasisLookup["$rawemphasis"] : false; } -function MPEGaudioCRCLookup($CRCbit) { - // inverse boolean cast :) - if ($CRCbit == '0') { - return TRUE; - } else { - return FALSE; - } +function MPEGaudioCRCLookup($CRCbit) +{ + // inverse boolean cast :) + if ($CRCbit == '0') { + return true; + } else { + return false; + } } ///////////////////////////////////////////////////////////////// @@ -1586,1304 +1693,1300 @@ function MPEGaudioCRCLookup($CRCbit) { // mpeg-audio streams define('MPEG_VALID_CHECK_FRAMES', 35); -function getMP3headerFilepointer(&$fd, &$ThisFileInfo) { +function getMP3headerFilepointer(&$fd, &$ThisFileInfo) +{ + getOnlyMPEGaudioInfo($fd, $ThisFileInfo, $ThisFileInfo['avdataoffset']); - getOnlyMPEGaudioInfo($fd, $ThisFileInfo, $ThisFileInfo['avdataoffset']); + if (isset($ThisFileInfo['mpeg']['audio']['bitrate_mode'])) { + $ThisFileInfo['audio']['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitrate_mode']); + } - if (isset($ThisFileInfo['mpeg']['audio']['bitrate_mode'])) { - $ThisFileInfo['audio']['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitrate_mode']); - } + if (((isset($ThisFileInfo['id3v2']) && ($ThisFileInfo['avdataoffset'] > $ThisFileInfo['id3v2']['headerlength'])) || (! isset($ThisFileInfo['id3v2']) && ($ThisFileInfo['avdataoffset'] > 0)))) { + $ThisFileInfo['warning'] .= "\n".'Unknown data before synch '; + if (isset($ThisFileInfo['id3v2']['headerlength'])) { + $ThisFileInfo['warning'] .= '(ID3v2 header ends at '.$ThisFileInfo['id3v2']['headerlength'].', then '.($ThisFileInfo['avdataoffset'] - $ThisFileInfo['id3v2']['headerlength']).' bytes garbage, '; + } else { + $ThisFileInfo['warning'] .= '(should be at beginning of file, '; + } + $ThisFileInfo['warning'] .= 'synch detected at '.$ThisFileInfo['avdataoffset'].')'; + if ($ThisFileInfo['audio']['bitrate_mode'] == 'cbr') { + if (! empty($ThisFileInfo['id3v2']['headerlength']) && (($ThisFileInfo['avdataoffset'] - $ThisFileInfo['id3v2']['headerlength']) == $ThisFileInfo['mpeg']['audio']['framelength'])) { + $ThisFileInfo['warning'] .= '. This is a known problem with some versions of LAME (3.91, 3.92) DLL in CBR mode.'; + $ThisFileInfo['audio']['codec'] = 'LAME'; + } elseif (empty($ThisFileInfo['id3v2']['headerlength']) && ($ThisFileInfo['avdataoffset'] == $ThisFileInfo['mpeg']['audio']['framelength'])) { + $ThisFileInfo['warning'] .= '. This is a known problem with some versions of LAME (3.91, 3.92) DLL in CBR mode.'; + $ThisFileInfo['audio']['codec'] = 'LAME'; + } + } + } - if (((isset($ThisFileInfo['id3v2']) && ($ThisFileInfo['avdataoffset'] > $ThisFileInfo['id3v2']['headerlength'])) || (!isset($ThisFileInfo['id3v2']) && ($ThisFileInfo['avdataoffset'] > 0)))) { + if (isset($ThisFileInfo['mpeg']['audio']['layer']) && ($ThisFileInfo['mpeg']['audio']['layer'] == 'II')) { + $ThisFileInfo['audio']['dataformat'] = 'mp2'; + } elseif (isset($ThisFileInfo['mpeg']['audio']['layer']) && ($ThisFileInfo['mpeg']['audio']['layer'] == 'I')) { + $ThisFileInfo['audio']['dataformat'] = 'mp1'; + } + if ($ThisFileInfo['fileformat'] == 'mp3') { + switch ($ThisFileInfo['audio']['dataformat']) { + case 'mp1': + case 'mp2': + case 'mp3': + $ThisFileInfo['fileformat'] = $ThisFileInfo['audio']['dataformat']; + break; - $ThisFileInfo['warning'] .= "\n".'Unknown data before synch '; - if (isset($ThisFileInfo['id3v2']['headerlength'])) { - $ThisFileInfo['warning'] .= '(ID3v2 header ends at '.$ThisFileInfo['id3v2']['headerlength'].', then '.($ThisFileInfo['avdataoffset'] - $ThisFileInfo['id3v2']['headerlength']).' bytes garbage, '; - } else { - $ThisFileInfo['warning'] .= '(should be at beginning of file, '; - } - $ThisFileInfo['warning'] .= 'synch detected at '.$ThisFileInfo['avdataoffset'].')'; - if ($ThisFileInfo['audio']['bitrate_mode'] == 'cbr') { - if (!empty($ThisFileInfo['id3v2']['headerlength']) && (($ThisFileInfo['avdataoffset'] - $ThisFileInfo['id3v2']['headerlength']) == $ThisFileInfo['mpeg']['audio']['framelength'])) { - $ThisFileInfo['warning'] .= '. This is a known problem with some versions of LAME (3.91, 3.92) DLL in CBR mode.'; - $ThisFileInfo['audio']['codec'] = 'LAME'; - } elseif (empty($ThisFileInfo['id3v2']['headerlength']) && ($ThisFileInfo['avdataoffset'] == $ThisFileInfo['mpeg']['audio']['framelength'])) { - $ThisFileInfo['warning'] .= '. This is a known problem with some versions of LAME (3.91, 3.92) DLL in CBR mode.'; - $ThisFileInfo['audio']['codec'] = 'LAME'; - } - } + default: + $ThisFileInfo['warning'] .= "\n".'Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$ThisFileInfo['audio']['dataformat'].'"'; + break; + } + } - } + if (empty($ThisFileInfo['fileformat'])) { + $ThisFileInfo['error'] .= "\n".'Synch not found'; + unset($ThisFileInfo['fileformat']); + unset($ThisFileInfo['audio']['bitrate_mode']); + unset($ThisFileInfo['avdataoffset']); + unset($ThisFileInfo['avdataend']); - if (isset($ThisFileInfo['mpeg']['audio']['layer']) && ($ThisFileInfo['mpeg']['audio']['layer'] == 'II')) { - $ThisFileInfo['audio']['dataformat'] = 'mp2'; - } elseif (isset($ThisFileInfo['mpeg']['audio']['layer']) && ($ThisFileInfo['mpeg']['audio']['layer'] == 'I')) { - $ThisFileInfo['audio']['dataformat'] = 'mp1'; - } - if ($ThisFileInfo['fileformat'] == 'mp3') { - switch ($ThisFileInfo['audio']['dataformat']) { - case 'mp1': - case 'mp2': - case 'mp3': - $ThisFileInfo['fileformat'] = $ThisFileInfo['audio']['dataformat']; - break; + return false; + } - default: - $ThisFileInfo['warning'] .= "\n".'Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$ThisFileInfo['audio']['dataformat'].'"'; - break; - } - } + $ThisFileInfo['mime_type'] = 'audio/mpeg'; + $ThisFileInfo['audio']['lossless'] = false; - if (empty($ThisFileInfo['fileformat'])) { - $ThisFileInfo['error'] .= "\n".'Synch not found'; - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['audio']['bitrate_mode']); - unset($ThisFileInfo['avdataoffset']); - unset($ThisFileInfo['avdataend']); - return false; - } + // Calculate playtime + if (! isset($ThisFileInfo['playtime_seconds']) && isset($ThisFileInfo['audio']['bitrate']) && ($ThisFileInfo['audio']['bitrate'] > 0)) { + $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['audio']['bitrate']; + } - $ThisFileInfo['mime_type'] = 'audio/mpeg'; - $ThisFileInfo['audio']['lossless'] = false; + if (isset($ThisFileInfo['mpeg']['audio']['LAME'])) { + $ThisFileInfo['audio']['codec'] = 'LAME'; + if (! empty($ThisFileInfo['mpeg']['audio']['LAME']['long_version'])) { + $ThisFileInfo['audio']['encoder'] = trim($ThisFileInfo['mpeg']['audio']['LAME']['long_version']); + } + } - // Calculate playtime - if (!isset($ThisFileInfo['playtime_seconds']) && isset($ThisFileInfo['audio']['bitrate']) && ($ThisFileInfo['audio']['bitrate'] > 0)) { - $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['audio']['bitrate']; - } - - if (isset($ThisFileInfo['mpeg']['audio']['LAME'])) { - $ThisFileInfo['audio']['codec'] = 'LAME'; - if (!empty($ThisFileInfo['mpeg']['audio']['LAME']['long_version'])) { - $ThisFileInfo['audio']['encoder'] = trim($ThisFileInfo['mpeg']['audio']['LAME']['long_version']); - } - } - - return true; + return true; } - -function decodeMPEGaudioHeader($fd, $offset, &$ThisFileInfo, $recursivesearch=true, $ScanAsCBR=false, $FastMPEGheaderScan=false) { - - static $MPEGaudioVersionLookup; - static $MPEGaudioLayerLookup; - static $MPEGaudioBitrateLookup; - static $MPEGaudioFrequencyLookup; - static $MPEGaudioChannelModeLookup; - static $MPEGaudioModeExtensionLookup; - static $MPEGaudioEmphasisLookup; - if (empty($MPEGaudioVersionLookup)) { - $MPEGaudioVersionLookup = MPEGaudioVersionArray(); - $MPEGaudioLayerLookup = MPEGaudioLayerArray(); - $MPEGaudioBitrateLookup = MPEGaudioBitrateArray(); - $MPEGaudioFrequencyLookup = MPEGaudioFrequencyArray(); - $MPEGaudioChannelModeLookup = MPEGaudioChannelModeArray(); - $MPEGaudioModeExtensionLookup = MPEGaudioModeExtensionArray(); - $MPEGaudioEmphasisLookup = MPEGaudioEmphasisArray(); - } - - if ($offset >= $ThisFileInfo['avdataend']) { - $ThisFileInfo['error'] .= "\n".'end of file encounter looking for MPEG synch'; - return false; - } - fseek($fd, $offset, SEEK_SET); - $headerstring = fread($fd, 1441); // worse-case max length = 32kHz @ 320kbps layer 3 = 1441 bytes/frame - - // MP3 audio frame structure: - // $aa $aa $aa $aa [$bb $bb] $cc... - // where $aa..$aa is the four-byte mpeg-audio header (below) - // $bb $bb is the optional 2-byte CRC - // and $cc... is the audio data - - $head4 = substr($headerstring, 0, 4); - - static $MPEGaudioHeaderDecodeCache = array(); - if (isset($MPEGaudioHeaderDecodeCache[$head4])) { - $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4]; - } else { - $MPEGheaderRawArray = MPEGaudioHeaderDecode($head4); - $MPEGaudioHeaderDecodeCache[$head4] = $MPEGheaderRawArray; - } - - static $MPEGaudioHeaderValidCache = array(); - - // Not in cache - if (!isset($MPEGaudioHeaderValidCache[$head4])) { - $MPEGaudioHeaderValidCache[$head4] = MPEGaudioHeaderValid($MPEGheaderRawArray); - } - - if ($MPEGaudioHeaderValidCache[$head4]) { - $ThisFileInfo['mpeg']['audio']['raw'] = $MPEGheaderRawArray; - } else { - $ThisFileInfo['error'] .= "\n".'Invalid MPEG audio header at offset '.$offset; - return false; - } - - if (!$FastMPEGheaderScan) { - - $ThisFileInfo['mpeg']['audio']['version'] = $MPEGaudioVersionLookup[$ThisFileInfo['mpeg']['audio']['raw']['version']]; - $ThisFileInfo['mpeg']['audio']['layer'] = $MPEGaudioLayerLookup[$ThisFileInfo['mpeg']['audio']['raw']['layer']]; - - $ThisFileInfo['mpeg']['audio']['channelmode'] = $MPEGaudioChannelModeLookup[$ThisFileInfo['mpeg']['audio']['raw']['channelmode']]; - $ThisFileInfo['mpeg']['audio']['channels'] = (($ThisFileInfo['mpeg']['audio']['channelmode'] == 'mono') ? 1 : 2); - $ThisFileInfo['mpeg']['audio']['sample_rate'] = $MPEGaudioFrequencyLookup[$ThisFileInfo['mpeg']['audio']['version']][$ThisFileInfo['mpeg']['audio']['raw']['sample_rate']]; - $ThisFileInfo['mpeg']['audio']['protection'] = !$ThisFileInfo['mpeg']['audio']['raw']['protection']; - $ThisFileInfo['mpeg']['audio']['private'] = (bool) $ThisFileInfo['mpeg']['audio']['raw']['private']; - $ThisFileInfo['mpeg']['audio']['modeextension'] = $MPEGaudioModeExtensionLookup[$ThisFileInfo['mpeg']['audio']['layer']][$ThisFileInfo['mpeg']['audio']['raw']['modeextension']]; - $ThisFileInfo['mpeg']['audio']['copyright'] = (bool) $ThisFileInfo['mpeg']['audio']['raw']['copyright']; - $ThisFileInfo['mpeg']['audio']['original'] = (bool) $ThisFileInfo['mpeg']['audio']['raw']['original']; - $ThisFileInfo['mpeg']['audio']['emphasis'] = $MPEGaudioEmphasisLookup[$ThisFileInfo['mpeg']['audio']['raw']['emphasis']]; - - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['mpeg']['audio']['channels']; - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate']; - - if ($ThisFileInfo['mpeg']['audio']['protection']) { - $ThisFileInfo['mpeg']['audio']['crc'] = BigEndian2Int(substr($headerstring, 4, 2)); - } - - } - - if ($ThisFileInfo['mpeg']['audio']['raw']['bitrate'] == 15) { - // http://www.hydrogenaudio.org/?act=ST&f=16&t=9682&st=0 - $ThisFileInfo['warning'] .= "\n".'Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1'; - $ThisFileInfo['mpeg']['audio']['raw']['bitrate'] = 0; - } - $ThisFileInfo['mpeg']['audio']['padding'] = (bool) $ThisFileInfo['mpeg']['audio']['raw']['padding']; - $ThisFileInfo['mpeg']['audio']['bitrate'] = $MPEGaudioBitrateLookup[$ThisFileInfo['mpeg']['audio']['version']][$ThisFileInfo['mpeg']['audio']['layer']][$ThisFileInfo['mpeg']['audio']['raw']['bitrate']]; - - if (($ThisFileInfo['mpeg']['audio']['bitrate'] == 'free') && ($offset == $ThisFileInfo['avdataoffset'])) { - // only skip multiple frame check if free-format bitstream found at beginning of file - // otherwise is quite possibly simply corrupted data - $recursivesearch = false; - } - - // For Layer II there are some combinations of bitrate and mode which are not allowed. - if (!$FastMPEGheaderScan && ($ThisFileInfo['mpeg']['audio']['layer'] == 'II')) { - - $ThisFileInfo['audio']['dataformat'] = 'mp2'; - switch ($ThisFileInfo['mpeg']['audio']['channelmode']) { - - case 'mono': - if (($ThisFileInfo['mpeg']['audio']['bitrate'] == 'free') || ($ThisFileInfo['mpeg']['audio']['bitrate'] <= 192)) { - // these are ok - } else { - $ThisFileInfo['error'] .= "\n".$ThisFileInfo['mpeg']['audio']['bitrate'].'kbps not allowed in Layer II, '.$ThisFileInfo['mpeg']['audio']['channelmode'].'.'; - return false; - } - break; - - case 'stereo': - case 'joint stereo': - case 'dual channel': - if (($ThisFileInfo['mpeg']['audio']['bitrate'] == 'free') || ($ThisFileInfo['mpeg']['audio']['bitrate'] == 64) || ($ThisFileInfo['mpeg']['audio']['bitrate'] >= 96)) { - // these are ok - } else { - $ThisFileInfo['error'] .= "\n".$ThisFileInfo['mpeg']['audio']['bitrate'].'kbps not allowed in Layer II, '.$ThisFileInfo['mpeg']['audio']['channelmode'].'.'; - return false; - } - break; - - } - - } - - - if ($ThisFileInfo['audio']['sample_rate'] > 0) { - $ThisFileInfo['mpeg']['audio']['framelength'] = MPEGaudioFrameLength($ThisFileInfo['mpeg']['audio']['bitrate'], $ThisFileInfo['mpeg']['audio']['version'], $ThisFileInfo['mpeg']['audio']['layer'], (int) $ThisFileInfo['mpeg']['audio']['padding'], $ThisFileInfo['audio']['sample_rate']); - } - - if ($ThisFileInfo['mpeg']['audio']['bitrate'] != 'free') { - - $ThisFileInfo['audio']['bitrate'] = 1000 * $ThisFileInfo['mpeg']['audio']['bitrate']; - - if (isset($ThisFileInfo['mpeg']['audio']['framelength'])) { - $nextframetestoffset = $offset + $ThisFileInfo['mpeg']['audio']['framelength']; - } else { - $ThisFileInfo['error'] .= "\n".'Frame at offset('.$offset.') is has an invalid frame length.'; - return false; - } - - } - - $ExpectedNumberOfAudioBytes = 0; - - //////////////////////////////////////////////////////////////////////////////////// - // Variable-bitrate headers - - if (substr($headerstring, 4 + 32, 4) == 'VBRI') { - // Fraunhofer VBR header is hardcoded 'VBRI' at offset 0x24 (36) - // specs taken from http://minnie.tuhs.org/pipermail/mp3encoder/2001-January/001800.html - - $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'vbr'; - $ThisFileInfo['mpeg']['audio']['VBR_method'] = 'Fraunhofer'; - $ThisFileInfo['audio']['codec'] = 'Fraunhofer'; - - $SideInfoData = substr($headerstring, 4 + 2, 32); - - $FraunhoferVBROffset = 36; - - $ThisFileInfo['mpeg']['audio']['VBR_encoder_version'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 4, 2)); - $ThisFileInfo['mpeg']['audio']['VBR_encoder_delay'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 6, 2)); - $ThisFileInfo['mpeg']['audio']['VBR_quality'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 8, 2)); - $ThisFileInfo['mpeg']['audio']['VBR_bytes'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 10, 4)); - $ThisFileInfo['mpeg']['audio']['VBR_frames'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 14, 4)); - $ThisFileInfo['mpeg']['audio']['VBR_seek_offsets'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 18, 2)); - //$ThisFileInfo['mpeg']['audio']['reserved'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 20, 4)); // hardcoded $00 $01 $00 $02 - purpose unknown - $ThisFileInfo['mpeg']['audio']['VBR_seek_offsets_stride'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 24, 2)); - - $ExpectedNumberOfAudioBytes = $ThisFileInfo['mpeg']['audio']['VBR_bytes']; - - $previousbyteoffset = $offset; - for ($i = 0; $i < $ThisFileInfo['mpeg']['audio']['VBR_seek_offsets']; $i++) { - $Fraunhofer_OffsetN = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset, 2)); - $FraunhoferVBROffset += 2; - $ThisFileInfo['mpeg']['audio']['VBR_offsets_relative'][$i] = $Fraunhofer_OffsetN; - $ThisFileInfo['mpeg']['audio']['VBR_offsets_absolute'][$i] = $Fraunhofer_OffsetN + $previousbyteoffset; - $previousbyteoffset += $Fraunhofer_OffsetN; - } - - - } else { - - // Xing VBR header is hardcoded 'Xing' at a offset 0x0D (13), 0x15 (21) or 0x24 (36) - // depending on MPEG layer and number of channels - - if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { - if ($ThisFileInfo['mpeg']['audio']['channelmode'] == 'mono') { - // MPEG-1 (mono) - $VBRidOffset = 4 + 17; // 0x15 - $SideInfoData = substr($headerstring, 4 + 2, 17); - } else { - // MPEG-1 (stereo, joint-stereo, dual-channel) - $VBRidOffset = 4 + 32; // 0x24 - $SideInfoData = substr($headerstring, 4 + 2, 32); - } - } else { // 2 or 2.5 - if ($ThisFileInfo['mpeg']['audio']['channelmode'] == 'mono') { - // MPEG-2, MPEG-2.5 (mono) - $VBRidOffset = 4 + 9; // 0x0D - $SideInfoData = substr($headerstring, 4 + 2, 9); - } else { - // MPEG-2, MPEG-2.5 (stereo, joint-stereo, dual-channel) - $VBRidOffset = 4 + 17; // 0x15 - $SideInfoData = substr($headerstring, 4 + 2, 17); - } - } - - if ((substr($headerstring, $VBRidOffset, strlen('Xing')) == 'Xing') || (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Info')) { - // 'Xing' is traditional Xing VBR frame - // 'Info' is LAME-encoded CBR (This was done to avoid CBR files to be recognized as traditional Xing VBR files by some decoders.) - - $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'vbr'; - $ThisFileInfo['mpeg']['audio']['VBR_method'] = 'Xing'; - - $ThisFileInfo['mpeg']['audio']['xing_flags_raw'] = BigEndian2Int(substr($headerstring, $VBRidOffset + 4, 4)); - - $ThisFileInfo['mpeg']['audio']['xing_flags']['frames'] = (bool) ($ThisFileInfo['mpeg']['audio']['xing_flags_raw'] & 0x00000001); - $ThisFileInfo['mpeg']['audio']['xing_flags']['bytes'] = (bool) ($ThisFileInfo['mpeg']['audio']['xing_flags_raw'] & 0x00000002); - $ThisFileInfo['mpeg']['audio']['xing_flags']['toc'] = (bool) ($ThisFileInfo['mpeg']['audio']['xing_flags_raw'] & 0x00000004); - $ThisFileInfo['mpeg']['audio']['xing_flags']['vbr_scale'] = (bool) ($ThisFileInfo['mpeg']['audio']['xing_flags_raw'] & 0x00000008); - - if ($ThisFileInfo['mpeg']['audio']['xing_flags']['frames']) { - $ThisFileInfo['mpeg']['audio']['VBR_frames'] = BigEndian2Int(substr($headerstring, $VBRidOffset + 8, 4)); - } - if ($ThisFileInfo['mpeg']['audio']['xing_flags']['bytes']) { - $ThisFileInfo['mpeg']['audio']['VBR_bytes'] = BigEndian2Int(substr($headerstring, $VBRidOffset + 12, 4)); - } - - if (($ThisFileInfo['mpeg']['audio']['bitrate'] == 'free') && !empty($ThisFileInfo['mpeg']['audio']['VBR_frames']) && !empty($ThisFileInfo['mpeg']['audio']['VBR_bytes'])) { - $framelengthfloat = $ThisFileInfo['mpeg']['audio']['VBR_bytes'] / $ThisFileInfo['mpeg']['audio']['VBR_frames']; - if ($ThisFileInfo['mpeg']['audio']['layer'] == 'I') { - // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12 - $ThisFileInfo['audio']['bitrate'] = ((($framelengthfloat / 4) - intval($ThisFileInfo['mpeg']['audio']['padding'])) * $ThisFileInfo['mpeg']['audio']['sample_rate']) / 12; - } else { - // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144 - $ThisFileInfo['audio']['bitrate'] = (($framelengthfloat - intval($ThisFileInfo['mpeg']['audio']['padding'])) * $ThisFileInfo['mpeg']['audio']['sample_rate']) / 144; - } - $ThisFileInfo['mpeg']['audio']['framelength'] = floor($framelengthfloat); - } - - if ($ThisFileInfo['mpeg']['audio']['xing_flags']['toc']) { - $LAMEtocData = substr($headerstring, $VBRidOffset + 16, 100); - for ($i = 0; $i < 100; $i++) { - $ThisFileInfo['mpeg']['audio']['toc'][$i] = ord($LAMEtocData{$i}); - } - } - if ($ThisFileInfo['mpeg']['audio']['xing_flags']['vbr_scale']) { - $ThisFileInfo['mpeg']['audio']['VBR_scale'] = BigEndian2Int(substr($headerstring, $VBRidOffset + 116, 4)); - } - - // http://gabriel.mp3-tech.org/mp3infotag.html - if (substr($headerstring, $VBRidOffset + 120, 4) == 'LAME') { - $ThisFileInfo['mpeg']['audio']['LAME']['long_version'] = substr($headerstring, $VBRidOffset + 120, 20); - $ThisFileInfo['mpeg']['audio']['LAME']['short_version'] = substr($ThisFileInfo['mpeg']['audio']['LAME']['long_version'], 0, 9); - $ThisFileInfo['mpeg']['audio']['LAME']['long_version'] = rtrim($ThisFileInfo['mpeg']['audio']['LAME']['long_version'], "\x55\xAA"); - - if ($ThisFileInfo['mpeg']['audio']['LAME']['short_version'] >= 'LAME3.90.') { - - // It the LAME tag was only introduced in LAME v3.90 - // http://www.hydrogenaudio.org/?act=ST&f=15&t=9933 - - // Offsets of various bytes in http://gabriel.mp3-tech.org/mp3infotag.html - // are assuming a 'Xing' identifier offset of 0x24, which is the case for - // MPEG-1 non-mono, but not for other combinations - $LAMEtagOffsetContant = $VBRidOffset - 0x24; - - // byte $9B VBR Quality - // This field is there to indicate a quality level, although the scale was not precised in the original Xing specifications. - // Actually overwrites original Xing bytes - unset($ThisFileInfo['mpeg']['audio']['VBR_scale']); - $ThisFileInfo['mpeg']['audio']['LAME']['vbr_quality'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0x9B, 1)); - - // bytes $9C-$A4 Encoder short VersionString - $ThisFileInfo['mpeg']['audio']['LAME']['short_version'] = substr($headerstring, $LAMEtagOffsetContant + 0x9C, 9); - $ThisFileInfo['mpeg']['audio']['LAME']['long_version'] = $ThisFileInfo['mpeg']['audio']['LAME']['short_version']; - - // byte $A5 Info Tag revision + VBR method - $LAMEtagRevisionVBRmethod = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA5, 1)); - - $ThisFileInfo['mpeg']['audio']['LAME']['tag_revision'] = ($LAMEtagRevisionVBRmethod & 0xF0) >> 4; - $ThisFileInfo['mpeg']['audio']['LAME']['raw']['vbr_method'] = $LAMEtagRevisionVBRmethod & 0x0F; - $ThisFileInfo['mpeg']['audio']['LAME']['vbr_method'] = LAMEvbrMethodLookup($ThisFileInfo['mpeg']['audio']['LAME']['raw']['vbr_method']); - - // byte $A6 Lowpass filter value - $ThisFileInfo['mpeg']['audio']['LAME']['lowpass_frequency'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100; - - // bytes $A7-$AE Replay Gain - // http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html - // bytes $A7-$AA : 32 bit floating point "Peak signal amplitude" - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude'] = BigEndian2Float(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4)); - $ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAB, 2)); - $ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAD, 2)); - - if ($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude'] == 0) { - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude'] = false; - } - - if ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] != 0) { - require_once(GETID3_INCLUDEPATH.'getid3.rgad.php'); - - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['name'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] & 0xE000) >> 13; - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['originator'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] & 0x1C00) >> 10; - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['sign_bit'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] & 0x0200) >> 9; - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['gain_adjust'] = $ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] & 0x01FF; - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['name'] = RGADnameLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['name']); - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['originator'] = RGADoriginatorLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['originator']); - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['gain_db'] = RGADadjustmentLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['gain_adjust'], $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['sign_bit']); - - if ($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude'] !== false) { - $ThisFileInfo['replay_gain']['radio']['peak'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude']; - } - $ThisFileInfo['replay_gain']['radio']['originator'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['originator']; - $ThisFileInfo['replay_gain']['radio']['adjustment'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['gain_db']; - } - if ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] != 0) { - require_once(GETID3_INCLUDEPATH.'getid3.rgad.php'); - - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['name'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] & 0xE000) >> 13; - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['originator'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] & 0x1C00) >> 10; - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['sign_bit'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] & 0x0200) >> 9; - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['gain_adjust'] = $ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] & 0x01FF; - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['name'] = RGADnameLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['name']); - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['originator'] = RGADoriginatorLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['originator']); - $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['gain_db'] = RGADadjustmentLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['gain_adjust'], $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['sign_bit']); - - if ($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude'] !== false) { - $ThisFileInfo['replay_gain']['audiophile']['peak'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude']; - } - $ThisFileInfo['replay_gain']['audiophile']['originator'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['originator']; - $ThisFileInfo['replay_gain']['audiophile']['adjustment'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['gain_db']; - } - - - // byte $AF Encoding flags + ATH Type - $EncodingFlagsATHtype = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAF, 1)); - $ThisFileInfo['mpeg']['audio']['LAME']['encoding_flags']['nspsytune'] = (bool) ($EncodingFlagsATHtype & 0x10); - $ThisFileInfo['mpeg']['audio']['LAME']['encoding_flags']['nssafejoint'] = (bool) ($EncodingFlagsATHtype & 0x20); - $ThisFileInfo['mpeg']['audio']['LAME']['encoding_flags']['nogap_next'] = (bool) ($EncodingFlagsATHtype & 0x40); - $ThisFileInfo['mpeg']['audio']['LAME']['encoding_flags']['nogap_prev'] = (bool) ($EncodingFlagsATHtype & 0x80); - $ThisFileInfo['mpeg']['audio']['LAME']['ath_type'] = $EncodingFlagsATHtype & 0x0F; - - // byte $B0 if ABR {specified bitrate} else {minimal bitrate} - $ABRbitrateMinBitrate = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB0, 1)); - if ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['vbr_method'] == 2) { // Average BitRate (ABR) - $ThisFileInfo['mpeg']['audio']['LAME']['bitrate_abr'] = $ABRbitrateMinBitrate; - } elseif ($ABRbitrateMinBitrate > 0) { // Variable BitRate (VBR) - minimum bitrate - $ThisFileInfo['mpeg']['audio']['LAME']['bitrate_min'] = $ABRbitrateMinBitrate; - } - - // bytes $B1-$B3 Encoder delays - $EncoderDelays = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB1, 3)); - $ThisFileInfo['mpeg']['audio']['LAME']['encoder_delay'] = ($EncoderDelays & 0xFFF000) >> 12; - $ThisFileInfo['mpeg']['audio']['LAME']['end_padding'] = $EncoderDelays & 0x000FFF; - - // byte $B4 Misc - $MiscByte = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB4, 1)); - $ThisFileInfo['mpeg']['audio']['LAME']['raw']['noise_shaping'] = ($MiscByte & 0x03); - $ThisFileInfo['mpeg']['audio']['LAME']['raw']['stereo_mode'] = ($MiscByte & 0x1C) >> 2; - $ThisFileInfo['mpeg']['audio']['LAME']['raw']['not_optimal_quality'] = ($MiscByte & 0x20) >> 5; - $ThisFileInfo['mpeg']['audio']['LAME']['raw']['source_sample_freq'] = ($MiscByte & 0xC0) >> 6; - $ThisFileInfo['mpeg']['audio']['LAME']['noise_shaping'] = $ThisFileInfo['mpeg']['audio']['LAME']['raw']['noise_shaping']; - $ThisFileInfo['mpeg']['audio']['LAME']['stereo_mode'] = LAMEmiscStereoModeLookup($ThisFileInfo['mpeg']['audio']['LAME']['raw']['stereo_mode']); - $ThisFileInfo['mpeg']['audio']['LAME']['not_optimal_quality'] = (bool) $ThisFileInfo['mpeg']['audio']['LAME']['raw']['not_optimal_quality']; - $ThisFileInfo['mpeg']['audio']['LAME']['source_sample_freq'] = LAMEmiscSourceSampleFrequencyLookup($ThisFileInfo['mpeg']['audio']['LAME']['raw']['source_sample_freq']); - - // byte $B5 MP3 Gain - $ThisFileInfo['mpeg']['audio']['LAME']['raw']['mp3_gain'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB5, 1), false, true); - $ThisFileInfo['mpeg']['audio']['LAME']['mp3_gain_db'] = 1.5 * $ThisFileInfo['mpeg']['audio']['LAME']['raw']['mp3_gain']; - $ThisFileInfo['mpeg']['audio']['LAME']['mp3_gain_factor'] = pow(2, ($ThisFileInfo['mpeg']['audio']['LAME']['mp3_gain_db'] / 6)); - - // bytes $B6-$B7 Preset and surround info - $PresetSurroundBytes = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB6, 2)); - // Reserved = ($PresetSurroundBytes & 0xC000); - $ThisFileInfo['mpeg']['audio']['LAME']['raw']['surround_info'] = ($PresetSurroundBytes & 0x3800); - $ThisFileInfo['mpeg']['audio']['LAME']['surround_info'] = LAMEsurroundInfoLookup($ThisFileInfo['mpeg']['audio']['LAME']['raw']['surround_info']); - $ThisFileInfo['mpeg']['audio']['LAME']['preset_used_id'] = ($PresetSurroundBytes & 0x07FF); - - // bytes $B8-$BB MusicLength - $ThisFileInfo['mpeg']['audio']['LAME']['audio_bytes'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB8, 4)); - $ExpectedNumberOfAudioBytes = (($ThisFileInfo['mpeg']['audio']['LAME']['audio_bytes'] > 0) ? $ThisFileInfo['mpeg']['audio']['LAME']['audio_bytes'] : $ThisFileInfo['mpeg']['audio']['VBR_bytes']); - - // bytes $BC-$BD MusicCRC - $ThisFileInfo['mpeg']['audio']['LAME']['music_crc'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBC, 2)); - - // bytes $BE-$BF CRC-16 of Info Tag - $ThisFileInfo['mpeg']['audio']['LAME']['lame_tag_crc'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBE, 2)); - - - // LAME CBR - if ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['vbr_method'] == 1) { - - $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'cbr'; - if (empty($ThisFileInfo['mpeg']['audio']['bitrate']) || ($ThisFileInfo['mpeg']['audio']['LAME']['bitrate_min'] != 255)) { - $ThisFileInfo['mpeg']['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['LAME']['bitrate_min']; - } - - } - - } - } - - } else { - - // not Fraunhofer or Xing VBR methods, most likely CBR (but could be VBR with no header) - $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'cbr'; - if ($recursivesearch) { - $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'vbr'; - if (RecursiveFrameScanning($fd, $ThisFileInfo, $offset, $nextframetestoffset, true)) { - $recursivesearch = false; - $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'cbr'; - } - if ($ThisFileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr') { - $ThisFileInfo['warning'] .= "\n".'VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.'; - } - } - - } - - } - - if (($ExpectedNumberOfAudioBytes > 0) && ($ExpectedNumberOfAudioBytes != ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']))) { - if (($ExpectedNumberOfAudioBytes - ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'])) == 1) { - $ThisFileInfo['warning'] .= "\n".'Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)'; - } elseif ($ExpectedNumberOfAudioBytes > ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'])) { - $ThisFileInfo['warning'] .= "\n".'Probable truncated file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, only found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']).' (short by '.($ExpectedNumberOfAudioBytes - ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'])).' bytes)'; - } else { - $ThisFileInfo['warning'] .= "\n".'Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']).' ('.(($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)'; - } - } - - if (($ThisFileInfo['mpeg']['audio']['bitrate'] == 'free') && empty($ThisFileInfo['audio']['bitrate'])) { - if (($offset == $ThisFileInfo['avdataoffset']) && empty($ThisFileInfo['mpeg']['audio']['VBR_frames'])) { - $framebytelength = FreeFormatFrameLength($fd, $offset, $ThisFileInfo, true); - if ($framebytelength > 0) { - $ThisFileInfo['mpeg']['audio']['framelength'] = $framebytelength; - if ($ThisFileInfo['mpeg']['audio']['layer'] == 'I') { - // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12 - $ThisFileInfo['audio']['bitrate'] = ((($framebytelength / 4) - intval($ThisFileInfo['mpeg']['audio']['padding'])) * $ThisFileInfo['mpeg']['audio']['sample_rate']) / 12; - } else { - // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144 - $ThisFileInfo['audio']['bitrate'] = (($framebytelength - intval($ThisFileInfo['mpeg']['audio']['padding'])) * $ThisFileInfo['mpeg']['audio']['sample_rate']) / 144; - } - } else { - $ThisFileInfo['error'] .= "\n".'Error calculating frame length of free-format MP3 without Xing/LAME header'; - } - } - } - - if (($ThisFileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr') && isset($ThisFileInfo['mpeg']['audio']['VBR_frames']) && ($ThisFileInfo['mpeg']['audio']['VBR_frames'] > 1)) { - $ThisFileInfo['mpeg']['audio']['VBR_frames']--; // don't count the Xing / VBRI frame - if (($ThisFileInfo['mpeg']['audio']['version'] == '1') && ($ThisFileInfo['mpeg']['audio']['layer'] == 'I')) { - $ThisFileInfo['mpeg']['audio']['VBR_bitrate'] = ((($ThisFileInfo['mpeg']['audio']['VBR_bytes'] / $ThisFileInfo['mpeg']['audio']['VBR_frames']) * 8) * ($ThisFileInfo['audio']['sample_rate'] / 384)) / 1000; - } elseif ((($ThisFileInfo['mpeg']['audio']['version'] == '2') || ($ThisFileInfo['mpeg']['audio']['version'] == '2.5')) && ($ThisFileInfo['mpeg']['audio']['layer'] == 'III')) { - $ThisFileInfo['mpeg']['audio']['VBR_bitrate'] = ((($ThisFileInfo['mpeg']['audio']['VBR_bytes'] / $ThisFileInfo['mpeg']['audio']['VBR_frames']) * 8) * ($ThisFileInfo['audio']['sample_rate'] / 576)) / 1000; - } else { - $ThisFileInfo['mpeg']['audio']['VBR_bitrate'] = ((($ThisFileInfo['mpeg']['audio']['VBR_bytes'] / $ThisFileInfo['mpeg']['audio']['VBR_frames']) * 8) * ($ThisFileInfo['audio']['sample_rate'] / 1152)) / 1000; - } - if ($ThisFileInfo['mpeg']['audio']['VBR_bitrate'] > 0) { - $ThisFileInfo['audio']['bitrate'] = 1000 * $ThisFileInfo['mpeg']['audio']['VBR_bitrate']; - $ThisFileInfo['mpeg']['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['VBR_bitrate']; // to avoid confusion - } - } - - // End variable-bitrate headers - //////////////////////////////////////////////////////////////////////////////////// - - if ($recursivesearch) { - - if (!RecursiveFrameScanning($fd, $ThisFileInfo, $offset, $nextframetestoffset, $ScanAsCBR)) { - return false; - } - - } - - - //if (false) { - // // experimental side info parsing section - not returning anything useful yet - // - // $SideInfoBitstream = BigEndian2Bin($SideInfoData); - // $SideInfoOffset = 0; - // - // if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { - // if ($ThisFileInfo['mpeg']['audio']['channelmode'] == 'mono') { - // // MPEG-1 (mono) - // $ThisFileInfo['mpeg']['audio']['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 9); - // $SideInfoOffset += 9; - // $SideInfoOffset += 5; - // } else { - // // MPEG-1 (stereo, joint-stereo, dual-channel) - // $ThisFileInfo['mpeg']['audio']['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 9); - // $SideInfoOffset += 9; - // $SideInfoOffset += 3; - // } - // } else { // 2 or 2.5 - // if ($ThisFileInfo['mpeg']['audio']['channelmode'] == 'mono') { - // // MPEG-2, MPEG-2.5 (mono) - // $ThisFileInfo['mpeg']['audio']['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 8); - // $SideInfoOffset += 8; - // $SideInfoOffset += 1; - // } else { - // // MPEG-2, MPEG-2.5 (stereo, joint-stereo, dual-channel) - // $ThisFileInfo['mpeg']['audio']['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 8); - // $SideInfoOffset += 8; - // $SideInfoOffset += 2; - // } - // } - // - // if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { - // for ($channel = 0; $channel < $ThisFileInfo['audio']['channels']; $channel++) { - // for ($scfsi_band = 0; $scfsi_band < 4; $scfsi_band++) { - // $ThisFileInfo['mpeg']['audio']['scfsi'][$channel][$scfsi_band] = substr($SideInfoBitstream, $SideInfoOffset, 1); - // $SideInfoOffset += 2; - // } - // } - // } - // for ($granule = 0; $granule < (($ThisFileInfo['mpeg']['audio']['version'] == '1') ? 2 : 1); $granule++) { - // for ($channel = 0; $channel < $ThisFileInfo['audio']['channels']; $channel++) { - // $ThisFileInfo['mpeg']['audio']['part2_3_length'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 12); - // $SideInfoOffset += 12; - // $ThisFileInfo['mpeg']['audio']['big_values'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 9); - // $SideInfoOffset += 9; - // $ThisFileInfo['mpeg']['audio']['global_gain'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 8); - // $SideInfoOffset += 8; - // if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { - // $ThisFileInfo['mpeg']['audio']['scalefac_compress'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 4); - // $SideInfoOffset += 4; - // } else { - // $ThisFileInfo['mpeg']['audio']['scalefac_compress'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 9); - // $SideInfoOffset += 9; - // } - // $ThisFileInfo['mpeg']['audio']['window_switching_flag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); - // $SideInfoOffset += 1; - // - // if ($ThisFileInfo['mpeg']['audio']['window_switching_flag'][$granule][$channel] == '1') { - // - // $ThisFileInfo['mpeg']['audio']['block_type'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 2); - // $SideInfoOffset += 2; - // $ThisFileInfo['mpeg']['audio']['mixed_block_flag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); - // $SideInfoOffset += 1; - // - // for ($region = 0; $region < 2; $region++) { - // $ThisFileInfo['mpeg']['audio']['table_select'][$granule][$channel][$region] = substr($SideInfoBitstream, $SideInfoOffset, 5); - // $SideInfoOffset += 5; - // } - // $ThisFileInfo['mpeg']['audio']['table_select'][$granule][$channel][2] = 0; - // - // for ($window = 0; $window < 3; $window++) { - // $ThisFileInfo['mpeg']['audio']['subblock_gain'][$granule][$channel][$window] = substr($SideInfoBitstream, $SideInfoOffset, 3); - // $SideInfoOffset += 3; - // } - // - // } else { - // - // for ($region = 0; $region < 3; $region++) { - // $ThisFileInfo['mpeg']['audio']['table_select'][$granule][$channel][$region] = substr($SideInfoBitstream, $SideInfoOffset, 5); - // $SideInfoOffset += 5; - // } - // - // $ThisFileInfo['mpeg']['audio']['region0_count'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 4); - // $SideInfoOffset += 4; - // $ThisFileInfo['mpeg']['audio']['region1_count'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 3); - // $SideInfoOffset += 3; - // $ThisFileInfo['mpeg']['audio']['block_type'][$granule][$channel] = 0; - // } - // - // if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { - // $ThisFileInfo['mpeg']['audio']['preflag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); - // $SideInfoOffset += 1; - // } - // $ThisFileInfo['mpeg']['audio']['scalefac_scale'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); - // $SideInfoOffset += 1; - // $ThisFileInfo['mpeg']['audio']['count1table_select'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); - // $SideInfoOffset += 1; - // } - // } - //} - - return true; +function decodeMPEGaudioHeader($fd, $offset, &$ThisFileInfo, $recursivesearch = true, $ScanAsCBR = false, $FastMPEGheaderScan = false) +{ + static $MPEGaudioVersionLookup; + static $MPEGaudioLayerLookup; + static $MPEGaudioBitrateLookup; + static $MPEGaudioFrequencyLookup; + static $MPEGaudioChannelModeLookup; + static $MPEGaudioModeExtensionLookup; + static $MPEGaudioEmphasisLookup; + if (empty($MPEGaudioVersionLookup)) { + $MPEGaudioVersionLookup = MPEGaudioVersionArray(); + $MPEGaudioLayerLookup = MPEGaudioLayerArray(); + $MPEGaudioBitrateLookup = MPEGaudioBitrateArray(); + $MPEGaudioFrequencyLookup = MPEGaudioFrequencyArray(); + $MPEGaudioChannelModeLookup = MPEGaudioChannelModeArray(); + $MPEGaudioModeExtensionLookup = MPEGaudioModeExtensionArray(); + $MPEGaudioEmphasisLookup = MPEGaudioEmphasisArray(); + } + + if ($offset >= $ThisFileInfo['avdataend']) { + $ThisFileInfo['error'] .= "\n".'end of file encounter looking for MPEG synch'; + + return false; + } + fseek($fd, $offset, SEEK_SET); + $headerstring = fread($fd, 1441); // worse-case max length = 32kHz @ 320kbps layer 3 = 1441 bytes/frame + + // MP3 audio frame structure: + // $aa $aa $aa $aa [$bb $bb] $cc... + // where $aa..$aa is the four-byte mpeg-audio header (below) + // $bb $bb is the optional 2-byte CRC + // and $cc... is the audio data + + $head4 = substr($headerstring, 0, 4); + + static $MPEGaudioHeaderDecodeCache = []; + if (isset($MPEGaudioHeaderDecodeCache[$head4])) { + $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4]; + } else { + $MPEGheaderRawArray = MPEGaudioHeaderDecode($head4); + $MPEGaudioHeaderDecodeCache[$head4] = $MPEGheaderRawArray; + } + + static $MPEGaudioHeaderValidCache = []; + + // Not in cache + if (! isset($MPEGaudioHeaderValidCache[$head4])) { + $MPEGaudioHeaderValidCache[$head4] = MPEGaudioHeaderValid($MPEGheaderRawArray); + } + + if ($MPEGaudioHeaderValidCache[$head4]) { + $ThisFileInfo['mpeg']['audio']['raw'] = $MPEGheaderRawArray; + } else { + $ThisFileInfo['error'] .= "\n".'Invalid MPEG audio header at offset '.$offset; + + return false; + } + + if (! $FastMPEGheaderScan) { + $ThisFileInfo['mpeg']['audio']['version'] = $MPEGaudioVersionLookup[$ThisFileInfo['mpeg']['audio']['raw']['version']]; + $ThisFileInfo['mpeg']['audio']['layer'] = $MPEGaudioLayerLookup[$ThisFileInfo['mpeg']['audio']['raw']['layer']]; + + $ThisFileInfo['mpeg']['audio']['channelmode'] = $MPEGaudioChannelModeLookup[$ThisFileInfo['mpeg']['audio']['raw']['channelmode']]; + $ThisFileInfo['mpeg']['audio']['channels'] = (($ThisFileInfo['mpeg']['audio']['channelmode'] == 'mono') ? 1 : 2); + $ThisFileInfo['mpeg']['audio']['sample_rate'] = $MPEGaudioFrequencyLookup[$ThisFileInfo['mpeg']['audio']['version']][$ThisFileInfo['mpeg']['audio']['raw']['sample_rate']]; + $ThisFileInfo['mpeg']['audio']['protection'] = ! $ThisFileInfo['mpeg']['audio']['raw']['protection']; + $ThisFileInfo['mpeg']['audio']['private'] = (bool) $ThisFileInfo['mpeg']['audio']['raw']['private']; + $ThisFileInfo['mpeg']['audio']['modeextension'] = $MPEGaudioModeExtensionLookup[$ThisFileInfo['mpeg']['audio']['layer']][$ThisFileInfo['mpeg']['audio']['raw']['modeextension']]; + $ThisFileInfo['mpeg']['audio']['copyright'] = (bool) $ThisFileInfo['mpeg']['audio']['raw']['copyright']; + $ThisFileInfo['mpeg']['audio']['original'] = (bool) $ThisFileInfo['mpeg']['audio']['raw']['original']; + $ThisFileInfo['mpeg']['audio']['emphasis'] = $MPEGaudioEmphasisLookup[$ThisFileInfo['mpeg']['audio']['raw']['emphasis']]; + + $ThisFileInfo['audio']['channels'] = $ThisFileInfo['mpeg']['audio']['channels']; + $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate']; + + if ($ThisFileInfo['mpeg']['audio']['protection']) { + $ThisFileInfo['mpeg']['audio']['crc'] = BigEndian2Int(substr($headerstring, 4, 2)); + } + } + + if ($ThisFileInfo['mpeg']['audio']['raw']['bitrate'] == 15) { + // http://www.hydrogenaudio.org/?act=ST&f=16&t=9682&st=0 + $ThisFileInfo['warning'] .= "\n".'Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1'; + $ThisFileInfo['mpeg']['audio']['raw']['bitrate'] = 0; + } + $ThisFileInfo['mpeg']['audio']['padding'] = (bool) $ThisFileInfo['mpeg']['audio']['raw']['padding']; + $ThisFileInfo['mpeg']['audio']['bitrate'] = $MPEGaudioBitrateLookup[$ThisFileInfo['mpeg']['audio']['version']][$ThisFileInfo['mpeg']['audio']['layer']][$ThisFileInfo['mpeg']['audio']['raw']['bitrate']]; + + if (($ThisFileInfo['mpeg']['audio']['bitrate'] == 'free') && ($offset == $ThisFileInfo['avdataoffset'])) { + // only skip multiple frame check if free-format bitstream found at beginning of file + // otherwise is quite possibly simply corrupted data + $recursivesearch = false; + } + + // For Layer II there are some combinations of bitrate and mode which are not allowed. + if (! $FastMPEGheaderScan && ($ThisFileInfo['mpeg']['audio']['layer'] == 'II')) { + $ThisFileInfo['audio']['dataformat'] = 'mp2'; + switch ($ThisFileInfo['mpeg']['audio']['channelmode']) { + + case 'mono': + if (($ThisFileInfo['mpeg']['audio']['bitrate'] == 'free') || ($ThisFileInfo['mpeg']['audio']['bitrate'] <= 192)) { + // these are ok + } else { + $ThisFileInfo['error'] .= "\n".$ThisFileInfo['mpeg']['audio']['bitrate'].'kbps not allowed in Layer II, '.$ThisFileInfo['mpeg']['audio']['channelmode'].'.'; + + return false; + } + break; + + case 'stereo': + case 'joint stereo': + case 'dual channel': + if (($ThisFileInfo['mpeg']['audio']['bitrate'] == 'free') || ($ThisFileInfo['mpeg']['audio']['bitrate'] == 64) || ($ThisFileInfo['mpeg']['audio']['bitrate'] >= 96)) { + // these are ok + } else { + $ThisFileInfo['error'] .= "\n".$ThisFileInfo['mpeg']['audio']['bitrate'].'kbps not allowed in Layer II, '.$ThisFileInfo['mpeg']['audio']['channelmode'].'.'; + + return false; + } + break; + + } + } + + if ($ThisFileInfo['audio']['sample_rate'] > 0) { + $ThisFileInfo['mpeg']['audio']['framelength'] = MPEGaudioFrameLength($ThisFileInfo['mpeg']['audio']['bitrate'], $ThisFileInfo['mpeg']['audio']['version'], $ThisFileInfo['mpeg']['audio']['layer'], (int) $ThisFileInfo['mpeg']['audio']['padding'], $ThisFileInfo['audio']['sample_rate']); + } + + if ($ThisFileInfo['mpeg']['audio']['bitrate'] != 'free') { + $ThisFileInfo['audio']['bitrate'] = 1000 * $ThisFileInfo['mpeg']['audio']['bitrate']; + + if (isset($ThisFileInfo['mpeg']['audio']['framelength'])) { + $nextframetestoffset = $offset + $ThisFileInfo['mpeg']['audio']['framelength']; + } else { + $ThisFileInfo['error'] .= "\n".'Frame at offset('.$offset.') is has an invalid frame length.'; + + return false; + } + } + + $ExpectedNumberOfAudioBytes = 0; + + //////////////////////////////////////////////////////////////////////////////////// + // Variable-bitrate headers + + if (substr($headerstring, 4 + 32, 4) == 'VBRI') { + // Fraunhofer VBR header is hardcoded 'VBRI' at offset 0x24 (36) + // specs taken from http://minnie.tuhs.org/pipermail/mp3encoder/2001-January/001800.html + + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'vbr'; + $ThisFileInfo['mpeg']['audio']['VBR_method'] = 'Fraunhofer'; + $ThisFileInfo['audio']['codec'] = 'Fraunhofer'; + + $SideInfoData = substr($headerstring, 4 + 2, 32); + + $FraunhoferVBROffset = 36; + + $ThisFileInfo['mpeg']['audio']['VBR_encoder_version'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 4, 2)); + $ThisFileInfo['mpeg']['audio']['VBR_encoder_delay'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 6, 2)); + $ThisFileInfo['mpeg']['audio']['VBR_quality'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 8, 2)); + $ThisFileInfo['mpeg']['audio']['VBR_bytes'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 10, 4)); + $ThisFileInfo['mpeg']['audio']['VBR_frames'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 14, 4)); + $ThisFileInfo['mpeg']['audio']['VBR_seek_offsets'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 18, 2)); + //$ThisFileInfo['mpeg']['audio']['reserved'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 20, 4)); // hardcoded $00 $01 $00 $02 - purpose unknown + $ThisFileInfo['mpeg']['audio']['VBR_seek_offsets_stride'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 24, 2)); + + $ExpectedNumberOfAudioBytes = $ThisFileInfo['mpeg']['audio']['VBR_bytes']; + + $previousbyteoffset = $offset; + for ($i = 0; $i < $ThisFileInfo['mpeg']['audio']['VBR_seek_offsets']; $i++) { + $Fraunhofer_OffsetN = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset, 2)); + $FraunhoferVBROffset += 2; + $ThisFileInfo['mpeg']['audio']['VBR_offsets_relative'][$i] = $Fraunhofer_OffsetN; + $ThisFileInfo['mpeg']['audio']['VBR_offsets_absolute'][$i] = $Fraunhofer_OffsetN + $previousbyteoffset; + $previousbyteoffset += $Fraunhofer_OffsetN; + } + } else { + + // Xing VBR header is hardcoded 'Xing' at a offset 0x0D (13), 0x15 (21) or 0x24 (36) + // depending on MPEG layer and number of channels + + if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { + if ($ThisFileInfo['mpeg']['audio']['channelmode'] == 'mono') { + // MPEG-1 (mono) + $VBRidOffset = 4 + 17; // 0x15 + $SideInfoData = substr($headerstring, 4 + 2, 17); + } else { + // MPEG-1 (stereo, joint-stereo, dual-channel) + $VBRidOffset = 4 + 32; // 0x24 + $SideInfoData = substr($headerstring, 4 + 2, 32); + } + } else { // 2 or 2.5 + if ($ThisFileInfo['mpeg']['audio']['channelmode'] == 'mono') { + // MPEG-2, MPEG-2.5 (mono) + $VBRidOffset = 4 + 9; // 0x0D + $SideInfoData = substr($headerstring, 4 + 2, 9); + } else { + // MPEG-2, MPEG-2.5 (stereo, joint-stereo, dual-channel) + $VBRidOffset = 4 + 17; // 0x15 + $SideInfoData = substr($headerstring, 4 + 2, 17); + } + } + + if ((substr($headerstring, $VBRidOffset, strlen('Xing')) == 'Xing') || (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Info')) { + // 'Xing' is traditional Xing VBR frame + // 'Info' is LAME-encoded CBR (This was done to avoid CBR files to be recognized as traditional Xing VBR files by some decoders.) + + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'vbr'; + $ThisFileInfo['mpeg']['audio']['VBR_method'] = 'Xing'; + + $ThisFileInfo['mpeg']['audio']['xing_flags_raw'] = BigEndian2Int(substr($headerstring, $VBRidOffset + 4, 4)); + + $ThisFileInfo['mpeg']['audio']['xing_flags']['frames'] = (bool) ($ThisFileInfo['mpeg']['audio']['xing_flags_raw'] & 0x00000001); + $ThisFileInfo['mpeg']['audio']['xing_flags']['bytes'] = (bool) ($ThisFileInfo['mpeg']['audio']['xing_flags_raw'] & 0x00000002); + $ThisFileInfo['mpeg']['audio']['xing_flags']['toc'] = (bool) ($ThisFileInfo['mpeg']['audio']['xing_flags_raw'] & 0x00000004); + $ThisFileInfo['mpeg']['audio']['xing_flags']['vbr_scale'] = (bool) ($ThisFileInfo['mpeg']['audio']['xing_flags_raw'] & 0x00000008); + + if ($ThisFileInfo['mpeg']['audio']['xing_flags']['frames']) { + $ThisFileInfo['mpeg']['audio']['VBR_frames'] = BigEndian2Int(substr($headerstring, $VBRidOffset + 8, 4)); + } + if ($ThisFileInfo['mpeg']['audio']['xing_flags']['bytes']) { + $ThisFileInfo['mpeg']['audio']['VBR_bytes'] = BigEndian2Int(substr($headerstring, $VBRidOffset + 12, 4)); + } + + if (($ThisFileInfo['mpeg']['audio']['bitrate'] == 'free') && ! empty($ThisFileInfo['mpeg']['audio']['VBR_frames']) && ! empty($ThisFileInfo['mpeg']['audio']['VBR_bytes'])) { + $framelengthfloat = $ThisFileInfo['mpeg']['audio']['VBR_bytes'] / $ThisFileInfo['mpeg']['audio']['VBR_frames']; + if ($ThisFileInfo['mpeg']['audio']['layer'] == 'I') { + // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12 + $ThisFileInfo['audio']['bitrate'] = ((($framelengthfloat / 4) - intval($ThisFileInfo['mpeg']['audio']['padding'])) * $ThisFileInfo['mpeg']['audio']['sample_rate']) / 12; + } else { + // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144 + $ThisFileInfo['audio']['bitrate'] = (($framelengthfloat - intval($ThisFileInfo['mpeg']['audio']['padding'])) * $ThisFileInfo['mpeg']['audio']['sample_rate']) / 144; + } + $ThisFileInfo['mpeg']['audio']['framelength'] = floor($framelengthfloat); + } + + if ($ThisFileInfo['mpeg']['audio']['xing_flags']['toc']) { + $LAMEtocData = substr($headerstring, $VBRidOffset + 16, 100); + for ($i = 0; $i < 100; $i++) { + $ThisFileInfo['mpeg']['audio']['toc'][$i] = ord($LAMEtocData[$i]); + } + } + if ($ThisFileInfo['mpeg']['audio']['xing_flags']['vbr_scale']) { + $ThisFileInfo['mpeg']['audio']['VBR_scale'] = BigEndian2Int(substr($headerstring, $VBRidOffset + 116, 4)); + } + + // http://gabriel.mp3-tech.org/mp3infotag.html + if (substr($headerstring, $VBRidOffset + 120, 4) == 'LAME') { + $ThisFileInfo['mpeg']['audio']['LAME']['long_version'] = substr($headerstring, $VBRidOffset + 120, 20); + $ThisFileInfo['mpeg']['audio']['LAME']['short_version'] = substr($ThisFileInfo['mpeg']['audio']['LAME']['long_version'], 0, 9); + $ThisFileInfo['mpeg']['audio']['LAME']['long_version'] = rtrim($ThisFileInfo['mpeg']['audio']['LAME']['long_version'], "\x55\xAA"); + + if ($ThisFileInfo['mpeg']['audio']['LAME']['short_version'] >= 'LAME3.90.') { + + // It the LAME tag was only introduced in LAME v3.90 + // http://www.hydrogenaudio.org/?act=ST&f=15&t=9933 + + // Offsets of various bytes in http://gabriel.mp3-tech.org/mp3infotag.html + // are assuming a 'Xing' identifier offset of 0x24, which is the case for + // MPEG-1 non-mono, but not for other combinations + $LAMEtagOffsetContant = $VBRidOffset - 0x24; + + // byte $9B VBR Quality + // This field is there to indicate a quality level, although the scale was not precised in the original Xing specifications. + // Actually overwrites original Xing bytes + unset($ThisFileInfo['mpeg']['audio']['VBR_scale']); + $ThisFileInfo['mpeg']['audio']['LAME']['vbr_quality'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0x9B, 1)); + + // bytes $9C-$A4 Encoder short VersionString + $ThisFileInfo['mpeg']['audio']['LAME']['short_version'] = substr($headerstring, $LAMEtagOffsetContant + 0x9C, 9); + $ThisFileInfo['mpeg']['audio']['LAME']['long_version'] = $ThisFileInfo['mpeg']['audio']['LAME']['short_version']; + + // byte $A5 Info Tag revision + VBR method + $LAMEtagRevisionVBRmethod = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA5, 1)); + + $ThisFileInfo['mpeg']['audio']['LAME']['tag_revision'] = ($LAMEtagRevisionVBRmethod & 0xF0) >> 4; + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['vbr_method'] = $LAMEtagRevisionVBRmethod & 0x0F; + $ThisFileInfo['mpeg']['audio']['LAME']['vbr_method'] = LAMEvbrMethodLookup($ThisFileInfo['mpeg']['audio']['LAME']['raw']['vbr_method']); + + // byte $A6 Lowpass filter value + $ThisFileInfo['mpeg']['audio']['LAME']['lowpass_frequency'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100; + + // bytes $A7-$AE Replay Gain + // http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html + // bytes $A7-$AA : 32 bit floating point "Peak signal amplitude" + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude'] = BigEndian2Float(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4)); + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAB, 2)); + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAD, 2)); + + if ($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude'] == 0) { + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude'] = false; + } + + if ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] != 0) { + require_once GETID3_INCLUDEPATH.'getid3.rgad.php'; + + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['name'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] & 0xE000) >> 13; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['originator'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] & 0x1C00) >> 10; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['sign_bit'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] & 0x0200) >> 9; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['gain_adjust'] = $ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] & 0x01FF; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['name'] = RGADnameLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['name']); + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['originator'] = RGADoriginatorLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['originator']); + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['gain_db'] = RGADadjustmentLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['gain_adjust'], $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['sign_bit']); + + if ($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude'] !== false) { + $ThisFileInfo['replay_gain']['radio']['peak'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude']; + } + $ThisFileInfo['replay_gain']['radio']['originator'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['originator']; + $ThisFileInfo['replay_gain']['radio']['adjustment'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['gain_db']; + } + if ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] != 0) { + require_once GETID3_INCLUDEPATH.'getid3.rgad.php'; + + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['name'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] & 0xE000) >> 13; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['originator'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] & 0x1C00) >> 10; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['sign_bit'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] & 0x0200) >> 9; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['gain_adjust'] = $ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] & 0x01FF; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['name'] = RGADnameLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['name']); + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['originator'] = RGADoriginatorLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['originator']); + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['gain_db'] = RGADadjustmentLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['gain_adjust'], $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['sign_bit']); + + if ($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude'] !== false) { + $ThisFileInfo['replay_gain']['audiophile']['peak'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude']; + } + $ThisFileInfo['replay_gain']['audiophile']['originator'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['originator']; + $ThisFileInfo['replay_gain']['audiophile']['adjustment'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['gain_db']; + } + + // byte $AF Encoding flags + ATH Type + $EncodingFlagsATHtype = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAF, 1)); + $ThisFileInfo['mpeg']['audio']['LAME']['encoding_flags']['nspsytune'] = (bool) ($EncodingFlagsATHtype & 0x10); + $ThisFileInfo['mpeg']['audio']['LAME']['encoding_flags']['nssafejoint'] = (bool) ($EncodingFlagsATHtype & 0x20); + $ThisFileInfo['mpeg']['audio']['LAME']['encoding_flags']['nogap_next'] = (bool) ($EncodingFlagsATHtype & 0x40); + $ThisFileInfo['mpeg']['audio']['LAME']['encoding_flags']['nogap_prev'] = (bool) ($EncodingFlagsATHtype & 0x80); + $ThisFileInfo['mpeg']['audio']['LAME']['ath_type'] = $EncodingFlagsATHtype & 0x0F; + + // byte $B0 if ABR {specified bitrate} else {minimal bitrate} + $ABRbitrateMinBitrate = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB0, 1)); + if ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['vbr_method'] == 2) { // Average BitRate (ABR) + $ThisFileInfo['mpeg']['audio']['LAME']['bitrate_abr'] = $ABRbitrateMinBitrate; + } elseif ($ABRbitrateMinBitrate > 0) { // Variable BitRate (VBR) - minimum bitrate + $ThisFileInfo['mpeg']['audio']['LAME']['bitrate_min'] = $ABRbitrateMinBitrate; + } + + // bytes $B1-$B3 Encoder delays + $EncoderDelays = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB1, 3)); + $ThisFileInfo['mpeg']['audio']['LAME']['encoder_delay'] = ($EncoderDelays & 0xFFF000) >> 12; + $ThisFileInfo['mpeg']['audio']['LAME']['end_padding'] = $EncoderDelays & 0x000FFF; + + // byte $B4 Misc + $MiscByte = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB4, 1)); + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['noise_shaping'] = ($MiscByte & 0x03); + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['stereo_mode'] = ($MiscByte & 0x1C) >> 2; + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['not_optimal_quality'] = ($MiscByte & 0x20) >> 5; + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['source_sample_freq'] = ($MiscByte & 0xC0) >> 6; + $ThisFileInfo['mpeg']['audio']['LAME']['noise_shaping'] = $ThisFileInfo['mpeg']['audio']['LAME']['raw']['noise_shaping']; + $ThisFileInfo['mpeg']['audio']['LAME']['stereo_mode'] = LAMEmiscStereoModeLookup($ThisFileInfo['mpeg']['audio']['LAME']['raw']['stereo_mode']); + $ThisFileInfo['mpeg']['audio']['LAME']['not_optimal_quality'] = (bool) $ThisFileInfo['mpeg']['audio']['LAME']['raw']['not_optimal_quality']; + $ThisFileInfo['mpeg']['audio']['LAME']['source_sample_freq'] = LAMEmiscSourceSampleFrequencyLookup($ThisFileInfo['mpeg']['audio']['LAME']['raw']['source_sample_freq']); + + // byte $B5 MP3 Gain + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['mp3_gain'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB5, 1), false, true); + $ThisFileInfo['mpeg']['audio']['LAME']['mp3_gain_db'] = 1.5 * $ThisFileInfo['mpeg']['audio']['LAME']['raw']['mp3_gain']; + $ThisFileInfo['mpeg']['audio']['LAME']['mp3_gain_factor'] = pow(2, ($ThisFileInfo['mpeg']['audio']['LAME']['mp3_gain_db'] / 6)); + + // bytes $B6-$B7 Preset and surround info + $PresetSurroundBytes = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB6, 2)); + // Reserved = ($PresetSurroundBytes & 0xC000); + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['surround_info'] = ($PresetSurroundBytes & 0x3800); + $ThisFileInfo['mpeg']['audio']['LAME']['surround_info'] = LAMEsurroundInfoLookup($ThisFileInfo['mpeg']['audio']['LAME']['raw']['surround_info']); + $ThisFileInfo['mpeg']['audio']['LAME']['preset_used_id'] = ($PresetSurroundBytes & 0x07FF); + + // bytes $B8-$BB MusicLength + $ThisFileInfo['mpeg']['audio']['LAME']['audio_bytes'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB8, 4)); + $ExpectedNumberOfAudioBytes = (($ThisFileInfo['mpeg']['audio']['LAME']['audio_bytes'] > 0) ? $ThisFileInfo['mpeg']['audio']['LAME']['audio_bytes'] : $ThisFileInfo['mpeg']['audio']['VBR_bytes']); + + // bytes $BC-$BD MusicCRC + $ThisFileInfo['mpeg']['audio']['LAME']['music_crc'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBC, 2)); + + // bytes $BE-$BF CRC-16 of Info Tag + $ThisFileInfo['mpeg']['audio']['LAME']['lame_tag_crc'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBE, 2)); + + // LAME CBR + if ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['vbr_method'] == 1) { + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'cbr'; + if (empty($ThisFileInfo['mpeg']['audio']['bitrate']) || ($ThisFileInfo['mpeg']['audio']['LAME']['bitrate_min'] != 255)) { + $ThisFileInfo['mpeg']['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['LAME']['bitrate_min']; + } + } + } + } + } else { + + // not Fraunhofer or Xing VBR methods, most likely CBR (but could be VBR with no header) + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'cbr'; + if ($recursivesearch) { + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'vbr'; + if (RecursiveFrameScanning($fd, $ThisFileInfo, $offset, $nextframetestoffset, true)) { + $recursivesearch = false; + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'cbr'; + } + if ($ThisFileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr') { + $ThisFileInfo['warning'] .= "\n".'VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.'; + } + } + } + } + + if (($ExpectedNumberOfAudioBytes > 0) && ($ExpectedNumberOfAudioBytes != ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']))) { + if (($ExpectedNumberOfAudioBytes - ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'])) == 1) { + $ThisFileInfo['warning'] .= "\n".'Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)'; + } elseif ($ExpectedNumberOfAudioBytes > ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'])) { + $ThisFileInfo['warning'] .= "\n".'Probable truncated file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, only found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']).' (short by '.($ExpectedNumberOfAudioBytes - ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'])).' bytes)'; + } else { + $ThisFileInfo['warning'] .= "\n".'Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']).' ('.(($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)'; + } + } + + if (($ThisFileInfo['mpeg']['audio']['bitrate'] == 'free') && empty($ThisFileInfo['audio']['bitrate'])) { + if (($offset == $ThisFileInfo['avdataoffset']) && empty($ThisFileInfo['mpeg']['audio']['VBR_frames'])) { + $framebytelength = FreeFormatFrameLength($fd, $offset, $ThisFileInfo, true); + if ($framebytelength > 0) { + $ThisFileInfo['mpeg']['audio']['framelength'] = $framebytelength; + if ($ThisFileInfo['mpeg']['audio']['layer'] == 'I') { + // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12 + $ThisFileInfo['audio']['bitrate'] = ((($framebytelength / 4) - intval($ThisFileInfo['mpeg']['audio']['padding'])) * $ThisFileInfo['mpeg']['audio']['sample_rate']) / 12; + } else { + // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144 + $ThisFileInfo['audio']['bitrate'] = (($framebytelength - intval($ThisFileInfo['mpeg']['audio']['padding'])) * $ThisFileInfo['mpeg']['audio']['sample_rate']) / 144; + } + } else { + $ThisFileInfo['error'] .= "\n".'Error calculating frame length of free-format MP3 without Xing/LAME header'; + } + } + } + + if (($ThisFileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr') && isset($ThisFileInfo['mpeg']['audio']['VBR_frames']) && ($ThisFileInfo['mpeg']['audio']['VBR_frames'] > 1)) { + $ThisFileInfo['mpeg']['audio']['VBR_frames']--; // don't count the Xing / VBRI frame + if (($ThisFileInfo['mpeg']['audio']['version'] == '1') && ($ThisFileInfo['mpeg']['audio']['layer'] == 'I')) { + $ThisFileInfo['mpeg']['audio']['VBR_bitrate'] = ((($ThisFileInfo['mpeg']['audio']['VBR_bytes'] / $ThisFileInfo['mpeg']['audio']['VBR_frames']) * 8) * ($ThisFileInfo['audio']['sample_rate'] / 384)) / 1000; + } elseif ((($ThisFileInfo['mpeg']['audio']['version'] == '2') || ($ThisFileInfo['mpeg']['audio']['version'] == '2.5')) && ($ThisFileInfo['mpeg']['audio']['layer'] == 'III')) { + $ThisFileInfo['mpeg']['audio']['VBR_bitrate'] = ((($ThisFileInfo['mpeg']['audio']['VBR_bytes'] / $ThisFileInfo['mpeg']['audio']['VBR_frames']) * 8) * ($ThisFileInfo['audio']['sample_rate'] / 576)) / 1000; + } else { + $ThisFileInfo['mpeg']['audio']['VBR_bitrate'] = ((($ThisFileInfo['mpeg']['audio']['VBR_bytes'] / $ThisFileInfo['mpeg']['audio']['VBR_frames']) * 8) * ($ThisFileInfo['audio']['sample_rate'] / 1152)) / 1000; + } + if ($ThisFileInfo['mpeg']['audio']['VBR_bitrate'] > 0) { + $ThisFileInfo['audio']['bitrate'] = 1000 * $ThisFileInfo['mpeg']['audio']['VBR_bitrate']; + $ThisFileInfo['mpeg']['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['VBR_bitrate']; // to avoid confusion + } + } + + // End variable-bitrate headers + //////////////////////////////////////////////////////////////////////////////////// + + if ($recursivesearch) { + if (! RecursiveFrameScanning($fd, $ThisFileInfo, $offset, $nextframetestoffset, $ScanAsCBR)) { + return false; + } + } + + //if (false) { + // // experimental side info parsing section - not returning anything useful yet + // + // $SideInfoBitstream = BigEndian2Bin($SideInfoData); + // $SideInfoOffset = 0; + // + // if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { + // if ($ThisFileInfo['mpeg']['audio']['channelmode'] == 'mono') { + // // MPEG-1 (mono) + // $ThisFileInfo['mpeg']['audio']['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 9); + // $SideInfoOffset += 9; + // $SideInfoOffset += 5; + // } else { + // // MPEG-1 (stereo, joint-stereo, dual-channel) + // $ThisFileInfo['mpeg']['audio']['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 9); + // $SideInfoOffset += 9; + // $SideInfoOffset += 3; + // } + // } else { // 2 or 2.5 + // if ($ThisFileInfo['mpeg']['audio']['channelmode'] == 'mono') { + // // MPEG-2, MPEG-2.5 (mono) + // $ThisFileInfo['mpeg']['audio']['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 8); + // $SideInfoOffset += 8; + // $SideInfoOffset += 1; + // } else { + // // MPEG-2, MPEG-2.5 (stereo, joint-stereo, dual-channel) + // $ThisFileInfo['mpeg']['audio']['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 8); + // $SideInfoOffset += 8; + // $SideInfoOffset += 2; + // } + // } + // + // if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { + // for ($channel = 0; $channel < $ThisFileInfo['audio']['channels']; $channel++) { + // for ($scfsi_band = 0; $scfsi_band < 4; $scfsi_band++) { + // $ThisFileInfo['mpeg']['audio']['scfsi'][$channel][$scfsi_band] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 2; + // } + // } + // } + // for ($granule = 0; $granule < (($ThisFileInfo['mpeg']['audio']['version'] == '1') ? 2 : 1); $granule++) { + // for ($channel = 0; $channel < $ThisFileInfo['audio']['channels']; $channel++) { + // $ThisFileInfo['mpeg']['audio']['part2_3_length'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 12); + // $SideInfoOffset += 12; + // $ThisFileInfo['mpeg']['audio']['big_values'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 9); + // $SideInfoOffset += 9; + // $ThisFileInfo['mpeg']['audio']['global_gain'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 8); + // $SideInfoOffset += 8; + // if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { + // $ThisFileInfo['mpeg']['audio']['scalefac_compress'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 4); + // $SideInfoOffset += 4; + // } else { + // $ThisFileInfo['mpeg']['audio']['scalefac_compress'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 9); + // $SideInfoOffset += 9; + // } + // $ThisFileInfo['mpeg']['audio']['window_switching_flag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 1; + // + // if ($ThisFileInfo['mpeg']['audio']['window_switching_flag'][$granule][$channel] == '1') { + // + // $ThisFileInfo['mpeg']['audio']['block_type'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 2); + // $SideInfoOffset += 2; + // $ThisFileInfo['mpeg']['audio']['mixed_block_flag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 1; + // + // for ($region = 0; $region < 2; $region++) { + // $ThisFileInfo['mpeg']['audio']['table_select'][$granule][$channel][$region] = substr($SideInfoBitstream, $SideInfoOffset, 5); + // $SideInfoOffset += 5; + // } + // $ThisFileInfo['mpeg']['audio']['table_select'][$granule][$channel][2] = 0; + // + // for ($window = 0; $window < 3; $window++) { + // $ThisFileInfo['mpeg']['audio']['subblock_gain'][$granule][$channel][$window] = substr($SideInfoBitstream, $SideInfoOffset, 3); + // $SideInfoOffset += 3; + // } + // + // } else { + // + // for ($region = 0; $region < 3; $region++) { + // $ThisFileInfo['mpeg']['audio']['table_select'][$granule][$channel][$region] = substr($SideInfoBitstream, $SideInfoOffset, 5); + // $SideInfoOffset += 5; + // } + // + // $ThisFileInfo['mpeg']['audio']['region0_count'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 4); + // $SideInfoOffset += 4; + // $ThisFileInfo['mpeg']['audio']['region1_count'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 3); + // $SideInfoOffset += 3; + // $ThisFileInfo['mpeg']['audio']['block_type'][$granule][$channel] = 0; + // } + // + // if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { + // $ThisFileInfo['mpeg']['audio']['preflag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 1; + // } + // $ThisFileInfo['mpeg']['audio']['scalefac_scale'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 1; + // $ThisFileInfo['mpeg']['audio']['count1table_select'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 1; + // } + // } + //} + + return true; } -function RecursiveFrameScanning(&$fd, &$ThisFileInfo, &$offset, &$nextframetestoffset, $ScanAsCBR) { - for ($i = 0; $i < MPEG_VALID_CHECK_FRAMES; $i++) { - // check next MPEG_VALID_CHECK_FRAMES frames for validity, to make sure we haven't run across a false synch - if (($nextframetestoffset + 4) >= $ThisFileInfo['avdataend']) { - // end of file - return true; - } +function RecursiveFrameScanning(&$fd, &$ThisFileInfo, &$offset, &$nextframetestoffset, $ScanAsCBR) +{ + for ($i = 0; $i < MPEG_VALID_CHECK_FRAMES; $i++) { + // check next MPEG_VALID_CHECK_FRAMES frames for validity, to make sure we haven't run across a false synch + if (($nextframetestoffset + 4) >= $ThisFileInfo['avdataend']) { + // end of file + return true; + } - $nextframetestarray = array('error'=>'', 'warning'=>'', 'avdataend'=>$ThisFileInfo['avdataend'], 'avdataoffset'=>$ThisFileInfo['avdataoffset']); - if (decodeMPEGaudioHeader($fd, $nextframetestoffset, $nextframetestarray, false)) { - if ($ScanAsCBR) { - // force CBR mode, used for trying to pick out invalid audio streams with - // valid(?) VBR headers, or VBR streams with no VBR header - if (!isset($nextframetestarray['mpeg']['audio']['bitrate']) || !isset($ThisFileInfo['mpeg']['audio']['bitrate']) || ($nextframetestarray['mpeg']['audio']['bitrate'] != $ThisFileInfo['mpeg']['audio']['bitrate'])) { - return false; - } - } + $nextframetestarray = ['error'=>'', 'warning'=>'', 'avdataend'=>$ThisFileInfo['avdataend'], 'avdataoffset'=>$ThisFileInfo['avdataoffset']]; + if (decodeMPEGaudioHeader($fd, $nextframetestoffset, $nextframetestarray, false)) { + if ($ScanAsCBR) { + // force CBR mode, used for trying to pick out invalid audio streams with + // valid(?) VBR headers, or VBR streams with no VBR header + if (! isset($nextframetestarray['mpeg']['audio']['bitrate']) || ! isset($ThisFileInfo['mpeg']['audio']['bitrate']) || ($nextframetestarray['mpeg']['audio']['bitrate'] != $ThisFileInfo['mpeg']['audio']['bitrate'])) { + return false; + } + } + // next frame is OK, get ready to check the one after that + if (isset($nextframetestarray['mpeg']['audio']['framelength']) && ($nextframetestarray['mpeg']['audio']['framelength'] > 0)) { + $nextframetestoffset += $nextframetestarray['mpeg']['audio']['framelength']; + } else { + $ThisFileInfo['error'] .= "\n".'Frame at offset ('.$offset.') is has an invalid frame length.'; - // next frame is OK, get ready to check the one after that - if (isset($nextframetestarray['mpeg']['audio']['framelength']) && ($nextframetestarray['mpeg']['audio']['framelength'] > 0)) { - $nextframetestoffset += $nextframetestarray['mpeg']['audio']['framelength']; - } else { - $ThisFileInfo['error'] .= "\n".'Frame at offset ('.$offset.') is has an invalid frame length.'; - return false; - } + return false; + } + } else { - } else { + // next frame is not valid, note the error and fail, so scanning can contiue for a valid frame sequence + $ThisFileInfo['error'] .= "\n".'Frame at offset ('.$offset.') is valid, but the next one at ('.$nextframetestoffset.') is not.'; - // next frame is not valid, note the error and fail, so scanning can contiue for a valid frame sequence - $ThisFileInfo['error'] .= "\n".'Frame at offset ('.$offset.') is valid, but the next one at ('.$nextframetestoffset.') is not.'; + return false; + } + } - return false; - } - } - return true; + return true; } -function FreeFormatFrameLength($fd, $offset, &$ThisFileInfo, $deepscan=false) { - fseek($fd, $offset, SEEK_SET); - $MPEGaudioData = fread($fd, 32768); +function FreeFormatFrameLength($fd, $offset, &$ThisFileInfo, $deepscan = false) +{ + fseek($fd, $offset, SEEK_SET); + $MPEGaudioData = fread($fd, 32768); - $SyncPattern1 = substr($MPEGaudioData, 0, 4); - // may be different pattern due to padding - $SyncPattern2 = $SyncPattern1{0}.$SyncPattern1{1}.chr(ord($SyncPattern1{2}) | 0x02).$SyncPattern1{3}; - if ($SyncPattern2 === $SyncPattern1) { - $SyncPattern2 = $SyncPattern1{0}.$SyncPattern1{1}.chr(ord($SyncPattern1{2}) & 0xFD).$SyncPattern1{3}; - } + $SyncPattern1 = substr($MPEGaudioData, 0, 4); + // may be different pattern due to padding + $SyncPattern2 = $SyncPattern1[0].$SyncPattern1[1].chr(ord($SyncPattern1[2]) | 0x02).$SyncPattern1[3]; + if ($SyncPattern2 === $SyncPattern1) { + $SyncPattern2 = $SyncPattern1[0].$SyncPattern1[1].chr(ord($SyncPattern1[2]) & 0xFD).$SyncPattern1[3]; + } - $framelength = false; - $framelength1 = strpos($MPEGaudioData, $SyncPattern1, 4); - $framelength2 = strpos($MPEGaudioData, $SyncPattern2, 4); - if ($framelength1 > 4) { - $framelength = $framelength1; - } - if (($framelength2 > 4) && ($framelength2 < $framelength1)) { - $framelength = $framelength2; - } - if (!$framelength) { + $framelength = false; + $framelength1 = strpos($MPEGaudioData, $SyncPattern1, 4); + $framelength2 = strpos($MPEGaudioData, $SyncPattern2, 4); + if ($framelength1 > 4) { + $framelength = $framelength1; + } + if (($framelength2 > 4) && ($framelength2 < $framelength1)) { + $framelength = $framelength2; + } + if (! $framelength) { - // LAME 3.88 has a different value for modeextension on the first frame vs the rest - $framelength1 = strpos($MPEGaudioData, substr($SyncPattern1, 0, 3), 4); - $framelength2 = strpos($MPEGaudioData, substr($SyncPattern2, 0, 3), 4); + // LAME 3.88 has a different value for modeextension on the first frame vs the rest + $framelength1 = strpos($MPEGaudioData, substr($SyncPattern1, 0, 3), 4); + $framelength2 = strpos($MPEGaudioData, substr($SyncPattern2, 0, 3), 4); - if ($framelength1 > 4) { - $framelength = $framelength1; - } - if (($framelength2 > 4) && ($framelength2 < $framelength1)) { - $framelength = $framelength2; - } - if (!$framelength) { - $ThisFileInfo['error'] .= "\n".'Cannot find next free-format synch pattern ('.PrintHexBytes($SyncPattern1).' or '.PrintHexBytes($SyncPattern2).') after offset '.$offset; - return false; - } else { - $ThisFileInfo['warning'] .= "\n".'ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)'; - $ThisFileInfo['audio']['codec'] = 'LAME'; - $ThisFileInfo['audio']['encoder'] = 'LAME3.88'; - $SyncPattern1 = substr($SyncPattern1, 0, 3); - $SyncPattern2 = substr($SyncPattern2, 0, 3); - } - } + if ($framelength1 > 4) { + $framelength = $framelength1; + } + if (($framelength2 > 4) && ($framelength2 < $framelength1)) { + $framelength = $framelength2; + } + if (! $framelength) { + $ThisFileInfo['error'] .= "\n".'Cannot find next free-format synch pattern ('.PrintHexBytes($SyncPattern1).' or '.PrintHexBytes($SyncPattern2).') after offset '.$offset; - if ($deepscan) { + return false; + } else { + $ThisFileInfo['warning'] .= "\n".'ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)'; + $ThisFileInfo['audio']['codec'] = 'LAME'; + $ThisFileInfo['audio']['encoder'] = 'LAME3.88'; + $SyncPattern1 = substr($SyncPattern1, 0, 3); + $SyncPattern2 = substr($SyncPattern2, 0, 3); + } + } - $ActualFrameLengthValues = array(); - $nextoffset = $offset + $framelength; - while ($nextoffset < ($ThisFileInfo['avdataend'] - 6)) { - fseek($fd, $nextoffset - 1, SEEK_SET); - $NextSyncPattern = fread($fd, 6); - if ((substr($NextSyncPattern, 1, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 1, strlen($SyncPattern2)) == $SyncPattern2)) { - // good - found where expected - $ActualFrameLengthValues[] = $framelength; - } elseif ((substr($NextSyncPattern, 0, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 0, strlen($SyncPattern2)) == $SyncPattern2)) { - // ok - found one byte earlier than expected (last frame wasn't padded, first frame was) - $ActualFrameLengthValues[] = ($framelength - 1); - $nextoffset--; - } elseif ((substr($NextSyncPattern, 2, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 2, strlen($SyncPattern2)) == $SyncPattern2)) { - // ok - found one byte later than expected (last frame was padded, first frame wasn't) - $ActualFrameLengthValues[] = ($framelength + 1); - $nextoffset++; - } else { - $ThisFileInfo['error'] .= "\n".'Did not find expected free-format sync pattern at offset '.$nextoffset; - return false; - } - $nextoffset += $framelength; - } - if (count($ActualFrameLengthValues) > 0) { - $framelength = round(array_sum($ActualFrameLengthValues) / count($ActualFrameLengthValues)); - } - } - return $framelength; + if ($deepscan) { + $ActualFrameLengthValues = []; + $nextoffset = $offset + $framelength; + while ($nextoffset < ($ThisFileInfo['avdataend'] - 6)) { + fseek($fd, $nextoffset - 1, SEEK_SET); + $NextSyncPattern = fread($fd, 6); + if ((substr($NextSyncPattern, 1, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 1, strlen($SyncPattern2)) == $SyncPattern2)) { + // good - found where expected + $ActualFrameLengthValues[] = $framelength; + } elseif ((substr($NextSyncPattern, 0, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 0, strlen($SyncPattern2)) == $SyncPattern2)) { + // ok - found one byte earlier than expected (last frame wasn't padded, first frame was) + $ActualFrameLengthValues[] = ($framelength - 1); + $nextoffset--; + } elseif ((substr($NextSyncPattern, 2, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 2, strlen($SyncPattern2)) == $SyncPattern2)) { + // ok - found one byte later than expected (last frame was padded, first frame wasn't) + $ActualFrameLengthValues[] = ($framelength + 1); + $nextoffset++; + } else { + $ThisFileInfo['error'] .= "\n".'Did not find expected free-format sync pattern at offset '.$nextoffset; + + return false; + } + $nextoffset += $framelength; + } + if (count($ActualFrameLengthValues) > 0) { + $framelength = round(array_sum($ActualFrameLengthValues) / count($ActualFrameLengthValues)); + } + } + + return $framelength; } +function getOnlyMPEGaudioInfo($fd, &$ThisFileInfo, $avdataoffset, $BitrateHistogram = false) +{ + // looks for synch, decodes MPEG audio header -function getOnlyMPEGaudioInfo($fd, &$ThisFileInfo, $avdataoffset, $BitrateHistogram=false) { - // looks for synch, decodes MPEG audio header + fseek($fd, $avdataoffset, SEEK_SET); + $header = ''; + $SynchSeekOffset = 0; - fseek($fd, $avdataoffset, SEEK_SET); - $header = ''; - $SynchSeekOffset = 0; + if (! defined('CONST_FF')) { + define('CONST_FF', chr(0xFF)); + define('CONST_E0', chr(0xE0)); + } - if (!defined('CONST_FF')) { - define('CONST_FF', chr(0xFF)); - define('CONST_E0', chr(0xE0)); - } + static $MPEGaudioVersionLookup; + static $MPEGaudioLayerLookup; + static $MPEGaudioBitrateLookup; + if (empty($MPEGaudioVersionLookup)) { + $MPEGaudioVersionLookup = MPEGaudioVersionArray(); + $MPEGaudioLayerLookup = MPEGaudioLayerArray(); + $MPEGaudioBitrateLookup = MPEGaudioBitrateArray(); + } - static $MPEGaudioVersionLookup; - static $MPEGaudioLayerLookup; - static $MPEGaudioBitrateLookup; - if (empty($MPEGaudioVersionLookup)) { - $MPEGaudioVersionLookup = MPEGaudioVersionArray(); - $MPEGaudioLayerLookup = MPEGaudioLayerArray(); - $MPEGaudioBitrateLookup = MPEGaudioBitrateArray(); + $header_len = strlen($header) - round(32768 / 2); + while (true) { + if (($SynchSeekOffset > $header_len) && (($avdataoffset + $SynchSeekOffset) < $ThisFileInfo['avdataend']) && ! feof($fd)) { + if ($SynchSeekOffset > 131072) { + // if a synch's not found within the first 128k bytes, then give up + $ThisFileInfo['error'] .= "\n".'could not find valid MPEG synch within the first 131072 bytes'; + if (isset($ThisFileInfo['audio']['bitrate'])) { + unset($ThisFileInfo['audio']['bitrate']); + } + if (isset($ThisFileInfo['mpeg']['audio'])) { + unset($ThisFileInfo['mpeg']['audio']); + } + if (isset($ThisFileInfo['mpeg']) && (! is_array($ThisFileInfo['mpeg']) || (count($ThisFileInfo['mpeg']) == 0))) { + unset($ThisFileInfo['mpeg']); + } - } + return false; + } elseif ($header .= fread($fd, 32768)) { - $header_len = strlen($header) - round(32768 / 2); - while (true) { + // great + $header_len = strlen($header) - round(32768 / 2); + } else { + $ThisFileInfo['error'] .= "\n".'could not find valid MPEG synch before end of file'; + if (isset($ThisFileInfo['audio']['bitrate'])) { + unset($ThisFileInfo['audio']['bitrate']); + } + if (isset($ThisFileInfo['mpeg']['audio'])) { + unset($ThisFileInfo['mpeg']['audio']); + } + if (isset($ThisFileInfo['mpeg']) && (! is_array($ThisFileInfo['mpeg']) || (count($ThisFileInfo['mpeg']) == 0))) { + unset($ThisFileInfo['mpeg']); + } - if (($SynchSeekOffset > $header_len) && (($avdataoffset + $SynchSeekOffset) < $ThisFileInfo['avdataend']) && !feof($fd)) { + return false; + } + } - if ($SynchSeekOffset > 131072) { - // if a synch's not found within the first 128k bytes, then give up - $ThisFileInfo['error'] .= "\n".'could not find valid MPEG synch within the first 131072 bytes'; - if (isset($ThisFileInfo['audio']['bitrate'])) { - unset($ThisFileInfo['audio']['bitrate']); - } - if (isset($ThisFileInfo['mpeg']['audio'])) { - unset($ThisFileInfo['mpeg']['audio']); - } - if (isset($ThisFileInfo['mpeg']) && (!is_array($ThisFileInfo['mpeg']) || (count($ThisFileInfo['mpeg']) == 0))) { - unset($ThisFileInfo['mpeg']); - } - return false; + if (($SynchSeekOffset + 1) >= strlen($header)) { + $ThisFileInfo['error'] .= "\n".'could not find valid MPEG synch before end of file'; - } elseif ($header .= fread($fd, 32768)) { + return false; + } - // great - $header_len = strlen($header) - round(32768 / 2); + if (($header[$SynchSeekOffset] == CONST_FF) && ($header[($SynchSeekOffset + 1)] > CONST_E0)) { // synch detected - } else { + if (! isset($FirstFrameThisfileInfo) && ! isset($ThisFileInfo['mpeg']['audio'])) { + $FirstFrameThisfileInfo = $ThisFileInfo; + $FirstFrameAVDataOffset = $avdataoffset + $SynchSeekOffset; + if (! decodeMPEGaudioHeader($fd, $avdataoffset + $SynchSeekOffset, $FirstFrameThisfileInfo, false)) { + // if this is the first valid MPEG-audio frame, save it in case it's a VBR header frame and there's + // garbage between this frame and a valid sequence of MPEG-audio frames, to be restored below + unset($FirstFrameThisfileInfo); + } + } + $dummy = $ThisFileInfo; // only overwrite real data if valid header found - $ThisFileInfo['error'] .= "\n".'could not find valid MPEG synch before end of file'; - if (isset($ThisFileInfo['audio']['bitrate'])) { - unset($ThisFileInfo['audio']['bitrate']); - } - if (isset($ThisFileInfo['mpeg']['audio'])) { - unset($ThisFileInfo['mpeg']['audio']); - } - if (isset($ThisFileInfo['mpeg']) && (!is_array($ThisFileInfo['mpeg']) || (count($ThisFileInfo['mpeg']) == 0))) { - unset($ThisFileInfo['mpeg']); - } - return false; + if (decodeMPEGaudioHeader($fd, $avdataoffset + $SynchSeekOffset, $dummy, true)) { + $ThisFileInfo = $dummy; + $ThisFileInfo['avdataoffset'] = $avdataoffset + $SynchSeekOffset; + switch ($ThisFileInfo['fileformat']) { + case '': + case 'id3': + case 'ape': + case 'mp3': + $ThisFileInfo['fileformat'] = 'mp3'; + $ThisFileInfo['audio']['dataformat'] = 'mp3'; + } + if (isset($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode']) && ($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr')) { + if (! CloseMatch($ThisFileInfo['audio']['bitrate'], $FirstFrameThisfileInfo['audio']['bitrate'], 1)) { + // If there is garbage data between a valid VBR header frame and a sequence + // of valid MPEG-audio frames the VBR data is no longer discarded. + $ThisFileInfo = $FirstFrameThisfileInfo; + $ThisFileInfo['avdataoffset'] = $FirstFrameAVDataOffset; + $ThisFileInfo['fileformat'] = 'mp3'; + $ThisFileInfo['audio']['dataformat'] = 'mp3'; + $dummy = $ThisFileInfo; + unset($dummy['mpeg']['audio']); + $GarbageOffsetStart = $FirstFrameAVDataOffset + $FirstFrameThisfileInfo['mpeg']['audio']['framelength']; + $GarbageOffsetEnd = $avdataoffset + $SynchSeekOffset; + if (decodeMPEGaudioHeader($fd, $GarbageOffsetEnd, $dummy, true, true)) { + $ThisFileInfo = $dummy; + $ThisFileInfo['avdataoffset'] = $GarbageOffsetEnd; + $ThisFileInfo['warning'] .= "\n".'apparently-valid VBR header not used because could not find '.MPEG_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.'), but did find valid CBR stream starting at '.$GarbageOffsetEnd; + } else { + $ThisFileInfo['warning'] .= "\n".'using data from VBR header even though could not find '.MPEG_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.')'; + } + } + } - } - } + if (isset($ThisFileInfo['mpeg']['audio']['bitrate_mode']) && ($ThisFileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr') && ! isset($ThisFileInfo['mpeg']['audio']['VBR_method'])) { + // VBR file with no VBR header + $BitrateHistogram = true; + } - if (($SynchSeekOffset + 1) >= strlen($header)) { - $ThisFileInfo['error'] .= "\n".'could not find valid MPEG synch before end of file'; - return false; - } + if ($BitrateHistogram) { + $ThisFileInfo['mpeg']['audio']['stereo_distribution'] = ['stereo'=>0, 'joint stereo'=>0, 'dual channel'=>0, 'mono'=>0]; + $ThisFileInfo['mpeg']['audio']['version_distribution'] = ['1'=>0, '2'=>0, '2.5'=>0]; - if (($header{$SynchSeekOffset} == CONST_FF) && ($header{($SynchSeekOffset + 1)} > CONST_E0)) { // synch detected + if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { + if ($ThisFileInfo['mpeg']['audio']['layer'] == 'III') { + $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = ['free'=>0, 32=>0, 40=>0, 48=>0, 56=>0, 64=>0, 80=>0, 96=>0, 112=>0, 128=>0, 160=>0, 192=>0, 224=>0, 256=>0, 320=>0]; + } elseif ($ThisFileInfo['mpeg']['audio']['layer'] == 'II') { + $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = ['free'=>0, 32=>0, 48=>0, 56=>0, 64=>0, 80=>0, 96=>0, 112=>0, 128=>0, 160=>0, 192=>0, 224=>0, 256=>0, 320=>0, 384=>0]; + } elseif ($ThisFileInfo['mpeg']['audio']['layer'] == 'I') { + $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = ['free'=>0, 32=>0, 64=>0, 96=>0, 128=>0, 160=>0, 192=>0, 224=>0, 256=>0, 288=>0, 320=>0, 352=>0, 384=>0, 416=>0, 448=>0]; + } + } elseif ($ThisFileInfo['mpeg']['audio']['layer'] == 'I') { + $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = ['free'=>0, 32=>0, 48=>0, 56=>0, 64=>0, 80=>0, 96=>0, 112=>0, 128=>0, 144=>0, 160=>0, 176=>0, 192=>0, 224=>0, 256=>0]; + } else { + $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = ['free'=>0, 8=>0, 16=>0, 24=>0, 32=>0, 40=>0, 48=>0, 56=>0, 64=>0, 80=>0, 96=>0, 112=>0, 128=>0, 144=>0, 160=>0]; + } - if (!isset($FirstFrameThisfileInfo) && !isset($ThisFileInfo['mpeg']['audio'])) { - $FirstFrameThisfileInfo = $ThisFileInfo; - $FirstFrameAVDataOffset = $avdataoffset + $SynchSeekOffset; - if (!decodeMPEGaudioHeader($fd, $avdataoffset + $SynchSeekOffset, $FirstFrameThisfileInfo, false)) { - // if this is the first valid MPEG-audio frame, save it in case it's a VBR header frame and there's - // garbage between this frame and a valid sequence of MPEG-audio frames, to be restored below - unset($FirstFrameThisfileInfo); - } - } - $dummy = $ThisFileInfo; // only overwrite real data if valid header found + $dummy = ['error'=>$ThisFileInfo['error'], 'warning'=>$ThisFileInfo['warning'], 'avdataend'=>$ThisFileInfo['avdataend'], 'avdataoffset'=>$ThisFileInfo['avdataoffset']]; + $synchstartoffset = $ThisFileInfo['avdataoffset']; - if (decodeMPEGaudioHeader($fd, $avdataoffset + $SynchSeekOffset, $dummy, true)) { + $FastMode = false; + while (decodeMPEGaudioHeader($fd, $synchstartoffset, $dummy, false, false, $FastMode)) { + $FastMode = true; + $thisframebitrate = $MPEGaudioBitrateLookup[$MPEGaudioVersionLookup[$dummy['mpeg']['audio']['raw']['version']]][$MPEGaudioLayerLookup[$dummy['mpeg']['audio']['raw']['layer']]][$dummy['mpeg']['audio']['raw']['bitrate']]; - $ThisFileInfo = $dummy; - $ThisFileInfo['avdataoffset'] = $avdataoffset + $SynchSeekOffset; - switch ($ThisFileInfo['fileformat']) { - case '': - case 'id3': - case 'ape': - case 'mp3': - $ThisFileInfo['fileformat'] = 'mp3'; - $ThisFileInfo['audio']['dataformat'] = 'mp3'; - } - if (isset($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode']) && ($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr')) { - if (!CloseMatch($ThisFileInfo['audio']['bitrate'], $FirstFrameThisfileInfo['audio']['bitrate'], 1)) { - // If there is garbage data between a valid VBR header frame and a sequence - // of valid MPEG-audio frames the VBR data is no longer discarded. - $ThisFileInfo = $FirstFrameThisfileInfo; - $ThisFileInfo['avdataoffset'] = $FirstFrameAVDataOffset; - $ThisFileInfo['fileformat'] = 'mp3'; - $ThisFileInfo['audio']['dataformat'] = 'mp3'; - $dummy = $ThisFileInfo; - unset($dummy['mpeg']['audio']); - $GarbageOffsetStart = $FirstFrameAVDataOffset + $FirstFrameThisfileInfo['mpeg']['audio']['framelength']; - $GarbageOffsetEnd = $avdataoffset + $SynchSeekOffset; - if (decodeMPEGaudioHeader($fd, $GarbageOffsetEnd, $dummy, true, true)) { + $ThisFileInfo['mpeg']['audio']['bitrate_distribution'][$thisframebitrate]++; + $ThisFileInfo['mpeg']['audio']['stereo_distribution'][$dummy['mpeg']['audio']['channelmode']]++; + $ThisFileInfo['mpeg']['audio']['version_distribution'][$dummy['mpeg']['audio']['version']]++; + if (empty($dummy['mpeg']['audio']['framelength'])) { + $ThisFileInfo['warning'] .= "\n".'Invalid/missing framelength in histogram analysis - aborting'; + $synchstartoffset += 4; + // return false; + } + $synchstartoffset += $dummy['mpeg']['audio']['framelength']; + } - $ThisFileInfo = $dummy; - $ThisFileInfo['avdataoffset'] = $GarbageOffsetEnd; - $ThisFileInfo['warning'] .= "\n".'apparently-valid VBR header not used because could not find '.MPEG_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.'), but did find valid CBR stream starting at '.$GarbageOffsetEnd; + $bittotal = 0; + $framecounter = 0; + foreach ($ThisFileInfo['mpeg']['audio']['bitrate_distribution'] as $bitratevalue => $bitratecount) { + $framecounter += $bitratecount; + if ($bitratevalue != 'free') { + $bittotal += ($bitratevalue * $bitratecount); + } + } + if ($framecounter == 0) { + $ThisFileInfo['error'] .= "\n".'Corrupt MP3 file: framecounter == zero'; - } else { + return false; + } + $ThisFileInfo['mpeg']['audio']['frame_count'] = $framecounter; + $ThisFileInfo['mpeg']['audio']['bitrate'] = 1000 * ($bittotal / $framecounter); - $ThisFileInfo['warning'] .= "\n".'using data from VBR header even though could not find '.MPEG_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.')'; + $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate']; - } - } - } + // Definitively set VBR vs CBR, even if the Xing/LAME/VBRI header says differently + $distinct_bitrates = 0; + foreach ($ThisFileInfo['mpeg']['audio']['bitrate_distribution'] as $bitrate_value => $bitrate_count) { + if ($bitrate_count > 0) { + $distinct_bitrates++; + } + } + if ($distinct_bitrates > 1) { + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'vbr'; + } else { + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'cbr'; + } + $ThisFileInfo['audio']['bitrate_mode'] = $ThisFileInfo['mpeg']['audio']['bitrate_mode']; + } - if (isset($ThisFileInfo['mpeg']['audio']['bitrate_mode']) && ($ThisFileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr') && !isset($ThisFileInfo['mpeg']['audio']['VBR_method'])) { - // VBR file with no VBR header - $BitrateHistogram = true; - } + break; // exit while() + } + } - if ($BitrateHistogram) { + $SynchSeekOffset++; + if (($avdataoffset + $SynchSeekOffset) >= $ThisFileInfo['avdataend']) { + // end of file/data - $ThisFileInfo['mpeg']['audio']['stereo_distribution'] = array('stereo'=>0, 'joint stereo'=>0, 'dual channel'=>0, 'mono'=>0); - $ThisFileInfo['mpeg']['audio']['version_distribution'] = array('1'=>0, '2'=>0, '2.5'=>0); + if (empty($ThisFileInfo['mpeg']['audio'])) { + $ThisFileInfo['error'] .= "\n".'could not find valid MPEG synch before end of file'; + if (isset($ThisFileInfo['audio']['bitrate'])) { + unset($ThisFileInfo['audio']['bitrate']); + } + if (isset($ThisFileInfo['mpeg']['audio'])) { + unset($ThisFileInfo['mpeg']['audio']); + } + if (isset($ThisFileInfo['mpeg']) && (! is_array($ThisFileInfo['mpeg']) || empty($ThisFileInfo['mpeg']))) { + unset($ThisFileInfo['mpeg']); + } - if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { - if ($ThisFileInfo['mpeg']['audio']['layer'] == 'III') { - $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32=>0, 40=>0, 48=>0, 56=>0, 64=>0, 80=>0, 96=>0, 112=>0, 128=>0, 160=>0, 192=>0, 224=>0, 256=>0, 320=>0); - } elseif ($ThisFileInfo['mpeg']['audio']['layer'] == 'II') { - $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32=>0, 48=>0, 56=>0, 64=>0, 80=>0, 96=>0, 112=>0, 128=>0, 160=>0, 192=>0, 224=>0, 256=>0, 320=>0, 384=>0); - } elseif ($ThisFileInfo['mpeg']['audio']['layer'] == 'I') { - $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32=>0, 64=>0, 96=>0, 128=>0, 160=>0, 192=>0, 224=>0, 256=>0, 288=>0, 320=>0, 352=>0, 384=>0, 416=>0, 448=>0); - } - } elseif ($ThisFileInfo['mpeg']['audio']['layer'] == 'I') { - $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32=>0, 48=>0, 56=>0, 64=>0, 80=>0, 96=>0, 112=>0, 128=>0, 144=>0, 160=>0, 176=>0, 192=>0, 224=>0, 256=>0); - } else { - $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 8=>0, 16=>0, 24=>0, 32=>0, 40=>0, 48=>0, 56=>0, 64=>0, 80=>0, 96=>0, 112=>0, 128=>0, 144=>0, 160=>0); - } + return false; + } + break; + } + } + $ThisFileInfo['audio']['bits_per_sample'] = 16; + $ThisFileInfo['audio']['channels'] = $ThisFileInfo['mpeg']['audio']['channels']; + $ThisFileInfo['audio']['channelmode'] = $ThisFileInfo['mpeg']['audio']['channelmode']; + $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate']; - $dummy = array('error'=>$ThisFileInfo['error'], 'warning'=>$ThisFileInfo['warning'], 'avdataend'=>$ThisFileInfo['avdataend'], 'avdataoffset'=>$ThisFileInfo['avdataoffset']); - $synchstartoffset = $ThisFileInfo['avdataoffset']; - - $FastMode = false; - while (decodeMPEGaudioHeader($fd, $synchstartoffset, $dummy, false, false, $FastMode)) { - $FastMode = true; - $thisframebitrate = $MPEGaudioBitrateLookup[$MPEGaudioVersionLookup[$dummy['mpeg']['audio']['raw']['version']]][$MPEGaudioLayerLookup[$dummy['mpeg']['audio']['raw']['layer']]][$dummy['mpeg']['audio']['raw']['bitrate']]; - - $ThisFileInfo['mpeg']['audio']['bitrate_distribution'][$thisframebitrate]++; - $ThisFileInfo['mpeg']['audio']['stereo_distribution'][$dummy['mpeg']['audio']['channelmode']]++; - $ThisFileInfo['mpeg']['audio']['version_distribution'][$dummy['mpeg']['audio']['version']]++; - if (empty($dummy['mpeg']['audio']['framelength'])) { - $ThisFileInfo['warning'] .= "\n".'Invalid/missing framelength in histogram analysis - aborting'; -$synchstartoffset += 4; -// return false; - } - $synchstartoffset += $dummy['mpeg']['audio']['framelength']; - } - - $bittotal = 0; - $framecounter = 0; - foreach ($ThisFileInfo['mpeg']['audio']['bitrate_distribution'] as $bitratevalue => $bitratecount) { - $framecounter += $bitratecount; - if ($bitratevalue != 'free') { - $bittotal += ($bitratevalue * $bitratecount); - } - } - if ($framecounter == 0) { - $ThisFileInfo['error'] .= "\n".'Corrupt MP3 file: framecounter == zero'; - return false; - } - $ThisFileInfo['mpeg']['audio']['frame_count'] = $framecounter; - $ThisFileInfo['mpeg']['audio']['bitrate'] = 1000 * ($bittotal / $framecounter); - - $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate']; - - - // Definitively set VBR vs CBR, even if the Xing/LAME/VBRI header says differently - $distinct_bitrates = 0; - foreach ($ThisFileInfo['mpeg']['audio']['bitrate_distribution'] as $bitrate_value => $bitrate_count) { - if ($bitrate_count > 0) { - $distinct_bitrates++; - } - } - if ($distinct_bitrates > 1) { - $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'vbr'; - } else { - $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'cbr'; - } - $ThisFileInfo['audio']['bitrate_mode'] = $ThisFileInfo['mpeg']['audio']['bitrate_mode']; - - } - - break; // exit while() - } - } - - $SynchSeekOffset++; - if (($avdataoffset + $SynchSeekOffset) >= $ThisFileInfo['avdataend']) { - // end of file/data - - if (empty($ThisFileInfo['mpeg']['audio'])) { - - $ThisFileInfo['error'] .= "\n".'could not find valid MPEG synch before end of file'; - if (isset($ThisFileInfo['audio']['bitrate'])) { - unset($ThisFileInfo['audio']['bitrate']); - } - if (isset($ThisFileInfo['mpeg']['audio'])) { - unset($ThisFileInfo['mpeg']['audio']); - } - if (isset($ThisFileInfo['mpeg']) && (!is_array($ThisFileInfo['mpeg']) || empty($ThisFileInfo['mpeg']))) { - unset($ThisFileInfo['mpeg']); - } - return false; - - } - break; - } - - } - $ThisFileInfo['audio']['bits_per_sample'] = 16; - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['mpeg']['audio']['channels']; - $ThisFileInfo['audio']['channelmode'] = $ThisFileInfo['mpeg']['audio']['channelmode']; - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate']; - return true; + return true; } +function MPEGaudioVersionArray() +{ + static $MPEGaudioVersion = ['2.5', false, '2', '1']; -function MPEGaudioVersionArray() { - static $MPEGaudioVersion = array('2.5', false, '2', '1'); - return $MPEGaudioVersion; + return $MPEGaudioVersion; } -function MPEGaudioLayerArray() { - static $MPEGaudioLayer = array(false, 'III', 'II', 'I'); - return $MPEGaudioLayer; +function MPEGaudioLayerArray() +{ + static $MPEGaudioLayer = [false, 'III', 'II', 'I']; + + return $MPEGaudioLayer; } -function MPEGaudioBitrateArray() { - static $MPEGaudioBitrate; - if (empty($MPEGaudioBitrate)) { - $MPEGaudioBitrate['1']['I'] = array('free', 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448); - $MPEGaudioBitrate['1']['II'] = array('free', 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384); - $MPEGaudioBitrate['1']['III'] = array('free', 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320); - $MPEGaudioBitrate['2']['I'] = array('free', 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256); - $MPEGaudioBitrate['2']['II'] = array('free', 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160); - $MPEGaudioBitrate['2']['III'] = $MPEGaudioBitrate['2']['II']; - $MPEGaudioBitrate['2.5']['I'] = $MPEGaudioBitrate['2']['I']; - $MPEGaudioBitrate['2.5']['II'] = $MPEGaudioBitrate['2']['II']; - $MPEGaudioBitrate['2.5']['III'] = $MPEGaudioBitrate['2']['III']; - } - return $MPEGaudioBitrate; +function MPEGaudioBitrateArray() +{ + static $MPEGaudioBitrate; + if (empty($MPEGaudioBitrate)) { + $MPEGaudioBitrate['1']['I'] = ['free', 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448]; + $MPEGaudioBitrate['1']['II'] = ['free', 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384]; + $MPEGaudioBitrate['1']['III'] = ['free', 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320]; + $MPEGaudioBitrate['2']['I'] = ['free', 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256]; + $MPEGaudioBitrate['2']['II'] = ['free', 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160]; + $MPEGaudioBitrate['2']['III'] = $MPEGaudioBitrate['2']['II']; + $MPEGaudioBitrate['2.5']['I'] = $MPEGaudioBitrate['2']['I']; + $MPEGaudioBitrate['2.5']['II'] = $MPEGaudioBitrate['2']['II']; + $MPEGaudioBitrate['2.5']['III'] = $MPEGaudioBitrate['2']['III']; + } + + return $MPEGaudioBitrate; } -function MPEGaudioFrequencyArray() { - static $MPEGaudioFrequency; - if (empty($MPEGaudioFrequency)) { - $MPEGaudioFrequency['1'] = array(44100, 48000, 32000); - $MPEGaudioFrequency['2'] = array(22050, 24000, 16000); - $MPEGaudioFrequency['2.5'] = array(11025, 12000, 8000); - } - return $MPEGaudioFrequency; +function MPEGaudioFrequencyArray() +{ + static $MPEGaudioFrequency; + if (empty($MPEGaudioFrequency)) { + $MPEGaudioFrequency['1'] = [44100, 48000, 32000]; + $MPEGaudioFrequency['2'] = [22050, 24000, 16000]; + $MPEGaudioFrequency['2.5'] = [11025, 12000, 8000]; + } + + return $MPEGaudioFrequency; } -function MPEGaudioChannelModeArray() { - static $MPEGaudioChannelMode = array('stereo', 'joint stereo', 'dual channel', 'mono'); - return $MPEGaudioChannelMode; +function MPEGaudioChannelModeArray() +{ + static $MPEGaudioChannelMode = ['stereo', 'joint stereo', 'dual channel', 'mono']; + + return $MPEGaudioChannelMode; } -function MPEGaudioModeExtensionArray() { - static $MPEGaudioModeExtension; - if (empty($MPEGaudioModeExtension)) { - $MPEGaudioModeExtension['I'] = array('4-31', '8-31', '12-31', '16-31'); - $MPEGaudioModeExtension['II'] = array('4-31', '8-31', '12-31', '16-31'); - $MPEGaudioModeExtension['III'] = array('', 'IS', 'MS', 'IS+MS'); - } - return $MPEGaudioModeExtension; +function MPEGaudioModeExtensionArray() +{ + static $MPEGaudioModeExtension; + if (empty($MPEGaudioModeExtension)) { + $MPEGaudioModeExtension['I'] = ['4-31', '8-31', '12-31', '16-31']; + $MPEGaudioModeExtension['II'] = ['4-31', '8-31', '12-31', '16-31']; + $MPEGaudioModeExtension['III'] = ['', 'IS', 'MS', 'IS+MS']; + } + + return $MPEGaudioModeExtension; } -function MPEGaudioEmphasisArray() { - static $MPEGaudioEmphasis = array('none', '50/15ms', false, 'CCIT J.17'); - return $MPEGaudioEmphasis; +function MPEGaudioEmphasisArray() +{ + static $MPEGaudioEmphasis = ['none', '50/15ms', false, 'CCIT J.17']; + + return $MPEGaudioEmphasis; } - -function MPEGaudioHeaderBytesValid($head4) { - return MPEGaudioHeaderValid(MPEGaudioHeaderDecode($head4)); +function MPEGaudioHeaderBytesValid($head4) +{ + return MPEGaudioHeaderValid(MPEGaudioHeaderDecode($head4)); } -function MPEGaudioHeaderValid($rawarray, $echoerrors=false) { +function MPEGaudioHeaderValid($rawarray, $echoerrors = false) +{ + if (($rawarray['synch'] & 0x0FFE) != 0x0FFE) { + return false; + } - if (($rawarray['synch'] & 0x0FFE) != 0x0FFE) { - return false; - } + static $MPEGaudioVersionLookup; + static $MPEGaudioLayerLookup; + static $MPEGaudioBitrateLookup; + static $MPEGaudioFrequencyLookup; + static $MPEGaudioChannelModeLookup; + static $MPEGaudioModeExtensionLookup; + static $MPEGaudioEmphasisLookup; + if (empty($MPEGaudioVersionLookup)) { + $MPEGaudioVersionLookup = MPEGaudioVersionArray(); + $MPEGaudioLayerLookup = MPEGaudioLayerArray(); + $MPEGaudioBitrateLookup = MPEGaudioBitrateArray(); + $MPEGaudioFrequencyLookup = MPEGaudioFrequencyArray(); + $MPEGaudioChannelModeLookup = MPEGaudioChannelModeArray(); + $MPEGaudioModeExtensionLookup = MPEGaudioModeExtensionArray(); + $MPEGaudioEmphasisLookup = MPEGaudioEmphasisArray(); + } - static $MPEGaudioVersionLookup; - static $MPEGaudioLayerLookup; - static $MPEGaudioBitrateLookup; - static $MPEGaudioFrequencyLookup; - static $MPEGaudioChannelModeLookup; - static $MPEGaudioModeExtensionLookup; - static $MPEGaudioEmphasisLookup; - if (empty($MPEGaudioVersionLookup)) { - $MPEGaudioVersionLookup = MPEGaudioVersionArray(); - $MPEGaudioLayerLookup = MPEGaudioLayerArray(); - $MPEGaudioBitrateLookup = MPEGaudioBitrateArray(); - $MPEGaudioFrequencyLookup = MPEGaudioFrequencyArray(); - $MPEGaudioChannelModeLookup = MPEGaudioChannelModeArray(); - $MPEGaudioModeExtensionLookup = MPEGaudioModeExtensionArray(); - $MPEGaudioEmphasisLookup = MPEGaudioEmphasisArray(); - } + if (isset($MPEGaudioVersionLookup[$rawarray['version']])) { + $decodedVersion = $MPEGaudioVersionLookup[$rawarray['version']]; + } else { + if ($echoerrors) { + echo "\n".'invalid Version ('.$rawarray['version'].')'; + } - if (isset($MPEGaudioVersionLookup[$rawarray['version']])) { - $decodedVersion = $MPEGaudioVersionLookup[$rawarray['version']]; - } else { - if ($echoerrors) { - echo "\n".'invalid Version ('.$rawarray['version'].')'; - } - return false; - } - if (isset($MPEGaudioLayerLookup[$rawarray['layer']])) { - $decodedLayer = $MPEGaudioLayerLookup[$rawarray['layer']]; - } else { - if ($echoerrors) { - echo "\n".'invalid Layer ('.$rawarray['layer'].')'; - } - return false; - } - if (!isset($MPEGaudioBitrateLookup[$decodedVersion][$decodedLayer][$rawarray['bitrate']])) { - if ($echoerrors) { - echo "\n".'invalid Bitrate ('.$rawarray['bitrate'].')'; - } - if ($rawarray['bitrate'] == 15) { - // known issue in LAME 3.90 - 3.93.1 where free-format has bitrate ID of 15 instead of 0 - // let it go through here otherwise file will not be identified - } else { - return false; - } - } - if (!isset($MPEGaudioFrequencyLookup[$decodedVersion][$rawarray['sample_rate']])) { - if ($echoerrors) { - echo "\n".'invalid Frequency ('.$rawarray['sample_rate'].')'; - } - return false; - } - if (!isset($MPEGaudioChannelModeLookup[$rawarray['channelmode']])) { - if ($echoerrors) { - echo "\n".'invalid ChannelMode ('.$rawarray['channelmode'].')'; - } - return false; - } - if (!isset($MPEGaudioModeExtensionLookup[$decodedLayer][$rawarray['modeextension']])) { - if ($echoerrors) { - echo "\n".'invalid Mode Extension ('.$rawarray['modeextension'].')'; - } - return false; - } - if (!isset($MPEGaudioEmphasisLookup[$rawarray['emphasis']])) { - if ($echoerrors) { - echo "\n".'invalid Emphasis ('.$rawarray['emphasis'].')'; - } - return false; - } - // These are just either set or not set, you can't mess that up :) - // $rawarray['protection']; - // $rawarray['padding']; - // $rawarray['private']; - // $rawarray['copyright']; - // $rawarray['original']; + return false; + } + if (isset($MPEGaudioLayerLookup[$rawarray['layer']])) { + $decodedLayer = $MPEGaudioLayerLookup[$rawarray['layer']]; + } else { + if ($echoerrors) { + echo "\n".'invalid Layer ('.$rawarray['layer'].')'; + } - return true; + return false; + } + if (! isset($MPEGaudioBitrateLookup[$decodedVersion][$decodedLayer][$rawarray['bitrate']])) { + if ($echoerrors) { + echo "\n".'invalid Bitrate ('.$rawarray['bitrate'].')'; + } + if ($rawarray['bitrate'] == 15) { + // known issue in LAME 3.90 - 3.93.1 where free-format has bitrate ID of 15 instead of 0 + // let it go through here otherwise file will not be identified + } else { + return false; + } + } + if (! isset($MPEGaudioFrequencyLookup[$decodedVersion][$rawarray['sample_rate']])) { + if ($echoerrors) { + echo "\n".'invalid Frequency ('.$rawarray['sample_rate'].')'; + } + + return false; + } + if (! isset($MPEGaudioChannelModeLookup[$rawarray['channelmode']])) { + if ($echoerrors) { + echo "\n".'invalid ChannelMode ('.$rawarray['channelmode'].')'; + } + + return false; + } + if (! isset($MPEGaudioModeExtensionLookup[$decodedLayer][$rawarray['modeextension']])) { + if ($echoerrors) { + echo "\n".'invalid Mode Extension ('.$rawarray['modeextension'].')'; + } + + return false; + } + if (! isset($MPEGaudioEmphasisLookup[$rawarray['emphasis']])) { + if ($echoerrors) { + echo "\n".'invalid Emphasis ('.$rawarray['emphasis'].')'; + } + + return false; + } + // These are just either set or not set, you can't mess that up :) + // $rawarray['protection']; + // $rawarray['padding']; + // $rawarray['private']; + // $rawarray['copyright']; + // $rawarray['original']; + + return true; } -function MPEGaudioHeaderDecode($Header4Bytes) { - // AAAA AAAA AAAB BCCD EEEE FFGH IIJJ KLMM - // A - Frame sync (all bits set) - // B - MPEG Audio version ID - // C - Layer description - // D - Protection bit - // E - Bitrate index - // F - Sampling rate frequency index - // G - Padding bit - // H - Private bit - // I - Channel Mode - // J - Mode extension (Only if Joint stereo) - // K - Copyright - // L - Original - // M - Emphasis +function MPEGaudioHeaderDecode($Header4Bytes) +{ + // AAAA AAAA AAAB BCCD EEEE FFGH IIJJ KLMM + // A - Frame sync (all bits set) + // B - MPEG Audio version ID + // C - Layer description + // D - Protection bit + // E - Bitrate index + // F - Sampling rate frequency index + // G - Padding bit + // H - Private bit + // I - Channel Mode + // J - Mode extension (Only if Joint stereo) + // K - Copyright + // L - Original + // M - Emphasis - if (strlen($Header4Bytes) != 4) { - return false; - } + if (strlen($Header4Bytes) != 4) { + return false; + } - $MPEGrawHeader['synch'] = (BigEndian2Int(substr($Header4Bytes, 0, 2)) & 0xFFE0) >> 4; - $MPEGrawHeader['version'] = (ord($Header4Bytes{1}) & 0x18) >> 3; // BB - $MPEGrawHeader['layer'] = (ord($Header4Bytes{1}) & 0x06) >> 1; // CC - $MPEGrawHeader['protection'] = (ord($Header4Bytes{1}) & 0x01); // D - $MPEGrawHeader['bitrate'] = (ord($Header4Bytes{2}) & 0xF0) >> 4; // EEEE - $MPEGrawHeader['sample_rate'] = (ord($Header4Bytes{2}) & 0x0C) >> 2; // FF - $MPEGrawHeader['padding'] = (ord($Header4Bytes{2}) & 0x02) >> 1; // G - $MPEGrawHeader['private'] = (ord($Header4Bytes{2}) & 0x01); // H - $MPEGrawHeader['channelmode'] = (ord($Header4Bytes{3}) & 0xC0) >> 6; // II - $MPEGrawHeader['modeextension'] = (ord($Header4Bytes{3}) & 0x30) >> 4; // JJ - $MPEGrawHeader['copyright'] = (ord($Header4Bytes{3}) & 0x08) >> 3; // K - $MPEGrawHeader['original'] = (ord($Header4Bytes{3}) & 0x04) >> 2; // L - $MPEGrawHeader['emphasis'] = (ord($Header4Bytes{3}) & 0x03); // MM + $MPEGrawHeader['synch'] = (BigEndian2Int(substr($Header4Bytes, 0, 2)) & 0xFFE0) >> 4; + $MPEGrawHeader['version'] = (ord($Header4Bytes[1]) & 0x18) >> 3; // BB + $MPEGrawHeader['layer'] = (ord($Header4Bytes[1]) & 0x06) >> 1; // CC + $MPEGrawHeader['protection'] = (ord($Header4Bytes[1]) & 0x01); // D + $MPEGrawHeader['bitrate'] = (ord($Header4Bytes[2]) & 0xF0) >> 4; // EEEE + $MPEGrawHeader['sample_rate'] = (ord($Header4Bytes[2]) & 0x0C) >> 2; // FF + $MPEGrawHeader['padding'] = (ord($Header4Bytes[2]) & 0x02) >> 1; // G + $MPEGrawHeader['private'] = (ord($Header4Bytes[2]) & 0x01); // H + $MPEGrawHeader['channelmode'] = (ord($Header4Bytes[3]) & 0xC0) >> 6; // II + $MPEGrawHeader['modeextension'] = (ord($Header4Bytes[3]) & 0x30) >> 4; // JJ + $MPEGrawHeader['copyright'] = (ord($Header4Bytes[3]) & 0x08) >> 3; // K + $MPEGrawHeader['original'] = (ord($Header4Bytes[3]) & 0x04) >> 2; // L + $MPEGrawHeader['emphasis'] = (ord($Header4Bytes[3]) & 0x03); // MM - return $MPEGrawHeader; + return $MPEGrawHeader; } -function MPEGaudioFrameLength(&$bitrate, &$version, &$layer, $padding, &$samplerate) { - static $AudioFrameLengthCache = array(); +function MPEGaudioFrameLength(&$bitrate, &$version, &$layer, $padding, &$samplerate) +{ + static $AudioFrameLengthCache = []; - if (!isset($AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate])) { - $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] = false; - if ($bitrate != 'free') { + if (! isset($AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate])) { + $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] = false; + if ($bitrate != 'free') { + if ($version == '1') { + if ($layer == 'I') { - if ($version == '1') { + // For Layer I slot is 32 bits long + $FrameLengthCoefficient = 48; + $SlotLength = 4; + } else { // Layer II / III - if ($layer == 'I') { + // for Layer II and Layer III slot is 8 bits long. + $FrameLengthCoefficient = 144; + $SlotLength = 1; + } + } else { // MPEG-2 / MPEG-2.5 - // For Layer I slot is 32 bits long - $FrameLengthCoefficient = 48; - $SlotLength = 4; + if ($layer == 'I') { - } else { // Layer II / III + // For Layer I slot is 32 bits long + $FrameLengthCoefficient = 24; + $SlotLength = 4; + } elseif ($layer == 'II') { - // for Layer II and Layer III slot is 8 bits long. - $FrameLengthCoefficient = 144; - $SlotLength = 1; + // for Layer II and Layer III slot is 8 bits long. + $FrameLengthCoefficient = 144; + $SlotLength = 1; + } else { // III - } + // for Layer II and Layer III slot is 8 bits long. + $FrameLengthCoefficient = 72; + $SlotLength = 1; + } + } - } else { // MPEG-2 / MPEG-2.5 + // FrameLengthInBytes = ((Coefficient * BitRate) / SampleRate) + Padding + // http://66.96.216.160/cgi-bin/YaBB.pl?board=c&action=display&num=1018474068 + // -> [Finding the next frame synch] on www.r3mix.net forums if the above link goes dead + if ($samplerate > 0) { + $NewFramelength = ($FrameLengthCoefficient * $bitrate * 1000) / $samplerate; + $NewFramelength = floor($NewFramelength / $SlotLength) * $SlotLength; // round to next-lower multiple of SlotLength (1 byte for Layer II/III, 4 bytes for Layer I) + if ($padding) { + $NewFramelength += $SlotLength; + } + $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] = (int) $NewFramelength; + } + } + } - if ($layer == 'I') { - - // For Layer I slot is 32 bits long - $FrameLengthCoefficient = 24; - $SlotLength = 4; - - } elseif ($layer == 'II') { - - // for Layer II and Layer III slot is 8 bits long. - $FrameLengthCoefficient = 144; - $SlotLength = 1; - - } else { // III - - // for Layer II and Layer III slot is 8 bits long. - $FrameLengthCoefficient = 72; - $SlotLength = 1; - - } - - } - - // FrameLengthInBytes = ((Coefficient * BitRate) / SampleRate) + Padding - // http://66.96.216.160/cgi-bin/YaBB.pl?board=c&action=display&num=1018474068 - // -> [Finding the next frame synch] on www.r3mix.net forums if the above link goes dead - if ($samplerate > 0) { - $NewFramelength = ($FrameLengthCoefficient * $bitrate * 1000) / $samplerate; - $NewFramelength = floor($NewFramelength / $SlotLength) * $SlotLength; // round to next-lower multiple of SlotLength (1 byte for Layer II/III, 4 bytes for Layer I) - if ($padding) { - $NewFramelength += $SlotLength; - } - $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] = (int) $NewFramelength; - } - } - } - return $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate]; + return $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate]; } -function LAMEvbrMethodLookup($VBRmethodID) { - static $LAMEvbrMethodLookup = array(); - if (empty($LAMEvbrMethodLookup)) { - $LAMEvbrMethodLookup[0x00] = 'unknown'; - $LAMEvbrMethodLookup[0x01] = 'cbr'; - $LAMEvbrMethodLookup[0x02] = 'abr'; - $LAMEvbrMethodLookup[0x03] = 'vbr-old / vbr-rh'; - $LAMEvbrMethodLookup[0x04] = 'vbr-mtrh'; - $LAMEvbrMethodLookup[0x05] = 'vbr-new / vbr-mt'; - } - return (isset($LAMEvbrMethodLookup[$VBRmethodID]) ? $LAMEvbrMethodLookup[$VBRmethodID] : ''); +function LAMEvbrMethodLookup($VBRmethodID) +{ + static $LAMEvbrMethodLookup = []; + if (empty($LAMEvbrMethodLookup)) { + $LAMEvbrMethodLookup[0x00] = 'unknown'; + $LAMEvbrMethodLookup[0x01] = 'cbr'; + $LAMEvbrMethodLookup[0x02] = 'abr'; + $LAMEvbrMethodLookup[0x03] = 'vbr-old / vbr-rh'; + $LAMEvbrMethodLookup[0x04] = 'vbr-mtrh'; + $LAMEvbrMethodLookup[0x05] = 'vbr-new / vbr-mt'; + } + + return isset($LAMEvbrMethodLookup[$VBRmethodID]) ? $LAMEvbrMethodLookup[$VBRmethodID] : ''; } -function LAMEmiscStereoModeLookup($StereoModeID) { - static $LAMEmiscStereoModeLookup = array(); - if (empty($LAMEmiscStereoModeLookup)) { - $LAMEmiscStereoModeLookup[0] = 'mono'; - $LAMEmiscStereoModeLookup[1] = 'stereo'; - $LAMEmiscStereoModeLookup[2] = 'dual'; - $LAMEmiscStereoModeLookup[3] = 'joint'; - $LAMEmiscStereoModeLookup[4] = 'forced'; - $LAMEmiscStereoModeLookup[5] = 'auto'; - $LAMEmiscStereoModeLookup[6] = 'intensity'; - $LAMEmiscStereoModeLookup[7] = 'other'; - } - return (isset($LAMEmiscStereoModeLookup[$StereoModeID]) ? $LAMEmiscStereoModeLookup[$StereoModeID] : ''); +function LAMEmiscStereoModeLookup($StereoModeID) +{ + static $LAMEmiscStereoModeLookup = []; + if (empty($LAMEmiscStereoModeLookup)) { + $LAMEmiscStereoModeLookup[0] = 'mono'; + $LAMEmiscStereoModeLookup[1] = 'stereo'; + $LAMEmiscStereoModeLookup[2] = 'dual'; + $LAMEmiscStereoModeLookup[3] = 'joint'; + $LAMEmiscStereoModeLookup[4] = 'forced'; + $LAMEmiscStereoModeLookup[5] = 'auto'; + $LAMEmiscStereoModeLookup[6] = 'intensity'; + $LAMEmiscStereoModeLookup[7] = 'other'; + } + + return isset($LAMEmiscStereoModeLookup[$StereoModeID]) ? $LAMEmiscStereoModeLookup[$StereoModeID] : ''; } -function LAMEmiscSourceSampleFrequencyLookup($SourceSampleFrequencyID) { - static $LAMEmiscSourceSampleFrequencyLookup = array(); - if (empty($LAMEmiscSourceSampleFrequencyLookup)) { - $LAMEmiscSourceSampleFrequencyLookup[0] = '<= 32 kHz'; - $LAMEmiscSourceSampleFrequencyLookup[1] = '44.1 kHz'; - $LAMEmiscSourceSampleFrequencyLookup[2] = '48 kHz'; - $LAMEmiscSourceSampleFrequencyLookup[3] = '> 48kHz'; - } - return (isset($LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID]) ? $LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID] : ''); +function LAMEmiscSourceSampleFrequencyLookup($SourceSampleFrequencyID) +{ + static $LAMEmiscSourceSampleFrequencyLookup = []; + if (empty($LAMEmiscSourceSampleFrequencyLookup)) { + $LAMEmiscSourceSampleFrequencyLookup[0] = '<= 32 kHz'; + $LAMEmiscSourceSampleFrequencyLookup[1] = '44.1 kHz'; + $LAMEmiscSourceSampleFrequencyLookup[2] = '48 kHz'; + $LAMEmiscSourceSampleFrequencyLookup[3] = '> 48kHz'; + } + + return isset($LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID]) ? $LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID] : ''; } -function LAMEsurroundInfoLookup($SurroundInfoID) { - static $LAMEsurroundInfoLookup = array(); - if (empty($LAMEsurroundInfoLookup)) { - $LAMEsurroundInfoLookup[0] = 'no surround info'; - $LAMEsurroundInfoLookup[1] = 'DPL encoding'; - $LAMEsurroundInfoLookup[2] = 'DPL2 encoding'; - $LAMEsurroundInfoLookup[3] = 'Ambisonic encoding'; - } - return (isset($LAMEsurroundInfoLookup[$SurroundInfoID]) ? $LAMEsurroundInfoLookup[$SurroundInfoID] : 'reserved'); +function LAMEsurroundInfoLookup($SurroundInfoID) +{ + static $LAMEsurroundInfoLookup = []; + if (empty($LAMEsurroundInfoLookup)) { + $LAMEsurroundInfoLookup[0] = 'no surround info'; + $LAMEsurroundInfoLookup[1] = 'DPL encoding'; + $LAMEsurroundInfoLookup[2] = 'DPL2 encoding'; + $LAMEsurroundInfoLookup[3] = 'Ambisonic encoding'; + } + + return isset($LAMEsurroundInfoLookup[$SurroundInfoID]) ? $LAMEsurroundInfoLookup[$SurroundInfoID] : 'reserved'; } for ($i = 0x00; $i <= 0xFF; $i++) { - $head4 = "\xFF\xFE".chr($i)."\x00"; - $isvalid = MPEGaudioHeaderBytesValid($head4); - echo '
'.str_pad(strtoupper(dechex($i)), 2, '0', STR_PAD_LEFT).' = '.htmlentities(chr($i)).' = '.($isvalid ? 'valid' : 'INVALID').'
'; + $head4 = "\xFF\xFE".chr($i)."\x00"; + $isvalid = MPEGaudioHeaderBytesValid($head4); + echo '
'.str_pad(strtoupper(dechex($i)), 2, '0', STR_PAD_LEFT).' = '.htmlentities(chr($i)).' = '.($isvalid ? 'valid' : 'INVALID').'
'; } diff --git a/app/Library/getid3/demos/demo.mysql.php b/app/Library/getid3/demos/demo.mysql.php index 24443994..1e2e6fa8 100644 --- a/app/Library/getid3/demos/demo.mysql.php +++ b/app/Library/getid3/demos/demo.mysql.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -15,2135 +16,1950 @@ die('Due to a security issue, this demo has been disabled. It can be enabled by removing line 16 in demos/demo.mysql.php'); - // OPTIONS: $getid3_demo_mysql_encoding = 'ISO-8859-1'; $getid3_demo_mysql_md5_data = false; // All data hashes are by far the slowest part of scanning $getid3_demo_mysql_md5_file = false; -define('GETID3_DB_HOST', 'localhost'); -define('GETID3_DB_USER', 'root'); -define('GETID3_DB_PASS', 'password'); -define('GETID3_DB_DB', 'getid3'); +define('GETID3_DB_HOST', 'localhost'); +define('GETID3_DB_USER', 'root'); +define('GETID3_DB_PASS', 'password'); +define('GETID3_DB_DB', 'getid3'); define('GETID3_DB_TABLE', 'files'); // CREATE DATABASE `getid3`; ob_start(); -if (!mysql_connect(GETID3_DB_HOST, GETID3_DB_USER, GETID3_DB_PASS)) { - $errormessage = ob_get_contents(); - ob_end_clean(); - die('Could not connect to MySQL host:
'.mysql_error().'
'); +if (! mysql_connect(GETID3_DB_HOST, GETID3_DB_USER, GETID3_DB_PASS)) { + $errormessage = ob_get_contents(); + ob_end_clean(); + die('Could not connect to MySQL host:
'.mysql_error().'
'); } -if (!mysql_select_db(GETID3_DB_DB)) { - $errormessage = ob_get_contents(); - ob_end_clean(); - die('Could not select database:
'.mysql_error().'
'); +if (! mysql_select_db(GETID3_DB_DB)) { + $errormessage = ob_get_contents(); + ob_end_clean(); + die('Could not select database:
'.mysql_error().'
'); } ob_end_clean(); $getid3PHP_filename = realpath('../getid3/getid3.php'); -if (!file_exists($getid3PHP_filename) || !include_once($getid3PHP_filename)) { - die('Cannot open '.$getid3PHP_filename); +if (! file_exists($getid3PHP_filename) || ! include_once($getid3PHP_filename)) { + die('Cannot open '.$getid3PHP_filename); } // Initialize getID3 engine $getID3 = new getID3; -$getID3->setOption(array( - 'option_md5_data' => $getid3_demo_mysql_md5_data, - 'encoding' => $getid3_demo_mysql_encoding, -)); +$getID3->setOption([ + 'option_md5_data' => $getid3_demo_mysql_md5_data, + 'encoding' => $getid3_demo_mysql_encoding, +]); - -function RemoveAccents($string) { - // Revised version by markstewardØhotmail*com - return strtr(strtr($string, 'ŠŽšžŸÀÃÂÃÄÅÇÈÉÊËÌÃÃŽÃÑÒÓÔÕÖØÙÚÛÜÃàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'), array('Þ' => 'TH', 'þ' => 'th', 'Ã' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'ÂŒ' => 'OE', 'Âœ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u')); +function RemoveAccents($string) +{ + // Revised version by markstewardØhotmail*com + return strtr(strtr($string, 'ŠŽšžŸÀÃÂÃÄÅÇÈÉÊËÌÃÃŽÃÑÒÓÔÕÖØÙÚÛÜÃàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'), ['Þ' => 'TH', 'þ' => 'th', 'Ã' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'ÂŒ' => 'OE', 'Âœ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u']); } -function BitrateColor($bitrate, $BitrateMaxScale=768) { - // $BitrateMaxScale is bitrate of maximum-quality color (bright green) - // below this is gradient, above is solid green +function BitrateColor($bitrate, $BitrateMaxScale = 768) +{ + // $BitrateMaxScale is bitrate of maximum-quality color (bright green) + // below this is gradient, above is solid green - $bitrate *= (256 / $BitrateMaxScale); // scale from 1-[768]kbps to 1-256 - $bitrate = round(min(max($bitrate, 1), 256)); - $bitrate--; // scale from 1-256kbps to 0-255kbps + $bitrate *= (256 / $BitrateMaxScale); // scale from 1-[768]kbps to 1-256 + $bitrate = round(min(max($bitrate, 1), 256)); + $bitrate--; // scale from 1-256kbps to 0-255kbps - $Rcomponent = max(255 - ($bitrate * 2), 0); - $Gcomponent = max(($bitrate * 2) - 255, 0); - if ($bitrate > 127) { - $Bcomponent = max((255 - $bitrate) * 2, 0); - } else { - $Bcomponent = max($bitrate * 2, 0); - } - return str_pad(dechex($Rcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Gcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Bcomponent), 2, '0', STR_PAD_LEFT); + $Rcomponent = max(255 - ($bitrate * 2), 0); + $Gcomponent = max(($bitrate * 2) - 255, 0); + if ($bitrate > 127) { + $Bcomponent = max((255 - $bitrate) * 2, 0); + } else { + $Bcomponent = max($bitrate * 2, 0); + } + + return str_pad(dechex($Rcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Gcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Bcomponent), 2, '0', STR_PAD_LEFT); } -function BitrateText($bitrate, $decimals=0) { - return ''.number_format($bitrate, $decimals).' kbps'; +function BitrateText($bitrate, $decimals = 0) +{ + return ''.number_format($bitrate, $decimals).' kbps'; } -function fileextension($filename, $numextensions=1) { - if (strstr($filename, '.')) { - $reversedfilename = strrev($filename); - $offset = 0; - for ($i = 0; $i < $numextensions; $i++) { - $offset = strpos($reversedfilename, '.', $offset + 1); - if ($offset === false) { - return ''; - } - } - return strrev(substr($reversedfilename, 0, $offset)); - } - return ''; +function fileextension($filename, $numextensions = 1) +{ + if (strstr($filename, '.')) { + $reversedfilename = strrev($filename); + $offset = 0; + for ($i = 0; $i < $numextensions; $i++) { + $offset = strpos($reversedfilename, '.', $offset + 1); + if ($offset === false) { + return ''; + } + } + + return strrev(substr($reversedfilename, 0, $offset)); + } + + return ''; } -function RenameFileFromTo($from, $to, &$results) { - $success = true; - if ($from === $to) { - $results = 'Source and Destination filenames identical
FAILED to rename'; - } elseif (!file_exists($from)) { - $results = 'Source file does not exist
FAILED to rename'; - } elseif (file_exists($to) && (strtolower($from) !== strtolower($to))) { - $results = 'Destination file already exists
FAILED to rename'; - } else { - ob_start(); - if (rename($from, $to)) { - ob_end_clean(); - $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($from).'")'; - mysql_query_safe($SQLquery); - $results = 'Successfully renamed'; - } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - $results = '
FAILED to rename'; - $success = false; - } - } - $results .= ' from:
'.$from.'
to:
'.$to.'

'; - return $success; +function RenameFileFromTo($from, $to, &$results) +{ + $success = true; + if ($from === $to) { + $results = 'Source and Destination filenames identical
FAILED to rename'; + } elseif (! file_exists($from)) { + $results = 'Source file does not exist
FAILED to rename'; + } elseif (file_exists($to) && (strtolower($from) !== strtolower($to))) { + $results = 'Destination file already exists
FAILED to rename'; + } else { + ob_start(); + if (rename($from, $to)) { + ob_end_clean(); + $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($from).'")'; + mysql_query_safe($SQLquery); + $results = 'Successfully renamed'; + } else { + $errormessage = ob_get_contents(); + ob_end_clean(); + $results = '
FAILED to rename'; + $success = false; + } + } + $results .= ' from:
'.$from.'
to:
'.$to.'

'; + + return $success; } -if (!empty($_REQUEST['renamefilefrom']) && !empty($_REQUEST['renamefileto'])) { - - $results = ''; - RenameFileFromTo($_REQUEST['renamefilefrom'], $_REQUEST['renamefileto'], $results); - echo $results; - exit; - -} elseif (!empty($_REQUEST['m3ufilename'])) { - - header('Content-type: audio/x-mpegurl'); - echo '#EXTM3U'."\n"; - echo WindowsShareSlashTranslate($_REQUEST['m3ufilename'])."\n"; - exit; - -} elseif (!isset($_REQUEST['m3u']) && !isset($_REQUEST['m3uartist']) && !isset($_REQUEST['m3utitle'])) { - - echo ''; - echo 'getID3() demo - /demo/mysql.php'; - +if (! empty($_REQUEST['renamefilefrom']) && ! empty($_REQUEST['renamefileto'])) { + $results = ''; + RenameFileFromTo($_REQUEST['renamefilefrom'], $_REQUEST['renamefileto'], $results); + echo $results; + exit; +} elseif (! empty($_REQUEST['m3ufilename'])) { + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + echo WindowsShareSlashTranslate($_REQUEST['m3ufilename'])."\n"; + exit; +} elseif (! isset($_REQUEST['m3u']) && ! isset($_REQUEST['m3uartist']) && ! isset($_REQUEST['m3utitle'])) { + echo ''; + echo 'getID3() demo - /demo/mysql.php'; } +function WindowsShareSlashTranslate($filename) +{ + if (substr($filename, 0, 2) == '//') { + return str_replace('/', '\\', $filename); + } -function WindowsShareSlashTranslate($filename) { - if (substr($filename, 0, 2) == '//') { - return str_replace('/', '\\', $filename); - } - return $filename; + return $filename; } -function mysql_query_safe($SQLquery) { - static $TimeSpentQuerying = 0; - if ($SQLquery === null) { - return $TimeSpentQuerying; - } - $starttime = microtime(true); - $result = mysql_query($SQLquery); - $TimeSpentQuerying += (microtime(true) - $starttime); - if (mysql_error()) { - die('
SQL error:
'.htmlentities(mysql_error()).'

'.htmlentities($SQLquery).'
'); - } - return $result; +function mysql_query_safe($SQLquery) +{ + static $TimeSpentQuerying = 0; + if ($SQLquery === null) { + return $TimeSpentQuerying; + } + $starttime = microtime(true); + $result = mysql_query($SQLquery); + $TimeSpentQuerying += (microtime(true) - $starttime); + if (mysql_error()) { + die('
SQL error:
'.htmlentities(mysql_error()).'

'.htmlentities($SQLquery).'
'); + } + + return $result; } -function mysql_table_exists($tablename) { - return (bool) mysql_query('DESCRIBE '.$tablename); +function mysql_table_exists($tablename) +{ + return (bool) mysql_query('DESCRIBE '.$tablename); } -function AcceptableExtensions($fileformat, $audio_dataformat='', $video_dataformat='') { - static $AcceptableExtensionsAudio = array(); - if (empty($AcceptableExtensionsAudio)) { - $AcceptableExtensionsAudio['mp3']['mp3'] = array('mp3'); - $AcceptableExtensionsAudio['mp2']['mp2'] = array('mp2'); - $AcceptableExtensionsAudio['mp1']['mp1'] = array('mp1'); - $AcceptableExtensionsAudio['asf']['asf'] = array('asf'); - $AcceptableExtensionsAudio['asf']['wma'] = array('wma'); - $AcceptableExtensionsAudio['riff']['mp3'] = array('wav'); - $AcceptableExtensionsAudio['riff']['wav'] = array('wav'); - } - static $AcceptableExtensionsVideo = array(); - if (empty($AcceptableExtensionsVideo)) { - $AcceptableExtensionsVideo['mp3']['mp3'] = array('mp3'); - $AcceptableExtensionsVideo['mp2']['mp2'] = array('mp2'); - $AcceptableExtensionsVideo['mp1']['mp1'] = array('mp1'); - $AcceptableExtensionsVideo['asf']['asf'] = array('asf'); - $AcceptableExtensionsVideo['asf']['wmv'] = array('wmv'); - $AcceptableExtensionsVideo['gif']['gif'] = array('gif'); - $AcceptableExtensionsVideo['jpg']['jpg'] = array('jpg'); - $AcceptableExtensionsVideo['png']['png'] = array('png'); - $AcceptableExtensionsVideo['bmp']['bmp'] = array('bmp'); - } - if (!empty($video_dataformat)) { - return (isset($AcceptableExtensionsVideo[$fileformat][$video_dataformat]) ? $AcceptableExtensionsVideo[$fileformat][$video_dataformat] : array()); - } else { - return (isset($AcceptableExtensionsAudio[$fileformat][$audio_dataformat]) ? $AcceptableExtensionsAudio[$fileformat][$audio_dataformat] : array()); - } +function AcceptableExtensions($fileformat, $audio_dataformat = '', $video_dataformat = '') +{ + static $AcceptableExtensionsAudio = []; + if (empty($AcceptableExtensionsAudio)) { + $AcceptableExtensionsAudio['mp3']['mp3'] = ['mp3']; + $AcceptableExtensionsAudio['mp2']['mp2'] = ['mp2']; + $AcceptableExtensionsAudio['mp1']['mp1'] = ['mp1']; + $AcceptableExtensionsAudio['asf']['asf'] = ['asf']; + $AcceptableExtensionsAudio['asf']['wma'] = ['wma']; + $AcceptableExtensionsAudio['riff']['mp3'] = ['wav']; + $AcceptableExtensionsAudio['riff']['wav'] = ['wav']; + } + static $AcceptableExtensionsVideo = []; + if (empty($AcceptableExtensionsVideo)) { + $AcceptableExtensionsVideo['mp3']['mp3'] = ['mp3']; + $AcceptableExtensionsVideo['mp2']['mp2'] = ['mp2']; + $AcceptableExtensionsVideo['mp1']['mp1'] = ['mp1']; + $AcceptableExtensionsVideo['asf']['asf'] = ['asf']; + $AcceptableExtensionsVideo['asf']['wmv'] = ['wmv']; + $AcceptableExtensionsVideo['gif']['gif'] = ['gif']; + $AcceptableExtensionsVideo['jpg']['jpg'] = ['jpg']; + $AcceptableExtensionsVideo['png']['png'] = ['png']; + $AcceptableExtensionsVideo['bmp']['bmp'] = ['bmp']; + } + if (! empty($video_dataformat)) { + return isset($AcceptableExtensionsVideo[$fileformat][$video_dataformat]) ? $AcceptableExtensionsVideo[$fileformat][$video_dataformat] : []; + } else { + return isset($AcceptableExtensionsAudio[$fileformat][$audio_dataformat]) ? $AcceptableExtensionsAudio[$fileformat][$audio_dataformat] : []; + } } - -if (!empty($_REQUEST['scan'])) { - if (mysql_table_exists(GETID3_DB_TABLE)) { - $SQLquery = 'DROP TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - mysql_query_safe($SQLquery); - } +if (! empty($_REQUEST['scan'])) { + if (mysql_table_exists(GETID3_DB_TABLE)) { + $SQLquery = 'DROP TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + mysql_query_safe($SQLquery); + } } -if (!mysql_table_exists(GETID3_DB_TABLE)) { - $SQLquery = "CREATE TABLE `".mysql_real_escape_string(GETID3_DB_TABLE)."` ("; - $SQLquery .= " `ID` int(11) unsigned NOT NULL auto_increment,"; - $SQLquery .= " `filename` text NOT NULL,"; - $SQLquery .= " `last_modified` int(11) NOT NULL default '0',"; - $SQLquery .= " `md5_file` varchar(32) NOT NULL default '',"; - $SQLquery .= " `md5_data` varchar(32) NOT NULL default '',"; - $SQLquery .= " `md5_data_source` varchar(32) NOT NULL default '',"; - $SQLquery .= " `filesize` int(10) unsigned NOT NULL default '0',"; - $SQLquery .= " `fileformat` varchar(255) NOT NULL default '',"; - $SQLquery .= " `audio_dataformat` varchar(255) NOT NULL default '',"; - $SQLquery .= " `video_dataformat` varchar(255) NOT NULL default '',"; - $SQLquery .= " `audio_bitrate` float NOT NULL default '0',"; - $SQLquery .= " `video_bitrate` float NOT NULL default '0',"; - $SQLquery .= " `playtime_seconds` varchar(255) NOT NULL default '',"; - $SQLquery .= " `tags` varchar(255) NOT NULL default '',"; - $SQLquery .= " `artist` varchar(255) NOT NULL default '',"; - $SQLquery .= " `title` varchar(255) NOT NULL default '',"; - $SQLquery .= " `remix` varchar(255) NOT NULL default '',"; - $SQLquery .= " `album` varchar(255) NOT NULL default '',"; - $SQLquery .= " `genre` varchar(255) NOT NULL default '',"; - $SQLquery .= " `comment` text NOT NULL,"; - $SQLquery .= " `track` varchar(7) NOT NULL default '',"; - $SQLquery .= " `comments_all` longtext NOT NULL,"; - $SQLquery .= " `comments_id3v2` longtext NOT NULL,"; - $SQLquery .= " `comments_ape` longtext NOT NULL,"; - $SQLquery .= " `comments_lyrics3` longtext NOT NULL,"; - $SQLquery .= " `comments_id3v1` text NOT NULL,"; - $SQLquery .= " `warning` longtext NOT NULL,"; - $SQLquery .= " `error` longtext NOT NULL,"; - $SQLquery .= " `track_volume` float NOT NULL default '0',"; - $SQLquery .= " `encoder_options` varchar(255) NOT NULL default '',"; - $SQLquery .= " `vbr_method` varchar(255) NOT NULL default '',"; - $SQLquery .= " PRIMARY KEY (`ID`)"; - $SQLquery .= ")"; - mysql_query_safe($SQLquery); +if (! mysql_table_exists(GETID3_DB_TABLE)) { + $SQLquery = 'CREATE TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ('; + $SQLquery .= ' `ID` int(11) unsigned NOT NULL auto_increment,'; + $SQLquery .= ' `filename` text NOT NULL,'; + $SQLquery .= " `last_modified` int(11) NOT NULL default '0',"; + $SQLquery .= " `md5_file` varchar(32) NOT NULL default '',"; + $SQLquery .= " `md5_data` varchar(32) NOT NULL default '',"; + $SQLquery .= " `md5_data_source` varchar(32) NOT NULL default '',"; + $SQLquery .= " `filesize` int(10) unsigned NOT NULL default '0',"; + $SQLquery .= " `fileformat` varchar(255) NOT NULL default '',"; + $SQLquery .= " `audio_dataformat` varchar(255) NOT NULL default '',"; + $SQLquery .= " `video_dataformat` varchar(255) NOT NULL default '',"; + $SQLquery .= " `audio_bitrate` float NOT NULL default '0',"; + $SQLquery .= " `video_bitrate` float NOT NULL default '0',"; + $SQLquery .= " `playtime_seconds` varchar(255) NOT NULL default '',"; + $SQLquery .= " `tags` varchar(255) NOT NULL default '',"; + $SQLquery .= " `artist` varchar(255) NOT NULL default '',"; + $SQLquery .= " `title` varchar(255) NOT NULL default '',"; + $SQLquery .= " `remix` varchar(255) NOT NULL default '',"; + $SQLquery .= " `album` varchar(255) NOT NULL default '',"; + $SQLquery .= " `genre` varchar(255) NOT NULL default '',"; + $SQLquery .= ' `comment` text NOT NULL,'; + $SQLquery .= " `track` varchar(7) NOT NULL default '',"; + $SQLquery .= ' `comments_all` longtext NOT NULL,'; + $SQLquery .= ' `comments_id3v2` longtext NOT NULL,'; + $SQLquery .= ' `comments_ape` longtext NOT NULL,'; + $SQLquery .= ' `comments_lyrics3` longtext NOT NULL,'; + $SQLquery .= ' `comments_id3v1` text NOT NULL,'; + $SQLquery .= ' `warning` longtext NOT NULL,'; + $SQLquery .= ' `error` longtext NOT NULL,'; + $SQLquery .= " `track_volume` float NOT NULL default '0',"; + $SQLquery .= " `encoder_options` varchar(255) NOT NULL default '',"; + $SQLquery .= " `vbr_method` varchar(255) NOT NULL default '',"; + $SQLquery .= ' PRIMARY KEY (`ID`)'; + $SQLquery .= ')'; + mysql_query_safe($SQLquery); } -$ExistingTableFields = array(); +$ExistingTableFields = []; $result = mysql_query_safe('DESCRIBE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'); while ($row = mysql_fetch_array($result)) { - $ExistingTableFields[$row['Field']] = $row; + $ExistingTableFields[$row['Field']] = $row; } -if (!isset($ExistingTableFields['encoder_options'])) { // Added in 1.7.0b2 - echo 'adding field `encoder_options`
'; - mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ADD `encoder_options` VARCHAR(255) default "" NOT NULL AFTER `error`'); - mysql_query_safe('OPTIMIZE TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'); +if (! isset($ExistingTableFields['encoder_options'])) { // Added in 1.7.0b2 + echo 'adding field `encoder_options`
'; + mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ADD `encoder_options` VARCHAR(255) default "" NOT NULL AFTER `error`'); + mysql_query_safe('OPTIMIZE TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'); } if (isset($ExistingTableFields['track']) && ($ExistingTableFields['track']['Type'] != 'varchar(7)')) { // Changed in 1.7.0b2 - echo 'changing field `track` to VARCHAR(7)
'; - mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `track` `track` VARCHAR(7) default "" NOT NULL'); - mysql_query_safe('OPTIMIZE TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'); + echo 'changing field `track` to VARCHAR(7)
'; + mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `track` `track` VARCHAR(7) default "" NOT NULL'); + mysql_query_safe('OPTIMIZE TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'); } -if (!isset($ExistingTableFields['track_volume'])) { // Added in 1.7.0b5 - echo '

WARNING! You should erase your database and rescan everything because the comment storing has been changed since the last version


'; - echo 'adding field `track_volume`
'; - mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ADD `track_volume` FLOAT NOT NULL AFTER `error`'); - mysql_query_safe('OPTIMIZE TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'); +if (! isset($ExistingTableFields['track_volume'])) { // Added in 1.7.0b5 + echo '

WARNING! You should erase your database and rescan everything because the comment storing has been changed since the last version


'; + echo 'adding field `track_volume`
'; + mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ADD `track_volume` FLOAT NOT NULL AFTER `error`'); + mysql_query_safe('OPTIMIZE TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'); } -if (!isset($ExistingTableFields['remix'])) { // Added in 1.7.3b1 - echo 'adding field `encoder_options`, `alternate_name`, `parody`
'; - mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ADD `remix` VARCHAR(255) default "" NOT NULL AFTER `title`'); - mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ADD `alternate_name` VARCHAR(255) default "" NOT NULL AFTER `track`'); - mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ADD `parody` VARCHAR(255) default "" NOT NULL AFTER `alternate_name`'); - mysql_query_safe('OPTIMIZE TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'); +if (! isset($ExistingTableFields['remix'])) { // Added in 1.7.3b1 + echo 'adding field `encoder_options`, `alternate_name`, `parody`
'; + mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ADD `remix` VARCHAR(255) default "" NOT NULL AFTER `title`'); + mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ADD `alternate_name` VARCHAR(255) default "" NOT NULL AFTER `track`'); + mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ADD `parody` VARCHAR(255) default "" NOT NULL AFTER `alternate_name`'); + mysql_query_safe('OPTIMIZE TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'); } if (isset($ExistingTableFields['comments_all']) && ($ExistingTableFields['comments_all']['Type'] != 'longtext')) { // Changed in 1.9.0 - echo 'changing comments fields from text to longtext
'; - // no need to change id3v1 - mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `comments_all` `comments_all` LONGTEXT NOT NULL'); - mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `comments_id3v2` `comments_id3v2` LONGTEXT NOT NULL'); - mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `comments_ape` `comments_ape` LONGTEXT NOT NULL'); - mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `comments_lyrics3` `comments_lyrics3` LONGTEXT NOT NULL'); - mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `warning` `warning` LONGTEXT NOT NULL'); - mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `error` `error` LONGTEXT NOT NULL'); + echo 'changing comments fields from text to longtext
'; + // no need to change id3v1 + mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `comments_all` `comments_all` LONGTEXT NOT NULL'); + mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `comments_id3v2` `comments_id3v2` LONGTEXT NOT NULL'); + mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `comments_ape` `comments_ape` LONGTEXT NOT NULL'); + mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `comments_lyrics3` `comments_lyrics3` LONGTEXT NOT NULL'); + mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `warning` `warning` LONGTEXT NOT NULL'); + mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `error` `error` LONGTEXT NOT NULL'); } +function SynchronizeAllTags($filename, $synchronizefrom, $synchronizeto, &$errors) +{ + global $getID3; -function SynchronizeAllTags($filename, $synchronizefrom='all', $synchronizeto='A12', &$errors) { - global $getID3; + set_time_limit(30); - set_time_limit(30); + $ThisFileInfo = $getID3->analyze($filename); + getid3_lib::CopyTagsToComments($ThisFileInfo); - $ThisFileInfo = $getID3->analyze($filename); - getid3_lib::CopyTagsToComments($ThisFileInfo); + if ($synchronizefrom == 'all') { + $SourceArray = (! empty($ThisFileInfo['comments']) ? $ThisFileInfo['comments'] : []); + } elseif (! empty($ThisFileInfo['tags'][$synchronizefrom])) { + $SourceArray = (! empty($ThisFileInfo['tags'][$synchronizefrom]) ? $ThisFileInfo['tags'][$synchronizefrom] : []); + } else { + die('ERROR: $ThisFileInfo[tags]['.$synchronizefrom.'] does not exist'); + } - if ($synchronizefrom == 'all') { - $SourceArray = (!empty($ThisFileInfo['comments']) ? $ThisFileInfo['comments'] : array()); - } elseif (!empty($ThisFileInfo['tags'][$synchronizefrom])) { - $SourceArray = (!empty($ThisFileInfo['tags'][$synchronizefrom]) ? $ThisFileInfo['tags'][$synchronizefrom] : array()); - } else { - die('ERROR: $ThisFileInfo[tags]['.$synchronizefrom.'] does not exist'); - } + $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($filename).'")'; + mysql_query_safe($SQLquery); - $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($filename).'")'; - mysql_query_safe($SQLquery); + $TagFormatsToWrite = []; + if ((strpos($synchronizeto, '2') !== false) && ($synchronizefrom != 'id3v2')) { + $TagFormatsToWrite[] = 'id3v2.3'; + } + if ((strpos($synchronizeto, 'A') !== false) && ($synchronizefrom != 'ape')) { + $TagFormatsToWrite[] = 'ape'; + } + if ((strpos($synchronizeto, 'L') !== false) && ($synchronizefrom != 'lyrics3')) { + $TagFormatsToWrite[] = 'lyrics3'; + } + if ((strpos($synchronizeto, '1') !== false) && ($synchronizefrom != 'id3v1')) { + $TagFormatsToWrite[] = 'id3v1'; + } + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.php', __FILE__, true); + $tagwriter = new getid3_writetags; + $tagwriter->filename = $filename; + $tagwriter->tagformats = $TagFormatsToWrite; + $tagwriter->overwrite_tags = true; + $tagwriter->tag_encoding = $getID3->encoding; + $tagwriter->tag_data = $SourceArray; - $TagFormatsToWrite = array(); - if ((strpos($synchronizeto, '2') !== false) && ($synchronizefrom != 'id3v2')) { - $TagFormatsToWrite[] = 'id3v2.3'; - } - if ((strpos($synchronizeto, 'A') !== false) && ($synchronizefrom != 'ape')) { - $TagFormatsToWrite[] = 'ape'; - } - if ((strpos($synchronizeto, 'L') !== false) && ($synchronizefrom != 'lyrics3')) { - $TagFormatsToWrite[] = 'lyrics3'; - } - if ((strpos($synchronizeto, '1') !== false) && ($synchronizefrom != 'id3v1')) { - $TagFormatsToWrite[] = 'id3v1'; - } + if ($tagwriter->WriteTags()) { + $errors = $tagwriter->errors; - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.php', __FILE__, true); - $tagwriter = new getid3_writetags; - $tagwriter->filename = $filename; - $tagwriter->tagformats = $TagFormatsToWrite; - $tagwriter->overwrite_tags = true; - $tagwriter->tag_encoding = $getID3->encoding; - $tagwriter->tag_data = $SourceArray; + return true; + } + $errors = $tagwriter->errors; - if ($tagwriter->WriteTags()) { - $errors = $tagwriter->errors; - return true; - } - $errors = $tagwriter->errors; - return false; + return false; } -$IgnoreNoTagFormats = array('', 'png', 'jpg', 'gif', 'bmp', 'swf', 'pdf', 'zip', 'rar', 'mid', 'mod', 'xm', 'it', 's3m'); - -if (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan']) || !empty($_REQUEST['rescanerrors'])) { - - $SQLquery = 'DELETE from `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`fileformat` = "")'; - mysql_query_safe($SQLquery); - - $FilesInDir = array(); - - if (!empty($_REQUEST['rescanerrors'])) { - - echo 'abort
'; - - echo 'Re-scanning all media files already in database that had errors and/or warnings in last scan
'; - - $SQLquery = 'SELECT `filename`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`error` <> "")'; - $SQLquery .= ' OR (`warning` <> "")'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - while ($row = mysql_fetch_array($result)) { - - if (!file_exists($row['filename'])) { - echo 'File missing: '.$row['filename'].'
'; - $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($row['filename']).'")'; - mysql_query_safe($SQLquery); - } else { - $FilesInDir[] = $row['filename']; - } - - } - - } elseif (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan'])) { - - echo 'abort
'; - - echo 'Scanning all media files in '.str_replace('\\', '/', realpath(!empty($_REQUEST['scan']) ? $_REQUEST['scan'] : $_REQUEST['newscan'])).' (and subdirectories)
'; - - $SQLquery = 'SELECT COUNT(*) AS `num`, `filename`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' GROUP BY `filename`'; - $SQLquery .= ' HAVING (`num` > 1)'; - $SQLquery .= ' ORDER BY `num` DESC'; - $result = mysql_query_safe($SQLquery); - $DupesDeleted = 0; - while ($row = mysql_fetch_array($result)) { - set_time_limit(30); - $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE `filename` LIKE "'.mysql_real_escape_string($row['filename']).'"'; - mysql_query_safe($SQLquery); - $DupesDeleted++; - } - if ($DupesDeleted > 0) { - echo 'Deleted '.number_format($DupesDeleted).' duplicate filenames
'; - } - - if (!empty($_REQUEST['newscan'])) { - $AlreadyInDatabase = array(); - set_time_limit(60); - $SQLquery = 'SELECT `filename`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - while ($row = mysql_fetch_array($result)) { - //$AlreadyInDatabase[] = strtolower($row['filename']); - $AlreadyInDatabase[] = $row['filename']; - } - } - - $DirectoriesToScan = array(!empty($_REQUEST['scan']) ? $_REQUEST['scan'] : $_REQUEST['newscan']); - $DirectoriesScanned = array(); - while (count($DirectoriesToScan) > 0) { - foreach ($DirectoriesToScan as $DirectoryKey => $startingdir) { - if ($dir = opendir($startingdir)) { - set_time_limit(30); - echo ''.str_replace('\\', '/', $startingdir).'
'; - flush(); - while (($file = readdir($dir)) !== false) { - if (($file != '.') && ($file != '..')) { - $RealPathName = realpath($startingdir.'/'.$file); - if (is_dir($RealPathName)) { - if (!in_array($RealPathName, $DirectoriesScanned) && !in_array($RealPathName, $DirectoriesToScan)) { - $DirectoriesToScan[] = $RealPathName; - } - } elseif (is_file($RealPathName)) { - if (!empty($_REQUEST['newscan'])) { - if (!in_array(str_replace('\\', '/', $RealPathName), $AlreadyInDatabase)) { - $FilesInDir[] = $RealPathName; - } - } elseif (!empty($_REQUEST['scan'])) { - $FilesInDir[] = $RealPathName; - } - } - } - } - closedir($dir); - } else { - echo '
Failed to open directory "'.htmlentities($startingdir).'"

'; - } - $DirectoriesScanned[] = $startingdir; - unset($DirectoriesToScan[$DirectoryKey]); - } - } - echo 'List of files to scan complete (added '.number_format(count($FilesInDir)).' files to scan)
'; - flush(); - } - - $FilesInDir = array_unique($FilesInDir); - sort($FilesInDir); - - $starttime = time(); - $rowcounter = 0; - $totaltoprocess = count($FilesInDir); - - foreach ($FilesInDir as $filename) { - set_time_limit(300); - - echo '
'.date('H:i:s').' ['.number_format(++$rowcounter).' / '.number_format($totaltoprocess).'] '.str_replace('\\', '/', $filename); - - $ThisFileInfo = $getID3->analyze($filename); - getid3_lib::CopyTagsToComments($ThisFileInfo); - - if (file_exists($filename)) { - $ThisFileInfo['file_modified_time'] = filemtime($filename); - $ThisFileInfo['md5_file'] = ($getid3_demo_mysql_md5_file ? md5_file($filename) : ''); - } - - if (empty($ThisFileInfo['fileformat'])) { - - echo ' (unknown file type)'; - - } else { - - if (!empty($ThisFileInfo['error'])) { - echo ' (errors)'; - } elseif (!empty($ThisFileInfo['warning'])) { - echo ' (warnings)'; - } else { - echo ' (OK)'; - } - - $this_track_track = ''; - if (!empty($ThisFileInfo['comments']['track'])) { - foreach ($ThisFileInfo['comments']['track'] as $key => $value) { - if (strlen($value) > strlen($this_track_track)) { - $this_track_track = str_pad($value, 2, '0', STR_PAD_LEFT); - } - } - if (preg_match('#^([0-9]+)/([0-9]+)$#', $this_track_track, $matches)) { - // change "1/5"->"01/05", "3/12"->"03/12", etc - $this_track_track = str_pad($matches[1], 2, '0', STR_PAD_LEFT).'/'.str_pad($matches[2], 2, '0', STR_PAD_LEFT); - } - } - - $this_track_remix = ''; - $this_track_title = ''; - if (!empty($ThisFileInfo['comments']['title'])) { - foreach ($ThisFileInfo['comments']['title'] as $possible_title) { - if (strlen($possible_title) > strlen($this_track_title)) { - $this_track_title = $possible_title; - } - } - } - - $ParenthesesPairs = array('()', '[]', '{}'); - foreach ($ParenthesesPairs as $pair) { - if (preg_match_all('/(.*) '.preg_quote($pair{0}).'(([^'.preg_quote($pair).']*[\- '.preg_quote($pair{0}).'])?(cut|dub|edit|version|live|reprise|[a-z]*mix))'.preg_quote($pair{1}).'/iU', $this_track_title, $matches)) { - $this_track_title = $matches[1][0]; - $this_track_remix = implode("\t", $matches[2]); - } - } - - - - if (!empty($_REQUEST['rescanerrors'])) { - - $SQLquery = 'UPDATE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` SET '; - $SQLquery .= ' `last_modified` = "'. mysql_real_escape_string(!empty($ThisFileInfo['file_modified_time'] ) ? $ThisFileInfo['file_modified_time'] : '').'"'; - $SQLquery .= ', `md5_file` = "'. mysql_real_escape_string(!empty($ThisFileInfo['md5_file'] ) ? $ThisFileInfo['md5_file'] : '').'"'; - $SQLquery .= ', `md5_data` = "'. mysql_real_escape_string(!empty($ThisFileInfo['md5_data'] ) ? $ThisFileInfo['md5_data'] : '').'"'; - $SQLquery .= ', `md5_data_source` = "'. mysql_real_escape_string(!empty($ThisFileInfo['md5_data_source'] ) ? $ThisFileInfo['md5_data_source'] : '').'"'; - $SQLquery .= ', `filesize` = "'. mysql_real_escape_string(!empty($ThisFileInfo['filesize'] ) ? $ThisFileInfo['filesize'] : 0).'"'; - $SQLquery .= ', `fileformat` = "'. mysql_real_escape_string(!empty($ThisFileInfo['fileformat'] ) ? $ThisFileInfo['fileformat'] : '').'"'; - $SQLquery .= ', `audio_dataformat` = "'.mysql_real_escape_string(!empty($ThisFileInfo['audio']['dataformat'] ) ? $ThisFileInfo['audio']['dataformat'] : '').'"'; - $SQLquery .= ', `video_dataformat` = "'.mysql_real_escape_string(!empty($ThisFileInfo['video']['dataformat'] ) ? $ThisFileInfo['video']['dataformat'] : '').'"'; - $SQLquery .= ', `vbr_method` = "'. mysql_real_escape_string(!empty($ThisFileInfo['mpeg']['audio']['VBR_method'] ) ? $ThisFileInfo['mpeg']['audio']['VBR_method'] : '').'"'; - $SQLquery .= ', `audio_bitrate` = "'. mysql_real_escape_string(!empty($ThisFileInfo['audio']['bitrate'] ) ? floatval($ThisFileInfo['audio']['bitrate']) : 0).'"'; - $SQLquery .= ', `video_bitrate` = "'. mysql_real_escape_string(!empty($ThisFileInfo['video']['bitrate'] ) ? floatval($ThisFileInfo['video']['bitrate']) : 0).'"'; - $SQLquery .= ', `playtime_seconds` = "'.mysql_real_escape_string(!empty($ThisFileInfo['playtime_seconds'] ) ? floatval($ThisFileInfo['playtime_seconds']) : 0).'"'; - $SQLquery .= ', `track_volume` = "'. mysql_real_escape_string(!empty($ThisFileInfo['replay_gain']['track']['volume']) ? floatval($ThisFileInfo['replay_gain']['track']['volume']) : 0).'"'; - $SQLquery .= ', `comments_all` = "'. mysql_real_escape_string(!empty($ThisFileInfo['comments'] ) ? serialize($ThisFileInfo['comments']) : '').'"'; - $SQLquery .= ', `comments_id3v2` = "'. mysql_real_escape_string(!empty($ThisFileInfo['tags']['id3v2'] ) ? serialize($ThisFileInfo['tags']['id3v2']) : '').'"'; - $SQLquery .= ', `comments_ape` = "'. mysql_real_escape_string(!empty($ThisFileInfo['tags']['ape'] ) ? serialize($ThisFileInfo['tags']['ape']) : '').'"'; - $SQLquery .= ', `comments_lyrics3` = "'.mysql_real_escape_string(!empty($ThisFileInfo['tags']['lyrics3'] ) ? serialize($ThisFileInfo['tags']['lyrics3']) : '').'"'; - $SQLquery .= ', `comments_id3v1` = "'. mysql_real_escape_string(!empty($ThisFileInfo['tags']['id3v1'] ) ? serialize($ThisFileInfo['tags']['id3v1']) : '').'"'; - $SQLquery .= ', `warning` = "'. mysql_real_escape_string(!empty($ThisFileInfo['warning'] ) ? implode("\t", $ThisFileInfo['warning']) : '').'"'; - $SQLquery .= ', `error` = "'. mysql_real_escape_string(!empty($ThisFileInfo['error'] ) ? implode("\t", $ThisFileInfo['error']) : '').'"'; - $SQLquery .= ', `album` = "'. mysql_real_escape_string(!empty($ThisFileInfo['comments']['album'] ) ? implode("\t", $ThisFileInfo['comments']['album']) : '').'"'; - $SQLquery .= ', `genre` = "'. mysql_real_escape_string(!empty($ThisFileInfo['comments']['genre'] ) ? implode("\t", $ThisFileInfo['comments']['genre']) : '').'"'; - $SQLquery .= ', `comment` = "'. mysql_real_escape_string(!empty($ThisFileInfo['comments']['comment'] ) ? implode("\t", $ThisFileInfo['comments']['comment']) : '').'"'; - $SQLquery .= ', `artist` = "'. mysql_real_escape_string(!empty($ThisFileInfo['comments']['artist'] ) ? implode("\t", $ThisFileInfo['comments']['artist']) : '').'"'; - $SQLquery .= ', `tags` = "'. mysql_real_escape_string(!empty($ThisFileInfo['tags'] ) ? implode("\t", array_keys($ThisFileInfo['tags'])) : '').'"'; - $SQLquery .= ', `encoder_options` = "'. mysql_real_escape_string(trim((!empty($ThisFileInfo['audio']['encoder']) ? $ThisFileInfo['audio']['encoder'] : '').' '.(!empty($ThisFileInfo['audio']['encoder_options']) ? $ThisFileInfo['audio']['encoder_options'] : ''))).'"'; - $SQLquery .= ', `title` = "'. mysql_real_escape_string($this_track_title).'"'; - $SQLquery .= ', `remix` = "'. mysql_real_escape_string($this_track_remix).'"'; - $SQLquery .= ', `track` = "'. mysql_real_escape_string($this_track_track).'"'; - $SQLquery .= 'WHERE (`filename` = "'. mysql_real_escape_string(isset($ThisFileInfo['filenamepath']) ? $ThisFileInfo['filenamepath'] : '').'")'; - - } elseif (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan'])) { - - //$SQLquery = 'INSERT INTO `'.mysql_real_escape_string(GETID3_DB_TABLE).'` (`filename`, `last_modified`, `md5_file`, `md5_data`, `md5_data_source`, `filesize`, `fileformat`, `audio_dataformat`, `video_dataformat`, `audio_bitrate`, `video_bitrate`, `playtime_seconds`, `artist`, `title`, `remix`, `album`, `genre`, `comment`, `track`, `comments_all`, `comments_id3v2`, `comments_ape`, `comments_lyrics3`, `comments_id3v1`, `warning`, `error`, `encoder_options`, `vbr_method`, `track_volume`) VALUES ('; - $SQLquery = 'INSERT INTO `'.mysql_real_escape_string(GETID3_DB_TABLE).'` (`filename`, `last_modified`, `md5_file`, `md5_data`, `md5_data_source`, `filesize`, `fileformat`, `audio_dataformat`, `video_dataformat`, `audio_bitrate`, `video_bitrate`, `playtime_seconds`, `tags`, `artist`, `title`, `remix`, `album`, `genre`, `comment`, `track`, `comments_all`, `comments_id3v2`, `comments_ape`, `comments_lyrics3`, `comments_id3v1`, `warning`, `error`, `encoder_options`, `vbr_method`, `track_volume`) VALUES ('; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['filenamepath'] ) ? $ThisFileInfo['filenamepath'] : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['file_modified_time'] ) ? $ThisFileInfo['file_modified_time'] : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['md5_file'] ) ? $ThisFileInfo['md5_file'] : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['md5_data'] ) ? $ThisFileInfo['md5_data'] : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['md5_data_source'] ) ? $ThisFileInfo['md5_data_source'] : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['filesize'] ) ? $ThisFileInfo['filesize'] : 0).'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['fileformat'] ) ? $ThisFileInfo['fileformat'] : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['audio']['dataformat'] ) ? $ThisFileInfo['audio']['dataformat'] : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['video']['dataformat'] ) ? $ThisFileInfo['video']['dataformat'] : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['audio']['bitrate'] ) ? floatval($ThisFileInfo['audio']['bitrate']) : 0).'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['video']['bitrate'] ) ? floatval($ThisFileInfo['video']['bitrate']) : 0).'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['playtime_seconds'] ) ? floatval($ThisFileInfo['playtime_seconds']) : 0).'", '; - //$SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['tags'] ) ? implode("\t", $ThisFileInfo['tags']) : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['tags'] ) ? implode("\t", array_keys($ThisFileInfo['tags'])) : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['comments']['artist'] ) ? implode("\t", $ThisFileInfo['comments']['artist']) : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string($this_track_title).'", '; - $SQLquery .= '"'.mysql_real_escape_string($this_track_remix).'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['comments']['album'] ) ? implode("\t", $ThisFileInfo['comments']['album']) : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['comments']['genre'] ) ? implode("\t", $ThisFileInfo['comments']['genre']) : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['comments']['comment'] ) ? implode("\t", $ThisFileInfo['comments']['comment']) : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string($this_track_track).'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['comments'] ) ? serialize($ThisFileInfo['comments']) : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['tags']['id3v2'] ) ? serialize($ThisFileInfo['tags']['id3v2']) : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['tags']['ape'] ) ? serialize($ThisFileInfo['tags']['ape']) : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['tags']['lyrics3'] ) ? serialize($ThisFileInfo['tags']['lyrics3']) : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['tags']['id3v1'] ) ? serialize($ThisFileInfo['tags']['id3v1']) : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['warning'] ) ? implode("\t", $ThisFileInfo['warning']) : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['error'] ) ? implode("\t", $ThisFileInfo['error']) : '').'", '; - $SQLquery .= '"'.mysql_real_escape_string(trim((!empty($ThisFileInfo['audio']['encoder']) ? $ThisFileInfo['audio']['encoder'] : '').' '.(!empty($ThisFileInfo['audio']['encoder_options']) ? $ThisFileInfo['audio']['encoder_options'] : ''))).'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['mpeg']['audio']['LAME']) ? 'LAME' : (!empty($ThisFileInfo['mpeg']['audio']['VBR_method']) ? $ThisFileInfo['mpeg']['audio']['VBR_method'] : '')).'", '; - $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['replay_gain']['track']['volume']) ? floatval($ThisFileInfo['replay_gain']['track']['volume']) : 0).'")'; - - } - flush(); - mysql_query_safe($SQLquery); - } - - } - - $SQLquery = 'OPTIMIZE TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - mysql_query_safe($SQLquery); - - echo '
Done scanning!
'; - -} elseif (!empty($_REQUEST['missingtrackvolume'])) { - - $MissingTrackVolumeFilesScanned = 0; - $MissingTrackVolumeFilesAdjusted = 0; - $MissingTrackVolumeFilesDeleted = 0; - $SQLquery = 'SELECT `filename`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`track_volume` = 0)'; - $SQLquery .= ' AND (`audio_bitrate` > 0)'; - $result = mysql_query_safe($SQLquery); - echo 'Scanning 0 / '.number_format(mysql_num_rows($result)).' files for track volume information:
'; - while ($row = mysql_fetch_array($result)) { - set_time_limit(30); - echo '. '; - flush(); - if (file_exists($row['filename'])) { - - $ThisFileInfo = $getID3->analyze($row['filename']); - if (!empty($ThisFileInfo['replay_gain']['track']['volume'])) { - $MissingTrackVolumeFilesAdjusted++; - $SQLquery = 'UPDATE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' SET `track_volume` = "'.$ThisFileInfo['replay_gain']['track']['volume'].'"'; - $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($row['filename']).'")'; - mysql_query_safe($SQLquery); - } - - } else { - - $MissingTrackVolumeFilesDeleted++; - $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($row['filename']).'")'; - mysql_query_safe($SQLquery); - - } - } - echo '
Scanned '.number_format($MissingTrackVolumeFilesScanned).' files with no track volume information.
'; - echo 'Found track volume information for '.number_format($MissingTrackVolumeFilesAdjusted).' of them (could not find info for '.number_format($MissingTrackVolumeFilesScanned - $MissingTrackVolumeFilesAdjusted).' files; deleted '.number_format($MissingTrackVolumeFilesDeleted).' records of missing files)
'; - -} elseif (!empty($_REQUEST['deadfilescheck'])) { - - $SQLquery = 'SELECT COUNT(*) AS `num`, `filename`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' GROUP BY `filename`'; - $SQLquery .= ' ORDER BY `num` DESC'; - $result = mysql_query_safe($SQLquery); - $DupesDeleted = 0; - while ($row = mysql_fetch_array($result)) { - set_time_limit(30); - if ($row['num'] <= 1) { - break; - } - echo '
'.htmlentities($row['filename']).' (duplicate)'; - $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE `filename` LIKE "'.mysql_real_escape_string($row['filename']).'"'; - mysql_query_safe($SQLquery); - $DupesDeleted++; - } - if ($DupesDeleted > 0) { - echo '
Deleted '.number_format($DupesDeleted).' duplicate filenames
'; - } - - $SQLquery = 'SELECT `filename`, `filesize`, `last_modified`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - $totalchecked = 0; - $totalremoved = 0; - $previousdir = ''; - while ($row = mysql_fetch_array($result)) { - $totalchecked++; - set_time_limit(30); - $reason = ''; - if (!file_exists($row['filename'])) { - $reason = 'deleted'; - } elseif (filesize($row['filename']) != $row['filesize']) { - $reason = 'filesize changed'; - } elseif (filemtime($row['filename']) != $row['last_modified']) { - if (abs(filemtime($row['filename']) - $row['last_modified']) != 3600) { - // off by exactly one hour == daylight savings time - $reason = 'last-modified time changed'; - } - } - - $thisdir = dirname($row['filename']); - if ($reason) { - - $totalremoved++; - echo '
'.htmlentities($row['filename']).' ('.$reason.')'; - flush(); - $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($row['filename']).'")'; - mysql_query_safe($SQLquery); - - } elseif ($thisdir != $previousdir) { - - echo '. '; - flush(); - - } - $previousdir = $thisdir; - } - - echo '
'.number_format($totalremoved).' of '.number_format($totalchecked).' files in database no longer exist, or have been altered since last scan. Removed from database.
'; - -} elseif (!empty($_REQUEST['encodedbydistribution'])) { - - if (!empty($_REQUEST['m3u'])) { - - header('Content-type: audio/x-mpegurl'); - echo '#EXTM3U'."\n"; - - $SQLquery = 'SELECT `filename`, `comments_id3v2`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`encoder_options` = "'.mysql_real_escape_string($_REQUEST['encodedbydistribution']).'")'; - $result = mysql_query_safe($SQLquery); - $NonBlankEncodedBy = ''; - $BlankEncodedBy = ''; - while ($row = mysql_fetch_array($result)) { - set_time_limit(30); - $CommentArray = unserialize($row['comments_id3v2']); - if (isset($CommentArray['encoded_by'][0])) { - $NonBlankEncodedBy .= WindowsShareSlashTranslate($row['filename'])."\n"; - } else { - $BlankEncodedBy .= WindowsShareSlashTranslate($row['filename'])."\n"; - } - } - echo $NonBlankEncodedBy; - echo $BlankEncodedBy; - exit; - - } elseif (!empty($_REQUEST['showfiles'])) { - - echo 'show all
'; - echo ''; - - $SQLquery = 'SELECT `filename`, `comments_id3v2`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $result = mysql_query_safe($SQLquery); - while ($row = mysql_fetch_array($result)) { - set_time_limit(30); - $CommentArray = unserialize($row['comments_id3v2']); - if (($_REQUEST['encodedbydistribution'] == '%') || (!empty($CommentArray['encoded_by'][0]) && ($_REQUEST['encodedbydistribution'] == $CommentArray['encoded_by'][0]))) { - echo ''; - echo ''; - } - } - echo '
m3u'.htmlentities($row['filename']).'
'; - - } else { - - $SQLquery = 'SELECT `encoder_options`, `comments_id3v2`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' ORDER BY (`encoder_options` LIKE "LAME%") DESC, (`encoder_options` LIKE "CBR%") DESC'; - $result = mysql_query_safe($SQLquery); - $EncodedBy = array(); - while ($row = mysql_fetch_array($result)) { - set_time_limit(30); - $CommentArray = unserialize($row['comments_id3v2']); - if (isset($CommentArray['encoded_by'][0])) { - if (isset($EncodedBy[$row['encoder_options']][$CommentArray['encoded_by'][0]])) { - $EncodedBy[$row['encoder_options']][$CommentArray['encoded_by'][0]]++; - } else { - $EncodedBy[$row['encoder_options']][$CommentArray['encoded_by'][0]] = 1; - } - } - } - echo '.m3u version
'; - echo ''; - foreach ($EncodedBy as $key => $value) { - echo ''; - echo ''; - echo ''; - } - echo '
m3uEncoder OptionsEncoded By (ID3v2)
m3u'.$key.''; - arsort($value); - foreach ($value as $string => $count) { - echo ''; - echo ''; - } - echo '
'.number_format($count).' '.$string.'
'; - - } - -} elseif (!empty($_REQUEST['audiobitrates'])) { - - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); - $BitrateDistribution = array(); - $SQLquery = 'SELECT ROUND(audio_bitrate / 1000) AS `RoundBitrate`, COUNT(*) AS `num`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`audio_bitrate` > 0)'; - $SQLquery .= ' GROUP BY `RoundBitrate`'; - $result = mysql_query_safe($SQLquery); - while ($row = mysql_fetch_array($result)) { - $this_bitrate = getid3_mp3::ClosestStandardMP3Bitrate($row['RoundBitrate'] * 1000); - if (isset($BitrateDistribution[$this_bitrate])) { - $BitrateDistribution[$this_bitrate] += $row['num']; - } else { - $BitrateDistribution[$this_bitrate] = $row['num']; - } - } - - echo ''; - echo ''; - foreach ($BitrateDistribution as $Bitrate => $Count) { - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
BitrateCount
'.round($Bitrate / 1000).' kbps'.number_format($Count).'
'; - - -} elseif (!empty($_REQUEST['emptygenres'])) { - - $SQLquery = 'SELECT `fileformat`, `filename`, `genre`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`genre` = "")'; - $SQLquery .= ' OR (`genre` = "Unknown")'; - $SQLquery .= ' OR (`genre` = "Other")'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - - if (!empty($_REQUEST['m3u'])) { - - header('Content-type: audio/x-mpegurl'); - echo '#EXTM3U'."\n"; - while ($row = mysql_fetch_array($result)) { - if (!in_array($row['fileformat'], $IgnoreNoTagFormats)) { - echo WindowsShareSlashTranslate($row['filename'])."\n"; - } - } - exit; - - } else { - - echo '.m3u version
'; - $EmptyGenreCounter = 0; - echo ''; - echo ''; - while ($row = mysql_fetch_array($result)) { - if (!in_array($row['fileformat'], $IgnoreNoTagFormats)) { - $EmptyGenreCounter++; - echo ''; - echo ''; - echo ''; - echo ''; - } - } - echo '
m3ufilename
m3u'.htmlentities($row['filename']).'
'; - echo ''.number_format($EmptyGenreCounter).' files with empty genres'; - - } - -} elseif (!empty($_REQUEST['nonemptycomments'])) { - - $SQLquery = 'SELECT `filename`, `comment`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`comment` <> "")'; - $SQLquery .= ' ORDER BY `comment` ASC'; - $result = mysql_query_safe($SQLquery); - - if (!empty($_REQUEST['m3u'])) { - - header('Content-type: audio/x-mpegurl'); - echo '#EXTM3U'."\n"; - while ($row = mysql_fetch_array($result)) { - echo WindowsShareSlashTranslate($row['filename'])."\n"; - } - exit; - - } else { - - $NonEmptyCommentsCounter = 0; - echo '.m3u version
'; - echo ''; - echo ''; - while ($row = mysql_fetch_array($result)) { - $NonEmptyCommentsCounter++; - echo ''; - echo ''; - echo ''; - if (strlen(trim($row['comment'])) > 0) { - echo ''; - } else { - echo ''; - } - echo ''; - } - echo '
m3ufilenamecomments
m3u'.htmlentities($row['filename']).''.htmlentities($row['comment']).'space
'; - echo ''.number_format($NonEmptyCommentsCounter).' files with non-empty comments'; - - } - -} elseif (!empty($_REQUEST['trackzero'])) { - - $SQLquery = 'SELECT `filename`, `track`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`track` <> "")'; - $SQLquery .= ' AND ((`track` < "1")'; - $SQLquery .= ' OR (`track` > "99"))'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - - if (!empty($_REQUEST['m3u'])) { - - header('Content-type: audio/x-mpegurl'); - echo '#EXTM3U'."\n"; - while ($row = mysql_fetch_array($result)) { - if ((strlen($row['track']) > 0) && ($row['track'] < 1) || ($row['track'] > 99)) { - echo WindowsShareSlashTranslate($row['filename'])."\n"; - } - } - exit; - - } else { - - echo '.m3u version
'; - $TrackZeroCounter = 0; - echo ''; - echo ''; - while ($row = mysql_fetch_array($result)) { - if ((strlen($row['track']) > 0) && ($row['track'] < 1) || ($row['track'] > 99)) { - $TrackZeroCounter++; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - } - echo '
m3ufilenametrack
m3u'.htmlentities($row['filename']).''.htmlentities($row['track']).'
'; - echo ''.number_format($TrackZeroCounter).' files with track "zero"'; - - } - - -} elseif (!empty($_REQUEST['titlefeat'])) { - - $SQLquery = 'SELECT `filename`, `title`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`title` LIKE "%feat.%")'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - - if (!empty($_REQUEST['m3u'])) { - - header('Content-type: audio/x-mpegurl'); - echo '#EXTM3U'."\n"; - while ($row = mysql_fetch_array($result)) { - echo WindowsShareSlashTranslate($row['filename'])."\n"; - } - exit; - - } else { - - echo ''.number_format(mysql_num_rows($result)).' files with "feat." in the title (instead of the artist)

'; - echo '.m3u version
'; - echo ''; - echo ''; - while ($row = mysql_fetch_array($result)) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
m3ufilenametitle
m3u'.htmlentities($row['filename']).''.preg_replace('#(feat\. .*)#i', '\\1', htmlentities($row['title'])).'
'; - - } - - -} elseif (!empty($_REQUEST['tracknoalbum'])) { - - $SQLquery = 'SELECT `filename`, `track`, `album`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`track` <> "")'; - $SQLquery .= ' AND (`album` = "")'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - - if (!empty($_REQUEST['m3u'])) { - - header('Content-type: audio/x-mpegurl'); - echo '#EXTM3U'."\n"; - while ($row = mysql_fetch_array($result)) { - echo WindowsShareSlashTranslate($row['filename'])."\n"; - } - exit; - - } else { - - echo ''.number_format(mysql_num_rows($result)).' files with a track number, but no album

'; - echo '.m3u version
'; - echo ''; - echo ''; - while ($row = mysql_fetch_array($result)) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
m3ufilenametrackalbum
m3u'.htmlentities($row['filename']).''.htmlentities($row['track']).''.htmlentities($row['album']).'
'; - - } - - -} elseif (!empty($_REQUEST['synchronizetagsfrom']) && !empty($_REQUEST['filename'])) { - - echo 'Applying new tags from '.$_REQUEST['synchronizetagsfrom'].' in '.htmlentities($_REQUEST['filename']).'
    '; - $errors = array(); - if (SynchronizeAllTags($_REQUEST['filename'], $_REQUEST['synchronizetagsfrom'], 'A12', $errors)) { - echo '
  • Sucessfully wrote tags
  • '; - } else { - echo '
  • Tag writing had errors:
    • '.implode('
    • ', $errors).'
  • '; - } - echo '
'; - - -} elseif (!empty($_REQUEST['unsynchronizedtags'])) { - - $NotOKfiles = 0; - $Autofixedfiles = 0; - $FieldsToCompare = array('title', 'artist', 'album', 'year', 'genre', 'comment', 'track'); - $TagsToCompare = array('id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false); - $ID3v1FieldLengths = array('title'=>30, 'artist'=>30, 'album'=>30, 'year'=>4, 'genre'=>99, 'comment'=>28); - if (strpos($_REQUEST['unsynchronizedtags'], '2') !== false) { - $TagsToCompare['id3v2'] = true; - } - if (strpos($_REQUEST['unsynchronizedtags'], 'A') !== false) { - $TagsToCompare['ape'] = true; - } - if (strpos($_REQUEST['unsynchronizedtags'], 'L') !== false) { - $TagsToCompare['lyrics3'] = true; - } - if (strpos($_REQUEST['unsynchronizedtags'], '1') !== false) { - $TagsToCompare['id3v1'] = true; - } - - echo 'Auto-fix empty tags

'; - echo '
'; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - if ($TagsToCompare['id3v2']) { - echo ''; - } - if ($TagsToCompare['ape']) { - echo ''; - } - if ($TagsToCompare['lyrics3']) { - echo ''; - } - if ($TagsToCompare['id3v1']) { - echo ''; - } - echo ''; - - $SQLquery = 'SELECT `filename`, `comments_all`, `comments_id3v2`, `comments_ape`, `comments_lyrics3`, `comments_id3v1`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`fileformat` = "mp3")'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - $lastdir = ''; - $serializedCommentsFields = array('all', 'id3v2', 'ape', 'lyrics3', 'id3v1'); - while ($row = mysql_fetch_array($result)) { - set_time_limit(30); - if ($lastdir != dirname($row['filename'])) { - echo ''; - flush(); - } - - $FileOK = true; - $Mismatched = array('id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false); - $SemiMatched = array('id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false); - $EmptyTags = array('id3v2'=>true, 'ape'=>true, 'lyrics3'=>true, 'id3v1'=>true); - - foreach ($serializedCommentsFields as $field) { - $Comments[$field] = array(); - ob_start(); - if ($unserialized = unserialize($row['comments_'.$field])) { - $Comments[$field] = $unserialized; - } - $errormessage = ob_get_contents(); - ob_end_clean(); - } - - if (isset($Comments['ape']['tracknumber'])) { - $Comments['ape']['track'] = $Comments['ape']['tracknumber']; - unset($Comments['ape']['tracknumber']); - } - if (isset($Comments['ape']['track_number'])) { - $Comments['ape']['track'] = $Comments['ape']['track_number']; - unset($Comments['ape']['track_number']); - } - if (isset($Comments['id3v2']['track_number'])) { - $Comments['id3v2']['track'] = $Comments['id3v2']['track_number']; - unset($Comments['id3v2']['track_number']); - } - if (!empty($Comments['all']['track'])) { - $besttrack = ''; - foreach ($Comments['all']['track'] as $key => $value) { - if (strlen($value) > strlen($besttrack)) { - $besttrack = $value; - } - } - $Comments['all']['track'] = array(0=>$besttrack); - } - - $ThisLine = ''; - $ThisLine .= ''; - $ThisLine .= ''; - $tagvalues = ''; - foreach ($FieldsToCompare as $fieldname) { - $tagvalues .= $fieldname.' = '.(!empty($Comments['all'][$fieldname]) ? implode(" \n", $Comments['all'][$fieldname]) : '')." \n"; - } - $ThisLine .= ''; - foreach ($TagsToCompare as $tagtype => $CompareThisTagType) { - if ($CompareThisTagType) { - $tagvalues = ''; - foreach ($FieldsToCompare as $fieldname) { - - if ($tagtype == 'id3v1') { - - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true); - if (($fieldname == 'genre') && !empty($Comments['all'][$fieldname][0]) && !getid3_id3v1::LookupGenreID($Comments['all'][$fieldname][0])) { - - // non-standard genres can never match, so just ignore - $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; - - } elseif ($fieldname == 'comment') { - - if (isset($Comments[$tagtype][$fieldname][0]) && isset($Comments['all'][$fieldname][0]) && (rtrim(substr($Comments[$tagtype][$fieldname][0], 0, 28)) != rtrim(substr($Comments['all'][$fieldname][0], 0, 28)))) { - $tagvalues .= $fieldname.' = [['.$Comments[$tagtype][$fieldname][0].']]'."\n"; - if (trim(strtolower(RemoveAccents(substr($Comments[$tagtype][$fieldname][0], 0, 28)))) == trim(strtolower(RemoveAccents(substr($Comments['all'][$fieldname][0], 0, 28))))) { - $SemiMatched[$tagtype] = true; - } else { - $Mismatched[$tagtype] = true; - } - $FileOK = false; - } else { - $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; - } - - } elseif ($fieldname == 'track') { - - // intval('01/20') == intval('1') - $trackA = (isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : ''); - $trackB = (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : ''); - if (intval($trackA) != intval($trackB)) { - $tagvalues .= $fieldname.' = [['.$trackA.']]'."\n"; - $Mismatched[$tagtype] = true; - $FileOK = false; - } else { - $tagvalues .= $fieldname.' = '.$trackA."\n"; - } - - } elseif ((isset($Comments[$tagtype][$fieldname][0]) ? rtrim(substr($Comments[$tagtype][$fieldname][0], 0, 30)) : '') != (isset($Comments['all'][$fieldname][0]) ? rtrim(substr($Comments['all'][$fieldname][0], 0, 30)) : '')) { - - $tagvalues .= $fieldname.' = [['.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '').']]'."\n"; - if (strtolower(RemoveAccents(trim(substr((isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : ''), 0, 30)))) == strtolower(RemoveAccents(trim(substr((isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : ''), 0, 30))))) { - $SemiMatched[$tagtype] = true; - } else { - $Mismatched[$tagtype] = true; - } - $FileOK = false; - if (!empty($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { - $EmptyTags[$tagtype] = false; - } - - } else { - - $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; - if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { - $EmptyTags[$tagtype] = false; - } - - } - - } elseif (($tagtype == 'ape') && ($fieldname == 'year')) { - - if (((isset($Comments['ape']['date'][0]) ? $Comments['ape']['date'][0] : '') != (isset($Comments['all']['year'][0]) ? $Comments['all']['year'][0] : '')) && ((isset($Comments['ape']['year'][0]) ? $Comments['ape']['year'][0] : '') != (isset($Comments['all']['year'][0]) ? $Comments['all']['year'][0] : ''))) { - - $tagvalues .= $fieldname.' = [['.(isset($Comments['ape']['date'][0]) ? $Comments['ape']['date'][0] : '').']]'."\n"; - $Mismatched[$tagtype] = true; - $FileOK = false; - if (isset($Comments['ape']['date'][0]) && (strlen(trim($Comments['ape']['date'][0])) > 0)) { - $EmptyTags[$tagtype] = false; - } - - } else { - - $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; - if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { - $EmptyTags[$tagtype] = false; - } - - } - - } elseif (($fieldname == 'genre') && !empty($Comments['all'][$fieldname]) && !empty($Comments[$tagtype][$fieldname]) && in_array($Comments[$tagtype][$fieldname][0], $Comments['all'][$fieldname])) { - - $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; - if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { - $EmptyTags[$tagtype] = false; - } - - } elseif ((isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '') != (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : '')) { - - $skiptracknumberfield = false; - switch ($fieldname) { - case 'track': - case 'tracknumber': - case 'track_number': - $trackA = (isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : ''); - $trackB = (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : ''); - if (intval($trackA) == intval($trackB)) { - $skiptracknumberfield = true; - } - break; - } - if (!$skiptracknumberfield) { - $tagvalues .= $fieldname.' = [['.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '').']]'."\n"; - $tagA = (isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : ''); - $tagB = (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : ''); - if (trim(strtolower(RemoveAccents($tagA))) == trim(strtolower(RemoveAccents($tagB)))) { - $SemiMatched[$tagtype] = true; - } else { - $Mismatched[$tagtype] = true; - } - $FileOK = false; - if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { - $EmptyTags[$tagtype] = false; - } - } - - } else { - - $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; - if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { - $EmptyTags[$tagtype] = false; - } - - } - } - - if ($EmptyTags[$tagtype]) { - $FileOK = false; - $ThisLine .= ''; - } - } - $ThisLine .= ''; - - if (!$FileOK) { - $NotOKfiles++; - - echo ''; - flush(); - - if (!empty($_REQUEST['autofix'])) { - - $AnyMismatched = false; - foreach ($Mismatched as $key => $value) { - if ($value && ($EmptyTags["$key"] === false)) { - $AnyMismatched = true; - } - } - if ($AnyMismatched && empty($_REQUEST['autofixforcesource'])) { - - echo $ThisLine; - - } else { - - $TagsToSynch = ''; - foreach ($EmptyTags as $key => $value) { - if ($value) { - switch ($key) { - case 'id3v1': - $TagsToSynch .= '1'; - break; - case 'id3v2': - $TagsToSynch .= '2'; - break; - case 'ape': - $TagsToSynch .= 'A'; - break; - } - } - } - - $autofixforcesource = (!empty($_REQUEST['autofixforcesource']) ? $_REQUEST['autofixforcesource'] : 'all'); - $TagsToSynch = (!empty($_REQUEST['autofixforcedest']) ? $_REQUEST['autofixforcedest'] : $TagsToSynch); - - $errors = array(); - if (SynchronizeAllTags($row['filename'], $autofixforcesource, $TagsToSynch, $errors)) { - $Autofixedfiles++; - echo ''; - } else { - echo ''; - } - echo ''; - echo ''; - } - - } else { - - echo $ThisLine; - - } - } - } - - echo '
ViewFilenameCombinedID3v2APELyrics3ID3v1
view'.htmlentities($row['filename']).'all'; - } elseif ($SemiMatched[$tagtype]) { - $ThisLine .= ''; - } elseif ($Mismatched[$tagtype]) { - $ThisLine .= ''; - } else { - $ThisLine .= ''; - } - $ThisLine .= ''.$tagtype.''; - $ThisLine .= '
 '; - echo ''.htmlentities($row['filename']).''; - echo ''; - echo '
'.$TagsToSynch.'

'; - echo ''; - echo 'Found '.number_format($NotOKfiles).' files with unsynchronized tags, and auto-fixed '.number_format($Autofixedfiles).' of them.'; - -} elseif (!empty($_REQUEST['filenamepattern'])) { - - $patterns['A'] = 'artist'; - $patterns['T'] = 'title'; - $patterns['M'] = 'album'; - $patterns['N'] = 'track'; - $patterns['G'] = 'genre'; - $patterns['R'] = 'remix'; - - $FieldsToUse = explode(' ', wordwrap(preg_replace('#[^A-Z]#i', '', $_REQUEST['filenamepattern']), 1, ' ', 1)); - //$FieldsToUse = explode(' ', wordwrap($_REQUEST['filenamepattern'], 1, ' ', 1)); - foreach ($FieldsToUse as $FieldID) { - $FieldNames[] = $patterns["$FieldID"]; - } - - $SQLquery = 'SELECT `filename`, `fileformat`, '.implode(', ', $FieldNames); - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - echo 'Files that do not match naming pattern: (auto-fix)
'; - echo ''; - echo ''; - $nonmatchingfilenames = 0; - $Pattern = $_REQUEST['filenamepattern']; - $PatternLength = strlen($Pattern); - while ($row = mysql_fetch_array($result)) { - set_time_limit(10); - $PatternFilename = ''; - for ($i = 0; $i < $PatternLength; $i++) { - if (isset($patterns[$Pattern{$i}])) { - $PatternFilename .= trim(strtr($row[$patterns[$Pattern{$i}]], ':\\*<>|', ';-¤«»¦'), ' '); - } else { - $PatternFilename .= $Pattern{$i}; - } - } - - // Replace "~" with "-" if characters immediately before and after are both numbers, - // "/" has been replaced with "~" above which is good for multi-song medley dividers, - // but for things like 24/7, 7/8ths, etc it looks better if it's 24-7, 7-8ths, etc. - $PatternFilename = preg_replace('#([ a-z]+)/([ a-z]+)#i', '\\1~\\2', $PatternFilename); - $PatternFilename = str_replace('/', '×', $PatternFilename); - - $PatternFilename = str_replace('?', '¿', $PatternFilename); - $PatternFilename = str_replace(' "', ' “', $PatternFilename); - $PatternFilename = str_replace('("', '(“', $PatternFilename); - $PatternFilename = str_replace('-"', '-“', $PatternFilename); - $PatternFilename = str_replace('" ', '” ', $PatternFilename.' '); - $PatternFilename = str_replace('"', '”', $PatternFilename); - $PatternFilename = str_replace(' ', ' ', $PatternFilename); - - - $ParenthesesPairs = array('()', '[]', '{}'); - foreach ($ParenthesesPairs as $pair) { - - // multiple remixes are stored tab-seperated in the database. - // change "{2000 Version\tSomebody Remix}" into "{2000 Version} {Somebody Remix}" - while (preg_match('#^(.*)'.preg_quote($pair{0}).'([^'.preg_quote($pair{1}).']*)('."\t".')([^'.preg_quote($pair{0}).']*)'.preg_quote($pair{1}).'#', $PatternFilename, $matches)) { - $PatternFilename = $matches[1].$pair{0}.$matches[2].$pair{1}.' '.$pair{0}.$matches[4].$pair{1}; - } - - // remove empty parenthesized pairs (probably where no track numbers, remix version, etc) - $PatternFilename = preg_replace('#'.preg_quote($pair).'#', '', $PatternFilename); - - // "[01] - Title With No Artist.mp3" ==> "[01] Title With No Artist.mp3" - $PatternFilename = preg_replace('#'.preg_quote($pair{1}).' +\- #', $pair{1}.' ', $PatternFilename); - - } - - // get rid of leading & trailing spaces if end items (artist or title for example) are missing - $PatternFilename = trim($PatternFilename, ' -'); - - if (!$PatternFilename) { - // no tags to create a filename from -- skip this file - continue; - } - $PatternFilename .= '.'.$row['fileformat']; - - $ActualFilename = basename($row['filename']); - if ($ActualFilename != $PatternFilename) { - - $NotMatchedReasons = ''; - if (strtolower($ActualFilename) === strtolower($PatternFilename)) { - $NotMatchedReasons .= 'Aa '; - } elseif (RemoveAccents($ActualFilename) === RemoveAccents($PatternFilename)) { - $NotMatchedReasons .= 'ée '; - } - - - $actualExt = '.'.fileextension($ActualFilename); - $patternExt = '.'.fileextension($PatternFilename); - $ActualFilenameNoExt = (($actualExt != '.') ? substr($ActualFilename, 0, 0 - strlen($actualExt)) : $ActualFilename); - $PatternFilenameNoExt = (($patternExt != '.') ? substr($PatternFilename, 0, 0 - strlen($patternExt)) : $PatternFilename); - - if (strpos($PatternFilenameNoExt, $ActualFilenameNoExt) !== false) { - $DifferenceBoldedName = str_replace($ActualFilenameNoExt, ''.$ActualFilenameNoExt.'', $PatternFilenameNoExt); - } else { - $ShortestNameLength = min(strlen($ActualFilenameNoExt), strlen($PatternFilenameNoExt)); - for ($DifferenceOffset = 0; $DifferenceOffset < $ShortestNameLength; $DifferenceOffset++) { - if ($ActualFilenameNoExt{$DifferenceOffset} !== $PatternFilenameNoExt{$DifferenceOffset}) { - break; - } - } - $DifferenceBoldedName = ''.substr($PatternFilenameNoExt, 0, $DifferenceOffset).''.substr($PatternFilenameNoExt, $DifferenceOffset); - } - $DifferenceBoldedName .= (($actualExt == $patternExt) ? ''.$patternExt.'' : $patternExt); - - - echo ''; - echo ''; - echo ''; - echo ''; - - if (!empty($_REQUEST['autofix'])) { - - $results = ''; - if (RenameFileFromTo($row['filename'], dirname($row['filename']).'/'.$PatternFilename, $results)) { - echo ''; - - - } else { - - echo ''; - - } - echo ''; - - $nonmatchingfilenames++; - } - } - echo '
viewWhyActual filename
(click to play/edit file)
Correct filename (based on tags)'.(empty($_REQUEST['autofix']) ? '
(click to rename file to this)' : '').'
view '.$NotMatchedReasons.''.htmlentities($ActualFilename).''; - } else { - echo ''; - } - echo ''.$DifferenceBoldedName.''; - echo ''.$DifferenceBoldedName.'

'; - echo 'Found '.number_format($nonmatchingfilenames).' files that do not match naming pattern
'; - - -} elseif (!empty($_REQUEST['encoderoptionsdistribution'])) { - - if (isset($_REQUEST['showtagfiles'])) { - $SQLquery = 'SELECT `filename`, `encoder_options` FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`encoder_options` LIKE "'.mysql_real_escape_string($_REQUEST['showtagfiles']).'")'; - $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - - if (!empty($_REQUEST['m3u'])) { - - header('Content-type: audio/x-mpegurl'); - echo '#EXTM3U'."\n"; - while ($row = mysql_fetch_array($result)) { - echo WindowsShareSlashTranslate($row['filename'])."\n"; - } - exit; - - } else { - - echo 'Show all Encoder Options
'; - echo 'Files with Encoder Options '.$_REQUEST['showtagfiles'].':
'; - echo ''; - while ($row = mysql_fetch_array($result)) { - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
'.htmlentities($row['filename']).''.$row['encoder_options'].'
'; - - } - - } elseif (!isset($_REQUEST['m3u'])) { - - $SQLquery = 'SELECT `encoder_options`, COUNT(*) AS `num` FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; - $SQLquery .= ' GROUP BY `encoder_options`'; - $SQLquery .= ' ORDER BY (`encoder_options` LIKE "LAME%") DESC, (`encoder_options` LIKE "CBR%") DESC, `num` DESC, `encoder_options` ASC'; - $result = mysql_query_safe($SQLquery); - echo 'Files with Encoder Options:
'; - echo ''; - echo ''; - while ($row = mysql_fetch_array($result)) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
Encoder OptionsCountM3U
'.$row['encoder_options'].''.number_format($row['num']).'m3u

'; - - } - -} elseif (!empty($_REQUEST['tagtypes'])) { - - if (!isset($_REQUEST['m3u'])) { - $SQLquery = 'SELECT `tags`, COUNT(*) AS `num` FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; - $SQLquery .= ' GROUP BY `tags`'; - $SQLquery .= ' ORDER BY `num` DESC'; - $result = mysql_query_safe($SQLquery); - echo 'Files with tags:
'; - echo ''; - echo ''; - while ($row = mysql_fetch_array($result)) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
TagsCountM3U
'.$row['tags'].''.number_format($row['num']).'m3u

'; - } - - if (isset($_REQUEST['showtagfiles'])) { - $SQLquery = 'SELECT `filename`, `tags` FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`tags` LIKE "'.mysql_real_escape_string($_REQUEST['showtagfiles']).'")'; - $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - - if (!empty($_REQUEST['m3u'])) { - - header('Content-type: audio/x-mpegurl'); - echo '#EXTM3U'."\n"; - while ($row = mysql_fetch_array($result)) { - echo WindowsShareSlashTranslate($row['filename'])."\n"; - } - exit; - - } else { - - echo ''; - while ($row = mysql_fetch_array($result)) { - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
'.htmlentities($row['filename']).''.$row['tags'].'
'; - - } - } - - -} elseif (!empty($_REQUEST['md5datadupes'])) { - - $OtherFormats = ''; - $AVFormats = ''; - - $SQLquery = 'SELECT `md5_data`, `filename`, COUNT(*) AS `num`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`md5_data` <> "")'; - $SQLquery .= ' GROUP BY `md5_data`'; - $SQLquery .= ' ORDER BY `num` DESC'; - $result = mysql_query_safe($SQLquery); - while (($row = mysql_fetch_array($result)) && ($row['num'] > 1)) { - set_time_limit(30); - - $filenames = array(); - $tags = array(); - $md5_data = array(); - $SQLquery = 'SELECT `fileformat`, `filename`, `tags`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`md5_data` = "'.mysql_real_escape_string($row['md5_data']).'")'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result2 = mysql_query_safe($SQLquery); - while ($row2 = mysql_fetch_array($result2)) { - $thisfileformat = $row2['fileformat']; - $filenames[] = $row2['filename']; - $tags[] = $row2['tags']; - $md5_data[] = $row['md5_data']; - } - - $thisline = ''; - $thisline .= ''.implode('
', $md5_data).''; - $thisline .= ''.implode('
', $tags).''; - $thisline .= ''.implode('
', $filenames).''; - $thisline .= ''; - - if (in_array($thisfileformat, $IgnoreNoTagFormats)) { - $OtherFormats .= $thisline; - } else { - $AVFormats .= $thisline; - } - } - echo 'Duplicated MD5_DATA (Audio/Video files):'; - echo $AVFormats.'

'; - echo 'Duplicated MD5_DATA (Other files):'; - echo $OtherFormats.'

'; - - -} elseif (!empty($_REQUEST['artisttitledupes'])) { - - if (isset($_REQUEST['m3uartist']) && isset($_REQUEST['m3utitle'])) { - - header('Content-type: audio/x-mpegurl'); - echo '#EXTM3U'."\n"; - $SQLquery = 'SELECT `filename`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`artist` = "'.mysql_real_escape_string($_REQUEST['m3uartist']).'")'; - $SQLquery .= ' AND (`title` = "'.mysql_real_escape_string($_REQUEST['m3utitle']).'")'; - $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC'; - $result = mysql_query_safe($SQLquery); - while ($row = mysql_fetch_array($result)) { - echo WindowsShareSlashTranslate($row['filename'])."\n"; - } - exit; - - } - - $SQLquery = 'SELECT `artist`, `title`, `filename`, COUNT(*) AS `num`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`artist` <> "")'; - $SQLquery .= ' AND (`title` <> "")'; - $SQLquery .= ' GROUP BY `artist`, `title`'.(!empty($_REQUEST['samemix']) ? ', `remix`' : ''); - $SQLquery .= ' ORDER BY `num` DESC, `artist` ASC, `title` ASC, `playtime_seconds` ASC, `remix` ASC'; - $result = mysql_query_safe($SQLquery); - $uniquetitles = 0; - $uniquefiles = 0; - - if (!empty($_REQUEST['m3u'])) { - - header('Content-type: audio/x-mpegurl'); - echo '#EXTM3U'."\n"; - while (($row = mysql_fetch_array($result)) && ($row['num'] > 1)) { - $SQLquery = 'SELECT `filename`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`artist` = "'.mysql_real_escape_string($row['artist']).'")'; - $SQLquery .= ' AND (`title` = "'.mysql_real_escape_string($row['title']).'")'; - if (!empty($_REQUEST['samemix'])) { - $SQLquery .= ' AND (`remix` = "'.mysql_real_escape_string($row['remix']).'")'; - } - $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC'; - $result2 = mysql_query_safe($SQLquery); - while ($row2 = mysql_fetch_array($result2)) { - echo WindowsShareSlashTranslate($row2['filename'])."\n"; - } - } - exit; - - } else { - - echo 'Duplicated aritst + title: (Identical Mix/Version only)
'; - echo '(.m3u version)
'; - echo ''; - echo ''; - - while (($row = mysql_fetch_array($result)) && ($row['num'] > 1)) { - $uniquetitles++; - set_time_limit(30); - - $filenames = array(); - $artists = array(); - $titles = array(); - $remixes = array(); - $bitrates = array(); - $playtimes = array(); - $SQLquery = 'SELECT `filename`, `artist`, `title`, `remix`, `audio_bitrate`, `vbr_method`, `playtime_seconds`, `encoder_options`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`artist` = "'.mysql_real_escape_string($row['artist']).'")'; - $SQLquery .= ' AND (`title` = "'.mysql_real_escape_string($row['title']).'")'; - $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC'; - $result2 = mysql_query_safe($SQLquery); - while ($row2 = mysql_fetch_array($result2)) { - $uniquefiles++; - $filenames[] = $row2['filename']; - $artists[] = $row2['artist']; - $titles[] = $row2['title']; - $remixes[] = $row2['remix']; - if ($row2['vbr_method']) { - $bitrates[] = ''.BitrateText($row2['audio_bitrate'] / 1000).''; - } else { - $bitrates[] = BitrateText($row2['audio_bitrate'] / 1000); - } - $playtimes[] = getid3_lib::PlaytimeString($row2['playtime_seconds']); - } - - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - - echo ''; - - echo ''; - } - - } - echo '
 ArtistTitleVersion  Filename
'; - foreach ($filenames as $file) { - echo 'delete
'; - } - echo '
'; - foreach ($filenames as $file) { - echo 'play
'; - } - echo '
play all'.implode('
', $artists).'
'.implode('
', $titles).'
'.implode('
', $remixes).'
'.implode('
', $bitrates).'
'.implode('
', $playtimes).'
'; - foreach ($filenames as $file) { - echo ''; - } - echo '
'.dirname($file).'/'.basename($file).'
'; - echo number_format($uniquefiles).' files with '.number_format($uniquetitles).' unique aritst + title
'; - echo '
'; - -} elseif (!empty($_REQUEST['filetypelist'])) { - - list($fileformat, $audioformat) = explode('|', $_REQUEST['filetypelist']); - $SQLquery = 'SELECT `filename`, `fileformat`, `audio_dataformat`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`fileformat` = "'.mysql_real_escape_string($fileformat).'")'; - $SQLquery .= ' AND (`audio_dataformat` = "'.mysql_real_escape_string($audioformat).'")'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - echo 'Files of format '.$fileformat.'.'.$audioformat.':'; - echo ''; - while ($row = mysql_fetch_array($result)) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
fileaudiofilename
'.$row['fileformat'].''.$row['audio_dataformat'].''.htmlentities($row['filename']).'

'; - -} elseif (!empty($_REQUEST['trackinalbum'])) { - - $SQLquery = 'SELECT `filename`, `album`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`album` LIKE "% [%")'; - $SQLquery .= ' ORDER BY `album` ASC, `filename` ASC'; - $result = mysql_query_safe($SQLquery); - if (!empty($_REQUEST['m3u'])) { - - header('Content-type: audio/x-mpegurl'); - echo '#EXTM3U'."\n"; - while ($row = mysql_fetch_array($result)) { - echo WindowsShareSlashTranslate($row['filename'])."\n"; - } - exit; - - } elseif (!empty($_REQUEST['autofix'])) { - - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true); - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); - - while ($row = mysql_fetch_array($result)) { - set_time_limit(30); - $ThisFileInfo = $getID3->analyze($filename); - getid3_lib::CopyTagsToComments($ThisFileInfo); - - if (!empty($ThisFileInfo['tags'])) { - - $Album = trim(str_replace(strstr($ThisFileInfo['comments']['album'][0], ' ['), '', $ThisFileInfo['comments']['album'][0])); - $Track = (string) intval(str_replace(' [', '', str_replace(']', '', strstr($ThisFileInfo['comments']['album'][0], ' [')))); - if ($Track == '0') { - $Track = ''; - } - if ($Album && $Track) { - echo '
'.htmlentities($row['filename']).'
'; - echo ''.htmlentities($Album).' (track #'.$Track.')
'; - echo 'ID3v2: '.(RemoveID3v2($row['filename'], false) ? 'removed' : 'REMOVAL FAILED!').', '; - $WriteID3v1_title = (isset($ThisFileInfo['comments']['title'][0]) ? $ThisFileInfo['comments']['title'][0] : ''); - $WriteID3v1_artist = (isset($ThisFileInfo['comments']['artist'][0]) ? $ThisFileInfo['comments']['artist'][0] : ''); - $WriteID3v1_year = (isset($ThisFileInfo['comments']['year'][0]) ? $ThisFileInfo['comments']['year'][0] : ''); - $WriteID3v1_comment = (isset($ThisFileInfo['comments']['comment'][0]) ? $ThisFileInfo['comments']['comment'][0] : ''); - $WriteID3v1_genreid = (isset($ThisFileInfo['comments']['genreid'][0]) ? $ThisFileInfo['comments']['genreid'][0] : ''); - echo 'ID3v1: '.(WriteID3v1($row['filename'], $WriteID3v1_title, $WriteID3v1_artist, $Album, $WriteID3v1_year, $WriteID3v1_comment, $WriteID3v1_genreid, $Track, false) ? 'updated' : 'UPDATE FAILED').'
'; - } else { - echo ' . '; - } - - } else { - - echo '
FAILED
'.htmlentities($row['filename']).'
'; - - } - flush(); - } - - } else { - - echo ''.number_format(mysql_num_rows($result)).' files with [??]-format track numbers in album field:
'; - if (mysql_num_rows($result) > 0) { - echo '(.m3u version)
'; - echo 'Try to auto-fix
'; - echo ''; - while ($row = mysql_fetch_array($result)) { - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
'.$row['album'].''.htmlentities($row['filename']).'
'; - } - echo '
'; - - } - -} elseif (!empty($_REQUEST['fileextensions'])) { - - $SQLquery = 'SELECT `filename`, `fileformat`, `audio_dataformat`, `video_dataformat`, `tags`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - $invalidextensionfiles = 0; - $invalidextensionline = ''; - $invalidextensionline .= ''; - while ($row = mysql_fetch_array($result)) { - set_time_limit(30); - - $acceptableextensions = AcceptableExtensions($row['fileformat'], $row['audio_dataformat'], $row['video_dataformat']); - $actualextension = strtolower(fileextension($row['filename'])); - if ($acceptableextensions && !in_array($actualextension, $acceptableextensions)) { - $invalidextensionfiles++; - - $invalidextensionline .= ''; - $invalidextensionline .= ''; - $invalidextensionline .= ''; - $invalidextensionline .= ''; - $invalidextensionline .= ''; - $invalidextensionline .= ''; - $invalidextensionline .= ''; - $invalidextensionline .= ''; - $invalidextensionline .= ''; - } - } - $invalidextensionline .= '
fileaudiovideotagsactualcorrectfilename
'.$row['fileformat'].''.$row['audio_dataformat'].''.$row['video_dataformat'].''.$row['tags'].''.$actualextension.''.implode('; ', $acceptableextensions).''.htmlentities($row['filename']).'

'; - echo number_format($invalidextensionfiles).' files with incorrect filename extension:
'; - echo $invalidextensionline; - +$IgnoreNoTagFormats = ['', 'png', 'jpg', 'gif', 'bmp', 'swf', 'pdf', 'zip', 'rar', 'mid', 'mod', 'xm', 'it', 's3m']; + +if (! empty($_REQUEST['scan']) || ! empty($_REQUEST['newscan']) || ! empty($_REQUEST['rescanerrors'])) { + $SQLquery = 'DELETE from `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` = "")'; + mysql_query_safe($SQLquery); + + $FilesInDir = []; + + if (! empty($_REQUEST['rescanerrors'])) { + echo 'abort
'; + + echo 'Re-scanning all media files already in database that had errors and/or warnings in last scan
'; + + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`error` <> "")'; + $SQLquery .= ' OR (`warning` <> "")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + while ($row = mysql_fetch_array($result)) { + if (! file_exists($row['filename'])) { + echo 'File missing: '.$row['filename'].'
'; + $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($row['filename']).'")'; + mysql_query_safe($SQLquery); + } else { + $FilesInDir[] = $row['filename']; + } + } + } elseif (! empty($_REQUEST['scan']) || ! empty($_REQUEST['newscan'])) { + echo 'abort
'; + + echo 'Scanning all media files in '.str_replace('\\', '/', realpath(! empty($_REQUEST['scan']) ? $_REQUEST['scan'] : $_REQUEST['newscan'])).' (and subdirectories)
'; + + $SQLquery = 'SELECT COUNT(*) AS `num`, `filename`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' GROUP BY `filename`'; + $SQLquery .= ' HAVING (`num` > 1)'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = mysql_query_safe($SQLquery); + $DupesDeleted = 0; + while ($row = mysql_fetch_array($result)) { + set_time_limit(30); + $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE `filename` LIKE "'.mysql_real_escape_string($row['filename']).'"'; + mysql_query_safe($SQLquery); + $DupesDeleted++; + } + if ($DupesDeleted > 0) { + echo 'Deleted '.number_format($DupesDeleted).' duplicate filenames
'; + } + + if (! empty($_REQUEST['newscan'])) { + $AlreadyInDatabase = []; + set_time_limit(60); + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + while ($row = mysql_fetch_array($result)) { + //$AlreadyInDatabase[] = strtolower($row['filename']); + $AlreadyInDatabase[] = $row['filename']; + } + } + + $DirectoriesToScan = [! empty($_REQUEST['scan']) ? $_REQUEST['scan'] : $_REQUEST['newscan']]; + $DirectoriesScanned = []; + while (count($DirectoriesToScan) > 0) { + foreach ($DirectoriesToScan as $DirectoryKey => $startingdir) { + if ($dir = opendir($startingdir)) { + set_time_limit(30); + echo ''.str_replace('\\', '/', $startingdir).'
'; + flush(); + while (($file = readdir($dir)) !== false) { + if (($file != '.') && ($file != '..')) { + $RealPathName = realpath($startingdir.'/'.$file); + if (is_dir($RealPathName)) { + if (! in_array($RealPathName, $DirectoriesScanned) && ! in_array($RealPathName, $DirectoriesToScan)) { + $DirectoriesToScan[] = $RealPathName; + } + } elseif (is_file($RealPathName)) { + if (! empty($_REQUEST['newscan'])) { + if (! in_array(str_replace('\\', '/', $RealPathName), $AlreadyInDatabase)) { + $FilesInDir[] = $RealPathName; + } + } elseif (! empty($_REQUEST['scan'])) { + $FilesInDir[] = $RealPathName; + } + } + } + } + closedir($dir); + } else { + echo '
Failed to open directory "'.htmlentities($startingdir).'"

'; + } + $DirectoriesScanned[] = $startingdir; + unset($DirectoriesToScan[$DirectoryKey]); + } + } + echo 'List of files to scan complete (added '.number_format(count($FilesInDir)).' files to scan)
'; + flush(); + } + + $FilesInDir = array_unique($FilesInDir); + sort($FilesInDir); + + $starttime = time(); + $rowcounter = 0; + $totaltoprocess = count($FilesInDir); + + foreach ($FilesInDir as $filename) { + set_time_limit(300); + + echo '
'.date('H:i:s').' ['.number_format(++$rowcounter).' / '.number_format($totaltoprocess).'] '.str_replace('\\', '/', $filename); + + $ThisFileInfo = $getID3->analyze($filename); + getid3_lib::CopyTagsToComments($ThisFileInfo); + + if (file_exists($filename)) { + $ThisFileInfo['file_modified_time'] = filemtime($filename); + $ThisFileInfo['md5_file'] = ($getid3_demo_mysql_md5_file ? md5_file($filename) : ''); + } + + if (empty($ThisFileInfo['fileformat'])) { + echo ' (unknown file type)'; + } else { + if (! empty($ThisFileInfo['error'])) { + echo ' (errors)'; + } elseif (! empty($ThisFileInfo['warning'])) { + echo ' (warnings)'; + } else { + echo ' (OK)'; + } + + $this_track_track = ''; + if (! empty($ThisFileInfo['comments']['track'])) { + foreach ($ThisFileInfo['comments']['track'] as $key => $value) { + if (strlen($value) > strlen($this_track_track)) { + $this_track_track = str_pad($value, 2, '0', STR_PAD_LEFT); + } + } + if (preg_match('#^([0-9]+)/([0-9]+)$#', $this_track_track, $matches)) { + // change "1/5"->"01/05", "3/12"->"03/12", etc + $this_track_track = str_pad($matches[1], 2, '0', STR_PAD_LEFT).'/'.str_pad($matches[2], 2, '0', STR_PAD_LEFT); + } + } + + $this_track_remix = ''; + $this_track_title = ''; + if (! empty($ThisFileInfo['comments']['title'])) { + foreach ($ThisFileInfo['comments']['title'] as $possible_title) { + if (strlen($possible_title) > strlen($this_track_title)) { + $this_track_title = $possible_title; + } + } + } + + $ParenthesesPairs = ['()', '[]', '{}']; + foreach ($ParenthesesPairs as $pair) { + if (preg_match_all('/(.*) '.preg_quote($pair[0]).'(([^'.preg_quote($pair).']*[\- '.preg_quote($pair[0]).'])?(cut|dub|edit|version|live|reprise|[a-z]*mix))'.preg_quote($pair[1]).'/iU', $this_track_title, $matches)) { + $this_track_title = $matches[1][0]; + $this_track_remix = implode("\t", $matches[2]); + } + } + + if (! empty($_REQUEST['rescanerrors'])) { + $SQLquery = 'UPDATE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` SET '; + $SQLquery .= ' `last_modified` = "'.mysql_real_escape_string(! empty($ThisFileInfo['file_modified_time']) ? $ThisFileInfo['file_modified_time'] : '').'"'; + $SQLquery .= ', `md5_file` = "'.mysql_real_escape_string(! empty($ThisFileInfo['md5_file']) ? $ThisFileInfo['md5_file'] : '').'"'; + $SQLquery .= ', `md5_data` = "'.mysql_real_escape_string(! empty($ThisFileInfo['md5_data']) ? $ThisFileInfo['md5_data'] : '').'"'; + $SQLquery .= ', `md5_data_source` = "'.mysql_real_escape_string(! empty($ThisFileInfo['md5_data_source']) ? $ThisFileInfo['md5_data_source'] : '').'"'; + $SQLquery .= ', `filesize` = "'.mysql_real_escape_string(! empty($ThisFileInfo['filesize']) ? $ThisFileInfo['filesize'] : 0).'"'; + $SQLquery .= ', `fileformat` = "'.mysql_real_escape_string(! empty($ThisFileInfo['fileformat']) ? $ThisFileInfo['fileformat'] : '').'"'; + $SQLquery .= ', `audio_dataformat` = "'.mysql_real_escape_string(! empty($ThisFileInfo['audio']['dataformat']) ? $ThisFileInfo['audio']['dataformat'] : '').'"'; + $SQLquery .= ', `video_dataformat` = "'.mysql_real_escape_string(! empty($ThisFileInfo['video']['dataformat']) ? $ThisFileInfo['video']['dataformat'] : '').'"'; + $SQLquery .= ', `vbr_method` = "'.mysql_real_escape_string(! empty($ThisFileInfo['mpeg']['audio']['VBR_method']) ? $ThisFileInfo['mpeg']['audio']['VBR_method'] : '').'"'; + $SQLquery .= ', `audio_bitrate` = "'.mysql_real_escape_string(! empty($ThisFileInfo['audio']['bitrate']) ? floatval($ThisFileInfo['audio']['bitrate']) : 0).'"'; + $SQLquery .= ', `video_bitrate` = "'.mysql_real_escape_string(! empty($ThisFileInfo['video']['bitrate']) ? floatval($ThisFileInfo['video']['bitrate']) : 0).'"'; + $SQLquery .= ', `playtime_seconds` = "'.mysql_real_escape_string(! empty($ThisFileInfo['playtime_seconds']) ? floatval($ThisFileInfo['playtime_seconds']) : 0).'"'; + $SQLquery .= ', `track_volume` = "'.mysql_real_escape_string(! empty($ThisFileInfo['replay_gain']['track']['volume']) ? floatval($ThisFileInfo['replay_gain']['track']['volume']) : 0).'"'; + $SQLquery .= ', `comments_all` = "'.mysql_real_escape_string(! empty($ThisFileInfo['comments']) ? serialize($ThisFileInfo['comments']) : '').'"'; + $SQLquery .= ', `comments_id3v2` = "'.mysql_real_escape_string(! empty($ThisFileInfo['tags']['id3v2']) ? serialize($ThisFileInfo['tags']['id3v2']) : '').'"'; + $SQLquery .= ', `comments_ape` = "'.mysql_real_escape_string(! empty($ThisFileInfo['tags']['ape']) ? serialize($ThisFileInfo['tags']['ape']) : '').'"'; + $SQLquery .= ', `comments_lyrics3` = "'.mysql_real_escape_string(! empty($ThisFileInfo['tags']['lyrics3']) ? serialize($ThisFileInfo['tags']['lyrics3']) : '').'"'; + $SQLquery .= ', `comments_id3v1` = "'.mysql_real_escape_string(! empty($ThisFileInfo['tags']['id3v1']) ? serialize($ThisFileInfo['tags']['id3v1']) : '').'"'; + $SQLquery .= ', `warning` = "'.mysql_real_escape_string(! empty($ThisFileInfo['warning']) ? implode("\t", $ThisFileInfo['warning']) : '').'"'; + $SQLquery .= ', `error` = "'.mysql_real_escape_string(! empty($ThisFileInfo['error']) ? implode("\t", $ThisFileInfo['error']) : '').'"'; + $SQLquery .= ', `album` = "'.mysql_real_escape_string(! empty($ThisFileInfo['comments']['album']) ? implode("\t", $ThisFileInfo['comments']['album']) : '').'"'; + $SQLquery .= ', `genre` = "'.mysql_real_escape_string(! empty($ThisFileInfo['comments']['genre']) ? implode("\t", $ThisFileInfo['comments']['genre']) : '').'"'; + $SQLquery .= ', `comment` = "'.mysql_real_escape_string(! empty($ThisFileInfo['comments']['comment']) ? implode("\t", $ThisFileInfo['comments']['comment']) : '').'"'; + $SQLquery .= ', `artist` = "'.mysql_real_escape_string(! empty($ThisFileInfo['comments']['artist']) ? implode("\t", $ThisFileInfo['comments']['artist']) : '').'"'; + $SQLquery .= ', `tags` = "'.mysql_real_escape_string(! empty($ThisFileInfo['tags']) ? implode("\t", array_keys($ThisFileInfo['tags'])) : '').'"'; + $SQLquery .= ', `encoder_options` = "'.mysql_real_escape_string(trim((! empty($ThisFileInfo['audio']['encoder']) ? $ThisFileInfo['audio']['encoder'] : '').' '.(! empty($ThisFileInfo['audio']['encoder_options']) ? $ThisFileInfo['audio']['encoder_options'] : ''))).'"'; + $SQLquery .= ', `title` = "'.mysql_real_escape_string($this_track_title).'"'; + $SQLquery .= ', `remix` = "'.mysql_real_escape_string($this_track_remix).'"'; + $SQLquery .= ', `track` = "'.mysql_real_escape_string($this_track_track).'"'; + $SQLquery .= 'WHERE (`filename` = "'.mysql_real_escape_string(isset($ThisFileInfo['filenamepath']) ? $ThisFileInfo['filenamepath'] : '').'")'; + } elseif (! empty($_REQUEST['scan']) || ! empty($_REQUEST['newscan'])) { + + //$SQLquery = 'INSERT INTO `'.mysql_real_escape_string(GETID3_DB_TABLE).'` (`filename`, `last_modified`, `md5_file`, `md5_data`, `md5_data_source`, `filesize`, `fileformat`, `audio_dataformat`, `video_dataformat`, `audio_bitrate`, `video_bitrate`, `playtime_seconds`, `artist`, `title`, `remix`, `album`, `genre`, `comment`, `track`, `comments_all`, `comments_id3v2`, `comments_ape`, `comments_lyrics3`, `comments_id3v1`, `warning`, `error`, `encoder_options`, `vbr_method`, `track_volume`) VALUES ('; + $SQLquery = 'INSERT INTO `'.mysql_real_escape_string(GETID3_DB_TABLE).'` (`filename`, `last_modified`, `md5_file`, `md5_data`, `md5_data_source`, `filesize`, `fileformat`, `audio_dataformat`, `video_dataformat`, `audio_bitrate`, `video_bitrate`, `playtime_seconds`, `tags`, `artist`, `title`, `remix`, `album`, `genre`, `comment`, `track`, `comments_all`, `comments_id3v2`, `comments_ape`, `comments_lyrics3`, `comments_id3v1`, `warning`, `error`, `encoder_options`, `vbr_method`, `track_volume`) VALUES ('; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['filenamepath']) ? $ThisFileInfo['filenamepath'] : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['file_modified_time']) ? $ThisFileInfo['file_modified_time'] : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['md5_file']) ? $ThisFileInfo['md5_file'] : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['md5_data']) ? $ThisFileInfo['md5_data'] : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['md5_data_source']) ? $ThisFileInfo['md5_data_source'] : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['filesize']) ? $ThisFileInfo['filesize'] : 0).'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['fileformat']) ? $ThisFileInfo['fileformat'] : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['audio']['dataformat']) ? $ThisFileInfo['audio']['dataformat'] : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['video']['dataformat']) ? $ThisFileInfo['video']['dataformat'] : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['audio']['bitrate']) ? floatval($ThisFileInfo['audio']['bitrate']) : 0).'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['video']['bitrate']) ? floatval($ThisFileInfo['video']['bitrate']) : 0).'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['playtime_seconds']) ? floatval($ThisFileInfo['playtime_seconds']) : 0).'", '; + //$SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['tags'] ) ? implode("\t", $ThisFileInfo['tags']) : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['tags']) ? implode("\t", array_keys($ThisFileInfo['tags'])) : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['comments']['artist']) ? implode("\t", $ThisFileInfo['comments']['artist']) : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string($this_track_title).'", '; + $SQLquery .= '"'.mysql_real_escape_string($this_track_remix).'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['comments']['album']) ? implode("\t", $ThisFileInfo['comments']['album']) : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['comments']['genre']) ? implode("\t", $ThisFileInfo['comments']['genre']) : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['comments']['comment']) ? implode("\t", $ThisFileInfo['comments']['comment']) : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string($this_track_track).'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['comments']) ? serialize($ThisFileInfo['comments']) : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['tags']['id3v2']) ? serialize($ThisFileInfo['tags']['id3v2']) : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['tags']['ape']) ? serialize($ThisFileInfo['tags']['ape']) : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['tags']['lyrics3']) ? serialize($ThisFileInfo['tags']['lyrics3']) : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['tags']['id3v1']) ? serialize($ThisFileInfo['tags']['id3v1']) : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['warning']) ? implode("\t", $ThisFileInfo['warning']) : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['error']) ? implode("\t", $ThisFileInfo['error']) : '').'", '; + $SQLquery .= '"'.mysql_real_escape_string(trim((! empty($ThisFileInfo['audio']['encoder']) ? $ThisFileInfo['audio']['encoder'] : '').' '.(! empty($ThisFileInfo['audio']['encoder_options']) ? $ThisFileInfo['audio']['encoder_options'] : ''))).'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['mpeg']['audio']['LAME']) ? 'LAME' : (! empty($ThisFileInfo['mpeg']['audio']['VBR_method']) ? $ThisFileInfo['mpeg']['audio']['VBR_method'] : '')).'", '; + $SQLquery .= '"'.mysql_real_escape_string(! empty($ThisFileInfo['replay_gain']['track']['volume']) ? floatval($ThisFileInfo['replay_gain']['track']['volume']) : 0).'")'; + } + flush(); + mysql_query_safe($SQLquery); + } + } + + $SQLquery = 'OPTIMIZE TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + mysql_query_safe($SQLquery); + + echo '
Done scanning!
'; +} elseif (! empty($_REQUEST['missingtrackvolume'])) { + $MissingTrackVolumeFilesScanned = 0; + $MissingTrackVolumeFilesAdjusted = 0; + $MissingTrackVolumeFilesDeleted = 0; + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`track_volume` = 0)'; + $SQLquery .= ' AND (`audio_bitrate` > 0)'; + $result = mysql_query_safe($SQLquery); + echo 'Scanning 0 / '.number_format(mysql_num_rows($result)).' files for track volume information:
'; + while ($row = mysql_fetch_array($result)) { + set_time_limit(30); + echo '. '; + flush(); + if (file_exists($row['filename'])) { + $ThisFileInfo = $getID3->analyze($row['filename']); + if (! empty($ThisFileInfo['replay_gain']['track']['volume'])) { + $MissingTrackVolumeFilesAdjusted++; + $SQLquery = 'UPDATE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' SET `track_volume` = "'.$ThisFileInfo['replay_gain']['track']['volume'].'"'; + $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($row['filename']).'")'; + mysql_query_safe($SQLquery); + } + } else { + $MissingTrackVolumeFilesDeleted++; + $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($row['filename']).'")'; + mysql_query_safe($SQLquery); + } + } + echo '
Scanned '.number_format($MissingTrackVolumeFilesScanned).' files with no track volume information.
'; + echo 'Found track volume information for '.number_format($MissingTrackVolumeFilesAdjusted).' of them (could not find info for '.number_format($MissingTrackVolumeFilesScanned - $MissingTrackVolumeFilesAdjusted).' files; deleted '.number_format($MissingTrackVolumeFilesDeleted).' records of missing files)
'; +} elseif (! empty($_REQUEST['deadfilescheck'])) { + $SQLquery = 'SELECT COUNT(*) AS `num`, `filename`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' GROUP BY `filename`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = mysql_query_safe($SQLquery); + $DupesDeleted = 0; + while ($row = mysql_fetch_array($result)) { + set_time_limit(30); + if ($row['num'] <= 1) { + break; + } + echo '
'.htmlentities($row['filename']).' (duplicate)'; + $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE `filename` LIKE "'.mysql_real_escape_string($row['filename']).'"'; + mysql_query_safe($SQLquery); + $DupesDeleted++; + } + if ($DupesDeleted > 0) { + echo '
Deleted '.number_format($DupesDeleted).' duplicate filenames
'; + } + + $SQLquery = 'SELECT `filename`, `filesize`, `last_modified`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + $totalchecked = 0; + $totalremoved = 0; + $previousdir = ''; + while ($row = mysql_fetch_array($result)) { + $totalchecked++; + set_time_limit(30); + $reason = ''; + if (! file_exists($row['filename'])) { + $reason = 'deleted'; + } elseif (filesize($row['filename']) != $row['filesize']) { + $reason = 'filesize changed'; + } elseif (filemtime($row['filename']) != $row['last_modified']) { + if (abs(filemtime($row['filename']) - $row['last_modified']) != 3600) { + // off by exactly one hour == daylight savings time + $reason = 'last-modified time changed'; + } + } + + $thisdir = dirname($row['filename']); + if ($reason) { + $totalremoved++; + echo '
'.htmlentities($row['filename']).' ('.$reason.')'; + flush(); + $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($row['filename']).'")'; + mysql_query_safe($SQLquery); + } elseif ($thisdir != $previousdir) { + echo '. '; + flush(); + } + $previousdir = $thisdir; + } + + echo '
'.number_format($totalremoved).' of '.number_format($totalchecked).' files in database no longer exist, or have been altered since last scan. Removed from database.
'; +} elseif (! empty($_REQUEST['encodedbydistribution'])) { + if (! empty($_REQUEST['m3u'])) { + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + + $SQLquery = 'SELECT `filename`, `comments_id3v2`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`encoder_options` = "'.mysql_real_escape_string($_REQUEST['encodedbydistribution']).'")'; + $result = mysql_query_safe($SQLquery); + $NonBlankEncodedBy = ''; + $BlankEncodedBy = ''; + while ($row = mysql_fetch_array($result)) { + set_time_limit(30); + $CommentArray = unserialize($row['comments_id3v2']); + if (isset($CommentArray['encoded_by'][0])) { + $NonBlankEncodedBy .= WindowsShareSlashTranslate($row['filename'])."\n"; + } else { + $BlankEncodedBy .= WindowsShareSlashTranslate($row['filename'])."\n"; + } + } + echo $NonBlankEncodedBy; + echo $BlankEncodedBy; + exit; + } elseif (! empty($_REQUEST['showfiles'])) { + echo 'show all
'; + echo ''; + + $SQLquery = 'SELECT `filename`, `comments_id3v2`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $result = mysql_query_safe($SQLquery); + while ($row = mysql_fetch_array($result)) { + set_time_limit(30); + $CommentArray = unserialize($row['comments_id3v2']); + if (($_REQUEST['encodedbydistribution'] == '%') || (! empty($CommentArray['encoded_by'][0]) && ($_REQUEST['encodedbydistribution'] == $CommentArray['encoded_by'][0]))) { + echo ''; + echo ''; + } + } + echo '
m3u'.htmlentities($row['filename']).'
'; + } else { + $SQLquery = 'SELECT `encoder_options`, `comments_id3v2`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' ORDER BY (`encoder_options` LIKE "LAME%") DESC, (`encoder_options` LIKE "CBR%") DESC'; + $result = mysql_query_safe($SQLquery); + $EncodedBy = []; + while ($row = mysql_fetch_array($result)) { + set_time_limit(30); + $CommentArray = unserialize($row['comments_id3v2']); + if (isset($CommentArray['encoded_by'][0])) { + if (isset($EncodedBy[$row['encoder_options']][$CommentArray['encoded_by'][0]])) { + $EncodedBy[$row['encoder_options']][$CommentArray['encoded_by'][0]]++; + } else { + $EncodedBy[$row['encoder_options']][$CommentArray['encoded_by'][0]] = 1; + } + } + } + echo '.m3u version
'; + echo ''; + foreach ($EncodedBy as $key => $value) { + echo ''; + echo ''; + echo ''; + } + echo '
m3uEncoder OptionsEncoded By (ID3v2)
m3u'.$key.''; + arsort($value); + foreach ($value as $string => $count) { + echo ''; + echo ''; + } + echo '
'.number_format($count).' '.$string.'
'; + } +} elseif (! empty($_REQUEST['audiobitrates'])) { + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); + $BitrateDistribution = []; + $SQLquery = 'SELECT ROUND(audio_bitrate / 1000) AS `RoundBitrate`, COUNT(*) AS `num`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`audio_bitrate` > 0)'; + $SQLquery .= ' GROUP BY `RoundBitrate`'; + $result = mysql_query_safe($SQLquery); + while ($row = mysql_fetch_array($result)) { + $this_bitrate = getid3_mp3::ClosestStandardMP3Bitrate($row['RoundBitrate'] * 1000); + if (isset($BitrateDistribution[$this_bitrate])) { + $BitrateDistribution[$this_bitrate] += $row['num']; + } else { + $BitrateDistribution[$this_bitrate] = $row['num']; + } + } + + echo ''; + echo ''; + foreach ($BitrateDistribution as $Bitrate => $Count) { + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
BitrateCount
'.round($Bitrate / 1000).' kbps'.number_format($Count).'
'; +} elseif (! empty($_REQUEST['emptygenres'])) { + $SQLquery = 'SELECT `fileformat`, `filename`, `genre`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`genre` = "")'; + $SQLquery .= ' OR (`genre` = "Unknown")'; + $SQLquery .= ' OR (`genre` = "Other")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + + if (! empty($_REQUEST['m3u'])) { + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysql_fetch_array($result)) { + if (! in_array($row['fileformat'], $IgnoreNoTagFormats)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + } + exit; + } else { + echo '.m3u version
'; + $EmptyGenreCounter = 0; + echo ''; + echo ''; + while ($row = mysql_fetch_array($result)) { + if (! in_array($row['fileformat'], $IgnoreNoTagFormats)) { + $EmptyGenreCounter++; + echo ''; + echo ''; + echo ''; + echo ''; + } + } + echo '
m3ufilename
m3u'.htmlentities($row['filename']).'
'; + echo ''.number_format($EmptyGenreCounter).' files with empty genres'; + } +} elseif (! empty($_REQUEST['nonemptycomments'])) { + $SQLquery = 'SELECT `filename`, `comment`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`comment` <> "")'; + $SQLquery .= ' ORDER BY `comment` ASC'; + $result = mysql_query_safe($SQLquery); + + if (! empty($_REQUEST['m3u'])) { + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysql_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + } else { + $NonEmptyCommentsCounter = 0; + echo '.m3u version
'; + echo ''; + echo ''; + while ($row = mysql_fetch_array($result)) { + $NonEmptyCommentsCounter++; + echo ''; + echo ''; + echo ''; + if (strlen(trim($row['comment'])) > 0) { + echo ''; + } else { + echo ''; + } + echo ''; + } + echo '
m3ufilenamecomments
m3u'.htmlentities($row['filename']).''.htmlentities($row['comment']).'space
'; + echo ''.number_format($NonEmptyCommentsCounter).' files with non-empty comments'; + } +} elseif (! empty($_REQUEST['trackzero'])) { + $SQLquery = 'SELECT `filename`, `track`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`track` <> "")'; + $SQLquery .= ' AND ((`track` < "1")'; + $SQLquery .= ' OR (`track` > "99"))'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + + if (! empty($_REQUEST['m3u'])) { + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysql_fetch_array($result)) { + if ((strlen($row['track']) > 0) && ($row['track'] < 1) || ($row['track'] > 99)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + } + exit; + } else { + echo '.m3u version
'; + $TrackZeroCounter = 0; + echo ''; + echo ''; + while ($row = mysql_fetch_array($result)) { + if ((strlen($row['track']) > 0) && ($row['track'] < 1) || ($row['track'] > 99)) { + $TrackZeroCounter++; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + } + echo '
m3ufilenametrack
m3u'.htmlentities($row['filename']).''.htmlentities($row['track']).'
'; + echo ''.number_format($TrackZeroCounter).' files with track "zero"'; + } +} elseif (! empty($_REQUEST['titlefeat'])) { + $SQLquery = 'SELECT `filename`, `title`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`title` LIKE "%feat.%")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + + if (! empty($_REQUEST['m3u'])) { + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysql_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + } else { + echo ''.number_format(mysql_num_rows($result)).' files with "feat." in the title (instead of the artist)

'; + echo '.m3u version
'; + echo ''; + echo ''; + while ($row = mysql_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
m3ufilenametitle
m3u'.htmlentities($row['filename']).''.preg_replace('#(feat\. .*)#i', '\\1', htmlentities($row['title'])).'
'; + } +} elseif (! empty($_REQUEST['tracknoalbum'])) { + $SQLquery = 'SELECT `filename`, `track`, `album`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`track` <> "")'; + $SQLquery .= ' AND (`album` = "")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + + if (! empty($_REQUEST['m3u'])) { + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysql_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + } else { + echo ''.number_format(mysql_num_rows($result)).' files with a track number, but no album

'; + echo '.m3u version
'; + echo ''; + echo ''; + while ($row = mysql_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
m3ufilenametrackalbum
m3u'.htmlentities($row['filename']).''.htmlentities($row['track']).''.htmlentities($row['album']).'
'; + } +} elseif (! empty($_REQUEST['synchronizetagsfrom']) && ! empty($_REQUEST['filename'])) { + echo 'Applying new tags from '.$_REQUEST['synchronizetagsfrom'].' in '.htmlentities($_REQUEST['filename']).'
    '; + $errors = []; + if (SynchronizeAllTags($_REQUEST['filename'], $_REQUEST['synchronizetagsfrom'], 'A12', $errors)) { + echo '
  • Sucessfully wrote tags
  • '; + } else { + echo '
  • Tag writing had errors:
    • '.implode('
    • ', $errors).'
  • '; + } + echo '
'; +} elseif (! empty($_REQUEST['unsynchronizedtags'])) { + $NotOKfiles = 0; + $Autofixedfiles = 0; + $FieldsToCompare = ['title', 'artist', 'album', 'year', 'genre', 'comment', 'track']; + $TagsToCompare = ['id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false]; + $ID3v1FieldLengths = ['title'=>30, 'artist'=>30, 'album'=>30, 'year'=>4, 'genre'=>99, 'comment'=>28]; + if (strpos($_REQUEST['unsynchronizedtags'], '2') !== false) { + $TagsToCompare['id3v2'] = true; + } + if (strpos($_REQUEST['unsynchronizedtags'], 'A') !== false) { + $TagsToCompare['ape'] = true; + } + if (strpos($_REQUEST['unsynchronizedtags'], 'L') !== false) { + $TagsToCompare['lyrics3'] = true; + } + if (strpos($_REQUEST['unsynchronizedtags'], '1') !== false) { + $TagsToCompare['id3v1'] = true; + } + + echo 'Auto-fix empty tags

'; + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + if ($TagsToCompare['id3v2']) { + echo ''; + } + if ($TagsToCompare['ape']) { + echo ''; + } + if ($TagsToCompare['lyrics3']) { + echo ''; + } + if ($TagsToCompare['id3v1']) { + echo ''; + } + echo ''; + + $SQLquery = 'SELECT `filename`, `comments_all`, `comments_id3v2`, `comments_ape`, `comments_lyrics3`, `comments_id3v1`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` = "mp3")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + $lastdir = ''; + $serializedCommentsFields = ['all', 'id3v2', 'ape', 'lyrics3', 'id3v1']; + while ($row = mysql_fetch_array($result)) { + set_time_limit(30); + if ($lastdir != dirname($row['filename'])) { + echo ''; + flush(); + } + + $FileOK = true; + $Mismatched = ['id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false]; + $SemiMatched = ['id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false]; + $EmptyTags = ['id3v2'=>true, 'ape'=>true, 'lyrics3'=>true, 'id3v1'=>true]; + + foreach ($serializedCommentsFields as $field) { + $Comments[$field] = []; + ob_start(); + if ($unserialized = unserialize($row['comments_'.$field])) { + $Comments[$field] = $unserialized; + } + $errormessage = ob_get_contents(); + ob_end_clean(); + } + + if (isset($Comments['ape']['tracknumber'])) { + $Comments['ape']['track'] = $Comments['ape']['tracknumber']; + unset($Comments['ape']['tracknumber']); + } + if (isset($Comments['ape']['track_number'])) { + $Comments['ape']['track'] = $Comments['ape']['track_number']; + unset($Comments['ape']['track_number']); + } + if (isset($Comments['id3v2']['track_number'])) { + $Comments['id3v2']['track'] = $Comments['id3v2']['track_number']; + unset($Comments['id3v2']['track_number']); + } + if (! empty($Comments['all']['track'])) { + $besttrack = ''; + foreach ($Comments['all']['track'] as $key => $value) { + if (strlen($value) > strlen($besttrack)) { + $besttrack = $value; + } + } + $Comments['all']['track'] = [0=>$besttrack]; + } + + $ThisLine = ''; + $ThisLine .= ''; + $ThisLine .= ''; + $tagvalues = ''; + foreach ($FieldsToCompare as $fieldname) { + $tagvalues .= $fieldname.' = '.(! empty($Comments['all'][$fieldname]) ? implode(" \n", $Comments['all'][$fieldname]) : '')." \n"; + } + $ThisLine .= ''; + foreach ($TagsToCompare as $tagtype => $CompareThisTagType) { + if ($CompareThisTagType) { + $tagvalues = ''; + foreach ($FieldsToCompare as $fieldname) { + if ($tagtype == 'id3v1') { + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true); + if (($fieldname == 'genre') && ! empty($Comments['all'][$fieldname][0]) && ! getid3_id3v1::LookupGenreID($Comments['all'][$fieldname][0])) { + + // non-standard genres can never match, so just ignore + $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; + } elseif ($fieldname == 'comment') { + if (isset($Comments[$tagtype][$fieldname][0]) && isset($Comments['all'][$fieldname][0]) && (rtrim(substr($Comments[$tagtype][$fieldname][0], 0, 28)) != rtrim(substr($Comments['all'][$fieldname][0], 0, 28)))) { + $tagvalues .= $fieldname.' = [['.$Comments[$tagtype][$fieldname][0].']]'."\n"; + if (trim(strtolower(RemoveAccents(substr($Comments[$tagtype][$fieldname][0], 0, 28)))) == trim(strtolower(RemoveAccents(substr($Comments['all'][$fieldname][0], 0, 28))))) { + $SemiMatched[$tagtype] = true; + } else { + $Mismatched[$tagtype] = true; + } + $FileOK = false; + } else { + $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; + } + } elseif ($fieldname == 'track') { + + // intval('01/20') == intval('1') + $trackA = (isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : ''); + $trackB = (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : ''); + if (intval($trackA) != intval($trackB)) { + $tagvalues .= $fieldname.' = [['.$trackA.']]'."\n"; + $Mismatched[$tagtype] = true; + $FileOK = false; + } else { + $tagvalues .= $fieldname.' = '.$trackA."\n"; + } + } elseif ((isset($Comments[$tagtype][$fieldname][0]) ? rtrim(substr($Comments[$tagtype][$fieldname][0], 0, 30)) : '') != (isset($Comments['all'][$fieldname][0]) ? rtrim(substr($Comments['all'][$fieldname][0], 0, 30)) : '')) { + $tagvalues .= $fieldname.' = [['.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '').']]'."\n"; + if (strtolower(RemoveAccents(trim(substr((isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : ''), 0, 30)))) == strtolower(RemoveAccents(trim(substr((isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : ''), 0, 30))))) { + $SemiMatched[$tagtype] = true; + } else { + $Mismatched[$tagtype] = true; + } + $FileOK = false; + if (! empty($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { + $EmptyTags[$tagtype] = false; + } + } else { + $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; + if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { + $EmptyTags[$tagtype] = false; + } + } + } elseif (($tagtype == 'ape') && ($fieldname == 'year')) { + if (((isset($Comments['ape']['date'][0]) ? $Comments['ape']['date'][0] : '') != (isset($Comments['all']['year'][0]) ? $Comments['all']['year'][0] : '')) && ((isset($Comments['ape']['year'][0]) ? $Comments['ape']['year'][0] : '') != (isset($Comments['all']['year'][0]) ? $Comments['all']['year'][0] : ''))) { + $tagvalues .= $fieldname.' = [['.(isset($Comments['ape']['date'][0]) ? $Comments['ape']['date'][0] : '').']]'."\n"; + $Mismatched[$tagtype] = true; + $FileOK = false; + if (isset($Comments['ape']['date'][0]) && (strlen(trim($Comments['ape']['date'][0])) > 0)) { + $EmptyTags[$tagtype] = false; + } + } else { + $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; + if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { + $EmptyTags[$tagtype] = false; + } + } + } elseif (($fieldname == 'genre') && ! empty($Comments['all'][$fieldname]) && ! empty($Comments[$tagtype][$fieldname]) && in_array($Comments[$tagtype][$fieldname][0], $Comments['all'][$fieldname])) { + $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; + if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { + $EmptyTags[$tagtype] = false; + } + } elseif ((isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '') != (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : '')) { + $skiptracknumberfield = false; + switch ($fieldname) { + case 'track': + case 'tracknumber': + case 'track_number': + $trackA = (isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : ''); + $trackB = (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : ''); + if (intval($trackA) == intval($trackB)) { + $skiptracknumberfield = true; + } + break; + } + if (! $skiptracknumberfield) { + $tagvalues .= $fieldname.' = [['.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '').']]'."\n"; + $tagA = (isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : ''); + $tagB = (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : ''); + if (trim(strtolower(RemoveAccents($tagA))) == trim(strtolower(RemoveAccents($tagB)))) { + $SemiMatched[$tagtype] = true; + } else { + $Mismatched[$tagtype] = true; + } + $FileOK = false; + if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { + $EmptyTags[$tagtype] = false; + } + } + } else { + $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; + if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { + $EmptyTags[$tagtype] = false; + } + } + } + + if ($EmptyTags[$tagtype]) { + $FileOK = false; + $ThisLine .= ''; + } + } + $ThisLine .= ''; + + if (! $FileOK) { + $NotOKfiles++; + + echo ''; + flush(); + + if (! empty($_REQUEST['autofix'])) { + $AnyMismatched = false; + foreach ($Mismatched as $key => $value) { + if ($value && ($EmptyTags["$key"] === false)) { + $AnyMismatched = true; + } + } + if ($AnyMismatched && empty($_REQUEST['autofixforcesource'])) { + echo $ThisLine; + } else { + $TagsToSynch = ''; + foreach ($EmptyTags as $key => $value) { + if ($value) { + switch ($key) { + case 'id3v1': + $TagsToSynch .= '1'; + break; + case 'id3v2': + $TagsToSynch .= '2'; + break; + case 'ape': + $TagsToSynch .= 'A'; + break; + } + } + } + + $autofixforcesource = (! empty($_REQUEST['autofixforcesource']) ? $_REQUEST['autofixforcesource'] : 'all'); + $TagsToSynch = (! empty($_REQUEST['autofixforcedest']) ? $_REQUEST['autofixforcedest'] : $TagsToSynch); + + $errors = []; + if (SynchronizeAllTags($row['filename'], $autofixforcesource, $TagsToSynch, $errors)) { + $Autofixedfiles++; + echo ''; + } else { + echo ''; + } + echo ''; + echo ''; + } + } else { + echo $ThisLine; + } + } + } + + echo '
ViewFilenameCombinedID3v2APELyrics3ID3v1
view'.htmlentities($row['filename']).'all'; + } elseif ($SemiMatched[$tagtype]) { + $ThisLine .= ''; + } elseif ($Mismatched[$tagtype]) { + $ThisLine .= ''; + } else { + $ThisLine .= ''; + } + $ThisLine .= ''.$tagtype.''; + $ThisLine .= '
 '; + echo ''.htmlentities($row['filename']).''; + echo ''; + echo '
'.$TagsToSynch.'

'; + echo ''; + echo 'Found '.number_format($NotOKfiles).' files with unsynchronized tags, and auto-fixed '.number_format($Autofixedfiles).' of them.'; +} elseif (! empty($_REQUEST['filenamepattern'])) { + $patterns['A'] = 'artist'; + $patterns['T'] = 'title'; + $patterns['M'] = 'album'; + $patterns['N'] = 'track'; + $patterns['G'] = 'genre'; + $patterns['R'] = 'remix'; + + $FieldsToUse = explode(' ', wordwrap(preg_replace('#[^A-Z]#i', '', $_REQUEST['filenamepattern']), 1, ' ', 1)); + //$FieldsToUse = explode(' ', wordwrap($_REQUEST['filenamepattern'], 1, ' ', 1)); + foreach ($FieldsToUse as $FieldID) { + $FieldNames[] = $patterns["$FieldID"]; + } + + $SQLquery = 'SELECT `filename`, `fileformat`, '.implode(', ', $FieldNames); + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + echo 'Files that do not match naming pattern: (auto-fix)
'; + echo ''; + echo ''; + $nonmatchingfilenames = 0; + $Pattern = $_REQUEST['filenamepattern']; + $PatternLength = strlen($Pattern); + while ($row = mysql_fetch_array($result)) { + set_time_limit(10); + $PatternFilename = ''; + for ($i = 0; $i < $PatternLength; $i++) { + if (isset($patterns[$Pattern[$i]])) { + $PatternFilename .= trim(strtr($row[$patterns[$Pattern[$i]]], ':\\*<>|', ';-¤«»¦'), ' '); + } else { + $PatternFilename .= $Pattern[$i]; + } + } + + // Replace "~" with "-" if characters immediately before and after are both numbers, + // "/" has been replaced with "~" above which is good for multi-song medley dividers, + // but for things like 24/7, 7/8ths, etc it looks better if it's 24-7, 7-8ths, etc. + $PatternFilename = preg_replace('#([ a-z]+)/([ a-z]+)#i', '\\1~\\2', $PatternFilename); + $PatternFilename = str_replace('/', '×', $PatternFilename); + + $PatternFilename = str_replace('?', '¿', $PatternFilename); + $PatternFilename = str_replace(' "', ' “', $PatternFilename); + $PatternFilename = str_replace('("', '(“', $PatternFilename); + $PatternFilename = str_replace('-"', '-“', $PatternFilename); + $PatternFilename = str_replace('" ', '” ', $PatternFilename.' '); + $PatternFilename = str_replace('"', '”', $PatternFilename); + $PatternFilename = str_replace(' ', ' ', $PatternFilename); + + $ParenthesesPairs = ['()', '[]', '{}']; + foreach ($ParenthesesPairs as $pair) { + + // multiple remixes are stored tab-seperated in the database. + // change "{2000 Version\tSomebody Remix}" into "{2000 Version} {Somebody Remix}" + while (preg_match('#^(.*)'.preg_quote($pair[0]).'([^'.preg_quote($pair[1]).']*)('."\t".')([^'.preg_quote($pair[0]).']*)'.preg_quote($pair[1]).'#', $PatternFilename, $matches)) { + $PatternFilename = $matches[1].$pair[0].$matches[2].$pair[1].' '.$pair[0].$matches[4].$pair[1]; + } + + // remove empty parenthesized pairs (probably where no track numbers, remix version, etc) + $PatternFilename = preg_replace('#'.preg_quote($pair).'#', '', $PatternFilename); + + // "[01] - Title With No Artist.mp3" ==> "[01] Title With No Artist.mp3" + $PatternFilename = preg_replace('#'.preg_quote($pair[1]).' +\- #', $pair[1].' ', $PatternFilename); + } + + // get rid of leading & trailing spaces if end items (artist or title for example) are missing + $PatternFilename = trim($PatternFilename, ' -'); + + if (! $PatternFilename) { + // no tags to create a filename from -- skip this file + continue; + } + $PatternFilename .= '.'.$row['fileformat']; + + $ActualFilename = basename($row['filename']); + if ($ActualFilename != $PatternFilename) { + $NotMatchedReasons = ''; + if (strtolower($ActualFilename) === strtolower($PatternFilename)) { + $NotMatchedReasons .= 'Aa '; + } elseif (RemoveAccents($ActualFilename) === RemoveAccents($PatternFilename)) { + $NotMatchedReasons .= 'ée '; + } + + $actualExt = '.'.fileextension($ActualFilename); + $patternExt = '.'.fileextension($PatternFilename); + $ActualFilenameNoExt = (($actualExt != '.') ? substr($ActualFilename, 0, 0 - strlen($actualExt)) : $ActualFilename); + $PatternFilenameNoExt = (($patternExt != '.') ? substr($PatternFilename, 0, 0 - strlen($patternExt)) : $PatternFilename); + + if (strpos($PatternFilenameNoExt, $ActualFilenameNoExt) !== false) { + $DifferenceBoldedName = str_replace($ActualFilenameNoExt, ''.$ActualFilenameNoExt.'', $PatternFilenameNoExt); + } else { + $ShortestNameLength = min(strlen($ActualFilenameNoExt), strlen($PatternFilenameNoExt)); + for ($DifferenceOffset = 0; $DifferenceOffset < $ShortestNameLength; $DifferenceOffset++) { + if ($ActualFilenameNoExt[$DifferenceOffset] !== $PatternFilenameNoExt[$DifferenceOffset]) { + break; + } + } + $DifferenceBoldedName = ''.substr($PatternFilenameNoExt, 0, $DifferenceOffset).''.substr($PatternFilenameNoExt, $DifferenceOffset); + } + $DifferenceBoldedName .= (($actualExt == $patternExt) ? ''.$patternExt.'' : $patternExt); + + echo ''; + echo ''; + echo ''; + echo ''; + + if (! empty($_REQUEST['autofix'])) { + $results = ''; + if (RenameFileFromTo($row['filename'], dirname($row['filename']).'/'.$PatternFilename, $results)) { + echo ''; + } else { + echo ''; + } + echo ''; + + $nonmatchingfilenames++; + } + } + echo '
viewWhyActual filename
(click to play/edit file)
Correct filename (based on tags)'.(empty($_REQUEST['autofix']) ? '
(click to rename file to this)' : '').'
view '.$NotMatchedReasons.''.htmlentities($ActualFilename).''; + } else { + echo ''; + } + echo ''.$DifferenceBoldedName.''; + echo ''.$DifferenceBoldedName.'

'; + echo 'Found '.number_format($nonmatchingfilenames).' files that do not match naming pattern
'; +} elseif (! empty($_REQUEST['encoderoptionsdistribution'])) { + if (isset($_REQUEST['showtagfiles'])) { + $SQLquery = 'SELECT `filename`, `encoder_options` FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`encoder_options` LIKE "'.mysql_real_escape_string($_REQUEST['showtagfiles']).'")'; + $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + + if (! empty($_REQUEST['m3u'])) { + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysql_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + } else { + echo 'Show all Encoder Options
'; + echo 'Files with Encoder Options '.$_REQUEST['showtagfiles'].':
'; + echo ''; + while ($row = mysql_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
'.htmlentities($row['filename']).''.$row['encoder_options'].'
'; + } + } elseif (! isset($_REQUEST['m3u'])) { + $SQLquery = 'SELECT `encoder_options`, COUNT(*) AS `num` FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' GROUP BY `encoder_options`'; + $SQLquery .= ' ORDER BY (`encoder_options` LIKE "LAME%") DESC, (`encoder_options` LIKE "CBR%") DESC, `num` DESC, `encoder_options` ASC'; + $result = mysql_query_safe($SQLquery); + echo 'Files with Encoder Options:
'; + echo ''; + echo ''; + while ($row = mysql_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
Encoder OptionsCountM3U
'.$row['encoder_options'].''.number_format($row['num']).'m3u

'; + } +} elseif (! empty($_REQUEST['tagtypes'])) { + if (! isset($_REQUEST['m3u'])) { + $SQLquery = 'SELECT `tags`, COUNT(*) AS `num` FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' GROUP BY `tags`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = mysql_query_safe($SQLquery); + echo 'Files with tags:
'; + echo ''; + echo ''; + while ($row = mysql_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
TagsCountM3U
'.$row['tags'].''.number_format($row['num']).'m3u

'; + } + + if (isset($_REQUEST['showtagfiles'])) { + $SQLquery = 'SELECT `filename`, `tags` FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`tags` LIKE "'.mysql_real_escape_string($_REQUEST['showtagfiles']).'")'; + $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + + if (! empty($_REQUEST['m3u'])) { + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysql_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + } else { + echo ''; + while ($row = mysql_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
'.htmlentities($row['filename']).''.$row['tags'].'
'; + } + } +} elseif (! empty($_REQUEST['md5datadupes'])) { + $OtherFormats = ''; + $AVFormats = ''; + + $SQLquery = 'SELECT `md5_data`, `filename`, COUNT(*) AS `num`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`md5_data` <> "")'; + $SQLquery .= ' GROUP BY `md5_data`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = mysql_query_safe($SQLquery); + while (($row = mysql_fetch_array($result)) && ($row['num'] > 1)) { + set_time_limit(30); + + $filenames = []; + $tags = []; + $md5_data = []; + $SQLquery = 'SELECT `fileformat`, `filename`, `tags`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`md5_data` = "'.mysql_real_escape_string($row['md5_data']).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result2 = mysql_query_safe($SQLquery); + while ($row2 = mysql_fetch_array($result2)) { + $thisfileformat = $row2['fileformat']; + $filenames[] = $row2['filename']; + $tags[] = $row2['tags']; + $md5_data[] = $row['md5_data']; + } + + $thisline = ''; + $thisline .= ''.implode('
', $md5_data).''; + $thisline .= ''.implode('
', $tags).''; + $thisline .= ''.implode('
', $filenames).''; + $thisline .= ''; + + if (in_array($thisfileformat, $IgnoreNoTagFormats)) { + $OtherFormats .= $thisline; + } else { + $AVFormats .= $thisline; + } + } + echo 'Duplicated MD5_DATA (Audio/Video files):'; + echo $AVFormats.'

'; + echo 'Duplicated MD5_DATA (Other files):'; + echo $OtherFormats.'

'; +} elseif (! empty($_REQUEST['artisttitledupes'])) { + if (isset($_REQUEST['m3uartist']) && isset($_REQUEST['m3utitle'])) { + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`artist` = "'.mysql_real_escape_string($_REQUEST['m3uartist']).'")'; + $SQLquery .= ' AND (`title` = "'.mysql_real_escape_string($_REQUEST['m3utitle']).'")'; + $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC'; + $result = mysql_query_safe($SQLquery); + while ($row = mysql_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + } + + $SQLquery = 'SELECT `artist`, `title`, `filename`, COUNT(*) AS `num`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`artist` <> "")'; + $SQLquery .= ' AND (`title` <> "")'; + $SQLquery .= ' GROUP BY `artist`, `title`'.(! empty($_REQUEST['samemix']) ? ', `remix`' : ''); + $SQLquery .= ' ORDER BY `num` DESC, `artist` ASC, `title` ASC, `playtime_seconds` ASC, `remix` ASC'; + $result = mysql_query_safe($SQLquery); + $uniquetitles = 0; + $uniquefiles = 0; + + if (! empty($_REQUEST['m3u'])) { + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while (($row = mysql_fetch_array($result)) && ($row['num'] > 1)) { + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`artist` = "'.mysql_real_escape_string($row['artist']).'")'; + $SQLquery .= ' AND (`title` = "'.mysql_real_escape_string($row['title']).'")'; + if (! empty($_REQUEST['samemix'])) { + $SQLquery .= ' AND (`remix` = "'.mysql_real_escape_string($row['remix']).'")'; + } + $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC'; + $result2 = mysql_query_safe($SQLquery); + while ($row2 = mysql_fetch_array($result2)) { + echo WindowsShareSlashTranslate($row2['filename'])."\n"; + } + } + exit; + } else { + echo 'Duplicated aritst + title: (Identical Mix/Version only)
'; + echo '(.m3u version)
'; + echo ''; + echo ''; + + while (($row = mysql_fetch_array($result)) && ($row['num'] > 1)) { + $uniquetitles++; + set_time_limit(30); + + $filenames = []; + $artists = []; + $titles = []; + $remixes = []; + $bitrates = []; + $playtimes = []; + $SQLquery = 'SELECT `filename`, `artist`, `title`, `remix`, `audio_bitrate`, `vbr_method`, `playtime_seconds`, `encoder_options`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`artist` = "'.mysql_real_escape_string($row['artist']).'")'; + $SQLquery .= ' AND (`title` = "'.mysql_real_escape_string($row['title']).'")'; + $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC'; + $result2 = mysql_query_safe($SQLquery); + while ($row2 = mysql_fetch_array($result2)) { + $uniquefiles++; + $filenames[] = $row2['filename']; + $artists[] = $row2['artist']; + $titles[] = $row2['title']; + $remixes[] = $row2['remix']; + if ($row2['vbr_method']) { + $bitrates[] = ''.BitrateText($row2['audio_bitrate'] / 1000).''; + } else { + $bitrates[] = BitrateText($row2['audio_bitrate'] / 1000); + } + $playtimes[] = getid3_lib::PlaytimeString($row2['playtime_seconds']); + } + + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + echo ''; + + echo ''; + } + } + echo '
 ArtistTitleVersion  Filename
'; + foreach ($filenames as $file) { + echo 'delete
'; + } + echo '
'; + foreach ($filenames as $file) { + echo 'play
'; + } + echo '
play all'.implode('
', $artists).'
'.implode('
', $titles).'
'.implode('
', $remixes).'
'.implode('
', $bitrates).'
'.implode('
', $playtimes).'
'; + foreach ($filenames as $file) { + echo ''; + } + echo '
'.dirname($file).'/'.basename($file).'
'; + echo number_format($uniquefiles).' files with '.number_format($uniquetitles).' unique aritst + title
'; + echo '
'; +} elseif (! empty($_REQUEST['filetypelist'])) { + list($fileformat, $audioformat) = explode('|', $_REQUEST['filetypelist']); + $SQLquery = 'SELECT `filename`, `fileformat`, `audio_dataformat`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` = "'.mysql_real_escape_string($fileformat).'")'; + $SQLquery .= ' AND (`audio_dataformat` = "'.mysql_real_escape_string($audioformat).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + echo 'Files of format '.$fileformat.'.'.$audioformat.':'; + echo ''; + while ($row = mysql_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
fileaudiofilename
'.$row['fileformat'].''.$row['audio_dataformat'].''.htmlentities($row['filename']).'

'; +} elseif (! empty($_REQUEST['trackinalbum'])) { + $SQLquery = 'SELECT `filename`, `album`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`album` LIKE "% [%")'; + $SQLquery .= ' ORDER BY `album` ASC, `filename` ASC'; + $result = mysql_query_safe($SQLquery); + if (! empty($_REQUEST['m3u'])) { + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysql_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + } elseif (! empty($_REQUEST['autofix'])) { + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true); + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); + + while ($row = mysql_fetch_array($result)) { + set_time_limit(30); + $ThisFileInfo = $getID3->analyze($filename); + getid3_lib::CopyTagsToComments($ThisFileInfo); + + if (! empty($ThisFileInfo['tags'])) { + $Album = trim(str_replace(strstr($ThisFileInfo['comments']['album'][0], ' ['), '', $ThisFileInfo['comments']['album'][0])); + $Track = (string) intval(str_replace(' [', '', str_replace(']', '', strstr($ThisFileInfo['comments']['album'][0], ' [')))); + if ($Track == '0') { + $Track = ''; + } + if ($Album && $Track) { + echo '
'.htmlentities($row['filename']).'
'; + echo ''.htmlentities($Album).' (track #'.$Track.')
'; + echo 'ID3v2: '.(RemoveID3v2($row['filename'], false) ? 'removed' : 'REMOVAL FAILED!').', '; + $WriteID3v1_title = (isset($ThisFileInfo['comments']['title'][0]) ? $ThisFileInfo['comments']['title'][0] : ''); + $WriteID3v1_artist = (isset($ThisFileInfo['comments']['artist'][0]) ? $ThisFileInfo['comments']['artist'][0] : ''); + $WriteID3v1_year = (isset($ThisFileInfo['comments']['year'][0]) ? $ThisFileInfo['comments']['year'][0] : ''); + $WriteID3v1_comment = (isset($ThisFileInfo['comments']['comment'][0]) ? $ThisFileInfo['comments']['comment'][0] : ''); + $WriteID3v1_genreid = (isset($ThisFileInfo['comments']['genreid'][0]) ? $ThisFileInfo['comments']['genreid'][0] : ''); + echo 'ID3v1: '.(WriteID3v1($row['filename'], $WriteID3v1_title, $WriteID3v1_artist, $Album, $WriteID3v1_year, $WriteID3v1_comment, $WriteID3v1_genreid, $Track, false) ? 'updated' : 'UPDATE FAILED').'
'; + } else { + echo ' . '; + } + } else { + echo '
FAILED
'.htmlentities($row['filename']).'
'; + } + flush(); + } + } else { + echo ''.number_format(mysql_num_rows($result)).' files with [??]-format track numbers in album field:
'; + if (mysql_num_rows($result) > 0) { + echo '(.m3u version)
'; + echo 'Try to auto-fix
'; + echo ''; + while ($row = mysql_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
'.$row['album'].''.htmlentities($row['filename']).'
'; + } + echo '
'; + } +} elseif (! empty($_REQUEST['fileextensions'])) { + $SQLquery = 'SELECT `filename`, `fileformat`, `audio_dataformat`, `video_dataformat`, `tags`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + $invalidextensionfiles = 0; + $invalidextensionline = ''; + $invalidextensionline .= ''; + while ($row = mysql_fetch_array($result)) { + set_time_limit(30); + + $acceptableextensions = AcceptableExtensions($row['fileformat'], $row['audio_dataformat'], $row['video_dataformat']); + $actualextension = strtolower(fileextension($row['filename'])); + if ($acceptableextensions && ! in_array($actualextension, $acceptableextensions)) { + $invalidextensionfiles++; + + $invalidextensionline .= ''; + $invalidextensionline .= ''; + $invalidextensionline .= ''; + $invalidextensionline .= ''; + $invalidextensionline .= ''; + $invalidextensionline .= ''; + $invalidextensionline .= ''; + $invalidextensionline .= ''; + $invalidextensionline .= ''; + } + } + $invalidextensionline .= '
fileaudiovideotagsactualcorrectfilename
'.$row['fileformat'].''.$row['audio_dataformat'].''.$row['video_dataformat'].''.$row['tags'].''.$actualextension.''.implode('; ', $acceptableextensions).''.htmlentities($row['filename']).'

'; + echo number_format($invalidextensionfiles).' files with incorrect filename extension:
'; + echo $invalidextensionline; } elseif (isset($_REQUEST['genredistribution'])) { + if (! empty($_REQUEST['m3u'])) { + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (BINARY `genre` = "'.$_REQUEST['genredistribution'].'")'; + $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + while ($row = mysql_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + } else { + if ($_REQUEST['genredistribution'] == '%') { + $SQLquery = 'SELECT COUNT(*) AS `num`, `genre`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' GROUP BY `genre`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = mysql_query_safe($SQLquery); + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true); + echo ''; + echo ''; + while ($row = mysql_fetch_array($result)) { + $GenreID = getid3_id3v1::LookupGenreID($row['genre']); + if (is_numeric($GenreID)) { + echo ''; + } else { + echo ''; + } + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
CountGenrem3u
'.number_format($row['num']).''.str_replace("\t", '
', $row['genre']).'
.m3u

'; + } else { + $SQLquery = 'SELECT `filename`, `genre`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`genre` LIKE "'.mysql_real_escape_string($_REQUEST['genredistribution']).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + echo 'All Genres
'; + echo ''; + echo ''; + while ($row = mysql_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
Genrem3uFilename
'.str_replace("\t", '
', $row['genre']).'
m3u'.htmlentities($row['filename']).'

'; + } + } +} elseif (! empty($_REQUEST['formatdistribution'])) { + $SQLquery = 'SELECT `fileformat`, `audio_dataformat`, COUNT(*) AS `num`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' GROUP BY `fileformat`, `audio_dataformat`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = mysql_query_safe($SQLquery); + echo 'File format distribution:'; + echo ''; + while ($row = mysql_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
NumberFormat
'.number_format($row['num']).''.($row['fileformat'] ? $row['fileformat'] : 'unknown').(($row['audio_dataformat'] && ($row['audio_dataformat'] != $row['fileformat'])) ? '.'.$row['audio_dataformat'] : '').'

'; +} elseif (! empty($_REQUEST['errorswarnings'])) { + $SQLquery = 'SELECT `filename`, `error`, `warning`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`error` <> "")'; + $SQLquery .= ' OR (`warning` <> "")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); - if (!empty($_REQUEST['m3u'])) { - - header('Content-type: audio/x-mpegurl'); - echo '#EXTM3U'."\n"; - $SQLquery = 'SELECT `filename`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (BINARY `genre` = "'.$_REQUEST['genredistribution'].'")'; - $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - while ($row = mysql_fetch_array($result)) { - echo WindowsShareSlashTranslate($row['filename'])."\n"; - } - exit; - - } else { - - if ($_REQUEST['genredistribution'] == '%') { - - $SQLquery = 'SELECT COUNT(*) AS `num`, `genre`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; - $SQLquery .= ' GROUP BY `genre`'; - $SQLquery .= ' ORDER BY `num` DESC'; - $result = mysql_query_safe($SQLquery); - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true); - echo ''; - echo ''; - while ($row = mysql_fetch_array($result)) { - $GenreID = getid3_id3v1::LookupGenreID($row['genre']); - if (is_numeric($GenreID)) { - echo ''; - } else { - echo ''; - } - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
CountGenrem3u
'.number_format($row['num']).''.str_replace("\t", '
', $row['genre']).'
.m3u

'; - - } else { - - $SQLquery = 'SELECT `filename`, `genre`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`genre` LIKE "'.mysql_real_escape_string($_REQUEST['genredistribution']).'")'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - echo 'All Genres
'; - echo ''; - echo ''; - while ($row = mysql_fetch_array($result)) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
Genrem3uFilename
'.str_replace("\t", '
', $row['genre']).'
m3u'.htmlentities($row['filename']).'

'; - - } - - - } - -} elseif (!empty($_REQUEST['formatdistribution'])) { - - $SQLquery = 'SELECT `fileformat`, `audio_dataformat`, COUNT(*) AS `num`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' GROUP BY `fileformat`, `audio_dataformat`'; - $SQLquery .= ' ORDER BY `num` DESC'; - $result = mysql_query_safe($SQLquery); - echo 'File format distribution:'; - echo ''; - while ($row = mysql_fetch_array($result)) { - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
NumberFormat
'.number_format($row['num']).''.($row['fileformat'] ? $row['fileformat'] : 'unknown').(($row['audio_dataformat'] && ($row['audio_dataformat'] != $row['fileformat'])) ? '.'.$row['audio_dataformat'] : '').'

'; - -} elseif (!empty($_REQUEST['errorswarnings'])) { - - $SQLquery = 'SELECT `filename`, `error`, `warning`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`error` <> "")'; - $SQLquery .= ' OR (`warning` <> "")'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - - if (!empty($_REQUEST['m3u'])) { - - header('Content-type: audio/x-mpegurl'); - echo '#EXTM3U'."\n"; - while ($row = mysql_fetch_array($result)) { - echo WindowsShareSlashTranslate($row['filename'])."\n"; - } - exit; - - } else { - - echo number_format(mysql_num_rows($result)).' files with errors or warnings:
'; - echo '(.m3u version)
'; - echo ''; - echo ''; - while ($row = mysql_fetch_array($result)) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - } - echo '
FilenameErrorWarning
'.htmlentities($row['filename']).''.(!empty($row['error']) ? '
  • '.str_replace("\t", '
  • ', htmlentities($row['error'])).'
  • ' : ' ').'
    '.(!empty($row['warning']) ? '
  • '.str_replace("\t", '
  • ', htmlentities($row['warning'])).'
  • ' : ' ').'

    '; - -} elseif (!empty($_REQUEST['fixid3v1padding'])) { - - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.id3v1.php', __FILE__, true); - $id3v1_writer = new getid3_write_id3v1; - - $SQLquery = 'SELECT `filename`, `error`, `warning`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`fileformat` = "mp3")'; - $SQLquery .= ' AND (`warning` <> "")'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - $totaltofix = mysql_num_rows($result); - $rowcounter = 0; - while ($row = mysql_fetch_array($result)) { - set_time_limit(30); - if (strpos($row['warning'], 'Some ID3v1 fields do not use NULL characters for padding') !== false) { - set_time_limit(30); - $id3v1_writer->filename = $row['filename']; - echo ($id3v1_writer->FixID3v1Padding() ? 'fixed - ' : 'error - '); - } else { - echo 'No error? - '; - } - echo '['.++$rowcounter.' / '.$totaltofix.'] '; - echo htmlentities($row['filename']).'
    '; - flush(); - } - -} elseif (!empty($_REQUEST['vbrmethod'])) { - - if ($_REQUEST['vbrmethod'] == '1') { - - $SQLquery = 'SELECT COUNT(*) AS `num`, `vbr_method`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' GROUP BY `vbr_method`'; - $SQLquery .= ' ORDER BY `vbr_method`'; - $result = mysql_query_safe($SQLquery); - echo 'VBR methods:'; - echo ''; - while ($row = mysql_fetch_array($result)) { - echo ''; - echo ''; - if ($row['vbr_method']) { - echo ''; - } else { - echo ''; - } - echo ''; - } - echo '
    CountVBR Method
    '.htmlentities(number_format($row['num'])).''.htmlentities($row['vbr_method']).'CBR
    '; - - } else { - - $SQLquery = 'SELECT `filename`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`vbr_method` = "'.mysql_real_escape_string($_REQUEST['vbrmethod']).'")'; - $result = mysql_query_safe($SQLquery); - echo number_format(mysql_num_rows($result)).' files with VBR_method of "'.$_REQUEST['vbrmethod'].'":'; - while ($row = mysql_fetch_array($result)) { - echo ''; - echo ''; - } - echo '
    m3u'.htmlentities($row['filename']).'
    '; - - } - echo '
    '; - -} elseif (!empty($_REQUEST['correctcase'])) { - - $SQLquery = 'SELECT `filename`, `fileformat`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; - $SQLquery .= ' WHERE (`fileformat` <> "")'; - $SQLquery .= ' ORDER BY `filename` ASC'; - $result = mysql_query_safe($SQLquery); - echo 'Copy and paste the following into a DOS batch file. You may have to run this script more than once to catch all the changes (remember to scan for deleted/changed files and rescan directory between scans)
    '; - echo '
    ';
    -	$lastdir = '';
    -	while ($row = mysql_fetch_array($result)) {
    -		set_time_limit(30);
    -		$CleanedFilename = CleanUpFileName($row['filename']);
    -		if ($row['filename'] != $CleanedFilename) {
    -			if (strtolower($lastdir) != strtolower(str_replace('/', '\\', dirname($row['filename'])))) {
    -				$lastdir = str_replace('/', '\\', dirname($row['filename']));
    -				echo 'cd "'.$lastdir.'"'."\n";
    -			}
    -			echo 'ren "'.basename($row['filename']).'" "'.basename(CleanUpFileName($row['filename'])).'"'."\n";
    -		}
    -	}
    -	echo '
    '; - echo '
    '; + if (! empty($_REQUEST['m3u'])) { + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysql_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + } else { + echo number_format(mysql_num_rows($result)).' files with errors or warnings:
    '; + echo '(.m3u version)
    '; + echo ''; + echo ''; + while ($row = mysql_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + } + echo '
    FilenameErrorWarning
    '.htmlentities($row['filename']).''.(! empty($row['error']) ? '
  • '.str_replace("\t", '
  • ', htmlentities($row['error'])).'
  • ' : ' ').'
    '.(! empty($row['warning']) ? '
  • '.str_replace("\t", '
  • ', htmlentities($row['warning'])).'
  • ' : ' ').'

    '; +} elseif (! empty($_REQUEST['fixid3v1padding'])) { + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.id3v1.php', __FILE__, true); + $id3v1_writer = new getid3_write_id3v1; + $SQLquery = 'SELECT `filename`, `error`, `warning`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` = "mp3")'; + $SQLquery .= ' AND (`warning` <> "")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + $totaltofix = mysql_num_rows($result); + $rowcounter = 0; + while ($row = mysql_fetch_array($result)) { + set_time_limit(30); + if (strpos($row['warning'], 'Some ID3v1 fields do not use NULL characters for padding') !== false) { + set_time_limit(30); + $id3v1_writer->filename = $row['filename']; + echo $id3v1_writer->FixID3v1Padding() ? 'fixed - ' : 'error - '; + } else { + echo 'No error? - '; + } + echo '['.++$rowcounter.' / '.$totaltofix.'] '; + echo htmlentities($row['filename']).'
    '; + flush(); + } +} elseif (! empty($_REQUEST['vbrmethod'])) { + if ($_REQUEST['vbrmethod'] == '1') { + $SQLquery = 'SELECT COUNT(*) AS `num`, `vbr_method`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' GROUP BY `vbr_method`'; + $SQLquery .= ' ORDER BY `vbr_method`'; + $result = mysql_query_safe($SQLquery); + echo 'VBR methods:'; + echo ''; + while ($row = mysql_fetch_array($result)) { + echo ''; + echo ''; + if ($row['vbr_method']) { + echo ''; + } else { + echo ''; + } + echo ''; + } + echo '
    CountVBR Method
    '.htmlentities(number_format($row['num'])).''.htmlentities($row['vbr_method']).'CBR
    '; + } else { + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`vbr_method` = "'.mysql_real_escape_string($_REQUEST['vbrmethod']).'")'; + $result = mysql_query_safe($SQLquery); + echo number_format(mysql_num_rows($result)).' files with VBR_method of "'.$_REQUEST['vbrmethod'].'":'; + while ($row = mysql_fetch_array($result)) { + echo ''; + echo ''; + } + echo '
    m3u'.htmlentities($row['filename']).'
    '; + } + echo '
    '; +} elseif (! empty($_REQUEST['correctcase'])) { + $SQLquery = 'SELECT `filename`, `fileformat`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` <> "")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysql_query_safe($SQLquery); + echo 'Copy and paste the following into a DOS batch file. You may have to run this script more than once to catch all the changes (remember to scan for deleted/changed files and rescan directory between scans)
    '; + echo '
    ';
    +    $lastdir = '';
    +    while ($row = mysql_fetch_array($result)) {
    +        set_time_limit(30);
    +        $CleanedFilename = CleanUpFileName($row['filename']);
    +        if ($row['filename'] != $CleanedFilename) {
    +            if (strtolower($lastdir) != strtolower(str_replace('/', '\\', dirname($row['filename'])))) {
    +                $lastdir = str_replace('/', '\\', dirname($row['filename']));
    +                echo 'cd "'.$lastdir.'"'."\n";
    +            }
    +            echo 'ren "'.basename($row['filename']).'" "'.basename(CleanUpFileName($row['filename'])).'"'."\n";
    +        }
    +    }
    +    echo '
    '; + echo '
    '; } -function CleanUpFileName($filename) { - $DirectoryName = dirname($filename); - $FileExtension = fileextension(basename($filename)); - $BaseFilename = basename($filename, '.'.$FileExtension); +function CleanUpFileName($filename) +{ + $DirectoryName = dirname($filename); + $FileExtension = fileextension(basename($filename)); + $BaseFilename = basename($filename, '.'.$FileExtension); - $BaseFilename = strtolower($BaseFilename); - $BaseFilename = str_replace('_', ' ', $BaseFilename); - //$BaseFilename = str_replace('-', ' - ', $BaseFilename); - $BaseFilename = str_replace('(', ' (', $BaseFilename); - $BaseFilename = str_replace('( ', '(', $BaseFilename); - $BaseFilename = str_replace(')', ') ', $BaseFilename); - $BaseFilename = str_replace(' )', ')', $BaseFilename); - $BaseFilename = str_replace(' \'\'', ' “', $BaseFilename); - $BaseFilename = str_replace('\'\' ', '” ', $BaseFilename); - $BaseFilename = str_replace(' vs ', ' vs. ', $BaseFilename); - while (strstr($BaseFilename, ' ') !== false) { - $BaseFilename = str_replace(' ', ' ', $BaseFilename); - } - $BaseFilename = trim($BaseFilename); + $BaseFilename = strtolower($BaseFilename); + $BaseFilename = str_replace('_', ' ', $BaseFilename); + //$BaseFilename = str_replace('-', ' - ', $BaseFilename); + $BaseFilename = str_replace('(', ' (', $BaseFilename); + $BaseFilename = str_replace('( ', '(', $BaseFilename); + $BaseFilename = str_replace(')', ') ', $BaseFilename); + $BaseFilename = str_replace(' )', ')', $BaseFilename); + $BaseFilename = str_replace(' \'\'', ' “', $BaseFilename); + $BaseFilename = str_replace('\'\' ', '” ', $BaseFilename); + $BaseFilename = str_replace(' vs ', ' vs. ', $BaseFilename); + while (strstr($BaseFilename, ' ') !== false) { + $BaseFilename = str_replace(' ', ' ', $BaseFilename); + } + $BaseFilename = trim($BaseFilename); - return $DirectoryName.'/'.BetterUCwords($BaseFilename).'.'.strtolower($FileExtension); + return $DirectoryName.'/'.BetterUCwords($BaseFilename).'.'.strtolower($FileExtension); } -function BetterUCwords($string) { - $stringlength = strlen($string); +function BetterUCwords($string) +{ + $stringlength = strlen($string); - $string{0} = strtoupper($string{0}); - for ($i = 1; $i < $stringlength; $i++) { - if (($string{$i - 1} == '\'') && ($i > 1) && (($string{$i - 2} == 'O') || ($string{$i - 2} == ' '))) { - // O'Clock, 'Em - $string{$i} = strtoupper($string{$i}); - } elseif (preg_match('#^[\'A-Za-z0-9À-ÿ]$#', $string{$i - 1})) { - $string{$i} = strtolower($string{$i}); - } else { - $string{$i} = strtoupper($string{$i}); - } - } + $string[0] = strtoupper($string[0]); + for ($i = 1; $i < $stringlength; $i++) { + if (($string[$i - 1] == '\'') && ($i > 1) && (($string[$i - 2] == 'O') || ($string[$i - 2] == ' '))) { + // O'Clock, 'Em + $string[$i] = strtoupper($string[$i]); + } elseif (preg_match('#^[\'A-Za-z0-9À-ÿ]$#', $string[$i - 1])) { + $string[$i] = strtolower($string[$i]); + } else { + $string[$i] = strtoupper($string[$i]); + } + } - static $LowerCaseWords = array('vs.', 'feat.'); - static $UpperCaseWords = array('DJ', 'USA', 'II', 'MC', 'CD', 'TV', '\'N\''); + static $LowerCaseWords = ['vs.', 'feat.']; + static $UpperCaseWords = ['DJ', 'USA', 'II', 'MC', 'CD', 'TV', '\'N\'']; - $OutputListOfWords = array(); - $ListOfWords = explode(' ', $string); - foreach ($ListOfWords as $ThisWord) { - if (in_array(strtolower(str_replace('(', '', $ThisWord)), $LowerCaseWords)) { - $ThisWord = strtolower($ThisWord); - } elseif (in_array(strtoupper(str_replace('(', '', $ThisWord)), $UpperCaseWords)) { - $ThisWord = strtoupper($ThisWord); - } elseif ((substr($ThisWord, 0, 2) == 'Mc') && (strlen($ThisWord) > 2)) { - $ThisWord{2} = strtoupper($ThisWord{2}); - } elseif ((substr($ThisWord, 0, 3) == 'Mac') && (strlen($ThisWord) > 3)) { - $ThisWord{3} = strtoupper($ThisWord{3}); - } - $OutputListOfWords[] = $ThisWord; - } - $UCstring = implode(' ', $OutputListOfWords); - $UCstring = str_replace(' From “', ' from “', $UCstring); - $UCstring = str_replace(' \'n\' ', ' \'N\' ', $UCstring); + $OutputListOfWords = []; + $ListOfWords = explode(' ', $string); + foreach ($ListOfWords as $ThisWord) { + if (in_array(strtolower(str_replace('(', '', $ThisWord)), $LowerCaseWords)) { + $ThisWord = strtolower($ThisWord); + } elseif (in_array(strtoupper(str_replace('(', '', $ThisWord)), $UpperCaseWords)) { + $ThisWord = strtoupper($ThisWord); + } elseif ((substr($ThisWord, 0, 2) == 'Mc') && (strlen($ThisWord) > 2)) { + $ThisWord[2] = strtoupper($ThisWord[2]); + } elseif ((substr($ThisWord, 0, 3) == 'Mac') && (strlen($ThisWord) > 3)) { + $ThisWord[3] = strtoupper($ThisWord[3]); + } + $OutputListOfWords[] = $ThisWord; + } + $UCstring = implode(' ', $OutputListOfWords); + $UCstring = str_replace(' From “', ' from “', $UCstring); + $UCstring = str_replace(' \'n\' ', ' \'N\' ', $UCstring); - return $UCstring; + return $UCstring; } - - echo '
    '; echo 'Warning: Scanning a new directory will erase all previous entries in the database!
    '; -echo 'Directory: '; +echo 'Directory: '; echo ''; echo '
    '; echo '
    '; echo 'Re-scanning a new directory will only add new, previously unscanned files into the list (and not erase the database).
    '; -echo 'Directory: '; +echo 'Directory: '; echo ''; echo '

    '; echo ''; -$SQLquery = 'SELECT COUNT(*) AS `TotalFiles`, SUM(`playtime_seconds`) AS `TotalPlaytime`, SUM(`filesize`) AS `TotalFilesize`, AVG(`playtime_seconds`) AS `AvgPlaytime`, AVG(`filesize`) AS `AvgFilesize`, AVG(`audio_bitrate` + `video_bitrate`) AS `AvgBitrate`'; +$SQLquery = 'SELECT COUNT(*) AS `TotalFiles`, SUM(`playtime_seconds`) AS `TotalPlaytime`, SUM(`filesize`) AS `TotalFilesize`, AVG(`playtime_seconds`) AS `AvgPlaytime`, AVG(`filesize`) AS `AvgFilesize`, AVG(`audio_bitrate` + `video_bitrate`) AS `AvgBitrate`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $result = mysql_query_safe($SQLquery); if ($row = mysql_fetch_array($result)) { - echo '
    '; - echo '
    '; - echo 'Spent '.number_format(mysql_query_safe(null), 3).' seconds querying the database
    '; - echo '
    '; - echo 'Currently in the database:'; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo '
    Total Files'.number_format($row['TotalFiles']).'
    Total Filesize'.number_format($row['TotalFilesize'] / 1048576).' MB
    Total Playtime'.number_format($row['TotalPlaytime'] / 3600, 1).' hours
    Average Filesize'.number_format($row['AvgFilesize'] / 1048576, 1).' MB
    Average Playtime'.getid3_lib::PlaytimeString($row['AvgPlaytime']).'
    Average Bitrate'.BitrateText($row['AvgBitrate'] / 1000, 1).'
    '; - echo '
    '; + echo '
    '; + echo '
    '; + echo 'Spent '.number_format(mysql_query_safe(null), 3).' seconds querying the database
    '; + echo '
    '; + echo 'Currently in the database:'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
    Total Files'.number_format($row['TotalFiles']).'
    Total Filesize'.number_format($row['TotalFilesize'] / 1048576).' MB
    Total Playtime'.number_format($row['TotalPlaytime'] / 3600, 1).' hours
    Average Filesize'.number_format($row['AvgFilesize'] / 1048576, 1).' MB
    Average Playtime'.getid3_lib::PlaytimeString($row['AvgPlaytime']).'
    Average Bitrate'.BitrateText($row['AvgBitrate'] / 1000, 1).'
    '; + echo '
    '; } -echo ''; \ No newline at end of file +echo ''; diff --git a/app/Library/getid3/demos/demo.simple.php b/app/Library/getid3/demos/demo.simple.php index dbaf7bb6..2abf402f 100644 --- a/app/Library/getid3/demos/demo.simple.php +++ b/app/Library/getid3/demos/demo.simple.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -20,9 +21,8 @@ echo 'getID3() - /demo/demo.simple.php (sample script)'; echo ''; echo ''; - // include getID3() library (can be in a different directory if full path is specified) -require_once('../getid3/getid3.php'); +require_once '../getid3/getid3.php'; // Initialize getID3 engine $getID3 = new getID3; @@ -32,24 +32,24 @@ $dir = opendir($DirectoryToScan); echo ''; echo ''; while (($file = readdir($dir)) !== false) { - $FullFileName = realpath($DirectoryToScan.'/'.$file); - if ((substr($file, 0, 1) != '.') && is_file($FullFileName)) { - set_time_limit(30); + $FullFileName = realpath($DirectoryToScan.'/'.$file); + if ((substr($file, 0, 1) != '.') && is_file($FullFileName)) { + set_time_limit(30); - $ThisFileInfo = $getID3->analyze($FullFileName); + $ThisFileInfo = $getID3->analyze($FullFileName); - getid3_lib::CopyTagsToComments($ThisFileInfo); + getid3_lib::CopyTagsToComments($ThisFileInfo); - // output desired information in whatever format you want - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } + // output desired information in whatever format you want + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } } echo '
    FilenameArtistTitleBitratePlaytime
    '.htmlentities($ThisFileInfo['filenamepath']).'' .htmlentities(!empty($ThisFileInfo['comments_html']['artist']) ? implode('
    ', $ThisFileInfo['comments_html']['artist']) : chr(160)).'
    ' .htmlentities(!empty($ThisFileInfo['comments_html']['title']) ? implode('
    ', $ThisFileInfo['comments_html']['title']) : chr(160)).'
    '.htmlentities(!empty($ThisFileInfo['audio']['bitrate']) ? round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps' : chr(160)).''.htmlentities(!empty($ThisFileInfo['playtime_string']) ? $ThisFileInfo['playtime_string'] : chr(160)).'
    '.htmlentities($ThisFileInfo['filenamepath']).''.htmlentities(! empty($ThisFileInfo['comments_html']['artist']) ? implode('
    ', $ThisFileInfo['comments_html']['artist']) : chr(160)).'
    '.htmlentities(! empty($ThisFileInfo['comments_html']['title']) ? implode('
    ', $ThisFileInfo['comments_html']['title']) : chr(160)).'
    '.htmlentities(! empty($ThisFileInfo['audio']['bitrate']) ? round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps' : chr(160)).''.htmlentities(! empty($ThisFileInfo['playtime_string']) ? $ThisFileInfo['playtime_string'] : chr(160)).'
    '; -echo ''; \ No newline at end of file +echo ''; diff --git a/app/Library/getid3/demos/demo.simple.write.php b/app/Library/getid3/demos/demo.simple.write.php index 8e8b4261..5ae0c6a3 100644 --- a/app/Library/getid3/demos/demo.simple.write.php +++ b/app/Library/getid3/demos/demo.simple.write.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -16,46 +17,46 @@ die('Due to a security issue, this demo has been disabled. It can be enabled by $TextEncoding = 'UTF-8'; -require_once('../getid3/getid3.php'); +require_once '../getid3/getid3.php'; // Initialize getID3 engine $getID3 = new getID3; -$getID3->setOption(array('encoding'=>$TextEncoding)); +$getID3->setOption(['encoding'=>$TextEncoding]); -require_once('../getid3/write.php'); +require_once '../getid3/write.php'; // Initialize getID3 tag-writing module $tagwriter = new getid3_writetags; //$tagwriter->filename = '/path/to/file.mp3'; $tagwriter->filename = 'c:/file.mp3'; //$tagwriter->tagformats = array('id3v1', 'id3v2.3'); -$tagwriter->tagformats = array('id3v2.3'); +$tagwriter->tagformats = ['id3v2.3']; // set various options (optional) -$tagwriter->overwrite_tags = true; // if true will erase existing tag data and write only passed data; if false will merge passed data with existing tag data (experimental) +$tagwriter->overwrite_tags = true; // if true will erase existing tag data and write only passed data; if false will merge passed data with existing tag data (experimental) $tagwriter->remove_other_tags = false; // if true removes other tag formats (e.g. ID3v1, ID3v2, APE, Lyrics3, etc) that may be present in the file and only write the specified tag format(s). If false leaves any unspecified tag formats as-is. -$tagwriter->tag_encoding = $TextEncoding; +$tagwriter->tag_encoding = $TextEncoding; $tagwriter->remove_other_tags = true; // populate data array -$TagData = array( - 'title' => array('My Song'), - 'artist' => array('The Artist'), - 'album' => array('Greatest Hits'), - 'year' => array('2004'), - 'genre' => array('Rock'), - 'comment' => array('excellent!'), - 'track' => array('04/16'), - 'popularimeter' => array('email'=>'user@example.net', 'rating'=>128, 'data'=>0), - 'unique_file_identifier' => array('ownerid'=>'user@example.net', 'data'=>md5(time())), -); +$TagData = [ + 'title' => ['My Song'], + 'artist' => ['The Artist'], + 'album' => ['Greatest Hits'], + 'year' => ['2004'], + 'genre' => ['Rock'], + 'comment' => ['excellent!'], + 'track' => ['04/16'], + 'popularimeter' => ['email'=>'user@example.net', 'rating'=>128, 'data'=>0], + 'unique_file_identifier' => ['ownerid'=>'user@example.net', 'data'=>md5(time())], +]; $tagwriter->tag_data = $TagData; // write tags if ($tagwriter->WriteTags()) { - echo 'Successfully wrote tags
    '; - if (!empty($tagwriter->warnings)) { - echo 'There were some warnings:
    '.implode('

    ', $tagwriter->warnings); - } + echo 'Successfully wrote tags
    '; + if (! empty($tagwriter->warnings)) { + echo 'There were some warnings:
    '.implode('

    ', $tagwriter->warnings); + } } else { - echo 'Failed to write tags!
    '.implode('

    ', $tagwriter->errors); + echo 'Failed to write tags!
    '.implode('

    ', $tagwriter->errors); } diff --git a/app/Library/getid3/demos/demo.write.php b/app/Library/getid3/demos/demo.write.php index c15394b3..e90b5b1b 100644 --- a/app/Library/getid3/demos/demo.write.php +++ b/app/Library/getid3/demos/demo.write.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -13,7 +14,6 @@ // /// ///////////////////////////////////////////////////////////////// - die('Due to a security issue, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in '.$_SERVER['PHP_SELF']); $TaggingFormat = 'UTF-8'; @@ -22,10 +22,10 @@ header('Content-Type: text/html; charset='.$TaggingFormat); echo ''; echo 'getID3() - Sample tag writer'; -require_once('../getid3/getid3.php'); +require_once '../getid3/getid3.php'; // Initialize getID3 engine $getID3 = new getID3; -$getID3->setOption(array('encoding'=>$TaggingFormat)); +$getID3->setOption(['encoding'=>$TaggingFormat]); getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.php', __FILE__, true); @@ -33,239 +33,225 @@ $browsescriptfilename = 'demo.browse.php'; $Filename = (isset($_REQUEST['Filename']) ? $_REQUEST['Filename'] : ''); - - if (isset($_POST['WriteTags'])) { + $TagFormatsToWrite = (isset($_POST['TagFormatsToWrite']) ? $_POST['TagFormatsToWrite'] : []); + if (! empty($TagFormatsToWrite)) { + echo 'starting to write tag(s)
    '; - $TagFormatsToWrite = (isset($_POST['TagFormatsToWrite']) ? $_POST['TagFormatsToWrite'] : array()); - if (!empty($TagFormatsToWrite)) { - echo 'starting to write tag(s)
    '; + $tagwriter = new getid3_writetags; + $tagwriter->filename = $Filename; + $tagwriter->tagformats = $TagFormatsToWrite; + $tagwriter->overwrite_tags = false; + $tagwriter->tag_encoding = $TaggingFormat; + if (! empty($_POST['remove_other_tags'])) { + $tagwriter->remove_other_tags = true; + } - $tagwriter = new getid3_writetags; - $tagwriter->filename = $Filename; - $tagwriter->tagformats = $TagFormatsToWrite; - $tagwriter->overwrite_tags = false; - $tagwriter->tag_encoding = $TaggingFormat; - if (!empty($_POST['remove_other_tags'])) { - $tagwriter->remove_other_tags = true; - } + $commonkeysarray = ['Title', 'Artist', 'Album', 'Year', 'Comment']; + foreach ($commonkeysarray as $key) { + if (! empty($_POST[$key])) { + $TagData[strtolower($key)][] = $_POST[$key]; + } + } + if (! empty($_POST['Genre'])) { + $TagData['genre'][] = $_POST['Genre']; + } + if (! empty($_POST['GenreOther'])) { + $TagData['genre'][] = $_POST['GenreOther']; + } + if (! empty($_POST['Track'])) { + $TagData['track'][] = $_POST['Track'].(! empty($_POST['TracksTotal']) ? '/'.$_POST['TracksTotal'] : ''); + } - $commonkeysarray = array('Title', 'Artist', 'Album', 'Year', 'Comment'); - foreach ($commonkeysarray as $key) { - if (!empty($_POST[$key])) { - $TagData[strtolower($key)][] = $_POST[$key]; - } - } - if (!empty($_POST['Genre'])) { - $TagData['genre'][] = $_POST['Genre']; - } - if (!empty($_POST['GenreOther'])) { - $TagData['genre'][] = $_POST['GenreOther']; - } - if (!empty($_POST['Track'])) { - $TagData['track'][] = $_POST['Track'].(!empty($_POST['TracksTotal']) ? '/'.$_POST['TracksTotal'] : ''); - } + if (! empty($_FILES['userfile']['tmp_name'])) { + if (in_array('id3v2.4', $tagwriter->tagformats) || in_array('id3v2.3', $tagwriter->tagformats) || in_array('id3v2.2', $tagwriter->tagformats)) { + if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { + ob_start(); + if ($fd = fopen($_FILES['userfile']['tmp_name'], 'rb')) { + ob_end_clean(); + $APICdata = fread($fd, filesize($_FILES['userfile']['tmp_name'])); + fclose($fd); - if (!empty($_FILES['userfile']['tmp_name'])) { - if (in_array('id3v2.4', $tagwriter->tagformats) || in_array('id3v2.3', $tagwriter->tagformats) || in_array('id3v2.2', $tagwriter->tagformats)) { - if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { - ob_start(); - if ($fd = fopen($_FILES['userfile']['tmp_name'], 'rb')) { - ob_end_clean(); - $APICdata = fread($fd, filesize($_FILES['userfile']['tmp_name'])); - fclose ($fd); - - list($APIC_width, $APIC_height, $APIC_imageTypeID) = GetImageSize($_FILES['userfile']['tmp_name']); - $imagetypes = array(1=>'gif', 2=>'jpeg', 3=>'png'); - if (isset($imagetypes[$APIC_imageTypeID])) { - - $TagData['attached_picture'][0]['data'] = $APICdata; - $TagData['attached_picture'][0]['picturetypeid'] = $_POST['APICpictureType']; - $TagData['attached_picture'][0]['description'] = $_FILES['userfile']['name']; - $TagData['attached_picture'][0]['mime'] = 'image/'.$imagetypes[$APIC_imageTypeID]; - - } else { - echo 'invalid image format (only GIF, JPEG, PNG)
    '; - } - } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - echo 'cannot open '.$_FILES['userfile']['tmp_name'].'
    '; - } - } else { - echo '!is_uploaded_file('.$_FILES['userfile']['tmp_name'].')
    '; - } - } else { - echo 'WARNING: Can only embed images for ID3v2
    '; - } - } - - $tagwriter->tag_data = $TagData; - if ($tagwriter->WriteTags()) { - echo 'Successfully wrote tags
    '; - if (!empty($tagwriter->warnings)) { - echo 'There were some warnings:
    '.implode('

    ', $tagwriter->warnings).'
    '; - } - } else { - echo 'Failed to write tags!
    '.implode('

    ', $tagwriter->errors).'
    '; - } - - } else { - - echo 'WARNING: no tag formats selected for writing - nothing written'; - - } - echo '
    '; + list($APIC_width, $APIC_height, $APIC_imageTypeID) = getimagesize($_FILES['userfile']['tmp_name']); + $imagetypes = [1=>'gif', 2=>'jpeg', 3=>'png']; + if (isset($imagetypes[$APIC_imageTypeID])) { + $TagData['attached_picture'][0]['data'] = $APICdata; + $TagData['attached_picture'][0]['picturetypeid'] = $_POST['APICpictureType']; + $TagData['attached_picture'][0]['description'] = $_FILES['userfile']['name']; + $TagData['attached_picture'][0]['mime'] = 'image/'.$imagetypes[$APIC_imageTypeID]; + } else { + echo 'invalid image format (only GIF, JPEG, PNG)
    '; + } + } else { + $errormessage = ob_get_contents(); + ob_end_clean(); + echo 'cannot open '.$_FILES['userfile']['tmp_name'].'
    '; + } + } else { + echo '!is_uploaded_file('.$_FILES['userfile']['tmp_name'].')
    '; + } + } else { + echo 'WARNING: Can only embed images for ID3v2
    '; + } + } + $tagwriter->tag_data = $TagData; + if ($tagwriter->WriteTags()) { + echo 'Successfully wrote tags
    '; + if (! empty($tagwriter->warnings)) { + echo 'There were some warnings:
    '.implode('

    ', $tagwriter->warnings).'
    '; + } + } else { + echo 'Failed to write tags!
    '.implode('

    ', $tagwriter->errors).'
    '; + } + } else { + echo 'WARNING: no tag formats selected for writing - nothing written'; + } + echo '
    '; } - echo '
    Sample tag editor/writer
    '; echo 'Browse current directory
    '; -if (!empty($Filename)) { - echo 'Start Over

    '; - echo '
    '; - echo ''; - echo ''; - if (file_exists($Filename)) { +if (! empty($Filename)) { + echo 'Start Over

    '; + echo ''; + echo '
    Filename:'.$Filename.'
    '; + echo ''; + if (file_exists($Filename)) { - // Initialize getID3 engine - $getID3 = new getID3; - $OldThisFileInfo = $getID3->analyze($Filename); - getid3_lib::CopyTagsToComments($OldThisFileInfo); + // Initialize getID3 engine + $getID3 = new getID3; + $OldThisFileInfo = $getID3->analyze($Filename); + getid3_lib::CopyTagsToComments($OldThisFileInfo); - switch ($OldThisFileInfo['fileformat']) { - case 'mp3': - case 'mp2': - case 'mp1': - $ValidTagTypes = array('id3v1', 'id3v2.3', 'ape'); - break; + switch ($OldThisFileInfo['fileformat']) { + case 'mp3': + case 'mp2': + case 'mp1': + $ValidTagTypes = ['id3v1', 'id3v2.3', 'ape']; + break; - case 'mpc': - $ValidTagTypes = array('ape'); - break; + case 'mpc': + $ValidTagTypes = ['ape']; + break; - case 'ogg': - if (!empty($OldThisFileInfo['audio']['dataformat']) && ($OldThisFileInfo['audio']['dataformat'] == 'flac')) { - //$ValidTagTypes = array('metaflac'); - // metaflac doesn't (yet) work with OggFLAC files - $ValidTagTypes = array(); - } else { - $ValidTagTypes = array('vorbiscomment'); - } - break; + case 'ogg': + if (! empty($OldThisFileInfo['audio']['dataformat']) && ($OldThisFileInfo['audio']['dataformat'] == 'flac')) { + //$ValidTagTypes = array('metaflac'); + // metaflac doesn't (yet) work with OggFLAC files + $ValidTagTypes = []; + } else { + $ValidTagTypes = ['vorbiscomment']; + } + break; - case 'flac': - $ValidTagTypes = array('metaflac'); - break; + case 'flac': + $ValidTagTypes = ['metaflac']; + break; - case 'real': - $ValidTagTypes = array('real'); - break; + case 'real': + $ValidTagTypes = ['real']; + break; - default: - $ValidTagTypes = array(); - break; - } - echo ''; - echo ''; - echo ''; - echo ''; + default: + $ValidTagTypes = []; + break; + } + echo ''; + echo ''; + echo ''; + echo ''; - $TracksTotal = ''; - $TrackNumber = ''; - if (!empty($OldThisFileInfo['comments']['track_number']) && is_array($OldThisFileInfo['comments']['track_number'])) { - $RawTrackNumberArray = $OldThisFileInfo['comments']['track_number']; - } elseif (!empty($OldThisFileInfo['comments']['track']) && is_array($OldThisFileInfo['comments']['track'])) { - $RawTrackNumberArray = $OldThisFileInfo['comments']['track']; - } else { - $RawTrackNumberArray = array(); - } - foreach ($RawTrackNumberArray as $key => $value) { - if (strlen($value) > strlen($TrackNumber)) { - // ID3v1 may store track as "3" but ID3v2/APE would store as "03/16" - $TrackNumber = $value; - } - } - if (strstr($TrackNumber, '/')) { - list($TrackNumber, $TracksTotal) = explode('/', $TrackNumber); - } - echo ''; + $TracksTotal = ''; + $TrackNumber = ''; + if (! empty($OldThisFileInfo['comments']['track_number']) && is_array($OldThisFileInfo['comments']['track_number'])) { + $RawTrackNumberArray = $OldThisFileInfo['comments']['track_number']; + } elseif (! empty($OldThisFileInfo['comments']['track']) && is_array($OldThisFileInfo['comments']['track'])) { + $RawTrackNumberArray = $OldThisFileInfo['comments']['track']; + } else { + $RawTrackNumberArray = []; + } + foreach ($RawTrackNumberArray as $key => $value) { + if (strlen($value) > strlen($TrackNumber)) { + // ID3v1 may store track as "3" but ID3v2/APE would store as "03/16" + $TrackNumber = $value; + } + } + if (strstr($TrackNumber, '/')) { + list($TrackNumber, $TracksTotal) = explode('/', $TrackNumber); + } + echo ''; - $ArrayOfGenresTemp = getid3_id3v1::ArrayOfGenres(); // get the array of genres - foreach ($ArrayOfGenresTemp as $key => $value) { // change keys to match displayed value - $ArrayOfGenres[$value] = $value; - } - unset($ArrayOfGenresTemp); // remove temporary array - unset($ArrayOfGenres['Cover']); // take off these special cases - unset($ArrayOfGenres['Remix']); - unset($ArrayOfGenres['Unknown']); - $ArrayOfGenres[''] = '- Unknown -'; // Add special cases back in with renamed key/value - $ArrayOfGenres['Cover'] = '-Cover-'; - $ArrayOfGenres['Remix'] = '-Remix-'; - asort($ArrayOfGenres); // sort into alphabetical order - echo ''; + $ArrayOfGenresTemp = getid3_id3v1::ArrayOfGenres(); // get the array of genres + foreach ($ArrayOfGenresTemp as $key => $value) { // change keys to match displayed value + $ArrayOfGenres[$value] = $value; + } + unset($ArrayOfGenresTemp); // remove temporary array + unset($ArrayOfGenres['Cover']); // take off these special cases + unset($ArrayOfGenres['Remix']); + unset($ArrayOfGenres['Unknown']); + $ArrayOfGenres[''] = '- Unknown -'; // Add special cases back in with renamed key/value + $ArrayOfGenres['Cover'] = '-Cover-'; + $ArrayOfGenres['Remix'] = '-Remix-'; + asort($ArrayOfGenres); // sort into alphabetical order + echo ''; - echo ''; + default: + if (isset($OldThisFileInfo['tags'][$ValidTagType])) { + echo ' checked="checked"'; + } + break; + } + } + echo '>'.$ValidTagType.'
    '; + } + if (count($ValidTagTypes) > 1) { + echo '
    Remove non-selected tag formats when writing new tag
    '; + } + echo ''; - echo ''; - - echo ''; - echo ''; - - } else { - - echo ''; - - } - echo '
    Filename:'.$Filename.'
    Title
    Artist
    Album
    Year
    Title
    Artist
    Album
    Year
    Track of
    Track of
    Genre
    Genre
    Write Tags'; - foreach ($ValidTagTypes as $ValidTagType) { - echo 'Write Tags'; + foreach ($ValidTagTypes as $ValidTagType) { + echo ''.$ValidTagType.'
    '; - } - if (count($ValidTagTypes) > 1) { - echo '
    Remove non-selected tag formats when writing new tag
    '; - } - echo '
    Comment
    Picture
    (ID3v2 only)

    '; - echo '
    '; - echo '
    Error'.htmlentities($Filename).' does not exist
    '; - echo '
    '; + echo 'Comment'; + echo 'Picture
    (ID3v2 only)
    '; + echo ''; + echo ' '; + echo ''; + } else { + echo 'Error'.htmlentities($Filename).' does not exist'; + } + echo ''; + echo ''; } -echo ''; \ No newline at end of file +echo ''; diff --git a/app/Library/getid3/demos/demo.zip.php b/app/Library/getid3/demos/demo.zip.php index 1aaeef7f..b07483bc 100644 --- a/app/Library/getid3/demos/demo.zip.php +++ b/app/Library/getid3/demos/demo.zip.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -12,90 +13,92 @@ // /// ///////////////////////////////////////////////////////////////// +function UnzipFileContents($filename, &$errors) +{ + $errors = []; + $DecompressedFileContents = []; + if (! class_exists('getID3')) { + $errors[] = 'class getID3 not defined, please include getid3.php'; + } elseif (include_once 'module.archive.zip.php') { + $getid3 = new getID3(); + $getid3->info['filesize'] = filesize($filename); + ob_start(); + if ($getid3->fp = fopen($filename, 'rb')) { + ob_end_clean(); + $getid3_zip = new getid3_zip($getid3); + $getid3_zip->analyze($filename); + if (($getid3->info['fileformat'] == 'zip') && ! empty($getid3->info['zip']['files'])) { + if (! empty($getid3->info['zip']['central_directory'])) { + $ZipDirectoryToWalk = $getid3->info['zip']['central_directory']; + } elseif (! empty($getid3->info['zip']['entries'])) { + $ZipDirectoryToWalk = $getid3->info['zip']['entries']; + } else { + $errors[] = 'failed to parse ZIP attachment "'.$piece_filename.'" (no central directory)
    '; + fclose($getid3->fp); -function UnzipFileContents($filename, &$errors) { - $errors = array(); - $DecompressedFileContents = array(); - if (!class_exists('getID3')) { - $errors[] = 'class getID3 not defined, please include getid3.php'; - } elseif (include_once('module.archive.zip.php')) { - $getid3 = new getID3(); - $getid3->info['filesize'] = filesize($filename); - ob_start(); - if ($getid3->fp = fopen($filename, 'rb')) { - ob_end_clean(); - $getid3_zip = new getid3_zip($getid3); - $getid3_zip->analyze($filename); - if (($getid3->info['fileformat'] == 'zip') && !empty($getid3->info['zip']['files'])) { - if (!empty($getid3->info['zip']['central_directory'])) { - $ZipDirectoryToWalk = $getid3->info['zip']['central_directory']; - } elseif (!empty($getid3->info['zip']['entries'])) { - $ZipDirectoryToWalk = $getid3->info['zip']['entries']; - } else { - $errors[] = 'failed to parse ZIP attachment "'.$piece_filename.'" (no central directory)
    '; - fclose($getid3->fp); - return false; - } - foreach ($ZipDirectoryToWalk as $key => $valuearray) { - fseek($getid3->fp, $valuearray['entry_offset'], SEEK_SET); - $LocalFileHeader = $getid3_zip->ZIPparseLocalFileHeader($getid3->fp); - if ($LocalFileHeader['flags']['encrypted']) { - // password-protected - $DecompressedFileContents[$valuearray['filename']] = ''; - } else { - fseek($getid3->fp, $LocalFileHeader['data_offset'], SEEK_SET); - $compressedFileData = ''; - while ((strlen($compressedFileData) < $LocalFileHeader['compressed_size']) && !feof($getid3->fp)) { - $compressedFileData .= fread($getid3->fp, 32768); - } - switch ($LocalFileHeader['raw']['compression_method']) { - case 0: // store - great, just copy data unchanged - $uncompressedFileData = $compressedFileData; - break; + return false; + } + foreach ($ZipDirectoryToWalk as $key => $valuearray) { + fseek($getid3->fp, $valuearray['entry_offset'], SEEK_SET); + $LocalFileHeader = $getid3_zip->ZIPparseLocalFileHeader($getid3->fp); + if ($LocalFileHeader['flags']['encrypted']) { + // password-protected + $DecompressedFileContents[$valuearray['filename']] = ''; + } else { + fseek($getid3->fp, $LocalFileHeader['data_offset'], SEEK_SET); + $compressedFileData = ''; + while ((strlen($compressedFileData) < $LocalFileHeader['compressed_size']) && ! feof($getid3->fp)) { + $compressedFileData .= fread($getid3->fp, 32768); + } + switch ($LocalFileHeader['raw']['compression_method']) { + case 0: // store - great, just copy data unchanged + $uncompressedFileData = $compressedFileData; + break; - case 8: // deflate - ob_start(); - $uncompressedFileData = gzinflate($compressedFileData); - $gzinflate_errors = trim(strip_tags(ob_get_contents())); - ob_end_clean(); - if ($gzinflate_errors) { - $errors[] = 'gzinflate() failed for file ['.$LocalFileHeader['filename'].']: "'.$gzinflate_errors.'"'; - continue 2; - } - break; + case 8: // deflate + ob_start(); + $uncompressedFileData = gzinflate($compressedFileData); + $gzinflate_errors = trim(strip_tags(ob_get_contents())); + ob_end_clean(); + if ($gzinflate_errors) { + $errors[] = 'gzinflate() failed for file ['.$LocalFileHeader['filename'].']: "'.$gzinflate_errors.'"'; + continue 2; + } + break; - case 1: // shrink - case 2: // reduce-1 - case 3: // reduce-2 - case 4: // reduce-3 - case 5: // reduce-4 - case 6: // implode - case 7: // tokenize - case 9: // deflate64 - case 10: // PKWARE Date Compression Library Imploding - $DecompressedFileContents[$valuearray['filename']] = ''; - $errors[] = 'unsupported ZIP compression method ('.$LocalFileHeader['raw']['compression_method'].' = '.$getid3_zip->ZIPcompressionMethodLookup($LocalFileHeader['raw']['compression_method']).')'; - continue 2; + case 1: // shrink + case 2: // reduce-1 + case 3: // reduce-2 + case 4: // reduce-3 + case 5: // reduce-4 + case 6: // implode + case 7: // tokenize + case 9: // deflate64 + case 10: // PKWARE Date Compression Library Imploding + $DecompressedFileContents[$valuearray['filename']] = ''; + $errors[] = 'unsupported ZIP compression method ('.$LocalFileHeader['raw']['compression_method'].' = '.$getid3_zip->ZIPcompressionMethodLookup($LocalFileHeader['raw']['compression_method']).')'; + continue 2; - default: - $DecompressedFileContents[$valuearray['filename']] = ''; - $errors[] = 'unknown ZIP compression method ('.$LocalFileHeader['raw']['compression_method'].')'; - continue 2; - } - $DecompressedFileContents[$valuearray['filename']] = $uncompressedFileData; - unset($compressedFileData); - } - } - } else { - $errors[] = $filename.' does not appear to be a zip file'; - } - } else { - $error_message = ob_get_contents(); - ob_end_clean(); - $errors[] = 'failed to fopen('.$filename.', rb): '.$error_message; - } - } else { - $errors[] = 'failed to include_once(module.archive.zip.php)'; - } - return $DecompressedFileContents; + default: + $DecompressedFileContents[$valuearray['filename']] = ''; + $errors[] = 'unknown ZIP compression method ('.$LocalFileHeader['raw']['compression_method'].')'; + continue 2; + } + $DecompressedFileContents[$valuearray['filename']] = $uncompressedFileData; + unset($compressedFileData); + } + } + } else { + $errors[] = $filename.' does not appear to be a zip file'; + } + } else { + $error_message = ob_get_contents(); + ob_end_clean(); + $errors[] = 'failed to fopen('.$filename.', rb): '.$error_message; + } + } else { + $errors[] = 'failed to include_once(module.archive.zip.php)'; + } + + return $DecompressedFileContents; } diff --git a/app/Library/getid3/demos/getid3.demo.dirscan.php b/app/Library/getid3/demos/getid3.demo.dirscan.php index bfb7c9db..657698ce 100644 --- a/app/Library/getid3/demos/getid3.demo.dirscan.php +++ b/app/Library/getid3/demos/getid3.demo.dirscan.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,24 +15,24 @@ // /// ///////////////////////////////////////////////////////////////////////////////// /** -* This is a directory scanning and caching cli tool for getID3(). -* -* use like so for the default sqlite3 database, which is hidden: -* -* cd -* php /getid3.dirscan.php -* -* or -* -* php /getid3.dirscan.php -* -* Supported Cache Types (this extension) -* -* SQL Databases: -* -* cache_type -* ------------------------------------------------------------------- -* mysql + * This is a directory scanning and caching cli tool for getID3(). + * + * use like so for the default sqlite3 database, which is hidden: + * + * cd + * php /getid3.dirscan.php + * + * or + * + * php /getid3.dirscan.php + * + * Supported Cache Types (this extension) + * + * SQL Databases: + * + * cache_type + * ------------------------------------------------------------------- + * mysql $cache='mysql'; $database['host']=''; @@ -40,219 +41,222 @@ $database['username']=''; $database['password']=''; $database['table']=''; -* sqlite3 + * sqlite3 $cache='sqlite3'; $database['table']='getid3_cache'; $database['hide']=true; - -*/ -$dir = $_SERVER['PWD']; -$media = array('mp4', 'm4v', 'mov', 'mp3', 'm4a', 'jpg', 'png', 'gif'); -$database = array(); + */ +$dir = $_SERVER['PWD']; +$media = ['mp4', 'm4v', 'mov', 'mp3', 'm4a', 'jpg', 'png', 'gif']; +$database = []; /** -* configure the database bellow -*/ + * configure the database bellow. + */ // sqlite3 -$cache = 'sqlite3'; +$cache = 'sqlite3'; $database['table'] = 'getid3_cache'; -$database['hide'] = true; +$database['hide'] = true; /** - * mysql + * mysql. $cache = 'mysql'; $database['host'] = ''; $database['database'] = ''; $database['username'] = ''; $database['password'] = ''; $database['table'] = ''; -*/ + */ /** -* id3 tags class file -*/ -require_once(dirname(__FILE__).'/getid3.php'); + * id3 tags class file. + */ +require_once dirname(__FILE__).'/getid3.php'; /** -* dirscan scans all directories for files that match your selected filetypes into the cache database -* this is useful for a lot of media files -* -* -* @package dirscan -* @author Karl Holz -* -*/ + * dirscan scans all directories for files that match your selected filetypes into the cache database + * this is useful for a lot of media files. + * + * + * @author Karl Holz + */ +class dirscan +{ + /** + * type_brace() * Might not work on Solaris and other non GNU systems *. + * + * Configures a filetype list for use with glob searches, + * will match uppercase or lowercase extensions only, no mixing + * @param string $dir directory to use + * @param mixed cvs list of extentions or an array + * @return string or null if checks fail + */ + private function type_brace($dir, $search = []) + { + $dir = str_replace(['///', '//'], ['/', '/'], $dir); + if (! is_dir($dir)) { + return null; + } + if (! is_array($search)) { + $e = explode(',', $search); + } elseif (count($search) < 1) { + return null; + } else { + $e = $search; + } + $ext = []; + foreach ($e as $new) { + $ext[] = strtolower(trim($new)); + $ext[] = strtoupper(trim($new)); + } + $b = $dir.'/*.{'.implode(',', $ext).'}'; -class dirscan { - /** - * type_brace() * Might not work on Solaris and other non GNU systems * - * - * Configures a filetype list for use with glob searches, - * will match uppercase or lowercase extensions only, no mixing - * @param string $dir directory to use - * @param mixed cvs list of extentions or an array - * @return string or null if checks fail - */ - private function type_brace($dir, $search=array()) { - $dir = str_replace(array('///', '//'), array('/', '/'), $dir); - if (!is_dir($dir)) { - return null; - } - if (!is_array($search)) { - $e = explode(',', $search); - } elseif (count($search) < 1) { - return null; - } else { - $e = $search; - } - $ext = array(); - foreach ($e as $new) { - $ext[] = strtolower(trim($new)); - $ext[] = strtoupper(trim($new)); - } - $b = $dir.'/*.{'.implode(',', $ext).'}'; - return $b; - } + return $b; + } - /** - * this function will search 4 levels deep for directories - * will return null on failure - * @param string $root - * @return array return an array of dirs under root - * @todo figure out how to block tabo directories with ease - */ - private function getDirs($root) { - switch ($root) { // return null on tabo directories, add as needed -> case {dir to block }: this is not perfect yet - case '/': - case '/var': - case '/etc': - case '/home': - case '/usr': - case '/root': - case '/private/etc': - case '/private/var': - case '/etc/apache2': - case '/home': - case '/tmp': - case '/var/log': - return null; - break; - default: // scan 4 directories deep - if (!is_dir($root)) { - return null; - } - $dirs = array_merge(glob($root.'/*', GLOB_ONLYDIR), glob($root.'/*/*', GLOB_ONLYDIR), glob($root.'/*/*/*', GLOB_ONLYDIR), glob($root.'/*/*/*/*', GLOB_ONLYDIR), glob($root.'/*/*/*/*/*', GLOB_ONLYDIR), glob($root.'/*/*/*/*/*/*', GLOB_ONLYDIR), glob($root.'/*/*/*/*/*/*/*', GLOB_ONLYDIR)); - break; - } - if (count($dirs) < 1) { - $dirs = array($root); - } - return $dirs; - } + /** + * this function will search 4 levels deep for directories + * will return null on failure. + * @param string $root + * @return array return an array of dirs under root + * @todo figure out how to block tabo directories with ease + */ + private function getDirs($root) + { + switch ($root) { // return null on tabo directories, add as needed -> case {dir to block }: this is not perfect yet + case '/': + case '/var': + case '/etc': + case '/home': + case '/usr': + case '/root': + case '/private/etc': + case '/private/var': + case '/etc/apache2': + case '/home': + case '/tmp': + case '/var/log': + return null; + break; + default: // scan 4 directories deep + if (! is_dir($root)) { + return null; + } + $dirs = array_merge(glob($root.'/*', GLOB_ONLYDIR), glob($root.'/*/*', GLOB_ONLYDIR), glob($root.'/*/*/*', GLOB_ONLYDIR), glob($root.'/*/*/*/*', GLOB_ONLYDIR), glob($root.'/*/*/*/*/*', GLOB_ONLYDIR), glob($root.'/*/*/*/*/*/*', GLOB_ONLYDIR), glob($root.'/*/*/*/*/*/*/*', GLOB_ONLYDIR)); + break; + } + if (count($dirs) < 1) { + $dirs = [$root]; + } - /** - * file_check() check the number of file that are found that match the brace search - * - * @param string $search - * @return mixed - */ - private function file_check($search) { - $t = array(); - $s = glob($search, GLOB_BRACE); - foreach ($s as $file) { - $t[] = str_replace(array('///', '//'), array('/', '/'), $file); - } - if (count($t) > 0) { - return $t; - } - return null; - } + return $dirs; + } - function getTime() { - return microtime(true); - // old method for PHP < 5 - //$a = explode(' ', microtime()); - //return (double) $a[0] + $a[1]; - } + /** + * file_check() check the number of file that are found that match the brace search. + * + * @param string $search + * @return mixed + */ + private function file_check($search) + { + $t = []; + $s = glob($search, GLOB_BRACE); + foreach ($s as $file) { + $t[] = str_replace(['///', '//'], ['/', '/'], $file); + } + if (count($t) > 0) { + return $t; + } + return null; + } - /** - * - * @param type $dir - * @param type $match search type name extentions, can be an array or csv list - * @param type $cache caching extention, select one of sqlite3, mysql, dbm - * @param array $opt database options, - */ - function scan_files($dir, $match, $cache='sqlite3', $opt=array('table'=>'getid3_cache', 'hide'=>true)) { - $Start = self::getTime(); - switch ($cache) { // load the caching module - case 'sqlite3': - if (!class_exists('getID3_cached_sqlite3')) { - require_once(dirname(__FILE__)).'/extension.cache.sqlite3.php'; - } - $id3 = new getID3_cached_sqlite3($opt['table'], $opt['hide']); - break; - case 'mysql': - if (!class_exists('getID3_cached_mysql')) { - require_once(dirname(__FILE__)).'/extension.cache.mysql.php'; - } - $id3 = new getID3_cached_mysql($opt['host'], $opt['database'], $opt['username'], $opt['password'], $opt['table']); - break; - // I'll leave this for some one else - //case 'dbm': - // if (!class_exists('getID3_cached_dbm')) { - // require_once(dirname(__FILE__)).'/extension.cache.dbm.php'; - // } - // die(' This has not be implemented, sorry for the inconvenience'); - // break; - default: - die(' You have selected an Invalid cache type, only "sqlite3" and "mysql" are valid'."\n"); - break; - } - $count = array('dir'=>0, 'file'=>0); - $dirs = self::getDirs($dir); - if ($dirs !== null) { - foreach ($dirs as $d) { - echo ' Scanning: '.$d."\n"; - $search = self::type_brace($d, $match); - if ($search !== null) { - $files = self::file_check($search); - if ($files !== null) { - foreach ($files as $f) { - echo ' * Analyzing '.$f.' '."\n"; - $id3->analyze($f); - $count['file']++; - } - $count['dir']++; - } else { - echo 'Failed to get files '."\n"; - } - } else { - echo 'Failed to create match string '."\n"; - } - } - echo '**************************************'."\n"; - echo '* Finished Scanning your directories '."\n*\n"; - echo '* Directories '.$count['dir']."\n"; - echo '* Files '.$count['file']."\n"; - $End = self::getTime(); - $t = number_format(($End - $Start) / 60, 2); - echo '* Time taken to scan '.$dir.' '.$t.' min '."\n"; - echo '**************************************'."\n"; - } else { - echo ' failed to get directories '."\n"; - } - } + public function getTime() + { + return microtime(true); + // old method for PHP < 5 + //$a = explode(' ', microtime()); + //return (double) $a[0] + $a[1]; + } + + /** + * @param type $dir + * @param type $match search type name extentions, can be an array or csv list + * @param type $cache caching extention, select one of sqlite3, mysql, dbm + * @param array $opt database options, + */ + public function scan_files($dir, $match, $cache = 'sqlite3', $opt = ['table'=>'getid3_cache', 'hide'=>true]) + { + $Start = self::getTime(); + switch ($cache) { // load the caching module + case 'sqlite3': + if (! class_exists('getID3_cached_sqlite3')) { + require_once(dirname(__FILE__)).'/extension.cache.sqlite3.php'; + } + $id3 = new getID3_cached_sqlite3($opt['table'], $opt['hide']); + break; + case 'mysql': + if (! class_exists('getID3_cached_mysql')) { + require_once(dirname(__FILE__)).'/extension.cache.mysql.php'; + } + $id3 = new getID3_cached_mysql($opt['host'], $opt['database'], $opt['username'], $opt['password'], $opt['table']); + break; + // I'll leave this for some one else + //case 'dbm': + // if (!class_exists('getID3_cached_dbm')) { + // require_once(dirname(__FILE__)).'/extension.cache.dbm.php'; + // } + // die(' This has not be implemented, sorry for the inconvenience'); + // break; + default: + die(' You have selected an Invalid cache type, only "sqlite3" and "mysql" are valid'."\n"); + break; + } + $count = ['dir'=>0, 'file'=>0]; + $dirs = self::getDirs($dir); + if ($dirs !== null) { + foreach ($dirs as $d) { + echo ' Scanning: '.$d."\n"; + $search = self::type_brace($d, $match); + if ($search !== null) { + $files = self::file_check($search); + if ($files !== null) { + foreach ($files as $f) { + echo ' * Analyzing '.$f.' '."\n"; + $id3->analyze($f); + $count['file']++; + } + $count['dir']++; + } else { + echo 'Failed to get files '."\n"; + } + } else { + echo 'Failed to create match string '."\n"; + } + } + echo '**************************************'."\n"; + echo '* Finished Scanning your directories '."\n*\n"; + echo '* Directories '.$count['dir']."\n"; + echo '* Files '.$count['file']."\n"; + $End = self::getTime(); + $t = number_format(($End - $Start) / 60, 2); + echo '* Time taken to scan '.$dir.' '.$t.' min '."\n"; + echo '**************************************'."\n"; + } else { + echo ' failed to get directories '."\n"; + } + } } if (PHP_SAPI === 'cli') { - if (count($argv) == 2) { - if (is_dir($argv[1])) { - $dir = $argv[1]; - } - if (count(explode(',', $argv[2])) > 0) { - $media = $arg[2]; - } - } - echo ' * Starting to scan directory: '.$dir."\n"; - echo ' * Using default media types: '.implode(',', $media)."\n"; - dirscan::scan_files($dir, $media, $cache, $database); + if (count($argv) == 2) { + if (is_dir($argv[1])) { + $dir = $argv[1]; + } + if (count(explode(',', $argv[2])) > 0) { + $media = $arg[2]; + } + } + echo ' * Starting to scan directory: '.$dir."\n"; + echo ' * Using default media types: '.implode(',', $media)."\n"; + dirscan::scan_files($dir, $media, $cache, $database); } diff --git a/app/Library/getid3/demos/index.php b/app/Library/getid3/demos/index.php index 89120759..d7dfff46 100644 --- a/app/Library/getid3/demos/index.php +++ b/app/Library/getid3/demos/index.php @@ -7,11 +7,11 @@ If you don't know what to run, take a look at demo. Other demos: diff --git a/app/Library/getid3/getid3/extension.cache.dbm.php b/app/Library/getid3/getid3/extension.cache.dbm.php index a9332b92..e5179ffb 100644 --- a/app/Library/getid3/getid3/extension.cache.dbm.php +++ b/app/Library/getid3/getid3/extension.cache.dbm.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -15,195 +16,187 @@ // /// ///////////////////////////////////////////////////////////////// - /** -* This is a caching extension for getID3(). It works the exact same -* way as the getID3 class, but return cached information very fast -* -* Example: -* -* Normal getID3 usage (example): -* -* require_once 'getid3/getid3.php'; -* $getID3 = new getID3; -* $getID3->encoding = 'UTF-8'; -* $info1 = $getID3->analyze('file1.flac'); -* $info2 = $getID3->analyze('file2.wv'); -* -* getID3_cached usage: -* -* require_once 'getid3/getid3.php'; -* require_once 'getid3/getid3/extension.cache.dbm.php'; -* $getID3 = new getID3_cached('db3', '/tmp/getid3_cache.dbm', -* '/tmp/getid3_cache.lock'); -* $getID3->encoding = 'UTF-8'; -* $info1 = $getID3->analyze('file1.flac'); -* $info2 = $getID3->analyze('file2.wv'); -* -* -* Supported Cache Types -* -* SQL Databases: (use extension.cache.mysql) -* -* cache_type cache_options -* ------------------------------------------------------------------- -* mysql host, database, username, password -* -* -* DBM-Style Databases: (this extension) -* -* cache_type cache_options -* ------------------------------------------------------------------- -* gdbm dbm_filename, lock_filename -* ndbm dbm_filename, lock_filename -* db2 dbm_filename, lock_filename -* db3 dbm_filename, lock_filename -* db4 dbm_filename, lock_filename (PHP5 required) -* -* PHP must have write access to both dbm_filename and lock_filename. -* -* -* Recommended Cache Types -* -* Infrequent updates, many reads any DBM -* Frequent updates mysql -*/ - - + * This is a caching extension for getID3(). It works the exact same + * way as the getID3 class, but return cached information very fast. + * + * Example: + * + * Normal getID3 usage (example): + * + * require_once 'getid3/getid3.php'; + * $getID3 = new getID3; + * $getID3->encoding = 'UTF-8'; + * $info1 = $getID3->analyze('file1.flac'); + * $info2 = $getID3->analyze('file2.wv'); + * + * getID3_cached usage: + * + * require_once 'getid3/getid3.php'; + * require_once 'getid3/getid3/extension.cache.dbm.php'; + * $getID3 = new getID3_cached('db3', '/tmp/getid3_cache.dbm', + * '/tmp/getid3_cache.lock'); + * $getID3->encoding = 'UTF-8'; + * $info1 = $getID3->analyze('file1.flac'); + * $info2 = $getID3->analyze('file2.wv'); + * + * + * Supported Cache Types + * + * SQL Databases: (use extension.cache.mysql) + * + * cache_type cache_options + * ------------------------------------------------------------------- + * mysql host, database, username, password + * + * + * DBM-Style Databases: (this extension) + * + * cache_type cache_options + * ------------------------------------------------------------------- + * gdbm dbm_filename, lock_filename + * ndbm dbm_filename, lock_filename + * db2 dbm_filename, lock_filename + * db3 dbm_filename, lock_filename + * db4 dbm_filename, lock_filename (PHP5 required) + * + * PHP must have write access to both dbm_filename and lock_filename. + * + * + * Recommended Cache Types + * + * Infrequent updates, many reads any DBM + * Frequent updates mysql + */ class getID3_cached_dbm extends getID3 { + // public: constructor - see top of this file for cache type and cache_options + public function __construct($cache_type, $dbm_filename, $lock_filename) + { - // public: constructor - see top of this file for cache type and cache_options - public function __construct($cache_type, $dbm_filename, $lock_filename) { + // Check for dba extension + if (! extension_loaded('dba')) { + throw new Exception('PHP is not compiled with dba support, required to use DBM style cache.'); + } - // Check for dba extension - if (!extension_loaded('dba')) { - throw new Exception('PHP is not compiled with dba support, required to use DBM style cache.'); - } + // Check for specific dba driver + if (! function_exists('dba_handlers') || ! in_array($cache_type, dba_handlers())) { + throw new Exception('PHP is not compiled --with '.$cache_type.' support, required to use DBM style cache.'); + } - // Check for specific dba driver - if (!function_exists('dba_handlers') || !in_array($cache_type, dba_handlers())) { - throw new Exception('PHP is not compiled --with '.$cache_type.' support, required to use DBM style cache.'); - } + // Create lock file if needed + if (! file_exists($lock_filename)) { + if (! touch($lock_filename)) { + throw new Exception('failed to create lock file: '.$lock_filename); + } + } - // Create lock file if needed - if (!file_exists($lock_filename)) { - if (!touch($lock_filename)) { - throw new Exception('failed to create lock file: '.$lock_filename); - } - } + // Open lock file for writing + if (! is_writable($lock_filename)) { + throw new Exception('lock file: '.$lock_filename.' is not writable'); + } + $this->lock = fopen($lock_filename, 'w'); - // Open lock file for writing - if (!is_writeable($lock_filename)) { - throw new Exception('lock file: '.$lock_filename.' is not writable'); - } - $this->lock = fopen($lock_filename, 'w'); + // Acquire exclusive write lock to lock file + flock($this->lock, LOCK_EX); - // Acquire exclusive write lock to lock file - flock($this->lock, LOCK_EX); + // Create dbm-file if needed + if (! file_exists($dbm_filename)) { + if (! touch($dbm_filename)) { + throw new Exception('failed to create dbm file: '.$dbm_filename); + } + } - // Create dbm-file if needed - if (!file_exists($dbm_filename)) { - if (!touch($dbm_filename)) { - throw new Exception('failed to create dbm file: '.$dbm_filename); - } - } + // Try to open dbm file for writing + $this->dba = dba_open($dbm_filename, 'w', $cache_type); + if (! $this->dba) { - // Try to open dbm file for writing - $this->dba = dba_open($dbm_filename, 'w', $cache_type); - if (!$this->dba) { + // Failed - create new dbm file + $this->dba = dba_open($dbm_filename, 'n', $cache_type); - // Failed - create new dbm file - $this->dba = dba_open($dbm_filename, 'n', $cache_type); + if (! $this->dba) { + throw new Exception('failed to create dbm file: '.$dbm_filename); + } - if (!$this->dba) { - throw new Exception('failed to create dbm file: '.$dbm_filename); - } + // Insert getID3 version number + dba_insert(getID3::VERSION, getID3::VERSION, $this->dba); + } - // Insert getID3 version number - dba_insert(getID3::VERSION, getID3::VERSION, $this->dba); - } + // Init misc values + $this->cache_type = $cache_type; + $this->dbm_filename = $dbm_filename; - // Init misc values - $this->cache_type = $cache_type; - $this->dbm_filename = $dbm_filename; + // Register destructor + register_shutdown_function([$this, '__destruct']); - // Register destructor - register_shutdown_function(array($this, '__destruct')); + // Check version number and clear cache if changed + if (dba_fetch(getID3::VERSION, $this->dba) != getID3::VERSION) { + $this->clear_cache(); + } - // Check version number and clear cache if changed - if (dba_fetch(getID3::VERSION, $this->dba) != getID3::VERSION) { - $this->clear_cache(); - } + parent::__construct(); + } - parent::__construct(); - } + // public: destructor + public function __destruct() + { + // Close dbm file + dba_close($this->dba); + // Release exclusive lock + flock($this->lock, LOCK_UN); - // public: destructor - public function __destruct() { + // Close lock file + fclose($this->lock); + } - // Close dbm file - dba_close($this->dba); + // public: clear cache + public function clear_cache() + { - // Release exclusive lock - flock($this->lock, LOCK_UN); + // Close dbm file + dba_close($this->dba); - // Close lock file - fclose($this->lock); - } + // Create new dbm file + $this->dba = dba_open($this->dbm_filename, 'n', $this->cache_type); + if (! $this->dba) { + throw new Exception('failed to clear cache/recreate dbm file: '.$this->dbm_filename); + } + // Insert getID3 version number + dba_insert(getID3::VERSION, getID3::VERSION, $this->dba); - // public: clear cache - public function clear_cache() { + // Re-register shutdown function + register_shutdown_function([$this, '__destruct']); + } - // Close dbm file - dba_close($this->dba); + // public: analyze file + public function analyze($filename) + { + if (file_exists($filename)) { - // Create new dbm file - $this->dba = dba_open($this->dbm_filename, 'n', $this->cache_type); + // Calc key filename::mod_time::size - should be unique + $key = $filename.'::'.filemtime($filename).'::'.filesize($filename); - if (!$this->dba) { - throw new Exception('failed to clear cache/recreate dbm file: '.$this->dbm_filename); - } + // Loopup key + $result = dba_fetch($key, $this->dba); - // Insert getID3 version number - dba_insert(getID3::VERSION, getID3::VERSION, $this->dba); + // Hit + if ($result !== false) { + return unserialize($result); + } + } - // Re-register shutdown function - register_shutdown_function(array($this, '__destruct')); - } + // Miss + $result = parent::analyze($filename); + // Save result + if (file_exists($filename)) { + dba_insert($key, serialize($result), $this->dba); + } - - // public: analyze file - public function analyze($filename) { - - if (file_exists($filename)) { - - // Calc key filename::mod_time::size - should be unique - $key = $filename.'::'.filemtime($filename).'::'.filesize($filename); - - // Loopup key - $result = dba_fetch($key, $this->dba); - - // Hit - if ($result !== false) { - return unserialize($result); - } - } - - // Miss - $result = parent::analyze($filename); - - // Save result - if (file_exists($filename)) { - dba_insert($key, serialize($result), $this->dba); - } - - return $result; - } - + return $result; + } } diff --git a/app/Library/getid3/getid3/extension.cache.mysql.php b/app/Library/getid3/getid3/extension.cache.mysql.php index b572676a..eb9ea346 100644 --- a/app/Library/getid3/getid3/extension.cache.mysql.php +++ b/app/Library/getid3/getid3/extension.cache.mysql.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -16,175 +17,167 @@ // /// ///////////////////////////////////////////////////////////////// - /** -* This is a caching extension for getID3(). It works the exact same -* way as the getID3 class, but return cached information very fast -* -* Example: (see also demo.cache.mysql.php in /demo/) -* -* Normal getID3 usage (example): -* -* require_once 'getid3/getid3.php'; -* $getID3 = new getID3; -* $getID3->encoding = 'UTF-8'; -* $info1 = $getID3->analyze('file1.flac'); -* $info2 = $getID3->analyze('file2.wv'); -* -* getID3_cached usage: -* -* require_once 'getid3/getid3.php'; -* require_once 'getid3/getid3/extension.cache.mysql.php'; -* // 5th parameter (tablename) is optional, default is 'getid3_cache' -* $getID3 = new getID3_cached_mysql('localhost', 'database', 'username', 'password', 'tablename'); -* $getID3->encoding = 'UTF-8'; -* $info1 = $getID3->analyze('file1.flac'); -* $info2 = $getID3->analyze('file2.wv'); -* -* -* Supported Cache Types (this extension) -* -* SQL Databases: -* -* cache_type cache_options -* ------------------------------------------------------------------- -* mysql host, database, username, password -* -* -* DBM-Style Databases: (use extension.cache.dbm) -* -* cache_type cache_options -* ------------------------------------------------------------------- -* gdbm dbm_filename, lock_filename -* ndbm dbm_filename, lock_filename -* db2 dbm_filename, lock_filename -* db3 dbm_filename, lock_filename -* db4 dbm_filename, lock_filename (PHP5 required) -* -* PHP must have write access to both dbm_filename and lock_filename. -* -* -* Recommended Cache Types -* -* Infrequent updates, many reads any DBM -* Frequent updates mysql -*/ - - + * This is a caching extension for getID3(). It works the exact same + * way as the getID3 class, but return cached information very fast. + * + * Example: (see also demo.cache.mysql.php in /demo/) + * + * Normal getID3 usage (example): + * + * require_once 'getid3/getid3.php'; + * $getID3 = new getID3; + * $getID3->encoding = 'UTF-8'; + * $info1 = $getID3->analyze('file1.flac'); + * $info2 = $getID3->analyze('file2.wv'); + * + * getID3_cached usage: + * + * require_once 'getid3/getid3.php'; + * require_once 'getid3/getid3/extension.cache.mysql.php'; + * // 5th parameter (tablename) is optional, default is 'getid3_cache' + * $getID3 = new getID3_cached_mysql('localhost', 'database', 'username', 'password', 'tablename'); + * $getID3->encoding = 'UTF-8'; + * $info1 = $getID3->analyze('file1.flac'); + * $info2 = $getID3->analyze('file2.wv'); + * + * + * Supported Cache Types (this extension) + * + * SQL Databases: + * + * cache_type cache_options + * ------------------------------------------------------------------- + * mysql host, database, username, password + * + * + * DBM-Style Databases: (use extension.cache.dbm) + * + * cache_type cache_options + * ------------------------------------------------------------------- + * gdbm dbm_filename, lock_filename + * ndbm dbm_filename, lock_filename + * db2 dbm_filename, lock_filename + * db3 dbm_filename, lock_filename + * db4 dbm_filename, lock_filename (PHP5 required) + * + * PHP must have write access to both dbm_filename and lock_filename. + * + * + * Recommended Cache Types + * + * Infrequent updates, many reads any DBM + * Frequent updates mysql + */ class getID3_cached_mysql extends getID3 { + // private vars + private $cursor; + private $connection; - // private vars - private $cursor; - private $connection; + // public: constructor - see top of this file for cache type and cache_options + public function __construct($host, $database, $username, $password, $table = 'getid3_cache') + { + // Check for mysql support + if (! function_exists('mysql_pconnect')) { + throw new Exception('PHP not compiled with mysql support.'); + } - // public: constructor - see top of this file for cache type and cache_options - public function __construct($host, $database, $username, $password, $table='getid3_cache') { + // Connect to database + $this->connection = mysql_pconnect($host, $username, $password); + if (! $this->connection) { + throw new Exception('mysql_pconnect() failed - check permissions and spelling.'); + } - // Check for mysql support - if (!function_exists('mysql_pconnect')) { - throw new Exception('PHP not compiled with mysql support.'); - } + // Select database + if (! mysql_select_db($database, $this->connection)) { + throw new Exception('Cannot use database '.$database); + } - // Connect to database - $this->connection = mysql_pconnect($host, $username, $password); - if (!$this->connection) { - throw new Exception('mysql_pconnect() failed - check permissions and spelling.'); - } + // Set table + $this->table = $table; - // Select database - if (!mysql_select_db($database, $this->connection)) { - throw new Exception('Cannot use database '.$database); - } + // Create cache table if not exists + $this->create_table(); - // Set table - $this->table = $table; + // Check version number and clear cache if changed + $version = ''; + $SQLquery = 'SELECT `value`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string($this->table).'`'; + $SQLquery .= ' WHERE (`filename` = \''.mysql_real_escape_string(getID3::VERSION).'\')'; + $SQLquery .= ' AND (`filesize` = -1)'; + $SQLquery .= ' AND (`filetime` = -1)'; + $SQLquery .= ' AND (`analyzetime` = -1)'; + if ($this->cursor = mysql_query($SQLquery, $this->connection)) { + list($version) = mysql_fetch_array($this->cursor); + } + if ($version != getID3::VERSION) { + $this->clear_cache(); + } - // Create cache table if not exists - $this->create_table(); + parent::__construct(); + } - // Check version number and clear cache if changed - $version = ''; - $SQLquery = 'SELECT `value`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string($this->table).'`'; - $SQLquery .= ' WHERE (`filename` = \''.mysql_real_escape_string(getID3::VERSION).'\')'; - $SQLquery .= ' AND (`filesize` = -1)'; - $SQLquery .= ' AND (`filetime` = -1)'; - $SQLquery .= ' AND (`analyzetime` = -1)'; - if ($this->cursor = mysql_query($SQLquery, $this->connection)) { - list($version) = mysql_fetch_array($this->cursor); - } - if ($version != getID3::VERSION) { - $this->clear_cache(); - } + // public: clear cache + public function clear_cache() + { + $this->cursor = mysql_query('DELETE FROM `'.mysql_real_escape_string($this->table).'`', $this->connection); + $this->cursor = mysql_query('INSERT INTO `'.mysql_real_escape_string($this->table).'` VALUES (\''.getID3::VERSION.'\', -1, -1, -1, \''.getID3::VERSION.'\')', $this->connection); + } - parent::__construct(); - } + // public: analyze file + public function analyze($filename, $filesize = null, $original_filename = '') + { + if (file_exists($filename)) { + // Short-hands + $filetime = filemtime($filename); + $filesize = filesize($filename); + // Lookup file + $SQLquery = 'SELECT `value`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string($this->table).'`'; + $SQLquery .= ' WHERE (`filename` = \''.mysql_real_escape_string($filename).'\')'; + $SQLquery .= ' AND (`filesize` = \''.mysql_real_escape_string($filesize).'\')'; + $SQLquery .= ' AND (`filetime` = \''.mysql_real_escape_string($filetime).'\')'; + $this->cursor = mysql_query($SQLquery, $this->connection); + if (mysql_num_rows($this->cursor) > 0) { + // Hit + list($result) = mysql_fetch_array($this->cursor); - // public: clear cache - public function clear_cache() { + return unserialize(base64_decode($result)); + } + } - $this->cursor = mysql_query('DELETE FROM `'.mysql_real_escape_string($this->table).'`', $this->connection); - $this->cursor = mysql_query('INSERT INTO `'.mysql_real_escape_string($this->table).'` VALUES (\''.getID3::VERSION.'\', -1, -1, -1, \''.getID3::VERSION.'\')', $this->connection); - } + // Miss + $analysis = parent::analyze($filename, $filesize, $original_filename); + // Save result + if (file_exists($filename)) { + $SQLquery = 'INSERT INTO `'.mysql_real_escape_string($this->table).'` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES ('; + $SQLquery .= '\''.mysql_real_escape_string($filename).'\''; + $SQLquery .= ', \''.mysql_real_escape_string($filesize).'\''; + $SQLquery .= ', \''.mysql_real_escape_string($filetime).'\''; + $SQLquery .= ', \''.mysql_real_escape_string(time()).'\''; + $SQLquery .= ', \''.mysql_real_escape_string(base64_encode(serialize($analysis))).'\')'; + $this->cursor = mysql_query($SQLquery, $this->connection); + } + return $analysis; + } - // public: analyze file - public function analyze($filename, $filesize=null, $original_filename='') { - - if (file_exists($filename)) { - - // Short-hands - $filetime = filemtime($filename); - $filesize = filesize($filename); - - // Lookup file - $SQLquery = 'SELECT `value`'; - $SQLquery .= ' FROM `'.mysql_real_escape_string($this->table).'`'; - $SQLquery .= ' WHERE (`filename` = \''.mysql_real_escape_string($filename).'\')'; - $SQLquery .= ' AND (`filesize` = \''.mysql_real_escape_string($filesize).'\')'; - $SQLquery .= ' AND (`filetime` = \''.mysql_real_escape_string($filetime).'\')'; - $this->cursor = mysql_query($SQLquery, $this->connection); - if (mysql_num_rows($this->cursor) > 0) { - // Hit - list($result) = mysql_fetch_array($this->cursor); - return unserialize(base64_decode($result)); - } - } - - // Miss - $analysis = parent::analyze($filename, $filesize, $original_filename); - - // Save result - if (file_exists($filename)) { - $SQLquery = 'INSERT INTO `'.mysql_real_escape_string($this->table).'` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES ('; - $SQLquery .= '\''.mysql_real_escape_string($filename).'\''; - $SQLquery .= ', \''.mysql_real_escape_string($filesize).'\''; - $SQLquery .= ', \''.mysql_real_escape_string($filetime).'\''; - $SQLquery .= ', \''.mysql_real_escape_string(time() ).'\''; - $SQLquery .= ', \''.mysql_real_escape_string(base64_encode(serialize($analysis))).'\')'; - $this->cursor = mysql_query($SQLquery, $this->connection); - } - return $analysis; - } - - - - // private: (re)create sql table - private function create_table($drop=false) { - - $SQLquery = 'CREATE TABLE IF NOT EXISTS `'.mysql_real_escape_string($this->table).'` ('; - $SQLquery .= '`filename` VARCHAR(990) NOT NULL DEFAULT \'\''; - $SQLquery .= ', `filesize` INT(11) NOT NULL DEFAULT \'0\''; - $SQLquery .= ', `filetime` INT(11) NOT NULL DEFAULT \'0\''; - $SQLquery .= ', `analyzetime` INT(11) NOT NULL DEFAULT \'0\''; - $SQLquery .= ', `value` LONGTEXT NOT NULL'; - $SQLquery .= ', PRIMARY KEY (`filename`, `filesize`, `filetime`)) ENGINE=MyISAM CHARACTER SET=latin1 COLLATE=latin1_general_ci'; - $this->cursor = mysql_query($SQLquery, $this->connection); - echo mysql_error($this->connection); - } + // private: (re)create sql table + private function create_table($drop = false) + { + $SQLquery = 'CREATE TABLE IF NOT EXISTS `'.mysql_real_escape_string($this->table).'` ('; + $SQLquery .= '`filename` VARCHAR(990) NOT NULL DEFAULT \'\''; + $SQLquery .= ', `filesize` INT(11) NOT NULL DEFAULT \'0\''; + $SQLquery .= ', `filetime` INT(11) NOT NULL DEFAULT \'0\''; + $SQLquery .= ', `analyzetime` INT(11) NOT NULL DEFAULT \'0\''; + $SQLquery .= ', `value` LONGTEXT NOT NULL'; + $SQLquery .= ', PRIMARY KEY (`filename`, `filesize`, `filetime`)) ENGINE=MyISAM CHARACTER SET=latin1 COLLATE=latin1_general_ci'; + $this->cursor = mysql_query($SQLquery, $this->connection); + echo mysql_error($this->connection); + } } diff --git a/app/Library/getid3/getid3/extension.cache.mysqli.php b/app/Library/getid3/getid3/extension.cache.mysqli.php index 3299caae..bb17c152 100644 --- a/app/Library/getid3/getid3/extension.cache.mysqli.php +++ b/app/Library/getid3/getid3/extension.cache.mysqli.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -16,168 +17,167 @@ // /// ///////////////////////////////////////////////////////////////// - /** -* This is a caching extension for getID3(). It works the exact same -* way as the getID3 class, but return cached information very fast -* -* Example: (see also demo.cache.mysql.php in /demo/) -* -* Normal getID3 usage (example): -* -* require_once 'getid3/getid3.php'; -* $getID3 = new getID3; -* $getID3->encoding = 'UTF-8'; -* $info1 = $getID3->analyze('file1.flac'); -* $info2 = $getID3->analyze('file2.wv'); -* -* getID3_cached usage: -* -* require_once 'getid3/getid3.php'; -* require_once 'getid3/getid3/extension.cache.mysqli.php'; -* // 5th parameter (tablename) is optional, default is 'getid3_cache' -* $getID3 = new getID3_cached_mysqli('localhost', 'database', 'username', 'password', 'tablename'); -* $getID3->encoding = 'UTF-8'; -* $info1 = $getID3->analyze('file1.flac'); -* $info2 = $getID3->analyze('file2.wv'); -* -* -* Supported Cache Types (this extension) -* -* SQL Databases: -* -* cache_type cache_options -* ------------------------------------------------------------------- -* mysqli host, database, username, password -* -* -* DBM-Style Databases: (use extension.cache.dbm) -* -* cache_type cache_options -* ------------------------------------------------------------------- -* gdbm dbm_filename, lock_filename -* ndbm dbm_filename, lock_filename -* db2 dbm_filename, lock_filename -* db3 dbm_filename, lock_filename -* db4 dbm_filename, lock_filename (PHP5 required) -* -* PHP must have write access to both dbm_filename and lock_filename. -* -* -* Recommended Cache Types -* -* Infrequent updates, many reads any DBM -* Frequent updates mysqli -*/ - + * This is a caching extension for getID3(). It works the exact same + * way as the getID3 class, but return cached information very fast. + * + * Example: (see also demo.cache.mysql.php in /demo/) + * + * Normal getID3 usage (example): + * + * require_once 'getid3/getid3.php'; + * $getID3 = new getID3; + * $getID3->encoding = 'UTF-8'; + * $info1 = $getID3->analyze('file1.flac'); + * $info2 = $getID3->analyze('file2.wv'); + * + * getID3_cached usage: + * + * require_once 'getid3/getid3.php'; + * require_once 'getid3/getid3/extension.cache.mysqli.php'; + * // 5th parameter (tablename) is optional, default is 'getid3_cache' + * $getID3 = new getID3_cached_mysqli('localhost', 'database', 'username', 'password', 'tablename'); + * $getID3->encoding = 'UTF-8'; + * $info1 = $getID3->analyze('file1.flac'); + * $info2 = $getID3->analyze('file2.wv'); + * + * + * Supported Cache Types (this extension) + * + * SQL Databases: + * + * cache_type cache_options + * ------------------------------------------------------------------- + * mysqli host, database, username, password + * + * + * DBM-Style Databases: (use extension.cache.dbm) + * + * cache_type cache_options + * ------------------------------------------------------------------- + * gdbm dbm_filename, lock_filename + * ndbm dbm_filename, lock_filename + * db2 dbm_filename, lock_filename + * db3 dbm_filename, lock_filename + * db4 dbm_filename, lock_filename (PHP5 required) + * + * PHP must have write access to both dbm_filename and lock_filename. + * + * + * Recommended Cache Types + * + * Infrequent updates, many reads any DBM + * Frequent updates mysqli + */ class getID3_cached_mysqli extends getID3 { - // private vars - private $mysqli; - private $cursor; + // private vars + private $mysqli; + private $cursor; + // public: constructor - see top of this file for cache type and cache_options + public function __construct($host, $database, $username, $password, $table = 'getid3_cache') + { - // public: constructor - see top of this file for cache type and cache_options - public function __construct($host, $database, $username, $password, $table='getid3_cache') { + // Check for mysqli support + if (! function_exists('mysqli_connect')) { + throw new Exception('PHP not compiled with mysqli support.'); + } - // Check for mysqli support - if (!function_exists('mysqli_connect')) { - throw new Exception('PHP not compiled with mysqli support.'); - } + // Connect to database + $this->mysqli = new mysqli($host, $username, $password); + if (! $this->mysqli) { + throw new Exception('mysqli_connect() failed - check permissions and spelling.'); + } - // Connect to database - $this->mysqli = new mysqli($host, $username, $password); - if (!$this->mysqli) { - throw new Exception('mysqli_connect() failed - check permissions and spelling.'); - } + // Select database + if (! $this->mysqli->select_db($database)) { + throw new Exception('Cannot use database '.$database); + } - // Select database - if (!$this->mysqli->select_db($database)) { - throw new Exception('Cannot use database '.$database); - } + // Set table + $this->table = $table; - // Set table - $this->table = $table; + // Create cache table if not exists + $this->create_table(); - // Create cache table if not exists - $this->create_table(); + // Check version number and clear cache if changed + $version = ''; + $SQLquery = 'SELECT `value`'; + $SQLquery .= ' FROM `'.$this->mysqli->real_escape_string($this->table).'`'; + $SQLquery .= ' WHERE (`filename` = \''.$this->mysqli->real_escape_string(getID3::VERSION).'\')'; + $SQLquery .= ' AND (`filesize` = -1)'; + $SQLquery .= ' AND (`filetime` = -1)'; + $SQLquery .= ' AND (`analyzetime` = -1)'; + if ($this->cursor = $this->mysqli->query($SQLquery)) { + list($version) = $this->cursor->fetch_array(); + } + if ($version != getID3::VERSION) { + $this->clear_cache(); + } - // Check version number and clear cache if changed - $version = ''; - $SQLquery = 'SELECT `value`'; - $SQLquery .= ' FROM `'.$this->mysqli->real_escape_string($this->table).'`'; - $SQLquery .= ' WHERE (`filename` = \''.$this->mysqli->real_escape_string(getID3::VERSION).'\')'; - $SQLquery .= ' AND (`filesize` = -1)'; - $SQLquery .= ' AND (`filetime` = -1)'; - $SQLquery .= ' AND (`analyzetime` = -1)'; - if ($this->cursor = $this->mysqli->query($SQLquery)) { - list($version) = $this->cursor->fetch_array(); - } - if ($version != getID3::VERSION) { - $this->clear_cache(); - } + parent::__construct(); + } - parent::__construct(); - } + // public: clear cache + public function clear_cache() + { + $this->mysqli->query('DELETE FROM `'.$this->mysqli->real_escape_string($this->table).'`'); + $this->mysqli->query('INSERT INTO `'.$this->mysqli->real_escape_string($this->table).'` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES (\''.getID3::VERSION.'\', -1, -1, -1, \''.getID3::VERSION.'\')'); + } + // public: analyze file + public function analyze($filename, $filesize = null, $original_filename = '') + { + if (file_exists($filename)) { - // public: clear cache - public function clear_cache() { - $this->mysqli->query('DELETE FROM `'.$this->mysqli->real_escape_string($this->table).'`'); - $this->mysqli->query('INSERT INTO `'.$this->mysqli->real_escape_string($this->table).'` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES (\''.getID3::VERSION.'\', -1, -1, -1, \''.getID3::VERSION.'\')'); - } + // Short-hands + $filetime = filemtime($filename); + $filesize = filesize($filename); + // Lookup file + $SQLquery = 'SELECT `value`'; + $SQLquery .= ' FROM `'.$this->mysqli->real_escape_string($this->table).'`'; + $SQLquery .= ' WHERE (`filename` = \''.$this->mysqli->real_escape_string($filename).'\')'; + $SQLquery .= ' AND (`filesize` = \''.$this->mysqli->real_escape_string($filesize).'\')'; + $SQLquery .= ' AND (`filetime` = \''.$this->mysqli->real_escape_string($filetime).'\')'; + $this->cursor = $this->mysqli->query($SQLquery); + if ($this->cursor->num_rows > 0) { + // Hit + list($result) = $this->cursor->fetch_array(); - // public: analyze file - public function analyze($filename, $filesize=null, $original_filename='') { + return unserialize(base64_decode($result)); + } + } - if (file_exists($filename)) { + // Miss + $analysis = parent::analyze($filename, $filesize, $original_filename); - // Short-hands - $filetime = filemtime($filename); - $filesize = filesize($filename); + // Save result + if (file_exists($filename)) { + $SQLquery = 'INSERT INTO `'.$this->mysqli->real_escape_string($this->table).'` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES ('; + $SQLquery .= '\''.$this->mysqli->real_escape_string($filename).'\''; + $SQLquery .= ', \''.$this->mysqli->real_escape_string($filesize).'\''; + $SQLquery .= ', \''.$this->mysqli->real_escape_string($filetime).'\''; + $SQLquery .= ', \''.$this->mysqli->real_escape_string(time()).'\''; + $SQLquery .= ', \''.$this->mysqli->real_escape_string(base64_encode(serialize($analysis))).'\')'; + $this->cursor = $this->mysqli->query($SQLquery); + } - // Lookup file - $SQLquery = 'SELECT `value`'; - $SQLquery .= ' FROM `'.$this->mysqli->real_escape_string($this->table).'`'; - $SQLquery .= ' WHERE (`filename` = \''.$this->mysqli->real_escape_string($filename).'\')'; - $SQLquery .= ' AND (`filesize` = \''.$this->mysqli->real_escape_string($filesize).'\')'; - $SQLquery .= ' AND (`filetime` = \''.$this->mysqli->real_escape_string($filetime).'\')'; - $this->cursor = $this->mysqli->query($SQLquery); - if ($this->cursor->num_rows > 0) { - // Hit - list($result) = $this->cursor->fetch_array(); - return unserialize(base64_decode($result)); - } - } + return $analysis; + } - // Miss - $analysis = parent::analyze($filename, $filesize, $original_filename); - - // Save result - if (file_exists($filename)) { - $SQLquery = 'INSERT INTO `'.$this->mysqli->real_escape_string($this->table).'` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES ('; - $SQLquery .= '\''.$this->mysqli->real_escape_string($filename).'\''; - $SQLquery .= ', \''.$this->mysqli->real_escape_string($filesize).'\''; - $SQLquery .= ', \''.$this->mysqli->real_escape_string($filetime).'\''; - $SQLquery .= ', \''.$this->mysqli->real_escape_string(time() ).'\''; - $SQLquery .= ', \''.$this->mysqli->real_escape_string(base64_encode(serialize($analysis))).'\')'; - $this->cursor = $this->mysqli->query($SQLquery); - } - return $analysis; - } - - - // private: (re)create mysqli table - private function create_table($drop=false) { - $SQLquery = 'CREATE TABLE IF NOT EXISTS `'.$this->mysqli->real_escape_string($this->table).'` ('; - $SQLquery .= '`filename` VARCHAR(990) NOT NULL DEFAULT \'\''; - $SQLquery .= ', `filesize` INT(11) NOT NULL DEFAULT \'0\''; - $SQLquery .= ', `filetime` INT(11) NOT NULL DEFAULT \'0\''; - $SQLquery .= ', `analyzetime` INT(11) NOT NULL DEFAULT \'0\''; - $SQLquery .= ', `value` LONGTEXT NOT NULL'; - $SQLquery .= ', PRIMARY KEY (`filename`, `filesize`, `filetime`)) ENGINE=MyISAM CHARACTER SET=latin1 COLLATE=latin1_general_ci'; - $this->cursor = $this->mysqli->query($SQLquery); - echo $this->mysqli->error; - } -} \ No newline at end of file + // private: (re)create mysqli table + private function create_table($drop = false) + { + $SQLquery = 'CREATE TABLE IF NOT EXISTS `'.$this->mysqli->real_escape_string($this->table).'` ('; + $SQLquery .= '`filename` VARCHAR(990) NOT NULL DEFAULT \'\''; + $SQLquery .= ', `filesize` INT(11) NOT NULL DEFAULT \'0\''; + $SQLquery .= ', `filetime` INT(11) NOT NULL DEFAULT \'0\''; + $SQLquery .= ', `analyzetime` INT(11) NOT NULL DEFAULT \'0\''; + $SQLquery .= ', `value` LONGTEXT NOT NULL'; + $SQLquery .= ', PRIMARY KEY (`filename`, `filesize`, `filetime`)) ENGINE=MyISAM CHARACTER SET=latin1 COLLATE=latin1_general_ci'; + $this->cursor = $this->mysqli->query($SQLquery); + echo $this->mysqli->error; + } +} diff --git a/app/Library/getid3/getid3/extension.cache.sqlite3.php b/app/Library/getid3/getid3/extension.cache.sqlite3.php index 58d4dc88..93248cda 100644 --- a/app/Library/getid3/getid3/extension.cache.sqlite3.php +++ b/app/Library/getid3/getid3/extension.cache.sqlite3.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -17,250 +18,258 @@ // /// ///////////////////////////////////////////////////////////////////////////////// /** -* This is a caching extension for getID3(). It works the exact same -* way as the getID3 class, but return cached information much faster -* -* Normal getID3 usage (example): -* -* require_once 'getid3/getid3.php'; -* $getID3 = new getID3; -* $getID3->encoding = 'UTF-8'; -* $info1 = $getID3->analyze('file1.flac'); -* $info2 = $getID3->analyze('file2.wv'); -* -* getID3_cached usage: -* -* require_once 'getid3/getid3.php'; -* require_once 'getid3/extension.cache.sqlite3.php'; -* // all parameters are optional, defaults are: -* $getID3 = new getID3_cached_sqlite3($table='getid3_cache', $hide=FALSE); -* $getID3->encoding = 'UTF-8'; -* $info1 = $getID3->analyze('file1.flac'); -* $info2 = $getID3->analyze('file2.wv'); -* -* -* Supported Cache Types (this extension) -* -* SQL Databases: -* -* cache_type cache_options -* ------------------------------------------------------------------- -* mysql host, database, username, password -* -* sqlite3 table='getid3_cache', hide=false (PHP5) -* -* -* *** database file will be stored in the same directory as this script, -* *** webserver must have write access to that directory! -* *** set $hide to TRUE to prefix db file with .ht to pervent access from web client -* *** this is a default setting in the Apache configuration: -* -* The following lines prevent .htaccess and .htpasswd files from being viewed by Web clients. -* -* -* Order allow,deny -* Deny from all -* Satisfy all -* -* -******************************************************************************** -* -* ------------------------------------------------------------------- -* DBM-Style Databases: (use extension.cache.dbm) -* -* cache_type cache_options -* ------------------------------------------------------------------- -* gdbm dbm_filename, lock_filename -* ndbm dbm_filename, lock_filename -* db2 dbm_filename, lock_filename -* db3 dbm_filename, lock_filename -* db4 dbm_filename, lock_filename (PHP5 required) -* -* PHP must have write access to both dbm_filename and lock_filename. -* -* Recommended Cache Types -* -* Infrequent updates, many reads any DBM -* Frequent updates mysql -******************************************************************************** -* -* IMHO this is still a bit slow, I'm using this with MP4/MOV/ M4v files -* there is a plan to add directory scanning and analyzing to make things work much faster -* -* -*/ -class getID3_cached_sqlite3 extends getID3 { + * This is a caching extension for getID3(). It works the exact same + * way as the getID3 class, but return cached information much faster. + * + * Normal getID3 usage (example): + * + * require_once 'getid3/getid3.php'; + * $getID3 = new getID3; + * $getID3->encoding = 'UTF-8'; + * $info1 = $getID3->analyze('file1.flac'); + * $info2 = $getID3->analyze('file2.wv'); + * + * getID3_cached usage: + * + * require_once 'getid3/getid3.php'; + * require_once 'getid3/extension.cache.sqlite3.php'; + * // all parameters are optional, defaults are: + * $getID3 = new getID3_cached_sqlite3($table='getid3_cache', $hide=FALSE); + * $getID3->encoding = 'UTF-8'; + * $info1 = $getID3->analyze('file1.flac'); + * $info2 = $getID3->analyze('file2.wv'); + * + * + * Supported Cache Types (this extension) + * + * SQL Databases: + * + * cache_type cache_options + * ------------------------------------------------------------------- + * mysql host, database, username, password + * + * sqlite3 table='getid3_cache', hide=false (PHP5) + * + * + * *** database file will be stored in the same directory as this script, + * *** webserver must have write access to that directory! + * *** set $hide to TRUE to prefix db file with .ht to pervent access from web client + * *** this is a default setting in the Apache configuration: + * + * The following lines prevent .htaccess and .htpasswd files from being viewed by Web clients. + * + * + * Order allow,deny + * Deny from all + * Satisfy all + * + * + ******************************************************************************** + * + * ------------------------------------------------------------------- + * DBM-Style Databases: (use extension.cache.dbm) + * + * cache_type cache_options + * ------------------------------------------------------------------- + * gdbm dbm_filename, lock_filename + * ndbm dbm_filename, lock_filename + * db2 dbm_filename, lock_filename + * db3 dbm_filename, lock_filename + * db4 dbm_filename, lock_filename (PHP5 required) + * + * PHP must have write access to both dbm_filename and lock_filename. + * + * Recommended Cache Types + * + * Infrequent updates, many reads any DBM + * Frequent updates mysql + ******************************************************************************** + * + * IMHO this is still a bit slow, I'm using this with MP4/MOV/ M4v files + * there is a plan to add directory scanning and analyzing to make things work much faster + */ +class getID3_cached_sqlite3 extends getID3 +{ + /** + * __construct(). + * @param string $table holds name of sqlite table + * @return type + */ + public function __construct($table = 'getid3_cache', $hide = false) + { + $this->table = $table; // Set table + $file = dirname(__FILE__).'/'.basename(__FILE__, 'php').'sqlite'; + if ($hide) { + $file = dirname(__FILE__).'/.ht.'.basename(__FILE__, 'php').'sqlite'; + } + $this->db = new SQLite3($file); + $db = $this->db; + $this->create_table(); // Create cache table if not exists + $version = ''; + $sql = $this->version_check; + $stmt = $db->prepare($sql); + $stmt->bindValue(':filename', getID3::VERSION, SQLITE3_TEXT); + $result = $stmt->execute(); + list($version) = $result->fetchArray(); + if ($version != getID3::VERSION) { // Check version number and clear cache if changed + $this->clear_cache(); + } - /** - * __construct() - * @param string $table holds name of sqlite table - * @return type - */ - public function __construct($table='getid3_cache', $hide=false) { - $this->table = $table; // Set table - $file = dirname(__FILE__).'/'.basename(__FILE__, 'php').'sqlite'; - if ($hide) { - $file = dirname(__FILE__).'/.ht.'.basename(__FILE__, 'php').'sqlite'; - } - $this->db = new SQLite3($file); - $db = $this->db; - $this->create_table(); // Create cache table if not exists - $version = ''; - $sql = $this->version_check; - $stmt = $db->prepare($sql); - $stmt->bindValue(':filename', getID3::VERSION, SQLITE3_TEXT); - $result = $stmt->execute(); - list($version) = $result->fetchArray(); - if ($version != getID3::VERSION) { // Check version number and clear cache if changed - $this->clear_cache(); - } - return parent::__construct(); - } + return parent::__construct(); + } - /** - * close the database connection - */ - public function __destruct() { - $db=$this->db; - $db->close(); - } + /** + * close the database connection. + */ + public function __destruct() + { + $db = $this->db; + $db->close(); + } - /** - * hold the sqlite db - * @var SQLite Resource - */ - private $db; + /** + * hold the sqlite db. + * @var SQLite Resource + */ + private $db; - /** - * table to use for caching - * @var string $table - */ - private $table; + /** + * table to use for caching. + * @var string + */ + private $table; - /** - * clear the cache - * @access private - * @return type - */ - private function clear_cache() { - $db = $this->db; - $sql = $this->delete_cache; - $db->exec($sql); - $sql = $this->set_version; - $stmt = $db->prepare($sql); - $stmt->bindValue(':filename', getID3::VERSION, SQLITE3_TEXT); - $stmt->bindValue(':dirname', getID3::VERSION, SQLITE3_TEXT); - $stmt->bindValue(':val', getID3::VERSION, SQLITE3_TEXT); - return $stmt->execute(); - } + /** + * clear the cache. + * @return type + */ + private function clear_cache() + { + $db = $this->db; + $sql = $this->delete_cache; + $db->exec($sql); + $sql = $this->set_version; + $stmt = $db->prepare($sql); + $stmt->bindValue(':filename', getID3::VERSION, SQLITE3_TEXT); + $stmt->bindValue(':dirname', getID3::VERSION, SQLITE3_TEXT); + $stmt->bindValue(':val', getID3::VERSION, SQLITE3_TEXT); - /** - * analyze file and cache them, if cached pull from the db - * @param type $filename - * @return boolean - */ - public function analyze($filename, $filesize=null, $original_filename='') { - if (!file_exists($filename)) { - return false; - } - // items to track for caching - $filetime = filemtime($filename); - $filesize_real = filesize($filename); - // this will be saved for a quick directory lookup of analized files - // ... why do 50 seperate sql quries when you can do 1 for the same result - $dirname = dirname($filename); - // Lookup file - $db = $this->db; - $sql = $this->get_id3_data; - $stmt = $db->prepare($sql); - $stmt->bindValue(':filename', $filename, SQLITE3_TEXT); - $stmt->bindValue(':filesize', $filesize_real, SQLITE3_INTEGER); - $stmt->bindValue(':filetime', $filetime, SQLITE3_INTEGER); - $res = $stmt->execute(); - list($result) = $res->fetchArray(); - if (count($result) > 0 ) { - return unserialize(base64_decode($result)); - } - // if it hasn't been analyzed before, then do it now - $analysis = parent::analyze($filename, $filesize, $original_filename); - // Save result - $sql = $this->cache_file; - $stmt = $db->prepare($sql); - $stmt->bindValue(':filename', $filename, SQLITE3_TEXT); - $stmt->bindValue(':dirname', $dirname, SQLITE3_TEXT); - $stmt->bindValue(':filesize', $filesize_real, SQLITE3_INTEGER); - $stmt->bindValue(':filetime', $filetime, SQLITE3_INTEGER); - $stmt->bindValue(':atime', time(), SQLITE3_INTEGER); - $stmt->bindValue(':val', base64_encode(serialize($analysis)), SQLITE3_TEXT); - $res = $stmt->execute(); - return $analysis; - } + return $stmt->execute(); + } - /** - * create data base table - * this is almost the same as MySQL, with the exception of the dirname being added - * @return type - */ - private function create_table() { - $db = $this->db; - $sql = $this->make_table; - return $db->exec($sql); - } + /** + * analyze file and cache them, if cached pull from the db. + * @param type $filename + * @return bool + */ + public function analyze($filename, $filesize = null, $original_filename = '') + { + if (! file_exists($filename)) { + return false; + } + // items to track for caching + $filetime = filemtime($filename); + $filesize_real = filesize($filename); + // this will be saved for a quick directory lookup of analized files + // ... why do 50 seperate sql quries when you can do 1 for the same result + $dirname = dirname($filename); + // Lookup file + $db = $this->db; + $sql = $this->get_id3_data; + $stmt = $db->prepare($sql); + $stmt->bindValue(':filename', $filename, SQLITE3_TEXT); + $stmt->bindValue(':filesize', $filesize_real, SQLITE3_INTEGER); + $stmt->bindValue(':filetime', $filetime, SQLITE3_INTEGER); + $res = $stmt->execute(); + list($result) = $res->fetchArray(); + if (count($result) > 0) { + return unserialize(base64_decode($result)); + } + // if it hasn't been analyzed before, then do it now + $analysis = parent::analyze($filename, $filesize, $original_filename); + // Save result + $sql = $this->cache_file; + $stmt = $db->prepare($sql); + $stmt->bindValue(':filename', $filename, SQLITE3_TEXT); + $stmt->bindValue(':dirname', $dirname, SQLITE3_TEXT); + $stmt->bindValue(':filesize', $filesize_real, SQLITE3_INTEGER); + $stmt->bindValue(':filetime', $filetime, SQLITE3_INTEGER); + $stmt->bindValue(':atime', time(), SQLITE3_INTEGER); + $stmt->bindValue(':val', base64_encode(serialize($analysis)), SQLITE3_TEXT); + $res = $stmt->execute(); - /** - * get cached directory - * - * This function is not in the MySQL extention, it's ment to speed up requesting multiple files - * which is ideal for podcasting, playlists, etc. - * - * @access public - * @param string $dir directory to search the cache database for - * @return array return an array of matching id3 data - */ - public function get_cached_dir($dir) { - $db = $this->db; - $rows = array(); - $sql = $this->get_cached_dir; - $stmt = $db->prepare($sql); - $stmt->bindValue(':dirname', $dir, SQLITE3_TEXT); - $res = $stmt->execute(); - while ($row=$res->fetchArray()) { - $rows[] = unserialize(base64_decode($row)); - } - return $rows; - } + return $analysis; + } - /** - * use the magical __get() for sql queries - * - * access as easy as $this->{case name}, returns NULL if query is not found - */ - public function __get($name) { - switch($name) { - case 'version_check': - return "SELECT val FROM $this->table WHERE filename = :filename AND filesize = '-1' AND filetime = '-1' AND analyzetime = '-1'"; - break; - case 'delete_cache': - return "DELETE FROM $this->table"; - break; - case 'set_version': - return "INSERT INTO $this->table (filename, dirname, filesize, filetime, analyzetime, val) VALUES (:filename, :dirname, -1, -1, -1, :val)"; - break; - case 'get_id3_data': - return "SELECT val FROM $this->table WHERE filename = :filename AND filesize = :filesize AND filetime = :filetime"; - break; - case 'cache_file': - return "INSERT INTO $this->table (filename, dirname, filesize, filetime, analyzetime, val) VALUES (:filename, :dirname, :filesize, :filetime, :atime, :val)"; - break; - case 'make_table': - //return "CREATE TABLE IF NOT EXISTS $this->table (filename VARCHAR(255) NOT NULL DEFAULT '', dirname VARCHAR(255) NOT NULL DEFAULT '', filesize INT(11) NOT NULL DEFAULT '0', filetime INT(11) NOT NULL DEFAULT '0', analyzetime INT(11) NOT NULL DEFAULT '0', val text not null, PRIMARY KEY (filename, filesize, filetime))"; - return "CREATE TABLE IF NOT EXISTS $this->table (filename VARCHAR(255) DEFAULT '', dirname VARCHAR(255) DEFAULT '', filesize INT(11) DEFAULT '0', filetime INT(11) DEFAULT '0', analyzetime INT(11) DEFAULT '0', val text, PRIMARY KEY (filename, filesize, filetime))"; - break; - case 'get_cached_dir': - return "SELECT val FROM $this->table WHERE dirname = :dirname"; - break; - } - return null; - } + /** + * create data base table + * this is almost the same as MySQL, with the exception of the dirname being added. + * @return type + */ + private function create_table() + { + $db = $this->db; + $sql = $this->make_table; + return $db->exec($sql); + } + + /** + * get cached directory. + * + * This function is not in the MySQL extention, it's ment to speed up requesting multiple files + * which is ideal for podcasting, playlists, etc. + * + * @param string $dir directory to search the cache database for + * @return array return an array of matching id3 data + */ + public function get_cached_dir($dir) + { + $db = $this->db; + $rows = []; + $sql = $this->get_cached_dir; + $stmt = $db->prepare($sql); + $stmt->bindValue(':dirname', $dir, SQLITE3_TEXT); + $res = $stmt->execute(); + while ($row = $res->fetchArray()) { + $rows[] = unserialize(base64_decode($row)); + } + + return $rows; + } + + /** + * use the magical __get() for sql queries. + * + * access as easy as $this->{case name}, returns NULL if query is not found + */ + public function __get($name) + { + switch ($name) { + case 'version_check': + return "SELECT val FROM $this->table WHERE filename = :filename AND filesize = '-1' AND filetime = '-1' AND analyzetime = '-1'"; + break; + case 'delete_cache': + return "DELETE FROM $this->table"; + break; + case 'set_version': + return "INSERT INTO $this->table (filename, dirname, filesize, filetime, analyzetime, val) VALUES (:filename, :dirname, -1, -1, -1, :val)"; + break; + case 'get_id3_data': + return "SELECT val FROM $this->table WHERE filename = :filename AND filesize = :filesize AND filetime = :filetime"; + break; + case 'cache_file': + return "INSERT INTO $this->table (filename, dirname, filesize, filetime, analyzetime, val) VALUES (:filename, :dirname, :filesize, :filetime, :atime, :val)"; + break; + case 'make_table': + //return "CREATE TABLE IF NOT EXISTS $this->table (filename VARCHAR(255) NOT NULL DEFAULT '', dirname VARCHAR(255) NOT NULL DEFAULT '', filesize INT(11) NOT NULL DEFAULT '0', filetime INT(11) NOT NULL DEFAULT '0', analyzetime INT(11) NOT NULL DEFAULT '0', val text not null, PRIMARY KEY (filename, filesize, filetime))"; + return "CREATE TABLE IF NOT EXISTS $this->table (filename VARCHAR(255) DEFAULT '', dirname VARCHAR(255) DEFAULT '', filesize INT(11) DEFAULT '0', filetime INT(11) DEFAULT '0', analyzetime INT(11) DEFAULT '0', val text, PRIMARY KEY (filename, filesize, filetime))"; + break; + case 'get_cached_dir': + return "SELECT val FROM $this->table WHERE dirname = :dirname"; + break; + } + + return null; + } } diff --git a/app/Library/getid3/getid3/getid3.lib.php b/app/Library/getid3/getid3/getid3.lib.php index 808f5921..369a4540 100644 --- a/app/Library/getid3/getid3/getid3.lib.php +++ b/app/Library/getid3/getid3/getid3.lib.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -11,1423 +12,1508 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_lib { - - public static function PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8') { - $returnstring = ''; - for ($i = 0; $i < strlen($string); $i++) { - if ($hex) { - $returnstring .= str_pad(dechex(ord($string{$i})), 2, '0', STR_PAD_LEFT); - } else { - $returnstring .= ' '.(preg_match("#[\x20-\x7E]#", $string{$i}) ? $string{$i} : '¤'); - } - if ($spaces) { - $returnstring .= ' '; - } - } - if (!empty($htmlencoding)) { - if ($htmlencoding === true) { - $htmlencoding = 'UTF-8'; // prior to getID3 v1.9.0 the function's 4th parameter was boolean - } - $returnstring = htmlentities($returnstring, ENT_QUOTES, $htmlencoding); - } - return $returnstring; - } - - public static function trunc($floatnumber) { - // truncates a floating-point number at the decimal point - // returns int (if possible, otherwise float) - if ($floatnumber >= 1) { - $truncatednumber = floor($floatnumber); - } elseif ($floatnumber <= -1) { - $truncatednumber = ceil($floatnumber); - } else { - $truncatednumber = 0; - } - if (self::intValueSupported($truncatednumber)) { - $truncatednumber = (int) $truncatednumber; - } - return $truncatednumber; - } - - - public static function safe_inc(&$variable, $increment=1) { - if (isset($variable)) { - $variable += $increment; - } else { - $variable = $increment; - } - return true; - } - - public static function CastAsInt($floatnum) { - // convert to float if not already - $floatnum = (float) $floatnum; - - // convert a float to type int, only if possible - if (self::trunc($floatnum) == $floatnum) { - // it's not floating point - if (self::intValueSupported($floatnum)) { - // it's within int range - $floatnum = (int) $floatnum; - } - } - return $floatnum; - } - - public static function intValueSupported($num) { - // check if integers are 64-bit - static $hasINT64 = null; - if ($hasINT64 === null) { // 10x faster than is_null() - $hasINT64 = is_int(pow(2, 31)); // 32-bit int are limited to (2^31)-1 - if (!$hasINT64 && !defined('PHP_INT_MIN')) { - define('PHP_INT_MIN', ~PHP_INT_MAX); - } - } - // if integers are 64-bit - no other check required - if ($hasINT64 || (($num <= PHP_INT_MAX) && ($num >= PHP_INT_MIN))) { - return true; - } - return false; - } - - public static function DecimalizeFraction($fraction) { - list($numerator, $denominator) = explode('/', $fraction); - return $numerator / ($denominator ? $denominator : 1); - } - - - public static function DecimalBinary2Float($binarynumerator) { - $numerator = self::Bin2Dec($binarynumerator); - $denominator = self::Bin2Dec('1'.str_repeat('0', strlen($binarynumerator))); - return ($numerator / $denominator); - } - - - public static function NormalizeBinaryPoint($binarypointnumber, $maxbits=52) { - // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html - if (strpos($binarypointnumber, '.') === false) { - $binarypointnumber = '0.'.$binarypointnumber; - } elseif ($binarypointnumber{0} == '.') { - $binarypointnumber = '0'.$binarypointnumber; - } - $exponent = 0; - while (($binarypointnumber{0} != '1') || (substr($binarypointnumber, 1, 1) != '.')) { - if (substr($binarypointnumber, 1, 1) == '.') { - $exponent--; - $binarypointnumber = substr($binarypointnumber, 2, 1).'.'.substr($binarypointnumber, 3); - } else { - $pointpos = strpos($binarypointnumber, '.'); - $exponent += ($pointpos - 1); - $binarypointnumber = str_replace('.', '', $binarypointnumber); - $binarypointnumber = $binarypointnumber{0}.'.'.substr($binarypointnumber, 1); - } - } - $binarypointnumber = str_pad(substr($binarypointnumber, 0, $maxbits + 2), $maxbits + 2, '0', STR_PAD_RIGHT); - return array('normalized'=>$binarypointnumber, 'exponent'=>(int) $exponent); - } - - - public static function Float2BinaryDecimal($floatvalue) { - // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html - $maxbits = 128; // to how many bits of precision should the calculations be taken? - $intpart = self::trunc($floatvalue); - $floatpart = abs($floatvalue - $intpart); - $pointbitstring = ''; - while (($floatpart != 0) && (strlen($pointbitstring) < $maxbits)) { - $floatpart *= 2; - $pointbitstring .= (string) self::trunc($floatpart); - $floatpart -= self::trunc($floatpart); - } - $binarypointnumber = decbin($intpart).'.'.$pointbitstring; - return $binarypointnumber; - } - - - public static function Float2String($floatvalue, $bits) { - // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html - switch ($bits) { - case 32: - $exponentbits = 8; - $fractionbits = 23; - break; - - case 64: - $exponentbits = 11; - $fractionbits = 52; - break; - - default: - return false; - break; - } - if ($floatvalue >= 0) { - $signbit = '0'; - } else { - $signbit = '1'; - } - $normalizedbinary = self::NormalizeBinaryPoint(self::Float2BinaryDecimal($floatvalue), $fractionbits); - $biasedexponent = pow(2, $exponentbits - 1) - 1 + $normalizedbinary['exponent']; // (127 or 1023) +/- exponent - $exponentbitstring = str_pad(decbin($biasedexponent), $exponentbits, '0', STR_PAD_LEFT); - $fractionbitstring = str_pad(substr($normalizedbinary['normalized'], 2), $fractionbits, '0', STR_PAD_RIGHT); - - return self::BigEndian2String(self::Bin2Dec($signbit.$exponentbitstring.$fractionbitstring), $bits % 8, false); - } - - - public static function LittleEndian2Float($byteword) { - return self::BigEndian2Float(strrev($byteword)); - } - - - public static function BigEndian2Float($byteword) { - // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic - // http://www.psc.edu/general/software/packages/ieee/ieee.html - // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html - - $bitword = self::BigEndian2Bin($byteword); - if (!$bitword) { - return 0; - } - $signbit = $bitword{0}; - - switch (strlen($byteword) * 8) { - case 32: - $exponentbits = 8; - $fractionbits = 23; - break; - - case 64: - $exponentbits = 11; - $fractionbits = 52; - break; - - case 80: - // 80-bit Apple SANE format - // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/ - $exponentstring = substr($bitword, 1, 15); - $isnormalized = intval($bitword{16}); - $fractionstring = substr($bitword, 17, 63); - $exponent = pow(2, self::Bin2Dec($exponentstring) - 16383); - $fraction = $isnormalized + self::DecimalBinary2Float($fractionstring); - $floatvalue = $exponent * $fraction; - if ($signbit == '1') { - $floatvalue *= -1; - } - return $floatvalue; - break; - - default: - return false; - break; - } - $exponentstring = substr($bitword, 1, $exponentbits); - $fractionstring = substr($bitword, $exponentbits + 1, $fractionbits); - $exponent = self::Bin2Dec($exponentstring); - $fraction = self::Bin2Dec($fractionstring); - - if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) { - // Not a Number - $floatvalue = false; - } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) { - if ($signbit == '1') { - $floatvalue = '-infinity'; - } else { - $floatvalue = '+infinity'; - } - } elseif (($exponent == 0) && ($fraction == 0)) { - if ($signbit == '1') { - $floatvalue = -0; - } else { - $floatvalue = 0; - } - $floatvalue = ($signbit ? 0 : -0); - } elseif (($exponent == 0) && ($fraction != 0)) { - // These are 'unnormalized' values - $floatvalue = pow(2, (-1 * (pow(2, $exponentbits - 1) - 2))) * self::DecimalBinary2Float($fractionstring); - if ($signbit == '1') { - $floatvalue *= -1; - } - } elseif ($exponent != 0) { - $floatvalue = pow(2, ($exponent - (pow(2, $exponentbits - 1) - 1))) * (1 + self::DecimalBinary2Float($fractionstring)); - if ($signbit == '1') { - $floatvalue *= -1; - } - } - return (float) $floatvalue; - } - - - public static function BigEndian2Int($byteword, $synchsafe=false, $signed=false) { - $intvalue = 0; - $bytewordlen = strlen($byteword); - if ($bytewordlen == 0) { - return false; - } - for ($i = 0; $i < $bytewordlen; $i++) { - if ($synchsafe) { // disregard MSB, effectively 7-bit bytes - //$intvalue = $intvalue | (ord($byteword{$i}) & 0x7F) << (($bytewordlen - 1 - $i) * 7); // faster, but runs into problems past 2^31 on 32-bit systems - $intvalue += (ord($byteword{$i}) & 0x7F) * pow(2, ($bytewordlen - 1 - $i) * 7); - } else { - $intvalue += ord($byteword{$i}) * pow(256, ($bytewordlen - 1 - $i)); - } - } - if ($signed && !$synchsafe) { - // synchsafe ints are not allowed to be signed - if ($bytewordlen <= PHP_INT_SIZE) { - $signMaskBit = 0x80 << (8 * ($bytewordlen - 1)); - if ($intvalue & $signMaskBit) { - $intvalue = 0 - ($intvalue & ($signMaskBit - 1)); - } - } else { - throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits ('.strlen($byteword).') in self::BigEndian2Int()'); - } - } - return self::CastAsInt($intvalue); - } - - - public static function LittleEndian2Int($byteword, $signed=false) { - return self::BigEndian2Int(strrev($byteword), false, $signed); - } - - - public static function BigEndian2Bin($byteword) { - $binvalue = ''; - $bytewordlen = strlen($byteword); - for ($i = 0; $i < $bytewordlen; $i++) { - $binvalue .= str_pad(decbin(ord($byteword{$i})), 8, '0', STR_PAD_LEFT); - } - return $binvalue; - } - - - public static function BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false) { - if ($number < 0) { - throw new Exception('ERROR: self::BigEndian2String() does not support negative numbers'); - } - $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF); - $intstring = ''; - if ($signed) { - if ($minbytes > PHP_INT_SIZE) { - throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits in self::BigEndian2String()'); - } - $number = $number & (0x80 << (8 * ($minbytes - 1))); - } - while ($number != 0) { - $quotient = ($number / ($maskbyte + 1)); - $intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)).$intstring; - $number = floor($quotient); - } - return str_pad($intstring, $minbytes, "\x00", STR_PAD_LEFT); - } - - - public static function Dec2Bin($number) { - while ($number >= 256) { - $bytes[] = (($number / 256) - (floor($number / 256))) * 256; - $number = floor($number / 256); - } - $bytes[] = $number; - $binstring = ''; - for ($i = 0; $i < count($bytes); $i++) { - $binstring = (($i == count($bytes) - 1) ? decbin($bytes[$i]) : str_pad(decbin($bytes[$i]), 8, '0', STR_PAD_LEFT)).$binstring; - } - return $binstring; - } - - - public static function Bin2Dec($binstring, $signed=false) { - $signmult = 1; - if ($signed) { - if ($binstring{0} == '1') { - $signmult = -1; - } - $binstring = substr($binstring, 1); - } - $decvalue = 0; - for ($i = 0; $i < strlen($binstring); $i++) { - $decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1, 1)) * pow(2, $i); - } - return self::CastAsInt($decvalue * $signmult); - } - - - public static function Bin2String($binstring) { - // return 'hi' for input of '0110100001101001' - $string = ''; - $binstringreversed = strrev($binstring); - for ($i = 0; $i < strlen($binstringreversed); $i += 8) { - $string = chr(self::Bin2Dec(strrev(substr($binstringreversed, $i, 8)))).$string; - } - return $string; - } - - - public static function LittleEndian2String($number, $minbytes=1, $synchsafe=false) { - $intstring = ''; - while ($number > 0) { - if ($synchsafe) { - $intstring = $intstring.chr($number & 127); - $number >>= 7; - } else { - $intstring = $intstring.chr($number & 255); - $number >>= 8; - } - } - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); - } - - - public static function array_merge_clobber($array1, $array2) { - // written by kcØhireability*com - // taken from http://www.php.net/manual/en/function.array-merge-recursive.php - if (!is_array($array1) || !is_array($array2)) { - return false; - } - $newarray = $array1; - foreach ($array2 as $key => $val) { - if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { - $newarray[$key] = self::array_merge_clobber($newarray[$key], $val); - } else { - $newarray[$key] = $val; - } - } - return $newarray; - } - - - public static function array_merge_noclobber($array1, $array2) { - if (!is_array($array1) || !is_array($array2)) { - return false; - } - $newarray = $array1; - foreach ($array2 as $key => $val) { - if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { - $newarray[$key] = self::array_merge_noclobber($newarray[$key], $val); - } elseif (!isset($newarray[$key])) { - $newarray[$key] = $val; - } - } - return $newarray; - } - - public static function flipped_array_merge_noclobber($array1, $array2) { - if (!is_array($array1) || !is_array($array2)) { - return false; - } - # naturally, this only works non-recursively - $newarray = array_flip($array1); - foreach (array_flip($array2) as $key => $val) { - if (!isset($newarray[$key])) { - $newarray[$key] = count($newarray); - } - } - return array_flip($newarray); - } - - - public static function ksort_recursive(&$theArray) { - ksort($theArray); - foreach ($theArray as $key => $value) { - if (is_array($value)) { - self::ksort_recursive($theArray[$key]); - } - } - return true; - } - - public static function fileextension($filename, $numextensions=1) { - if (strstr($filename, '.')) { - $reversedfilename = strrev($filename); - $offset = 0; - for ($i = 0; $i < $numextensions; $i++) { - $offset = strpos($reversedfilename, '.', $offset + 1); - if ($offset === false) { - return ''; - } - } - return strrev(substr($reversedfilename, 0, $offset)); - } - return ''; - } - - - public static function PlaytimeString($seconds) { - $sign = (($seconds < 0) ? '-' : ''); - $seconds = round(abs($seconds)); - $H = (int) floor( $seconds / 3600); - $M = (int) floor(($seconds - (3600 * $H) ) / 60); - $S = (int) round( $seconds - (3600 * $H) - (60 * $M) ); - return $sign.($H ? $H.':' : '').($H ? str_pad($M, 2, '0', STR_PAD_LEFT) : intval($M)).':'.str_pad($S, 2, 0, STR_PAD_LEFT); - } - - - public static function DateMac2Unix($macdate) { - // Macintosh timestamp: seconds since 00:00h January 1, 1904 - // UNIX timestamp: seconds since 00:00h January 1, 1970 - return self::CastAsInt($macdate - 2082844800); - } - - - public static function FixedPoint8_8($rawdata) { - return self::BigEndian2Int(substr($rawdata, 0, 1)) + (float) (self::BigEndian2Int(substr($rawdata, 1, 1)) / pow(2, 8)); - } - - - public static function FixedPoint16_16($rawdata) { - return self::BigEndian2Int(substr($rawdata, 0, 2)) + (float) (self::BigEndian2Int(substr($rawdata, 2, 2)) / pow(2, 16)); - } - - - public static function FixedPoint2_30($rawdata) { - $binarystring = self::BigEndian2Bin($rawdata); - return self::Bin2Dec(substr($binarystring, 0, 2)) + (float) (self::Bin2Dec(substr($binarystring, 2, 30)) / pow(2, 30)); - } - - - public static function CreateDeepArray($ArrayPath, $Separator, $Value) { - // assigns $Value to a nested array path: - // $foo = self::CreateDeepArray('/path/to/my', '/', 'file.txt') - // is the same as: - // $foo = array('path'=>array('to'=>'array('my'=>array('file.txt')))); - // or - // $foo['path']['to']['my'] = 'file.txt'; - $ArrayPath = ltrim($ArrayPath, $Separator); - if (($pos = strpos($ArrayPath, $Separator)) !== false) { - $ReturnedArray[substr($ArrayPath, 0, $pos)] = self::CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value); - } else { - $ReturnedArray[$ArrayPath] = $Value; - } - return $ReturnedArray; - } - - public static function array_max($arraydata, $returnkey=false) { - $maxvalue = false; - $maxkey = false; - foreach ($arraydata as $key => $value) { - if (!is_array($value)) { - if ($value > $maxvalue) { - $maxvalue = $value; - $maxkey = $key; - } - } - } - return ($returnkey ? $maxkey : $maxvalue); - } - - public static function array_min($arraydata, $returnkey=false) { - $minvalue = false; - $minkey = false; - foreach ($arraydata as $key => $value) { - if (!is_array($value)) { - if ($value > $minvalue) { - $minvalue = $value; - $minkey = $key; - } - } - } - return ($returnkey ? $minkey : $minvalue); - } - - public static function XML2array($XMLstring) { - if (function_exists('simplexml_load_string') && function_exists('libxml_disable_entity_loader')) { - // http://websec.io/2012/08/27/Preventing-XEE-in-PHP.html - // https://core.trac.wordpress.org/changeset/29378 - $loader = libxml_disable_entity_loader(true); - $XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', LIBXML_NOENT); - $return = self::SimpleXMLelement2array($XMLobject); - libxml_disable_entity_loader($loader); - return $return; - } - return false; - } - - public static function SimpleXMLelement2array($XMLobject) { - if (!is_object($XMLobject) && !is_array($XMLobject)) { - return $XMLobject; - } - $XMLarray = (is_object($XMLobject) ? get_object_vars($XMLobject) : $XMLobject); - foreach ($XMLarray as $key => $value) { - $XMLarray[$key] = self::SimpleXMLelement2array($value); - } - return $XMLarray; - } - - - // Allan Hansen - // self::md5_data() - returns md5sum for a file from startuing position to absolute end position - public static function hash_data($file, $offset, $end, $algorithm) { - static $tempdir = ''; - if (!self::intValueSupported($end)) { - return false; - } - switch ($algorithm) { - case 'md5': - $hash_function = 'md5_file'; - $unix_call = 'md5sum'; - $windows_call = 'md5sum.exe'; - $hash_length = 32; - break; - - case 'sha1': - $hash_function = 'sha1_file'; - $unix_call = 'sha1sum'; - $windows_call = 'sha1sum.exe'; - $hash_length = 40; - break; - - default: - throw new Exception('Invalid algorithm ('.$algorithm.') in self::hash_data()'); - break; - } - $size = $end - $offset; - while (true) { - if (GETID3_OS_ISWINDOWS) { - - // It seems that sha1sum.exe for Windows only works on physical files, does not accept piped data - // Fall back to create-temp-file method: - if ($algorithm == 'sha1') { - break; - } - - $RequiredFiles = array('cygwin1.dll', 'head.exe', 'tail.exe', $windows_call); - foreach ($RequiredFiles as $required_file) { - if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) { - // helper apps not available - fall back to old method - break 2; - } - } - $commandline = GETID3_HELPERAPPSDIR.'head.exe -c '.$end.' '.escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $file)).' | '; - $commandline .= GETID3_HELPERAPPSDIR.'tail.exe -c '.$size.' | '; - $commandline .= GETID3_HELPERAPPSDIR.$windows_call; - - } else { - - $commandline = 'head -c'.$end.' '.escapeshellarg($file).' | '; - $commandline .= 'tail -c'.$size.' | '; - $commandline .= $unix_call; - - } - if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { - //throw new Exception('PHP running in Safe Mode - backtick operator not available, using slower non-system-call '.$algorithm.' algorithm'); - break; - } - return substr(`$commandline`, 0, $hash_length); - } - - if (empty($tempdir)) { - // yes this is ugly, feel free to suggest a better way - require_once(dirname(__FILE__).'/getid3.php'); - $getid3_temp = new getID3(); - $tempdir = $getid3_temp->tempdir; - unset($getid3_temp); - } - // try to create a temporary file in the system temp directory - invalid dirname should force to system temp dir - if (($data_filename = tempnam($tempdir, 'gI3')) === false) { - // can't find anywhere to create a temp file, just fail - return false; - } - - // Init - $result = false; - - // copy parts of file - try { - self::CopyFileParts($file, $data_filename, $offset, $end - $offset); - $result = $hash_function($data_filename); - } catch (Exception $e) { - throw new Exception('self::CopyFileParts() failed in getid_lib::hash_data(): '.$e->getMessage()); - } - unlink($data_filename); - return $result; - } - - public static function CopyFileParts($filename_source, $filename_dest, $offset, $length) { - if (!self::intValueSupported($offset + $length)) { - throw new Exception('cannot copy file portion, it extends beyond the '.round(PHP_INT_MAX / 1073741824).'GB limit'); - } - if (is_readable($filename_source) && is_file($filename_source) && ($fp_src = fopen($filename_source, 'rb'))) { - if (($fp_dest = fopen($filename_dest, 'wb'))) { - if (fseek($fp_src, $offset) == 0) { - $byteslefttowrite = $length; - while (($byteslefttowrite > 0) && ($buffer = fread($fp_src, min($byteslefttowrite, getID3::FREAD_BUFFER_SIZE)))) { - $byteswritten = fwrite($fp_dest, $buffer, $byteslefttowrite); - $byteslefttowrite -= $byteswritten; - } - return true; - } else { - throw new Exception('failed to seek to offset '.$offset.' in '.$filename_source); - } - fclose($fp_dest); - } else { - throw new Exception('failed to create file for writing '.$filename_dest); - } - fclose($fp_src); - } else { - throw new Exception('failed to open file for reading '.$filename_source); - } - return false; - } - - public static function iconv_fallback_int_utf8($charval) { - if ($charval < 128) { - // 0bbbbbbb - $newcharstring = chr($charval); - } elseif ($charval < 2048) { - // 110bbbbb 10bbbbbb - $newcharstring = chr(($charval >> 6) | 0xC0); - $newcharstring .= chr(($charval & 0x3F) | 0x80); - } elseif ($charval < 65536) { - // 1110bbbb 10bbbbbb 10bbbbbb - $newcharstring = chr(($charval >> 12) | 0xE0); - $newcharstring .= chr(($charval >> 6) | 0xC0); - $newcharstring .= chr(($charval & 0x3F) | 0x80); - } else { - // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb - $newcharstring = chr(($charval >> 18) | 0xF0); - $newcharstring .= chr(($charval >> 12) | 0xC0); - $newcharstring .= chr(($charval >> 6) | 0xC0); - $newcharstring .= chr(($charval & 0x3F) | 0x80); - } - return $newcharstring; - } - - // ISO-8859-1 => UTF-8 - public static function iconv_fallback_iso88591_utf8($string, $bom=false) { - if (function_exists('utf8_encode')) { - return utf8_encode($string); - } - // utf8_encode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support) - $newcharstring = ''; - if ($bom) { - $newcharstring .= "\xEF\xBB\xBF"; - } - for ($i = 0; $i < strlen($string); $i++) { - $charval = ord($string{$i}); - $newcharstring .= self::iconv_fallback_int_utf8($charval); - } - return $newcharstring; - } - - // ISO-8859-1 => UTF-16BE - public static function iconv_fallback_iso88591_utf16be($string, $bom=false) { - $newcharstring = ''; - if ($bom) { - $newcharstring .= "\xFE\xFF"; - } - for ($i = 0; $i < strlen($string); $i++) { - $newcharstring .= "\x00".$string{$i}; - } - return $newcharstring; - } - - // ISO-8859-1 => UTF-16LE - public static function iconv_fallback_iso88591_utf16le($string, $bom=false) { - $newcharstring = ''; - if ($bom) { - $newcharstring .= "\xFF\xFE"; - } - for ($i = 0; $i < strlen($string); $i++) { - $newcharstring .= $string{$i}."\x00"; - } - return $newcharstring; - } - - // ISO-8859-1 => UTF-16LE (BOM) - public static function iconv_fallback_iso88591_utf16($string) { - return self::iconv_fallback_iso88591_utf16le($string, true); - } - - // UTF-8 => ISO-8859-1 - public static function iconv_fallback_utf8_iso88591($string) { - if (function_exists('utf8_decode')) { - return utf8_decode($string); - } - // utf8_decode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support) - $newcharstring = ''; - $offset = 0; - $stringlength = strlen($string); - while ($offset < $stringlength) { - if ((ord($string{$offset}) | 0x07) == 0xF7) { - // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) & - ((ord($string{($offset + 1)}) & 0x3F) << 12) & - ((ord($string{($offset + 2)}) & 0x3F) << 6) & - (ord($string{($offset + 3)}) & 0x3F); - $offset += 4; - } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) { - // 1110bbbb 10bbbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) & - ((ord($string{($offset + 1)}) & 0x3F) << 6) & - (ord($string{($offset + 2)}) & 0x3F); - $offset += 3; - } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) { - // 110bbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) & - (ord($string{($offset + 1)}) & 0x3F); - $offset += 2; - } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) { - // 0bbbbbbb - $charval = ord($string{$offset}); - $offset += 1; - } else { - // error? throw some kind of warning here? - $charval = false; - $offset += 1; - } - if ($charval !== false) { - $newcharstring .= (($charval < 256) ? chr($charval) : '?'); - } - } - return $newcharstring; - } - - // UTF-8 => UTF-16BE - public static function iconv_fallback_utf8_utf16be($string, $bom=false) { - $newcharstring = ''; - if ($bom) { - $newcharstring .= "\xFE\xFF"; - } - $offset = 0; - $stringlength = strlen($string); - while ($offset < $stringlength) { - if ((ord($string{$offset}) | 0x07) == 0xF7) { - // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) & - ((ord($string{($offset + 1)}) & 0x3F) << 12) & - ((ord($string{($offset + 2)}) & 0x3F) << 6) & - (ord($string{($offset + 3)}) & 0x3F); - $offset += 4; - } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) { - // 1110bbbb 10bbbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) & - ((ord($string{($offset + 1)}) & 0x3F) << 6) & - (ord($string{($offset + 2)}) & 0x3F); - $offset += 3; - } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) { - // 110bbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) & - (ord($string{($offset + 1)}) & 0x3F); - $offset += 2; - } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) { - // 0bbbbbbb - $charval = ord($string{$offset}); - $offset += 1; - } else { - // error? throw some kind of warning here? - $charval = false; - $offset += 1; - } - if ($charval !== false) { - $newcharstring .= (($charval < 65536) ? self::BigEndian2String($charval, 2) : "\x00".'?'); - } - } - return $newcharstring; - } - - // UTF-8 => UTF-16LE - public static function iconv_fallback_utf8_utf16le($string, $bom=false) { - $newcharstring = ''; - if ($bom) { - $newcharstring .= "\xFF\xFE"; - } - $offset = 0; - $stringlength = strlen($string); - while ($offset < $stringlength) { - if ((ord($string{$offset}) | 0x07) == 0xF7) { - // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) & - ((ord($string{($offset + 1)}) & 0x3F) << 12) & - ((ord($string{($offset + 2)}) & 0x3F) << 6) & - (ord($string{($offset + 3)}) & 0x3F); - $offset += 4; - } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) { - // 1110bbbb 10bbbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) & - ((ord($string{($offset + 1)}) & 0x3F) << 6) & - (ord($string{($offset + 2)}) & 0x3F); - $offset += 3; - } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) { - // 110bbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) & - (ord($string{($offset + 1)}) & 0x3F); - $offset += 2; - } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) { - // 0bbbbbbb - $charval = ord($string{$offset}); - $offset += 1; - } else { - // error? maybe throw some warning here? - $charval = false; - $offset += 1; - } - if ($charval !== false) { - $newcharstring .= (($charval < 65536) ? self::LittleEndian2String($charval, 2) : '?'."\x00"); - } - } - return $newcharstring; - } - - // UTF-8 => UTF-16LE (BOM) - public static function iconv_fallback_utf8_utf16($string) { - return self::iconv_fallback_utf8_utf16le($string, true); - } - - // UTF-16BE => UTF-8 - public static function iconv_fallback_utf16be_utf8($string) { - if (substr($string, 0, 2) == "\xFE\xFF") { - // strip BOM - $string = substr($string, 2); - } - $newcharstring = ''; - for ($i = 0; $i < strlen($string); $i += 2) { - $charval = self::BigEndian2Int(substr($string, $i, 2)); - $newcharstring .= self::iconv_fallback_int_utf8($charval); - } - return $newcharstring; - } - - // UTF-16LE => UTF-8 - public static function iconv_fallback_utf16le_utf8($string) { - if (substr($string, 0, 2) == "\xFF\xFE") { - // strip BOM - $string = substr($string, 2); - } - $newcharstring = ''; - for ($i = 0; $i < strlen($string); $i += 2) { - $charval = self::LittleEndian2Int(substr($string, $i, 2)); - $newcharstring .= self::iconv_fallback_int_utf8($charval); - } - return $newcharstring; - } - - // UTF-16BE => ISO-8859-1 - public static function iconv_fallback_utf16be_iso88591($string) { - if (substr($string, 0, 2) == "\xFE\xFF") { - // strip BOM - $string = substr($string, 2); - } - $newcharstring = ''; - for ($i = 0; $i < strlen($string); $i += 2) { - $charval = self::BigEndian2Int(substr($string, $i, 2)); - $newcharstring .= (($charval < 256) ? chr($charval) : '?'); - } - return $newcharstring; - } - - // UTF-16LE => ISO-8859-1 - public static function iconv_fallback_utf16le_iso88591($string) { - if (substr($string, 0, 2) == "\xFF\xFE") { - // strip BOM - $string = substr($string, 2); - } - $newcharstring = ''; - for ($i = 0; $i < strlen($string); $i += 2) { - $charval = self::LittleEndian2Int(substr($string, $i, 2)); - $newcharstring .= (($charval < 256) ? chr($charval) : '?'); - } - return $newcharstring; - } - - // UTF-16 (BOM) => ISO-8859-1 - public static function iconv_fallback_utf16_iso88591($string) { - $bom = substr($string, 0, 2); - if ($bom == "\xFE\xFF") { - return self::iconv_fallback_utf16be_iso88591(substr($string, 2)); - } elseif ($bom == "\xFF\xFE") { - return self::iconv_fallback_utf16le_iso88591(substr($string, 2)); - } - return $string; - } - - // UTF-16 (BOM) => UTF-8 - public static function iconv_fallback_utf16_utf8($string) { - $bom = substr($string, 0, 2); - if ($bom == "\xFE\xFF") { - return self::iconv_fallback_utf16be_utf8(substr($string, 2)); - } elseif ($bom == "\xFF\xFE") { - return self::iconv_fallback_utf16le_utf8(substr($string, 2)); - } - return $string; - } - - public static function iconv_fallback($in_charset, $out_charset, $string) { - - if ($in_charset == $out_charset) { - return $string; - } - - // mb_convert_encoding() availble - if (function_exists('mb_convert_encoding')) { - if ($converted_string = @mb_convert_encoding($string, $out_charset, $in_charset)) { - switch ($out_charset) { - case 'ISO-8859-1': - $converted_string = rtrim($converted_string, "\x00"); - break; - } - return $converted_string; - } - return $string; - } - // iconv() availble - else if (function_exists('iconv')) { - if ($converted_string = @iconv($in_charset, $out_charset.'//TRANSLIT', $string)) { - switch ($out_charset) { - case 'ISO-8859-1': - $converted_string = rtrim($converted_string, "\x00"); - break; - } - return $converted_string; - } - - // iconv() may sometimes fail with "illegal character in input string" error message - // and return an empty string, but returning the unconverted string is more useful - return $string; - } - - - // neither mb_convert_encoding or iconv() is available - static $ConversionFunctionList = array(); - if (empty($ConversionFunctionList)) { - $ConversionFunctionList['ISO-8859-1']['UTF-8'] = 'iconv_fallback_iso88591_utf8'; - $ConversionFunctionList['ISO-8859-1']['UTF-16'] = 'iconv_fallback_iso88591_utf16'; - $ConversionFunctionList['ISO-8859-1']['UTF-16BE'] = 'iconv_fallback_iso88591_utf16be'; - $ConversionFunctionList['ISO-8859-1']['UTF-16LE'] = 'iconv_fallback_iso88591_utf16le'; - $ConversionFunctionList['UTF-8']['ISO-8859-1'] = 'iconv_fallback_utf8_iso88591'; - $ConversionFunctionList['UTF-8']['UTF-16'] = 'iconv_fallback_utf8_utf16'; - $ConversionFunctionList['UTF-8']['UTF-16BE'] = 'iconv_fallback_utf8_utf16be'; - $ConversionFunctionList['UTF-8']['UTF-16LE'] = 'iconv_fallback_utf8_utf16le'; - $ConversionFunctionList['UTF-16']['ISO-8859-1'] = 'iconv_fallback_utf16_iso88591'; - $ConversionFunctionList['UTF-16']['UTF-8'] = 'iconv_fallback_utf16_utf8'; - $ConversionFunctionList['UTF-16LE']['ISO-8859-1'] = 'iconv_fallback_utf16le_iso88591'; - $ConversionFunctionList['UTF-16LE']['UTF-8'] = 'iconv_fallback_utf16le_utf8'; - $ConversionFunctionList['UTF-16BE']['ISO-8859-1'] = 'iconv_fallback_utf16be_iso88591'; - $ConversionFunctionList['UTF-16BE']['UTF-8'] = 'iconv_fallback_utf16be_utf8'; - } - if (isset($ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)])) { - $ConversionFunction = $ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)]; - return self::$ConversionFunction($string); - } - throw new Exception('PHP does not has mb_convert_encoding() or iconv() support - cannot convert from '.$in_charset.' to '.$out_charset); - } - - public static function recursiveMultiByteCharString2HTML($data, $charset='ISO-8859-1') { - if (is_string($data)) { - return self::MultiByteCharString2HTML($data, $charset); - } elseif (is_array($data)) { - $return_data = array(); - foreach ($data as $key => $value) { - $return_data[$key] = self::recursiveMultiByteCharString2HTML($value, $charset); - } - return $return_data; - } - // integer, float, objects, resources, etc - return $data; - } - - public static function MultiByteCharString2HTML($string, $charset='ISO-8859-1') { - $string = (string) $string; // in case trying to pass a numeric (float, int) string, would otherwise return an empty string - $HTMLstring = ''; - - switch (strtolower($charset)) { - case '1251': - case '1252': - case '866': - case '932': - case '936': - case '950': - case 'big5': - case 'big5-hkscs': - case 'cp1251': - case 'cp1252': - case 'cp866': - case 'euc-jp': - case 'eucjp': - case 'gb2312': - case 'ibm866': - case 'iso-8859-1': - case 'iso-8859-15': - case 'iso8859-1': - case 'iso8859-15': - case 'koi8-r': - case 'koi8-ru': - case 'koi8r': - case 'shift_jis': - case 'sjis': - case 'win-1251': - case 'windows-1251': - case 'windows-1252': - $HTMLstring = htmlentities($string, ENT_COMPAT, $charset); - break; - - case 'utf-8': - $strlen = strlen($string); - for ($i = 0; $i < $strlen; $i++) { - $char_ord_val = ord($string{$i}); - $charval = 0; - if ($char_ord_val < 0x80) { - $charval = $char_ord_val; - } elseif ((($char_ord_val & 0xF0) >> 4) == 0x0F && $i+3 < $strlen) { - $charval = (($char_ord_val & 0x07) << 18); - $charval += ((ord($string{++$i}) & 0x3F) << 12); - $charval += ((ord($string{++$i}) & 0x3F) << 6); - $charval += (ord($string{++$i}) & 0x3F); - } elseif ((($char_ord_val & 0xE0) >> 5) == 0x07 && $i+2 < $strlen) { - $charval = (($char_ord_val & 0x0F) << 12); - $charval += ((ord($string{++$i}) & 0x3F) << 6); - $charval += (ord($string{++$i}) & 0x3F); - } elseif ((($char_ord_val & 0xC0) >> 6) == 0x03 && $i+1 < $strlen) { - $charval = (($char_ord_val & 0x1F) << 6); - $charval += (ord($string{++$i}) & 0x3F); - } - if (($charval >= 32) && ($charval <= 127)) { - $HTMLstring .= htmlentities(chr($charval)); - } else { - $HTMLstring .= '&#'.$charval.';'; - } - } - break; - - case 'utf-16le': - for ($i = 0; $i < strlen($string); $i += 2) { - $charval = self::LittleEndian2Int(substr($string, $i, 2)); - if (($charval >= 32) && ($charval <= 127)) { - $HTMLstring .= chr($charval); - } else { - $HTMLstring .= '&#'.$charval.';'; - } - } - break; - - case 'utf-16be': - for ($i = 0; $i < strlen($string); $i += 2) { - $charval = self::BigEndian2Int(substr($string, $i, 2)); - if (($charval >= 32) && ($charval <= 127)) { - $HTMLstring .= chr($charval); - } else { - $HTMLstring .= '&#'.$charval.';'; - } - } - break; - - default: - $HTMLstring = 'ERROR: Character set "'.$charset.'" not supported in MultiByteCharString2HTML()'; - break; - } - return $HTMLstring; - } - - - - public static function RGADnameLookup($namecode) { - static $RGADname = array(); - if (empty($RGADname)) { - $RGADname[0] = 'not set'; - $RGADname[1] = 'Track Gain Adjustment'; - $RGADname[2] = 'Album Gain Adjustment'; - } - - return (isset($RGADname[$namecode]) ? $RGADname[$namecode] : ''); - } - - - public static function RGADoriginatorLookup($originatorcode) { - static $RGADoriginator = array(); - if (empty($RGADoriginator)) { - $RGADoriginator[0] = 'unspecified'; - $RGADoriginator[1] = 'pre-set by artist/producer/mastering engineer'; - $RGADoriginator[2] = 'set by user'; - $RGADoriginator[3] = 'determined automatically'; - } - - return (isset($RGADoriginator[$originatorcode]) ? $RGADoriginator[$originatorcode] : ''); - } - - - public static function RGADadjustmentLookup($rawadjustment, $signbit) { - $adjustment = $rawadjustment / 10; - if ($signbit == 1) { - $adjustment *= -1; - } - return (float) $adjustment; - } - - - public static function RGADgainString($namecode, $originatorcode, $replaygain) { - if ($replaygain < 0) { - $signbit = '1'; - } else { - $signbit = '0'; - } - $storedreplaygain = intval(round($replaygain * 10)); - $gainstring = str_pad(decbin($namecode), 3, '0', STR_PAD_LEFT); - $gainstring .= str_pad(decbin($originatorcode), 3, '0', STR_PAD_LEFT); - $gainstring .= $signbit; - $gainstring .= str_pad(decbin($storedreplaygain), 9, '0', STR_PAD_LEFT); - - return $gainstring; - } - - public static function RGADamplitude2dB($amplitude) { - return 20 * log10($amplitude); - } - - - public static function GetDataImageSize($imgData, &$imageinfo=array()) { - static $tempdir = ''; - if (empty($tempdir)) { - if (function_exists('sys_get_temp_dir')) { - $tempdir = sys_get_temp_dir(); // https://github.com/JamesHeinrich/getID3/issues/52 - } - - // yes this is ugly, feel free to suggest a better way - if (include_once(dirname(__FILE__).'/getid3.php')) { - if ($getid3_temp = new getID3()) { - if ($getid3_temp_tempdir = $getid3_temp->tempdir) { - $tempdir = $getid3_temp_tempdir; - } - unset($getid3_temp, $getid3_temp_tempdir); - } - } - } - $GetDataImageSize = false; - if ($tempfilename = tempnam($tempdir, 'gI3')) { - if (is_writable($tempfilename) && is_file($tempfilename) && ($tmp = fopen($tempfilename, 'wb'))) { - fwrite($tmp, $imgData); - fclose($tmp); - $GetDataImageSize = @getimagesize($tempfilename, $imageinfo); - if (($GetDataImageSize === false) || !isset($GetDataImageSize[0]) || !isset($GetDataImageSize[1])) { - return false; - } - $GetDataImageSize['height'] = $GetDataImageSize[0]; - $GetDataImageSize['width'] = $GetDataImageSize[1]; - } - unlink($tempfilename); - } - return $GetDataImageSize; - } - - public static function ImageExtFromMime($mime_type) { - // temporary way, works OK for now, but should be reworked in the future - return str_replace(array('image/', 'x-', 'jpeg'), array('', '', 'jpg'), $mime_type); - } - - public static function ImageTypesLookup($imagetypeid) { - static $ImageTypesLookup = array(); - if (empty($ImageTypesLookup)) { - $ImageTypesLookup[1] = 'gif'; - $ImageTypesLookup[2] = 'jpeg'; - $ImageTypesLookup[3] = 'png'; - $ImageTypesLookup[4] = 'swf'; - $ImageTypesLookup[5] = 'psd'; - $ImageTypesLookup[6] = 'bmp'; - $ImageTypesLookup[7] = 'tiff (little-endian)'; - $ImageTypesLookup[8] = 'tiff (big-endian)'; - $ImageTypesLookup[9] = 'jpc'; - $ImageTypesLookup[10] = 'jp2'; - $ImageTypesLookup[11] = 'jpx'; - $ImageTypesLookup[12] = 'jb2'; - $ImageTypesLookup[13] = 'swc'; - $ImageTypesLookup[14] = 'iff'; - } - return (isset($ImageTypesLookup[$imagetypeid]) ? $ImageTypesLookup[$imagetypeid] : ''); - } - - public static function CopyTagsToComments(&$ThisFileInfo) { - - // Copy all entries from ['tags'] into common ['comments'] - if (!empty($ThisFileInfo['tags'])) { - foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) { - foreach ($tagarray as $tagname => $tagdata) { - foreach ($tagdata as $key => $value) { - if (!empty($value)) { - if (empty($ThisFileInfo['comments'][$tagname])) { - - // fall through and append value - - } elseif ($tagtype == 'id3v1') { - - $newvaluelength = strlen(trim($value)); - foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) { - $oldvaluelength = strlen(trim($existingvalue)); - if (($newvaluelength <= $oldvaluelength) && (substr($existingvalue, 0, $newvaluelength) == trim($value))) { - // new value is identical but shorter-than (or equal-length to) one already in comments - skip - break 2; - } - } - - } elseif (!is_array($value)) { - - $newvaluelength = strlen(trim($value)); - foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) { - $oldvaluelength = strlen(trim($existingvalue)); - if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) { - $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value); - //break 2; - break; - } - } - - } - if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) { - $value = (is_string($value) ? trim($value) : $value); - if (!is_int($key) && !ctype_digit($key)) { - $ThisFileInfo['comments'][$tagname][$key] = $value; - } else { - if (isset($ThisFileInfo['comments'][$tagname])) { - $ThisFileInfo['comments'][$tagname] = array($value); - } else { - $ThisFileInfo['comments'][$tagname][] = $value; - } - } - } - } - } - } - } - - // attempt to standardize spelling of returned keys - $StandardizeFieldNames = array( - 'tracknumber' => 'track_number', - 'track' => 'track_number', - ); - foreach ($StandardizeFieldNames as $badkey => $goodkey) { - if (array_key_exists($badkey, $ThisFileInfo['comments']) && !array_key_exists($goodkey, $ThisFileInfo['comments'])) { - $ThisFileInfo['comments'][$goodkey] = $ThisFileInfo['comments'][$badkey]; - unset($ThisFileInfo['comments'][$badkey]); - } - } - - // Copy to ['comments_html'] - if (!empty($ThisFileInfo['comments'])) { - foreach ($ThisFileInfo['comments'] as $field => $values) { - if ($field == 'picture') { - // pictures can take up a lot of space, and we don't need multiple copies of them - // let there be a single copy in [comments][picture], and not elsewhere - continue; - } - foreach ($values as $index => $value) { - if (is_array($value)) { - $ThisFileInfo['comments_html'][$field][$index] = $value; - } else { - $ThisFileInfo['comments_html'][$field][$index] = str_replace('�', '', self::MultiByteCharString2HTML($value, $ThisFileInfo['encoding'])); - } - } - } - } - - } - return true; - } - - - public static function EmbeddedLookup($key, $begin, $end, $file, $name) { - - // Cached - static $cache; - if (isset($cache[$file][$name])) { - return (isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : ''); - } - - // Init - $keylength = strlen($key); - $line_count = $end - $begin - 7; - - // Open php file - $fp = fopen($file, 'r'); - - // Discard $begin lines - for ($i = 0; $i < ($begin + 3); $i++) { - fgets($fp, 1024); - } - - // Loop thru line - while (0 < $line_count--) { - - // Read line - $line = ltrim(fgets($fp, 1024), "\t "); - - // METHOD A: only cache the matching key - less memory but slower on next lookup of not-previously-looked-up key - //$keycheck = substr($line, 0, $keylength); - //if ($key == $keycheck) { - // $cache[$file][$name][$keycheck] = substr($line, $keylength + 1); - // break; - //} - - // METHOD B: cache all keys in this lookup - more memory but faster on next lookup of not-previously-looked-up key - //$cache[$file][$name][substr($line, 0, $keylength)] = trim(substr($line, $keylength + 1)); - $explodedLine = explode("\t", $line, 2); - $ThisKey = (isset($explodedLine[0]) ? $explodedLine[0] : ''); - $ThisValue = (isset($explodedLine[1]) ? $explodedLine[1] : ''); - $cache[$file][$name][$ThisKey] = trim($ThisValue); - } - - // Close and return - fclose($fp); - return (isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : ''); - } - - public static function IncludeDependency($filename, $sourcefile, $DieOnFailure=false) { - global $GETID3_ERRORARRAY; - - if (file_exists($filename)) { - if (include_once($filename)) { - return true; - } else { - $diemessage = basename($sourcefile).' depends on '.$filename.', which has errors'; - } - } else { - $diemessage = basename($sourcefile).' depends on '.$filename.', which is missing'; - } - if ($DieOnFailure) { - throw new Exception($diemessage); - } else { - $GETID3_ERRORARRAY[] = $diemessage; - } - return false; - } - - public static function trimNullByte($string) { - return trim($string, "\x00"); - } - - public static function getFileSizeSyscall($path) { - $filesize = false; - - if (GETID3_OS_ISWINDOWS) { - if (class_exists('COM')) { // From PHP 5.3.15 and 5.4.5, COM and DOTNET is no longer built into the php core.you have to add COM support in php.ini: - $filesystem = new COM('Scripting.FileSystemObject'); - $file = $filesystem->GetFile($path); - $filesize = $file->Size(); - unset($filesystem, $file); - } else { - $commandline = 'for %I in ('.escapeshellarg($path).') do @echo %~zI'; - } - } else { - $commandline = 'ls -l '.escapeshellarg($path).' | awk \'{print $5}\''; - } - if (isset($commandline)) { - $output = trim(`$commandline`); - if (ctype_digit($output)) { - $filesize = (float) $output; - } - } - return $filesize; - } - - - /** - * Workaround for Bug #37268 (https://bugs.php.net/bug.php?id=37268) - * @param string $path A path. - * @param string $suffix If the name component ends in suffix this will also be cut off. - * @return string - */ - public static function mb_basename($path, $suffix = null) { - $splited = preg_split('#/#', rtrim($path, '/ ')); - return substr(basename('X'.$splited[count($splited) - 1], $suffix), 1); - } - + public static function PrintHexBytes($string, $hex = true, $spaces = true, $htmlencoding = 'UTF-8') + { + $returnstring = ''; + for ($i = 0; $i < strlen($string); $i++) { + if ($hex) { + $returnstring .= str_pad(dechex(ord($string[$i])), 2, '0', STR_PAD_LEFT); + } else { + $returnstring .= ' '.(preg_match("#[\x20-\x7E]#", $string[$i]) ? $string[$i] : '¤'); + } + if ($spaces) { + $returnstring .= ' '; + } + } + if (! empty($htmlencoding)) { + if ($htmlencoding === true) { + $htmlencoding = 'UTF-8'; // prior to getID3 v1.9.0 the function's 4th parameter was boolean + } + $returnstring = htmlentities($returnstring, ENT_QUOTES, $htmlencoding); + } + + return $returnstring; + } + + public static function trunc($floatnumber) + { + // truncates a floating-point number at the decimal point + // returns int (if possible, otherwise float) + if ($floatnumber >= 1) { + $truncatednumber = floor($floatnumber); + } elseif ($floatnumber <= -1) { + $truncatednumber = ceil($floatnumber); + } else { + $truncatednumber = 0; + } + if (self::intValueSupported($truncatednumber)) { + $truncatednumber = (int) $truncatednumber; + } + + return $truncatednumber; + } + + public static function safe_inc(&$variable, $increment = 1) + { + if (isset($variable)) { + $variable += $increment; + } else { + $variable = $increment; + } + + return true; + } + + public static function CastAsInt($floatnum) + { + // convert to float if not already + $floatnum = (float) $floatnum; + + // convert a float to type int, only if possible + if (self::trunc($floatnum) == $floatnum) { + // it's not floating point + if (self::intValueSupported($floatnum)) { + // it's within int range + $floatnum = (int) $floatnum; + } + } + + return $floatnum; + } + + public static function intValueSupported($num) + { + // check if integers are 64-bit + static $hasINT64 = null; + if ($hasINT64 === null) { // 10x faster than is_null() + $hasINT64 = is_int(pow(2, 31)); // 32-bit int are limited to (2^31)-1 + if (! $hasINT64 && ! defined('PHP_INT_MIN')) { + define('PHP_INT_MIN', ~PHP_INT_MAX); + } + } + // if integers are 64-bit - no other check required + if ($hasINT64 || (($num <= PHP_INT_MAX) && ($num >= PHP_INT_MIN))) { + return true; + } + + return false; + } + + public static function DecimalizeFraction($fraction) + { + list($numerator, $denominator) = explode('/', $fraction); + + return $numerator / ($denominator ? $denominator : 1); + } + + public static function DecimalBinary2Float($binarynumerator) + { + $numerator = self::Bin2Dec($binarynumerator); + $denominator = self::Bin2Dec('1'.str_repeat('0', strlen($binarynumerator))); + + return $numerator / $denominator; + } + + public static function NormalizeBinaryPoint($binarypointnumber, $maxbits = 52) + { + // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html + if (strpos($binarypointnumber, '.') === false) { + $binarypointnumber = '0.'.$binarypointnumber; + } elseif ($binarypointnumber[0] == '.') { + $binarypointnumber = '0'.$binarypointnumber; + } + $exponent = 0; + while (($binarypointnumber[0] != '1') || (substr($binarypointnumber, 1, 1) != '.')) { + if (substr($binarypointnumber, 1, 1) == '.') { + $exponent--; + $binarypointnumber = substr($binarypointnumber, 2, 1).'.'.substr($binarypointnumber, 3); + } else { + $pointpos = strpos($binarypointnumber, '.'); + $exponent += ($pointpos - 1); + $binarypointnumber = str_replace('.', '', $binarypointnumber); + $binarypointnumber = $binarypointnumber[0].'.'.substr($binarypointnumber, 1); + } + } + $binarypointnumber = str_pad(substr($binarypointnumber, 0, $maxbits + 2), $maxbits + 2, '0', STR_PAD_RIGHT); + + return ['normalized'=>$binarypointnumber, 'exponent'=>(int) $exponent]; + } + + public static function Float2BinaryDecimal($floatvalue) + { + // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html + $maxbits = 128; // to how many bits of precision should the calculations be taken? + $intpart = self::trunc($floatvalue); + $floatpart = abs($floatvalue - $intpart); + $pointbitstring = ''; + while (($floatpart != 0) && (strlen($pointbitstring) < $maxbits)) { + $floatpart *= 2; + $pointbitstring .= (string) self::trunc($floatpart); + $floatpart -= self::trunc($floatpart); + } + $binarypointnumber = decbin($intpart).'.'.$pointbitstring; + + return $binarypointnumber; + } + + public static function Float2String($floatvalue, $bits) + { + // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html + switch ($bits) { + case 32: + $exponentbits = 8; + $fractionbits = 23; + break; + + case 64: + $exponentbits = 11; + $fractionbits = 52; + break; + + default: + return false; + break; + } + if ($floatvalue >= 0) { + $signbit = '0'; + } else { + $signbit = '1'; + } + $normalizedbinary = self::NormalizeBinaryPoint(self::Float2BinaryDecimal($floatvalue), $fractionbits); + $biasedexponent = pow(2, $exponentbits - 1) - 1 + $normalizedbinary['exponent']; // (127 or 1023) +/- exponent + $exponentbitstring = str_pad(decbin($biasedexponent), $exponentbits, '0', STR_PAD_LEFT); + $fractionbitstring = str_pad(substr($normalizedbinary['normalized'], 2), $fractionbits, '0', STR_PAD_RIGHT); + + return self::BigEndian2String(self::Bin2Dec($signbit.$exponentbitstring.$fractionbitstring), $bits % 8, false); + } + + public static function LittleEndian2Float($byteword) + { + return self::BigEndian2Float(strrev($byteword)); + } + + public static function BigEndian2Float($byteword) + { + // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic + // http://www.psc.edu/general/software/packages/ieee/ieee.html + // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html + + $bitword = self::BigEndian2Bin($byteword); + if (! $bitword) { + return 0; + } + $signbit = $bitword[0]; + + switch (strlen($byteword) * 8) { + case 32: + $exponentbits = 8; + $fractionbits = 23; + break; + + case 64: + $exponentbits = 11; + $fractionbits = 52; + break; + + case 80: + // 80-bit Apple SANE format + // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/ + $exponentstring = substr($bitword, 1, 15); + $isnormalized = intval($bitword[16]); + $fractionstring = substr($bitword, 17, 63); + $exponent = pow(2, self::Bin2Dec($exponentstring) - 16383); + $fraction = $isnormalized + self::DecimalBinary2Float($fractionstring); + $floatvalue = $exponent * $fraction; + if ($signbit == '1') { + $floatvalue *= -1; + } + + return $floatvalue; + break; + + default: + return false; + break; + } + $exponentstring = substr($bitword, 1, $exponentbits); + $fractionstring = substr($bitword, $exponentbits + 1, $fractionbits); + $exponent = self::Bin2Dec($exponentstring); + $fraction = self::Bin2Dec($fractionstring); + + if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) { + // Not a Number + $floatvalue = false; + } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) { + if ($signbit == '1') { + $floatvalue = '-infinity'; + } else { + $floatvalue = '+infinity'; + } + } elseif (($exponent == 0) && ($fraction == 0)) { + if ($signbit == '1') { + $floatvalue = -0; + } else { + $floatvalue = 0; + } + $floatvalue = ($signbit ? 0 : -0); + } elseif (($exponent == 0) && ($fraction != 0)) { + // These are 'unnormalized' values + $floatvalue = pow(2, (-1 * (pow(2, $exponentbits - 1) - 2))) * self::DecimalBinary2Float($fractionstring); + if ($signbit == '1') { + $floatvalue *= -1; + } + } elseif ($exponent != 0) { + $floatvalue = pow(2, ($exponent - (pow(2, $exponentbits - 1) - 1))) * (1 + self::DecimalBinary2Float($fractionstring)); + if ($signbit == '1') { + $floatvalue *= -1; + } + } + + return (float) $floatvalue; + } + + public static function BigEndian2Int($byteword, $synchsafe = false, $signed = false) + { + $intvalue = 0; + $bytewordlen = strlen($byteword); + if ($bytewordlen == 0) { + return false; + } + for ($i = 0; $i < $bytewordlen; $i++) { + if ($synchsafe) { // disregard MSB, effectively 7-bit bytes + //$intvalue = $intvalue | (ord($byteword{$i}) & 0x7F) << (($bytewordlen - 1 - $i) * 7); // faster, but runs into problems past 2^31 on 32-bit systems + $intvalue += (ord($byteword[$i]) & 0x7F) * pow(2, ($bytewordlen - 1 - $i) * 7); + } else { + $intvalue += ord($byteword[$i]) * pow(256, ($bytewordlen - 1 - $i)); + } + } + if ($signed && ! $synchsafe) { + // synchsafe ints are not allowed to be signed + if ($bytewordlen <= PHP_INT_SIZE) { + $signMaskBit = 0x80 << (8 * ($bytewordlen - 1)); + if ($intvalue & $signMaskBit) { + $intvalue = 0 - ($intvalue & ($signMaskBit - 1)); + } + } else { + throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits ('.strlen($byteword).') in self::BigEndian2Int()'); + } + } + + return self::CastAsInt($intvalue); + } + + public static function LittleEndian2Int($byteword, $signed = false) + { + return self::BigEndian2Int(strrev($byteword), false, $signed); + } + + public static function BigEndian2Bin($byteword) + { + $binvalue = ''; + $bytewordlen = strlen($byteword); + for ($i = 0; $i < $bytewordlen; $i++) { + $binvalue .= str_pad(decbin(ord($byteword[$i])), 8, '0', STR_PAD_LEFT); + } + + return $binvalue; + } + + public static function BigEndian2String($number, $minbytes = 1, $synchsafe = false, $signed = false) + { + if ($number < 0) { + throw new Exception('ERROR: self::BigEndian2String() does not support negative numbers'); + } + $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF); + $intstring = ''; + if ($signed) { + if ($minbytes > PHP_INT_SIZE) { + throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits in self::BigEndian2String()'); + } + $number = $number & (0x80 << (8 * ($minbytes - 1))); + } + while ($number != 0) { + $quotient = ($number / ($maskbyte + 1)); + $intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)).$intstring; + $number = floor($quotient); + } + + return str_pad($intstring, $minbytes, "\x00", STR_PAD_LEFT); + } + + public static function Dec2Bin($number) + { + while ($number >= 256) { + $bytes[] = (($number / 256) - (floor($number / 256))) * 256; + $number = floor($number / 256); + } + $bytes[] = $number; + $binstring = ''; + for ($i = 0; $i < count($bytes); $i++) { + $binstring = (($i == count($bytes) - 1) ? decbin($bytes[$i]) : str_pad(decbin($bytes[$i]), 8, '0', STR_PAD_LEFT)).$binstring; + } + + return $binstring; + } + + public static function Bin2Dec($binstring, $signed = false) + { + $signmult = 1; + if ($signed) { + if ($binstring[0] == '1') { + $signmult = -1; + } + $binstring = substr($binstring, 1); + } + $decvalue = 0; + for ($i = 0; $i < strlen($binstring); $i++) { + $decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1, 1)) * pow(2, $i); + } + + return self::CastAsInt($decvalue * $signmult); + } + + public static function Bin2String($binstring) + { + // return 'hi' for input of '0110100001101001' + $string = ''; + $binstringreversed = strrev($binstring); + for ($i = 0; $i < strlen($binstringreversed); $i += 8) { + $string = chr(self::Bin2Dec(strrev(substr($binstringreversed, $i, 8)))).$string; + } + + return $string; + } + + public static function LittleEndian2String($number, $minbytes = 1, $synchsafe = false) + { + $intstring = ''; + while ($number > 0) { + if ($synchsafe) { + $intstring = $intstring.chr($number & 127); + $number >>= 7; + } else { + $intstring = $intstring.chr($number & 255); + $number >>= 8; + } + } + + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); + } + + public static function array_merge_clobber($array1, $array2) + { + // written by kcØhireability*com + // taken from http://www.php.net/manual/en/function.array-merge-recursive.php + if (! is_array($array1) || ! is_array($array2)) { + return false; + } + $newarray = $array1; + foreach ($array2 as $key => $val) { + if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { + $newarray[$key] = self::array_merge_clobber($newarray[$key], $val); + } else { + $newarray[$key] = $val; + } + } + + return $newarray; + } + + public static function array_merge_noclobber($array1, $array2) + { + if (! is_array($array1) || ! is_array($array2)) { + return false; + } + $newarray = $array1; + foreach ($array2 as $key => $val) { + if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { + $newarray[$key] = self::array_merge_noclobber($newarray[$key], $val); + } elseif (! isset($newarray[$key])) { + $newarray[$key] = $val; + } + } + + return $newarray; + } + + public static function flipped_array_merge_noclobber($array1, $array2) + { + if (! is_array($array1) || ! is_array($array2)) { + return false; + } + // naturally, this only works non-recursively + $newarray = array_flip($array1); + foreach (array_flip($array2) as $key => $val) { + if (! isset($newarray[$key])) { + $newarray[$key] = count($newarray); + } + } + + return array_flip($newarray); + } + + public static function ksort_recursive(&$theArray) + { + ksort($theArray); + foreach ($theArray as $key => $value) { + if (is_array($value)) { + self::ksort_recursive($theArray[$key]); + } + } + + return true; + } + + public static function fileextension($filename, $numextensions = 1) + { + if (strstr($filename, '.')) { + $reversedfilename = strrev($filename); + $offset = 0; + for ($i = 0; $i < $numextensions; $i++) { + $offset = strpos($reversedfilename, '.', $offset + 1); + if ($offset === false) { + return ''; + } + } + + return strrev(substr($reversedfilename, 0, $offset)); + } + + return ''; + } + + public static function PlaytimeString($seconds) + { + $sign = (($seconds < 0) ? '-' : ''); + $seconds = round(abs($seconds)); + $H = (int) floor($seconds / 3600); + $M = (int) floor(($seconds - (3600 * $H)) / 60); + $S = (int) round($seconds - (3600 * $H) - (60 * $M)); + + return $sign.($H ? $H.':' : '').($H ? str_pad($M, 2, '0', STR_PAD_LEFT) : intval($M)).':'.str_pad($S, 2, 0, STR_PAD_LEFT); + } + + public static function DateMac2Unix($macdate) + { + // Macintosh timestamp: seconds since 00:00h January 1, 1904 + // UNIX timestamp: seconds since 00:00h January 1, 1970 + return self::CastAsInt($macdate - 2082844800); + } + + public static function FixedPoint8_8($rawdata) + { + return self::BigEndian2Int(substr($rawdata, 0, 1)) + (float) (self::BigEndian2Int(substr($rawdata, 1, 1)) / pow(2, 8)); + } + + public static function FixedPoint16_16($rawdata) + { + return self::BigEndian2Int(substr($rawdata, 0, 2)) + (float) (self::BigEndian2Int(substr($rawdata, 2, 2)) / pow(2, 16)); + } + + public static function FixedPoint2_30($rawdata) + { + $binarystring = self::BigEndian2Bin($rawdata); + + return self::Bin2Dec(substr($binarystring, 0, 2)) + (float) (self::Bin2Dec(substr($binarystring, 2, 30)) / pow(2, 30)); + } + + public static function CreateDeepArray($ArrayPath, $Separator, $Value) + { + // assigns $Value to a nested array path: + // $foo = self::CreateDeepArray('/path/to/my', '/', 'file.txt') + // is the same as: + // $foo = array('path'=>array('to'=>'array('my'=>array('file.txt')))); + // or + // $foo['path']['to']['my'] = 'file.txt'; + $ArrayPath = ltrim($ArrayPath, $Separator); + if (($pos = strpos($ArrayPath, $Separator)) !== false) { + $ReturnedArray[substr($ArrayPath, 0, $pos)] = self::CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value); + } else { + $ReturnedArray[$ArrayPath] = $Value; + } + + return $ReturnedArray; + } + + public static function array_max($arraydata, $returnkey = false) + { + $maxvalue = false; + $maxkey = false; + foreach ($arraydata as $key => $value) { + if (! is_array($value)) { + if ($value > $maxvalue) { + $maxvalue = $value; + $maxkey = $key; + } + } + } + + return $returnkey ? $maxkey : $maxvalue; + } + + public static function array_min($arraydata, $returnkey = false) + { + $minvalue = false; + $minkey = false; + foreach ($arraydata as $key => $value) { + if (! is_array($value)) { + if ($value > $minvalue) { + $minvalue = $value; + $minkey = $key; + } + } + } + + return $returnkey ? $minkey : $minvalue; + } + + public static function XML2array($XMLstring) + { + if (function_exists('simplexml_load_string') && function_exists('libxml_disable_entity_loader')) { + // http://websec.io/2012/08/27/Preventing-XEE-in-PHP.html + // https://core.trac.wordpress.org/changeset/29378 + $loader = libxml_disable_entity_loader(true); + $XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', LIBXML_NOENT); + $return = self::SimpleXMLelement2array($XMLobject); + libxml_disable_entity_loader($loader); + + return $return; + } + + return false; + } + + public static function SimpleXMLelement2array($XMLobject) + { + if (! is_object($XMLobject) && ! is_array($XMLobject)) { + return $XMLobject; + } + $XMLarray = (is_object($XMLobject) ? get_object_vars($XMLobject) : $XMLobject); + foreach ($XMLarray as $key => $value) { + $XMLarray[$key] = self::SimpleXMLelement2array($value); + } + + return $XMLarray; + } + + // Allan Hansen + // self::md5_data() - returns md5sum for a file from startuing position to absolute end position + public static function hash_data($file, $offset, $end, $algorithm) + { + static $tempdir = ''; + if (! self::intValueSupported($end)) { + return false; + } + switch ($algorithm) { + case 'md5': + $hash_function = 'md5_file'; + $unix_call = 'md5sum'; + $windows_call = 'md5sum.exe'; + $hash_length = 32; + break; + + case 'sha1': + $hash_function = 'sha1_file'; + $unix_call = 'sha1sum'; + $windows_call = 'sha1sum.exe'; + $hash_length = 40; + break; + + default: + throw new Exception('Invalid algorithm ('.$algorithm.') in self::hash_data()'); + break; + } + $size = $end - $offset; + while (true) { + if (GETID3_OS_ISWINDOWS) { + + // It seems that sha1sum.exe for Windows only works on physical files, does not accept piped data + // Fall back to create-temp-file method: + if ($algorithm == 'sha1') { + break; + } + + $RequiredFiles = ['cygwin1.dll', 'head.exe', 'tail.exe', $windows_call]; + foreach ($RequiredFiles as $required_file) { + if (! is_readable(GETID3_HELPERAPPSDIR.$required_file)) { + // helper apps not available - fall back to old method + break 2; + } + } + $commandline = GETID3_HELPERAPPSDIR.'head.exe -c '.$end.' '.escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $file)).' | '; + $commandline .= GETID3_HELPERAPPSDIR.'tail.exe -c '.$size.' | '; + $commandline .= GETID3_HELPERAPPSDIR.$windows_call; + } else { + $commandline = 'head -c'.$end.' '.escapeshellarg($file).' | '; + $commandline .= 'tail -c'.$size.' | '; + $commandline .= $unix_call; + } + if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { + //throw new Exception('PHP running in Safe Mode - backtick operator not available, using slower non-system-call '.$algorithm.' algorithm'); + break; + } + + return substr(`$commandline`, 0, $hash_length); + } + + if (empty($tempdir)) { + // yes this is ugly, feel free to suggest a better way + require_once dirname(__FILE__).'/getid3.php'; + $getid3_temp = new getID3(); + $tempdir = $getid3_temp->tempdir; + unset($getid3_temp); + } + // try to create a temporary file in the system temp directory - invalid dirname should force to system temp dir + if (($data_filename = tempnam($tempdir, 'gI3')) === false) { + // can't find anywhere to create a temp file, just fail + return false; + } + + // Init + $result = false; + + // copy parts of file + try { + self::CopyFileParts($file, $data_filename, $offset, $end - $offset); + $result = $hash_function($data_filename); + } catch (Exception $e) { + throw new Exception('self::CopyFileParts() failed in getid_lib::hash_data(): '.$e->getMessage()); + } + unlink($data_filename); + + return $result; + } + + public static function CopyFileParts($filename_source, $filename_dest, $offset, $length) + { + if (! self::intValueSupported($offset + $length)) { + throw new Exception('cannot copy file portion, it extends beyond the '.round(PHP_INT_MAX / 1073741824).'GB limit'); + } + if (is_readable($filename_source) && is_file($filename_source) && ($fp_src = fopen($filename_source, 'rb'))) { + if (($fp_dest = fopen($filename_dest, 'wb'))) { + if (fseek($fp_src, $offset) == 0) { + $byteslefttowrite = $length; + while (($byteslefttowrite > 0) && ($buffer = fread($fp_src, min($byteslefttowrite, getID3::FREAD_BUFFER_SIZE)))) { + $byteswritten = fwrite($fp_dest, $buffer, $byteslefttowrite); + $byteslefttowrite -= $byteswritten; + } + + return true; + } else { + throw new Exception('failed to seek to offset '.$offset.' in '.$filename_source); + } + fclose($fp_dest); + } else { + throw new Exception('failed to create file for writing '.$filename_dest); + } + fclose($fp_src); + } else { + throw new Exception('failed to open file for reading '.$filename_source); + } + + return false; + } + + public static function iconv_fallback_int_utf8($charval) + { + if ($charval < 128) { + // 0bbbbbbb + $newcharstring = chr($charval); + } elseif ($charval < 2048) { + // 110bbbbb 10bbbbbb + $newcharstring = chr(($charval >> 6) | 0xC0); + $newcharstring .= chr(($charval & 0x3F) | 0x80); + } elseif ($charval < 65536) { + // 1110bbbb 10bbbbbb 10bbbbbb + $newcharstring = chr(($charval >> 12) | 0xE0); + $newcharstring .= chr(($charval >> 6) | 0xC0); + $newcharstring .= chr(($charval & 0x3F) | 0x80); + } else { + // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb + $newcharstring = chr(($charval >> 18) | 0xF0); + $newcharstring .= chr(($charval >> 12) | 0xC0); + $newcharstring .= chr(($charval >> 6) | 0xC0); + $newcharstring .= chr(($charval & 0x3F) | 0x80); + } + + return $newcharstring; + } + + // ISO-8859-1 => UTF-8 + public static function iconv_fallback_iso88591_utf8($string, $bom = false) + { + if (function_exists('utf8_encode')) { + return utf8_encode($string); + } + // utf8_encode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support) + $newcharstring = ''; + if ($bom) { + $newcharstring .= "\xEF\xBB\xBF"; + } + for ($i = 0; $i < strlen($string); $i++) { + $charval = ord($string[$i]); + $newcharstring .= self::iconv_fallback_int_utf8($charval); + } + + return $newcharstring; + } + + // ISO-8859-1 => UTF-16BE + public static function iconv_fallback_iso88591_utf16be($string, $bom = false) + { + $newcharstring = ''; + if ($bom) { + $newcharstring .= "\xFE\xFF"; + } + for ($i = 0; $i < strlen($string); $i++) { + $newcharstring .= "\x00".$string[$i]; + } + + return $newcharstring; + } + + // ISO-8859-1 => UTF-16LE + public static function iconv_fallback_iso88591_utf16le($string, $bom = false) + { + $newcharstring = ''; + if ($bom) { + $newcharstring .= "\xFF\xFE"; + } + for ($i = 0; $i < strlen($string); $i++) { + $newcharstring .= $string[$i]."\x00"; + } + + return $newcharstring; + } + + // ISO-8859-1 => UTF-16LE (BOM) + public static function iconv_fallback_iso88591_utf16($string) + { + return self::iconv_fallback_iso88591_utf16le($string, true); + } + + // UTF-8 => ISO-8859-1 + public static function iconv_fallback_utf8_iso88591($string) + { + if (function_exists('utf8_decode')) { + return utf8_decode($string); + } + // utf8_decode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support) + $newcharstring = ''; + $offset = 0; + $stringlength = strlen($string); + while ($offset < $stringlength) { + if ((ord($string[$offset]) | 0x07) == 0xF7) { + // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x07) << 18) & + ((ord($string[($offset + 1)]) & 0x3F) << 12) & + ((ord($string[($offset + 2)]) & 0x3F) << 6) & + (ord($string[($offset + 3)]) & 0x3F); + $offset += 4; + } elseif ((ord($string[$offset]) | 0x0F) == 0xEF) { + // 1110bbbb 10bbbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x0F) << 12) & + ((ord($string[($offset + 1)]) & 0x3F) << 6) & + (ord($string[($offset + 2)]) & 0x3F); + $offset += 3; + } elseif ((ord($string[$offset]) | 0x1F) == 0xDF) { + // 110bbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x1F) << 6) & + (ord($string[($offset + 1)]) & 0x3F); + $offset += 2; + } elseif ((ord($string[$offset]) | 0x7F) == 0x7F) { + // 0bbbbbbb + $charval = ord($string[$offset]); + $offset += 1; + } else { + // error? throw some kind of warning here? + $charval = false; + $offset += 1; + } + if ($charval !== false) { + $newcharstring .= (($charval < 256) ? chr($charval) : '?'); + } + } + + return $newcharstring; + } + + // UTF-8 => UTF-16BE + public static function iconv_fallback_utf8_utf16be($string, $bom = false) + { + $newcharstring = ''; + if ($bom) { + $newcharstring .= "\xFE\xFF"; + } + $offset = 0; + $stringlength = strlen($string); + while ($offset < $stringlength) { + if ((ord($string[$offset]) | 0x07) == 0xF7) { + // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x07) << 18) & + ((ord($string[($offset + 1)]) & 0x3F) << 12) & + ((ord($string[($offset + 2)]) & 0x3F) << 6) & + (ord($string[($offset + 3)]) & 0x3F); + $offset += 4; + } elseif ((ord($string[$offset]) | 0x0F) == 0xEF) { + // 1110bbbb 10bbbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x0F) << 12) & + ((ord($string[($offset + 1)]) & 0x3F) << 6) & + (ord($string[($offset + 2)]) & 0x3F); + $offset += 3; + } elseif ((ord($string[$offset]) | 0x1F) == 0xDF) { + // 110bbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x1F) << 6) & + (ord($string[($offset + 1)]) & 0x3F); + $offset += 2; + } elseif ((ord($string[$offset]) | 0x7F) == 0x7F) { + // 0bbbbbbb + $charval = ord($string[$offset]); + $offset += 1; + } else { + // error? throw some kind of warning here? + $charval = false; + $offset += 1; + } + if ($charval !== false) { + $newcharstring .= (($charval < 65536) ? self::BigEndian2String($charval, 2) : "\x00".'?'); + } + } + + return $newcharstring; + } + + // UTF-8 => UTF-16LE + public static function iconv_fallback_utf8_utf16le($string, $bom = false) + { + $newcharstring = ''; + if ($bom) { + $newcharstring .= "\xFF\xFE"; + } + $offset = 0; + $stringlength = strlen($string); + while ($offset < $stringlength) { + if ((ord($string[$offset]) | 0x07) == 0xF7) { + // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x07) << 18) & + ((ord($string[($offset + 1)]) & 0x3F) << 12) & + ((ord($string[($offset + 2)]) & 0x3F) << 6) & + (ord($string[($offset + 3)]) & 0x3F); + $offset += 4; + } elseif ((ord($string[$offset]) | 0x0F) == 0xEF) { + // 1110bbbb 10bbbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x0F) << 12) & + ((ord($string[($offset + 1)]) & 0x3F) << 6) & + (ord($string[($offset + 2)]) & 0x3F); + $offset += 3; + } elseif ((ord($string[$offset]) | 0x1F) == 0xDF) { + // 110bbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x1F) << 6) & + (ord($string[($offset + 1)]) & 0x3F); + $offset += 2; + } elseif ((ord($string[$offset]) | 0x7F) == 0x7F) { + // 0bbbbbbb + $charval = ord($string[$offset]); + $offset += 1; + } else { + // error? maybe throw some warning here? + $charval = false; + $offset += 1; + } + if ($charval !== false) { + $newcharstring .= (($charval < 65536) ? self::LittleEndian2String($charval, 2) : '?'."\x00"); + } + } + + return $newcharstring; + } + + // UTF-8 => UTF-16LE (BOM) + public static function iconv_fallback_utf8_utf16($string) + { + return self::iconv_fallback_utf8_utf16le($string, true); + } + + // UTF-16BE => UTF-8 + public static function iconv_fallback_utf16be_utf8($string) + { + if (substr($string, 0, 2) == "\xFE\xFF") { + // strip BOM + $string = substr($string, 2); + } + $newcharstring = ''; + for ($i = 0; $i < strlen($string); $i += 2) { + $charval = self::BigEndian2Int(substr($string, $i, 2)); + $newcharstring .= self::iconv_fallback_int_utf8($charval); + } + + return $newcharstring; + } + + // UTF-16LE => UTF-8 + public static function iconv_fallback_utf16le_utf8($string) + { + if (substr($string, 0, 2) == "\xFF\xFE") { + // strip BOM + $string = substr($string, 2); + } + $newcharstring = ''; + for ($i = 0; $i < strlen($string); $i += 2) { + $charval = self::LittleEndian2Int(substr($string, $i, 2)); + $newcharstring .= self::iconv_fallback_int_utf8($charval); + } + + return $newcharstring; + } + + // UTF-16BE => ISO-8859-1 + public static function iconv_fallback_utf16be_iso88591($string) + { + if (substr($string, 0, 2) == "\xFE\xFF") { + // strip BOM + $string = substr($string, 2); + } + $newcharstring = ''; + for ($i = 0; $i < strlen($string); $i += 2) { + $charval = self::BigEndian2Int(substr($string, $i, 2)); + $newcharstring .= (($charval < 256) ? chr($charval) : '?'); + } + + return $newcharstring; + } + + // UTF-16LE => ISO-8859-1 + public static function iconv_fallback_utf16le_iso88591($string) + { + if (substr($string, 0, 2) == "\xFF\xFE") { + // strip BOM + $string = substr($string, 2); + } + $newcharstring = ''; + for ($i = 0; $i < strlen($string); $i += 2) { + $charval = self::LittleEndian2Int(substr($string, $i, 2)); + $newcharstring .= (($charval < 256) ? chr($charval) : '?'); + } + + return $newcharstring; + } + + // UTF-16 (BOM) => ISO-8859-1 + public static function iconv_fallback_utf16_iso88591($string) + { + $bom = substr($string, 0, 2); + if ($bom == "\xFE\xFF") { + return self::iconv_fallback_utf16be_iso88591(substr($string, 2)); + } elseif ($bom == "\xFF\xFE") { + return self::iconv_fallback_utf16le_iso88591(substr($string, 2)); + } + + return $string; + } + + // UTF-16 (BOM) => UTF-8 + public static function iconv_fallback_utf16_utf8($string) + { + $bom = substr($string, 0, 2); + if ($bom == "\xFE\xFF") { + return self::iconv_fallback_utf16be_utf8(substr($string, 2)); + } elseif ($bom == "\xFF\xFE") { + return self::iconv_fallback_utf16le_utf8(substr($string, 2)); + } + + return $string; + } + + public static function iconv_fallback($in_charset, $out_charset, $string) + { + if ($in_charset == $out_charset) { + return $string; + } + + // mb_convert_encoding() availble + if (function_exists('mb_convert_encoding')) { + if ($converted_string = @mb_convert_encoding($string, $out_charset, $in_charset)) { + switch ($out_charset) { + case 'ISO-8859-1': + $converted_string = rtrim($converted_string, "\x00"); + break; + } + + return $converted_string; + } + + return $string; + } + // iconv() availble + elseif (function_exists('iconv')) { + if ($converted_string = @iconv($in_charset, $out_charset.'//TRANSLIT', $string)) { + switch ($out_charset) { + case 'ISO-8859-1': + $converted_string = rtrim($converted_string, "\x00"); + break; + } + + return $converted_string; + } + + // iconv() may sometimes fail with "illegal character in input string" error message + // and return an empty string, but returning the unconverted string is more useful + return $string; + } + + // neither mb_convert_encoding or iconv() is available + static $ConversionFunctionList = []; + if (empty($ConversionFunctionList)) { + $ConversionFunctionList['ISO-8859-1']['UTF-8'] = 'iconv_fallback_iso88591_utf8'; + $ConversionFunctionList['ISO-8859-1']['UTF-16'] = 'iconv_fallback_iso88591_utf16'; + $ConversionFunctionList['ISO-8859-1']['UTF-16BE'] = 'iconv_fallback_iso88591_utf16be'; + $ConversionFunctionList['ISO-8859-1']['UTF-16LE'] = 'iconv_fallback_iso88591_utf16le'; + $ConversionFunctionList['UTF-8']['ISO-8859-1'] = 'iconv_fallback_utf8_iso88591'; + $ConversionFunctionList['UTF-8']['UTF-16'] = 'iconv_fallback_utf8_utf16'; + $ConversionFunctionList['UTF-8']['UTF-16BE'] = 'iconv_fallback_utf8_utf16be'; + $ConversionFunctionList['UTF-8']['UTF-16LE'] = 'iconv_fallback_utf8_utf16le'; + $ConversionFunctionList['UTF-16']['ISO-8859-1'] = 'iconv_fallback_utf16_iso88591'; + $ConversionFunctionList['UTF-16']['UTF-8'] = 'iconv_fallback_utf16_utf8'; + $ConversionFunctionList['UTF-16LE']['ISO-8859-1'] = 'iconv_fallback_utf16le_iso88591'; + $ConversionFunctionList['UTF-16LE']['UTF-8'] = 'iconv_fallback_utf16le_utf8'; + $ConversionFunctionList['UTF-16BE']['ISO-8859-1'] = 'iconv_fallback_utf16be_iso88591'; + $ConversionFunctionList['UTF-16BE']['UTF-8'] = 'iconv_fallback_utf16be_utf8'; + } + if (isset($ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)])) { + $ConversionFunction = $ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)]; + + return self::$ConversionFunction($string); + } + throw new Exception('PHP does not has mb_convert_encoding() or iconv() support - cannot convert from '.$in_charset.' to '.$out_charset); + } + + public static function recursiveMultiByteCharString2HTML($data, $charset = 'ISO-8859-1') + { + if (is_string($data)) { + return self::MultiByteCharString2HTML($data, $charset); + } elseif (is_array($data)) { + $return_data = []; + foreach ($data as $key => $value) { + $return_data[$key] = self::recursiveMultiByteCharString2HTML($value, $charset); + } + + return $return_data; + } + // integer, float, objects, resources, etc + return $data; + } + + public static function MultiByteCharString2HTML($string, $charset = 'ISO-8859-1') + { + $string = (string) $string; // in case trying to pass a numeric (float, int) string, would otherwise return an empty string + $HTMLstring = ''; + + switch (strtolower($charset)) { + case '1251': + case '1252': + case '866': + case '932': + case '936': + case '950': + case 'big5': + case 'big5-hkscs': + case 'cp1251': + case 'cp1252': + case 'cp866': + case 'euc-jp': + case 'eucjp': + case 'gb2312': + case 'ibm866': + case 'iso-8859-1': + case 'iso-8859-15': + case 'iso8859-1': + case 'iso8859-15': + case 'koi8-r': + case 'koi8-ru': + case 'koi8r': + case 'shift_jis': + case 'sjis': + case 'win-1251': + case 'windows-1251': + case 'windows-1252': + $HTMLstring = htmlentities($string, ENT_COMPAT, $charset); + break; + + case 'utf-8': + $strlen = strlen($string); + for ($i = 0; $i < $strlen; $i++) { + $char_ord_val = ord($string[$i]); + $charval = 0; + if ($char_ord_val < 0x80) { + $charval = $char_ord_val; + } elseif ((($char_ord_val & 0xF0) >> 4) == 0x0F && $i + 3 < $strlen) { + $charval = (($char_ord_val & 0x07) << 18); + $charval += ((ord($string[++$i]) & 0x3F) << 12); + $charval += ((ord($string[++$i]) & 0x3F) << 6); + $charval += (ord($string[++$i]) & 0x3F); + } elseif ((($char_ord_val & 0xE0) >> 5) == 0x07 && $i + 2 < $strlen) { + $charval = (($char_ord_val & 0x0F) << 12); + $charval += ((ord($string[++$i]) & 0x3F) << 6); + $charval += (ord($string[++$i]) & 0x3F); + } elseif ((($char_ord_val & 0xC0) >> 6) == 0x03 && $i + 1 < $strlen) { + $charval = (($char_ord_val & 0x1F) << 6); + $charval += (ord($string[++$i]) & 0x3F); + } + if (($charval >= 32) && ($charval <= 127)) { + $HTMLstring .= htmlentities(chr($charval)); + } else { + $HTMLstring .= '&#'.$charval.';'; + } + } + break; + + case 'utf-16le': + for ($i = 0; $i < strlen($string); $i += 2) { + $charval = self::LittleEndian2Int(substr($string, $i, 2)); + if (($charval >= 32) && ($charval <= 127)) { + $HTMLstring .= chr($charval); + } else { + $HTMLstring .= '&#'.$charval.';'; + } + } + break; + + case 'utf-16be': + for ($i = 0; $i < strlen($string); $i += 2) { + $charval = self::BigEndian2Int(substr($string, $i, 2)); + if (($charval >= 32) && ($charval <= 127)) { + $HTMLstring .= chr($charval); + } else { + $HTMLstring .= '&#'.$charval.';'; + } + } + break; + + default: + $HTMLstring = 'ERROR: Character set "'.$charset.'" not supported in MultiByteCharString2HTML()'; + break; + } + + return $HTMLstring; + } + + public static function RGADnameLookup($namecode) + { + static $RGADname = []; + if (empty($RGADname)) { + $RGADname[0] = 'not set'; + $RGADname[1] = 'Track Gain Adjustment'; + $RGADname[2] = 'Album Gain Adjustment'; + } + + return isset($RGADname[$namecode]) ? $RGADname[$namecode] : ''; + } + + public static function RGADoriginatorLookup($originatorcode) + { + static $RGADoriginator = []; + if (empty($RGADoriginator)) { + $RGADoriginator[0] = 'unspecified'; + $RGADoriginator[1] = 'pre-set by artist/producer/mastering engineer'; + $RGADoriginator[2] = 'set by user'; + $RGADoriginator[3] = 'determined automatically'; + } + + return isset($RGADoriginator[$originatorcode]) ? $RGADoriginator[$originatorcode] : ''; + } + + public static function RGADadjustmentLookup($rawadjustment, $signbit) + { + $adjustment = $rawadjustment / 10; + if ($signbit == 1) { + $adjustment *= -1; + } + + return (float) $adjustment; + } + + public static function RGADgainString($namecode, $originatorcode, $replaygain) + { + if ($replaygain < 0) { + $signbit = '1'; + } else { + $signbit = '0'; + } + $storedreplaygain = intval(round($replaygain * 10)); + $gainstring = str_pad(decbin($namecode), 3, '0', STR_PAD_LEFT); + $gainstring .= str_pad(decbin($originatorcode), 3, '0', STR_PAD_LEFT); + $gainstring .= $signbit; + $gainstring .= str_pad(decbin($storedreplaygain), 9, '0', STR_PAD_LEFT); + + return $gainstring; + } + + public static function RGADamplitude2dB($amplitude) + { + return 20 * log10($amplitude); + } + + public static function GetDataImageSize($imgData, &$imageinfo = []) + { + static $tempdir = ''; + if (empty($tempdir)) { + if (function_exists('sys_get_temp_dir')) { + $tempdir = sys_get_temp_dir(); // https://github.com/JamesHeinrich/getID3/issues/52 + } + + // yes this is ugly, feel free to suggest a better way + if (include_once dirname(__FILE__).'/getid3.php') { + if ($getid3_temp = new getID3()) { + if ($getid3_temp_tempdir = $getid3_temp->tempdir) { + $tempdir = $getid3_temp_tempdir; + } + unset($getid3_temp, $getid3_temp_tempdir); + } + } + } + $GetDataImageSize = false; + if ($tempfilename = tempnam($tempdir, 'gI3')) { + if (is_writable($tempfilename) && is_file($tempfilename) && ($tmp = fopen($tempfilename, 'wb'))) { + fwrite($tmp, $imgData); + fclose($tmp); + $GetDataImageSize = @getimagesize($tempfilename, $imageinfo); + if (($GetDataImageSize === false) || ! isset($GetDataImageSize[0]) || ! isset($GetDataImageSize[1])) { + return false; + } + $GetDataImageSize['height'] = $GetDataImageSize[0]; + $GetDataImageSize['width'] = $GetDataImageSize[1]; + } + unlink($tempfilename); + } + + return $GetDataImageSize; + } + + public static function ImageExtFromMime($mime_type) + { + // temporary way, works OK for now, but should be reworked in the future + return str_replace(['image/', 'x-', 'jpeg'], ['', '', 'jpg'], $mime_type); + } + + public static function ImageTypesLookup($imagetypeid) + { + static $ImageTypesLookup = []; + if (empty($ImageTypesLookup)) { + $ImageTypesLookup[1] = 'gif'; + $ImageTypesLookup[2] = 'jpeg'; + $ImageTypesLookup[3] = 'png'; + $ImageTypesLookup[4] = 'swf'; + $ImageTypesLookup[5] = 'psd'; + $ImageTypesLookup[6] = 'bmp'; + $ImageTypesLookup[7] = 'tiff (little-endian)'; + $ImageTypesLookup[8] = 'tiff (big-endian)'; + $ImageTypesLookup[9] = 'jpc'; + $ImageTypesLookup[10] = 'jp2'; + $ImageTypesLookup[11] = 'jpx'; + $ImageTypesLookup[12] = 'jb2'; + $ImageTypesLookup[13] = 'swc'; + $ImageTypesLookup[14] = 'iff'; + } + + return isset($ImageTypesLookup[$imagetypeid]) ? $ImageTypesLookup[$imagetypeid] : ''; + } + + public static function CopyTagsToComments(&$ThisFileInfo) + { + + // Copy all entries from ['tags'] into common ['comments'] + if (! empty($ThisFileInfo['tags'])) { + foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) { + foreach ($tagarray as $tagname => $tagdata) { + foreach ($tagdata as $key => $value) { + if (! empty($value)) { + if (empty($ThisFileInfo['comments'][$tagname])) { + + // fall through and append value + } elseif ($tagtype == 'id3v1') { + $newvaluelength = strlen(trim($value)); + foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) { + $oldvaluelength = strlen(trim($existingvalue)); + if (($newvaluelength <= $oldvaluelength) && (substr($existingvalue, 0, $newvaluelength) == trim($value))) { + // new value is identical but shorter-than (or equal-length to) one already in comments - skip + break 2; + } + } + } elseif (! is_array($value)) { + $newvaluelength = strlen(trim($value)); + foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) { + $oldvaluelength = strlen(trim($existingvalue)); + if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) { + $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value); + //break 2; + break; + } + } + } + if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || ! in_array(trim($value), $ThisFileInfo['comments'][$tagname])) { + $value = (is_string($value) ? trim($value) : $value); + if (! is_int($key) && ! ctype_digit($key)) { + $ThisFileInfo['comments'][$tagname][$key] = $value; + } else { + if (isset($ThisFileInfo['comments'][$tagname])) { + $ThisFileInfo['comments'][$tagname] = [$value]; + } else { + $ThisFileInfo['comments'][$tagname][] = $value; + } + } + } + } + } + } + } + + // attempt to standardize spelling of returned keys + $StandardizeFieldNames = [ + 'tracknumber' => 'track_number', + 'track' => 'track_number', + ]; + foreach ($StandardizeFieldNames as $badkey => $goodkey) { + if (array_key_exists($badkey, $ThisFileInfo['comments']) && ! array_key_exists($goodkey, $ThisFileInfo['comments'])) { + $ThisFileInfo['comments'][$goodkey] = $ThisFileInfo['comments'][$badkey]; + unset($ThisFileInfo['comments'][$badkey]); + } + } + + // Copy to ['comments_html'] + if (! empty($ThisFileInfo['comments'])) { + foreach ($ThisFileInfo['comments'] as $field => $values) { + if ($field == 'picture') { + // pictures can take up a lot of space, and we don't need multiple copies of them + // let there be a single copy in [comments][picture], and not elsewhere + continue; + } + foreach ($values as $index => $value) { + if (is_array($value)) { + $ThisFileInfo['comments_html'][$field][$index] = $value; + } else { + $ThisFileInfo['comments_html'][$field][$index] = str_replace('�', '', self::MultiByteCharString2HTML($value, $ThisFileInfo['encoding'])); + } + } + } + } + } + + return true; + } + + public static function EmbeddedLookup($key, $begin, $end, $file, $name) + { + + // Cached + static $cache; + if (isset($cache[$file][$name])) { + return isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : ''; + } + + // Init + $keylength = strlen($key); + $line_count = $end - $begin - 7; + + // Open php file + $fp = fopen($file, 'r'); + + // Discard $begin lines + for ($i = 0; $i < ($begin + 3); $i++) { + fgets($fp, 1024); + } + + // Loop thru line + while (0 < $line_count--) { + + // Read line + $line = ltrim(fgets($fp, 1024), "\t "); + + // METHOD A: only cache the matching key - less memory but slower on next lookup of not-previously-looked-up key + //$keycheck = substr($line, 0, $keylength); + //if ($key == $keycheck) { + // $cache[$file][$name][$keycheck] = substr($line, $keylength + 1); + // break; + //} + + // METHOD B: cache all keys in this lookup - more memory but faster on next lookup of not-previously-looked-up key + //$cache[$file][$name][substr($line, 0, $keylength)] = trim(substr($line, $keylength + 1)); + $explodedLine = explode("\t", $line, 2); + $ThisKey = (isset($explodedLine[0]) ? $explodedLine[0] : ''); + $ThisValue = (isset($explodedLine[1]) ? $explodedLine[1] : ''); + $cache[$file][$name][$ThisKey] = trim($ThisValue); + } + + // Close and return + fclose($fp); + + return isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : ''; + } + + public static function IncludeDependency($filename, $sourcefile, $DieOnFailure = false) + { + global $GETID3_ERRORARRAY; + + if (file_exists($filename)) { + if (include_once $filename) { + return true; + } else { + $diemessage = basename($sourcefile).' depends on '.$filename.', which has errors'; + } + } else { + $diemessage = basename($sourcefile).' depends on '.$filename.', which is missing'; + } + if ($DieOnFailure) { + throw new Exception($diemessage); + } else { + $GETID3_ERRORARRAY[] = $diemessage; + } + + return false; + } + + public static function trimNullByte($string) + { + return trim($string, "\x00"); + } + + public static function getFileSizeSyscall($path) + { + $filesize = false; + + if (GETID3_OS_ISWINDOWS) { + if (class_exists('COM')) { // From PHP 5.3.15 and 5.4.5, COM and DOTNET is no longer built into the php core.you have to add COM support in php.ini: + $filesystem = new COM('Scripting.FileSystemObject'); + $file = $filesystem->GetFile($path); + $filesize = $file->Size(); + unset($filesystem, $file); + } else { + $commandline = 'for %I in ('.escapeshellarg($path).') do @echo %~zI'; + } + } else { + $commandline = 'ls -l '.escapeshellarg($path).' | awk \'{print $5}\''; + } + if (isset($commandline)) { + $output = trim(`$commandline`); + if (ctype_digit($output)) { + $filesize = (float) $output; + } + } + + return $filesize; + } + + /** + * Workaround for Bug #37268 (https://bugs.php.net/bug.php?id=37268). + * @param string $path A path. + * @param string $suffix If the name component ends in suffix this will also be cut off. + * @return string + */ + public static function mb_basename($path, $suffix = null) + { + $splited = preg_split('#/#', rtrim($path, '/ ')); + + return substr(basename('X'.$splited[count($splited) - 1], $suffix), 1); + } } diff --git a/app/Library/getid3/getid3/getid3.php b/app/Library/getid3/getid3/getid3.php index 37bf9443..06591bff 100644 --- a/app/Library/getid3/getid3/getid3.php +++ b/app/Library/getid3/getid3/getid3.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -11,704 +12,711 @@ ///////////////////////////////////////////////////////////////// // define a constant rather than looking up every time it is needed -if (!defined('GETID3_OS_ISWINDOWS')) { - define('GETID3_OS_ISWINDOWS', (stripos(PHP_OS, 'WIN') === 0)); +if (! defined('GETID3_OS_ISWINDOWS')) { + define('GETID3_OS_ISWINDOWS', (stripos(PHP_OS, 'WIN') === 0)); } // Get base path of getID3() - ONCE -if (!defined('GETID3_INCLUDEPATH')) { - define('GETID3_INCLUDEPATH', dirname(__FILE__).DIRECTORY_SEPARATOR); +if (! defined('GETID3_INCLUDEPATH')) { + define('GETID3_INCLUDEPATH', dirname(__FILE__).DIRECTORY_SEPARATOR); } // Workaround Bug #39923 (https://bugs.php.net/bug.php?id=39923) -if (!defined('IMG_JPG') && defined('IMAGETYPE_JPEG')) { - define('IMG_JPG', IMAGETYPE_JPEG); +if (! defined('IMG_JPG') && defined('IMAGETYPE_JPEG')) { + define('IMG_JPG', IMAGETYPE_JPEG); } -if (!defined('ENT_SUBSTITUTE')) { // PHP5.3 adds ENT_IGNORE, PHP5.4 adds ENT_SUBSTITUTE - define('ENT_SUBSTITUTE', (defined('ENT_IGNORE') ? ENT_IGNORE : 8)); +if (! defined('ENT_SUBSTITUTE')) { // PHP5.3 adds ENT_IGNORE, PHP5.4 adds ENT_SUBSTITUTE + define('ENT_SUBSTITUTE', (defined('ENT_IGNORE') ? ENT_IGNORE : 8)); } // attempt to define temp dir as something flexible but reliable $temp_dir = ini_get('upload_tmp_dir'); -if ($temp_dir && (!is_dir($temp_dir) || !is_readable($temp_dir))) { - $temp_dir = ''; +if ($temp_dir && (! is_dir($temp_dir) || ! is_readable($temp_dir))) { + $temp_dir = ''; } -if (!$temp_dir && function_exists('sys_get_temp_dir')) { // sys_get_temp_dir added in PHP v5.2.1 - // sys_get_temp_dir() may give inaccessible temp dir, e.g. with open_basedir on virtual hosts - $temp_dir = sys_get_temp_dir(); +if (! $temp_dir && function_exists('sys_get_temp_dir')) { // sys_get_temp_dir added in PHP v5.2.1 + // sys_get_temp_dir() may give inaccessible temp dir, e.g. with open_basedir on virtual hosts + $temp_dir = sys_get_temp_dir(); } $temp_dir = @realpath($temp_dir); // see https://github.com/JamesHeinrich/getID3/pull/10 $open_basedir = ini_get('open_basedir'); if ($open_basedir) { - // e.g. "/var/www/vhosts/getid3.org/httpdocs/:/tmp/" - $temp_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $temp_dir); - $open_basedir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $open_basedir); - if (substr($temp_dir, -1, 1) != DIRECTORY_SEPARATOR) { - $temp_dir .= DIRECTORY_SEPARATOR; - } - $found_valid_tempdir = false; - $open_basedirs = explode(PATH_SEPARATOR, $open_basedir); - foreach ($open_basedirs as $basedir) { - if (substr($basedir, -1, 1) != DIRECTORY_SEPARATOR) { - $basedir .= DIRECTORY_SEPARATOR; - } - if (preg_match('#^'.preg_quote($basedir).'#', $temp_dir)) { - $found_valid_tempdir = true; - break; - } - } - if (!$found_valid_tempdir) { - $temp_dir = ''; - } - unset($open_basedirs, $found_valid_tempdir, $basedir); + // e.g. "/var/www/vhosts/getid3.org/httpdocs/:/tmp/" + $temp_dir = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $temp_dir); + $open_basedir = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $open_basedir); + if (substr($temp_dir, -1, 1) != DIRECTORY_SEPARATOR) { + $temp_dir .= DIRECTORY_SEPARATOR; + } + $found_valid_tempdir = false; + $open_basedirs = explode(PATH_SEPARATOR, $open_basedir); + foreach ($open_basedirs as $basedir) { + if (substr($basedir, -1, 1) != DIRECTORY_SEPARATOR) { + $basedir .= DIRECTORY_SEPARATOR; + } + if (preg_match('#^'.preg_quote($basedir).'#', $temp_dir)) { + $found_valid_tempdir = true; + break; + } + } + if (! $found_valid_tempdir) { + $temp_dir = ''; + } + unset($open_basedirs, $found_valid_tempdir, $basedir); } -if (!$temp_dir) { - $temp_dir = '*'; // invalid directory name should force tempnam() to use system default temp dir +if (! $temp_dir) { + $temp_dir = '*'; // invalid directory name should force tempnam() to use system default temp dir } // $temp_dir = '/something/else/'; // feel free to override temp dir here if it works better for your system -if (!defined('GETID3_TEMP_DIR')) { - define('GETID3_TEMP_DIR', $temp_dir); +if (! defined('GETID3_TEMP_DIR')) { + define('GETID3_TEMP_DIR', $temp_dir); } unset($open_basedir, $temp_dir); // End: Defines - class getID3 { - // public: Settings - public $encoding = 'UTF-8'; // CASE SENSITIVE! - i.e. (must be supported by iconv()). Examples: ISO-8859-1 UTF-8 UTF-16 UTF-16BE - public $encoding_id3v1 = 'ISO-8859-1'; // Should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'EUC-CN' or 'CP1252' - - // public: Optional tag checks - disable for speed. - public $option_tag_id3v1 = true; // Read and process ID3v1 tags - public $option_tag_id3v2 = true; // Read and process ID3v2 tags - public $option_tag_lyrics3 = true; // Read and process Lyrics3 tags - public $option_tag_apetag = true; // Read and process APE tags - public $option_tags_process = true; // Copy tags to root key 'tags' and encode to $this->encoding - public $option_tags_html = true; // Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities - - // public: Optional tag/comment calucations - public $option_extra_info = true; // Calculate additional info such as bitrate, channelmode etc - - // public: Optional handling of embedded attachments (e.g. images) - public $option_save_attachments = true; // defaults to true (ATTACHMENTS_INLINE) for backward compatibility - - // public: Optional calculations - public $option_md5_data = false; // Get MD5 sum of data part - slow - public $option_md5_data_source = false; // Use MD5 of source file if availble - only FLAC and OptimFROG - public $option_sha1_data = false; // Get SHA1 sum of data part - slow - public $option_max_2gb_check = null; // Check whether file is larger than 2GB and thus not supported by 32-bit PHP (null: auto-detect based on PHP_INT_MAX) - - // public: Read buffer size in bytes - public $option_fread_buffer_size = 32768; - - // Public variables - public $filename; // Filename of file being analysed. - public $fp; // Filepointer to file being analysed. - public $info; // Result array. - public $tempdir = GETID3_TEMP_DIR; - public $memory_limit = 0; - - // Protected variables - protected $startup_error = ''; - protected $startup_warning = ''; - - const VERSION = '1.9.14-201703261440'; - const FREAD_BUFFER_SIZE = 32768; - - const ATTACHMENTS_NONE = false; - const ATTACHMENTS_INLINE = true; - - // public: constructor - public function __construct() { - - // Check for PHP version - $required_php_version = '5.3.0'; - if (version_compare(PHP_VERSION, $required_php_version, '<')) { - $this->startup_error .= 'getID3() requires PHP v'.$required_php_version.' or higher - you are running v'.PHP_VERSION."\n"; - return false; - } - - // Check memory - $this->memory_limit = ini_get('memory_limit'); - if (preg_match('#([0-9]+)M#i', $this->memory_limit, $matches)) { - // could be stored as "16M" rather than 16777216 for example - $this->memory_limit = $matches[1] * 1048576; - } elseif (preg_match('#([0-9]+)G#i', $this->memory_limit, $matches)) { // The 'G' modifier is available since PHP 5.1.0 - // could be stored as "2G" rather than 2147483648 for example - $this->memory_limit = $matches[1] * 1073741824; - } - if ($this->memory_limit <= 0) { - // memory limits probably disabled - } elseif ($this->memory_limit <= 4194304) { - $this->startup_error .= 'PHP has less than 4MB available memory and will very likely run out. Increase memory_limit in php.ini'."\n"; - } elseif ($this->memory_limit <= 12582912) { - $this->startup_warning .= 'PHP has less than 12MB available memory and might run out if all modules are loaded. Increase memory_limit in php.ini'."\n"; - } - - // Check safe_mode off - if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { - $this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.'); - } - - if (($mbstring_func_overload = ini_get('mbstring.func_overload')) && ($mbstring_func_overload & 0x02)) { - // http://php.net/manual/en/mbstring.overload.php - // "mbstring.func_overload in php.ini is a positive value that represents a combination of bitmasks specifying the categories of functions to be overloaded. It should be set to 1 to overload the mail() function. 2 for string functions, 4 for regular expression functions" - // getID3 cannot run when string functions are overloaded. It doesn't matter if mail() or ereg* functions are overloaded since getID3 does not use those. - $this->startup_error .= 'WARNING: php.ini contains "mbstring.func_overload = '.ini_get('mbstring.func_overload').'", getID3 cannot run with this setting (bitmask 2 (string functions) cannot be set). Recommended to disable entirely.'."\n"; - } - - // Check for magic_quotes_runtime - if (function_exists('get_magic_quotes_runtime')) { - if (get_magic_quotes_runtime()) { - $this->startup_error .= 'magic_quotes_runtime must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_runtime(0) and set_magic_quotes_runtime(1).'."\n"; - } - } - - // Check for magic_quotes_gpc - if (function_exists('magic_quotes_gpc')) { - if (get_magic_quotes_gpc()) { - $this->startup_error .= 'magic_quotes_gpc must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_gpc(0) and set_magic_quotes_gpc(1).'."\n"; - } - } - - // Load support library - if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) { - $this->startup_error .= 'getid3.lib.php is missing or corrupt'."\n"; - } - - if ($this->option_max_2gb_check === null) { - $this->option_max_2gb_check = (PHP_INT_MAX <= 2147483647); - } - - - // Needed for Windows only: - // Define locations of helper applications for Shorten, VorbisComment, MetaFLAC - // as well as other helper functions such as head, tail, md5sum, etc - // This path cannot contain spaces, but the below code will attempt to get the - // 8.3-equivalent path automatically - // IMPORTANT: This path must include the trailing slash - if (GETID3_OS_ISWINDOWS && !defined('GETID3_HELPERAPPSDIR')) { - - $helperappsdir = GETID3_INCLUDEPATH.'..'.DIRECTORY_SEPARATOR.'helperapps'; // must not have any space in this path - - if (!is_dir($helperappsdir)) { - $this->startup_warning .= '"'.$helperappsdir.'" cannot be defined as GETID3_HELPERAPPSDIR because it does not exist'."\n"; - } elseif (strpos(realpath($helperappsdir), ' ') !== false) { - $DirPieces = explode(DIRECTORY_SEPARATOR, realpath($helperappsdir)); - $path_so_far = array(); - foreach ($DirPieces as $key => $value) { - if (strpos($value, ' ') !== false) { - if (!empty($path_so_far)) { - $commandline = 'dir /x '.escapeshellarg(implode(DIRECTORY_SEPARATOR, $path_so_far)); - $dir_listing = `$commandline`; - $lines = explode("\n", $dir_listing); - foreach ($lines as $line) { - $line = trim($line); - if (preg_match('#^([0-9/]{10}) +([0-9:]{4,5}( [AP]M)?) +(|[0-9,]+) +([^ ]{0,11}) +(.+)$#', $line, $matches)) { - list($dummy, $date, $time, $ampm, $filesize, $shortname, $filename) = $matches; - if ((strtoupper($filesize) == '') && (strtolower($filename) == strtolower($value))) { - $value = $shortname; - } - } - } - } else { - $this->startup_warning .= 'GETID3_HELPERAPPSDIR must not have any spaces in it - use 8dot3 naming convention if neccesary. You can run "dir /x" from the commandline to see the correct 8.3-style names.'."\n"; - } - } - $path_so_far[] = $value; - } - $helperappsdir = implode(DIRECTORY_SEPARATOR, $path_so_far); - } - define('GETID3_HELPERAPPSDIR', $helperappsdir.DIRECTORY_SEPARATOR); - } - - if (!empty($this->startup_error)) { - echo $this->startup_error; - throw new getid3_exception($this->startup_error); - } - - return true; - } - - public function version() { - return self::VERSION; - } - - public function fread_buffer_size() { - return $this->option_fread_buffer_size; - } - - - // public: setOption - public function setOption($optArray) { - if (!is_array($optArray) || empty($optArray)) { - return false; - } - foreach ($optArray as $opt => $val) { - if (isset($this->$opt) === false) { - continue; - } - $this->$opt = $val; - } - return true; - } - - - public function openfile($filename, $filesize=null) { - try { - if (!empty($this->startup_error)) { - throw new getid3_exception($this->startup_error); - } - if (!empty($this->startup_warning)) { - foreach (explode("\n", $this->startup_warning) as $startup_warning) { - $this->warning($startup_warning); - } - } - - // init result array and set parameters - $this->filename = $filename; - $this->info = array(); - $this->info['GETID3_VERSION'] = $this->version(); - $this->info['php_memory_limit'] = (($this->memory_limit > 0) ? $this->memory_limit : false); - - // remote files not supported - if (preg_match('#^(ht|f)tp://#', $filename)) { - throw new getid3_exception('Remote files are not supported - please copy the file locally first'); - } - - $filename = str_replace('/', DIRECTORY_SEPARATOR, $filename); - $filename = preg_replace('#(.+)'.preg_quote(DIRECTORY_SEPARATOR).'{2,}#U', '\1'.DIRECTORY_SEPARATOR, $filename); - - // open local file - //if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) { // see http://www.getid3.org/phpBB3/viewtopic.php?t=1720 - if ((is_readable($filename) || file_exists($filename)) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) { - // great - } else { - $errormessagelist = array(); - if (!is_readable($filename)) { - $errormessagelist[] = '!is_readable'; - } - if (!is_file($filename)) { - $errormessagelist[] = '!is_file'; - } - if (!file_exists($filename)) { - $errormessagelist[] = '!file_exists'; - } - if (empty($errormessagelist)) { - $errormessagelist[] = 'fopen failed'; - } - throw new getid3_exception('Could not open "'.$filename.'" ('.implode('; ', $errormessagelist).')'); - } - - $this->info['filesize'] = (!is_null($filesize) ? $filesize : filesize($filename)); - // set redundant parameters - might be needed in some include file - // filenames / filepaths in getID3 are always expressed with forward slashes (unix-style) for both Windows and other to try and minimize confusion - $filename = str_replace('\\', '/', $filename); - $this->info['filepath'] = str_replace('\\', '/', realpath(dirname($filename))); - $this->info['filename'] = getid3_lib::mb_basename($filename); - $this->info['filenamepath'] = $this->info['filepath'].'/'.$this->info['filename']; - - // set more parameters - $this->info['avdataoffset'] = 0; - $this->info['avdataend'] = $this->info['filesize']; - $this->info['fileformat'] = ''; // filled in later - $this->info['audio']['dataformat'] = ''; // filled in later, unset if not used - $this->info['video']['dataformat'] = ''; // filled in later, unset if not used - $this->info['tags'] = array(); // filled in later, unset if not used - $this->info['error'] = array(); // filled in later, unset if not used - $this->info['warning'] = array(); // filled in later, unset if not used - $this->info['comments'] = array(); // filled in later, unset if not used - $this->info['encoding'] = $this->encoding; // required by id3v2 and iso modules - can be unset at the end if desired - - // option_max_2gb_check - if ($this->option_max_2gb_check) { - // PHP (32-bit all, and 64-bit Windows) doesn't support integers larger than 2^31 (~2GB) - // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize - // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer - $fseek = fseek($this->fp, 0, SEEK_END); - if (($fseek < 0) || (($this->info['filesize'] != 0) && (ftell($this->fp) == 0)) || - ($this->info['filesize'] < 0) || - (ftell($this->fp) < 0)) { - $real_filesize = getid3_lib::getFileSizeSyscall($this->info['filenamepath']); - - if ($real_filesize === false) { - unset($this->info['filesize']); - fclose($this->fp); - throw new getid3_exception('Unable to determine actual filesize. File is most likely larger than '.round(PHP_INT_MAX / 1073741824).'GB and is not supported by PHP.'); - } elseif (getid3_lib::intValueSupported($real_filesize)) { - unset($this->info['filesize']); - fclose($this->fp); - throw new getid3_exception('PHP seems to think the file is larger than '.round(PHP_INT_MAX / 1073741824).'GB, but filesystem reports it as '.number_format($real_filesize, 3).'GB, please report to info@getid3.org'); - } - $this->info['filesize'] = $real_filesize; - $this->warning('File is larger than '.round(PHP_INT_MAX / 1073741824).'GB (filesystem reports it as '.number_format($real_filesize, 3).'GB) and is not properly supported by PHP.'); - } - } - - return true; - - } catch (Exception $e) { - $this->error($e->getMessage()); - } - return false; - } - - // public: analyze file - public function analyze($filename, $filesize=null, $original_filename='') { - try { - if (!$this->openfile($filename, $filesize)) { - return $this->info; - } - - // Handle tags - foreach (array('id3v2'=>'id3v2', 'id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3') as $tag_name => $tag_key) { - $option_tag = 'option_tag_'.$tag_name; - if ($this->$option_tag) { - $this->include_module('tag.'.$tag_name); - try { - $tag_class = 'getid3_'.$tag_name; - $tag = new $tag_class($this); - $tag->Analyze(); - } - catch (getid3_exception $e) { - throw $e; - } - } - } - if (isset($this->info['id3v2']['tag_offset_start'])) { - $this->info['avdataoffset'] = max($this->info['avdataoffset'], $this->info['id3v2']['tag_offset_end']); - } - foreach (array('id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3') as $tag_name => $tag_key) { - if (isset($this->info[$tag_key]['tag_offset_start'])) { - $this->info['avdataend'] = min($this->info['avdataend'], $this->info[$tag_key]['tag_offset_start']); - } - } - - // ID3v2 detection (NOT parsing), even if ($this->option_tag_id3v2 == false) done to make fileformat easier - if (!$this->option_tag_id3v2) { - fseek($this->fp, 0); - $header = fread($this->fp, 10); - if ((substr($header, 0, 3) == 'ID3') && (strlen($header) == 10)) { - $this->info['id3v2']['header'] = true; - $this->info['id3v2']['majorversion'] = ord($header{3}); - $this->info['id3v2']['minorversion'] = ord($header{4}); - $this->info['avdataoffset'] += getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length - } - } - - // read 32 kb file data - fseek($this->fp, $this->info['avdataoffset']); - $formattest = fread($this->fp, 32774); - - // determine format - $determined_format = $this->GetFileFormat($formattest, ($original_filename ? $original_filename : $filename)); - - // unable to determine file format - if (!$determined_format) { - fclose($this->fp); - return $this->error('unable to determine file format'); - } - - // check for illegal ID3 tags - if (isset($determined_format['fail_id3']) && (in_array('id3v1', $this->info['tags']) || in_array('id3v2', $this->info['tags']))) { - if ($determined_format['fail_id3'] === 'ERROR') { - fclose($this->fp); - return $this->error('ID3 tags not allowed on this file type.'); - } elseif ($determined_format['fail_id3'] === 'WARNING') { - $this->warning('ID3 tags not allowed on this file type.'); - } - } - - // check for illegal APE tags - if (isset($determined_format['fail_ape']) && in_array('ape', $this->info['tags'])) { - if ($determined_format['fail_ape'] === 'ERROR') { - fclose($this->fp); - return $this->error('APE tags not allowed on this file type.'); - } elseif ($determined_format['fail_ape'] === 'WARNING') { - $this->warning('APE tags not allowed on this file type.'); - } - } - - // set mime type - $this->info['mime_type'] = $determined_format['mime_type']; - - // supported format signature pattern detected, but module deleted - if (!file_exists(GETID3_INCLUDEPATH.$determined_format['include'])) { - fclose($this->fp); - return $this->error('Format not supported, module "'.$determined_format['include'].'" was removed.'); - } - - // module requires mb_convert_encoding/iconv support - // Check encoding/iconv support - if (!empty($determined_format['iconv_req']) && !function_exists('mb_convert_encoding') && !function_exists('iconv') && !in_array($this->encoding, array('ISO-8859-1', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'UTF-16'))) { - $errormessage = 'mb_convert_encoding() or iconv() support is required for this module ('.$determined_format['include'].') for encodings other than ISO-8859-1, UTF-8, UTF-16LE, UTF16-BE, UTF-16. '; - if (GETID3_OS_ISWINDOWS) { - $errormessage .= 'PHP does not have mb_convert_encoding() or iconv() support. Please enable php_mbstring.dll / php_iconv.dll in php.ini, and copy php_mbstring.dll / iconv.dll from c:/php/dlls to c:/windows/system32'; - } else { - $errormessage .= 'PHP is not compiled with mb_convert_encoding() or iconv() support. Please recompile with the --enable-mbstring / --with-iconv switch'; - } - return $this->error($errormessage); - } - - // include module - include_once(GETID3_INCLUDEPATH.$determined_format['include']); - - // instantiate module class - $class_name = 'getid3_'.$determined_format['module']; - if (!class_exists($class_name)) { - return $this->error('Format not supported, module "'.$determined_format['include'].'" is corrupt.'); - } - $class = new $class_name($this); - $class->Analyze(); - unset($class); - - // close file - fclose($this->fp); - - // process all tags - copy to 'tags' and convert charsets - if ($this->option_tags_process) { - $this->HandleAllTags(); - } - - // perform more calculations - if ($this->option_extra_info) { - $this->ChannelsBitratePlaytimeCalculations(); - $this->CalculateCompressionRatioVideo(); - $this->CalculateCompressionRatioAudio(); - $this->CalculateReplayGain(); - $this->ProcessAudioStreams(); - } - - // get the MD5 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags - if ($this->option_md5_data) { - // do not calc md5_data if md5_data_source is present - set by flac only - future MPC/SV8 too - if (!$this->option_md5_data_source || empty($this->info['md5_data_source'])) { - $this->getHashdata('md5'); - } - } - - // get the SHA1 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags - if ($this->option_sha1_data) { - $this->getHashdata('sha1'); - } - - // remove undesired keys - $this->CleanUp(); - - } catch (Exception $e) { - $this->error('Caught exception: '.$e->getMessage()); - } - - // return info array - return $this->info; - } - - - // private: error handling - public function error($message) { - $this->CleanUp(); - if (!isset($this->info['error'])) { - $this->info['error'] = array(); - } - $this->info['error'][] = $message; - return $this->info; - } - - - // private: warning handling - public function warning($message) { - $this->info['warning'][] = $message; - return true; - } - - - // private: CleanUp - private function CleanUp() { - - // remove possible empty keys - $AVpossibleEmptyKeys = array('dataformat', 'bits_per_sample', 'encoder_options', 'streams', 'bitrate'); - foreach ($AVpossibleEmptyKeys as $dummy => $key) { - if (empty($this->info['audio'][$key]) && isset($this->info['audio'][$key])) { - unset($this->info['audio'][$key]); - } - if (empty($this->info['video'][$key]) && isset($this->info['video'][$key])) { - unset($this->info['video'][$key]); - } - } - - // remove empty root keys - if (!empty($this->info)) { - foreach ($this->info as $key => $value) { - if (empty($this->info[$key]) && ($this->info[$key] !== 0) && ($this->info[$key] !== '0')) { - unset($this->info[$key]); - } - } - } - - // remove meaningless entries from unknown-format files - if (empty($this->info['fileformat'])) { - if (isset($this->info['avdataoffset'])) { - unset($this->info['avdataoffset']); - } - if (isset($this->info['avdataend'])) { - unset($this->info['avdataend']); - } - } - - // remove possible duplicated identical entries - if (!empty($this->info['error'])) { - $this->info['error'] = array_values(array_unique($this->info['error'])); - } - if (!empty($this->info['warning'])) { - $this->info['warning'] = array_values(array_unique($this->info['warning'])); - } - - // remove "global variable" type keys - unset($this->info['php_memory_limit']); - - return true; - } - - - // return array containing information about all supported formats - public function GetFileFormatArray() { - static $format_info = array(); - if (empty($format_info)) { - $format_info = array( - - // Audio formats - - // AC-3 - audio - Dolby AC-3 / Dolby Digital - 'ac3' => array( - 'pattern' => '^\\x0B\\x77', - 'group' => 'audio', - 'module' => 'ac3', - 'mime_type' => 'audio/ac3', - ), - - // AAC - audio - Advanced Audio Coding (AAC) - ADIF format - 'adif' => array( - 'pattern' => '^ADIF', - 'group' => 'audio', - 'module' => 'aac', - 'mime_type' => 'application/octet-stream', - 'fail_ape' => 'WARNING', - ), + // public: Settings + public $encoding = 'UTF-8'; // CASE SENSITIVE! - i.e. (must be supported by iconv()). Examples: ISO-8859-1 UTF-8 UTF-16 UTF-16BE + public $encoding_id3v1 = 'ISO-8859-1'; // Should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'EUC-CN' or 'CP1252' + + // public: Optional tag checks - disable for speed. + public $option_tag_id3v1 = true; // Read and process ID3v1 tags + public $option_tag_id3v2 = true; // Read and process ID3v2 tags + public $option_tag_lyrics3 = true; // Read and process Lyrics3 tags + public $option_tag_apetag = true; // Read and process APE tags + public $option_tags_process = true; // Copy tags to root key 'tags' and encode to $this->encoding + public $option_tags_html = true; // Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities + + // public: Optional tag/comment calucations + public $option_extra_info = true; // Calculate additional info such as bitrate, channelmode etc + + // public: Optional handling of embedded attachments (e.g. images) + public $option_save_attachments = true; // defaults to true (ATTACHMENTS_INLINE) for backward compatibility + + // public: Optional calculations + public $option_md5_data = false; // Get MD5 sum of data part - slow + public $option_md5_data_source = false; // Use MD5 of source file if availble - only FLAC and OptimFROG + public $option_sha1_data = false; // Get SHA1 sum of data part - slow + public $option_max_2gb_check = null; // Check whether file is larger than 2GB and thus not supported by 32-bit PHP (null: auto-detect based on PHP_INT_MAX) + + // public: Read buffer size in bytes + public $option_fread_buffer_size = 32768; + + // Public variables + public $filename; // Filename of file being analysed. + public $fp; // Filepointer to file being analysed. + public $info; // Result array. + public $tempdir = GETID3_TEMP_DIR; + public $memory_limit = 0; + + // Protected variables + protected $startup_error = ''; + protected $startup_warning = ''; + + const VERSION = '1.9.14-201703261440'; + const FREAD_BUFFER_SIZE = 32768; + + const ATTACHMENTS_NONE = false; + const ATTACHMENTS_INLINE = true; + + // public: constructor + public function __construct() + { + + // Check for PHP version + $required_php_version = '5.3.0'; + if (version_compare(PHP_VERSION, $required_php_version, '<')) { + $this->startup_error .= 'getID3() requires PHP v'.$required_php_version.' or higher - you are running v'.PHP_VERSION."\n"; + + return false; + } + + // Check memory + $this->memory_limit = ini_get('memory_limit'); + if (preg_match('#([0-9]+)M#i', $this->memory_limit, $matches)) { + // could be stored as "16M" rather than 16777216 for example + $this->memory_limit = $matches[1] * 1048576; + } elseif (preg_match('#([0-9]+)G#i', $this->memory_limit, $matches)) { // The 'G' modifier is available since PHP 5.1.0 + // could be stored as "2G" rather than 2147483648 for example + $this->memory_limit = $matches[1] * 1073741824; + } + if ($this->memory_limit <= 0) { + // memory limits probably disabled + } elseif ($this->memory_limit <= 4194304) { + $this->startup_error .= 'PHP has less than 4MB available memory and will very likely run out. Increase memory_limit in php.ini'."\n"; + } elseif ($this->memory_limit <= 12582912) { + $this->startup_warning .= 'PHP has less than 12MB available memory and might run out if all modules are loaded. Increase memory_limit in php.ini'."\n"; + } + + // Check safe_mode off + if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { + $this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.'); + } + + if (($mbstring_func_overload = ini_get('mbstring.func_overload')) && ($mbstring_func_overload & 0x02)) { + // http://php.net/manual/en/mbstring.overload.php + // "mbstring.func_overload in php.ini is a positive value that represents a combination of bitmasks specifying the categories of functions to be overloaded. It should be set to 1 to overload the mail() function. 2 for string functions, 4 for regular expression functions" + // getID3 cannot run when string functions are overloaded. It doesn't matter if mail() or ereg* functions are overloaded since getID3 does not use those. + $this->startup_error .= 'WARNING: php.ini contains "mbstring.func_overload = '.ini_get('mbstring.func_overload').'", getID3 cannot run with this setting (bitmask 2 (string functions) cannot be set). Recommended to disable entirely.'."\n"; + } + + // Check for magic_quotes_runtime + if (function_exists('get_magic_quotes_runtime')) { + if (get_magic_quotes_runtime()) { + $this->startup_error .= 'magic_quotes_runtime must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_runtime(0) and set_magic_quotes_runtime(1).'."\n"; + } + } + + // Check for magic_quotes_gpc + if (function_exists('magic_quotes_gpc')) { + if (get_magic_quotes_gpc()) { + $this->startup_error .= 'magic_quotes_gpc must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_gpc(0) and set_magic_quotes_gpc(1).'."\n"; + } + } + + // Load support library + if (! include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) { + $this->startup_error .= 'getid3.lib.php is missing or corrupt'."\n"; + } + + if ($this->option_max_2gb_check === null) { + $this->option_max_2gb_check = (PHP_INT_MAX <= 2147483647); + } + + // Needed for Windows only: + // Define locations of helper applications for Shorten, VorbisComment, MetaFLAC + // as well as other helper functions such as head, tail, md5sum, etc + // This path cannot contain spaces, but the below code will attempt to get the + // 8.3-equivalent path automatically + // IMPORTANT: This path must include the trailing slash + if (GETID3_OS_ISWINDOWS && ! defined('GETID3_HELPERAPPSDIR')) { + $helperappsdir = GETID3_INCLUDEPATH.'..'.DIRECTORY_SEPARATOR.'helperapps'; // must not have any space in this path + + if (! is_dir($helperappsdir)) { + $this->startup_warning .= '"'.$helperappsdir.'" cannot be defined as GETID3_HELPERAPPSDIR because it does not exist'."\n"; + } elseif (strpos(realpath($helperappsdir), ' ') !== false) { + $DirPieces = explode(DIRECTORY_SEPARATOR, realpath($helperappsdir)); + $path_so_far = []; + foreach ($DirPieces as $key => $value) { + if (strpos($value, ' ') !== false) { + if (! empty($path_so_far)) { + $commandline = 'dir /x '.escapeshellarg(implode(DIRECTORY_SEPARATOR, $path_so_far)); + $dir_listing = `$commandline`; + $lines = explode("\n", $dir_listing); + foreach ($lines as $line) { + $line = trim($line); + if (preg_match('#^([0-9/]{10}) +([0-9:]{4,5}( [AP]M)?) +(|[0-9,]+) +([^ ]{0,11}) +(.+)$#', $line, $matches)) { + list($dummy, $date, $time, $ampm, $filesize, $shortname, $filename) = $matches; + if ((strtoupper($filesize) == '') && (strtolower($filename) == strtolower($value))) { + $value = $shortname; + } + } + } + } else { + $this->startup_warning .= 'GETID3_HELPERAPPSDIR must not have any spaces in it - use 8dot3 naming convention if neccesary. You can run "dir /x" from the commandline to see the correct 8.3-style names.'."\n"; + } + } + $path_so_far[] = $value; + } + $helperappsdir = implode(DIRECTORY_SEPARATOR, $path_so_far); + } + define('GETID3_HELPERAPPSDIR', $helperappsdir.DIRECTORY_SEPARATOR); + } + + if (! empty($this->startup_error)) { + echo $this->startup_error; + throw new getid3_exception($this->startup_error); + } + + return true; + } + + public function version() + { + return self::VERSION; + } + + public function fread_buffer_size() + { + return $this->option_fread_buffer_size; + } + + // public: setOption + public function setOption($optArray) + { + if (! is_array($optArray) || empty($optArray)) { + return false; + } + foreach ($optArray as $opt => $val) { + if (isset($this->$opt) === false) { + continue; + } + $this->$opt = $val; + } + + return true; + } + + public function openfile($filename, $filesize = null) + { + try { + if (! empty($this->startup_error)) { + throw new getid3_exception($this->startup_error); + } + if (! empty($this->startup_warning)) { + foreach (explode("\n", $this->startup_warning) as $startup_warning) { + $this->warning($startup_warning); + } + } + + // init result array and set parameters + $this->filename = $filename; + $this->info = []; + $this->info['GETID3_VERSION'] = $this->version(); + $this->info['php_memory_limit'] = (($this->memory_limit > 0) ? $this->memory_limit : false); + + // remote files not supported + if (preg_match('#^(ht|f)tp://#', $filename)) { + throw new getid3_exception('Remote files are not supported - please copy the file locally first'); + } + + $filename = str_replace('/', DIRECTORY_SEPARATOR, $filename); + $filename = preg_replace('#(.+)'.preg_quote(DIRECTORY_SEPARATOR).'{2,}#U', '\1'.DIRECTORY_SEPARATOR, $filename); + + // open local file + //if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) { // see http://www.getid3.org/phpBB3/viewtopic.php?t=1720 + if ((is_readable($filename) || file_exists($filename)) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) { + // great + } else { + $errormessagelist = []; + if (! is_readable($filename)) { + $errormessagelist[] = '!is_readable'; + } + if (! is_file($filename)) { + $errormessagelist[] = '!is_file'; + } + if (! file_exists($filename)) { + $errormessagelist[] = '!file_exists'; + } + if (empty($errormessagelist)) { + $errormessagelist[] = 'fopen failed'; + } + throw new getid3_exception('Could not open "'.$filename.'" ('.implode('; ', $errormessagelist).')'); + } + + $this->info['filesize'] = (! is_null($filesize) ? $filesize : filesize($filename)); + // set redundant parameters - might be needed in some include file + // filenames / filepaths in getID3 are always expressed with forward slashes (unix-style) for both Windows and other to try and minimize confusion + $filename = str_replace('\\', '/', $filename); + $this->info['filepath'] = str_replace('\\', '/', realpath(dirname($filename))); + $this->info['filename'] = getid3_lib::mb_basename($filename); + $this->info['filenamepath'] = $this->info['filepath'].'/'.$this->info['filename']; + + // set more parameters + $this->info['avdataoffset'] = 0; + $this->info['avdataend'] = $this->info['filesize']; + $this->info['fileformat'] = ''; // filled in later + $this->info['audio']['dataformat'] = ''; // filled in later, unset if not used + $this->info['video']['dataformat'] = ''; // filled in later, unset if not used + $this->info['tags'] = []; // filled in later, unset if not used + $this->info['error'] = []; // filled in later, unset if not used + $this->info['warning'] = []; // filled in later, unset if not used + $this->info['comments'] = []; // filled in later, unset if not used + $this->info['encoding'] = $this->encoding; // required by id3v2 and iso modules - can be unset at the end if desired + + // option_max_2gb_check + if ($this->option_max_2gb_check) { + // PHP (32-bit all, and 64-bit Windows) doesn't support integers larger than 2^31 (~2GB) + // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize + // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer + $fseek = fseek($this->fp, 0, SEEK_END); + if (($fseek < 0) || (($this->info['filesize'] != 0) && (ftell($this->fp) == 0)) || + ($this->info['filesize'] < 0) || + (ftell($this->fp) < 0)) { + $real_filesize = getid3_lib::getFileSizeSyscall($this->info['filenamepath']); + + if ($real_filesize === false) { + unset($this->info['filesize']); + fclose($this->fp); + throw new getid3_exception('Unable to determine actual filesize. File is most likely larger than '.round(PHP_INT_MAX / 1073741824).'GB and is not supported by PHP.'); + } elseif (getid3_lib::intValueSupported($real_filesize)) { + unset($this->info['filesize']); + fclose($this->fp); + throw new getid3_exception('PHP seems to think the file is larger than '.round(PHP_INT_MAX / 1073741824).'GB, but filesystem reports it as '.number_format($real_filesize, 3).'GB, please report to info@getid3.org'); + } + $this->info['filesize'] = $real_filesize; + $this->warning('File is larger than '.round(PHP_INT_MAX / 1073741824).'GB (filesystem reports it as '.number_format($real_filesize, 3).'GB) and is not properly supported by PHP.'); + } + } + + return true; + } catch (Exception $e) { + $this->error($e->getMessage()); + } + + return false; + } + + // public: analyze file + public function analyze($filename, $filesize = null, $original_filename = '') + { + try { + if (! $this->openfile($filename, $filesize)) { + return $this->info; + } + + // Handle tags + foreach (['id3v2'=>'id3v2', 'id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3'] as $tag_name => $tag_key) { + $option_tag = 'option_tag_'.$tag_name; + if ($this->$option_tag) { + $this->include_module('tag.'.$tag_name); + try { + $tag_class = 'getid3_'.$tag_name; + $tag = new $tag_class($this); + $tag->Analyze(); + } catch (getid3_exception $e) { + throw $e; + } + } + } + if (isset($this->info['id3v2']['tag_offset_start'])) { + $this->info['avdataoffset'] = max($this->info['avdataoffset'], $this->info['id3v2']['tag_offset_end']); + } + foreach (['id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3'] as $tag_name => $tag_key) { + if (isset($this->info[$tag_key]['tag_offset_start'])) { + $this->info['avdataend'] = min($this->info['avdataend'], $this->info[$tag_key]['tag_offset_start']); + } + } + + // ID3v2 detection (NOT parsing), even if ($this->option_tag_id3v2 == false) done to make fileformat easier + if (! $this->option_tag_id3v2) { + fseek($this->fp, 0); + $header = fread($this->fp, 10); + if ((substr($header, 0, 3) == 'ID3') && (strlen($header) == 10)) { + $this->info['id3v2']['header'] = true; + $this->info['id3v2']['majorversion'] = ord($header[3]); + $this->info['id3v2']['minorversion'] = ord($header[4]); + $this->info['avdataoffset'] += getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length + } + } + + // read 32 kb file data + fseek($this->fp, $this->info['avdataoffset']); + $formattest = fread($this->fp, 32774); + + // determine format + $determined_format = $this->GetFileFormat($formattest, ($original_filename ? $original_filename : $filename)); + + // unable to determine file format + if (! $determined_format) { + fclose($this->fp); + + return $this->error('unable to determine file format'); + } + + // check for illegal ID3 tags + if (isset($determined_format['fail_id3']) && (in_array('id3v1', $this->info['tags']) || in_array('id3v2', $this->info['tags']))) { + if ($determined_format['fail_id3'] === 'ERROR') { + fclose($this->fp); + + return $this->error('ID3 tags not allowed on this file type.'); + } elseif ($determined_format['fail_id3'] === 'WARNING') { + $this->warning('ID3 tags not allowed on this file type.'); + } + } + + // check for illegal APE tags + if (isset($determined_format['fail_ape']) && in_array('ape', $this->info['tags'])) { + if ($determined_format['fail_ape'] === 'ERROR') { + fclose($this->fp); + + return $this->error('APE tags not allowed on this file type.'); + } elseif ($determined_format['fail_ape'] === 'WARNING') { + $this->warning('APE tags not allowed on this file type.'); + } + } + + // set mime type + $this->info['mime_type'] = $determined_format['mime_type']; + + // supported format signature pattern detected, but module deleted + if (! file_exists(GETID3_INCLUDEPATH.$determined_format['include'])) { + fclose($this->fp); + + return $this->error('Format not supported, module "'.$determined_format['include'].'" was removed.'); + } + + // module requires mb_convert_encoding/iconv support + // Check encoding/iconv support + if (! empty($determined_format['iconv_req']) && ! function_exists('mb_convert_encoding') && ! function_exists('iconv') && ! in_array($this->encoding, ['ISO-8859-1', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'UTF-16'])) { + $errormessage = 'mb_convert_encoding() or iconv() support is required for this module ('.$determined_format['include'].') for encodings other than ISO-8859-1, UTF-8, UTF-16LE, UTF16-BE, UTF-16. '; + if (GETID3_OS_ISWINDOWS) { + $errormessage .= 'PHP does not have mb_convert_encoding() or iconv() support. Please enable php_mbstring.dll / php_iconv.dll in php.ini, and copy php_mbstring.dll / iconv.dll from c:/php/dlls to c:/windows/system32'; + } else { + $errormessage .= 'PHP is not compiled with mb_convert_encoding() or iconv() support. Please recompile with the --enable-mbstring / --with-iconv switch'; + } + + return $this->error($errormessage); + } + + // include module + include_once GETID3_INCLUDEPATH.$determined_format['include']; + + // instantiate module class + $class_name = 'getid3_'.$determined_format['module']; + if (! class_exists($class_name)) { + return $this->error('Format not supported, module "'.$determined_format['include'].'" is corrupt.'); + } + $class = new $class_name($this); + $class->Analyze(); + unset($class); + + // close file + fclose($this->fp); + + // process all tags - copy to 'tags' and convert charsets + if ($this->option_tags_process) { + $this->HandleAllTags(); + } + + // perform more calculations + if ($this->option_extra_info) { + $this->ChannelsBitratePlaytimeCalculations(); + $this->CalculateCompressionRatioVideo(); + $this->CalculateCompressionRatioAudio(); + $this->CalculateReplayGain(); + $this->ProcessAudioStreams(); + } + + // get the MD5 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags + if ($this->option_md5_data) { + // do not calc md5_data if md5_data_source is present - set by flac only - future MPC/SV8 too + if (! $this->option_md5_data_source || empty($this->info['md5_data_source'])) { + $this->getHashdata('md5'); + } + } + + // get the SHA1 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags + if ($this->option_sha1_data) { + $this->getHashdata('sha1'); + } + + // remove undesired keys + $this->CleanUp(); + } catch (Exception $e) { + $this->error('Caught exception: '.$e->getMessage()); + } + + // return info array + return $this->info; + } + + // private: error handling + public function error($message) + { + $this->CleanUp(); + if (! isset($this->info['error'])) { + $this->info['error'] = []; + } + $this->info['error'][] = $message; + + return $this->info; + } + + // private: warning handling + public function warning($message) + { + $this->info['warning'][] = $message; + + return true; + } + + // private: CleanUp + private function CleanUp() + { + + // remove possible empty keys + $AVpossibleEmptyKeys = ['dataformat', 'bits_per_sample', 'encoder_options', 'streams', 'bitrate']; + foreach ($AVpossibleEmptyKeys as $dummy => $key) { + if (empty($this->info['audio'][$key]) && isset($this->info['audio'][$key])) { + unset($this->info['audio'][$key]); + } + if (empty($this->info['video'][$key]) && isset($this->info['video'][$key])) { + unset($this->info['video'][$key]); + } + } + + // remove empty root keys + if (! empty($this->info)) { + foreach ($this->info as $key => $value) { + if (empty($this->info[$key]) && ($this->info[$key] !== 0) && ($this->info[$key] !== '0')) { + unset($this->info[$key]); + } + } + } + + // remove meaningless entries from unknown-format files + if (empty($this->info['fileformat'])) { + if (isset($this->info['avdataoffset'])) { + unset($this->info['avdataoffset']); + } + if (isset($this->info['avdataend'])) { + unset($this->info['avdataend']); + } + } + + // remove possible duplicated identical entries + if (! empty($this->info['error'])) { + $this->info['error'] = array_values(array_unique($this->info['error'])); + } + if (! empty($this->info['warning'])) { + $this->info['warning'] = array_values(array_unique($this->info['warning'])); + } + + // remove "global variable" type keys + unset($this->info['php_memory_limit']); + + return true; + } + + // return array containing information about all supported formats + public function GetFileFormatArray() + { + static $format_info = []; + if (empty($format_info)) { + $format_info = [ + + // Audio formats + + // AC-3 - audio - Dolby AC-3 / Dolby Digital + 'ac3' => [ + 'pattern' => '^\\x0B\\x77', + 'group' => 'audio', + 'module' => 'ac3', + 'mime_type' => 'audio/ac3', + ], + + // AAC - audio - Advanced Audio Coding (AAC) - ADIF format + 'adif' => [ + 'pattern' => '^ADIF', + 'group' => 'audio', + 'module' => 'aac', + 'mime_type' => 'application/octet-stream', + 'fail_ape' => 'WARNING', + ], /* - // AA - audio - Audible Audiobook - 'aa' => array( - 'pattern' => '^.{4}\\x57\\x90\\x75\\x36', - 'group' => 'audio', - 'module' => 'aa', - 'mime_type' => 'audio/audible', - ), + // AA - audio - Audible Audiobook + 'aa' => array( + 'pattern' => '^.{4}\\x57\\x90\\x75\\x36', + 'group' => 'audio', + 'module' => 'aa', + 'mime_type' => 'audio/audible', + ), */ - // AAC - audio - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3) - 'adts' => array( - 'pattern' => '^\\xFF[\\xF0-\\xF1\\xF8-\\xF9]', - 'group' => 'audio', - 'module' => 'aac', - 'mime_type' => 'application/octet-stream', - 'fail_ape' => 'WARNING', - ), + // AAC - audio - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3) + 'adts' => [ + 'pattern' => '^\\xFF[\\xF0-\\xF1\\xF8-\\xF9]', + 'group' => 'audio', + 'module' => 'aac', + 'mime_type' => 'application/octet-stream', + 'fail_ape' => 'WARNING', + ], + // AU - audio - NeXT/Sun AUdio (AU) + 'au' => [ + 'pattern' => '^\\.snd', + 'group' => 'audio', + 'module' => 'au', + 'mime_type' => 'audio/basic', + ], - // AU - audio - NeXT/Sun AUdio (AU) - 'au' => array( - 'pattern' => '^\\.snd', - 'group' => 'audio', - 'module' => 'au', - 'mime_type' => 'audio/basic', - ), + // AMR - audio - Adaptive Multi Rate + 'amr' => [ + 'pattern' => '^\\x23\\x21AMR\\x0A', // #!AMR[0A] + 'group' => 'audio', + 'module' => 'amr', + 'mime_type' => 'audio/amr', + ], - // AMR - audio - Adaptive Multi Rate - 'amr' => array( - 'pattern' => '^\\x23\\x21AMR\\x0A', // #!AMR[0A] - 'group' => 'audio', - 'module' => 'amr', - 'mime_type' => 'audio/amr', - ), + // AVR - audio - Audio Visual Research + 'avr' => [ + 'pattern' => '^2BIT', + 'group' => 'audio', + 'module' => 'avr', + 'mime_type' => 'application/octet-stream', + ], - // AVR - audio - Audio Visual Research - 'avr' => array( - 'pattern' => '^2BIT', - 'group' => 'audio', - 'module' => 'avr', - 'mime_type' => 'application/octet-stream', - ), + // BONK - audio - Bonk v0.9+ + 'bonk' => [ + 'pattern' => '^\\x00(BONK|INFO|META| ID3)', + 'group' => 'audio', + 'module' => 'bonk', + 'mime_type' => 'audio/xmms-bonk', + ], - // BONK - audio - Bonk v0.9+ - 'bonk' => array( - 'pattern' => '^\\x00(BONK|INFO|META| ID3)', - 'group' => 'audio', - 'module' => 'bonk', - 'mime_type' => 'audio/xmms-bonk', - ), + // DSF - audio - Direct Stream Digital (DSD) Storage Facility files (DSF) - https://en.wikipedia.org/wiki/Direct_Stream_Digital + 'dsf' => [ + 'pattern' => '^DSD ', // including trailing space: 44 53 44 20 + 'group' => 'audio', + 'module' => 'dsf', + 'mime_type' => 'audio/dsd', + ], - // DSF - audio - Direct Stream Digital (DSD) Storage Facility files (DSF) - https://en.wikipedia.org/wiki/Direct_Stream_Digital - 'dsf' => array( - 'pattern' => '^DSD ', // including trailing space: 44 53 44 20 - 'group' => 'audio', - 'module' => 'dsf', - 'mime_type' => 'audio/dsd', - ), + // DSS - audio - Digital Speech Standard + 'dss' => [ + 'pattern' => '^[\\x02-\\x06]ds[s2]', + 'group' => 'audio', + 'module' => 'dss', + 'mime_type' => 'application/octet-stream', + ], - // DSS - audio - Digital Speech Standard - 'dss' => array( - 'pattern' => '^[\\x02-\\x06]ds[s2]', - 'group' => 'audio', - 'module' => 'dss', - 'mime_type' => 'application/octet-stream', - ), + // DTS - audio - Dolby Theatre System + 'dts' => [ + 'pattern' => '^\\x7F\\xFE\\x80\\x01', + 'group' => 'audio', + 'module' => 'dts', + 'mime_type' => 'audio/dts', + ], - // DTS - audio - Dolby Theatre System - 'dts' => array( - 'pattern' => '^\\x7F\\xFE\\x80\\x01', - 'group' => 'audio', - 'module' => 'dts', - 'mime_type' => 'audio/dts', - ), + // FLAC - audio - Free Lossless Audio Codec + 'flac' => [ + 'pattern' => '^fLaC', + 'group' => 'audio', + 'module' => 'flac', + 'mime_type' => 'audio/x-flac', + ], - // FLAC - audio - Free Lossless Audio Codec - 'flac' => array( - 'pattern' => '^fLaC', - 'group' => 'audio', - 'module' => 'flac', - 'mime_type' => 'audio/x-flac', - ), + // LA - audio - Lossless Audio (LA) + 'la' => [ + 'pattern' => '^LA0[2-4]', + 'group' => 'audio', + 'module' => 'la', + 'mime_type' => 'application/octet-stream', + ], - // LA - audio - Lossless Audio (LA) - 'la' => array( - 'pattern' => '^LA0[2-4]', - 'group' => 'audio', - 'module' => 'la', - 'mime_type' => 'application/octet-stream', - ), + // LPAC - audio - Lossless Predictive Audio Compression (LPAC) + 'lpac' => [ + 'pattern' => '^LPAC', + 'group' => 'audio', + 'module' => 'lpac', + 'mime_type' => 'application/octet-stream', + ], - // LPAC - audio - Lossless Predictive Audio Compression (LPAC) - 'lpac' => array( - 'pattern' => '^LPAC', - 'group' => 'audio', - 'module' => 'lpac', - 'mime_type' => 'application/octet-stream', - ), + // MIDI - audio - MIDI (Musical Instrument Digital Interface) + 'midi' => [ + 'pattern' => '^MThd', + 'group' => 'audio', + 'module' => 'midi', + 'mime_type' => 'audio/midi', + ], - // MIDI - audio - MIDI (Musical Instrument Digital Interface) - 'midi' => array( - 'pattern' => '^MThd', - 'group' => 'audio', - 'module' => 'midi', - 'mime_type' => 'audio/midi', - ), - - // MAC - audio - Monkey's Audio Compressor - 'mac' => array( - 'pattern' => '^MAC ', - 'group' => 'audio', - 'module' => 'monkey', - 'mime_type' => 'application/octet-stream', - ), + // MAC - audio - Monkey's Audio Compressor + 'mac' => [ + 'pattern' => '^MAC ', + 'group' => 'audio', + 'module' => 'monkey', + 'mime_type' => 'application/octet-stream', + ], // has been known to produce false matches in random files (e.g. JPEGs), leave out until more precise matching available // // MOD - audio - MODule (assorted sub-formats) @@ -720,1121 +728,1112 @@ class getID3 // 'mime_type' => 'audio/mod', // ), - // MOD - audio - MODule (Impulse Tracker) - 'it' => array( - 'pattern' => '^IMPM', - 'group' => 'audio', - 'module' => 'mod', - //'option' => 'it', - 'mime_type' => 'audio/it', - ), - - // MOD - audio - MODule (eXtended Module, various sub-formats) - 'xm' => array( - 'pattern' => '^Extended Module', - 'group' => 'audio', - 'module' => 'mod', - //'option' => 'xm', - 'mime_type' => 'audio/xm', - ), - - // MOD - audio - MODule (ScreamTracker) - 's3m' => array( - 'pattern' => '^.{44}SCRM', - 'group' => 'audio', - 'module' => 'mod', - //'option' => 's3m', - 'mime_type' => 'audio/s3m', - ), - - // MPC - audio - Musepack / MPEGplus - 'mpc' => array( - 'pattern' => '^(MPCK|MP\\+|[\\x00\\x01\\x10\\x11\\x40\\x41\\x50\\x51\\x80\\x81\\x90\\x91\\xC0\\xC1\\xD0\\xD1][\\x20-\\x37][\\x00\\x20\\x40\\x60\\x80\\xA0\\xC0\\xE0])', - 'group' => 'audio', - 'module' => 'mpc', - 'mime_type' => 'audio/x-musepack', - ), - - // MP3 - audio - MPEG-audio Layer 3 (very similar to AAC-ADTS) - 'mp3' => array( - 'pattern' => '^\\xFF[\\xE2-\\xE7\\xF2-\\xF7\\xFA-\\xFF][\\x00-\\x0B\\x10-\\x1B\\x20-\\x2B\\x30-\\x3B\\x40-\\x4B\\x50-\\x5B\\x60-\\x6B\\x70-\\x7B\\x80-\\x8B\\x90-\\x9B\\xA0-\\xAB\\xB0-\\xBB\\xC0-\\xCB\\xD0-\\xDB\\xE0-\\xEB\\xF0-\\xFB]', - 'group' => 'audio', - 'module' => 'mp3', - 'mime_type' => 'audio/mpeg', - ), - - // OFR - audio - OptimFROG - 'ofr' => array( - 'pattern' => '^(\\*RIFF|OFR)', - 'group' => 'audio', - 'module' => 'optimfrog', - 'mime_type' => 'application/octet-stream', - ), - - // RKAU - audio - RKive AUdio compressor - 'rkau' => array( - 'pattern' => '^RKA', - 'group' => 'audio', - 'module' => 'rkau', - 'mime_type' => 'application/octet-stream', - ), - - // SHN - audio - Shorten - 'shn' => array( - 'pattern' => '^ajkg', - 'group' => 'audio', - 'module' => 'shorten', - 'mime_type' => 'audio/xmms-shn', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // TTA - audio - TTA Lossless Audio Compressor (http://tta.corecodec.org) - 'tta' => array( - 'pattern' => '^TTA', // could also be '^TTA(\\x01|\\x02|\\x03|2|1)' - 'group' => 'audio', - 'module' => 'tta', - 'mime_type' => 'application/octet-stream', - ), - - // VOC - audio - Creative Voice (VOC) - 'voc' => array( - 'pattern' => '^Creative Voice File', - 'group' => 'audio', - 'module' => 'voc', - 'mime_type' => 'audio/voc', - ), - - // VQF - audio - transform-domain weighted interleave Vector Quantization Format (VQF) - 'vqf' => array( - 'pattern' => '^TWIN', - 'group' => 'audio', - 'module' => 'vqf', - 'mime_type' => 'application/octet-stream', - ), - - // WV - audio - WavPack (v4.0+) - 'wv' => array( - 'pattern' => '^wvpk', - 'group' => 'audio', - 'module' => 'wavpack', - 'mime_type' => 'application/octet-stream', - ), - - - // Audio-Video formats - - // ASF - audio/video - Advanced Streaming Format, Windows Media Video, Windows Media Audio - 'asf' => array( - 'pattern' => '^\\x30\\x26\\xB2\\x75\\x8E\\x66\\xCF\\x11\\xA6\\xD9\\x00\\xAA\\x00\\x62\\xCE\\x6C', - 'group' => 'audio-video', - 'module' => 'asf', - 'mime_type' => 'video/x-ms-asf', - 'iconv_req' => false, - ), - - // BINK - audio/video - Bink / Smacker - 'bink' => array( - 'pattern' => '^(BIK|SMK)', - 'group' => 'audio-video', - 'module' => 'bink', - 'mime_type' => 'application/octet-stream', - ), - - // FLV - audio/video - FLash Video - 'flv' => array( - 'pattern' => '^FLV[\\x01]', - 'group' => 'audio-video', - 'module' => 'flv', - 'mime_type' => 'video/x-flv', - ), - - // MKAV - audio/video - Mastroka - 'matroska' => array( - 'pattern' => '^\\x1A\\x45\\xDF\\xA3', - 'group' => 'audio-video', - 'module' => 'matroska', - 'mime_type' => 'video/x-matroska', // may also be audio/x-matroska - ), - - // MPEG - audio/video - MPEG (Moving Pictures Experts Group) - 'mpeg' => array( - 'pattern' => '^\\x00\\x00\\x01[\\xB3\\xBA]', - 'group' => 'audio-video', - 'module' => 'mpeg', - 'mime_type' => 'video/mpeg', - ), - - // NSV - audio/video - Nullsoft Streaming Video (NSV) - 'nsv' => array( - 'pattern' => '^NSV[sf]', - 'group' => 'audio-video', - 'module' => 'nsv', - 'mime_type' => 'application/octet-stream', - ), - - // Ogg - audio/video - Ogg (Ogg-Vorbis, Ogg-FLAC, Speex, Ogg-Theora(*), Ogg-Tarkin(*)) - 'ogg' => array( - 'pattern' => '^OggS', - 'group' => 'audio', - 'module' => 'ogg', - 'mime_type' => 'application/ogg', - 'fail_id3' => 'WARNING', - 'fail_ape' => 'WARNING', - ), - - // QT - audio/video - Quicktime - 'quicktime' => array( - 'pattern' => '^.{4}(cmov|free|ftyp|mdat|moov|pnot|skip|wide)', - 'group' => 'audio-video', - 'module' => 'quicktime', - 'mime_type' => 'video/quicktime', - ), - - // RIFF - audio/video - Resource Interchange File Format (RIFF) / WAV / AVI / CD-audio / SDSS = renamed variant used by SmartSound QuickTracks (www.smartsound.com) / FORM = Audio Interchange File Format (AIFF) - 'riff' => array( - 'pattern' => '^(RIFF|SDSS|FORM)', - 'group' => 'audio-video', - 'module' => 'riff', - 'mime_type' => 'audio/x-wav', - 'fail_ape' => 'WARNING', - ), - - // Real - audio/video - RealAudio, RealVideo - 'real' => array( - 'pattern' => '^\\.(RMF|ra)', - 'group' => 'audio-video', - 'module' => 'real', - 'mime_type' => 'audio/x-realaudio', - ), - - // SWF - audio/video - ShockWave Flash - 'swf' => array( - 'pattern' => '^(F|C)WS', - 'group' => 'audio-video', - 'module' => 'swf', - 'mime_type' => 'application/x-shockwave-flash', - ), - - // TS - audio/video - MPEG-2 Transport Stream - 'ts' => array( - 'pattern' => '^(\\x47.{187}){10,}', // packets are 188 bytes long and start with 0x47 "G". Check for at least 10 packets matching this pattern - 'group' => 'audio-video', - 'module' => 'ts', - 'mime_type' => 'video/MP2T', - ), - - - // Still-Image formats - - // BMP - still image - Bitmap (Windows, OS/2; uncompressed, RLE8, RLE4) - 'bmp' => array( - 'pattern' => '^BM', - 'group' => 'graphic', - 'module' => 'bmp', - 'mime_type' => 'image/bmp', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // GIF - still image - Graphics Interchange Format - 'gif' => array( - 'pattern' => '^GIF', - 'group' => 'graphic', - 'module' => 'gif', - 'mime_type' => 'image/gif', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // JPEG - still image - Joint Photographic Experts Group (JPEG) - 'jpg' => array( - 'pattern' => '^\\xFF\\xD8\\xFF', - 'group' => 'graphic', - 'module' => 'jpg', - 'mime_type' => 'image/jpeg', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // PCD - still image - Kodak Photo CD - 'pcd' => array( - 'pattern' => '^.{2048}PCD_IPI\\x00', - 'group' => 'graphic', - 'module' => 'pcd', - 'mime_type' => 'image/x-photo-cd', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - - // PNG - still image - Portable Network Graphics (PNG) - 'png' => array( - 'pattern' => '^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A', - 'group' => 'graphic', - 'module' => 'png', - 'mime_type' => 'image/png', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - - // SVG - still image - Scalable Vector Graphics (SVG) - 'svg' => array( - 'pattern' => '( 'graphic', - 'module' => 'svg', - 'mime_type' => 'image/svg+xml', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - - // TIFF - still image - Tagged Information File Format (TIFF) - 'tiff' => array( - 'pattern' => '^(II\\x2A\\x00|MM\\x00\\x2A)', - 'group' => 'graphic', - 'module' => 'tiff', - 'mime_type' => 'image/tiff', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - - // EFAX - still image - eFax (TIFF derivative) - 'efax' => array( - 'pattern' => '^\\xDC\\xFE', - 'group' => 'graphic', - 'module' => 'efax', - 'mime_type' => 'image/efax', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - - // Data formats - - // ISO - data - International Standards Organization (ISO) CD-ROM Image - 'iso' => array( - 'pattern' => '^.{32769}CD001', - 'group' => 'misc', - 'module' => 'iso', - 'mime_type' => 'application/octet-stream', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - 'iconv_req' => false, - ), - - // RAR - data - RAR compressed data - 'rar' => array( - 'pattern' => '^Rar\\!', - 'group' => 'archive', - 'module' => 'rar', - 'mime_type' => 'application/octet-stream', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // SZIP - audio/data - SZIP compressed data - 'szip' => array( - 'pattern' => '^SZ\\x0A\\x04', - 'group' => 'archive', - 'module' => 'szip', - 'mime_type' => 'application/octet-stream', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // TAR - data - TAR compressed data - 'tar' => array( - 'pattern' => '^.{100}[0-9\\x20]{7}\\x00[0-9\\x20]{7}\\x00[0-9\\x20]{7}\\x00[0-9\\x20\\x00]{12}[0-9\\x20\\x00]{12}', - 'group' => 'archive', - 'module' => 'tar', - 'mime_type' => 'application/x-tar', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // GZIP - data - GZIP compressed data - 'gz' => array( - 'pattern' => '^\\x1F\\x8B\\x08', - 'group' => 'archive', - 'module' => 'gzip', - 'mime_type' => 'application/x-gzip', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // ZIP - data - ZIP compressed data - 'zip' => array( - 'pattern' => '^PK\\x03\\x04', - 'group' => 'archive', - 'module' => 'zip', - 'mime_type' => 'application/zip', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - - // Misc other formats - - // PAR2 - data - Parity Volume Set Specification 2.0 - 'par2' => array ( - 'pattern' => '^PAR2\\x00PKT', - 'group' => 'misc', - 'module' => 'par2', - 'mime_type' => 'application/octet-stream', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // PDF - data - Portable Document Format - 'pdf' => array( - 'pattern' => '^\\x25PDF', - 'group' => 'misc', - 'module' => 'pdf', - 'mime_type' => 'application/pdf', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // MSOFFICE - data - ZIP compressed data - 'msoffice' => array( - 'pattern' => '^\\xD0\\xCF\\x11\\xE0\\xA1\\xB1\\x1A\\xE1', // D0CF11E == DOCFILE == Microsoft Office Document - 'group' => 'misc', - 'module' => 'msoffice', - 'mime_type' => 'application/octet-stream', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // CUE - data - CUEsheet (index to single-file disc images) - 'cue' => array( - 'pattern' => '', // empty pattern means cannot be automatically detected, will fall through all other formats and match based on filename and very basic file contents - 'group' => 'misc', - 'module' => 'cue', - 'mime_type' => 'application/octet-stream', - ), - - ); - } - - return $format_info; - } - - - - public function GetFileFormat(&$filedata, $filename='') { - // this function will determine the format of a file based on usually - // the first 2-4 bytes of the file (8 bytes for PNG, 16 bytes for JPG, - // and in the case of ISO CD image, 6 bytes offset 32kb from the start - // of the file). - - // Identify file format - loop through $format_info and detect with reg expr - foreach ($this->GetFileFormatArray() as $format_name => $info) { - // The /s switch on preg_match() forces preg_match() NOT to treat - // newline (0x0A) characters as special chars but do a binary match - if (!empty($info['pattern']) && preg_match('#'.$info['pattern'].'#s', $filedata)) { - $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php'; - return $info; - } - } - - - if (preg_match('#\\.mp[123a]$#i', $filename)) { - // Too many mp3 encoders on the market put gabage in front of mpeg files - // use assume format on these if format detection failed - $GetFileFormatArray = $this->GetFileFormatArray(); - $info = $GetFileFormatArray['mp3']; - $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php'; - return $info; - } elseif (preg_match('#\\.cue$#i', $filename) && preg_match('#FILE "[^"]+" (BINARY|MOTOROLA|AIFF|WAVE|MP3)#', $filedata)) { - // there's not really a useful consistent "magic" at the beginning of .cue files to identify them - // so until I think of something better, just go by filename if all other format checks fail - // and verify there's at least one instance of "TRACK xx AUDIO" in the file - $GetFileFormatArray = $this->GetFileFormatArray(); - $info = $GetFileFormatArray['cue']; - $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php'; - return $info; - } - - return false; - } - - - // converts array to $encoding charset from $this->encoding - public function CharConvert(&$array, $encoding) { - - // identical encoding - end here - if ($encoding == $this->encoding) { - return; - } - - // loop thru array - foreach ($array as $key => $value) { - - // go recursive - if (is_array($value)) { - $this->CharConvert($array[$key], $encoding); - } - - // convert string - elseif (is_string($value)) { - $array[$key] = trim(getid3_lib::iconv_fallback($encoding, $this->encoding, $value)); - } - } - } - - - public function HandleAllTags() { - - // key name => array (tag name, character encoding) - static $tags; - if (empty($tags)) { - $tags = array( - 'asf' => array('asf' , 'UTF-16LE'), - 'midi' => array('midi' , 'ISO-8859-1'), - 'nsv' => array('nsv' , 'ISO-8859-1'), - 'ogg' => array('vorbiscomment' , 'UTF-8'), - 'png' => array('png' , 'UTF-8'), - 'tiff' => array('tiff' , 'ISO-8859-1'), - 'quicktime' => array('quicktime' , 'UTF-8'), - 'real' => array('real' , 'ISO-8859-1'), - 'vqf' => array('vqf' , 'ISO-8859-1'), - 'zip' => array('zip' , 'ISO-8859-1'), - 'riff' => array('riff' , 'ISO-8859-1'), - 'lyrics3' => array('lyrics3' , 'ISO-8859-1'), - 'id3v1' => array('id3v1' , $this->encoding_id3v1), - 'id3v2' => array('id3v2' , 'UTF-8'), // not according to the specs (every frame can have a different encoding), but getID3() force-converts all encodings to UTF-8 - 'ape' => array('ape' , 'UTF-8'), - 'cue' => array('cue' , 'ISO-8859-1'), - 'matroska' => array('matroska' , 'UTF-8'), - 'flac' => array('vorbiscomment' , 'UTF-8'), - 'divxtag' => array('divx' , 'ISO-8859-1'), - 'iptc' => array('iptc' , 'ISO-8859-1'), - ); - } - - // loop through comments array - foreach ($tags as $comment_name => $tagname_encoding_array) { - list($tag_name, $encoding) = $tagname_encoding_array; - - // fill in default encoding type if not already present - if (isset($this->info[$comment_name]) && !isset($this->info[$comment_name]['encoding'])) { - $this->info[$comment_name]['encoding'] = $encoding; - } - - // copy comments if key name set - if (!empty($this->info[$comment_name]['comments'])) { - foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) { - foreach ($valuearray as $key => $value) { - if (is_string($value)) { - $value = trim($value, " \r\n\t"); // do not trim nulls from $value!! Unicode characters will get mangled if trailing nulls are removed! - } - if ($value) { - if (!is_numeric($key)) { - $this->info['tags'][trim($tag_name)][trim($tag_key)][$key] = $value; - } else { - $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value; - } - } - } - if ($tag_key == 'picture') { - unset($this->info[$comment_name]['comments'][$tag_key]); - } - } - - if (!isset($this->info['tags'][$tag_name])) { - // comments are set but contain nothing but empty strings, so skip - continue; - } - - $this->CharConvert($this->info['tags'][$tag_name], $this->info[$comment_name]['encoding']); // only copy gets converted! - - if ($this->option_tags_html) { - foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) { - $this->info['tags_html'][$tag_name][$tag_key] = getid3_lib::recursiveMultiByteCharString2HTML($valuearray, $this->info[$comment_name]['encoding']); - } - } - - } - - } - - // pictures can take up a lot of space, and we don't need multiple copies of them - // let there be a single copy in [comments][picture], and not elsewhere - if (!empty($this->info['tags'])) { - $unset_keys = array('tags', 'tags_html'); - foreach ($this->info['tags'] as $tagtype => $tagarray) { - foreach ($tagarray as $tagname => $tagdata) { - if ($tagname == 'picture') { - foreach ($tagdata as $key => $tagarray) { - $this->info['comments']['picture'][] = $tagarray; - if (isset($tagarray['data']) && isset($tagarray['image_mime'])) { - if (isset($this->info['tags'][$tagtype][$tagname][$key])) { - unset($this->info['tags'][$tagtype][$tagname][$key]); - } - if (isset($this->info['tags_html'][$tagtype][$tagname][$key])) { - unset($this->info['tags_html'][$tagtype][$tagname][$key]); - } - } - } - } - } - foreach ($unset_keys as $unset_key) { - // remove possible empty keys from (e.g. [tags][id3v2][picture]) - if (empty($this->info[$unset_key][$tagtype]['picture'])) { - unset($this->info[$unset_key][$tagtype]['picture']); - } - if (empty($this->info[$unset_key][$tagtype])) { - unset($this->info[$unset_key][$tagtype]); - } - if (empty($this->info[$unset_key])) { - unset($this->info[$unset_key]); - } - } - // remove duplicate copy of picture data from (e.g. [id3v2][comments][picture]) - if (isset($this->info[$tagtype]['comments']['picture'])) { - unset($this->info[$tagtype]['comments']['picture']); - } - if (empty($this->info[$tagtype]['comments'])) { - unset($this->info[$tagtype]['comments']); - } - if (empty($this->info[$tagtype])) { - unset($this->info[$tagtype]); - } - } - } - return true; - } - - public function getHashdata($algorithm) { - switch ($algorithm) { - case 'md5': - case 'sha1': - break; - - default: - return $this->error('bad algorithm "'.$algorithm.'" in getHashdata()'); - break; - } - - if (!empty($this->info['fileformat']) && !empty($this->info['dataformat']) && ($this->info['fileformat'] == 'ogg') && ($this->info['audio']['dataformat'] == 'vorbis')) { - - // We cannot get an identical md5_data value for Ogg files where the comments - // span more than 1 Ogg page (compared to the same audio data with smaller - // comments) using the normal getID3() method of MD5'ing the data between the - // end of the comments and the end of the file (minus any trailing tags), - // because the page sequence numbers of the pages that the audio data is on - // do not match. Under normal circumstances, where comments are smaller than - // the nominal 4-8kB page size, then this is not a problem, but if there are - // very large comments, the only way around it is to strip off the comment - // tags with vorbiscomment and MD5 that file. - // This procedure must be applied to ALL Ogg files, not just the ones with - // comments larger than 1 page, because the below method simply MD5's the - // whole file with the comments stripped, not just the portion after the - // comments block (which is the standard getID3() method. - - // The above-mentioned problem of comments spanning multiple pages and changing - // page sequence numbers likely happens for OggSpeex and OggFLAC as well, but - // currently vorbiscomment only works on OggVorbis files. - - if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { - - $this->warning('Failed making system call to vorbiscomment.exe - '.$algorithm.'_data is incorrect - error returned: PHP running in Safe Mode (backtick operator not available)'); - $this->info[$algorithm.'_data'] = false; - - } else { - - // Prevent user from aborting script - $old_abort = ignore_user_abort(true); - - // Create empty file - $empty = tempnam(GETID3_TEMP_DIR, 'getID3'); - touch($empty); - - // Use vorbiscomment to make temp file without comments - $temp = tempnam(GETID3_TEMP_DIR, 'getID3'); - $file = $this->info['filenamepath']; - - if (GETID3_OS_ISWINDOWS) { - - if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) { - - $commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w -c "'.$empty.'" "'.$file.'" "'.$temp.'"'; - $VorbisCommentError = `$commandline`; - - } else { - - $VorbisCommentError = 'vorbiscomment.exe not found in '.GETID3_HELPERAPPSDIR; - - } - - } else { - - $commandline = 'vorbiscomment -w -c "'.$empty.'" "'.$file.'" "'.$temp.'" 2>&1'; - $commandline = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg($file).' '.escapeshellarg($temp).' 2>&1'; - $VorbisCommentError = `$commandline`; - - } - - if (!empty($VorbisCommentError)) { - - $this->warning('Failed making system call to vorbiscomment(.exe) - '.$algorithm.'_data will be incorrect. If vorbiscomment is unavailable, please download from http://www.vorbis.com/download.psp and put in the getID3() directory. Error returned: '.$VorbisCommentError); - $this->info[$algorithm.'_data'] = false; - - } else { - - // Get hash of newly created file - switch ($algorithm) { - case 'md5': - $this->info[$algorithm.'_data'] = md5_file($temp); - break; - - case 'sha1': - $this->info[$algorithm.'_data'] = sha1_file($temp); - break; - } - } - - // Clean up - unlink($empty); - unlink($temp); - - // Reset abort setting - ignore_user_abort($old_abort); - - } - - } else { - - if (!empty($this->info['avdataoffset']) || (isset($this->info['avdataend']) && ($this->info['avdataend'] < $this->info['filesize']))) { - - // get hash from part of file - $this->info[$algorithm.'_data'] = getid3_lib::hash_data($this->info['filenamepath'], $this->info['avdataoffset'], $this->info['avdataend'], $algorithm); - - } else { - - // get hash from whole file - switch ($algorithm) { - case 'md5': - $this->info[$algorithm.'_data'] = md5_file($this->info['filenamepath']); - break; - - case 'sha1': - $this->info[$algorithm.'_data'] = sha1_file($this->info['filenamepath']); - break; - } - } - - } - return true; - } - - - public function ChannelsBitratePlaytimeCalculations() { - - // set channelmode on audio - if (!empty($this->info['audio']['channelmode']) || !isset($this->info['audio']['channels'])) { - // ignore - } elseif ($this->info['audio']['channels'] == 1) { - $this->info['audio']['channelmode'] = 'mono'; - } elseif ($this->info['audio']['channels'] == 2) { - $this->info['audio']['channelmode'] = 'stereo'; - } - - // Calculate combined bitrate - audio + video - $CombinedBitrate = 0; - $CombinedBitrate += (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : 0); - $CombinedBitrate += (isset($this->info['video']['bitrate']) ? $this->info['video']['bitrate'] : 0); - if (($CombinedBitrate > 0) && empty($this->info['bitrate'])) { - $this->info['bitrate'] = $CombinedBitrate; - } - //if ((isset($this->info['video']) && !isset($this->info['video']['bitrate'])) || (isset($this->info['audio']) && !isset($this->info['audio']['bitrate']))) { - // // for example, VBR MPEG video files cannot determine video bitrate: - // // should not set overall bitrate and playtime from audio bitrate only - // unset($this->info['bitrate']); - //} - - // video bitrate undetermined, but calculable - if (isset($this->info['video']['dataformat']) && $this->info['video']['dataformat'] && (!isset($this->info['video']['bitrate']) || ($this->info['video']['bitrate'] == 0))) { - // if video bitrate not set - if (isset($this->info['audio']['bitrate']) && ($this->info['audio']['bitrate'] > 0) && ($this->info['audio']['bitrate'] == $this->info['bitrate'])) { - // AND if audio bitrate is set to same as overall bitrate - if (isset($this->info['playtime_seconds']) && ($this->info['playtime_seconds'] > 0)) { - // AND if playtime is set - if (isset($this->info['avdataend']) && isset($this->info['avdataoffset'])) { - // AND if AV data offset start/end is known - // THEN we can calculate the video bitrate - $this->info['bitrate'] = round((($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds']); - $this->info['video']['bitrate'] = $this->info['bitrate'] - $this->info['audio']['bitrate']; - } - } - } - } - - if ((!isset($this->info['playtime_seconds']) || ($this->info['playtime_seconds'] <= 0)) && !empty($this->info['bitrate'])) { - $this->info['playtime_seconds'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['bitrate']; - } - - if (!isset($this->info['bitrate']) && !empty($this->info['playtime_seconds'])) { - $this->info['bitrate'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds']; - } - if (isset($this->info['bitrate']) && empty($this->info['audio']['bitrate']) && empty($this->info['video']['bitrate'])) { - if (isset($this->info['audio']['dataformat']) && empty($this->info['video']['resolution_x'])) { - // audio only - $this->info['audio']['bitrate'] = $this->info['bitrate']; - } elseif (isset($this->info['video']['resolution_x']) && empty($this->info['audio']['dataformat'])) { - // video only - $this->info['video']['bitrate'] = $this->info['bitrate']; - } - } - - // Set playtime string - if (!empty($this->info['playtime_seconds']) && empty($this->info['playtime_string'])) { - $this->info['playtime_string'] = getid3_lib::PlaytimeString($this->info['playtime_seconds']); - } - } - - - public function CalculateCompressionRatioVideo() { - if (empty($this->info['video'])) { - return false; - } - if (empty($this->info['video']['resolution_x']) || empty($this->info['video']['resolution_y'])) { - return false; - } - if (empty($this->info['video']['bits_per_sample'])) { - return false; - } - - switch ($this->info['video']['dataformat']) { - case 'bmp': - case 'gif': - case 'jpeg': - case 'jpg': - case 'png': - case 'tiff': - $FrameRate = 1; - $PlaytimeSeconds = 1; - $BitrateCompressed = $this->info['filesize'] * 8; - break; - - default: - if (!empty($this->info['video']['frame_rate'])) { - $FrameRate = $this->info['video']['frame_rate']; - } else { - return false; - } - if (!empty($this->info['playtime_seconds'])) { - $PlaytimeSeconds = $this->info['playtime_seconds']; - } else { - return false; - } - if (!empty($this->info['video']['bitrate'])) { - $BitrateCompressed = $this->info['video']['bitrate']; - } else { - return false; - } - break; - } - $BitrateUncompressed = $this->info['video']['resolution_x'] * $this->info['video']['resolution_y'] * $this->info['video']['bits_per_sample'] * $FrameRate; - - $this->info['video']['compression_ratio'] = $BitrateCompressed / $BitrateUncompressed; - return true; - } - - - public function CalculateCompressionRatioAudio() { - if (empty($this->info['audio']['bitrate']) || empty($this->info['audio']['channels']) || empty($this->info['audio']['sample_rate']) || !is_numeric($this->info['audio']['sample_rate'])) { - return false; - } - $this->info['audio']['compression_ratio'] = $this->info['audio']['bitrate'] / ($this->info['audio']['channels'] * $this->info['audio']['sample_rate'] * (!empty($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : 16)); - - if (!empty($this->info['audio']['streams'])) { - foreach ($this->info['audio']['streams'] as $streamnumber => $streamdata) { - if (!empty($streamdata['bitrate']) && !empty($streamdata['channels']) && !empty($streamdata['sample_rate'])) { - $this->info['audio']['streams'][$streamnumber]['compression_ratio'] = $streamdata['bitrate'] / ($streamdata['channels'] * $streamdata['sample_rate'] * (!empty($streamdata['bits_per_sample']) ? $streamdata['bits_per_sample'] : 16)); - } - } - } - return true; - } - - - public function CalculateReplayGain() { - if (isset($this->info['replay_gain'])) { - if (!isset($this->info['replay_gain']['reference_volume'])) { - $this->info['replay_gain']['reference_volume'] = (double) 89.0; - } - if (isset($this->info['replay_gain']['track']['adjustment'])) { - $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment']; - } - if (isset($this->info['replay_gain']['album']['adjustment'])) { - $this->info['replay_gain']['album']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['album']['adjustment']; - } - - if (isset($this->info['replay_gain']['track']['peak'])) { - $this->info['replay_gain']['track']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['track']['peak']); - } - if (isset($this->info['replay_gain']['album']['peak'])) { - $this->info['replay_gain']['album']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['album']['peak']); - } - } - return true; - } - - public function ProcessAudioStreams() { - if (!empty($this->info['audio']['bitrate']) || !empty($this->info['audio']['channels']) || !empty($this->info['audio']['sample_rate'])) { - if (!isset($this->info['audio']['streams'])) { - foreach ($this->info['audio'] as $key => $value) { - if ($key != 'streams') { - $this->info['audio']['streams'][0][$key] = $value; - } - } - } - } - return true; - } - - public function getid3_tempnam() { - return tempnam($this->tempdir, 'gI3'); - } - - public function include_module($name) { - //if (!file_exists($this->include_path.'module.'.$name.'.php')) { - if (!file_exists(GETID3_INCLUDEPATH.'module.'.$name.'.php')) { - throw new getid3_exception('Required module.'.$name.'.php is missing.'); - } - include_once(GETID3_INCLUDEPATH.'module.'.$name.'.php'); - return true; - } - + // MOD - audio - MODule (Impulse Tracker) + 'it' => [ + 'pattern' => '^IMPM', + 'group' => 'audio', + 'module' => 'mod', + //'option' => 'it', + 'mime_type' => 'audio/it', + ], + + // MOD - audio - MODule (eXtended Module, various sub-formats) + 'xm' => [ + 'pattern' => '^Extended Module', + 'group' => 'audio', + 'module' => 'mod', + //'option' => 'xm', + 'mime_type' => 'audio/xm', + ], + + // MOD - audio - MODule (ScreamTracker) + 's3m' => [ + 'pattern' => '^.{44}SCRM', + 'group' => 'audio', + 'module' => 'mod', + //'option' => 's3m', + 'mime_type' => 'audio/s3m', + ], + + // MPC - audio - Musepack / MPEGplus + 'mpc' => [ + 'pattern' => '^(MPCK|MP\\+|[\\x00\\x01\\x10\\x11\\x40\\x41\\x50\\x51\\x80\\x81\\x90\\x91\\xC0\\xC1\\xD0\\xD1][\\x20-\\x37][\\x00\\x20\\x40\\x60\\x80\\xA0\\xC0\\xE0])', + 'group' => 'audio', + 'module' => 'mpc', + 'mime_type' => 'audio/x-musepack', + ], + + // MP3 - audio - MPEG-audio Layer 3 (very similar to AAC-ADTS) + 'mp3' => [ + 'pattern' => '^\\xFF[\\xE2-\\xE7\\xF2-\\xF7\\xFA-\\xFF][\\x00-\\x0B\\x10-\\x1B\\x20-\\x2B\\x30-\\x3B\\x40-\\x4B\\x50-\\x5B\\x60-\\x6B\\x70-\\x7B\\x80-\\x8B\\x90-\\x9B\\xA0-\\xAB\\xB0-\\xBB\\xC0-\\xCB\\xD0-\\xDB\\xE0-\\xEB\\xF0-\\xFB]', + 'group' => 'audio', + 'module' => 'mp3', + 'mime_type' => 'audio/mpeg', + ], + + // OFR - audio - OptimFROG + 'ofr' => [ + 'pattern' => '^(\\*RIFF|OFR)', + 'group' => 'audio', + 'module' => 'optimfrog', + 'mime_type' => 'application/octet-stream', + ], + + // RKAU - audio - RKive AUdio compressor + 'rkau' => [ + 'pattern' => '^RKA', + 'group' => 'audio', + 'module' => 'rkau', + 'mime_type' => 'application/octet-stream', + ], + + // SHN - audio - Shorten + 'shn' => [ + 'pattern' => '^ajkg', + 'group' => 'audio', + 'module' => 'shorten', + 'mime_type' => 'audio/xmms-shn', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // TTA - audio - TTA Lossless Audio Compressor (http://tta.corecodec.org) + 'tta' => [ + 'pattern' => '^TTA', // could also be '^TTA(\\x01|\\x02|\\x03|2|1)' + 'group' => 'audio', + 'module' => 'tta', + 'mime_type' => 'application/octet-stream', + ], + + // VOC - audio - Creative Voice (VOC) + 'voc' => [ + 'pattern' => '^Creative Voice File', + 'group' => 'audio', + 'module' => 'voc', + 'mime_type' => 'audio/voc', + ], + + // VQF - audio - transform-domain weighted interleave Vector Quantization Format (VQF) + 'vqf' => [ + 'pattern' => '^TWIN', + 'group' => 'audio', + 'module' => 'vqf', + 'mime_type' => 'application/octet-stream', + ], + + // WV - audio - WavPack (v4.0+) + 'wv' => [ + 'pattern' => '^wvpk', + 'group' => 'audio', + 'module' => 'wavpack', + 'mime_type' => 'application/octet-stream', + ], + + // Audio-Video formats + + // ASF - audio/video - Advanced Streaming Format, Windows Media Video, Windows Media Audio + 'asf' => [ + 'pattern' => '^\\x30\\x26\\xB2\\x75\\x8E\\x66\\xCF\\x11\\xA6\\xD9\\x00\\xAA\\x00\\x62\\xCE\\x6C', + 'group' => 'audio-video', + 'module' => 'asf', + 'mime_type' => 'video/x-ms-asf', + 'iconv_req' => false, + ], + + // BINK - audio/video - Bink / Smacker + 'bink' => [ + 'pattern' => '^(BIK|SMK)', + 'group' => 'audio-video', + 'module' => 'bink', + 'mime_type' => 'application/octet-stream', + ], + + // FLV - audio/video - FLash Video + 'flv' => [ + 'pattern' => '^FLV[\\x01]', + 'group' => 'audio-video', + 'module' => 'flv', + 'mime_type' => 'video/x-flv', + ], + + // MKAV - audio/video - Mastroka + 'matroska' => [ + 'pattern' => '^\\x1A\\x45\\xDF\\xA3', + 'group' => 'audio-video', + 'module' => 'matroska', + 'mime_type' => 'video/x-matroska', // may also be audio/x-matroska + ], + + // MPEG - audio/video - MPEG (Moving Pictures Experts Group) + 'mpeg' => [ + 'pattern' => '^\\x00\\x00\\x01[\\xB3\\xBA]', + 'group' => 'audio-video', + 'module' => 'mpeg', + 'mime_type' => 'video/mpeg', + ], + + // NSV - audio/video - Nullsoft Streaming Video (NSV) + 'nsv' => [ + 'pattern' => '^NSV[sf]', + 'group' => 'audio-video', + 'module' => 'nsv', + 'mime_type' => 'application/octet-stream', + ], + + // Ogg - audio/video - Ogg (Ogg-Vorbis, Ogg-FLAC, Speex, Ogg-Theora(*), Ogg-Tarkin(*)) + 'ogg' => [ + 'pattern' => '^OggS', + 'group' => 'audio', + 'module' => 'ogg', + 'mime_type' => 'application/ogg', + 'fail_id3' => 'WARNING', + 'fail_ape' => 'WARNING', + ], + + // QT - audio/video - Quicktime + 'quicktime' => [ + 'pattern' => '^.{4}(cmov|free|ftyp|mdat|moov|pnot|skip|wide)', + 'group' => 'audio-video', + 'module' => 'quicktime', + 'mime_type' => 'video/quicktime', + ], + + // RIFF - audio/video - Resource Interchange File Format (RIFF) / WAV / AVI / CD-audio / SDSS = renamed variant used by SmartSound QuickTracks (www.smartsound.com) / FORM = Audio Interchange File Format (AIFF) + 'riff' => [ + 'pattern' => '^(RIFF|SDSS|FORM)', + 'group' => 'audio-video', + 'module' => 'riff', + 'mime_type' => 'audio/x-wav', + 'fail_ape' => 'WARNING', + ], + + // Real - audio/video - RealAudio, RealVideo + 'real' => [ + 'pattern' => '^\\.(RMF|ra)', + 'group' => 'audio-video', + 'module' => 'real', + 'mime_type' => 'audio/x-realaudio', + ], + + // SWF - audio/video - ShockWave Flash + 'swf' => [ + 'pattern' => '^(F|C)WS', + 'group' => 'audio-video', + 'module' => 'swf', + 'mime_type' => 'application/x-shockwave-flash', + ], + + // TS - audio/video - MPEG-2 Transport Stream + 'ts' => [ + 'pattern' => '^(\\x47.{187}){10,}', // packets are 188 bytes long and start with 0x47 "G". Check for at least 10 packets matching this pattern + 'group' => 'audio-video', + 'module' => 'ts', + 'mime_type' => 'video/MP2T', + ], + + // Still-Image formats + + // BMP - still image - Bitmap (Windows, OS/2; uncompressed, RLE8, RLE4) + 'bmp' => [ + 'pattern' => '^BM', + 'group' => 'graphic', + 'module' => 'bmp', + 'mime_type' => 'image/bmp', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // GIF - still image - Graphics Interchange Format + 'gif' => [ + 'pattern' => '^GIF', + 'group' => 'graphic', + 'module' => 'gif', + 'mime_type' => 'image/gif', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // JPEG - still image - Joint Photographic Experts Group (JPEG) + 'jpg' => [ + 'pattern' => '^\\xFF\\xD8\\xFF', + 'group' => 'graphic', + 'module' => 'jpg', + 'mime_type' => 'image/jpeg', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // PCD - still image - Kodak Photo CD + 'pcd' => [ + 'pattern' => '^.{2048}PCD_IPI\\x00', + 'group' => 'graphic', + 'module' => 'pcd', + 'mime_type' => 'image/x-photo-cd', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // PNG - still image - Portable Network Graphics (PNG) + 'png' => [ + 'pattern' => '^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A', + 'group' => 'graphic', + 'module' => 'png', + 'mime_type' => 'image/png', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // SVG - still image - Scalable Vector Graphics (SVG) + 'svg' => [ + 'pattern' => '( 'graphic', + 'module' => 'svg', + 'mime_type' => 'image/svg+xml', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // TIFF - still image - Tagged Information File Format (TIFF) + 'tiff' => [ + 'pattern' => '^(II\\x2A\\x00|MM\\x00\\x2A)', + 'group' => 'graphic', + 'module' => 'tiff', + 'mime_type' => 'image/tiff', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // EFAX - still image - eFax (TIFF derivative) + 'efax' => [ + 'pattern' => '^\\xDC\\xFE', + 'group' => 'graphic', + 'module' => 'efax', + 'mime_type' => 'image/efax', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // Data formats + + // ISO - data - International Standards Organization (ISO) CD-ROM Image + 'iso' => [ + 'pattern' => '^.{32769}CD001', + 'group' => 'misc', + 'module' => 'iso', + 'mime_type' => 'application/octet-stream', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + 'iconv_req' => false, + ], + + // RAR - data - RAR compressed data + 'rar' => [ + 'pattern' => '^Rar\\!', + 'group' => 'archive', + 'module' => 'rar', + 'mime_type' => 'application/octet-stream', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // SZIP - audio/data - SZIP compressed data + 'szip' => [ + 'pattern' => '^SZ\\x0A\\x04', + 'group' => 'archive', + 'module' => 'szip', + 'mime_type' => 'application/octet-stream', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // TAR - data - TAR compressed data + 'tar' => [ + 'pattern' => '^.{100}[0-9\\x20]{7}\\x00[0-9\\x20]{7}\\x00[0-9\\x20]{7}\\x00[0-9\\x20\\x00]{12}[0-9\\x20\\x00]{12}', + 'group' => 'archive', + 'module' => 'tar', + 'mime_type' => 'application/x-tar', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // GZIP - data - GZIP compressed data + 'gz' => [ + 'pattern' => '^\\x1F\\x8B\\x08', + 'group' => 'archive', + 'module' => 'gzip', + 'mime_type' => 'application/x-gzip', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // ZIP - data - ZIP compressed data + 'zip' => [ + 'pattern' => '^PK\\x03\\x04', + 'group' => 'archive', + 'module' => 'zip', + 'mime_type' => 'application/zip', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // Misc other formats + + // PAR2 - data - Parity Volume Set Specification 2.0 + 'par2' => [ + 'pattern' => '^PAR2\\x00PKT', + 'group' => 'misc', + 'module' => 'par2', + 'mime_type' => 'application/octet-stream', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // PDF - data - Portable Document Format + 'pdf' => [ + 'pattern' => '^\\x25PDF', + 'group' => 'misc', + 'module' => 'pdf', + 'mime_type' => 'application/pdf', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // MSOFFICE - data - ZIP compressed data + 'msoffice' => [ + 'pattern' => '^\\xD0\\xCF\\x11\\xE0\\xA1\\xB1\\x1A\\xE1', // D0CF11E == DOCFILE == Microsoft Office Document + 'group' => 'misc', + 'module' => 'msoffice', + 'mime_type' => 'application/octet-stream', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ], + + // CUE - data - CUEsheet (index to single-file disc images) + 'cue' => [ + 'pattern' => '', // empty pattern means cannot be automatically detected, will fall through all other formats and match based on filename and very basic file contents + 'group' => 'misc', + 'module' => 'cue', + 'mime_type' => 'application/octet-stream', + ], + + ]; + } + + return $format_info; + } + + public function GetFileFormat(&$filedata, $filename = '') + { + // this function will determine the format of a file based on usually + // the first 2-4 bytes of the file (8 bytes for PNG, 16 bytes for JPG, + // and in the case of ISO CD image, 6 bytes offset 32kb from the start + // of the file). + + // Identify file format - loop through $format_info and detect with reg expr + foreach ($this->GetFileFormatArray() as $format_name => $info) { + // The /s switch on preg_match() forces preg_match() NOT to treat + // newline (0x0A) characters as special chars but do a binary match + if (! empty($info['pattern']) && preg_match('#'.$info['pattern'].'#s', $filedata)) { + $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php'; + + return $info; + } + } + + if (preg_match('#\\.mp[123a]$#i', $filename)) { + // Too many mp3 encoders on the market put gabage in front of mpeg files + // use assume format on these if format detection failed + $GetFileFormatArray = $this->GetFileFormatArray(); + $info = $GetFileFormatArray['mp3']; + $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php'; + + return $info; + } elseif (preg_match('#\\.cue$#i', $filename) && preg_match('#FILE "[^"]+" (BINARY|MOTOROLA|AIFF|WAVE|MP3)#', $filedata)) { + // there's not really a useful consistent "magic" at the beginning of .cue files to identify them + // so until I think of something better, just go by filename if all other format checks fail + // and verify there's at least one instance of "TRACK xx AUDIO" in the file + $GetFileFormatArray = $this->GetFileFormatArray(); + $info = $GetFileFormatArray['cue']; + $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php'; + + return $info; + } + + return false; + } + + // converts array to $encoding charset from $this->encoding + public function CharConvert(&$array, $encoding) + { + + // identical encoding - end here + if ($encoding == $this->encoding) { + return; + } + + // loop thru array + foreach ($array as $key => $value) { + + // go recursive + if (is_array($value)) { + $this->CharConvert($array[$key], $encoding); + } + + // convert string + elseif (is_string($value)) { + $array[$key] = trim(getid3_lib::iconv_fallback($encoding, $this->encoding, $value)); + } + } + } + + public function HandleAllTags() + { + + // key name => array (tag name, character encoding) + static $tags; + if (empty($tags)) { + $tags = [ + 'asf' => ['asf', 'UTF-16LE'], + 'midi' => ['midi', 'ISO-8859-1'], + 'nsv' => ['nsv', 'ISO-8859-1'], + 'ogg' => ['vorbiscomment', 'UTF-8'], + 'png' => ['png', 'UTF-8'], + 'tiff' => ['tiff', 'ISO-8859-1'], + 'quicktime' => ['quicktime', 'UTF-8'], + 'real' => ['real', 'ISO-8859-1'], + 'vqf' => ['vqf', 'ISO-8859-1'], + 'zip' => ['zip', 'ISO-8859-1'], + 'riff' => ['riff', 'ISO-8859-1'], + 'lyrics3' => ['lyrics3', 'ISO-8859-1'], + 'id3v1' => ['id3v1', $this->encoding_id3v1], + 'id3v2' => ['id3v2', 'UTF-8'], // not according to the specs (every frame can have a different encoding), but getID3() force-converts all encodings to UTF-8 + 'ape' => ['ape', 'UTF-8'], + 'cue' => ['cue', 'ISO-8859-1'], + 'matroska' => ['matroska', 'UTF-8'], + 'flac' => ['vorbiscomment', 'UTF-8'], + 'divxtag' => ['divx', 'ISO-8859-1'], + 'iptc' => ['iptc', 'ISO-8859-1'], + ]; + } + + // loop through comments array + foreach ($tags as $comment_name => $tagname_encoding_array) { + list($tag_name, $encoding) = $tagname_encoding_array; + + // fill in default encoding type if not already present + if (isset($this->info[$comment_name]) && ! isset($this->info[$comment_name]['encoding'])) { + $this->info[$comment_name]['encoding'] = $encoding; + } + + // copy comments if key name set + if (! empty($this->info[$comment_name]['comments'])) { + foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) { + foreach ($valuearray as $key => $value) { + if (is_string($value)) { + $value = trim($value, " \r\n\t"); // do not trim nulls from $value!! Unicode characters will get mangled if trailing nulls are removed! + } + if ($value) { + if (! is_numeric($key)) { + $this->info['tags'][trim($tag_name)][trim($tag_key)][$key] = $value; + } else { + $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value; + } + } + } + if ($tag_key == 'picture') { + unset($this->info[$comment_name]['comments'][$tag_key]); + } + } + + if (! isset($this->info['tags'][$tag_name])) { + // comments are set but contain nothing but empty strings, so skip + continue; + } + + $this->CharConvert($this->info['tags'][$tag_name], $this->info[$comment_name]['encoding']); // only copy gets converted! + + if ($this->option_tags_html) { + foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) { + $this->info['tags_html'][$tag_name][$tag_key] = getid3_lib::recursiveMultiByteCharString2HTML($valuearray, $this->info[$comment_name]['encoding']); + } + } + } + } + + // pictures can take up a lot of space, and we don't need multiple copies of them + // let there be a single copy in [comments][picture], and not elsewhere + if (! empty($this->info['tags'])) { + $unset_keys = ['tags', 'tags_html']; + foreach ($this->info['tags'] as $tagtype => $tagarray) { + foreach ($tagarray as $tagname => $tagdata) { + if ($tagname == 'picture') { + foreach ($tagdata as $key => $tagarray) { + $this->info['comments']['picture'][] = $tagarray; + if (isset($tagarray['data']) && isset($tagarray['image_mime'])) { + if (isset($this->info['tags'][$tagtype][$tagname][$key])) { + unset($this->info['tags'][$tagtype][$tagname][$key]); + } + if (isset($this->info['tags_html'][$tagtype][$tagname][$key])) { + unset($this->info['tags_html'][$tagtype][$tagname][$key]); + } + } + } + } + } + foreach ($unset_keys as $unset_key) { + // remove possible empty keys from (e.g. [tags][id3v2][picture]) + if (empty($this->info[$unset_key][$tagtype]['picture'])) { + unset($this->info[$unset_key][$tagtype]['picture']); + } + if (empty($this->info[$unset_key][$tagtype])) { + unset($this->info[$unset_key][$tagtype]); + } + if (empty($this->info[$unset_key])) { + unset($this->info[$unset_key]); + } + } + // remove duplicate copy of picture data from (e.g. [id3v2][comments][picture]) + if (isset($this->info[$tagtype]['comments']['picture'])) { + unset($this->info[$tagtype]['comments']['picture']); + } + if (empty($this->info[$tagtype]['comments'])) { + unset($this->info[$tagtype]['comments']); + } + if (empty($this->info[$tagtype])) { + unset($this->info[$tagtype]); + } + } + } + + return true; + } + + public function getHashdata($algorithm) + { + switch ($algorithm) { + case 'md5': + case 'sha1': + break; + + default: + return $this->error('bad algorithm "'.$algorithm.'" in getHashdata()'); + break; + } + + if (! empty($this->info['fileformat']) && ! empty($this->info['dataformat']) && ($this->info['fileformat'] == 'ogg') && ($this->info['audio']['dataformat'] == 'vorbis')) { + + // We cannot get an identical md5_data value for Ogg files where the comments + // span more than 1 Ogg page (compared to the same audio data with smaller + // comments) using the normal getID3() method of MD5'ing the data between the + // end of the comments and the end of the file (minus any trailing tags), + // because the page sequence numbers of the pages that the audio data is on + // do not match. Under normal circumstances, where comments are smaller than + // the nominal 4-8kB page size, then this is not a problem, but if there are + // very large comments, the only way around it is to strip off the comment + // tags with vorbiscomment and MD5 that file. + // This procedure must be applied to ALL Ogg files, not just the ones with + // comments larger than 1 page, because the below method simply MD5's the + // whole file with the comments stripped, not just the portion after the + // comments block (which is the standard getID3() method. + + // The above-mentioned problem of comments spanning multiple pages and changing + // page sequence numbers likely happens for OggSpeex and OggFLAC as well, but + // currently vorbiscomment only works on OggVorbis files. + + if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { + $this->warning('Failed making system call to vorbiscomment.exe - '.$algorithm.'_data is incorrect - error returned: PHP running in Safe Mode (backtick operator not available)'); + $this->info[$algorithm.'_data'] = false; + } else { + + // Prevent user from aborting script + $old_abort = ignore_user_abort(true); + + // Create empty file + $empty = tempnam(GETID3_TEMP_DIR, 'getID3'); + touch($empty); + + // Use vorbiscomment to make temp file without comments + $temp = tempnam(GETID3_TEMP_DIR, 'getID3'); + $file = $this->info['filenamepath']; + + if (GETID3_OS_ISWINDOWS) { + if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) { + $commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w -c "'.$empty.'" "'.$file.'" "'.$temp.'"'; + $VorbisCommentError = `$commandline`; + } else { + $VorbisCommentError = 'vorbiscomment.exe not found in '.GETID3_HELPERAPPSDIR; + } + } else { + $commandline = 'vorbiscomment -w -c "'.$empty.'" "'.$file.'" "'.$temp.'" 2>&1'; + $commandline = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg($file).' '.escapeshellarg($temp).' 2>&1'; + $VorbisCommentError = `$commandline`; + } + + if (! empty($VorbisCommentError)) { + $this->warning('Failed making system call to vorbiscomment(.exe) - '.$algorithm.'_data will be incorrect. If vorbiscomment is unavailable, please download from http://www.vorbis.com/download.psp and put in the getID3() directory. Error returned: '.$VorbisCommentError); + $this->info[$algorithm.'_data'] = false; + } else { + + // Get hash of newly created file + switch ($algorithm) { + case 'md5': + $this->info[$algorithm.'_data'] = md5_file($temp); + break; + + case 'sha1': + $this->info[$algorithm.'_data'] = sha1_file($temp); + break; + } + } + + // Clean up + unlink($empty); + unlink($temp); + + // Reset abort setting + ignore_user_abort($old_abort); + } + } else { + if (! empty($this->info['avdataoffset']) || (isset($this->info['avdataend']) && ($this->info['avdataend'] < $this->info['filesize']))) { + + // get hash from part of file + $this->info[$algorithm.'_data'] = getid3_lib::hash_data($this->info['filenamepath'], $this->info['avdataoffset'], $this->info['avdataend'], $algorithm); + } else { + + // get hash from whole file + switch ($algorithm) { + case 'md5': + $this->info[$algorithm.'_data'] = md5_file($this->info['filenamepath']); + break; + + case 'sha1': + $this->info[$algorithm.'_data'] = sha1_file($this->info['filenamepath']); + break; + } + } + } + + return true; + } + + public function ChannelsBitratePlaytimeCalculations() + { + + // set channelmode on audio + if (! empty($this->info['audio']['channelmode']) || ! isset($this->info['audio']['channels'])) { + // ignore + } elseif ($this->info['audio']['channels'] == 1) { + $this->info['audio']['channelmode'] = 'mono'; + } elseif ($this->info['audio']['channels'] == 2) { + $this->info['audio']['channelmode'] = 'stereo'; + } + + // Calculate combined bitrate - audio + video + $CombinedBitrate = 0; + $CombinedBitrate += (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : 0); + $CombinedBitrate += (isset($this->info['video']['bitrate']) ? $this->info['video']['bitrate'] : 0); + if (($CombinedBitrate > 0) && empty($this->info['bitrate'])) { + $this->info['bitrate'] = $CombinedBitrate; + } + //if ((isset($this->info['video']) && !isset($this->info['video']['bitrate'])) || (isset($this->info['audio']) && !isset($this->info['audio']['bitrate']))) { + // // for example, VBR MPEG video files cannot determine video bitrate: + // // should not set overall bitrate and playtime from audio bitrate only + // unset($this->info['bitrate']); + //} + + // video bitrate undetermined, but calculable + if (isset($this->info['video']['dataformat']) && $this->info['video']['dataformat'] && (! isset($this->info['video']['bitrate']) || ($this->info['video']['bitrate'] == 0))) { + // if video bitrate not set + if (isset($this->info['audio']['bitrate']) && ($this->info['audio']['bitrate'] > 0) && ($this->info['audio']['bitrate'] == $this->info['bitrate'])) { + // AND if audio bitrate is set to same as overall bitrate + if (isset($this->info['playtime_seconds']) && ($this->info['playtime_seconds'] > 0)) { + // AND if playtime is set + if (isset($this->info['avdataend']) && isset($this->info['avdataoffset'])) { + // AND if AV data offset start/end is known + // THEN we can calculate the video bitrate + $this->info['bitrate'] = round((($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds']); + $this->info['video']['bitrate'] = $this->info['bitrate'] - $this->info['audio']['bitrate']; + } + } + } + } + + if ((! isset($this->info['playtime_seconds']) || ($this->info['playtime_seconds'] <= 0)) && ! empty($this->info['bitrate'])) { + $this->info['playtime_seconds'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['bitrate']; + } + + if (! isset($this->info['bitrate']) && ! empty($this->info['playtime_seconds'])) { + $this->info['bitrate'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds']; + } + if (isset($this->info['bitrate']) && empty($this->info['audio']['bitrate']) && empty($this->info['video']['bitrate'])) { + if (isset($this->info['audio']['dataformat']) && empty($this->info['video']['resolution_x'])) { + // audio only + $this->info['audio']['bitrate'] = $this->info['bitrate']; + } elseif (isset($this->info['video']['resolution_x']) && empty($this->info['audio']['dataformat'])) { + // video only + $this->info['video']['bitrate'] = $this->info['bitrate']; + } + } + + // Set playtime string + if (! empty($this->info['playtime_seconds']) && empty($this->info['playtime_string'])) { + $this->info['playtime_string'] = getid3_lib::PlaytimeString($this->info['playtime_seconds']); + } + } + + public function CalculateCompressionRatioVideo() + { + if (empty($this->info['video'])) { + return false; + } + if (empty($this->info['video']['resolution_x']) || empty($this->info['video']['resolution_y'])) { + return false; + } + if (empty($this->info['video']['bits_per_sample'])) { + return false; + } + + switch ($this->info['video']['dataformat']) { + case 'bmp': + case 'gif': + case 'jpeg': + case 'jpg': + case 'png': + case 'tiff': + $FrameRate = 1; + $PlaytimeSeconds = 1; + $BitrateCompressed = $this->info['filesize'] * 8; + break; + + default: + if (! empty($this->info['video']['frame_rate'])) { + $FrameRate = $this->info['video']['frame_rate']; + } else { + return false; + } + if (! empty($this->info['playtime_seconds'])) { + $PlaytimeSeconds = $this->info['playtime_seconds']; + } else { + return false; + } + if (! empty($this->info['video']['bitrate'])) { + $BitrateCompressed = $this->info['video']['bitrate']; + } else { + return false; + } + break; + } + $BitrateUncompressed = $this->info['video']['resolution_x'] * $this->info['video']['resolution_y'] * $this->info['video']['bits_per_sample'] * $FrameRate; + + $this->info['video']['compression_ratio'] = $BitrateCompressed / $BitrateUncompressed; + + return true; + } + + public function CalculateCompressionRatioAudio() + { + if (empty($this->info['audio']['bitrate']) || empty($this->info['audio']['channels']) || empty($this->info['audio']['sample_rate']) || ! is_numeric($this->info['audio']['sample_rate'])) { + return false; + } + $this->info['audio']['compression_ratio'] = $this->info['audio']['bitrate'] / ($this->info['audio']['channels'] * $this->info['audio']['sample_rate'] * (! empty($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : 16)); + + if (! empty($this->info['audio']['streams'])) { + foreach ($this->info['audio']['streams'] as $streamnumber => $streamdata) { + if (! empty($streamdata['bitrate']) && ! empty($streamdata['channels']) && ! empty($streamdata['sample_rate'])) { + $this->info['audio']['streams'][$streamnumber]['compression_ratio'] = $streamdata['bitrate'] / ($streamdata['channels'] * $streamdata['sample_rate'] * (! empty($streamdata['bits_per_sample']) ? $streamdata['bits_per_sample'] : 16)); + } + } + } + + return true; + } + + public function CalculateReplayGain() + { + if (isset($this->info['replay_gain'])) { + if (! isset($this->info['replay_gain']['reference_volume'])) { + $this->info['replay_gain']['reference_volume'] = (float) 89.0; + } + if (isset($this->info['replay_gain']['track']['adjustment'])) { + $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment']; + } + if (isset($this->info['replay_gain']['album']['adjustment'])) { + $this->info['replay_gain']['album']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['album']['adjustment']; + } + + if (isset($this->info['replay_gain']['track']['peak'])) { + $this->info['replay_gain']['track']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['track']['peak']); + } + if (isset($this->info['replay_gain']['album']['peak'])) { + $this->info['replay_gain']['album']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['album']['peak']); + } + } + + return true; + } + + public function ProcessAudioStreams() + { + if (! empty($this->info['audio']['bitrate']) || ! empty($this->info['audio']['channels']) || ! empty($this->info['audio']['sample_rate'])) { + if (! isset($this->info['audio']['streams'])) { + foreach ($this->info['audio'] as $key => $value) { + if ($key != 'streams') { + $this->info['audio']['streams'][0][$key] = $value; + } + } + } + } + + return true; + } + + public function getid3_tempnam() + { + return tempnam($this->tempdir, 'gI3'); + } + + public function include_module($name) + { + //if (!file_exists($this->include_path.'module.'.$name.'.php')) { + if (! file_exists(GETID3_INCLUDEPATH.'module.'.$name.'.php')) { + throw new getid3_exception('Required module.'.$name.'.php is missing.'); + } + include_once GETID3_INCLUDEPATH.'module.'.$name.'.php'; + + return true; + } } +abstract class getid3_handler +{ + /** + * @var getID3 + */ + protected $getid3; // pointer -abstract class getid3_handler { + protected $data_string_flag = false; // analyzing filepointer or string + protected $data_string = ''; // string to analyze + protected $data_string_position = 0; // seek position in string + protected $data_string_length = 0; // string length - /** - * @var getID3 - */ - protected $getid3; // pointer + private $dependency_to = null; - protected $data_string_flag = false; // analyzing filepointer or string - protected $data_string = ''; // string to analyze - protected $data_string_position = 0; // seek position in string - protected $data_string_length = 0; // string length + public function __construct(getID3 $getid3, $call_module = null) + { + $this->getid3 = $getid3; - private $dependency_to = null; + if ($call_module) { + $this->dependency_to = str_replace('getid3_', '', $call_module); + } + } + // Analyze from file pointer + abstract public function Analyze(); - public function __construct(getID3 $getid3, $call_module=null) { - $this->getid3 = $getid3; + // Analyze from string instead + public function AnalyzeString($string) + { + // Enter string mode + $this->setStringMode($string); - if ($call_module) { - $this->dependency_to = str_replace('getid3_', '', $call_module); - } - } + // Save info + $saved_avdataoffset = $this->getid3->info['avdataoffset']; + $saved_avdataend = $this->getid3->info['avdataend']; + $saved_filesize = (isset($this->getid3->info['filesize']) ? $this->getid3->info['filesize'] : null); // may be not set if called as dependency without openfile() call + // Reset some info + $this->getid3->info['avdataoffset'] = 0; + $this->getid3->info['avdataend'] = $this->getid3->info['filesize'] = $this->data_string_length; - // Analyze from file pointer - abstract public function Analyze(); + // Analyze + $this->Analyze(); + // Restore some info + $this->getid3->info['avdataoffset'] = $saved_avdataoffset; + $this->getid3->info['avdataend'] = $saved_avdataend; + $this->getid3->info['filesize'] = $saved_filesize; - // Analyze from string instead - public function AnalyzeString($string) { - // Enter string mode - $this->setStringMode($string); + // Exit string mode + $this->data_string_flag = false; + } - // Save info - $saved_avdataoffset = $this->getid3->info['avdataoffset']; - $saved_avdataend = $this->getid3->info['avdataend']; - $saved_filesize = (isset($this->getid3->info['filesize']) ? $this->getid3->info['filesize'] : null); // may be not set if called as dependency without openfile() call + public function setStringMode($string) + { + $this->data_string_flag = true; + $this->data_string = $string; + $this->data_string_length = strlen($string); + } - // Reset some info - $this->getid3->info['avdataoffset'] = 0; - $this->getid3->info['avdataend'] = $this->getid3->info['filesize'] = $this->data_string_length; + protected function ftell() + { + if ($this->data_string_flag) { + return $this->data_string_position; + } - // Analyze - $this->Analyze(); + return ftell($this->getid3->fp); + } - // Restore some info - $this->getid3->info['avdataoffset'] = $saved_avdataoffset; - $this->getid3->info['avdataend'] = $saved_avdataend; - $this->getid3->info['filesize'] = $saved_filesize; + protected function fread($bytes) + { + if ($this->data_string_flag) { + $this->data_string_position += $bytes; - // Exit string mode - $this->data_string_flag = false; - } + return substr($this->data_string, $this->data_string_position - $bytes, $bytes); + } + $pos = $this->ftell() + $bytes; + if (! getid3_lib::intValueSupported($pos)) { + throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') because beyond PHP filesystem limit', 10); + } - public function setStringMode($string) { - $this->data_string_flag = true; - $this->data_string = $string; - $this->data_string_length = strlen($string); - } + //return fread($this->getid3->fp, $bytes); + /* + * http://www.getid3.org/phpBB3/viewtopic.php?t=1930 + * "I found out that the root cause for the problem was how getID3 uses the PHP system function fread(). + * It seems to assume that fread() would always return as many bytes as were requested. + * However, according the PHP manual (http://php.net/manual/en/function.fread.php), this is the case only with regular local files, but not e.g. with Linux pipes. + * The call may return only part of the requested data and a new call is needed to get more." + */ + $contents = ''; + do { + $part = fread($this->getid3->fp, $bytes); + $partLength = strlen($part); + $bytes -= $partLength; + $contents .= $part; + } while (($bytes > 0) && ($partLength > 0)); - protected function ftell() { - if ($this->data_string_flag) { - return $this->data_string_position; - } - return ftell($this->getid3->fp); - } + return $contents; + } - protected function fread($bytes) { - if ($this->data_string_flag) { - $this->data_string_position += $bytes; - return substr($this->data_string, $this->data_string_position - $bytes, $bytes); - } - $pos = $this->ftell() + $bytes; - if (!getid3_lib::intValueSupported($pos)) { - throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') because beyond PHP filesystem limit', 10); - } + protected function fseek($bytes, $whence = SEEK_SET) + { + if ($this->data_string_flag) { + switch ($whence) { + case SEEK_SET: + $this->data_string_position = $bytes; + break; - //return fread($this->getid3->fp, $bytes); - /* - * http://www.getid3.org/phpBB3/viewtopic.php?t=1930 - * "I found out that the root cause for the problem was how getID3 uses the PHP system function fread(). - * It seems to assume that fread() would always return as many bytes as were requested. - * However, according the PHP manual (http://php.net/manual/en/function.fread.php), this is the case only with regular local files, but not e.g. with Linux pipes. - * The call may return only part of the requested data and a new call is needed to get more." - */ - $contents = ''; - do { - $part = fread($this->getid3->fp, $bytes); - $partLength = strlen($part); - $bytes -= $partLength; - $contents .= $part; - } while (($bytes > 0) && ($partLength > 0)); - return $contents; - } + case SEEK_CUR: + $this->data_string_position += $bytes; + break; - protected function fseek($bytes, $whence=SEEK_SET) { - if ($this->data_string_flag) { - switch ($whence) { - case SEEK_SET: - $this->data_string_position = $bytes; - break; + case SEEK_END: + $this->data_string_position = $this->data_string_length + $bytes; + break; + } - case SEEK_CUR: - $this->data_string_position += $bytes; - break; + return 0; + } else { + $pos = $bytes; + if ($whence == SEEK_CUR) { + $pos = $this->ftell() + $bytes; + } elseif ($whence == SEEK_END) { + $pos = $this->getid3->info['filesize'] + $bytes; + } + if (! getid3_lib::intValueSupported($pos)) { + throw new getid3_exception('cannot fseek('.$pos.') because beyond PHP filesystem limit', 10); + } + } - case SEEK_END: - $this->data_string_position = $this->data_string_length + $bytes; - break; - } - return 0; - } else { - $pos = $bytes; - if ($whence == SEEK_CUR) { - $pos = $this->ftell() + $bytes; - } elseif ($whence == SEEK_END) { - $pos = $this->getid3->info['filesize'] + $bytes; - } - if (!getid3_lib::intValueSupported($pos)) { - throw new getid3_exception('cannot fseek('.$pos.') because beyond PHP filesystem limit', 10); - } - } - return fseek($this->getid3->fp, $bytes, $whence); - } + return fseek($this->getid3->fp, $bytes, $whence); + } - protected function feof() { - if ($this->data_string_flag) { - return $this->data_string_position >= $this->data_string_length; - } - return feof($this->getid3->fp); - } + protected function feof() + { + if ($this->data_string_flag) { + return $this->data_string_position >= $this->data_string_length; + } - final protected function isDependencyFor($module) { - return $this->dependency_to == $module; - } + return feof($this->getid3->fp); + } - protected function error($text) { - $this->getid3->info['error'][] = $text; + final protected function isDependencyFor($module) + { + return $this->dependency_to == $module; + } - return false; - } + protected function error($text) + { + $this->getid3->info['error'][] = $text; - protected function warning($text) { - return $this->getid3->warning($text); - } + return false; + } - protected function notice($text) { - // does nothing for now - } + protected function warning($text) + { + return $this->getid3->warning($text); + } - public function saveAttachment($name, $offset, $length, $image_mime=null) { - try { + protected function notice($text) + { + // does nothing for now + } - // do not extract at all - if ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_NONE) { + public function saveAttachment($name, $offset, $length, $image_mime = null) + { + try { - $attachment = null; // do not set any + // do not extract at all + if ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_NONE) { + $attachment = null; // do not set any - // extract to return array - } elseif ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_INLINE) { + // extract to return array + } elseif ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_INLINE) { + $this->fseek($offset); + $attachment = $this->fread($length); // get whole data in one pass, till it is anyway stored in memory + if ($attachment === false || strlen($attachment) != $length) { + throw new Exception('failed to read attachment data'); + } - $this->fseek($offset); - $attachment = $this->fread($length); // get whole data in one pass, till it is anyway stored in memory - if ($attachment === false || strlen($attachment) != $length) { - throw new Exception('failed to read attachment data'); - } + // assume directory path is given + } else { - // assume directory path is given - } else { + // set up destination path + $dir = rtrim(str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $this->getid3->option_save_attachments), DIRECTORY_SEPARATOR); + if (! is_dir($dir) || ! is_writable($dir)) { // check supplied directory + throw new Exception('supplied path ('.$dir.') does not exist, or is not writable'); + } + $dest = $dir.DIRECTORY_SEPARATOR.$name.($image_mime ? '.'.getid3_lib::ImageExtFromMime($image_mime) : ''); - // set up destination path - $dir = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->getid3->option_save_attachments), DIRECTORY_SEPARATOR); - if (!is_dir($dir) || !is_writable($dir)) { // check supplied directory - throw new Exception('supplied path ('.$dir.') does not exist, or is not writable'); - } - $dest = $dir.DIRECTORY_SEPARATOR.$name.($image_mime ? '.'.getid3_lib::ImageExtFromMime($image_mime) : ''); + // create dest file + if (($fp_dest = fopen($dest, 'wb')) == false) { + throw new Exception('failed to create file '.$dest); + } - // create dest file - if (($fp_dest = fopen($dest, 'wb')) == false) { - throw new Exception('failed to create file '.$dest); - } + // copy data + $this->fseek($offset); + $buffersize = ($this->data_string_flag ? $length : $this->getid3->fread_buffer_size()); + $bytesleft = $length; + while ($bytesleft > 0) { + if (($buffer = $this->fread(min($buffersize, $bytesleft))) === false || ($byteswritten = fwrite($fp_dest, $buffer)) === false || ($byteswritten === 0)) { + throw new Exception($buffer === false ? 'not enough data to read' : 'failed to write to destination file, may be not enough disk space'); + } + $bytesleft -= $byteswritten; + } - // copy data - $this->fseek($offset); - $buffersize = ($this->data_string_flag ? $length : $this->getid3->fread_buffer_size()); - $bytesleft = $length; - while ($bytesleft > 0) { - if (($buffer = $this->fread(min($buffersize, $bytesleft))) === false || ($byteswritten = fwrite($fp_dest, $buffer)) === false || ($byteswritten === 0)) { - throw new Exception($buffer === false ? 'not enough data to read' : 'failed to write to destination file, may be not enough disk space'); - } - $bytesleft -= $byteswritten; - } + fclose($fp_dest); + $attachment = $dest; + } + } catch (Exception $e) { - fclose($fp_dest); - $attachment = $dest; + // close and remove dest file if created + if (isset($fp_dest) && is_resource($fp_dest)) { + fclose($fp_dest); + unlink($dest); + } - } + // do not set any is case of error + $attachment = null; + $this->warning('Failed to extract attachment '.$name.': '.$e->getMessage()); + } - } catch (Exception $e) { - - // close and remove dest file if created - if (isset($fp_dest) && is_resource($fp_dest)) { - fclose($fp_dest); - unlink($dest); - } - - // do not set any is case of error - $attachment = null; - $this->warning('Failed to extract attachment '.$name.': '.$e->getMessage()); - - } - - // seek to the end of attachment - $this->fseek($offset + $length); - - return $attachment; - } + // seek to the end of attachment + $this->fseek($offset + $length); + return $attachment; + } } - class getid3_exception extends Exception { - public $message; + public $message; } diff --git a/app/Library/getid3/getid3/module.archive.gzip.php b/app/Library/getid3/getid3/module.archive.gzip.php index 112a1e6d..9aaa77f0 100644 --- a/app/Library/getid3/getid3/module.archive.gzip.php +++ b/app/Library/getid3/getid3/module.archive.gzip.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -19,263 +20,269 @@ // // ///////////////////////////////////////////////////////////////// +class getid3_gzip extends getid3_handler +{ + // public: Optional file list - disable for speed. + public $option_gzip_parse_contents = false; // decode gzipped files, if possible, and parse recursively (.tar.gz for example) -class getid3_gzip extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - // public: Optional file list - disable for speed. - public $option_gzip_parse_contents = false; // decode gzipped files, if possible, and parse recursively (.tar.gz for example) + $info['fileformat'] = 'gzip'; - public function Analyze() { - $info = &$this->getid3->info; + $start_length = 10; + $unpack_header = 'a1id1/a1id2/a1cmethod/a1flags/a4mtime/a1xflags/a1os'; + //+---+---+---+---+---+---+---+---+---+---+ + //|ID1|ID2|CM |FLG| MTIME |XFL|OS | + //+---+---+---+---+---+---+---+---+---+---+ - $info['fileformat'] = 'gzip'; + if ($info['php_memory_limit'] && ($info['filesize'] > $info['php_memory_limit'])) { + $this->error('File is too large ('.number_format($info['filesize']).' bytes) to read into memory (limit: '.number_format($info['php_memory_limit'] / 1048576).'MB)'); - $start_length = 10; - $unpack_header = 'a1id1/a1id2/a1cmethod/a1flags/a4mtime/a1xflags/a1os'; - //+---+---+---+---+---+---+---+---+---+---+ - //|ID1|ID2|CM |FLG| MTIME |XFL|OS | - //+---+---+---+---+---+---+---+---+---+---+ + return false; + } + $this->fseek(0); + $buffer = $this->fread($info['filesize']); - if ($info['php_memory_limit'] && ($info['filesize'] > $info['php_memory_limit'])) { - $this->error('File is too large ('.number_format($info['filesize']).' bytes) to read into memory (limit: '.number_format($info['php_memory_limit'] / 1048576).'MB)'); - return false; - } - $this->fseek(0); - $buffer = $this->fread($info['filesize']); + $arr_members = explode("\x1F\x8B\x08", $buffer); + while (true) { + $is_wrong_members = false; + $num_members = intval(count($arr_members)); + for ($i = 0; $i < $num_members; $i++) { + if (strlen($arr_members[$i]) == 0) { + continue; + } + $buf = "\x1F\x8B\x08".$arr_members[$i]; - $arr_members = explode("\x1F\x8B\x08", $buffer); - while (true) { - $is_wrong_members = false; - $num_members = intval(count($arr_members)); - for ($i = 0; $i < $num_members; $i++) { - if (strlen($arr_members[$i]) == 0) { - continue; - } - $buf = "\x1F\x8B\x08".$arr_members[$i]; + $attr = unpack($unpack_header, substr($buf, 0, $start_length)); + if (! $this->get_os_type(ord($attr['os']))) { + // Merge member with previous if wrong OS type + $arr_members[($i - 1)] .= $buf; + $arr_members[$i] = ''; + $is_wrong_members = true; + continue; + } + } + if (! $is_wrong_members) { + break; + } + } - $attr = unpack($unpack_header, substr($buf, 0, $start_length)); - if (!$this->get_os_type(ord($attr['os']))) { - // Merge member with previous if wrong OS type - $arr_members[($i - 1)] .= $buf; - $arr_members[$i] = ''; - $is_wrong_members = true; - continue; - } - } - if (!$is_wrong_members) { - break; - } - } + $info['gzip']['files'] = []; - $info['gzip']['files'] = array(); + $fpointer = 0; + $idx = 0; + for ($i = 0; $i < $num_members; $i++) { + if (strlen($arr_members[$i]) == 0) { + continue; + } + $thisInfo = &$info['gzip']['member_header'][++$idx]; - $fpointer = 0; - $idx = 0; - for ($i = 0; $i < $num_members; $i++) { - if (strlen($arr_members[$i]) == 0) { - continue; - } - $thisInfo = &$info['gzip']['member_header'][++$idx]; + $buff = "\x1F\x8B\x08".$arr_members[$i]; - $buff = "\x1F\x8B\x08".$arr_members[$i]; + $attr = unpack($unpack_header, substr($buff, 0, $start_length)); + $thisInfo['filemtime'] = getid3_lib::LittleEndian2Int($attr['mtime']); + $thisInfo['raw']['id1'] = ord($attr['cmethod']); + $thisInfo['raw']['id2'] = ord($attr['cmethod']); + $thisInfo['raw']['cmethod'] = ord($attr['cmethod']); + $thisInfo['raw']['os'] = ord($attr['os']); + $thisInfo['raw']['xflags'] = ord($attr['xflags']); + $thisInfo['raw']['flags'] = ord($attr['flags']); - $attr = unpack($unpack_header, substr($buff, 0, $start_length)); - $thisInfo['filemtime'] = getid3_lib::LittleEndian2Int($attr['mtime']); - $thisInfo['raw']['id1'] = ord($attr['cmethod']); - $thisInfo['raw']['id2'] = ord($attr['cmethod']); - $thisInfo['raw']['cmethod'] = ord($attr['cmethod']); - $thisInfo['raw']['os'] = ord($attr['os']); - $thisInfo['raw']['xflags'] = ord($attr['xflags']); - $thisInfo['raw']['flags'] = ord($attr['flags']); + $thisInfo['flags']['crc16'] = (bool) ($thisInfo['raw']['flags'] & 0x02); + $thisInfo['flags']['extra'] = (bool) ($thisInfo['raw']['flags'] & 0x04); + $thisInfo['flags']['filename'] = (bool) ($thisInfo['raw']['flags'] & 0x08); + $thisInfo['flags']['comment'] = (bool) ($thisInfo['raw']['flags'] & 0x10); - $thisInfo['flags']['crc16'] = (bool) ($thisInfo['raw']['flags'] & 0x02); - $thisInfo['flags']['extra'] = (bool) ($thisInfo['raw']['flags'] & 0x04); - $thisInfo['flags']['filename'] = (bool) ($thisInfo['raw']['flags'] & 0x08); - $thisInfo['flags']['comment'] = (bool) ($thisInfo['raw']['flags'] & 0x10); + $thisInfo['compression'] = $this->get_xflag_type($thisInfo['raw']['xflags']); - $thisInfo['compression'] = $this->get_xflag_type($thisInfo['raw']['xflags']); + $thisInfo['os'] = $this->get_os_type($thisInfo['raw']['os']); + if (! $thisInfo['os']) { + $this->error('Read error on gzip file'); - $thisInfo['os'] = $this->get_os_type($thisInfo['raw']['os']); - if (!$thisInfo['os']) { - $this->error('Read error on gzip file'); - return false; - } + return false; + } - $fpointer = 10; - $arr_xsubfield = array(); - // bit 2 - FLG.FEXTRA - //+---+---+=================================+ - //| XLEN |...XLEN bytes of "extra field"...| - //+---+---+=================================+ - if ($thisInfo['flags']['extra']) { - $w_xlen = substr($buff, $fpointer, 2); - $xlen = getid3_lib::LittleEndian2Int($w_xlen); - $fpointer += 2; + $fpointer = 10; + $arr_xsubfield = []; + // bit 2 - FLG.FEXTRA + //+---+---+=================================+ + //| XLEN |...XLEN bytes of "extra field"...| + //+---+---+=================================+ + if ($thisInfo['flags']['extra']) { + $w_xlen = substr($buff, $fpointer, 2); + $xlen = getid3_lib::LittleEndian2Int($w_xlen); + $fpointer += 2; - $thisInfo['raw']['xfield'] = substr($buff, $fpointer, $xlen); - // Extra SubFields - //+---+---+---+---+==================================+ - //|SI1|SI2| LEN |... LEN bytes of subfield data ...| - //+---+---+---+---+==================================+ - $idx = 0; - while (true) { - if ($idx >= $xlen) { - break; - } - $si1 = ord(substr($buff, $fpointer + $idx++, 1)); - $si2 = ord(substr($buff, $fpointer + $idx++, 1)); - if (($si1 == 0x41) && ($si2 == 0x70)) { - $w_xsublen = substr($buff, $fpointer + $idx, 2); - $xsublen = getid3_lib::LittleEndian2Int($w_xsublen); - $idx += 2; - $arr_xsubfield[] = substr($buff, $fpointer + $idx, $xsublen); - $idx += $xsublen; - } else { - break; - } - } - $fpointer += $xlen; - } - // bit 3 - FLG.FNAME - //+=========================================+ - //|...original file name, zero-terminated...| - //+=========================================+ - // GZIP files may have only one file, with no filename, so assume original filename is current filename without .gz - $thisInfo['filename'] = preg_replace('#\\.gz$#i', '', $info['filename']); - if ($thisInfo['flags']['filename']) { - $thisInfo['filename'] = ''; - while (true) { - if (ord($buff[$fpointer]) == 0) { - $fpointer++; - break; - } - $thisInfo['filename'] .= $buff[$fpointer]; - $fpointer++; - } - } - // bit 4 - FLG.FCOMMENT - //+===================================+ - //|...file comment, zero-terminated...| - //+===================================+ - if ($thisInfo['flags']['comment']) { - while (true) { - if (ord($buff[$fpointer]) == 0) { - $fpointer++; - break; - } - $thisInfo['comment'] .= $buff[$fpointer]; - $fpointer++; - } - } - // bit 1 - FLG.FHCRC - //+---+---+ - //| CRC16 | - //+---+---+ - if ($thisInfo['flags']['crc16']) { - $w_crc = substr($buff, $fpointer, 2); - $thisInfo['crc16'] = getid3_lib::LittleEndian2Int($w_crc); - $fpointer += 2; - } - // bit 0 - FLG.FTEXT - //if ($thisInfo['raw']['flags'] & 0x01) { - // Ignored... - //} - // bits 5, 6, 7 - reserved + $thisInfo['raw']['xfield'] = substr($buff, $fpointer, $xlen); + // Extra SubFields + //+---+---+---+---+==================================+ + //|SI1|SI2| LEN |... LEN bytes of subfield data ...| + //+---+---+---+---+==================================+ + $idx = 0; + while (true) { + if ($idx >= $xlen) { + break; + } + $si1 = ord(substr($buff, $fpointer + $idx++, 1)); + $si2 = ord(substr($buff, $fpointer + $idx++, 1)); + if (($si1 == 0x41) && ($si2 == 0x70)) { + $w_xsublen = substr($buff, $fpointer + $idx, 2); + $xsublen = getid3_lib::LittleEndian2Int($w_xsublen); + $idx += 2; + $arr_xsubfield[] = substr($buff, $fpointer + $idx, $xsublen); + $idx += $xsublen; + } else { + break; + } + } + $fpointer += $xlen; + } + // bit 3 - FLG.FNAME + //+=========================================+ + //|...original file name, zero-terminated...| + //+=========================================+ + // GZIP files may have only one file, with no filename, so assume original filename is current filename without .gz + $thisInfo['filename'] = preg_replace('#\\.gz$#i', '', $info['filename']); + if ($thisInfo['flags']['filename']) { + $thisInfo['filename'] = ''; + while (true) { + if (ord($buff[$fpointer]) == 0) { + $fpointer++; + break; + } + $thisInfo['filename'] .= $buff[$fpointer]; + $fpointer++; + } + } + // bit 4 - FLG.FCOMMENT + //+===================================+ + //|...file comment, zero-terminated...| + //+===================================+ + if ($thisInfo['flags']['comment']) { + while (true) { + if (ord($buff[$fpointer]) == 0) { + $fpointer++; + break; + } + $thisInfo['comment'] .= $buff[$fpointer]; + $fpointer++; + } + } + // bit 1 - FLG.FHCRC + //+---+---+ + //| CRC16 | + //+---+---+ + if ($thisInfo['flags']['crc16']) { + $w_crc = substr($buff, $fpointer, 2); + $thisInfo['crc16'] = getid3_lib::LittleEndian2Int($w_crc); + $fpointer += 2; + } + // bit 0 - FLG.FTEXT + //if ($thisInfo['raw']['flags'] & 0x01) { + // Ignored... + //} + // bits 5, 6, 7 - reserved - $thisInfo['crc32'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 8, 4)); - $thisInfo['filesize'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 4)); + $thisInfo['crc32'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 8, 4)); + $thisInfo['filesize'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 4)); - $info['gzip']['files'] = getid3_lib::array_merge_clobber($info['gzip']['files'], getid3_lib::CreateDeepArray($thisInfo['filename'], '/', $thisInfo['filesize'])); + $info['gzip']['files'] = getid3_lib::array_merge_clobber($info['gzip']['files'], getid3_lib::CreateDeepArray($thisInfo['filename'], '/', $thisInfo['filesize'])); - if ($this->option_gzip_parse_contents) { - // Try to inflate GZip - $csize = 0; - $inflated = ''; - $chkcrc32 = ''; - if (function_exists('gzinflate')) { - $cdata = substr($buff, $fpointer); - $cdata = substr($cdata, 0, strlen($cdata) - 8); - $csize = strlen($cdata); - $inflated = gzinflate($cdata); + if ($this->option_gzip_parse_contents) { + // Try to inflate GZip + $csize = 0; + $inflated = ''; + $chkcrc32 = ''; + if (function_exists('gzinflate')) { + $cdata = substr($buff, $fpointer); + $cdata = substr($cdata, 0, strlen($cdata) - 8); + $csize = strlen($cdata); + $inflated = gzinflate($cdata); - // Calculate CRC32 for inflated content - $thisInfo['crc32_valid'] = (bool) (sprintf('%u', crc32($inflated)) == $thisInfo['crc32']); + // Calculate CRC32 for inflated content + $thisInfo['crc32_valid'] = (bool) (sprintf('%u', crc32($inflated)) == $thisInfo['crc32']); - // determine format - $formattest = substr($inflated, 0, 32774); - $getid3_temp = new getID3(); - $determined_format = $getid3_temp->GetFileFormat($formattest); - unset($getid3_temp); + // determine format + $formattest = substr($inflated, 0, 32774); + $getid3_temp = new getID3(); + $determined_format = $getid3_temp->GetFileFormat($formattest); + unset($getid3_temp); - // file format is determined - $determined_format['module'] = (isset($determined_format['module']) ? $determined_format['module'] : ''); - switch ($determined_format['module']) { - case 'tar': - // view TAR-file info - if (file_exists(GETID3_INCLUDEPATH.$determined_format['include']) && include_once(GETID3_INCLUDEPATH.$determined_format['include'])) { - if (($temp_tar_filename = tempnam(GETID3_TEMP_DIR, 'getID3')) === false) { - // can't find anywhere to create a temp file, abort - $this->error('Unable to create temp file to parse TAR inside GZIP file'); - break; - } - if ($fp_temp_tar = fopen($temp_tar_filename, 'w+b')) { - fwrite($fp_temp_tar, $inflated); - fclose($fp_temp_tar); - $getid3_temp = new getID3(); - $getid3_temp->openfile($temp_tar_filename); - $getid3_tar = new getid3_tar($getid3_temp); - $getid3_tar->Analyze(); - $info['gzip']['member_header'][$idx]['tar'] = $getid3_temp->info['tar']; - unset($getid3_temp, $getid3_tar); - unlink($temp_tar_filename); - } else { - $this->error('Unable to fopen() temp file to parse TAR inside GZIP file'); - break; - } - } - break; + // file format is determined + $determined_format['module'] = (isset($determined_format['module']) ? $determined_format['module'] : ''); + switch ($determined_format['module']) { + case 'tar': + // view TAR-file info + if (file_exists(GETID3_INCLUDEPATH.$determined_format['include']) && include_once(GETID3_INCLUDEPATH.$determined_format['include'])) { + if (($temp_tar_filename = tempnam(GETID3_TEMP_DIR, 'getID3')) === false) { + // can't find anywhere to create a temp file, abort + $this->error('Unable to create temp file to parse TAR inside GZIP file'); + break; + } + if ($fp_temp_tar = fopen($temp_tar_filename, 'w+b')) { + fwrite($fp_temp_tar, $inflated); + fclose($fp_temp_tar); + $getid3_temp = new getID3(); + $getid3_temp->openfile($temp_tar_filename); + $getid3_tar = new getid3_tar($getid3_temp); + $getid3_tar->Analyze(); + $info['gzip']['member_header'][$idx]['tar'] = $getid3_temp->info['tar']; + unset($getid3_temp, $getid3_tar); + unlink($temp_tar_filename); + } else { + $this->error('Unable to fopen() temp file to parse TAR inside GZIP file'); + break; + } + } + break; - case '': - default: - // unknown or unhandled format - break; - } - } - } - } - return true; - } + case '': + default: + // unknown or unhandled format + break; + } + } + } + } - // Converts the OS type - public function get_os_type($key) { - static $os_type = array( - '0' => 'FAT filesystem (MS-DOS, OS/2, NT/Win32)', - '1' => 'Amiga', - '2' => 'VMS (or OpenVMS)', - '3' => 'Unix', - '4' => 'VM/CMS', - '5' => 'Atari TOS', - '6' => 'HPFS filesystem (OS/2, NT)', - '7' => 'Macintosh', - '8' => 'Z-System', - '9' => 'CP/M', - '10' => 'TOPS-20', - '11' => 'NTFS filesystem (NT)', - '12' => 'QDOS', - '13' => 'Acorn RISCOS', - '255' => 'unknown' - ); - return (isset($os_type[$key]) ? $os_type[$key] : ''); - } + return true; + } - // Converts the eXtra FLags - public function get_xflag_type($key) { - static $xflag_type = array( - '0' => 'unknown', - '2' => 'maximum compression', - '4' => 'fastest algorithm' - ); - return (isset($xflag_type[$key]) ? $xflag_type[$key] : ''); - } + // Converts the OS type + public function get_os_type($key) + { + static $os_type = [ + '0' => 'FAT filesystem (MS-DOS, OS/2, NT/Win32)', + '1' => 'Amiga', + '2' => 'VMS (or OpenVMS)', + '3' => 'Unix', + '4' => 'VM/CMS', + '5' => 'Atari TOS', + '6' => 'HPFS filesystem (OS/2, NT)', + '7' => 'Macintosh', + '8' => 'Z-System', + '9' => 'CP/M', + '10' => 'TOPS-20', + '11' => 'NTFS filesystem (NT)', + '12' => 'QDOS', + '13' => 'Acorn RISCOS', + '255' => 'unknown', + ]; + + return isset($os_type[$key]) ? $os_type[$key] : ''; + } + + // Converts the eXtra FLags + public function get_xflag_type($key) + { + static $xflag_type = [ + '0' => 'unknown', + '2' => 'maximum compression', + '4' => 'fastest algorithm', + ]; + + return isset($xflag_type[$key]) ? $xflag_type[$key] : ''; + } } - diff --git a/app/Library/getid3/getid3/module.archive.rar.php b/app/Library/getid3/getid3/module.archive.rar.php index 30961fb5..59c4afc1 100644 --- a/app/Library/getid3/getid3/module.archive.rar.php +++ b/app/Library/getid3/getid3/module.archive.rar.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,38 +15,37 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_rar extends getid3_handler { + public $option_use_rar_extension = false; - public $option_use_rar_extension = false; + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $info['fileformat'] = 'rar'; - $info['fileformat'] = 'rar'; + if ($this->option_use_rar_extension === true) { + if (function_exists('rar_open')) { + if ($rp = rar_open($info['filenamepath'])) { + $info['rar']['files'] = []; + $entries = rar_list($rp); + foreach ($entries as $entry) { + $info['rar']['files'] = getid3_lib::array_merge_clobber($info['rar']['files'], getid3_lib::CreateDeepArray($entry->getName(), '/', $entry->getUnpackedSize())); + } + rar_close($rp); - if ($this->option_use_rar_extension === true) { - if (function_exists('rar_open')) { - if ($rp = rar_open($info['filenamepath'])) { - $info['rar']['files'] = array(); - $entries = rar_list($rp); - foreach ($entries as $entry) { - $info['rar']['files'] = getid3_lib::array_merge_clobber($info['rar']['files'], getid3_lib::CreateDeepArray($entry->getName(), '/', $entry->getUnpackedSize())); - } - rar_close($rp); - return true; - } else { - $this->error('failed to rar_open('.$info['filename'].')'); - } - } else { - $this->error('RAR support does not appear to be available in this PHP installation'); - } - } else { - $this->error('PHP-RAR processing has been disabled (set $getid3_rar->option_use_rar_extension=true to enable)'); - } - return false; - - } + return true; + } else { + $this->error('failed to rar_open('.$info['filename'].')'); + } + } else { + $this->error('RAR support does not appear to be available in this PHP installation'); + } + } else { + $this->error('PHP-RAR processing has been disabled (set $getid3_rar->option_use_rar_extension=true to enable)'); + } + return false; + } } diff --git a/app/Library/getid3/getid3/module.archive.szip.php b/app/Library/getid3/getid3/module.archive.szip.php index 67517294..0f2aeef0 100644 --- a/app/Library/getid3/getid3/module.archive.szip.php +++ b/app/Library/getid3/getid3/module.archive.szip.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,84 +15,83 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_szip extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $SZIPHeader = $this->fread(6); + if (substr($SZIPHeader, 0, 4) != "SZ\x0A\x04") { + $this->error('Expecting "53 5A 0A 04" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($SZIPHeader, 0, 4)).'"'); - $this->fseek($info['avdataoffset']); - $SZIPHeader = $this->fread(6); - if (substr($SZIPHeader, 0, 4) != "SZ\x0A\x04") { - $this->error('Expecting "53 5A 0A 04" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($SZIPHeader, 0, 4)).'"'); - return false; - } - $info['fileformat'] = 'szip'; - $info['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 4, 1)); - $info['szip']['minor_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 5, 1)); -$this->error('SZIP parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); -return false; + return false; + } + $info['fileformat'] = 'szip'; + $info['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 4, 1)); + $info['szip']['minor_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 5, 1)); + $this->error('SZIP parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); - while (!$this->feof()) { - $NextBlockID = $this->fread(2); - switch ($NextBlockID) { - case 'SZ': - // Note that szip files can be concatenated, this has the same effect as - // concatenating the files. this also means that global header blocks - // might be present between directory/data blocks. - $this->fseek(4, SEEK_CUR); - break; + return false; - case 'BH': - $BHheaderbytes = getid3_lib::BigEndian2Int($this->fread(3)); - $BHheaderdata = $this->fread($BHheaderbytes); - $BHheaderoffset = 0; - while (strpos($BHheaderdata, "\x00", $BHheaderoffset) > 0) { - //filename as \0 terminated string (empty string indicates end) - //owner as \0 terminated string (empty is same as last file) - //group as \0 terminated string (empty is same as last file) - //3 byte filelength in this block - //2 byte access flags - //4 byte creation time (like in unix) - //4 byte modification time (like in unix) - //4 byte access time (like in unix) + while (! $this->feof()) { + $NextBlockID = $this->fread(2); + switch ($NextBlockID) { + case 'SZ': + // Note that szip files can be concatenated, this has the same effect as + // concatenating the files. this also means that global header blocks + // might be present between directory/data blocks. + $this->fseek(4, SEEK_CUR); + break; - $BHdataArray['filename'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00")); - $BHheaderoffset += (strlen($BHdataArray['filename']) + 1); + case 'BH': + $BHheaderbytes = getid3_lib::BigEndian2Int($this->fread(3)); + $BHheaderdata = $this->fread($BHheaderbytes); + $BHheaderoffset = 0; + while (strpos($BHheaderdata, "\x00", $BHheaderoffset) > 0) { + //filename as \0 terminated string (empty string indicates end) + //owner as \0 terminated string (empty is same as last file) + //group as \0 terminated string (empty is same as last file) + //3 byte filelength in this block + //2 byte access flags + //4 byte creation time (like in unix) + //4 byte modification time (like in unix) + //4 byte access time (like in unix) - $BHdataArray['owner'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00")); - $BHheaderoffset += (strlen($BHdataArray['owner']) + 1); + $BHdataArray['filename'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00")); + $BHheaderoffset += (strlen($BHdataArray['filename']) + 1); - $BHdataArray['group'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00")); - $BHheaderoffset += (strlen($BHdataArray['group']) + 1); + $BHdataArray['owner'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00")); + $BHheaderoffset += (strlen($BHdataArray['owner']) + 1); - $BHdataArray['filelength'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 3)); - $BHheaderoffset += 3; + $BHdataArray['group'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00")); + $BHheaderoffset += (strlen($BHdataArray['group']) + 1); - $BHdataArray['access_flags'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 2)); - $BHheaderoffset += 2; + $BHdataArray['filelength'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 3)); + $BHheaderoffset += 3; - $BHdataArray['creation_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); - $BHheaderoffset += 4; + $BHdataArray['access_flags'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 2)); + $BHheaderoffset += 2; - $BHdataArray['modification_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); - $BHheaderoffset += 4; + $BHdataArray['creation_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); + $BHheaderoffset += 4; - $BHdataArray['access_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); - $BHheaderoffset += 4; + $BHdataArray['modification_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); + $BHheaderoffset += 4; - $info['szip']['BH'][] = $BHdataArray; - } - break; + $BHdataArray['access_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); + $BHheaderoffset += 4; - default: - break 2; - } - } + $info['szip']['BH'][] = $BHdataArray; + } + break; - return true; - - } + default: + break 2; + } + } + return true; + } } diff --git a/app/Library/getid3/getid3/module.archive.tar.php b/app/Library/getid3/getid3/module.archive.tar.php index 9e8d72a2..2aaa9300 100644 --- a/app/Library/getid3/getid3/module.archive.tar.php +++ b/app/Library/getid3/getid3/module.archive.tar.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -19,159 +20,184 @@ // // ///////////////////////////////////////////////////////////////// - class getid3_tar extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $info['fileformat'] = 'tar'; + $info['tar']['files'] = []; - $info['fileformat'] = 'tar'; - $info['tar']['files'] = array(); + $unpack_header = 'a100fname/a8mode/a8uid/a8gid/a12size/a12mtime/a8chksum/a1typflag/a100lnkname/a6magic/a2ver/a32uname/a32gname/a8devmaj/a8devmin/a155prefix'; + $null_512k = str_repeat("\x00", 512); // end-of-file marker - $unpack_header = 'a100fname/a8mode/a8uid/a8gid/a12size/a12mtime/a8chksum/a1typflag/a100lnkname/a6magic/a2ver/a32uname/a32gname/a8devmaj/a8devmin/a155prefix'; - $null_512k = str_repeat("\x00", 512); // end-of-file marker + $this->fseek(0); + while (! feof($this->getid3->fp)) { + $buffer = $this->fread(512); + if (strlen($buffer) < 512) { + break; + } - $this->fseek(0); - while (!feof($this->getid3->fp)) { - $buffer = $this->fread(512); - if (strlen($buffer) < 512) { - break; - } + // check the block + $checksum = 0; + for ($i = 0; $i < 148; $i++) { + $checksum += ord($buffer[$i]); + } + for ($i = 148; $i < 156; $i++) { + $checksum += ord(' '); + } + for ($i = 156; $i < 512; $i++) { + $checksum += ord($buffer[$i]); + } + $attr = unpack($unpack_header, $buffer); + $name = (isset($attr['fname']) ? trim($attr['fname']) : ''); + $mode = octdec(isset($attr['mode']) ? trim($attr['mode']) : ''); + $uid = octdec(isset($attr['uid']) ? trim($attr['uid']) : ''); + $gid = octdec(isset($attr['gid']) ? trim($attr['gid']) : ''); + $size = octdec(isset($attr['size']) ? trim($attr['size']) : ''); + $mtime = octdec(isset($attr['mtime']) ? trim($attr['mtime']) : ''); + $chksum = octdec(isset($attr['chksum']) ? trim($attr['chksum']) : ''); + $typflag = (isset($attr['typflag']) ? trim($attr['typflag']) : ''); + $lnkname = (isset($attr['lnkname']) ? trim($attr['lnkname']) : ''); + $magic = (isset($attr['magic']) ? trim($attr['magic']) : ''); + $ver = (isset($attr['ver']) ? trim($attr['ver']) : ''); + $uname = (isset($attr['uname']) ? trim($attr['uname']) : ''); + $gname = (isset($attr['gname']) ? trim($attr['gname']) : ''); + $devmaj = octdec(isset($attr['devmaj']) ? trim($attr['devmaj']) : ''); + $devmin = octdec(isset($attr['devmin']) ? trim($attr['devmin']) : ''); + $prefix = (isset($attr['prefix']) ? trim($attr['prefix']) : ''); + if (($checksum == 256) && ($chksum == 0)) { + // EOF Found + break; + } + if ($prefix) { + $name = $prefix.'/'.$name; + } + if ((preg_match('#/$#', $name)) && ! $name) { + $typeflag = 5; + } + if ($buffer == $null_512k) { + // it's the end of the tar-file... + break; + } - // check the block - $checksum = 0; - for ($i = 0; $i < 148; $i++) { - $checksum += ord($buffer{$i}); - } - for ($i = 148; $i < 156; $i++) { - $checksum += ord(' '); - } - for ($i = 156; $i < 512; $i++) { - $checksum += ord($buffer{$i}); - } - $attr = unpack($unpack_header, $buffer); - $name = (isset($attr['fname'] ) ? trim($attr['fname'] ) : ''); - $mode = octdec(isset($attr['mode'] ) ? trim($attr['mode'] ) : ''); - $uid = octdec(isset($attr['uid'] ) ? trim($attr['uid'] ) : ''); - $gid = octdec(isset($attr['gid'] ) ? trim($attr['gid'] ) : ''); - $size = octdec(isset($attr['size'] ) ? trim($attr['size'] ) : ''); - $mtime = octdec(isset($attr['mtime'] ) ? trim($attr['mtime'] ) : ''); - $chksum = octdec(isset($attr['chksum'] ) ? trim($attr['chksum'] ) : ''); - $typflag = (isset($attr['typflag']) ? trim($attr['typflag']) : ''); - $lnkname = (isset($attr['lnkname']) ? trim($attr['lnkname']) : ''); - $magic = (isset($attr['magic'] ) ? trim($attr['magic'] ) : ''); - $ver = (isset($attr['ver'] ) ? trim($attr['ver'] ) : ''); - $uname = (isset($attr['uname'] ) ? trim($attr['uname'] ) : ''); - $gname = (isset($attr['gname'] ) ? trim($attr['gname'] ) : ''); - $devmaj = octdec(isset($attr['devmaj'] ) ? trim($attr['devmaj'] ) : ''); - $devmin = octdec(isset($attr['devmin'] ) ? trim($attr['devmin'] ) : ''); - $prefix = (isset($attr['prefix'] ) ? trim($attr['prefix'] ) : ''); - if (($checksum == 256) && ($chksum == 0)) { - // EOF Found - break; - } - if ($prefix) { - $name = $prefix.'/'.$name; - } - if ((preg_match('#/$#', $name)) && !$name) { - $typeflag = 5; - } - if ($buffer == $null_512k) { - // it's the end of the tar-file... - break; - } + // Read to the next chunk + $this->fseek($size, SEEK_CUR); - // Read to the next chunk - $this->fseek($size, SEEK_CUR); + $diff = $size % 512; + if ($diff != 0) { + // Padding, throw away + $this->fseek((512 - $diff), SEEK_CUR); + } + // Protect against tar-files with garbage at the end + if ($name == '') { + break; + } + $info['tar']['file_details'][$name] = [ + 'name' => $name, + 'mode_raw' => $mode, + 'mode' => self::display_perms($mode), + 'uid' => $uid, + 'gid' => $gid, + 'size' => $size, + 'mtime' => $mtime, + 'chksum' => $chksum, + 'typeflag' => self::get_flag_type($typflag), + 'linkname' => $lnkname, + 'magic' => $magic, + 'version' => $ver, + 'uname' => $uname, + 'gname' => $gname, + 'devmajor' => $devmaj, + 'devminor' => $devmin, + ]; + $info['tar']['files'] = getid3_lib::array_merge_clobber($info['tar']['files'], getid3_lib::CreateDeepArray($info['tar']['file_details'][$name]['name'], '/', $size)); + } - $diff = $size % 512; - if ($diff != 0) { - // Padding, throw away - $this->fseek((512 - $diff), SEEK_CUR); - } - // Protect against tar-files with garbage at the end - if ($name == '') { - break; - } - $info['tar']['file_details'][$name] = array ( - 'name' => $name, - 'mode_raw' => $mode, - 'mode' => self::display_perms($mode), - 'uid' => $uid, - 'gid' => $gid, - 'size' => $size, - 'mtime' => $mtime, - 'chksum' => $chksum, - 'typeflag' => self::get_flag_type($typflag), - 'linkname' => $lnkname, - 'magic' => $magic, - 'version' => $ver, - 'uname' => $uname, - 'gname' => $gname, - 'devmajor' => $devmaj, - 'devminor' => $devmin - ); - $info['tar']['files'] = getid3_lib::array_merge_clobber($info['tar']['files'], getid3_lib::CreateDeepArray($info['tar']['file_details'][$name]['name'], '/', $size)); - } - return true; - } + return true; + } - // Parses the file mode to file permissions - public function display_perms($mode) { - // Determine Type - if ($mode & 0x1000) $type='p'; // FIFO pipe - elseif ($mode & 0x2000) $type='c'; // Character special - elseif ($mode & 0x4000) $type='d'; // Directory - elseif ($mode & 0x6000) $type='b'; // Block special - elseif ($mode & 0x8000) $type='-'; // Regular - elseif ($mode & 0xA000) $type='l'; // Symbolic Link - elseif ($mode & 0xC000) $type='s'; // Socket - else $type='u'; // UNKNOWN + // Parses the file mode to file permissions + public function display_perms($mode) + { + // Determine Type + if ($mode & 0x1000) { + $type = 'p'; + } // FIFO pipe + elseif ($mode & 0x2000) { + $type = 'c'; + } // Character special + elseif ($mode & 0x4000) { + $type = 'd'; + } // Directory + elseif ($mode & 0x6000) { + $type = 'b'; + } // Block special + elseif ($mode & 0x8000) { + $type = '-'; + } // Regular + elseif ($mode & 0xA000) { + $type = 'l'; + } // Symbolic Link + elseif ($mode & 0xC000) { + $type = 's'; + } // Socket + else { + $type = 'u'; + } // UNKNOWN - // Determine permissions - $owner['read'] = (($mode & 00400) ? 'r' : '-'); - $owner['write'] = (($mode & 00200) ? 'w' : '-'); - $owner['execute'] = (($mode & 00100) ? 'x' : '-'); - $group['read'] = (($mode & 00040) ? 'r' : '-'); - $group['write'] = (($mode & 00020) ? 'w' : '-'); - $group['execute'] = (($mode & 00010) ? 'x' : '-'); - $world['read'] = (($mode & 00004) ? 'r' : '-'); - $world['write'] = (($mode & 00002) ? 'w' : '-'); - $world['execute'] = (($mode & 00001) ? 'x' : '-'); + // Determine permissions + $owner['read'] = (($mode & 00400) ? 'r' : '-'); + $owner['write'] = (($mode & 00200) ? 'w' : '-'); + $owner['execute'] = (($mode & 00100) ? 'x' : '-'); + $group['read'] = (($mode & 00040) ? 'r' : '-'); + $group['write'] = (($mode & 00020) ? 'w' : '-'); + $group['execute'] = (($mode & 00010) ? 'x' : '-'); + $world['read'] = (($mode & 00004) ? 'r' : '-'); + $world['write'] = (($mode & 00002) ? 'w' : '-'); + $world['execute'] = (($mode & 00001) ? 'x' : '-'); - // Adjust for SUID, SGID and sticky bit - if ($mode & 0x800) $owner['execute'] = ($owner['execute'] == 'x') ? 's' : 'S'; - if ($mode & 0x400) $group['execute'] = ($group['execute'] == 'x') ? 's' : 'S'; - if ($mode & 0x200) $world['execute'] = ($world['execute'] == 'x') ? 't' : 'T'; + // Adjust for SUID, SGID and sticky bit + if ($mode & 0x800) { + $owner['execute'] = ($owner['execute'] == 'x') ? 's' : 'S'; + } + if ($mode & 0x400) { + $group['execute'] = ($group['execute'] == 'x') ? 's' : 'S'; + } + if ($mode & 0x200) { + $world['execute'] = ($world['execute'] == 'x') ? 't' : 'T'; + } - $s = sprintf('%1s', $type); - $s .= sprintf('%1s%1s%1s', $owner['read'], $owner['write'], $owner['execute']); - $s .= sprintf('%1s%1s%1s', $group['read'], $group['write'], $group['execute']); - $s .= sprintf('%1s%1s%1s'."\n", $world['read'], $world['write'], $world['execute']); - return $s; - } + $s = sprintf('%1s', $type); + $s .= sprintf('%1s%1s%1s', $owner['read'], $owner['write'], $owner['execute']); + $s .= sprintf('%1s%1s%1s', $group['read'], $group['write'], $group['execute']); + $s .= sprintf('%1s%1s%1s'."\n", $world['read'], $world['write'], $world['execute']); - // Converts the file type - public function get_flag_type($typflag) { - static $flag_types = array( - '0' => 'LF_NORMAL', - '1' => 'LF_LINK', - '2' => 'LF_SYNLINK', - '3' => 'LF_CHR', - '4' => 'LF_BLK', - '5' => 'LF_DIR', - '6' => 'LF_FIFO', - '7' => 'LF_CONFIG', - 'D' => 'LF_DUMPDIR', - 'K' => 'LF_LONGLINK', - 'L' => 'LF_LONGNAME', - 'M' => 'LF_MULTIVOL', - 'N' => 'LF_NAMES', - 'S' => 'LF_SPARSE', - 'V' => 'LF_VOLHDR' - ); - return (isset($flag_types[$typflag]) ? $flag_types[$typflag] : ''); - } + return $s; + } + // Converts the file type + public function get_flag_type($typflag) + { + static $flag_types = [ + '0' => 'LF_NORMAL', + '1' => 'LF_LINK', + '2' => 'LF_SYNLINK', + '3' => 'LF_CHR', + '4' => 'LF_BLK', + '5' => 'LF_DIR', + '6' => 'LF_FIFO', + '7' => 'LF_CONFIG', + 'D' => 'LF_DUMPDIR', + 'K' => 'LF_LONGLINK', + 'L' => 'LF_LONGNAME', + 'M' => 'LF_MULTIVOL', + 'N' => 'LF_NAMES', + 'S' => 'LF_SPARSE', + 'V' => 'LF_VOLHDR', + ]; + + return isset($flag_types[$typflag]) ? $flag_types[$typflag] : ''; + } } diff --git a/app/Library/getid3/getid3/module.archive.zip.php b/app/Library/getid3/getid3/module.archive.zip.php index 4b7aa583..72868eab 100644 --- a/app/Library/getid3/getid3/module.archive.zip.php +++ b/app/Library/getid3/getid3/module.archive.zip.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,500 +15,511 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_zip extends getid3_handler { - - public function Analyze() { - $info = &$this->getid3->info; - - $info['fileformat'] = 'zip'; - $info['zip']['encoding'] = 'ISO-8859-1'; - $info['zip']['files'] = array(); - - $info['zip']['compressed_size'] = 0; - $info['zip']['uncompressed_size'] = 0; - $info['zip']['entries_count'] = 0; - - if (!getid3_lib::intValueSupported($info['filesize'])) { - $this->error('File is larger than '.round(PHP_INT_MAX / 1073741824).'GB, not supported by PHP'); - return false; - } else { - $EOCDsearchData = ''; - $EOCDsearchCounter = 0; - while ($EOCDsearchCounter++ < 512) { - - $this->fseek(-128 * $EOCDsearchCounter, SEEK_END); - $EOCDsearchData = $this->fread(128).$EOCDsearchData; - - if (strstr($EOCDsearchData, 'PK'."\x05\x06")) { - - $EOCDposition = strpos($EOCDsearchData, 'PK'."\x05\x06"); - $this->fseek((-128 * $EOCDsearchCounter) + $EOCDposition, SEEK_END); - $info['zip']['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory(); - - $this->fseek($info['zip']['end_central_directory']['directory_offset']); - $info['zip']['entries_count'] = 0; - while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($this->getid3->fp)) { - $info['zip']['central_directory'][] = $centraldirectoryentry; - $info['zip']['entries_count']++; - $info['zip']['compressed_size'] += $centraldirectoryentry['compressed_size']; - $info['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size']; - - //if ($centraldirectoryentry['uncompressed_size'] > 0) { zero-byte files are valid - if (!empty($centraldirectoryentry['filename'])) { - $info['zip']['files'] = getid3_lib::array_merge_clobber($info['zip']['files'], getid3_lib::CreateDeepArray($centraldirectoryentry['filename'], '/', $centraldirectoryentry['uncompressed_size'])); - } - } - - if ($info['zip']['entries_count'] == 0) { - $this->error('No Central Directory entries found (truncated file?)'); - return false; - } - - if (!empty($info['zip']['end_central_directory']['comment'])) { - $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment']; - } - - if (isset($info['zip']['central_directory'][0]['compression_method'])) { - $info['zip']['compression_method'] = $info['zip']['central_directory'][0]['compression_method']; - } - if (isset($info['zip']['central_directory'][0]['flags']['compression_speed'])) { - $info['zip']['compression_speed'] = $info['zip']['central_directory'][0]['flags']['compression_speed']; - } - if (isset($info['zip']['compression_method']) && ($info['zip']['compression_method'] == 'store') && !isset($info['zip']['compression_speed'])) { - $info['zip']['compression_speed'] = 'store'; - } - - // secondary check - we (should) already have all the info we NEED from the Central Directory above, but scanning each - // Local File Header entry will - foreach ($info['zip']['central_directory'] as $central_directory_entry) { - $this->fseek($central_directory_entry['entry_offset']); - if ($fileentry = $this->ZIPparseLocalFileHeader()) { - $info['zip']['entries'][] = $fileentry; - } else { - $this->warning('Error parsing Local File Header at offset '.$central_directory_entry['entry_offset']); - } - } - - if (!empty($info['zip']['files']['[Content_Types].xml']) && - !empty($info['zip']['files']['_rels']['.rels']) && - !empty($info['zip']['files']['docProps']['app.xml']) && - !empty($info['zip']['files']['docProps']['core.xml'])) { - // http://technet.microsoft.com/en-us/library/cc179224.aspx - $info['fileformat'] = 'zip.msoffice'; - if (!empty($ThisFileInfo['zip']['files']['ppt'])) { - $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; - } elseif (!empty($ThisFileInfo['zip']['files']['xl'])) { - $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; - } elseif (!empty($ThisFileInfo['zip']['files']['word'])) { - $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; - } - } - - return true; - } - } - } - - if (!$this->getZIPentriesFilepointer()) { - unset($info['zip']); - $info['fileformat'] = ''; - $this->error('Cannot find End Of Central Directory (truncated file?)'); - return false; - } - - // central directory couldn't be found and/or parsed - // scan through actual file data entries, recover as much as possible from probable trucated file - if ($info['zip']['compressed_size'] > ($info['filesize'] - 46 - 22)) { - $this->error('Warning: Truncated file! - Total compressed file sizes ('.$info['zip']['compressed_size'].' bytes) is greater than filesize minus Central Directory and End Of Central Directory structures ('.($info['filesize'] - 46 - 22).' bytes)'); - } - $this->error('Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete'); - foreach ($info['zip']['entries'] as $key => $valuearray) { - $info['zip']['files'][$valuearray['filename']] = $valuearray['uncompressed_size']; - } - return true; - } - - - public function getZIPHeaderFilepointerTopDown() { - $info = &$this->getid3->info; - - $info['fileformat'] = 'zip'; - - $info['zip']['compressed_size'] = 0; - $info['zip']['uncompressed_size'] = 0; - $info['zip']['entries_count'] = 0; - - rewind($this->getid3->fp); - while ($fileentry = $this->ZIPparseLocalFileHeader()) { - $info['zip']['entries'][] = $fileentry; - $info['zip']['entries_count']++; - } - if ($info['zip']['entries_count'] == 0) { - $this->error('No Local File Header entries found'); - return false; - } - - $info['zip']['entries_count'] = 0; - while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($this->getid3->fp)) { - $info['zip']['central_directory'][] = $centraldirectoryentry; - $info['zip']['entries_count']++; - $info['zip']['compressed_size'] += $centraldirectoryentry['compressed_size']; - $info['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size']; - } - if ($info['zip']['entries_count'] == 0) { - $this->error('No Central Directory entries found (truncated file?)'); - return false; - } - - if ($EOCD = $this->ZIPparseEndOfCentralDirectory()) { - $info['zip']['end_central_directory'] = $EOCD; - } else { - $this->error('No End Of Central Directory entry found (truncated file?)'); - return false; - } - - if (!empty($info['zip']['end_central_directory']['comment'])) { - $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment']; - } - - return true; - } - - - public function getZIPentriesFilepointer() { - $info = &$this->getid3->info; - - $info['zip']['compressed_size'] = 0; - $info['zip']['uncompressed_size'] = 0; - $info['zip']['entries_count'] = 0; - - rewind($this->getid3->fp); - while ($fileentry = $this->ZIPparseLocalFileHeader()) { - $info['zip']['entries'][] = $fileentry; - $info['zip']['entries_count']++; - $info['zip']['compressed_size'] += $fileentry['compressed_size']; - $info['zip']['uncompressed_size'] += $fileentry['uncompressed_size']; - } - if ($info['zip']['entries_count'] == 0) { - $this->error('No Local File Header entries found'); - return false; - } - - return true; - } - - - public function ZIPparseLocalFileHeader() { - $LocalFileHeader['offset'] = $this->ftell(); - - $ZIPlocalFileHeader = $this->fread(30); - - $LocalFileHeader['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 0, 4)); - if ($LocalFileHeader['raw']['signature'] != 0x04034B50) { // "PK\x03\x04" - // invalid Local File Header Signature - $this->fseek($LocalFileHeader['offset']); // seek back to where filepointer originally was so it can be handled properly - return false; - } - $LocalFileHeader['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 4, 2)); - $LocalFileHeader['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 6, 2)); - $LocalFileHeader['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 8, 2)); - $LocalFileHeader['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 10, 2)); - $LocalFileHeader['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 12, 2)); - $LocalFileHeader['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 14, 4)); - $LocalFileHeader['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 18, 4)); - $LocalFileHeader['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 22, 4)); - $LocalFileHeader['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 26, 2)); - $LocalFileHeader['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 28, 2)); - - $LocalFileHeader['extract_version'] = sprintf('%1.1f', $LocalFileHeader['raw']['extract_version'] / 10); - $LocalFileHeader['host_os'] = $this->ZIPversionOSLookup(($LocalFileHeader['raw']['extract_version'] & 0xFF00) >> 8); - $LocalFileHeader['compression_method'] = $this->ZIPcompressionMethodLookup($LocalFileHeader['raw']['compression_method']); - $LocalFileHeader['compressed_size'] = $LocalFileHeader['raw']['compressed_size']; - $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['raw']['uncompressed_size']; - $LocalFileHeader['flags'] = $this->ZIPparseGeneralPurposeFlags($LocalFileHeader['raw']['general_flags'], $LocalFileHeader['raw']['compression_method']); - $LocalFileHeader['last_modified_timestamp'] = $this->DOStime2UNIXtime($LocalFileHeader['raw']['last_mod_file_date'], $LocalFileHeader['raw']['last_mod_file_time']); - - $FilenameExtrafieldLength = $LocalFileHeader['raw']['filename_length'] + $LocalFileHeader['raw']['extra_field_length']; - if ($FilenameExtrafieldLength > 0) { - $ZIPlocalFileHeader .= $this->fread($FilenameExtrafieldLength); - - if ($LocalFileHeader['raw']['filename_length'] > 0) { - $LocalFileHeader['filename'] = substr($ZIPlocalFileHeader, 30, $LocalFileHeader['raw']['filename_length']); - } - if ($LocalFileHeader['raw']['extra_field_length'] > 0) { - $LocalFileHeader['raw']['extra_field_data'] = substr($ZIPlocalFileHeader, 30 + $LocalFileHeader['raw']['filename_length'], $LocalFileHeader['raw']['extra_field_length']); - } - } - - if ($LocalFileHeader['compressed_size'] == 0) { - // *Could* be a zero-byte file - // But could also be a file written on the fly that didn't know compressed filesize beforehand. - // Correct compressed filesize should be in the data_descriptor located after this file data, and also in Central Directory (at end of zip file) - if (!empty($this->getid3->info['zip']['central_directory'])) { - foreach ($this->getid3->info['zip']['central_directory'] as $central_directory_entry) { - if ($central_directory_entry['entry_offset'] == $LocalFileHeader['offset']) { - if ($central_directory_entry['compressed_size'] > 0) { - // overwrite local zero value (but not ['raw']'compressed_size']) so that seeking for data_descriptor (and next file entry) works correctly - $LocalFileHeader['compressed_size'] = $central_directory_entry['compressed_size']; - } - break; - } - } - } - - } - $LocalFileHeader['data_offset'] = $this->ftell(); - $this->fseek($LocalFileHeader['compressed_size'], SEEK_CUR); // this should (but may not) match value in $LocalFileHeader['raw']['compressed_size'] -- $LocalFileHeader['compressed_size'] could have been overwritten above with value from Central Directory - - if ($LocalFileHeader['flags']['data_descriptor_used']) { - $DataDescriptor = $this->fread(16); - $LocalFileHeader['data_descriptor']['signature'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 0, 4)); - if ($LocalFileHeader['data_descriptor']['signature'] != 0x08074B50) { // "PK\x07\x08" - $this->getid3->warning[] = 'invalid Local File Header Data Descriptor Signature at offset '.($this->ftell() - 16).' - expecting 08 07 4B 50, found '.getid3_lib::PrintHexBytes($LocalFileHeader['data_descriptor']['signature']); - $this->fseek($LocalFileHeader['offset']); // seek back to where filepointer originally was so it can be handled properly - return false; - } - $LocalFileHeader['data_descriptor']['crc_32'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 4, 4)); - $LocalFileHeader['data_descriptor']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 8, 4)); - $LocalFileHeader['data_descriptor']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 12, 4)); - if (!$LocalFileHeader['raw']['compressed_size'] && $LocalFileHeader['data_descriptor']['compressed_size']) { - foreach ($this->getid3->info['zip']['central_directory'] as $central_directory_entry) { - if ($central_directory_entry['entry_offset'] == $LocalFileHeader['offset']) { - if ($LocalFileHeader['data_descriptor']['compressed_size'] == $central_directory_entry['compressed_size']) { - // $LocalFileHeader['compressed_size'] already set from Central Directory - } else { - $this->warning('conflicting compressed_size from data_descriptor ('.$LocalFileHeader['data_descriptor']['compressed_size'].') vs Central Directory ('.$central_directory_entry['compressed_size'].') for file at offset '.$LocalFileHeader['offset']); - } - - if ($LocalFileHeader['data_descriptor']['uncompressed_size'] == $central_directory_entry['uncompressed_size']) { - $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['data_descriptor']['uncompressed_size']; - } else { - $this->warning('conflicting uncompressed_size from data_descriptor ('.$LocalFileHeader['data_descriptor']['uncompressed_size'].') vs Central Directory ('.$central_directory_entry['uncompressed_size'].') for file at offset '.$LocalFileHeader['offset']); - } - break; - } - } - } - } - return $LocalFileHeader; - } - - - public function ZIPparseCentralDirectory() { - $CentralDirectory['offset'] = $this->ftell(); - - $ZIPcentralDirectory = $this->fread(46); - - $CentralDirectory['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 0, 4)); - if ($CentralDirectory['raw']['signature'] != 0x02014B50) { - // invalid Central Directory Signature - $this->fseek($CentralDirectory['offset']); // seek back to where filepointer originally was so it can be handled properly - return false; - } - $CentralDirectory['raw']['create_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 4, 2)); - $CentralDirectory['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 6, 2)); - $CentralDirectory['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 8, 2)); - $CentralDirectory['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 10, 2)); - $CentralDirectory['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 12, 2)); - $CentralDirectory['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 14, 2)); - $CentralDirectory['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 16, 4)); - $CentralDirectory['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 20, 4)); - $CentralDirectory['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 24, 4)); - $CentralDirectory['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 28, 2)); - $CentralDirectory['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 30, 2)); - $CentralDirectory['raw']['file_comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 32, 2)); - $CentralDirectory['raw']['disk_number_start'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 34, 2)); - $CentralDirectory['raw']['internal_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 36, 2)); - $CentralDirectory['raw']['external_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 38, 4)); - $CentralDirectory['raw']['local_header_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 42, 4)); - - $CentralDirectory['entry_offset'] = $CentralDirectory['raw']['local_header_offset']; - $CentralDirectory['create_version'] = sprintf('%1.1f', $CentralDirectory['raw']['create_version'] / 10); - $CentralDirectory['extract_version'] = sprintf('%1.1f', $CentralDirectory['raw']['extract_version'] / 10); - $CentralDirectory['host_os'] = $this->ZIPversionOSLookup(($CentralDirectory['raw']['extract_version'] & 0xFF00) >> 8); - $CentralDirectory['compression_method'] = $this->ZIPcompressionMethodLookup($CentralDirectory['raw']['compression_method']); - $CentralDirectory['compressed_size'] = $CentralDirectory['raw']['compressed_size']; - $CentralDirectory['uncompressed_size'] = $CentralDirectory['raw']['uncompressed_size']; - $CentralDirectory['flags'] = $this->ZIPparseGeneralPurposeFlags($CentralDirectory['raw']['general_flags'], $CentralDirectory['raw']['compression_method']); - $CentralDirectory['last_modified_timestamp'] = $this->DOStime2UNIXtime($CentralDirectory['raw']['last_mod_file_date'], $CentralDirectory['raw']['last_mod_file_time']); - - $FilenameExtrafieldCommentLength = $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'] + $CentralDirectory['raw']['file_comment_length']; - if ($FilenameExtrafieldCommentLength > 0) { - $FilenameExtrafieldComment = $this->fread($FilenameExtrafieldCommentLength); - - if ($CentralDirectory['raw']['filename_length'] > 0) { - $CentralDirectory['filename'] = substr($FilenameExtrafieldComment, 0, $CentralDirectory['raw']['filename_length']); - } - if ($CentralDirectory['raw']['extra_field_length'] > 0) { - $CentralDirectory['raw']['extra_field_data'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'], $CentralDirectory['raw']['extra_field_length']); - } - if ($CentralDirectory['raw']['file_comment_length'] > 0) { - $CentralDirectory['file_comment'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'], $CentralDirectory['raw']['file_comment_length']); - } - } - - return $CentralDirectory; - } - - public function ZIPparseEndOfCentralDirectory() { - $EndOfCentralDirectory['offset'] = $this->ftell(); - - $ZIPendOfCentralDirectory = $this->fread(22); - - $EndOfCentralDirectory['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 0, 4)); - if ($EndOfCentralDirectory['signature'] != 0x06054B50) { - // invalid End Of Central Directory Signature - $this->fseek($EndOfCentralDirectory['offset']); // seek back to where filepointer originally was so it can be handled properly - return false; - } - $EndOfCentralDirectory['disk_number_current'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 4, 2)); - $EndOfCentralDirectory['disk_number_start_directory'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 6, 2)); - $EndOfCentralDirectory['directory_entries_this_disk'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 8, 2)); - $EndOfCentralDirectory['directory_entries_total'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 10, 2)); - $EndOfCentralDirectory['directory_size'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 12, 4)); - $EndOfCentralDirectory['directory_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 16, 4)); - $EndOfCentralDirectory['comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 20, 2)); - - if ($EndOfCentralDirectory['comment_length'] > 0) { - $EndOfCentralDirectory['comment'] = $this->fread($EndOfCentralDirectory['comment_length']); - } - - return $EndOfCentralDirectory; - } - - - public static function ZIPparseGeneralPurposeFlags($flagbytes, $compressionmethod) { - // https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip-printable.html - $ParsedFlags['encrypted'] = (bool) ($flagbytes & 0x0001); - // 0x0002 -- see below - // 0x0004 -- see below - $ParsedFlags['data_descriptor_used'] = (bool) ($flagbytes & 0x0008); - $ParsedFlags['enhanced_deflation'] = (bool) ($flagbytes & 0x0010); - $ParsedFlags['compressed_patched_data'] = (bool) ($flagbytes & 0x0020); - $ParsedFlags['strong_encryption'] = (bool) ($flagbytes & 0x0040); - // 0x0080 - unused - // 0x0100 - unused - // 0x0200 - unused - // 0x0400 - unused - $ParsedFlags['language_encoding'] = (bool) ($flagbytes & 0x0800); - // 0x1000 - reserved - $ParsedFlags['mask_header_values'] = (bool) ($flagbytes & 0x2000); - // 0x4000 - reserved - // 0x8000 - reserved - - switch ($compressionmethod) { - case 6: - $ParsedFlags['dictionary_size'] = (($flagbytes & 0x0002) ? 8192 : 4096); - $ParsedFlags['shannon_fano_trees'] = (($flagbytes & 0x0004) ? 3 : 2); - break; - - case 8: - case 9: - switch (($flagbytes & 0x0006) >> 1) { - case 0: - $ParsedFlags['compression_speed'] = 'normal'; - break; - case 1: - $ParsedFlags['compression_speed'] = 'maximum'; - break; - case 2: - $ParsedFlags['compression_speed'] = 'fast'; - break; - case 3: - $ParsedFlags['compression_speed'] = 'superfast'; - break; - } - break; - } - - return $ParsedFlags; - } - - - public static function ZIPversionOSLookup($index) { - static $ZIPversionOSLookup = array( - 0 => 'MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)', - 1 => 'Amiga', - 2 => 'OpenVMS', - 3 => 'Unix', - 4 => 'VM/CMS', - 5 => 'Atari ST', - 6 => 'OS/2 H.P.F.S.', - 7 => 'Macintosh', - 8 => 'Z-System', - 9 => 'CP/M', - 10 => 'Windows NTFS', - 11 => 'MVS', - 12 => 'VSE', - 13 => 'Acorn Risc', - 14 => 'VFAT', - 15 => 'Alternate MVS', - 16 => 'BeOS', - 17 => 'Tandem', - 18 => 'OS/400', - 19 => 'OS/X (Darwin)', - ); - - return (isset($ZIPversionOSLookup[$index]) ? $ZIPversionOSLookup[$index] : '[unknown]'); - } - - public static function ZIPcompressionMethodLookup($index) { - // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/ZIP.html - static $ZIPcompressionMethodLookup = array( - 0 => 'store', - 1 => 'shrink', - 2 => 'reduce-1', - 3 => 'reduce-2', - 4 => 'reduce-3', - 5 => 'reduce-4', - 6 => 'implode', - 7 => 'tokenize', - 8 => 'deflate', - 9 => 'deflate64', - 10 => 'Imploded (old IBM TERSE)', - 11 => 'RESERVED[11]', - 12 => 'BZIP2', - 13 => 'RESERVED[13]', - 14 => 'LZMA (EFS)', - 15 => 'RESERVED[15]', - 16 => 'RESERVED[16]', - 17 => 'RESERVED[17]', - 18 => 'IBM TERSE (new)', - 19 => 'IBM LZ77 z Architecture (PFS)', - 96 => 'JPEG recompressed', - 97 => 'WavPack compressed', - 98 => 'PPMd version I, Rev 1', - ); - - return (isset($ZIPcompressionMethodLookup[$index]) ? $ZIPcompressionMethodLookup[$index] : '[unknown]'); - } - - public static function DOStime2UNIXtime($DOSdate, $DOStime) { - // wFatDate - // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format: - // Bits Contents - // 0-4 Day of the month (1-31) - // 5-8 Month (1 = January, 2 = February, and so on) - // 9-15 Year offset from 1980 (add 1980 to get actual year) - - $UNIXday = ($DOSdate & 0x001F); - $UNIXmonth = (($DOSdate & 0x01E0) >> 5); - $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980; - - // wFatTime - // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format: - // Bits Contents - // 0-4 Second divided by 2 - // 5-10 Minute (0-59) - // 11-15 Hour (0-23 on a 24-hour clock) - - $UNIXsecond = ($DOStime & 0x001F) * 2; - $UNIXminute = (($DOStime & 0x07E0) >> 5); - $UNIXhour = (($DOStime & 0xF800) >> 11); - - return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear); - } - + public function Analyze() + { + $info = &$this->getid3->info; + + $info['fileformat'] = 'zip'; + $info['zip']['encoding'] = 'ISO-8859-1'; + $info['zip']['files'] = []; + + $info['zip']['compressed_size'] = 0; + $info['zip']['uncompressed_size'] = 0; + $info['zip']['entries_count'] = 0; + + if (! getid3_lib::intValueSupported($info['filesize'])) { + $this->error('File is larger than '.round(PHP_INT_MAX / 1073741824).'GB, not supported by PHP'); + + return false; + } else { + $EOCDsearchData = ''; + $EOCDsearchCounter = 0; + while ($EOCDsearchCounter++ < 512) { + $this->fseek(-128 * $EOCDsearchCounter, SEEK_END); + $EOCDsearchData = $this->fread(128).$EOCDsearchData; + + if (strstr($EOCDsearchData, 'PK'."\x05\x06")) { + $EOCDposition = strpos($EOCDsearchData, 'PK'."\x05\x06"); + $this->fseek((-128 * $EOCDsearchCounter) + $EOCDposition, SEEK_END); + $info['zip']['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory(); + + $this->fseek($info['zip']['end_central_directory']['directory_offset']); + $info['zip']['entries_count'] = 0; + while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($this->getid3->fp)) { + $info['zip']['central_directory'][] = $centraldirectoryentry; + $info['zip']['entries_count']++; + $info['zip']['compressed_size'] += $centraldirectoryentry['compressed_size']; + $info['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size']; + + //if ($centraldirectoryentry['uncompressed_size'] > 0) { zero-byte files are valid + if (! empty($centraldirectoryentry['filename'])) { + $info['zip']['files'] = getid3_lib::array_merge_clobber($info['zip']['files'], getid3_lib::CreateDeepArray($centraldirectoryentry['filename'], '/', $centraldirectoryentry['uncompressed_size'])); + } + } + + if ($info['zip']['entries_count'] == 0) { + $this->error('No Central Directory entries found (truncated file?)'); + + return false; + } + + if (! empty($info['zip']['end_central_directory']['comment'])) { + $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment']; + } + + if (isset($info['zip']['central_directory'][0]['compression_method'])) { + $info['zip']['compression_method'] = $info['zip']['central_directory'][0]['compression_method']; + } + if (isset($info['zip']['central_directory'][0]['flags']['compression_speed'])) { + $info['zip']['compression_speed'] = $info['zip']['central_directory'][0]['flags']['compression_speed']; + } + if (isset($info['zip']['compression_method']) && ($info['zip']['compression_method'] == 'store') && ! isset($info['zip']['compression_speed'])) { + $info['zip']['compression_speed'] = 'store'; + } + + // secondary check - we (should) already have all the info we NEED from the Central Directory above, but scanning each + // Local File Header entry will + foreach ($info['zip']['central_directory'] as $central_directory_entry) { + $this->fseek($central_directory_entry['entry_offset']); + if ($fileentry = $this->ZIPparseLocalFileHeader()) { + $info['zip']['entries'][] = $fileentry; + } else { + $this->warning('Error parsing Local File Header at offset '.$central_directory_entry['entry_offset']); + } + } + + if (! empty($info['zip']['files']['[Content_Types].xml']) && + ! empty($info['zip']['files']['_rels']['.rels']) && + ! empty($info['zip']['files']['docProps']['app.xml']) && + ! empty($info['zip']['files']['docProps']['core.xml'])) { + // http://technet.microsoft.com/en-us/library/cc179224.aspx + $info['fileformat'] = 'zip.msoffice'; + if (! empty($ThisFileInfo['zip']['files']['ppt'])) { + $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; + } elseif (! empty($ThisFileInfo['zip']['files']['xl'])) { + $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + } elseif (! empty($ThisFileInfo['zip']['files']['word'])) { + $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; + } + } + + return true; + } + } + } + + if (! $this->getZIPentriesFilepointer()) { + unset($info['zip']); + $info['fileformat'] = ''; + $this->error('Cannot find End Of Central Directory (truncated file?)'); + + return false; + } + + // central directory couldn't be found and/or parsed + // scan through actual file data entries, recover as much as possible from probable trucated file + if ($info['zip']['compressed_size'] > ($info['filesize'] - 46 - 22)) { + $this->error('Warning: Truncated file! - Total compressed file sizes ('.$info['zip']['compressed_size'].' bytes) is greater than filesize minus Central Directory and End Of Central Directory structures ('.($info['filesize'] - 46 - 22).' bytes)'); + } + $this->error('Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete'); + foreach ($info['zip']['entries'] as $key => $valuearray) { + $info['zip']['files'][$valuearray['filename']] = $valuearray['uncompressed_size']; + } + + return true; + } + + public function getZIPHeaderFilepointerTopDown() + { + $info = &$this->getid3->info; + + $info['fileformat'] = 'zip'; + + $info['zip']['compressed_size'] = 0; + $info['zip']['uncompressed_size'] = 0; + $info['zip']['entries_count'] = 0; + + rewind($this->getid3->fp); + while ($fileentry = $this->ZIPparseLocalFileHeader()) { + $info['zip']['entries'][] = $fileentry; + $info['zip']['entries_count']++; + } + if ($info['zip']['entries_count'] == 0) { + $this->error('No Local File Header entries found'); + + return false; + } + + $info['zip']['entries_count'] = 0; + while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($this->getid3->fp)) { + $info['zip']['central_directory'][] = $centraldirectoryentry; + $info['zip']['entries_count']++; + $info['zip']['compressed_size'] += $centraldirectoryentry['compressed_size']; + $info['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size']; + } + if ($info['zip']['entries_count'] == 0) { + $this->error('No Central Directory entries found (truncated file?)'); + + return false; + } + + if ($EOCD = $this->ZIPparseEndOfCentralDirectory()) { + $info['zip']['end_central_directory'] = $EOCD; + } else { + $this->error('No End Of Central Directory entry found (truncated file?)'); + + return false; + } + + if (! empty($info['zip']['end_central_directory']['comment'])) { + $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment']; + } + + return true; + } + + public function getZIPentriesFilepointer() + { + $info = &$this->getid3->info; + + $info['zip']['compressed_size'] = 0; + $info['zip']['uncompressed_size'] = 0; + $info['zip']['entries_count'] = 0; + + rewind($this->getid3->fp); + while ($fileentry = $this->ZIPparseLocalFileHeader()) { + $info['zip']['entries'][] = $fileentry; + $info['zip']['entries_count']++; + $info['zip']['compressed_size'] += $fileentry['compressed_size']; + $info['zip']['uncompressed_size'] += $fileentry['uncompressed_size']; + } + if ($info['zip']['entries_count'] == 0) { + $this->error('No Local File Header entries found'); + + return false; + } + + return true; + } + + public function ZIPparseLocalFileHeader() + { + $LocalFileHeader['offset'] = $this->ftell(); + + $ZIPlocalFileHeader = $this->fread(30); + + $LocalFileHeader['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 0, 4)); + if ($LocalFileHeader['raw']['signature'] != 0x04034B50) { // "PK\x03\x04" + // invalid Local File Header Signature + $this->fseek($LocalFileHeader['offset']); // seek back to where filepointer originally was so it can be handled properly + + return false; + } + $LocalFileHeader['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 4, 2)); + $LocalFileHeader['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 6, 2)); + $LocalFileHeader['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 8, 2)); + $LocalFileHeader['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 10, 2)); + $LocalFileHeader['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 12, 2)); + $LocalFileHeader['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 14, 4)); + $LocalFileHeader['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 18, 4)); + $LocalFileHeader['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 22, 4)); + $LocalFileHeader['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 26, 2)); + $LocalFileHeader['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 28, 2)); + + $LocalFileHeader['extract_version'] = sprintf('%1.1f', $LocalFileHeader['raw']['extract_version'] / 10); + $LocalFileHeader['host_os'] = $this->ZIPversionOSLookup(($LocalFileHeader['raw']['extract_version'] & 0xFF00) >> 8); + $LocalFileHeader['compression_method'] = $this->ZIPcompressionMethodLookup($LocalFileHeader['raw']['compression_method']); + $LocalFileHeader['compressed_size'] = $LocalFileHeader['raw']['compressed_size']; + $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['raw']['uncompressed_size']; + $LocalFileHeader['flags'] = $this->ZIPparseGeneralPurposeFlags($LocalFileHeader['raw']['general_flags'], $LocalFileHeader['raw']['compression_method']); + $LocalFileHeader['last_modified_timestamp'] = $this->DOStime2UNIXtime($LocalFileHeader['raw']['last_mod_file_date'], $LocalFileHeader['raw']['last_mod_file_time']); + + $FilenameExtrafieldLength = $LocalFileHeader['raw']['filename_length'] + $LocalFileHeader['raw']['extra_field_length']; + if ($FilenameExtrafieldLength > 0) { + $ZIPlocalFileHeader .= $this->fread($FilenameExtrafieldLength); + + if ($LocalFileHeader['raw']['filename_length'] > 0) { + $LocalFileHeader['filename'] = substr($ZIPlocalFileHeader, 30, $LocalFileHeader['raw']['filename_length']); + } + if ($LocalFileHeader['raw']['extra_field_length'] > 0) { + $LocalFileHeader['raw']['extra_field_data'] = substr($ZIPlocalFileHeader, 30 + $LocalFileHeader['raw']['filename_length'], $LocalFileHeader['raw']['extra_field_length']); + } + } + + if ($LocalFileHeader['compressed_size'] == 0) { + // *Could* be a zero-byte file + // But could also be a file written on the fly that didn't know compressed filesize beforehand. + // Correct compressed filesize should be in the data_descriptor located after this file data, and also in Central Directory (at end of zip file) + if (! empty($this->getid3->info['zip']['central_directory'])) { + foreach ($this->getid3->info['zip']['central_directory'] as $central_directory_entry) { + if ($central_directory_entry['entry_offset'] == $LocalFileHeader['offset']) { + if ($central_directory_entry['compressed_size'] > 0) { + // overwrite local zero value (but not ['raw']'compressed_size']) so that seeking for data_descriptor (and next file entry) works correctly + $LocalFileHeader['compressed_size'] = $central_directory_entry['compressed_size']; + } + break; + } + } + } + } + $LocalFileHeader['data_offset'] = $this->ftell(); + $this->fseek($LocalFileHeader['compressed_size'], SEEK_CUR); // this should (but may not) match value in $LocalFileHeader['raw']['compressed_size'] -- $LocalFileHeader['compressed_size'] could have been overwritten above with value from Central Directory + + if ($LocalFileHeader['flags']['data_descriptor_used']) { + $DataDescriptor = $this->fread(16); + $LocalFileHeader['data_descriptor']['signature'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 0, 4)); + if ($LocalFileHeader['data_descriptor']['signature'] != 0x08074B50) { // "PK\x07\x08" + $this->getid3->warning[] = 'invalid Local File Header Data Descriptor Signature at offset '.($this->ftell() - 16).' - expecting 08 07 4B 50, found '.getid3_lib::PrintHexBytes($LocalFileHeader['data_descriptor']['signature']); + $this->fseek($LocalFileHeader['offset']); // seek back to where filepointer originally was so it can be handled properly + + return false; + } + $LocalFileHeader['data_descriptor']['crc_32'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 4, 4)); + $LocalFileHeader['data_descriptor']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 8, 4)); + $LocalFileHeader['data_descriptor']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 12, 4)); + if (! $LocalFileHeader['raw']['compressed_size'] && $LocalFileHeader['data_descriptor']['compressed_size']) { + foreach ($this->getid3->info['zip']['central_directory'] as $central_directory_entry) { + if ($central_directory_entry['entry_offset'] == $LocalFileHeader['offset']) { + if ($LocalFileHeader['data_descriptor']['compressed_size'] == $central_directory_entry['compressed_size']) { + // $LocalFileHeader['compressed_size'] already set from Central Directory + } else { + $this->warning('conflicting compressed_size from data_descriptor ('.$LocalFileHeader['data_descriptor']['compressed_size'].') vs Central Directory ('.$central_directory_entry['compressed_size'].') for file at offset '.$LocalFileHeader['offset']); + } + + if ($LocalFileHeader['data_descriptor']['uncompressed_size'] == $central_directory_entry['uncompressed_size']) { + $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['data_descriptor']['uncompressed_size']; + } else { + $this->warning('conflicting uncompressed_size from data_descriptor ('.$LocalFileHeader['data_descriptor']['uncompressed_size'].') vs Central Directory ('.$central_directory_entry['uncompressed_size'].') for file at offset '.$LocalFileHeader['offset']); + } + break; + } + } + } + } + + return $LocalFileHeader; + } + + public function ZIPparseCentralDirectory() + { + $CentralDirectory['offset'] = $this->ftell(); + + $ZIPcentralDirectory = $this->fread(46); + + $CentralDirectory['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 0, 4)); + if ($CentralDirectory['raw']['signature'] != 0x02014B50) { + // invalid Central Directory Signature + $this->fseek($CentralDirectory['offset']); // seek back to where filepointer originally was so it can be handled properly + + return false; + } + $CentralDirectory['raw']['create_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 4, 2)); + $CentralDirectory['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 6, 2)); + $CentralDirectory['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 8, 2)); + $CentralDirectory['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 10, 2)); + $CentralDirectory['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 12, 2)); + $CentralDirectory['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 14, 2)); + $CentralDirectory['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 16, 4)); + $CentralDirectory['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 20, 4)); + $CentralDirectory['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 24, 4)); + $CentralDirectory['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 28, 2)); + $CentralDirectory['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 30, 2)); + $CentralDirectory['raw']['file_comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 32, 2)); + $CentralDirectory['raw']['disk_number_start'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 34, 2)); + $CentralDirectory['raw']['internal_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 36, 2)); + $CentralDirectory['raw']['external_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 38, 4)); + $CentralDirectory['raw']['local_header_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 42, 4)); + + $CentralDirectory['entry_offset'] = $CentralDirectory['raw']['local_header_offset']; + $CentralDirectory['create_version'] = sprintf('%1.1f', $CentralDirectory['raw']['create_version'] / 10); + $CentralDirectory['extract_version'] = sprintf('%1.1f', $CentralDirectory['raw']['extract_version'] / 10); + $CentralDirectory['host_os'] = $this->ZIPversionOSLookup(($CentralDirectory['raw']['extract_version'] & 0xFF00) >> 8); + $CentralDirectory['compression_method'] = $this->ZIPcompressionMethodLookup($CentralDirectory['raw']['compression_method']); + $CentralDirectory['compressed_size'] = $CentralDirectory['raw']['compressed_size']; + $CentralDirectory['uncompressed_size'] = $CentralDirectory['raw']['uncompressed_size']; + $CentralDirectory['flags'] = $this->ZIPparseGeneralPurposeFlags($CentralDirectory['raw']['general_flags'], $CentralDirectory['raw']['compression_method']); + $CentralDirectory['last_modified_timestamp'] = $this->DOStime2UNIXtime($CentralDirectory['raw']['last_mod_file_date'], $CentralDirectory['raw']['last_mod_file_time']); + + $FilenameExtrafieldCommentLength = $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'] + $CentralDirectory['raw']['file_comment_length']; + if ($FilenameExtrafieldCommentLength > 0) { + $FilenameExtrafieldComment = $this->fread($FilenameExtrafieldCommentLength); + + if ($CentralDirectory['raw']['filename_length'] > 0) { + $CentralDirectory['filename'] = substr($FilenameExtrafieldComment, 0, $CentralDirectory['raw']['filename_length']); + } + if ($CentralDirectory['raw']['extra_field_length'] > 0) { + $CentralDirectory['raw']['extra_field_data'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'], $CentralDirectory['raw']['extra_field_length']); + } + if ($CentralDirectory['raw']['file_comment_length'] > 0) { + $CentralDirectory['file_comment'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'], $CentralDirectory['raw']['file_comment_length']); + } + } + + return $CentralDirectory; + } + + public function ZIPparseEndOfCentralDirectory() + { + $EndOfCentralDirectory['offset'] = $this->ftell(); + + $ZIPendOfCentralDirectory = $this->fread(22); + + $EndOfCentralDirectory['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 0, 4)); + if ($EndOfCentralDirectory['signature'] != 0x06054B50) { + // invalid End Of Central Directory Signature + $this->fseek($EndOfCentralDirectory['offset']); // seek back to where filepointer originally was so it can be handled properly + + return false; + } + $EndOfCentralDirectory['disk_number_current'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 4, 2)); + $EndOfCentralDirectory['disk_number_start_directory'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 6, 2)); + $EndOfCentralDirectory['directory_entries_this_disk'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 8, 2)); + $EndOfCentralDirectory['directory_entries_total'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 10, 2)); + $EndOfCentralDirectory['directory_size'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 12, 4)); + $EndOfCentralDirectory['directory_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 16, 4)); + $EndOfCentralDirectory['comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 20, 2)); + + if ($EndOfCentralDirectory['comment_length'] > 0) { + $EndOfCentralDirectory['comment'] = $this->fread($EndOfCentralDirectory['comment_length']); + } + + return $EndOfCentralDirectory; + } + + public static function ZIPparseGeneralPurposeFlags($flagbytes, $compressionmethod) + { + // https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip-printable.html + $ParsedFlags['encrypted'] = (bool) ($flagbytes & 0x0001); + // 0x0002 -- see below + // 0x0004 -- see below + $ParsedFlags['data_descriptor_used'] = (bool) ($flagbytes & 0x0008); + $ParsedFlags['enhanced_deflation'] = (bool) ($flagbytes & 0x0010); + $ParsedFlags['compressed_patched_data'] = (bool) ($flagbytes & 0x0020); + $ParsedFlags['strong_encryption'] = (bool) ($flagbytes & 0x0040); + // 0x0080 - unused + // 0x0100 - unused + // 0x0200 - unused + // 0x0400 - unused + $ParsedFlags['language_encoding'] = (bool) ($flagbytes & 0x0800); + // 0x1000 - reserved + $ParsedFlags['mask_header_values'] = (bool) ($flagbytes & 0x2000); + // 0x4000 - reserved + // 0x8000 - reserved + + switch ($compressionmethod) { + case 6: + $ParsedFlags['dictionary_size'] = (($flagbytes & 0x0002) ? 8192 : 4096); + $ParsedFlags['shannon_fano_trees'] = (($flagbytes & 0x0004) ? 3 : 2); + break; + + case 8: + case 9: + switch (($flagbytes & 0x0006) >> 1) { + case 0: + $ParsedFlags['compression_speed'] = 'normal'; + break; + case 1: + $ParsedFlags['compression_speed'] = 'maximum'; + break; + case 2: + $ParsedFlags['compression_speed'] = 'fast'; + break; + case 3: + $ParsedFlags['compression_speed'] = 'superfast'; + break; + } + break; + } + + return $ParsedFlags; + } + + public static function ZIPversionOSLookup($index) + { + static $ZIPversionOSLookup = [ + 0 => 'MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)', + 1 => 'Amiga', + 2 => 'OpenVMS', + 3 => 'Unix', + 4 => 'VM/CMS', + 5 => 'Atari ST', + 6 => 'OS/2 H.P.F.S.', + 7 => 'Macintosh', + 8 => 'Z-System', + 9 => 'CP/M', + 10 => 'Windows NTFS', + 11 => 'MVS', + 12 => 'VSE', + 13 => 'Acorn Risc', + 14 => 'VFAT', + 15 => 'Alternate MVS', + 16 => 'BeOS', + 17 => 'Tandem', + 18 => 'OS/400', + 19 => 'OS/X (Darwin)', + ]; + + return isset($ZIPversionOSLookup[$index]) ? $ZIPversionOSLookup[$index] : '[unknown]'; + } + + public static function ZIPcompressionMethodLookup($index) + { + // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/ZIP.html + static $ZIPcompressionMethodLookup = [ + 0 => 'store', + 1 => 'shrink', + 2 => 'reduce-1', + 3 => 'reduce-2', + 4 => 'reduce-3', + 5 => 'reduce-4', + 6 => 'implode', + 7 => 'tokenize', + 8 => 'deflate', + 9 => 'deflate64', + 10 => 'Imploded (old IBM TERSE)', + 11 => 'RESERVED[11]', + 12 => 'BZIP2', + 13 => 'RESERVED[13]', + 14 => 'LZMA (EFS)', + 15 => 'RESERVED[15]', + 16 => 'RESERVED[16]', + 17 => 'RESERVED[17]', + 18 => 'IBM TERSE (new)', + 19 => 'IBM LZ77 z Architecture (PFS)', + 96 => 'JPEG recompressed', + 97 => 'WavPack compressed', + 98 => 'PPMd version I, Rev 1', + ]; + + return isset($ZIPcompressionMethodLookup[$index]) ? $ZIPcompressionMethodLookup[$index] : '[unknown]'; + } + + public static function DOStime2UNIXtime($DOSdate, $DOStime) + { + // wFatDate + // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format: + // Bits Contents + // 0-4 Day of the month (1-31) + // 5-8 Month (1 = January, 2 = February, and so on) + // 9-15 Year offset from 1980 (add 1980 to get actual year) + + $UNIXday = ($DOSdate & 0x001F); + $UNIXmonth = (($DOSdate & 0x01E0) >> 5); + $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980; + + // wFatTime + // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format: + // Bits Contents + // 0-4 Second divided by 2 + // 5-10 Minute (0-59) + // 11-15 Hour (0-23 on a 24-hour clock) + + $UNIXsecond = ($DOStime & 0x001F) * 2; + $UNIXminute = (($DOStime & 0x07E0) >> 5); + $UNIXhour = (($DOStime & 0xF800) >> 11); + + return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear); + } } diff --git a/app/Library/getid3/getid3/module.audio-video.asf.php b/app/Library/getid3/getid3/module.audio-video.asf.php index 23d3a0e6..d32e6ef3 100644 --- a/app/Library/getid3/getid3/module.audio-video.asf.php +++ b/app/Library/getid3/getid3/module.audio-video.asf.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -16,1998 +17,2009 @@ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); -class getid3_asf extends getid3_handler { - - public function __construct(getID3 $getid3) { - parent::__construct($getid3); // extends getid3_handler::__construct() - - // initialize all GUID constants - $GUIDarray = $this->KnownGUIDs(); - foreach ($GUIDarray as $GUIDname => $hexstringvalue) { - if (!defined($GUIDname)) { - define($GUIDname, $this->GUIDtoBytestring($hexstringvalue)); - } - } - } - - public function Analyze() { - $info = &$this->getid3->info; - - // Shortcuts - $thisfile_audio = &$info['audio']; - $thisfile_video = &$info['video']; - $info['asf'] = array(); - $thisfile_asf = &$info['asf']; - $thisfile_asf['comments'] = array(); - $thisfile_asf_comments = &$thisfile_asf['comments']; - $thisfile_asf['header_object'] = array(); - $thisfile_asf_headerobject = &$thisfile_asf['header_object']; - - - // ASF structure: - // * Header Object [required] - // * File Properties Object [required] (global file attributes) - // * Stream Properties Object [required] (defines media stream & characteristics) - // * Header Extension Object [required] (additional functionality) - // * Content Description Object (bibliographic information) - // * Script Command Object (commands for during playback) - // * Marker Object (named jumped points within the file) - // * Data Object [required] - // * Data Packets - // * Index Object - - // Header Object: (mandatory, one only) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for header object - GETID3_ASF_Header_Object - // Object Size QWORD 64 // size of header object, including 30 bytes of Header Object header - // Number of Header Objects DWORD 32 // number of objects in header object - // Reserved1 BYTE 8 // hardcoded: 0x01 - // Reserved2 BYTE 8 // hardcoded: 0x02 - - $info['fileformat'] = 'asf'; - - $this->fseek($info['avdataoffset']); - $HeaderObjectData = $this->fread(30); - - $thisfile_asf_headerobject['objectid'] = substr($HeaderObjectData, 0, 16); - $thisfile_asf_headerobject['objectid_guid'] = $this->BytestringToGUID($thisfile_asf_headerobject['objectid']); - if ($thisfile_asf_headerobject['objectid'] != GETID3_ASF_Header_Object) { - unset($info['fileformat'], $info['asf']); - return $this->error('ASF header GUID {'.$this->BytestringToGUID($thisfile_asf_headerobject['objectid']).'} does not match expected "GETID3_ASF_Header_Object" GUID {'.$this->BytestringToGUID(GETID3_ASF_Header_Object).'}'); - } - $thisfile_asf_headerobject['objectsize'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 16, 8)); - $thisfile_asf_headerobject['headerobjects'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 24, 4)); - $thisfile_asf_headerobject['reserved1'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 28, 1)); - $thisfile_asf_headerobject['reserved2'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 29, 1)); - - $NextObjectOffset = $this->ftell(); - $ASFHeaderData = $this->fread($thisfile_asf_headerobject['objectsize'] - 30); - $offset = 0; - - for ($HeaderObjectsCounter = 0; $HeaderObjectsCounter < $thisfile_asf_headerobject['headerobjects']; $HeaderObjectsCounter++) { - $NextObjectGUID = substr($ASFHeaderData, $offset, 16); - $offset += 16; - $NextObjectGUIDtext = $this->BytestringToGUID($NextObjectGUID); - $NextObjectSize = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); - $offset += 8; - switch ($NextObjectGUID) { - - case GETID3_ASF_File_Properties_Object: - // File Properties Object: (mandatory, one only) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for file properties object - GETID3_ASF_File_Properties_Object - // Object Size QWORD 64 // size of file properties object, including 104 bytes of File Properties Object header - // File ID GUID 128 // unique ID - identical to File ID in Data Object - // File Size QWORD 64 // entire file in bytes. Invalid if Broadcast Flag == 1 - // Creation Date QWORD 64 // date & time of file creation. Maybe invalid if Broadcast Flag == 1 - // Data Packets Count QWORD 64 // number of data packets in Data Object. Invalid if Broadcast Flag == 1 - // Play Duration QWORD 64 // playtime, in 100-nanosecond units. Invalid if Broadcast Flag == 1 - // Send Duration QWORD 64 // time needed to send file, in 100-nanosecond units. Players can ignore this value. Invalid if Broadcast Flag == 1 - // Preroll QWORD 64 // time to buffer data before starting to play file, in 1-millisecond units. If <> 0, PlayDuration and PresentationTime have been offset by this amount - // Flags DWORD 32 // - // * Broadcast Flag bits 1 (0x01) // file is currently being written, some header values are invalid - // * Seekable Flag bits 1 (0x02) // is file seekable - // * Reserved bits 30 (0xFFFFFFFC) // reserved - set to zero - // Minimum Data Packet Size DWORD 32 // in bytes. should be same as Maximum Data Packet Size. Invalid if Broadcast Flag == 1 - // Maximum Data Packet Size DWORD 32 // in bytes. should be same as Minimum Data Packet Size. Invalid if Broadcast Flag == 1 - // Maximum Bitrate DWORD 32 // maximum instantaneous bitrate in bits per second for entire file, including all data streams and ASF overhead - - // shortcut - $thisfile_asf['file_properties_object'] = array(); - $thisfile_asf_filepropertiesobject = &$thisfile_asf['file_properties_object']; - - $thisfile_asf_filepropertiesobject['offset'] = $NextObjectOffset + $offset; - $thisfile_asf_filepropertiesobject['objectid'] = $NextObjectGUID; - $thisfile_asf_filepropertiesobject['objectid_guid'] = $NextObjectGUIDtext; - $thisfile_asf_filepropertiesobject['objectsize'] = $NextObjectSize; - $thisfile_asf_filepropertiesobject['fileid'] = substr($ASFHeaderData, $offset, 16); - $offset += 16; - $thisfile_asf_filepropertiesobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_filepropertiesobject['fileid']); - $thisfile_asf_filepropertiesobject['filesize'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); - $offset += 8; - $thisfile_asf_filepropertiesobject['creation_date'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); - $thisfile_asf_filepropertiesobject['creation_date_unix'] = $this->FILETIMEtoUNIXtime($thisfile_asf_filepropertiesobject['creation_date']); - $offset += 8; - $thisfile_asf_filepropertiesobject['data_packets'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); - $offset += 8; - $thisfile_asf_filepropertiesobject['play_duration'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); - $offset += 8; - $thisfile_asf_filepropertiesobject['send_duration'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); - $offset += 8; - $thisfile_asf_filepropertiesobject['preroll'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); - $offset += 8; - $thisfile_asf_filepropertiesobject['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); - $offset += 4; - $thisfile_asf_filepropertiesobject['flags']['broadcast'] = (bool) ($thisfile_asf_filepropertiesobject['flags_raw'] & 0x0001); - $thisfile_asf_filepropertiesobject['flags']['seekable'] = (bool) ($thisfile_asf_filepropertiesobject['flags_raw'] & 0x0002); - - $thisfile_asf_filepropertiesobject['min_packet_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); - $offset += 4; - $thisfile_asf_filepropertiesobject['max_packet_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); - $offset += 4; - $thisfile_asf_filepropertiesobject['max_bitrate'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); - $offset += 4; - - if ($thisfile_asf_filepropertiesobject['flags']['broadcast']) { - - // broadcast flag is set, some values invalid - unset($thisfile_asf_filepropertiesobject['filesize']); - unset($thisfile_asf_filepropertiesobject['data_packets']); - unset($thisfile_asf_filepropertiesobject['play_duration']); - unset($thisfile_asf_filepropertiesobject['send_duration']); - unset($thisfile_asf_filepropertiesobject['min_packet_size']); - unset($thisfile_asf_filepropertiesobject['max_packet_size']); - - } else { - - // broadcast flag NOT set, perform calculations - $info['playtime_seconds'] = ($thisfile_asf_filepropertiesobject['play_duration'] / 10000000) - ($thisfile_asf_filepropertiesobject['preroll'] / 1000); - - //$info['bitrate'] = $thisfile_asf_filepropertiesobject['max_bitrate']; - $info['bitrate'] = ((isset($thisfile_asf_filepropertiesobject['filesize']) ? $thisfile_asf_filepropertiesobject['filesize'] : $info['filesize']) * 8) / $info['playtime_seconds']; - } - break; - - case GETID3_ASF_Stream_Properties_Object: - // Stream Properties Object: (mandatory, one per media stream) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for stream properties object - GETID3_ASF_Stream_Properties_Object - // Object Size QWORD 64 // size of stream properties object, including 78 bytes of Stream Properties Object header - // Stream Type GUID 128 // GETID3_ASF_Audio_Media, GETID3_ASF_Video_Media or GETID3_ASF_Command_Media - // Error Correction Type GUID 128 // GETID3_ASF_Audio_Spread for audio-only streams, GETID3_ASF_No_Error_Correction for other stream types - // Time Offset QWORD 64 // 100-nanosecond units. typically zero. added to all timestamps of samples in the stream - // Type-Specific Data Length DWORD 32 // number of bytes for Type-Specific Data field - // Error Correction Data Length DWORD 32 // number of bytes for Error Correction Data field - // Flags WORD 16 // - // * Stream Number bits 7 (0x007F) // number of this stream. 1 <= valid <= 127 - // * Reserved bits 8 (0x7F80) // reserved - set to zero - // * Encrypted Content Flag bits 1 (0x8000) // stream contents encrypted if set - // Reserved DWORD 32 // reserved - set to zero - // Type-Specific Data BYTESTREAM variable // type-specific format data, depending on value of Stream Type - // Error Correction Data BYTESTREAM variable // error-correction-specific format data, depending on value of Error Correct Type - - // There is one GETID3_ASF_Stream_Properties_Object for each stream (audio, video) but the - // stream number isn't known until halfway through decoding the structure, hence it - // it is decoded to a temporary variable and then stuck in the appropriate index later - - $StreamPropertiesObjectData['offset'] = $NextObjectOffset + $offset; - $StreamPropertiesObjectData['objectid'] = $NextObjectGUID; - $StreamPropertiesObjectData['objectid_guid'] = $NextObjectGUIDtext; - $StreamPropertiesObjectData['objectsize'] = $NextObjectSize; - $StreamPropertiesObjectData['stream_type'] = substr($ASFHeaderData, $offset, 16); - $offset += 16; - $StreamPropertiesObjectData['stream_type_guid'] = $this->BytestringToGUID($StreamPropertiesObjectData['stream_type']); - $StreamPropertiesObjectData['error_correct_type'] = substr($ASFHeaderData, $offset, 16); - $offset += 16; - $StreamPropertiesObjectData['error_correct_guid'] = $this->BytestringToGUID($StreamPropertiesObjectData['error_correct_type']); - $StreamPropertiesObjectData['time_offset'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); - $offset += 8; - $StreamPropertiesObjectData['type_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); - $offset += 4; - $StreamPropertiesObjectData['error_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); - $offset += 4; - $StreamPropertiesObjectData['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $StreamPropertiesObjectStreamNumber = $StreamPropertiesObjectData['flags_raw'] & 0x007F; - $StreamPropertiesObjectData['flags']['encrypted'] = (bool) ($StreamPropertiesObjectData['flags_raw'] & 0x8000); - - $offset += 4; // reserved - DWORD - $StreamPropertiesObjectData['type_specific_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['type_data_length']); - $offset += $StreamPropertiesObjectData['type_data_length']; - $StreamPropertiesObjectData['error_correct_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['error_data_length']); - $offset += $StreamPropertiesObjectData['error_data_length']; - - switch ($StreamPropertiesObjectData['stream_type']) { - - case GETID3_ASF_Audio_Media: - $thisfile_audio['dataformat'] = (!empty($thisfile_audio['dataformat']) ? $thisfile_audio['dataformat'] : 'asf'); - $thisfile_audio['bitrate_mode'] = (!empty($thisfile_audio['bitrate_mode']) ? $thisfile_audio['bitrate_mode'] : 'cbr'); - - $audiodata = getid3_riff::parseWAVEFORMATex(substr($StreamPropertiesObjectData['type_specific_data'], 0, 16)); - unset($audiodata['raw']); - $thisfile_audio = getid3_lib::array_merge_noclobber($audiodata, $thisfile_audio); - break; - - case GETID3_ASF_Video_Media: - $thisfile_video['dataformat'] = (!empty($thisfile_video['dataformat']) ? $thisfile_video['dataformat'] : 'asf'); - $thisfile_video['bitrate_mode'] = (!empty($thisfile_video['bitrate_mode']) ? $thisfile_video['bitrate_mode'] : 'cbr'); - break; - - case GETID3_ASF_Command_Media: - default: - // do nothing - break; - - } - - $thisfile_asf['stream_properties_object'][$StreamPropertiesObjectStreamNumber] = $StreamPropertiesObjectData; - unset($StreamPropertiesObjectData); // clear for next stream, if any - break; - - case GETID3_ASF_Header_Extension_Object: - // Header Extension Object: (mandatory, one only) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for Header Extension object - GETID3_ASF_Header_Extension_Object - // Object Size QWORD 64 // size of Header Extension object, including 46 bytes of Header Extension Object header - // Reserved Field 1 GUID 128 // hardcoded: GETID3_ASF_Reserved_1 - // Reserved Field 2 WORD 16 // hardcoded: 0x00000006 - // Header Extension Data Size DWORD 32 // in bytes. valid: 0, or > 24. equals object size minus 46 - // Header Extension Data BYTESTREAM variable // array of zero or more extended header objects - - // shortcut - $thisfile_asf['header_extension_object'] = array(); - $thisfile_asf_headerextensionobject = &$thisfile_asf['header_extension_object']; - - $thisfile_asf_headerextensionobject['offset'] = $NextObjectOffset + $offset; - $thisfile_asf_headerextensionobject['objectid'] = $NextObjectGUID; - $thisfile_asf_headerextensionobject['objectid_guid'] = $NextObjectGUIDtext; - $thisfile_asf_headerextensionobject['objectsize'] = $NextObjectSize; - $thisfile_asf_headerextensionobject['reserved_1'] = substr($ASFHeaderData, $offset, 16); - $offset += 16; - $thisfile_asf_headerextensionobject['reserved_1_guid'] = $this->BytestringToGUID($thisfile_asf_headerextensionobject['reserved_1']); - if ($thisfile_asf_headerextensionobject['reserved_1'] != GETID3_ASF_Reserved_1) { - $this->warning('header_extension_object.reserved_1 GUID ('.$this->BytestringToGUID($thisfile_asf_headerextensionobject['reserved_1']).') does not match expected "GETID3_ASF_Reserved_1" GUID ('.$this->BytestringToGUID(GETID3_ASF_Reserved_1).')'); - //return false; - break; - } - $thisfile_asf_headerextensionobject['reserved_2'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - if ($thisfile_asf_headerextensionobject['reserved_2'] != 6) { - $this->warning('header_extension_object.reserved_2 ('.getid3_lib::PrintHexBytes($thisfile_asf_headerextensionobject['reserved_2']).') does not match expected value of "6"'); - //return false; - break; - } - $thisfile_asf_headerextensionobject['extension_data_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); - $offset += 4; - $thisfile_asf_headerextensionobject['extension_data'] = substr($ASFHeaderData, $offset, $thisfile_asf_headerextensionobject['extension_data_size']); - $unhandled_sections = 0; - $thisfile_asf_headerextensionobject['extension_data_parsed'] = $this->HeaderExtensionObjectDataParse($thisfile_asf_headerextensionobject['extension_data'], $unhandled_sections); - if ($unhandled_sections === 0) { - unset($thisfile_asf_headerextensionobject['extension_data']); - } - $offset += $thisfile_asf_headerextensionobject['extension_data_size']; - break; - - case GETID3_ASF_Codec_List_Object: - // Codec List Object: (optional, one only) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for Codec List object - GETID3_ASF_Codec_List_Object - // Object Size QWORD 64 // size of Codec List object, including 44 bytes of Codec List Object header - // Reserved GUID 128 // hardcoded: 86D15241-311D-11D0-A3A4-00A0C90348F6 - // Codec Entries Count DWORD 32 // number of entries in Codec Entries array - // Codec Entries array of: variable // - // * Type WORD 16 // 0x0001 = Video Codec, 0x0002 = Audio Codec, 0xFFFF = Unknown Codec - // * Codec Name Length WORD 16 // number of Unicode characters stored in the Codec Name field - // * Codec Name WCHAR variable // array of Unicode characters - name of codec used to create the content - // * Codec Description Length WORD 16 // number of Unicode characters stored in the Codec Description field - // * Codec Description WCHAR variable // array of Unicode characters - description of format used to create the content - // * Codec Information Length WORD 16 // number of Unicode characters stored in the Codec Information field - // * Codec Information BYTESTREAM variable // opaque array of information bytes about the codec used to create the content - - // shortcut - $thisfile_asf['codec_list_object'] = array(); - $thisfile_asf_codeclistobject = &$thisfile_asf['codec_list_object']; - - $thisfile_asf_codeclistobject['offset'] = $NextObjectOffset + $offset; - $thisfile_asf_codeclistobject['objectid'] = $NextObjectGUID; - $thisfile_asf_codeclistobject['objectid_guid'] = $NextObjectGUIDtext; - $thisfile_asf_codeclistobject['objectsize'] = $NextObjectSize; - $thisfile_asf_codeclistobject['reserved'] = substr($ASFHeaderData, $offset, 16); - $offset += 16; - $thisfile_asf_codeclistobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_codeclistobject['reserved']); - if ($thisfile_asf_codeclistobject['reserved'] != $this->GUIDtoBytestring('86D15241-311D-11D0-A3A4-00A0C90348F6')) { - $this->warning('codec_list_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_codeclistobject['reserved']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {86D15241-311D-11D0-A3A4-00A0C90348F6}'); - //return false; - break; - } - $thisfile_asf_codeclistobject['codec_entries_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); - $offset += 4; - for ($CodecEntryCounter = 0; $CodecEntryCounter < $thisfile_asf_codeclistobject['codec_entries_count']; $CodecEntryCounter++) { - // shortcut - $thisfile_asf_codeclistobject['codec_entries'][$CodecEntryCounter] = array(); - $thisfile_asf_codeclistobject_codecentries_current = &$thisfile_asf_codeclistobject['codec_entries'][$CodecEntryCounter]; - - $thisfile_asf_codeclistobject_codecentries_current['type_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_codeclistobject_codecentries_current['type'] = self::codecListObjectTypeLookup($thisfile_asf_codeclistobject_codecentries_current['type_raw']); - - $CodecNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character - $offset += 2; - $thisfile_asf_codeclistobject_codecentries_current['name'] = substr($ASFHeaderData, $offset, $CodecNameLength); - $offset += $CodecNameLength; - - $CodecDescriptionLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character - $offset += 2; - $thisfile_asf_codeclistobject_codecentries_current['description'] = substr($ASFHeaderData, $offset, $CodecDescriptionLength); - $offset += $CodecDescriptionLength; - - $CodecInformationLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_codeclistobject_codecentries_current['information'] = substr($ASFHeaderData, $offset, $CodecInformationLength); - $offset += $CodecInformationLength; - - if ($thisfile_asf_codeclistobject_codecentries_current['type_raw'] == 2) { // audio codec - - if (strpos($thisfile_asf_codeclistobject_codecentries_current['description'], ',') === false) { - $this->warning('[asf][codec_list_object][codec_entries]['.$CodecEntryCounter.'][description] expected to contain comma-separated list of parameters: "'.$thisfile_asf_codeclistobject_codecentries_current['description'].'"'); - } else { - - list($AudioCodecBitrate, $AudioCodecFrequency, $AudioCodecChannels) = explode(',', $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description'])); - $thisfile_audio['codec'] = $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['name']); - - if (!isset($thisfile_audio['bitrate']) && strstr($AudioCodecBitrate, 'kbps')) { - $thisfile_audio['bitrate'] = (int) (trim(str_replace('kbps', '', $AudioCodecBitrate)) * 1000); - } - //if (!isset($thisfile_video['bitrate']) && isset($thisfile_audio['bitrate']) && isset($thisfile_asf['file_properties_object']['max_bitrate']) && ($thisfile_asf_codeclistobject['codec_entries_count'] > 1)) { - if (empty($thisfile_video['bitrate']) && !empty($thisfile_audio['bitrate']) && !empty($info['bitrate'])) { - //$thisfile_video['bitrate'] = $thisfile_asf['file_properties_object']['max_bitrate'] - $thisfile_audio['bitrate']; - $thisfile_video['bitrate'] = $info['bitrate'] - $thisfile_audio['bitrate']; - } - - $AudioCodecFrequency = (int) trim(str_replace('kHz', '', $AudioCodecFrequency)); - switch ($AudioCodecFrequency) { - case 8: - case 8000: - $thisfile_audio['sample_rate'] = 8000; - break; - - case 11: - case 11025: - $thisfile_audio['sample_rate'] = 11025; - break; - - case 12: - case 12000: - $thisfile_audio['sample_rate'] = 12000; - break; - - case 16: - case 16000: - $thisfile_audio['sample_rate'] = 16000; - break; - - case 22: - case 22050: - $thisfile_audio['sample_rate'] = 22050; - break; - - case 24: - case 24000: - $thisfile_audio['sample_rate'] = 24000; - break; - - case 32: - case 32000: - $thisfile_audio['sample_rate'] = 32000; - break; - - case 44: - case 441000: - $thisfile_audio['sample_rate'] = 44100; - break; - - case 48: - case 48000: - $thisfile_audio['sample_rate'] = 48000; - break; - - default: - $this->warning('unknown frequency: "'.$AudioCodecFrequency.'" ('.$this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description']).')'); - break; - } - - if (!isset($thisfile_audio['channels'])) { - if (strstr($AudioCodecChannels, 'stereo')) { - $thisfile_audio['channels'] = 2; - } elseif (strstr($AudioCodecChannels, 'mono')) { - $thisfile_audio['channels'] = 1; - } - } - - } - } - } - break; - - case GETID3_ASF_Script_Command_Object: - // Script Command Object: (optional, one only) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for Script Command object - GETID3_ASF_Script_Command_Object - // Object Size QWORD 64 // size of Script Command object, including 44 bytes of Script Command Object header - // Reserved GUID 128 // hardcoded: 4B1ACBE3-100B-11D0-A39B-00A0C90348F6 - // Commands Count WORD 16 // number of Commands structures in the Script Commands Objects - // Command Types Count WORD 16 // number of Command Types structures in the Script Commands Objects - // Command Types array of: variable // - // * Command Type Name Length WORD 16 // number of Unicode characters for Command Type Name - // * Command Type Name WCHAR variable // array of Unicode characters - name of a type of command - // Commands array of: variable // - // * Presentation Time DWORD 32 // presentation time of that command, in milliseconds - // * Type Index WORD 16 // type of this command, as a zero-based index into the array of Command Types of this object - // * Command Name Length WORD 16 // number of Unicode characters for Command Name - // * Command Name WCHAR variable // array of Unicode characters - name of this command - - // shortcut - $thisfile_asf['script_command_object'] = array(); - $thisfile_asf_scriptcommandobject = &$thisfile_asf['script_command_object']; - - $thisfile_asf_scriptcommandobject['offset'] = $NextObjectOffset + $offset; - $thisfile_asf_scriptcommandobject['objectid'] = $NextObjectGUID; - $thisfile_asf_scriptcommandobject['objectid_guid'] = $NextObjectGUIDtext; - $thisfile_asf_scriptcommandobject['objectsize'] = $NextObjectSize; - $thisfile_asf_scriptcommandobject['reserved'] = substr($ASFHeaderData, $offset, 16); - $offset += 16; - $thisfile_asf_scriptcommandobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_scriptcommandobject['reserved']); - if ($thisfile_asf_scriptcommandobject['reserved'] != $this->GUIDtoBytestring('4B1ACBE3-100B-11D0-A39B-00A0C90348F6')) { - $this->warning('script_command_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_scriptcommandobject['reserved']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {4B1ACBE3-100B-11D0-A39B-00A0C90348F6}'); - //return false; - break; - } - $thisfile_asf_scriptcommandobject['commands_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_scriptcommandobject['command_types_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - for ($CommandTypesCounter = 0; $CommandTypesCounter < $thisfile_asf_scriptcommandobject['command_types_count']; $CommandTypesCounter++) { - $CommandTypeNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character - $offset += 2; - $thisfile_asf_scriptcommandobject['command_types'][$CommandTypesCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength); - $offset += $CommandTypeNameLength; - } - for ($CommandsCounter = 0; $CommandsCounter < $thisfile_asf_scriptcommandobject['commands_count']; $CommandsCounter++) { - $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); - $offset += 4; - $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['type_index'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - - $CommandTypeNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character - $offset += 2; - $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength); - $offset += $CommandTypeNameLength; - } - break; - - case GETID3_ASF_Marker_Object: - // Marker Object: (optional, one only) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for Marker object - GETID3_ASF_Marker_Object - // Object Size QWORD 64 // size of Marker object, including 48 bytes of Marker Object header - // Reserved GUID 128 // hardcoded: 4CFEDB20-75F6-11CF-9C0F-00A0C90349CB - // Markers Count DWORD 32 // number of Marker structures in Marker Object - // Reserved WORD 16 // hardcoded: 0x0000 - // Name Length WORD 16 // number of bytes in the Name field - // Name WCHAR variable // name of the Marker Object - // Markers array of: variable // - // * Offset QWORD 64 // byte offset into Data Object - // * Presentation Time QWORD 64 // in 100-nanosecond units - // * Entry Length WORD 16 // length in bytes of (Send Time + Flags + Marker Description Length + Marker Description + Padding) - // * Send Time DWORD 32 // in milliseconds - // * Flags DWORD 32 // hardcoded: 0x00000000 - // * Marker Description Length DWORD 32 // number of bytes in Marker Description field - // * Marker Description WCHAR variable // array of Unicode characters - description of marker entry - // * Padding BYTESTREAM variable // optional padding bytes - - // shortcut - $thisfile_asf['marker_object'] = array(); - $thisfile_asf_markerobject = &$thisfile_asf['marker_object']; - - $thisfile_asf_markerobject['offset'] = $NextObjectOffset + $offset; - $thisfile_asf_markerobject['objectid'] = $NextObjectGUID; - $thisfile_asf_markerobject['objectid_guid'] = $NextObjectGUIDtext; - $thisfile_asf_markerobject['objectsize'] = $NextObjectSize; - $thisfile_asf_markerobject['reserved'] = substr($ASFHeaderData, $offset, 16); - $offset += 16; - $thisfile_asf_markerobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_markerobject['reserved']); - if ($thisfile_asf_markerobject['reserved'] != $this->GUIDtoBytestring('4CFEDB20-75F6-11CF-9C0F-00A0C90349CB')) { - $this->warning('marker_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_markerobject['reserved_1']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {4CFEDB20-75F6-11CF-9C0F-00A0C90349CB}'); - break; - } - $thisfile_asf_markerobject['markers_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); - $offset += 4; - $thisfile_asf_markerobject['reserved_2'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - if ($thisfile_asf_markerobject['reserved_2'] != 0) { - $this->warning('marker_object.reserved_2 ('.getid3_lib::PrintHexBytes($thisfile_asf_markerobject['reserved_2']).') does not match expected value of "0"'); - break; - } - $thisfile_asf_markerobject['name_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_markerobject['name'] = substr($ASFHeaderData, $offset, $thisfile_asf_markerobject['name_length']); - $offset += $thisfile_asf_markerobject['name_length']; - for ($MarkersCounter = 0; $MarkersCounter < $thisfile_asf_markerobject['markers_count']; $MarkersCounter++) { - $thisfile_asf_markerobject['markers'][$MarkersCounter]['offset'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); - $offset += 8; - $thisfile_asf_markerobject['markers'][$MarkersCounter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); - $offset += 8; - $thisfile_asf_markerobject['markers'][$MarkersCounter]['entry_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_markerobject['markers'][$MarkersCounter]['send_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); - $offset += 4; - $thisfile_asf_markerobject['markers'][$MarkersCounter]['flags'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); - $offset += 4; - $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); - $offset += 4; - $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description'] = substr($ASFHeaderData, $offset, $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length']); - $offset += $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length']; - $PaddingLength = $thisfile_asf_markerobject['markers'][$MarkersCounter]['entry_length'] - 4 - 4 - 4 - $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length']; - if ($PaddingLength > 0) { - $thisfile_asf_markerobject['markers'][$MarkersCounter]['padding'] = substr($ASFHeaderData, $offset, $PaddingLength); - $offset += $PaddingLength; - } - } - break; - - case GETID3_ASF_Bitrate_Mutual_Exclusion_Object: - // Bitrate Mutual Exclusion Object: (optional) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for Bitrate Mutual Exclusion object - GETID3_ASF_Bitrate_Mutual_Exclusion_Object - // Object Size QWORD 64 // size of Bitrate Mutual Exclusion object, including 42 bytes of Bitrate Mutual Exclusion Object header - // Exlusion Type GUID 128 // nature of mutual exclusion relationship. one of: (GETID3_ASF_Mutex_Bitrate, GETID3_ASF_Mutex_Unknown) - // Stream Numbers Count WORD 16 // number of video streams - // Stream Numbers WORD variable // array of mutually exclusive video stream numbers. 1 <= valid <= 127 - - // shortcut - $thisfile_asf['bitrate_mutual_exclusion_object'] = array(); - $thisfile_asf_bitratemutualexclusionobject = &$thisfile_asf['bitrate_mutual_exclusion_object']; - - $thisfile_asf_bitratemutualexclusionobject['offset'] = $NextObjectOffset + $offset; - $thisfile_asf_bitratemutualexclusionobject['objectid'] = $NextObjectGUID; - $thisfile_asf_bitratemutualexclusionobject['objectid_guid'] = $NextObjectGUIDtext; - $thisfile_asf_bitratemutualexclusionobject['objectsize'] = $NextObjectSize; - $thisfile_asf_bitratemutualexclusionobject['reserved'] = substr($ASFHeaderData, $offset, 16); - $thisfile_asf_bitratemutualexclusionobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_bitratemutualexclusionobject['reserved']); - $offset += 16; - if (($thisfile_asf_bitratemutualexclusionobject['reserved'] != GETID3_ASF_Mutex_Bitrate) && ($thisfile_asf_bitratemutualexclusionobject['reserved'] != GETID3_ASF_Mutex_Unknown)) { - $this->warning('bitrate_mutual_exclusion_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_bitratemutualexclusionobject['reserved']).'} does not match expected "GETID3_ASF_Mutex_Bitrate" GUID {'.$this->BytestringToGUID(GETID3_ASF_Mutex_Bitrate).'} or "GETID3_ASF_Mutex_Unknown" GUID {'.$this->BytestringToGUID(GETID3_ASF_Mutex_Unknown).'}'); - //return false; - break; - } - $thisfile_asf_bitratemutualexclusionobject['stream_numbers_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - for ($StreamNumberCounter = 0; $StreamNumberCounter < $thisfile_asf_bitratemutualexclusionobject['stream_numbers_count']; $StreamNumberCounter++) { - $thisfile_asf_bitratemutualexclusionobject['stream_numbers'][$StreamNumberCounter] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - } - break; - - case GETID3_ASF_Error_Correction_Object: - // Error Correction Object: (optional, one only) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for Error Correction object - GETID3_ASF_Error_Correction_Object - // Object Size QWORD 64 // size of Error Correction object, including 44 bytes of Error Correction Object header - // Error Correction Type GUID 128 // type of error correction. one of: (GETID3_ASF_No_Error_Correction, GETID3_ASF_Audio_Spread) - // Error Correction Data Length DWORD 32 // number of bytes in Error Correction Data field - // Error Correction Data BYTESTREAM variable // structure depends on value of Error Correction Type field - - // shortcut - $thisfile_asf['error_correction_object'] = array(); - $thisfile_asf_errorcorrectionobject = &$thisfile_asf['error_correction_object']; - - $thisfile_asf_errorcorrectionobject['offset'] = $NextObjectOffset + $offset; - $thisfile_asf_errorcorrectionobject['objectid'] = $NextObjectGUID; - $thisfile_asf_errorcorrectionobject['objectid_guid'] = $NextObjectGUIDtext; - $thisfile_asf_errorcorrectionobject['objectsize'] = $NextObjectSize; - $thisfile_asf_errorcorrectionobject['error_correction_type'] = substr($ASFHeaderData, $offset, 16); - $offset += 16; - $thisfile_asf_errorcorrectionobject['error_correction_guid'] = $this->BytestringToGUID($thisfile_asf_errorcorrectionobject['error_correction_type']); - $thisfile_asf_errorcorrectionobject['error_correction_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); - $offset += 4; - switch ($thisfile_asf_errorcorrectionobject['error_correction_type']) { - case GETID3_ASF_No_Error_Correction: - // should be no data, but just in case there is, skip to the end of the field - $offset += $thisfile_asf_errorcorrectionobject['error_correction_data_length']; - break; - - case GETID3_ASF_Audio_Spread: - // Field Name Field Type Size (bits) - // Span BYTE 8 // number of packets over which audio will be spread. - // Virtual Packet Length WORD 16 // size of largest audio payload found in audio stream - // Virtual Chunk Length WORD 16 // size of largest audio payload found in audio stream - // Silence Data Length WORD 16 // number of bytes in Silence Data field - // Silence Data BYTESTREAM variable // hardcoded: 0x00 * (Silence Data Length) bytes - - $thisfile_asf_errorcorrectionobject['span'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 1)); - $offset += 1; - $thisfile_asf_errorcorrectionobject['virtual_packet_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_errorcorrectionobject['virtual_chunk_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_errorcorrectionobject['silence_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_errorcorrectionobject['silence_data'] = substr($ASFHeaderData, $offset, $thisfile_asf_errorcorrectionobject['silence_data_length']); - $offset += $thisfile_asf_errorcorrectionobject['silence_data_length']; - break; - - default: - $this->warning('error_correction_object.error_correction_type GUID {'.$this->BytestringToGUID($thisfile_asf_errorcorrectionobject['reserved']).'} does not match expected "GETID3_ASF_No_Error_Correction" GUID {'.$this->BytestringToGUID(GETID3_ASF_No_Error_Correction).'} or "GETID3_ASF_Audio_Spread" GUID {'.$this->BytestringToGUID(GETID3_ASF_Audio_Spread).'}'); - //return false; - break; - } - - break; - - case GETID3_ASF_Content_Description_Object: - // Content Description Object: (optional, one only) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for Content Description object - GETID3_ASF_Content_Description_Object - // Object Size QWORD 64 // size of Content Description object, including 34 bytes of Content Description Object header - // Title Length WORD 16 // number of bytes in Title field - // Author Length WORD 16 // number of bytes in Author field - // Copyright Length WORD 16 // number of bytes in Copyright field - // Description Length WORD 16 // number of bytes in Description field - // Rating Length WORD 16 // number of bytes in Rating field - // Title WCHAR 16 // array of Unicode characters - Title - // Author WCHAR 16 // array of Unicode characters - Author - // Copyright WCHAR 16 // array of Unicode characters - Copyright - // Description WCHAR 16 // array of Unicode characters - Description - // Rating WCHAR 16 // array of Unicode characters - Rating - - // shortcut - $thisfile_asf['content_description_object'] = array(); - $thisfile_asf_contentdescriptionobject = &$thisfile_asf['content_description_object']; - - $thisfile_asf_contentdescriptionobject['offset'] = $NextObjectOffset + $offset; - $thisfile_asf_contentdescriptionobject['objectid'] = $NextObjectGUID; - $thisfile_asf_contentdescriptionobject['objectid_guid'] = $NextObjectGUIDtext; - $thisfile_asf_contentdescriptionobject['objectsize'] = $NextObjectSize; - $thisfile_asf_contentdescriptionobject['title_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_contentdescriptionobject['author_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_contentdescriptionobject['copyright_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_contentdescriptionobject['description_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_contentdescriptionobject['rating_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_contentdescriptionobject['title'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['title_length']); - $offset += $thisfile_asf_contentdescriptionobject['title_length']; - $thisfile_asf_contentdescriptionobject['author'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['author_length']); - $offset += $thisfile_asf_contentdescriptionobject['author_length']; - $thisfile_asf_contentdescriptionobject['copyright'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['copyright_length']); - $offset += $thisfile_asf_contentdescriptionobject['copyright_length']; - $thisfile_asf_contentdescriptionobject['description'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['description_length']); - $offset += $thisfile_asf_contentdescriptionobject['description_length']; - $thisfile_asf_contentdescriptionobject['rating'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['rating_length']); - $offset += $thisfile_asf_contentdescriptionobject['rating_length']; - - $ASFcommentKeysToCopy = array('title'=>'title', 'author'=>'artist', 'copyright'=>'copyright', 'description'=>'comment', 'rating'=>'rating'); - foreach ($ASFcommentKeysToCopy as $keytocopyfrom => $keytocopyto) { - if (!empty($thisfile_asf_contentdescriptionobject[$keytocopyfrom])) { - $thisfile_asf_comments[$keytocopyto][] = $this->TrimTerm($thisfile_asf_contentdescriptionobject[$keytocopyfrom]); - } - } - break; - - case GETID3_ASF_Extended_Content_Description_Object: - // Extended Content Description Object: (optional, one only) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for Extended Content Description object - GETID3_ASF_Extended_Content_Description_Object - // Object Size QWORD 64 // size of ExtendedContent Description object, including 26 bytes of Extended Content Description Object header - // Content Descriptors Count WORD 16 // number of entries in Content Descriptors list - // Content Descriptors array of: variable // - // * Descriptor Name Length WORD 16 // size in bytes of Descriptor Name field - // * Descriptor Name WCHAR variable // array of Unicode characters - Descriptor Name - // * Descriptor Value Data Type WORD 16 // Lookup array: - // 0x0000 = Unicode String (variable length) - // 0x0001 = BYTE array (variable length) - // 0x0002 = BOOL (DWORD, 32 bits) - // 0x0003 = DWORD (DWORD, 32 bits) - // 0x0004 = QWORD (QWORD, 64 bits) - // 0x0005 = WORD (WORD, 16 bits) - // * Descriptor Value Length WORD 16 // number of bytes stored in Descriptor Value field - // * Descriptor Value variable variable // value for Content Descriptor - - // shortcut - $thisfile_asf['extended_content_description_object'] = array(); - $thisfile_asf_extendedcontentdescriptionobject = &$thisfile_asf['extended_content_description_object']; - - $thisfile_asf_extendedcontentdescriptionobject['offset'] = $NextObjectOffset + $offset; - $thisfile_asf_extendedcontentdescriptionobject['objectid'] = $NextObjectGUID; - $thisfile_asf_extendedcontentdescriptionobject['objectid_guid'] = $NextObjectGUIDtext; - $thisfile_asf_extendedcontentdescriptionobject['objectsize'] = $NextObjectSize; - $thisfile_asf_extendedcontentdescriptionobject['content_descriptors_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - for ($ExtendedContentDescriptorsCounter = 0; $ExtendedContentDescriptorsCounter < $thisfile_asf_extendedcontentdescriptionobject['content_descriptors_count']; $ExtendedContentDescriptorsCounter++) { - // shortcut - $thisfile_asf_extendedcontentdescriptionobject['content_descriptors'][$ExtendedContentDescriptorsCounter] = array(); - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current = &$thisfile_asf_extendedcontentdescriptionobject['content_descriptors'][$ExtendedContentDescriptorsCounter]; - - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['base_offset'] = $offset + 30; - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name'] = substr($ASFHeaderData, $offset, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length']); - $offset += $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length']; - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = substr($ASFHeaderData, $offset, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length']); - $offset += $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length']; - switch ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type']) { - case 0x0000: // Unicode string - break; - - case 0x0001: // BYTE array - // do nothing - break; - - case 0x0002: // BOOL - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = (bool) getid3_lib::LittleEndian2Int($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']); - break; - - case 0x0003: // DWORD - case 0x0004: // QWORD - case 0x0005: // WORD - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = getid3_lib::LittleEndian2Int($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']); - break; - - default: - $this->warning('extended_content_description.content_descriptors.'.$ExtendedContentDescriptorsCounter.'.value_type is invalid ('.$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'].')'); - //return false; - break; - } - switch ($this->TrimConvert(strtolower($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name']))) { - - case 'wm/albumartist': - case 'artist': - // Note: not 'artist', that comes from 'author' tag - $thisfile_asf_comments['albumartist'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])); - break; - - case 'wm/albumtitle': - case 'album': - $thisfile_asf_comments['album'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])); - break; - - case 'wm/genre': - case 'genre': - $thisfile_asf_comments['genre'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])); - break; - - case 'wm/partofset': - $thisfile_asf_comments['partofset'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])); - break; - - case 'wm/tracknumber': - case 'tracknumber': - // be careful casting to int: casting unicode strings to int gives unexpected results (stops parsing at first non-numeric character) - $thisfile_asf_comments['track'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])); - foreach ($thisfile_asf_comments['track'] as $key => $value) { - if (preg_match('/^[0-9\x00]+$/', $value)) { - $thisfile_asf_comments['track'][$key] = intval(str_replace("\x00", '', $value)); - } - } - break; - - case 'wm/track': - if (empty($thisfile_asf_comments['track'])) { - $thisfile_asf_comments['track'] = array(1 + $this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])); - } - break; - - case 'wm/year': - case 'year': - case 'date': - $thisfile_asf_comments['year'] = array( $this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])); - break; - - case 'wm/lyrics': - case 'lyrics': - $thisfile_asf_comments['lyrics'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])); - break; - - case 'isvbr': - if ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']) { - $thisfile_audio['bitrate_mode'] = 'vbr'; - $thisfile_video['bitrate_mode'] = 'vbr'; - } - break; - - case 'id3': - $this->getid3->include_module('tag.id3v2'); - - $getid3_id3v2 = new getid3_id3v2($this->getid3); - $getid3_id3v2->AnalyzeString($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']); - unset($getid3_id3v2); - - if ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'] > 1024) { - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = ''; - } - break; - - case 'wm/encodingtime': - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['encoding_time_unix'] = $this->FILETIMEtoUNIXtime($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']); - $thisfile_asf_comments['encoding_time_unix'] = array($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['encoding_time_unix']); - break; - - case 'wm/picture': - $WMpicture = $this->ASF_WMpicture($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']); - foreach ($WMpicture as $key => $value) { - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current[$key] = $value; - } - unset($WMpicture); +class getid3_asf extends getid3_handler +{ + public function __construct(getID3 $getid3) + { + parent::__construct($getid3); // extends getid3_handler::__construct() + + // initialize all GUID constants + $GUIDarray = $this->KnownGUIDs(); + foreach ($GUIDarray as $GUIDname => $hexstringvalue) { + if (! defined($GUIDname)) { + define($GUIDname, $this->GUIDtoBytestring($hexstringvalue)); + } + } + } + + public function Analyze() + { + $info = &$this->getid3->info; + + // Shortcuts + $thisfile_audio = &$info['audio']; + $thisfile_video = &$info['video']; + $info['asf'] = []; + $thisfile_asf = &$info['asf']; + $thisfile_asf['comments'] = []; + $thisfile_asf_comments = &$thisfile_asf['comments']; + $thisfile_asf['header_object'] = []; + $thisfile_asf_headerobject = &$thisfile_asf['header_object']; + + // ASF structure: + // * Header Object [required] + // * File Properties Object [required] (global file attributes) + // * Stream Properties Object [required] (defines media stream & characteristics) + // * Header Extension Object [required] (additional functionality) + // * Content Description Object (bibliographic information) + // * Script Command Object (commands for during playback) + // * Marker Object (named jumped points within the file) + // * Data Object [required] + // * Data Packets + // * Index Object + + // Header Object: (mandatory, one only) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for header object - GETID3_ASF_Header_Object + // Object Size QWORD 64 // size of header object, including 30 bytes of Header Object header + // Number of Header Objects DWORD 32 // number of objects in header object + // Reserved1 BYTE 8 // hardcoded: 0x01 + // Reserved2 BYTE 8 // hardcoded: 0x02 + + $info['fileformat'] = 'asf'; + + $this->fseek($info['avdataoffset']); + $HeaderObjectData = $this->fread(30); + + $thisfile_asf_headerobject['objectid'] = substr($HeaderObjectData, 0, 16); + $thisfile_asf_headerobject['objectid_guid'] = $this->BytestringToGUID($thisfile_asf_headerobject['objectid']); + if ($thisfile_asf_headerobject['objectid'] != GETID3_ASF_Header_Object) { + unset($info['fileformat'], $info['asf']); + + return $this->error('ASF header GUID {'.$this->BytestringToGUID($thisfile_asf_headerobject['objectid']).'} does not match expected "GETID3_ASF_Header_Object" GUID {'.$this->BytestringToGUID(GETID3_ASF_Header_Object).'}'); + } + $thisfile_asf_headerobject['objectsize'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 16, 8)); + $thisfile_asf_headerobject['headerobjects'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 24, 4)); + $thisfile_asf_headerobject['reserved1'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 28, 1)); + $thisfile_asf_headerobject['reserved2'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 29, 1)); + + $NextObjectOffset = $this->ftell(); + $ASFHeaderData = $this->fread($thisfile_asf_headerobject['objectsize'] - 30); + $offset = 0; + + for ($HeaderObjectsCounter = 0; $HeaderObjectsCounter < $thisfile_asf_headerobject['headerobjects']; $HeaderObjectsCounter++) { + $NextObjectGUID = substr($ASFHeaderData, $offset, 16); + $offset += 16; + $NextObjectGUIDtext = $this->BytestringToGUID($NextObjectGUID); + $NextObjectSize = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); + $offset += 8; + switch ($NextObjectGUID) { + + case GETID3_ASF_File_Properties_Object: + // File Properties Object: (mandatory, one only) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for file properties object - GETID3_ASF_File_Properties_Object + // Object Size QWORD 64 // size of file properties object, including 104 bytes of File Properties Object header + // File ID GUID 128 // unique ID - identical to File ID in Data Object + // File Size QWORD 64 // entire file in bytes. Invalid if Broadcast Flag == 1 + // Creation Date QWORD 64 // date & time of file creation. Maybe invalid if Broadcast Flag == 1 + // Data Packets Count QWORD 64 // number of data packets in Data Object. Invalid if Broadcast Flag == 1 + // Play Duration QWORD 64 // playtime, in 100-nanosecond units. Invalid if Broadcast Flag == 1 + // Send Duration QWORD 64 // time needed to send file, in 100-nanosecond units. Players can ignore this value. Invalid if Broadcast Flag == 1 + // Preroll QWORD 64 // time to buffer data before starting to play file, in 1-millisecond units. If <> 0, PlayDuration and PresentationTime have been offset by this amount + // Flags DWORD 32 // + // * Broadcast Flag bits 1 (0x01) // file is currently being written, some header values are invalid + // * Seekable Flag bits 1 (0x02) // is file seekable + // * Reserved bits 30 (0xFFFFFFFC) // reserved - set to zero + // Minimum Data Packet Size DWORD 32 // in bytes. should be same as Maximum Data Packet Size. Invalid if Broadcast Flag == 1 + // Maximum Data Packet Size DWORD 32 // in bytes. should be same as Minimum Data Packet Size. Invalid if Broadcast Flag == 1 + // Maximum Bitrate DWORD 32 // maximum instantaneous bitrate in bits per second for entire file, including all data streams and ASF overhead + + // shortcut + $thisfile_asf['file_properties_object'] = []; + $thisfile_asf_filepropertiesobject = &$thisfile_asf['file_properties_object']; + + $thisfile_asf_filepropertiesobject['offset'] = $NextObjectOffset + $offset; + $thisfile_asf_filepropertiesobject['objectid'] = $NextObjectGUID; + $thisfile_asf_filepropertiesobject['objectid_guid'] = $NextObjectGUIDtext; + $thisfile_asf_filepropertiesobject['objectsize'] = $NextObjectSize; + $thisfile_asf_filepropertiesobject['fileid'] = substr($ASFHeaderData, $offset, 16); + $offset += 16; + $thisfile_asf_filepropertiesobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_filepropertiesobject['fileid']); + $thisfile_asf_filepropertiesobject['filesize'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); + $offset += 8; + $thisfile_asf_filepropertiesobject['creation_date'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); + $thisfile_asf_filepropertiesobject['creation_date_unix'] = $this->FILETIMEtoUNIXtime($thisfile_asf_filepropertiesobject['creation_date']); + $offset += 8; + $thisfile_asf_filepropertiesobject['data_packets'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); + $offset += 8; + $thisfile_asf_filepropertiesobject['play_duration'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); + $offset += 8; + $thisfile_asf_filepropertiesobject['send_duration'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); + $offset += 8; + $thisfile_asf_filepropertiesobject['preroll'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); + $offset += 8; + $thisfile_asf_filepropertiesobject['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + $offset += 4; + $thisfile_asf_filepropertiesobject['flags']['broadcast'] = (bool) ($thisfile_asf_filepropertiesobject['flags_raw'] & 0x0001); + $thisfile_asf_filepropertiesobject['flags']['seekable'] = (bool) ($thisfile_asf_filepropertiesobject['flags_raw'] & 0x0002); + + $thisfile_asf_filepropertiesobject['min_packet_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + $offset += 4; + $thisfile_asf_filepropertiesobject['max_packet_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + $offset += 4; + $thisfile_asf_filepropertiesobject['max_bitrate'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + $offset += 4; + + if ($thisfile_asf_filepropertiesobject['flags']['broadcast']) { + + // broadcast flag is set, some values invalid + unset($thisfile_asf_filepropertiesobject['filesize']); + unset($thisfile_asf_filepropertiesobject['data_packets']); + unset($thisfile_asf_filepropertiesobject['play_duration']); + unset($thisfile_asf_filepropertiesobject['send_duration']); + unset($thisfile_asf_filepropertiesobject['min_packet_size']); + unset($thisfile_asf_filepropertiesobject['max_packet_size']); + } else { + + // broadcast flag NOT set, perform calculations + $info['playtime_seconds'] = ($thisfile_asf_filepropertiesobject['play_duration'] / 10000000) - ($thisfile_asf_filepropertiesobject['preroll'] / 1000); + + //$info['bitrate'] = $thisfile_asf_filepropertiesobject['max_bitrate']; + $info['bitrate'] = ((isset($thisfile_asf_filepropertiesobject['filesize']) ? $thisfile_asf_filepropertiesobject['filesize'] : $info['filesize']) * 8) / $info['playtime_seconds']; + } + break; + + case GETID3_ASF_Stream_Properties_Object: + // Stream Properties Object: (mandatory, one per media stream) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for stream properties object - GETID3_ASF_Stream_Properties_Object + // Object Size QWORD 64 // size of stream properties object, including 78 bytes of Stream Properties Object header + // Stream Type GUID 128 // GETID3_ASF_Audio_Media, GETID3_ASF_Video_Media or GETID3_ASF_Command_Media + // Error Correction Type GUID 128 // GETID3_ASF_Audio_Spread for audio-only streams, GETID3_ASF_No_Error_Correction for other stream types + // Time Offset QWORD 64 // 100-nanosecond units. typically zero. added to all timestamps of samples in the stream + // Type-Specific Data Length DWORD 32 // number of bytes for Type-Specific Data field + // Error Correction Data Length DWORD 32 // number of bytes for Error Correction Data field + // Flags WORD 16 // + // * Stream Number bits 7 (0x007F) // number of this stream. 1 <= valid <= 127 + // * Reserved bits 8 (0x7F80) // reserved - set to zero + // * Encrypted Content Flag bits 1 (0x8000) // stream contents encrypted if set + // Reserved DWORD 32 // reserved - set to zero + // Type-Specific Data BYTESTREAM variable // type-specific format data, depending on value of Stream Type + // Error Correction Data BYTESTREAM variable // error-correction-specific format data, depending on value of Error Correct Type + + // There is one GETID3_ASF_Stream_Properties_Object for each stream (audio, video) but the + // stream number isn't known until halfway through decoding the structure, hence it + // it is decoded to a temporary variable and then stuck in the appropriate index later + + $StreamPropertiesObjectData['offset'] = $NextObjectOffset + $offset; + $StreamPropertiesObjectData['objectid'] = $NextObjectGUID; + $StreamPropertiesObjectData['objectid_guid'] = $NextObjectGUIDtext; + $StreamPropertiesObjectData['objectsize'] = $NextObjectSize; + $StreamPropertiesObjectData['stream_type'] = substr($ASFHeaderData, $offset, 16); + $offset += 16; + $StreamPropertiesObjectData['stream_type_guid'] = $this->BytestringToGUID($StreamPropertiesObjectData['stream_type']); + $StreamPropertiesObjectData['error_correct_type'] = substr($ASFHeaderData, $offset, 16); + $offset += 16; + $StreamPropertiesObjectData['error_correct_guid'] = $this->BytestringToGUID($StreamPropertiesObjectData['error_correct_type']); + $StreamPropertiesObjectData['time_offset'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); + $offset += 8; + $StreamPropertiesObjectData['type_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + $offset += 4; + $StreamPropertiesObjectData['error_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + $offset += 4; + $StreamPropertiesObjectData['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $StreamPropertiesObjectStreamNumber = $StreamPropertiesObjectData['flags_raw'] & 0x007F; + $StreamPropertiesObjectData['flags']['encrypted'] = (bool) ($StreamPropertiesObjectData['flags_raw'] & 0x8000); + + $offset += 4; // reserved - DWORD + $StreamPropertiesObjectData['type_specific_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['type_data_length']); + $offset += $StreamPropertiesObjectData['type_data_length']; + $StreamPropertiesObjectData['error_correct_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['error_data_length']); + $offset += $StreamPropertiesObjectData['error_data_length']; + + switch ($StreamPropertiesObjectData['stream_type']) { + + case GETID3_ASF_Audio_Media: + $thisfile_audio['dataformat'] = (! empty($thisfile_audio['dataformat']) ? $thisfile_audio['dataformat'] : 'asf'); + $thisfile_audio['bitrate_mode'] = (! empty($thisfile_audio['bitrate_mode']) ? $thisfile_audio['bitrate_mode'] : 'cbr'); + + $audiodata = getid3_riff::parseWAVEFORMATex(substr($StreamPropertiesObjectData['type_specific_data'], 0, 16)); + unset($audiodata['raw']); + $thisfile_audio = getid3_lib::array_merge_noclobber($audiodata, $thisfile_audio); + break; + + case GETID3_ASF_Video_Media: + $thisfile_video['dataformat'] = (! empty($thisfile_video['dataformat']) ? $thisfile_video['dataformat'] : 'asf'); + $thisfile_video['bitrate_mode'] = (! empty($thisfile_video['bitrate_mode']) ? $thisfile_video['bitrate_mode'] : 'cbr'); + break; + + case GETID3_ASF_Command_Media: + default: + // do nothing + break; + + } + + $thisfile_asf['stream_properties_object'][$StreamPropertiesObjectStreamNumber] = $StreamPropertiesObjectData; + unset($StreamPropertiesObjectData); // clear for next stream, if any + break; + + case GETID3_ASF_Header_Extension_Object: + // Header Extension Object: (mandatory, one only) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for Header Extension object - GETID3_ASF_Header_Extension_Object + // Object Size QWORD 64 // size of Header Extension object, including 46 bytes of Header Extension Object header + // Reserved Field 1 GUID 128 // hardcoded: GETID3_ASF_Reserved_1 + // Reserved Field 2 WORD 16 // hardcoded: 0x00000006 + // Header Extension Data Size DWORD 32 // in bytes. valid: 0, or > 24. equals object size minus 46 + // Header Extension Data BYTESTREAM variable // array of zero or more extended header objects + + // shortcut + $thisfile_asf['header_extension_object'] = []; + $thisfile_asf_headerextensionobject = &$thisfile_asf['header_extension_object']; + + $thisfile_asf_headerextensionobject['offset'] = $NextObjectOffset + $offset; + $thisfile_asf_headerextensionobject['objectid'] = $NextObjectGUID; + $thisfile_asf_headerextensionobject['objectid_guid'] = $NextObjectGUIDtext; + $thisfile_asf_headerextensionobject['objectsize'] = $NextObjectSize; + $thisfile_asf_headerextensionobject['reserved_1'] = substr($ASFHeaderData, $offset, 16); + $offset += 16; + $thisfile_asf_headerextensionobject['reserved_1_guid'] = $this->BytestringToGUID($thisfile_asf_headerextensionobject['reserved_1']); + if ($thisfile_asf_headerextensionobject['reserved_1'] != GETID3_ASF_Reserved_1) { + $this->warning('header_extension_object.reserved_1 GUID ('.$this->BytestringToGUID($thisfile_asf_headerextensionobject['reserved_1']).') does not match expected "GETID3_ASF_Reserved_1" GUID ('.$this->BytestringToGUID(GETID3_ASF_Reserved_1).')'); + //return false; + break; + } + $thisfile_asf_headerextensionobject['reserved_2'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + if ($thisfile_asf_headerextensionobject['reserved_2'] != 6) { + $this->warning('header_extension_object.reserved_2 ('.getid3_lib::PrintHexBytes($thisfile_asf_headerextensionobject['reserved_2']).') does not match expected value of "6"'); + //return false; + break; + } + $thisfile_asf_headerextensionobject['extension_data_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + $offset += 4; + $thisfile_asf_headerextensionobject['extension_data'] = substr($ASFHeaderData, $offset, $thisfile_asf_headerextensionobject['extension_data_size']); + $unhandled_sections = 0; + $thisfile_asf_headerextensionobject['extension_data_parsed'] = $this->HeaderExtensionObjectDataParse($thisfile_asf_headerextensionobject['extension_data'], $unhandled_sections); + if ($unhandled_sections === 0) { + unset($thisfile_asf_headerextensionobject['extension_data']); + } + $offset += $thisfile_asf_headerextensionobject['extension_data_size']; + break; + + case GETID3_ASF_Codec_List_Object: + // Codec List Object: (optional, one only) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for Codec List object - GETID3_ASF_Codec_List_Object + // Object Size QWORD 64 // size of Codec List object, including 44 bytes of Codec List Object header + // Reserved GUID 128 // hardcoded: 86D15241-311D-11D0-A3A4-00A0C90348F6 + // Codec Entries Count DWORD 32 // number of entries in Codec Entries array + // Codec Entries array of: variable // + // * Type WORD 16 // 0x0001 = Video Codec, 0x0002 = Audio Codec, 0xFFFF = Unknown Codec + // * Codec Name Length WORD 16 // number of Unicode characters stored in the Codec Name field + // * Codec Name WCHAR variable // array of Unicode characters - name of codec used to create the content + // * Codec Description Length WORD 16 // number of Unicode characters stored in the Codec Description field + // * Codec Description WCHAR variable // array of Unicode characters - description of format used to create the content + // * Codec Information Length WORD 16 // number of Unicode characters stored in the Codec Information field + // * Codec Information BYTESTREAM variable // opaque array of information bytes about the codec used to create the content + + // shortcut + $thisfile_asf['codec_list_object'] = []; + $thisfile_asf_codeclistobject = &$thisfile_asf['codec_list_object']; + + $thisfile_asf_codeclistobject['offset'] = $NextObjectOffset + $offset; + $thisfile_asf_codeclistobject['objectid'] = $NextObjectGUID; + $thisfile_asf_codeclistobject['objectid_guid'] = $NextObjectGUIDtext; + $thisfile_asf_codeclistobject['objectsize'] = $NextObjectSize; + $thisfile_asf_codeclistobject['reserved'] = substr($ASFHeaderData, $offset, 16); + $offset += 16; + $thisfile_asf_codeclistobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_codeclistobject['reserved']); + if ($thisfile_asf_codeclistobject['reserved'] != $this->GUIDtoBytestring('86D15241-311D-11D0-A3A4-00A0C90348F6')) { + $this->warning('codec_list_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_codeclistobject['reserved']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {86D15241-311D-11D0-A3A4-00A0C90348F6}'); + //return false; + break; + } + $thisfile_asf_codeclistobject['codec_entries_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + $offset += 4; + for ($CodecEntryCounter = 0; $CodecEntryCounter < $thisfile_asf_codeclistobject['codec_entries_count']; $CodecEntryCounter++) { + // shortcut + $thisfile_asf_codeclistobject['codec_entries'][$CodecEntryCounter] = []; + $thisfile_asf_codeclistobject_codecentries_current = &$thisfile_asf_codeclistobject['codec_entries'][$CodecEntryCounter]; + + $thisfile_asf_codeclistobject_codecentries_current['type_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_codeclistobject_codecentries_current['type'] = self::codecListObjectTypeLookup($thisfile_asf_codeclistobject_codecentries_current['type_raw']); + + $CodecNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character + $offset += 2; + $thisfile_asf_codeclistobject_codecentries_current['name'] = substr($ASFHeaderData, $offset, $CodecNameLength); + $offset += $CodecNameLength; + + $CodecDescriptionLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character + $offset += 2; + $thisfile_asf_codeclistobject_codecentries_current['description'] = substr($ASFHeaderData, $offset, $CodecDescriptionLength); + $offset += $CodecDescriptionLength; + + $CodecInformationLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_codeclistobject_codecentries_current['information'] = substr($ASFHeaderData, $offset, $CodecInformationLength); + $offset += $CodecInformationLength; + + if ($thisfile_asf_codeclistobject_codecentries_current['type_raw'] == 2) { // audio codec + + if (strpos($thisfile_asf_codeclistobject_codecentries_current['description'], ',') === false) { + $this->warning('[asf][codec_list_object][codec_entries]['.$CodecEntryCounter.'][description] expected to contain comma-separated list of parameters: "'.$thisfile_asf_codeclistobject_codecentries_current['description'].'"'); + } else { + list($AudioCodecBitrate, $AudioCodecFrequency, $AudioCodecChannels) = explode(',', $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description'])); + $thisfile_audio['codec'] = $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['name']); + + if (! isset($thisfile_audio['bitrate']) && strstr($AudioCodecBitrate, 'kbps')) { + $thisfile_audio['bitrate'] = (int) (trim(str_replace('kbps', '', $AudioCodecBitrate)) * 1000); + } + //if (!isset($thisfile_video['bitrate']) && isset($thisfile_audio['bitrate']) && isset($thisfile_asf['file_properties_object']['max_bitrate']) && ($thisfile_asf_codeclistobject['codec_entries_count'] > 1)) { + if (empty($thisfile_video['bitrate']) && ! empty($thisfile_audio['bitrate']) && ! empty($info['bitrate'])) { + //$thisfile_video['bitrate'] = $thisfile_asf['file_properties_object']['max_bitrate'] - $thisfile_audio['bitrate']; + $thisfile_video['bitrate'] = $info['bitrate'] - $thisfile_audio['bitrate']; + } + + $AudioCodecFrequency = (int) trim(str_replace('kHz', '', $AudioCodecFrequency)); + switch ($AudioCodecFrequency) { + case 8: + case 8000: + $thisfile_audio['sample_rate'] = 8000; + break; + + case 11: + case 11025: + $thisfile_audio['sample_rate'] = 11025; + break; + + case 12: + case 12000: + $thisfile_audio['sample_rate'] = 12000; + break; + + case 16: + case 16000: + $thisfile_audio['sample_rate'] = 16000; + break; + + case 22: + case 22050: + $thisfile_audio['sample_rate'] = 22050; + break; + + case 24: + case 24000: + $thisfile_audio['sample_rate'] = 24000; + break; + + case 32: + case 32000: + $thisfile_audio['sample_rate'] = 32000; + break; + + case 44: + case 441000: + $thisfile_audio['sample_rate'] = 44100; + break; + + case 48: + case 48000: + $thisfile_audio['sample_rate'] = 48000; + break; + + default: + $this->warning('unknown frequency: "'.$AudioCodecFrequency.'" ('.$this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description']).')'); + break; + } + + if (! isset($thisfile_audio['channels'])) { + if (strstr($AudioCodecChannels, 'stereo')) { + $thisfile_audio['channels'] = 2; + } elseif (strstr($AudioCodecChannels, 'mono')) { + $thisfile_audio['channels'] = 1; + } + } + } + } + } + break; + + case GETID3_ASF_Script_Command_Object: + // Script Command Object: (optional, one only) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for Script Command object - GETID3_ASF_Script_Command_Object + // Object Size QWORD 64 // size of Script Command object, including 44 bytes of Script Command Object header + // Reserved GUID 128 // hardcoded: 4B1ACBE3-100B-11D0-A39B-00A0C90348F6 + // Commands Count WORD 16 // number of Commands structures in the Script Commands Objects + // Command Types Count WORD 16 // number of Command Types structures in the Script Commands Objects + // Command Types array of: variable // + // * Command Type Name Length WORD 16 // number of Unicode characters for Command Type Name + // * Command Type Name WCHAR variable // array of Unicode characters - name of a type of command + // Commands array of: variable // + // * Presentation Time DWORD 32 // presentation time of that command, in milliseconds + // * Type Index WORD 16 // type of this command, as a zero-based index into the array of Command Types of this object + // * Command Name Length WORD 16 // number of Unicode characters for Command Name + // * Command Name WCHAR variable // array of Unicode characters - name of this command + + // shortcut + $thisfile_asf['script_command_object'] = []; + $thisfile_asf_scriptcommandobject = &$thisfile_asf['script_command_object']; + + $thisfile_asf_scriptcommandobject['offset'] = $NextObjectOffset + $offset; + $thisfile_asf_scriptcommandobject['objectid'] = $NextObjectGUID; + $thisfile_asf_scriptcommandobject['objectid_guid'] = $NextObjectGUIDtext; + $thisfile_asf_scriptcommandobject['objectsize'] = $NextObjectSize; + $thisfile_asf_scriptcommandobject['reserved'] = substr($ASFHeaderData, $offset, 16); + $offset += 16; + $thisfile_asf_scriptcommandobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_scriptcommandobject['reserved']); + if ($thisfile_asf_scriptcommandobject['reserved'] != $this->GUIDtoBytestring('4B1ACBE3-100B-11D0-A39B-00A0C90348F6')) { + $this->warning('script_command_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_scriptcommandobject['reserved']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {4B1ACBE3-100B-11D0-A39B-00A0C90348F6}'); + //return false; + break; + } + $thisfile_asf_scriptcommandobject['commands_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_scriptcommandobject['command_types_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + for ($CommandTypesCounter = 0; $CommandTypesCounter < $thisfile_asf_scriptcommandobject['command_types_count']; $CommandTypesCounter++) { + $CommandTypeNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character + $offset += 2; + $thisfile_asf_scriptcommandobject['command_types'][$CommandTypesCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength); + $offset += $CommandTypeNameLength; + } + for ($CommandsCounter = 0; $CommandsCounter < $thisfile_asf_scriptcommandobject['commands_count']; $CommandsCounter++) { + $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + $offset += 4; + $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['type_index'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + + $CommandTypeNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character + $offset += 2; + $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength); + $offset += $CommandTypeNameLength; + } + break; + + case GETID3_ASF_Marker_Object: + // Marker Object: (optional, one only) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for Marker object - GETID3_ASF_Marker_Object + // Object Size QWORD 64 // size of Marker object, including 48 bytes of Marker Object header + // Reserved GUID 128 // hardcoded: 4CFEDB20-75F6-11CF-9C0F-00A0C90349CB + // Markers Count DWORD 32 // number of Marker structures in Marker Object + // Reserved WORD 16 // hardcoded: 0x0000 + // Name Length WORD 16 // number of bytes in the Name field + // Name WCHAR variable // name of the Marker Object + // Markers array of: variable // + // * Offset QWORD 64 // byte offset into Data Object + // * Presentation Time QWORD 64 // in 100-nanosecond units + // * Entry Length WORD 16 // length in bytes of (Send Time + Flags + Marker Description Length + Marker Description + Padding) + // * Send Time DWORD 32 // in milliseconds + // * Flags DWORD 32 // hardcoded: 0x00000000 + // * Marker Description Length DWORD 32 // number of bytes in Marker Description field + // * Marker Description WCHAR variable // array of Unicode characters - description of marker entry + // * Padding BYTESTREAM variable // optional padding bytes + + // shortcut + $thisfile_asf['marker_object'] = []; + $thisfile_asf_markerobject = &$thisfile_asf['marker_object']; + + $thisfile_asf_markerobject['offset'] = $NextObjectOffset + $offset; + $thisfile_asf_markerobject['objectid'] = $NextObjectGUID; + $thisfile_asf_markerobject['objectid_guid'] = $NextObjectGUIDtext; + $thisfile_asf_markerobject['objectsize'] = $NextObjectSize; + $thisfile_asf_markerobject['reserved'] = substr($ASFHeaderData, $offset, 16); + $offset += 16; + $thisfile_asf_markerobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_markerobject['reserved']); + if ($thisfile_asf_markerobject['reserved'] != $this->GUIDtoBytestring('4CFEDB20-75F6-11CF-9C0F-00A0C90349CB')) { + $this->warning('marker_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_markerobject['reserved_1']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {4CFEDB20-75F6-11CF-9C0F-00A0C90349CB}'); + break; + } + $thisfile_asf_markerobject['markers_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + $offset += 4; + $thisfile_asf_markerobject['reserved_2'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + if ($thisfile_asf_markerobject['reserved_2'] != 0) { + $this->warning('marker_object.reserved_2 ('.getid3_lib::PrintHexBytes($thisfile_asf_markerobject['reserved_2']).') does not match expected value of "0"'); + break; + } + $thisfile_asf_markerobject['name_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_markerobject['name'] = substr($ASFHeaderData, $offset, $thisfile_asf_markerobject['name_length']); + $offset += $thisfile_asf_markerobject['name_length']; + for ($MarkersCounter = 0; $MarkersCounter < $thisfile_asf_markerobject['markers_count']; $MarkersCounter++) { + $thisfile_asf_markerobject['markers'][$MarkersCounter]['offset'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); + $offset += 8; + $thisfile_asf_markerobject['markers'][$MarkersCounter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); + $offset += 8; + $thisfile_asf_markerobject['markers'][$MarkersCounter]['entry_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_markerobject['markers'][$MarkersCounter]['send_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + $offset += 4; + $thisfile_asf_markerobject['markers'][$MarkersCounter]['flags'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + $offset += 4; + $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + $offset += 4; + $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description'] = substr($ASFHeaderData, $offset, $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length']); + $offset += $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length']; + $PaddingLength = $thisfile_asf_markerobject['markers'][$MarkersCounter]['entry_length'] - 4 - 4 - 4 - $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length']; + if ($PaddingLength > 0) { + $thisfile_asf_markerobject['markers'][$MarkersCounter]['padding'] = substr($ASFHeaderData, $offset, $PaddingLength); + $offset += $PaddingLength; + } + } + break; + + case GETID3_ASF_Bitrate_Mutual_Exclusion_Object: + // Bitrate Mutual Exclusion Object: (optional) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for Bitrate Mutual Exclusion object - GETID3_ASF_Bitrate_Mutual_Exclusion_Object + // Object Size QWORD 64 // size of Bitrate Mutual Exclusion object, including 42 bytes of Bitrate Mutual Exclusion Object header + // Exlusion Type GUID 128 // nature of mutual exclusion relationship. one of: (GETID3_ASF_Mutex_Bitrate, GETID3_ASF_Mutex_Unknown) + // Stream Numbers Count WORD 16 // number of video streams + // Stream Numbers WORD variable // array of mutually exclusive video stream numbers. 1 <= valid <= 127 + + // shortcut + $thisfile_asf['bitrate_mutual_exclusion_object'] = []; + $thisfile_asf_bitratemutualexclusionobject = &$thisfile_asf['bitrate_mutual_exclusion_object']; + + $thisfile_asf_bitratemutualexclusionobject['offset'] = $NextObjectOffset + $offset; + $thisfile_asf_bitratemutualexclusionobject['objectid'] = $NextObjectGUID; + $thisfile_asf_bitratemutualexclusionobject['objectid_guid'] = $NextObjectGUIDtext; + $thisfile_asf_bitratemutualexclusionobject['objectsize'] = $NextObjectSize; + $thisfile_asf_bitratemutualexclusionobject['reserved'] = substr($ASFHeaderData, $offset, 16); + $thisfile_asf_bitratemutualexclusionobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_bitratemutualexclusionobject['reserved']); + $offset += 16; + if (($thisfile_asf_bitratemutualexclusionobject['reserved'] != GETID3_ASF_Mutex_Bitrate) && ($thisfile_asf_bitratemutualexclusionobject['reserved'] != GETID3_ASF_Mutex_Unknown)) { + $this->warning('bitrate_mutual_exclusion_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_bitratemutualexclusionobject['reserved']).'} does not match expected "GETID3_ASF_Mutex_Bitrate" GUID {'.$this->BytestringToGUID(GETID3_ASF_Mutex_Bitrate).'} or "GETID3_ASF_Mutex_Unknown" GUID {'.$this->BytestringToGUID(GETID3_ASF_Mutex_Unknown).'}'); + //return false; + break; + } + $thisfile_asf_bitratemutualexclusionobject['stream_numbers_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + for ($StreamNumberCounter = 0; $StreamNumberCounter < $thisfile_asf_bitratemutualexclusionobject['stream_numbers_count']; $StreamNumberCounter++) { + $thisfile_asf_bitratemutualexclusionobject['stream_numbers'][$StreamNumberCounter] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + } + break; + + case GETID3_ASF_Error_Correction_Object: + // Error Correction Object: (optional, one only) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for Error Correction object - GETID3_ASF_Error_Correction_Object + // Object Size QWORD 64 // size of Error Correction object, including 44 bytes of Error Correction Object header + // Error Correction Type GUID 128 // type of error correction. one of: (GETID3_ASF_No_Error_Correction, GETID3_ASF_Audio_Spread) + // Error Correction Data Length DWORD 32 // number of bytes in Error Correction Data field + // Error Correction Data BYTESTREAM variable // structure depends on value of Error Correction Type field + + // shortcut + $thisfile_asf['error_correction_object'] = []; + $thisfile_asf_errorcorrectionobject = &$thisfile_asf['error_correction_object']; + + $thisfile_asf_errorcorrectionobject['offset'] = $NextObjectOffset + $offset; + $thisfile_asf_errorcorrectionobject['objectid'] = $NextObjectGUID; + $thisfile_asf_errorcorrectionobject['objectid_guid'] = $NextObjectGUIDtext; + $thisfile_asf_errorcorrectionobject['objectsize'] = $NextObjectSize; + $thisfile_asf_errorcorrectionobject['error_correction_type'] = substr($ASFHeaderData, $offset, 16); + $offset += 16; + $thisfile_asf_errorcorrectionobject['error_correction_guid'] = $this->BytestringToGUID($thisfile_asf_errorcorrectionobject['error_correction_type']); + $thisfile_asf_errorcorrectionobject['error_correction_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + $offset += 4; + switch ($thisfile_asf_errorcorrectionobject['error_correction_type']) { + case GETID3_ASF_No_Error_Correction: + // should be no data, but just in case there is, skip to the end of the field + $offset += $thisfile_asf_errorcorrectionobject['error_correction_data_length']; + break; + + case GETID3_ASF_Audio_Spread: + // Field Name Field Type Size (bits) + // Span BYTE 8 // number of packets over which audio will be spread. + // Virtual Packet Length WORD 16 // size of largest audio payload found in audio stream + // Virtual Chunk Length WORD 16 // size of largest audio payload found in audio stream + // Silence Data Length WORD 16 // number of bytes in Silence Data field + // Silence Data BYTESTREAM variable // hardcoded: 0x00 * (Silence Data Length) bytes + + $thisfile_asf_errorcorrectionobject['span'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 1)); + $offset += 1; + $thisfile_asf_errorcorrectionobject['virtual_packet_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_errorcorrectionobject['virtual_chunk_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_errorcorrectionobject['silence_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_errorcorrectionobject['silence_data'] = substr($ASFHeaderData, $offset, $thisfile_asf_errorcorrectionobject['silence_data_length']); + $offset += $thisfile_asf_errorcorrectionobject['silence_data_length']; + break; + + default: + $this->warning('error_correction_object.error_correction_type GUID {'.$this->BytestringToGUID($thisfile_asf_errorcorrectionobject['reserved']).'} does not match expected "GETID3_ASF_No_Error_Correction" GUID {'.$this->BytestringToGUID(GETID3_ASF_No_Error_Correction).'} or "GETID3_ASF_Audio_Spread" GUID {'.$this->BytestringToGUID(GETID3_ASF_Audio_Spread).'}'); + //return false; + break; + } + + break; + + case GETID3_ASF_Content_Description_Object: + // Content Description Object: (optional, one only) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for Content Description object - GETID3_ASF_Content_Description_Object + // Object Size QWORD 64 // size of Content Description object, including 34 bytes of Content Description Object header + // Title Length WORD 16 // number of bytes in Title field + // Author Length WORD 16 // number of bytes in Author field + // Copyright Length WORD 16 // number of bytes in Copyright field + // Description Length WORD 16 // number of bytes in Description field + // Rating Length WORD 16 // number of bytes in Rating field + // Title WCHAR 16 // array of Unicode characters - Title + // Author WCHAR 16 // array of Unicode characters - Author + // Copyright WCHAR 16 // array of Unicode characters - Copyright + // Description WCHAR 16 // array of Unicode characters - Description + // Rating WCHAR 16 // array of Unicode characters - Rating + + // shortcut + $thisfile_asf['content_description_object'] = []; + $thisfile_asf_contentdescriptionobject = &$thisfile_asf['content_description_object']; + + $thisfile_asf_contentdescriptionobject['offset'] = $NextObjectOffset + $offset; + $thisfile_asf_contentdescriptionobject['objectid'] = $NextObjectGUID; + $thisfile_asf_contentdescriptionobject['objectid_guid'] = $NextObjectGUIDtext; + $thisfile_asf_contentdescriptionobject['objectsize'] = $NextObjectSize; + $thisfile_asf_contentdescriptionobject['title_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_contentdescriptionobject['author_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_contentdescriptionobject['copyright_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_contentdescriptionobject['description_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_contentdescriptionobject['rating_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_contentdescriptionobject['title'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['title_length']); + $offset += $thisfile_asf_contentdescriptionobject['title_length']; + $thisfile_asf_contentdescriptionobject['author'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['author_length']); + $offset += $thisfile_asf_contentdescriptionobject['author_length']; + $thisfile_asf_contentdescriptionobject['copyright'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['copyright_length']); + $offset += $thisfile_asf_contentdescriptionobject['copyright_length']; + $thisfile_asf_contentdescriptionobject['description'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['description_length']); + $offset += $thisfile_asf_contentdescriptionobject['description_length']; + $thisfile_asf_contentdescriptionobject['rating'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['rating_length']); + $offset += $thisfile_asf_contentdescriptionobject['rating_length']; + + $ASFcommentKeysToCopy = ['title'=>'title', 'author'=>'artist', 'copyright'=>'copyright', 'description'=>'comment', 'rating'=>'rating']; + foreach ($ASFcommentKeysToCopy as $keytocopyfrom => $keytocopyto) { + if (! empty($thisfile_asf_contentdescriptionobject[$keytocopyfrom])) { + $thisfile_asf_comments[$keytocopyto][] = $this->TrimTerm($thisfile_asf_contentdescriptionobject[$keytocopyfrom]); + } + } + break; + + case GETID3_ASF_Extended_Content_Description_Object: + // Extended Content Description Object: (optional, one only) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for Extended Content Description object - GETID3_ASF_Extended_Content_Description_Object + // Object Size QWORD 64 // size of ExtendedContent Description object, including 26 bytes of Extended Content Description Object header + // Content Descriptors Count WORD 16 // number of entries in Content Descriptors list + // Content Descriptors array of: variable // + // * Descriptor Name Length WORD 16 // size in bytes of Descriptor Name field + // * Descriptor Name WCHAR variable // array of Unicode characters - Descriptor Name + // * Descriptor Value Data Type WORD 16 // Lookup array: + // 0x0000 = Unicode String (variable length) + // 0x0001 = BYTE array (variable length) + // 0x0002 = BOOL (DWORD, 32 bits) + // 0x0003 = DWORD (DWORD, 32 bits) + // 0x0004 = QWORD (QWORD, 64 bits) + // 0x0005 = WORD (WORD, 16 bits) + // * Descriptor Value Length WORD 16 // number of bytes stored in Descriptor Value field + // * Descriptor Value variable variable // value for Content Descriptor + + // shortcut + $thisfile_asf['extended_content_description_object'] = []; + $thisfile_asf_extendedcontentdescriptionobject = &$thisfile_asf['extended_content_description_object']; + + $thisfile_asf_extendedcontentdescriptionobject['offset'] = $NextObjectOffset + $offset; + $thisfile_asf_extendedcontentdescriptionobject['objectid'] = $NextObjectGUID; + $thisfile_asf_extendedcontentdescriptionobject['objectid_guid'] = $NextObjectGUIDtext; + $thisfile_asf_extendedcontentdescriptionobject['objectsize'] = $NextObjectSize; + $thisfile_asf_extendedcontentdescriptionobject['content_descriptors_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + for ($ExtendedContentDescriptorsCounter = 0; $ExtendedContentDescriptorsCounter < $thisfile_asf_extendedcontentdescriptionobject['content_descriptors_count']; $ExtendedContentDescriptorsCounter++) { + // shortcut + $thisfile_asf_extendedcontentdescriptionobject['content_descriptors'][$ExtendedContentDescriptorsCounter] = []; + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current = &$thisfile_asf_extendedcontentdescriptionobject['content_descriptors'][$ExtendedContentDescriptorsCounter]; + + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['base_offset'] = $offset + 30; + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name'] = substr($ASFHeaderData, $offset, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length']); + $offset += $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length']; + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = substr($ASFHeaderData, $offset, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length']); + $offset += $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length']; + switch ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type']) { + case 0x0000: // Unicode string + break; + + case 0x0001: // BYTE array + // do nothing + break; + + case 0x0002: // BOOL + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = (bool) getid3_lib::LittleEndian2Int($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']); + break; + + case 0x0003: // DWORD + case 0x0004: // QWORD + case 0x0005: // WORD + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = getid3_lib::LittleEndian2Int($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']); + break; + + default: + $this->warning('extended_content_description.content_descriptors.'.$ExtendedContentDescriptorsCounter.'.value_type is invalid ('.$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'].')'); + //return false; + break; + } + switch ($this->TrimConvert(strtolower($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name']))) { + + case 'wm/albumartist': + case 'artist': + // Note: not 'artist', that comes from 'author' tag + $thisfile_asf_comments['albumartist'] = [$this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])]; + break; + + case 'wm/albumtitle': + case 'album': + $thisfile_asf_comments['album'] = [$this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])]; + break; + + case 'wm/genre': + case 'genre': + $thisfile_asf_comments['genre'] = [$this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])]; + break; + + case 'wm/partofset': + $thisfile_asf_comments['partofset'] = [$this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])]; + break; + + case 'wm/tracknumber': + case 'tracknumber': + // be careful casting to int: casting unicode strings to int gives unexpected results (stops parsing at first non-numeric character) + $thisfile_asf_comments['track'] = [$this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])]; + foreach ($thisfile_asf_comments['track'] as $key => $value) { + if (preg_match('/^[0-9\x00]+$/', $value)) { + $thisfile_asf_comments['track'][$key] = intval(str_replace("\x00", '', $value)); + } + } + break; + + case 'wm/track': + if (empty($thisfile_asf_comments['track'])) { + $thisfile_asf_comments['track'] = [1 + $this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])]; + } + break; + + case 'wm/year': + case 'year': + case 'date': + $thisfile_asf_comments['year'] = [$this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])]; + break; + + case 'wm/lyrics': + case 'lyrics': + $thisfile_asf_comments['lyrics'] = [$this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])]; + break; + + case 'isvbr': + if ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']) { + $thisfile_audio['bitrate_mode'] = 'vbr'; + $thisfile_video['bitrate_mode'] = 'vbr'; + } + break; + + case 'id3': + $this->getid3->include_module('tag.id3v2'); + + $getid3_id3v2 = new getid3_id3v2($this->getid3); + $getid3_id3v2->AnalyzeString($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']); + unset($getid3_id3v2); + + if ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'] > 1024) { + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = ''; + } + break; + + case 'wm/encodingtime': + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['encoding_time_unix'] = $this->FILETIMEtoUNIXtime($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']); + $thisfile_asf_comments['encoding_time_unix'] = [$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['encoding_time_unix']]; + break; + + case 'wm/picture': + $WMpicture = $this->ASF_WMpicture($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']); + foreach ($WMpicture as $key => $value) { + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current[$key] = $value; + } + unset($WMpicture); /* - $wm_picture_offset = 0; - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 1)); - $wm_picture_offset += 1; - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type'] = self::WMpictureTypeLookup($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id']); - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 4)); - $wm_picture_offset += 4; + $wm_picture_offset = 0; + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 1)); + $wm_picture_offset += 1; + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type'] = self::WMpictureTypeLookup($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id']); + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 4)); + $wm_picture_offset += 4; - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] = ''; - do { - $next_byte_pair = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 2); - $wm_picture_offset += 2; - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] .= $next_byte_pair; - } while ($next_byte_pair !== "\x00\x00"); + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] = ''; + do { + $next_byte_pair = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 2); + $wm_picture_offset += 2; + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] .= $next_byte_pair; + } while ($next_byte_pair !== "\x00\x00"); - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_description'] = ''; - do { - $next_byte_pair = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 2); - $wm_picture_offset += 2; - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_description'] .= $next_byte_pair; - } while ($next_byte_pair !== "\x00\x00"); + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_description'] = ''; + do { + $next_byte_pair = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 2); + $wm_picture_offset += 2; + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_description'] .= $next_byte_pair; + } while ($next_byte_pair !== "\x00\x00"); - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['dataoffset'] = $wm_picture_offset; - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'] = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset); - unset($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']); + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['dataoffset'] = $wm_picture_offset; + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'] = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset); + unset($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']); - $imageinfo = array(); - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] = ''; - $imagechunkcheck = getid3_lib::GetDataImageSize($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'], $imageinfo); - unset($imageinfo); - if (!empty($imagechunkcheck)) { - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]); - } - if (!isset($thisfile_asf_comments['picture'])) { - $thisfile_asf_comments['picture'] = array(); - } - $thisfile_asf_comments['picture'][] = array('data'=>$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'], 'image_mime'=>$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime']); + $imageinfo = array(); + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] = ''; + $imagechunkcheck = getid3_lib::GetDataImageSize($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'], $imageinfo); + unset($imageinfo); + if (!empty($imagechunkcheck)) { + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]); + } + if (!isset($thisfile_asf_comments['picture'])) { + $thisfile_asf_comments['picture'] = array(); + } + $thisfile_asf_comments['picture'][] = array('data'=>$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'], 'image_mime'=>$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime']); */ - break; - - default: - switch ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type']) { - case 0: // Unicode string - if (substr($this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name']), 0, 3) == 'WM/') { - $thisfile_asf_comments[str_replace('wm/', '', strtolower($this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name'])))] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])); - } - break; - - case 1: - break; - } - break; - } - - } - break; - - case GETID3_ASF_Stream_Bitrate_Properties_Object: - // Stream Bitrate Properties Object: (optional, one only) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for Stream Bitrate Properties object - GETID3_ASF_Stream_Bitrate_Properties_Object - // Object Size QWORD 64 // size of Extended Content Description object, including 26 bytes of Stream Bitrate Properties Object header - // Bitrate Records Count WORD 16 // number of records in Bitrate Records - // Bitrate Records array of: variable // - // * Flags WORD 16 // - // * * Stream Number bits 7 (0x007F) // number of this stream - // * * Reserved bits 9 (0xFF80) // hardcoded: 0 - // * Average Bitrate DWORD 32 // in bits per second - - // shortcut - $thisfile_asf['stream_bitrate_properties_object'] = array(); - $thisfile_asf_streambitratepropertiesobject = &$thisfile_asf['stream_bitrate_properties_object']; - - $thisfile_asf_streambitratepropertiesobject['offset'] = $NextObjectOffset + $offset; - $thisfile_asf_streambitratepropertiesobject['objectid'] = $NextObjectGUID; - $thisfile_asf_streambitratepropertiesobject['objectid_guid'] = $NextObjectGUIDtext; - $thisfile_asf_streambitratepropertiesobject['objectsize'] = $NextObjectSize; - $thisfile_asf_streambitratepropertiesobject['bitrate_records_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitratepropertiesobject['bitrate_records_count']; $BitrateRecordsCounter++) { - $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); - $offset += 2; - $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags']['stream_number'] = $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] & 0x007F; - $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['bitrate'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); - $offset += 4; - } - break; - - case GETID3_ASF_Padding_Object: - // Padding Object: (optional) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for Padding object - GETID3_ASF_Padding_Object - // Object Size QWORD 64 // size of Padding object, including 24 bytes of ASF Padding Object header - // Padding Data BYTESTREAM variable // ignore - - // shortcut - $thisfile_asf['padding_object'] = array(); - $thisfile_asf_paddingobject = &$thisfile_asf['padding_object']; - - $thisfile_asf_paddingobject['offset'] = $NextObjectOffset + $offset; - $thisfile_asf_paddingobject['objectid'] = $NextObjectGUID; - $thisfile_asf_paddingobject['objectid_guid'] = $NextObjectGUIDtext; - $thisfile_asf_paddingobject['objectsize'] = $NextObjectSize; - $thisfile_asf_paddingobject['padding_length'] = $thisfile_asf_paddingobject['objectsize'] - 16 - 8; - $thisfile_asf_paddingobject['padding'] = substr($ASFHeaderData, $offset, $thisfile_asf_paddingobject['padding_length']); - $offset += ($NextObjectSize - 16 - 8); - break; - - case GETID3_ASF_Extended_Content_Encryption_Object: - case GETID3_ASF_Content_Encryption_Object: - // WMA DRM - just ignore - $offset += ($NextObjectSize - 16 - 8); - break; - - default: - // Implementations shall ignore any standard or non-standard object that they do not know how to handle. - if ($this->GUIDname($NextObjectGUIDtext)) { - $this->warning('unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF header at offset '.($offset - 16 - 8)); - } else { - $this->warning('unknown GUID {'.$NextObjectGUIDtext.'} in ASF header at offset '.($offset - 16 - 8)); - } - $offset += ($NextObjectSize - 16 - 8); - break; - } - } - if (isset($thisfile_asf_streambitrateproperties['bitrate_records_count'])) { - $ASFbitrateAudio = 0; - $ASFbitrateVideo = 0; - for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitrateproperties['bitrate_records_count']; $BitrateRecordsCounter++) { - if (isset($thisfile_asf_codeclistobject['codec_entries'][$BitrateRecordsCounter])) { - switch ($thisfile_asf_codeclistobject['codec_entries'][$BitrateRecordsCounter]['type_raw']) { - case 1: - $ASFbitrateVideo += $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate']; - break; - - case 2: - $ASFbitrateAudio += $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate']; - break; - - default: - // do nothing - break; - } - } - } - if ($ASFbitrateAudio > 0) { - $thisfile_audio['bitrate'] = $ASFbitrateAudio; - } - if ($ASFbitrateVideo > 0) { - $thisfile_video['bitrate'] = $ASFbitrateVideo; - } - } - if (isset($thisfile_asf['stream_properties_object']) && is_array($thisfile_asf['stream_properties_object'])) { - - $thisfile_audio['bitrate'] = 0; - $thisfile_video['bitrate'] = 0; - - foreach ($thisfile_asf['stream_properties_object'] as $streamnumber => $streamdata) { - - switch ($streamdata['stream_type']) { - case GETID3_ASF_Audio_Media: - // Field Name Field Type Size (bits) - // Codec ID / Format Tag WORD 16 // unique ID of audio codec - defined as wFormatTag field of WAVEFORMATEX structure - // Number of Channels WORD 16 // number of channels of audio - defined as nChannels field of WAVEFORMATEX structure - // Samples Per Second DWORD 32 // in Hertz - defined as nSamplesPerSec field of WAVEFORMATEX structure - // Average number of Bytes/sec DWORD 32 // bytes/sec of audio stream - defined as nAvgBytesPerSec field of WAVEFORMATEX structure - // Block Alignment WORD 16 // block size in bytes of audio codec - defined as nBlockAlign field of WAVEFORMATEX structure - // Bits per sample WORD 16 // bits per sample of mono data. set to zero for variable bitrate codecs. defined as wBitsPerSample field of WAVEFORMATEX structure - // Codec Specific Data Size WORD 16 // size in bytes of Codec Specific Data buffer - defined as cbSize field of WAVEFORMATEX structure - // Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes - - // shortcut - $thisfile_asf['audio_media'][$streamnumber] = array(); - $thisfile_asf_audiomedia_currentstream = &$thisfile_asf['audio_media'][$streamnumber]; - - $audiomediaoffset = 0; - - $thisfile_asf_audiomedia_currentstream = getid3_riff::parseWAVEFORMATex(substr($streamdata['type_specific_data'], $audiomediaoffset, 16)); - $audiomediaoffset += 16; - - $thisfile_audio['lossless'] = false; - switch ($thisfile_asf_audiomedia_currentstream['raw']['wFormatTag']) { - case 0x0001: // PCM - case 0x0163: // WMA9 Lossless - $thisfile_audio['lossless'] = true; - break; - } - - if (!empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) { - foreach ($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'] as $dummy => $dataarray) { - if (isset($dataarray['flags']['stream_number']) && ($dataarray['flags']['stream_number'] == $streamnumber)) { - $thisfile_asf_audiomedia_currentstream['bitrate'] = $dataarray['bitrate']; - $thisfile_audio['bitrate'] += $dataarray['bitrate']; - break; - } - } - } else { - if (!empty($thisfile_asf_audiomedia_currentstream['bytes_sec'])) { - $thisfile_audio['bitrate'] += $thisfile_asf_audiomedia_currentstream['bytes_sec'] * 8; - } elseif (!empty($thisfile_asf_audiomedia_currentstream['bitrate'])) { - $thisfile_audio['bitrate'] += $thisfile_asf_audiomedia_currentstream['bitrate']; - } - } - $thisfile_audio['streams'][$streamnumber] = $thisfile_asf_audiomedia_currentstream; - $thisfile_audio['streams'][$streamnumber]['wformattag'] = $thisfile_asf_audiomedia_currentstream['raw']['wFormatTag']; - $thisfile_audio['streams'][$streamnumber]['lossless'] = $thisfile_audio['lossless']; - $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate']; - $thisfile_audio['streams'][$streamnumber]['dataformat'] = 'wma'; - unset($thisfile_audio['streams'][$streamnumber]['raw']); - - $thisfile_asf_audiomedia_currentstream['codec_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $audiomediaoffset, 2)); - $audiomediaoffset += 2; - $thisfile_asf_audiomedia_currentstream['codec_data'] = substr($streamdata['type_specific_data'], $audiomediaoffset, $thisfile_asf_audiomedia_currentstream['codec_data_size']); - $audiomediaoffset += $thisfile_asf_audiomedia_currentstream['codec_data_size']; - - break; - - case GETID3_ASF_Video_Media: - // Field Name Field Type Size (bits) - // Encoded Image Width DWORD 32 // width of image in pixels - // Encoded Image Height DWORD 32 // height of image in pixels - // Reserved Flags BYTE 8 // hardcoded: 0x02 - // Format Data Size WORD 16 // size of Format Data field in bytes - // Format Data array of: variable // - // * Format Data Size DWORD 32 // number of bytes in Format Data field, in bytes - defined as biSize field of BITMAPINFOHEADER structure - // * Image Width LONG 32 // width of encoded image in pixels - defined as biWidth field of BITMAPINFOHEADER structure - // * Image Height LONG 32 // height of encoded image in pixels - defined as biHeight field of BITMAPINFOHEADER structure - // * Reserved WORD 16 // hardcoded: 0x0001 - defined as biPlanes field of BITMAPINFOHEADER structure - // * Bits Per Pixel Count WORD 16 // bits per pixel - defined as biBitCount field of BITMAPINFOHEADER structure - // * Compression ID FOURCC 32 // fourcc of video codec - defined as biCompression field of BITMAPINFOHEADER structure - // * Image Size DWORD 32 // image size in bytes - defined as biSizeImage field of BITMAPINFOHEADER structure - // * Horizontal Pixels / Meter DWORD 32 // horizontal resolution of target device in pixels per meter - defined as biXPelsPerMeter field of BITMAPINFOHEADER structure - // * Vertical Pixels / Meter DWORD 32 // vertical resolution of target device in pixels per meter - defined as biYPelsPerMeter field of BITMAPINFOHEADER structure - // * Colors Used Count DWORD 32 // number of color indexes in the color table that are actually used - defined as biClrUsed field of BITMAPINFOHEADER structure - // * Important Colors Count DWORD 32 // number of color index required for displaying bitmap. if zero, all colors are required. defined as biClrImportant field of BITMAPINFOHEADER structure - // * Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes - - // shortcut - $thisfile_asf['video_media'][$streamnumber] = array(); - $thisfile_asf_videomedia_currentstream = &$thisfile_asf['video_media'][$streamnumber]; - - $videomediaoffset = 0; - $thisfile_asf_videomedia_currentstream['image_width'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); - $videomediaoffset += 4; - $thisfile_asf_videomedia_currentstream['image_height'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); - $videomediaoffset += 4; - $thisfile_asf_videomedia_currentstream['flags'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 1)); - $videomediaoffset += 1; - $thisfile_asf_videomedia_currentstream['format_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2)); - $videomediaoffset += 2; - $thisfile_asf_videomedia_currentstream['format_data']['format_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); - $videomediaoffset += 4; - $thisfile_asf_videomedia_currentstream['format_data']['image_width'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); - $videomediaoffset += 4; - $thisfile_asf_videomedia_currentstream['format_data']['image_height'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); - $videomediaoffset += 4; - $thisfile_asf_videomedia_currentstream['format_data']['reserved'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2)); - $videomediaoffset += 2; - $thisfile_asf_videomedia_currentstream['format_data']['bits_per_pixel'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2)); - $videomediaoffset += 2; - $thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc'] = substr($streamdata['type_specific_data'], $videomediaoffset, 4); - $videomediaoffset += 4; - $thisfile_asf_videomedia_currentstream['format_data']['image_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); - $videomediaoffset += 4; - $thisfile_asf_videomedia_currentstream['format_data']['horizontal_pels'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); - $videomediaoffset += 4; - $thisfile_asf_videomedia_currentstream['format_data']['vertical_pels'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); - $videomediaoffset += 4; - $thisfile_asf_videomedia_currentstream['format_data']['colors_used'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); - $videomediaoffset += 4; - $thisfile_asf_videomedia_currentstream['format_data']['colors_important'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); - $videomediaoffset += 4; - $thisfile_asf_videomedia_currentstream['format_data']['codec_data'] = substr($streamdata['type_specific_data'], $videomediaoffset); - - if (!empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) { - foreach ($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'] as $dummy => $dataarray) { - if (isset($dataarray['flags']['stream_number']) && ($dataarray['flags']['stream_number'] == $streamnumber)) { - $thisfile_asf_videomedia_currentstream['bitrate'] = $dataarray['bitrate']; - $thisfile_video['streams'][$streamnumber]['bitrate'] = $dataarray['bitrate']; - $thisfile_video['bitrate'] += $dataarray['bitrate']; - break; - } - } - } - - $thisfile_asf_videomedia_currentstream['format_data']['codec'] = getid3_riff::fourccLookup($thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc']); - - $thisfile_video['streams'][$streamnumber]['fourcc'] = $thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc']; - $thisfile_video['streams'][$streamnumber]['codec'] = $thisfile_asf_videomedia_currentstream['format_data']['codec']; - $thisfile_video['streams'][$streamnumber]['resolution_x'] = $thisfile_asf_videomedia_currentstream['image_width']; - $thisfile_video['streams'][$streamnumber]['resolution_y'] = $thisfile_asf_videomedia_currentstream['image_height']; - $thisfile_video['streams'][$streamnumber]['bits_per_sample'] = $thisfile_asf_videomedia_currentstream['format_data']['bits_per_pixel']; - break; - - default: - break; - } - } - } - - while ($this->ftell() < $info['avdataend']) { - $NextObjectDataHeader = $this->fread(24); - $offset = 0; - $NextObjectGUID = substr($NextObjectDataHeader, 0, 16); - $offset += 16; - $NextObjectGUIDtext = $this->BytestringToGUID($NextObjectGUID); - $NextObjectSize = getid3_lib::LittleEndian2Int(substr($NextObjectDataHeader, $offset, 8)); - $offset += 8; - - switch ($NextObjectGUID) { - case GETID3_ASF_Data_Object: - // Data Object: (mandatory, one only) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for Data object - GETID3_ASF_Data_Object - // Object Size QWORD 64 // size of Data object, including 50 bytes of Data Object header. may be 0 if FilePropertiesObject.BroadcastFlag == 1 - // File ID GUID 128 // unique identifier. identical to File ID field in Header Object - // Total Data Packets QWORD 64 // number of Data Packet entries in Data Object. invalid if FilePropertiesObject.BroadcastFlag == 1 - // Reserved WORD 16 // hardcoded: 0x0101 - - // shortcut - $thisfile_asf['data_object'] = array(); - $thisfile_asf_dataobject = &$thisfile_asf['data_object']; - - $DataObjectData = $NextObjectDataHeader.$this->fread(50 - 24); - $offset = 24; - - $thisfile_asf_dataobject['objectid'] = $NextObjectGUID; - $thisfile_asf_dataobject['objectid_guid'] = $NextObjectGUIDtext; - $thisfile_asf_dataobject['objectsize'] = $NextObjectSize; - - $thisfile_asf_dataobject['fileid'] = substr($DataObjectData, $offset, 16); - $offset += 16; - $thisfile_asf_dataobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_dataobject['fileid']); - $thisfile_asf_dataobject['total_data_packets'] = getid3_lib::LittleEndian2Int(substr($DataObjectData, $offset, 8)); - $offset += 8; - $thisfile_asf_dataobject['reserved'] = getid3_lib::LittleEndian2Int(substr($DataObjectData, $offset, 2)); - $offset += 2; - if ($thisfile_asf_dataobject['reserved'] != 0x0101) { - $this->warning('data_object.reserved ('.getid3_lib::PrintHexBytes($thisfile_asf_dataobject['reserved']).') does not match expected value of "0x0101"'); - //return false; - break; - } - - // Data Packets array of: variable // - // * Error Correction Flags BYTE 8 // - // * * Error Correction Data Length bits 4 // if Error Correction Length Type == 00, size of Error Correction Data in bytes, else hardcoded: 0000 - // * * Opaque Data Present bits 1 // - // * * Error Correction Length Type bits 2 // number of bits for size of the error correction data. hardcoded: 00 - // * * Error Correction Present bits 1 // If set, use Opaque Data Packet structure, else use Payload structure - // * Error Correction Data - - $info['avdataoffset'] = $this->ftell(); - $this->fseek(($thisfile_asf_dataobject['objectsize'] - 50), SEEK_CUR); // skip actual audio/video data - $info['avdataend'] = $this->ftell(); - break; - - case GETID3_ASF_Simple_Index_Object: - // Simple Index Object: (optional, recommended, one per video stream) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for Simple Index object - GETID3_ASF_Data_Object - // Object Size QWORD 64 // size of Simple Index object, including 56 bytes of Simple Index Object header - // File ID GUID 128 // unique identifier. may be zero or identical to File ID field in Data Object and Header Object - // Index Entry Time Interval QWORD 64 // interval between index entries in 100-nanosecond units - // Maximum Packet Count DWORD 32 // maximum packet count for all index entries - // Index Entries Count DWORD 32 // number of Index Entries structures - // Index Entries array of: variable // - // * Packet Number DWORD 32 // number of the Data Packet associated with this index entry - // * Packet Count WORD 16 // number of Data Packets to sent at this index entry - - // shortcut - $thisfile_asf['simple_index_object'] = array(); - $thisfile_asf_simpleindexobject = &$thisfile_asf['simple_index_object']; - - $SimpleIndexObjectData = $NextObjectDataHeader.$this->fread(56 - 24); - $offset = 24; - - $thisfile_asf_simpleindexobject['objectid'] = $NextObjectGUID; - $thisfile_asf_simpleindexobject['objectid_guid'] = $NextObjectGUIDtext; - $thisfile_asf_simpleindexobject['objectsize'] = $NextObjectSize; - - $thisfile_asf_simpleindexobject['fileid'] = substr($SimpleIndexObjectData, $offset, 16); - $offset += 16; - $thisfile_asf_simpleindexobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_simpleindexobject['fileid']); - $thisfile_asf_simpleindexobject['index_entry_time_interval'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 8)); - $offset += 8; - $thisfile_asf_simpleindexobject['maximum_packet_count'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4)); - $offset += 4; - $thisfile_asf_simpleindexobject['index_entries_count'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4)); - $offset += 4; - - $IndexEntriesData = $SimpleIndexObjectData.$this->fread(6 * $thisfile_asf_simpleindexobject['index_entries_count']); - for ($IndexEntriesCounter = 0; $IndexEntriesCounter < $thisfile_asf_simpleindexobject['index_entries_count']; $IndexEntriesCounter++) { - $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_number'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4)); - $offset += 4; - $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_count'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4)); - $offset += 2; - } - - break; - - case GETID3_ASF_Index_Object: - // 6.2 ASF top-level Index Object (optional but recommended when appropriate, 0 or 1) - // Field Name Field Type Size (bits) - // Object ID GUID 128 // GUID for the Index Object - GETID3_ASF_Index_Object - // Object Size QWORD 64 // Specifies the size, in bytes, of the Index Object, including at least 34 bytes of Index Object header - // Index Entry Time Interval DWORD 32 // Specifies the time interval between each index entry in ms. - // Index Specifiers Count WORD 16 // Specifies the number of Index Specifiers structures in this Index Object. - // Index Blocks Count DWORD 32 // Specifies the number of Index Blocks structures in this Index Object. - - // Index Entry Time Interval DWORD 32 // Specifies the time interval between index entries in milliseconds. This value cannot be 0. - // Index Specifiers Count WORD 16 // Specifies the number of entries in the Index Specifiers list. Valid values are 1 and greater. - // Index Specifiers array of: varies // - // * Stream Number WORD 16 // Specifies the stream number that the Index Specifiers refer to. Valid values are between 1 and 127. - // * Index Type WORD 16 // Specifies Index Type values as follows: - // 1 = Nearest Past Data Packet - indexes point to the data packet whose presentation time is closest to the index entry time. - // 2 = Nearest Past Media Object - indexes point to the closest data packet containing an entire object or first fragment of an object. - // 3 = Nearest Past Cleanpoint. - indexes point to the closest data packet containing an entire object (or first fragment of an object) that has the Cleanpoint Flag set. - // Nearest Past Cleanpoint is the most common type of index. - // Index Entry Count DWORD 32 // Specifies the number of Index Entries in the block. - // * Block Positions QWORD varies // Specifies a list of byte offsets of the beginnings of the blocks relative to the beginning of the first Data Packet (i.e., the beginning of the Data Object + 50 bytes). The number of entries in this list is specified by the value of the Index Specifiers Count field. The order of those byte offsets is tied to the order in which Index Specifiers are listed. - // * Index Entries array of: varies // - // * * Offsets DWORD varies // An offset value of 0xffffffff indicates an invalid offset value - - // shortcut - $thisfile_asf['asf_index_object'] = array(); - $thisfile_asf_asfindexobject = &$thisfile_asf['asf_index_object']; - - $ASFIndexObjectData = $NextObjectDataHeader.$this->fread(34 - 24); - $offset = 24; - - $thisfile_asf_asfindexobject['objectid'] = $NextObjectGUID; - $thisfile_asf_asfindexobject['objectid_guid'] = $NextObjectGUIDtext; - $thisfile_asf_asfindexobject['objectsize'] = $NextObjectSize; - - $thisfile_asf_asfindexobject['entry_time_interval'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4)); - $offset += 4; - $thisfile_asf_asfindexobject['index_specifiers_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2)); - $offset += 2; - $thisfile_asf_asfindexobject['index_blocks_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4)); - $offset += 4; - - $ASFIndexObjectData .= $this->fread(4 * $thisfile_asf_asfindexobject['index_specifiers_count']); - for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) { - $IndexSpecifierStreamNumber = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2)); - $offset += 2; - $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['stream_number'] = $IndexSpecifierStreamNumber; - $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2)); - $offset += 2; - $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type_text'] = $this->ASFIndexObjectIndexTypeLookup($thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type']); - } - - $ASFIndexObjectData .= $this->fread(4); - $thisfile_asf_asfindexobject['index_entry_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4)); - $offset += 4; - - $ASFIndexObjectData .= $this->fread(8 * $thisfile_asf_asfindexobject['index_specifiers_count']); - for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) { - $thisfile_asf_asfindexobject['block_positions'][$IndexSpecifiersCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 8)); - $offset += 8; - } - - $ASFIndexObjectData .= $this->fread(4 * $thisfile_asf_asfindexobject['index_specifiers_count'] * $thisfile_asf_asfindexobject['index_entry_count']); - for ($IndexEntryCounter = 0; $IndexEntryCounter < $thisfile_asf_asfindexobject['index_entry_count']; $IndexEntryCounter++) { - for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) { - $thisfile_asf_asfindexobject['offsets'][$IndexSpecifiersCounter][$IndexEntryCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4)); - $offset += 4; - } - } - break; - - - default: - // Implementations shall ignore any standard or non-standard object that they do not know how to handle. - if ($this->GUIDname($NextObjectGUIDtext)) { - $this->warning('unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF body at offset '.($offset - 16 - 8)); - } else { - $this->warning('unknown GUID {'.$NextObjectGUIDtext.'} in ASF body at offset '.($this->ftell() - 16 - 8)); - } - $this->fseek(($NextObjectSize - 16 - 8), SEEK_CUR); - break; - } - } - - if (isset($thisfile_asf_codeclistobject['codec_entries']) && is_array($thisfile_asf_codeclistobject['codec_entries'])) { - foreach ($thisfile_asf_codeclistobject['codec_entries'] as $streamnumber => $streamdata) { - switch ($streamdata['information']) { - case 'WMV1': - case 'WMV2': - case 'WMV3': - case 'MSS1': - case 'MSS2': - case 'WMVA': - case 'WVC1': - case 'WMVP': - case 'WVP2': - $thisfile_video['dataformat'] = 'wmv'; - $info['mime_type'] = 'video/x-ms-wmv'; - break; - - case 'MP42': - case 'MP43': - case 'MP4S': - case 'mp4s': - $thisfile_video['dataformat'] = 'asf'; - $info['mime_type'] = 'video/x-ms-asf'; - break; - - default: - switch ($streamdata['type_raw']) { - case 1: - if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) { - $thisfile_video['dataformat'] = 'wmv'; - if ($info['mime_type'] == 'video/x-ms-asf') { - $info['mime_type'] = 'video/x-ms-wmv'; - } - } - break; - - case 2: - if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) { - $thisfile_audio['dataformat'] = 'wma'; - if ($info['mime_type'] == 'video/x-ms-asf') { - $info['mime_type'] = 'audio/x-ms-wma'; - } - } - break; - - } - break; - } - } - } - - switch (isset($thisfile_audio['codec']) ? $thisfile_audio['codec'] : '') { - case 'MPEG Layer-3': - $thisfile_audio['dataformat'] = 'mp3'; - break; - - default: - break; - } - - if (isset($thisfile_asf_codeclistobject['codec_entries'])) { - foreach ($thisfile_asf_codeclistobject['codec_entries'] as $streamnumber => $streamdata) { - switch ($streamdata['type_raw']) { - - case 1: // video - $thisfile_video['encoder'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][$streamnumber]['name']); - break; - - case 2: // audio - $thisfile_audio['encoder'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][$streamnumber]['name']); - - // AH 2003-10-01 - $thisfile_audio['encoder_options'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][0]['description']); - - $thisfile_audio['codec'] = $thisfile_audio['encoder']; - break; - - default: - $this->warning('Unknown streamtype: [codec_list_object][codec_entries]['.$streamnumber.'][type_raw] == '.$streamdata['type_raw']); - break; - - } - } - } - - if (isset($info['audio'])) { - $thisfile_audio['lossless'] = (isset($thisfile_audio['lossless']) ? $thisfile_audio['lossless'] : false); - $thisfile_audio['dataformat'] = (!empty($thisfile_audio['dataformat']) ? $thisfile_audio['dataformat'] : 'asf'); - } - if (!empty($thisfile_video['dataformat'])) { - $thisfile_video['lossless'] = (isset($thisfile_audio['lossless']) ? $thisfile_audio['lossless'] : false); - $thisfile_video['pixel_aspect_ratio'] = (isset($thisfile_audio['pixel_aspect_ratio']) ? $thisfile_audio['pixel_aspect_ratio'] : (float) 1); - $thisfile_video['dataformat'] = (!empty($thisfile_video['dataformat']) ? $thisfile_video['dataformat'] : 'asf'); - } - if (!empty($thisfile_video['streams'])) { - $thisfile_video['resolution_x'] = 0; - $thisfile_video['resolution_y'] = 0; - foreach ($thisfile_video['streams'] as $key => $valuearray) { - if (($valuearray['resolution_x'] > $thisfile_video['resolution_x']) || ($valuearray['resolution_y'] > $thisfile_video['resolution_y'])) { - $thisfile_video['resolution_x'] = $valuearray['resolution_x']; - $thisfile_video['resolution_y'] = $valuearray['resolution_y']; - } - } - } - $info['bitrate'] = (isset($thisfile_audio['bitrate']) ? $thisfile_audio['bitrate'] : 0) + (isset($thisfile_video['bitrate']) ? $thisfile_video['bitrate'] : 0); - - if ((!isset($info['playtime_seconds']) || ($info['playtime_seconds'] <= 0)) && ($info['bitrate'] > 0)) { - $info['playtime_seconds'] = ($info['filesize'] - $info['avdataoffset']) / ($info['bitrate'] / 8); - } - - return true; - } - - public static function codecListObjectTypeLookup($CodecListType) { - static $lookup = array( - 0x0001 => 'Video Codec', - 0x0002 => 'Audio Codec', - 0xFFFF => 'Unknown Codec' - ); - - return (isset($lookup[$CodecListType]) ? $lookup[$CodecListType] : 'Invalid Codec Type'); - } - - public static function KnownGUIDs() { - static $GUIDarray = array( - 'GETID3_ASF_Extended_Stream_Properties_Object' => '14E6A5CB-C672-4332-8399-A96952065B5A', - 'GETID3_ASF_Padding_Object' => '1806D474-CADF-4509-A4BA-9AABCB96AAE8', - 'GETID3_ASF_Payload_Ext_Syst_Pixel_Aspect_Ratio' => '1B1EE554-F9EA-4BC8-821A-376B74E4C4B8', - 'GETID3_ASF_Script_Command_Object' => '1EFB1A30-0B62-11D0-A39B-00A0C90348F6', - 'GETID3_ASF_No_Error_Correction' => '20FB5700-5B55-11CF-A8FD-00805F5C442B', - 'GETID3_ASF_Content_Branding_Object' => '2211B3FA-BD23-11D2-B4B7-00A0C955FC6E', - 'GETID3_ASF_Content_Encryption_Object' => '2211B3FB-BD23-11D2-B4B7-00A0C955FC6E', - 'GETID3_ASF_Digital_Signature_Object' => '2211B3FC-BD23-11D2-B4B7-00A0C955FC6E', - 'GETID3_ASF_Extended_Content_Encryption_Object' => '298AE614-2622-4C17-B935-DAE07EE9289C', - 'GETID3_ASF_Simple_Index_Object' => '33000890-E5B1-11CF-89F4-00A0C90349CB', - 'GETID3_ASF_Degradable_JPEG_Media' => '35907DE0-E415-11CF-A917-00805F5C442B', - 'GETID3_ASF_Payload_Extension_System_Timecode' => '399595EC-8667-4E2D-8FDB-98814CE76C1E', - 'GETID3_ASF_Binary_Media' => '3AFB65E2-47EF-40F2-AC2C-70A90D71D343', - 'GETID3_ASF_Timecode_Index_Object' => '3CB73FD0-0C4A-4803-953D-EDF7B6228F0C', - 'GETID3_ASF_Metadata_Library_Object' => '44231C94-9498-49D1-A141-1D134E457054', - 'GETID3_ASF_Reserved_3' => '4B1ACBE3-100B-11D0-A39B-00A0C90348F6', - 'GETID3_ASF_Reserved_4' => '4CFEDB20-75F6-11CF-9C0F-00A0C90349CB', - 'GETID3_ASF_Command_Media' => '59DACFC0-59E6-11D0-A3AC-00A0C90348F6', - 'GETID3_ASF_Header_Extension_Object' => '5FBF03B5-A92E-11CF-8EE3-00C00C205365', - 'GETID3_ASF_Media_Object_Index_Parameters_Obj' => '6B203BAD-3F11-4E84-ACA8-D7613DE2CFA7', - 'GETID3_ASF_Header_Object' => '75B22630-668E-11CF-A6D9-00AA0062CE6C', - 'GETID3_ASF_Content_Description_Object' => '75B22633-668E-11CF-A6D9-00AA0062CE6C', - 'GETID3_ASF_Error_Correction_Object' => '75B22635-668E-11CF-A6D9-00AA0062CE6C', - 'GETID3_ASF_Data_Object' => '75B22636-668E-11CF-A6D9-00AA0062CE6C', - 'GETID3_ASF_Web_Stream_Media_Subtype' => '776257D4-C627-41CB-8F81-7AC7FF1C40CC', - 'GETID3_ASF_Stream_Bitrate_Properties_Object' => '7BF875CE-468D-11D1-8D82-006097C9A2B2', - 'GETID3_ASF_Language_List_Object' => '7C4346A9-EFE0-4BFC-B229-393EDE415C85', - 'GETID3_ASF_Codec_List_Object' => '86D15240-311D-11D0-A3A4-00A0C90348F6', - 'GETID3_ASF_Reserved_2' => '86D15241-311D-11D0-A3A4-00A0C90348F6', - 'GETID3_ASF_File_Properties_Object' => '8CABDCA1-A947-11CF-8EE4-00C00C205365', - 'GETID3_ASF_File_Transfer_Media' => '91BD222C-F21C-497A-8B6D-5AA86BFC0185', - 'GETID3_ASF_Old_RTP_Extension_Data' => '96800C63-4C94-11D1-837B-0080C7A37F95', - 'GETID3_ASF_Advanced_Mutual_Exclusion_Object' => 'A08649CF-4775-4670-8A16-6E35357566CD', - 'GETID3_ASF_Bandwidth_Sharing_Object' => 'A69609E6-517B-11D2-B6AF-00C04FD908E9', - 'GETID3_ASF_Reserved_1' => 'ABD3D211-A9BA-11cf-8EE6-00C00C205365', - 'GETID3_ASF_Bandwidth_Sharing_Exclusive' => 'AF6060AA-5197-11D2-B6AF-00C04FD908E9', - 'GETID3_ASF_Bandwidth_Sharing_Partial' => 'AF6060AB-5197-11D2-B6AF-00C04FD908E9', - 'GETID3_ASF_JFIF_Media' => 'B61BE100-5B4E-11CF-A8FD-00805F5C442B', - 'GETID3_ASF_Stream_Properties_Object' => 'B7DC0791-A9B7-11CF-8EE6-00C00C205365', - 'GETID3_ASF_Video_Media' => 'BC19EFC0-5B4D-11CF-A8FD-00805F5C442B', - 'GETID3_ASF_Audio_Spread' => 'BFC3CD50-618F-11CF-8BB2-00AA00B4E220', - 'GETID3_ASF_Metadata_Object' => 'C5F8CBEA-5BAF-4877-8467-AA8C44FA4CCA', - 'GETID3_ASF_Payload_Ext_Syst_Sample_Duration' => 'C6BD9450-867F-4907-83A3-C77921B733AD', - 'GETID3_ASF_Group_Mutual_Exclusion_Object' => 'D1465A40-5A79-4338-B71B-E36B8FD6C249', - 'GETID3_ASF_Extended_Content_Description_Object' => 'D2D0A440-E307-11D2-97F0-00A0C95EA850', - 'GETID3_ASF_Stream_Prioritization_Object' => 'D4FED15B-88D3-454F-81F0-ED5C45999E24', - 'GETID3_ASF_Payload_Ext_System_Content_Type' => 'D590DC20-07BC-436C-9CF7-F3BBFBF1A4DC', - 'GETID3_ASF_Old_File_Properties_Object' => 'D6E229D0-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_ASF_Header_Object' => 'D6E229D1-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_ASF_Data_Object' => 'D6E229D2-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Index_Object' => 'D6E229D3-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Stream_Properties_Object' => 'D6E229D4-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Content_Description_Object' => 'D6E229D5-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Script_Command_Object' => 'D6E229D6-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Marker_Object' => 'D6E229D7-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Component_Download_Object' => 'D6E229D8-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Stream_Group_Object' => 'D6E229D9-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Scalable_Object' => 'D6E229DA-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Prioritization_Object' => 'D6E229DB-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Bitrate_Mutual_Exclusion_Object' => 'D6E229DC-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Inter_Media_Dependency_Object' => 'D6E229DD-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Rating_Object' => 'D6E229DE-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Index_Parameters_Object' => 'D6E229DF-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Color_Table_Object' => 'D6E229E0-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Language_List_Object' => 'D6E229E1-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Audio_Media' => 'D6E229E2-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Video_Media' => 'D6E229E3-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Image_Media' => 'D6E229E4-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Timecode_Media' => 'D6E229E5-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Text_Media' => 'D6E229E6-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_MIDI_Media' => 'D6E229E7-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Command_Media' => 'D6E229E8-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_No_Error_Concealment' => 'D6E229EA-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Scrambled_Audio' => 'D6E229EB-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_No_Color_Table' => 'D6E229EC-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_SMPTE_Time' => 'D6E229ED-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_ASCII_Text' => 'D6E229EE-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Unicode_Text' => 'D6E229EF-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_HTML_Text' => 'D6E229F0-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_URL_Command' => 'D6E229F1-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Filename_Command' => 'D6E229F2-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_ACM_Codec' => 'D6E229F3-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_VCM_Codec' => 'D6E229F4-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_QuickTime_Codec' => 'D6E229F5-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_DirectShow_Transform_Filter' => 'D6E229F6-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_DirectShow_Rendering_Filter' => 'D6E229F7-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_No_Enhancement' => 'D6E229F8-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Unknown_Enhancement_Type' => 'D6E229F9-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Temporal_Enhancement' => 'D6E229FA-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Spatial_Enhancement' => 'D6E229FB-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Quality_Enhancement' => 'D6E229FC-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Number_of_Channels_Enhancement' => 'D6E229FD-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Frequency_Response_Enhancement' => 'D6E229FE-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Media_Object' => 'D6E229FF-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Mutex_Language' => 'D6E22A00-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Mutex_Bitrate' => 'D6E22A01-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Mutex_Unknown' => 'D6E22A02-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_ASF_Placeholder_Object' => 'D6E22A0E-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Old_Data_Unit_Extension_Object' => 'D6E22A0F-35DA-11D1-9034-00A0C90349BE', - 'GETID3_ASF_Web_Stream_Format' => 'DA1E6B13-8359-4050-B398-388E965BF00C', - 'GETID3_ASF_Payload_Ext_System_File_Name' => 'E165EC0E-19ED-45D7-B4A7-25CBD1E28E9B', - 'GETID3_ASF_Marker_Object' => 'F487CD01-A951-11CF-8EE6-00C00C205365', - 'GETID3_ASF_Timecode_Index_Parameters_Object' => 'F55E496D-9797-4B5D-8C8B-604DFE9BFB24', - 'GETID3_ASF_Audio_Media' => 'F8699E40-5B4D-11CF-A8FD-00805F5C442B', - 'GETID3_ASF_Media_Object_Index_Object' => 'FEB103F8-12AD-4C64-840F-2A1D2F7AD48C', - 'GETID3_ASF_Alt_Extended_Content_Encryption_Obj' => 'FF889EF1-ADEE-40DA-9E71-98704BB928CE', - 'GETID3_ASF_Index_Placeholder_Object' => 'D9AADE20-7C17-4F9C-BC28-8555DD98E2A2', // http://cpan.uwinnipeg.ca/htdocs/Audio-WMA/Audio/WMA.pm.html - 'GETID3_ASF_Compatibility_Object' => '26F18B5D-4584-47EC-9F5F-0E651F0452C9', // http://cpan.uwinnipeg.ca/htdocs/Audio-WMA/Audio/WMA.pm.html - ); - return $GUIDarray; - } - - public static function GUIDname($GUIDstring) { - static $GUIDarray = array(); - if (empty($GUIDarray)) { - $GUIDarray = self::KnownGUIDs(); - } - return array_search($GUIDstring, $GUIDarray); - } - - public static function ASFIndexObjectIndexTypeLookup($id) { - static $ASFIndexObjectIndexTypeLookup = array(); - if (empty($ASFIndexObjectIndexTypeLookup)) { - $ASFIndexObjectIndexTypeLookup[1] = 'Nearest Past Data Packet'; - $ASFIndexObjectIndexTypeLookup[2] = 'Nearest Past Media Object'; - $ASFIndexObjectIndexTypeLookup[3] = 'Nearest Past Cleanpoint'; - } - return (isset($ASFIndexObjectIndexTypeLookup[$id]) ? $ASFIndexObjectIndexTypeLookup[$id] : 'invalid'); - } - - public static function GUIDtoBytestring($GUIDstring) { - // Microsoft defines these 16-byte (128-bit) GUIDs in the strangest way: - // first 4 bytes are in little-endian order - // next 2 bytes are appended in little-endian order - // next 2 bytes are appended in little-endian order - // next 2 bytes are appended in big-endian order - // next 6 bytes are appended in big-endian order - - // AaBbCcDd-EeFf-GgHh-IiJj-KkLlMmNnOoPp is stored as this 16-byte string: - // $Dd $Cc $Bb $Aa $Ff $Ee $Hh $Gg $Ii $Jj $Kk $Ll $Mm $Nn $Oo $Pp - - $hexbytecharstring = chr(hexdec(substr($GUIDstring, 6, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 4, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 2, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 0, 2))); - - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 11, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 9, 2))); - - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 16, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 14, 2))); - - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 19, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 21, 2))); - - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 24, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 26, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 28, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 30, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 32, 2))); - $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 34, 2))); - - return $hexbytecharstring; - } - - public static function BytestringToGUID($Bytestring) { - $GUIDstring = str_pad(dechex(ord($Bytestring{3})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{2})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{1})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{0})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= '-'; - $GUIDstring .= str_pad(dechex(ord($Bytestring{5})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{4})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= '-'; - $GUIDstring .= str_pad(dechex(ord($Bytestring{7})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{6})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= '-'; - $GUIDstring .= str_pad(dechex(ord($Bytestring{8})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{9})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= '-'; - $GUIDstring .= str_pad(dechex(ord($Bytestring{10})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{11})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{12})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{13})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{14})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{15})), 2, '0', STR_PAD_LEFT); - - return strtoupper($GUIDstring); - } - - public static function FILETIMEtoUNIXtime($FILETIME, $round=true) { - // FILETIME is a 64-bit unsigned integer representing - // the number of 100-nanosecond intervals since January 1, 1601 - // UNIX timestamp is number of seconds since January 1, 1970 - // 116444736000000000 = 10000000 * 60 * 60 * 24 * 365 * 369 + 89 leap days - if ($round) { - return intval(round(($FILETIME - 116444736000000000) / 10000000)); - } - return ($FILETIME - 116444736000000000) / 10000000; - } - - public static function WMpictureTypeLookup($WMpictureType) { - static $lookup = null; - if ($lookup === null) { - $lookup = array( - 0x03 => 'Front Cover', - 0x04 => 'Back Cover', - 0x00 => 'User Defined', - 0x05 => 'Leaflet Page', - 0x06 => 'Media Label', - 0x07 => 'Lead Artist', - 0x08 => 'Artist', - 0x09 => 'Conductor', - 0x0A => 'Band', - 0x0B => 'Composer', - 0x0C => 'Lyricist', - 0x0D => 'Recording Location', - 0x0E => 'During Recording', - 0x0F => 'During Performance', - 0x10 => 'Video Screen Capture', - 0x12 => 'Illustration', - 0x13 => 'Band Logotype', - 0x14 => 'Publisher Logotype' - ); - $lookup = array_map(function($str) { - return getid3_lib::iconv_fallback('UTF-8', 'UTF-16LE', $str); - }, $lookup); - } - - return (isset($lookup[$WMpictureType]) ? $lookup[$WMpictureType] : ''); - } - - public function HeaderExtensionObjectDataParse(&$asf_header_extension_object_data, &$unhandled_sections) { - // http://msdn.microsoft.com/en-us/library/bb643323.aspx - - $offset = 0; - $objectOffset = 0; - $HeaderExtensionObjectParsed = array(); - while ($objectOffset < strlen($asf_header_extension_object_data)) { - $offset = $objectOffset; - $thisObject = array(); - - $thisObject['guid'] = substr($asf_header_extension_object_data, $offset, 16); - $offset += 16; - $thisObject['guid_text'] = $this->BytestringToGUID($thisObject['guid']); - $thisObject['guid_name'] = $this->GUIDname($thisObject['guid_text']); - - $thisObject['size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 8)); - $offset += 8; - if ($thisObject['size'] <= 0) { - break; - } - - switch ($thisObject['guid']) { - case GETID3_ASF_Extended_Stream_Properties_Object: - $thisObject['start_time'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 8)); - $offset += 8; - $thisObject['start_time_unix'] = $this->FILETIMEtoUNIXtime($thisObject['start_time']); - - $thisObject['end_time'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 8)); - $offset += 8; - $thisObject['end_time_unix'] = $this->FILETIMEtoUNIXtime($thisObject['end_time']); - - $thisObject['data_bitrate'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); - $offset += 4; - - $thisObject['buffer_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); - $offset += 4; - - $thisObject['initial_buffer_fullness'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); - $offset += 4; - - $thisObject['alternate_data_bitrate'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); - $offset += 4; - - $thisObject['alternate_buffer_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); - $offset += 4; - - $thisObject['alternate_initial_buffer_fullness'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); - $offset += 4; - - $thisObject['maximum_object_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); - $offset += 4; - - $thisObject['flags_raw'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); - $offset += 4; - $thisObject['flags']['reliable'] = (bool) $thisObject['flags_raw'] & 0x00000001; - $thisObject['flags']['seekable'] = (bool) $thisObject['flags_raw'] & 0x00000002; - $thisObject['flags']['no_cleanpoints'] = (bool) $thisObject['flags_raw'] & 0x00000004; - $thisObject['flags']['resend_live_cleanpoints'] = (bool) $thisObject['flags_raw'] & 0x00000008; - - $thisObject['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; - - $thisObject['stream_language_id_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; - - $thisObject['average_time_per_frame'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); - $offset += 4; - - $thisObject['stream_name_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; - - $thisObject['payload_extension_system_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; - - for ($i = 0; $i < $thisObject['stream_name_count']; $i++) { - $streamName = array(); - - $streamName['language_id_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; + break; + + default: + switch ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type']) { + case 0: // Unicode string + if (substr($this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name']), 0, 3) == 'WM/') { + $thisfile_asf_comments[str_replace('wm/', '', strtolower($this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name'])))] = [$this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])]; + } + break; + + case 1: + break; + } + break; + } + } + break; + + case GETID3_ASF_Stream_Bitrate_Properties_Object: + // Stream Bitrate Properties Object: (optional, one only) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for Stream Bitrate Properties object - GETID3_ASF_Stream_Bitrate_Properties_Object + // Object Size QWORD 64 // size of Extended Content Description object, including 26 bytes of Stream Bitrate Properties Object header + // Bitrate Records Count WORD 16 // number of records in Bitrate Records + // Bitrate Records array of: variable // + // * Flags WORD 16 // + // * * Stream Number bits 7 (0x007F) // number of this stream + // * * Reserved bits 9 (0xFF80) // hardcoded: 0 + // * Average Bitrate DWORD 32 // in bits per second + + // shortcut + $thisfile_asf['stream_bitrate_properties_object'] = []; + $thisfile_asf_streambitratepropertiesobject = &$thisfile_asf['stream_bitrate_properties_object']; + + $thisfile_asf_streambitratepropertiesobject['offset'] = $NextObjectOffset + $offset; + $thisfile_asf_streambitratepropertiesobject['objectid'] = $NextObjectGUID; + $thisfile_asf_streambitratepropertiesobject['objectid_guid'] = $NextObjectGUIDtext; + $thisfile_asf_streambitratepropertiesobject['objectsize'] = $NextObjectSize; + $thisfile_asf_streambitratepropertiesobject['bitrate_records_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitratepropertiesobject['bitrate_records_count']; $BitrateRecordsCounter++) { + $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); + $offset += 2; + $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags']['stream_number'] = $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] & 0x007F; + $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['bitrate'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + $offset += 4; + } + break; + + case GETID3_ASF_Padding_Object: + // Padding Object: (optional) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for Padding object - GETID3_ASF_Padding_Object + // Object Size QWORD 64 // size of Padding object, including 24 bytes of ASF Padding Object header + // Padding Data BYTESTREAM variable // ignore + + // shortcut + $thisfile_asf['padding_object'] = []; + $thisfile_asf_paddingobject = &$thisfile_asf['padding_object']; + + $thisfile_asf_paddingobject['offset'] = $NextObjectOffset + $offset; + $thisfile_asf_paddingobject['objectid'] = $NextObjectGUID; + $thisfile_asf_paddingobject['objectid_guid'] = $NextObjectGUIDtext; + $thisfile_asf_paddingobject['objectsize'] = $NextObjectSize; + $thisfile_asf_paddingobject['padding_length'] = $thisfile_asf_paddingobject['objectsize'] - 16 - 8; + $thisfile_asf_paddingobject['padding'] = substr($ASFHeaderData, $offset, $thisfile_asf_paddingobject['padding_length']); + $offset += ($NextObjectSize - 16 - 8); + break; + + case GETID3_ASF_Extended_Content_Encryption_Object: + case GETID3_ASF_Content_Encryption_Object: + // WMA DRM - just ignore + $offset += ($NextObjectSize - 16 - 8); + break; + + default: + // Implementations shall ignore any standard or non-standard object that they do not know how to handle. + if ($this->GUIDname($NextObjectGUIDtext)) { + $this->warning('unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF header at offset '.($offset - 16 - 8)); + } else { + $this->warning('unknown GUID {'.$NextObjectGUIDtext.'} in ASF header at offset '.($offset - 16 - 8)); + } + $offset += ($NextObjectSize - 16 - 8); + break; + } + } + if (isset($thisfile_asf_streambitrateproperties['bitrate_records_count'])) { + $ASFbitrateAudio = 0; + $ASFbitrateVideo = 0; + for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitrateproperties['bitrate_records_count']; $BitrateRecordsCounter++) { + if (isset($thisfile_asf_codeclistobject['codec_entries'][$BitrateRecordsCounter])) { + switch ($thisfile_asf_codeclistobject['codec_entries'][$BitrateRecordsCounter]['type_raw']) { + case 1: + $ASFbitrateVideo += $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate']; + break; + + case 2: + $ASFbitrateAudio += $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate']; + break; + + default: + // do nothing + break; + } + } + } + if ($ASFbitrateAudio > 0) { + $thisfile_audio['bitrate'] = $ASFbitrateAudio; + } + if ($ASFbitrateVideo > 0) { + $thisfile_video['bitrate'] = $ASFbitrateVideo; + } + } + if (isset($thisfile_asf['stream_properties_object']) && is_array($thisfile_asf['stream_properties_object'])) { + $thisfile_audio['bitrate'] = 0; + $thisfile_video['bitrate'] = 0; + + foreach ($thisfile_asf['stream_properties_object'] as $streamnumber => $streamdata) { + switch ($streamdata['stream_type']) { + case GETID3_ASF_Audio_Media: + // Field Name Field Type Size (bits) + // Codec ID / Format Tag WORD 16 // unique ID of audio codec - defined as wFormatTag field of WAVEFORMATEX structure + // Number of Channels WORD 16 // number of channels of audio - defined as nChannels field of WAVEFORMATEX structure + // Samples Per Second DWORD 32 // in Hertz - defined as nSamplesPerSec field of WAVEFORMATEX structure + // Average number of Bytes/sec DWORD 32 // bytes/sec of audio stream - defined as nAvgBytesPerSec field of WAVEFORMATEX structure + // Block Alignment WORD 16 // block size in bytes of audio codec - defined as nBlockAlign field of WAVEFORMATEX structure + // Bits per sample WORD 16 // bits per sample of mono data. set to zero for variable bitrate codecs. defined as wBitsPerSample field of WAVEFORMATEX structure + // Codec Specific Data Size WORD 16 // size in bytes of Codec Specific Data buffer - defined as cbSize field of WAVEFORMATEX structure + // Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes + + // shortcut + $thisfile_asf['audio_media'][$streamnumber] = []; + $thisfile_asf_audiomedia_currentstream = &$thisfile_asf['audio_media'][$streamnumber]; + + $audiomediaoffset = 0; + + $thisfile_asf_audiomedia_currentstream = getid3_riff::parseWAVEFORMATex(substr($streamdata['type_specific_data'], $audiomediaoffset, 16)); + $audiomediaoffset += 16; + + $thisfile_audio['lossless'] = false; + switch ($thisfile_asf_audiomedia_currentstream['raw']['wFormatTag']) { + case 0x0001: // PCM + case 0x0163: // WMA9 Lossless + $thisfile_audio['lossless'] = true; + break; + } + + if (! empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) { + foreach ($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'] as $dummy => $dataarray) { + if (isset($dataarray['flags']['stream_number']) && ($dataarray['flags']['stream_number'] == $streamnumber)) { + $thisfile_asf_audiomedia_currentstream['bitrate'] = $dataarray['bitrate']; + $thisfile_audio['bitrate'] += $dataarray['bitrate']; + break; + } + } + } else { + if (! empty($thisfile_asf_audiomedia_currentstream['bytes_sec'])) { + $thisfile_audio['bitrate'] += $thisfile_asf_audiomedia_currentstream['bytes_sec'] * 8; + } elseif (! empty($thisfile_asf_audiomedia_currentstream['bitrate'])) { + $thisfile_audio['bitrate'] += $thisfile_asf_audiomedia_currentstream['bitrate']; + } + } + $thisfile_audio['streams'][$streamnumber] = $thisfile_asf_audiomedia_currentstream; + $thisfile_audio['streams'][$streamnumber]['wformattag'] = $thisfile_asf_audiomedia_currentstream['raw']['wFormatTag']; + $thisfile_audio['streams'][$streamnumber]['lossless'] = $thisfile_audio['lossless']; + $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate']; + $thisfile_audio['streams'][$streamnumber]['dataformat'] = 'wma'; + unset($thisfile_audio['streams'][$streamnumber]['raw']); + + $thisfile_asf_audiomedia_currentstream['codec_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $audiomediaoffset, 2)); + $audiomediaoffset += 2; + $thisfile_asf_audiomedia_currentstream['codec_data'] = substr($streamdata['type_specific_data'], $audiomediaoffset, $thisfile_asf_audiomedia_currentstream['codec_data_size']); + $audiomediaoffset += $thisfile_asf_audiomedia_currentstream['codec_data_size']; + + break; + + case GETID3_ASF_Video_Media: + // Field Name Field Type Size (bits) + // Encoded Image Width DWORD 32 // width of image in pixels + // Encoded Image Height DWORD 32 // height of image in pixels + // Reserved Flags BYTE 8 // hardcoded: 0x02 + // Format Data Size WORD 16 // size of Format Data field in bytes + // Format Data array of: variable // + // * Format Data Size DWORD 32 // number of bytes in Format Data field, in bytes - defined as biSize field of BITMAPINFOHEADER structure + // * Image Width LONG 32 // width of encoded image in pixels - defined as biWidth field of BITMAPINFOHEADER structure + // * Image Height LONG 32 // height of encoded image in pixels - defined as biHeight field of BITMAPINFOHEADER structure + // * Reserved WORD 16 // hardcoded: 0x0001 - defined as biPlanes field of BITMAPINFOHEADER structure + // * Bits Per Pixel Count WORD 16 // bits per pixel - defined as biBitCount field of BITMAPINFOHEADER structure + // * Compression ID FOURCC 32 // fourcc of video codec - defined as biCompression field of BITMAPINFOHEADER structure + // * Image Size DWORD 32 // image size in bytes - defined as biSizeImage field of BITMAPINFOHEADER structure + // * Horizontal Pixels / Meter DWORD 32 // horizontal resolution of target device in pixels per meter - defined as biXPelsPerMeter field of BITMAPINFOHEADER structure + // * Vertical Pixels / Meter DWORD 32 // vertical resolution of target device in pixels per meter - defined as biYPelsPerMeter field of BITMAPINFOHEADER structure + // * Colors Used Count DWORD 32 // number of color indexes in the color table that are actually used - defined as biClrUsed field of BITMAPINFOHEADER structure + // * Important Colors Count DWORD 32 // number of color index required for displaying bitmap. if zero, all colors are required. defined as biClrImportant field of BITMAPINFOHEADER structure + // * Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes + + // shortcut + $thisfile_asf['video_media'][$streamnumber] = []; + $thisfile_asf_videomedia_currentstream = &$thisfile_asf['video_media'][$streamnumber]; + + $videomediaoffset = 0; + $thisfile_asf_videomedia_currentstream['image_width'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); + $videomediaoffset += 4; + $thisfile_asf_videomedia_currentstream['image_height'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); + $videomediaoffset += 4; + $thisfile_asf_videomedia_currentstream['flags'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 1)); + $videomediaoffset += 1; + $thisfile_asf_videomedia_currentstream['format_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2)); + $videomediaoffset += 2; + $thisfile_asf_videomedia_currentstream['format_data']['format_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); + $videomediaoffset += 4; + $thisfile_asf_videomedia_currentstream['format_data']['image_width'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); + $videomediaoffset += 4; + $thisfile_asf_videomedia_currentstream['format_data']['image_height'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); + $videomediaoffset += 4; + $thisfile_asf_videomedia_currentstream['format_data']['reserved'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2)); + $videomediaoffset += 2; + $thisfile_asf_videomedia_currentstream['format_data']['bits_per_pixel'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2)); + $videomediaoffset += 2; + $thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc'] = substr($streamdata['type_specific_data'], $videomediaoffset, 4); + $videomediaoffset += 4; + $thisfile_asf_videomedia_currentstream['format_data']['image_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); + $videomediaoffset += 4; + $thisfile_asf_videomedia_currentstream['format_data']['horizontal_pels'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); + $videomediaoffset += 4; + $thisfile_asf_videomedia_currentstream['format_data']['vertical_pels'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); + $videomediaoffset += 4; + $thisfile_asf_videomedia_currentstream['format_data']['colors_used'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); + $videomediaoffset += 4; + $thisfile_asf_videomedia_currentstream['format_data']['colors_important'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4)); + $videomediaoffset += 4; + $thisfile_asf_videomedia_currentstream['format_data']['codec_data'] = substr($streamdata['type_specific_data'], $videomediaoffset); + + if (! empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) { + foreach ($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'] as $dummy => $dataarray) { + if (isset($dataarray['flags']['stream_number']) && ($dataarray['flags']['stream_number'] == $streamnumber)) { + $thisfile_asf_videomedia_currentstream['bitrate'] = $dataarray['bitrate']; + $thisfile_video['streams'][$streamnumber]['bitrate'] = $dataarray['bitrate']; + $thisfile_video['bitrate'] += $dataarray['bitrate']; + break; + } + } + } + + $thisfile_asf_videomedia_currentstream['format_data']['codec'] = getid3_riff::fourccLookup($thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc']); + + $thisfile_video['streams'][$streamnumber]['fourcc'] = $thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc']; + $thisfile_video['streams'][$streamnumber]['codec'] = $thisfile_asf_videomedia_currentstream['format_data']['codec']; + $thisfile_video['streams'][$streamnumber]['resolution_x'] = $thisfile_asf_videomedia_currentstream['image_width']; + $thisfile_video['streams'][$streamnumber]['resolution_y'] = $thisfile_asf_videomedia_currentstream['image_height']; + $thisfile_video['streams'][$streamnumber]['bits_per_sample'] = $thisfile_asf_videomedia_currentstream['format_data']['bits_per_pixel']; + break; + + default: + break; + } + } + } + + while ($this->ftell() < $info['avdataend']) { + $NextObjectDataHeader = $this->fread(24); + $offset = 0; + $NextObjectGUID = substr($NextObjectDataHeader, 0, 16); + $offset += 16; + $NextObjectGUIDtext = $this->BytestringToGUID($NextObjectGUID); + $NextObjectSize = getid3_lib::LittleEndian2Int(substr($NextObjectDataHeader, $offset, 8)); + $offset += 8; + + switch ($NextObjectGUID) { + case GETID3_ASF_Data_Object: + // Data Object: (mandatory, one only) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for Data object - GETID3_ASF_Data_Object + // Object Size QWORD 64 // size of Data object, including 50 bytes of Data Object header. may be 0 if FilePropertiesObject.BroadcastFlag == 1 + // File ID GUID 128 // unique identifier. identical to File ID field in Header Object + // Total Data Packets QWORD 64 // number of Data Packet entries in Data Object. invalid if FilePropertiesObject.BroadcastFlag == 1 + // Reserved WORD 16 // hardcoded: 0x0101 + + // shortcut + $thisfile_asf['data_object'] = []; + $thisfile_asf_dataobject = &$thisfile_asf['data_object']; + + $DataObjectData = $NextObjectDataHeader.$this->fread(50 - 24); + $offset = 24; + + $thisfile_asf_dataobject['objectid'] = $NextObjectGUID; + $thisfile_asf_dataobject['objectid_guid'] = $NextObjectGUIDtext; + $thisfile_asf_dataobject['objectsize'] = $NextObjectSize; + + $thisfile_asf_dataobject['fileid'] = substr($DataObjectData, $offset, 16); + $offset += 16; + $thisfile_asf_dataobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_dataobject['fileid']); + $thisfile_asf_dataobject['total_data_packets'] = getid3_lib::LittleEndian2Int(substr($DataObjectData, $offset, 8)); + $offset += 8; + $thisfile_asf_dataobject['reserved'] = getid3_lib::LittleEndian2Int(substr($DataObjectData, $offset, 2)); + $offset += 2; + if ($thisfile_asf_dataobject['reserved'] != 0x0101) { + $this->warning('data_object.reserved ('.getid3_lib::PrintHexBytes($thisfile_asf_dataobject['reserved']).') does not match expected value of "0x0101"'); + //return false; + break; + } + + // Data Packets array of: variable // + // * Error Correction Flags BYTE 8 // + // * * Error Correction Data Length bits 4 // if Error Correction Length Type == 00, size of Error Correction Data in bytes, else hardcoded: 0000 + // * * Opaque Data Present bits 1 // + // * * Error Correction Length Type bits 2 // number of bits for size of the error correction data. hardcoded: 00 + // * * Error Correction Present bits 1 // If set, use Opaque Data Packet structure, else use Payload structure + // * Error Correction Data + + $info['avdataoffset'] = $this->ftell(); + $this->fseek(($thisfile_asf_dataobject['objectsize'] - 50), SEEK_CUR); // skip actual audio/video data + $info['avdataend'] = $this->ftell(); + break; + + case GETID3_ASF_Simple_Index_Object: + // Simple Index Object: (optional, recommended, one per video stream) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for Simple Index object - GETID3_ASF_Data_Object + // Object Size QWORD 64 // size of Simple Index object, including 56 bytes of Simple Index Object header + // File ID GUID 128 // unique identifier. may be zero or identical to File ID field in Data Object and Header Object + // Index Entry Time Interval QWORD 64 // interval between index entries in 100-nanosecond units + // Maximum Packet Count DWORD 32 // maximum packet count for all index entries + // Index Entries Count DWORD 32 // number of Index Entries structures + // Index Entries array of: variable // + // * Packet Number DWORD 32 // number of the Data Packet associated with this index entry + // * Packet Count WORD 16 // number of Data Packets to sent at this index entry + + // shortcut + $thisfile_asf['simple_index_object'] = []; + $thisfile_asf_simpleindexobject = &$thisfile_asf['simple_index_object']; + + $SimpleIndexObjectData = $NextObjectDataHeader.$this->fread(56 - 24); + $offset = 24; + + $thisfile_asf_simpleindexobject['objectid'] = $NextObjectGUID; + $thisfile_asf_simpleindexobject['objectid_guid'] = $NextObjectGUIDtext; + $thisfile_asf_simpleindexobject['objectsize'] = $NextObjectSize; + + $thisfile_asf_simpleindexobject['fileid'] = substr($SimpleIndexObjectData, $offset, 16); + $offset += 16; + $thisfile_asf_simpleindexobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_simpleindexobject['fileid']); + $thisfile_asf_simpleindexobject['index_entry_time_interval'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 8)); + $offset += 8; + $thisfile_asf_simpleindexobject['maximum_packet_count'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4)); + $offset += 4; + $thisfile_asf_simpleindexobject['index_entries_count'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4)); + $offset += 4; + + $IndexEntriesData = $SimpleIndexObjectData.$this->fread(6 * $thisfile_asf_simpleindexobject['index_entries_count']); + for ($IndexEntriesCounter = 0; $IndexEntriesCounter < $thisfile_asf_simpleindexobject['index_entries_count']; $IndexEntriesCounter++) { + $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_number'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4)); + $offset += 4; + $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_count'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4)); + $offset += 2; + } + + break; + + case GETID3_ASF_Index_Object: + // 6.2 ASF top-level Index Object (optional but recommended when appropriate, 0 or 1) + // Field Name Field Type Size (bits) + // Object ID GUID 128 // GUID for the Index Object - GETID3_ASF_Index_Object + // Object Size QWORD 64 // Specifies the size, in bytes, of the Index Object, including at least 34 bytes of Index Object header + // Index Entry Time Interval DWORD 32 // Specifies the time interval between each index entry in ms. + // Index Specifiers Count WORD 16 // Specifies the number of Index Specifiers structures in this Index Object. + // Index Blocks Count DWORD 32 // Specifies the number of Index Blocks structures in this Index Object. + + // Index Entry Time Interval DWORD 32 // Specifies the time interval between index entries in milliseconds. This value cannot be 0. + // Index Specifiers Count WORD 16 // Specifies the number of entries in the Index Specifiers list. Valid values are 1 and greater. + // Index Specifiers array of: varies // + // * Stream Number WORD 16 // Specifies the stream number that the Index Specifiers refer to. Valid values are between 1 and 127. + // * Index Type WORD 16 // Specifies Index Type values as follows: + // 1 = Nearest Past Data Packet - indexes point to the data packet whose presentation time is closest to the index entry time. + // 2 = Nearest Past Media Object - indexes point to the closest data packet containing an entire object or first fragment of an object. + // 3 = Nearest Past Cleanpoint. - indexes point to the closest data packet containing an entire object (or first fragment of an object) that has the Cleanpoint Flag set. + // Nearest Past Cleanpoint is the most common type of index. + // Index Entry Count DWORD 32 // Specifies the number of Index Entries in the block. + // * Block Positions QWORD varies // Specifies a list of byte offsets of the beginnings of the blocks relative to the beginning of the first Data Packet (i.e., the beginning of the Data Object + 50 bytes). The number of entries in this list is specified by the value of the Index Specifiers Count field. The order of those byte offsets is tied to the order in which Index Specifiers are listed. + // * Index Entries array of: varies // + // * * Offsets DWORD varies // An offset value of 0xffffffff indicates an invalid offset value + + // shortcut + $thisfile_asf['asf_index_object'] = []; + $thisfile_asf_asfindexobject = &$thisfile_asf['asf_index_object']; + + $ASFIndexObjectData = $NextObjectDataHeader.$this->fread(34 - 24); + $offset = 24; + + $thisfile_asf_asfindexobject['objectid'] = $NextObjectGUID; + $thisfile_asf_asfindexobject['objectid_guid'] = $NextObjectGUIDtext; + $thisfile_asf_asfindexobject['objectsize'] = $NextObjectSize; + + $thisfile_asf_asfindexobject['entry_time_interval'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4)); + $offset += 4; + $thisfile_asf_asfindexobject['index_specifiers_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2)); + $offset += 2; + $thisfile_asf_asfindexobject['index_blocks_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4)); + $offset += 4; + + $ASFIndexObjectData .= $this->fread(4 * $thisfile_asf_asfindexobject['index_specifiers_count']); + for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) { + $IndexSpecifierStreamNumber = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2)); + $offset += 2; + $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['stream_number'] = $IndexSpecifierStreamNumber; + $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2)); + $offset += 2; + $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type_text'] = $this->ASFIndexObjectIndexTypeLookup($thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type']); + } + + $ASFIndexObjectData .= $this->fread(4); + $thisfile_asf_asfindexobject['index_entry_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4)); + $offset += 4; + + $ASFIndexObjectData .= $this->fread(8 * $thisfile_asf_asfindexobject['index_specifiers_count']); + for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) { + $thisfile_asf_asfindexobject['block_positions'][$IndexSpecifiersCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 8)); + $offset += 8; + } + + $ASFIndexObjectData .= $this->fread(4 * $thisfile_asf_asfindexobject['index_specifiers_count'] * $thisfile_asf_asfindexobject['index_entry_count']); + for ($IndexEntryCounter = 0; $IndexEntryCounter < $thisfile_asf_asfindexobject['index_entry_count']; $IndexEntryCounter++) { + for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) { + $thisfile_asf_asfindexobject['offsets'][$IndexSpecifiersCounter][$IndexEntryCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4)); + $offset += 4; + } + } + break; + + default: + // Implementations shall ignore any standard or non-standard object that they do not know how to handle. + if ($this->GUIDname($NextObjectGUIDtext)) { + $this->warning('unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF body at offset '.($offset - 16 - 8)); + } else { + $this->warning('unknown GUID {'.$NextObjectGUIDtext.'} in ASF body at offset '.($this->ftell() - 16 - 8)); + } + $this->fseek(($NextObjectSize - 16 - 8), SEEK_CUR); + break; + } + } + + if (isset($thisfile_asf_codeclistobject['codec_entries']) && is_array($thisfile_asf_codeclistobject['codec_entries'])) { + foreach ($thisfile_asf_codeclistobject['codec_entries'] as $streamnumber => $streamdata) { + switch ($streamdata['information']) { + case 'WMV1': + case 'WMV2': + case 'WMV3': + case 'MSS1': + case 'MSS2': + case 'WMVA': + case 'WVC1': + case 'WMVP': + case 'WVP2': + $thisfile_video['dataformat'] = 'wmv'; + $info['mime_type'] = 'video/x-ms-wmv'; + break; + + case 'MP42': + case 'MP43': + case 'MP4S': + case 'mp4s': + $thisfile_video['dataformat'] = 'asf'; + $info['mime_type'] = 'video/x-ms-asf'; + break; + + default: + switch ($streamdata['type_raw']) { + case 1: + if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) { + $thisfile_video['dataformat'] = 'wmv'; + if ($info['mime_type'] == 'video/x-ms-asf') { + $info['mime_type'] = 'video/x-ms-wmv'; + } + } + break; + + case 2: + if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) { + $thisfile_audio['dataformat'] = 'wma'; + if ($info['mime_type'] == 'video/x-ms-asf') { + $info['mime_type'] = 'audio/x-ms-wma'; + } + } + break; + + } + break; + } + } + } + + switch (isset($thisfile_audio['codec']) ? $thisfile_audio['codec'] : '') { + case 'MPEG Layer-3': + $thisfile_audio['dataformat'] = 'mp3'; + break; + + default: + break; + } + + if (isset($thisfile_asf_codeclistobject['codec_entries'])) { + foreach ($thisfile_asf_codeclistobject['codec_entries'] as $streamnumber => $streamdata) { + switch ($streamdata['type_raw']) { + + case 1: // video + $thisfile_video['encoder'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][$streamnumber]['name']); + break; + + case 2: // audio + $thisfile_audio['encoder'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][$streamnumber]['name']); + + // AH 2003-10-01 + $thisfile_audio['encoder_options'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][0]['description']); + + $thisfile_audio['codec'] = $thisfile_audio['encoder']; + break; + + default: + $this->warning('Unknown streamtype: [codec_list_object][codec_entries]['.$streamnumber.'][type_raw] == '.$streamdata['type_raw']); + break; + + } + } + } + + if (isset($info['audio'])) { + $thisfile_audio['lossless'] = (isset($thisfile_audio['lossless']) ? $thisfile_audio['lossless'] : false); + $thisfile_audio['dataformat'] = (! empty($thisfile_audio['dataformat']) ? $thisfile_audio['dataformat'] : 'asf'); + } + if (! empty($thisfile_video['dataformat'])) { + $thisfile_video['lossless'] = (isset($thisfile_audio['lossless']) ? $thisfile_audio['lossless'] : false); + $thisfile_video['pixel_aspect_ratio'] = (isset($thisfile_audio['pixel_aspect_ratio']) ? $thisfile_audio['pixel_aspect_ratio'] : (float) 1); + $thisfile_video['dataformat'] = (! empty($thisfile_video['dataformat']) ? $thisfile_video['dataformat'] : 'asf'); + } + if (! empty($thisfile_video['streams'])) { + $thisfile_video['resolution_x'] = 0; + $thisfile_video['resolution_y'] = 0; + foreach ($thisfile_video['streams'] as $key => $valuearray) { + if (($valuearray['resolution_x'] > $thisfile_video['resolution_x']) || ($valuearray['resolution_y'] > $thisfile_video['resolution_y'])) { + $thisfile_video['resolution_x'] = $valuearray['resolution_x']; + $thisfile_video['resolution_y'] = $valuearray['resolution_y']; + } + } + } + $info['bitrate'] = (isset($thisfile_audio['bitrate']) ? $thisfile_audio['bitrate'] : 0) + (isset($thisfile_video['bitrate']) ? $thisfile_video['bitrate'] : 0); + + if ((! isset($info['playtime_seconds']) || ($info['playtime_seconds'] <= 0)) && ($info['bitrate'] > 0)) { + $info['playtime_seconds'] = ($info['filesize'] - $info['avdataoffset']) / ($info['bitrate'] / 8); + } + + return true; + } + + public static function codecListObjectTypeLookup($CodecListType) + { + static $lookup = [ + 0x0001 => 'Video Codec', + 0x0002 => 'Audio Codec', + 0xFFFF => 'Unknown Codec', + ]; + + return isset($lookup[$CodecListType]) ? $lookup[$CodecListType] : 'Invalid Codec Type'; + } + + public static function KnownGUIDs() + { + static $GUIDarray = [ + 'GETID3_ASF_Extended_Stream_Properties_Object' => '14E6A5CB-C672-4332-8399-A96952065B5A', + 'GETID3_ASF_Padding_Object' => '1806D474-CADF-4509-A4BA-9AABCB96AAE8', + 'GETID3_ASF_Payload_Ext_Syst_Pixel_Aspect_Ratio' => '1B1EE554-F9EA-4BC8-821A-376B74E4C4B8', + 'GETID3_ASF_Script_Command_Object' => '1EFB1A30-0B62-11D0-A39B-00A0C90348F6', + 'GETID3_ASF_No_Error_Correction' => '20FB5700-5B55-11CF-A8FD-00805F5C442B', + 'GETID3_ASF_Content_Branding_Object' => '2211B3FA-BD23-11D2-B4B7-00A0C955FC6E', + 'GETID3_ASF_Content_Encryption_Object' => '2211B3FB-BD23-11D2-B4B7-00A0C955FC6E', + 'GETID3_ASF_Digital_Signature_Object' => '2211B3FC-BD23-11D2-B4B7-00A0C955FC6E', + 'GETID3_ASF_Extended_Content_Encryption_Object' => '298AE614-2622-4C17-B935-DAE07EE9289C', + 'GETID3_ASF_Simple_Index_Object' => '33000890-E5B1-11CF-89F4-00A0C90349CB', + 'GETID3_ASF_Degradable_JPEG_Media' => '35907DE0-E415-11CF-A917-00805F5C442B', + 'GETID3_ASF_Payload_Extension_System_Timecode' => '399595EC-8667-4E2D-8FDB-98814CE76C1E', + 'GETID3_ASF_Binary_Media' => '3AFB65E2-47EF-40F2-AC2C-70A90D71D343', + 'GETID3_ASF_Timecode_Index_Object' => '3CB73FD0-0C4A-4803-953D-EDF7B6228F0C', + 'GETID3_ASF_Metadata_Library_Object' => '44231C94-9498-49D1-A141-1D134E457054', + 'GETID3_ASF_Reserved_3' => '4B1ACBE3-100B-11D0-A39B-00A0C90348F6', + 'GETID3_ASF_Reserved_4' => '4CFEDB20-75F6-11CF-9C0F-00A0C90349CB', + 'GETID3_ASF_Command_Media' => '59DACFC0-59E6-11D0-A3AC-00A0C90348F6', + 'GETID3_ASF_Header_Extension_Object' => '5FBF03B5-A92E-11CF-8EE3-00C00C205365', + 'GETID3_ASF_Media_Object_Index_Parameters_Obj' => '6B203BAD-3F11-4E84-ACA8-D7613DE2CFA7', + 'GETID3_ASF_Header_Object' => '75B22630-668E-11CF-A6D9-00AA0062CE6C', + 'GETID3_ASF_Content_Description_Object' => '75B22633-668E-11CF-A6D9-00AA0062CE6C', + 'GETID3_ASF_Error_Correction_Object' => '75B22635-668E-11CF-A6D9-00AA0062CE6C', + 'GETID3_ASF_Data_Object' => '75B22636-668E-11CF-A6D9-00AA0062CE6C', + 'GETID3_ASF_Web_Stream_Media_Subtype' => '776257D4-C627-41CB-8F81-7AC7FF1C40CC', + 'GETID3_ASF_Stream_Bitrate_Properties_Object' => '7BF875CE-468D-11D1-8D82-006097C9A2B2', + 'GETID3_ASF_Language_List_Object' => '7C4346A9-EFE0-4BFC-B229-393EDE415C85', + 'GETID3_ASF_Codec_List_Object' => '86D15240-311D-11D0-A3A4-00A0C90348F6', + 'GETID3_ASF_Reserved_2' => '86D15241-311D-11D0-A3A4-00A0C90348F6', + 'GETID3_ASF_File_Properties_Object' => '8CABDCA1-A947-11CF-8EE4-00C00C205365', + 'GETID3_ASF_File_Transfer_Media' => '91BD222C-F21C-497A-8B6D-5AA86BFC0185', + 'GETID3_ASF_Old_RTP_Extension_Data' => '96800C63-4C94-11D1-837B-0080C7A37F95', + 'GETID3_ASF_Advanced_Mutual_Exclusion_Object' => 'A08649CF-4775-4670-8A16-6E35357566CD', + 'GETID3_ASF_Bandwidth_Sharing_Object' => 'A69609E6-517B-11D2-B6AF-00C04FD908E9', + 'GETID3_ASF_Reserved_1' => 'ABD3D211-A9BA-11cf-8EE6-00C00C205365', + 'GETID3_ASF_Bandwidth_Sharing_Exclusive' => 'AF6060AA-5197-11D2-B6AF-00C04FD908E9', + 'GETID3_ASF_Bandwidth_Sharing_Partial' => 'AF6060AB-5197-11D2-B6AF-00C04FD908E9', + 'GETID3_ASF_JFIF_Media' => 'B61BE100-5B4E-11CF-A8FD-00805F5C442B', + 'GETID3_ASF_Stream_Properties_Object' => 'B7DC0791-A9B7-11CF-8EE6-00C00C205365', + 'GETID3_ASF_Video_Media' => 'BC19EFC0-5B4D-11CF-A8FD-00805F5C442B', + 'GETID3_ASF_Audio_Spread' => 'BFC3CD50-618F-11CF-8BB2-00AA00B4E220', + 'GETID3_ASF_Metadata_Object' => 'C5F8CBEA-5BAF-4877-8467-AA8C44FA4CCA', + 'GETID3_ASF_Payload_Ext_Syst_Sample_Duration' => 'C6BD9450-867F-4907-83A3-C77921B733AD', + 'GETID3_ASF_Group_Mutual_Exclusion_Object' => 'D1465A40-5A79-4338-B71B-E36B8FD6C249', + 'GETID3_ASF_Extended_Content_Description_Object' => 'D2D0A440-E307-11D2-97F0-00A0C95EA850', + 'GETID3_ASF_Stream_Prioritization_Object' => 'D4FED15B-88D3-454F-81F0-ED5C45999E24', + 'GETID3_ASF_Payload_Ext_System_Content_Type' => 'D590DC20-07BC-436C-9CF7-F3BBFBF1A4DC', + 'GETID3_ASF_Old_File_Properties_Object' => 'D6E229D0-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_ASF_Header_Object' => 'D6E229D1-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_ASF_Data_Object' => 'D6E229D2-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Index_Object' => 'D6E229D3-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Stream_Properties_Object' => 'D6E229D4-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Content_Description_Object' => 'D6E229D5-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Script_Command_Object' => 'D6E229D6-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Marker_Object' => 'D6E229D7-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Component_Download_Object' => 'D6E229D8-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Stream_Group_Object' => 'D6E229D9-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Scalable_Object' => 'D6E229DA-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Prioritization_Object' => 'D6E229DB-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Bitrate_Mutual_Exclusion_Object' => 'D6E229DC-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Inter_Media_Dependency_Object' => 'D6E229DD-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Rating_Object' => 'D6E229DE-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Index_Parameters_Object' => 'D6E229DF-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Color_Table_Object' => 'D6E229E0-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Language_List_Object' => 'D6E229E1-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Audio_Media' => 'D6E229E2-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Video_Media' => 'D6E229E3-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Image_Media' => 'D6E229E4-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Timecode_Media' => 'D6E229E5-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Text_Media' => 'D6E229E6-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_MIDI_Media' => 'D6E229E7-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Command_Media' => 'D6E229E8-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_No_Error_Concealment' => 'D6E229EA-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Scrambled_Audio' => 'D6E229EB-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_No_Color_Table' => 'D6E229EC-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_SMPTE_Time' => 'D6E229ED-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_ASCII_Text' => 'D6E229EE-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Unicode_Text' => 'D6E229EF-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_HTML_Text' => 'D6E229F0-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_URL_Command' => 'D6E229F1-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Filename_Command' => 'D6E229F2-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_ACM_Codec' => 'D6E229F3-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_VCM_Codec' => 'D6E229F4-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_QuickTime_Codec' => 'D6E229F5-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_DirectShow_Transform_Filter' => 'D6E229F6-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_DirectShow_Rendering_Filter' => 'D6E229F7-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_No_Enhancement' => 'D6E229F8-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Unknown_Enhancement_Type' => 'D6E229F9-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Temporal_Enhancement' => 'D6E229FA-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Spatial_Enhancement' => 'D6E229FB-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Quality_Enhancement' => 'D6E229FC-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Number_of_Channels_Enhancement' => 'D6E229FD-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Frequency_Response_Enhancement' => 'D6E229FE-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Media_Object' => 'D6E229FF-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Mutex_Language' => 'D6E22A00-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Mutex_Bitrate' => 'D6E22A01-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Mutex_Unknown' => 'D6E22A02-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_ASF_Placeholder_Object' => 'D6E22A0E-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Data_Unit_Extension_Object' => 'D6E22A0F-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Web_Stream_Format' => 'DA1E6B13-8359-4050-B398-388E965BF00C', + 'GETID3_ASF_Payload_Ext_System_File_Name' => 'E165EC0E-19ED-45D7-B4A7-25CBD1E28E9B', + 'GETID3_ASF_Marker_Object' => 'F487CD01-A951-11CF-8EE6-00C00C205365', + 'GETID3_ASF_Timecode_Index_Parameters_Object' => 'F55E496D-9797-4B5D-8C8B-604DFE9BFB24', + 'GETID3_ASF_Audio_Media' => 'F8699E40-5B4D-11CF-A8FD-00805F5C442B', + 'GETID3_ASF_Media_Object_Index_Object' => 'FEB103F8-12AD-4C64-840F-2A1D2F7AD48C', + 'GETID3_ASF_Alt_Extended_Content_Encryption_Obj' => 'FF889EF1-ADEE-40DA-9E71-98704BB928CE', + 'GETID3_ASF_Index_Placeholder_Object' => 'D9AADE20-7C17-4F9C-BC28-8555DD98E2A2', // http://cpan.uwinnipeg.ca/htdocs/Audio-WMA/Audio/WMA.pm.html + 'GETID3_ASF_Compatibility_Object' => '26F18B5D-4584-47EC-9F5F-0E651F0452C9', // http://cpan.uwinnipeg.ca/htdocs/Audio-WMA/Audio/WMA.pm.html + ]; + + return $GUIDarray; + } + + public static function GUIDname($GUIDstring) + { + static $GUIDarray = []; + if (empty($GUIDarray)) { + $GUIDarray = self::KnownGUIDs(); + } + + return array_search($GUIDstring, $GUIDarray); + } + + public static function ASFIndexObjectIndexTypeLookup($id) + { + static $ASFIndexObjectIndexTypeLookup = []; + if (empty($ASFIndexObjectIndexTypeLookup)) { + $ASFIndexObjectIndexTypeLookup[1] = 'Nearest Past Data Packet'; + $ASFIndexObjectIndexTypeLookup[2] = 'Nearest Past Media Object'; + $ASFIndexObjectIndexTypeLookup[3] = 'Nearest Past Cleanpoint'; + } + + return isset($ASFIndexObjectIndexTypeLookup[$id]) ? $ASFIndexObjectIndexTypeLookup[$id] : 'invalid'; + } + + public static function GUIDtoBytestring($GUIDstring) + { + // Microsoft defines these 16-byte (128-bit) GUIDs in the strangest way: + // first 4 bytes are in little-endian order + // next 2 bytes are appended in little-endian order + // next 2 bytes are appended in little-endian order + // next 2 bytes are appended in big-endian order + // next 6 bytes are appended in big-endian order + + // AaBbCcDd-EeFf-GgHh-IiJj-KkLlMmNnOoPp is stored as this 16-byte string: + // $Dd $Cc $Bb $Aa $Ff $Ee $Hh $Gg $Ii $Jj $Kk $Ll $Mm $Nn $Oo $Pp + + $hexbytecharstring = chr(hexdec(substr($GUIDstring, 6, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 4, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 2, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 0, 2))); + + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 11, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 9, 2))); + + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 16, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 14, 2))); + + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 19, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 21, 2))); + + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 24, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 26, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 28, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 30, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 32, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 34, 2))); + + return $hexbytecharstring; + } + + public static function BytestringToGUID($Bytestring) + { + $GUIDstring = str_pad(dechex(ord($Bytestring[3])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[2])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[1])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[0])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= '-'; + $GUIDstring .= str_pad(dechex(ord($Bytestring[5])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[4])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= '-'; + $GUIDstring .= str_pad(dechex(ord($Bytestring[7])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[6])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= '-'; + $GUIDstring .= str_pad(dechex(ord($Bytestring[8])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[9])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= '-'; + $GUIDstring .= str_pad(dechex(ord($Bytestring[10])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[11])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[12])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[13])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[14])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[15])), 2, '0', STR_PAD_LEFT); + + return strtoupper($GUIDstring); + } + + public static function FILETIMEtoUNIXtime($FILETIME, $round = true) + { + // FILETIME is a 64-bit unsigned integer representing + // the number of 100-nanosecond intervals since January 1, 1601 + // UNIX timestamp is number of seconds since January 1, 1970 + // 116444736000000000 = 10000000 * 60 * 60 * 24 * 365 * 369 + 89 leap days + if ($round) { + return intval(round(($FILETIME - 116444736000000000) / 10000000)); + } + + return ($FILETIME - 116444736000000000) / 10000000; + } + + public static function WMpictureTypeLookup($WMpictureType) + { + static $lookup = null; + if ($lookup === null) { + $lookup = [ + 0x03 => 'Front Cover', + 0x04 => 'Back Cover', + 0x00 => 'User Defined', + 0x05 => 'Leaflet Page', + 0x06 => 'Media Label', + 0x07 => 'Lead Artist', + 0x08 => 'Artist', + 0x09 => 'Conductor', + 0x0A => 'Band', + 0x0B => 'Composer', + 0x0C => 'Lyricist', + 0x0D => 'Recording Location', + 0x0E => 'During Recording', + 0x0F => 'During Performance', + 0x10 => 'Video Screen Capture', + 0x12 => 'Illustration', + 0x13 => 'Band Logotype', + 0x14 => 'Publisher Logotype', + ]; + $lookup = array_map(function ($str) { + return getid3_lib::iconv_fallback('UTF-8', 'UTF-16LE', $str); + }, $lookup); + } + + return isset($lookup[$WMpictureType]) ? $lookup[$WMpictureType] : ''; + } + + public function HeaderExtensionObjectDataParse(&$asf_header_extension_object_data, &$unhandled_sections) + { + // http://msdn.microsoft.com/en-us/library/bb643323.aspx + + $offset = 0; + $objectOffset = 0; + $HeaderExtensionObjectParsed = []; + while ($objectOffset < strlen($asf_header_extension_object_data)) { + $offset = $objectOffset; + $thisObject = []; + + $thisObject['guid'] = substr($asf_header_extension_object_data, $offset, 16); + $offset += 16; + $thisObject['guid_text'] = $this->BytestringToGUID($thisObject['guid']); + $thisObject['guid_name'] = $this->GUIDname($thisObject['guid_text']); + + $thisObject['size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 8)); + $offset += 8; + if ($thisObject['size'] <= 0) { + break; + } + + switch ($thisObject['guid']) { + case GETID3_ASF_Extended_Stream_Properties_Object: + $thisObject['start_time'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 8)); + $offset += 8; + $thisObject['start_time_unix'] = $this->FILETIMEtoUNIXtime($thisObject['start_time']); + + $thisObject['end_time'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 8)); + $offset += 8; + $thisObject['end_time_unix'] = $this->FILETIMEtoUNIXtime($thisObject['end_time']); + + $thisObject['data_bitrate'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['buffer_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['initial_buffer_fullness'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['alternate_data_bitrate'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['alternate_buffer_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['alternate_initial_buffer_fullness'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['maximum_object_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['flags_raw'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + $thisObject['flags']['reliable'] = (bool) $thisObject['flags_raw'] & 0x00000001; + $thisObject['flags']['seekable'] = (bool) $thisObject['flags_raw'] & 0x00000002; + $thisObject['flags']['no_cleanpoints'] = (bool) $thisObject['flags_raw'] & 0x00000004; + $thisObject['flags']['resend_live_cleanpoints'] = (bool) $thisObject['flags_raw'] & 0x00000008; + + $thisObject['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $thisObject['stream_language_id_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $thisObject['average_time_per_frame'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['stream_name_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $thisObject['payload_extension_system_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + for ($i = 0; $i < $thisObject['stream_name_count']; $i++) { + $streamName = []; + + $streamName['language_id_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; - $streamName['stream_name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; + $streamName['stream_name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; - $streamName['stream_name'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, $streamName['stream_name_length'])); - $offset += $streamName['stream_name_length']; + $streamName['stream_name'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, $streamName['stream_name_length'])); + $offset += $streamName['stream_name_length']; - $thisObject['stream_names'][$i] = $streamName; - } + $thisObject['stream_names'][$i] = $streamName; + } - for ($i = 0; $i < $thisObject['payload_extension_system_count']; $i++) { - $payloadExtensionSystem = array(); + for ($i = 0; $i < $thisObject['payload_extension_system_count']; $i++) { + $payloadExtensionSystem = []; - $payloadExtensionSystem['extension_system_id'] = substr($asf_header_extension_object_data, $offset, 16); - $offset += 16; - $payloadExtensionSystem['extension_system_id_text'] = $this->BytestringToGUID($payloadExtensionSystem['extension_system_id']); + $payloadExtensionSystem['extension_system_id'] = substr($asf_header_extension_object_data, $offset, 16); + $offset += 16; + $payloadExtensionSystem['extension_system_id_text'] = $this->BytestringToGUID($payloadExtensionSystem['extension_system_id']); - $payloadExtensionSystem['extension_system_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; - if ($payloadExtensionSystem['extension_system_size'] <= 0) { - break 2; - } + $payloadExtensionSystem['extension_system_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + if ($payloadExtensionSystem['extension_system_size'] <= 0) { + break 2; + } - $payloadExtensionSystem['extension_system_info_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); - $offset += 4; + $payloadExtensionSystem['extension_system_info_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; - $payloadExtensionSystem['extension_system_info_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, $payloadExtensionSystem['extension_system_info_length'])); - $offset += $payloadExtensionSystem['extension_system_info_length']; + $payloadExtensionSystem['extension_system_info_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, $payloadExtensionSystem['extension_system_info_length'])); + $offset += $payloadExtensionSystem['extension_system_info_length']; - $thisObject['payload_extension_systems'][$i] = $payloadExtensionSystem; - } + $thisObject['payload_extension_systems'][$i] = $payloadExtensionSystem; + } - break; + break; - case GETID3_ASF_Padding_Object: - // padding, skip it - break; + case GETID3_ASF_Padding_Object: + // padding, skip it + break; - case GETID3_ASF_Metadata_Object: - $thisObject['description_record_counts'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; + case GETID3_ASF_Metadata_Object: + $thisObject['description_record_counts'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; - for ($i = 0; $i < $thisObject['description_record_counts']; $i++) { - $descriptionRecord = array(); + for ($i = 0; $i < $thisObject['description_record_counts']; $i++) { + $descriptionRecord = []; - $descriptionRecord['reserved_1'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); // must be zero - $offset += 2; + $descriptionRecord['reserved_1'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); // must be zero + $offset += 2; - $descriptionRecord['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; + $descriptionRecord['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; - $descriptionRecord['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; + $descriptionRecord['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; - $descriptionRecord['data_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; - $descriptionRecord['data_type_text'] = self::metadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']); + $descriptionRecord['data_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + $descriptionRecord['data_type_text'] = self::metadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']); - $descriptionRecord['data_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); - $offset += 4; + $descriptionRecord['data_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; - $descriptionRecord['name'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['name_length']); - $offset += $descriptionRecord['name_length']; + $descriptionRecord['name'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['name_length']); + $offset += $descriptionRecord['name_length']; - $descriptionRecord['data'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['data_length']); - $offset += $descriptionRecord['data_length']; - switch ($descriptionRecord['data_type']) { - case 0x0000: // Unicode string - break; + $descriptionRecord['data'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['data_length']); + $offset += $descriptionRecord['data_length']; + switch ($descriptionRecord['data_type']) { + case 0x0000: // Unicode string + break; - case 0x0001: // BYTE array - // do nothing - break; + case 0x0001: // BYTE array + // do nothing + break; - case 0x0002: // BOOL - $descriptionRecord['data'] = (bool) getid3_lib::LittleEndian2Int($descriptionRecord['data']); - break; + case 0x0002: // BOOL + $descriptionRecord['data'] = (bool) getid3_lib::LittleEndian2Int($descriptionRecord['data']); + break; - case 0x0003: // DWORD - case 0x0004: // QWORD - case 0x0005: // WORD - $descriptionRecord['data'] = getid3_lib::LittleEndian2Int($descriptionRecord['data']); - break; + case 0x0003: // DWORD + case 0x0004: // QWORD + case 0x0005: // WORD + $descriptionRecord['data'] = getid3_lib::LittleEndian2Int($descriptionRecord['data']); + break; - case 0x0006: // GUID - $descriptionRecord['data_text'] = $this->BytestringToGUID($descriptionRecord['data']); - break; - } + case 0x0006: // GUID + $descriptionRecord['data_text'] = $this->BytestringToGUID($descriptionRecord['data']); + break; + } - $thisObject['description_record'][$i] = $descriptionRecord; - } - break; + $thisObject['description_record'][$i] = $descriptionRecord; + } + break; - case GETID3_ASF_Language_List_Object: - $thisObject['language_id_record_counts'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; - - for ($i = 0; $i < $thisObject['language_id_record_counts']; $i++) { - $languageIDrecord = array(); - - $languageIDrecord['language_id_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 1)); - $offset += 1; - - $languageIDrecord['language_id'] = substr($asf_header_extension_object_data, $offset, $languageIDrecord['language_id_length']); - $offset += $languageIDrecord['language_id_length']; - - $thisObject['language_id_record'][$i] = $languageIDrecord; - } - break; - - case GETID3_ASF_Metadata_Library_Object: - $thisObject['description_records_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; - - for ($i = 0; $i < $thisObject['description_records_count']; $i++) { - $descriptionRecord = array(); - - $descriptionRecord['language_list_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; - - $descriptionRecord['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; - - $descriptionRecord['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; - - $descriptionRecord['data_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); - $offset += 2; - $descriptionRecord['data_type_text'] = self::metadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']); - - $descriptionRecord['data_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); - $offset += 4; - - $descriptionRecord['name'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['name_length']); - $offset += $descriptionRecord['name_length']; - - $descriptionRecord['data'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['data_length']); - $offset += $descriptionRecord['data_length']; - - if (preg_match('#^WM/Picture$#', str_replace("\x00", '', trim($descriptionRecord['name'])))) { - $WMpicture = $this->ASF_WMpicture($descriptionRecord['data']); - foreach ($WMpicture as $key => $value) { - $descriptionRecord['data'] = $WMpicture; - } - unset($WMpicture); - } - - $thisObject['description_record'][$i] = $descriptionRecord; - } - break; - - default: - $unhandled_sections++; - if ($this->GUIDname($thisObject['guid_text'])) { - $this->warning('unhandled Header Extension Object GUID "'.$this->GUIDname($thisObject['guid_text']).'" {'.$thisObject['guid_text'].'} at offset '.($offset - 16 - 8)); - } else { - $this->warning('unknown Header Extension Object GUID {'.$thisObject['guid_text'].'} in at offset '.($offset - 16 - 8)); - } - break; - } - $HeaderExtensionObjectParsed[] = $thisObject; - - $objectOffset += $thisObject['size']; - } - return $HeaderExtensionObjectParsed; - } - - - public static function metadataLibraryObjectDataTypeLookup($id) { - static $lookup = array( - 0x0000 => 'Unicode string', // The data consists of a sequence of Unicode characters - 0x0001 => 'BYTE array', // The type of the data is implementation-specific - 0x0002 => 'BOOL', // The data is 2 bytes long and should be interpreted as a 16-bit unsigned integer. Only 0x0000 or 0x0001 are permitted values - 0x0003 => 'DWORD', // The data is 4 bytes long and should be interpreted as a 32-bit unsigned integer - 0x0004 => 'QWORD', // The data is 8 bytes long and should be interpreted as a 64-bit unsigned integer - 0x0005 => 'WORD', // The data is 2 bytes long and should be interpreted as a 16-bit unsigned integer - 0x0006 => 'GUID', // The data is 16 bytes long and should be interpreted as a 128-bit GUID - ); - return (isset($lookup[$id]) ? $lookup[$id] : 'invalid'); - } - - public function ASF_WMpicture(&$data) { - //typedef struct _WMPicture{ - // LPWSTR pwszMIMEType; - // BYTE bPictureType; - // LPWSTR pwszDescription; - // DWORD dwDataLen; - // BYTE* pbData; - //} WM_PICTURE; - - $WMpicture = array(); - - $offset = 0; - $WMpicture['image_type_id'] = getid3_lib::LittleEndian2Int(substr($data, $offset, 1)); - $offset += 1; - $WMpicture['image_type'] = self::WMpictureTypeLookup($WMpicture['image_type_id']); - $WMpicture['image_size'] = getid3_lib::LittleEndian2Int(substr($data, $offset, 4)); - $offset += 4; - - $WMpicture['image_mime'] = ''; - do { - $next_byte_pair = substr($data, $offset, 2); - $offset += 2; - $WMpicture['image_mime'] .= $next_byte_pair; - } while ($next_byte_pair !== "\x00\x00"); - - $WMpicture['image_description'] = ''; - do { - $next_byte_pair = substr($data, $offset, 2); - $offset += 2; - $WMpicture['image_description'] .= $next_byte_pair; - } while ($next_byte_pair !== "\x00\x00"); - - $WMpicture['dataoffset'] = $offset; - $WMpicture['data'] = substr($data, $offset); - - $imageinfo = array(); - $WMpicture['image_mime'] = ''; - $imagechunkcheck = getid3_lib::GetDataImageSize($WMpicture['data'], $imageinfo); - unset($imageinfo); - if (!empty($imagechunkcheck)) { - $WMpicture['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]); - } - if (!isset($this->getid3->info['asf']['comments']['picture'])) { - $this->getid3->info['asf']['comments']['picture'] = array(); - } - $this->getid3->info['asf']['comments']['picture'][] = array('data'=>$WMpicture['data'], 'image_mime'=>$WMpicture['image_mime']); - - return $WMpicture; - } - - - // Remove terminator 00 00 and convert UTF-16LE to Latin-1 - public static function TrimConvert($string) { - return trim(getid3_lib::iconv_fallback('UTF-16LE', 'ISO-8859-1', self::TrimTerm($string)), ' '); - } - - - // Remove terminator 00 00 - public static function TrimTerm($string) { - // remove terminator, only if present (it should be, but...) - if (substr($string, -2) === "\x00\x00") { - $string = substr($string, 0, -2); - } - return $string; - } + case GETID3_ASF_Language_List_Object: + $thisObject['language_id_record_counts'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + for ($i = 0; $i < $thisObject['language_id_record_counts']; $i++) { + $languageIDrecord = []; + + $languageIDrecord['language_id_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 1)); + $offset += 1; + + $languageIDrecord['language_id'] = substr($asf_header_extension_object_data, $offset, $languageIDrecord['language_id_length']); + $offset += $languageIDrecord['language_id_length']; + + $thisObject['language_id_record'][$i] = $languageIDrecord; + } + break; + + case GETID3_ASF_Metadata_Library_Object: + $thisObject['description_records_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + for ($i = 0; $i < $thisObject['description_records_count']; $i++) { + $descriptionRecord = []; + + $descriptionRecord['language_list_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $descriptionRecord['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $descriptionRecord['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $descriptionRecord['data_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + $descriptionRecord['data_type_text'] = self::metadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']); + + $descriptionRecord['data_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $descriptionRecord['name'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['name_length']); + $offset += $descriptionRecord['name_length']; + + $descriptionRecord['data'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['data_length']); + $offset += $descriptionRecord['data_length']; + + if (preg_match('#^WM/Picture$#', str_replace("\x00", '', trim($descriptionRecord['name'])))) { + $WMpicture = $this->ASF_WMpicture($descriptionRecord['data']); + foreach ($WMpicture as $key => $value) { + $descriptionRecord['data'] = $WMpicture; + } + unset($WMpicture); + } + + $thisObject['description_record'][$i] = $descriptionRecord; + } + break; + + default: + $unhandled_sections++; + if ($this->GUIDname($thisObject['guid_text'])) { + $this->warning('unhandled Header Extension Object GUID "'.$this->GUIDname($thisObject['guid_text']).'" {'.$thisObject['guid_text'].'} at offset '.($offset - 16 - 8)); + } else { + $this->warning('unknown Header Extension Object GUID {'.$thisObject['guid_text'].'} in at offset '.($offset - 16 - 8)); + } + break; + } + $HeaderExtensionObjectParsed[] = $thisObject; + + $objectOffset += $thisObject['size']; + } + + return $HeaderExtensionObjectParsed; + } + + public static function metadataLibraryObjectDataTypeLookup($id) + { + static $lookup = [ + 0x0000 => 'Unicode string', // The data consists of a sequence of Unicode characters + 0x0001 => 'BYTE array', // The type of the data is implementation-specific + 0x0002 => 'BOOL', // The data is 2 bytes long and should be interpreted as a 16-bit unsigned integer. Only 0x0000 or 0x0001 are permitted values + 0x0003 => 'DWORD', // The data is 4 bytes long and should be interpreted as a 32-bit unsigned integer + 0x0004 => 'QWORD', // The data is 8 bytes long and should be interpreted as a 64-bit unsigned integer + 0x0005 => 'WORD', // The data is 2 bytes long and should be interpreted as a 16-bit unsigned integer + 0x0006 => 'GUID', // The data is 16 bytes long and should be interpreted as a 128-bit GUID + ]; + + return isset($lookup[$id]) ? $lookup[$id] : 'invalid'; + } + + public function ASF_WMpicture(&$data) + { + //typedef struct _WMPicture{ + // LPWSTR pwszMIMEType; + // BYTE bPictureType; + // LPWSTR pwszDescription; + // DWORD dwDataLen; + // BYTE* pbData; + //} WM_PICTURE; + + $WMpicture = []; + + $offset = 0; + $WMpicture['image_type_id'] = getid3_lib::LittleEndian2Int(substr($data, $offset, 1)); + $offset += 1; + $WMpicture['image_type'] = self::WMpictureTypeLookup($WMpicture['image_type_id']); + $WMpicture['image_size'] = getid3_lib::LittleEndian2Int(substr($data, $offset, 4)); + $offset += 4; + + $WMpicture['image_mime'] = ''; + do { + $next_byte_pair = substr($data, $offset, 2); + $offset += 2; + $WMpicture['image_mime'] .= $next_byte_pair; + } while ($next_byte_pair !== "\x00\x00"); + + $WMpicture['image_description'] = ''; + do { + $next_byte_pair = substr($data, $offset, 2); + $offset += 2; + $WMpicture['image_description'] .= $next_byte_pair; + } while ($next_byte_pair !== "\x00\x00"); + + $WMpicture['dataoffset'] = $offset; + $WMpicture['data'] = substr($data, $offset); + + $imageinfo = []; + $WMpicture['image_mime'] = ''; + $imagechunkcheck = getid3_lib::GetDataImageSize($WMpicture['data'], $imageinfo); + unset($imageinfo); + if (! empty($imagechunkcheck)) { + $WMpicture['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]); + } + if (! isset($this->getid3->info['asf']['comments']['picture'])) { + $this->getid3->info['asf']['comments']['picture'] = []; + } + $this->getid3->info['asf']['comments']['picture'][] = ['data'=>$WMpicture['data'], 'image_mime'=>$WMpicture['image_mime']]; + + return $WMpicture; + } + + // Remove terminator 00 00 and convert UTF-16LE to Latin-1 + public static function TrimConvert($string) + { + return trim(getid3_lib::iconv_fallback('UTF-16LE', 'ISO-8859-1', self::TrimTerm($string)), ' '); + } + + // Remove terminator 00 00 + public static function TrimTerm($string) + { + // remove terminator, only if present (it should be, but...) + if (substr($string, -2) === "\x00\x00") { + $string = substr($string, 0, -2); + } + + return $string; + } } diff --git a/app/Library/getid3/getid3/module.audio-video.bink.php b/app/Library/getid3/getid3/module.audio-video.bink.php index af4b4f8d..afcef3b5 100644 --- a/app/Library/getid3/getid3/module.audio-video.bink.php +++ b/app/Library/getid3/getid3/module.audio-video.bink.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,59 +15,59 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_bink extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->error('Bink / Smacker files not properly processed by this version of getID3() ['.$this->getid3->version().']'); -$this->error('Bink / Smacker files not properly processed by this version of getID3() ['.$this->getid3->version().']'); + $this->fseek($info['avdataoffset']); + $fileTypeID = $this->fread(3); + switch ($fileTypeID) { + case 'BIK': + return $this->ParseBink(); + break; - $this->fseek($info['avdataoffset']); - $fileTypeID = $this->fread(3); - switch ($fileTypeID) { - case 'BIK': - return $this->ParseBink(); - break; + case 'SMK': + return $this->ParseSmacker(); + break; - case 'SMK': - return $this->ParseSmacker(); - break; + default: + $this->error('Expecting "BIK" or "SMK" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($fileTypeID).'"'); - default: - $this->error('Expecting "BIK" or "SMK" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($fileTypeID).'"'); - return false; - break; - } + return false; + break; + } - return true; + return true; + } - } + public function ParseBink() + { + $info = &$this->getid3->info; + $info['fileformat'] = 'bink'; + $info['video']['dataformat'] = 'bink'; - public function ParseBink() { - $info = &$this->getid3->info; - $info['fileformat'] = 'bink'; - $info['video']['dataformat'] = 'bink'; + $fileData = 'BIK'.$this->fread(13); - $fileData = 'BIK'.$this->fread(13); + $info['bink']['data_size'] = getid3_lib::LittleEndian2Int(substr($fileData, 4, 4)); + $info['bink']['frame_count'] = getid3_lib::LittleEndian2Int(substr($fileData, 8, 2)); - $info['bink']['data_size'] = getid3_lib::LittleEndian2Int(substr($fileData, 4, 4)); - $info['bink']['frame_count'] = getid3_lib::LittleEndian2Int(substr($fileData, 8, 2)); + if (($info['avdataend'] - $info['avdataoffset']) != ($info['bink']['data_size'] + 8)) { + $this->error('Probably truncated file: expecting '.$info['bink']['data_size'].' bytes, found '.($info['avdataend'] - $info['avdataoffset'])); + } - if (($info['avdataend'] - $info['avdataoffset']) != ($info['bink']['data_size'] + 8)) { - $this->error('Probably truncated file: expecting '.$info['bink']['data_size'].' bytes, found '.($info['avdataend'] - $info['avdataoffset'])); - } + return true; + } - return true; - } - - public function ParseSmacker() { - $info = &$this->getid3->info; - $info['fileformat'] = 'smacker'; - $info['video']['dataformat'] = 'smacker'; - - return true; - } + public function ParseSmacker() + { + $info = &$this->getid3->info; + $info['fileformat'] = 'smacker'; + $info['video']['dataformat'] = 'smacker'; + return true; + } } diff --git a/app/Library/getid3/getid3/module.audio-video.flv.php b/app/Library/getid3/getid3/module.audio-video.flv.php index 661c77ca..714f2e7c 100644 --- a/app/Library/getid3/getid3/module.audio-video.flv.php +++ b/app/Library/getid3/getid3/module.audio-video.flv.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -52,694 +53,754 @@ // /// ///////////////////////////////////////////////////////////////// -define('GETID3_FLV_TAG_AUDIO', 8); -define('GETID3_FLV_TAG_VIDEO', 9); -define('GETID3_FLV_TAG_META', 18); +define('GETID3_FLV_TAG_AUDIO', 8); +define('GETID3_FLV_TAG_VIDEO', 9); +define('GETID3_FLV_TAG_META', 18); -define('GETID3_FLV_VIDEO_H263', 2); -define('GETID3_FLV_VIDEO_SCREEN', 3); -define('GETID3_FLV_VIDEO_VP6FLV', 4); +define('GETID3_FLV_VIDEO_H263', 2); +define('GETID3_FLV_VIDEO_SCREEN', 3); +define('GETID3_FLV_VIDEO_VP6FLV', 4); define('GETID3_FLV_VIDEO_VP6FLV_ALPHA', 5); -define('GETID3_FLV_VIDEO_SCREENV2', 6); -define('GETID3_FLV_VIDEO_H264', 7); +define('GETID3_FLV_VIDEO_SCREENV2', 6); +define('GETID3_FLV_VIDEO_H264', 7); -define('H264_AVC_SEQUENCE_HEADER', 0); -define('H264_PROFILE_BASELINE', 66); -define('H264_PROFILE_MAIN', 77); -define('H264_PROFILE_EXTENDED', 88); -define('H264_PROFILE_HIGH', 100); -define('H264_PROFILE_HIGH10', 110); -define('H264_PROFILE_HIGH422', 122); -define('H264_PROFILE_HIGH444', 144); +define('H264_AVC_SEQUENCE_HEADER', 0); +define('H264_PROFILE_BASELINE', 66); +define('H264_PROFILE_MAIN', 77); +define('H264_PROFILE_EXTENDED', 88); +define('H264_PROFILE_HIGH', 100); +define('H264_PROFILE_HIGH10', 110); +define('H264_PROFILE_HIGH422', 122); +define('H264_PROFILE_HIGH444', 144); define('H264_PROFILE_HIGH444_PREDICTIVE', 244); -class getid3_flv extends getid3_handler { +class getid3_flv extends getid3_handler +{ + const magic = 'FLV'; - const magic = 'FLV'; + public $max_frames = 100000; // break out of the loop if too many frames have been scanned; only scan this many if meta frame does not contain useful duration - public $max_frames = 100000; // break out of the loop if too many frames have been scanned; only scan this many if meta frame does not contain useful duration + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); - $this->fseek($info['avdataoffset']); + $FLVdataLength = $info['avdataend'] - $info['avdataoffset']; + $FLVheader = $this->fread(5); - $FLVdataLength = $info['avdataend'] - $info['avdataoffset']; - $FLVheader = $this->fread(5); + $info['fileformat'] = 'flv'; + $info['flv']['header']['signature'] = substr($FLVheader, 0, 3); + $info['flv']['header']['version'] = getid3_lib::BigEndian2Int(substr($FLVheader, 3, 1)); + $TypeFlags = getid3_lib::BigEndian2Int(substr($FLVheader, 4, 1)); - $info['fileformat'] = 'flv'; - $info['flv']['header']['signature'] = substr($FLVheader, 0, 3); - $info['flv']['header']['version'] = getid3_lib::BigEndian2Int(substr($FLVheader, 3, 1)); - $TypeFlags = getid3_lib::BigEndian2Int(substr($FLVheader, 4, 1)); + if ($info['flv']['header']['signature'] != self::magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes(self::magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['flv']['header']['signature']).'"'); + unset($info['flv'], $info['fileformat']); - if ($info['flv']['header']['signature'] != self::magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes(self::magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['flv']['header']['signature']).'"'); - unset($info['flv'], $info['fileformat']); - return false; - } + return false; + } - $info['flv']['header']['hasAudio'] = (bool) ($TypeFlags & 0x04); - $info['flv']['header']['hasVideo'] = (bool) ($TypeFlags & 0x01); + $info['flv']['header']['hasAudio'] = (bool) ($TypeFlags & 0x04); + $info['flv']['header']['hasVideo'] = (bool) ($TypeFlags & 0x01); - $FrameSizeDataLength = getid3_lib::BigEndian2Int($this->fread(4)); - $FLVheaderFrameLength = 9; - if ($FrameSizeDataLength > $FLVheaderFrameLength) { - $this->fseek($FrameSizeDataLength - $FLVheaderFrameLength, SEEK_CUR); - } - $Duration = 0; - $found_video = false; - $found_audio = false; - $found_meta = false; - $found_valid_meta_playtime = false; - $tagParseCount = 0; - $info['flv']['framecount'] = array('total'=>0, 'audio'=>0, 'video'=>0); - $flv_framecount = &$info['flv']['framecount']; - while ((($this->ftell() + 16) < $info['avdataend']) && (($tagParseCount++ <= $this->max_frames) || !$found_valid_meta_playtime)) { - $ThisTagHeader = $this->fread(16); + $FrameSizeDataLength = getid3_lib::BigEndian2Int($this->fread(4)); + $FLVheaderFrameLength = 9; + if ($FrameSizeDataLength > $FLVheaderFrameLength) { + $this->fseek($FrameSizeDataLength - $FLVheaderFrameLength, SEEK_CUR); + } + $Duration = 0; + $found_video = false; + $found_audio = false; + $found_meta = false; + $found_valid_meta_playtime = false; + $tagParseCount = 0; + $info['flv']['framecount'] = ['total'=>0, 'audio'=>0, 'video'=>0]; + $flv_framecount = &$info['flv']['framecount']; + while ((($this->ftell() + 16) < $info['avdataend']) && (($tagParseCount++ <= $this->max_frames) || ! $found_valid_meta_playtime)) { + $ThisTagHeader = $this->fread(16); - $PreviousTagLength = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 0, 4)); - $TagType = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 4, 1)); - $DataLength = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 5, 3)); - $Timestamp = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 8, 3)); - $LastHeaderByte = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 15, 1)); - $NextOffset = $this->ftell() - 1 + $DataLength; - if ($Timestamp > $Duration) { - $Duration = $Timestamp; - } + $PreviousTagLength = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 0, 4)); + $TagType = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 4, 1)); + $DataLength = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 5, 3)); + $Timestamp = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 8, 3)); + $LastHeaderByte = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 15, 1)); + $NextOffset = $this->ftell() - 1 + $DataLength; + if ($Timestamp > $Duration) { + $Duration = $Timestamp; + } - $flv_framecount['total']++; - switch ($TagType) { - case GETID3_FLV_TAG_AUDIO: - $flv_framecount['audio']++; - if (!$found_audio) { - $found_audio = true; - $info['flv']['audio']['audioFormat'] = ($LastHeaderByte >> 4) & 0x0F; - $info['flv']['audio']['audioRate'] = ($LastHeaderByte >> 2) & 0x03; - $info['flv']['audio']['audioSampleSize'] = ($LastHeaderByte >> 1) & 0x01; - $info['flv']['audio']['audioType'] = $LastHeaderByte & 0x01; - } - break; + $flv_framecount['total']++; + switch ($TagType) { + case GETID3_FLV_TAG_AUDIO: + $flv_framecount['audio']++; + if (! $found_audio) { + $found_audio = true; + $info['flv']['audio']['audioFormat'] = ($LastHeaderByte >> 4) & 0x0F; + $info['flv']['audio']['audioRate'] = ($LastHeaderByte >> 2) & 0x03; + $info['flv']['audio']['audioSampleSize'] = ($LastHeaderByte >> 1) & 0x01; + $info['flv']['audio']['audioType'] = $LastHeaderByte & 0x01; + } + break; - case GETID3_FLV_TAG_VIDEO: - $flv_framecount['video']++; - if (!$found_video) { - $found_video = true; - $info['flv']['video']['videoCodec'] = $LastHeaderByte & 0x07; + case GETID3_FLV_TAG_VIDEO: + $flv_framecount['video']++; + if (! $found_video) { + $found_video = true; + $info['flv']['video']['videoCodec'] = $LastHeaderByte & 0x07; - $FLVvideoHeader = $this->fread(11); + $FLVvideoHeader = $this->fread(11); - if ($info['flv']['video']['videoCodec'] == GETID3_FLV_VIDEO_H264) { - // this code block contributed by: moysevichØgmail*com + if ($info['flv']['video']['videoCodec'] == GETID3_FLV_VIDEO_H264) { + // this code block contributed by: moysevichØgmail*com - $AVCPacketType = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 0, 1)); - if ($AVCPacketType == H264_AVC_SEQUENCE_HEADER) { - // read AVCDecoderConfigurationRecord - $configurationVersion = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 1)); - $AVCProfileIndication = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 1)); - $profile_compatibility = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 1)); - $lengthSizeMinusOne = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 7, 1)); - $numOfSequenceParameterSets = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 8, 1)); + $AVCPacketType = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 0, 1)); + if ($AVCPacketType == H264_AVC_SEQUENCE_HEADER) { + // read AVCDecoderConfigurationRecord + $configurationVersion = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 1)); + $AVCProfileIndication = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 1)); + $profile_compatibility = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 1)); + $lengthSizeMinusOne = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 7, 1)); + $numOfSequenceParameterSets = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 8, 1)); - if (($numOfSequenceParameterSets & 0x1F) != 0) { - // there is at least one SequenceParameterSet - // read size of the first SequenceParameterSet - //$spsSize = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 9, 2)); - $spsSize = getid3_lib::LittleEndian2Int(substr($FLVvideoHeader, 9, 2)); - // read the first SequenceParameterSet - $sps = $this->fread($spsSize); - if (strlen($sps) == $spsSize) { // make sure that whole SequenceParameterSet was red - $spsReader = new AVCSequenceParameterSetReader($sps); - $spsReader->readData(); - $info['video']['resolution_x'] = $spsReader->getWidth(); - $info['video']['resolution_y'] = $spsReader->getHeight(); - } - } - } - // end: moysevichØgmail*com + if (($numOfSequenceParameterSets & 0x1F) != 0) { + // there is at least one SequenceParameterSet + // read size of the first SequenceParameterSet + //$spsSize = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 9, 2)); + $spsSize = getid3_lib::LittleEndian2Int(substr($FLVvideoHeader, 9, 2)); + // read the first SequenceParameterSet + $sps = $this->fread($spsSize); + if (strlen($sps) == $spsSize) { // make sure that whole SequenceParameterSet was red + $spsReader = new AVCSequenceParameterSetReader($sps); + $spsReader->readData(); + $info['video']['resolution_x'] = $spsReader->getWidth(); + $info['video']['resolution_y'] = $spsReader->getHeight(); + } + } + } + // end: moysevichØgmail*com + } elseif ($info['flv']['video']['videoCodec'] == GETID3_FLV_VIDEO_H263) { + $PictureSizeType = (getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 3, 2))) >> 7; + $PictureSizeType = $PictureSizeType & 0x0007; + $info['flv']['header']['videoSizeType'] = $PictureSizeType; + switch ($PictureSizeType) { + case 0: + //$PictureSizeEnc = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 2)); + //$PictureSizeEnc <<= 1; + //$info['video']['resolution_x'] = ($PictureSizeEnc & 0xFF00) >> 8; + //$PictureSizeEnc = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 2)); + //$PictureSizeEnc <<= 1; + //$info['video']['resolution_y'] = ($PictureSizeEnc & 0xFF00) >> 8; - } elseif ($info['flv']['video']['videoCodec'] == GETID3_FLV_VIDEO_H263) { + $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 2)) >> 7; + $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 2)) >> 7; + $info['video']['resolution_x'] = $PictureSizeEnc['x'] & 0xFF; + $info['video']['resolution_y'] = $PictureSizeEnc['y'] & 0xFF; + break; - $PictureSizeType = (getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 3, 2))) >> 7; - $PictureSizeType = $PictureSizeType & 0x0007; - $info['flv']['header']['videoSizeType'] = $PictureSizeType; - switch ($PictureSizeType) { - case 0: - //$PictureSizeEnc = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 2)); - //$PictureSizeEnc <<= 1; - //$info['video']['resolution_x'] = ($PictureSizeEnc & 0xFF00) >> 8; - //$PictureSizeEnc = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 2)); - //$PictureSizeEnc <<= 1; - //$info['video']['resolution_y'] = ($PictureSizeEnc & 0xFF00) >> 8; + case 1: + $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 3)) >> 7; + $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 3)) >> 7; + $info['video']['resolution_x'] = $PictureSizeEnc['x'] & 0xFFFF; + $info['video']['resolution_y'] = $PictureSizeEnc['y'] & 0xFFFF; + break; - $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 2)) >> 7; - $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 2)) >> 7; - $info['video']['resolution_x'] = $PictureSizeEnc['x'] & 0xFF; - $info['video']['resolution_y'] = $PictureSizeEnc['y'] & 0xFF; - break; + case 2: + $info['video']['resolution_x'] = 352; + $info['video']['resolution_y'] = 288; + break; - case 1: - $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 3)) >> 7; - $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 3)) >> 7; - $info['video']['resolution_x'] = $PictureSizeEnc['x'] & 0xFFFF; - $info['video']['resolution_y'] = $PictureSizeEnc['y'] & 0xFFFF; - break; + case 3: + $info['video']['resolution_x'] = 176; + $info['video']['resolution_y'] = 144; + break; - case 2: - $info['video']['resolution_x'] = 352; - $info['video']['resolution_y'] = 288; - break; + case 4: + $info['video']['resolution_x'] = 128; + $info['video']['resolution_y'] = 96; + break; - case 3: - $info['video']['resolution_x'] = 176; - $info['video']['resolution_y'] = 144; - break; + case 5: + $info['video']['resolution_x'] = 320; + $info['video']['resolution_y'] = 240; + break; - case 4: - $info['video']['resolution_x'] = 128; - $info['video']['resolution_y'] = 96; - break; + case 6: + $info['video']['resolution_x'] = 160; + $info['video']['resolution_y'] = 120; + break; - case 5: - $info['video']['resolution_x'] = 320; - $info['video']['resolution_y'] = 240; - break; + default: + $info['video']['resolution_x'] = 0; + $info['video']['resolution_y'] = 0; + break; - case 6: - $info['video']['resolution_x'] = 160; - $info['video']['resolution_y'] = 120; - break; + } + } elseif ($info['flv']['video']['videoCodec'] == GETID3_FLV_VIDEO_VP6FLV_ALPHA) { - default: - $info['video']['resolution_x'] = 0; - $info['video']['resolution_y'] = 0; - break; + /* contributed by schouwerwouØgmail*com */ + if (! isset($info['video']['resolution_x'])) { // only when meta data isn't set + $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 2)); + $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 7, 2)); + $info['video']['resolution_x'] = ($PictureSizeEnc['x'] & 0xFF) << 3; + $info['video']['resolution_y'] = ($PictureSizeEnc['y'] & 0xFF) << 3; + } + /* end schouwerwouØgmail*com */ + } + if (! empty($info['video']['resolution_x']) && ! empty($info['video']['resolution_y'])) { + $info['video']['pixel_aspect_ratio'] = $info['video']['resolution_x'] / $info['video']['resolution_y']; + } + } + break; - } + // Meta tag + case GETID3_FLV_TAG_META: + if (! $found_meta) { + $found_meta = true; + $this->fseek(-1, SEEK_CUR); + $datachunk = $this->fread($DataLength); + $AMFstream = new AMFStream($datachunk); + $reader = new AMFReader($AMFstream); + $eventName = $reader->readData(); + $info['flv']['meta'][$eventName] = $reader->readData(); + unset($reader); - } elseif ($info['flv']['video']['videoCodec'] == GETID3_FLV_VIDEO_VP6FLV_ALPHA) { + $copykeys = ['framerate'=>'frame_rate', 'width'=>'resolution_x', 'height'=>'resolution_y', 'audiodatarate'=>'bitrate', 'videodatarate'=>'bitrate']; + foreach ($copykeys as $sourcekey => $destkey) { + if (isset($info['flv']['meta']['onMetaData'][$sourcekey])) { + switch ($sourcekey) { + case 'width': + case 'height': + $info['video'][$destkey] = intval(round($info['flv']['meta']['onMetaData'][$sourcekey])); + break; + case 'audiodatarate': + $info['audio'][$destkey] = getid3_lib::CastAsInt(round($info['flv']['meta']['onMetaData'][$sourcekey] * 1000)); + break; + case 'videodatarate': + case 'frame_rate': + default: + $info['video'][$destkey] = $info['flv']['meta']['onMetaData'][$sourcekey]; + break; + } + } + } + if (! empty($info['flv']['meta']['onMetaData']['duration'])) { + $found_valid_meta_playtime = true; + } + } + break; - /* contributed by schouwerwouØgmail*com */ - if (!isset($info['video']['resolution_x'])) { // only when meta data isn't set - $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 2)); - $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 7, 2)); - $info['video']['resolution_x'] = ($PictureSizeEnc['x'] & 0xFF) << 3; - $info['video']['resolution_y'] = ($PictureSizeEnc['y'] & 0xFF) << 3; - } - /* end schouwerwouØgmail*com */ + default: + // noop + break; + } + $this->fseek($NextOffset); + } - } - if (!empty($info['video']['resolution_x']) && !empty($info['video']['resolution_y'])) { - $info['video']['pixel_aspect_ratio'] = $info['video']['resolution_x'] / $info['video']['resolution_y']; - } - } - break; + $info['playtime_seconds'] = $Duration / 1000; + if ($info['playtime_seconds'] > 0) { + $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + } - // Meta tag - case GETID3_FLV_TAG_META: - if (!$found_meta) { - $found_meta = true; - $this->fseek(-1, SEEK_CUR); - $datachunk = $this->fread($DataLength); - $AMFstream = new AMFStream($datachunk); - $reader = new AMFReader($AMFstream); - $eventName = $reader->readData(); - $info['flv']['meta'][$eventName] = $reader->readData(); - unset($reader); + if ($info['flv']['header']['hasAudio']) { + $info['audio']['codec'] = self::audioFormatLookup($info['flv']['audio']['audioFormat']); + $info['audio']['sample_rate'] = self::audioRateLookup($info['flv']['audio']['audioRate']); + $info['audio']['bits_per_sample'] = self::audioBitDepthLookup($info['flv']['audio']['audioSampleSize']); - $copykeys = array('framerate'=>'frame_rate', 'width'=>'resolution_x', 'height'=>'resolution_y', 'audiodatarate'=>'bitrate', 'videodatarate'=>'bitrate'); - foreach ($copykeys as $sourcekey => $destkey) { - if (isset($info['flv']['meta']['onMetaData'][$sourcekey])) { - switch ($sourcekey) { - case 'width': - case 'height': - $info['video'][$destkey] = intval(round($info['flv']['meta']['onMetaData'][$sourcekey])); - break; - case 'audiodatarate': - $info['audio'][$destkey] = getid3_lib::CastAsInt(round($info['flv']['meta']['onMetaData'][$sourcekey] * 1000)); - break; - case 'videodatarate': - case 'frame_rate': - default: - $info['video'][$destkey] = $info['flv']['meta']['onMetaData'][$sourcekey]; - break; - } - } - } - if (!empty($info['flv']['meta']['onMetaData']['duration'])) { - $found_valid_meta_playtime = true; - } - } - break; + $info['audio']['channels'] = $info['flv']['audio']['audioType'] + 1; // 0=mono,1=stereo + $info['audio']['lossless'] = ($info['flv']['audio']['audioFormat'] ? false : true); // 0=uncompressed + $info['audio']['dataformat'] = 'flv'; + } + if (! empty($info['flv']['header']['hasVideo'])) { + $info['video']['codec'] = self::videoCodecLookup($info['flv']['video']['videoCodec']); + $info['video']['dataformat'] = 'flv'; + $info['video']['lossless'] = false; + } - default: - // noop - break; - } - $this->fseek($NextOffset); - } + // Set information from meta + if (! empty($info['flv']['meta']['onMetaData']['duration'])) { + $info['playtime_seconds'] = $info['flv']['meta']['onMetaData']['duration']; + $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + } + if (isset($info['flv']['meta']['onMetaData']['audiocodecid'])) { + $info['audio']['codec'] = self::audioFormatLookup($info['flv']['meta']['onMetaData']['audiocodecid']); + } + if (isset($info['flv']['meta']['onMetaData']['videocodecid'])) { + $info['video']['codec'] = self::videoCodecLookup($info['flv']['meta']['onMetaData']['videocodecid']); + } - $info['playtime_seconds'] = $Duration / 1000; - if ($info['playtime_seconds'] > 0) { - $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; - } + return true; + } - if ($info['flv']['header']['hasAudio']) { - $info['audio']['codec'] = self::audioFormatLookup($info['flv']['audio']['audioFormat']); - $info['audio']['sample_rate'] = self::audioRateLookup($info['flv']['audio']['audioRate']); - $info['audio']['bits_per_sample'] = self::audioBitDepthLookup($info['flv']['audio']['audioSampleSize']); + public static function audioFormatLookup($id) + { + static $lookup = [ + 0 => 'Linear PCM, platform endian', + 1 => 'ADPCM', + 2 => 'mp3', + 3 => 'Linear PCM, little endian', + 4 => 'Nellymoser 16kHz mono', + 5 => 'Nellymoser 8kHz mono', + 6 => 'Nellymoser', + 7 => 'G.711A-law logarithmic PCM', + 8 => 'G.711 mu-law logarithmic PCM', + 9 => 'reserved', + 10 => 'AAC', + 11 => 'Speex', + 12 => false, // unknown? + 13 => false, // unknown? + 14 => 'mp3 8kHz', + 15 => 'Device-specific sound', + ]; - $info['audio']['channels'] = $info['flv']['audio']['audioType'] + 1; // 0=mono,1=stereo - $info['audio']['lossless'] = ($info['flv']['audio']['audioFormat'] ? false : true); // 0=uncompressed - $info['audio']['dataformat'] = 'flv'; - } - if (!empty($info['flv']['header']['hasVideo'])) { - $info['video']['codec'] = self::videoCodecLookup($info['flv']['video']['videoCodec']); - $info['video']['dataformat'] = 'flv'; - $info['video']['lossless'] = false; - } + return isset($lookup[$id]) ? $lookup[$id] : false; + } - // Set information from meta - if (!empty($info['flv']['meta']['onMetaData']['duration'])) { - $info['playtime_seconds'] = $info['flv']['meta']['onMetaData']['duration']; - $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; - } - if (isset($info['flv']['meta']['onMetaData']['audiocodecid'])) { - $info['audio']['codec'] = self::audioFormatLookup($info['flv']['meta']['onMetaData']['audiocodecid']); - } - if (isset($info['flv']['meta']['onMetaData']['videocodecid'])) { - $info['video']['codec'] = self::videoCodecLookup($info['flv']['meta']['onMetaData']['videocodecid']); - } - return true; - } + public static function audioRateLookup($id) + { + static $lookup = [ + 0 => 5500, + 1 => 11025, + 2 => 22050, + 3 => 44100, + ]; + return isset($lookup[$id]) ? $lookup[$id] : false; + } - public static function audioFormatLookup($id) { - static $lookup = array( - 0 => 'Linear PCM, platform endian', - 1 => 'ADPCM', - 2 => 'mp3', - 3 => 'Linear PCM, little endian', - 4 => 'Nellymoser 16kHz mono', - 5 => 'Nellymoser 8kHz mono', - 6 => 'Nellymoser', - 7 => 'G.711A-law logarithmic PCM', - 8 => 'G.711 mu-law logarithmic PCM', - 9 => 'reserved', - 10 => 'AAC', - 11 => 'Speex', - 12 => false, // unknown? - 13 => false, // unknown? - 14 => 'mp3 8kHz', - 15 => 'Device-specific sound', - ); - return (isset($lookup[$id]) ? $lookup[$id] : false); - } + public static function audioBitDepthLookup($id) + { + static $lookup = [ + 0 => 8, + 1 => 16, + ]; - public static function audioRateLookup($id) { - static $lookup = array( - 0 => 5500, - 1 => 11025, - 2 => 22050, - 3 => 44100, - ); - return (isset($lookup[$id]) ? $lookup[$id] : false); - } + return isset($lookup[$id]) ? $lookup[$id] : false; + } - public static function audioBitDepthLookup($id) { - static $lookup = array( - 0 => 8, - 1 => 16, - ); - return (isset($lookup[$id]) ? $lookup[$id] : false); - } + public static function videoCodecLookup($id) + { + static $lookup = [ + GETID3_FLV_VIDEO_H263 => 'Sorenson H.263', + GETID3_FLV_VIDEO_SCREEN => 'Screen video', + GETID3_FLV_VIDEO_VP6FLV => 'On2 VP6', + GETID3_FLV_VIDEO_VP6FLV_ALPHA => 'On2 VP6 with alpha channel', + GETID3_FLV_VIDEO_SCREENV2 => 'Screen video v2', + GETID3_FLV_VIDEO_H264 => 'Sorenson H.264', + ]; - public static function videoCodecLookup($id) { - static $lookup = array( - GETID3_FLV_VIDEO_H263 => 'Sorenson H.263', - GETID3_FLV_VIDEO_SCREEN => 'Screen video', - GETID3_FLV_VIDEO_VP6FLV => 'On2 VP6', - GETID3_FLV_VIDEO_VP6FLV_ALPHA => 'On2 VP6 with alpha channel', - GETID3_FLV_VIDEO_SCREENV2 => 'Screen video v2', - GETID3_FLV_VIDEO_H264 => 'Sorenson H.264', - ); - return (isset($lookup[$id]) ? $lookup[$id] : false); - } + return isset($lookup[$id]) ? $lookup[$id] : false; + } } -class AMFStream { - public $bytes; - public $pos; +class AMFStream +{ + public $bytes; + public $pos; - public function __construct(&$bytes) { - $this->bytes =& $bytes; - $this->pos = 0; - } + public function __construct(&$bytes) + { + $this->bytes = &$bytes; + $this->pos = 0; + } - public function readByte() { - return getid3_lib::BigEndian2Int(substr($this->bytes, $this->pos++, 1)); - } + public function readByte() + { + return getid3_lib::BigEndian2Int(substr($this->bytes, $this->pos++, 1)); + } - public function readInt() { - return ($this->readByte() << 8) + $this->readByte(); - } + public function readInt() + { + return ($this->readByte() << 8) + $this->readByte(); + } - public function readLong() { - return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte(); - } + public function readLong() + { + return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte(); + } - public function readDouble() { - return getid3_lib::BigEndian2Float($this->read(8)); - } + public function readDouble() + { + return getid3_lib::BigEndian2Float($this->read(8)); + } - public function readUTF() { - $length = $this->readInt(); - return $this->read($length); - } + public function readUTF() + { + $length = $this->readInt(); - public function readLongUTF() { - $length = $this->readLong(); - return $this->read($length); - } + return $this->read($length); + } - public function read($length) { - $val = substr($this->bytes, $this->pos, $length); - $this->pos += $length; - return $val; - } + public function readLongUTF() + { + $length = $this->readLong(); - public function peekByte() { - $pos = $this->pos; - $val = $this->readByte(); - $this->pos = $pos; - return $val; - } + return $this->read($length); + } - public function peekInt() { - $pos = $this->pos; - $val = $this->readInt(); - $this->pos = $pos; - return $val; - } + public function read($length) + { + $val = substr($this->bytes, $this->pos, $length); + $this->pos += $length; - public function peekLong() { - $pos = $this->pos; - $val = $this->readLong(); - $this->pos = $pos; - return $val; - } + return $val; + } - public function peekDouble() { - $pos = $this->pos; - $val = $this->readDouble(); - $this->pos = $pos; - return $val; - } + public function peekByte() + { + $pos = $this->pos; + $val = $this->readByte(); + $this->pos = $pos; - public function peekUTF() { - $pos = $this->pos; - $val = $this->readUTF(); - $this->pos = $pos; - return $val; - } + return $val; + } - public function peekLongUTF() { - $pos = $this->pos; - $val = $this->readLongUTF(); - $this->pos = $pos; - return $val; - } + public function peekInt() + { + $pos = $this->pos; + $val = $this->readInt(); + $this->pos = $pos; + + return $val; + } + + public function peekLong() + { + $pos = $this->pos; + $val = $this->readLong(); + $this->pos = $pos; + + return $val; + } + + public function peekDouble() + { + $pos = $this->pos; + $val = $this->readDouble(); + $this->pos = $pos; + + return $val; + } + + public function peekUTF() + { + $pos = $this->pos; + $val = $this->readUTF(); + $this->pos = $pos; + + return $val; + } + + public function peekLongUTF() + { + $pos = $this->pos; + $val = $this->readLongUTF(); + $this->pos = $pos; + + return $val; + } } -class AMFReader { - public $stream; +class AMFReader +{ + public $stream; - public function __construct(&$stream) { - $this->stream =& $stream; - } + public function __construct(&$stream) + { + $this->stream = &$stream; + } - public function readData() { - $value = null; + public function readData() + { + $value = null; - $type = $this->stream->readByte(); - switch ($type) { + $type = $this->stream->readByte(); + switch ($type) { - // Double - case 0: - $value = $this->readDouble(); - break; + // Double + case 0: + $value = $this->readDouble(); + break; - // Boolean - case 1: - $value = $this->readBoolean(); - break; + // Boolean + case 1: + $value = $this->readBoolean(); + break; - // String - case 2: - $value = $this->readString(); - break; + // String + case 2: + $value = $this->readString(); + break; - // Object - case 3: - $value = $this->readObject(); - break; + // Object + case 3: + $value = $this->readObject(); + break; - // null - case 6: - return null; - break; + // null + case 6: + return null; + break; - // Mixed array - case 8: - $value = $this->readMixedArray(); - break; + // Mixed array + case 8: + $value = $this->readMixedArray(); + break; - // Array - case 10: - $value = $this->readArray(); - break; + // Array + case 10: + $value = $this->readArray(); + break; - // Date - case 11: - $value = $this->readDate(); - break; + // Date + case 11: + $value = $this->readDate(); + break; - // Long string - case 13: - $value = $this->readLongString(); - break; + // Long string + case 13: + $value = $this->readLongString(); + break; - // XML (handled as string) - case 15: - $value = $this->readXML(); - break; + // XML (handled as string) + case 15: + $value = $this->readXML(); + break; - // Typed object (handled as object) - case 16: - $value = $this->readTypedObject(); - break; + // Typed object (handled as object) + case 16: + $value = $this->readTypedObject(); + break; - // Long string - default: - $value = '(unknown or unsupported data type)'; - break; - } + // Long string + default: + $value = '(unknown or unsupported data type)'; + break; + } - return $value; - } + return $value; + } - public function readDouble() { - return $this->stream->readDouble(); - } + public function readDouble() + { + return $this->stream->readDouble(); + } - public function readBoolean() { - return $this->stream->readByte() == 1; - } + public function readBoolean() + { + return $this->stream->readByte() == 1; + } - public function readString() { - return $this->stream->readUTF(); - } + public function readString() + { + return $this->stream->readUTF(); + } - public function readObject() { - // Get highest numerical index - ignored -// $highestIndex = $this->stream->readLong(); + public function readObject() + { + // Get highest numerical index - ignored + // $highestIndex = $this->stream->readLong(); - $data = array(); + $data = []; - while ($key = $this->stream->readUTF()) { - $data[$key] = $this->readData(); - } - // Mixed array record ends with empty string (0x00 0x00) and 0x09 - if (($key == '') && ($this->stream->peekByte() == 0x09)) { - // Consume byte - $this->stream->readByte(); - } - return $data; - } + while ($key = $this->stream->readUTF()) { + $data[$key] = $this->readData(); + } + // Mixed array record ends with empty string (0x00 0x00) and 0x09 + if (($key == '') && ($this->stream->peekByte() == 0x09)) { + // Consume byte + $this->stream->readByte(); + } - public function readMixedArray() { - // Get highest numerical index - ignored - $highestIndex = $this->stream->readLong(); + return $data; + } - $data = array(); + public function readMixedArray() + { + // Get highest numerical index - ignored + $highestIndex = $this->stream->readLong(); - while ($key = $this->stream->readUTF()) { - if (is_numeric($key)) { - $key = (float) $key; - } - $data[$key] = $this->readData(); - } - // Mixed array record ends with empty string (0x00 0x00) and 0x09 - if (($key == '') && ($this->stream->peekByte() == 0x09)) { - // Consume byte - $this->stream->readByte(); - } + $data = []; - return $data; - } + while ($key = $this->stream->readUTF()) { + if (is_numeric($key)) { + $key = (float) $key; + } + $data[$key] = $this->readData(); + } + // Mixed array record ends with empty string (0x00 0x00) and 0x09 + if (($key == '') && ($this->stream->peekByte() == 0x09)) { + // Consume byte + $this->stream->readByte(); + } - public function readArray() { - $length = $this->stream->readLong(); - $data = array(); + return $data; + } - for ($i = 0; $i < $length; $i++) { - $data[] = $this->readData(); - } - return $data; - } + public function readArray() + { + $length = $this->stream->readLong(); + $data = []; - public function readDate() { - $timestamp = $this->stream->readDouble(); - $timezone = $this->stream->readInt(); - return $timestamp; - } + for ($i = 0; $i < $length; $i++) { + $data[] = $this->readData(); + } - public function readLongString() { - return $this->stream->readLongUTF(); - } + return $data; + } - public function readXML() { - return $this->stream->readLongUTF(); - } + public function readDate() + { + $timestamp = $this->stream->readDouble(); + $timezone = $this->stream->readInt(); - public function readTypedObject() { - $className = $this->stream->readUTF(); - return $this->readObject(); - } + return $timestamp; + } + + public function readLongString() + { + return $this->stream->readLongUTF(); + } + + public function readXML() + { + return $this->stream->readLongUTF(); + } + + public function readTypedObject() + { + $className = $this->stream->readUTF(); + + return $this->readObject(); + } } -class AVCSequenceParameterSetReader { - public $sps; - public $start = 0; - public $currentBytes = 0; - public $currentBits = 0; - public $width; - public $height; +class AVCSequenceParameterSetReader +{ + public $sps; + public $start = 0; + public $currentBytes = 0; + public $currentBits = 0; + public $width; + public $height; - public function __construct($sps) { - $this->sps = $sps; - } + public function __construct($sps) + { + $this->sps = $sps; + } - public function readData() { - $this->skipBits(8); - $this->skipBits(8); - $profile = $this->getBits(8); // read profile - if ($profile > 0) { - $this->skipBits(8); - $level_idc = $this->getBits(8); // level_idc - $this->expGolombUe(); // seq_parameter_set_id // sps - $this->expGolombUe(); // log2_max_frame_num_minus4 - $picOrderType = $this->expGolombUe(); // pic_order_cnt_type - if ($picOrderType == 0) { - $this->expGolombUe(); // log2_max_pic_order_cnt_lsb_minus4 - } elseif ($picOrderType == 1) { - $this->skipBits(1); // delta_pic_order_always_zero_flag - $this->expGolombSe(); // offset_for_non_ref_pic - $this->expGolombSe(); // offset_for_top_to_bottom_field - $num_ref_frames_in_pic_order_cnt_cycle = $this->expGolombUe(); // num_ref_frames_in_pic_order_cnt_cycle - for ($i = 0; $i < $num_ref_frames_in_pic_order_cnt_cycle; $i++) { - $this->expGolombSe(); // offset_for_ref_frame[ i ] - } - } - $this->expGolombUe(); // num_ref_frames - $this->skipBits(1); // gaps_in_frame_num_value_allowed_flag - $pic_width_in_mbs_minus1 = $this->expGolombUe(); // pic_width_in_mbs_minus1 - $pic_height_in_map_units_minus1 = $this->expGolombUe(); // pic_height_in_map_units_minus1 + public function readData() + { + $this->skipBits(8); + $this->skipBits(8); + $profile = $this->getBits(8); // read profile + if ($profile > 0) { + $this->skipBits(8); + $level_idc = $this->getBits(8); // level_idc + $this->expGolombUe(); // seq_parameter_set_id // sps + $this->expGolombUe(); // log2_max_frame_num_minus4 + $picOrderType = $this->expGolombUe(); // pic_order_cnt_type + if ($picOrderType == 0) { + $this->expGolombUe(); // log2_max_pic_order_cnt_lsb_minus4 + } elseif ($picOrderType == 1) { + $this->skipBits(1); // delta_pic_order_always_zero_flag + $this->expGolombSe(); // offset_for_non_ref_pic + $this->expGolombSe(); // offset_for_top_to_bottom_field + $num_ref_frames_in_pic_order_cnt_cycle = $this->expGolombUe(); // num_ref_frames_in_pic_order_cnt_cycle + for ($i = 0; $i < $num_ref_frames_in_pic_order_cnt_cycle; $i++) { + $this->expGolombSe(); // offset_for_ref_frame[ i ] + } + } + $this->expGolombUe(); // num_ref_frames + $this->skipBits(1); // gaps_in_frame_num_value_allowed_flag + $pic_width_in_mbs_minus1 = $this->expGolombUe(); // pic_width_in_mbs_minus1 + $pic_height_in_map_units_minus1 = $this->expGolombUe(); // pic_height_in_map_units_minus1 - $frame_mbs_only_flag = $this->getBits(1); // frame_mbs_only_flag - if ($frame_mbs_only_flag == 0) { - $this->skipBits(1); // mb_adaptive_frame_field_flag - } - $this->skipBits(1); // direct_8x8_inference_flag - $frame_cropping_flag = $this->getBits(1); // frame_cropping_flag + $frame_mbs_only_flag = $this->getBits(1); // frame_mbs_only_flag + if ($frame_mbs_only_flag == 0) { + $this->skipBits(1); // mb_adaptive_frame_field_flag + } + $this->skipBits(1); // direct_8x8_inference_flag + $frame_cropping_flag = $this->getBits(1); // frame_cropping_flag - $frame_crop_left_offset = 0; - $frame_crop_right_offset = 0; - $frame_crop_top_offset = 0; - $frame_crop_bottom_offset = 0; + $frame_crop_left_offset = 0; + $frame_crop_right_offset = 0; + $frame_crop_top_offset = 0; + $frame_crop_bottom_offset = 0; - if ($frame_cropping_flag) { - $frame_crop_left_offset = $this->expGolombUe(); // frame_crop_left_offset - $frame_crop_right_offset = $this->expGolombUe(); // frame_crop_right_offset - $frame_crop_top_offset = $this->expGolombUe(); // frame_crop_top_offset - $frame_crop_bottom_offset = $this->expGolombUe(); // frame_crop_bottom_offset - } - $this->skipBits(1); // vui_parameters_present_flag - // etc + if ($frame_cropping_flag) { + $frame_crop_left_offset = $this->expGolombUe(); // frame_crop_left_offset + $frame_crop_right_offset = $this->expGolombUe(); // frame_crop_right_offset + $frame_crop_top_offset = $this->expGolombUe(); // frame_crop_top_offset + $frame_crop_bottom_offset = $this->expGolombUe(); // frame_crop_bottom_offset + } + $this->skipBits(1); // vui_parameters_present_flag + // etc - $this->width = (($pic_width_in_mbs_minus1 + 1) * 16) - ($frame_crop_left_offset * 2) - ($frame_crop_right_offset * 2); - $this->height = ((2 - $frame_mbs_only_flag) * ($pic_height_in_map_units_minus1 + 1) * 16) - ($frame_crop_top_offset * 2) - ($frame_crop_bottom_offset * 2); - } - } + $this->width = (($pic_width_in_mbs_minus1 + 1) * 16) - ($frame_crop_left_offset * 2) - ($frame_crop_right_offset * 2); + $this->height = ((2 - $frame_mbs_only_flag) * ($pic_height_in_map_units_minus1 + 1) * 16) - ($frame_crop_top_offset * 2) - ($frame_crop_bottom_offset * 2); + } + } - public function skipBits($bits) { - $newBits = $this->currentBits + $bits; - $this->currentBytes += (int)floor($newBits / 8); - $this->currentBits = $newBits % 8; - } + public function skipBits($bits) + { + $newBits = $this->currentBits + $bits; + $this->currentBytes += (int) floor($newBits / 8); + $this->currentBits = $newBits % 8; + } - public function getBit() { - $result = (getid3_lib::BigEndian2Int(substr($this->sps, $this->currentBytes, 1)) >> (7 - $this->currentBits)) & 0x01; - $this->skipBits(1); - return $result; - } + public function getBit() + { + $result = (getid3_lib::BigEndian2Int(substr($this->sps, $this->currentBytes, 1)) >> (7 - $this->currentBits)) & 0x01; + $this->skipBits(1); - public function getBits($bits) { - $result = 0; - for ($i = 0; $i < $bits; $i++) { - $result = ($result << 1) + $this->getBit(); - } - return $result; - } + return $result; + } - public function expGolombUe() { - $significantBits = 0; - $bit = $this->getBit(); - while ($bit == 0) { - $significantBits++; - $bit = $this->getBit(); + public function getBits($bits) + { + $result = 0; + for ($i = 0; $i < $bits; $i++) { + $result = ($result << 1) + $this->getBit(); + } - if ($significantBits > 31) { - // something is broken, this is an emergency escape to prevent infinite loops - return 0; - } - } - return (1 << $significantBits) + $this->getBits($significantBits) - 1; - } + return $result; + } - public function expGolombSe() { - $result = $this->expGolombUe(); - if (($result & 0x01) == 0) { - return -($result >> 1); - } else { - return ($result + 1) >> 1; - } - } + public function expGolombUe() + { + $significantBits = 0; + $bit = $this->getBit(); + while ($bit == 0) { + $significantBits++; + $bit = $this->getBit(); - public function getWidth() { - return $this->width; - } + if ($significantBits > 31) { + // something is broken, this is an emergency escape to prevent infinite loops + return 0; + } + } - public function getHeight() { - return $this->height; - } + return (1 << $significantBits) + $this->getBits($significantBits) - 1; + } + + public function expGolombSe() + { + $result = $this->expGolombUe(); + if (($result & 0x01) == 0) { + return -($result >> 1); + } else { + return ($result + 1) >> 1; + } + } + + public function getWidth() + { + return $this->width; + } + + public function getHeight() + { + return $this->height; + } } diff --git a/app/Library/getid3/getid3/module.audio-video.matroska.php b/app/Library/getid3/getid3/module.audio-video.matroska.php index 825a22e1..f9533f37 100644 --- a/app/Library/getid3/getid3/module.audio-video.matroska.php +++ b/app/Library/getid3/getid3/module.audio-video.matroska.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,1777 +15,1807 @@ // /// ///////////////////////////////////////////////////////////////// - -define('EBML_ID_CHAPTERS', 0x0043A770); // [10][43][A7][70] -- A system to define basic menus and partition data. For more detailed information, look at the Chapters Explanation. -define('EBML_ID_SEEKHEAD', 0x014D9B74); // [11][4D][9B][74] -- Contains the position of other level 1 elements. -define('EBML_ID_TAGS', 0x0254C367); // [12][54][C3][67] -- Element containing elements specific to Tracks/Chapters. A list of valid tags can be found . -define('EBML_ID_INFO', 0x0549A966); // [15][49][A9][66] -- Contains miscellaneous general information and statistics on the file. -define('EBML_ID_TRACKS', 0x0654AE6B); // [16][54][AE][6B] -- A top-level block of information with many tracks described. -define('EBML_ID_SEGMENT', 0x08538067); // [18][53][80][67] -- This element contains all other top-level (level 1) elements. Typically a Matroska file is composed of 1 segment. -define('EBML_ID_ATTACHMENTS', 0x0941A469); // [19][41][A4][69] -- Contain attached files. -define('EBML_ID_EBML', 0x0A45DFA3); // [1A][45][DF][A3] -- Set the EBML characteristics of the data to follow. Each EBML document has to start with this. -define('EBML_ID_CUES', 0x0C53BB6B); // [1C][53][BB][6B] -- A top-level element to speed seeking access. All entries are local to the segment. -define('EBML_ID_CLUSTER', 0x0F43B675); // [1F][43][B6][75] -- The lower level element containing the (monolithic) Block structure. -define('EBML_ID_LANGUAGE', 0x02B59C); // [22][B5][9C] -- Specifies the language of the track in the Matroska languages form. -define('EBML_ID_TRACKTIMECODESCALE', 0x03314F); // [23][31][4F] -- The scale to apply on this track to work at normal speed in relation with other tracks (mostly used to adjust video speed when the audio length differs). -define('EBML_ID_DEFAULTDURATION', 0x03E383); // [23][E3][83] -- Number of nanoseconds (i.e. not scaled) per frame. -define('EBML_ID_CODECNAME', 0x058688); // [25][86][88] -- A human-readable string specifying the codec. -define('EBML_ID_CODECDOWNLOADURL', 0x06B240); // [26][B2][40] -- A URL to download about the codec used. -define('EBML_ID_TIMECODESCALE', 0x0AD7B1); // [2A][D7][B1] -- Timecode scale in nanoseconds (1.000.000 means all timecodes in the segment are expressed in milliseconds). -define('EBML_ID_COLOURSPACE', 0x0EB524); // [2E][B5][24] -- Same value as in AVI (32 bits). -define('EBML_ID_GAMMAVALUE', 0x0FB523); // [2F][B5][23] -- Gamma Value. -define('EBML_ID_CODECSETTINGS', 0x1A9697); // [3A][96][97] -- A string describing the encoding setting used. -define('EBML_ID_CODECINFOURL', 0x1B4040); // [3B][40][40] -- A URL to find information about the codec used. -define('EBML_ID_PREVFILENAME', 0x1C83AB); // [3C][83][AB] -- An escaped filename corresponding to the previous segment. -define('EBML_ID_PREVUID', 0x1CB923); // [3C][B9][23] -- A unique ID to identify the previous chained segment (128 bits). -define('EBML_ID_NEXTFILENAME', 0x1E83BB); // [3E][83][BB] -- An escaped filename corresponding to the next segment. -define('EBML_ID_NEXTUID', 0x1EB923); // [3E][B9][23] -- A unique ID to identify the next chained segment (128 bits). -define('EBML_ID_CONTENTCOMPALGO', 0x0254); // [42][54] -- The compression algorithm used. Algorithms that have been specified so far are: -define('EBML_ID_CONTENTCOMPSETTINGS', 0x0255); // [42][55] -- Settings that might be needed by the decompressor. For Header Stripping (ContentCompAlgo=3), the bytes that were removed from the beggining of each frames of the track. -define('EBML_ID_DOCTYPE', 0x0282); // [42][82] -- A string that describes the type of document that follows this EBML header ('matroska' in our case). -define('EBML_ID_DOCTYPEREADVERSION', 0x0285); // [42][85] -- The minimum DocType version an interpreter has to support to read this file. -define('EBML_ID_EBMLVERSION', 0x0286); // [42][86] -- The version of EBML parser used to create the file. -define('EBML_ID_DOCTYPEVERSION', 0x0287); // [42][87] -- The version of DocType interpreter used to create the file. -define('EBML_ID_EBMLMAXIDLENGTH', 0x02F2); // [42][F2] -- The maximum length of the IDs you'll find in this file (4 or less in Matroska). -define('EBML_ID_EBMLMAXSIZELENGTH', 0x02F3); // [42][F3] -- The maximum length of the sizes you'll find in this file (8 or less in Matroska). This does not override the element size indicated at the beginning of an element. Elements that have an indicated size which is larger than what is allowed by EBMLMaxSizeLength shall be considered invalid. -define('EBML_ID_EBMLREADVERSION', 0x02F7); // [42][F7] -- The minimum EBML version a parser has to support to read this file. -define('EBML_ID_CHAPLANGUAGE', 0x037C); // [43][7C] -- The languages corresponding to the string, in the bibliographic ISO-639-2 form. -define('EBML_ID_CHAPCOUNTRY', 0x037E); // [43][7E] -- The countries corresponding to the string, same 2 octets as in Internet domains. -define('EBML_ID_SEGMENTFAMILY', 0x0444); // [44][44] -- A randomly generated unique ID that all segments related to each other must use (128 bits). -define('EBML_ID_DATEUTC', 0x0461); // [44][61] -- Date of the origin of timecode (value 0), i.e. production date. -define('EBML_ID_TAGLANGUAGE', 0x047A); // [44][7A] -- Specifies the language of the tag specified, in the Matroska languages form. -define('EBML_ID_TAGDEFAULT', 0x0484); // [44][84] -- Indication to know if this is the default/original language to use for the given tag. -define('EBML_ID_TAGBINARY', 0x0485); // [44][85] -- The values of the Tag if it is binary. Note that this cannot be used in the same SimpleTag as TagString. -define('EBML_ID_TAGSTRING', 0x0487); // [44][87] -- The value of the Tag. -define('EBML_ID_DURATION', 0x0489); // [44][89] -- Duration of the segment (based on TimecodeScale). -define('EBML_ID_CHAPPROCESSPRIVATE', 0x050D); // [45][0D] -- Some optional data attached to the ChapProcessCodecID information. For ChapProcessCodecID = 1, it is the "DVD level" equivalent. -define('EBML_ID_CHAPTERFLAGENABLED', 0x0598); // [45][98] -- Specify wether the chapter is enabled. It can be enabled/disabled by a Control Track. When disabled, the movie should skip all the content between the TimeStart and TimeEnd of this chapter. -define('EBML_ID_TAGNAME', 0x05A3); // [45][A3] -- The name of the Tag that is going to be stored. -define('EBML_ID_EDITIONENTRY', 0x05B9); // [45][B9] -- Contains all information about a segment edition. -define('EBML_ID_EDITIONUID', 0x05BC); // [45][BC] -- A unique ID to identify the edition. It's useful for tagging an edition. -define('EBML_ID_EDITIONFLAGHIDDEN', 0x05BD); // [45][BD] -- If an edition is hidden (1), it should not be available to the user interface (but still to Control Tracks). -define('EBML_ID_EDITIONFLAGDEFAULT', 0x05DB); // [45][DB] -- If a flag is set (1) the edition should be used as the default one. -define('EBML_ID_EDITIONFLAGORDERED', 0x05DD); // [45][DD] -- Specify if the chapters can be defined multiple times and the order to play them is enforced. -define('EBML_ID_FILEDATA', 0x065C); // [46][5C] -- The data of the file. -define('EBML_ID_FILEMIMETYPE', 0x0660); // [46][60] -- MIME type of the file. -define('EBML_ID_FILENAME', 0x066E); // [46][6E] -- Filename of the attached file. -define('EBML_ID_FILEREFERRAL', 0x0675); // [46][75] -- A binary value that a track/codec can refer to when the attachment is needed. -define('EBML_ID_FILEDESCRIPTION', 0x067E); // [46][7E] -- A human-friendly name for the attached file. -define('EBML_ID_FILEUID', 0x06AE); // [46][AE] -- Unique ID representing the file, as random as possible. -define('EBML_ID_CONTENTENCALGO', 0x07E1); // [47][E1] -- The encryption algorithm used. The value '0' means that the contents have not been encrypted but only signed. Predefined values: -define('EBML_ID_CONTENTENCKEYID', 0x07E2); // [47][E2] -- For public key algorithms this is the ID of the public key the the data was encrypted with. -define('EBML_ID_CONTENTSIGNATURE', 0x07E3); // [47][E3] -- A cryptographic signature of the contents. -define('EBML_ID_CONTENTSIGKEYID', 0x07E4); // [47][E4] -- This is the ID of the private key the data was signed with. -define('EBML_ID_CONTENTSIGALGO', 0x07E5); // [47][E5] -- The algorithm used for the signature. A value of '0' means that the contents have not been signed but only encrypted. Predefined values: -define('EBML_ID_CONTENTSIGHASHALGO', 0x07E6); // [47][E6] -- The hash algorithm used for the signature. A value of '0' means that the contents have not been signed but only encrypted. Predefined values: -define('EBML_ID_MUXINGAPP', 0x0D80); // [4D][80] -- Muxing application or library ("libmatroska-0.4.3"). -define('EBML_ID_SEEK', 0x0DBB); // [4D][BB] -- Contains a single seek entry to an EBML element. -define('EBML_ID_CONTENTENCODINGORDER', 0x1031); // [50][31] -- Tells when this modification was used during encoding/muxing starting with 0 and counting upwards. The decoder/demuxer has to start with the highest order number it finds and work its way down. This value has to be unique over all ContentEncodingOrder elements in the segment. -define('EBML_ID_CONTENTENCODINGSCOPE', 0x1032); // [50][32] -- A bit field that describes which elements have been modified in this way. Values (big endian) can be OR'ed. Possible values: -define('EBML_ID_CONTENTENCODINGTYPE', 0x1033); // [50][33] -- A value describing what kind of transformation has been done. Possible values: -define('EBML_ID_CONTENTCOMPRESSION', 0x1034); // [50][34] -- Settings describing the compression used. Must be present if the value of ContentEncodingType is 0 and absent otherwise. Each block must be decompressable even if no previous block is available in order not to prevent seeking. -define('EBML_ID_CONTENTENCRYPTION', 0x1035); // [50][35] -- Settings describing the encryption used. Must be present if the value of ContentEncodingType is 1 and absent otherwise. -define('EBML_ID_CUEREFNUMBER', 0x135F); // [53][5F] -- Number of the referenced Block of Track X in the specified Cluster. -define('EBML_ID_NAME', 0x136E); // [53][6E] -- A human-readable track name. -define('EBML_ID_CUEBLOCKNUMBER', 0x1378); // [53][78] -- Number of the Block in the specified Cluster. -define('EBML_ID_TRACKOFFSET', 0x137F); // [53][7F] -- A value to add to the Block's Timecode. This can be used to adjust the playback offset of a track. -define('EBML_ID_SEEKID', 0x13AB); // [53][AB] -- The binary ID corresponding to the element name. -define('EBML_ID_SEEKPOSITION', 0x13AC); // [53][AC] -- The position of the element in the segment in octets (0 = first level 1 element). -define('EBML_ID_STEREOMODE', 0x13B8); // [53][B8] -- Stereo-3D video mode. -define('EBML_ID_OLDSTEREOMODE', 0x13B9); // [53][B9] -- Bogus StereoMode value used in old versions of libmatroska. DO NOT USE. (0: mono, 1: right eye, 2: left eye, 3: both eyes). -define('EBML_ID_PIXELCROPBOTTOM', 0x14AA); // [54][AA] -- The number of video pixels to remove at the bottom of the image (for HDTV content). -define('EBML_ID_DISPLAYWIDTH', 0x14B0); // [54][B0] -- Width of the video frames to display. -define('EBML_ID_DISPLAYUNIT', 0x14B2); // [54][B2] -- Type of the unit for DisplayWidth/Height (0: pixels, 1: centimeters, 2: inches). -define('EBML_ID_ASPECTRATIOTYPE', 0x14B3); // [54][B3] -- Specify the possible modifications to the aspect ratio (0: free resizing, 1: keep aspect ratio, 2: fixed). -define('EBML_ID_DISPLAYHEIGHT', 0x14BA); // [54][BA] -- Height of the video frames to display. -define('EBML_ID_PIXELCROPTOP', 0x14BB); // [54][BB] -- The number of video pixels to remove at the top of the image. -define('EBML_ID_PIXELCROPLEFT', 0x14CC); // [54][CC] -- The number of video pixels to remove on the left of the image. -define('EBML_ID_PIXELCROPRIGHT', 0x14DD); // [54][DD] -- The number of video pixels to remove on the right of the image. -define('EBML_ID_FLAGFORCED', 0x15AA); // [55][AA] -- Set if that track MUST be used during playback. There can be many forced track for a kind (audio, video or subs), the player should select the one which language matches the user preference or the default + forced track. Overlay MAY happen between a forced and non-forced track of the same kind. -define('EBML_ID_MAXBLOCKADDITIONID', 0x15EE); // [55][EE] -- The maximum value of BlockAddID. A value 0 means there is no BlockAdditions for this track. -define('EBML_ID_WRITINGAPP', 0x1741); // [57][41] -- Writing application ("mkvmerge-0.3.3"). -define('EBML_ID_CLUSTERSILENTTRACKS', 0x1854); // [58][54] -- The list of tracks that are not used in that part of the stream. It is useful when using overlay tracks on seeking. Then you should decide what track to use. -define('EBML_ID_CLUSTERSILENTTRACKNUMBER', 0x18D7); // [58][D7] -- One of the track number that are not used from now on in the stream. It could change later if not specified as silent in a further Cluster. -define('EBML_ID_ATTACHEDFILE', 0x21A7); // [61][A7] -- An attached file. -define('EBML_ID_CONTENTENCODING', 0x2240); // [62][40] -- Settings for one content encoding like compression or encryption. -define('EBML_ID_BITDEPTH', 0x2264); // [62][64] -- Bits per sample, mostly used for PCM. -define('EBML_ID_CODECPRIVATE', 0x23A2); // [63][A2] -- Private data only known to the codec. -define('EBML_ID_TARGETS', 0x23C0); // [63][C0] -- Contain all UIDs where the specified meta data apply. It is void to describe everything in the segment. -define('EBML_ID_CHAPTERPHYSICALEQUIV', 0x23C3); // [63][C3] -- Specify the physical equivalent of this ChapterAtom like "DVD" (60) or "SIDE" (50), see complete list of values. -define('EBML_ID_TAGCHAPTERUID', 0x23C4); // [63][C4] -- A unique ID to identify the Chapter(s) the tags belong to. If the value is 0 at this level, the tags apply to all chapters in the Segment. -define('EBML_ID_TAGTRACKUID', 0x23C5); // [63][C5] -- A unique ID to identify the Track(s) the tags belong to. If the value is 0 at this level, the tags apply to all tracks in the Segment. -define('EBML_ID_TAGATTACHMENTUID', 0x23C6); // [63][C6] -- A unique ID to identify the Attachment(s) the tags belong to. If the value is 0 at this level, the tags apply to all the attachments in the Segment. -define('EBML_ID_TAGEDITIONUID', 0x23C9); // [63][C9] -- A unique ID to identify the EditionEntry(s) the tags belong to. If the value is 0 at this level, the tags apply to all editions in the Segment. -define('EBML_ID_TARGETTYPE', 0x23CA); // [63][CA] -- An informational string that can be used to display the logical level of the target like "ALBUM", "TRACK", "MOVIE", "CHAPTER", etc (see TargetType). -define('EBML_ID_TRACKTRANSLATE', 0x2624); // [66][24] -- The track identification for the given Chapter Codec. -define('EBML_ID_TRACKTRANSLATETRACKID', 0x26A5); // [66][A5] -- The binary value used to represent this track in the chapter codec data. The format depends on the ChapProcessCodecID used. -define('EBML_ID_TRACKTRANSLATECODEC', 0x26BF); // [66][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu). -define('EBML_ID_TRACKTRANSLATEEDITIONUID', 0x26FC); // [66][FC] -- Specify an edition UID on which this translation applies. When not specified, it means for all editions found in the segment. -define('EBML_ID_SIMPLETAG', 0x27C8); // [67][C8] -- Contains general information about the target. -define('EBML_ID_TARGETTYPEVALUE', 0x28CA); // [68][CA] -- A number to indicate the logical level of the target (see TargetType). -define('EBML_ID_CHAPPROCESSCOMMAND', 0x2911); // [69][11] -- Contains all the commands associated to the Atom. -define('EBML_ID_CHAPPROCESSTIME', 0x2922); // [69][22] -- Defines when the process command should be handled (0: during the whole chapter, 1: before starting playback, 2: after playback of the chapter). -define('EBML_ID_CHAPTERTRANSLATE', 0x2924); // [69][24] -- A tuple of corresponding ID used by chapter codecs to represent this segment. -define('EBML_ID_CHAPPROCESSDATA', 0x2933); // [69][33] -- Contains the command information. The data should be interpreted depending on the ChapProcessCodecID value. For ChapProcessCodecID = 1, the data correspond to the binary DVD cell pre/post commands. -define('EBML_ID_CHAPPROCESS', 0x2944); // [69][44] -- Contains all the commands associated to the Atom. -define('EBML_ID_CHAPPROCESSCODECID', 0x2955); // [69][55] -- Contains the type of the codec used for the processing. A value of 0 means native Matroska processing (to be defined), a value of 1 means the DVD command set is used. More codec IDs can be added later. -define('EBML_ID_CHAPTERTRANSLATEID', 0x29A5); // [69][A5] -- The binary value used to represent this segment in the chapter codec data. The format depends on the ChapProcessCodecID used. -define('EBML_ID_CHAPTERTRANSLATECODEC', 0x29BF); // [69][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu). -define('EBML_ID_CHAPTERTRANSLATEEDITIONUID', 0x29FC); // [69][FC] -- Specify an edition UID on which this correspondance applies. When not specified, it means for all editions found in the segment. -define('EBML_ID_CONTENTENCODINGS', 0x2D80); // [6D][80] -- Settings for several content encoding mechanisms like compression or encryption. -define('EBML_ID_MINCACHE', 0x2DE7); // [6D][E7] -- The minimum number of frames a player should be able to cache during playback. If set to 0, the reference pseudo-cache system is not used. -define('EBML_ID_MAXCACHE', 0x2DF8); // [6D][F8] -- The maximum cache size required to store referenced frames in and the current frame. 0 means no cache is needed. -define('EBML_ID_CHAPTERSEGMENTUID', 0x2E67); // [6E][67] -- A segment to play in place of this chapter. Edition ChapterSegmentEditionUID should be used for this segment, otherwise no edition is used. -define('EBML_ID_CHAPTERSEGMENTEDITIONUID', 0x2EBC); // [6E][BC] -- The edition to play from the segment linked in ChapterSegmentUID. -define('EBML_ID_TRACKOVERLAY', 0x2FAB); // [6F][AB] -- Specify that this track is an overlay track for the Track specified (in the u-integer). That means when this track has a gap (see SilentTracks) the overlay track should be used instead. The order of multiple TrackOverlay matters, the first one is the one that should be used. If not found it should be the second, etc. -define('EBML_ID_TAG', 0x3373); // [73][73] -- Element containing elements specific to Tracks/Chapters. -define('EBML_ID_SEGMENTFILENAME', 0x3384); // [73][84] -- A filename corresponding to this segment. -define('EBML_ID_SEGMENTUID', 0x33A4); // [73][A4] -- A randomly generated unique ID to identify the current segment between many others (128 bits). -define('EBML_ID_CHAPTERUID', 0x33C4); // [73][C4] -- A unique ID to identify the Chapter. -define('EBML_ID_TRACKUID', 0x33C5); // [73][C5] -- A unique ID to identify the Track. This should be kept the same when making a direct stream copy of the Track to another file. -define('EBML_ID_ATTACHMENTLINK', 0x3446); // [74][46] -- The UID of an attachment that is used by this codec. -define('EBML_ID_CLUSTERBLOCKADDITIONS', 0x35A1); // [75][A1] -- Contain additional blocks to complete the main one. An EBML parser that has no knowledge of the Block structure could still see and use/skip these data. -define('EBML_ID_CHANNELPOSITIONS', 0x347B); // [7D][7B] -- Table of horizontal angles for each successive channel, see appendix. -define('EBML_ID_OUTPUTSAMPLINGFREQUENCY', 0x38B5); // [78][B5] -- Real output sampling frequency in Hz (used for SBR techniques). -define('EBML_ID_TITLE', 0x3BA9); // [7B][A9] -- General name of the segment. -define('EBML_ID_CHAPTERDISPLAY', 0x00); // [80] -- Contains all possible strings to use for the chapter display. -define('EBML_ID_TRACKTYPE', 0x03); // [83] -- A set of track types coded on 8 bits (1: video, 2: audio, 3: complex, 0x10: logo, 0x11: subtitle, 0x12: buttons, 0x20: control). -define('EBML_ID_CHAPSTRING', 0x05); // [85] -- Contains the string to use as the chapter atom. -define('EBML_ID_CODECID', 0x06); // [86] -- An ID corresponding to the codec, see the codec page for more info. -define('EBML_ID_FLAGDEFAULT', 0x08); // [88] -- Set if that track (audio, video or subs) SHOULD be used if no language found matches the user preference. -define('EBML_ID_CHAPTERTRACKNUMBER', 0x09); // [89] -- UID of the Track to apply this chapter too. In the absense of a control track, choosing this chapter will select the listed Tracks and deselect unlisted tracks. Absense of this element indicates that the Chapter should be applied to any currently used Tracks. -define('EBML_ID_CLUSTERSLICES', 0x0E); // [8E] -- Contains slices description. -define('EBML_ID_CHAPTERTRACK', 0x0F); // [8F] -- List of tracks on which the chapter applies. If this element is not present, all tracks apply -define('EBML_ID_CHAPTERTIMESTART', 0x11); // [91] -- Timecode of the start of Chapter (not scaled). -define('EBML_ID_CHAPTERTIMEEND', 0x12); // [92] -- Timecode of the end of Chapter (timecode excluded, not scaled). -define('EBML_ID_CUEREFTIME', 0x16); // [96] -- Timecode of the referenced Block. -define('EBML_ID_CUEREFCLUSTER', 0x17); // [97] -- Position of the Cluster containing the referenced Block. -define('EBML_ID_CHAPTERFLAGHIDDEN', 0x18); // [98] -- If a chapter is hidden (1), it should not be available to the user interface (but still to Control Tracks). -define('EBML_ID_FLAGINTERLACED', 0x1A); // [9A] -- Set if the video is interlaced. -define('EBML_ID_CLUSTERBLOCKDURATION', 0x1B); // [9B] -- The duration of the Block (based on TimecodeScale). This element is mandatory when DefaultDuration is set for the track. When not written and with no DefaultDuration, the value is assumed to be the difference between the timecode of this Block and the timecode of the next Block in "display" order (not coding order). This element can be useful at the end of a Track (as there is not other Block available), or when there is a break in a track like for subtitle tracks. -define('EBML_ID_FLAGLACING', 0x1C); // [9C] -- Set if the track may contain blocks using lacing. -define('EBML_ID_CHANNELS', 0x1F); // [9F] -- Numbers of channels in the track. -define('EBML_ID_CLUSTERBLOCKGROUP', 0x20); // [A0] -- Basic container of information containing a single Block or BlockVirtual, and information specific to that Block/VirtualBlock. -define('EBML_ID_CLUSTERBLOCK', 0x21); // [A1] -- Block containing the actual data to be rendered and a timecode relative to the Cluster Timecode. -define('EBML_ID_CLUSTERBLOCKVIRTUAL', 0x22); // [A2] -- A Block with no data. It must be stored in the stream at the place the real Block should be in display order. -define('EBML_ID_CLUSTERSIMPLEBLOCK', 0x23); // [A3] -- Similar to Block but without all the extra information, mostly used to reduced overhead when no extra feature is needed. -define('EBML_ID_CLUSTERCODECSTATE', 0x24); // [A4] -- The new codec state to use. Data interpretation is private to the codec. This information should always be referenced by a seek entry. -define('EBML_ID_CLUSTERBLOCKADDITIONAL', 0x25); // [A5] -- Interpreted by the codec as it wishes (using the BlockAddID). -define('EBML_ID_CLUSTERBLOCKMORE', 0x26); // [A6] -- Contain the BlockAdditional and some parameters. -define('EBML_ID_CLUSTERPOSITION', 0x27); // [A7] -- Position of the Cluster in the segment (0 in live broadcast streams). It might help to resynchronise offset on damaged streams. -define('EBML_ID_CODECDECODEALL', 0x2A); // [AA] -- The codec can decode potentially damaged data. -define('EBML_ID_CLUSTERPREVSIZE', 0x2B); // [AB] -- Size of the previous Cluster, in octets. Can be useful for backward playing. -define('EBML_ID_TRACKENTRY', 0x2E); // [AE] -- Describes a track with all elements. -define('EBML_ID_CLUSTERENCRYPTEDBLOCK', 0x2F); // [AF] -- Similar to SimpleBlock but the data inside the Block are Transformed (encrypt and/or signed). -define('EBML_ID_PIXELWIDTH', 0x30); // [B0] -- Width of the encoded video frames in pixels. -define('EBML_ID_CUETIME', 0x33); // [B3] -- Absolute timecode according to the segment time base. -define('EBML_ID_SAMPLINGFREQUENCY', 0x35); // [B5] -- Sampling frequency in Hz. -define('EBML_ID_CHAPTERATOM', 0x36); // [B6] -- Contains the atom information to use as the chapter atom (apply to all tracks). -define('EBML_ID_CUETRACKPOSITIONS', 0x37); // [B7] -- Contain positions for different tracks corresponding to the timecode. -define('EBML_ID_FLAGENABLED', 0x39); // [B9] -- Set if the track is used. -define('EBML_ID_PIXELHEIGHT', 0x3A); // [BA] -- Height of the encoded video frames in pixels. -define('EBML_ID_CUEPOINT', 0x3B); // [BB] -- Contains all information relative to a seek point in the segment. -define('EBML_ID_CRC32', 0x3F); // [BF] -- The CRC is computed on all the data of the Master element it's in, regardless of its position. It's recommended to put the CRC value at the beggining of the Master element for easier reading. All level 1 elements should include a CRC-32. -define('EBML_ID_CLUSTERBLOCKADDITIONID', 0x4B); // [CB] -- The ID of the BlockAdditional element (0 is the main Block). -define('EBML_ID_CLUSTERLACENUMBER', 0x4C); // [CC] -- The reverse number of the frame in the lace (0 is the last frame, 1 is the next to last, etc). While there are a few files in the wild with this element, it is no longer in use and has been deprecated. Being able to interpret this element is not required for playback. -define('EBML_ID_CLUSTERFRAMENUMBER', 0x4D); // [CD] -- The number of the frame to generate from this lace with this delay (allow you to generate many frames from the same Block/Frame). -define('EBML_ID_CLUSTERDELAY', 0x4E); // [CE] -- The (scaled) delay to apply to the element. -define('EBML_ID_CLUSTERDURATION', 0x4F); // [CF] -- The (scaled) duration to apply to the element. -define('EBML_ID_TRACKNUMBER', 0x57); // [D7] -- The track number as used in the Block Header (using more than 127 tracks is not encouraged, though the design allows an unlimited number). -define('EBML_ID_CUEREFERENCE', 0x5B); // [DB] -- The Clusters containing the required referenced Blocks. -define('EBML_ID_VIDEO', 0x60); // [E0] -- Video settings. -define('EBML_ID_AUDIO', 0x61); // [E1] -- Audio settings. -define('EBML_ID_CLUSTERTIMESLICE', 0x68); // [E8] -- Contains extra time information about the data contained in the Block. While there are a few files in the wild with this element, it is no longer in use and has been deprecated. Being able to interpret this element is not required for playback. -define('EBML_ID_CUECODECSTATE', 0x6A); // [EA] -- The position of the Codec State corresponding to this Cue element. 0 means that the data is taken from the initial Track Entry. -define('EBML_ID_CUEREFCODECSTATE', 0x6B); // [EB] -- The position of the Codec State corresponding to this referenced element. 0 means that the data is taken from the initial Track Entry. -define('EBML_ID_VOID', 0x6C); // [EC] -- Used to void damaged data, to avoid unexpected behaviors when using damaged data. The content is discarded. Also used to reserve space in a sub-element for later use. -define('EBML_ID_CLUSTERTIMECODE', 0x67); // [E7] -- Absolute timecode of the cluster (based on TimecodeScale). -define('EBML_ID_CLUSTERBLOCKADDID', 0x6E); // [EE] -- An ID to identify the BlockAdditional level. -define('EBML_ID_CUECLUSTERPOSITION', 0x71); // [F1] -- The position of the Cluster containing the required Block. -define('EBML_ID_CUETRACK', 0x77); // [F7] -- The track for which a position is given. -define('EBML_ID_CLUSTERREFERENCEPRIORITY', 0x7A); // [FA] -- This frame is referenced and has the specified cache priority. In cache only a frame of the same or higher priority can replace this frame. A value of 0 means the frame is not referenced. -define('EBML_ID_CLUSTERREFERENCEBLOCK', 0x7B); // [FB] -- Timecode of another frame used as a reference (ie: B or P frame). The timecode is relative to the block it's attached to. -define('EBML_ID_CLUSTERREFERENCEVIRTUAL', 0x7D); // [FD] -- Relative position of the data that should be in position of the virtual block. - +define('EBML_ID_CHAPTERS', 0x0043A770); // [10][43][A7][70] -- A system to define basic menus and partition data. For more detailed information, look at the Chapters Explanation. +define('EBML_ID_SEEKHEAD', 0x014D9B74); // [11][4D][9B][74] -- Contains the position of other level 1 elements. +define('EBML_ID_TAGS', 0x0254C367); // [12][54][C3][67] -- Element containing elements specific to Tracks/Chapters. A list of valid tags can be found . +define('EBML_ID_INFO', 0x0549A966); // [15][49][A9][66] -- Contains miscellaneous general information and statistics on the file. +define('EBML_ID_TRACKS', 0x0654AE6B); // [16][54][AE][6B] -- A top-level block of information with many tracks described. +define('EBML_ID_SEGMENT', 0x08538067); // [18][53][80][67] -- This element contains all other top-level (level 1) elements. Typically a Matroska file is composed of 1 segment. +define('EBML_ID_ATTACHMENTS', 0x0941A469); // [19][41][A4][69] -- Contain attached files. +define('EBML_ID_EBML', 0x0A45DFA3); // [1A][45][DF][A3] -- Set the EBML characteristics of the data to follow. Each EBML document has to start with this. +define('EBML_ID_CUES', 0x0C53BB6B); // [1C][53][BB][6B] -- A top-level element to speed seeking access. All entries are local to the segment. +define('EBML_ID_CLUSTER', 0x0F43B675); // [1F][43][B6][75] -- The lower level element containing the (monolithic) Block structure. +define('EBML_ID_LANGUAGE', 0x02B59C); // [22][B5][9C] -- Specifies the language of the track in the Matroska languages form. +define('EBML_ID_TRACKTIMECODESCALE', 0x03314F); // [23][31][4F] -- The scale to apply on this track to work at normal speed in relation with other tracks (mostly used to adjust video speed when the audio length differs). +define('EBML_ID_DEFAULTDURATION', 0x03E383); // [23][E3][83] -- Number of nanoseconds (i.e. not scaled) per frame. +define('EBML_ID_CODECNAME', 0x058688); // [25][86][88] -- A human-readable string specifying the codec. +define('EBML_ID_CODECDOWNLOADURL', 0x06B240); // [26][B2][40] -- A URL to download about the codec used. +define('EBML_ID_TIMECODESCALE', 0x0AD7B1); // [2A][D7][B1] -- Timecode scale in nanoseconds (1.000.000 means all timecodes in the segment are expressed in milliseconds). +define('EBML_ID_COLOURSPACE', 0x0EB524); // [2E][B5][24] -- Same value as in AVI (32 bits). +define('EBML_ID_GAMMAVALUE', 0x0FB523); // [2F][B5][23] -- Gamma Value. +define('EBML_ID_CODECSETTINGS', 0x1A9697); // [3A][96][97] -- A string describing the encoding setting used. +define('EBML_ID_CODECINFOURL', 0x1B4040); // [3B][40][40] -- A URL to find information about the codec used. +define('EBML_ID_PREVFILENAME', 0x1C83AB); // [3C][83][AB] -- An escaped filename corresponding to the previous segment. +define('EBML_ID_PREVUID', 0x1CB923); // [3C][B9][23] -- A unique ID to identify the previous chained segment (128 bits). +define('EBML_ID_NEXTFILENAME', 0x1E83BB); // [3E][83][BB] -- An escaped filename corresponding to the next segment. +define('EBML_ID_NEXTUID', 0x1EB923); // [3E][B9][23] -- A unique ID to identify the next chained segment (128 bits). +define('EBML_ID_CONTENTCOMPALGO', 0x0254); // [42][54] -- The compression algorithm used. Algorithms that have been specified so far are: +define('EBML_ID_CONTENTCOMPSETTINGS', 0x0255); // [42][55] -- Settings that might be needed by the decompressor. For Header Stripping (ContentCompAlgo=3), the bytes that were removed from the beggining of each frames of the track. +define('EBML_ID_DOCTYPE', 0x0282); // [42][82] -- A string that describes the type of document that follows this EBML header ('matroska' in our case). +define('EBML_ID_DOCTYPEREADVERSION', 0x0285); // [42][85] -- The minimum DocType version an interpreter has to support to read this file. +define('EBML_ID_EBMLVERSION', 0x0286); // [42][86] -- The version of EBML parser used to create the file. +define('EBML_ID_DOCTYPEVERSION', 0x0287); // [42][87] -- The version of DocType interpreter used to create the file. +define('EBML_ID_EBMLMAXIDLENGTH', 0x02F2); // [42][F2] -- The maximum length of the IDs you'll find in this file (4 or less in Matroska). +define('EBML_ID_EBMLMAXSIZELENGTH', 0x02F3); // [42][F3] -- The maximum length of the sizes you'll find in this file (8 or less in Matroska). This does not override the element size indicated at the beginning of an element. Elements that have an indicated size which is larger than what is allowed by EBMLMaxSizeLength shall be considered invalid. +define('EBML_ID_EBMLREADVERSION', 0x02F7); // [42][F7] -- The minimum EBML version a parser has to support to read this file. +define('EBML_ID_CHAPLANGUAGE', 0x037C); // [43][7C] -- The languages corresponding to the string, in the bibliographic ISO-639-2 form. +define('EBML_ID_CHAPCOUNTRY', 0x037E); // [43][7E] -- The countries corresponding to the string, same 2 octets as in Internet domains. +define('EBML_ID_SEGMENTFAMILY', 0x0444); // [44][44] -- A randomly generated unique ID that all segments related to each other must use (128 bits). +define('EBML_ID_DATEUTC', 0x0461); // [44][61] -- Date of the origin of timecode (value 0), i.e. production date. +define('EBML_ID_TAGLANGUAGE', 0x047A); // [44][7A] -- Specifies the language of the tag specified, in the Matroska languages form. +define('EBML_ID_TAGDEFAULT', 0x0484); // [44][84] -- Indication to know if this is the default/original language to use for the given tag. +define('EBML_ID_TAGBINARY', 0x0485); // [44][85] -- The values of the Tag if it is binary. Note that this cannot be used in the same SimpleTag as TagString. +define('EBML_ID_TAGSTRING', 0x0487); // [44][87] -- The value of the Tag. +define('EBML_ID_DURATION', 0x0489); // [44][89] -- Duration of the segment (based on TimecodeScale). +define('EBML_ID_CHAPPROCESSPRIVATE', 0x050D); // [45][0D] -- Some optional data attached to the ChapProcessCodecID information. For ChapProcessCodecID = 1, it is the "DVD level" equivalent. +define('EBML_ID_CHAPTERFLAGENABLED', 0x0598); // [45][98] -- Specify wether the chapter is enabled. It can be enabled/disabled by a Control Track. When disabled, the movie should skip all the content between the TimeStart and TimeEnd of this chapter. +define('EBML_ID_TAGNAME', 0x05A3); // [45][A3] -- The name of the Tag that is going to be stored. +define('EBML_ID_EDITIONENTRY', 0x05B9); // [45][B9] -- Contains all information about a segment edition. +define('EBML_ID_EDITIONUID', 0x05BC); // [45][BC] -- A unique ID to identify the edition. It's useful for tagging an edition. +define('EBML_ID_EDITIONFLAGHIDDEN', 0x05BD); // [45][BD] -- If an edition is hidden (1), it should not be available to the user interface (but still to Control Tracks). +define('EBML_ID_EDITIONFLAGDEFAULT', 0x05DB); // [45][DB] -- If a flag is set (1) the edition should be used as the default one. +define('EBML_ID_EDITIONFLAGORDERED', 0x05DD); // [45][DD] -- Specify if the chapters can be defined multiple times and the order to play them is enforced. +define('EBML_ID_FILEDATA', 0x065C); // [46][5C] -- The data of the file. +define('EBML_ID_FILEMIMETYPE', 0x0660); // [46][60] -- MIME type of the file. +define('EBML_ID_FILENAME', 0x066E); // [46][6E] -- Filename of the attached file. +define('EBML_ID_FILEREFERRAL', 0x0675); // [46][75] -- A binary value that a track/codec can refer to when the attachment is needed. +define('EBML_ID_FILEDESCRIPTION', 0x067E); // [46][7E] -- A human-friendly name for the attached file. +define('EBML_ID_FILEUID', 0x06AE); // [46][AE] -- Unique ID representing the file, as random as possible. +define('EBML_ID_CONTENTENCALGO', 0x07E1); // [47][E1] -- The encryption algorithm used. The value '0' means that the contents have not been encrypted but only signed. Predefined values: +define('EBML_ID_CONTENTENCKEYID', 0x07E2); // [47][E2] -- For public key algorithms this is the ID of the public key the the data was encrypted with. +define('EBML_ID_CONTENTSIGNATURE', 0x07E3); // [47][E3] -- A cryptographic signature of the contents. +define('EBML_ID_CONTENTSIGKEYID', 0x07E4); // [47][E4] -- This is the ID of the private key the data was signed with. +define('EBML_ID_CONTENTSIGALGO', 0x07E5); // [47][E5] -- The algorithm used for the signature. A value of '0' means that the contents have not been signed but only encrypted. Predefined values: +define('EBML_ID_CONTENTSIGHASHALGO', 0x07E6); // [47][E6] -- The hash algorithm used for the signature. A value of '0' means that the contents have not been signed but only encrypted. Predefined values: +define('EBML_ID_MUXINGAPP', 0x0D80); // [4D][80] -- Muxing application or library ("libmatroska-0.4.3"). +define('EBML_ID_SEEK', 0x0DBB); // [4D][BB] -- Contains a single seek entry to an EBML element. +define('EBML_ID_CONTENTENCODINGORDER', 0x1031); // [50][31] -- Tells when this modification was used during encoding/muxing starting with 0 and counting upwards. The decoder/demuxer has to start with the highest order number it finds and work its way down. This value has to be unique over all ContentEncodingOrder elements in the segment. +define('EBML_ID_CONTENTENCODINGSCOPE', 0x1032); // [50][32] -- A bit field that describes which elements have been modified in this way. Values (big endian) can be OR'ed. Possible values: +define('EBML_ID_CONTENTENCODINGTYPE', 0x1033); // [50][33] -- A value describing what kind of transformation has been done. Possible values: +define('EBML_ID_CONTENTCOMPRESSION', 0x1034); // [50][34] -- Settings describing the compression used. Must be present if the value of ContentEncodingType is 0 and absent otherwise. Each block must be decompressable even if no previous block is available in order not to prevent seeking. +define('EBML_ID_CONTENTENCRYPTION', 0x1035); // [50][35] -- Settings describing the encryption used. Must be present if the value of ContentEncodingType is 1 and absent otherwise. +define('EBML_ID_CUEREFNUMBER', 0x135F); // [53][5F] -- Number of the referenced Block of Track X in the specified Cluster. +define('EBML_ID_NAME', 0x136E); // [53][6E] -- A human-readable track name. +define('EBML_ID_CUEBLOCKNUMBER', 0x1378); // [53][78] -- Number of the Block in the specified Cluster. +define('EBML_ID_TRACKOFFSET', 0x137F); // [53][7F] -- A value to add to the Block's Timecode. This can be used to adjust the playback offset of a track. +define('EBML_ID_SEEKID', 0x13AB); // [53][AB] -- The binary ID corresponding to the element name. +define('EBML_ID_SEEKPOSITION', 0x13AC); // [53][AC] -- The position of the element in the segment in octets (0 = first level 1 element). +define('EBML_ID_STEREOMODE', 0x13B8); // [53][B8] -- Stereo-3D video mode. +define('EBML_ID_OLDSTEREOMODE', 0x13B9); // [53][B9] -- Bogus StereoMode value used in old versions of libmatroska. DO NOT USE. (0: mono, 1: right eye, 2: left eye, 3: both eyes). +define('EBML_ID_PIXELCROPBOTTOM', 0x14AA); // [54][AA] -- The number of video pixels to remove at the bottom of the image (for HDTV content). +define('EBML_ID_DISPLAYWIDTH', 0x14B0); // [54][B0] -- Width of the video frames to display. +define('EBML_ID_DISPLAYUNIT', 0x14B2); // [54][B2] -- Type of the unit for DisplayWidth/Height (0: pixels, 1: centimeters, 2: inches). +define('EBML_ID_ASPECTRATIOTYPE', 0x14B3); // [54][B3] -- Specify the possible modifications to the aspect ratio (0: free resizing, 1: keep aspect ratio, 2: fixed). +define('EBML_ID_DISPLAYHEIGHT', 0x14BA); // [54][BA] -- Height of the video frames to display. +define('EBML_ID_PIXELCROPTOP', 0x14BB); // [54][BB] -- The number of video pixels to remove at the top of the image. +define('EBML_ID_PIXELCROPLEFT', 0x14CC); // [54][CC] -- The number of video pixels to remove on the left of the image. +define('EBML_ID_PIXELCROPRIGHT', 0x14DD); // [54][DD] -- The number of video pixels to remove on the right of the image. +define('EBML_ID_FLAGFORCED', 0x15AA); // [55][AA] -- Set if that track MUST be used during playback. There can be many forced track for a kind (audio, video or subs), the player should select the one which language matches the user preference or the default + forced track. Overlay MAY happen between a forced and non-forced track of the same kind. +define('EBML_ID_MAXBLOCKADDITIONID', 0x15EE); // [55][EE] -- The maximum value of BlockAddID. A value 0 means there is no BlockAdditions for this track. +define('EBML_ID_WRITINGAPP', 0x1741); // [57][41] -- Writing application ("mkvmerge-0.3.3"). +define('EBML_ID_CLUSTERSILENTTRACKS', 0x1854); // [58][54] -- The list of tracks that are not used in that part of the stream. It is useful when using overlay tracks on seeking. Then you should decide what track to use. +define('EBML_ID_CLUSTERSILENTTRACKNUMBER', 0x18D7); // [58][D7] -- One of the track number that are not used from now on in the stream. It could change later if not specified as silent in a further Cluster. +define('EBML_ID_ATTACHEDFILE', 0x21A7); // [61][A7] -- An attached file. +define('EBML_ID_CONTENTENCODING', 0x2240); // [62][40] -- Settings for one content encoding like compression or encryption. +define('EBML_ID_BITDEPTH', 0x2264); // [62][64] -- Bits per sample, mostly used for PCM. +define('EBML_ID_CODECPRIVATE', 0x23A2); // [63][A2] -- Private data only known to the codec. +define('EBML_ID_TARGETS', 0x23C0); // [63][C0] -- Contain all UIDs where the specified meta data apply. It is void to describe everything in the segment. +define('EBML_ID_CHAPTERPHYSICALEQUIV', 0x23C3); // [63][C3] -- Specify the physical equivalent of this ChapterAtom like "DVD" (60) or "SIDE" (50), see complete list of values. +define('EBML_ID_TAGCHAPTERUID', 0x23C4); // [63][C4] -- A unique ID to identify the Chapter(s) the tags belong to. If the value is 0 at this level, the tags apply to all chapters in the Segment. +define('EBML_ID_TAGTRACKUID', 0x23C5); // [63][C5] -- A unique ID to identify the Track(s) the tags belong to. If the value is 0 at this level, the tags apply to all tracks in the Segment. +define('EBML_ID_TAGATTACHMENTUID', 0x23C6); // [63][C6] -- A unique ID to identify the Attachment(s) the tags belong to. If the value is 0 at this level, the tags apply to all the attachments in the Segment. +define('EBML_ID_TAGEDITIONUID', 0x23C9); // [63][C9] -- A unique ID to identify the EditionEntry(s) the tags belong to. If the value is 0 at this level, the tags apply to all editions in the Segment. +define('EBML_ID_TARGETTYPE', 0x23CA); // [63][CA] -- An informational string that can be used to display the logical level of the target like "ALBUM", "TRACK", "MOVIE", "CHAPTER", etc (see TargetType). +define('EBML_ID_TRACKTRANSLATE', 0x2624); // [66][24] -- The track identification for the given Chapter Codec. +define('EBML_ID_TRACKTRANSLATETRACKID', 0x26A5); // [66][A5] -- The binary value used to represent this track in the chapter codec data. The format depends on the ChapProcessCodecID used. +define('EBML_ID_TRACKTRANSLATECODEC', 0x26BF); // [66][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu). +define('EBML_ID_TRACKTRANSLATEEDITIONUID', 0x26FC); // [66][FC] -- Specify an edition UID on which this translation applies. When not specified, it means for all editions found in the segment. +define('EBML_ID_SIMPLETAG', 0x27C8); // [67][C8] -- Contains general information about the target. +define('EBML_ID_TARGETTYPEVALUE', 0x28CA); // [68][CA] -- A number to indicate the logical level of the target (see TargetType). +define('EBML_ID_CHAPPROCESSCOMMAND', 0x2911); // [69][11] -- Contains all the commands associated to the Atom. +define('EBML_ID_CHAPPROCESSTIME', 0x2922); // [69][22] -- Defines when the process command should be handled (0: during the whole chapter, 1: before starting playback, 2: after playback of the chapter). +define('EBML_ID_CHAPTERTRANSLATE', 0x2924); // [69][24] -- A tuple of corresponding ID used by chapter codecs to represent this segment. +define('EBML_ID_CHAPPROCESSDATA', 0x2933); // [69][33] -- Contains the command information. The data should be interpreted depending on the ChapProcessCodecID value. For ChapProcessCodecID = 1, the data correspond to the binary DVD cell pre/post commands. +define('EBML_ID_CHAPPROCESS', 0x2944); // [69][44] -- Contains all the commands associated to the Atom. +define('EBML_ID_CHAPPROCESSCODECID', 0x2955); // [69][55] -- Contains the type of the codec used for the processing. A value of 0 means native Matroska processing (to be defined), a value of 1 means the DVD command set is used. More codec IDs can be added later. +define('EBML_ID_CHAPTERTRANSLATEID', 0x29A5); // [69][A5] -- The binary value used to represent this segment in the chapter codec data. The format depends on the ChapProcessCodecID used. +define('EBML_ID_CHAPTERTRANSLATECODEC', 0x29BF); // [69][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu). +define('EBML_ID_CHAPTERTRANSLATEEDITIONUID', 0x29FC); // [69][FC] -- Specify an edition UID on which this correspondance applies. When not specified, it means for all editions found in the segment. +define('EBML_ID_CONTENTENCODINGS', 0x2D80); // [6D][80] -- Settings for several content encoding mechanisms like compression or encryption. +define('EBML_ID_MINCACHE', 0x2DE7); // [6D][E7] -- The minimum number of frames a player should be able to cache during playback. If set to 0, the reference pseudo-cache system is not used. +define('EBML_ID_MAXCACHE', 0x2DF8); // [6D][F8] -- The maximum cache size required to store referenced frames in and the current frame. 0 means no cache is needed. +define('EBML_ID_CHAPTERSEGMENTUID', 0x2E67); // [6E][67] -- A segment to play in place of this chapter. Edition ChapterSegmentEditionUID should be used for this segment, otherwise no edition is used. +define('EBML_ID_CHAPTERSEGMENTEDITIONUID', 0x2EBC); // [6E][BC] -- The edition to play from the segment linked in ChapterSegmentUID. +define('EBML_ID_TRACKOVERLAY', 0x2FAB); // [6F][AB] -- Specify that this track is an overlay track for the Track specified (in the u-integer). That means when this track has a gap (see SilentTracks) the overlay track should be used instead. The order of multiple TrackOverlay matters, the first one is the one that should be used. If not found it should be the second, etc. +define('EBML_ID_TAG', 0x3373); // [73][73] -- Element containing elements specific to Tracks/Chapters. +define('EBML_ID_SEGMENTFILENAME', 0x3384); // [73][84] -- A filename corresponding to this segment. +define('EBML_ID_SEGMENTUID', 0x33A4); // [73][A4] -- A randomly generated unique ID to identify the current segment between many others (128 bits). +define('EBML_ID_CHAPTERUID', 0x33C4); // [73][C4] -- A unique ID to identify the Chapter. +define('EBML_ID_TRACKUID', 0x33C5); // [73][C5] -- A unique ID to identify the Track. This should be kept the same when making a direct stream copy of the Track to another file. +define('EBML_ID_ATTACHMENTLINK', 0x3446); // [74][46] -- The UID of an attachment that is used by this codec. +define('EBML_ID_CLUSTERBLOCKADDITIONS', 0x35A1); // [75][A1] -- Contain additional blocks to complete the main one. An EBML parser that has no knowledge of the Block structure could still see and use/skip these data. +define('EBML_ID_CHANNELPOSITIONS', 0x347B); // [7D][7B] -- Table of horizontal angles for each successive channel, see appendix. +define('EBML_ID_OUTPUTSAMPLINGFREQUENCY', 0x38B5); // [78][B5] -- Real output sampling frequency in Hz (used for SBR techniques). +define('EBML_ID_TITLE', 0x3BA9); // [7B][A9] -- General name of the segment. +define('EBML_ID_CHAPTERDISPLAY', 0x00); // [80] -- Contains all possible strings to use for the chapter display. +define('EBML_ID_TRACKTYPE', 0x03); // [83] -- A set of track types coded on 8 bits (1: video, 2: audio, 3: complex, 0x10: logo, 0x11: subtitle, 0x12: buttons, 0x20: control). +define('EBML_ID_CHAPSTRING', 0x05); // [85] -- Contains the string to use as the chapter atom. +define('EBML_ID_CODECID', 0x06); // [86] -- An ID corresponding to the codec, see the codec page for more info. +define('EBML_ID_FLAGDEFAULT', 0x08); // [88] -- Set if that track (audio, video or subs) SHOULD be used if no language found matches the user preference. +define('EBML_ID_CHAPTERTRACKNUMBER', 0x09); // [89] -- UID of the Track to apply this chapter too. In the absense of a control track, choosing this chapter will select the listed Tracks and deselect unlisted tracks. Absense of this element indicates that the Chapter should be applied to any currently used Tracks. +define('EBML_ID_CLUSTERSLICES', 0x0E); // [8E] -- Contains slices description. +define('EBML_ID_CHAPTERTRACK', 0x0F); // [8F] -- List of tracks on which the chapter applies. If this element is not present, all tracks apply +define('EBML_ID_CHAPTERTIMESTART', 0x11); // [91] -- Timecode of the start of Chapter (not scaled). +define('EBML_ID_CHAPTERTIMEEND', 0x12); // [92] -- Timecode of the end of Chapter (timecode excluded, not scaled). +define('EBML_ID_CUEREFTIME', 0x16); // [96] -- Timecode of the referenced Block. +define('EBML_ID_CUEREFCLUSTER', 0x17); // [97] -- Position of the Cluster containing the referenced Block. +define('EBML_ID_CHAPTERFLAGHIDDEN', 0x18); // [98] -- If a chapter is hidden (1), it should not be available to the user interface (but still to Control Tracks). +define('EBML_ID_FLAGINTERLACED', 0x1A); // [9A] -- Set if the video is interlaced. +define('EBML_ID_CLUSTERBLOCKDURATION', 0x1B); // [9B] -- The duration of the Block (based on TimecodeScale). This element is mandatory when DefaultDuration is set for the track. When not written and with no DefaultDuration, the value is assumed to be the difference between the timecode of this Block and the timecode of the next Block in "display" order (not coding order). This element can be useful at the end of a Track (as there is not other Block available), or when there is a break in a track like for subtitle tracks. +define('EBML_ID_FLAGLACING', 0x1C); // [9C] -- Set if the track may contain blocks using lacing. +define('EBML_ID_CHANNELS', 0x1F); // [9F] -- Numbers of channels in the track. +define('EBML_ID_CLUSTERBLOCKGROUP', 0x20); // [A0] -- Basic container of information containing a single Block or BlockVirtual, and information specific to that Block/VirtualBlock. +define('EBML_ID_CLUSTERBLOCK', 0x21); // [A1] -- Block containing the actual data to be rendered and a timecode relative to the Cluster Timecode. +define('EBML_ID_CLUSTERBLOCKVIRTUAL', 0x22); // [A2] -- A Block with no data. It must be stored in the stream at the place the real Block should be in display order. +define('EBML_ID_CLUSTERSIMPLEBLOCK', 0x23); // [A3] -- Similar to Block but without all the extra information, mostly used to reduced overhead when no extra feature is needed. +define('EBML_ID_CLUSTERCODECSTATE', 0x24); // [A4] -- The new codec state to use. Data interpretation is private to the codec. This information should always be referenced by a seek entry. +define('EBML_ID_CLUSTERBLOCKADDITIONAL', 0x25); // [A5] -- Interpreted by the codec as it wishes (using the BlockAddID). +define('EBML_ID_CLUSTERBLOCKMORE', 0x26); // [A6] -- Contain the BlockAdditional and some parameters. +define('EBML_ID_CLUSTERPOSITION', 0x27); // [A7] -- Position of the Cluster in the segment (0 in live broadcast streams). It might help to resynchronise offset on damaged streams. +define('EBML_ID_CODECDECODEALL', 0x2A); // [AA] -- The codec can decode potentially damaged data. +define('EBML_ID_CLUSTERPREVSIZE', 0x2B); // [AB] -- Size of the previous Cluster, in octets. Can be useful for backward playing. +define('EBML_ID_TRACKENTRY', 0x2E); // [AE] -- Describes a track with all elements. +define('EBML_ID_CLUSTERENCRYPTEDBLOCK', 0x2F); // [AF] -- Similar to SimpleBlock but the data inside the Block are Transformed (encrypt and/or signed). +define('EBML_ID_PIXELWIDTH', 0x30); // [B0] -- Width of the encoded video frames in pixels. +define('EBML_ID_CUETIME', 0x33); // [B3] -- Absolute timecode according to the segment time base. +define('EBML_ID_SAMPLINGFREQUENCY', 0x35); // [B5] -- Sampling frequency in Hz. +define('EBML_ID_CHAPTERATOM', 0x36); // [B6] -- Contains the atom information to use as the chapter atom (apply to all tracks). +define('EBML_ID_CUETRACKPOSITIONS', 0x37); // [B7] -- Contain positions for different tracks corresponding to the timecode. +define('EBML_ID_FLAGENABLED', 0x39); // [B9] -- Set if the track is used. +define('EBML_ID_PIXELHEIGHT', 0x3A); // [BA] -- Height of the encoded video frames in pixels. +define('EBML_ID_CUEPOINT', 0x3B); // [BB] -- Contains all information relative to a seek point in the segment. +define('EBML_ID_CRC32', 0x3F); // [BF] -- The CRC is computed on all the data of the Master element it's in, regardless of its position. It's recommended to put the CRC value at the beggining of the Master element for easier reading. All level 1 elements should include a CRC-32. +define('EBML_ID_CLUSTERBLOCKADDITIONID', 0x4B); // [CB] -- The ID of the BlockAdditional element (0 is the main Block). +define('EBML_ID_CLUSTERLACENUMBER', 0x4C); // [CC] -- The reverse number of the frame in the lace (0 is the last frame, 1 is the next to last, etc). While there are a few files in the wild with this element, it is no longer in use and has been deprecated. Being able to interpret this element is not required for playback. +define('EBML_ID_CLUSTERFRAMENUMBER', 0x4D); // [CD] -- The number of the frame to generate from this lace with this delay (allow you to generate many frames from the same Block/Frame). +define('EBML_ID_CLUSTERDELAY', 0x4E); // [CE] -- The (scaled) delay to apply to the element. +define('EBML_ID_CLUSTERDURATION', 0x4F); // [CF] -- The (scaled) duration to apply to the element. +define('EBML_ID_TRACKNUMBER', 0x57); // [D7] -- The track number as used in the Block Header (using more than 127 tracks is not encouraged, though the design allows an unlimited number). +define('EBML_ID_CUEREFERENCE', 0x5B); // [DB] -- The Clusters containing the required referenced Blocks. +define('EBML_ID_VIDEO', 0x60); // [E0] -- Video settings. +define('EBML_ID_AUDIO', 0x61); // [E1] -- Audio settings. +define('EBML_ID_CLUSTERTIMESLICE', 0x68); // [E8] -- Contains extra time information about the data contained in the Block. While there are a few files in the wild with this element, it is no longer in use and has been deprecated. Being able to interpret this element is not required for playback. +define('EBML_ID_CUECODECSTATE', 0x6A); // [EA] -- The position of the Codec State corresponding to this Cue element. 0 means that the data is taken from the initial Track Entry. +define('EBML_ID_CUEREFCODECSTATE', 0x6B); // [EB] -- The position of the Codec State corresponding to this referenced element. 0 means that the data is taken from the initial Track Entry. +define('EBML_ID_VOID', 0x6C); // [EC] -- Used to void damaged data, to avoid unexpected behaviors when using damaged data. The content is discarded. Also used to reserve space in a sub-element for later use. +define('EBML_ID_CLUSTERTIMECODE', 0x67); // [E7] -- Absolute timecode of the cluster (based on TimecodeScale). +define('EBML_ID_CLUSTERBLOCKADDID', 0x6E); // [EE] -- An ID to identify the BlockAdditional level. +define('EBML_ID_CUECLUSTERPOSITION', 0x71); // [F1] -- The position of the Cluster containing the required Block. +define('EBML_ID_CUETRACK', 0x77); // [F7] -- The track for which a position is given. +define('EBML_ID_CLUSTERREFERENCEPRIORITY', 0x7A); // [FA] -- This frame is referenced and has the specified cache priority. In cache only a frame of the same or higher priority can replace this frame. A value of 0 means the frame is not referenced. +define('EBML_ID_CLUSTERREFERENCEBLOCK', 0x7B); // [FB] -- Timecode of another frame used as a reference (ie: B or P frame). The timecode is relative to the block it's attached to. +define('EBML_ID_CLUSTERREFERENCEVIRTUAL', 0x7D); // [FD] -- Relative position of the data that should be in position of the virtual block. /** -* @tutorial http://www.matroska.org/technical/specs/index.html -* -* @todo Rewrite EBML parser to reduce it's size and honor default element values -* @todo After rewrite implement stream size calculation, that will provide additional useful info and enable AAC/FLAC audio bitrate detection -*/ + * @tutorial http://www.matroska.org/technical/specs/index.html + * + * @todo Rewrite EBML parser to reduce it's size and honor default element values + * @todo After rewrite implement stream size calculation, that will provide additional useful info and enable AAC/FLAC audio bitrate detection + */ class getid3_matroska extends getid3_handler { - // public options - public static $hide_clusters = true; // if true, do not return information about CLUSTER chunks, since there's a lot of them and they're not usually useful [default: TRUE] - public static $parse_whole_file = false; // true to parse the whole file, not only header [default: FALSE] - - // private parser settings/placeholders - private $EBMLbuffer = ''; - private $EBMLbuffer_offset = 0; - private $EBMLbuffer_length = 0; - private $current_offset = 0; - private $unuseful_elements = array(EBML_ID_CRC32, EBML_ID_VOID); - - public function Analyze() - { - $info = &$this->getid3->info; - - // parse container - try { - $this->parseEBML($info); - } catch (Exception $e) { - $this->error('EBML parser: '.$e->getMessage()); - } - - // calculate playtime - if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) { - foreach ($info['matroska']['info'] as $key => $infoarray) { - if (isset($infoarray['Duration'])) { - // TimecodeScale is how many nanoseconds each Duration unit is - $info['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000); - break; - } - } - } - - // extract tags - if (isset($info['matroska']['tags']) && is_array($info['matroska']['tags'])) { - foreach ($info['matroska']['tags'] as $key => $infoarray) { - $this->ExtractCommentsSimpleTag($infoarray); - } - } - - // process tracks - if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) { - foreach ($info['matroska']['tracks']['tracks'] as $key => $trackarray) { - - $track_info = array(); - $track_info['dataformat'] = self::CodecIDtoCommonName($trackarray['CodecID']); - $track_info['default'] = (isset($trackarray['FlagDefault']) ? $trackarray['FlagDefault'] : true); - if (isset($trackarray['Name'])) { $track_info['name'] = $trackarray['Name']; } - - switch ($trackarray['TrackType']) { - - case 1: // Video - $track_info['resolution_x'] = $trackarray['PixelWidth']; - $track_info['resolution_y'] = $trackarray['PixelHeight']; - $track_info['display_unit'] = self::displayUnit(isset($trackarray['DisplayUnit']) ? $trackarray['DisplayUnit'] : 0); - $track_info['display_x'] = (isset($trackarray['DisplayWidth']) ? $trackarray['DisplayWidth'] : $trackarray['PixelWidth']); - $track_info['display_y'] = (isset($trackarray['DisplayHeight']) ? $trackarray['DisplayHeight'] : $trackarray['PixelHeight']); - - if (isset($trackarray['PixelCropBottom'])) { $track_info['crop_bottom'] = $trackarray['PixelCropBottom']; } - if (isset($trackarray['PixelCropTop'])) { $track_info['crop_top'] = $trackarray['PixelCropTop']; } - if (isset($trackarray['PixelCropLeft'])) { $track_info['crop_left'] = $trackarray['PixelCropLeft']; } - if (isset($trackarray['PixelCropRight'])) { $track_info['crop_right'] = $trackarray['PixelCropRight']; } - if (isset($trackarray['DefaultDuration'])) { $track_info['frame_rate'] = round(1000000000 / $trackarray['DefaultDuration'], 3); } - if (isset($trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; } - - switch ($trackarray['CodecID']) { - case 'V_MS/VFW/FOURCC': - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); - - $parsed = getid3_riff::ParseBITMAPINFOHEADER($trackarray['CodecPrivate']); - $track_info['codec'] = getid3_riff::fourccLookup($parsed['fourcc']); - $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed; - break; - - /*case 'V_MPEG4/ISO/AVC': - $h264['profile'] = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 1, 1)); - $h264['level'] = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 3, 1)); - $rn = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 4, 1)); - $h264['NALUlength'] = ($rn & 3) + 1; - $rn = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 5, 1)); - $nsps = ($rn & 31); - $offset = 6; - for ($i = 0; $i < $nsps; $i ++) { - $length = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 2)); - $h264['SPS'][] = substr($trackarray['CodecPrivate'], $offset + 2, $length); - $offset += 2 + $length; - } - $npps = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 1)); - $offset += 1; - for ($i = 0; $i < $npps; $i ++) { - $length = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 2)); - $h264['PPS'][] = substr($trackarray['CodecPrivate'], $offset + 2, $length); - $offset += 2 + $length; - } - $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $h264; - break;*/ - } - - $info['video']['streams'][] = $track_info; - break; - - case 2: // Audio - $track_info['sample_rate'] = (isset($trackarray['SamplingFrequency']) ? $trackarray['SamplingFrequency'] : 8000.0); - $track_info['channels'] = (isset($trackarray['Channels']) ? $trackarray['Channels'] : 1); - $track_info['language'] = (isset($trackarray['Language']) ? $trackarray['Language'] : 'eng'); - if (isset($trackarray['BitDepth'])) { $track_info['bits_per_sample'] = $trackarray['BitDepth']; } - if (isset($trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; } - - switch ($trackarray['CodecID']) { - case 'A_PCM/INT/LIT': - case 'A_PCM/INT/BIG': - $track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth']; - break; - - case 'A_AC3': - case 'A_EAC3': - case 'A_DTS': - case 'A_MPEG/L3': - case 'A_MPEG/L2': - case 'A_FLAC': - $module_dataformat = ($track_info['dataformat'] == 'mp2' ? 'mp3' : ($track_info['dataformat'] == 'eac3' ? 'ac3' : $track_info['dataformat'])); - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.'.$module_dataformat.'.php', __FILE__, true); - - if (!isset($info['matroska']['track_data_offsets'][$trackarray['TrackNumber']])) { - $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because $info[matroska][track_data_offsets]['.$trackarray['TrackNumber'].'] not set'); - break; - } - - // create temp instance - $getid3_temp = new getID3(); - if ($track_info['dataformat'] != 'flac') { - $getid3_temp->openfile($this->getid3->filename); - } - $getid3_temp->info['avdataoffset'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset']; - if ($track_info['dataformat'][0] == 'm' || $track_info['dataformat'] == 'flac') { - $getid3_temp->info['avdataend'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'] + $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['length']; - } - - // analyze - $class = 'getid3_'.$module_dataformat; - $header_data_key = $track_info['dataformat'][0] == 'm' ? 'mpeg' : $track_info['dataformat']; - $getid3_audio = new $class($getid3_temp, __CLASS__); - if ($track_info['dataformat'] == 'flac') { - $getid3_audio->AnalyzeString($trackarray['CodecPrivate']); - } - else { - $getid3_audio->Analyze(); - } - if (!empty($getid3_temp->info[$header_data_key])) { - $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info[$header_data_key]; - if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) { - foreach ($getid3_temp->info['audio'] as $key => $value) { - $track_info[$key] = $value; - } - } - } - else { - $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because '.$class.'::Analyze() failed at offset '.$getid3_temp->info['avdataoffset']); - } - - // copy errors and warnings - if (!empty($getid3_temp->info['error'])) { - foreach ($getid3_temp->info['error'] as $newerror) { - $this->warning($class.'() says: ['.$newerror.']'); - } - } - if (!empty($getid3_temp->info['warning'])) { - foreach ($getid3_temp->info['warning'] as $newerror) { - $this->warning($class.'() says: ['.$newerror.']'); - } - } - unset($getid3_temp, $getid3_audio); - break; - - case 'A_AAC': - case 'A_AAC/MPEG2/LC': - case 'A_AAC/MPEG2/LC/SBR': - case 'A_AAC/MPEG4/LC': - case 'A_AAC/MPEG4/LC/SBR': - $this->warning($trackarray['CodecID'].' audio data contains no header, audio/video bitrates can\'t be calculated'); - break; - - case 'A_VORBIS': - if (!isset($trackarray['CodecPrivate'])) { - $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data not set'); - break; - } - $vorbis_offset = strpos($trackarray['CodecPrivate'], 'vorbis', 1); - if ($vorbis_offset === false) { - $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data does not contain "vorbis" keyword'); - break; - } - $vorbis_offset -= 1; - - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, true); - - // create temp instance - $getid3_temp = new getID3(); - - // analyze - $getid3_ogg = new getid3_ogg($getid3_temp); - $oggpageinfo['page_seqno'] = 0; - $getid3_ogg->ParseVorbisPageHeader($trackarray['CodecPrivate'], $vorbis_offset, $oggpageinfo); - if (!empty($getid3_temp->info['ogg'])) { - $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info['ogg']; - if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) { - foreach ($getid3_temp->info['audio'] as $key => $value) { - $track_info[$key] = $value; - } - } - } - - // copy errors and warnings - if (!empty($getid3_temp->info['error'])) { - foreach ($getid3_temp->info['error'] as $newerror) { - $this->warning('getid3_ogg() says: ['.$newerror.']'); - } - } - if (!empty($getid3_temp->info['warning'])) { - foreach ($getid3_temp->info['warning'] as $newerror) { - $this->warning('getid3_ogg() says: ['.$newerror.']'); - } - } - - if (!empty($getid3_temp->info['ogg']['bitrate_nominal'])) { - $track_info['bitrate'] = $getid3_temp->info['ogg']['bitrate_nominal']; - } - unset($getid3_temp, $getid3_ogg, $oggpageinfo, $vorbis_offset); - break; - - case 'A_MS/ACM': - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); - - $parsed = getid3_riff::parseWAVEFORMATex($trackarray['CodecPrivate']); - foreach ($parsed as $key => $value) { - if ($key != 'raw') { - $track_info[$key] = $value; - } - } - $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed; - break; - - default: - $this->warning('Unhandled audio type "'.(isset($trackarray['CodecID']) ? $trackarray['CodecID'] : '').'"'); - break; - } - - $info['audio']['streams'][] = $track_info; - break; - } - } - - if (!empty($info['video']['streams'])) { - $info['video'] = self::getDefaultStreamInfo($info['video']['streams']); - } - if (!empty($info['audio']['streams'])) { - $info['audio'] = self::getDefaultStreamInfo($info['audio']['streams']); - } - } - - // process attachments - if (isset($info['matroska']['attachments']) && $this->getid3->option_save_attachments !== getID3::ATTACHMENTS_NONE) { - foreach ($info['matroska']['attachments'] as $i => $entry) { - if (strpos($entry['FileMimeType'], 'image/') === 0 && !empty($entry['FileData'])) { - $info['matroska']['comments']['picture'][] = array('data' => $entry['FileData'], 'image_mime' => $entry['FileMimeType'], 'filename' => $entry['FileName']); - } - } - } - - // determine mime type - if (!empty($info['video']['streams'])) { - $info['mime_type'] = ($info['matroska']['doctype'] == 'webm' ? 'video/webm' : 'video/x-matroska'); - } elseif (!empty($info['audio']['streams'])) { - $info['mime_type'] = ($info['matroska']['doctype'] == 'webm' ? 'audio/webm' : 'audio/x-matroska'); - } elseif (isset($info['mime_type'])) { - unset($info['mime_type']); - } - - return true; - } - - private function parseEBML(&$info) { - // http://www.matroska.org/technical/specs/index.html#EBMLBasics - $this->current_offset = $info['avdataoffset']; - - while ($this->getEBMLelement($top_element, $info['avdataend'])) { - switch ($top_element['id']) { - - case EBML_ID_EBML: - $info['matroska']['header']['offset'] = $top_element['offset']; - $info['matroska']['header']['length'] = $top_element['length']; - - while ($this->getEBMLelement($element_data, $top_element['end'], true)) { - switch ($element_data['id']) { - - case EBML_ID_EBMLVERSION: - case EBML_ID_EBMLREADVERSION: - case EBML_ID_EBMLMAXIDLENGTH: - case EBML_ID_EBMLMAXSIZELENGTH: - case EBML_ID_DOCTYPEVERSION: - case EBML_ID_DOCTYPEREADVERSION: - $element_data['data'] = getid3_lib::BigEndian2Int($element_data['data']); - break; - - case EBML_ID_DOCTYPE: - $element_data['data'] = getid3_lib::trimNullByte($element_data['data']); - $info['matroska']['doctype'] = $element_data['data']; - $info['fileformat'] = $element_data['data']; - break; - - default: - $this->unhandledElement('header', __LINE__, $element_data); - break; - } - - unset($element_data['offset'], $element_data['end']); - $info['matroska']['header']['elements'][] = $element_data; - } - break; - - case EBML_ID_SEGMENT: - $info['matroska']['segment'][0]['offset'] = $top_element['offset']; - $info['matroska']['segment'][0]['length'] = $top_element['length']; - - while ($this->getEBMLelement($element_data, $top_element['end'])) { - if ($element_data['id'] != EBML_ID_CLUSTER || !self::$hide_clusters) { // collect clusters only if required - $info['matroska']['segments'][] = $element_data; - } - switch ($element_data['id']) { - - case EBML_ID_SEEKHEAD: // Contains the position of other level 1 elements. - - while ($this->getEBMLelement($seek_entry, $element_data['end'])) { - switch ($seek_entry['id']) { - - case EBML_ID_SEEK: // Contains a single seek entry to an EBML element - while ($this->getEBMLelement($sub_seek_entry, $seek_entry['end'], true)) { - - switch ($sub_seek_entry['id']) { - - case EBML_ID_SEEKID: - $seek_entry['target_id'] = self::EBML2Int($sub_seek_entry['data']); - $seek_entry['target_name'] = self::EBMLidName($seek_entry['target_id']); - break; - - case EBML_ID_SEEKPOSITION: - $seek_entry['target_offset'] = $element_data['offset'] + getid3_lib::BigEndian2Int($sub_seek_entry['data']); - break; - - default: - $this->unhandledElement('seekhead.seek', __LINE__, $sub_seek_entry); } - break; - } - if (!isset($seek_entry['target_id'])) { - $this->warning('seek_entry[target_id] unexpectedly not set at '.$seek_entry['offset']); - break; - } - if (($seek_entry['target_id'] != EBML_ID_CLUSTER) || !self::$hide_clusters) { // collect clusters only if required - $info['matroska']['seek'][] = $seek_entry; - } - break; - - default: - $this->unhandledElement('seekhead', __LINE__, $seek_entry); - break; - } - } - break; - - case EBML_ID_TRACKS: // A top-level block of information with many tracks described. - $info['matroska']['tracks'] = $element_data; - - while ($this->getEBMLelement($track_entry, $element_data['end'])) { - switch ($track_entry['id']) { - - case EBML_ID_TRACKENTRY: //subelements: Describes a track with all elements. - - while ($this->getEBMLelement($subelement, $track_entry['end'], array(EBML_ID_VIDEO, EBML_ID_AUDIO, EBML_ID_CONTENTENCODINGS, EBML_ID_CODECPRIVATE))) { - switch ($subelement['id']) { - - case EBML_ID_TRACKNUMBER: - case EBML_ID_TRACKUID: - case EBML_ID_TRACKTYPE: - case EBML_ID_MINCACHE: - case EBML_ID_MAXCACHE: - case EBML_ID_MAXBLOCKADDITIONID: - case EBML_ID_DEFAULTDURATION: // nanoseconds per frame - $track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); - break; - - case EBML_ID_TRACKTIMECODESCALE: - $track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']); - break; - - case EBML_ID_CODECID: - case EBML_ID_LANGUAGE: - case EBML_ID_NAME: - case EBML_ID_CODECNAME: - $track_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']); - break; - - case EBML_ID_CODECPRIVATE: - $track_entry[$subelement['id_name']] = $this->readEBMLelementData($subelement['length'], true); - break; - - case EBML_ID_FLAGENABLED: - case EBML_ID_FLAGDEFAULT: - case EBML_ID_FLAGFORCED: - case EBML_ID_FLAGLACING: - case EBML_ID_CODECDECODEALL: - $track_entry[$subelement['id_name']] = (bool) getid3_lib::BigEndian2Int($subelement['data']); - break; - - case EBML_ID_VIDEO: - - while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { - switch ($sub_subelement['id']) { - - case EBML_ID_PIXELWIDTH: - case EBML_ID_PIXELHEIGHT: - case EBML_ID_PIXELCROPBOTTOM: - case EBML_ID_PIXELCROPTOP: - case EBML_ID_PIXELCROPLEFT: - case EBML_ID_PIXELCROPRIGHT: - case EBML_ID_DISPLAYWIDTH: - case EBML_ID_DISPLAYHEIGHT: - case EBML_ID_DISPLAYUNIT: - case EBML_ID_ASPECTRATIOTYPE: - case EBML_ID_STEREOMODE: - case EBML_ID_OLDSTEREOMODE: - $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); - break; - - case EBML_ID_FLAGINTERLACED: - $track_entry[$sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_subelement['data']); - break; - - case EBML_ID_GAMMAVALUE: - $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']); - break; - - case EBML_ID_COLOURSPACE: - $track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); - break; - - default: - $this->unhandledElement('track.video', __LINE__, $sub_subelement); - break; - } - } - break; - - case EBML_ID_AUDIO: - - while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { - switch ($sub_subelement['id']) { - - case EBML_ID_CHANNELS: - case EBML_ID_BITDEPTH: - $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); - break; - - case EBML_ID_SAMPLINGFREQUENCY: - case EBML_ID_OUTPUTSAMPLINGFREQUENCY: - $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']); - break; - - case EBML_ID_CHANNELPOSITIONS: - $track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); - break; - - default: - $this->unhandledElement('track.audio', __LINE__, $sub_subelement); - break; - } - } - break; - - case EBML_ID_CONTENTENCODINGS: - - while ($this->getEBMLelement($sub_subelement, $subelement['end'])) { - switch ($sub_subelement['id']) { - - case EBML_ID_CONTENTENCODING: - - while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], array(EBML_ID_CONTENTCOMPRESSION, EBML_ID_CONTENTENCRYPTION))) { - switch ($sub_sub_subelement['id']) { - - case EBML_ID_CONTENTENCODINGORDER: - case EBML_ID_CONTENTENCODINGSCOPE: - case EBML_ID_CONTENTENCODINGTYPE: - $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); - break; - - case EBML_ID_CONTENTCOMPRESSION: - - while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { - switch ($sub_sub_sub_subelement['id']) { - - case EBML_ID_CONTENTCOMPALGO: - $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']); - break; - - case EBML_ID_CONTENTCOMPSETTINGS: - $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data']; - break; - - default: - $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement); - break; - } - } - break; - - case EBML_ID_CONTENTENCRYPTION: - - while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { - switch ($sub_sub_sub_subelement['id']) { - - case EBML_ID_CONTENTENCALGO: - case EBML_ID_CONTENTSIGALGO: - case EBML_ID_CONTENTSIGHASHALGO: - $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']); - break; - - case EBML_ID_CONTENTENCKEYID: - case EBML_ID_CONTENTSIGNATURE: - case EBML_ID_CONTENTSIGKEYID: - $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data']; - break; - - default: - $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement); - break; - } - } - break; - - default: - $this->unhandledElement('track.contentencodings.contentencoding', __LINE__, $sub_sub_subelement); - break; - } - } - break; - - default: - $this->unhandledElement('track.contentencodings', __LINE__, $sub_subelement); - break; - } - } - break; - - default: - $this->unhandledElement('track', __LINE__, $subelement); - break; - } - } - - $info['matroska']['tracks']['tracks'][] = $track_entry; - break; - - default: - $this->unhandledElement('tracks', __LINE__, $track_entry); - break; - } - } - break; - - case EBML_ID_INFO: // Contains miscellaneous general information and statistics on the file. - $info_entry = array(); - - while ($this->getEBMLelement($subelement, $element_data['end'], true)) { - switch ($subelement['id']) { - - case EBML_ID_TIMECODESCALE: - $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); - break; - - case EBML_ID_DURATION: - $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']); - break; - - case EBML_ID_DATEUTC: - $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); - $info_entry[$subelement['id_name'].'_unix'] = self::EBMLdate2unix($info_entry[$subelement['id_name']]); - break; - - case EBML_ID_SEGMENTUID: - case EBML_ID_PREVUID: - case EBML_ID_NEXTUID: - $info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']); - break; - - case EBML_ID_SEGMENTFAMILY: - $info_entry[$subelement['id_name']][] = getid3_lib::trimNullByte($subelement['data']); - break; - - case EBML_ID_SEGMENTFILENAME: - case EBML_ID_PREVFILENAME: - case EBML_ID_NEXTFILENAME: - case EBML_ID_TITLE: - case EBML_ID_MUXINGAPP: - case EBML_ID_WRITINGAPP: - $info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']); - $info['matroska']['comments'][strtolower($subelement['id_name'])][] = $info_entry[$subelement['id_name']]; - break; - - case EBML_ID_CHAPTERTRANSLATE: - $chaptertranslate_entry = array(); - - while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { - switch ($sub_subelement['id']) { - - case EBML_ID_CHAPTERTRANSLATEEDITIONUID: - $chaptertranslate_entry[$sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_subelement['data']); - break; - - case EBML_ID_CHAPTERTRANSLATECODEC: - $chaptertranslate_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); - break; - - case EBML_ID_CHAPTERTRANSLATEID: - $chaptertranslate_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); - break; - - default: - $this->unhandledElement('info.chaptertranslate', __LINE__, $sub_subelement); - break; - } - } - $info_entry[$subelement['id_name']] = $chaptertranslate_entry; - break; - - default: - $this->unhandledElement('info', __LINE__, $subelement); - break; - } - } - $info['matroska']['info'][] = $info_entry; - break; - - case EBML_ID_CUES: // A top-level element to speed seeking access. All entries are local to the segment. Should be mandatory for non "live" streams. - if (self::$hide_clusters) { // do not parse cues if hide clusters is "ON" till they point to clusters anyway - $this->current_offset = $element_data['end']; - break; - } - $cues_entry = array(); - - while ($this->getEBMLelement($subelement, $element_data['end'])) { - switch ($subelement['id']) { - - case EBML_ID_CUEPOINT: - $cuepoint_entry = array(); - - while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CUETRACKPOSITIONS))) { - switch ($sub_subelement['id']) { - - case EBML_ID_CUETRACKPOSITIONS: - $cuetrackpositions_entry = array(); - - while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) { - switch ($sub_sub_subelement['id']) { - - case EBML_ID_CUETRACK: - case EBML_ID_CUECLUSTERPOSITION: - case EBML_ID_CUEBLOCKNUMBER: - case EBML_ID_CUECODECSTATE: - $cuetrackpositions_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); - break; - - default: - $this->unhandledElement('cues.cuepoint.cuetrackpositions', __LINE__, $sub_sub_subelement); - break; - } - } - $cuepoint_entry[$sub_subelement['id_name']][] = $cuetrackpositions_entry; - break; - - case EBML_ID_CUETIME: - $cuepoint_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); - break; - - default: - $this->unhandledElement('cues.cuepoint', __LINE__, $sub_subelement); - break; - } - } - $cues_entry[] = $cuepoint_entry; - break; - - default: - $this->unhandledElement('cues', __LINE__, $subelement); - break; - } - } - $info['matroska']['cues'] = $cues_entry; - break; - - case EBML_ID_TAGS: // Element containing elements specific to Tracks/Chapters. - $tags_entry = array(); - - while ($this->getEBMLelement($subelement, $element_data['end'], false)) { - switch ($subelement['id']) { - - case EBML_ID_TAG: - $tag_entry = array(); - - while ($this->getEBMLelement($sub_subelement, $subelement['end'], false)) { - switch ($sub_subelement['id']) { - - case EBML_ID_TARGETS: - $targets_entry = array(); - - while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) { - switch ($sub_sub_subelement['id']) { - - case EBML_ID_TARGETTYPEVALUE: - $targets_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); - $targets_entry[strtolower($sub_sub_subelement['id_name']).'_long'] = self::TargetTypeValue($targets_entry[$sub_sub_subelement['id_name']]); - break; - - case EBML_ID_TARGETTYPE: - $targets_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data']; - break; - - case EBML_ID_TAGTRACKUID: - case EBML_ID_TAGEDITIONUID: - case EBML_ID_TAGCHAPTERUID: - case EBML_ID_TAGATTACHMENTUID: - $targets_entry[$sub_sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); - break; - - default: - $this->unhandledElement('tags.tag.targets', __LINE__, $sub_sub_subelement); - break; - } - } - $tag_entry[$sub_subelement['id_name']] = $targets_entry; - break; - - case EBML_ID_SIMPLETAG: - $tag_entry[$sub_subelement['id_name']][] = $this->HandleEMBLSimpleTag($sub_subelement['end']); - break; - - default: - $this->unhandledElement('tags.tag', __LINE__, $sub_subelement); - break; - } - } - $tags_entry[] = $tag_entry; - break; - - default: - $this->unhandledElement('tags', __LINE__, $subelement); - break; - } - } - $info['matroska']['tags'] = $tags_entry; - break; - - case EBML_ID_ATTACHMENTS: // Contain attached files. - - while ($this->getEBMLelement($subelement, $element_data['end'])) { - switch ($subelement['id']) { - - case EBML_ID_ATTACHEDFILE: - $attachedfile_entry = array(); - - while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_FILEDATA))) { - switch ($sub_subelement['id']) { - - case EBML_ID_FILEDESCRIPTION: - case EBML_ID_FILENAME: - case EBML_ID_FILEMIMETYPE: - $attachedfile_entry[$sub_subelement['id_name']] = $sub_subelement['data']; - break; - - case EBML_ID_FILEDATA: - $attachedfile_entry['data_offset'] = $this->current_offset; - $attachedfile_entry['data_length'] = $sub_subelement['length']; - - $attachedfile_entry[$sub_subelement['id_name']] = $this->saveAttachment( - $attachedfile_entry['FileName'], - $attachedfile_entry['data_offset'], - $attachedfile_entry['data_length']); - - $this->current_offset = $sub_subelement['end']; - break; - - case EBML_ID_FILEUID: - $attachedfile_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); - break; - - default: - $this->unhandledElement('attachments.attachedfile', __LINE__, $sub_subelement); - break; - } - } - $info['matroska']['attachments'][] = $attachedfile_entry; - break; - - default: - $this->unhandledElement('attachments', __LINE__, $subelement); - break; - } - } - break; - - case EBML_ID_CHAPTERS: - - while ($this->getEBMLelement($subelement, $element_data['end'])) { - switch ($subelement['id']) { - - case EBML_ID_EDITIONENTRY: - $editionentry_entry = array(); - - while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CHAPTERATOM))) { - switch ($sub_subelement['id']) { - - case EBML_ID_EDITIONUID: - $editionentry_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); - break; - - case EBML_ID_EDITIONFLAGHIDDEN: - case EBML_ID_EDITIONFLAGDEFAULT: - case EBML_ID_EDITIONFLAGORDERED: - $editionentry_entry[$sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_subelement['data']); - break; - - case EBML_ID_CHAPTERATOM: - $chapteratom_entry = array(); - - while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], array(EBML_ID_CHAPTERTRACK, EBML_ID_CHAPTERDISPLAY))) { - switch ($sub_sub_subelement['id']) { - - case EBML_ID_CHAPTERSEGMENTUID: - case EBML_ID_CHAPTERSEGMENTEDITIONUID: - $chapteratom_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data']; - break; - - case EBML_ID_CHAPTERFLAGENABLED: - case EBML_ID_CHAPTERFLAGHIDDEN: - $chapteratom_entry[$sub_sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_sub_subelement['data']); - break; - - case EBML_ID_CHAPTERUID: - case EBML_ID_CHAPTERTIMESTART: - case EBML_ID_CHAPTERTIMEEND: - $chapteratom_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); - break; - - case EBML_ID_CHAPTERTRACK: - $chaptertrack_entry = array(); - - while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { - switch ($sub_sub_sub_subelement['id']) { - - case EBML_ID_CHAPTERTRACKNUMBER: - $chaptertrack_entry[$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']); - break; - - default: - $this->unhandledElement('chapters.editionentry.chapteratom.chaptertrack', __LINE__, $sub_sub_sub_subelement); - break; - } - } - $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chaptertrack_entry; - break; - - case EBML_ID_CHAPTERDISPLAY: - $chapterdisplay_entry = array(); - - while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { - switch ($sub_sub_sub_subelement['id']) { - - case EBML_ID_CHAPSTRING: - case EBML_ID_CHAPLANGUAGE: - case EBML_ID_CHAPCOUNTRY: - $chapterdisplay_entry[$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data']; - break; - - default: - $this->unhandledElement('chapters.editionentry.chapteratom.chapterdisplay', __LINE__, $sub_sub_sub_subelement); - break; - } - } - $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chapterdisplay_entry; - break; - - default: - $this->unhandledElement('chapters.editionentry.chapteratom', __LINE__, $sub_sub_subelement); - break; - } - } - $editionentry_entry[$sub_subelement['id_name']][] = $chapteratom_entry; - break; - - default: - $this->unhandledElement('chapters.editionentry', __LINE__, $sub_subelement); - break; - } - } - $info['matroska']['chapters'][] = $editionentry_entry; - break; - - default: - $this->unhandledElement('chapters', __LINE__, $subelement); - break; - } - } - break; - - case EBML_ID_CLUSTER: // The lower level element containing the (monolithic) Block structure. - $cluster_entry = array(); - - while ($this->getEBMLelement($subelement, $element_data['end'], array(EBML_ID_CLUSTERSILENTTRACKS, EBML_ID_CLUSTERBLOCKGROUP, EBML_ID_CLUSTERSIMPLEBLOCK))) { - switch ($subelement['id']) { - - case EBML_ID_CLUSTERTIMECODE: - case EBML_ID_CLUSTERPOSITION: - case EBML_ID_CLUSTERPREVSIZE: - $cluster_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); - break; - - case EBML_ID_CLUSTERSILENTTRACKS: - $cluster_silent_tracks = array(); - - while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { - switch ($sub_subelement['id']) { - - case EBML_ID_CLUSTERSILENTTRACKNUMBER: - $cluster_silent_tracks[] = getid3_lib::BigEndian2Int($sub_subelement['data']); - break; - - default: - $this->unhandledElement('cluster.silenttracks', __LINE__, $sub_subelement); - break; - } - } - $cluster_entry[$subelement['id_name']][] = $cluster_silent_tracks; - break; - - case EBML_ID_CLUSTERBLOCKGROUP: - $cluster_block_group = array('offset' => $this->current_offset); - - while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CLUSTERBLOCK))) { - switch ($sub_subelement['id']) { - - case EBML_ID_CLUSTERBLOCK: - $cluster_block_group[$sub_subelement['id_name']] = $this->HandleEMBLClusterBlock($sub_subelement, EBML_ID_CLUSTERBLOCK, $info); - break; - - case EBML_ID_CLUSTERREFERENCEPRIORITY: // unsigned-int - case EBML_ID_CLUSTERBLOCKDURATION: // unsigned-int - $cluster_block_group[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); - break; - - case EBML_ID_CLUSTERREFERENCEBLOCK: // signed-int - $cluster_block_group[$sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_subelement['data'], false, true); - break; - - case EBML_ID_CLUSTERCODECSTATE: - $cluster_block_group[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); - break; - - default: - $this->unhandledElement('clusters.blockgroup', __LINE__, $sub_subelement); - break; - } - } - $cluster_entry[$subelement['id_name']][] = $cluster_block_group; - break; - - case EBML_ID_CLUSTERSIMPLEBLOCK: - $cluster_entry[$subelement['id_name']][] = $this->HandleEMBLClusterBlock($subelement, EBML_ID_CLUSTERSIMPLEBLOCK, $info); - break; - - default: - $this->unhandledElement('cluster', __LINE__, $subelement); - break; - } - $this->current_offset = $subelement['end']; - } - if (!self::$hide_clusters) { - $info['matroska']['cluster'][] = $cluster_entry; - } - - // check to see if all the data we need exists already, if so, break out of the loop - if (!self::$parse_whole_file) { - if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) { - if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) { - if (count($info['matroska']['track_data_offsets']) == count($info['matroska']['tracks']['tracks'])) { - return; - } - } - } - } - break; - - default: - $this->unhandledElement('segment', __LINE__, $element_data); - break; - } - } - break; - - default: - $this->unhandledElement('root', __LINE__, $top_element); - break; - } - } - } - - private function EnsureBufferHasEnoughData($min_data=1024) { - if (($this->current_offset - $this->EBMLbuffer_offset) >= ($this->EBMLbuffer_length - $min_data)) { - $read_bytes = max($min_data, $this->getid3->fread_buffer_size()); - - try { - $this->fseek($this->current_offset); - $this->EBMLbuffer_offset = $this->current_offset; - $this->EBMLbuffer = $this->fread($read_bytes); - $this->EBMLbuffer_length = strlen($this->EBMLbuffer); - } catch (getid3_exception $e) { - $this->warning('EBML parser: '.$e->getMessage()); - return false; - } - - if ($this->EBMLbuffer_length == 0 && $this->feof()) { - return $this->error('EBML parser: ran out of file at offset '.$this->current_offset); - } - } - return true; - } - - private function readEBMLint() { - $actual_offset = $this->current_offset - $this->EBMLbuffer_offset; - - // get length of integer - $first_byte_int = ord($this->EBMLbuffer[$actual_offset]); - if (0x80 & $first_byte_int) { - $length = 1; - } elseif (0x40 & $first_byte_int) { - $length = 2; - } elseif (0x20 & $first_byte_int) { - $length = 3; - } elseif (0x10 & $first_byte_int) { - $length = 4; - } elseif (0x08 & $first_byte_int) { - $length = 5; - } elseif (0x04 & $first_byte_int) { - $length = 6; - } elseif (0x02 & $first_byte_int) { - $length = 7; - } elseif (0x01 & $first_byte_int) { - $length = 8; - } else { - throw new Exception('invalid EBML integer (leading 0x00) at '.$this->current_offset); - } - - // read - $int_value = self::EBML2Int(substr($this->EBMLbuffer, $actual_offset, $length)); - $this->current_offset += $length; - - return $int_value; - } - - private function readEBMLelementData($length, $check_buffer=false) { - if ($check_buffer && !$this->EnsureBufferHasEnoughData($length)) { - return false; - } - $data = substr($this->EBMLbuffer, $this->current_offset - $this->EBMLbuffer_offset, $length); - $this->current_offset += $length; - return $data; - } - - private function getEBMLelement(&$element, $parent_end, $get_data=false) { - if ($this->current_offset >= $parent_end) { - return false; - } - - if (!$this->EnsureBufferHasEnoughData()) { - $this->current_offset = PHP_INT_MAX; // do not exit parser right now, allow to finish current loop to gather maximum information - return false; - } - - $element = array(); - - // set offset - $element['offset'] = $this->current_offset; - - // get ID - $element['id'] = $this->readEBMLint(); - - // get name - $element['id_name'] = self::EBMLidName($element['id']); - - // get length - $element['length'] = $this->readEBMLint(); - - // get end offset - $element['end'] = $this->current_offset + $element['length']; - - // get raw data - $dont_parse = (in_array($element['id'], $this->unuseful_elements) || $element['id_name'] == dechex($element['id'])); - if (($get_data === true || (is_array($get_data) && !in_array($element['id'], $get_data))) && !$dont_parse) { - $element['data'] = $this->readEBMLelementData($element['length'], $element); - } - - return true; - } - - private function unhandledElement($type, $line, $element) { - // warn only about unknown and missed elements, not about unuseful - if (!in_array($element['id'], $this->unuseful_elements)) { - $this->warning('Unhandled '.$type.' element ['.basename(__FILE__).':'.$line.'] ('.$element['id'].'::'.$element['id_name'].' ['.$element['length'].' bytes]) at '.$element['offset']); - } - - // increase offset for unparsed elements - if (!isset($element['data'])) { - $this->current_offset = $element['end']; - } - } - - private function ExtractCommentsSimpleTag($SimpleTagArray) { - if (!empty($SimpleTagArray['SimpleTag'])) { - foreach ($SimpleTagArray['SimpleTag'] as $SimpleTagKey => $SimpleTagData) { - if (!empty($SimpleTagData['TagName']) && !empty($SimpleTagData['TagString'])) { - $this->getid3->info['matroska']['comments'][strtolower($SimpleTagData['TagName'])][] = $SimpleTagData['TagString']; - } - if (!empty($SimpleTagData['SimpleTag'])) { - $this->ExtractCommentsSimpleTag($SimpleTagData); - } - } - } - - return true; - } - - private function HandleEMBLSimpleTag($parent_end) { - $simpletag_entry = array(); - - while ($this->getEBMLelement($element, $parent_end, array(EBML_ID_SIMPLETAG))) { - switch ($element['id']) { - - case EBML_ID_TAGNAME: - case EBML_ID_TAGLANGUAGE: - case EBML_ID_TAGSTRING: - case EBML_ID_TAGBINARY: - $simpletag_entry[$element['id_name']] = $element['data']; - break; - - case EBML_ID_SIMPLETAG: - $simpletag_entry[$element['id_name']][] = $this->HandleEMBLSimpleTag($element['end']); - break; - - case EBML_ID_TAGDEFAULT: - $simpletag_entry[$element['id_name']] = (bool)getid3_lib::BigEndian2Int($element['data']); - break; - - default: - $this->unhandledElement('tag.simpletag', __LINE__, $element); - break; - } - } - - return $simpletag_entry; - } - - private function HandleEMBLClusterBlock($element, $block_type, &$info) { - // http://www.matroska.org/technical/specs/index.html#block_structure - // http://www.matroska.org/technical/specs/index.html#simpleblock_structure - - $block_data = array(); - $block_data['tracknumber'] = $this->readEBMLint(); - $block_data['timecode'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(2), false, true); - $block_data['flags_raw'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)); - - if ($block_type == EBML_ID_CLUSTERSIMPLEBLOCK) { - $block_data['flags']['keyframe'] = (($block_data['flags_raw'] & 0x80) >> 7); - //$block_data['flags']['reserved1'] = (($block_data['flags_raw'] & 0x70) >> 4); - } - else { - //$block_data['flags']['reserved1'] = (($block_data['flags_raw'] & 0xF0) >> 4); - } - $block_data['flags']['invisible'] = (bool)(($block_data['flags_raw'] & 0x08) >> 3); - $block_data['flags']['lacing'] = (($block_data['flags_raw'] & 0x06) >> 1); // 00=no lacing; 01=Xiph lacing; 11=EBML lacing; 10=fixed-size lacing - if ($block_type == EBML_ID_CLUSTERSIMPLEBLOCK) { - $block_data['flags']['discardable'] = (($block_data['flags_raw'] & 0x01)); - } - else { - //$block_data['flags']['reserved2'] = (($block_data['flags_raw'] & 0x01) >> 0); - } - $block_data['flags']['lacing_type'] = self::BlockLacingType($block_data['flags']['lacing']); - - // Lace (when lacing bit is set) - if ($block_data['flags']['lacing'] > 0) { - $block_data['lace_frames'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)) + 1; // Number of frames in the lace-1 (uint8) - if ($block_data['flags']['lacing'] != 0x02) { - for ($i = 1; $i < $block_data['lace_frames']; $i ++) { // Lace-coded size of each frame of the lace, except for the last one (multiple uint8). *This is not used with Fixed-size lacing as it is calculated automatically from (total size of lace) / (number of frames in lace). - if ($block_data['flags']['lacing'] == 0x03) { // EBML lacing - $block_data['lace_frames_size'][$i] = $this->readEBMLint(); // TODO: read size correctly, calc size for the last frame. For now offsets are deteminded OK with readEBMLint() and that's the most important thing. - } - else { // Xiph lacing - $block_data['lace_frames_size'][$i] = 0; - do { - $size = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)); - $block_data['lace_frames_size'][$i] += $size; - } - while ($size == 255); - } - } - if ($block_data['flags']['lacing'] == 0x01) { // calc size of the last frame only for Xiph lacing, till EBML sizes are now anyway determined incorrectly - $block_data['lace_frames_size'][] = $element['end'] - $this->current_offset - array_sum($block_data['lace_frames_size']); - } - } - } - - if (!isset($info['matroska']['track_data_offsets'][$block_data['tracknumber']])) { - $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['offset'] = $this->current_offset; - $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['length'] = $element['end'] - $this->current_offset; - //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['total_length'] = 0; - } - //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['total_length'] += $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['length']; - //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['duration'] = $block_data['timecode'] * ((isset($info['matroska']['info'][0]['TimecodeScale']) ? $info['matroska']['info'][0]['TimecodeScale'] : 1000000) / 1000000000); - - // set offset manually - $this->current_offset = $element['end']; - - return $block_data; - } - - private static function EBML2Int($EBMLstring) { - // http://matroska.org/specs/ - - // Element ID coded with an UTF-8 like system: - // 1xxx xxxx - Class A IDs (2^7 -2 possible values) (base 0x8X) - // 01xx xxxx xxxx xxxx - Class B IDs (2^14-2 possible values) (base 0x4X 0xXX) - // 001x xxxx xxxx xxxx xxxx xxxx - Class C IDs (2^21-2 possible values) (base 0x2X 0xXX 0xXX) - // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - Class D IDs (2^28-2 possible values) (base 0x1X 0xXX 0xXX 0xXX) - // Values with all x at 0 and 1 are reserved (hence the -2). - - // Data size, in octets, is also coded with an UTF-8 like system : - // 1xxx xxxx - value 0 to 2^7-2 - // 01xx xxxx xxxx xxxx - value 0 to 2^14-2 - // 001x xxxx xxxx xxxx xxxx xxxx - value 0 to 2^21-2 - // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^28-2 - // 0000 1xxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^35-2 - // 0000 01xx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^42-2 - // 0000 001x xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^49-2 - // 0000 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^56-2 - - $first_byte_int = ord($EBMLstring[0]); - if (0x80 & $first_byte_int) { - $EBMLstring[0] = chr($first_byte_int & 0x7F); - } elseif (0x40 & $first_byte_int) { - $EBMLstring[0] = chr($first_byte_int & 0x3F); - } elseif (0x20 & $first_byte_int) { - $EBMLstring[0] = chr($first_byte_int & 0x1F); - } elseif (0x10 & $first_byte_int) { - $EBMLstring[0] = chr($first_byte_int & 0x0F); - } elseif (0x08 & $first_byte_int) { - $EBMLstring[0] = chr($first_byte_int & 0x07); - } elseif (0x04 & $first_byte_int) { - $EBMLstring[0] = chr($first_byte_int & 0x03); - } elseif (0x02 & $first_byte_int) { - $EBMLstring[0] = chr($first_byte_int & 0x01); - } elseif (0x01 & $first_byte_int) { - $EBMLstring[0] = chr($first_byte_int & 0x00); - } - - return getid3_lib::BigEndian2Int($EBMLstring); - } - - private static function EBMLdate2unix($EBMLdatestamp) { - // Date - signed 8 octets integer in nanoseconds with 0 indicating the precise beginning of the millennium (at 2001-01-01T00:00:00,000000000 UTC) - // 978307200 == mktime(0, 0, 0, 1, 1, 2001) == January 1, 2001 12:00:00am UTC - return round(($EBMLdatestamp / 1000000000) + 978307200); - } - - public static function TargetTypeValue($target_type) { - // http://www.matroska.org/technical/specs/tagging/index.html - static $TargetTypeValue = array(); - if (empty($TargetTypeValue)) { - $TargetTypeValue[10] = 'A: ~ V:shot'; // the lowest hierarchy found in music or movies - $TargetTypeValue[20] = 'A:subtrack/part/movement ~ V:scene'; // corresponds to parts of a track for audio (like a movement) - $TargetTypeValue[30] = 'A:track/song ~ V:chapter'; // the common parts of an album or a movie - $TargetTypeValue[40] = 'A:part/session ~ V:part/session'; // when an album or episode has different logical parts - $TargetTypeValue[50] = 'A:album/opera/concert ~ V:movie/episode/concert'; // the most common grouping level of music and video (equals to an episode for TV series) - $TargetTypeValue[60] = 'A:edition/issue/volume/opus ~ V:season/sequel/volume'; // a list of lower levels grouped together - $TargetTypeValue[70] = 'A:collection ~ V:collection'; // the high hierarchy consisting of many different lower items - } - return (isset($TargetTypeValue[$target_type]) ? $TargetTypeValue[$target_type] : $target_type); - } - - public static function BlockLacingType($lacingtype) { - // http://matroska.org/technical/specs/index.html#block_structure - static $BlockLacingType = array(); - if (empty($BlockLacingType)) { - $BlockLacingType[0x00] = 'no lacing'; - $BlockLacingType[0x01] = 'Xiph lacing'; - $BlockLacingType[0x02] = 'fixed-size lacing'; - $BlockLacingType[0x03] = 'EBML lacing'; - } - return (isset($BlockLacingType[$lacingtype]) ? $BlockLacingType[$lacingtype] : $lacingtype); - } - - public static function CodecIDtoCommonName($codecid) { - // http://www.matroska.org/technical/specs/codecid/index.html - static $CodecIDlist = array(); - if (empty($CodecIDlist)) { - $CodecIDlist['A_AAC'] = 'aac'; - $CodecIDlist['A_AAC/MPEG2/LC'] = 'aac'; - $CodecIDlist['A_AC3'] = 'ac3'; - $CodecIDlist['A_EAC3'] = 'eac3'; - $CodecIDlist['A_DTS'] = 'dts'; - $CodecIDlist['A_FLAC'] = 'flac'; - $CodecIDlist['A_MPEG/L1'] = 'mp1'; - $CodecIDlist['A_MPEG/L2'] = 'mp2'; - $CodecIDlist['A_MPEG/L3'] = 'mp3'; - $CodecIDlist['A_PCM/INT/LIT'] = 'pcm'; // PCM Integer Little Endian - $CodecIDlist['A_PCM/INT/BIG'] = 'pcm'; // PCM Integer Big Endian - $CodecIDlist['A_QUICKTIME/QDMC'] = 'quicktime'; // Quicktime: QDesign Music - $CodecIDlist['A_QUICKTIME/QDM2'] = 'quicktime'; // Quicktime: QDesign Music v2 - $CodecIDlist['A_VORBIS'] = 'vorbis'; - $CodecIDlist['V_MPEG1'] = 'mpeg'; - $CodecIDlist['V_THEORA'] = 'theora'; - $CodecIDlist['V_REAL/RV40'] = 'real'; - $CodecIDlist['V_REAL/RV10'] = 'real'; - $CodecIDlist['V_REAL/RV20'] = 'real'; - $CodecIDlist['V_REAL/RV30'] = 'real'; - $CodecIDlist['V_QUICKTIME'] = 'quicktime'; // Quicktime - $CodecIDlist['V_MPEG4/ISO/AP'] = 'mpeg4'; - $CodecIDlist['V_MPEG4/ISO/ASP'] = 'mpeg4'; - $CodecIDlist['V_MPEG4/ISO/AVC'] = 'h264'; - $CodecIDlist['V_MPEG4/ISO/SP'] = 'mpeg4'; - $CodecIDlist['V_VP8'] = 'vp8'; - $CodecIDlist['V_MS/VFW/FOURCC'] = 'vcm'; // Microsoft (TM) Video Codec Manager (VCM) - $CodecIDlist['A_MS/ACM'] = 'acm'; // Microsoft (TM) Audio Codec Manager (ACM) - } - return (isset($CodecIDlist[$codecid]) ? $CodecIDlist[$codecid] : $codecid); - } - - private static function EBMLidName($value) { - static $EBMLidList = array(); - if (empty($EBMLidList)) { - $EBMLidList[EBML_ID_ASPECTRATIOTYPE] = 'AspectRatioType'; - $EBMLidList[EBML_ID_ATTACHEDFILE] = 'AttachedFile'; - $EBMLidList[EBML_ID_ATTACHMENTLINK] = 'AttachmentLink'; - $EBMLidList[EBML_ID_ATTACHMENTS] = 'Attachments'; - $EBMLidList[EBML_ID_AUDIO] = 'Audio'; - $EBMLidList[EBML_ID_BITDEPTH] = 'BitDepth'; - $EBMLidList[EBML_ID_CHANNELPOSITIONS] = 'ChannelPositions'; - $EBMLidList[EBML_ID_CHANNELS] = 'Channels'; - $EBMLidList[EBML_ID_CHAPCOUNTRY] = 'ChapCountry'; - $EBMLidList[EBML_ID_CHAPLANGUAGE] = 'ChapLanguage'; - $EBMLidList[EBML_ID_CHAPPROCESS] = 'ChapProcess'; - $EBMLidList[EBML_ID_CHAPPROCESSCODECID] = 'ChapProcessCodecID'; - $EBMLidList[EBML_ID_CHAPPROCESSCOMMAND] = 'ChapProcessCommand'; - $EBMLidList[EBML_ID_CHAPPROCESSDATA] = 'ChapProcessData'; - $EBMLidList[EBML_ID_CHAPPROCESSPRIVATE] = 'ChapProcessPrivate'; - $EBMLidList[EBML_ID_CHAPPROCESSTIME] = 'ChapProcessTime'; - $EBMLidList[EBML_ID_CHAPSTRING] = 'ChapString'; - $EBMLidList[EBML_ID_CHAPTERATOM] = 'ChapterAtom'; - $EBMLidList[EBML_ID_CHAPTERDISPLAY] = 'ChapterDisplay'; - $EBMLidList[EBML_ID_CHAPTERFLAGENABLED] = 'ChapterFlagEnabled'; - $EBMLidList[EBML_ID_CHAPTERFLAGHIDDEN] = 'ChapterFlagHidden'; - $EBMLidList[EBML_ID_CHAPTERPHYSICALEQUIV] = 'ChapterPhysicalEquiv'; - $EBMLidList[EBML_ID_CHAPTERS] = 'Chapters'; - $EBMLidList[EBML_ID_CHAPTERSEGMENTEDITIONUID] = 'ChapterSegmentEditionUID'; - $EBMLidList[EBML_ID_CHAPTERSEGMENTUID] = 'ChapterSegmentUID'; - $EBMLidList[EBML_ID_CHAPTERTIMEEND] = 'ChapterTimeEnd'; - $EBMLidList[EBML_ID_CHAPTERTIMESTART] = 'ChapterTimeStart'; - $EBMLidList[EBML_ID_CHAPTERTRACK] = 'ChapterTrack'; - $EBMLidList[EBML_ID_CHAPTERTRACKNUMBER] = 'ChapterTrackNumber'; - $EBMLidList[EBML_ID_CHAPTERTRANSLATE] = 'ChapterTranslate'; - $EBMLidList[EBML_ID_CHAPTERTRANSLATECODEC] = 'ChapterTranslateCodec'; - $EBMLidList[EBML_ID_CHAPTERTRANSLATEEDITIONUID] = 'ChapterTranslateEditionUID'; - $EBMLidList[EBML_ID_CHAPTERTRANSLATEID] = 'ChapterTranslateID'; - $EBMLidList[EBML_ID_CHAPTERUID] = 'ChapterUID'; - $EBMLidList[EBML_ID_CLUSTER] = 'Cluster'; - $EBMLidList[EBML_ID_CLUSTERBLOCK] = 'ClusterBlock'; - $EBMLidList[EBML_ID_CLUSTERBLOCKADDID] = 'ClusterBlockAddID'; - $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONAL] = 'ClusterBlockAdditional'; - $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONID] = 'ClusterBlockAdditionID'; - $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONS] = 'ClusterBlockAdditions'; - $EBMLidList[EBML_ID_CLUSTERBLOCKDURATION] = 'ClusterBlockDuration'; - $EBMLidList[EBML_ID_CLUSTERBLOCKGROUP] = 'ClusterBlockGroup'; - $EBMLidList[EBML_ID_CLUSTERBLOCKMORE] = 'ClusterBlockMore'; - $EBMLidList[EBML_ID_CLUSTERBLOCKVIRTUAL] = 'ClusterBlockVirtual'; - $EBMLidList[EBML_ID_CLUSTERCODECSTATE] = 'ClusterCodecState'; - $EBMLidList[EBML_ID_CLUSTERDELAY] = 'ClusterDelay'; - $EBMLidList[EBML_ID_CLUSTERDURATION] = 'ClusterDuration'; - $EBMLidList[EBML_ID_CLUSTERENCRYPTEDBLOCK] = 'ClusterEncryptedBlock'; - $EBMLidList[EBML_ID_CLUSTERFRAMENUMBER] = 'ClusterFrameNumber'; - $EBMLidList[EBML_ID_CLUSTERLACENUMBER] = 'ClusterLaceNumber'; - $EBMLidList[EBML_ID_CLUSTERPOSITION] = 'ClusterPosition'; - $EBMLidList[EBML_ID_CLUSTERPREVSIZE] = 'ClusterPrevSize'; - $EBMLidList[EBML_ID_CLUSTERREFERENCEBLOCK] = 'ClusterReferenceBlock'; - $EBMLidList[EBML_ID_CLUSTERREFERENCEPRIORITY] = 'ClusterReferencePriority'; - $EBMLidList[EBML_ID_CLUSTERREFERENCEVIRTUAL] = 'ClusterReferenceVirtual'; - $EBMLidList[EBML_ID_CLUSTERSILENTTRACKNUMBER] = 'ClusterSilentTrackNumber'; - $EBMLidList[EBML_ID_CLUSTERSILENTTRACKS] = 'ClusterSilentTracks'; - $EBMLidList[EBML_ID_CLUSTERSIMPLEBLOCK] = 'ClusterSimpleBlock'; - $EBMLidList[EBML_ID_CLUSTERTIMECODE] = 'ClusterTimecode'; - $EBMLidList[EBML_ID_CLUSTERTIMESLICE] = 'ClusterTimeSlice'; - $EBMLidList[EBML_ID_CODECDECODEALL] = 'CodecDecodeAll'; - $EBMLidList[EBML_ID_CODECDOWNLOADURL] = 'CodecDownloadURL'; - $EBMLidList[EBML_ID_CODECID] = 'CodecID'; - $EBMLidList[EBML_ID_CODECINFOURL] = 'CodecInfoURL'; - $EBMLidList[EBML_ID_CODECNAME] = 'CodecName'; - $EBMLidList[EBML_ID_CODECPRIVATE] = 'CodecPrivate'; - $EBMLidList[EBML_ID_CODECSETTINGS] = 'CodecSettings'; - $EBMLidList[EBML_ID_COLOURSPACE] = 'ColourSpace'; - $EBMLidList[EBML_ID_CONTENTCOMPALGO] = 'ContentCompAlgo'; - $EBMLidList[EBML_ID_CONTENTCOMPRESSION] = 'ContentCompression'; - $EBMLidList[EBML_ID_CONTENTCOMPSETTINGS] = 'ContentCompSettings'; - $EBMLidList[EBML_ID_CONTENTENCALGO] = 'ContentEncAlgo'; - $EBMLidList[EBML_ID_CONTENTENCKEYID] = 'ContentEncKeyID'; - $EBMLidList[EBML_ID_CONTENTENCODING] = 'ContentEncoding'; - $EBMLidList[EBML_ID_CONTENTENCODINGORDER] = 'ContentEncodingOrder'; - $EBMLidList[EBML_ID_CONTENTENCODINGS] = 'ContentEncodings'; - $EBMLidList[EBML_ID_CONTENTENCODINGSCOPE] = 'ContentEncodingScope'; - $EBMLidList[EBML_ID_CONTENTENCODINGTYPE] = 'ContentEncodingType'; - $EBMLidList[EBML_ID_CONTENTENCRYPTION] = 'ContentEncryption'; - $EBMLidList[EBML_ID_CONTENTSIGALGO] = 'ContentSigAlgo'; - $EBMLidList[EBML_ID_CONTENTSIGHASHALGO] = 'ContentSigHashAlgo'; - $EBMLidList[EBML_ID_CONTENTSIGKEYID] = 'ContentSigKeyID'; - $EBMLidList[EBML_ID_CONTENTSIGNATURE] = 'ContentSignature'; - $EBMLidList[EBML_ID_CRC32] = 'CRC32'; - $EBMLidList[EBML_ID_CUEBLOCKNUMBER] = 'CueBlockNumber'; - $EBMLidList[EBML_ID_CUECLUSTERPOSITION] = 'CueClusterPosition'; - $EBMLidList[EBML_ID_CUECODECSTATE] = 'CueCodecState'; - $EBMLidList[EBML_ID_CUEPOINT] = 'CuePoint'; - $EBMLidList[EBML_ID_CUEREFCLUSTER] = 'CueRefCluster'; - $EBMLidList[EBML_ID_CUEREFCODECSTATE] = 'CueRefCodecState'; - $EBMLidList[EBML_ID_CUEREFERENCE] = 'CueReference'; - $EBMLidList[EBML_ID_CUEREFNUMBER] = 'CueRefNumber'; - $EBMLidList[EBML_ID_CUEREFTIME] = 'CueRefTime'; - $EBMLidList[EBML_ID_CUES] = 'Cues'; - $EBMLidList[EBML_ID_CUETIME] = 'CueTime'; - $EBMLidList[EBML_ID_CUETRACK] = 'CueTrack'; - $EBMLidList[EBML_ID_CUETRACKPOSITIONS] = 'CueTrackPositions'; - $EBMLidList[EBML_ID_DATEUTC] = 'DateUTC'; - $EBMLidList[EBML_ID_DEFAULTDURATION] = 'DefaultDuration'; - $EBMLidList[EBML_ID_DISPLAYHEIGHT] = 'DisplayHeight'; - $EBMLidList[EBML_ID_DISPLAYUNIT] = 'DisplayUnit'; - $EBMLidList[EBML_ID_DISPLAYWIDTH] = 'DisplayWidth'; - $EBMLidList[EBML_ID_DOCTYPE] = 'DocType'; - $EBMLidList[EBML_ID_DOCTYPEREADVERSION] = 'DocTypeReadVersion'; - $EBMLidList[EBML_ID_DOCTYPEVERSION] = 'DocTypeVersion'; - $EBMLidList[EBML_ID_DURATION] = 'Duration'; - $EBMLidList[EBML_ID_EBML] = 'EBML'; - $EBMLidList[EBML_ID_EBMLMAXIDLENGTH] = 'EBMLMaxIDLength'; - $EBMLidList[EBML_ID_EBMLMAXSIZELENGTH] = 'EBMLMaxSizeLength'; - $EBMLidList[EBML_ID_EBMLREADVERSION] = 'EBMLReadVersion'; - $EBMLidList[EBML_ID_EBMLVERSION] = 'EBMLVersion'; - $EBMLidList[EBML_ID_EDITIONENTRY] = 'EditionEntry'; - $EBMLidList[EBML_ID_EDITIONFLAGDEFAULT] = 'EditionFlagDefault'; - $EBMLidList[EBML_ID_EDITIONFLAGHIDDEN] = 'EditionFlagHidden'; - $EBMLidList[EBML_ID_EDITIONFLAGORDERED] = 'EditionFlagOrdered'; - $EBMLidList[EBML_ID_EDITIONUID] = 'EditionUID'; - $EBMLidList[EBML_ID_FILEDATA] = 'FileData'; - $EBMLidList[EBML_ID_FILEDESCRIPTION] = 'FileDescription'; - $EBMLidList[EBML_ID_FILEMIMETYPE] = 'FileMimeType'; - $EBMLidList[EBML_ID_FILENAME] = 'FileName'; - $EBMLidList[EBML_ID_FILEREFERRAL] = 'FileReferral'; - $EBMLidList[EBML_ID_FILEUID] = 'FileUID'; - $EBMLidList[EBML_ID_FLAGDEFAULT] = 'FlagDefault'; - $EBMLidList[EBML_ID_FLAGENABLED] = 'FlagEnabled'; - $EBMLidList[EBML_ID_FLAGFORCED] = 'FlagForced'; - $EBMLidList[EBML_ID_FLAGINTERLACED] = 'FlagInterlaced'; - $EBMLidList[EBML_ID_FLAGLACING] = 'FlagLacing'; - $EBMLidList[EBML_ID_GAMMAVALUE] = 'GammaValue'; - $EBMLidList[EBML_ID_INFO] = 'Info'; - $EBMLidList[EBML_ID_LANGUAGE] = 'Language'; - $EBMLidList[EBML_ID_MAXBLOCKADDITIONID] = 'MaxBlockAdditionID'; - $EBMLidList[EBML_ID_MAXCACHE] = 'MaxCache'; - $EBMLidList[EBML_ID_MINCACHE] = 'MinCache'; - $EBMLidList[EBML_ID_MUXINGAPP] = 'MuxingApp'; - $EBMLidList[EBML_ID_NAME] = 'Name'; - $EBMLidList[EBML_ID_NEXTFILENAME] = 'NextFilename'; - $EBMLidList[EBML_ID_NEXTUID] = 'NextUID'; - $EBMLidList[EBML_ID_OUTPUTSAMPLINGFREQUENCY] = 'OutputSamplingFrequency'; - $EBMLidList[EBML_ID_PIXELCROPBOTTOM] = 'PixelCropBottom'; - $EBMLidList[EBML_ID_PIXELCROPLEFT] = 'PixelCropLeft'; - $EBMLidList[EBML_ID_PIXELCROPRIGHT] = 'PixelCropRight'; - $EBMLidList[EBML_ID_PIXELCROPTOP] = 'PixelCropTop'; - $EBMLidList[EBML_ID_PIXELHEIGHT] = 'PixelHeight'; - $EBMLidList[EBML_ID_PIXELWIDTH] = 'PixelWidth'; - $EBMLidList[EBML_ID_PREVFILENAME] = 'PrevFilename'; - $EBMLidList[EBML_ID_PREVUID] = 'PrevUID'; - $EBMLidList[EBML_ID_SAMPLINGFREQUENCY] = 'SamplingFrequency'; - $EBMLidList[EBML_ID_SEEK] = 'Seek'; - $EBMLidList[EBML_ID_SEEKHEAD] = 'SeekHead'; - $EBMLidList[EBML_ID_SEEKID] = 'SeekID'; - $EBMLidList[EBML_ID_SEEKPOSITION] = 'SeekPosition'; - $EBMLidList[EBML_ID_SEGMENT] = 'Segment'; - $EBMLidList[EBML_ID_SEGMENTFAMILY] = 'SegmentFamily'; - $EBMLidList[EBML_ID_SEGMENTFILENAME] = 'SegmentFilename'; - $EBMLidList[EBML_ID_SEGMENTUID] = 'SegmentUID'; - $EBMLidList[EBML_ID_SIMPLETAG] = 'SimpleTag'; - $EBMLidList[EBML_ID_CLUSTERSLICES] = 'ClusterSlices'; - $EBMLidList[EBML_ID_STEREOMODE] = 'StereoMode'; - $EBMLidList[EBML_ID_OLDSTEREOMODE] = 'OldStereoMode'; - $EBMLidList[EBML_ID_TAG] = 'Tag'; - $EBMLidList[EBML_ID_TAGATTACHMENTUID] = 'TagAttachmentUID'; - $EBMLidList[EBML_ID_TAGBINARY] = 'TagBinary'; - $EBMLidList[EBML_ID_TAGCHAPTERUID] = 'TagChapterUID'; - $EBMLidList[EBML_ID_TAGDEFAULT] = 'TagDefault'; - $EBMLidList[EBML_ID_TAGEDITIONUID] = 'TagEditionUID'; - $EBMLidList[EBML_ID_TAGLANGUAGE] = 'TagLanguage'; - $EBMLidList[EBML_ID_TAGNAME] = 'TagName'; - $EBMLidList[EBML_ID_TAGTRACKUID] = 'TagTrackUID'; - $EBMLidList[EBML_ID_TAGS] = 'Tags'; - $EBMLidList[EBML_ID_TAGSTRING] = 'TagString'; - $EBMLidList[EBML_ID_TARGETS] = 'Targets'; - $EBMLidList[EBML_ID_TARGETTYPE] = 'TargetType'; - $EBMLidList[EBML_ID_TARGETTYPEVALUE] = 'TargetTypeValue'; - $EBMLidList[EBML_ID_TIMECODESCALE] = 'TimecodeScale'; - $EBMLidList[EBML_ID_TITLE] = 'Title'; - $EBMLidList[EBML_ID_TRACKENTRY] = 'TrackEntry'; - $EBMLidList[EBML_ID_TRACKNUMBER] = 'TrackNumber'; - $EBMLidList[EBML_ID_TRACKOFFSET] = 'TrackOffset'; - $EBMLidList[EBML_ID_TRACKOVERLAY] = 'TrackOverlay'; - $EBMLidList[EBML_ID_TRACKS] = 'Tracks'; - $EBMLidList[EBML_ID_TRACKTIMECODESCALE] = 'TrackTimecodeScale'; - $EBMLidList[EBML_ID_TRACKTRANSLATE] = 'TrackTranslate'; - $EBMLidList[EBML_ID_TRACKTRANSLATECODEC] = 'TrackTranslateCodec'; - $EBMLidList[EBML_ID_TRACKTRANSLATEEDITIONUID] = 'TrackTranslateEditionUID'; - $EBMLidList[EBML_ID_TRACKTRANSLATETRACKID] = 'TrackTranslateTrackID'; - $EBMLidList[EBML_ID_TRACKTYPE] = 'TrackType'; - $EBMLidList[EBML_ID_TRACKUID] = 'TrackUID'; - $EBMLidList[EBML_ID_VIDEO] = 'Video'; - $EBMLidList[EBML_ID_VOID] = 'Void'; - $EBMLidList[EBML_ID_WRITINGAPP] = 'WritingApp'; - } - - return (isset($EBMLidList[$value]) ? $EBMLidList[$value] : dechex($value)); - } - - public static function displayUnit($value) { - // http://www.matroska.org/technical/specs/index.html#DisplayUnit - static $units = array( - 0 => 'pixels', - 1 => 'centimeters', - 2 => 'inches', - 3 => 'Display Aspect Ratio'); - - return (isset($units[$value]) ? $units[$value] : 'unknown'); - } - - private static function getDefaultStreamInfo($streams) - { - foreach (array_reverse($streams) as $stream) { - if ($stream['default']) { - break; - } - } - - $unset = array('default', 'name'); - foreach ($unset as $u) { - if (isset($stream[$u])) { - unset($stream[$u]); - } - } - - $info = $stream; - $info['streams'] = $streams; - - return $info; - } - + // public options + public static $hide_clusters = true; // if true, do not return information about CLUSTER chunks, since there's a lot of them and they're not usually useful [default: TRUE] + public static $parse_whole_file = false; // true to parse the whole file, not only header [default: FALSE] + + // private parser settings/placeholders + private $EBMLbuffer = ''; + private $EBMLbuffer_offset = 0; + private $EBMLbuffer_length = 0; + private $current_offset = 0; + private $unuseful_elements = [EBML_ID_CRC32, EBML_ID_VOID]; + + public function Analyze() + { + $info = &$this->getid3->info; + + // parse container + try { + $this->parseEBML($info); + } catch (Exception $e) { + $this->error('EBML parser: '.$e->getMessage()); + } + + // calculate playtime + if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) { + foreach ($info['matroska']['info'] as $key => $infoarray) { + if (isset($infoarray['Duration'])) { + // TimecodeScale is how many nanoseconds each Duration unit is + $info['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000); + break; + } + } + } + + // extract tags + if (isset($info['matroska']['tags']) && is_array($info['matroska']['tags'])) { + foreach ($info['matroska']['tags'] as $key => $infoarray) { + $this->ExtractCommentsSimpleTag($infoarray); + } + } + + // process tracks + if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) { + foreach ($info['matroska']['tracks']['tracks'] as $key => $trackarray) { + $track_info = []; + $track_info['dataformat'] = self::CodecIDtoCommonName($trackarray['CodecID']); + $track_info['default'] = (isset($trackarray['FlagDefault']) ? $trackarray['FlagDefault'] : true); + if (isset($trackarray['Name'])) { + $track_info['name'] = $trackarray['Name']; + } + + switch ($trackarray['TrackType']) { + + case 1: // Video + $track_info['resolution_x'] = $trackarray['PixelWidth']; + $track_info['resolution_y'] = $trackarray['PixelHeight']; + $track_info['display_unit'] = self::displayUnit(isset($trackarray['DisplayUnit']) ? $trackarray['DisplayUnit'] : 0); + $track_info['display_x'] = (isset($trackarray['DisplayWidth']) ? $trackarray['DisplayWidth'] : $trackarray['PixelWidth']); + $track_info['display_y'] = (isset($trackarray['DisplayHeight']) ? $trackarray['DisplayHeight'] : $trackarray['PixelHeight']); + + if (isset($trackarray['PixelCropBottom'])) { + $track_info['crop_bottom'] = $trackarray['PixelCropBottom']; + } + if (isset($trackarray['PixelCropTop'])) { + $track_info['crop_top'] = $trackarray['PixelCropTop']; + } + if (isset($trackarray['PixelCropLeft'])) { + $track_info['crop_left'] = $trackarray['PixelCropLeft']; + } + if (isset($trackarray['PixelCropRight'])) { + $track_info['crop_right'] = $trackarray['PixelCropRight']; + } + if (isset($trackarray['DefaultDuration'])) { + $track_info['frame_rate'] = round(1000000000 / $trackarray['DefaultDuration'], 3); + } + if (isset($trackarray['CodecName'])) { + $track_info['codec'] = $trackarray['CodecName']; + } + + switch ($trackarray['CodecID']) { + case 'V_MS/VFW/FOURCC': + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); + + $parsed = getid3_riff::ParseBITMAPINFOHEADER($trackarray['CodecPrivate']); + $track_info['codec'] = getid3_riff::fourccLookup($parsed['fourcc']); + $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed; + break; + + /*case 'V_MPEG4/ISO/AVC': + $h264['profile'] = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 1, 1)); + $h264['level'] = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 3, 1)); + $rn = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 4, 1)); + $h264['NALUlength'] = ($rn & 3) + 1; + $rn = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 5, 1)); + $nsps = ($rn & 31); + $offset = 6; + for ($i = 0; $i < $nsps; $i ++) { + $length = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 2)); + $h264['SPS'][] = substr($trackarray['CodecPrivate'], $offset + 2, $length); + $offset += 2 + $length; + } + $npps = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 1)); + $offset += 1; + for ($i = 0; $i < $npps; $i ++) { + $length = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 2)); + $h264['PPS'][] = substr($trackarray['CodecPrivate'], $offset + 2, $length); + $offset += 2 + $length; + } + $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $h264; + break;*/ + } + + $info['video']['streams'][] = $track_info; + break; + + case 2: // Audio + $track_info['sample_rate'] = (isset($trackarray['SamplingFrequency']) ? $trackarray['SamplingFrequency'] : 8000.0); + $track_info['channels'] = (isset($trackarray['Channels']) ? $trackarray['Channels'] : 1); + $track_info['language'] = (isset($trackarray['Language']) ? $trackarray['Language'] : 'eng'); + if (isset($trackarray['BitDepth'])) { + $track_info['bits_per_sample'] = $trackarray['BitDepth']; + } + if (isset($trackarray['CodecName'])) { + $track_info['codec'] = $trackarray['CodecName']; + } + + switch ($trackarray['CodecID']) { + case 'A_PCM/INT/LIT': + case 'A_PCM/INT/BIG': + $track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth']; + break; + + case 'A_AC3': + case 'A_EAC3': + case 'A_DTS': + case 'A_MPEG/L3': + case 'A_MPEG/L2': + case 'A_FLAC': + $module_dataformat = ($track_info['dataformat'] == 'mp2' ? 'mp3' : ($track_info['dataformat'] == 'eac3' ? 'ac3' : $track_info['dataformat'])); + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.'.$module_dataformat.'.php', __FILE__, true); + + if (! isset($info['matroska']['track_data_offsets'][$trackarray['TrackNumber']])) { + $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because $info[matroska][track_data_offsets]['.$trackarray['TrackNumber'].'] not set'); + break; + } + + // create temp instance + $getid3_temp = new getID3(); + if ($track_info['dataformat'] != 'flac') { + $getid3_temp->openfile($this->getid3->filename); + } + $getid3_temp->info['avdataoffset'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset']; + if ($track_info['dataformat'][0] == 'm' || $track_info['dataformat'] == 'flac') { + $getid3_temp->info['avdataend'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'] + $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['length']; + } + + // analyze + $class = 'getid3_'.$module_dataformat; + $header_data_key = $track_info['dataformat'][0] == 'm' ? 'mpeg' : $track_info['dataformat']; + $getid3_audio = new $class($getid3_temp, __CLASS__); + if ($track_info['dataformat'] == 'flac') { + $getid3_audio->AnalyzeString($trackarray['CodecPrivate']); + } else { + $getid3_audio->Analyze(); + } + if (! empty($getid3_temp->info[$header_data_key])) { + $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info[$header_data_key]; + if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) { + foreach ($getid3_temp->info['audio'] as $key => $value) { + $track_info[$key] = $value; + } + } + } else { + $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because '.$class.'::Analyze() failed at offset '.$getid3_temp->info['avdataoffset']); + } + + // copy errors and warnings + if (! empty($getid3_temp->info['error'])) { + foreach ($getid3_temp->info['error'] as $newerror) { + $this->warning($class.'() says: ['.$newerror.']'); + } + } + if (! empty($getid3_temp->info['warning'])) { + foreach ($getid3_temp->info['warning'] as $newerror) { + $this->warning($class.'() says: ['.$newerror.']'); + } + } + unset($getid3_temp, $getid3_audio); + break; + + case 'A_AAC': + case 'A_AAC/MPEG2/LC': + case 'A_AAC/MPEG2/LC/SBR': + case 'A_AAC/MPEG4/LC': + case 'A_AAC/MPEG4/LC/SBR': + $this->warning($trackarray['CodecID'].' audio data contains no header, audio/video bitrates can\'t be calculated'); + break; + + case 'A_VORBIS': + if (! isset($trackarray['CodecPrivate'])) { + $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data not set'); + break; + } + $vorbis_offset = strpos($trackarray['CodecPrivate'], 'vorbis', 1); + if ($vorbis_offset === false) { + $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data does not contain "vorbis" keyword'); + break; + } + $vorbis_offset -= 1; + + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, true); + + // create temp instance + $getid3_temp = new getID3(); + + // analyze + $getid3_ogg = new getid3_ogg($getid3_temp); + $oggpageinfo['page_seqno'] = 0; + $getid3_ogg->ParseVorbisPageHeader($trackarray['CodecPrivate'], $vorbis_offset, $oggpageinfo); + if (! empty($getid3_temp->info['ogg'])) { + $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info['ogg']; + if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) { + foreach ($getid3_temp->info['audio'] as $key => $value) { + $track_info[$key] = $value; + } + } + } + + // copy errors and warnings + if (! empty($getid3_temp->info['error'])) { + foreach ($getid3_temp->info['error'] as $newerror) { + $this->warning('getid3_ogg() says: ['.$newerror.']'); + } + } + if (! empty($getid3_temp->info['warning'])) { + foreach ($getid3_temp->info['warning'] as $newerror) { + $this->warning('getid3_ogg() says: ['.$newerror.']'); + } + } + + if (! empty($getid3_temp->info['ogg']['bitrate_nominal'])) { + $track_info['bitrate'] = $getid3_temp->info['ogg']['bitrate_nominal']; + } + unset($getid3_temp, $getid3_ogg, $oggpageinfo, $vorbis_offset); + break; + + case 'A_MS/ACM': + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); + + $parsed = getid3_riff::parseWAVEFORMATex($trackarray['CodecPrivate']); + foreach ($parsed as $key => $value) { + if ($key != 'raw') { + $track_info[$key] = $value; + } + } + $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed; + break; + + default: + $this->warning('Unhandled audio type "'.(isset($trackarray['CodecID']) ? $trackarray['CodecID'] : '').'"'); + break; + } + + $info['audio']['streams'][] = $track_info; + break; + } + } + + if (! empty($info['video']['streams'])) { + $info['video'] = self::getDefaultStreamInfo($info['video']['streams']); + } + if (! empty($info['audio']['streams'])) { + $info['audio'] = self::getDefaultStreamInfo($info['audio']['streams']); + } + } + + // process attachments + if (isset($info['matroska']['attachments']) && $this->getid3->option_save_attachments !== getID3::ATTACHMENTS_NONE) { + foreach ($info['matroska']['attachments'] as $i => $entry) { + if (strpos($entry['FileMimeType'], 'image/') === 0 && ! empty($entry['FileData'])) { + $info['matroska']['comments']['picture'][] = ['data' => $entry['FileData'], 'image_mime' => $entry['FileMimeType'], 'filename' => $entry['FileName']]; + } + } + } + + // determine mime type + if (! empty($info['video']['streams'])) { + $info['mime_type'] = ($info['matroska']['doctype'] == 'webm' ? 'video/webm' : 'video/x-matroska'); + } elseif (! empty($info['audio']['streams'])) { + $info['mime_type'] = ($info['matroska']['doctype'] == 'webm' ? 'audio/webm' : 'audio/x-matroska'); + } elseif (isset($info['mime_type'])) { + unset($info['mime_type']); + } + + return true; + } + + private function parseEBML(&$info) + { + // http://www.matroska.org/technical/specs/index.html#EBMLBasics + $this->current_offset = $info['avdataoffset']; + + while ($this->getEBMLelement($top_element, $info['avdataend'])) { + switch ($top_element['id']) { + + case EBML_ID_EBML: + $info['matroska']['header']['offset'] = $top_element['offset']; + $info['matroska']['header']['length'] = $top_element['length']; + + while ($this->getEBMLelement($element_data, $top_element['end'], true)) { + switch ($element_data['id']) { + + case EBML_ID_EBMLVERSION: + case EBML_ID_EBMLREADVERSION: + case EBML_ID_EBMLMAXIDLENGTH: + case EBML_ID_EBMLMAXSIZELENGTH: + case EBML_ID_DOCTYPEVERSION: + case EBML_ID_DOCTYPEREADVERSION: + $element_data['data'] = getid3_lib::BigEndian2Int($element_data['data']); + break; + + case EBML_ID_DOCTYPE: + $element_data['data'] = getid3_lib::trimNullByte($element_data['data']); + $info['matroska']['doctype'] = $element_data['data']; + $info['fileformat'] = $element_data['data']; + break; + + default: + $this->unhandledElement('header', __LINE__, $element_data); + break; + } + + unset($element_data['offset'], $element_data['end']); + $info['matroska']['header']['elements'][] = $element_data; + } + break; + + case EBML_ID_SEGMENT: + $info['matroska']['segment'][0]['offset'] = $top_element['offset']; + $info['matroska']['segment'][0]['length'] = $top_element['length']; + + while ($this->getEBMLelement($element_data, $top_element['end'])) { + if ($element_data['id'] != EBML_ID_CLUSTER || ! self::$hide_clusters) { // collect clusters only if required + $info['matroska']['segments'][] = $element_data; + } + switch ($element_data['id']) { + + case EBML_ID_SEEKHEAD: // Contains the position of other level 1 elements. + + while ($this->getEBMLelement($seek_entry, $element_data['end'])) { + switch ($seek_entry['id']) { + + case EBML_ID_SEEK: // Contains a single seek entry to an EBML element + while ($this->getEBMLelement($sub_seek_entry, $seek_entry['end'], true)) { + switch ($sub_seek_entry['id']) { + + case EBML_ID_SEEKID: + $seek_entry['target_id'] = self::EBML2Int($sub_seek_entry['data']); + $seek_entry['target_name'] = self::EBMLidName($seek_entry['target_id']); + break; + + case EBML_ID_SEEKPOSITION: + $seek_entry['target_offset'] = $element_data['offset'] + getid3_lib::BigEndian2Int($sub_seek_entry['data']); + break; + + default: + $this->unhandledElement('seekhead.seek', __LINE__, $sub_seek_entry); } + break; + } + if (! isset($seek_entry['target_id'])) { + $this->warning('seek_entry[target_id] unexpectedly not set at '.$seek_entry['offset']); + break; + } + if (($seek_entry['target_id'] != EBML_ID_CLUSTER) || ! self::$hide_clusters) { // collect clusters only if required + $info['matroska']['seek'][] = $seek_entry; + } + break; + + default: + $this->unhandledElement('seekhead', __LINE__, $seek_entry); + break; + } + } + break; + + case EBML_ID_TRACKS: // A top-level block of information with many tracks described. + $info['matroska']['tracks'] = $element_data; + + while ($this->getEBMLelement($track_entry, $element_data['end'])) { + switch ($track_entry['id']) { + + case EBML_ID_TRACKENTRY: //subelements: Describes a track with all elements. + + while ($this->getEBMLelement($subelement, $track_entry['end'], [EBML_ID_VIDEO, EBML_ID_AUDIO, EBML_ID_CONTENTENCODINGS, EBML_ID_CODECPRIVATE])) { + switch ($subelement['id']) { + + case EBML_ID_TRACKNUMBER: + case EBML_ID_TRACKUID: + case EBML_ID_TRACKTYPE: + case EBML_ID_MINCACHE: + case EBML_ID_MAXCACHE: + case EBML_ID_MAXBLOCKADDITIONID: + case EBML_ID_DEFAULTDURATION: // nanoseconds per frame + $track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); + break; + + case EBML_ID_TRACKTIMECODESCALE: + $track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']); + break; + + case EBML_ID_CODECID: + case EBML_ID_LANGUAGE: + case EBML_ID_NAME: + case EBML_ID_CODECNAME: + $track_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']); + break; + + case EBML_ID_CODECPRIVATE: + $track_entry[$subelement['id_name']] = $this->readEBMLelementData($subelement['length'], true); + break; + + case EBML_ID_FLAGENABLED: + case EBML_ID_FLAGDEFAULT: + case EBML_ID_FLAGFORCED: + case EBML_ID_FLAGLACING: + case EBML_ID_CODECDECODEALL: + $track_entry[$subelement['id_name']] = (bool) getid3_lib::BigEndian2Int($subelement['data']); + break; + + case EBML_ID_VIDEO: + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { + switch ($sub_subelement['id']) { + + case EBML_ID_PIXELWIDTH: + case EBML_ID_PIXELHEIGHT: + case EBML_ID_PIXELCROPBOTTOM: + case EBML_ID_PIXELCROPTOP: + case EBML_ID_PIXELCROPLEFT: + case EBML_ID_PIXELCROPRIGHT: + case EBML_ID_DISPLAYWIDTH: + case EBML_ID_DISPLAYHEIGHT: + case EBML_ID_DISPLAYUNIT: + case EBML_ID_ASPECTRATIOTYPE: + case EBML_ID_STEREOMODE: + case EBML_ID_OLDSTEREOMODE: + $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); + break; + + case EBML_ID_FLAGINTERLACED: + $track_entry[$sub_subelement['id_name']] = (bool) getid3_lib::BigEndian2Int($sub_subelement['data']); + break; + + case EBML_ID_GAMMAVALUE: + $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']); + break; + + case EBML_ID_COLOURSPACE: + $track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); + break; + + default: + $this->unhandledElement('track.video', __LINE__, $sub_subelement); + break; + } + } + break; + + case EBML_ID_AUDIO: + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { + switch ($sub_subelement['id']) { + + case EBML_ID_CHANNELS: + case EBML_ID_BITDEPTH: + $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); + break; + + case EBML_ID_SAMPLINGFREQUENCY: + case EBML_ID_OUTPUTSAMPLINGFREQUENCY: + $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']); + break; + + case EBML_ID_CHANNELPOSITIONS: + $track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); + break; + + default: + $this->unhandledElement('track.audio', __LINE__, $sub_subelement); + break; + } + } + break; + + case EBML_ID_CONTENTENCODINGS: + + while ($this->getEBMLelement($sub_subelement, $subelement['end'])) { + switch ($sub_subelement['id']) { + + case EBML_ID_CONTENTENCODING: + + while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], [EBML_ID_CONTENTCOMPRESSION, EBML_ID_CONTENTENCRYPTION])) { + switch ($sub_sub_subelement['id']) { + + case EBML_ID_CONTENTENCODINGORDER: + case EBML_ID_CONTENTENCODINGSCOPE: + case EBML_ID_CONTENTENCODINGTYPE: + $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); + break; + + case EBML_ID_CONTENTCOMPRESSION: + + while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { + switch ($sub_sub_sub_subelement['id']) { + + case EBML_ID_CONTENTCOMPALGO: + $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']); + break; + + case EBML_ID_CONTENTCOMPSETTINGS: + $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data']; + break; + + default: + $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement); + break; + } + } + break; + + case EBML_ID_CONTENTENCRYPTION: + + while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { + switch ($sub_sub_sub_subelement['id']) { + + case EBML_ID_CONTENTENCALGO: + case EBML_ID_CONTENTSIGALGO: + case EBML_ID_CONTENTSIGHASHALGO: + $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']); + break; + + case EBML_ID_CONTENTENCKEYID: + case EBML_ID_CONTENTSIGNATURE: + case EBML_ID_CONTENTSIGKEYID: + $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data']; + break; + + default: + $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement); + break; + } + } + break; + + default: + $this->unhandledElement('track.contentencodings.contentencoding', __LINE__, $sub_sub_subelement); + break; + } + } + break; + + default: + $this->unhandledElement('track.contentencodings', __LINE__, $sub_subelement); + break; + } + } + break; + + default: + $this->unhandledElement('track', __LINE__, $subelement); + break; + } + } + + $info['matroska']['tracks']['tracks'][] = $track_entry; + break; + + default: + $this->unhandledElement('tracks', __LINE__, $track_entry); + break; + } + } + break; + + case EBML_ID_INFO: // Contains miscellaneous general information and statistics on the file. + $info_entry = []; + + while ($this->getEBMLelement($subelement, $element_data['end'], true)) { + switch ($subelement['id']) { + + case EBML_ID_TIMECODESCALE: + $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); + break; + + case EBML_ID_DURATION: + $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']); + break; + + case EBML_ID_DATEUTC: + $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); + $info_entry[$subelement['id_name'].'_unix'] = self::EBMLdate2unix($info_entry[$subelement['id_name']]); + break; + + case EBML_ID_SEGMENTUID: + case EBML_ID_PREVUID: + case EBML_ID_NEXTUID: + $info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']); + break; + + case EBML_ID_SEGMENTFAMILY: + $info_entry[$subelement['id_name']][] = getid3_lib::trimNullByte($subelement['data']); + break; + + case EBML_ID_SEGMENTFILENAME: + case EBML_ID_PREVFILENAME: + case EBML_ID_NEXTFILENAME: + case EBML_ID_TITLE: + case EBML_ID_MUXINGAPP: + case EBML_ID_WRITINGAPP: + $info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']); + $info['matroska']['comments'][strtolower($subelement['id_name'])][] = $info_entry[$subelement['id_name']]; + break; + + case EBML_ID_CHAPTERTRANSLATE: + $chaptertranslate_entry = []; + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { + switch ($sub_subelement['id']) { + + case EBML_ID_CHAPTERTRANSLATEEDITIONUID: + $chaptertranslate_entry[$sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_subelement['data']); + break; + + case EBML_ID_CHAPTERTRANSLATECODEC: + $chaptertranslate_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); + break; + + case EBML_ID_CHAPTERTRANSLATEID: + $chaptertranslate_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); + break; + + default: + $this->unhandledElement('info.chaptertranslate', __LINE__, $sub_subelement); + break; + } + } + $info_entry[$subelement['id_name']] = $chaptertranslate_entry; + break; + + default: + $this->unhandledElement('info', __LINE__, $subelement); + break; + } + } + $info['matroska']['info'][] = $info_entry; + break; + + case EBML_ID_CUES: // A top-level element to speed seeking access. All entries are local to the segment. Should be mandatory for non "live" streams. + if (self::$hide_clusters) { // do not parse cues if hide clusters is "ON" till they point to clusters anyway + $this->current_offset = $element_data['end']; + break; + } + $cues_entry = []; + + while ($this->getEBMLelement($subelement, $element_data['end'])) { + switch ($subelement['id']) { + + case EBML_ID_CUEPOINT: + $cuepoint_entry = []; + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], [EBML_ID_CUETRACKPOSITIONS])) { + switch ($sub_subelement['id']) { + + case EBML_ID_CUETRACKPOSITIONS: + $cuetrackpositions_entry = []; + + while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) { + switch ($sub_sub_subelement['id']) { + + case EBML_ID_CUETRACK: + case EBML_ID_CUECLUSTERPOSITION: + case EBML_ID_CUEBLOCKNUMBER: + case EBML_ID_CUECODECSTATE: + $cuetrackpositions_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); + break; + + default: + $this->unhandledElement('cues.cuepoint.cuetrackpositions', __LINE__, $sub_sub_subelement); + break; + } + } + $cuepoint_entry[$sub_subelement['id_name']][] = $cuetrackpositions_entry; + break; + + case EBML_ID_CUETIME: + $cuepoint_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); + break; + + default: + $this->unhandledElement('cues.cuepoint', __LINE__, $sub_subelement); + break; + } + } + $cues_entry[] = $cuepoint_entry; + break; + + default: + $this->unhandledElement('cues', __LINE__, $subelement); + break; + } + } + $info['matroska']['cues'] = $cues_entry; + break; + + case EBML_ID_TAGS: // Element containing elements specific to Tracks/Chapters. + $tags_entry = []; + + while ($this->getEBMLelement($subelement, $element_data['end'], false)) { + switch ($subelement['id']) { + + case EBML_ID_TAG: + $tag_entry = []; + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], false)) { + switch ($sub_subelement['id']) { + + case EBML_ID_TARGETS: + $targets_entry = []; + + while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) { + switch ($sub_sub_subelement['id']) { + + case EBML_ID_TARGETTYPEVALUE: + $targets_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); + $targets_entry[strtolower($sub_sub_subelement['id_name']).'_long'] = self::TargetTypeValue($targets_entry[$sub_sub_subelement['id_name']]); + break; + + case EBML_ID_TARGETTYPE: + $targets_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data']; + break; + + case EBML_ID_TAGTRACKUID: + case EBML_ID_TAGEDITIONUID: + case EBML_ID_TAGCHAPTERUID: + case EBML_ID_TAGATTACHMENTUID: + $targets_entry[$sub_sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); + break; + + default: + $this->unhandledElement('tags.tag.targets', __LINE__, $sub_sub_subelement); + break; + } + } + $tag_entry[$sub_subelement['id_name']] = $targets_entry; + break; + + case EBML_ID_SIMPLETAG: + $tag_entry[$sub_subelement['id_name']][] = $this->HandleEMBLSimpleTag($sub_subelement['end']); + break; + + default: + $this->unhandledElement('tags.tag', __LINE__, $sub_subelement); + break; + } + } + $tags_entry[] = $tag_entry; + break; + + default: + $this->unhandledElement('tags', __LINE__, $subelement); + break; + } + } + $info['matroska']['tags'] = $tags_entry; + break; + + case EBML_ID_ATTACHMENTS: // Contain attached files. + + while ($this->getEBMLelement($subelement, $element_data['end'])) { + switch ($subelement['id']) { + + case EBML_ID_ATTACHEDFILE: + $attachedfile_entry = []; + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], [EBML_ID_FILEDATA])) { + switch ($sub_subelement['id']) { + + case EBML_ID_FILEDESCRIPTION: + case EBML_ID_FILENAME: + case EBML_ID_FILEMIMETYPE: + $attachedfile_entry[$sub_subelement['id_name']] = $sub_subelement['data']; + break; + + case EBML_ID_FILEDATA: + $attachedfile_entry['data_offset'] = $this->current_offset; + $attachedfile_entry['data_length'] = $sub_subelement['length']; + + $attachedfile_entry[$sub_subelement['id_name']] = $this->saveAttachment( + $attachedfile_entry['FileName'], + $attachedfile_entry['data_offset'], + $attachedfile_entry['data_length']); + + $this->current_offset = $sub_subelement['end']; + break; + + case EBML_ID_FILEUID: + $attachedfile_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); + break; + + default: + $this->unhandledElement('attachments.attachedfile', __LINE__, $sub_subelement); + break; + } + } + $info['matroska']['attachments'][] = $attachedfile_entry; + break; + + default: + $this->unhandledElement('attachments', __LINE__, $subelement); + break; + } + } + break; + + case EBML_ID_CHAPTERS: + + while ($this->getEBMLelement($subelement, $element_data['end'])) { + switch ($subelement['id']) { + + case EBML_ID_EDITIONENTRY: + $editionentry_entry = []; + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], [EBML_ID_CHAPTERATOM])) { + switch ($sub_subelement['id']) { + + case EBML_ID_EDITIONUID: + $editionentry_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); + break; + + case EBML_ID_EDITIONFLAGHIDDEN: + case EBML_ID_EDITIONFLAGDEFAULT: + case EBML_ID_EDITIONFLAGORDERED: + $editionentry_entry[$sub_subelement['id_name']] = (bool) getid3_lib::BigEndian2Int($sub_subelement['data']); + break; + + case EBML_ID_CHAPTERATOM: + $chapteratom_entry = []; + + while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], [EBML_ID_CHAPTERTRACK, EBML_ID_CHAPTERDISPLAY])) { + switch ($sub_sub_subelement['id']) { + + case EBML_ID_CHAPTERSEGMENTUID: + case EBML_ID_CHAPTERSEGMENTEDITIONUID: + $chapteratom_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data']; + break; + + case EBML_ID_CHAPTERFLAGENABLED: + case EBML_ID_CHAPTERFLAGHIDDEN: + $chapteratom_entry[$sub_sub_subelement['id_name']] = (bool) getid3_lib::BigEndian2Int($sub_sub_subelement['data']); + break; + + case EBML_ID_CHAPTERUID: + case EBML_ID_CHAPTERTIMESTART: + case EBML_ID_CHAPTERTIMEEND: + $chapteratom_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); + break; + + case EBML_ID_CHAPTERTRACK: + $chaptertrack_entry = []; + + while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { + switch ($sub_sub_sub_subelement['id']) { + + case EBML_ID_CHAPTERTRACKNUMBER: + $chaptertrack_entry[$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']); + break; + + default: + $this->unhandledElement('chapters.editionentry.chapteratom.chaptertrack', __LINE__, $sub_sub_sub_subelement); + break; + } + } + $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chaptertrack_entry; + break; + + case EBML_ID_CHAPTERDISPLAY: + $chapterdisplay_entry = []; + + while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { + switch ($sub_sub_sub_subelement['id']) { + + case EBML_ID_CHAPSTRING: + case EBML_ID_CHAPLANGUAGE: + case EBML_ID_CHAPCOUNTRY: + $chapterdisplay_entry[$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data']; + break; + + default: + $this->unhandledElement('chapters.editionentry.chapteratom.chapterdisplay', __LINE__, $sub_sub_sub_subelement); + break; + } + } + $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chapterdisplay_entry; + break; + + default: + $this->unhandledElement('chapters.editionentry.chapteratom', __LINE__, $sub_sub_subelement); + break; + } + } + $editionentry_entry[$sub_subelement['id_name']][] = $chapteratom_entry; + break; + + default: + $this->unhandledElement('chapters.editionentry', __LINE__, $sub_subelement); + break; + } + } + $info['matroska']['chapters'][] = $editionentry_entry; + break; + + default: + $this->unhandledElement('chapters', __LINE__, $subelement); + break; + } + } + break; + + case EBML_ID_CLUSTER: // The lower level element containing the (monolithic) Block structure. + $cluster_entry = []; + + while ($this->getEBMLelement($subelement, $element_data['end'], [EBML_ID_CLUSTERSILENTTRACKS, EBML_ID_CLUSTERBLOCKGROUP, EBML_ID_CLUSTERSIMPLEBLOCK])) { + switch ($subelement['id']) { + + case EBML_ID_CLUSTERTIMECODE: + case EBML_ID_CLUSTERPOSITION: + case EBML_ID_CLUSTERPREVSIZE: + $cluster_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); + break; + + case EBML_ID_CLUSTERSILENTTRACKS: + $cluster_silent_tracks = []; + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { + switch ($sub_subelement['id']) { + + case EBML_ID_CLUSTERSILENTTRACKNUMBER: + $cluster_silent_tracks[] = getid3_lib::BigEndian2Int($sub_subelement['data']); + break; + + default: + $this->unhandledElement('cluster.silenttracks', __LINE__, $sub_subelement); + break; + } + } + $cluster_entry[$subelement['id_name']][] = $cluster_silent_tracks; + break; + + case EBML_ID_CLUSTERBLOCKGROUP: + $cluster_block_group = ['offset' => $this->current_offset]; + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], [EBML_ID_CLUSTERBLOCK])) { + switch ($sub_subelement['id']) { + + case EBML_ID_CLUSTERBLOCK: + $cluster_block_group[$sub_subelement['id_name']] = $this->HandleEMBLClusterBlock($sub_subelement, EBML_ID_CLUSTERBLOCK, $info); + break; + + case EBML_ID_CLUSTERREFERENCEPRIORITY: // unsigned-int + case EBML_ID_CLUSTERBLOCKDURATION: // unsigned-int + $cluster_block_group[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); + break; + + case EBML_ID_CLUSTERREFERENCEBLOCK: // signed-int + $cluster_block_group[$sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_subelement['data'], false, true); + break; + + case EBML_ID_CLUSTERCODECSTATE: + $cluster_block_group[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); + break; + + default: + $this->unhandledElement('clusters.blockgroup', __LINE__, $sub_subelement); + break; + } + } + $cluster_entry[$subelement['id_name']][] = $cluster_block_group; + break; + + case EBML_ID_CLUSTERSIMPLEBLOCK: + $cluster_entry[$subelement['id_name']][] = $this->HandleEMBLClusterBlock($subelement, EBML_ID_CLUSTERSIMPLEBLOCK, $info); + break; + + default: + $this->unhandledElement('cluster', __LINE__, $subelement); + break; + } + $this->current_offset = $subelement['end']; + } + if (! self::$hide_clusters) { + $info['matroska']['cluster'][] = $cluster_entry; + } + + // check to see if all the data we need exists already, if so, break out of the loop + if (! self::$parse_whole_file) { + if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) { + if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) { + if (count($info['matroska']['track_data_offsets']) == count($info['matroska']['tracks']['tracks'])) { + return; + } + } + } + } + break; + + default: + $this->unhandledElement('segment', __LINE__, $element_data); + break; + } + } + break; + + default: + $this->unhandledElement('root', __LINE__, $top_element); + break; + } + } + } + + private function EnsureBufferHasEnoughData($min_data = 1024) + { + if (($this->current_offset - $this->EBMLbuffer_offset) >= ($this->EBMLbuffer_length - $min_data)) { + $read_bytes = max($min_data, $this->getid3->fread_buffer_size()); + + try { + $this->fseek($this->current_offset); + $this->EBMLbuffer_offset = $this->current_offset; + $this->EBMLbuffer = $this->fread($read_bytes); + $this->EBMLbuffer_length = strlen($this->EBMLbuffer); + } catch (getid3_exception $e) { + $this->warning('EBML parser: '.$e->getMessage()); + + return false; + } + + if ($this->EBMLbuffer_length == 0 && $this->feof()) { + return $this->error('EBML parser: ran out of file at offset '.$this->current_offset); + } + } + + return true; + } + + private function readEBMLint() + { + $actual_offset = $this->current_offset - $this->EBMLbuffer_offset; + + // get length of integer + $first_byte_int = ord($this->EBMLbuffer[$actual_offset]); + if (0x80 & $first_byte_int) { + $length = 1; + } elseif (0x40 & $first_byte_int) { + $length = 2; + } elseif (0x20 & $first_byte_int) { + $length = 3; + } elseif (0x10 & $first_byte_int) { + $length = 4; + } elseif (0x08 & $first_byte_int) { + $length = 5; + } elseif (0x04 & $first_byte_int) { + $length = 6; + } elseif (0x02 & $first_byte_int) { + $length = 7; + } elseif (0x01 & $first_byte_int) { + $length = 8; + } else { + throw new Exception('invalid EBML integer (leading 0x00) at '.$this->current_offset); + } + + // read + $int_value = self::EBML2Int(substr($this->EBMLbuffer, $actual_offset, $length)); + $this->current_offset += $length; + + return $int_value; + } + + private function readEBMLelementData($length, $check_buffer = false) + { + if ($check_buffer && ! $this->EnsureBufferHasEnoughData($length)) { + return false; + } + $data = substr($this->EBMLbuffer, $this->current_offset - $this->EBMLbuffer_offset, $length); + $this->current_offset += $length; + + return $data; + } + + private function getEBMLelement(&$element, $parent_end, $get_data = false) + { + if ($this->current_offset >= $parent_end) { + return false; + } + + if (! $this->EnsureBufferHasEnoughData()) { + $this->current_offset = PHP_INT_MAX; // do not exit parser right now, allow to finish current loop to gather maximum information + + return false; + } + + $element = []; + + // set offset + $element['offset'] = $this->current_offset; + + // get ID + $element['id'] = $this->readEBMLint(); + + // get name + $element['id_name'] = self::EBMLidName($element['id']); + + // get length + $element['length'] = $this->readEBMLint(); + + // get end offset + $element['end'] = $this->current_offset + $element['length']; + + // get raw data + $dont_parse = (in_array($element['id'], $this->unuseful_elements) || $element['id_name'] == dechex($element['id'])); + if (($get_data === true || (is_array($get_data) && ! in_array($element['id'], $get_data))) && ! $dont_parse) { + $element['data'] = $this->readEBMLelementData($element['length'], $element); + } + + return true; + } + + private function unhandledElement($type, $line, $element) + { + // warn only about unknown and missed elements, not about unuseful + if (! in_array($element['id'], $this->unuseful_elements)) { + $this->warning('Unhandled '.$type.' element ['.basename(__FILE__).':'.$line.'] ('.$element['id'].'::'.$element['id_name'].' ['.$element['length'].' bytes]) at '.$element['offset']); + } + + // increase offset for unparsed elements + if (! isset($element['data'])) { + $this->current_offset = $element['end']; + } + } + + private function ExtractCommentsSimpleTag($SimpleTagArray) + { + if (! empty($SimpleTagArray['SimpleTag'])) { + foreach ($SimpleTagArray['SimpleTag'] as $SimpleTagKey => $SimpleTagData) { + if (! empty($SimpleTagData['TagName']) && ! empty($SimpleTagData['TagString'])) { + $this->getid3->info['matroska']['comments'][strtolower($SimpleTagData['TagName'])][] = $SimpleTagData['TagString']; + } + if (! empty($SimpleTagData['SimpleTag'])) { + $this->ExtractCommentsSimpleTag($SimpleTagData); + } + } + } + + return true; + } + + private function HandleEMBLSimpleTag($parent_end) + { + $simpletag_entry = []; + + while ($this->getEBMLelement($element, $parent_end, [EBML_ID_SIMPLETAG])) { + switch ($element['id']) { + + case EBML_ID_TAGNAME: + case EBML_ID_TAGLANGUAGE: + case EBML_ID_TAGSTRING: + case EBML_ID_TAGBINARY: + $simpletag_entry[$element['id_name']] = $element['data']; + break; + + case EBML_ID_SIMPLETAG: + $simpletag_entry[$element['id_name']][] = $this->HandleEMBLSimpleTag($element['end']); + break; + + case EBML_ID_TAGDEFAULT: + $simpletag_entry[$element['id_name']] = (bool) getid3_lib::BigEndian2Int($element['data']); + break; + + default: + $this->unhandledElement('tag.simpletag', __LINE__, $element); + break; + } + } + + return $simpletag_entry; + } + + private function HandleEMBLClusterBlock($element, $block_type, &$info) + { + // http://www.matroska.org/technical/specs/index.html#block_structure + // http://www.matroska.org/technical/specs/index.html#simpleblock_structure + + $block_data = []; + $block_data['tracknumber'] = $this->readEBMLint(); + $block_data['timecode'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(2), false, true); + $block_data['flags_raw'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)); + + if ($block_type == EBML_ID_CLUSTERSIMPLEBLOCK) { + $block_data['flags']['keyframe'] = (($block_data['flags_raw'] & 0x80) >> 7); + //$block_data['flags']['reserved1'] = (($block_data['flags_raw'] & 0x70) >> 4); + } else { + //$block_data['flags']['reserved1'] = (($block_data['flags_raw'] & 0xF0) >> 4); + } + $block_data['flags']['invisible'] = (bool) (($block_data['flags_raw'] & 0x08) >> 3); + $block_data['flags']['lacing'] = (($block_data['flags_raw'] & 0x06) >> 1); // 00=no lacing; 01=Xiph lacing; 11=EBML lacing; 10=fixed-size lacing + if ($block_type == EBML_ID_CLUSTERSIMPLEBLOCK) { + $block_data['flags']['discardable'] = (($block_data['flags_raw'] & 0x01)); + } else { + //$block_data['flags']['reserved2'] = (($block_data['flags_raw'] & 0x01) >> 0); + } + $block_data['flags']['lacing_type'] = self::BlockLacingType($block_data['flags']['lacing']); + + // Lace (when lacing bit is set) + if ($block_data['flags']['lacing'] > 0) { + $block_data['lace_frames'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)) + 1; // Number of frames in the lace-1 (uint8) + if ($block_data['flags']['lacing'] != 0x02) { + for ($i = 1; $i < $block_data['lace_frames']; $i++) { // Lace-coded size of each frame of the lace, except for the last one (multiple uint8). *This is not used with Fixed-size lacing as it is calculated automatically from (total size of lace) / (number of frames in lace). + if ($block_data['flags']['lacing'] == 0x03) { // EBML lacing + $block_data['lace_frames_size'][$i] = $this->readEBMLint(); // TODO: read size correctly, calc size for the last frame. For now offsets are deteminded OK with readEBMLint() and that's the most important thing. + } else { // Xiph lacing + $block_data['lace_frames_size'][$i] = 0; + do { + $size = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)); + $block_data['lace_frames_size'][$i] += $size; + } while ($size == 255); + } + } + if ($block_data['flags']['lacing'] == 0x01) { // calc size of the last frame only for Xiph lacing, till EBML sizes are now anyway determined incorrectly + $block_data['lace_frames_size'][] = $element['end'] - $this->current_offset - array_sum($block_data['lace_frames_size']); + } + } + } + + if (! isset($info['matroska']['track_data_offsets'][$block_data['tracknumber']])) { + $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['offset'] = $this->current_offset; + $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['length'] = $element['end'] - $this->current_offset; + //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['total_length'] = 0; + } + //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['total_length'] += $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['length']; + //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['duration'] = $block_data['timecode'] * ((isset($info['matroska']['info'][0]['TimecodeScale']) ? $info['matroska']['info'][0]['TimecodeScale'] : 1000000) / 1000000000); + + // set offset manually + $this->current_offset = $element['end']; + + return $block_data; + } + + private static function EBML2Int($EBMLstring) + { + // http://matroska.org/specs/ + + // Element ID coded with an UTF-8 like system: + // 1xxx xxxx - Class A IDs (2^7 -2 possible values) (base 0x8X) + // 01xx xxxx xxxx xxxx - Class B IDs (2^14-2 possible values) (base 0x4X 0xXX) + // 001x xxxx xxxx xxxx xxxx xxxx - Class C IDs (2^21-2 possible values) (base 0x2X 0xXX 0xXX) + // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - Class D IDs (2^28-2 possible values) (base 0x1X 0xXX 0xXX 0xXX) + // Values with all x at 0 and 1 are reserved (hence the -2). + + // Data size, in octets, is also coded with an UTF-8 like system : + // 1xxx xxxx - value 0 to 2^7-2 + // 01xx xxxx xxxx xxxx - value 0 to 2^14-2 + // 001x xxxx xxxx xxxx xxxx xxxx - value 0 to 2^21-2 + // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^28-2 + // 0000 1xxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^35-2 + // 0000 01xx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^42-2 + // 0000 001x xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^49-2 + // 0000 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^56-2 + + $first_byte_int = ord($EBMLstring[0]); + if (0x80 & $first_byte_int) { + $EBMLstring[0] = chr($first_byte_int & 0x7F); + } elseif (0x40 & $first_byte_int) { + $EBMLstring[0] = chr($first_byte_int & 0x3F); + } elseif (0x20 & $first_byte_int) { + $EBMLstring[0] = chr($first_byte_int & 0x1F); + } elseif (0x10 & $first_byte_int) { + $EBMLstring[0] = chr($first_byte_int & 0x0F); + } elseif (0x08 & $first_byte_int) { + $EBMLstring[0] = chr($first_byte_int & 0x07); + } elseif (0x04 & $first_byte_int) { + $EBMLstring[0] = chr($first_byte_int & 0x03); + } elseif (0x02 & $first_byte_int) { + $EBMLstring[0] = chr($first_byte_int & 0x01); + } elseif (0x01 & $first_byte_int) { + $EBMLstring[0] = chr($first_byte_int & 0x00); + } + + return getid3_lib::BigEndian2Int($EBMLstring); + } + + private static function EBMLdate2unix($EBMLdatestamp) + { + // Date - signed 8 octets integer in nanoseconds with 0 indicating the precise beginning of the millennium (at 2001-01-01T00:00:00,000000000 UTC) + // 978307200 == mktime(0, 0, 0, 1, 1, 2001) == January 1, 2001 12:00:00am UTC + return round(($EBMLdatestamp / 1000000000) + 978307200); + } + + public static function TargetTypeValue($target_type) + { + // http://www.matroska.org/technical/specs/tagging/index.html + static $TargetTypeValue = []; + if (empty($TargetTypeValue)) { + $TargetTypeValue[10] = 'A: ~ V:shot'; // the lowest hierarchy found in music or movies + $TargetTypeValue[20] = 'A:subtrack/part/movement ~ V:scene'; // corresponds to parts of a track for audio (like a movement) + $TargetTypeValue[30] = 'A:track/song ~ V:chapter'; // the common parts of an album or a movie + $TargetTypeValue[40] = 'A:part/session ~ V:part/session'; // when an album or episode has different logical parts + $TargetTypeValue[50] = 'A:album/opera/concert ~ V:movie/episode/concert'; // the most common grouping level of music and video (equals to an episode for TV series) + $TargetTypeValue[60] = 'A:edition/issue/volume/opus ~ V:season/sequel/volume'; // a list of lower levels grouped together + $TargetTypeValue[70] = 'A:collection ~ V:collection'; // the high hierarchy consisting of many different lower items + } + + return isset($TargetTypeValue[$target_type]) ? $TargetTypeValue[$target_type] : $target_type; + } + + public static function BlockLacingType($lacingtype) + { + // http://matroska.org/technical/specs/index.html#block_structure + static $BlockLacingType = []; + if (empty($BlockLacingType)) { + $BlockLacingType[0x00] = 'no lacing'; + $BlockLacingType[0x01] = 'Xiph lacing'; + $BlockLacingType[0x02] = 'fixed-size lacing'; + $BlockLacingType[0x03] = 'EBML lacing'; + } + + return isset($BlockLacingType[$lacingtype]) ? $BlockLacingType[$lacingtype] : $lacingtype; + } + + public static function CodecIDtoCommonName($codecid) + { + // http://www.matroska.org/technical/specs/codecid/index.html + static $CodecIDlist = []; + if (empty($CodecIDlist)) { + $CodecIDlist['A_AAC'] = 'aac'; + $CodecIDlist['A_AAC/MPEG2/LC'] = 'aac'; + $CodecIDlist['A_AC3'] = 'ac3'; + $CodecIDlist['A_EAC3'] = 'eac3'; + $CodecIDlist['A_DTS'] = 'dts'; + $CodecIDlist['A_FLAC'] = 'flac'; + $CodecIDlist['A_MPEG/L1'] = 'mp1'; + $CodecIDlist['A_MPEG/L2'] = 'mp2'; + $CodecIDlist['A_MPEG/L3'] = 'mp3'; + $CodecIDlist['A_PCM/INT/LIT'] = 'pcm'; // PCM Integer Little Endian + $CodecIDlist['A_PCM/INT/BIG'] = 'pcm'; // PCM Integer Big Endian + $CodecIDlist['A_QUICKTIME/QDMC'] = 'quicktime'; // Quicktime: QDesign Music + $CodecIDlist['A_QUICKTIME/QDM2'] = 'quicktime'; // Quicktime: QDesign Music v2 + $CodecIDlist['A_VORBIS'] = 'vorbis'; + $CodecIDlist['V_MPEG1'] = 'mpeg'; + $CodecIDlist['V_THEORA'] = 'theora'; + $CodecIDlist['V_REAL/RV40'] = 'real'; + $CodecIDlist['V_REAL/RV10'] = 'real'; + $CodecIDlist['V_REAL/RV20'] = 'real'; + $CodecIDlist['V_REAL/RV30'] = 'real'; + $CodecIDlist['V_QUICKTIME'] = 'quicktime'; // Quicktime + $CodecIDlist['V_MPEG4/ISO/AP'] = 'mpeg4'; + $CodecIDlist['V_MPEG4/ISO/ASP'] = 'mpeg4'; + $CodecIDlist['V_MPEG4/ISO/AVC'] = 'h264'; + $CodecIDlist['V_MPEG4/ISO/SP'] = 'mpeg4'; + $CodecIDlist['V_VP8'] = 'vp8'; + $CodecIDlist['V_MS/VFW/FOURCC'] = 'vcm'; // Microsoft (TM) Video Codec Manager (VCM) + $CodecIDlist['A_MS/ACM'] = 'acm'; // Microsoft (TM) Audio Codec Manager (ACM) + } + + return isset($CodecIDlist[$codecid]) ? $CodecIDlist[$codecid] : $codecid; + } + + private static function EBMLidName($value) + { + static $EBMLidList = []; + if (empty($EBMLidList)) { + $EBMLidList[EBML_ID_ASPECTRATIOTYPE] = 'AspectRatioType'; + $EBMLidList[EBML_ID_ATTACHEDFILE] = 'AttachedFile'; + $EBMLidList[EBML_ID_ATTACHMENTLINK] = 'AttachmentLink'; + $EBMLidList[EBML_ID_ATTACHMENTS] = 'Attachments'; + $EBMLidList[EBML_ID_AUDIO] = 'Audio'; + $EBMLidList[EBML_ID_BITDEPTH] = 'BitDepth'; + $EBMLidList[EBML_ID_CHANNELPOSITIONS] = 'ChannelPositions'; + $EBMLidList[EBML_ID_CHANNELS] = 'Channels'; + $EBMLidList[EBML_ID_CHAPCOUNTRY] = 'ChapCountry'; + $EBMLidList[EBML_ID_CHAPLANGUAGE] = 'ChapLanguage'; + $EBMLidList[EBML_ID_CHAPPROCESS] = 'ChapProcess'; + $EBMLidList[EBML_ID_CHAPPROCESSCODECID] = 'ChapProcessCodecID'; + $EBMLidList[EBML_ID_CHAPPROCESSCOMMAND] = 'ChapProcessCommand'; + $EBMLidList[EBML_ID_CHAPPROCESSDATA] = 'ChapProcessData'; + $EBMLidList[EBML_ID_CHAPPROCESSPRIVATE] = 'ChapProcessPrivate'; + $EBMLidList[EBML_ID_CHAPPROCESSTIME] = 'ChapProcessTime'; + $EBMLidList[EBML_ID_CHAPSTRING] = 'ChapString'; + $EBMLidList[EBML_ID_CHAPTERATOM] = 'ChapterAtom'; + $EBMLidList[EBML_ID_CHAPTERDISPLAY] = 'ChapterDisplay'; + $EBMLidList[EBML_ID_CHAPTERFLAGENABLED] = 'ChapterFlagEnabled'; + $EBMLidList[EBML_ID_CHAPTERFLAGHIDDEN] = 'ChapterFlagHidden'; + $EBMLidList[EBML_ID_CHAPTERPHYSICALEQUIV] = 'ChapterPhysicalEquiv'; + $EBMLidList[EBML_ID_CHAPTERS] = 'Chapters'; + $EBMLidList[EBML_ID_CHAPTERSEGMENTEDITIONUID] = 'ChapterSegmentEditionUID'; + $EBMLidList[EBML_ID_CHAPTERSEGMENTUID] = 'ChapterSegmentUID'; + $EBMLidList[EBML_ID_CHAPTERTIMEEND] = 'ChapterTimeEnd'; + $EBMLidList[EBML_ID_CHAPTERTIMESTART] = 'ChapterTimeStart'; + $EBMLidList[EBML_ID_CHAPTERTRACK] = 'ChapterTrack'; + $EBMLidList[EBML_ID_CHAPTERTRACKNUMBER] = 'ChapterTrackNumber'; + $EBMLidList[EBML_ID_CHAPTERTRANSLATE] = 'ChapterTranslate'; + $EBMLidList[EBML_ID_CHAPTERTRANSLATECODEC] = 'ChapterTranslateCodec'; + $EBMLidList[EBML_ID_CHAPTERTRANSLATEEDITIONUID] = 'ChapterTranslateEditionUID'; + $EBMLidList[EBML_ID_CHAPTERTRANSLATEID] = 'ChapterTranslateID'; + $EBMLidList[EBML_ID_CHAPTERUID] = 'ChapterUID'; + $EBMLidList[EBML_ID_CLUSTER] = 'Cluster'; + $EBMLidList[EBML_ID_CLUSTERBLOCK] = 'ClusterBlock'; + $EBMLidList[EBML_ID_CLUSTERBLOCKADDID] = 'ClusterBlockAddID'; + $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONAL] = 'ClusterBlockAdditional'; + $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONID] = 'ClusterBlockAdditionID'; + $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONS] = 'ClusterBlockAdditions'; + $EBMLidList[EBML_ID_CLUSTERBLOCKDURATION] = 'ClusterBlockDuration'; + $EBMLidList[EBML_ID_CLUSTERBLOCKGROUP] = 'ClusterBlockGroup'; + $EBMLidList[EBML_ID_CLUSTERBLOCKMORE] = 'ClusterBlockMore'; + $EBMLidList[EBML_ID_CLUSTERBLOCKVIRTUAL] = 'ClusterBlockVirtual'; + $EBMLidList[EBML_ID_CLUSTERCODECSTATE] = 'ClusterCodecState'; + $EBMLidList[EBML_ID_CLUSTERDELAY] = 'ClusterDelay'; + $EBMLidList[EBML_ID_CLUSTERDURATION] = 'ClusterDuration'; + $EBMLidList[EBML_ID_CLUSTERENCRYPTEDBLOCK] = 'ClusterEncryptedBlock'; + $EBMLidList[EBML_ID_CLUSTERFRAMENUMBER] = 'ClusterFrameNumber'; + $EBMLidList[EBML_ID_CLUSTERLACENUMBER] = 'ClusterLaceNumber'; + $EBMLidList[EBML_ID_CLUSTERPOSITION] = 'ClusterPosition'; + $EBMLidList[EBML_ID_CLUSTERPREVSIZE] = 'ClusterPrevSize'; + $EBMLidList[EBML_ID_CLUSTERREFERENCEBLOCK] = 'ClusterReferenceBlock'; + $EBMLidList[EBML_ID_CLUSTERREFERENCEPRIORITY] = 'ClusterReferencePriority'; + $EBMLidList[EBML_ID_CLUSTERREFERENCEVIRTUAL] = 'ClusterReferenceVirtual'; + $EBMLidList[EBML_ID_CLUSTERSILENTTRACKNUMBER] = 'ClusterSilentTrackNumber'; + $EBMLidList[EBML_ID_CLUSTERSILENTTRACKS] = 'ClusterSilentTracks'; + $EBMLidList[EBML_ID_CLUSTERSIMPLEBLOCK] = 'ClusterSimpleBlock'; + $EBMLidList[EBML_ID_CLUSTERTIMECODE] = 'ClusterTimecode'; + $EBMLidList[EBML_ID_CLUSTERTIMESLICE] = 'ClusterTimeSlice'; + $EBMLidList[EBML_ID_CODECDECODEALL] = 'CodecDecodeAll'; + $EBMLidList[EBML_ID_CODECDOWNLOADURL] = 'CodecDownloadURL'; + $EBMLidList[EBML_ID_CODECID] = 'CodecID'; + $EBMLidList[EBML_ID_CODECINFOURL] = 'CodecInfoURL'; + $EBMLidList[EBML_ID_CODECNAME] = 'CodecName'; + $EBMLidList[EBML_ID_CODECPRIVATE] = 'CodecPrivate'; + $EBMLidList[EBML_ID_CODECSETTINGS] = 'CodecSettings'; + $EBMLidList[EBML_ID_COLOURSPACE] = 'ColourSpace'; + $EBMLidList[EBML_ID_CONTENTCOMPALGO] = 'ContentCompAlgo'; + $EBMLidList[EBML_ID_CONTENTCOMPRESSION] = 'ContentCompression'; + $EBMLidList[EBML_ID_CONTENTCOMPSETTINGS] = 'ContentCompSettings'; + $EBMLidList[EBML_ID_CONTENTENCALGO] = 'ContentEncAlgo'; + $EBMLidList[EBML_ID_CONTENTENCKEYID] = 'ContentEncKeyID'; + $EBMLidList[EBML_ID_CONTENTENCODING] = 'ContentEncoding'; + $EBMLidList[EBML_ID_CONTENTENCODINGORDER] = 'ContentEncodingOrder'; + $EBMLidList[EBML_ID_CONTENTENCODINGS] = 'ContentEncodings'; + $EBMLidList[EBML_ID_CONTENTENCODINGSCOPE] = 'ContentEncodingScope'; + $EBMLidList[EBML_ID_CONTENTENCODINGTYPE] = 'ContentEncodingType'; + $EBMLidList[EBML_ID_CONTENTENCRYPTION] = 'ContentEncryption'; + $EBMLidList[EBML_ID_CONTENTSIGALGO] = 'ContentSigAlgo'; + $EBMLidList[EBML_ID_CONTENTSIGHASHALGO] = 'ContentSigHashAlgo'; + $EBMLidList[EBML_ID_CONTENTSIGKEYID] = 'ContentSigKeyID'; + $EBMLidList[EBML_ID_CONTENTSIGNATURE] = 'ContentSignature'; + $EBMLidList[EBML_ID_CRC32] = 'CRC32'; + $EBMLidList[EBML_ID_CUEBLOCKNUMBER] = 'CueBlockNumber'; + $EBMLidList[EBML_ID_CUECLUSTERPOSITION] = 'CueClusterPosition'; + $EBMLidList[EBML_ID_CUECODECSTATE] = 'CueCodecState'; + $EBMLidList[EBML_ID_CUEPOINT] = 'CuePoint'; + $EBMLidList[EBML_ID_CUEREFCLUSTER] = 'CueRefCluster'; + $EBMLidList[EBML_ID_CUEREFCODECSTATE] = 'CueRefCodecState'; + $EBMLidList[EBML_ID_CUEREFERENCE] = 'CueReference'; + $EBMLidList[EBML_ID_CUEREFNUMBER] = 'CueRefNumber'; + $EBMLidList[EBML_ID_CUEREFTIME] = 'CueRefTime'; + $EBMLidList[EBML_ID_CUES] = 'Cues'; + $EBMLidList[EBML_ID_CUETIME] = 'CueTime'; + $EBMLidList[EBML_ID_CUETRACK] = 'CueTrack'; + $EBMLidList[EBML_ID_CUETRACKPOSITIONS] = 'CueTrackPositions'; + $EBMLidList[EBML_ID_DATEUTC] = 'DateUTC'; + $EBMLidList[EBML_ID_DEFAULTDURATION] = 'DefaultDuration'; + $EBMLidList[EBML_ID_DISPLAYHEIGHT] = 'DisplayHeight'; + $EBMLidList[EBML_ID_DISPLAYUNIT] = 'DisplayUnit'; + $EBMLidList[EBML_ID_DISPLAYWIDTH] = 'DisplayWidth'; + $EBMLidList[EBML_ID_DOCTYPE] = 'DocType'; + $EBMLidList[EBML_ID_DOCTYPEREADVERSION] = 'DocTypeReadVersion'; + $EBMLidList[EBML_ID_DOCTYPEVERSION] = 'DocTypeVersion'; + $EBMLidList[EBML_ID_DURATION] = 'Duration'; + $EBMLidList[EBML_ID_EBML] = 'EBML'; + $EBMLidList[EBML_ID_EBMLMAXIDLENGTH] = 'EBMLMaxIDLength'; + $EBMLidList[EBML_ID_EBMLMAXSIZELENGTH] = 'EBMLMaxSizeLength'; + $EBMLidList[EBML_ID_EBMLREADVERSION] = 'EBMLReadVersion'; + $EBMLidList[EBML_ID_EBMLVERSION] = 'EBMLVersion'; + $EBMLidList[EBML_ID_EDITIONENTRY] = 'EditionEntry'; + $EBMLidList[EBML_ID_EDITIONFLAGDEFAULT] = 'EditionFlagDefault'; + $EBMLidList[EBML_ID_EDITIONFLAGHIDDEN] = 'EditionFlagHidden'; + $EBMLidList[EBML_ID_EDITIONFLAGORDERED] = 'EditionFlagOrdered'; + $EBMLidList[EBML_ID_EDITIONUID] = 'EditionUID'; + $EBMLidList[EBML_ID_FILEDATA] = 'FileData'; + $EBMLidList[EBML_ID_FILEDESCRIPTION] = 'FileDescription'; + $EBMLidList[EBML_ID_FILEMIMETYPE] = 'FileMimeType'; + $EBMLidList[EBML_ID_FILENAME] = 'FileName'; + $EBMLidList[EBML_ID_FILEREFERRAL] = 'FileReferral'; + $EBMLidList[EBML_ID_FILEUID] = 'FileUID'; + $EBMLidList[EBML_ID_FLAGDEFAULT] = 'FlagDefault'; + $EBMLidList[EBML_ID_FLAGENABLED] = 'FlagEnabled'; + $EBMLidList[EBML_ID_FLAGFORCED] = 'FlagForced'; + $EBMLidList[EBML_ID_FLAGINTERLACED] = 'FlagInterlaced'; + $EBMLidList[EBML_ID_FLAGLACING] = 'FlagLacing'; + $EBMLidList[EBML_ID_GAMMAVALUE] = 'GammaValue'; + $EBMLidList[EBML_ID_INFO] = 'Info'; + $EBMLidList[EBML_ID_LANGUAGE] = 'Language'; + $EBMLidList[EBML_ID_MAXBLOCKADDITIONID] = 'MaxBlockAdditionID'; + $EBMLidList[EBML_ID_MAXCACHE] = 'MaxCache'; + $EBMLidList[EBML_ID_MINCACHE] = 'MinCache'; + $EBMLidList[EBML_ID_MUXINGAPP] = 'MuxingApp'; + $EBMLidList[EBML_ID_NAME] = 'Name'; + $EBMLidList[EBML_ID_NEXTFILENAME] = 'NextFilename'; + $EBMLidList[EBML_ID_NEXTUID] = 'NextUID'; + $EBMLidList[EBML_ID_OUTPUTSAMPLINGFREQUENCY] = 'OutputSamplingFrequency'; + $EBMLidList[EBML_ID_PIXELCROPBOTTOM] = 'PixelCropBottom'; + $EBMLidList[EBML_ID_PIXELCROPLEFT] = 'PixelCropLeft'; + $EBMLidList[EBML_ID_PIXELCROPRIGHT] = 'PixelCropRight'; + $EBMLidList[EBML_ID_PIXELCROPTOP] = 'PixelCropTop'; + $EBMLidList[EBML_ID_PIXELHEIGHT] = 'PixelHeight'; + $EBMLidList[EBML_ID_PIXELWIDTH] = 'PixelWidth'; + $EBMLidList[EBML_ID_PREVFILENAME] = 'PrevFilename'; + $EBMLidList[EBML_ID_PREVUID] = 'PrevUID'; + $EBMLidList[EBML_ID_SAMPLINGFREQUENCY] = 'SamplingFrequency'; + $EBMLidList[EBML_ID_SEEK] = 'Seek'; + $EBMLidList[EBML_ID_SEEKHEAD] = 'SeekHead'; + $EBMLidList[EBML_ID_SEEKID] = 'SeekID'; + $EBMLidList[EBML_ID_SEEKPOSITION] = 'SeekPosition'; + $EBMLidList[EBML_ID_SEGMENT] = 'Segment'; + $EBMLidList[EBML_ID_SEGMENTFAMILY] = 'SegmentFamily'; + $EBMLidList[EBML_ID_SEGMENTFILENAME] = 'SegmentFilename'; + $EBMLidList[EBML_ID_SEGMENTUID] = 'SegmentUID'; + $EBMLidList[EBML_ID_SIMPLETAG] = 'SimpleTag'; + $EBMLidList[EBML_ID_CLUSTERSLICES] = 'ClusterSlices'; + $EBMLidList[EBML_ID_STEREOMODE] = 'StereoMode'; + $EBMLidList[EBML_ID_OLDSTEREOMODE] = 'OldStereoMode'; + $EBMLidList[EBML_ID_TAG] = 'Tag'; + $EBMLidList[EBML_ID_TAGATTACHMENTUID] = 'TagAttachmentUID'; + $EBMLidList[EBML_ID_TAGBINARY] = 'TagBinary'; + $EBMLidList[EBML_ID_TAGCHAPTERUID] = 'TagChapterUID'; + $EBMLidList[EBML_ID_TAGDEFAULT] = 'TagDefault'; + $EBMLidList[EBML_ID_TAGEDITIONUID] = 'TagEditionUID'; + $EBMLidList[EBML_ID_TAGLANGUAGE] = 'TagLanguage'; + $EBMLidList[EBML_ID_TAGNAME] = 'TagName'; + $EBMLidList[EBML_ID_TAGTRACKUID] = 'TagTrackUID'; + $EBMLidList[EBML_ID_TAGS] = 'Tags'; + $EBMLidList[EBML_ID_TAGSTRING] = 'TagString'; + $EBMLidList[EBML_ID_TARGETS] = 'Targets'; + $EBMLidList[EBML_ID_TARGETTYPE] = 'TargetType'; + $EBMLidList[EBML_ID_TARGETTYPEVALUE] = 'TargetTypeValue'; + $EBMLidList[EBML_ID_TIMECODESCALE] = 'TimecodeScale'; + $EBMLidList[EBML_ID_TITLE] = 'Title'; + $EBMLidList[EBML_ID_TRACKENTRY] = 'TrackEntry'; + $EBMLidList[EBML_ID_TRACKNUMBER] = 'TrackNumber'; + $EBMLidList[EBML_ID_TRACKOFFSET] = 'TrackOffset'; + $EBMLidList[EBML_ID_TRACKOVERLAY] = 'TrackOverlay'; + $EBMLidList[EBML_ID_TRACKS] = 'Tracks'; + $EBMLidList[EBML_ID_TRACKTIMECODESCALE] = 'TrackTimecodeScale'; + $EBMLidList[EBML_ID_TRACKTRANSLATE] = 'TrackTranslate'; + $EBMLidList[EBML_ID_TRACKTRANSLATECODEC] = 'TrackTranslateCodec'; + $EBMLidList[EBML_ID_TRACKTRANSLATEEDITIONUID] = 'TrackTranslateEditionUID'; + $EBMLidList[EBML_ID_TRACKTRANSLATETRACKID] = 'TrackTranslateTrackID'; + $EBMLidList[EBML_ID_TRACKTYPE] = 'TrackType'; + $EBMLidList[EBML_ID_TRACKUID] = 'TrackUID'; + $EBMLidList[EBML_ID_VIDEO] = 'Video'; + $EBMLidList[EBML_ID_VOID] = 'Void'; + $EBMLidList[EBML_ID_WRITINGAPP] = 'WritingApp'; + } + + return isset($EBMLidList[$value]) ? $EBMLidList[$value] : dechex($value); + } + + public static function displayUnit($value) + { + // http://www.matroska.org/technical/specs/index.html#DisplayUnit + static $units = [ + 0 => 'pixels', + 1 => 'centimeters', + 2 => 'inches', + 3 => 'Display Aspect Ratio', ]; + + return isset($units[$value]) ? $units[$value] : 'unknown'; + } + + private static function getDefaultStreamInfo($streams) + { + foreach (array_reverse($streams) as $stream) { + if ($stream['default']) { + break; + } + } + + $unset = ['default', 'name']; + foreach ($unset as $u) { + if (isset($stream[$u])) { + unset($stream[$u]); + } + } + + $info = $stream; + $info['streams'] = $streams; + + return $info; + } } diff --git a/app/Library/getid3/getid3/module.audio-video.mpeg.php b/app/Library/getid3/getid3/module.audio-video.mpeg.php index 044481fb..f6b495a7 100644 --- a/app/Library/getid3/getid3/module.audio-video.mpeg.php +++ b/app/Library/getid3/getid3/module.audio-video.mpeg.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -16,591 +17,601 @@ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); -class getid3_mpeg extends getid3_handler { +class getid3_mpeg extends getid3_handler +{ + const START_CODE_BASE = "\x00\x00\x01"; + const VIDEO_PICTURE_START = "\x00\x00\x01\x00"; + const VIDEO_USER_DATA_START = "\x00\x00\x01\xB2"; + const VIDEO_SEQUENCE_HEADER = "\x00\x00\x01\xB3"; + const VIDEO_SEQUENCE_ERROR = "\x00\x00\x01\xB4"; + const VIDEO_EXTENSION_START = "\x00\x00\x01\xB5"; + const VIDEO_SEQUENCE_END = "\x00\x00\x01\xB7"; + const VIDEO_GROUP_START = "\x00\x00\x01\xB8"; + const AUDIO_START = "\x00\x00\x01\xC0"; - const START_CODE_BASE = "\x00\x00\x01"; - const VIDEO_PICTURE_START = "\x00\x00\x01\x00"; - const VIDEO_USER_DATA_START = "\x00\x00\x01\xB2"; - const VIDEO_SEQUENCE_HEADER = "\x00\x00\x01\xB3"; - const VIDEO_SEQUENCE_ERROR = "\x00\x00\x01\xB4"; - const VIDEO_EXTENSION_START = "\x00\x00\x01\xB5"; - const VIDEO_SEQUENCE_END = "\x00\x00\x01\xB7"; - const VIDEO_GROUP_START = "\x00\x00\x01\xB8"; - const AUDIO_START = "\x00\x00\x01\xC0"; + public function Analyze() + { + $info = &$this->getid3->info; + $info['fileformat'] = 'mpeg'; + $this->fseek($info['avdataoffset']); - public function Analyze() { - $info = &$this->getid3->info; + $MPEGstreamData = $this->fread($this->getid3->option_fread_buffer_size); + $MPEGstreamBaseOffset = 0; // how far are we from the beginning of the file data ($info['avdataoffset']) + $MPEGstreamDataOffset = 0; // how far are we from the beginning of the buffer data (~32kB) - $info['fileformat'] = 'mpeg'; - $this->fseek($info['avdataoffset']); + $StartCodeValue = false; + $prevStartCodeValue = false; - $MPEGstreamData = $this->fread($this->getid3->option_fread_buffer_size); - $MPEGstreamBaseOffset = 0; // how far are we from the beginning of the file data ($info['avdataoffset']) - $MPEGstreamDataOffset = 0; // how far are we from the beginning of the buffer data (~32kB) + $GOPcounter = -1; + $FramesByGOP = []; + $ParsedAVchannels = []; - $StartCodeValue = false; - $prevStartCodeValue = false; + do { + //echo $MPEGstreamDataOffset.' vs '.(strlen($MPEGstreamData) - 1024).'
    '; + if ($MPEGstreamDataOffset > (strlen($MPEGstreamData) - 16384)) { + // buffer running low, get more data + //echo 'reading more data
    '; + $MPEGstreamData .= $this->fread($this->getid3->option_fread_buffer_size); + if (strlen($MPEGstreamData) > $this->getid3->option_fread_buffer_size) { + $MPEGstreamData = substr($MPEGstreamData, $MPEGstreamDataOffset); + $MPEGstreamBaseOffset += $MPEGstreamDataOffset; + $MPEGstreamDataOffset = 0; + } + } + if (($StartCodeOffset = strpos($MPEGstreamData, self::START_CODE_BASE, $MPEGstreamDataOffset)) === false) { + //echo 'no more start codes found.
    '; + break; + } else { + $MPEGstreamDataOffset = $StartCodeOffset; + $prevStartCodeValue = $StartCodeValue; + $StartCodeValue = ord(substr($MPEGstreamData, $StartCodeOffset + 3, 1)); + //echo 'Found "'.strtoupper(dechex($StartCodeValue)).'" at offset '.($MPEGstreamBaseOffset + $StartCodeOffset).' ($MPEGstreamDataOffset = '.$MPEGstreamDataOffset.')
    '; + } + $MPEGstreamDataOffset += 4; + switch ($StartCodeValue) { - $GOPcounter = -1; - $FramesByGOP = array(); - $ParsedAVchannels = array(); + case 0x00: // picture_start_code + if (! empty($info['mpeg']['video']['bitrate_mode']) && ($info['mpeg']['video']['bitrate_mode'] == 'vbr')) { + $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 4)); + $bitstreamoffset = 0; - do { -//echo $MPEGstreamDataOffset.' vs '.(strlen($MPEGstreamData) - 1024).'
    '; - if ($MPEGstreamDataOffset > (strlen($MPEGstreamData) - 16384)) { - // buffer running low, get more data -//echo 'reading more data
    '; - $MPEGstreamData .= $this->fread($this->getid3->option_fread_buffer_size); - if (strlen($MPEGstreamData) > $this->getid3->option_fread_buffer_size) { - $MPEGstreamData = substr($MPEGstreamData, $MPEGstreamDataOffset); - $MPEGstreamBaseOffset += $MPEGstreamDataOffset; - $MPEGstreamDataOffset = 0; - } - } - if (($StartCodeOffset = strpos($MPEGstreamData, self::START_CODE_BASE, $MPEGstreamDataOffset)) === false) { -//echo 'no more start codes found.
    '; - break; - } else { - $MPEGstreamDataOffset = $StartCodeOffset; - $prevStartCodeValue = $StartCodeValue; - $StartCodeValue = ord(substr($MPEGstreamData, $StartCodeOffset + 3, 1)); -//echo 'Found "'.strtoupper(dechex($StartCodeValue)).'" at offset '.($MPEGstreamBaseOffset + $StartCodeOffset).' ($MPEGstreamDataOffset = '.$MPEGstreamDataOffset.')
    '; - } - $MPEGstreamDataOffset += 4; - switch ($StartCodeValue) { + $PictureHeader = []; - case 0x00: // picture_start_code - if (!empty($info['mpeg']['video']['bitrate_mode']) && ($info['mpeg']['video']['bitrate_mode'] == 'vbr')) { - $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 4)); - $bitstreamoffset = 0; + $PictureHeader['temporal_reference'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 10); // 10-bit unsigned integer associated with each input picture. It is incremented by one, modulo 1024, for each input frame. When a frame is coded as two fields the temporal reference in the picture header of both fields is the same. Following a group start header the temporal reference of the earliest picture (in display order) shall be reset to zero. + $PictureHeader['picture_coding_type'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for picture_coding_type + $PictureHeader['vbv_delay'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 16); // 16 bits for vbv_delay + //... etc - $PictureHeader = array(); + $FramesByGOP[$GOPcounter][] = $PictureHeader; + } + break; - $PictureHeader['temporal_reference'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 10); // 10-bit unsigned integer associated with each input picture. It is incremented by one, modulo 1024, for each input frame. When a frame is coded as two fields the temporal reference in the picture header of both fields is the same. Following a group start header the temporal reference of the earliest picture (in display order) shall be reset to zero. - $PictureHeader['picture_coding_type'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for picture_coding_type - $PictureHeader['vbv_delay'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 16); // 16 bits for vbv_delay - //... etc + case 0xB3: // sequence_header_code + /* + Note: purposely doing the less-pretty (and probably a bit slower) method of using string of bits rather than bitwise operations. + Mostly because PHP 32-bit doesn't handle unsigned integers well for bitwise operation. + Also the MPEG stream is designed as a bitstream and often doesn't align nicely with byte boundaries. + */ + $info['video']['codec'] = 'MPEG-1'; // will be updated if extension_start_code found - $FramesByGOP[$GOPcounter][] = $PictureHeader; - } - break; + $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 8)); + $bitstreamoffset = 0; - case 0xB3: // sequence_header_code - /* - Note: purposely doing the less-pretty (and probably a bit slower) method of using string of bits rather than bitwise operations. - Mostly because PHP 32-bit doesn't handle unsigned integers well for bitwise operation. - Also the MPEG stream is designed as a bitstream and often doesn't align nicely with byte boundaries. - */ - $info['video']['codec'] = 'MPEG-1'; // will be updated if extension_start_code found + $info['mpeg']['video']['raw']['horizontal_size_value'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 12); // 12 bits for horizontal frame size. Note: horizontal_size_extension, if present, will add 2 most-significant bits to this value + $info['mpeg']['video']['raw']['vertical_size_value'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 12); // 12 bits for vertical frame size. Note: vertical_size_extension, if present, will add 2 most-significant bits to this value + $info['mpeg']['video']['raw']['aspect_ratio_information'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for aspect_ratio_information + $info['mpeg']['video']['raw']['frame_rate_code'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for Frame Rate id code + $info['mpeg']['video']['raw']['bitrate'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 18); // 18 bits for bit_rate_value (18 set bits = VBR, otherwise bitrate = this value * 400) + $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. + $info['mpeg']['video']['raw']['vbv_buffer_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 10); // 10 bits vbv_buffer_size_value + $info['mpeg']['video']['raw']['constrained_param_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: constrained_param_flag + $info['mpeg']['video']['raw']['load_intra_quantiser_matrix'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: load_intra_quantiser_matrix - $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 8)); - $bitstreamoffset = 0; + if ($info['mpeg']['video']['raw']['load_intra_quantiser_matrix']) { + $bitstream .= getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 12, 64)); + for ($i = 0; $i < 64; $i++) { + $info['mpeg']['video']['raw']['intra_quantiser_matrix'][$i] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); + } + } + $info['mpeg']['video']['raw']['load_non_intra_quantiser_matrix'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); - $info['mpeg']['video']['raw']['horizontal_size_value'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 12); // 12 bits for horizontal frame size. Note: horizontal_size_extension, if present, will add 2 most-significant bits to this value - $info['mpeg']['video']['raw']['vertical_size_value'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 12); // 12 bits for vertical frame size. Note: vertical_size_extension, if present, will add 2 most-significant bits to this value - $info['mpeg']['video']['raw']['aspect_ratio_information'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for aspect_ratio_information - $info['mpeg']['video']['raw']['frame_rate_code'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for Frame Rate id code - $info['mpeg']['video']['raw']['bitrate'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 18); // 18 bits for bit_rate_value (18 set bits = VBR, otherwise bitrate = this value * 400) - $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. - $info['mpeg']['video']['raw']['vbv_buffer_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 10); // 10 bits vbv_buffer_size_value - $info['mpeg']['video']['raw']['constrained_param_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: constrained_param_flag - $info['mpeg']['video']['raw']['load_intra_quantiser_matrix'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: load_intra_quantiser_matrix + if ($info['mpeg']['video']['raw']['load_non_intra_quantiser_matrix']) { + $bitstream .= getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 12 + ($info['mpeg']['video']['raw']['load_intra_quantiser_matrix'] ? 64 : 0), 64)); + for ($i = 0; $i < 64; $i++) { + $info['mpeg']['video']['raw']['non_intra_quantiser_matrix'][$i] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); + } + } - if ($info['mpeg']['video']['raw']['load_intra_quantiser_matrix']) { - $bitstream .= getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 12, 64)); - for ($i = 0; $i < 64; $i++) { - $info['mpeg']['video']['raw']['intra_quantiser_matrix'][$i] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); - } - } - $info['mpeg']['video']['raw']['load_non_intra_quantiser_matrix'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); + $info['mpeg']['video']['pixel_aspect_ratio'] = self::videoAspectRatioLookup($info['mpeg']['video']['raw']['aspect_ratio_information']); + $info['mpeg']['video']['pixel_aspect_ratio_text'] = self::videoAspectRatioTextLookup($info['mpeg']['video']['raw']['aspect_ratio_information']); + $info['mpeg']['video']['frame_rate'] = self::videoFramerateLookup($info['mpeg']['video']['raw']['frame_rate_code']); + if ($info['mpeg']['video']['raw']['bitrate'] == 0x3FFFF) { // 18 set bits = VBR + //$this->warning('This version of getID3() ['.$this->getid3->version().'] cannot determine average bitrate of VBR MPEG video files'); + $info['mpeg']['video']['bitrate_mode'] = 'vbr'; + } else { + $info['mpeg']['video']['bitrate'] = $info['mpeg']['video']['raw']['bitrate'] * 400; + $info['mpeg']['video']['bitrate_mode'] = 'cbr'; + $info['video']['bitrate'] = $info['mpeg']['video']['bitrate']; + } + $info['video']['resolution_x'] = $info['mpeg']['video']['raw']['horizontal_size_value']; + $info['video']['resolution_y'] = $info['mpeg']['video']['raw']['vertical_size_value']; + $info['video']['frame_rate'] = $info['mpeg']['video']['frame_rate']; + $info['video']['bitrate_mode'] = $info['mpeg']['video']['bitrate_mode']; + $info['video']['pixel_aspect_ratio'] = $info['mpeg']['video']['pixel_aspect_ratio']; + $info['video']['lossless'] = false; + $info['video']['bits_per_sample'] = 24; + break; - if ($info['mpeg']['video']['raw']['load_non_intra_quantiser_matrix']) { - $bitstream .= getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 12 + ($info['mpeg']['video']['raw']['load_intra_quantiser_matrix'] ? 64 : 0), 64)); - for ($i = 0; $i < 64; $i++) { - $info['mpeg']['video']['raw']['non_intra_quantiser_matrix'][$i] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); - } - } + case 0xB5: // extension_start_code + $info['video']['codec'] = 'MPEG-2'; - $info['mpeg']['video']['pixel_aspect_ratio'] = self::videoAspectRatioLookup($info['mpeg']['video']['raw']['aspect_ratio_information']); - $info['mpeg']['video']['pixel_aspect_ratio_text'] = self::videoAspectRatioTextLookup($info['mpeg']['video']['raw']['aspect_ratio_information']); - $info['mpeg']['video']['frame_rate'] = self::videoFramerateLookup($info['mpeg']['video']['raw']['frame_rate_code']); - if ($info['mpeg']['video']['raw']['bitrate'] == 0x3FFFF) { // 18 set bits = VBR - //$this->warning('This version of getID3() ['.$this->getid3->version().'] cannot determine average bitrate of VBR MPEG video files'); - $info['mpeg']['video']['bitrate_mode'] = 'vbr'; - } else { - $info['mpeg']['video']['bitrate'] = $info['mpeg']['video']['raw']['bitrate'] * 400; - $info['mpeg']['video']['bitrate_mode'] = 'cbr'; - $info['video']['bitrate'] = $info['mpeg']['video']['bitrate']; - } - $info['video']['resolution_x'] = $info['mpeg']['video']['raw']['horizontal_size_value']; - $info['video']['resolution_y'] = $info['mpeg']['video']['raw']['vertical_size_value']; - $info['video']['frame_rate'] = $info['mpeg']['video']['frame_rate']; - $info['video']['bitrate_mode'] = $info['mpeg']['video']['bitrate_mode']; - $info['video']['pixel_aspect_ratio'] = $info['mpeg']['video']['pixel_aspect_ratio']; - $info['video']['lossless'] = false; - $info['video']['bits_per_sample'] = 24; - break; + $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 8)); // 48 bits for Sequence Extension ID; 61 bits for Sequence Display Extension ID; 59 bits for Sequence Scalable Extension ID + $bitstreamoffset = 0; - case 0xB5: // extension_start_code - $info['video']['codec'] = 'MPEG-2'; - - $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 8)); // 48 bits for Sequence Extension ID; 61 bits for Sequence Display Extension ID; 59 bits for Sequence Scalable Extension ID - $bitstreamoffset = 0; - - $info['mpeg']['video']['raw']['extension_start_code_identifier'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for extension_start_code_identifier + $info['mpeg']['video']['raw']['extension_start_code_identifier'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for extension_start_code_identifier //echo $info['mpeg']['video']['raw']['extension_start_code_identifier'].'
    '; - switch ($info['mpeg']['video']['raw']['extension_start_code_identifier']) { - case 1: // 0001 Sequence Extension ID - $info['mpeg']['video']['raw']['profile_and_level_indication'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for profile_and_level_indication - $info['mpeg']['video']['raw']['progressive_sequence'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: progressive_sequence - $info['mpeg']['video']['raw']['chroma_format'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for chroma_format - $info['mpeg']['video']['raw']['horizontal_size_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for horizontal_size_extension - $info['mpeg']['video']['raw']['vertical_size_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for vertical_size_extension - $info['mpeg']['video']['raw']['bit_rate_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 12); // 12 bits for bit_rate_extension - $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. - $info['mpeg']['video']['raw']['vbv_buffer_size_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for vbv_buffer_size_extension - $info['mpeg']['video']['raw']['low_delay'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: low_delay - $info['mpeg']['video']['raw']['frame_rate_extension_n'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for frame_rate_extension_n - $info['mpeg']['video']['raw']['frame_rate_extension_d'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for frame_rate_extension_d + switch ($info['mpeg']['video']['raw']['extension_start_code_identifier']) { + case 1: // 0001 Sequence Extension ID + $info['mpeg']['video']['raw']['profile_and_level_indication'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for profile_and_level_indication + $info['mpeg']['video']['raw']['progressive_sequence'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: progressive_sequence + $info['mpeg']['video']['raw']['chroma_format'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for chroma_format + $info['mpeg']['video']['raw']['horizontal_size_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for horizontal_size_extension + $info['mpeg']['video']['raw']['vertical_size_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for vertical_size_extension + $info['mpeg']['video']['raw']['bit_rate_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 12); // 12 bits for bit_rate_extension + $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. + $info['mpeg']['video']['raw']['vbv_buffer_size_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for vbv_buffer_size_extension + $info['mpeg']['video']['raw']['low_delay'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: low_delay + $info['mpeg']['video']['raw']['frame_rate_extension_n'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for frame_rate_extension_n + $info['mpeg']['video']['raw']['frame_rate_extension_d'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for frame_rate_extension_d - $info['video']['resolution_x'] = ($info['mpeg']['video']['raw']['horizontal_size_extension'] << 12) | $info['mpeg']['video']['raw']['horizontal_size_value']; - $info['video']['resolution_y'] = ($info['mpeg']['video']['raw']['vertical_size_extension'] << 12) | $info['mpeg']['video']['raw']['vertical_size_value']; - $info['video']['interlaced'] = !$info['mpeg']['video']['raw']['progressive_sequence']; - $info['mpeg']['video']['interlaced'] = !$info['mpeg']['video']['raw']['progressive_sequence']; - $info['mpeg']['video']['chroma_format'] = self::chromaFormatTextLookup($info['mpeg']['video']['raw']['chroma_format']); - break; + $info['video']['resolution_x'] = ($info['mpeg']['video']['raw']['horizontal_size_extension'] << 12) | $info['mpeg']['video']['raw']['horizontal_size_value']; + $info['video']['resolution_y'] = ($info['mpeg']['video']['raw']['vertical_size_extension'] << 12) | $info['mpeg']['video']['raw']['vertical_size_value']; + $info['video']['interlaced'] = ! $info['mpeg']['video']['raw']['progressive_sequence']; + $info['mpeg']['video']['interlaced'] = ! $info['mpeg']['video']['raw']['progressive_sequence']; + $info['mpeg']['video']['chroma_format'] = self::chromaFormatTextLookup($info['mpeg']['video']['raw']['chroma_format']); + break; - case 2: // 0010 Sequence Display Extension ID - $info['mpeg']['video']['raw']['video_format'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for video_format - $info['mpeg']['video']['raw']['colour_description'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: colour_description - if ($info['mpeg']['video']['raw']['colour_description']) { - $info['mpeg']['video']['raw']['colour_primaries'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for colour_primaries - $info['mpeg']['video']['raw']['transfer_characteristics'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for transfer_characteristics - $info['mpeg']['video']['raw']['matrix_coefficients'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for matrix_coefficients - } - $info['mpeg']['video']['raw']['display_horizontal_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for display_horizontal_size - $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. - $info['mpeg']['video']['raw']['display_vertical_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for display_vertical_size + case 2: // 0010 Sequence Display Extension ID + $info['mpeg']['video']['raw']['video_format'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for video_format + $info['mpeg']['video']['raw']['colour_description'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: colour_description + if ($info['mpeg']['video']['raw']['colour_description']) { + $info['mpeg']['video']['raw']['colour_primaries'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for colour_primaries + $info['mpeg']['video']['raw']['transfer_characteristics'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for transfer_characteristics + $info['mpeg']['video']['raw']['matrix_coefficients'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for matrix_coefficients + } + $info['mpeg']['video']['raw']['display_horizontal_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for display_horizontal_size + $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. + $info['mpeg']['video']['raw']['display_vertical_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for display_vertical_size - $info['mpeg']['video']['video_format'] = self::videoFormatTextLookup($info['mpeg']['video']['raw']['video_format']); - break; + $info['mpeg']['video']['video_format'] = self::videoFormatTextLookup($info['mpeg']['video']['raw']['video_format']); + break; - case 3: // 0011 Quant Matrix Extension ID - break; + case 3: // 0011 Quant Matrix Extension ID + break; - case 5: // 0101 Sequence Scalable Extension ID - $info['mpeg']['video']['raw']['scalable_mode'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for scalable_mode - $info['mpeg']['video']['raw']['layer_id'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for layer_id - if ($info['mpeg']['video']['raw']['scalable_mode'] == 1) { // "spatial scalability" - $info['mpeg']['video']['raw']['lower_layer_prediction_horizontal_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for lower_layer_prediction_horizontal_size - $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. - $info['mpeg']['video']['raw']['lower_layer_prediction_vertical_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for lower_layer_prediction_vertical_size - $info['mpeg']['video']['raw']['horizontal_subsampling_factor_m'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for horizontal_subsampling_factor_m - $info['mpeg']['video']['raw']['horizontal_subsampling_factor_n'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for horizontal_subsampling_factor_n - $info['mpeg']['video']['raw']['vertical_subsampling_factor_m'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for vertical_subsampling_factor_m - $info['mpeg']['video']['raw']['vertical_subsampling_factor_n'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for vertical_subsampling_factor_n - } elseif ($info['mpeg']['video']['raw']['scalable_mode'] == 3) { // "temporal scalability" - $info['mpeg']['video']['raw']['picture_mux_enable'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: picture_mux_enable - if ($info['mpeg']['video']['raw']['picture_mux_enable']) { - $info['mpeg']['video']['raw']['mux_to_progressive_sequence'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: mux_to_progressive_sequence - } - $info['mpeg']['video']['raw']['picture_mux_order'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for picture_mux_order - $info['mpeg']['video']['raw']['picture_mux_factor'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for picture_mux_factor - } + case 5: // 0101 Sequence Scalable Extension ID + $info['mpeg']['video']['raw']['scalable_mode'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for scalable_mode + $info['mpeg']['video']['raw']['layer_id'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for layer_id + if ($info['mpeg']['video']['raw']['scalable_mode'] == 1) { // "spatial scalability" + $info['mpeg']['video']['raw']['lower_layer_prediction_horizontal_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for lower_layer_prediction_horizontal_size + $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. + $info['mpeg']['video']['raw']['lower_layer_prediction_vertical_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for lower_layer_prediction_vertical_size + $info['mpeg']['video']['raw']['horizontal_subsampling_factor_m'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for horizontal_subsampling_factor_m + $info['mpeg']['video']['raw']['horizontal_subsampling_factor_n'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for horizontal_subsampling_factor_n + $info['mpeg']['video']['raw']['vertical_subsampling_factor_m'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for vertical_subsampling_factor_m + $info['mpeg']['video']['raw']['vertical_subsampling_factor_n'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for vertical_subsampling_factor_n + } elseif ($info['mpeg']['video']['raw']['scalable_mode'] == 3) { // "temporal scalability" + $info['mpeg']['video']['raw']['picture_mux_enable'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: picture_mux_enable + if ($info['mpeg']['video']['raw']['picture_mux_enable']) { + $info['mpeg']['video']['raw']['mux_to_progressive_sequence'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: mux_to_progressive_sequence + } + $info['mpeg']['video']['raw']['picture_mux_order'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for picture_mux_order + $info['mpeg']['video']['raw']['picture_mux_factor'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for picture_mux_factor + } - $info['mpeg']['video']['scalable_mode'] = self::scalableModeTextLookup($info['mpeg']['video']['raw']['scalable_mode']); - break; + $info['mpeg']['video']['scalable_mode'] = self::scalableModeTextLookup($info['mpeg']['video']['raw']['scalable_mode']); + break; - case 7: // 0111 Picture Display Extension ID - break; + case 7: // 0111 Picture Display Extension ID + break; - case 8: // 1000 Picture Coding Extension ID - $info['mpeg']['video']['raw']['f_code_00'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[0][0] (forward horizontal) - $info['mpeg']['video']['raw']['f_code_01'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[0][1] (forward vertical) - $info['mpeg']['video']['raw']['f_code_10'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[1][0] (backward horizontal) - $info['mpeg']['video']['raw']['f_code_11'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[1][1] (backward vertical) - $info['mpeg']['video']['raw']['intra_dc_precision'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for intra_dc_precision - $info['mpeg']['video']['raw']['picture_structure'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for picture_structure - $info['mpeg']['video']['raw']['top_field_first'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: top_field_first - $info['mpeg']['video']['raw']['frame_pred_frame_dct'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: frame_pred_frame_dct - $info['mpeg']['video']['raw']['concealment_motion_vectors'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: concealment_motion_vectors - $info['mpeg']['video']['raw']['q_scale_type'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: q_scale_type - $info['mpeg']['video']['raw']['intra_vlc_format'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: intra_vlc_format - $info['mpeg']['video']['raw']['alternate_scan'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: alternate_scan - $info['mpeg']['video']['raw']['repeat_first_field'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: repeat_first_field - $info['mpeg']['video']['raw']['chroma_420_type'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: chroma_420_type - $info['mpeg']['video']['raw']['progressive_frame'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: progressive_frame - $info['mpeg']['video']['raw']['composite_display_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: composite_display_flag - if ($info['mpeg']['video']['raw']['composite_display_flag']) { - $info['mpeg']['video']['raw']['v_axis'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: v_axis - $info['mpeg']['video']['raw']['field_sequence'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for field_sequence - $info['mpeg']['video']['raw']['sub_carrier'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: sub_carrier - $info['mpeg']['video']['raw']['burst_amplitude'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 7); // 7 bits for burst_amplitude - $info['mpeg']['video']['raw']['sub_carrier_phase'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for sub_carrier_phase - } + case 8: // 1000 Picture Coding Extension ID + $info['mpeg']['video']['raw']['f_code_00'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[0][0] (forward horizontal) + $info['mpeg']['video']['raw']['f_code_01'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[0][1] (forward vertical) + $info['mpeg']['video']['raw']['f_code_10'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[1][0] (backward horizontal) + $info['mpeg']['video']['raw']['f_code_11'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[1][1] (backward vertical) + $info['mpeg']['video']['raw']['intra_dc_precision'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for intra_dc_precision + $info['mpeg']['video']['raw']['picture_structure'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for picture_structure + $info['mpeg']['video']['raw']['top_field_first'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: top_field_first + $info['mpeg']['video']['raw']['frame_pred_frame_dct'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: frame_pred_frame_dct + $info['mpeg']['video']['raw']['concealment_motion_vectors'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: concealment_motion_vectors + $info['mpeg']['video']['raw']['q_scale_type'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: q_scale_type + $info['mpeg']['video']['raw']['intra_vlc_format'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: intra_vlc_format + $info['mpeg']['video']['raw']['alternate_scan'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: alternate_scan + $info['mpeg']['video']['raw']['repeat_first_field'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: repeat_first_field + $info['mpeg']['video']['raw']['chroma_420_type'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: chroma_420_type + $info['mpeg']['video']['raw']['progressive_frame'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: progressive_frame + $info['mpeg']['video']['raw']['composite_display_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: composite_display_flag + if ($info['mpeg']['video']['raw']['composite_display_flag']) { + $info['mpeg']['video']['raw']['v_axis'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: v_axis + $info['mpeg']['video']['raw']['field_sequence'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for field_sequence + $info['mpeg']['video']['raw']['sub_carrier'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: sub_carrier + $info['mpeg']['video']['raw']['burst_amplitude'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 7); // 7 bits for burst_amplitude + $info['mpeg']['video']['raw']['sub_carrier_phase'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for sub_carrier_phase + } - $info['mpeg']['video']['intra_dc_precision_bits'] = $info['mpeg']['video']['raw']['intra_dc_precision'] + 8; - $info['mpeg']['video']['picture_structure'] = self::pictureStructureTextLookup($info['mpeg']['video']['raw']['picture_structure']); - break; + $info['mpeg']['video']['intra_dc_precision_bits'] = $info['mpeg']['video']['raw']['intra_dc_precision'] + 8; + $info['mpeg']['video']['picture_structure'] = self::pictureStructureTextLookup($info['mpeg']['video']['raw']['picture_structure']); + break; - case 9: // 1001 Picture Spatial Scalable Extension ID - break; - case 10: // 1010 Picture Temporal Scalable Extension ID - break; + case 9: // 1001 Picture Spatial Scalable Extension ID + break; + case 10: // 1010 Picture Temporal Scalable Extension ID + break; - default: - $this->warning('Unexpected $info[mpeg][video][raw][extension_start_code_identifier] value of '.$info['mpeg']['video']['raw']['extension_start_code_identifier']); - break; - } - break; + default: + $this->warning('Unexpected $info[mpeg][video][raw][extension_start_code_identifier] value of '.$info['mpeg']['video']['raw']['extension_start_code_identifier']); + break; + } + break; + case 0xB8: // group_of_pictures_header + $GOPcounter++; + if ($info['mpeg']['video']['bitrate_mode'] == 'vbr') { + $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 4)); // 27 bits needed for group_of_pictures_header + $bitstreamoffset = 0; - case 0xB8: // group_of_pictures_header - $GOPcounter++; - if ($info['mpeg']['video']['bitrate_mode'] == 'vbr') { - $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 4)); // 27 bits needed for group_of_pictures_header - $bitstreamoffset = 0; + $GOPheader = []; - $GOPheader = array(); + $GOPheader['byte_offset'] = $MPEGstreamBaseOffset + $StartCodeOffset; + $GOPheader['drop_frame_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: drop_frame_flag + $GOPheader['time_code_hours'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for time_code_hours + $GOPheader['time_code_minutes'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 6); // 6 bits for time_code_minutes + $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. + $GOPheader['time_code_seconds'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 6); // 6 bits for time_code_seconds + $GOPheader['time_code_pictures'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 6); // 6 bits for time_code_pictures + $GOPheader['closed_gop'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: closed_gop + $GOPheader['broken_link'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: broken_link - $GOPheader['byte_offset'] = $MPEGstreamBaseOffset + $StartCodeOffset; - $GOPheader['drop_frame_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: drop_frame_flag - $GOPheader['time_code_hours'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for time_code_hours - $GOPheader['time_code_minutes'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 6); // 6 bits for time_code_minutes - $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. - $GOPheader['time_code_seconds'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 6); // 6 bits for time_code_seconds - $GOPheader['time_code_pictures'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 6); // 6 bits for time_code_pictures - $GOPheader['closed_gop'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: closed_gop - $GOPheader['broken_link'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: broken_link + $time_code_separator = ($GOPheader['drop_frame_flag'] ? ';' : ':'); // While non-drop time code is displayed with colons separating the digit pairs—"HH:MM:SS:FF"—drop frame is usually represented with a semi-colon (;) or period (.) as the divider between all the digit pairs—"HH;MM;SS;FF", "HH.MM.SS.FF" + $GOPheader['time_code'] = sprintf('%02d'.$time_code_separator.'%02d'.$time_code_separator.'%02d'.$time_code_separator.'%02d', $GOPheader['time_code_hours'], $GOPheader['time_code_minutes'], $GOPheader['time_code_seconds'], $GOPheader['time_code_pictures']); - $time_code_separator = ($GOPheader['drop_frame_flag'] ? ';' : ':'); // While non-drop time code is displayed with colons separating the digit pairs—"HH:MM:SS:FF"—drop frame is usually represented with a semi-colon (;) or period (.) as the divider between all the digit pairs—"HH;MM;SS;FF", "HH.MM.SS.FF" - $GOPheader['time_code'] = sprintf('%02d'.$time_code_separator.'%02d'.$time_code_separator.'%02d'.$time_code_separator.'%02d', $GOPheader['time_code_hours'], $GOPheader['time_code_minutes'], $GOPheader['time_code_seconds'], $GOPheader['time_code_pictures']); + $info['mpeg']['group_of_pictures'][] = $GOPheader; + } + break; - $info['mpeg']['group_of_pictures'][] = $GOPheader; - } - break; - - case 0xC0: // audio stream - case 0xC1: // audio stream - case 0xC2: // audio stream - case 0xC3: // audio stream - case 0xC4: // audio stream - case 0xC5: // audio stream - case 0xC6: // audio stream - case 0xC7: // audio stream - case 0xC8: // audio stream - case 0xC9: // audio stream - case 0xCA: // audio stream - case 0xCB: // audio stream - case 0xCC: // audio stream - case 0xCD: // audio stream - case 0xCE: // audio stream - case 0xCF: // audio stream - case 0xD0: // audio stream - case 0xD1: // audio stream - case 0xD2: // audio stream - case 0xD3: // audio stream - case 0xD4: // audio stream - case 0xD5: // audio stream - case 0xD6: // audio stream - case 0xD7: // audio stream - case 0xD8: // audio stream - case 0xD9: // audio stream - case 0xDA: // audio stream - case 0xDB: // audio stream - case 0xDC: // audio stream - case 0xDD: // audio stream - case 0xDE: // audio stream - case 0xDF: // audio stream - //case 0xE0: // video stream - //case 0xE1: // video stream - //case 0xE2: // video stream - //case 0xE3: // video stream - //case 0xE4: // video stream - //case 0xE5: // video stream - //case 0xE6: // video stream - //case 0xE7: // video stream - //case 0xE8: // video stream - //case 0xE9: // video stream - //case 0xEA: // video stream - //case 0xEB: // video stream - //case 0xEC: // video stream - //case 0xED: // video stream - //case 0xEE: // video stream - //case 0xEF: // video stream - if (isset($ParsedAVchannels[$StartCodeValue])) { - break; - } - $ParsedAVchannels[$StartCodeValue] = $StartCodeValue; - // http://en.wikipedia.org/wiki/Packetized_elementary_stream - // http://dvd.sourceforge.net/dvdinfo/pes-hdr.html + case 0xC0: // audio stream + case 0xC1: // audio stream + case 0xC2: // audio stream + case 0xC3: // audio stream + case 0xC4: // audio stream + case 0xC5: // audio stream + case 0xC6: // audio stream + case 0xC7: // audio stream + case 0xC8: // audio stream + case 0xC9: // audio stream + case 0xCA: // audio stream + case 0xCB: // audio stream + case 0xCC: // audio stream + case 0xCD: // audio stream + case 0xCE: // audio stream + case 0xCF: // audio stream + case 0xD0: // audio stream + case 0xD1: // audio stream + case 0xD2: // audio stream + case 0xD3: // audio stream + case 0xD4: // audio stream + case 0xD5: // audio stream + case 0xD6: // audio stream + case 0xD7: // audio stream + case 0xD8: // audio stream + case 0xD9: // audio stream + case 0xDA: // audio stream + case 0xDB: // audio stream + case 0xDC: // audio stream + case 0xDD: // audio stream + case 0xDE: // audio stream + case 0xDF: // audio stream + //case 0xE0: // video stream + //case 0xE1: // video stream + //case 0xE2: // video stream + //case 0xE3: // video stream + //case 0xE4: // video stream + //case 0xE5: // video stream + //case 0xE6: // video stream + //case 0xE7: // video stream + //case 0xE8: // video stream + //case 0xE9: // video stream + //case 0xEA: // video stream + //case 0xEB: // video stream + //case 0xEC: // video stream + //case 0xED: // video stream + //case 0xEE: // video stream + //case 0xEF: // video stream + if (isset($ParsedAVchannels[$StartCodeValue])) { + break; + } + $ParsedAVchannels[$StartCodeValue] = $StartCodeValue; + // http://en.wikipedia.org/wiki/Packetized_elementary_stream + // http://dvd.sourceforge.net/dvdinfo/pes-hdr.html /* - $PackedElementaryStream = array(); - if ($StartCodeValue >= 0xE0) { - $PackedElementaryStream['stream_type'] = 'video'; - $PackedElementaryStream['stream_id'] = $StartCodeValue - 0xE0; - } else { - $PackedElementaryStream['stream_type'] = 'audio'; - $PackedElementaryStream['stream_id'] = $StartCodeValue - 0xC0; - } - $PackedElementaryStream['packet_length'] = getid3_lib::BigEndian2Int(substr($MPEGstreamData, $StartCodeOffset + 4, 2)); + $PackedElementaryStream = array(); + if ($StartCodeValue >= 0xE0) { + $PackedElementaryStream['stream_type'] = 'video'; + $PackedElementaryStream['stream_id'] = $StartCodeValue - 0xE0; + } else { + $PackedElementaryStream['stream_type'] = 'audio'; + $PackedElementaryStream['stream_id'] = $StartCodeValue - 0xC0; + } + $PackedElementaryStream['packet_length'] = getid3_lib::BigEndian2Int(substr($MPEGstreamData, $StartCodeOffset + 4, 2)); - $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 6, 3)); // more may be needed below - $bitstreamoffset = 0; + $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 6, 3)); // more may be needed below + $bitstreamoffset = 0; - $PackedElementaryStream['marker_bits'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for marker_bits -- should be "10" = 2 + $PackedElementaryStream['marker_bits'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for marker_bits -- should be "10" = 2 echo 'marker_bits = '.$PackedElementaryStream['marker_bits'].'
    '; - $PackedElementaryStream['scrambling_control'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for scrambling_control -- 00 implies not scrambled - $PackedElementaryStream['priority'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: priority - $PackedElementaryStream['data_alignment_indicator'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: data_alignment_indicator -- 1 indicates that the PES packet header is immediately followed by the video start code or audio syncword - $PackedElementaryStream['copyright'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: copyright -- 1 implies copyrighted - $PackedElementaryStream['original_or_copy'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: original_or_copy -- 1 implies original - $PackedElementaryStream['pts_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: pts_flag -- Presentation Time Stamp - $PackedElementaryStream['dts_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: dts_flag -- Decode Time Stamp - $PackedElementaryStream['escr_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: escr_flag -- Elementary Stream Clock Reference - $PackedElementaryStream['es_rate_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: es_rate_flag -- Elementary Stream [data] Rate - $PackedElementaryStream['dsm_trick_mode_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: dsm_trick_mode_flag -- DSM trick mode - not used by DVD - $PackedElementaryStream['additional_copy_info_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: additional_copy_info_flag - $PackedElementaryStream['crc_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: crc_flag - $PackedElementaryStream['extension_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: extension_flag - $PackedElementaryStream['pes_remain_header_length'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 1 bit flag: priority + $PackedElementaryStream['scrambling_control'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for scrambling_control -- 00 implies not scrambled + $PackedElementaryStream['priority'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: priority + $PackedElementaryStream['data_alignment_indicator'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: data_alignment_indicator -- 1 indicates that the PES packet header is immediately followed by the video start code or audio syncword + $PackedElementaryStream['copyright'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: copyright -- 1 implies copyrighted + $PackedElementaryStream['original_or_copy'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: original_or_copy -- 1 implies original + $PackedElementaryStream['pts_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: pts_flag -- Presentation Time Stamp + $PackedElementaryStream['dts_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: dts_flag -- Decode Time Stamp + $PackedElementaryStream['escr_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: escr_flag -- Elementary Stream Clock Reference + $PackedElementaryStream['es_rate_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: es_rate_flag -- Elementary Stream [data] Rate + $PackedElementaryStream['dsm_trick_mode_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: dsm_trick_mode_flag -- DSM trick mode - not used by DVD + $PackedElementaryStream['additional_copy_info_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: additional_copy_info_flag + $PackedElementaryStream['crc_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: crc_flag + $PackedElementaryStream['extension_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: extension_flag + $PackedElementaryStream['pes_remain_header_length'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 1 bit flag: priority - $additional_header_bytes = 0; - $additional_header_bytes += ($PackedElementaryStream['pts_flag'] ? 5 : 0); - $additional_header_bytes += ($PackedElementaryStream['dts_flag'] ? 5 : 0); - $additional_header_bytes += ($PackedElementaryStream['escr_flag'] ? 6 : 0); - $additional_header_bytes += ($PackedElementaryStream['es_rate_flag'] ? 3 : 0); - $additional_header_bytes += ($PackedElementaryStream['additional_copy_info_flag'] ? 1 : 0); - $additional_header_bytes += ($PackedElementaryStream['crc_flag'] ? 2 : 0); - $additional_header_bytes += ($PackedElementaryStream['extension_flag'] ? 1 : 0); + $additional_header_bytes = 0; + $additional_header_bytes += ($PackedElementaryStream['pts_flag'] ? 5 : 0); + $additional_header_bytes += ($PackedElementaryStream['dts_flag'] ? 5 : 0); + $additional_header_bytes += ($PackedElementaryStream['escr_flag'] ? 6 : 0); + $additional_header_bytes += ($PackedElementaryStream['es_rate_flag'] ? 3 : 0); + $additional_header_bytes += ($PackedElementaryStream['additional_copy_info_flag'] ? 1 : 0); + $additional_header_bytes += ($PackedElementaryStream['crc_flag'] ? 2 : 0); + $additional_header_bytes += ($PackedElementaryStream['extension_flag'] ? 1 : 0); $PackedElementaryStream['additional_header_bytes'] = $additional_header_bytes; - $bitstream .= getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 9, $additional_header_bytes)); + $bitstream .= getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 9, $additional_header_bytes)); - $info['mpeg']['packed_elementary_streams'][$PackedElementaryStream['stream_type']][$PackedElementaryStream['stream_id']][] = $PackedElementaryStream; + $info['mpeg']['packed_elementary_streams'][$PackedElementaryStream['stream_type']][$PackedElementaryStream['stream_id']][] = $PackedElementaryStream; */ - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_temp->info = $info; - $getid3_mp3 = new getid3_mp3($getid3_temp); - for ($i = 0; $i <= 7; $i++) { - // some files have the MPEG-audio header 8 bytes after the end of the $00 $00 $01 $C0 signature, some have it up to 13 bytes (or more?) after - // I have no idea why or what the difference is, so this is a stupid hack. - // If anybody has any better idea of what's going on, please let me know - info@getid3.org - $getid3_temp->info = $info; // only overwrite real data if valid header found + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_temp->info = $info; + $getid3_mp3 = new getid3_mp3($getid3_temp); + for ($i = 0; $i <= 7; $i++) { + // some files have the MPEG-audio header 8 bytes after the end of the $00 $00 $01 $C0 signature, some have it up to 13 bytes (or more?) after + // I have no idea why or what the difference is, so this is a stupid hack. + // If anybody has any better idea of what's going on, please let me know - info@getid3.org + $getid3_temp->info = $info; // only overwrite real data if valid header found //echo 'audio at? '.($MPEGstreamBaseOffset + $StartCodeOffset + 4 + 8 + $i).'
    '; - if ($getid3_mp3->decodeMPEGaudioHeader($MPEGstreamBaseOffset + $StartCodeOffset + 4 + 8 + $i, $getid3_temp->info, false)) { -//echo 'yes!
    '; - $info = $getid3_temp->info; - $info['audio']['bitrate_mode'] = 'cbr'; - $info['audio']['lossless'] = false; - break; - } - } - unset($getid3_temp, $getid3_mp3); - break; + if ($getid3_mp3->decodeMPEGaudioHeader($MPEGstreamBaseOffset + $StartCodeOffset + 4 + 8 + $i, $getid3_temp->info, false)) { + //echo 'yes!
    '; + $info = $getid3_temp->info; + $info['audio']['bitrate_mode'] = 'cbr'; + $info['audio']['lossless'] = false; + break; + } + } + unset($getid3_temp, $getid3_mp3); + break; - case 0xBC: // Program Stream Map - case 0xBD: // Private stream 1 (non MPEG audio, subpictures) - case 0xBE: // Padding stream - case 0xBF: // Private stream 2 (navigation data) - case 0xF0: // ECM stream - case 0xF1: // EMM stream - case 0xF2: // DSM-CC stream - case 0xF3: // ISO/IEC_13522_stream - case 0xF4: // ITU-I Rec. H.222.1 type A - case 0xF5: // ITU-I Rec. H.222.1 type B - case 0xF6: // ITU-I Rec. H.222.1 type C - case 0xF7: // ITU-I Rec. H.222.1 type D - case 0xF8: // ITU-I Rec. H.222.1 type E - case 0xF9: // ancilliary stream - case 0xFA: // ISO/IEC 14496-1 SL-packtized stream - case 0xFB: // ISO/IEC 14496-1 FlexMux stream - case 0xFC: // metadata stream - case 0xFD: // extended stream ID - case 0xFE: // reserved data stream - case 0xFF: // program stream directory - // ignore - break; + case 0xBC: // Program Stream Map + case 0xBD: // Private stream 1 (non MPEG audio, subpictures) + case 0xBE: // Padding stream + case 0xBF: // Private stream 2 (navigation data) + case 0xF0: // ECM stream + case 0xF1: // EMM stream + case 0xF2: // DSM-CC stream + case 0xF3: // ISO/IEC_13522_stream + case 0xF4: // ITU-I Rec. H.222.1 type A + case 0xF5: // ITU-I Rec. H.222.1 type B + case 0xF6: // ITU-I Rec. H.222.1 type C + case 0xF7: // ITU-I Rec. H.222.1 type D + case 0xF8: // ITU-I Rec. H.222.1 type E + case 0xF9: // ancilliary stream + case 0xFA: // ISO/IEC 14496-1 SL-packtized stream + case 0xFB: // ISO/IEC 14496-1 FlexMux stream + case 0xFC: // metadata stream + case 0xFD: // extended stream ID + case 0xFE: // reserved data stream + case 0xFF: // program stream directory + // ignore + break; - default: - // ignore - break; - } - } while (true); + default: + // ignore + break; + } + } while (true); - - -// // Temporary hack to account for interleaving overhead: -// if (!empty($info['video']['bitrate']) && !empty($info['audio']['bitrate'])) { -// $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / ($info['video']['bitrate'] + $info['audio']['bitrate']); + // // Temporary hack to account for interleaving overhead: + // if (!empty($info['video']['bitrate']) && !empty($info['audio']['bitrate'])) { + // $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / ($info['video']['bitrate'] + $info['audio']['bitrate']); // -// // Interleaved MPEG audio/video files have a certain amount of overhead that varies -// // by both video and audio bitrates, and not in any sensible, linear/logarithmic pattern -// // Use interpolated lookup tables to approximately guess how much is overhead, because -// // playtime is calculated as filesize / total-bitrate -// $info['playtime_seconds'] *= self::systemNonOverheadPercentage($info['video']['bitrate'], $info['audio']['bitrate']); + // // Interleaved MPEG audio/video files have a certain amount of overhead that varies + // // by both video and audio bitrates, and not in any sensible, linear/logarithmic pattern + // // Use interpolated lookup tables to approximately guess how much is overhead, because + // // playtime is calculated as filesize / total-bitrate + // $info['playtime_seconds'] *= self::systemNonOverheadPercentage($info['video']['bitrate'], $info['audio']['bitrate']); // -// //switch ($info['video']['bitrate']) { -// // case('5000000'): -// // $multiplier = 0.93292642112380355828048824319889; -// // break; -// // case('5500000'): -// // $multiplier = 0.93582895375200989965359777343219; -// // break; -// // case('6000000'): -// // $multiplier = 0.93796247714820932532911373859139; -// // break; -// // case('7000000'): -// // $multiplier = 0.9413264083635103463010117778776; -// // break; -// // default: -// // $multiplier = 1; -// // break; -// //} -// //$info['playtime_seconds'] *= $multiplier; -// //$this->warning('Interleaved MPEG audio/video playtime may be inaccurate. With current hack should be within a few seconds of accurate. Report to info@getid3.org if off by more than 10 seconds.'); -// if ($info['video']['bitrate'] < 50000) { -// $this->warning('Interleaved MPEG audio/video playtime may be slightly inaccurate for video bitrates below 100kbps. Except in extreme low-bitrate situations, error should be less than 1%. Report to info@getid3.org if greater than this.'); -// } -// } + // //switch ($info['video']['bitrate']) { + // // case('5000000'): + // // $multiplier = 0.93292642112380355828048824319889; + // // break; + // // case('5500000'): + // // $multiplier = 0.93582895375200989965359777343219; + // // break; + // // case('6000000'): + // // $multiplier = 0.93796247714820932532911373859139; + // // break; + // // case('7000000'): + // // $multiplier = 0.9413264083635103463010117778776; + // // break; + // // default: + // // $multiplier = 1; + // // break; + // //} + // //$info['playtime_seconds'] *= $multiplier; + // //$this->warning('Interleaved MPEG audio/video playtime may be inaccurate. With current hack should be within a few seconds of accurate. Report to info@getid3.org if off by more than 10 seconds.'); + // if ($info['video']['bitrate'] < 50000) { + // $this->warning('Interleaved MPEG audio/video playtime may be slightly inaccurate for video bitrates below 100kbps. Except in extreme low-bitrate situations, error should be less than 1%. Report to info@getid3.org if greater than this.'); + // } + // } // -/* -$time_prev = 0; -$byte_prev = 0; -$vbr_bitrates = array(); -foreach ($info['mpeg']['group_of_pictures'] as $gopkey => $gopdata) { - $time_this = ($gopdata['time_code_hours'] * 3600) + ($gopdata['time_code_minutes'] * 60) + $gopdata['time_code_seconds'] + ($gopdata['time_code_seconds'] / 30); - $byte_this = $gopdata['byte_offset']; - if ($gopkey > 0) { - if ($time_this > $time_prev) { - $bytedelta = $byte_this - $byte_prev; - $timedelta = $time_this - $time_prev; - $this_bitrate = ($bytedelta * 8) / $timedelta; -echo $gopkey.': ('.number_format($time_prev, 2).'-'.number_format($time_this, 2).') '.number_format($bytedelta).' bytes over '.number_format($timedelta, 3).' seconds = '.number_format($this_bitrate / 1000, 2).'kbps
    '; - $time_prev = $time_this; - $byte_prev = $byte_this; - $vbr_bitrates[] = $this_bitrate; - } - } + /* + $time_prev = 0; + $byte_prev = 0; + $vbr_bitrates = array(); + foreach ($info['mpeg']['group_of_pictures'] as $gopkey => $gopdata) { + $time_this = ($gopdata['time_code_hours'] * 3600) + ($gopdata['time_code_minutes'] * 60) + $gopdata['time_code_seconds'] + ($gopdata['time_code_seconds'] / 30); + $byte_this = $gopdata['byte_offset']; + if ($gopkey > 0) { + if ($time_this > $time_prev) { + $bytedelta = $byte_this - $byte_prev; + $timedelta = $time_this - $time_prev; + $this_bitrate = ($bytedelta * 8) / $timedelta; + echo $gopkey.': ('.number_format($time_prev, 2).'-'.number_format($time_this, 2).') '.number_format($bytedelta).' bytes over '.number_format($timedelta, 3).' seconds = '.number_format($this_bitrate / 1000, 2).'kbps
    '; + $time_prev = $time_this; + $byte_prev = $byte_this; + $vbr_bitrates[] = $this_bitrate; + } + } + } + echo 'average_File_bitrate = '.number_format(array_sum($vbr_bitrates) / count($vbr_bitrates), 1).'
    '; + */ + //echo '
    '.print_r($FramesByGOP, true).'
    '; + if (! empty($info['mpeg']['video']['bitrate_mode']) && ($info['mpeg']['video']['bitrate_mode'] == 'vbr')) { + $last_GOP_id = max(array_keys($FramesByGOP)); + $frames_in_last_GOP = count($FramesByGOP[$last_GOP_id]); + $gopdata = &$info['mpeg']['group_of_pictures'][$last_GOP_id]; + $info['playtime_seconds'] = ($gopdata['time_code_hours'] * 3600) + ($gopdata['time_code_minutes'] * 60) + $gopdata['time_code_seconds'] + (($gopdata['time_code_pictures'] + $frames_in_last_GOP + 1) / $info['mpeg']['video']['frame_rate']); + if (! isset($info['video']['bitrate'])) { + $overall_bitrate = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['playtime_seconds']; + $info['video']['bitrate'] = $overall_bitrate - (isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : 0); + } + unset($info['mpeg']['group_of_pictures']); + } + + return true; + } + + private function readBitsFromStream(&$bitstream, &$bitstreamoffset, $bits_to_read, $return_singlebit_as_boolean = true) + { + $return = bindec(substr($bitstream, $bitstreamoffset, $bits_to_read)); + $bitstreamoffset += $bits_to_read; + if (($bits_to_read == 1) && $return_singlebit_as_boolean) { + $return = (bool) $return; + } + + return $return; + } + + public static function systemNonOverheadPercentage($VideoBitrate, $AudioBitrate) + { + $OverheadPercentage = 0; + + $AudioBitrate = max(min($AudioBitrate / 1000, 384), 32); // limit to range of 32kbps - 384kbps (should be only legal bitrates, but maybe VBR?) + $VideoBitrate = max(min($VideoBitrate / 1000, 10000), 10); // limit to range of 10kbps - 10Mbps (beyond that curves flatten anyways, no big loss) + + //OMBB[audiobitrate] = array(video-10kbps, video-100kbps, video-1000kbps, video-10000kbps) + $OverheadMultiplierByBitrate[32] = [0, 0.9676287944368530, 0.9802276264360310, 0.9844916183244460, 0.9852821845179940]; + $OverheadMultiplierByBitrate[48] = [0, 0.9779100089209830, 0.9787770035359320, 0.9846738664076130, 0.9852683013799960]; + $OverheadMultiplierByBitrate[56] = [0, 0.9731249855367600, 0.9776624308938040, 0.9832606361852130, 0.9843922606633340]; + $OverheadMultiplierByBitrate[64] = [0, 0.9755642683275760, 0.9795256705493390, 0.9836573009193170, 0.9851122539404470]; + $OverheadMultiplierByBitrate[96] = [0, 0.9788025247497290, 0.9798553314148700, 0.9822956869792560, 0.9834815119124690]; + $OverheadMultiplierByBitrate[128] = [0, 0.9816940050925480, 0.9821675936072120, 0.9829756927470870, 0.9839763420152050]; + $OverheadMultiplierByBitrate[160] = [0, 0.9825894094561180, 0.9820913399073960, 0.9823907143253970, 0.9832821783651570]; + $OverheadMultiplierByBitrate[192] = [0, 0.9832038474336260, 0.9825731694317960, 0.9821028622712400, 0.9828262076447620]; + $OverheadMultiplierByBitrate[224] = [0, 0.9836516298538770, 0.9824718601823890, 0.9818302180625380, 0.9823735101626480]; + $OverheadMultiplierByBitrate[256] = [0, 0.9845863022094920, 0.9837229411967540, 0.9824521662210830, 0.9828645172100790]; + $OverheadMultiplierByBitrate[320] = [0, 0.9849565280263180, 0.9837683142805110, 0.9822885275960400, 0.9824424382727190]; + $OverheadMultiplierByBitrate[384] = [0, 0.9856094774357600, 0.9844573394432720, 0.9825970399837330, 0.9824673808303890]; + + $BitrateToUseMin = 32; + $BitrateToUseMax = 32; + $previousBitrate = 32; + foreach ($OverheadMultiplierByBitrate as $key => $value) { + if ($AudioBitrate >= $previousBitrate) { + $BitrateToUseMin = $previousBitrate; + } + if ($AudioBitrate < $key) { + $BitrateToUseMax = $key; + break; + } + $previousBitrate = $key; + } + $FactorA = ($BitrateToUseMax - $AudioBitrate) / ($BitrateToUseMax - $BitrateToUseMin); + + $VideoBitrateLog10 = log10($VideoBitrate); + $VideoFactorMin1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][floor($VideoBitrateLog10)]; + $VideoFactorMin2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][floor($VideoBitrateLog10)]; + $VideoFactorMax1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][ceil($VideoBitrateLog10)]; + $VideoFactorMax2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][ceil($VideoBitrateLog10)]; + $FactorV = $VideoBitrateLog10 - floor($VideoBitrateLog10); + + $OverheadPercentage = $VideoFactorMin1 * $FactorA * $FactorV; + $OverheadPercentage += $VideoFactorMin2 * (1 - $FactorA) * $FactorV; + $OverheadPercentage += $VideoFactorMax1 * $FactorA * (1 - $FactorV); + $OverheadPercentage += $VideoFactorMax2 * (1 - $FactorA) * (1 - $FactorV); + + return $OverheadPercentage; + } + + public static function videoFramerateLookup($rawframerate) + { + $lookup = [0, 23.976, 24, 25, 29.97, 30, 50, 59.94, 60]; + + return isset($lookup[$rawframerate]) ? (float) $lookup[$rawframerate] : (float) 0; + } + + public static function videoAspectRatioLookup($rawaspectratio) + { + $lookup = [0, 1, 0.6735, 0.7031, 0.7615, 0.8055, 0.8437, 0.8935, 0.9157, 0.9815, 1.0255, 1.0695, 1.0950, 1.1575, 1.2015, 0]; + + return isset($lookup[$rawaspectratio]) ? (float) $lookup[$rawaspectratio] : (float) 0; + } + + public static function videoAspectRatioTextLookup($rawaspectratio) + { + $lookup = ['forbidden', 'square pixels', '0.6735', '16:9, 625 line, PAL', '0.7615', '0.8055', '16:9, 525 line, NTSC', '0.8935', '4:3, 625 line, PAL, CCIR601', '0.9815', '1.0255', '1.0695', '4:3, 525 line, NTSC, CCIR601', '1.1575', '1.2015', 'reserved']; + + return isset($lookup[$rawaspectratio]) ? $lookup[$rawaspectratio] : ''; + } + + public static function videoFormatTextLookup($video_format) + { + // ISO/IEC 13818-2, section 6.3.6, Table 6-6. Meaning of video_format + $lookup = ['component', 'PAL', 'NTSC', 'SECAM', 'MAC', 'Unspecified video format', 'reserved(6)', 'reserved(7)']; + + return isset($lookup[$video_format]) ? $lookup[$video_format] : ''; + } + + public static function scalableModeTextLookup($scalable_mode) + { + // ISO/IEC 13818-2, section 6.3.8, Table 6-10. Definition of scalable_mode + $lookup = ['data partitioning', 'spatial scalability', 'SNR scalability', 'temporal scalability']; + + return isset($lookup[$scalable_mode]) ? $lookup[$scalable_mode] : ''; + } + + public static function pictureStructureTextLookup($picture_structure) + { + // ISO/IEC 13818-2, section 6.3.11, Table 6-14 Meaning of picture_structure + $lookup = ['reserved', 'Top Field', 'Bottom Field', 'Frame picture']; + + return isset($lookup[$picture_structure]) ? $lookup[$picture_structure] : ''; + } + + public static function chromaFormatTextLookup($chroma_format) + { + // ISO/IEC 13818-2, section 6.3.11, Table 6-14 Meaning of picture_structure + $lookup = ['reserved', '4:2:0', '4:2:2', '4:4:4']; + + return isset($lookup[$chroma_format]) ? $lookup[$chroma_format] : ''; + } } -echo 'average_File_bitrate = '.number_format(array_sum($vbr_bitrates) / count($vbr_bitrates), 1).'
    '; -*/ -//echo '
    '.print_r($FramesByGOP, true).'
    '; - if (!empty($info['mpeg']['video']['bitrate_mode']) && ($info['mpeg']['video']['bitrate_mode'] == 'vbr')) { - $last_GOP_id = max(array_keys($FramesByGOP)); - $frames_in_last_GOP = count($FramesByGOP[$last_GOP_id]); - $gopdata = &$info['mpeg']['group_of_pictures'][$last_GOP_id]; - $info['playtime_seconds'] = ($gopdata['time_code_hours'] * 3600) + ($gopdata['time_code_minutes'] * 60) + $gopdata['time_code_seconds'] + (($gopdata['time_code_pictures'] + $frames_in_last_GOP + 1) / $info['mpeg']['video']['frame_rate']); - if (!isset($info['video']['bitrate'])) { - $overall_bitrate = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['playtime_seconds']; - $info['video']['bitrate'] = $overall_bitrate - (isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : 0); - } - unset($info['mpeg']['group_of_pictures']); - } - - return true; - } - - private function readBitsFromStream(&$bitstream, &$bitstreamoffset, $bits_to_read, $return_singlebit_as_boolean=true) { - $return = bindec(substr($bitstream, $bitstreamoffset, $bits_to_read)); - $bitstreamoffset += $bits_to_read; - if (($bits_to_read == 1) && $return_singlebit_as_boolean) { - $return = (bool) $return; - } - return $return; - } - - - public static function systemNonOverheadPercentage($VideoBitrate, $AudioBitrate) { - $OverheadPercentage = 0; - - $AudioBitrate = max(min($AudioBitrate / 1000, 384), 32); // limit to range of 32kbps - 384kbps (should be only legal bitrates, but maybe VBR?) - $VideoBitrate = max(min($VideoBitrate / 1000, 10000), 10); // limit to range of 10kbps - 10Mbps (beyond that curves flatten anyways, no big loss) - - - //OMBB[audiobitrate] = array(video-10kbps, video-100kbps, video-1000kbps, video-10000kbps) - $OverheadMultiplierByBitrate[32] = array(0, 0.9676287944368530, 0.9802276264360310, 0.9844916183244460, 0.9852821845179940); - $OverheadMultiplierByBitrate[48] = array(0, 0.9779100089209830, 0.9787770035359320, 0.9846738664076130, 0.9852683013799960); - $OverheadMultiplierByBitrate[56] = array(0, 0.9731249855367600, 0.9776624308938040, 0.9832606361852130, 0.9843922606633340); - $OverheadMultiplierByBitrate[64] = array(0, 0.9755642683275760, 0.9795256705493390, 0.9836573009193170, 0.9851122539404470); - $OverheadMultiplierByBitrate[96] = array(0, 0.9788025247497290, 0.9798553314148700, 0.9822956869792560, 0.9834815119124690); - $OverheadMultiplierByBitrate[128] = array(0, 0.9816940050925480, 0.9821675936072120, 0.9829756927470870, 0.9839763420152050); - $OverheadMultiplierByBitrate[160] = array(0, 0.9825894094561180, 0.9820913399073960, 0.9823907143253970, 0.9832821783651570); - $OverheadMultiplierByBitrate[192] = array(0, 0.9832038474336260, 0.9825731694317960, 0.9821028622712400, 0.9828262076447620); - $OverheadMultiplierByBitrate[224] = array(0, 0.9836516298538770, 0.9824718601823890, 0.9818302180625380, 0.9823735101626480); - $OverheadMultiplierByBitrate[256] = array(0, 0.9845863022094920, 0.9837229411967540, 0.9824521662210830, 0.9828645172100790); - $OverheadMultiplierByBitrate[320] = array(0, 0.9849565280263180, 0.9837683142805110, 0.9822885275960400, 0.9824424382727190); - $OverheadMultiplierByBitrate[384] = array(0, 0.9856094774357600, 0.9844573394432720, 0.9825970399837330, 0.9824673808303890); - - $BitrateToUseMin = 32; - $BitrateToUseMax = 32; - $previousBitrate = 32; - foreach ($OverheadMultiplierByBitrate as $key => $value) { - if ($AudioBitrate >= $previousBitrate) { - $BitrateToUseMin = $previousBitrate; - } - if ($AudioBitrate < $key) { - $BitrateToUseMax = $key; - break; - } - $previousBitrate = $key; - } - $FactorA = ($BitrateToUseMax - $AudioBitrate) / ($BitrateToUseMax - $BitrateToUseMin); - - $VideoBitrateLog10 = log10($VideoBitrate); - $VideoFactorMin1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][floor($VideoBitrateLog10)]; - $VideoFactorMin2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][floor($VideoBitrateLog10)]; - $VideoFactorMax1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][ceil($VideoBitrateLog10)]; - $VideoFactorMax2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][ceil($VideoBitrateLog10)]; - $FactorV = $VideoBitrateLog10 - floor($VideoBitrateLog10); - - $OverheadPercentage = $VideoFactorMin1 * $FactorA * $FactorV; - $OverheadPercentage += $VideoFactorMin2 * (1 - $FactorA) * $FactorV; - $OverheadPercentage += $VideoFactorMax1 * $FactorA * (1 - $FactorV); - $OverheadPercentage += $VideoFactorMax2 * (1 - $FactorA) * (1 - $FactorV); - - return $OverheadPercentage; - } - - - public static function videoFramerateLookup($rawframerate) { - $lookup = array(0, 23.976, 24, 25, 29.97, 30, 50, 59.94, 60); - return (isset($lookup[$rawframerate]) ? (float) $lookup[$rawframerate] : (float) 0); - } - - public static function videoAspectRatioLookup($rawaspectratio) { - $lookup = array(0, 1, 0.6735, 0.7031, 0.7615, 0.8055, 0.8437, 0.8935, 0.9157, 0.9815, 1.0255, 1.0695, 1.0950, 1.1575, 1.2015, 0); - return (isset($lookup[$rawaspectratio]) ? (float) $lookup[$rawaspectratio] : (float) 0); - } - - public static function videoAspectRatioTextLookup($rawaspectratio) { - $lookup = array('forbidden', 'square pixels', '0.6735', '16:9, 625 line, PAL', '0.7615', '0.8055', '16:9, 525 line, NTSC', '0.8935', '4:3, 625 line, PAL, CCIR601', '0.9815', '1.0255', '1.0695', '4:3, 525 line, NTSC, CCIR601', '1.1575', '1.2015', 'reserved'); - return (isset($lookup[$rawaspectratio]) ? $lookup[$rawaspectratio] : ''); - } - - public static function videoFormatTextLookup($video_format) { - // ISO/IEC 13818-2, section 6.3.6, Table 6-6. Meaning of video_format - $lookup = array('component', 'PAL', 'NTSC', 'SECAM', 'MAC', 'Unspecified video format', 'reserved(6)', 'reserved(7)'); - return (isset($lookup[$video_format]) ? $lookup[$video_format] : ''); - } - - public static function scalableModeTextLookup($scalable_mode) { - // ISO/IEC 13818-2, section 6.3.8, Table 6-10. Definition of scalable_mode - $lookup = array('data partitioning', 'spatial scalability', 'SNR scalability', 'temporal scalability'); - return (isset($lookup[$scalable_mode]) ? $lookup[$scalable_mode] : ''); - } - - public static function pictureStructureTextLookup($picture_structure) { - // ISO/IEC 13818-2, section 6.3.11, Table 6-14 Meaning of picture_structure - $lookup = array('reserved', 'Top Field', 'Bottom Field', 'Frame picture'); - return (isset($lookup[$picture_structure]) ? $lookup[$picture_structure] : ''); - } - - public static function chromaFormatTextLookup($chroma_format) { - // ISO/IEC 13818-2, section 6.3.11, Table 6-14 Meaning of picture_structure - $lookup = array('reserved', '4:2:0', '4:2:2', '4:4:4'); - return (isset($lookup[$chroma_format]) ? $lookup[$chroma_format] : ''); - } - -} \ No newline at end of file diff --git a/app/Library/getid3/getid3/module.audio-video.nsv.php b/app/Library/getid3/getid3/module.audio-video.nsv.php index eab601b7..d2983027 100644 --- a/app/Library/getid3/getid3/module.audio-video.nsv.php +++ b/app/Library/getid3/getid3/module.audio-video.nsv.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,211 +15,216 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_nsv extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $NSVheader = $this->fread(4); - $this->fseek($info['avdataoffset']); - $NSVheader = $this->fread(4); + switch ($NSVheader) { + case 'NSVs': + if ($this->getNSVsHeaderFilepointer(0)) { + $info['fileformat'] = 'nsv'; + $info['audio']['dataformat'] = 'nsv'; + $info['video']['dataformat'] = 'nsv'; + $info['audio']['lossless'] = false; + $info['video']['lossless'] = false; + } + break; - switch ($NSVheader) { - case 'NSVs': - if ($this->getNSVsHeaderFilepointer(0)) { - $info['fileformat'] = 'nsv'; - $info['audio']['dataformat'] = 'nsv'; - $info['video']['dataformat'] = 'nsv'; - $info['audio']['lossless'] = false; - $info['video']['lossless'] = false; - } - break; + case 'NSVf': + if ($this->getNSVfHeaderFilepointer(0)) { + $info['fileformat'] = 'nsv'; + $info['audio']['dataformat'] = 'nsv'; + $info['video']['dataformat'] = 'nsv'; + $info['audio']['lossless'] = false; + $info['video']['lossless'] = false; + $this->getNSVsHeaderFilepointer($info['nsv']['NSVf']['header_length']); + } + break; - case 'NSVf': - if ($this->getNSVfHeaderFilepointer(0)) { - $info['fileformat'] = 'nsv'; - $info['audio']['dataformat'] = 'nsv'; - $info['video']['dataformat'] = 'nsv'; - $info['audio']['lossless'] = false; - $info['video']['lossless'] = false; - $this->getNSVsHeaderFilepointer($info['nsv']['NSVf']['header_length']); - } - break; + default: + $this->error('Expecting "NSVs" or "NSVf" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($NSVheader).'"'); - default: - $this->error('Expecting "NSVs" or "NSVf" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($NSVheader).'"'); - return false; - break; - } + return false; + break; + } - if (!isset($info['nsv']['NSVf'])) { - $this->warning('NSVf header not present - cannot calculate playtime or bitrate'); - } + if (! isset($info['nsv']['NSVf'])) { + $this->warning('NSVf header not present - cannot calculate playtime or bitrate'); + } - return true; - } + return true; + } - public function getNSVsHeaderFilepointer($fileoffset) { - $info = &$this->getid3->info; - $this->fseek($fileoffset); - $NSVsheader = $this->fread(28); - $offset = 0; + public function getNSVsHeaderFilepointer($fileoffset) + { + $info = &$this->getid3->info; + $this->fseek($fileoffset); + $NSVsheader = $this->fread(28); + $offset = 0; - $info['nsv']['NSVs']['identifier'] = substr($NSVsheader, $offset, 4); - $offset += 4; + $info['nsv']['NSVs']['identifier'] = substr($NSVsheader, $offset, 4); + $offset += 4; - if ($info['nsv']['NSVs']['identifier'] != 'NSVs') { - $this->error('expected "NSVs" at offset ('.$fileoffset.'), found "'.$info['nsv']['NSVs']['identifier'].'" instead'); - unset($info['nsv']['NSVs']); - return false; - } + if ($info['nsv']['NSVs']['identifier'] != 'NSVs') { + $this->error('expected "NSVs" at offset ('.$fileoffset.'), found "'.$info['nsv']['NSVs']['identifier'].'" instead'); + unset($info['nsv']['NSVs']); - $info['nsv']['NSVs']['offset'] = $fileoffset; + return false; + } - $info['nsv']['NSVs']['video_codec'] = substr($NSVsheader, $offset, 4); - $offset += 4; - $info['nsv']['NSVs']['audio_codec'] = substr($NSVsheader, $offset, 4); - $offset += 4; - $info['nsv']['NSVs']['resolution_x'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2)); - $offset += 2; - $info['nsv']['NSVs']['resolution_y'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2)); - $offset += 2; + $info['nsv']['NSVs']['offset'] = $fileoffset; - $info['nsv']['NSVs']['framerate_index'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - //$info['nsv']['NSVs']['unknown1b'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - //$info['nsv']['NSVs']['unknown1c'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - //$info['nsv']['NSVs']['unknown1d'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - //$info['nsv']['NSVs']['unknown2a'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - //$info['nsv']['NSVs']['unknown2b'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - //$info['nsv']['NSVs']['unknown2c'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - //$info['nsv']['NSVs']['unknown2d'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; + $info['nsv']['NSVs']['video_codec'] = substr($NSVsheader, $offset, 4); + $offset += 4; + $info['nsv']['NSVs']['audio_codec'] = substr($NSVsheader, $offset, 4); + $offset += 4; + $info['nsv']['NSVs']['resolution_x'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2)); + $offset += 2; + $info['nsv']['NSVs']['resolution_y'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2)); + $offset += 2; - switch ($info['nsv']['NSVs']['audio_codec']) { - case 'PCM ': - $info['nsv']['NSVs']['bits_channel'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - $info['nsv']['NSVs']['channels'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - $info['nsv']['NSVs']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2)); - $offset += 2; + $info['nsv']['NSVs']['framerate_index'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + //$info['nsv']['NSVs']['unknown1b'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + //$info['nsv']['NSVs']['unknown1c'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + //$info['nsv']['NSVs']['unknown1d'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + //$info['nsv']['NSVs']['unknown2a'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + //$info['nsv']['NSVs']['unknown2b'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + //$info['nsv']['NSVs']['unknown2c'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + //$info['nsv']['NSVs']['unknown2d'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; - $info['audio']['sample_rate'] = $info['nsv']['NSVs']['sample_rate']; - break; + switch ($info['nsv']['NSVs']['audio_codec']) { + case 'PCM ': + $info['nsv']['NSVs']['bits_channel'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + $info['nsv']['NSVs']['channels'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + $info['nsv']['NSVs']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2)); + $offset += 2; - case 'MP3 ': - case 'NONE': - default: - //$info['nsv']['NSVs']['unknown3'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 4)); - $offset += 4; - break; - } + $info['audio']['sample_rate'] = $info['nsv']['NSVs']['sample_rate']; + break; - $info['video']['resolution_x'] = $info['nsv']['NSVs']['resolution_x']; - $info['video']['resolution_y'] = $info['nsv']['NSVs']['resolution_y']; - $info['nsv']['NSVs']['frame_rate'] = $this->NSVframerateLookup($info['nsv']['NSVs']['framerate_index']); - $info['video']['frame_rate'] = $info['nsv']['NSVs']['frame_rate']; - $info['video']['bits_per_sample'] = 24; - $info['video']['pixel_aspect_ratio'] = (float) 1; + case 'MP3 ': + case 'NONE': + default: + //$info['nsv']['NSVs']['unknown3'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 4)); + $offset += 4; + break; + } - return true; - } + $info['video']['resolution_x'] = $info['nsv']['NSVs']['resolution_x']; + $info['video']['resolution_y'] = $info['nsv']['NSVs']['resolution_y']; + $info['nsv']['NSVs']['frame_rate'] = $this->NSVframerateLookup($info['nsv']['NSVs']['framerate_index']); + $info['video']['frame_rate'] = $info['nsv']['NSVs']['frame_rate']; + $info['video']['bits_per_sample'] = 24; + $info['video']['pixel_aspect_ratio'] = (float) 1; - public function getNSVfHeaderFilepointer($fileoffset, $getTOCoffsets=false) { - $info = &$this->getid3->info; - $this->fseek($fileoffset); - $NSVfheader = $this->fread(28); - $offset = 0; + return true; + } - $info['nsv']['NSVf']['identifier'] = substr($NSVfheader, $offset, 4); - $offset += 4; + public function getNSVfHeaderFilepointer($fileoffset, $getTOCoffsets = false) + { + $info = &$this->getid3->info; + $this->fseek($fileoffset); + $NSVfheader = $this->fread(28); + $offset = 0; - if ($info['nsv']['NSVf']['identifier'] != 'NSVf') { - $this->error('expected "NSVf" at offset ('.$fileoffset.'), found "'.$info['nsv']['NSVf']['identifier'].'" instead'); - unset($info['nsv']['NSVf']); - return false; - } + $info['nsv']['NSVf']['identifier'] = substr($NSVfheader, $offset, 4); + $offset += 4; - $info['nsv']['NSVs']['offset'] = $fileoffset; + if ($info['nsv']['NSVf']['identifier'] != 'NSVf') { + $this->error('expected "NSVf" at offset ('.$fileoffset.'), found "'.$info['nsv']['NSVf']['identifier'].'" instead'); + unset($info['nsv']['NSVf']); - $info['nsv']['NSVf']['header_length'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); - $offset += 4; - $info['nsv']['NSVf']['file_size'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); - $offset += 4; + return false; + } - if ($info['nsv']['NSVf']['file_size'] > $info['avdataend']) { - $this->warning('truncated file - NSVf header indicates '.$info['nsv']['NSVf']['file_size'].' bytes, file actually '.$info['avdataend'].' bytes'); - } + $info['nsv']['NSVs']['offset'] = $fileoffset; - $info['nsv']['NSVf']['playtime_ms'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); - $offset += 4; - $info['nsv']['NSVf']['meta_size'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); - $offset += 4; - $info['nsv']['NSVf']['TOC_entries_1'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); - $offset += 4; - $info['nsv']['NSVf']['TOC_entries_2'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); - $offset += 4; + $info['nsv']['NSVf']['header_length'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); + $offset += 4; + $info['nsv']['NSVf']['file_size'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); + $offset += 4; - if ($info['nsv']['NSVf']['playtime_ms'] == 0) { - $this->error('Corrupt NSV file: NSVf.playtime_ms == zero'); - return false; - } + if ($info['nsv']['NSVf']['file_size'] > $info['avdataend']) { + $this->warning('truncated file - NSVf header indicates '.$info['nsv']['NSVf']['file_size'].' bytes, file actually '.$info['avdataend'].' bytes'); + } - $NSVfheader .= $this->fread($info['nsv']['NSVf']['meta_size'] + (4 * $info['nsv']['NSVf']['TOC_entries_1']) + (4 * $info['nsv']['NSVf']['TOC_entries_2'])); - $NSVfheaderlength = strlen($NSVfheader); - $info['nsv']['NSVf']['metadata'] = substr($NSVfheader, $offset, $info['nsv']['NSVf']['meta_size']); - $offset += $info['nsv']['NSVf']['meta_size']; + $info['nsv']['NSVf']['playtime_ms'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); + $offset += 4; + $info['nsv']['NSVf']['meta_size'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); + $offset += 4; + $info['nsv']['NSVf']['TOC_entries_1'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); + $offset += 4; + $info['nsv']['NSVf']['TOC_entries_2'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); + $offset += 4; - if ($getTOCoffsets) { - $TOCcounter = 0; - while ($TOCcounter < $info['nsv']['NSVf']['TOC_entries_1']) { - if ($TOCcounter < $info['nsv']['NSVf']['TOC_entries_1']) { - $info['nsv']['NSVf']['TOC_1'][$TOCcounter] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); - $offset += 4; - $TOCcounter++; - } - } - } + if ($info['nsv']['NSVf']['playtime_ms'] == 0) { + $this->error('Corrupt NSV file: NSVf.playtime_ms == zero'); - if (trim($info['nsv']['NSVf']['metadata']) != '') { - $info['nsv']['NSVf']['metadata'] = str_replace('`', "\x01", $info['nsv']['NSVf']['metadata']); - $CommentPairArray = explode("\x01".' ', $info['nsv']['NSVf']['metadata']); - foreach ($CommentPairArray as $CommentPair) { - if (strstr($CommentPair, '='."\x01")) { - list($key, $value) = explode('='."\x01", $CommentPair, 2); - $info['nsv']['comments'][strtolower($key)][] = trim(str_replace("\x01", '', $value)); - } - } - } + return false; + } - $info['playtime_seconds'] = $info['nsv']['NSVf']['playtime_ms'] / 1000; - $info['bitrate'] = ($info['nsv']['NSVf']['file_size'] * 8) / $info['playtime_seconds']; + $NSVfheader .= $this->fread($info['nsv']['NSVf']['meta_size'] + (4 * $info['nsv']['NSVf']['TOC_entries_1']) + (4 * $info['nsv']['NSVf']['TOC_entries_2'])); + $NSVfheaderlength = strlen($NSVfheader); + $info['nsv']['NSVf']['metadata'] = substr($NSVfheader, $offset, $info['nsv']['NSVf']['meta_size']); + $offset += $info['nsv']['NSVf']['meta_size']; - return true; - } + if ($getTOCoffsets) { + $TOCcounter = 0; + while ($TOCcounter < $info['nsv']['NSVf']['TOC_entries_1']) { + if ($TOCcounter < $info['nsv']['NSVf']['TOC_entries_1']) { + $info['nsv']['NSVf']['TOC_1'][$TOCcounter] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); + $offset += 4; + $TOCcounter++; + } + } + } + if (trim($info['nsv']['NSVf']['metadata']) != '') { + $info['nsv']['NSVf']['metadata'] = str_replace('`', "\x01", $info['nsv']['NSVf']['metadata']); + $CommentPairArray = explode("\x01".' ', $info['nsv']['NSVf']['metadata']); + foreach ($CommentPairArray as $CommentPair) { + if (strstr($CommentPair, '='."\x01")) { + list($key, $value) = explode('='."\x01", $CommentPair, 2); + $info['nsv']['comments'][strtolower($key)][] = trim(str_replace("\x01", '', $value)); + } + } + } - public static function NSVframerateLookup($framerateindex) { - if ($framerateindex <= 127) { - return (float) $framerateindex; - } - static $NSVframerateLookup = array(); - if (empty($NSVframerateLookup)) { - $NSVframerateLookup[129] = (float) 29.970; - $NSVframerateLookup[131] = (float) 23.976; - $NSVframerateLookup[133] = (float) 14.985; - $NSVframerateLookup[197] = (float) 59.940; - $NSVframerateLookup[199] = (float) 47.952; - } - return (isset($NSVframerateLookup[$framerateindex]) ? $NSVframerateLookup[$framerateindex] : false); - } + $info['playtime_seconds'] = $info['nsv']['NSVf']['playtime_ms'] / 1000; + $info['bitrate'] = ($info['nsv']['NSVf']['file_size'] * 8) / $info['playtime_seconds']; + return true; + } + + public static function NSVframerateLookup($framerateindex) + { + if ($framerateindex <= 127) { + return (float) $framerateindex; + } + static $NSVframerateLookup = []; + if (empty($NSVframerateLookup)) { + $NSVframerateLookup[129] = (float) 29.970; + $NSVframerateLookup[131] = (float) 23.976; + $NSVframerateLookup[133] = (float) 14.985; + $NSVframerateLookup[197] = (float) 59.940; + $NSVframerateLookup[199] = (float) 47.952; + } + + return isset($NSVframerateLookup[$framerateindex]) ? $NSVframerateLookup[$framerateindex] : false; + } } diff --git a/app/Library/getid3/getid3/module.audio-video.quicktime.php b/app/Library/getid3/getid3/module.audio-video.quicktime.php index 2ae7c749..ca7013ac 100644 --- a/app/Library/getid3/getid3/module.audio-video.quicktime.php +++ b/app/Library/getid3/getid3/module.audio-video.quicktime.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -20,2474 +21,2471 @@ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE_ class getid3_quicktime extends getid3_handler { - - public $ReturnAtomData = true; - public $ParseAllPossibleAtoms = false; - - public function Analyze() { - $info = &$this->getid3->info; - - $info['fileformat'] = 'quicktime'; - $info['quicktime']['hinting'] = false; - $info['quicktime']['controller'] = 'standard'; // may be overridden if 'ctyp' atom is present - - $this->fseek($info['avdataoffset']); - - $offset = 0; - $atomcounter = 0; - $atom_data_read_buffer_size = max($this->getid3->option_fread_buffer_size * 1024, ($info['php_memory_limit'] ? round($info['php_memory_limit'] / 4) : 1024)); // set read buffer to 25% of PHP memory limit (if one is specified), otherwise use option_fread_buffer_size [default: 32MB] - while ($offset < $info['avdataend']) { - if (!getid3_lib::intValueSupported($offset)) { - $this->error('Unable to parse atom at offset '.$offset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions'); - break; - } - $this->fseek($offset); - $AtomHeader = $this->fread(8); - - $atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4)); - $atomname = substr($AtomHeader, 4, 4); - - // 64-bit MOV patch by jlegateØktnc*com - if ($atomsize == 1) { - $atomsize = getid3_lib::BigEndian2Int($this->fread(8)); - } - - $info['quicktime'][$atomname]['name'] = $atomname; - $info['quicktime'][$atomname]['size'] = $atomsize; - $info['quicktime'][$atomname]['offset'] = $offset; - - if (($offset + $atomsize) > $info['avdataend']) { - $this->error('Atom at offset '.$offset.' claims to go beyond end-of-file (length: '.$atomsize.' bytes)'); - return false; - } - - if ($atomsize == 0) { - // Furthermore, for historical reasons the list of atoms is optionally - // terminated by a 32-bit integer set to 0. If you are writing a program - // to read user data atoms, you should allow for the terminating 0. - break; - } - $atomHierarchy = array(); - $info['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, $this->fread(min($atomsize, $atom_data_read_buffer_size)), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms); - - $offset += $atomsize; - $atomcounter++; - } - - if (!empty($info['avdataend_tmp'])) { - // this value is assigned to a temp value and then erased because - // otherwise any atoms beyond the 'mdat' atom would not get parsed - $info['avdataend'] = $info['avdataend_tmp']; - unset($info['avdataend_tmp']); - } - - if (!empty($info['quicktime']['comments']['chapters']) && is_array($info['quicktime']['comments']['chapters']) && (count($info['quicktime']['comments']['chapters']) > 0)) { - $durations = $this->quicktime_time_to_sample_table($info); - for ($i = 0; $i < count($info['quicktime']['comments']['chapters']); $i++) { - $bookmark = array(); - $bookmark['title'] = $info['quicktime']['comments']['chapters'][$i]; - if (isset($durations[$i])) { - $bookmark['duration_sample'] = $durations[$i]['sample_duration']; - if ($i > 0) { - $bookmark['start_sample'] = $info['quicktime']['bookmarks'][($i - 1)]['start_sample'] + $info['quicktime']['bookmarks'][($i - 1)]['duration_sample']; - } else { - $bookmark['start_sample'] = 0; - } - if ($time_scale = $this->quicktime_bookmark_time_scale($info)) { - $bookmark['duration_seconds'] = $bookmark['duration_sample'] / $time_scale; - $bookmark['start_seconds'] = $bookmark['start_sample'] / $time_scale; - } - } - $info['quicktime']['bookmarks'][] = $bookmark; - } - } - - if (isset($info['quicktime']['temp_meta_key_names'])) { - unset($info['quicktime']['temp_meta_key_names']); - } - - if (!empty($info['quicktime']['comments']['location.ISO6709'])) { - // https://en.wikipedia.org/wiki/ISO_6709 - foreach ($info['quicktime']['comments']['location.ISO6709'] as $ISO6709string) { - $latitude = false; - $longitude = false; - $altitude = false; - if (preg_match('#^([\\+\\-])([0-9]{2}|[0-9]{4}|[0-9]{6})(\\.[0-9]+)?([\\+\\-])([0-9]{3}|[0-9]{5}|[0-9]{7})(\\.[0-9]+)?(([\\+\\-])([0-9]{3}|[0-9]{5}|[0-9]{7})(\\.[0-9]+)?)?/$#', $ISO6709string, $matches)) { - @list($dummy, $lat_sign, $lat_deg, $lat_deg_dec, $lon_sign, $lon_deg, $lon_deg_dec, $dummy, $alt_sign, $alt_deg, $alt_deg_dec) = $matches; - - if (strlen($lat_deg) == 2) { // [+-]DD.D - $latitude = floatval(ltrim($lat_deg, '0').$lat_deg_dec); - } elseif (strlen($lat_deg) == 4) { // [+-]DDMM.M - $latitude = floatval(ltrim(substr($lat_deg, 0, 2), '0')) + floatval(ltrim(substr($lat_deg, 2, 2), '0').$lat_deg_dec / 60); - } elseif (strlen($lat_deg) == 6) { // [+-]DDMMSS.S - $latitude = floatval(ltrim(substr($lat_deg, 0, 2), '0')) + floatval(ltrim(substr($lat_deg, 2, 2), '0') / 60) + floatval(ltrim(substr($lat_deg, 4, 2), '0').$lat_deg_dec / 3600); - } - - if (strlen($lon_deg) == 3) { // [+-]DDD.D - $longitude = floatval(ltrim($lon_deg, '0').$lon_deg_dec); - } elseif (strlen($lon_deg) == 5) { // [+-]DDDMM.M - $longitude = floatval(ltrim(substr($lon_deg, 0, 2), '0')) + floatval(ltrim(substr($lon_deg, 2, 2), '0').$lon_deg_dec / 60); - } elseif (strlen($lon_deg) == 7) { // [+-]DDDMMSS.S - $longitude = floatval(ltrim(substr($lon_deg, 0, 2), '0')) + floatval(ltrim(substr($lon_deg, 2, 2), '0') / 60) + floatval(ltrim(substr($lon_deg, 4, 2), '0').$lon_deg_dec / 3600); - } - - if (strlen($alt_deg) == 3) { // [+-]DDD.D - $altitude = floatval(ltrim($alt_deg, '0').$alt_deg_dec); - } elseif (strlen($alt_deg) == 5) { // [+-]DDDMM.M - $altitude = floatval(ltrim(substr($alt_deg, 0, 2), '0')) + floatval(ltrim(substr($alt_deg, 2, 2), '0').$alt_deg_dec / 60); - } elseif (strlen($alt_deg) == 7) { // [+-]DDDMMSS.S - $altitude = floatval(ltrim(substr($alt_deg, 0, 2), '0')) + floatval(ltrim(substr($alt_deg, 2, 2), '0') / 60) + floatval(ltrim(substr($alt_deg, 4, 2), '0').$alt_deg_dec / 3600); - } - - if ($latitude !== false) { - $info['quicktime']['comments']['gps_latitude'][] = (($lat_sign == '-') ? -1 : 1) * floatval($latitude); - } - if ($longitude !== false) { - $info['quicktime']['comments']['gps_longitude'][] = (($lon_sign == '-') ? -1 : 1) * floatval($longitude); - } - if ($altitude !== false) { - $info['quicktime']['comments']['gps_altitude'][] = (($alt_sign == '-') ? -1 : 1) * floatval($altitude); - } - } - if ($latitude === false) { - $this->warning('location.ISO6709 string not parsed correctly: "'.$ISO6709string.'", please submit as a bug'); - } - break; - } - } - - if (!isset($info['bitrate']) && isset($info['playtime_seconds'])) { - $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; - } - if (isset($info['bitrate']) && !isset($info['audio']['bitrate']) && !isset($info['quicktime']['video'])) { - $info['audio']['bitrate'] = $info['bitrate']; - } - if (!empty($info['playtime_seconds']) && !isset($info['video']['frame_rate']) && !empty($info['quicktime']['stts_framecount'])) { - foreach ($info['quicktime']['stts_framecount'] as $key => $samples_count) { - $samples_per_second = $samples_count / $info['playtime_seconds']; - if ($samples_per_second > 240) { - // has to be audio samples - } else { - $info['video']['frame_rate'] = $samples_per_second; - break; - } - } - } - if ($info['audio']['dataformat'] == 'mp4') { - $info['fileformat'] = 'mp4'; - if (empty($info['video']['resolution_x'])) { - $info['mime_type'] = 'audio/mp4'; - unset($info['video']['dataformat']); - } else { - $info['mime_type'] = 'video/mp4'; - } - } - - if (!$this->ReturnAtomData) { - unset($info['quicktime']['moov']); - } - - if (empty($info['audio']['dataformat']) && !empty($info['quicktime']['audio'])) { - $info['audio']['dataformat'] = 'quicktime'; - } - if (empty($info['video']['dataformat']) && !empty($info['quicktime']['video'])) { - $info['video']['dataformat'] = 'quicktime'; - } - - return true; - } - - public function QuicktimeParseAtom($atomname, $atomsize, $atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) { - // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm - // https://code.google.com/p/mp4v2/wiki/iTunesMetadata - - $info = &$this->getid3->info; - - $atom_parent = end($atomHierarchy); // not array_pop($atomHierarchy); see http://www.getid3.org/phpBB3/viewtopic.php?t=1717 - array_push($atomHierarchy, $atomname); - $atom_structure['hierarchy'] = implode(' ', $atomHierarchy); - $atom_structure['name'] = $atomname; - $atom_structure['size'] = $atomsize; - $atom_structure['offset'] = $baseoffset; - switch ($atomname) { - case 'moov': // MOVie container atom - case 'trak': // TRAcK container atom - case 'clip': // CLIPping container atom - case 'matt': // track MATTe container atom - case 'edts': // EDiTS container atom - case 'tref': // Track REFerence container atom - case 'mdia': // MeDIA container atom - case 'minf': // Media INFormation container atom - case 'dinf': // Data INFormation container atom - case 'udta': // User DaTA container atom - case 'cmov': // Compressed MOVie container atom - case 'rmra': // Reference Movie Record Atom - case 'rmda': // Reference Movie Descriptor Atom - case 'gmhd': // Generic Media info HeaDer atom (seen on QTVR) - $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); - break; - - case 'ilst': // Item LiST container atom - if ($atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms)) { - // some "ilst" atoms contain data atoms that have a numeric name, and the data is far more accessible if the returned array is compacted - $allnumericnames = true; - foreach ($atom_structure['subatoms'] as $subatomarray) { - if (!is_integer($subatomarray['name']) || (count($subatomarray['subatoms']) != 1)) { - $allnumericnames = false; - break; - } - } - if ($allnumericnames) { - $newData = array(); - foreach ($atom_structure['subatoms'] as $subatomarray) { - foreach ($subatomarray['subatoms'] as $newData_subatomarray) { - unset($newData_subatomarray['hierarchy'], $newData_subatomarray['name']); - $newData[$subatomarray['name']] = $newData_subatomarray; - break; - } - } - $atom_structure['data'] = $newData; - unset($atom_structure['subatoms']); - } - } - break; - - case "\x00\x00\x00\x01": - case "\x00\x00\x00\x02": - case "\x00\x00\x00\x03": - case "\x00\x00\x00\x04": - case "\x00\x00\x00\x05": - $atomname = getid3_lib::BigEndian2Int($atomname); - $atom_structure['name'] = $atomname; - $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); - break; - - case 'stbl': // Sample TaBLe container atom - $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); - $isVideo = false; - $framerate = 0; - $framecount = 0; - foreach ($atom_structure['subatoms'] as $key => $value_array) { - if (isset($value_array['sample_description_table'])) { - foreach ($value_array['sample_description_table'] as $key2 => $value_array2) { - if (isset($value_array2['data_format'])) { - switch ($value_array2['data_format']) { - case 'avc1': - case 'mp4v': - // video data - $isVideo = true; - break; - case 'mp4a': - // audio data - break; - } - } - } - } elseif (isset($value_array['time_to_sample_table'])) { - foreach ($value_array['time_to_sample_table'] as $key2 => $value_array2) { - if (isset($value_array2['sample_count']) && isset($value_array2['sample_duration']) && ($value_array2['sample_duration'] > 0)) { - $framerate = round($info['quicktime']['time_scale'] / $value_array2['sample_duration'], 3); - $framecount = $value_array2['sample_count']; - } - } - } - } - if ($isVideo && $framerate) { - $info['quicktime']['video']['frame_rate'] = $framerate; - $info['video']['frame_rate'] = $info['quicktime']['video']['frame_rate']; - } - if ($isVideo && $framecount) { - $info['quicktime']['video']['frame_count'] = $framecount; - } - break; - - - case "\xA9".'alb': // ALBum - case "\xA9".'ART': // - case "\xA9".'art': // ARTist - case "\xA9".'aut': // - case "\xA9".'cmt': // CoMmenT - case "\xA9".'com': // COMposer - case "\xA9".'cpy': // - case "\xA9".'day': // content created year - case "\xA9".'dir': // - case "\xA9".'ed1': // - case "\xA9".'ed2': // - case "\xA9".'ed3': // - case "\xA9".'ed4': // - case "\xA9".'ed5': // - case "\xA9".'ed6': // - case "\xA9".'ed7': // - case "\xA9".'ed8': // - case "\xA9".'ed9': // - case "\xA9".'enc': // - case "\xA9".'fmt': // - case "\xA9".'gen': // GENre - case "\xA9".'grp': // GRouPing - case "\xA9".'hst': // - case "\xA9".'inf': // - case "\xA9".'lyr': // LYRics - case "\xA9".'mak': // - case "\xA9".'mod': // - case "\xA9".'nam': // full NAMe - case "\xA9".'ope': // - case "\xA9".'PRD': // - case "\xA9".'prf': // - case "\xA9".'req': // - case "\xA9".'src': // - case "\xA9".'swr': // - case "\xA9".'too': // encoder - case "\xA9".'trk': // TRacK - case "\xA9".'url': // - case "\xA9".'wrn': // - case "\xA9".'wrt': // WRiTer - case '----': // itunes specific - case 'aART': // Album ARTist - case 'akID': // iTunes store account type - case 'apID': // Purchase Account - case 'atID': // - case 'catg': // CaTeGory - case 'cmID': // - case 'cnID': // - case 'covr': // COVeR artwork - case 'cpil': // ComPILation - case 'cprt': // CoPyRighT - case 'desc': // DESCription - case 'disk': // DISK number - case 'egid': // Episode Global ID - case 'geID': // - case 'gnre': // GeNRE - case 'hdvd': // HD ViDeo - case 'keyw': // KEYWord - case 'ldes': // Long DEScription - case 'pcst': // PodCaST - case 'pgap': // GAPless Playback - case 'plID': // - case 'purd': // PURchase Date - case 'purl': // Podcast URL - case 'rati': // - case 'rndu': // - case 'rpdu': // - case 'rtng': // RaTiNG - case 'sfID': // iTunes store country - case 'soaa': // SOrt Album Artist - case 'soal': // SOrt ALbum - case 'soar': // SOrt ARtist - case 'soco': // SOrt COmposer - case 'sonm': // SOrt NaMe - case 'sosn': // SOrt Show Name - case 'stik': // - case 'tmpo': // TeMPO (BPM) - case 'trkn': // TRacK Number - case 'tven': // tvEpisodeID - case 'tves': // TV EpiSode - case 'tvnn': // TV Network Name - case 'tvsh': // TV SHow Name - case 'tvsn': // TV SeasoN - if ($atom_parent == 'udta') { - // User data atom handler - $atom_structure['data_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); - $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); - $atom_structure['data'] = substr($atom_data, 4); - - $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); - if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) { - $info['comments']['language'][] = $atom_structure['language']; - } - } else { - // Apple item list box atom handler - $atomoffset = 0; - if (substr($atom_data, 2, 2) == "\x10\xB5") { - // not sure what it means, but observed on iPhone4 data. - // Each $atom_data has 2 bytes of datasize, plus 0x10B5, then data - while ($atomoffset < strlen($atom_data)) { - $boxsmallsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 2)); - $boxsmalltype = substr($atom_data, $atomoffset + 2, 2); - $boxsmalldata = substr($atom_data, $atomoffset + 4, $boxsmallsize); - if ($boxsmallsize <= 1) { - $this->warning('Invalid QuickTime atom smallbox size "'.$boxsmallsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset)); - $atom_structure['data'] = null; - $atomoffset = strlen($atom_data); - break; - } - switch ($boxsmalltype) { - case "\x10\xB5": - $atom_structure['data'] = $boxsmalldata; - break; - default: - $this->warning('Unknown QuickTime smallbox type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxsmalltype).'" ('.trim(getid3_lib::PrintHexBytes($boxsmalltype)).') at offset '.$baseoffset); - $atom_structure['data'] = $atom_data; - break; - } - $atomoffset += (4 + $boxsmallsize); - } - } else { - while ($atomoffset < strlen($atom_data)) { - $boxsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 4)); - $boxtype = substr($atom_data, $atomoffset + 4, 4); - $boxdata = substr($atom_data, $atomoffset + 8, $boxsize - 8); - if ($boxsize <= 1) { - $this->warning('Invalid QuickTime atom box size "'.$boxsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset)); - $atom_structure['data'] = null; - $atomoffset = strlen($atom_data); - break; - } - $atomoffset += $boxsize; - - switch ($boxtype) { - case 'mean': - case 'name': - $atom_structure[$boxtype] = substr($boxdata, 4); - break; - - case 'data': - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($boxdata, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($boxdata, 1, 3)); - switch ($atom_structure['flags_raw']) { - case 0: // data flag - case 21: // tmpo/cpil flag - switch ($atomname) { - case 'cpil': - case 'hdvd': - case 'pcst': - case 'pgap': - // 8-bit integer (boolean) - $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); - break; - - case 'tmpo': - // 16-bit integer - $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 2)); - break; - - case 'disk': - case 'trkn': - // binary - $num = getid3_lib::BigEndian2Int(substr($boxdata, 10, 2)); - $num_total = getid3_lib::BigEndian2Int(substr($boxdata, 12, 2)); - $atom_structure['data'] = empty($num) ? '' : $num; - $atom_structure['data'] .= empty($num_total) ? '' : '/'.$num_total; - break; - - case 'gnre': - // enum - $GenreID = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); - $atom_structure['data'] = getid3_id3v1::LookupGenreName($GenreID - 1); - break; - - case 'rtng': - // 8-bit integer - $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); - $atom_structure['data'] = $this->QuicktimeContentRatingLookup($atom_structure[$atomname]); - break; - - case 'stik': - // 8-bit integer (enum) - $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); - $atom_structure['data'] = $this->QuicktimeSTIKLookup($atom_structure[$atomname]); - break; - - case 'sfID': - // 32-bit integer - $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); - $atom_structure['data'] = $this->QuicktimeStoreFrontCodeLookup($atom_structure[$atomname]); - break; - - case 'egid': - case 'purl': - $atom_structure['data'] = substr($boxdata, 8); - break; - - case 'plID': - // 64-bit integer - $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 8)); - break; - - case 'covr': - $atom_structure['data'] = substr($boxdata, 8); - // not a foolproof check, but better than nothing - if (preg_match('#^\\xFF\\xD8\\xFF#', $atom_structure['data'])) { - $atom_structure['image_mime'] = 'image/jpeg'; - } elseif (preg_match('#^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A#', $atom_structure['data'])) { - $atom_structure['image_mime'] = 'image/png'; - } elseif (preg_match('#^GIF#', $atom_structure['data'])) { - $atom_structure['image_mime'] = 'image/gif'; - } - break; - - case 'atID': - case 'cnID': - case 'geID': - case 'tves': - case 'tvsn': - default: - // 32-bit integer - $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); - } - break; - - case 1: // text flag - case 13: // image flag - default: - $atom_structure['data'] = substr($boxdata, 8); - if ($atomname == 'covr') { - // not a foolproof check, but better than nothing - if (preg_match('#^\\xFF\\xD8\\xFF#', $atom_structure['data'])) { - $atom_structure['image_mime'] = 'image/jpeg'; - } elseif (preg_match('#^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A#', $atom_structure['data'])) { - $atom_structure['image_mime'] = 'image/png'; - } elseif (preg_match('#^GIF#', $atom_structure['data'])) { - $atom_structure['image_mime'] = 'image/gif'; - } - } - break; - - } - break; - - default: - $this->warning('Unknown QuickTime box type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxtype).'" ('.trim(getid3_lib::PrintHexBytes($boxtype)).') at offset '.$baseoffset); - $atom_structure['data'] = $atom_data; - - } - } - } - } - $this->CopyToAppropriateCommentsSection($atomname, $atom_structure['data'], $atom_structure['name']); - break; - - - case 'play': // auto-PLAY atom - $atom_structure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - - $info['quicktime']['autoplay'] = $atom_structure['autoplay']; - break; - - - case 'WLOC': // Window LOCation atom - $atom_structure['location_x'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); - $atom_structure['location_y'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); - break; - - - case 'LOOP': // LOOPing atom - case 'SelO': // play SELection Only atom - case 'AllF': // play ALL Frames atom - $atom_structure['data'] = getid3_lib::BigEndian2Int($atom_data); - break; - - - case 'name': // - case 'MCPS': // Media Cleaner PRo - case '@PRM': // adobe PReMiere version - case '@PRQ': // adobe PRemiere Quicktime version - $atom_structure['data'] = $atom_data; - break; - - - case 'cmvd': // Compressed MooV Data atom - // Code by ubergeekØubergeek*tv based on information from - // http://developer.apple.com/quicktime/icefloe/dispatch012.html - $atom_structure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); - - $CompressedFileData = substr($atom_data, 4); - if ($UncompressedHeader = @gzuncompress($CompressedFileData)) { - $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($UncompressedHeader, 0, $atomHierarchy, $ParseAllPossibleAtoms); - } else { - $this->warning('Error decompressing compressed MOV atom at offset '.$atom_structure['offset']); - } - break; - - - case 'dcom': // Data COMpression atom - $atom_structure['compression_id'] = $atom_data; - $atom_structure['compression_text'] = $this->QuicktimeDCOMLookup($atom_data); - break; - - - case 'rdrf': // Reference movie Data ReFerence atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); - $atom_structure['flags']['internal_data'] = (bool) ($atom_structure['flags_raw'] & 0x000001); - - $atom_structure['reference_type_name'] = substr($atom_data, 4, 4); - $atom_structure['reference_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); - switch ($atom_structure['reference_type_name']) { - case 'url ': - $atom_structure['url'] = $this->NoNullString(substr($atom_data, 12)); - break; - - case 'alis': - $atom_structure['file_alias'] = substr($atom_data, 12); - break; - - case 'rsrc': - $atom_structure['resource_alias'] = substr($atom_data, 12); - break; - - default: - $atom_structure['data'] = substr($atom_data, 12); - break; - } - break; - - - case 'rmqu': // Reference Movie QUality atom - $atom_structure['movie_quality'] = getid3_lib::BigEndian2Int($atom_data); - break; - - - case 'rmcs': // Reference Movie Cpu Speed atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['cpu_speed_rating'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); - break; - - - case 'rmvc': // Reference Movie Version Check atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['gestalt_selector'] = substr($atom_data, 4, 4); - $atom_structure['gestalt_value_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); - $atom_structure['gestalt_value'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); - $atom_structure['gestalt_check_type'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2)); - break; - - - case 'rmcd': // Reference Movie Component check atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['component_type'] = substr($atom_data, 4, 4); - $atom_structure['component_subtype'] = substr($atom_data, 8, 4); - $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4); - $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); - $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); - $atom_structure['component_min_version'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 4)); - break; - - - case 'rmdr': // Reference Movie Data Rate atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['data_rate'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - - $atom_structure['data_rate_bps'] = $atom_structure['data_rate'] * 10; - break; - - - case 'rmla': // Reference Movie Language Atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); - - $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); - if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) { - $info['comments']['language'][] = $atom_structure['language']; - } - break; - - - case 'rmla': // Reference Movie Language Atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); - break; - - - case 'ptv ': // Print To Video - defines a movie's full screen mode - // http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm - $atom_structure['display_size_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); - $atom_structure['reserved_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); // hardcoded: 0x0000 - $atom_structure['reserved_2'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x0000 - $atom_structure['slide_show_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 1)); - $atom_structure['play_on_open_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 7, 1)); - - $atom_structure['flags']['play_on_open'] = (bool) $atom_structure['play_on_open_flag']; - $atom_structure['flags']['slide_show'] = (bool) $atom_structure['slide_show_flag']; - - $ptv_lookup[0] = 'normal'; - $ptv_lookup[1] = 'double'; - $ptv_lookup[2] = 'half'; - $ptv_lookup[3] = 'full'; - $ptv_lookup[4] = 'current'; - if (isset($ptv_lookup[$atom_structure['display_size_raw']])) { - $atom_structure['display_size'] = $ptv_lookup[$atom_structure['display_size_raw']]; - } else { - $this->warning('unknown "ptv " display constant ('.$atom_structure['display_size_raw'].')'); - } - break; - - - case 'stsd': // Sample Table Sample Description atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $stsdEntriesDataOffset = 8; - for ($i = 0; $i < $atom_structure['number_entries']; $i++) { - $atom_structure['sample_description_table'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 4)); - $stsdEntriesDataOffset += 4; - $atom_structure['sample_description_table'][$i]['data_format'] = substr($atom_data, $stsdEntriesDataOffset, 4); - $stsdEntriesDataOffset += 4; - $atom_structure['sample_description_table'][$i]['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 6)); - $stsdEntriesDataOffset += 6; - $atom_structure['sample_description_table'][$i]['reference_index'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 2)); - $stsdEntriesDataOffset += 2; - $atom_structure['sample_description_table'][$i]['data'] = substr($atom_data, $stsdEntriesDataOffset, ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2)); - $stsdEntriesDataOffset += ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2); - - $atom_structure['sample_description_table'][$i]['encoder_version'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 0, 2)); - $atom_structure['sample_description_table'][$i]['encoder_revision'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 2, 2)); - $atom_structure['sample_description_table'][$i]['encoder_vendor'] = substr($atom_structure['sample_description_table'][$i]['data'], 4, 4); - - switch ($atom_structure['sample_description_table'][$i]['encoder_vendor']) { - - case "\x00\x00\x00\x00": - // audio tracks - $atom_structure['sample_description_table'][$i]['audio_channels'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 2)); - $atom_structure['sample_description_table'][$i]['audio_bit_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 10, 2)); - $atom_structure['sample_description_table'][$i]['audio_compression_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 2)); - $atom_structure['sample_description_table'][$i]['audio_packet_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 14, 2)); - $atom_structure['sample_description_table'][$i]['audio_sample_rate'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 16, 4)); - - // video tracks - // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap3/qtff3.html - $atom_structure['sample_description_table'][$i]['temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4)); - $atom_structure['sample_description_table'][$i]['spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4)); - $atom_structure['sample_description_table'][$i]['width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2)); - $atom_structure['sample_description_table'][$i]['height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2)); - $atom_structure['sample_description_table'][$i]['resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4)); - $atom_structure['sample_description_table'][$i]['resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4)); - $atom_structure['sample_description_table'][$i]['data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 4)); - $atom_structure['sample_description_table'][$i]['frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 36, 2)); - $atom_structure['sample_description_table'][$i]['compressor_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 38, 4); - $atom_structure['sample_description_table'][$i]['pixel_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 42, 2)); - $atom_structure['sample_description_table'][$i]['color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 44, 2)); - - switch ($atom_structure['sample_description_table'][$i]['data_format']) { - case '2vuY': - case 'avc1': - case 'cvid': - case 'dvc ': - case 'dvcp': - case 'gif ': - case 'h263': - case 'jpeg': - case 'kpcd': - case 'mjpa': - case 'mjpb': - case 'mp4v': - case 'png ': - case 'raw ': - case 'rle ': - case 'rpza': - case 'smc ': - case 'SVQ1': - case 'SVQ3': - case 'tiff': - case 'v210': - case 'v216': - case 'v308': - case 'v408': - case 'v410': - case 'yuv2': - $info['fileformat'] = 'mp4'; - $info['video']['fourcc'] = $atom_structure['sample_description_table'][$i]['data_format']; + public $ReturnAtomData = true; + public $ParseAllPossibleAtoms = false; + + public function Analyze() + { + $info = &$this->getid3->info; + + $info['fileformat'] = 'quicktime'; + $info['quicktime']['hinting'] = false; + $info['quicktime']['controller'] = 'standard'; // may be overridden if 'ctyp' atom is present + + $this->fseek($info['avdataoffset']); + + $offset = 0; + $atomcounter = 0; + $atom_data_read_buffer_size = max($this->getid3->option_fread_buffer_size * 1024, ($info['php_memory_limit'] ? round($info['php_memory_limit'] / 4) : 1024)); // set read buffer to 25% of PHP memory limit (if one is specified), otherwise use option_fread_buffer_size [default: 32MB] + while ($offset < $info['avdataend']) { + if (! getid3_lib::intValueSupported($offset)) { + $this->error('Unable to parse atom at offset '.$offset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions'); + break; + } + $this->fseek($offset); + $AtomHeader = $this->fread(8); + + $atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4)); + $atomname = substr($AtomHeader, 4, 4); + + // 64-bit MOV patch by jlegateØktnc*com + if ($atomsize == 1) { + $atomsize = getid3_lib::BigEndian2Int($this->fread(8)); + } + + $info['quicktime'][$atomname]['name'] = $atomname; + $info['quicktime'][$atomname]['size'] = $atomsize; + $info['quicktime'][$atomname]['offset'] = $offset; + + if (($offset + $atomsize) > $info['avdataend']) { + $this->error('Atom at offset '.$offset.' claims to go beyond end-of-file (length: '.$atomsize.' bytes)'); + + return false; + } + + if ($atomsize == 0) { + // Furthermore, for historical reasons the list of atoms is optionally + // terminated by a 32-bit integer set to 0. If you are writing a program + // to read user data atoms, you should allow for the terminating 0. + break; + } + $atomHierarchy = []; + $info['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, $this->fread(min($atomsize, $atom_data_read_buffer_size)), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms); + + $offset += $atomsize; + $atomcounter++; + } + + if (! empty($info['avdataend_tmp'])) { + // this value is assigned to a temp value and then erased because + // otherwise any atoms beyond the 'mdat' atom would not get parsed + $info['avdataend'] = $info['avdataend_tmp']; + unset($info['avdataend_tmp']); + } + + if (! empty($info['quicktime']['comments']['chapters']) && is_array($info['quicktime']['comments']['chapters']) && (count($info['quicktime']['comments']['chapters']) > 0)) { + $durations = $this->quicktime_time_to_sample_table($info); + for ($i = 0; $i < count($info['quicktime']['comments']['chapters']); $i++) { + $bookmark = []; + $bookmark['title'] = $info['quicktime']['comments']['chapters'][$i]; + if (isset($durations[$i])) { + $bookmark['duration_sample'] = $durations[$i]['sample_duration']; + if ($i > 0) { + $bookmark['start_sample'] = $info['quicktime']['bookmarks'][($i - 1)]['start_sample'] + $info['quicktime']['bookmarks'][($i - 1)]['duration_sample']; + } else { + $bookmark['start_sample'] = 0; + } + if ($time_scale = $this->quicktime_bookmark_time_scale($info)) { + $bookmark['duration_seconds'] = $bookmark['duration_sample'] / $time_scale; + $bookmark['start_seconds'] = $bookmark['start_sample'] / $time_scale; + } + } + $info['quicktime']['bookmarks'][] = $bookmark; + } + } + + if (isset($info['quicktime']['temp_meta_key_names'])) { + unset($info['quicktime']['temp_meta_key_names']); + } + + if (! empty($info['quicktime']['comments']['location.ISO6709'])) { + // https://en.wikipedia.org/wiki/ISO_6709 + foreach ($info['quicktime']['comments']['location.ISO6709'] as $ISO6709string) { + $latitude = false; + $longitude = false; + $altitude = false; + if (preg_match('#^([\\+\\-])([0-9]{2}|[0-9]{4}|[0-9]{6})(\\.[0-9]+)?([\\+\\-])([0-9]{3}|[0-9]{5}|[0-9]{7})(\\.[0-9]+)?(([\\+\\-])([0-9]{3}|[0-9]{5}|[0-9]{7})(\\.[0-9]+)?)?/$#', $ISO6709string, $matches)) { + @list($dummy, $lat_sign, $lat_deg, $lat_deg_dec, $lon_sign, $lon_deg, $lon_deg_dec, $dummy, $alt_sign, $alt_deg, $alt_deg_dec) = $matches; + + if (strlen($lat_deg) == 2) { // [+-]DD.D + $latitude = floatval(ltrim($lat_deg, '0').$lat_deg_dec); + } elseif (strlen($lat_deg) == 4) { // [+-]DDMM.M + $latitude = floatval(ltrim(substr($lat_deg, 0, 2), '0')) + floatval(ltrim(substr($lat_deg, 2, 2), '0').$lat_deg_dec / 60); + } elseif (strlen($lat_deg) == 6) { // [+-]DDMMSS.S + $latitude = floatval(ltrim(substr($lat_deg, 0, 2), '0')) + floatval(ltrim(substr($lat_deg, 2, 2), '0') / 60) + floatval(ltrim(substr($lat_deg, 4, 2), '0').$lat_deg_dec / 3600); + } + + if (strlen($lon_deg) == 3) { // [+-]DDD.D + $longitude = floatval(ltrim($lon_deg, '0').$lon_deg_dec); + } elseif (strlen($lon_deg) == 5) { // [+-]DDDMM.M + $longitude = floatval(ltrim(substr($lon_deg, 0, 2), '0')) + floatval(ltrim(substr($lon_deg, 2, 2), '0').$lon_deg_dec / 60); + } elseif (strlen($lon_deg) == 7) { // [+-]DDDMMSS.S + $longitude = floatval(ltrim(substr($lon_deg, 0, 2), '0')) + floatval(ltrim(substr($lon_deg, 2, 2), '0') / 60) + floatval(ltrim(substr($lon_deg, 4, 2), '0').$lon_deg_dec / 3600); + } + + if (strlen($alt_deg) == 3) { // [+-]DDD.D + $altitude = floatval(ltrim($alt_deg, '0').$alt_deg_dec); + } elseif (strlen($alt_deg) == 5) { // [+-]DDDMM.M + $altitude = floatval(ltrim(substr($alt_deg, 0, 2), '0')) + floatval(ltrim(substr($alt_deg, 2, 2), '0').$alt_deg_dec / 60); + } elseif (strlen($alt_deg) == 7) { // [+-]DDDMMSS.S + $altitude = floatval(ltrim(substr($alt_deg, 0, 2), '0')) + floatval(ltrim(substr($alt_deg, 2, 2), '0') / 60) + floatval(ltrim(substr($alt_deg, 4, 2), '0').$alt_deg_dec / 3600); + } + + if ($latitude !== false) { + $info['quicktime']['comments']['gps_latitude'][] = (($lat_sign == '-') ? -1 : 1) * floatval($latitude); + } + if ($longitude !== false) { + $info['quicktime']['comments']['gps_longitude'][] = (($lon_sign == '-') ? -1 : 1) * floatval($longitude); + } + if ($altitude !== false) { + $info['quicktime']['comments']['gps_altitude'][] = (($alt_sign == '-') ? -1 : 1) * floatval($altitude); + } + } + if ($latitude === false) { + $this->warning('location.ISO6709 string not parsed correctly: "'.$ISO6709string.'", please submit as a bug'); + } + break; + } + } + + if (! isset($info['bitrate']) && isset($info['playtime_seconds'])) { + $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + } + if (isset($info['bitrate']) && ! isset($info['audio']['bitrate']) && ! isset($info['quicktime']['video'])) { + $info['audio']['bitrate'] = $info['bitrate']; + } + if (! empty($info['playtime_seconds']) && ! isset($info['video']['frame_rate']) && ! empty($info['quicktime']['stts_framecount'])) { + foreach ($info['quicktime']['stts_framecount'] as $key => $samples_count) { + $samples_per_second = $samples_count / $info['playtime_seconds']; + if ($samples_per_second > 240) { + // has to be audio samples + } else { + $info['video']['frame_rate'] = $samples_per_second; + break; + } + } + } + if ($info['audio']['dataformat'] == 'mp4') { + $info['fileformat'] = 'mp4'; + if (empty($info['video']['resolution_x'])) { + $info['mime_type'] = 'audio/mp4'; + unset($info['video']['dataformat']); + } else { + $info['mime_type'] = 'video/mp4'; + } + } + + if (! $this->ReturnAtomData) { + unset($info['quicktime']['moov']); + } + + if (empty($info['audio']['dataformat']) && ! empty($info['quicktime']['audio'])) { + $info['audio']['dataformat'] = 'quicktime'; + } + if (empty($info['video']['dataformat']) && ! empty($info['quicktime']['video'])) { + $info['video']['dataformat'] = 'quicktime'; + } + + return true; + } + + public function QuicktimeParseAtom($atomname, $atomsize, $atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) + { + // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm + // https://code.google.com/p/mp4v2/wiki/iTunesMetadata + + $info = &$this->getid3->info; + + $atom_parent = end($atomHierarchy); // not array_pop($atomHierarchy); see http://www.getid3.org/phpBB3/viewtopic.php?t=1717 + array_push($atomHierarchy, $atomname); + $atom_structure['hierarchy'] = implode(' ', $atomHierarchy); + $atom_structure['name'] = $atomname; + $atom_structure['size'] = $atomsize; + $atom_structure['offset'] = $baseoffset; + switch ($atomname) { + case 'moov': // MOVie container atom + case 'trak': // TRAcK container atom + case 'clip': // CLIPping container atom + case 'matt': // track MATTe container atom + case 'edts': // EDiTS container atom + case 'tref': // Track REFerence container atom + case 'mdia': // MeDIA container atom + case 'minf': // Media INFormation container atom + case 'dinf': // Data INFormation container atom + case 'udta': // User DaTA container atom + case 'cmov': // Compressed MOVie container atom + case 'rmra': // Reference Movie Record Atom + case 'rmda': // Reference Movie Descriptor Atom + case 'gmhd': // Generic Media info HeaDer atom (seen on QTVR) + $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); + break; + + case 'ilst': // Item LiST container atom + if ($atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms)) { + // some "ilst" atoms contain data atoms that have a numeric name, and the data is far more accessible if the returned array is compacted + $allnumericnames = true; + foreach ($atom_structure['subatoms'] as $subatomarray) { + if (! is_int($subatomarray['name']) || (count($subatomarray['subatoms']) != 1)) { + $allnumericnames = false; + break; + } + } + if ($allnumericnames) { + $newData = []; + foreach ($atom_structure['subatoms'] as $subatomarray) { + foreach ($subatomarray['subatoms'] as $newData_subatomarray) { + unset($newData_subatomarray['hierarchy'], $newData_subatomarray['name']); + $newData[$subatomarray['name']] = $newData_subatomarray; + break; + } + } + $atom_structure['data'] = $newData; + unset($atom_structure['subatoms']); + } + } + break; + + case "\x00\x00\x00\x01": + case "\x00\x00\x00\x02": + case "\x00\x00\x00\x03": + case "\x00\x00\x00\x04": + case "\x00\x00\x00\x05": + $atomname = getid3_lib::BigEndian2Int($atomname); + $atom_structure['name'] = $atomname; + $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); + break; + + case 'stbl': // Sample TaBLe container atom + $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); + $isVideo = false; + $framerate = 0; + $framecount = 0; + foreach ($atom_structure['subatoms'] as $key => $value_array) { + if (isset($value_array['sample_description_table'])) { + foreach ($value_array['sample_description_table'] as $key2 => $value_array2) { + if (isset($value_array2['data_format'])) { + switch ($value_array2['data_format']) { + case 'avc1': + case 'mp4v': + // video data + $isVideo = true; + break; + case 'mp4a': + // audio data + break; + } + } + } + } elseif (isset($value_array['time_to_sample_table'])) { + foreach ($value_array['time_to_sample_table'] as $key2 => $value_array2) { + if (isset($value_array2['sample_count']) && isset($value_array2['sample_duration']) && ($value_array2['sample_duration'] > 0)) { + $framerate = round($info['quicktime']['time_scale'] / $value_array2['sample_duration'], 3); + $framecount = $value_array2['sample_count']; + } + } + } + } + if ($isVideo && $framerate) { + $info['quicktime']['video']['frame_rate'] = $framerate; + $info['video']['frame_rate'] = $info['quicktime']['video']['frame_rate']; + } + if ($isVideo && $framecount) { + $info['quicktime']['video']['frame_count'] = $framecount; + } + break; + + case "\xA9".'alb': // ALBum + case "\xA9".'ART': // + case "\xA9".'art': // ARTist + case "\xA9".'aut': // + case "\xA9".'cmt': // CoMmenT + case "\xA9".'com': // COMposer + case "\xA9".'cpy': // + case "\xA9".'day': // content created year + case "\xA9".'dir': // + case "\xA9".'ed1': // + case "\xA9".'ed2': // + case "\xA9".'ed3': // + case "\xA9".'ed4': // + case "\xA9".'ed5': // + case "\xA9".'ed6': // + case "\xA9".'ed7': // + case "\xA9".'ed8': // + case "\xA9".'ed9': // + case "\xA9".'enc': // + case "\xA9".'fmt': // + case "\xA9".'gen': // GENre + case "\xA9".'grp': // GRouPing + case "\xA9".'hst': // + case "\xA9".'inf': // + case "\xA9".'lyr': // LYRics + case "\xA9".'mak': // + case "\xA9".'mod': // + case "\xA9".'nam': // full NAMe + case "\xA9".'ope': // + case "\xA9".'PRD': // + case "\xA9".'prf': // + case "\xA9".'req': // + case "\xA9".'src': // + case "\xA9".'swr': // + case "\xA9".'too': // encoder + case "\xA9".'trk': // TRacK + case "\xA9".'url': // + case "\xA9".'wrn': // + case "\xA9".'wrt': // WRiTer + case '----': // itunes specific + case 'aART': // Album ARTist + case 'akID': // iTunes store account type + case 'apID': // Purchase Account + case 'atID': // + case 'catg': // CaTeGory + case 'cmID': // + case 'cnID': // + case 'covr': // COVeR artwork + case 'cpil': // ComPILation + case 'cprt': // CoPyRighT + case 'desc': // DESCription + case 'disk': // DISK number + case 'egid': // Episode Global ID + case 'geID': // + case 'gnre': // GeNRE + case 'hdvd': // HD ViDeo + case 'keyw': // KEYWord + case 'ldes': // Long DEScription + case 'pcst': // PodCaST + case 'pgap': // GAPless Playback + case 'plID': // + case 'purd': // PURchase Date + case 'purl': // Podcast URL + case 'rati': // + case 'rndu': // + case 'rpdu': // + case 'rtng': // RaTiNG + case 'sfID': // iTunes store country + case 'soaa': // SOrt Album Artist + case 'soal': // SOrt ALbum + case 'soar': // SOrt ARtist + case 'soco': // SOrt COmposer + case 'sonm': // SOrt NaMe + case 'sosn': // SOrt Show Name + case 'stik': // + case 'tmpo': // TeMPO (BPM) + case 'trkn': // TRacK Number + case 'tven': // tvEpisodeID + case 'tves': // TV EpiSode + case 'tvnn': // TV Network Name + case 'tvsh': // TV SHow Name + case 'tvsn': // TV SeasoN + if ($atom_parent == 'udta') { + // User data atom handler + $atom_structure['data_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); + $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); + $atom_structure['data'] = substr($atom_data, 4); + + $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); + if (empty($info['comments']['language']) || (! in_array($atom_structure['language'], $info['comments']['language']))) { + $info['comments']['language'][] = $atom_structure['language']; + } + } else { + // Apple item list box atom handler + $atomoffset = 0; + if (substr($atom_data, 2, 2) == "\x10\xB5") { + // not sure what it means, but observed on iPhone4 data. + // Each $atom_data has 2 bytes of datasize, plus 0x10B5, then data + while ($atomoffset < strlen($atom_data)) { + $boxsmallsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 2)); + $boxsmalltype = substr($atom_data, $atomoffset + 2, 2); + $boxsmalldata = substr($atom_data, $atomoffset + 4, $boxsmallsize); + if ($boxsmallsize <= 1) { + $this->warning('Invalid QuickTime atom smallbox size "'.$boxsmallsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset)); + $atom_structure['data'] = null; + $atomoffset = strlen($atom_data); + break; + } + switch ($boxsmalltype) { + case "\x10\xB5": + $atom_structure['data'] = $boxsmalldata; + break; + default: + $this->warning('Unknown QuickTime smallbox type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxsmalltype).'" ('.trim(getid3_lib::PrintHexBytes($boxsmalltype)).') at offset '.$baseoffset); + $atom_structure['data'] = $atom_data; + break; + } + $atomoffset += (4 + $boxsmallsize); + } + } else { + while ($atomoffset < strlen($atom_data)) { + $boxsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 4)); + $boxtype = substr($atom_data, $atomoffset + 4, 4); + $boxdata = substr($atom_data, $atomoffset + 8, $boxsize - 8); + if ($boxsize <= 1) { + $this->warning('Invalid QuickTime atom box size "'.$boxsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset)); + $atom_structure['data'] = null; + $atomoffset = strlen($atom_data); + break; + } + $atomoffset += $boxsize; + + switch ($boxtype) { + case 'mean': + case 'name': + $atom_structure[$boxtype] = substr($boxdata, 4); + break; + + case 'data': + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($boxdata, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($boxdata, 1, 3)); + switch ($atom_structure['flags_raw']) { + case 0: // data flag + case 21: // tmpo/cpil flag + switch ($atomname) { + case 'cpil': + case 'hdvd': + case 'pcst': + case 'pgap': + // 8-bit integer (boolean) + $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); + break; + + case 'tmpo': + // 16-bit integer + $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 2)); + break; + + case 'disk': + case 'trkn': + // binary + $num = getid3_lib::BigEndian2Int(substr($boxdata, 10, 2)); + $num_total = getid3_lib::BigEndian2Int(substr($boxdata, 12, 2)); + $atom_structure['data'] = empty($num) ? '' : $num; + $atom_structure['data'] .= empty($num_total) ? '' : '/'.$num_total; + break; + + case 'gnre': + // enum + $GenreID = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); + $atom_structure['data'] = getid3_id3v1::LookupGenreName($GenreID - 1); + break; + + case 'rtng': + // 8-bit integer + $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); + $atom_structure['data'] = $this->QuicktimeContentRatingLookup($atom_structure[$atomname]); + break; + + case 'stik': + // 8-bit integer (enum) + $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); + $atom_structure['data'] = $this->QuicktimeSTIKLookup($atom_structure[$atomname]); + break; + + case 'sfID': + // 32-bit integer + $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); + $atom_structure['data'] = $this->QuicktimeStoreFrontCodeLookup($atom_structure[$atomname]); + break; + + case 'egid': + case 'purl': + $atom_structure['data'] = substr($boxdata, 8); + break; + + case 'plID': + // 64-bit integer + $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 8)); + break; + + case 'covr': + $atom_structure['data'] = substr($boxdata, 8); + // not a foolproof check, but better than nothing + if (preg_match('#^\\xFF\\xD8\\xFF#', $atom_structure['data'])) { + $atom_structure['image_mime'] = 'image/jpeg'; + } elseif (preg_match('#^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A#', $atom_structure['data'])) { + $atom_structure['image_mime'] = 'image/png'; + } elseif (preg_match('#^GIF#', $atom_structure['data'])) { + $atom_structure['image_mime'] = 'image/gif'; + } + break; + + case 'atID': + case 'cnID': + case 'geID': + case 'tves': + case 'tvsn': + default: + // 32-bit integer + $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); + } + break; + + case 1: // text flag + case 13: // image flag + default: + $atom_structure['data'] = substr($boxdata, 8); + if ($atomname == 'covr') { + // not a foolproof check, but better than nothing + if (preg_match('#^\\xFF\\xD8\\xFF#', $atom_structure['data'])) { + $atom_structure['image_mime'] = 'image/jpeg'; + } elseif (preg_match('#^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A#', $atom_structure['data'])) { + $atom_structure['image_mime'] = 'image/png'; + } elseif (preg_match('#^GIF#', $atom_structure['data'])) { + $atom_structure['image_mime'] = 'image/gif'; + } + } + break; + + } + break; + + default: + $this->warning('Unknown QuickTime box type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxtype).'" ('.trim(getid3_lib::PrintHexBytes($boxtype)).') at offset '.$baseoffset); + $atom_structure['data'] = $atom_data; + + } + } + } + } + $this->CopyToAppropriateCommentsSection($atomname, $atom_structure['data'], $atom_structure['name']); + break; + + case 'play': // auto-PLAY atom + $atom_structure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + + $info['quicktime']['autoplay'] = $atom_structure['autoplay']; + break; + + case 'WLOC': // Window LOCation atom + $atom_structure['location_x'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); + $atom_structure['location_y'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); + break; + + case 'LOOP': // LOOPing atom + case 'SelO': // play SELection Only atom + case 'AllF': // play ALL Frames atom + $atom_structure['data'] = getid3_lib::BigEndian2Int($atom_data); + break; + + case 'name': // + case 'MCPS': // Media Cleaner PRo + case '@PRM': // adobe PReMiere version + case '@PRQ': // adobe PRemiere Quicktime version + $atom_structure['data'] = $atom_data; + break; + + case 'cmvd': // Compressed MooV Data atom + // Code by ubergeekØubergeek*tv based on information from + // http://developer.apple.com/quicktime/icefloe/dispatch012.html + $atom_structure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); + + $CompressedFileData = substr($atom_data, 4); + if ($UncompressedHeader = @gzuncompress($CompressedFileData)) { + $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($UncompressedHeader, 0, $atomHierarchy, $ParseAllPossibleAtoms); + } else { + $this->warning('Error decompressing compressed MOV atom at offset '.$atom_structure['offset']); + } + break; + + case 'dcom': // Data COMpression atom + $atom_structure['compression_id'] = $atom_data; + $atom_structure['compression_text'] = $this->QuicktimeDCOMLookup($atom_data); + break; + + case 'rdrf': // Reference movie Data ReFerence atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); + $atom_structure['flags']['internal_data'] = (bool) ($atom_structure['flags_raw'] & 0x000001); + + $atom_structure['reference_type_name'] = substr($atom_data, 4, 4); + $atom_structure['reference_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); + switch ($atom_structure['reference_type_name']) { + case 'url ': + $atom_structure['url'] = $this->NoNullString(substr($atom_data, 12)); + break; + + case 'alis': + $atom_structure['file_alias'] = substr($atom_data, 12); + break; + + case 'rsrc': + $atom_structure['resource_alias'] = substr($atom_data, 12); + break; + + default: + $atom_structure['data'] = substr($atom_data, 12); + break; + } + break; + + case 'rmqu': // Reference Movie QUality atom + $atom_structure['movie_quality'] = getid3_lib::BigEndian2Int($atom_data); + break; + + case 'rmcs': // Reference Movie Cpu Speed atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['cpu_speed_rating'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); + break; + + case 'rmvc': // Reference Movie Version Check atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['gestalt_selector'] = substr($atom_data, 4, 4); + $atom_structure['gestalt_value_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); + $atom_structure['gestalt_value'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); + $atom_structure['gestalt_check_type'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2)); + break; + + case 'rmcd': // Reference Movie Component check atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['component_type'] = substr($atom_data, 4, 4); + $atom_structure['component_subtype'] = substr($atom_data, 8, 4); + $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4); + $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); + $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); + $atom_structure['component_min_version'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 4)); + break; + + case 'rmdr': // Reference Movie Data Rate atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['data_rate'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + + $atom_structure['data_rate_bps'] = $atom_structure['data_rate'] * 10; + break; + + case 'rmla': // Reference Movie Language Atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); + + $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); + if (empty($info['comments']['language']) || (! in_array($atom_structure['language'], $info['comments']['language']))) { + $info['comments']['language'][] = $atom_structure['language']; + } + break; + + case 'rmla': // Reference Movie Language Atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); + break; + + case 'ptv ': // Print To Video - defines a movie's full screen mode + // http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm + $atom_structure['display_size_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); + $atom_structure['reserved_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); // hardcoded: 0x0000 + $atom_structure['reserved_2'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x0000 + $atom_structure['slide_show_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 1)); + $atom_structure['play_on_open_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 7, 1)); + + $atom_structure['flags']['play_on_open'] = (bool) $atom_structure['play_on_open_flag']; + $atom_structure['flags']['slide_show'] = (bool) $atom_structure['slide_show_flag']; + + $ptv_lookup[0] = 'normal'; + $ptv_lookup[1] = 'double'; + $ptv_lookup[2] = 'half'; + $ptv_lookup[3] = 'full'; + $ptv_lookup[4] = 'current'; + if (isset($ptv_lookup[$atom_structure['display_size_raw']])) { + $atom_structure['display_size'] = $ptv_lookup[$atom_structure['display_size_raw']]; + } else { + $this->warning('unknown "ptv " display constant ('.$atom_structure['display_size_raw'].')'); + } + break; + + case 'stsd': // Sample Table Sample Description atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $stsdEntriesDataOffset = 8; + for ($i = 0; $i < $atom_structure['number_entries']; $i++) { + $atom_structure['sample_description_table'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 4)); + $stsdEntriesDataOffset += 4; + $atom_structure['sample_description_table'][$i]['data_format'] = substr($atom_data, $stsdEntriesDataOffset, 4); + $stsdEntriesDataOffset += 4; + $atom_structure['sample_description_table'][$i]['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 6)); + $stsdEntriesDataOffset += 6; + $atom_structure['sample_description_table'][$i]['reference_index'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 2)); + $stsdEntriesDataOffset += 2; + $atom_structure['sample_description_table'][$i]['data'] = substr($atom_data, $stsdEntriesDataOffset, ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2)); + $stsdEntriesDataOffset += ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2); + + $atom_structure['sample_description_table'][$i]['encoder_version'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 0, 2)); + $atom_structure['sample_description_table'][$i]['encoder_revision'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 2, 2)); + $atom_structure['sample_description_table'][$i]['encoder_vendor'] = substr($atom_structure['sample_description_table'][$i]['data'], 4, 4); + + switch ($atom_structure['sample_description_table'][$i]['encoder_vendor']) { + + case "\x00\x00\x00\x00": + // audio tracks + $atom_structure['sample_description_table'][$i]['audio_channels'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 2)); + $atom_structure['sample_description_table'][$i]['audio_bit_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 10, 2)); + $atom_structure['sample_description_table'][$i]['audio_compression_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 2)); + $atom_structure['sample_description_table'][$i]['audio_packet_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 14, 2)); + $atom_structure['sample_description_table'][$i]['audio_sample_rate'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 16, 4)); + + // video tracks + // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap3/qtff3.html + $atom_structure['sample_description_table'][$i]['temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4)); + $atom_structure['sample_description_table'][$i]['spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4)); + $atom_structure['sample_description_table'][$i]['width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2)); + $atom_structure['sample_description_table'][$i]['height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2)); + $atom_structure['sample_description_table'][$i]['resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4)); + $atom_structure['sample_description_table'][$i]['resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4)); + $atom_structure['sample_description_table'][$i]['data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 4)); + $atom_structure['sample_description_table'][$i]['frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 36, 2)); + $atom_structure['sample_description_table'][$i]['compressor_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 38, 4); + $atom_structure['sample_description_table'][$i]['pixel_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 42, 2)); + $atom_structure['sample_description_table'][$i]['color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 44, 2)); + + switch ($atom_structure['sample_description_table'][$i]['data_format']) { + case '2vuY': + case 'avc1': + case 'cvid': + case 'dvc ': + case 'dvcp': + case 'gif ': + case 'h263': + case 'jpeg': + case 'kpcd': + case 'mjpa': + case 'mjpb': + case 'mp4v': + case 'png ': + case 'raw ': + case 'rle ': + case 'rpza': + case 'smc ': + case 'SVQ1': + case 'SVQ3': + case 'tiff': + case 'v210': + case 'v216': + case 'v308': + case 'v408': + case 'v410': + case 'yuv2': + $info['fileformat'] = 'mp4'; + $info['video']['fourcc'] = $atom_structure['sample_description_table'][$i]['data_format']; // http://www.getid3.org/phpBB3/viewtopic.php?t=1550 //if ((!empty($atom_structure['sample_description_table'][$i]['width']) && !empty($atom_structure['sample_description_table'][$i]['width'])) && (empty($info['video']['resolution_x']) || empty($info['video']['resolution_y']) || (number_format($info['video']['resolution_x'], 6) != number_format(round($info['video']['resolution_x']), 6)) || (number_format($info['video']['resolution_y'], 6) != number_format(round($info['video']['resolution_y']), 6)))) { // ugly check for floating point numbers -if (!empty($atom_structure['sample_description_table'][$i]['width']) && !empty($atom_structure['sample_description_table'][$i]['height'])) { - // assume that values stored here are more important than values stored in [tkhd] atom - $info['video']['resolution_x'] = $atom_structure['sample_description_table'][$i]['width']; - $info['video']['resolution_y'] = $atom_structure['sample_description_table'][$i]['height']; - $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x']; - $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y']; +if (! empty($atom_structure['sample_description_table'][$i]['width']) && ! empty($atom_structure['sample_description_table'][$i]['height'])) { + // assume that values stored here are more important than values stored in [tkhd] atom + $info['video']['resolution_x'] = $atom_structure['sample_description_table'][$i]['width']; + $info['video']['resolution_y'] = $atom_structure['sample_description_table'][$i]['height']; + $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x']; + $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y']; } - break; - - case 'qtvr': - $info['video']['dataformat'] = 'quicktimevr'; - break; - - case 'mp4a': - default: - $info['quicktime']['audio']['codec'] = $this->QuicktimeAudioCodecLookup($atom_structure['sample_description_table'][$i]['data_format']); - $info['quicktime']['audio']['sample_rate'] = $atom_structure['sample_description_table'][$i]['audio_sample_rate']; - $info['quicktime']['audio']['channels'] = $atom_structure['sample_description_table'][$i]['audio_channels']; - $info['quicktime']['audio']['bit_depth'] = $atom_structure['sample_description_table'][$i]['audio_bit_depth']; - $info['audio']['codec'] = $info['quicktime']['audio']['codec']; - $info['audio']['sample_rate'] = $info['quicktime']['audio']['sample_rate']; - $info['audio']['channels'] = $info['quicktime']['audio']['channels']; - $info['audio']['bits_per_sample'] = $info['quicktime']['audio']['bit_depth']; - switch ($atom_structure['sample_description_table'][$i]['data_format']) { - case 'raw ': // PCM - case 'alac': // Apple Lossless Audio Codec - $info['audio']['lossless'] = true; - break; - default: - $info['audio']['lossless'] = false; - break; - } - break; - } - break; - - default: - switch ($atom_structure['sample_description_table'][$i]['data_format']) { - case 'mp4s': - $info['fileformat'] = 'mp4'; - break; - - default: - // video atom - $atom_structure['sample_description_table'][$i]['video_temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4)); - $atom_structure['sample_description_table'][$i]['video_spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4)); - $atom_structure['sample_description_table'][$i]['video_frame_width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2)); - $atom_structure['sample_description_table'][$i]['video_frame_height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2)); - $atom_structure['sample_description_table'][$i]['video_resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 20, 4)); - $atom_structure['sample_description_table'][$i]['video_resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4)); - $atom_structure['sample_description_table'][$i]['video_data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4)); - $atom_structure['sample_description_table'][$i]['video_frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 2)); - $atom_structure['sample_description_table'][$i]['video_encoder_name_len'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 34, 1)); - $atom_structure['sample_description_table'][$i]['video_encoder_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 35, $atom_structure['sample_description_table'][$i]['video_encoder_name_len']); - $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 66, 2)); - $atom_structure['sample_description_table'][$i]['video_color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 68, 2)); - - $atom_structure['sample_description_table'][$i]['video_pixel_color_type'] = (($atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] > 32) ? 'grayscale' : 'color'); - $atom_structure['sample_description_table'][$i]['video_pixel_color_name'] = $this->QuicktimeColorNameLookup($atom_structure['sample_description_table'][$i]['video_pixel_color_depth']); - - if ($atom_structure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') { - $info['quicktime']['video']['codec_fourcc'] = $atom_structure['sample_description_table'][$i]['data_format']; - $info['quicktime']['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atom_structure['sample_description_table'][$i]['data_format']); - $info['quicktime']['video']['codec'] = (($atom_structure['sample_description_table'][$i]['video_encoder_name_len'] > 0) ? $atom_structure['sample_description_table'][$i]['video_encoder_name'] : $atom_structure['sample_description_table'][$i]['data_format']); - $info['quicktime']['video']['color_depth'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth']; - $info['quicktime']['video']['color_depth_name'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_name']; - - $info['video']['codec'] = $info['quicktime']['video']['codec']; - $info['video']['bits_per_sample'] = $info['quicktime']['video']['color_depth']; - } - $info['video']['lossless'] = false; - $info['video']['pixel_aspect_ratio'] = (float) 1; - break; - } - break; - } - switch (strtolower($atom_structure['sample_description_table'][$i]['data_format'])) { - case 'mp4a': - $info['audio']['dataformat'] = 'mp4'; - $info['quicktime']['audio']['codec'] = 'mp4'; - break; - - case '3ivx': - case '3iv1': - case '3iv2': - $info['video']['dataformat'] = '3ivx'; - break; - - case 'xvid': - $info['video']['dataformat'] = 'xvid'; - break; - - case 'mp4v': - $info['video']['dataformat'] = 'mpeg4'; - break; - - case 'divx': - case 'div1': - case 'div2': - case 'div3': - case 'div4': - case 'div5': - case 'div6': - $info['video']['dataformat'] = 'divx'; - break; - - default: - // do nothing - break; - } - unset($atom_structure['sample_description_table'][$i]['data']); - } - break; - - - case 'stts': // Sample Table Time-to-Sample atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $sttsEntriesDataOffset = 8; - //$FrameRateCalculatorArray = array(); - $frames_count = 0; - - $max_stts_entries_to_scan = ($info['php_memory_limit'] ? min(floor($this->getid3->memory_limit / 10000), $atom_structure['number_entries']) : $atom_structure['number_entries']); - if ($max_stts_entries_to_scan < $atom_structure['number_entries']) { - $this->warning('QuickTime atom "stts" has '.$atom_structure['number_entries'].' but only scanning the first '.$max_stts_entries_to_scan.' entries due to limited PHP memory available ('.floor($atom_structure['number_entries'] / 1048576).'MB).'); - } - for ($i = 0; $i < $max_stts_entries_to_scan; $i++) { - $atom_structure['time_to_sample_table'][$i]['sample_count'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4)); - $sttsEntriesDataOffset += 4; - $atom_structure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4)); - $sttsEntriesDataOffset += 4; - - $frames_count += $atom_structure['time_to_sample_table'][$i]['sample_count']; - - // THIS SECTION REPLACED WITH CODE IN "stbl" ATOM - //if (!empty($info['quicktime']['time_scale']) && ($atom_structure['time_to_sample_table'][$i]['sample_duration'] > 0)) { - // $stts_new_framerate = $info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration']; - // if ($stts_new_framerate <= 60) { - // // some atoms have durations of "1" giving a very large framerate, which probably is not right - // $info['video']['frame_rate'] = max($info['video']['frame_rate'], $stts_new_framerate); - // } - //} - // - //$FrameRateCalculatorArray[($info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'])] += $atom_structure['time_to_sample_table'][$i]['sample_count']; - } - $info['quicktime']['stts_framecount'][] = $frames_count; - //$sttsFramesTotal = 0; - //$sttsSecondsTotal = 0; - //foreach ($FrameRateCalculatorArray as $frames_per_second => $frame_count) { - // if (($frames_per_second > 60) || ($frames_per_second < 1)) { - // // not video FPS information, probably audio information - // $sttsFramesTotal = 0; - // $sttsSecondsTotal = 0; - // break; - // } - // $sttsFramesTotal += $frame_count; - // $sttsSecondsTotal += $frame_count / $frames_per_second; - //} - //if (($sttsFramesTotal > 0) && ($sttsSecondsTotal > 0)) { - // if (($sttsFramesTotal / $sttsSecondsTotal) > $info['video']['frame_rate']) { - // $info['video']['frame_rate'] = $sttsFramesTotal / $sttsSecondsTotal; - // } - //} - break; - - - case 'stss': // Sample Table Sync Sample (key frames) atom - if ($ParseAllPossibleAtoms) { - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $stssEntriesDataOffset = 8; - for ($i = 0; $i < $atom_structure['number_entries']; $i++) { - $atom_structure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stssEntriesDataOffset, 4)); - $stssEntriesDataOffset += 4; - } - } - break; - - - case 'stsc': // Sample Table Sample-to-Chunk atom - if ($ParseAllPossibleAtoms) { - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $stscEntriesDataOffset = 8; - for ($i = 0; $i < $atom_structure['number_entries']; $i++) { - $atom_structure['sample_to_chunk_table'][$i]['first_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); - $stscEntriesDataOffset += 4; - $atom_structure['sample_to_chunk_table'][$i]['samples_per_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); - $stscEntriesDataOffset += 4; - $atom_structure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); - $stscEntriesDataOffset += 4; - } - } - break; - - - case 'stsz': // Sample Table SiZe atom - if ($ParseAllPossibleAtoms) { - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['sample_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); - $stszEntriesDataOffset = 12; - if ($atom_structure['sample_size'] == 0) { - for ($i = 0; $i < $atom_structure['number_entries']; $i++) { - $atom_structure['sample_size_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stszEntriesDataOffset, 4)); - $stszEntriesDataOffset += 4; - } - } - } - break; - - - case 'stco': // Sample Table Chunk Offset atom - if ($ParseAllPossibleAtoms) { - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $stcoEntriesDataOffset = 8; - for ($i = 0; $i < $atom_structure['number_entries']; $i++) { - $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 4)); - $stcoEntriesDataOffset += 4; - } - } - break; - - - case 'co64': // Chunk Offset 64-bit (version of "stco" that supports > 2GB files) - if ($ParseAllPossibleAtoms) { - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $stcoEntriesDataOffset = 8; - for ($i = 0; $i < $atom_structure['number_entries']; $i++) { - $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 8)); - $stcoEntriesDataOffset += 8; - } - } - break; - - - case 'dref': // Data REFerence atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $drefDataOffset = 8; - for ($i = 0; $i < $atom_structure['number_entries']; $i++) { - $atom_structure['data_references'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 4)); - $drefDataOffset += 4; - $atom_structure['data_references'][$i]['type'] = substr($atom_data, $drefDataOffset, 4); - $drefDataOffset += 4; - $atom_structure['data_references'][$i]['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 1)); - $drefDataOffset += 1; - $atom_structure['data_references'][$i]['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 3)); // hardcoded: 0x0000 - $drefDataOffset += 3; - $atom_structure['data_references'][$i]['data'] = substr($atom_data, $drefDataOffset, ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3)); - $drefDataOffset += ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3); - - $atom_structure['data_references'][$i]['flags']['self_reference'] = (bool) ($atom_structure['data_references'][$i]['flags_raw'] & 0x001); - } - break; - - - case 'gmin': // base Media INformation atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); - $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); - $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2)); - $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); - $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 2)); - $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2)); - break; - - - case 'smhd': // Sound Media information HeaDer atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); - $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); - break; - - - case 'vmhd': // Video Media information HeaDer atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); - $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); - $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); - $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2)); - $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); - - $atom_structure['flags']['no_lean_ahead'] = (bool) ($atom_structure['flags_raw'] & 0x001); - break; - - - case 'hdlr': // HanDLeR reference atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['component_type'] = substr($atom_data, 4, 4); - $atom_structure['component_subtype'] = substr($atom_data, 8, 4); - $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4); - $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); - $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); - $atom_structure['component_name'] = $this->Pascal2String(substr($atom_data, 24)); - - if (($atom_structure['component_subtype'] == 'STpn') && ($atom_structure['component_manufacturer'] == 'zzzz')) { - $info['video']['dataformat'] = 'quicktimevr'; - } - break; - - - case 'mdhd': // MeDia HeaDer atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); - $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); - $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); - $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 2)); - $atom_structure['quality'] = getid3_lib::BigEndian2Int(substr($atom_data, 22, 2)); - - if ($atom_structure['time_scale'] == 0) { - $this->error('Corrupt Quicktime file: mdhd.time_scale == zero'); - return false; - } - $info['quicktime']['time_scale'] = ((isset($info['quicktime']['time_scale']) && ($info['quicktime']['time_scale'] < 1000)) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']); - - $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); - $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); - $atom_structure['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale']; - $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); - if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) { - $info['comments']['language'][] = $atom_structure['language']; - } - break; - - - case 'pnot': // Preview atom - $atom_structure['modification_date'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // "standard Macintosh format" - $atom_structure['version_number'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x00 - $atom_structure['atom_type'] = substr($atom_data, 6, 4); // usually: 'PICT' - $atom_structure['atom_index'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); // usually: 0x01 - - $atom_structure['modification_date_unix'] = getid3_lib::DateMac2Unix($atom_structure['modification_date']); - break; - - - case 'crgn': // Clipping ReGioN atom - $atom_structure['region_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); // The Region size, Region boundary box, - $atom_structure['boundary_box'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 8)); // and Clipping region data fields - $atom_structure['clipping_data'] = substr($atom_data, 10); // constitute a QuickDraw region. - break; - - - case 'load': // track LOAD settings atom - $atom_structure['preload_start_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); - $atom_structure['preload_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $atom_structure['preload_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); - $atom_structure['default_hints_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); - - $atom_structure['default_hints']['double_buffer'] = (bool) ($atom_structure['default_hints_raw'] & 0x0020); - $atom_structure['default_hints']['high_quality'] = (bool) ($atom_structure['default_hints_raw'] & 0x0100); - break; - - - case 'tmcd': // TiMe CoDe atom - case 'chap': // CHAPter list atom - case 'sync': // SYNChronization atom - case 'scpt': // tranSCriPT atom - case 'ssrc': // non-primary SouRCe atom - for ($i = 0; $i < strlen($atom_data); $i += 4) { - @$atom_structure['track_id'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4)); - } - break; - - - case 'elst': // Edit LiST atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - for ($i = 0; $i < $atom_structure['number_entries']; $i++ ) { - $atom_structure['edit_list'][$i]['track_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 0, 4)); - $atom_structure['edit_list'][$i]['media_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 4, 4)); - $atom_structure['edit_list'][$i]['media_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 8 + ($i * 12) + 8, 4)); - } - break; - - - case 'kmat': // compressed MATte atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['matte_data_raw'] = substr($atom_data, 4); - break; - - - case 'ctab': // Color TABle atom - $atom_structure['color_table_seed'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // hardcoded: 0x00000000 - $atom_structure['color_table_flags'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x8000 - $atom_structure['color_table_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)) + 1; - for ($colortableentry = 0; $colortableentry < $atom_structure['color_table_size']; $colortableentry++) { - $atom_structure['color_table'][$colortableentry]['alpha'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 0, 2)); - $atom_structure['color_table'][$colortableentry]['red'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 2, 2)); - $atom_structure['color_table'][$colortableentry]['green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 4, 2)); - $atom_structure['color_table'][$colortableentry]['blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 6, 2)); - } - break; - - - case 'mvhd': // MoVie HeaDer atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); - $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); - $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); - $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); - $atom_structure['preferred_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 20, 4)); - $atom_structure['preferred_volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 24, 2)); - $atom_structure['reserved'] = substr($atom_data, 26, 10); - $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 36, 4)); - $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4)); - $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 44, 4)); - $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 48, 4)); - $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4)); - $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 56, 4)); - $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 60, 4)); - $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4)); - $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 68, 4)); - $atom_structure['preview_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 72, 4)); - $atom_structure['preview_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 76, 4)); - $atom_structure['poster_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 80, 4)); - $atom_structure['selection_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 84, 4)); - $atom_structure['selection_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 88, 4)); - $atom_structure['current_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 92, 4)); - $atom_structure['next_track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 96, 4)); - - if ($atom_structure['time_scale'] == 0) { - $this->error('Corrupt Quicktime file: mvhd.time_scale == zero'); - return false; - } - $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); - $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); - $info['quicktime']['time_scale'] = ((isset($info['quicktime']['time_scale']) && ($info['quicktime']['time_scale'] < 1000)) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']); - $info['quicktime']['display_scale'] = $atom_structure['matrix_a']; - $info['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale']; - break; - - - case 'tkhd': // TracK HeaDer atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); - $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); - $atom_structure['trackid'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); - $atom_structure['reserved1'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); - $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); - $atom_structure['reserved2'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 8)); - $atom_structure['layer'] = getid3_lib::BigEndian2Int(substr($atom_data, 32, 2)); - $atom_structure['alternate_group'] = getid3_lib::BigEndian2Int(substr($atom_data, 34, 2)); - $atom_structure['volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 36, 2)); - $atom_structure['reserved3'] = getid3_lib::BigEndian2Int(substr($atom_data, 38, 2)); + break; + + case 'qtvr': + $info['video']['dataformat'] = 'quicktimevr'; + break; + + case 'mp4a': + default: + $info['quicktime']['audio']['codec'] = $this->QuicktimeAudioCodecLookup($atom_structure['sample_description_table'][$i]['data_format']); + $info['quicktime']['audio']['sample_rate'] = $atom_structure['sample_description_table'][$i]['audio_sample_rate']; + $info['quicktime']['audio']['channels'] = $atom_structure['sample_description_table'][$i]['audio_channels']; + $info['quicktime']['audio']['bit_depth'] = $atom_structure['sample_description_table'][$i]['audio_bit_depth']; + $info['audio']['codec'] = $info['quicktime']['audio']['codec']; + $info['audio']['sample_rate'] = $info['quicktime']['audio']['sample_rate']; + $info['audio']['channels'] = $info['quicktime']['audio']['channels']; + $info['audio']['bits_per_sample'] = $info['quicktime']['audio']['bit_depth']; + switch ($atom_structure['sample_description_table'][$i]['data_format']) { + case 'raw ': // PCM + case 'alac': // Apple Lossless Audio Codec + $info['audio']['lossless'] = true; + break; + default: + $info['audio']['lossless'] = false; + break; + } + break; + } + break; + + default: + switch ($atom_structure['sample_description_table'][$i]['data_format']) { + case 'mp4s': + $info['fileformat'] = 'mp4'; + break; + + default: + // video atom + $atom_structure['sample_description_table'][$i]['video_temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4)); + $atom_structure['sample_description_table'][$i]['video_spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4)); + $atom_structure['sample_description_table'][$i]['video_frame_width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2)); + $atom_structure['sample_description_table'][$i]['video_frame_height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2)); + $atom_structure['sample_description_table'][$i]['video_resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 20, 4)); + $atom_structure['sample_description_table'][$i]['video_resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4)); + $atom_structure['sample_description_table'][$i]['video_data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4)); + $atom_structure['sample_description_table'][$i]['video_frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 2)); + $atom_structure['sample_description_table'][$i]['video_encoder_name_len'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 34, 1)); + $atom_structure['sample_description_table'][$i]['video_encoder_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 35, $atom_structure['sample_description_table'][$i]['video_encoder_name_len']); + $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 66, 2)); + $atom_structure['sample_description_table'][$i]['video_color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 68, 2)); + + $atom_structure['sample_description_table'][$i]['video_pixel_color_type'] = (($atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] > 32) ? 'grayscale' : 'color'); + $atom_structure['sample_description_table'][$i]['video_pixel_color_name'] = $this->QuicktimeColorNameLookup($atom_structure['sample_description_table'][$i]['video_pixel_color_depth']); + + if ($atom_structure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') { + $info['quicktime']['video']['codec_fourcc'] = $atom_structure['sample_description_table'][$i]['data_format']; + $info['quicktime']['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atom_structure['sample_description_table'][$i]['data_format']); + $info['quicktime']['video']['codec'] = (($atom_structure['sample_description_table'][$i]['video_encoder_name_len'] > 0) ? $atom_structure['sample_description_table'][$i]['video_encoder_name'] : $atom_structure['sample_description_table'][$i]['data_format']); + $info['quicktime']['video']['color_depth'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth']; + $info['quicktime']['video']['color_depth_name'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_name']; + + $info['video']['codec'] = $info['quicktime']['video']['codec']; + $info['video']['bits_per_sample'] = $info['quicktime']['video']['color_depth']; + } + $info['video']['lossless'] = false; + $info['video']['pixel_aspect_ratio'] = (float) 1; + break; + } + break; + } + switch (strtolower($atom_structure['sample_description_table'][$i]['data_format'])) { + case 'mp4a': + $info['audio']['dataformat'] = 'mp4'; + $info['quicktime']['audio']['codec'] = 'mp4'; + break; + + case '3ivx': + case '3iv1': + case '3iv2': + $info['video']['dataformat'] = '3ivx'; + break; + + case 'xvid': + $info['video']['dataformat'] = 'xvid'; + break; + + case 'mp4v': + $info['video']['dataformat'] = 'mpeg4'; + break; + + case 'divx': + case 'div1': + case 'div2': + case 'div3': + case 'div4': + case 'div5': + case 'div6': + $info['video']['dataformat'] = 'divx'; + break; + + default: + // do nothing + break; + } + unset($atom_structure['sample_description_table'][$i]['data']); + } + break; + + case 'stts': // Sample Table Time-to-Sample atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $sttsEntriesDataOffset = 8; + //$FrameRateCalculatorArray = array(); + $frames_count = 0; + + $max_stts_entries_to_scan = ($info['php_memory_limit'] ? min(floor($this->getid3->memory_limit / 10000), $atom_structure['number_entries']) : $atom_structure['number_entries']); + if ($max_stts_entries_to_scan < $atom_structure['number_entries']) { + $this->warning('QuickTime atom "stts" has '.$atom_structure['number_entries'].' but only scanning the first '.$max_stts_entries_to_scan.' entries due to limited PHP memory available ('.floor($atom_structure['number_entries'] / 1048576).'MB).'); + } + for ($i = 0; $i < $max_stts_entries_to_scan; $i++) { + $atom_structure['time_to_sample_table'][$i]['sample_count'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4)); + $sttsEntriesDataOffset += 4; + $atom_structure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4)); + $sttsEntriesDataOffset += 4; + + $frames_count += $atom_structure['time_to_sample_table'][$i]['sample_count']; + + // THIS SECTION REPLACED WITH CODE IN "stbl" ATOM + //if (!empty($info['quicktime']['time_scale']) && ($atom_structure['time_to_sample_table'][$i]['sample_duration'] > 0)) { + // $stts_new_framerate = $info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration']; + // if ($stts_new_framerate <= 60) { + // // some atoms have durations of "1" giving a very large framerate, which probably is not right + // $info['video']['frame_rate'] = max($info['video']['frame_rate'], $stts_new_framerate); + // } + //} + // + //$FrameRateCalculatorArray[($info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'])] += $atom_structure['time_to_sample_table'][$i]['sample_count']; + } + $info['quicktime']['stts_framecount'][] = $frames_count; + //$sttsFramesTotal = 0; + //$sttsSecondsTotal = 0; + //foreach ($FrameRateCalculatorArray as $frames_per_second => $frame_count) { + // if (($frames_per_second > 60) || ($frames_per_second < 1)) { + // // not video FPS information, probably audio information + // $sttsFramesTotal = 0; + // $sttsSecondsTotal = 0; + // break; + // } + // $sttsFramesTotal += $frame_count; + // $sttsSecondsTotal += $frame_count / $frames_per_second; + //} + //if (($sttsFramesTotal > 0) && ($sttsSecondsTotal > 0)) { + // if (($sttsFramesTotal / $sttsSecondsTotal) > $info['video']['frame_rate']) { + // $info['video']['frame_rate'] = $sttsFramesTotal / $sttsSecondsTotal; + // } + //} + break; + + case 'stss': // Sample Table Sync Sample (key frames) atom + if ($ParseAllPossibleAtoms) { + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $stssEntriesDataOffset = 8; + for ($i = 0; $i < $atom_structure['number_entries']; $i++) { + $atom_structure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stssEntriesDataOffset, 4)); + $stssEntriesDataOffset += 4; + } + } + break; + + case 'stsc': // Sample Table Sample-to-Chunk atom + if ($ParseAllPossibleAtoms) { + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $stscEntriesDataOffset = 8; + for ($i = 0; $i < $atom_structure['number_entries']; $i++) { + $atom_structure['sample_to_chunk_table'][$i]['first_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); + $stscEntriesDataOffset += 4; + $atom_structure['sample_to_chunk_table'][$i]['samples_per_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); + $stscEntriesDataOffset += 4; + $atom_structure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); + $stscEntriesDataOffset += 4; + } + } + break; + + case 'stsz': // Sample Table SiZe atom + if ($ParseAllPossibleAtoms) { + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['sample_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); + $stszEntriesDataOffset = 12; + if ($atom_structure['sample_size'] == 0) { + for ($i = 0; $i < $atom_structure['number_entries']; $i++) { + $atom_structure['sample_size_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stszEntriesDataOffset, 4)); + $stszEntriesDataOffset += 4; + } + } + } + break; + + case 'stco': // Sample Table Chunk Offset atom + if ($ParseAllPossibleAtoms) { + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $stcoEntriesDataOffset = 8; + for ($i = 0; $i < $atom_structure['number_entries']; $i++) { + $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 4)); + $stcoEntriesDataOffset += 4; + } + } + break; + + case 'co64': // Chunk Offset 64-bit (version of "stco" that supports > 2GB files) + if ($ParseAllPossibleAtoms) { + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $stcoEntriesDataOffset = 8; + for ($i = 0; $i < $atom_structure['number_entries']; $i++) { + $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 8)); + $stcoEntriesDataOffset += 8; + } + } + break; + + case 'dref': // Data REFerence atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $drefDataOffset = 8; + for ($i = 0; $i < $atom_structure['number_entries']; $i++) { + $atom_structure['data_references'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 4)); + $drefDataOffset += 4; + $atom_structure['data_references'][$i]['type'] = substr($atom_data, $drefDataOffset, 4); + $drefDataOffset += 4; + $atom_structure['data_references'][$i]['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 1)); + $drefDataOffset += 1; + $atom_structure['data_references'][$i]['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 3)); // hardcoded: 0x0000 + $drefDataOffset += 3; + $atom_structure['data_references'][$i]['data'] = substr($atom_data, $drefDataOffset, ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3)); + $drefDataOffset += ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3); + + $atom_structure['data_references'][$i]['flags']['self_reference'] = (bool) ($atom_structure['data_references'][$i]['flags_raw'] & 0x001); + } + break; + + case 'gmin': // base Media INformation atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); + $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); + $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2)); + $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); + $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 2)); + $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2)); + break; + + case 'smhd': // Sound Media information HeaDer atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); + $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); + break; + + case 'vmhd': // Video Media information HeaDer atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); + $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); + $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); + $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2)); + $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); + + $atom_structure['flags']['no_lean_ahead'] = (bool) ($atom_structure['flags_raw'] & 0x001); + break; + + case 'hdlr': // HanDLeR reference atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['component_type'] = substr($atom_data, 4, 4); + $atom_structure['component_subtype'] = substr($atom_data, 8, 4); + $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4); + $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); + $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); + $atom_structure['component_name'] = $this->Pascal2String(substr($atom_data, 24)); + + if (($atom_structure['component_subtype'] == 'STpn') && ($atom_structure['component_manufacturer'] == 'zzzz')) { + $info['video']['dataformat'] = 'quicktimevr'; + } + break; + + case 'mdhd': // MeDia HeaDer atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); + $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); + $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); + $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 2)); + $atom_structure['quality'] = getid3_lib::BigEndian2Int(substr($atom_data, 22, 2)); + + if ($atom_structure['time_scale'] == 0) { + $this->error('Corrupt Quicktime file: mdhd.time_scale == zero'); + + return false; + } + $info['quicktime']['time_scale'] = ((isset($info['quicktime']['time_scale']) && ($info['quicktime']['time_scale'] < 1000)) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']); + + $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); + $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); + $atom_structure['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale']; + $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); + if (empty($info['comments']['language']) || (! in_array($atom_structure['language'], $info['comments']['language']))) { + $info['comments']['language'][] = $atom_structure['language']; + } + break; + + case 'pnot': // Preview atom + $atom_structure['modification_date'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // "standard Macintosh format" + $atom_structure['version_number'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x00 + $atom_structure['atom_type'] = substr($atom_data, 6, 4); // usually: 'PICT' + $atom_structure['atom_index'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); // usually: 0x01 + + $atom_structure['modification_date_unix'] = getid3_lib::DateMac2Unix($atom_structure['modification_date']); + break; + + case 'crgn': // Clipping ReGioN atom + $atom_structure['region_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); // The Region size, Region boundary box, + $atom_structure['boundary_box'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 8)); // and Clipping region data fields + $atom_structure['clipping_data'] = substr($atom_data, 10); // constitute a QuickDraw region. + break; + + case 'load': // track LOAD settings atom + $atom_structure['preload_start_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); + $atom_structure['preload_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $atom_structure['preload_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); + $atom_structure['default_hints_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); + + $atom_structure['default_hints']['double_buffer'] = (bool) ($atom_structure['default_hints_raw'] & 0x0020); + $atom_structure['default_hints']['high_quality'] = (bool) ($atom_structure['default_hints_raw'] & 0x0100); + break; + + case 'tmcd': // TiMe CoDe atom + case 'chap': // CHAPter list atom + case 'sync': // SYNChronization atom + case 'scpt': // tranSCriPT atom + case 'ssrc': // non-primary SouRCe atom + for ($i = 0; $i < strlen($atom_data); $i += 4) { + @$atom_structure['track_id'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4)); + } + break; + + case 'elst': // Edit LiST atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + for ($i = 0; $i < $atom_structure['number_entries']; $i++) { + $atom_structure['edit_list'][$i]['track_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 0, 4)); + $atom_structure['edit_list'][$i]['media_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 4, 4)); + $atom_structure['edit_list'][$i]['media_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 8 + ($i * 12) + 8, 4)); + } + break; + + case 'kmat': // compressed MATte atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['matte_data_raw'] = substr($atom_data, 4); + break; + + case 'ctab': // Color TABle atom + $atom_structure['color_table_seed'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // hardcoded: 0x00000000 + $atom_structure['color_table_flags'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x8000 + $atom_structure['color_table_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)) + 1; + for ($colortableentry = 0; $colortableentry < $atom_structure['color_table_size']; $colortableentry++) { + $atom_structure['color_table'][$colortableentry]['alpha'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 0, 2)); + $atom_structure['color_table'][$colortableentry]['red'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 2, 2)); + $atom_structure['color_table'][$colortableentry]['green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 4, 2)); + $atom_structure['color_table'][$colortableentry]['blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 6, 2)); + } + break; + + case 'mvhd': // MoVie HeaDer atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); + $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); + $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); + $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); + $atom_structure['preferred_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 20, 4)); + $atom_structure['preferred_volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 24, 2)); + $atom_structure['reserved'] = substr($atom_data, 26, 10); + $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 36, 4)); + $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4)); + $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 44, 4)); + $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 48, 4)); + $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4)); + $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 56, 4)); + $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 60, 4)); + $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4)); + $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 68, 4)); + $atom_structure['preview_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 72, 4)); + $atom_structure['preview_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 76, 4)); + $atom_structure['poster_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 80, 4)); + $atom_structure['selection_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 84, 4)); + $atom_structure['selection_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 88, 4)); + $atom_structure['current_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 92, 4)); + $atom_structure['next_track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 96, 4)); + + if ($atom_structure['time_scale'] == 0) { + $this->error('Corrupt Quicktime file: mvhd.time_scale == zero'); + + return false; + } + $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); + $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); + $info['quicktime']['time_scale'] = ((isset($info['quicktime']['time_scale']) && ($info['quicktime']['time_scale'] < 1000)) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']); + $info['quicktime']['display_scale'] = $atom_structure['matrix_a']; + $info['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale']; + break; + + case 'tkhd': // TracK HeaDer atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); + $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); + $atom_structure['trackid'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); + $atom_structure['reserved1'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); + $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); + $atom_structure['reserved2'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 8)); + $atom_structure['layer'] = getid3_lib::BigEndian2Int(substr($atom_data, 32, 2)); + $atom_structure['alternate_group'] = getid3_lib::BigEndian2Int(substr($atom_data, 34, 2)); + $atom_structure['volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 36, 2)); + $atom_structure['reserved3'] = getid3_lib::BigEndian2Int(substr($atom_data, 38, 2)); // http://developer.apple.com/library/mac/#documentation/QuickTime/RM/MovieBasics/MTEditing/K-Chapter/11MatrixFunctions.html // http://developer.apple.com/library/mac/#documentation/QuickTime/qtff/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-18737 - $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4)); - $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 44, 4)); - $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 48, 4)); - $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4)); - $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 56, 4)); - $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 60, 4)); - $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4)); - $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 68, 4)); - $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 72, 4)); - $atom_structure['width'] = getid3_lib::FixedPoint16_16(substr($atom_data, 76, 4)); - $atom_structure['height'] = getid3_lib::FixedPoint16_16(substr($atom_data, 80, 4)); - $atom_structure['flags']['enabled'] = (bool) ($atom_structure['flags_raw'] & 0x0001); - $atom_structure['flags']['in_movie'] = (bool) ($atom_structure['flags_raw'] & 0x0002); - $atom_structure['flags']['in_preview'] = (bool) ($atom_structure['flags_raw'] & 0x0004); - $atom_structure['flags']['in_poster'] = (bool) ($atom_structure['flags_raw'] & 0x0008); - $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); - $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); + $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4)); + $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 44, 4)); + $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 48, 4)); + $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4)); + $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 56, 4)); + $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 60, 4)); + $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4)); + $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 68, 4)); + $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 72, 4)); + $atom_structure['width'] = getid3_lib::FixedPoint16_16(substr($atom_data, 76, 4)); + $atom_structure['height'] = getid3_lib::FixedPoint16_16(substr($atom_data, 80, 4)); + $atom_structure['flags']['enabled'] = (bool) ($atom_structure['flags_raw'] & 0x0001); + $atom_structure['flags']['in_movie'] = (bool) ($atom_structure['flags_raw'] & 0x0002); + $atom_structure['flags']['in_preview'] = (bool) ($atom_structure['flags_raw'] & 0x0004); + $atom_structure['flags']['in_poster'] = (bool) ($atom_structure['flags_raw'] & 0x0008); + $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); + $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); - if ($atom_structure['flags']['enabled'] == 1) { - if (!isset($info['video']['resolution_x']) || !isset($info['video']['resolution_y'])) { - $info['video']['resolution_x'] = $atom_structure['width']; - $info['video']['resolution_y'] = $atom_structure['height']; - } - $info['video']['resolution_x'] = max($info['video']['resolution_x'], $atom_structure['width']); - $info['video']['resolution_y'] = max($info['video']['resolution_y'], $atom_structure['height']); - $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x']; - $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y']; - } else { - // see: http://www.getid3.org/phpBB3/viewtopic.php?t=1295 - //if (isset($info['video']['resolution_x'])) { unset($info['video']['resolution_x']); } - //if (isset($info['video']['resolution_y'])) { unset($info['video']['resolution_y']); } - //if (isset($info['quicktime']['video'])) { unset($info['quicktime']['video']); } - } - break; + if ($atom_structure['flags']['enabled'] == 1) { + if (! isset($info['video']['resolution_x']) || ! isset($info['video']['resolution_y'])) { + $info['video']['resolution_x'] = $atom_structure['width']; + $info['video']['resolution_y'] = $atom_structure['height']; + } + $info['video']['resolution_x'] = max($info['video']['resolution_x'], $atom_structure['width']); + $info['video']['resolution_y'] = max($info['video']['resolution_y'], $atom_structure['height']); + $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x']; + $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y']; + } else { + // see: http://www.getid3.org/phpBB3/viewtopic.php?t=1295 + //if (isset($info['video']['resolution_x'])) { unset($info['video']['resolution_x']); } + //if (isset($info['video']['resolution_y'])) { unset($info['video']['resolution_y']); } + //if (isset($info['quicktime']['video'])) { unset($info['quicktime']['video']); } + } + break; + case 'iods': // Initial Object DeScriptor atom + // http://www.koders.com/c/fid1FAB3E762903DC482D8A246D4A4BF9F28E049594.aspx?s=windows.h + // http://libquicktime.sourcearchive.com/documentation/1.0.2plus-pdebian/iods_8c-source.html + $offset = 0; + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 3)); + $offset += 3; + $atom_structure['mp4_iod_tag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; + $atom_structure['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset); + //$offset already adjusted by quicktime_read_mp4_descr_length() + $atom_structure['object_descriptor_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); + $offset += 2; + $atom_structure['od_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; + $atom_structure['scene_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; + $atom_structure['audio_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; + $atom_structure['video_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; + $atom_structure['graphics_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; - case 'iods': // Initial Object DeScriptor atom - // http://www.koders.com/c/fid1FAB3E762903DC482D8A246D4A4BF9F28E049594.aspx?s=windows.h - // http://libquicktime.sourcearchive.com/documentation/1.0.2plus-pdebian/iods_8c-source.html - $offset = 0; - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 3)); - $offset += 3; - $atom_structure['mp4_iod_tag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; - $atom_structure['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset); - //$offset already adjusted by quicktime_read_mp4_descr_length() - $atom_structure['object_descriptor_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); - $offset += 2; - $atom_structure['od_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; - $atom_structure['scene_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; - $atom_structure['audio_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; - $atom_structure['video_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; - $atom_structure['graphics_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; + $atom_structure['num_iods_tracks'] = ($atom_structure['length'] - 7) / 6; // 6 bytes would only be right if all tracks use 1-byte length fields + for ($i = 0; $i < $atom_structure['num_iods_tracks']; $i++) { + $atom_structure['track'][$i]['ES_ID_IncTag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; + $atom_structure['track'][$i]['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset); + //$offset already adjusted by quicktime_read_mp4_descr_length() + $atom_structure['track'][$i]['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4)); + $offset += 4; + } - $atom_structure['num_iods_tracks'] = ($atom_structure['length'] - 7) / 6; // 6 bytes would only be right if all tracks use 1-byte length fields - for ($i = 0; $i < $atom_structure['num_iods_tracks']; $i++) { - $atom_structure['track'][$i]['ES_ID_IncTag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; - $atom_structure['track'][$i]['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset); - //$offset already adjusted by quicktime_read_mp4_descr_length() - $atom_structure['track'][$i]['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4)); - $offset += 4; - } + $atom_structure['audio_profile_name'] = $this->QuicktimeIODSaudioProfileName($atom_structure['audio_profile_id']); + $atom_structure['video_profile_name'] = $this->QuicktimeIODSvideoProfileName($atom_structure['video_profile_id']); + break; - $atom_structure['audio_profile_name'] = $this->QuicktimeIODSaudioProfileName($atom_structure['audio_profile_id']); - $atom_structure['video_profile_name'] = $this->QuicktimeIODSvideoProfileName($atom_structure['video_profile_id']); - break; + case 'ftyp': // FileTYPe (?) atom (for MP4 it seems) + $atom_structure['signature'] = substr($atom_data, 0, 4); + $atom_structure['unknown_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $atom_structure['fourcc'] = substr($atom_data, 8, 4); + break; - case 'ftyp': // FileTYPe (?) atom (for MP4 it seems) - $atom_structure['signature'] = substr($atom_data, 0, 4); - $atom_structure['unknown_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $atom_structure['fourcc'] = substr($atom_data, 8, 4); - break; - - case 'mdat': // Media DATa atom - // 'mdat' contains the actual data for the audio/video, possibly also subtitles + case 'mdat': // Media DATa atom + // 'mdat' contains the actual data for the audio/video, possibly also subtitles /* due to lack of known documentation, this is a kludge implementation. If you know of documentation on how mdat is properly structed, please send it to info@getid3.org */ - // first, skip any 'wide' padding, and second 'mdat' header (with specified size of zero?) - $mdat_offset = 0; - while (true) { - if (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x08".'wide') { - $mdat_offset += 8; - } elseif (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x00".'mdat') { - $mdat_offset += 8; - } else { - break; - } - } + // first, skip any 'wide' padding, and second 'mdat' header (with specified size of zero?) + $mdat_offset = 0; + while (true) { + if (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x08".'wide') { + $mdat_offset += 8; + } elseif (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x00".'mdat') { + $mdat_offset += 8; + } else { + break; + } + } - // check to see if it looks like chapter titles, in the form of unterminated strings with a leading 16-bit size field - while (($mdat_offset < (strlen($atom_data) - 8)) - && ($chapter_string_length = getid3_lib::BigEndian2Int(substr($atom_data, $mdat_offset, 2))) - && ($chapter_string_length < 1000) - && ($chapter_string_length <= (strlen($atom_data) - $mdat_offset - 2)) - && preg_match('#^([\x00-\xFF]{2})([\x20-\xFF]+)$#', substr($atom_data, $mdat_offset, $chapter_string_length + 2), $chapter_matches)) { - list($dummy, $chapter_string_length_hex, $chapter_string) = $chapter_matches; - $mdat_offset += (2 + $chapter_string_length); - @$info['quicktime']['comments']['chapters'][] = $chapter_string; + // check to see if it looks like chapter titles, in the form of unterminated strings with a leading 16-bit size field + while (($mdat_offset < (strlen($atom_data) - 8)) + && ($chapter_string_length = getid3_lib::BigEndian2Int(substr($atom_data, $mdat_offset, 2))) + && ($chapter_string_length < 1000) + && ($chapter_string_length <= (strlen($atom_data) - $mdat_offset - 2)) + && preg_match('#^([\x00-\xFF]{2})([\x20-\xFF]+)$#', substr($atom_data, $mdat_offset, $chapter_string_length + 2), $chapter_matches)) { + list($dummy, $chapter_string_length_hex, $chapter_string) = $chapter_matches; + $mdat_offset += (2 + $chapter_string_length); + @$info['quicktime']['comments']['chapters'][] = $chapter_string; - // "encd" atom specifies encoding. In theory could be anything, almost always UTF-8, but may be UTF-16 with BOM (not currently handled) - if (substr($atom_data, $mdat_offset, 12) == "\x00\x00\x00\x0C\x65\x6E\x63\x64\x00\x00\x01\x00") { // UTF-8 - $mdat_offset += 12; - } - } + // "encd" atom specifies encoding. In theory could be anything, almost always UTF-8, but may be UTF-16 with BOM (not currently handled) + if (substr($atom_data, $mdat_offset, 12) == "\x00\x00\x00\x0C\x65\x6E\x63\x64\x00\x00\x01\x00") { // UTF-8 + $mdat_offset += 12; + } + } + if (($atomsize > 8) && (! isset($info['avdataend_tmp']) || ($info['quicktime'][$atomname]['size'] > ($info['avdataend_tmp'] - $info['avdataoffset'])))) { + $info['avdataoffset'] = $atom_structure['offset'] + 8; // $info['quicktime'][$atomname]['offset'] + 8; + $OldAVDataEnd = $info['avdataend']; + $info['avdataend'] = $atom_structure['offset'] + $atom_structure['size']; // $info['quicktime'][$atomname]['offset'] + $info['quicktime'][$atomname]['size']; - if (($atomsize > 8) && (!isset($info['avdataend_tmp']) || ($info['quicktime'][$atomname]['size'] > ($info['avdataend_tmp'] - $info['avdataoffset'])))) { + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; + $getid3_temp->info['avdataend'] = $info['avdataend']; + $getid3_mp3 = new getid3_mp3($getid3_temp); + if ($getid3_mp3->MPEGaudioHeaderValid($getid3_mp3->MPEGaudioHeaderDecode($this->fread(4)))) { + $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false); + if (! empty($getid3_temp->info['warning'])) { + foreach ($getid3_temp->info['warning'] as $value) { + $this->warning($value); + } + } + if (! empty($getid3_temp->info['mpeg'])) { + $info['mpeg'] = $getid3_temp->info['mpeg']; + if (isset($info['mpeg']['audio'])) { + $info['audio']['dataformat'] = 'mp3'; + $info['audio']['codec'] = (! empty($info['mpeg']['audio']['encoder']) ? $info['mpeg']['audio']['encoder'] : (! empty($info['mpeg']['audio']['codec']) ? $info['mpeg']['audio']['codec'] : (! empty($info['mpeg']['audio']['LAME']) ? 'LAME' : 'mp3'))); + $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; + $info['audio']['channels'] = $info['mpeg']['audio']['channels']; + $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; + $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); + $info['bitrate'] = $info['audio']['bitrate']; + } + } + } + unset($getid3_mp3, $getid3_temp); + $info['avdataend'] = $OldAVDataEnd; + unset($OldAVDataEnd); + } - $info['avdataoffset'] = $atom_structure['offset'] + 8; // $info['quicktime'][$atomname]['offset'] + 8; - $OldAVDataEnd = $info['avdataend']; - $info['avdataend'] = $atom_structure['offset'] + $atom_structure['size']; // $info['quicktime'][$atomname]['offset'] + $info['quicktime'][$atomname]['size']; + unset($mdat_offset, $chapter_string_length, $chapter_matches); + break; - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; - $getid3_temp->info['avdataend'] = $info['avdataend']; - $getid3_mp3 = new getid3_mp3($getid3_temp); - if ($getid3_mp3->MPEGaudioHeaderValid($getid3_mp3->MPEGaudioHeaderDecode($this->fread(4)))) { - $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false); - if (!empty($getid3_temp->info['warning'])) { - foreach ($getid3_temp->info['warning'] as $value) { - $this->warning($value); - } - } - if (!empty($getid3_temp->info['mpeg'])) { - $info['mpeg'] = $getid3_temp->info['mpeg']; - if (isset($info['mpeg']['audio'])) { - $info['audio']['dataformat'] = 'mp3'; - $info['audio']['codec'] = (!empty($info['mpeg']['audio']['encoder']) ? $info['mpeg']['audio']['encoder'] : (!empty($info['mpeg']['audio']['codec']) ? $info['mpeg']['audio']['codec'] : (!empty($info['mpeg']['audio']['LAME']) ? 'LAME' :'mp3'))); - $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; - $info['audio']['channels'] = $info['mpeg']['audio']['channels']; - $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; - $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); - $info['bitrate'] = $info['audio']['bitrate']; - } - } - } - unset($getid3_mp3, $getid3_temp); - $info['avdataend'] = $OldAVDataEnd; - unset($OldAVDataEnd); + case 'free': // FREE space atom + case 'skip': // SKIP atom + case 'wide': // 64-bit expansion placeholder atom + // 'free', 'skip' and 'wide' are just padding, contains no useful data at all - } + // When writing QuickTime files, it is sometimes necessary to update an atom's size. + // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom + // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime + // puts an 8-byte placeholder atom before any atoms it may have to update the size of. + // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the + // placeholder atom can be overwritten to obtain the necessary 8 extra bytes. + // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ). + break; - unset($mdat_offset, $chapter_string_length, $chapter_matches); - break; + case 'nsav': // NoSAVe atom + // http://developer.apple.com/technotes/tn/tn2038.html + $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); + break; - case 'free': // FREE space atom - case 'skip': // SKIP atom - case 'wide': // 64-bit expansion placeholder atom - // 'free', 'skip' and 'wide' are just padding, contains no useful data at all + case 'ctyp': // Controller TYPe atom (seen on QTVR) + // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt + // some controller names are: + // 0x00 + 'std' for linear movie + // 'none' for no controls + $atom_structure['ctyp'] = substr($atom_data, 0, 4); + $info['quicktime']['controller'] = $atom_structure['ctyp']; + switch ($atom_structure['ctyp']) { + case 'qtvr': + $info['video']['dataformat'] = 'quicktimevr'; + break; + } + break; - // When writing QuickTime files, it is sometimes necessary to update an atom's size. - // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom - // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime - // puts an 8-byte placeholder atom before any atoms it may have to update the size of. - // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the - // placeholder atom can be overwritten to obtain the necessary 8 extra bytes. - // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ). - break; + case 'pano': // PANOrama track (seen on QTVR) + $atom_structure['pano'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); + break; + case 'hint': // HINT track + case 'hinf': // + case 'hinv': // + case 'hnti': // + $info['quicktime']['hinting'] = true; + break; - case 'nsav': // NoSAVe atom - // http://developer.apple.com/technotes/tn/tn2038.html - $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); - break; + case 'imgt': // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR) + for ($i = 0; $i < ($atom_structure['size'] - 8); $i += 4) { + $atom_structure['imgt'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4)); + } + break; - case 'ctyp': // Controller TYPe atom (seen on QTVR) - // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt - // some controller names are: - // 0x00 + 'std' for linear movie - // 'none' for no controls - $atom_structure['ctyp'] = substr($atom_data, 0, 4); - $info['quicktime']['controller'] = $atom_structure['ctyp']; - switch ($atom_structure['ctyp']) { - case 'qtvr': - $info['video']['dataformat'] = 'quicktimevr'; - break; - } - break; + // Observed-but-not-handled atom types are just listed here to prevent warnings being generated + case 'FXTC': // Something to do with Adobe After Effects (?) + case 'PrmA': + case 'code': + case 'FIEL': // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html + case 'tapt': // TrackApertureModeDimensionsAID - http://developer.apple.com/documentation/QuickTime/Reference/QT7-1_Update_Reference/Constants/Constants.html + // tapt seems to be used to compute the video size [http://www.getid3.org/phpBB3/viewtopic.php?t=838] + // * http://lists.apple.com/archives/quicktime-api/2006/Aug/msg00014.html + // * http://handbrake.fr/irclogs/handbrake-dev/handbrake-dev20080128_pg2.html + case 'ctts':// STCompositionOffsetAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html + case 'cslg':// STCompositionShiftLeastGreatestAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html + case 'sdtp':// STSampleDependencyAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html + case 'stps':// STPartialSyncSampleAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html + //$atom_structure['data'] = $atom_data; + break; - case 'pano': // PANOrama track (seen on QTVR) - $atom_structure['pano'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); - break; + case "\xA9".'xyz': // GPS latitude+longitude+altitude + $atom_structure['data'] = $atom_data; + if (preg_match('#([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)?/$#i', $atom_data, $matches)) { + @list($all, $latitude, $longitude, $altitude) = $matches; + $info['quicktime']['comments']['gps_latitude'][] = floatval($latitude); + $info['quicktime']['comments']['gps_longitude'][] = floatval($longitude); + if (! empty($altitude)) { + $info['quicktime']['comments']['gps_altitude'][] = floatval($altitude); + } + } else { + $this->warning('QuickTime atom "©xyz" data does not match expected data pattern at offset '.$baseoffset.'. Please report as getID3() bug.'); + } + break; - case 'hint': // HINT track - case 'hinf': // - case 'hinv': // - case 'hnti': // - $info['quicktime']['hinting'] = true; - break; + case 'NCDT': + // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html + // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100 + $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 4, $atomHierarchy, $ParseAllPossibleAtoms); + break; + case 'NCTH': // Nikon Camera THumbnail image + case 'NCVW': // Nikon Camera preVieW image + // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html + if (preg_match('/^\xFF\xD8\xFF/', $atom_data)) { + $atom_structure['data'] = $atom_data; + $atom_structure['image_mime'] = 'image/jpeg'; + $atom_structure['description'] = (($atomname == 'NCTH') ? 'Nikon Camera Thumbnail Image' : (($atomname == 'NCVW') ? 'Nikon Camera Preview Image' : 'Nikon preview image')); + $info['quicktime']['comments']['picture'][] = ['image_mime'=>$atom_structure['image_mime'], 'data'=>$atom_data, 'description'=>$atom_structure['description']]; + } + break; + case 'NCTG': // Nikon - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG + $atom_structure['data'] = $this->QuicktimeParseNikonNCTG($atom_data); + break; + case 'NCHD': // Nikon:MakerNoteVersion - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html + case 'NCDB': // Nikon - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html + case 'CNCV': // Canon:CompressorVersion - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html + $atom_structure['data'] = $atom_data; + break; - case 'imgt': // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR) - for ($i = 0; $i < ($atom_structure['size'] - 8); $i += 4) { - $atom_structure['imgt'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4)); - } - break; + case "\x00\x00\x00\x00": + // some kind of metacontainer, may contain a big data dump such as: + // mdta keys \005 mdtacom.apple.quicktime.make (mdtacom.apple.quicktime.creationdate ,mdtacom.apple.quicktime.location.ISO6709 $mdtacom.apple.quicktime.software !mdtacom.apple.quicktime.model ilst \01D \001 \015data \001DE\010Apple 0 \002 (data \001DE\0102011-05-11T17:54:04+0200 2 \003 *data \001DE\010+52.4936+013.3897+040.247/ \01D \004 \015data \001DE\0104.3.1 \005 \018data \001DE\010iPhone 4 + // http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); + $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom(substr($atom_data, 4), $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); + //$atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); + break; - // Observed-but-not-handled atom types are just listed here to prevent warnings being generated - case 'FXTC': // Something to do with Adobe After Effects (?) - case 'PrmA': - case 'code': - case 'FIEL': // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html - case 'tapt': // TrackApertureModeDimensionsAID - http://developer.apple.com/documentation/QuickTime/Reference/QT7-1_Update_Reference/Constants/Constants.html - // tapt seems to be used to compute the video size [http://www.getid3.org/phpBB3/viewtopic.php?t=838] - // * http://lists.apple.com/archives/quicktime-api/2006/Aug/msg00014.html - // * http://handbrake.fr/irclogs/handbrake-dev/handbrake-dev20080128_pg2.html - case 'ctts':// STCompositionOffsetAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html - case 'cslg':// STCompositionShiftLeastGreatestAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html - case 'sdtp':// STSampleDependencyAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html - case 'stps':// STPartialSyncSampleAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html - //$atom_structure['data'] = $atom_data; - break; + case 'meta': // METAdata atom + // https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/Metadata/Metadata.html - case "\xA9".'xyz': // GPS latitude+longitude+altitude - $atom_structure['data'] = $atom_data; - if (preg_match('#([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)?/$#i', $atom_data, $matches)) { - @list($all, $latitude, $longitude, $altitude) = $matches; - $info['quicktime']['comments']['gps_latitude'][] = floatval($latitude); - $info['quicktime']['comments']['gps_longitude'][] = floatval($longitude); - if (!empty($altitude)) { - $info['quicktime']['comments']['gps_altitude'][] = floatval($altitude); - } - } else { - $this->warning('QuickTime atom "©xyz" data does not match expected data pattern at offset '.$baseoffset.'. Please report as getID3() bug.'); - } - break; + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); + $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); + break; - case 'NCDT': - // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html - // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100 - $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 4, $atomHierarchy, $ParseAllPossibleAtoms); - break; - case 'NCTH': // Nikon Camera THumbnail image - case 'NCVW': // Nikon Camera preVieW image - // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html - if (preg_match('/^\xFF\xD8\xFF/', $atom_data)) { - $atom_structure['data'] = $atom_data; - $atom_structure['image_mime'] = 'image/jpeg'; - $atom_structure['description'] = (($atomname == 'NCTH') ? 'Nikon Camera Thumbnail Image' : (($atomname == 'NCVW') ? 'Nikon Camera Preview Image' : 'Nikon preview image')); - $info['quicktime']['comments']['picture'][] = array('image_mime'=>$atom_structure['image_mime'], 'data'=>$atom_data, 'description'=>$atom_structure['description']); - } - break; - case 'NCTG': // Nikon - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG - $atom_structure['data'] = $this->QuicktimeParseNikonNCTG($atom_data); - break; - case 'NCHD': // Nikon:MakerNoteVersion - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html - case 'NCDB': // Nikon - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html - case 'CNCV': // Canon:CompressorVersion - http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html - $atom_structure['data'] = $atom_data; - break; + case 'data': // metaDATA atom + static $metaDATAkey = 1; // real ugly, but so is the QuickTime structure that stores keys and values in different multinested locations that are hard to relate to each other + // seems to be 2 bytes language code (ASCII), 2 bytes unknown (set to 0x10B5 in sample I have), remainder is useful data + $atom_structure['language'] = substr($atom_data, 4 + 0, 2); + $atom_structure['unknown'] = getid3_lib::BigEndian2Int(substr($atom_data, 4 + 2, 2)); + $atom_structure['data'] = substr($atom_data, 4 + 4); + $atom_structure['key_name'] = @$info['quicktime']['temp_meta_key_names'][$metaDATAkey++]; - case "\x00\x00\x00\x00": - // some kind of metacontainer, may contain a big data dump such as: - // mdta keys \005 mdtacom.apple.quicktime.make (mdtacom.apple.quicktime.creationdate ,mdtacom.apple.quicktime.location.ISO6709 $mdtacom.apple.quicktime.software !mdtacom.apple.quicktime.model ilst \01D \001 \015data \001DE\010Apple 0 \002 (data \001DE\0102011-05-11T17:54:04+0200 2 \003 *data \001DE\010+52.4936+013.3897+040.247/ \01D \004 \015data \001DE\0104.3.1 \005 \018data \001DE\010iPhone 4 - // http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt + if ($atom_structure['key_name'] && $atom_structure['data']) { + @$info['quicktime']['comments'][str_replace('com.apple.quicktime.', '', $atom_structure['key_name'])][] = $atom_structure['data']; + } + break; - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); - $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom(substr($atom_data, 4), $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); - //$atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); - break; + case 'keys': // KEYS that may be present in the metadata atom. + // https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/Metadata/Metadata.html#//apple_ref/doc/uid/TP40000939-CH1-SW21 + // The metadata item keys atom holds a list of the metadata keys that may be present in the metadata atom. + // This list is indexed starting with 1; 0 is a reserved index value. The metadata item keys atom is a full atom with an atom type of "keys". + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); + $atom_structure['entry_count'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $keys_atom_offset = 8; + for ($i = 1; $i <= $atom_structure['entry_count']; $i++) { + $atom_structure['keys'][$i]['key_size'] = getid3_lib::BigEndian2Int(substr($atom_data, $keys_atom_offset + 0, 4)); + $atom_structure['keys'][$i]['key_namespace'] = substr($atom_data, $keys_atom_offset + 4, 4); + $atom_structure['keys'][$i]['key_value'] = substr($atom_data, $keys_atom_offset + 8, $atom_structure['keys'][$i]['key_size'] - 8); + $keys_atom_offset += $atom_structure['keys'][$i]['key_size']; // key_size includes the 4+4 bytes for key_size and key_namespace - case 'meta': // METAdata atom - // https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/Metadata/Metadata.html + $info['quicktime']['temp_meta_key_names'][$i] = $atom_structure['keys'][$i]['key_value']; + } + break; - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); - $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); - break; + default: + $this->warning('Unknown QuickTime atom type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" ('.trim(getid3_lib::PrintHexBytes($atomname)).') at offset '.$baseoffset); + $atom_structure['data'] = $atom_data; + break; + } + array_pop($atomHierarchy); - case 'data': // metaDATA atom - static $metaDATAkey = 1; // real ugly, but so is the QuickTime structure that stores keys and values in different multinested locations that are hard to relate to each other - // seems to be 2 bytes language code (ASCII), 2 bytes unknown (set to 0x10B5 in sample I have), remainder is useful data - $atom_structure['language'] = substr($atom_data, 4 + 0, 2); - $atom_structure['unknown'] = getid3_lib::BigEndian2Int(substr($atom_data, 4 + 2, 2)); - $atom_structure['data'] = substr($atom_data, 4 + 4); - $atom_structure['key_name'] = @$info['quicktime']['temp_meta_key_names'][$metaDATAkey++]; + return $atom_structure; + } - if ($atom_structure['key_name'] && $atom_structure['data']) { - @$info['quicktime']['comments'][str_replace('com.apple.quicktime.', '', $atom_structure['key_name'])][] = $atom_structure['data']; - } - break; + public function QuicktimeParseContainerAtom($atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) + { + //echo 'QuicktimeParseContainerAtom('.substr($atom_data, 4, 4).') @ '.$baseoffset.'

    '; + $atom_structure = false; + $subatomoffset = 0; + $subatomcounter = 0; + if ((strlen($atom_data) == 4) && (getid3_lib::BigEndian2Int($atom_data) == 0x00000000)) { + return false; + } + while ($subatomoffset < strlen($atom_data)) { + $subatomsize = getid3_lib::BigEndian2Int(substr($atom_data, $subatomoffset + 0, 4)); + $subatomname = substr($atom_data, $subatomoffset + 4, 4); + $subatomdata = substr($atom_data, $subatomoffset + 8, $subatomsize - 8); + if ($subatomsize == 0) { + // Furthermore, for historical reasons the list of atoms is optionally + // terminated by a 32-bit integer set to 0. If you are writing a program + // to read user data atoms, you should allow for the terminating 0. + if (strlen($atom_data) > 12) { + $subatomoffset += 4; + continue; + } - case 'keys': // KEYS that may be present in the metadata atom. - // https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/Metadata/Metadata.html#//apple_ref/doc/uid/TP40000939-CH1-SW21 - // The metadata item keys atom holds a list of the metadata keys that may be present in the metadata atom. - // This list is indexed starting with 1; 0 is a reserved index value. The metadata item keys atom is a full atom with an atom type of "keys". - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); - $atom_structure['entry_count'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $keys_atom_offset = 8; - for ($i = 1; $i <= $atom_structure['entry_count']; $i++) { - $atom_structure['keys'][$i]['key_size'] = getid3_lib::BigEndian2Int(substr($atom_data, $keys_atom_offset + 0, 4)); - $atom_structure['keys'][$i]['key_namespace'] = substr($atom_data, $keys_atom_offset + 4, 4); - $atom_structure['keys'][$i]['key_value'] = substr($atom_data, $keys_atom_offset + 8, $atom_structure['keys'][$i]['key_size'] - 8); - $keys_atom_offset += $atom_structure['keys'][$i]['key_size']; // key_size includes the 4+4 bytes for key_size and key_namespace + return $atom_structure; + } - $info['quicktime']['temp_meta_key_names'][$i] = $atom_structure['keys'][$i]['key_value']; - } - break; + $atom_structure[$subatomcounter] = $this->QuicktimeParseAtom($subatomname, $subatomsize, $subatomdata, $baseoffset + $subatomoffset, $atomHierarchy, $ParseAllPossibleAtoms); - default: - $this->warning('Unknown QuickTime atom type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" ('.trim(getid3_lib::PrintHexBytes($atomname)).') at offset '.$baseoffset); - $atom_structure['data'] = $atom_data; - break; - } - array_pop($atomHierarchy); - return $atom_structure; - } + $subatomoffset += $subatomsize; + $subatomcounter++; + } - public function QuicktimeParseContainerAtom($atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) { -//echo 'QuicktimeParseContainerAtom('.substr($atom_data, 4, 4).') @ '.$baseoffset.'

    '; - $atom_structure = false; - $subatomoffset = 0; - $subatomcounter = 0; - if ((strlen($atom_data) == 4) && (getid3_lib::BigEndian2Int($atom_data) == 0x00000000)) { - return false; - } - while ($subatomoffset < strlen($atom_data)) { - $subatomsize = getid3_lib::BigEndian2Int(substr($atom_data, $subatomoffset + 0, 4)); - $subatomname = substr($atom_data, $subatomoffset + 4, 4); - $subatomdata = substr($atom_data, $subatomoffset + 8, $subatomsize - 8); - if ($subatomsize == 0) { - // Furthermore, for historical reasons the list of atoms is optionally - // terminated by a 32-bit integer set to 0. If you are writing a program - // to read user data atoms, you should allow for the terminating 0. - if (strlen($atom_data) > 12) { - $subatomoffset += 4; - continue; - } - return $atom_structure; - } + return $atom_structure; + } - $atom_structure[$subatomcounter] = $this->QuicktimeParseAtom($subatomname, $subatomsize, $subatomdata, $baseoffset + $subatomoffset, $atomHierarchy, $ParseAllPossibleAtoms); + public function quicktime_read_mp4_descr_length($data, &$offset) + { + // http://libquicktime.sourcearchive.com/documentation/2:1.0.2plus-pdebian-2build1/esds_8c-source.html + $num_bytes = 0; + $length = 0; + do { + $b = ord(substr($data, $offset++, 1)); + $length = ($length << 7) | ($b & 0x7F); + } while (($b & 0x80) && ($num_bytes++ < 4)); - $subatomoffset += $subatomsize; - $subatomcounter++; - } - return $atom_structure; - } + return $length; + } + public function QuicktimeLanguageLookup($languageid) + { + // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-34353 + static $QuicktimeLanguageLookup = []; + if (empty($QuicktimeLanguageLookup)) { + $QuicktimeLanguageLookup[0] = 'English'; + $QuicktimeLanguageLookup[1] = 'French'; + $QuicktimeLanguageLookup[2] = 'German'; + $QuicktimeLanguageLookup[3] = 'Italian'; + $QuicktimeLanguageLookup[4] = 'Dutch'; + $QuicktimeLanguageLookup[5] = 'Swedish'; + $QuicktimeLanguageLookup[6] = 'Spanish'; + $QuicktimeLanguageLookup[7] = 'Danish'; + $QuicktimeLanguageLookup[8] = 'Portuguese'; + $QuicktimeLanguageLookup[9] = 'Norwegian'; + $QuicktimeLanguageLookup[10] = 'Hebrew'; + $QuicktimeLanguageLookup[11] = 'Japanese'; + $QuicktimeLanguageLookup[12] = 'Arabic'; + $QuicktimeLanguageLookup[13] = 'Finnish'; + $QuicktimeLanguageLookup[14] = 'Greek'; + $QuicktimeLanguageLookup[15] = 'Icelandic'; + $QuicktimeLanguageLookup[16] = 'Maltese'; + $QuicktimeLanguageLookup[17] = 'Turkish'; + $QuicktimeLanguageLookup[18] = 'Croatian'; + $QuicktimeLanguageLookup[19] = 'Chinese (Traditional)'; + $QuicktimeLanguageLookup[20] = 'Urdu'; + $QuicktimeLanguageLookup[21] = 'Hindi'; + $QuicktimeLanguageLookup[22] = 'Thai'; + $QuicktimeLanguageLookup[23] = 'Korean'; + $QuicktimeLanguageLookup[24] = 'Lithuanian'; + $QuicktimeLanguageLookup[25] = 'Polish'; + $QuicktimeLanguageLookup[26] = 'Hungarian'; + $QuicktimeLanguageLookup[27] = 'Estonian'; + $QuicktimeLanguageLookup[28] = 'Lettish'; + $QuicktimeLanguageLookup[28] = 'Latvian'; + $QuicktimeLanguageLookup[29] = 'Saamisk'; + $QuicktimeLanguageLookup[29] = 'Lappish'; + $QuicktimeLanguageLookup[30] = 'Faeroese'; + $QuicktimeLanguageLookup[31] = 'Farsi'; + $QuicktimeLanguageLookup[31] = 'Persian'; + $QuicktimeLanguageLookup[32] = 'Russian'; + $QuicktimeLanguageLookup[33] = 'Chinese (Simplified)'; + $QuicktimeLanguageLookup[34] = 'Flemish'; + $QuicktimeLanguageLookup[35] = 'Irish'; + $QuicktimeLanguageLookup[36] = 'Albanian'; + $QuicktimeLanguageLookup[37] = 'Romanian'; + $QuicktimeLanguageLookup[38] = 'Czech'; + $QuicktimeLanguageLookup[39] = 'Slovak'; + $QuicktimeLanguageLookup[40] = 'Slovenian'; + $QuicktimeLanguageLookup[41] = 'Yiddish'; + $QuicktimeLanguageLookup[42] = 'Serbian'; + $QuicktimeLanguageLookup[43] = 'Macedonian'; + $QuicktimeLanguageLookup[44] = 'Bulgarian'; + $QuicktimeLanguageLookup[45] = 'Ukrainian'; + $QuicktimeLanguageLookup[46] = 'Byelorussian'; + $QuicktimeLanguageLookup[47] = 'Uzbek'; + $QuicktimeLanguageLookup[48] = 'Kazakh'; + $QuicktimeLanguageLookup[49] = 'Azerbaijani'; + $QuicktimeLanguageLookup[50] = 'AzerbaijanAr'; + $QuicktimeLanguageLookup[51] = 'Armenian'; + $QuicktimeLanguageLookup[52] = 'Georgian'; + $QuicktimeLanguageLookup[53] = 'Moldavian'; + $QuicktimeLanguageLookup[54] = 'Kirghiz'; + $QuicktimeLanguageLookup[55] = 'Tajiki'; + $QuicktimeLanguageLookup[56] = 'Turkmen'; + $QuicktimeLanguageLookup[57] = 'Mongolian'; + $QuicktimeLanguageLookup[58] = 'MongolianCyr'; + $QuicktimeLanguageLookup[59] = 'Pashto'; + $QuicktimeLanguageLookup[60] = 'Kurdish'; + $QuicktimeLanguageLookup[61] = 'Kashmiri'; + $QuicktimeLanguageLookup[62] = 'Sindhi'; + $QuicktimeLanguageLookup[63] = 'Tibetan'; + $QuicktimeLanguageLookup[64] = 'Nepali'; + $QuicktimeLanguageLookup[65] = 'Sanskrit'; + $QuicktimeLanguageLookup[66] = 'Marathi'; + $QuicktimeLanguageLookup[67] = 'Bengali'; + $QuicktimeLanguageLookup[68] = 'Assamese'; + $QuicktimeLanguageLookup[69] = 'Gujarati'; + $QuicktimeLanguageLookup[70] = 'Punjabi'; + $QuicktimeLanguageLookup[71] = 'Oriya'; + $QuicktimeLanguageLookup[72] = 'Malayalam'; + $QuicktimeLanguageLookup[73] = 'Kannada'; + $QuicktimeLanguageLookup[74] = 'Tamil'; + $QuicktimeLanguageLookup[75] = 'Telugu'; + $QuicktimeLanguageLookup[76] = 'Sinhalese'; + $QuicktimeLanguageLookup[77] = 'Burmese'; + $QuicktimeLanguageLookup[78] = 'Khmer'; + $QuicktimeLanguageLookup[79] = 'Lao'; + $QuicktimeLanguageLookup[80] = 'Vietnamese'; + $QuicktimeLanguageLookup[81] = 'Indonesian'; + $QuicktimeLanguageLookup[82] = 'Tagalog'; + $QuicktimeLanguageLookup[83] = 'MalayRoman'; + $QuicktimeLanguageLookup[84] = 'MalayArabic'; + $QuicktimeLanguageLookup[85] = 'Amharic'; + $QuicktimeLanguageLookup[86] = 'Tigrinya'; + $QuicktimeLanguageLookup[87] = 'Galla'; + $QuicktimeLanguageLookup[87] = 'Oromo'; + $QuicktimeLanguageLookup[88] = 'Somali'; + $QuicktimeLanguageLookup[89] = 'Swahili'; + $QuicktimeLanguageLookup[90] = 'Ruanda'; + $QuicktimeLanguageLookup[91] = 'Rundi'; + $QuicktimeLanguageLookup[92] = 'Chewa'; + $QuicktimeLanguageLookup[93] = 'Malagasy'; + $QuicktimeLanguageLookup[94] = 'Esperanto'; + $QuicktimeLanguageLookup[128] = 'Welsh'; + $QuicktimeLanguageLookup[129] = 'Basque'; + $QuicktimeLanguageLookup[130] = 'Catalan'; + $QuicktimeLanguageLookup[131] = 'Latin'; + $QuicktimeLanguageLookup[132] = 'Quechua'; + $QuicktimeLanguageLookup[133] = 'Guarani'; + $QuicktimeLanguageLookup[134] = 'Aymara'; + $QuicktimeLanguageLookup[135] = 'Tatar'; + $QuicktimeLanguageLookup[136] = 'Uighur'; + $QuicktimeLanguageLookup[137] = 'Dzongkha'; + $QuicktimeLanguageLookup[138] = 'JavaneseRom'; + $QuicktimeLanguageLookup[32767] = 'Unspecified'; + } + if (($languageid > 138) && ($languageid < 32767)) { + /* + ISO Language Codes - http://www.loc.gov/standards/iso639-2/php/code_list.php + Because the language codes specified by ISO 639-2/T are three characters long, they must be packed to fit into a 16-bit field. + The packing algorithm must map each of the three characters, which are always lowercase, into a 5-bit integer and then concatenate + these integers into the least significant 15 bits of a 16-bit integer, leaving the 16-bit integer's most significant bit set to zero. - public function quicktime_read_mp4_descr_length($data, &$offset) { - // http://libquicktime.sourcearchive.com/documentation/2:1.0.2plus-pdebian-2build1/esds_8c-source.html - $num_bytes = 0; - $length = 0; - do { - $b = ord(substr($data, $offset++, 1)); - $length = ($length << 7) | ($b & 0x7F); - } while (($b & 0x80) && ($num_bytes++ < 4)); - return $length; - } + One algorithm for performing this packing is to treat each ISO character as a 16-bit integer. Subtract 0x60 from the first character + and multiply by 2^10 (0x400), subtract 0x60 from the second character and multiply by 2^5 (0x20), subtract 0x60 from the third character, + and add the three 16-bit values. This will result in a single 16-bit value with the three codes correctly packed into the 15 least + significant bits and the most significant bit set to zero. + */ + $iso_language_id = ''; + $iso_language_id .= chr((($languageid & 0x7C00) >> 10) + 0x60); + $iso_language_id .= chr((($languageid & 0x03E0) >> 5) + 0x60); + $iso_language_id .= chr((($languageid & 0x001F) >> 0) + 0x60); + $QuicktimeLanguageLookup[$languageid] = getid3_id3v2::LanguageLookup($iso_language_id); + } + return isset($QuicktimeLanguageLookup[$languageid]) ? $QuicktimeLanguageLookup[$languageid] : 'invalid'; + } - public function QuicktimeLanguageLookup($languageid) { - // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-34353 - static $QuicktimeLanguageLookup = array(); - if (empty($QuicktimeLanguageLookup)) { - $QuicktimeLanguageLookup[0] = 'English'; - $QuicktimeLanguageLookup[1] = 'French'; - $QuicktimeLanguageLookup[2] = 'German'; - $QuicktimeLanguageLookup[3] = 'Italian'; - $QuicktimeLanguageLookup[4] = 'Dutch'; - $QuicktimeLanguageLookup[5] = 'Swedish'; - $QuicktimeLanguageLookup[6] = 'Spanish'; - $QuicktimeLanguageLookup[7] = 'Danish'; - $QuicktimeLanguageLookup[8] = 'Portuguese'; - $QuicktimeLanguageLookup[9] = 'Norwegian'; - $QuicktimeLanguageLookup[10] = 'Hebrew'; - $QuicktimeLanguageLookup[11] = 'Japanese'; - $QuicktimeLanguageLookup[12] = 'Arabic'; - $QuicktimeLanguageLookup[13] = 'Finnish'; - $QuicktimeLanguageLookup[14] = 'Greek'; - $QuicktimeLanguageLookup[15] = 'Icelandic'; - $QuicktimeLanguageLookup[16] = 'Maltese'; - $QuicktimeLanguageLookup[17] = 'Turkish'; - $QuicktimeLanguageLookup[18] = 'Croatian'; - $QuicktimeLanguageLookup[19] = 'Chinese (Traditional)'; - $QuicktimeLanguageLookup[20] = 'Urdu'; - $QuicktimeLanguageLookup[21] = 'Hindi'; - $QuicktimeLanguageLookup[22] = 'Thai'; - $QuicktimeLanguageLookup[23] = 'Korean'; - $QuicktimeLanguageLookup[24] = 'Lithuanian'; - $QuicktimeLanguageLookup[25] = 'Polish'; - $QuicktimeLanguageLookup[26] = 'Hungarian'; - $QuicktimeLanguageLookup[27] = 'Estonian'; - $QuicktimeLanguageLookup[28] = 'Lettish'; - $QuicktimeLanguageLookup[28] = 'Latvian'; - $QuicktimeLanguageLookup[29] = 'Saamisk'; - $QuicktimeLanguageLookup[29] = 'Lappish'; - $QuicktimeLanguageLookup[30] = 'Faeroese'; - $QuicktimeLanguageLookup[31] = 'Farsi'; - $QuicktimeLanguageLookup[31] = 'Persian'; - $QuicktimeLanguageLookup[32] = 'Russian'; - $QuicktimeLanguageLookup[33] = 'Chinese (Simplified)'; - $QuicktimeLanguageLookup[34] = 'Flemish'; - $QuicktimeLanguageLookup[35] = 'Irish'; - $QuicktimeLanguageLookup[36] = 'Albanian'; - $QuicktimeLanguageLookup[37] = 'Romanian'; - $QuicktimeLanguageLookup[38] = 'Czech'; - $QuicktimeLanguageLookup[39] = 'Slovak'; - $QuicktimeLanguageLookup[40] = 'Slovenian'; - $QuicktimeLanguageLookup[41] = 'Yiddish'; - $QuicktimeLanguageLookup[42] = 'Serbian'; - $QuicktimeLanguageLookup[43] = 'Macedonian'; - $QuicktimeLanguageLookup[44] = 'Bulgarian'; - $QuicktimeLanguageLookup[45] = 'Ukrainian'; - $QuicktimeLanguageLookup[46] = 'Byelorussian'; - $QuicktimeLanguageLookup[47] = 'Uzbek'; - $QuicktimeLanguageLookup[48] = 'Kazakh'; - $QuicktimeLanguageLookup[49] = 'Azerbaijani'; - $QuicktimeLanguageLookup[50] = 'AzerbaijanAr'; - $QuicktimeLanguageLookup[51] = 'Armenian'; - $QuicktimeLanguageLookup[52] = 'Georgian'; - $QuicktimeLanguageLookup[53] = 'Moldavian'; - $QuicktimeLanguageLookup[54] = 'Kirghiz'; - $QuicktimeLanguageLookup[55] = 'Tajiki'; - $QuicktimeLanguageLookup[56] = 'Turkmen'; - $QuicktimeLanguageLookup[57] = 'Mongolian'; - $QuicktimeLanguageLookup[58] = 'MongolianCyr'; - $QuicktimeLanguageLookup[59] = 'Pashto'; - $QuicktimeLanguageLookup[60] = 'Kurdish'; - $QuicktimeLanguageLookup[61] = 'Kashmiri'; - $QuicktimeLanguageLookup[62] = 'Sindhi'; - $QuicktimeLanguageLookup[63] = 'Tibetan'; - $QuicktimeLanguageLookup[64] = 'Nepali'; - $QuicktimeLanguageLookup[65] = 'Sanskrit'; - $QuicktimeLanguageLookup[66] = 'Marathi'; - $QuicktimeLanguageLookup[67] = 'Bengali'; - $QuicktimeLanguageLookup[68] = 'Assamese'; - $QuicktimeLanguageLookup[69] = 'Gujarati'; - $QuicktimeLanguageLookup[70] = 'Punjabi'; - $QuicktimeLanguageLookup[71] = 'Oriya'; - $QuicktimeLanguageLookup[72] = 'Malayalam'; - $QuicktimeLanguageLookup[73] = 'Kannada'; - $QuicktimeLanguageLookup[74] = 'Tamil'; - $QuicktimeLanguageLookup[75] = 'Telugu'; - $QuicktimeLanguageLookup[76] = 'Sinhalese'; - $QuicktimeLanguageLookup[77] = 'Burmese'; - $QuicktimeLanguageLookup[78] = 'Khmer'; - $QuicktimeLanguageLookup[79] = 'Lao'; - $QuicktimeLanguageLookup[80] = 'Vietnamese'; - $QuicktimeLanguageLookup[81] = 'Indonesian'; - $QuicktimeLanguageLookup[82] = 'Tagalog'; - $QuicktimeLanguageLookup[83] = 'MalayRoman'; - $QuicktimeLanguageLookup[84] = 'MalayArabic'; - $QuicktimeLanguageLookup[85] = 'Amharic'; - $QuicktimeLanguageLookup[86] = 'Tigrinya'; - $QuicktimeLanguageLookup[87] = 'Galla'; - $QuicktimeLanguageLookup[87] = 'Oromo'; - $QuicktimeLanguageLookup[88] = 'Somali'; - $QuicktimeLanguageLookup[89] = 'Swahili'; - $QuicktimeLanguageLookup[90] = 'Ruanda'; - $QuicktimeLanguageLookup[91] = 'Rundi'; - $QuicktimeLanguageLookup[92] = 'Chewa'; - $QuicktimeLanguageLookup[93] = 'Malagasy'; - $QuicktimeLanguageLookup[94] = 'Esperanto'; - $QuicktimeLanguageLookup[128] = 'Welsh'; - $QuicktimeLanguageLookup[129] = 'Basque'; - $QuicktimeLanguageLookup[130] = 'Catalan'; - $QuicktimeLanguageLookup[131] = 'Latin'; - $QuicktimeLanguageLookup[132] = 'Quechua'; - $QuicktimeLanguageLookup[133] = 'Guarani'; - $QuicktimeLanguageLookup[134] = 'Aymara'; - $QuicktimeLanguageLookup[135] = 'Tatar'; - $QuicktimeLanguageLookup[136] = 'Uighur'; - $QuicktimeLanguageLookup[137] = 'Dzongkha'; - $QuicktimeLanguageLookup[138] = 'JavaneseRom'; - $QuicktimeLanguageLookup[32767] = 'Unspecified'; - } - if (($languageid > 138) && ($languageid < 32767)) { - /* - ISO Language Codes - http://www.loc.gov/standards/iso639-2/php/code_list.php - Because the language codes specified by ISO 639-2/T are three characters long, they must be packed to fit into a 16-bit field. - The packing algorithm must map each of the three characters, which are always lowercase, into a 5-bit integer and then concatenate - these integers into the least significant 15 bits of a 16-bit integer, leaving the 16-bit integer's most significant bit set to zero. + public function QuicktimeVideoCodecLookup($codecid) + { + static $QuicktimeVideoCodecLookup = []; + if (empty($QuicktimeVideoCodecLookup)) { + $QuicktimeVideoCodecLookup['.SGI'] = 'SGI'; + $QuicktimeVideoCodecLookup['3IV1'] = '3ivx MPEG-4 v1'; + $QuicktimeVideoCodecLookup['3IV2'] = '3ivx MPEG-4 v2'; + $QuicktimeVideoCodecLookup['3IVX'] = '3ivx MPEG-4'; + $QuicktimeVideoCodecLookup['8BPS'] = 'Planar RGB'; + $QuicktimeVideoCodecLookup['avc1'] = 'H.264/MPEG-4 AVC'; + $QuicktimeVideoCodecLookup['avr '] = 'AVR-JPEG'; + $QuicktimeVideoCodecLookup['b16g'] = '16Gray'; + $QuicktimeVideoCodecLookup['b32a'] = '32AlphaGray'; + $QuicktimeVideoCodecLookup['b48r'] = '48RGB'; + $QuicktimeVideoCodecLookup['b64a'] = '64ARGB'; + $QuicktimeVideoCodecLookup['base'] = 'Base'; + $QuicktimeVideoCodecLookup['clou'] = 'Cloud'; + $QuicktimeVideoCodecLookup['cmyk'] = 'CMYK'; + $QuicktimeVideoCodecLookup['cvid'] = 'Cinepak'; + $QuicktimeVideoCodecLookup['dmb1'] = 'OpenDML JPEG'; + $QuicktimeVideoCodecLookup['dvc '] = 'DVC-NTSC'; + $QuicktimeVideoCodecLookup['dvcp'] = 'DVC-PAL'; + $QuicktimeVideoCodecLookup['dvpn'] = 'DVCPro-NTSC'; + $QuicktimeVideoCodecLookup['dvpp'] = 'DVCPro-PAL'; + $QuicktimeVideoCodecLookup['fire'] = 'Fire'; + $QuicktimeVideoCodecLookup['flic'] = 'FLC'; + $QuicktimeVideoCodecLookup['gif '] = 'GIF'; + $QuicktimeVideoCodecLookup['h261'] = 'H261'; + $QuicktimeVideoCodecLookup['h263'] = 'H263'; + $QuicktimeVideoCodecLookup['IV41'] = 'Indeo4'; + $QuicktimeVideoCodecLookup['jpeg'] = 'JPEG'; + $QuicktimeVideoCodecLookup['kpcd'] = 'PhotoCD'; + $QuicktimeVideoCodecLookup['mjpa'] = 'Motion JPEG-A'; + $QuicktimeVideoCodecLookup['mjpb'] = 'Motion JPEG-B'; + $QuicktimeVideoCodecLookup['msvc'] = 'Microsoft Video1'; + $QuicktimeVideoCodecLookup['myuv'] = 'MPEG YUV420'; + $QuicktimeVideoCodecLookup['path'] = 'Vector'; + $QuicktimeVideoCodecLookup['png '] = 'PNG'; + $QuicktimeVideoCodecLookup['PNTG'] = 'MacPaint'; + $QuicktimeVideoCodecLookup['qdgx'] = 'QuickDrawGX'; + $QuicktimeVideoCodecLookup['qdrw'] = 'QuickDraw'; + $QuicktimeVideoCodecLookup['raw '] = 'RAW'; + $QuicktimeVideoCodecLookup['ripl'] = 'WaterRipple'; + $QuicktimeVideoCodecLookup['rpza'] = 'Video'; + $QuicktimeVideoCodecLookup['smc '] = 'Graphics'; + $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 1'; + $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 3'; + $QuicktimeVideoCodecLookup['syv9'] = 'Sorenson YUV9'; + $QuicktimeVideoCodecLookup['tga '] = 'Targa'; + $QuicktimeVideoCodecLookup['tiff'] = 'TIFF'; + $QuicktimeVideoCodecLookup['WRAW'] = 'Windows RAW'; + $QuicktimeVideoCodecLookup['WRLE'] = 'BMP'; + $QuicktimeVideoCodecLookup['y420'] = 'YUV420'; + $QuicktimeVideoCodecLookup['yuv2'] = 'ComponentVideo'; + $QuicktimeVideoCodecLookup['yuvs'] = 'ComponentVideoUnsigned'; + $QuicktimeVideoCodecLookup['yuvu'] = 'ComponentVideoSigned'; + } - One algorithm for performing this packing is to treat each ISO character as a 16-bit integer. Subtract 0x60 from the first character - and multiply by 2^10 (0x400), subtract 0x60 from the second character and multiply by 2^5 (0x20), subtract 0x60 from the third character, - and add the three 16-bit values. This will result in a single 16-bit value with the three codes correctly packed into the 15 least - significant bits and the most significant bit set to zero. - */ - $iso_language_id = ''; - $iso_language_id .= chr((($languageid & 0x7C00) >> 10) + 0x60); - $iso_language_id .= chr((($languageid & 0x03E0) >> 5) + 0x60); - $iso_language_id .= chr((($languageid & 0x001F) >> 0) + 0x60); - $QuicktimeLanguageLookup[$languageid] = getid3_id3v2::LanguageLookup($iso_language_id); - } - return (isset($QuicktimeLanguageLookup[$languageid]) ? $QuicktimeLanguageLookup[$languageid] : 'invalid'); - } + return isset($QuicktimeVideoCodecLookup[$codecid]) ? $QuicktimeVideoCodecLookup[$codecid] : ''; + } - public function QuicktimeVideoCodecLookup($codecid) { - static $QuicktimeVideoCodecLookup = array(); - if (empty($QuicktimeVideoCodecLookup)) { - $QuicktimeVideoCodecLookup['.SGI'] = 'SGI'; - $QuicktimeVideoCodecLookup['3IV1'] = '3ivx MPEG-4 v1'; - $QuicktimeVideoCodecLookup['3IV2'] = '3ivx MPEG-4 v2'; - $QuicktimeVideoCodecLookup['3IVX'] = '3ivx MPEG-4'; - $QuicktimeVideoCodecLookup['8BPS'] = 'Planar RGB'; - $QuicktimeVideoCodecLookup['avc1'] = 'H.264/MPEG-4 AVC'; - $QuicktimeVideoCodecLookup['avr '] = 'AVR-JPEG'; - $QuicktimeVideoCodecLookup['b16g'] = '16Gray'; - $QuicktimeVideoCodecLookup['b32a'] = '32AlphaGray'; - $QuicktimeVideoCodecLookup['b48r'] = '48RGB'; - $QuicktimeVideoCodecLookup['b64a'] = '64ARGB'; - $QuicktimeVideoCodecLookup['base'] = 'Base'; - $QuicktimeVideoCodecLookup['clou'] = 'Cloud'; - $QuicktimeVideoCodecLookup['cmyk'] = 'CMYK'; - $QuicktimeVideoCodecLookup['cvid'] = 'Cinepak'; - $QuicktimeVideoCodecLookup['dmb1'] = 'OpenDML JPEG'; - $QuicktimeVideoCodecLookup['dvc '] = 'DVC-NTSC'; - $QuicktimeVideoCodecLookup['dvcp'] = 'DVC-PAL'; - $QuicktimeVideoCodecLookup['dvpn'] = 'DVCPro-NTSC'; - $QuicktimeVideoCodecLookup['dvpp'] = 'DVCPro-PAL'; - $QuicktimeVideoCodecLookup['fire'] = 'Fire'; - $QuicktimeVideoCodecLookup['flic'] = 'FLC'; - $QuicktimeVideoCodecLookup['gif '] = 'GIF'; - $QuicktimeVideoCodecLookup['h261'] = 'H261'; - $QuicktimeVideoCodecLookup['h263'] = 'H263'; - $QuicktimeVideoCodecLookup['IV41'] = 'Indeo4'; - $QuicktimeVideoCodecLookup['jpeg'] = 'JPEG'; - $QuicktimeVideoCodecLookup['kpcd'] = 'PhotoCD'; - $QuicktimeVideoCodecLookup['mjpa'] = 'Motion JPEG-A'; - $QuicktimeVideoCodecLookup['mjpb'] = 'Motion JPEG-B'; - $QuicktimeVideoCodecLookup['msvc'] = 'Microsoft Video1'; - $QuicktimeVideoCodecLookup['myuv'] = 'MPEG YUV420'; - $QuicktimeVideoCodecLookup['path'] = 'Vector'; - $QuicktimeVideoCodecLookup['png '] = 'PNG'; - $QuicktimeVideoCodecLookup['PNTG'] = 'MacPaint'; - $QuicktimeVideoCodecLookup['qdgx'] = 'QuickDrawGX'; - $QuicktimeVideoCodecLookup['qdrw'] = 'QuickDraw'; - $QuicktimeVideoCodecLookup['raw '] = 'RAW'; - $QuicktimeVideoCodecLookup['ripl'] = 'WaterRipple'; - $QuicktimeVideoCodecLookup['rpza'] = 'Video'; - $QuicktimeVideoCodecLookup['smc '] = 'Graphics'; - $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 1'; - $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 3'; - $QuicktimeVideoCodecLookup['syv9'] = 'Sorenson YUV9'; - $QuicktimeVideoCodecLookup['tga '] = 'Targa'; - $QuicktimeVideoCodecLookup['tiff'] = 'TIFF'; - $QuicktimeVideoCodecLookup['WRAW'] = 'Windows RAW'; - $QuicktimeVideoCodecLookup['WRLE'] = 'BMP'; - $QuicktimeVideoCodecLookup['y420'] = 'YUV420'; - $QuicktimeVideoCodecLookup['yuv2'] = 'ComponentVideo'; - $QuicktimeVideoCodecLookup['yuvs'] = 'ComponentVideoUnsigned'; - $QuicktimeVideoCodecLookup['yuvu'] = 'ComponentVideoSigned'; - } - return (isset($QuicktimeVideoCodecLookup[$codecid]) ? $QuicktimeVideoCodecLookup[$codecid] : ''); - } + public function QuicktimeAudioCodecLookup($codecid) + { + static $QuicktimeAudioCodecLookup = []; + if (empty($QuicktimeAudioCodecLookup)) { + $QuicktimeAudioCodecLookup['.mp3'] = 'Fraunhofer MPEG Layer-III alias'; + $QuicktimeAudioCodecLookup['aac '] = 'ISO/IEC 14496-3 AAC'; + $QuicktimeAudioCodecLookup['agsm'] = 'Apple GSM 10:1'; + $QuicktimeAudioCodecLookup['alac'] = 'Apple Lossless Audio Codec'; + $QuicktimeAudioCodecLookup['alaw'] = 'A-law 2:1'; + $QuicktimeAudioCodecLookup['conv'] = 'Sample Format'; + $QuicktimeAudioCodecLookup['dvca'] = 'DV'; + $QuicktimeAudioCodecLookup['dvi '] = 'DV 4:1'; + $QuicktimeAudioCodecLookup['eqal'] = 'Frequency Equalizer'; + $QuicktimeAudioCodecLookup['fl32'] = '32-bit Floating Point'; + $QuicktimeAudioCodecLookup['fl64'] = '64-bit Floating Point'; + $QuicktimeAudioCodecLookup['ima4'] = 'Interactive Multimedia Association 4:1'; + $QuicktimeAudioCodecLookup['in24'] = '24-bit Integer'; + $QuicktimeAudioCodecLookup['in32'] = '32-bit Integer'; + $QuicktimeAudioCodecLookup['lpc '] = 'LPC 23:1'; + $QuicktimeAudioCodecLookup['MAC3'] = 'Macintosh Audio Compression/Expansion (MACE) 3:1'; + $QuicktimeAudioCodecLookup['MAC6'] = 'Macintosh Audio Compression/Expansion (MACE) 6:1'; + $QuicktimeAudioCodecLookup['mixb'] = '8-bit Mixer'; + $QuicktimeAudioCodecLookup['mixw'] = '16-bit Mixer'; + $QuicktimeAudioCodecLookup['mp4a'] = 'ISO/IEC 14496-3 AAC'; + $QuicktimeAudioCodecLookup['MS'."\x00\x02"] = 'Microsoft ADPCM'; + $QuicktimeAudioCodecLookup['MS'."\x00\x11"] = 'DV IMA'; + $QuicktimeAudioCodecLookup['MS'."\x00\x55"] = 'Fraunhofer MPEG Layer III'; + $QuicktimeAudioCodecLookup['NONE'] = 'No Encoding'; + $QuicktimeAudioCodecLookup['Qclp'] = 'Qualcomm PureVoice'; + $QuicktimeAudioCodecLookup['QDM2'] = 'QDesign Music 2'; + $QuicktimeAudioCodecLookup['QDMC'] = 'QDesign Music 1'; + $QuicktimeAudioCodecLookup['ratb'] = '8-bit Rate'; + $QuicktimeAudioCodecLookup['ratw'] = '16-bit Rate'; + $QuicktimeAudioCodecLookup['raw '] = 'raw PCM'; + $QuicktimeAudioCodecLookup['sour'] = 'Sound Source'; + $QuicktimeAudioCodecLookup['sowt'] = 'signed/two\'s complement (Little Endian)'; + $QuicktimeAudioCodecLookup['str1'] = 'Iomega MPEG layer II'; + $QuicktimeAudioCodecLookup['str2'] = 'Iomega MPEG *layer II'; + $QuicktimeAudioCodecLookup['str3'] = 'Iomega MPEG **layer II'; + $QuicktimeAudioCodecLookup['str4'] = 'Iomega MPEG ***layer II'; + $QuicktimeAudioCodecLookup['twos'] = 'signed/two\'s complement (Big Endian)'; + $QuicktimeAudioCodecLookup['ulaw'] = 'mu-law 2:1'; + } - public function QuicktimeAudioCodecLookup($codecid) { - static $QuicktimeAudioCodecLookup = array(); - if (empty($QuicktimeAudioCodecLookup)) { - $QuicktimeAudioCodecLookup['.mp3'] = 'Fraunhofer MPEG Layer-III alias'; - $QuicktimeAudioCodecLookup['aac '] = 'ISO/IEC 14496-3 AAC'; - $QuicktimeAudioCodecLookup['agsm'] = 'Apple GSM 10:1'; - $QuicktimeAudioCodecLookup['alac'] = 'Apple Lossless Audio Codec'; - $QuicktimeAudioCodecLookup['alaw'] = 'A-law 2:1'; - $QuicktimeAudioCodecLookup['conv'] = 'Sample Format'; - $QuicktimeAudioCodecLookup['dvca'] = 'DV'; - $QuicktimeAudioCodecLookup['dvi '] = 'DV 4:1'; - $QuicktimeAudioCodecLookup['eqal'] = 'Frequency Equalizer'; - $QuicktimeAudioCodecLookup['fl32'] = '32-bit Floating Point'; - $QuicktimeAudioCodecLookup['fl64'] = '64-bit Floating Point'; - $QuicktimeAudioCodecLookup['ima4'] = 'Interactive Multimedia Association 4:1'; - $QuicktimeAudioCodecLookup['in24'] = '24-bit Integer'; - $QuicktimeAudioCodecLookup['in32'] = '32-bit Integer'; - $QuicktimeAudioCodecLookup['lpc '] = 'LPC 23:1'; - $QuicktimeAudioCodecLookup['MAC3'] = 'Macintosh Audio Compression/Expansion (MACE) 3:1'; - $QuicktimeAudioCodecLookup['MAC6'] = 'Macintosh Audio Compression/Expansion (MACE) 6:1'; - $QuicktimeAudioCodecLookup['mixb'] = '8-bit Mixer'; - $QuicktimeAudioCodecLookup['mixw'] = '16-bit Mixer'; - $QuicktimeAudioCodecLookup['mp4a'] = 'ISO/IEC 14496-3 AAC'; - $QuicktimeAudioCodecLookup['MS'."\x00\x02"] = 'Microsoft ADPCM'; - $QuicktimeAudioCodecLookup['MS'."\x00\x11"] = 'DV IMA'; - $QuicktimeAudioCodecLookup['MS'."\x00\x55"] = 'Fraunhofer MPEG Layer III'; - $QuicktimeAudioCodecLookup['NONE'] = 'No Encoding'; - $QuicktimeAudioCodecLookup['Qclp'] = 'Qualcomm PureVoice'; - $QuicktimeAudioCodecLookup['QDM2'] = 'QDesign Music 2'; - $QuicktimeAudioCodecLookup['QDMC'] = 'QDesign Music 1'; - $QuicktimeAudioCodecLookup['ratb'] = '8-bit Rate'; - $QuicktimeAudioCodecLookup['ratw'] = '16-bit Rate'; - $QuicktimeAudioCodecLookup['raw '] = 'raw PCM'; - $QuicktimeAudioCodecLookup['sour'] = 'Sound Source'; - $QuicktimeAudioCodecLookup['sowt'] = 'signed/two\'s complement (Little Endian)'; - $QuicktimeAudioCodecLookup['str1'] = 'Iomega MPEG layer II'; - $QuicktimeAudioCodecLookup['str2'] = 'Iomega MPEG *layer II'; - $QuicktimeAudioCodecLookup['str3'] = 'Iomega MPEG **layer II'; - $QuicktimeAudioCodecLookup['str4'] = 'Iomega MPEG ***layer II'; - $QuicktimeAudioCodecLookup['twos'] = 'signed/two\'s complement (Big Endian)'; - $QuicktimeAudioCodecLookup['ulaw'] = 'mu-law 2:1'; - } - return (isset($QuicktimeAudioCodecLookup[$codecid]) ? $QuicktimeAudioCodecLookup[$codecid] : ''); - } + return isset($QuicktimeAudioCodecLookup[$codecid]) ? $QuicktimeAudioCodecLookup[$codecid] : ''; + } - public function QuicktimeDCOMLookup($compressionid) { - static $QuicktimeDCOMLookup = array(); - if (empty($QuicktimeDCOMLookup)) { - $QuicktimeDCOMLookup['zlib'] = 'ZLib Deflate'; - $QuicktimeDCOMLookup['adec'] = 'Apple Compression'; - } - return (isset($QuicktimeDCOMLookup[$compressionid]) ? $QuicktimeDCOMLookup[$compressionid] : ''); - } + public function QuicktimeDCOMLookup($compressionid) + { + static $QuicktimeDCOMLookup = []; + if (empty($QuicktimeDCOMLookup)) { + $QuicktimeDCOMLookup['zlib'] = 'ZLib Deflate'; + $QuicktimeDCOMLookup['adec'] = 'Apple Compression'; + } - public function QuicktimeColorNameLookup($colordepthid) { - static $QuicktimeColorNameLookup = array(); - if (empty($QuicktimeColorNameLookup)) { - $QuicktimeColorNameLookup[1] = '2-color (monochrome)'; - $QuicktimeColorNameLookup[2] = '4-color'; - $QuicktimeColorNameLookup[4] = '16-color'; - $QuicktimeColorNameLookup[8] = '256-color'; - $QuicktimeColorNameLookup[16] = 'thousands (16-bit color)'; - $QuicktimeColorNameLookup[24] = 'millions (24-bit color)'; - $QuicktimeColorNameLookup[32] = 'millions+ (32-bit color)'; - $QuicktimeColorNameLookup[33] = 'black & white'; - $QuicktimeColorNameLookup[34] = '4-gray'; - $QuicktimeColorNameLookup[36] = '16-gray'; - $QuicktimeColorNameLookup[40] = '256-gray'; - } - return (isset($QuicktimeColorNameLookup[$colordepthid]) ? $QuicktimeColorNameLookup[$colordepthid] : 'invalid'); - } + return isset($QuicktimeDCOMLookup[$compressionid]) ? $QuicktimeDCOMLookup[$compressionid] : ''; + } - public function QuicktimeSTIKLookup($stik) { - static $QuicktimeSTIKLookup = array(); - if (empty($QuicktimeSTIKLookup)) { - $QuicktimeSTIKLookup[0] = 'Movie'; - $QuicktimeSTIKLookup[1] = 'Normal'; - $QuicktimeSTIKLookup[2] = 'Audiobook'; - $QuicktimeSTIKLookup[5] = 'Whacked Bookmark'; - $QuicktimeSTIKLookup[6] = 'Music Video'; - $QuicktimeSTIKLookup[9] = 'Short Film'; - $QuicktimeSTIKLookup[10] = 'TV Show'; - $QuicktimeSTIKLookup[11] = 'Booklet'; - $QuicktimeSTIKLookup[14] = 'Ringtone'; - $QuicktimeSTIKLookup[21] = 'Podcast'; - } - return (isset($QuicktimeSTIKLookup[$stik]) ? $QuicktimeSTIKLookup[$stik] : 'invalid'); - } + public function QuicktimeColorNameLookup($colordepthid) + { + static $QuicktimeColorNameLookup = []; + if (empty($QuicktimeColorNameLookup)) { + $QuicktimeColorNameLookup[1] = '2-color (monochrome)'; + $QuicktimeColorNameLookup[2] = '4-color'; + $QuicktimeColorNameLookup[4] = '16-color'; + $QuicktimeColorNameLookup[8] = '256-color'; + $QuicktimeColorNameLookup[16] = 'thousands (16-bit color)'; + $QuicktimeColorNameLookup[24] = 'millions (24-bit color)'; + $QuicktimeColorNameLookup[32] = 'millions+ (32-bit color)'; + $QuicktimeColorNameLookup[33] = 'black & white'; + $QuicktimeColorNameLookup[34] = '4-gray'; + $QuicktimeColorNameLookup[36] = '16-gray'; + $QuicktimeColorNameLookup[40] = '256-gray'; + } - public function QuicktimeIODSaudioProfileName($audio_profile_id) { - static $QuicktimeIODSaudioProfileNameLookup = array(); - if (empty($QuicktimeIODSaudioProfileNameLookup)) { - $QuicktimeIODSaudioProfileNameLookup = array( - 0x00 => 'ISO Reserved (0x00)', - 0x01 => 'Main Audio Profile @ Level 1', - 0x02 => 'Main Audio Profile @ Level 2', - 0x03 => 'Main Audio Profile @ Level 3', - 0x04 => 'Main Audio Profile @ Level 4', - 0x05 => 'Scalable Audio Profile @ Level 1', - 0x06 => 'Scalable Audio Profile @ Level 2', - 0x07 => 'Scalable Audio Profile @ Level 3', - 0x08 => 'Scalable Audio Profile @ Level 4', - 0x09 => 'Speech Audio Profile @ Level 1', - 0x0A => 'Speech Audio Profile @ Level 2', - 0x0B => 'Synthetic Audio Profile @ Level 1', - 0x0C => 'Synthetic Audio Profile @ Level 2', - 0x0D => 'Synthetic Audio Profile @ Level 3', - 0x0E => 'High Quality Audio Profile @ Level 1', - 0x0F => 'High Quality Audio Profile @ Level 2', - 0x10 => 'High Quality Audio Profile @ Level 3', - 0x11 => 'High Quality Audio Profile @ Level 4', - 0x12 => 'High Quality Audio Profile @ Level 5', - 0x13 => 'High Quality Audio Profile @ Level 6', - 0x14 => 'High Quality Audio Profile @ Level 7', - 0x15 => 'High Quality Audio Profile @ Level 8', - 0x16 => 'Low Delay Audio Profile @ Level 1', - 0x17 => 'Low Delay Audio Profile @ Level 2', - 0x18 => 'Low Delay Audio Profile @ Level 3', - 0x19 => 'Low Delay Audio Profile @ Level 4', - 0x1A => 'Low Delay Audio Profile @ Level 5', - 0x1B => 'Low Delay Audio Profile @ Level 6', - 0x1C => 'Low Delay Audio Profile @ Level 7', - 0x1D => 'Low Delay Audio Profile @ Level 8', - 0x1E => 'Natural Audio Profile @ Level 1', - 0x1F => 'Natural Audio Profile @ Level 2', - 0x20 => 'Natural Audio Profile @ Level 3', - 0x21 => 'Natural Audio Profile @ Level 4', - 0x22 => 'Mobile Audio Internetworking Profile @ Level 1', - 0x23 => 'Mobile Audio Internetworking Profile @ Level 2', - 0x24 => 'Mobile Audio Internetworking Profile @ Level 3', - 0x25 => 'Mobile Audio Internetworking Profile @ Level 4', - 0x26 => 'Mobile Audio Internetworking Profile @ Level 5', - 0x27 => 'Mobile Audio Internetworking Profile @ Level 6', - 0x28 => 'AAC Profile @ Level 1', - 0x29 => 'AAC Profile @ Level 2', - 0x2A => 'AAC Profile @ Level 4', - 0x2B => 'AAC Profile @ Level 5', - 0x2C => 'High Efficiency AAC Profile @ Level 2', - 0x2D => 'High Efficiency AAC Profile @ Level 3', - 0x2E => 'High Efficiency AAC Profile @ Level 4', - 0x2F => 'High Efficiency AAC Profile @ Level 5', - 0xFE => 'Not part of MPEG-4 audio profiles', - 0xFF => 'No audio capability required', - ); - } - return (isset($QuicktimeIODSaudioProfileNameLookup[$audio_profile_id]) ? $QuicktimeIODSaudioProfileNameLookup[$audio_profile_id] : 'ISO Reserved / User Private'); - } + return isset($QuicktimeColorNameLookup[$colordepthid]) ? $QuicktimeColorNameLookup[$colordepthid] : 'invalid'; + } + public function QuicktimeSTIKLookup($stik) + { + static $QuicktimeSTIKLookup = []; + if (empty($QuicktimeSTIKLookup)) { + $QuicktimeSTIKLookup[0] = 'Movie'; + $QuicktimeSTIKLookup[1] = 'Normal'; + $QuicktimeSTIKLookup[2] = 'Audiobook'; + $QuicktimeSTIKLookup[5] = 'Whacked Bookmark'; + $QuicktimeSTIKLookup[6] = 'Music Video'; + $QuicktimeSTIKLookup[9] = 'Short Film'; + $QuicktimeSTIKLookup[10] = 'TV Show'; + $QuicktimeSTIKLookup[11] = 'Booklet'; + $QuicktimeSTIKLookup[14] = 'Ringtone'; + $QuicktimeSTIKLookup[21] = 'Podcast'; + } - public function QuicktimeIODSvideoProfileName($video_profile_id) { - static $QuicktimeIODSvideoProfileNameLookup = array(); - if (empty($QuicktimeIODSvideoProfileNameLookup)) { - $QuicktimeIODSvideoProfileNameLookup = array( - 0x00 => 'Reserved (0x00) Profile', - 0x01 => 'Simple Profile @ Level 1', - 0x02 => 'Simple Profile @ Level 2', - 0x03 => 'Simple Profile @ Level 3', - 0x08 => 'Simple Profile @ Level 0', - 0x10 => 'Simple Scalable Profile @ Level 0', - 0x11 => 'Simple Scalable Profile @ Level 1', - 0x12 => 'Simple Scalable Profile @ Level 2', - 0x15 => 'AVC/H264 Profile', - 0x21 => 'Core Profile @ Level 1', - 0x22 => 'Core Profile @ Level 2', - 0x32 => 'Main Profile @ Level 2', - 0x33 => 'Main Profile @ Level 3', - 0x34 => 'Main Profile @ Level 4', - 0x42 => 'N-bit Profile @ Level 2', - 0x51 => 'Scalable Texture Profile @ Level 1', - 0x61 => 'Simple Face Animation Profile @ Level 1', - 0x62 => 'Simple Face Animation Profile @ Level 2', - 0x63 => 'Simple FBA Profile @ Level 1', - 0x64 => 'Simple FBA Profile @ Level 2', - 0x71 => 'Basic Animated Texture Profile @ Level 1', - 0x72 => 'Basic Animated Texture Profile @ Level 2', - 0x81 => 'Hybrid Profile @ Level 1', - 0x82 => 'Hybrid Profile @ Level 2', - 0x91 => 'Advanced Real Time Simple Profile @ Level 1', - 0x92 => 'Advanced Real Time Simple Profile @ Level 2', - 0x93 => 'Advanced Real Time Simple Profile @ Level 3', - 0x94 => 'Advanced Real Time Simple Profile @ Level 4', - 0xA1 => 'Core Scalable Profile @ Level1', - 0xA2 => 'Core Scalable Profile @ Level2', - 0xA3 => 'Core Scalable Profile @ Level3', - 0xB1 => 'Advanced Coding Efficiency Profile @ Level 1', - 0xB2 => 'Advanced Coding Efficiency Profile @ Level 2', - 0xB3 => 'Advanced Coding Efficiency Profile @ Level 3', - 0xB4 => 'Advanced Coding Efficiency Profile @ Level 4', - 0xC1 => 'Advanced Core Profile @ Level 1', - 0xC2 => 'Advanced Core Profile @ Level 2', - 0xD1 => 'Advanced Scalable Texture @ Level1', - 0xD2 => 'Advanced Scalable Texture @ Level2', - 0xE1 => 'Simple Studio Profile @ Level 1', - 0xE2 => 'Simple Studio Profile @ Level 2', - 0xE3 => 'Simple Studio Profile @ Level 3', - 0xE4 => 'Simple Studio Profile @ Level 4', - 0xE5 => 'Core Studio Profile @ Level 1', - 0xE6 => 'Core Studio Profile @ Level 2', - 0xE7 => 'Core Studio Profile @ Level 3', - 0xE8 => 'Core Studio Profile @ Level 4', - 0xF0 => 'Advanced Simple Profile @ Level 0', - 0xF1 => 'Advanced Simple Profile @ Level 1', - 0xF2 => 'Advanced Simple Profile @ Level 2', - 0xF3 => 'Advanced Simple Profile @ Level 3', - 0xF4 => 'Advanced Simple Profile @ Level 4', - 0xF5 => 'Advanced Simple Profile @ Level 5', - 0xF7 => 'Advanced Simple Profile @ Level 3b', - 0xF8 => 'Fine Granularity Scalable Profile @ Level 0', - 0xF9 => 'Fine Granularity Scalable Profile @ Level 1', - 0xFA => 'Fine Granularity Scalable Profile @ Level 2', - 0xFB => 'Fine Granularity Scalable Profile @ Level 3', - 0xFC => 'Fine Granularity Scalable Profile @ Level 4', - 0xFD => 'Fine Granularity Scalable Profile @ Level 5', - 0xFE => 'Not part of MPEG-4 Visual profiles', - 0xFF => 'No visual capability required', - ); - } - return (isset($QuicktimeIODSvideoProfileNameLookup[$video_profile_id]) ? $QuicktimeIODSvideoProfileNameLookup[$video_profile_id] : 'ISO Reserved Profile'); - } + return isset($QuicktimeSTIKLookup[$stik]) ? $QuicktimeSTIKLookup[$stik] : 'invalid'; + } + public function QuicktimeIODSaudioProfileName($audio_profile_id) + { + static $QuicktimeIODSaudioProfileNameLookup = []; + if (empty($QuicktimeIODSaudioProfileNameLookup)) { + $QuicktimeIODSaudioProfileNameLookup = [ + 0x00 => 'ISO Reserved (0x00)', + 0x01 => 'Main Audio Profile @ Level 1', + 0x02 => 'Main Audio Profile @ Level 2', + 0x03 => 'Main Audio Profile @ Level 3', + 0x04 => 'Main Audio Profile @ Level 4', + 0x05 => 'Scalable Audio Profile @ Level 1', + 0x06 => 'Scalable Audio Profile @ Level 2', + 0x07 => 'Scalable Audio Profile @ Level 3', + 0x08 => 'Scalable Audio Profile @ Level 4', + 0x09 => 'Speech Audio Profile @ Level 1', + 0x0A => 'Speech Audio Profile @ Level 2', + 0x0B => 'Synthetic Audio Profile @ Level 1', + 0x0C => 'Synthetic Audio Profile @ Level 2', + 0x0D => 'Synthetic Audio Profile @ Level 3', + 0x0E => 'High Quality Audio Profile @ Level 1', + 0x0F => 'High Quality Audio Profile @ Level 2', + 0x10 => 'High Quality Audio Profile @ Level 3', + 0x11 => 'High Quality Audio Profile @ Level 4', + 0x12 => 'High Quality Audio Profile @ Level 5', + 0x13 => 'High Quality Audio Profile @ Level 6', + 0x14 => 'High Quality Audio Profile @ Level 7', + 0x15 => 'High Quality Audio Profile @ Level 8', + 0x16 => 'Low Delay Audio Profile @ Level 1', + 0x17 => 'Low Delay Audio Profile @ Level 2', + 0x18 => 'Low Delay Audio Profile @ Level 3', + 0x19 => 'Low Delay Audio Profile @ Level 4', + 0x1A => 'Low Delay Audio Profile @ Level 5', + 0x1B => 'Low Delay Audio Profile @ Level 6', + 0x1C => 'Low Delay Audio Profile @ Level 7', + 0x1D => 'Low Delay Audio Profile @ Level 8', + 0x1E => 'Natural Audio Profile @ Level 1', + 0x1F => 'Natural Audio Profile @ Level 2', + 0x20 => 'Natural Audio Profile @ Level 3', + 0x21 => 'Natural Audio Profile @ Level 4', + 0x22 => 'Mobile Audio Internetworking Profile @ Level 1', + 0x23 => 'Mobile Audio Internetworking Profile @ Level 2', + 0x24 => 'Mobile Audio Internetworking Profile @ Level 3', + 0x25 => 'Mobile Audio Internetworking Profile @ Level 4', + 0x26 => 'Mobile Audio Internetworking Profile @ Level 5', + 0x27 => 'Mobile Audio Internetworking Profile @ Level 6', + 0x28 => 'AAC Profile @ Level 1', + 0x29 => 'AAC Profile @ Level 2', + 0x2A => 'AAC Profile @ Level 4', + 0x2B => 'AAC Profile @ Level 5', + 0x2C => 'High Efficiency AAC Profile @ Level 2', + 0x2D => 'High Efficiency AAC Profile @ Level 3', + 0x2E => 'High Efficiency AAC Profile @ Level 4', + 0x2F => 'High Efficiency AAC Profile @ Level 5', + 0xFE => 'Not part of MPEG-4 audio profiles', + 0xFF => 'No audio capability required', + ]; + } - public function QuicktimeContentRatingLookup($rtng) { - static $QuicktimeContentRatingLookup = array(); - if (empty($QuicktimeContentRatingLookup)) { - $QuicktimeContentRatingLookup[0] = 'None'; - $QuicktimeContentRatingLookup[2] = 'Clean'; - $QuicktimeContentRatingLookup[4] = 'Explicit'; - } - return (isset($QuicktimeContentRatingLookup[$rtng]) ? $QuicktimeContentRatingLookup[$rtng] : 'invalid'); - } + return isset($QuicktimeIODSaudioProfileNameLookup[$audio_profile_id]) ? $QuicktimeIODSaudioProfileNameLookup[$audio_profile_id] : 'ISO Reserved / User Private'; + } - public function QuicktimeStoreAccountTypeLookup($akid) { - static $QuicktimeStoreAccountTypeLookup = array(); - if (empty($QuicktimeStoreAccountTypeLookup)) { - $QuicktimeStoreAccountTypeLookup[0] = 'iTunes'; - $QuicktimeStoreAccountTypeLookup[1] = 'AOL'; - } - return (isset($QuicktimeStoreAccountTypeLookup[$akid]) ? $QuicktimeStoreAccountTypeLookup[$akid] : 'invalid'); - } + public function QuicktimeIODSvideoProfileName($video_profile_id) + { + static $QuicktimeIODSvideoProfileNameLookup = []; + if (empty($QuicktimeIODSvideoProfileNameLookup)) { + $QuicktimeIODSvideoProfileNameLookup = [ + 0x00 => 'Reserved (0x00) Profile', + 0x01 => 'Simple Profile @ Level 1', + 0x02 => 'Simple Profile @ Level 2', + 0x03 => 'Simple Profile @ Level 3', + 0x08 => 'Simple Profile @ Level 0', + 0x10 => 'Simple Scalable Profile @ Level 0', + 0x11 => 'Simple Scalable Profile @ Level 1', + 0x12 => 'Simple Scalable Profile @ Level 2', + 0x15 => 'AVC/H264 Profile', + 0x21 => 'Core Profile @ Level 1', + 0x22 => 'Core Profile @ Level 2', + 0x32 => 'Main Profile @ Level 2', + 0x33 => 'Main Profile @ Level 3', + 0x34 => 'Main Profile @ Level 4', + 0x42 => 'N-bit Profile @ Level 2', + 0x51 => 'Scalable Texture Profile @ Level 1', + 0x61 => 'Simple Face Animation Profile @ Level 1', + 0x62 => 'Simple Face Animation Profile @ Level 2', + 0x63 => 'Simple FBA Profile @ Level 1', + 0x64 => 'Simple FBA Profile @ Level 2', + 0x71 => 'Basic Animated Texture Profile @ Level 1', + 0x72 => 'Basic Animated Texture Profile @ Level 2', + 0x81 => 'Hybrid Profile @ Level 1', + 0x82 => 'Hybrid Profile @ Level 2', + 0x91 => 'Advanced Real Time Simple Profile @ Level 1', + 0x92 => 'Advanced Real Time Simple Profile @ Level 2', + 0x93 => 'Advanced Real Time Simple Profile @ Level 3', + 0x94 => 'Advanced Real Time Simple Profile @ Level 4', + 0xA1 => 'Core Scalable Profile @ Level1', + 0xA2 => 'Core Scalable Profile @ Level2', + 0xA3 => 'Core Scalable Profile @ Level3', + 0xB1 => 'Advanced Coding Efficiency Profile @ Level 1', + 0xB2 => 'Advanced Coding Efficiency Profile @ Level 2', + 0xB3 => 'Advanced Coding Efficiency Profile @ Level 3', + 0xB4 => 'Advanced Coding Efficiency Profile @ Level 4', + 0xC1 => 'Advanced Core Profile @ Level 1', + 0xC2 => 'Advanced Core Profile @ Level 2', + 0xD1 => 'Advanced Scalable Texture @ Level1', + 0xD2 => 'Advanced Scalable Texture @ Level2', + 0xE1 => 'Simple Studio Profile @ Level 1', + 0xE2 => 'Simple Studio Profile @ Level 2', + 0xE3 => 'Simple Studio Profile @ Level 3', + 0xE4 => 'Simple Studio Profile @ Level 4', + 0xE5 => 'Core Studio Profile @ Level 1', + 0xE6 => 'Core Studio Profile @ Level 2', + 0xE7 => 'Core Studio Profile @ Level 3', + 0xE8 => 'Core Studio Profile @ Level 4', + 0xF0 => 'Advanced Simple Profile @ Level 0', + 0xF1 => 'Advanced Simple Profile @ Level 1', + 0xF2 => 'Advanced Simple Profile @ Level 2', + 0xF3 => 'Advanced Simple Profile @ Level 3', + 0xF4 => 'Advanced Simple Profile @ Level 4', + 0xF5 => 'Advanced Simple Profile @ Level 5', + 0xF7 => 'Advanced Simple Profile @ Level 3b', + 0xF8 => 'Fine Granularity Scalable Profile @ Level 0', + 0xF9 => 'Fine Granularity Scalable Profile @ Level 1', + 0xFA => 'Fine Granularity Scalable Profile @ Level 2', + 0xFB => 'Fine Granularity Scalable Profile @ Level 3', + 0xFC => 'Fine Granularity Scalable Profile @ Level 4', + 0xFD => 'Fine Granularity Scalable Profile @ Level 5', + 0xFE => 'Not part of MPEG-4 Visual profiles', + 0xFF => 'No visual capability required', + ]; + } - public function QuicktimeStoreFrontCodeLookup($sfid) { - static $QuicktimeStoreFrontCodeLookup = array(); - if (empty($QuicktimeStoreFrontCodeLookup)) { - $QuicktimeStoreFrontCodeLookup[143460] = 'Australia'; - $QuicktimeStoreFrontCodeLookup[143445] = 'Austria'; - $QuicktimeStoreFrontCodeLookup[143446] = 'Belgium'; - $QuicktimeStoreFrontCodeLookup[143455] = 'Canada'; - $QuicktimeStoreFrontCodeLookup[143458] = 'Denmark'; - $QuicktimeStoreFrontCodeLookup[143447] = 'Finland'; - $QuicktimeStoreFrontCodeLookup[143442] = 'France'; - $QuicktimeStoreFrontCodeLookup[143443] = 'Germany'; - $QuicktimeStoreFrontCodeLookup[143448] = 'Greece'; - $QuicktimeStoreFrontCodeLookup[143449] = 'Ireland'; - $QuicktimeStoreFrontCodeLookup[143450] = 'Italy'; - $QuicktimeStoreFrontCodeLookup[143462] = 'Japan'; - $QuicktimeStoreFrontCodeLookup[143451] = 'Luxembourg'; - $QuicktimeStoreFrontCodeLookup[143452] = 'Netherlands'; - $QuicktimeStoreFrontCodeLookup[143461] = 'New Zealand'; - $QuicktimeStoreFrontCodeLookup[143457] = 'Norway'; - $QuicktimeStoreFrontCodeLookup[143453] = 'Portugal'; - $QuicktimeStoreFrontCodeLookup[143454] = 'Spain'; - $QuicktimeStoreFrontCodeLookup[143456] = 'Sweden'; - $QuicktimeStoreFrontCodeLookup[143459] = 'Switzerland'; - $QuicktimeStoreFrontCodeLookup[143444] = 'United Kingdom'; - $QuicktimeStoreFrontCodeLookup[143441] = 'United States'; - } - return (isset($QuicktimeStoreFrontCodeLookup[$sfid]) ? $QuicktimeStoreFrontCodeLookup[$sfid] : 'invalid'); - } + return isset($QuicktimeIODSvideoProfileNameLookup[$video_profile_id]) ? $QuicktimeIODSvideoProfileNameLookup[$video_profile_id] : 'ISO Reserved Profile'; + } - public function QuicktimeParseNikonNCTG($atom_data) { - // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG - // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100 - // Data is stored as records of: - // * 4 bytes record type - // * 2 bytes size of data field type: - // 0x0001 = flag (size field *= 1-byte) - // 0x0002 = char (size field *= 1-byte) - // 0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB - // 0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD - // 0x0005 = float (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together - // 0x0007 = bytes (size field *= 1-byte), values are stored as ?????? - // 0x0008 = ????? (size field *= 2-byte), values are stored as ?????? - // * 2 bytes data size field - // * ? bytes data (string data may be null-padded; datestamp fields are in the format "2011:05:25 20:24:15") - // all integers are stored BigEndian + public function QuicktimeContentRatingLookup($rtng) + { + static $QuicktimeContentRatingLookup = []; + if (empty($QuicktimeContentRatingLookup)) { + $QuicktimeContentRatingLookup[0] = 'None'; + $QuicktimeContentRatingLookup[2] = 'Clean'; + $QuicktimeContentRatingLookup[4] = 'Explicit'; + } - $NCTGtagName = array( - 0x00000001 => 'Make', - 0x00000002 => 'Model', - 0x00000003 => 'Software', - 0x00000011 => 'CreateDate', - 0x00000012 => 'DateTimeOriginal', - 0x00000013 => 'FrameCount', - 0x00000016 => 'FrameRate', - 0x00000022 => 'FrameWidth', - 0x00000023 => 'FrameHeight', - 0x00000032 => 'AudioChannels', - 0x00000033 => 'AudioBitsPerSample', - 0x00000034 => 'AudioSampleRate', - 0x02000001 => 'MakerNoteVersion', - 0x02000005 => 'WhiteBalance', - 0x0200000b => 'WhiteBalanceFineTune', - 0x0200001e => 'ColorSpace', - 0x02000023 => 'PictureControlData', - 0x02000024 => 'WorldTime', - 0x02000032 => 'UnknownInfo', - 0x02000083 => 'LensType', - 0x02000084 => 'Lens', - ); + return isset($QuicktimeContentRatingLookup[$rtng]) ? $QuicktimeContentRatingLookup[$rtng] : 'invalid'; + } - $offset = 0; - $datalength = strlen($atom_data); - $parsed = array(); - while ($offset < $datalength) { -//echo getid3_lib::PrintHexBytes(substr($atom_data, $offset, 4)).'
    '; - $record_type = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4)); $offset += 4; - $data_size_type = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); $offset += 2; - $data_size = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); $offset += 2; - switch ($data_size_type) { - case 0x0001: // 0x0001 = flag (size field *= 1-byte) - $data = getid3_lib::BigEndian2Int(substr($atom_data, $offset, $data_size * 1)); - $offset += ($data_size * 1); - break; - case 0x0002: // 0x0002 = char (size field *= 1-byte) - $data = substr($atom_data, $offset, $data_size * 1); - $offset += ($data_size * 1); - $data = rtrim($data, "\x00"); - break; - case 0x0003: // 0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB - $data = ''; - for ($i = $data_size - 1; $i >= 0; $i--) { - $data .= substr($atom_data, $offset + ($i * 2), 2); - } - $data = getid3_lib::BigEndian2Int($data); - $offset += ($data_size * 2); - break; - case 0x0004: // 0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD - $data = ''; - for ($i = $data_size - 1; $i >= 0; $i--) { - $data .= substr($atom_data, $offset + ($i * 4), 4); - } - $data = getid3_lib::BigEndian2Int($data); - $offset += ($data_size * 4); - break; - case 0x0005: // 0x0005 = float (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together - $data = array(); - for ($i = 0; $i < $data_size; $i++) { - $numerator = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 0, 4)); - $denomninator = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 4, 4)); - if ($denomninator == 0) { - $data[$i] = false; - } else { - $data[$i] = (double) $numerator / $denomninator; - } - } - $offset += (8 * $data_size); - if (count($data) == 1) { - $data = $data[0]; - } - break; - case 0x0007: // 0x0007 = bytes (size field *= 1-byte), values are stored as ?????? - $data = substr($atom_data, $offset, $data_size * 1); - $offset += ($data_size * 1); - break; - case 0x0008: // 0x0008 = ????? (size field *= 2-byte), values are stored as ?????? - $data = substr($atom_data, $offset, $data_size * 2); - $offset += ($data_size * 2); - break; - default: + public function QuicktimeStoreAccountTypeLookup($akid) + { + static $QuicktimeStoreAccountTypeLookup = []; + if (empty($QuicktimeStoreAccountTypeLookup)) { + $QuicktimeStoreAccountTypeLookup[0] = 'iTunes'; + $QuicktimeStoreAccountTypeLookup[1] = 'AOL'; + } + + return isset($QuicktimeStoreAccountTypeLookup[$akid]) ? $QuicktimeStoreAccountTypeLookup[$akid] : 'invalid'; + } + + public function QuicktimeStoreFrontCodeLookup($sfid) + { + static $QuicktimeStoreFrontCodeLookup = []; + if (empty($QuicktimeStoreFrontCodeLookup)) { + $QuicktimeStoreFrontCodeLookup[143460] = 'Australia'; + $QuicktimeStoreFrontCodeLookup[143445] = 'Austria'; + $QuicktimeStoreFrontCodeLookup[143446] = 'Belgium'; + $QuicktimeStoreFrontCodeLookup[143455] = 'Canada'; + $QuicktimeStoreFrontCodeLookup[143458] = 'Denmark'; + $QuicktimeStoreFrontCodeLookup[143447] = 'Finland'; + $QuicktimeStoreFrontCodeLookup[143442] = 'France'; + $QuicktimeStoreFrontCodeLookup[143443] = 'Germany'; + $QuicktimeStoreFrontCodeLookup[143448] = 'Greece'; + $QuicktimeStoreFrontCodeLookup[143449] = 'Ireland'; + $QuicktimeStoreFrontCodeLookup[143450] = 'Italy'; + $QuicktimeStoreFrontCodeLookup[143462] = 'Japan'; + $QuicktimeStoreFrontCodeLookup[143451] = 'Luxembourg'; + $QuicktimeStoreFrontCodeLookup[143452] = 'Netherlands'; + $QuicktimeStoreFrontCodeLookup[143461] = 'New Zealand'; + $QuicktimeStoreFrontCodeLookup[143457] = 'Norway'; + $QuicktimeStoreFrontCodeLookup[143453] = 'Portugal'; + $QuicktimeStoreFrontCodeLookup[143454] = 'Spain'; + $QuicktimeStoreFrontCodeLookup[143456] = 'Sweden'; + $QuicktimeStoreFrontCodeLookup[143459] = 'Switzerland'; + $QuicktimeStoreFrontCodeLookup[143444] = 'United Kingdom'; + $QuicktimeStoreFrontCodeLookup[143441] = 'United States'; + } + + return isset($QuicktimeStoreFrontCodeLookup[$sfid]) ? $QuicktimeStoreFrontCodeLookup[$sfid] : 'invalid'; + } + + public function QuicktimeParseNikonNCTG($atom_data) + { + // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG + // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100 + // Data is stored as records of: + // * 4 bytes record type + // * 2 bytes size of data field type: + // 0x0001 = flag (size field *= 1-byte) + // 0x0002 = char (size field *= 1-byte) + // 0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB + // 0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD + // 0x0005 = float (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together + // 0x0007 = bytes (size field *= 1-byte), values are stored as ?????? + // 0x0008 = ????? (size field *= 2-byte), values are stored as ?????? + // * 2 bytes data size field + // * ? bytes data (string data may be null-padded; datestamp fields are in the format "2011:05:25 20:24:15") + // all integers are stored BigEndian + + $NCTGtagName = [ + 0x00000001 => 'Make', + 0x00000002 => 'Model', + 0x00000003 => 'Software', + 0x00000011 => 'CreateDate', + 0x00000012 => 'DateTimeOriginal', + 0x00000013 => 'FrameCount', + 0x00000016 => 'FrameRate', + 0x00000022 => 'FrameWidth', + 0x00000023 => 'FrameHeight', + 0x00000032 => 'AudioChannels', + 0x00000033 => 'AudioBitsPerSample', + 0x00000034 => 'AudioSampleRate', + 0x02000001 => 'MakerNoteVersion', + 0x02000005 => 'WhiteBalance', + 0x0200000b => 'WhiteBalanceFineTune', + 0x0200001e => 'ColorSpace', + 0x02000023 => 'PictureControlData', + 0x02000024 => 'WorldTime', + 0x02000032 => 'UnknownInfo', + 0x02000083 => 'LensType', + 0x02000084 => 'Lens', + ]; + + $offset = 0; + $datalength = strlen($atom_data); + $parsed = []; + while ($offset < $datalength) { + //echo getid3_lib::PrintHexBytes(substr($atom_data, $offset, 4)).'
    '; + $record_type = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4)); + $offset += 4; + $data_size_type = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); + $offset += 2; + $data_size = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); + $offset += 2; + switch ($data_size_type) { + case 0x0001: // 0x0001 = flag (size field *= 1-byte) + $data = getid3_lib::BigEndian2Int(substr($atom_data, $offset, $data_size * 1)); + $offset += ($data_size * 1); + break; + case 0x0002: // 0x0002 = char (size field *= 1-byte) + $data = substr($atom_data, $offset, $data_size * 1); + $offset += ($data_size * 1); + $data = rtrim($data, "\x00"); + break; + case 0x0003: // 0x0003 = DWORD+ (size field *= 2-byte), values are stored CDAB + $data = ''; + for ($i = $data_size - 1; $i >= 0; $i--) { + $data .= substr($atom_data, $offset + ($i * 2), 2); + } + $data = getid3_lib::BigEndian2Int($data); + $offset += ($data_size * 2); + break; + case 0x0004: // 0x0004 = QWORD+ (size field *= 4-byte), values are stored EFGHABCD + $data = ''; + for ($i = $data_size - 1; $i >= 0; $i--) { + $data .= substr($atom_data, $offset + ($i * 4), 4); + } + $data = getid3_lib::BigEndian2Int($data); + $offset += ($data_size * 4); + break; + case 0x0005: // 0x0005 = float (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together + $data = []; + for ($i = 0; $i < $data_size; $i++) { + $numerator = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 0, 4)); + $denomninator = getid3_lib::BigEndian2Int(substr($atom_data, $offset + ($i * 8) + 4, 4)); + if ($denomninator == 0) { + $data[$i] = false; + } else { + $data[$i] = (float) $numerator / $denomninator; + } + } + $offset += (8 * $data_size); + if (count($data) == 1) { + $data = $data[0]; + } + break; + case 0x0007: // 0x0007 = bytes (size field *= 1-byte), values are stored as ?????? + $data = substr($atom_data, $offset, $data_size * 1); + $offset += ($data_size * 1); + break; + case 0x0008: // 0x0008 = ????? (size field *= 2-byte), values are stored as ?????? + $data = substr($atom_data, $offset, $data_size * 2); + $offset += ($data_size * 2); + break; + default: echo 'QuicktimeParseNikonNCTG()::unknown $data_size_type: '.$data_size_type.'
    '; - break 2; - } + break 2; + } - switch ($record_type) { - case 0x00000011: // CreateDate - case 0x00000012: // DateTimeOriginal - $data = strtotime($data); - break; - case 0x0200001e: // ColorSpace - switch ($data) { - case 1: - $data = 'sRGB'; - break; - case 2: - $data = 'Adobe RGB'; - break; - } - break; - case 0x02000023: // PictureControlData - $PictureControlAdjust = array(0=>'default', 1=>'quick', 2=>'full'); - $FilterEffect = array(0x80=>'off', 0x81=>'yellow', 0x82=>'orange', 0x83=>'red', 0x84=>'green', 0xff=>'n/a'); - $ToningEffect = array(0x80=>'b&w', 0x81=>'sepia', 0x82=>'cyanotype', 0x83=>'red', 0x84=>'yellow', 0x85=>'green', 0x86=>'blue-green', 0x87=>'blue', 0x88=>'purple-blue', 0x89=>'red-purple', 0xff=>'n/a'); - $data = array( - 'PictureControlVersion' => substr($data, 0, 4), - 'PictureControlName' => rtrim(substr($data, 4, 20), "\x00"), - 'PictureControlBase' => rtrim(substr($data, 24, 20), "\x00"), - //'?' => substr($data, 44, 4), - 'PictureControlAdjust' => $PictureControlAdjust[ord(substr($data, 48, 1))], - 'PictureControlQuickAdjust' => ord(substr($data, 49, 1)), - 'Sharpness' => ord(substr($data, 50, 1)), - 'Contrast' => ord(substr($data, 51, 1)), - 'Brightness' => ord(substr($data, 52, 1)), - 'Saturation' => ord(substr($data, 53, 1)), - 'HueAdjustment' => ord(substr($data, 54, 1)), - 'FilterEffect' => $FilterEffect[ord(substr($data, 55, 1))], - 'ToningEffect' => $ToningEffect[ord(substr($data, 56, 1))], - 'ToningSaturation' => ord(substr($data, 57, 1)), - ); - break; - case 0x02000024: // WorldTime - // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#WorldTime - // timezone is stored as offset from GMT in minutes - $timezone = getid3_lib::BigEndian2Int(substr($data, 0, 2)); - if ($timezone & 0x8000) { - $timezone = 0 - (0x10000 - $timezone); - } - $timezone /= 60; + switch ($record_type) { + case 0x00000011: // CreateDate + case 0x00000012: // DateTimeOriginal + $data = strtotime($data); + break; + case 0x0200001e: // ColorSpace + switch ($data) { + case 1: + $data = 'sRGB'; + break; + case 2: + $data = 'Adobe RGB'; + break; + } + break; + case 0x02000023: // PictureControlData + $PictureControlAdjust = [0=>'default', 1=>'quick', 2=>'full']; + $FilterEffect = [0x80=>'off', 0x81=>'yellow', 0x82=>'orange', 0x83=>'red', 0x84=>'green', 0xff=>'n/a']; + $ToningEffect = [0x80=>'b&w', 0x81=>'sepia', 0x82=>'cyanotype', 0x83=>'red', 0x84=>'yellow', 0x85=>'green', 0x86=>'blue-green', 0x87=>'blue', 0x88=>'purple-blue', 0x89=>'red-purple', 0xff=>'n/a']; + $data = [ + 'PictureControlVersion' => substr($data, 0, 4), + 'PictureControlName' => rtrim(substr($data, 4, 20), "\x00"), + 'PictureControlBase' => rtrim(substr($data, 24, 20), "\x00"), + //'?' => substr($data, 44, 4), + 'PictureControlAdjust' => $PictureControlAdjust[ord(substr($data, 48, 1))], + 'PictureControlQuickAdjust' => ord(substr($data, 49, 1)), + 'Sharpness' => ord(substr($data, 50, 1)), + 'Contrast' => ord(substr($data, 51, 1)), + 'Brightness' => ord(substr($data, 52, 1)), + 'Saturation' => ord(substr($data, 53, 1)), + 'HueAdjustment' => ord(substr($data, 54, 1)), + 'FilterEffect' => $FilterEffect[ord(substr($data, 55, 1))], + 'ToningEffect' => $ToningEffect[ord(substr($data, 56, 1))], + 'ToningSaturation' => ord(substr($data, 57, 1)), + ]; + break; + case 0x02000024: // WorldTime + // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#WorldTime + // timezone is stored as offset from GMT in minutes + $timezone = getid3_lib::BigEndian2Int(substr($data, 0, 2)); + if ($timezone & 0x8000) { + $timezone = 0 - (0x10000 - $timezone); + } + $timezone /= 60; - $dst = (bool) getid3_lib::BigEndian2Int(substr($data, 2, 1)); - switch (getid3_lib::BigEndian2Int(substr($data, 3, 1))) { - case 2: - $datedisplayformat = 'D/M/Y'; break; - case 1: - $datedisplayformat = 'M/D/Y'; break; - case 0: - default: - $datedisplayformat = 'Y/M/D'; break; - } + $dst = (bool) getid3_lib::BigEndian2Int(substr($data, 2, 1)); + switch (getid3_lib::BigEndian2Int(substr($data, 3, 1))) { + case 2: + $datedisplayformat = 'D/M/Y'; break; + case 1: + $datedisplayformat = 'M/D/Y'; break; + case 0: + default: + $datedisplayformat = 'Y/M/D'; break; + } - $data = array('timezone'=>floatval($timezone), 'dst'=>$dst, 'display'=>$datedisplayformat); - break; - case 0x02000083: // LensType - $data = array( - //'_' => $data, - 'mf' => (bool) ($data & 0x01), - 'd' => (bool) ($data & 0x02), - 'g' => (bool) ($data & 0x04), - 'vr' => (bool) ($data & 0x08), - ); - break; - } - $tag_name = (isset($NCTGtagName[$record_type]) ? $NCTGtagName[$record_type] : '0x'.str_pad(dechex($record_type), 8, '0', STR_PAD_LEFT)); - $parsed[$tag_name] = $data; - } - return $parsed; - } + $data = ['timezone'=>floatval($timezone), 'dst'=>$dst, 'display'=>$datedisplayformat]; + break; + case 0x02000083: // LensType + $data = [ + //'_' => $data, + 'mf' => (bool) ($data & 0x01), + 'd' => (bool) ($data & 0x02), + 'g' => (bool) ($data & 0x04), + 'vr' => (bool) ($data & 0x08), + ]; + break; + } + $tag_name = (isset($NCTGtagName[$record_type]) ? $NCTGtagName[$record_type] : '0x'.str_pad(dechex($record_type), 8, '0', STR_PAD_LEFT)); + $parsed[$tag_name] = $data; + } + return $parsed; + } - public function CopyToAppropriateCommentsSection($keyname, $data, $boxname='') { - static $handyatomtranslatorarray = array(); - if (empty($handyatomtranslatorarray)) { - // http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt - // http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt - // http://atomicparsley.sourceforge.net/mpeg-4files.html - // https://code.google.com/p/mp4v2/wiki/iTunesMetadata - $handyatomtranslatorarray["\xA9".'alb'] = 'album'; // iTunes 4.0 - $handyatomtranslatorarray["\xA9".'ART'] = 'artist'; - $handyatomtranslatorarray["\xA9".'art'] = 'artist'; // iTunes 4.0 - $handyatomtranslatorarray["\xA9".'aut'] = 'author'; - $handyatomtranslatorarray["\xA9".'cmt'] = 'comment'; // iTunes 4.0 - $handyatomtranslatorarray["\xA9".'com'] = 'comment'; - $handyatomtranslatorarray["\xA9".'cpy'] = 'copyright'; - $handyatomtranslatorarray["\xA9".'day'] = 'creation_date'; // iTunes 4.0 - $handyatomtranslatorarray["\xA9".'dir'] = 'director'; - $handyatomtranslatorarray["\xA9".'ed1'] = 'edit1'; - $handyatomtranslatorarray["\xA9".'ed2'] = 'edit2'; - $handyatomtranslatorarray["\xA9".'ed3'] = 'edit3'; - $handyatomtranslatorarray["\xA9".'ed4'] = 'edit4'; - $handyatomtranslatorarray["\xA9".'ed5'] = 'edit5'; - $handyatomtranslatorarray["\xA9".'ed6'] = 'edit6'; - $handyatomtranslatorarray["\xA9".'ed7'] = 'edit7'; - $handyatomtranslatorarray["\xA9".'ed8'] = 'edit8'; - $handyatomtranslatorarray["\xA9".'ed9'] = 'edit9'; - $handyatomtranslatorarray["\xA9".'enc'] = 'encoded_by'; - $handyatomtranslatorarray["\xA9".'fmt'] = 'format'; - $handyatomtranslatorarray["\xA9".'gen'] = 'genre'; // iTunes 4.0 - $handyatomtranslatorarray["\xA9".'grp'] = 'grouping'; // iTunes 4.2 - $handyatomtranslatorarray["\xA9".'hst'] = 'host_computer'; - $handyatomtranslatorarray["\xA9".'inf'] = 'information'; - $handyatomtranslatorarray["\xA9".'lyr'] = 'lyrics'; // iTunes 5.0 - $handyatomtranslatorarray["\xA9".'mak'] = 'make'; - $handyatomtranslatorarray["\xA9".'mod'] = 'model'; - $handyatomtranslatorarray["\xA9".'nam'] = 'title'; // iTunes 4.0 - $handyatomtranslatorarray["\xA9".'ope'] = 'composer'; - $handyatomtranslatorarray["\xA9".'prd'] = 'producer'; - $handyatomtranslatorarray["\xA9".'PRD'] = 'product'; - $handyatomtranslatorarray["\xA9".'prf'] = 'performers'; - $handyatomtranslatorarray["\xA9".'req'] = 'system_requirements'; - $handyatomtranslatorarray["\xA9".'src'] = 'source_credit'; - $handyatomtranslatorarray["\xA9".'swr'] = 'software'; - $handyatomtranslatorarray["\xA9".'too'] = 'encoding_tool'; // iTunes 4.0 - $handyatomtranslatorarray["\xA9".'trk'] = 'track'; - $handyatomtranslatorarray["\xA9".'url'] = 'url'; - $handyatomtranslatorarray["\xA9".'wrn'] = 'warning'; - $handyatomtranslatorarray["\xA9".'wrt'] = 'composer'; - $handyatomtranslatorarray['aART'] = 'album_artist'; - $handyatomtranslatorarray['apID'] = 'purchase_account'; - $handyatomtranslatorarray['catg'] = 'category'; // iTunes 4.9 - $handyatomtranslatorarray['covr'] = 'picture'; // iTunes 4.0 - $handyatomtranslatorarray['cpil'] = 'compilation'; // iTunes 4.0 - $handyatomtranslatorarray['cprt'] = 'copyright'; // iTunes 4.0? - $handyatomtranslatorarray['desc'] = 'description'; // iTunes 5.0 - $handyatomtranslatorarray['disk'] = 'disc_number'; // iTunes 4.0 - $handyatomtranslatorarray['egid'] = 'episode_guid'; // iTunes 4.9 - $handyatomtranslatorarray['gnre'] = 'genre'; // iTunes 4.0 - $handyatomtranslatorarray['hdvd'] = 'hd_video'; // iTunes 4.0 - $handyatomtranslatorarray['ldes'] = 'description_long'; // - $handyatomtranslatorarray['keyw'] = 'keyword'; // iTunes 4.9 - $handyatomtranslatorarray['pcst'] = 'podcast'; // iTunes 4.9 - $handyatomtranslatorarray['pgap'] = 'gapless_playback'; // iTunes 7.0 - $handyatomtranslatorarray['purd'] = 'purchase_date'; // iTunes 6.0.2 - $handyatomtranslatorarray['purl'] = 'podcast_url'; // iTunes 4.9 - $handyatomtranslatorarray['rtng'] = 'rating'; // iTunes 4.0 - $handyatomtranslatorarray['soaa'] = 'sort_album_artist'; // - $handyatomtranslatorarray['soal'] = 'sort_album'; // - $handyatomtranslatorarray['soar'] = 'sort_artist'; // - $handyatomtranslatorarray['soco'] = 'sort_composer'; // - $handyatomtranslatorarray['sonm'] = 'sort_title'; // - $handyatomtranslatorarray['sosn'] = 'sort_show'; // - $handyatomtranslatorarray['stik'] = 'stik'; // iTunes 4.9 - $handyatomtranslatorarray['tmpo'] = 'bpm'; // iTunes 4.0 - $handyatomtranslatorarray['trkn'] = 'track_number'; // iTunes 4.0 - $handyatomtranslatorarray['tven'] = 'tv_episode_id'; // - $handyatomtranslatorarray['tves'] = 'tv_episode'; // iTunes 6.0 - $handyatomtranslatorarray['tvnn'] = 'tv_network_name'; // iTunes 6.0 - $handyatomtranslatorarray['tvsh'] = 'tv_show_name'; // iTunes 6.0 - $handyatomtranslatorarray['tvsn'] = 'tv_season'; // iTunes 6.0 + public function CopyToAppropriateCommentsSection($keyname, $data, $boxname = '') + { + static $handyatomtranslatorarray = []; + if (empty($handyatomtranslatorarray)) { + // http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt + // http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt + // http://atomicparsley.sourceforge.net/mpeg-4files.html + // https://code.google.com/p/mp4v2/wiki/iTunesMetadata + $handyatomtranslatorarray["\xA9".'alb'] = 'album'; // iTunes 4.0 + $handyatomtranslatorarray["\xA9".'ART'] = 'artist'; + $handyatomtranslatorarray["\xA9".'art'] = 'artist'; // iTunes 4.0 + $handyatomtranslatorarray["\xA9".'aut'] = 'author'; + $handyatomtranslatorarray["\xA9".'cmt'] = 'comment'; // iTunes 4.0 + $handyatomtranslatorarray["\xA9".'com'] = 'comment'; + $handyatomtranslatorarray["\xA9".'cpy'] = 'copyright'; + $handyatomtranslatorarray["\xA9".'day'] = 'creation_date'; // iTunes 4.0 + $handyatomtranslatorarray["\xA9".'dir'] = 'director'; + $handyatomtranslatorarray["\xA9".'ed1'] = 'edit1'; + $handyatomtranslatorarray["\xA9".'ed2'] = 'edit2'; + $handyatomtranslatorarray["\xA9".'ed3'] = 'edit3'; + $handyatomtranslatorarray["\xA9".'ed4'] = 'edit4'; + $handyatomtranslatorarray["\xA9".'ed5'] = 'edit5'; + $handyatomtranslatorarray["\xA9".'ed6'] = 'edit6'; + $handyatomtranslatorarray["\xA9".'ed7'] = 'edit7'; + $handyatomtranslatorarray["\xA9".'ed8'] = 'edit8'; + $handyatomtranslatorarray["\xA9".'ed9'] = 'edit9'; + $handyatomtranslatorarray["\xA9".'enc'] = 'encoded_by'; + $handyatomtranslatorarray["\xA9".'fmt'] = 'format'; + $handyatomtranslatorarray["\xA9".'gen'] = 'genre'; // iTunes 4.0 + $handyatomtranslatorarray["\xA9".'grp'] = 'grouping'; // iTunes 4.2 + $handyatomtranslatorarray["\xA9".'hst'] = 'host_computer'; + $handyatomtranslatorarray["\xA9".'inf'] = 'information'; + $handyatomtranslatorarray["\xA9".'lyr'] = 'lyrics'; // iTunes 5.0 + $handyatomtranslatorarray["\xA9".'mak'] = 'make'; + $handyatomtranslatorarray["\xA9".'mod'] = 'model'; + $handyatomtranslatorarray["\xA9".'nam'] = 'title'; // iTunes 4.0 + $handyatomtranslatorarray["\xA9".'ope'] = 'composer'; + $handyatomtranslatorarray["\xA9".'prd'] = 'producer'; + $handyatomtranslatorarray["\xA9".'PRD'] = 'product'; + $handyatomtranslatorarray["\xA9".'prf'] = 'performers'; + $handyatomtranslatorarray["\xA9".'req'] = 'system_requirements'; + $handyatomtranslatorarray["\xA9".'src'] = 'source_credit'; + $handyatomtranslatorarray["\xA9".'swr'] = 'software'; + $handyatomtranslatorarray["\xA9".'too'] = 'encoding_tool'; // iTunes 4.0 + $handyatomtranslatorarray["\xA9".'trk'] = 'track'; + $handyatomtranslatorarray["\xA9".'url'] = 'url'; + $handyatomtranslatorarray["\xA9".'wrn'] = 'warning'; + $handyatomtranslatorarray["\xA9".'wrt'] = 'composer'; + $handyatomtranslatorarray['aART'] = 'album_artist'; + $handyatomtranslatorarray['apID'] = 'purchase_account'; + $handyatomtranslatorarray['catg'] = 'category'; // iTunes 4.9 + $handyatomtranslatorarray['covr'] = 'picture'; // iTunes 4.0 + $handyatomtranslatorarray['cpil'] = 'compilation'; // iTunes 4.0 + $handyatomtranslatorarray['cprt'] = 'copyright'; // iTunes 4.0? + $handyatomtranslatorarray['desc'] = 'description'; // iTunes 5.0 + $handyatomtranslatorarray['disk'] = 'disc_number'; // iTunes 4.0 + $handyatomtranslatorarray['egid'] = 'episode_guid'; // iTunes 4.9 + $handyatomtranslatorarray['gnre'] = 'genre'; // iTunes 4.0 + $handyatomtranslatorarray['hdvd'] = 'hd_video'; // iTunes 4.0 + $handyatomtranslatorarray['ldes'] = 'description_long'; // + $handyatomtranslatorarray['keyw'] = 'keyword'; // iTunes 4.9 + $handyatomtranslatorarray['pcst'] = 'podcast'; // iTunes 4.9 + $handyatomtranslatorarray['pgap'] = 'gapless_playback'; // iTunes 7.0 + $handyatomtranslatorarray['purd'] = 'purchase_date'; // iTunes 6.0.2 + $handyatomtranslatorarray['purl'] = 'podcast_url'; // iTunes 4.9 + $handyatomtranslatorarray['rtng'] = 'rating'; // iTunes 4.0 + $handyatomtranslatorarray['soaa'] = 'sort_album_artist'; // + $handyatomtranslatorarray['soal'] = 'sort_album'; // + $handyatomtranslatorarray['soar'] = 'sort_artist'; // + $handyatomtranslatorarray['soco'] = 'sort_composer'; // + $handyatomtranslatorarray['sonm'] = 'sort_title'; // + $handyatomtranslatorarray['sosn'] = 'sort_show'; // + $handyatomtranslatorarray['stik'] = 'stik'; // iTunes 4.9 + $handyatomtranslatorarray['tmpo'] = 'bpm'; // iTunes 4.0 + $handyatomtranslatorarray['trkn'] = 'track_number'; // iTunes 4.0 + $handyatomtranslatorarray['tven'] = 'tv_episode_id'; // + $handyatomtranslatorarray['tves'] = 'tv_episode'; // iTunes 6.0 + $handyatomtranslatorarray['tvnn'] = 'tv_network_name'; // iTunes 6.0 + $handyatomtranslatorarray['tvsh'] = 'tv_show_name'; // iTunes 6.0 + $handyatomtranslatorarray['tvsn'] = 'tv_season'; // iTunes 6.0 - // boxnames: - /* - $handyatomtranslatorarray['iTunSMPB'] = 'iTunSMPB'; - $handyatomtranslatorarray['iTunNORM'] = 'iTunNORM'; - $handyatomtranslatorarray['Encoding Params'] = 'Encoding Params'; - $handyatomtranslatorarray['replaygain_track_gain'] = 'replaygain_track_gain'; - $handyatomtranslatorarray['replaygain_track_peak'] = 'replaygain_track_peak'; - $handyatomtranslatorarray['replaygain_track_minmax'] = 'replaygain_track_minmax'; - $handyatomtranslatorarray['MusicIP PUID'] = 'MusicIP PUID'; - $handyatomtranslatorarray['MusicBrainz Artist Id'] = 'MusicBrainz Artist Id'; - $handyatomtranslatorarray['MusicBrainz Album Id'] = 'MusicBrainz Album Id'; - $handyatomtranslatorarray['MusicBrainz Album Artist Id'] = 'MusicBrainz Album Artist Id'; - $handyatomtranslatorarray['MusicBrainz Track Id'] = 'MusicBrainz Track Id'; - $handyatomtranslatorarray['MusicBrainz Disc Id'] = 'MusicBrainz Disc Id'; + // boxnames: + /* + $handyatomtranslatorarray['iTunSMPB'] = 'iTunSMPB'; + $handyatomtranslatorarray['iTunNORM'] = 'iTunNORM'; + $handyatomtranslatorarray['Encoding Params'] = 'Encoding Params'; + $handyatomtranslatorarray['replaygain_track_gain'] = 'replaygain_track_gain'; + $handyatomtranslatorarray['replaygain_track_peak'] = 'replaygain_track_peak'; + $handyatomtranslatorarray['replaygain_track_minmax'] = 'replaygain_track_minmax'; + $handyatomtranslatorarray['MusicIP PUID'] = 'MusicIP PUID'; + $handyatomtranslatorarray['MusicBrainz Artist Id'] = 'MusicBrainz Artist Id'; + $handyatomtranslatorarray['MusicBrainz Album Id'] = 'MusicBrainz Album Id'; + $handyatomtranslatorarray['MusicBrainz Album Artist Id'] = 'MusicBrainz Album Artist Id'; + $handyatomtranslatorarray['MusicBrainz Track Id'] = 'MusicBrainz Track Id'; + $handyatomtranslatorarray['MusicBrainz Disc Id'] = 'MusicBrainz Disc Id'; - // http://age.hobba.nl/audio/tag_frame_reference.html - $handyatomtranslatorarray['PLAY_COUNTER'] = 'play_counter'; // Foobar2000 - http://www.getid3.org/phpBB3/viewtopic.php?t=1355 - $handyatomtranslatorarray['MEDIATYPE'] = 'mediatype'; // Foobar2000 - http://www.getid3.org/phpBB3/viewtopic.php?t=1355 - */ - } - $info = &$this->getid3->info; - $comment_key = ''; - if ($boxname && ($boxname != $keyname)) { - $comment_key = (isset($handyatomtranslatorarray[$boxname]) ? $handyatomtranslatorarray[$boxname] : $boxname); - } elseif (isset($handyatomtranslatorarray[$keyname])) { - $comment_key = $handyatomtranslatorarray[$keyname]; - } - if ($comment_key) { - if ($comment_key == 'picture') { - if (!is_array($data)) { - $image_mime = ''; - if (preg_match('#^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A#', $data)) { - $image_mime = 'image/png'; - } elseif (preg_match('#^\xFF\xD8\xFF#', $data)) { - $image_mime = 'image/jpeg'; - } elseif (preg_match('#^GIF#', $data)) { - $image_mime = 'image/gif'; - } elseif (preg_match('#^BM#', $data)) { - $image_mime = 'image/bmp'; - } - $data = array('data'=>$data, 'image_mime'=>$image_mime); - } - } - $gooddata = array($data); - if ($comment_key == 'genre') { - // some other taggers separate multiple genres with semicolon, e.g. "Heavy Metal;Thrash Metal;Metal" - $gooddata = explode(';', $data); - } - foreach ($gooddata as $data) { - $info['quicktime']['comments'][$comment_key][] = $data; - } - } - return true; - } + // http://age.hobba.nl/audio/tag_frame_reference.html + $handyatomtranslatorarray['PLAY_COUNTER'] = 'play_counter'; // Foobar2000 - http://www.getid3.org/phpBB3/viewtopic.php?t=1355 + $handyatomtranslatorarray['MEDIATYPE'] = 'mediatype'; // Foobar2000 - http://www.getid3.org/phpBB3/viewtopic.php?t=1355 + */ + } + $info = &$this->getid3->info; + $comment_key = ''; + if ($boxname && ($boxname != $keyname)) { + $comment_key = (isset($handyatomtranslatorarray[$boxname]) ? $handyatomtranslatorarray[$boxname] : $boxname); + } elseif (isset($handyatomtranslatorarray[$keyname])) { + $comment_key = $handyatomtranslatorarray[$keyname]; + } + if ($comment_key) { + if ($comment_key == 'picture') { + if (! is_array($data)) { + $image_mime = ''; + if (preg_match('#^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A#', $data)) { + $image_mime = 'image/png'; + } elseif (preg_match('#^\xFF\xD8\xFF#', $data)) { + $image_mime = 'image/jpeg'; + } elseif (preg_match('#^GIF#', $data)) { + $image_mime = 'image/gif'; + } elseif (preg_match('#^BM#', $data)) { + $image_mime = 'image/bmp'; + } + $data = ['data'=>$data, 'image_mime'=>$image_mime]; + } + } + $gooddata = [$data]; + if ($comment_key == 'genre') { + // some other taggers separate multiple genres with semicolon, e.g. "Heavy Metal;Thrash Metal;Metal" + $gooddata = explode(';', $data); + } + foreach ($gooddata as $data) { + $info['quicktime']['comments'][$comment_key][] = $data; + } + } - public function NoNullString($nullterminatedstring) { - // remove the single null terminator on null terminated strings - if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === "\x00") { - return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1); - } - return $nullterminatedstring; - } + return true; + } - public function Pascal2String($pascalstring) { - // Pascal strings have 1 unsigned byte at the beginning saying how many chars (1-255) are in the string - return substr($pascalstring, 1); - } + public function NoNullString($nullterminatedstring) + { + // remove the single null terminator on null terminated strings + if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === "\x00") { + return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1); + } + return $nullterminatedstring; + } - /* - // helper functions for m4b audiobook chapters - // code by Steffen Hartmann 2015-Nov-08 - */ - public function search_tag_by_key($info, $tag, $history, &$result) { - foreach ($info as $key => $value) { - $key_history = $history.'/'.$key; - if ($key === $tag) { - $result[] = array($key_history, $info); - } else { - if (is_array($value)) { - $this->search_tag_by_key($value, $tag, $key_history, $result); - } - } - } - } + public function Pascal2String($pascalstring) + { + // Pascal strings have 1 unsigned byte at the beginning saying how many chars (1-255) are in the string + return substr($pascalstring, 1); + } - public function search_tag_by_pair($info, $k, $v, $history, &$result) { - foreach ($info as $key => $value) { - $key_history = $history.'/'.$key; - if (($key === $k) && ($value === $v)) { - $result[] = array($key_history, $info); - } else { - if (is_array($value)) { - $this->search_tag_by_pair($value, $k, $v, $key_history, $result); - } - } - } - } + /* + // helper functions for m4b audiobook chapters + // code by Steffen Hartmann 2015-Nov-08 + */ + public function search_tag_by_key($info, $tag, $history, &$result) + { + foreach ($info as $key => $value) { + $key_history = $history.'/'.$key; + if ($key === $tag) { + $result[] = [$key_history, $info]; + } else { + if (is_array($value)) { + $this->search_tag_by_key($value, $tag, $key_history, $result); + } + } + } + } - public function quicktime_time_to_sample_table($info) { - $res = array(); - $this->search_tag_by_pair($info['quicktime']['moov'], 'name', 'stbl', 'quicktime/moov', $res); - foreach ($res as $value) { - $stbl_res = array(); - $this->search_tag_by_pair($value[1], 'data_format', 'text', $value[0], $stbl_res); - if (count($stbl_res) > 0) { - $stts_res = array(); - $this->search_tag_by_key($value[1], 'time_to_sample_table', $value[0], $stts_res); - if (count($stts_res) > 0) { - return $stts_res[0][1]['time_to_sample_table']; - } - } - } - return array(); - } + public function search_tag_by_pair($info, $k, $v, $history, &$result) + { + foreach ($info as $key => $value) { + $key_history = $history.'/'.$key; + if (($key === $k) && ($value === $v)) { + $result[] = [$key_history, $info]; + } else { + if (is_array($value)) { + $this->search_tag_by_pair($value, $k, $v, $key_history, $result); + } + } + } + } - function quicktime_bookmark_time_scale($info) { - $time_scale = ''; - $ts_prefix_len = 0; - $res = array(); - $this->search_tag_by_pair($info['quicktime']['moov'], 'name', 'stbl', 'quicktime/moov', $res); - foreach ($res as $value) { - $stbl_res = array(); - $this->search_tag_by_pair($value[1], 'data_format', 'text', $value[0], $stbl_res); - if (count($stbl_res) > 0) { - $ts_res = array(); - $this->search_tag_by_key($info['quicktime']['moov'], 'time_scale', 'quicktime/moov', $ts_res); - foreach ($ts_res as $value) { - $prefix = substr($value[0], 0, -12); - if ((substr($stbl_res[0][0], 0, strlen($prefix)) === $prefix) && ($ts_prefix_len < strlen($prefix))) { - $time_scale = $value[1]['time_scale']; - $ts_prefix_len = strlen($prefix); - } - } - } - } - return $time_scale; - } - /* - // END helper functions for m4b audiobook chapters - */ + public function quicktime_time_to_sample_table($info) + { + $res = []; + $this->search_tag_by_pair($info['quicktime']['moov'], 'name', 'stbl', 'quicktime/moov', $res); + foreach ($res as $value) { + $stbl_res = []; + $this->search_tag_by_pair($value[1], 'data_format', 'text', $value[0], $stbl_res); + if (count($stbl_res) > 0) { + $stts_res = []; + $this->search_tag_by_key($value[1], 'time_to_sample_table', $value[0], $stts_res); + if (count($stts_res) > 0) { + return $stts_res[0][1]['time_to_sample_table']; + } + } + } + return []; + } + public function quicktime_bookmark_time_scale($info) + { + $time_scale = ''; + $ts_prefix_len = 0; + $res = []; + $this->search_tag_by_pair($info['quicktime']['moov'], 'name', 'stbl', 'quicktime/moov', $res); + foreach ($res as $value) { + $stbl_res = []; + $this->search_tag_by_pair($value[1], 'data_format', 'text', $value[0], $stbl_res); + if (count($stbl_res) > 0) { + $ts_res = []; + $this->search_tag_by_key($info['quicktime']['moov'], 'time_scale', 'quicktime/moov', $ts_res); + foreach ($ts_res as $value) { + $prefix = substr($value[0], 0, -12); + if ((substr($stbl_res[0][0], 0, strlen($prefix)) === $prefix) && ($ts_prefix_len < strlen($prefix))) { + $time_scale = $value[1]['time_scale']; + $ts_prefix_len = strlen($prefix); + } + } + } + } + + return $time_scale; + } + + /* + // END helper functions for m4b audiobook chapters + */ } diff --git a/app/Library/getid3/getid3/module.audio-video.real.php b/app/Library/getid3/getid3/module.audio-video.real.php index 280d43c8..84e74359 100644 --- a/app/Library/getid3/getid3/module.audio-video.real.php +++ b/app/Library/getid3/getid3/module.audio-video.real.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -18,511 +19,501 @@ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', class getid3_real extends getid3_handler { - - public function Analyze() { - $info = &$this->getid3->info; - - $info['fileformat'] = 'real'; - $info['bitrate'] = 0; - $info['playtime_seconds'] = 0; - - $this->fseek($info['avdataoffset']); - $ChunkCounter = 0; - while ($this->ftell() < $info['avdataend']) { - $ChunkData = $this->fread(8); - $ChunkName = substr($ChunkData, 0, 4); - $ChunkSize = getid3_lib::BigEndian2Int(substr($ChunkData, 4, 4)); - - if ($ChunkName == '.ra'."\xFD") { - $ChunkData .= $this->fread($ChunkSize - 8); - if ($this->ParseOldRAheader(substr($ChunkData, 0, 128), $info['real']['old_ra_header'])) { - $info['audio']['dataformat'] = 'real'; - $info['audio']['lossless'] = false; - $info['audio']['sample_rate'] = $info['real']['old_ra_header']['sample_rate']; - $info['audio']['bits_per_sample'] = $info['real']['old_ra_header']['bits_per_sample']; - $info['audio']['channels'] = $info['real']['old_ra_header']['channels']; - - $info['playtime_seconds'] = 60 * ($info['real']['old_ra_header']['audio_bytes'] / $info['real']['old_ra_header']['bytes_per_minute']); - $info['audio']['bitrate'] = 8 * ($info['real']['old_ra_header']['audio_bytes'] / $info['playtime_seconds']); - $info['audio']['codec'] = $this->RealAudioCodecFourCClookup($info['real']['old_ra_header']['fourcc'], $info['audio']['bitrate']); - - foreach ($info['real']['old_ra_header']['comments'] as $key => $valuearray) { - if (strlen(trim($valuearray[0])) > 0) { - $info['real']['comments'][$key][] = trim($valuearray[0]); - } - } - return true; - } - $this->error('There was a problem parsing this RealAudio file. Please submit it for analysis to info@getid3.org'); - unset($info['bitrate']); - unset($info['playtime_seconds']); - return false; - } - - // shortcut - $info['real']['chunks'][$ChunkCounter] = array(); - $thisfile_real_chunks_currentchunk = &$info['real']['chunks'][$ChunkCounter]; - - $thisfile_real_chunks_currentchunk['name'] = $ChunkName; - $thisfile_real_chunks_currentchunk['offset'] = $this->ftell() - 8; - $thisfile_real_chunks_currentchunk['length'] = $ChunkSize; - if (($thisfile_real_chunks_currentchunk['offset'] + $thisfile_real_chunks_currentchunk['length']) > $info['avdataend']) { - $this->warning('Chunk "'.$thisfile_real_chunks_currentchunk['name'].'" at offset '.$thisfile_real_chunks_currentchunk['offset'].' claims to be '.$thisfile_real_chunks_currentchunk['length'].' bytes long, which is beyond end of file'); - return false; - } - - if ($ChunkSize > ($this->getid3->fread_buffer_size() + 8)) { - - $ChunkData .= $this->fread($this->getid3->fread_buffer_size() - 8); - $this->fseek($thisfile_real_chunks_currentchunk['offset'] + $ChunkSize); - - } elseif(($ChunkSize - 8) > 0) { - - $ChunkData .= $this->fread($ChunkSize - 8); - - } - $offset = 8; - - switch ($ChunkName) { - - case '.RMF': // RealMedia File Header - $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); - $offset += 2; - switch ($thisfile_real_chunks_currentchunk['object_version']) { - - case 0: - $thisfile_real_chunks_currentchunk['file_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['headers_count'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - break; - - default: - //$this->warning('Expected .RMF-object_version to be "0", actual value is "'.$thisfile_real_chunks_currentchunk['object_version'].'" (should not be a problem)'); - break; - - } - break; - - - case 'PROP': // Properties Header - $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); - $offset += 2; - if ($thisfile_real_chunks_currentchunk['object_version'] == 0) { - $thisfile_real_chunks_currentchunk['max_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['avg_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['max_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['avg_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['num_packets'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['duration'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['preroll'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['index_offset'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['data_offset'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['num_streams'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); - $offset += 2; - $thisfile_real_chunks_currentchunk['flags_raw'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); - $offset += 2; - $info['playtime_seconds'] = $thisfile_real_chunks_currentchunk['duration'] / 1000; - if ($thisfile_real_chunks_currentchunk['duration'] > 0) { - $info['bitrate'] += $thisfile_real_chunks_currentchunk['avg_bit_rate']; - } - $thisfile_real_chunks_currentchunk['flags']['save_enabled'] = (bool) ($thisfile_real_chunks_currentchunk['flags_raw'] & 0x0001); - $thisfile_real_chunks_currentchunk['flags']['perfect_play'] = (bool) ($thisfile_real_chunks_currentchunk['flags_raw'] & 0x0002); - $thisfile_real_chunks_currentchunk['flags']['live_broadcast'] = (bool) ($thisfile_real_chunks_currentchunk['flags_raw'] & 0x0004); - } - break; - - case 'MDPR': // Media Properties Header - $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); - $offset += 2; - if ($thisfile_real_chunks_currentchunk['object_version'] == 0) { - $thisfile_real_chunks_currentchunk['stream_number'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); - $offset += 2; - $thisfile_real_chunks_currentchunk['max_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['avg_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['max_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['avg_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['start_time'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['preroll'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['duration'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['stream_name_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 1)); - $offset += 1; - $thisfile_real_chunks_currentchunk['stream_name'] = substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['stream_name_size']); - $offset += $thisfile_real_chunks_currentchunk['stream_name_size']; - $thisfile_real_chunks_currentchunk['mime_type_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 1)); - $offset += 1; - $thisfile_real_chunks_currentchunk['mime_type'] = substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['mime_type_size']); - $offset += $thisfile_real_chunks_currentchunk['mime_type_size']; - $thisfile_real_chunks_currentchunk['type_specific_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['type_specific_data'] = substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['type_specific_len']); - $offset += $thisfile_real_chunks_currentchunk['type_specific_len']; - - // shortcut - $thisfile_real_chunks_currentchunk_typespecificdata = &$thisfile_real_chunks_currentchunk['type_specific_data']; - - switch ($thisfile_real_chunks_currentchunk['mime_type']) { - case 'video/x-pn-realvideo': - case 'video/x-pn-multirate-realvideo': - // http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html - - // shortcut - $thisfile_real_chunks_currentchunk['video_info'] = array(); - $thisfile_real_chunks_currentchunk_videoinfo = &$thisfile_real_chunks_currentchunk['video_info']; - - $thisfile_real_chunks_currentchunk_videoinfo['dwSize'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 0, 4)); - $thisfile_real_chunks_currentchunk_videoinfo['fourcc1'] = substr($thisfile_real_chunks_currentchunk_typespecificdata, 4, 4); - $thisfile_real_chunks_currentchunk_videoinfo['fourcc2'] = substr($thisfile_real_chunks_currentchunk_typespecificdata, 8, 4); - $thisfile_real_chunks_currentchunk_videoinfo['width'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 12, 2)); - $thisfile_real_chunks_currentchunk_videoinfo['height'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 14, 2)); - $thisfile_real_chunks_currentchunk_videoinfo['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 16, 2)); - //$thisfile_real_chunks_currentchunk_videoinfo['unknown1'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 18, 2)); - //$thisfile_real_chunks_currentchunk_videoinfo['unknown2'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 20, 2)); - $thisfile_real_chunks_currentchunk_videoinfo['frames_per_second'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 22, 2)); - //$thisfile_real_chunks_currentchunk_videoinfo['unknown3'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 24, 2)); - //$thisfile_real_chunks_currentchunk_videoinfo['unknown4'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 26, 2)); - //$thisfile_real_chunks_currentchunk_videoinfo['unknown5'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 28, 2)); - //$thisfile_real_chunks_currentchunk_videoinfo['unknown6'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 30, 2)); - //$thisfile_real_chunks_currentchunk_videoinfo['unknown7'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 32, 2)); - //$thisfile_real_chunks_currentchunk_videoinfo['unknown8'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 34, 2)); - //$thisfile_real_chunks_currentchunk_videoinfo['unknown9'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 36, 2)); - - $thisfile_real_chunks_currentchunk_videoinfo['codec'] = getid3_riff::fourccLookup($thisfile_real_chunks_currentchunk_videoinfo['fourcc2']); - - $info['video']['resolution_x'] = $thisfile_real_chunks_currentchunk_videoinfo['width']; - $info['video']['resolution_y'] = $thisfile_real_chunks_currentchunk_videoinfo['height']; - $info['video']['frame_rate'] = (float) $thisfile_real_chunks_currentchunk_videoinfo['frames_per_second']; - $info['video']['codec'] = $thisfile_real_chunks_currentchunk_videoinfo['codec']; - $info['video']['bits_per_sample'] = $thisfile_real_chunks_currentchunk_videoinfo['bits_per_sample']; - break; - - case 'audio/x-pn-realaudio': - case 'audio/x-pn-multirate-realaudio': - $this->ParseOldRAheader($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk['parsed_audio_data']); - - $info['audio']['sample_rate'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['sample_rate']; - $info['audio']['bits_per_sample'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['bits_per_sample']; - $info['audio']['channels'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['channels']; - if (!empty($info['audio']['dataformat'])) { - foreach ($info['audio'] as $key => $value) { - if ($key != 'streams') { - $info['audio']['streams'][$thisfile_real_chunks_currentchunk['stream_number']][$key] = $value; - } - } - } - break; - - case 'logical-fileinfo': - // shortcut - $thisfile_real_chunks_currentchunk['logical_fileinfo'] = array(); - $thisfile_real_chunks_currentchunk_logicalfileinfo = &$thisfile_real_chunks_currentchunk['logical_fileinfo']; - - $thisfile_real_chunks_currentchunk_logicalfileinfo_offset = 0; - $thisfile_real_chunks_currentchunk_logicalfileinfo['logical_fileinfo_length'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4)); - $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4; - - //$thisfile_real_chunks_currentchunk_logicalfileinfo['unknown1'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4)); - $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4; - - $thisfile_real_chunks_currentchunk_logicalfileinfo['num_tags'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4)); - $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4; - - //$thisfile_real_chunks_currentchunk_logicalfileinfo['unknown2'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4)); - $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4; - - //$thisfile_real_chunks_currentchunk_logicalfileinfo['d'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 1)); - - //$thisfile_real_chunks_currentchunk_logicalfileinfo['one_type'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4)); - //$thisfile_real_chunks_currentchunk_logicalfileinfo_thislength = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 4 + $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 2)); - //$thisfile_real_chunks_currentchunk_logicalfileinfo['one'] = substr($thisfile_real_chunks_currentchunk_typespecificdata, 6 + $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, $thisfile_real_chunks_currentchunk_logicalfileinfo_thislength); - //$thisfile_real_chunks_currentchunk_logicalfileinfo_offset += (6 + $thisfile_real_chunks_currentchunk_logicalfileinfo_thislength); - - break; - - } - - - if (empty($info['playtime_seconds'])) { - $info['playtime_seconds'] = max($info['playtime_seconds'], ($thisfile_real_chunks_currentchunk['duration'] + $thisfile_real_chunks_currentchunk['start_time']) / 1000); - } - if ($thisfile_real_chunks_currentchunk['duration'] > 0) { - switch ($thisfile_real_chunks_currentchunk['mime_type']) { - case 'audio/x-pn-realaudio': - case 'audio/x-pn-multirate-realaudio': - $info['audio']['bitrate'] = (isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate']; - $info['audio']['codec'] = $this->RealAudioCodecFourCClookup($thisfile_real_chunks_currentchunk['parsed_audio_data']['fourcc'], $info['audio']['bitrate']); - $info['audio']['dataformat'] = 'real'; - $info['audio']['lossless'] = false; - break; - - case 'video/x-pn-realvideo': - case 'video/x-pn-multirate-realvideo': - $info['video']['bitrate'] = (isset($info['video']['bitrate']) ? $info['video']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate']; - $info['video']['bitrate_mode'] = 'cbr'; - $info['video']['dataformat'] = 'real'; - $info['video']['lossless'] = false; - $info['video']['pixel_aspect_ratio'] = (float) 1; - break; - - case 'audio/x-ralf-mpeg4-generic': - $info['audio']['bitrate'] = (isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate']; - $info['audio']['codec'] = 'RealAudio Lossless'; - $info['audio']['dataformat'] = 'real'; - $info['audio']['lossless'] = true; - break; - } - $info['bitrate'] = (isset($info['video']['bitrate']) ? $info['video']['bitrate'] : 0) + (isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : 0); - } - } - break; - - case 'CONT': // Content Description Header (text comments) - $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); - $offset += 2; - if ($thisfile_real_chunks_currentchunk['object_version'] == 0) { - $thisfile_real_chunks_currentchunk['title_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); - $offset += 2; - $thisfile_real_chunks_currentchunk['title'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['title_len']); - $offset += $thisfile_real_chunks_currentchunk['title_len']; - - $thisfile_real_chunks_currentchunk['artist_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); - $offset += 2; - $thisfile_real_chunks_currentchunk['artist'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['artist_len']); - $offset += $thisfile_real_chunks_currentchunk['artist_len']; - - $thisfile_real_chunks_currentchunk['copyright_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); - $offset += 2; - $thisfile_real_chunks_currentchunk['copyright'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['copyright_len']); - $offset += $thisfile_real_chunks_currentchunk['copyright_len']; - - $thisfile_real_chunks_currentchunk['comment_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); - $offset += 2; - $thisfile_real_chunks_currentchunk['comment'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['comment_len']); - $offset += $thisfile_real_chunks_currentchunk['comment_len']; - - - $commentkeystocopy = array('title'=>'title', 'artist'=>'artist', 'copyright'=>'copyright', 'comment'=>'comment'); - foreach ($commentkeystocopy as $key => $val) { - if ($thisfile_real_chunks_currentchunk[$key]) { - $info['real']['comments'][$val][] = trim($thisfile_real_chunks_currentchunk[$key]); - } - } - - } - break; - - - case 'DATA': // Data Chunk Header - // do nothing - break; - - case 'INDX': // Index Section Header - $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); - $offset += 2; - if ($thisfile_real_chunks_currentchunk['object_version'] == 0) { - $thisfile_real_chunks_currentchunk['num_indices'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - $thisfile_real_chunks_currentchunk['stream_number'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); - $offset += 2; - $thisfile_real_chunks_currentchunk['next_index_header'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); - $offset += 4; - - if ($thisfile_real_chunks_currentchunk['next_index_header'] == 0) { - // last index chunk found, ignore rest of file - break 2; - } else { - // non-last index chunk, seek to next index chunk (skipping actual index data) - $this->fseek($thisfile_real_chunks_currentchunk['next_index_header']); - } - } - break; - - default: - $this->warning('Unhandled RealMedia chunk "'.$ChunkName.'" at offset '.$thisfile_real_chunks_currentchunk['offset']); - break; - } - $ChunkCounter++; - } - - if (!empty($info['audio']['streams'])) { - $info['audio']['bitrate'] = 0; - foreach ($info['audio']['streams'] as $key => $valuearray) { - $info['audio']['bitrate'] += $valuearray['bitrate']; - } - } - - return true; - } - - - public function ParseOldRAheader($OldRAheaderData, &$ParsedArray) { - // http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html - - $ParsedArray = array(); - $ParsedArray['magic'] = substr($OldRAheaderData, 0, 4); - if ($ParsedArray['magic'] != '.ra'."\xFD") { - return false; - } - $ParsedArray['version1'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 4, 2)); - - if ($ParsedArray['version1'] < 3) { - - return false; - - } elseif ($ParsedArray['version1'] == 3) { - - $ParsedArray['fourcc1'] = '.ra3'; - $ParsedArray['bits_per_sample'] = 16; // hard-coded for old versions? - $ParsedArray['sample_rate'] = 8000; // hard-coded for old versions? - - $ParsedArray['header_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 6, 2)); - $ParsedArray['channels'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 8, 2)); // always 1 (?) - //$ParsedArray['unknown1'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 10, 2)); - //$ParsedArray['unknown2'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 12, 2)); - //$ParsedArray['unknown3'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 14, 2)); - $ParsedArray['bytes_per_minute'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 16, 2)); - $ParsedArray['audio_bytes'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 18, 4)); - $ParsedArray['comments_raw'] = substr($OldRAheaderData, 22, $ParsedArray['header_size'] - 22 + 1); // not including null terminator - - $commentoffset = 0; - $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1)); - $ParsedArray['comments']['title'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength); - $commentoffset += $commentlength; - - $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1)); - $ParsedArray['comments']['artist'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength); - $commentoffset += $commentlength; - - $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1)); - $ParsedArray['comments']['copyright'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength); - $commentoffset += $commentlength; - - $commentoffset++; // final null terminator (?) - $commentoffset++; // fourcc length (?) should be 4 - $ParsedArray['fourcc'] = substr($OldRAheaderData, 23 + $commentoffset, 4); - - } elseif ($ParsedArray['version1'] <= 5) { - - //$ParsedArray['unknown1'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 6, 2)); - $ParsedArray['fourcc1'] = substr($OldRAheaderData, 8, 4); - $ParsedArray['file_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 12, 4)); - $ParsedArray['version2'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 16, 2)); - $ParsedArray['header_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 18, 4)); - $ParsedArray['codec_flavor_id'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 22, 2)); - $ParsedArray['coded_frame_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 24, 4)); - $ParsedArray['audio_bytes'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 28, 4)); - $ParsedArray['bytes_per_minute'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 32, 4)); - //$ParsedArray['unknown5'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 36, 4)); - $ParsedArray['sub_packet_h'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 40, 2)); - $ParsedArray['frame_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 42, 2)); - $ParsedArray['sub_packet_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 44, 2)); - //$ParsedArray['unknown6'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 46, 2)); - - switch ($ParsedArray['version1']) { - - case 4: - $ParsedArray['sample_rate'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 48, 2)); - //$ParsedArray['unknown8'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 50, 2)); - $ParsedArray['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 52, 2)); - $ParsedArray['channels'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 54, 2)); - $ParsedArray['length_fourcc2'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 56, 1)); - $ParsedArray['fourcc2'] = substr($OldRAheaderData, 57, 4); - $ParsedArray['length_fourcc3'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 61, 1)); - $ParsedArray['fourcc3'] = substr($OldRAheaderData, 62, 4); - //$ParsedArray['unknown9'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 66, 1)); - //$ParsedArray['unknown10'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 67, 2)); - $ParsedArray['comments_raw'] = substr($OldRAheaderData, 69, $ParsedArray['header_size'] - 69 + 16); - - $commentoffset = 0; - $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1)); - $ParsedArray['comments']['title'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength); - $commentoffset += $commentlength; - - $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1)); - $ParsedArray['comments']['artist'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength); - $commentoffset += $commentlength; - - $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1)); - $ParsedArray['comments']['copyright'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength); - $commentoffset += $commentlength; - break; - - case 5: - $ParsedArray['sample_rate'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 48, 4)); - $ParsedArray['sample_rate2'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 52, 4)); - $ParsedArray['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 56, 4)); - $ParsedArray['channels'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 60, 2)); - $ParsedArray['genr'] = substr($OldRAheaderData, 62, 4); - $ParsedArray['fourcc3'] = substr($OldRAheaderData, 66, 4); - $ParsedArray['comments'] = array(); - break; - } - $ParsedArray['fourcc'] = $ParsedArray['fourcc3']; - - } - foreach ($ParsedArray['comments'] as $key => $value) { - if ($ParsedArray['comments'][$key][0] === false) { - $ParsedArray['comments'][$key][0] = ''; - } - } - - return true; - } - - public function RealAudioCodecFourCClookup($fourcc, $bitrate) { - static $RealAudioCodecFourCClookup = array(); - if (empty($RealAudioCodecFourCClookup)) { - // http://www.its.msstate.edu/net/real/reports/config/tags.stats - // http://www.freelists.org/archives/matroska-devel/06-2003/fullthread18.html - - $RealAudioCodecFourCClookup['14_4'][8000] = 'RealAudio v2 (14.4kbps)'; - $RealAudioCodecFourCClookup['14.4'][8000] = 'RealAudio v2 (14.4kbps)'; - $RealAudioCodecFourCClookup['lpcJ'][8000] = 'RealAudio v2 (14.4kbps)'; - $RealAudioCodecFourCClookup['28_8'][15200] = 'RealAudio v2 (28.8kbps)'; - $RealAudioCodecFourCClookup['28.8'][15200] = 'RealAudio v2 (28.8kbps)'; - $RealAudioCodecFourCClookup['sipr'][4933] = 'RealAudio v4 (5kbps Voice)'; - $RealAudioCodecFourCClookup['sipr'][6444] = 'RealAudio v4 (6.5kbps Voice)'; - $RealAudioCodecFourCClookup['sipr'][8444] = 'RealAudio v4 (8.5kbps Voice)'; - $RealAudioCodecFourCClookup['sipr'][16000] = 'RealAudio v4 (16kbps Wideband)'; - $RealAudioCodecFourCClookup['dnet'][8000] = 'RealAudio v3 (8kbps Music)'; - $RealAudioCodecFourCClookup['dnet'][16000] = 'RealAudio v3 (16kbps Music Low Response)'; - $RealAudioCodecFourCClookup['dnet'][15963] = 'RealAudio v3 (16kbps Music Mid/High Response)'; - $RealAudioCodecFourCClookup['dnet'][20000] = 'RealAudio v3 (20kbps Music Stereo)'; - $RealAudioCodecFourCClookup['dnet'][32000] = 'RealAudio v3 (32kbps Music Mono)'; - $RealAudioCodecFourCClookup['dnet'][31951] = 'RealAudio v3 (32kbps Music Stereo)'; - $RealAudioCodecFourCClookup['dnet'][39965] = 'RealAudio v3 (40kbps Music Mono)'; - $RealAudioCodecFourCClookup['dnet'][40000] = 'RealAudio v3 (40kbps Music Stereo)'; - $RealAudioCodecFourCClookup['dnet'][79947] = 'RealAudio v3 (80kbps Music Mono)'; - $RealAudioCodecFourCClookup['dnet'][80000] = 'RealAudio v3 (80kbps Music Stereo)'; - - $RealAudioCodecFourCClookup['dnet'][0] = 'RealAudio v3'; - $RealAudioCodecFourCClookup['sipr'][0] = 'RealAudio v4'; - $RealAudioCodecFourCClookup['cook'][0] = 'RealAudio G2'; - $RealAudioCodecFourCClookup['atrc'][0] = 'RealAudio 8'; - } - $roundbitrate = intval(round($bitrate)); - if (isset($RealAudioCodecFourCClookup[$fourcc][$roundbitrate])) { - return $RealAudioCodecFourCClookup[$fourcc][$roundbitrate]; - } elseif (isset($RealAudioCodecFourCClookup[$fourcc][0])) { - return $RealAudioCodecFourCClookup[$fourcc][0]; - } - return $fourcc; - } - + public function Analyze() + { + $info = &$this->getid3->info; + + $info['fileformat'] = 'real'; + $info['bitrate'] = 0; + $info['playtime_seconds'] = 0; + + $this->fseek($info['avdataoffset']); + $ChunkCounter = 0; + while ($this->ftell() < $info['avdataend']) { + $ChunkData = $this->fread(8); + $ChunkName = substr($ChunkData, 0, 4); + $ChunkSize = getid3_lib::BigEndian2Int(substr($ChunkData, 4, 4)); + + if ($ChunkName == '.ra'."\xFD") { + $ChunkData .= $this->fread($ChunkSize - 8); + if ($this->ParseOldRAheader(substr($ChunkData, 0, 128), $info['real']['old_ra_header'])) { + $info['audio']['dataformat'] = 'real'; + $info['audio']['lossless'] = false; + $info['audio']['sample_rate'] = $info['real']['old_ra_header']['sample_rate']; + $info['audio']['bits_per_sample'] = $info['real']['old_ra_header']['bits_per_sample']; + $info['audio']['channels'] = $info['real']['old_ra_header']['channels']; + + $info['playtime_seconds'] = 60 * ($info['real']['old_ra_header']['audio_bytes'] / $info['real']['old_ra_header']['bytes_per_minute']); + $info['audio']['bitrate'] = 8 * ($info['real']['old_ra_header']['audio_bytes'] / $info['playtime_seconds']); + $info['audio']['codec'] = $this->RealAudioCodecFourCClookup($info['real']['old_ra_header']['fourcc'], $info['audio']['bitrate']); + + foreach ($info['real']['old_ra_header']['comments'] as $key => $valuearray) { + if (strlen(trim($valuearray[0])) > 0) { + $info['real']['comments'][$key][] = trim($valuearray[0]); + } + } + + return true; + } + $this->error('There was a problem parsing this RealAudio file. Please submit it for analysis to info@getid3.org'); + unset($info['bitrate']); + unset($info['playtime_seconds']); + + return false; + } + + // shortcut + $info['real']['chunks'][$ChunkCounter] = []; + $thisfile_real_chunks_currentchunk = &$info['real']['chunks'][$ChunkCounter]; + + $thisfile_real_chunks_currentchunk['name'] = $ChunkName; + $thisfile_real_chunks_currentchunk['offset'] = $this->ftell() - 8; + $thisfile_real_chunks_currentchunk['length'] = $ChunkSize; + if (($thisfile_real_chunks_currentchunk['offset'] + $thisfile_real_chunks_currentchunk['length']) > $info['avdataend']) { + $this->warning('Chunk "'.$thisfile_real_chunks_currentchunk['name'].'" at offset '.$thisfile_real_chunks_currentchunk['offset'].' claims to be '.$thisfile_real_chunks_currentchunk['length'].' bytes long, which is beyond end of file'); + + return false; + } + + if ($ChunkSize > ($this->getid3->fread_buffer_size() + 8)) { + $ChunkData .= $this->fread($this->getid3->fread_buffer_size() - 8); + $this->fseek($thisfile_real_chunks_currentchunk['offset'] + $ChunkSize); + } elseif (($ChunkSize - 8) > 0) { + $ChunkData .= $this->fread($ChunkSize - 8); + } + $offset = 8; + + switch ($ChunkName) { + + case '.RMF': // RealMedia File Header + $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); + $offset += 2; + switch ($thisfile_real_chunks_currentchunk['object_version']) { + + case 0: + $thisfile_real_chunks_currentchunk['file_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['headers_count'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + break; + + default: + //$this->warning('Expected .RMF-object_version to be "0", actual value is "'.$thisfile_real_chunks_currentchunk['object_version'].'" (should not be a problem)'); + break; + + } + break; + + case 'PROP': // Properties Header + $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); + $offset += 2; + if ($thisfile_real_chunks_currentchunk['object_version'] == 0) { + $thisfile_real_chunks_currentchunk['max_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['avg_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['max_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['avg_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['num_packets'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['duration'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['preroll'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['index_offset'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['data_offset'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['num_streams'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); + $offset += 2; + $thisfile_real_chunks_currentchunk['flags_raw'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); + $offset += 2; + $info['playtime_seconds'] = $thisfile_real_chunks_currentchunk['duration'] / 1000; + if ($thisfile_real_chunks_currentchunk['duration'] > 0) { + $info['bitrate'] += $thisfile_real_chunks_currentchunk['avg_bit_rate']; + } + $thisfile_real_chunks_currentchunk['flags']['save_enabled'] = (bool) ($thisfile_real_chunks_currentchunk['flags_raw'] & 0x0001); + $thisfile_real_chunks_currentchunk['flags']['perfect_play'] = (bool) ($thisfile_real_chunks_currentchunk['flags_raw'] & 0x0002); + $thisfile_real_chunks_currentchunk['flags']['live_broadcast'] = (bool) ($thisfile_real_chunks_currentchunk['flags_raw'] & 0x0004); + } + break; + + case 'MDPR': // Media Properties Header + $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); + $offset += 2; + if ($thisfile_real_chunks_currentchunk['object_version'] == 0) { + $thisfile_real_chunks_currentchunk['stream_number'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); + $offset += 2; + $thisfile_real_chunks_currentchunk['max_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['avg_bit_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['max_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['avg_packet_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['start_time'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['preroll'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['duration'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['stream_name_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 1)); + $offset += 1; + $thisfile_real_chunks_currentchunk['stream_name'] = substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['stream_name_size']); + $offset += $thisfile_real_chunks_currentchunk['stream_name_size']; + $thisfile_real_chunks_currentchunk['mime_type_size'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 1)); + $offset += 1; + $thisfile_real_chunks_currentchunk['mime_type'] = substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['mime_type_size']); + $offset += $thisfile_real_chunks_currentchunk['mime_type_size']; + $thisfile_real_chunks_currentchunk['type_specific_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['type_specific_data'] = substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['type_specific_len']); + $offset += $thisfile_real_chunks_currentchunk['type_specific_len']; + + // shortcut + $thisfile_real_chunks_currentchunk_typespecificdata = &$thisfile_real_chunks_currentchunk['type_specific_data']; + + switch ($thisfile_real_chunks_currentchunk['mime_type']) { + case 'video/x-pn-realvideo': + case 'video/x-pn-multirate-realvideo': + // http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html + + // shortcut + $thisfile_real_chunks_currentchunk['video_info'] = []; + $thisfile_real_chunks_currentchunk_videoinfo = &$thisfile_real_chunks_currentchunk['video_info']; + + $thisfile_real_chunks_currentchunk_videoinfo['dwSize'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 0, 4)); + $thisfile_real_chunks_currentchunk_videoinfo['fourcc1'] = substr($thisfile_real_chunks_currentchunk_typespecificdata, 4, 4); + $thisfile_real_chunks_currentchunk_videoinfo['fourcc2'] = substr($thisfile_real_chunks_currentchunk_typespecificdata, 8, 4); + $thisfile_real_chunks_currentchunk_videoinfo['width'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 12, 2)); + $thisfile_real_chunks_currentchunk_videoinfo['height'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 14, 2)); + $thisfile_real_chunks_currentchunk_videoinfo['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 16, 2)); + //$thisfile_real_chunks_currentchunk_videoinfo['unknown1'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 18, 2)); + //$thisfile_real_chunks_currentchunk_videoinfo['unknown2'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 20, 2)); + $thisfile_real_chunks_currentchunk_videoinfo['frames_per_second'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 22, 2)); + //$thisfile_real_chunks_currentchunk_videoinfo['unknown3'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 24, 2)); + //$thisfile_real_chunks_currentchunk_videoinfo['unknown4'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 26, 2)); + //$thisfile_real_chunks_currentchunk_videoinfo['unknown5'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 28, 2)); + //$thisfile_real_chunks_currentchunk_videoinfo['unknown6'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 30, 2)); + //$thisfile_real_chunks_currentchunk_videoinfo['unknown7'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 32, 2)); + //$thisfile_real_chunks_currentchunk_videoinfo['unknown8'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 34, 2)); + //$thisfile_real_chunks_currentchunk_videoinfo['unknown9'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 36, 2)); + + $thisfile_real_chunks_currentchunk_videoinfo['codec'] = getid3_riff::fourccLookup($thisfile_real_chunks_currentchunk_videoinfo['fourcc2']); + + $info['video']['resolution_x'] = $thisfile_real_chunks_currentchunk_videoinfo['width']; + $info['video']['resolution_y'] = $thisfile_real_chunks_currentchunk_videoinfo['height']; + $info['video']['frame_rate'] = (float) $thisfile_real_chunks_currentchunk_videoinfo['frames_per_second']; + $info['video']['codec'] = $thisfile_real_chunks_currentchunk_videoinfo['codec']; + $info['video']['bits_per_sample'] = $thisfile_real_chunks_currentchunk_videoinfo['bits_per_sample']; + break; + + case 'audio/x-pn-realaudio': + case 'audio/x-pn-multirate-realaudio': + $this->ParseOldRAheader($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk['parsed_audio_data']); + + $info['audio']['sample_rate'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['sample_rate']; + $info['audio']['bits_per_sample'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['bits_per_sample']; + $info['audio']['channels'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['channels']; + if (! empty($info['audio']['dataformat'])) { + foreach ($info['audio'] as $key => $value) { + if ($key != 'streams') { + $info['audio']['streams'][$thisfile_real_chunks_currentchunk['stream_number']][$key] = $value; + } + } + } + break; + + case 'logical-fileinfo': + // shortcut + $thisfile_real_chunks_currentchunk['logical_fileinfo'] = []; + $thisfile_real_chunks_currentchunk_logicalfileinfo = &$thisfile_real_chunks_currentchunk['logical_fileinfo']; + + $thisfile_real_chunks_currentchunk_logicalfileinfo_offset = 0; + $thisfile_real_chunks_currentchunk_logicalfileinfo['logical_fileinfo_length'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4)); + $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4; + + //$thisfile_real_chunks_currentchunk_logicalfileinfo['unknown1'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4)); + $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4; + + $thisfile_real_chunks_currentchunk_logicalfileinfo['num_tags'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4)); + $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4; + + //$thisfile_real_chunks_currentchunk_logicalfileinfo['unknown2'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4)); + $thisfile_real_chunks_currentchunk_logicalfileinfo_offset += 4; + + //$thisfile_real_chunks_currentchunk_logicalfileinfo['d'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 1)); + + //$thisfile_real_chunks_currentchunk_logicalfileinfo['one_type'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 4)); + //$thisfile_real_chunks_currentchunk_logicalfileinfo_thislength = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 4 + $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, 2)); + //$thisfile_real_chunks_currentchunk_logicalfileinfo['one'] = substr($thisfile_real_chunks_currentchunk_typespecificdata, 6 + $thisfile_real_chunks_currentchunk_logicalfileinfo_offset, $thisfile_real_chunks_currentchunk_logicalfileinfo_thislength); + //$thisfile_real_chunks_currentchunk_logicalfileinfo_offset += (6 + $thisfile_real_chunks_currentchunk_logicalfileinfo_thislength); + + break; + + } + + if (empty($info['playtime_seconds'])) { + $info['playtime_seconds'] = max($info['playtime_seconds'], ($thisfile_real_chunks_currentchunk['duration'] + $thisfile_real_chunks_currentchunk['start_time']) / 1000); + } + if ($thisfile_real_chunks_currentchunk['duration'] > 0) { + switch ($thisfile_real_chunks_currentchunk['mime_type']) { + case 'audio/x-pn-realaudio': + case 'audio/x-pn-multirate-realaudio': + $info['audio']['bitrate'] = (isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate']; + $info['audio']['codec'] = $this->RealAudioCodecFourCClookup($thisfile_real_chunks_currentchunk['parsed_audio_data']['fourcc'], $info['audio']['bitrate']); + $info['audio']['dataformat'] = 'real'; + $info['audio']['lossless'] = false; + break; + + case 'video/x-pn-realvideo': + case 'video/x-pn-multirate-realvideo': + $info['video']['bitrate'] = (isset($info['video']['bitrate']) ? $info['video']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate']; + $info['video']['bitrate_mode'] = 'cbr'; + $info['video']['dataformat'] = 'real'; + $info['video']['lossless'] = false; + $info['video']['pixel_aspect_ratio'] = (float) 1; + break; + + case 'audio/x-ralf-mpeg4-generic': + $info['audio']['bitrate'] = (isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate']; + $info['audio']['codec'] = 'RealAudio Lossless'; + $info['audio']['dataformat'] = 'real'; + $info['audio']['lossless'] = true; + break; + } + $info['bitrate'] = (isset($info['video']['bitrate']) ? $info['video']['bitrate'] : 0) + (isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : 0); + } + } + break; + + case 'CONT': // Content Description Header (text comments) + $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); + $offset += 2; + if ($thisfile_real_chunks_currentchunk['object_version'] == 0) { + $thisfile_real_chunks_currentchunk['title_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); + $offset += 2; + $thisfile_real_chunks_currentchunk['title'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['title_len']); + $offset += $thisfile_real_chunks_currentchunk['title_len']; + + $thisfile_real_chunks_currentchunk['artist_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); + $offset += 2; + $thisfile_real_chunks_currentchunk['artist'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['artist_len']); + $offset += $thisfile_real_chunks_currentchunk['artist_len']; + + $thisfile_real_chunks_currentchunk['copyright_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); + $offset += 2; + $thisfile_real_chunks_currentchunk['copyright'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['copyright_len']); + $offset += $thisfile_real_chunks_currentchunk['copyright_len']; + + $thisfile_real_chunks_currentchunk['comment_len'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); + $offset += 2; + $thisfile_real_chunks_currentchunk['comment'] = (string) substr($ChunkData, $offset, $thisfile_real_chunks_currentchunk['comment_len']); + $offset += $thisfile_real_chunks_currentchunk['comment_len']; + + $commentkeystocopy = ['title'=>'title', 'artist'=>'artist', 'copyright'=>'copyright', 'comment'=>'comment']; + foreach ($commentkeystocopy as $key => $val) { + if ($thisfile_real_chunks_currentchunk[$key]) { + $info['real']['comments'][$val][] = trim($thisfile_real_chunks_currentchunk[$key]); + } + } + } + break; + + case 'DATA': // Data Chunk Header + // do nothing + break; + + case 'INDX': // Index Section Header + $thisfile_real_chunks_currentchunk['object_version'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); + $offset += 2; + if ($thisfile_real_chunks_currentchunk['object_version'] == 0) { + $thisfile_real_chunks_currentchunk['num_indices'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + $thisfile_real_chunks_currentchunk['stream_number'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); + $offset += 2; + $thisfile_real_chunks_currentchunk['next_index_header'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 4)); + $offset += 4; + + if ($thisfile_real_chunks_currentchunk['next_index_header'] == 0) { + // last index chunk found, ignore rest of file + break 2; + } else { + // non-last index chunk, seek to next index chunk (skipping actual index data) + $this->fseek($thisfile_real_chunks_currentchunk['next_index_header']); + } + } + break; + + default: + $this->warning('Unhandled RealMedia chunk "'.$ChunkName.'" at offset '.$thisfile_real_chunks_currentchunk['offset']); + break; + } + $ChunkCounter++; + } + + if (! empty($info['audio']['streams'])) { + $info['audio']['bitrate'] = 0; + foreach ($info['audio']['streams'] as $key => $valuearray) { + $info['audio']['bitrate'] += $valuearray['bitrate']; + } + } + + return true; + } + + public function ParseOldRAheader($OldRAheaderData, &$ParsedArray) + { + // http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html + + $ParsedArray = []; + $ParsedArray['magic'] = substr($OldRAheaderData, 0, 4); + if ($ParsedArray['magic'] != '.ra'."\xFD") { + return false; + } + $ParsedArray['version1'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 4, 2)); + + if ($ParsedArray['version1'] < 3) { + return false; + } elseif ($ParsedArray['version1'] == 3) { + $ParsedArray['fourcc1'] = '.ra3'; + $ParsedArray['bits_per_sample'] = 16; // hard-coded for old versions? + $ParsedArray['sample_rate'] = 8000; // hard-coded for old versions? + + $ParsedArray['header_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 6, 2)); + $ParsedArray['channels'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 8, 2)); // always 1 (?) + //$ParsedArray['unknown1'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 10, 2)); + //$ParsedArray['unknown2'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 12, 2)); + //$ParsedArray['unknown3'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 14, 2)); + $ParsedArray['bytes_per_minute'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 16, 2)); + $ParsedArray['audio_bytes'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 18, 4)); + $ParsedArray['comments_raw'] = substr($OldRAheaderData, 22, $ParsedArray['header_size'] - 22 + 1); // not including null terminator + + $commentoffset = 0; + $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1)); + $ParsedArray['comments']['title'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength); + $commentoffset += $commentlength; + + $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1)); + $ParsedArray['comments']['artist'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength); + $commentoffset += $commentlength; + + $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1)); + $ParsedArray['comments']['copyright'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength); + $commentoffset += $commentlength; + + $commentoffset++; // final null terminator (?) + $commentoffset++; // fourcc length (?) should be 4 + $ParsedArray['fourcc'] = substr($OldRAheaderData, 23 + $commentoffset, 4); + } elseif ($ParsedArray['version1'] <= 5) { + + //$ParsedArray['unknown1'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 6, 2)); + $ParsedArray['fourcc1'] = substr($OldRAheaderData, 8, 4); + $ParsedArray['file_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 12, 4)); + $ParsedArray['version2'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 16, 2)); + $ParsedArray['header_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 18, 4)); + $ParsedArray['codec_flavor_id'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 22, 2)); + $ParsedArray['coded_frame_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 24, 4)); + $ParsedArray['audio_bytes'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 28, 4)); + $ParsedArray['bytes_per_minute'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 32, 4)); + //$ParsedArray['unknown5'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 36, 4)); + $ParsedArray['sub_packet_h'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 40, 2)); + $ParsedArray['frame_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 42, 2)); + $ParsedArray['sub_packet_size'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 44, 2)); + //$ParsedArray['unknown6'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 46, 2)); + + switch ($ParsedArray['version1']) { + + case 4: + $ParsedArray['sample_rate'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 48, 2)); + //$ParsedArray['unknown8'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 50, 2)); + $ParsedArray['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 52, 2)); + $ParsedArray['channels'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 54, 2)); + $ParsedArray['length_fourcc2'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 56, 1)); + $ParsedArray['fourcc2'] = substr($OldRAheaderData, 57, 4); + $ParsedArray['length_fourcc3'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 61, 1)); + $ParsedArray['fourcc3'] = substr($OldRAheaderData, 62, 4); + //$ParsedArray['unknown9'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 66, 1)); + //$ParsedArray['unknown10'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 67, 2)); + $ParsedArray['comments_raw'] = substr($OldRAheaderData, 69, $ParsedArray['header_size'] - 69 + 16); + + $commentoffset = 0; + $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1)); + $ParsedArray['comments']['title'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength); + $commentoffset += $commentlength; + + $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1)); + $ParsedArray['comments']['artist'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength); + $commentoffset += $commentlength; + + $commentlength = getid3_lib::BigEndian2Int(substr($ParsedArray['comments_raw'], $commentoffset++, 1)); + $ParsedArray['comments']['copyright'][] = substr($ParsedArray['comments_raw'], $commentoffset, $commentlength); + $commentoffset += $commentlength; + break; + + case 5: + $ParsedArray['sample_rate'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 48, 4)); + $ParsedArray['sample_rate2'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 52, 4)); + $ParsedArray['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 56, 4)); + $ParsedArray['channels'] = getid3_lib::BigEndian2Int(substr($OldRAheaderData, 60, 2)); + $ParsedArray['genr'] = substr($OldRAheaderData, 62, 4); + $ParsedArray['fourcc3'] = substr($OldRAheaderData, 66, 4); + $ParsedArray['comments'] = []; + break; + } + $ParsedArray['fourcc'] = $ParsedArray['fourcc3']; + } + foreach ($ParsedArray['comments'] as $key => $value) { + if ($ParsedArray['comments'][$key][0] === false) { + $ParsedArray['comments'][$key][0] = ''; + } + } + + return true; + } + + public function RealAudioCodecFourCClookup($fourcc, $bitrate) + { + static $RealAudioCodecFourCClookup = []; + if (empty($RealAudioCodecFourCClookup)) { + // http://www.its.msstate.edu/net/real/reports/config/tags.stats + // http://www.freelists.org/archives/matroska-devel/06-2003/fullthread18.html + + $RealAudioCodecFourCClookup['14_4'][8000] = 'RealAudio v2 (14.4kbps)'; + $RealAudioCodecFourCClookup['14.4'][8000] = 'RealAudio v2 (14.4kbps)'; + $RealAudioCodecFourCClookup['lpcJ'][8000] = 'RealAudio v2 (14.4kbps)'; + $RealAudioCodecFourCClookup['28_8'][15200] = 'RealAudio v2 (28.8kbps)'; + $RealAudioCodecFourCClookup['28.8'][15200] = 'RealAudio v2 (28.8kbps)'; + $RealAudioCodecFourCClookup['sipr'][4933] = 'RealAudio v4 (5kbps Voice)'; + $RealAudioCodecFourCClookup['sipr'][6444] = 'RealAudio v4 (6.5kbps Voice)'; + $RealAudioCodecFourCClookup['sipr'][8444] = 'RealAudio v4 (8.5kbps Voice)'; + $RealAudioCodecFourCClookup['sipr'][16000] = 'RealAudio v4 (16kbps Wideband)'; + $RealAudioCodecFourCClookup['dnet'][8000] = 'RealAudio v3 (8kbps Music)'; + $RealAudioCodecFourCClookup['dnet'][16000] = 'RealAudio v3 (16kbps Music Low Response)'; + $RealAudioCodecFourCClookup['dnet'][15963] = 'RealAudio v3 (16kbps Music Mid/High Response)'; + $RealAudioCodecFourCClookup['dnet'][20000] = 'RealAudio v3 (20kbps Music Stereo)'; + $RealAudioCodecFourCClookup['dnet'][32000] = 'RealAudio v3 (32kbps Music Mono)'; + $RealAudioCodecFourCClookup['dnet'][31951] = 'RealAudio v3 (32kbps Music Stereo)'; + $RealAudioCodecFourCClookup['dnet'][39965] = 'RealAudio v3 (40kbps Music Mono)'; + $RealAudioCodecFourCClookup['dnet'][40000] = 'RealAudio v3 (40kbps Music Stereo)'; + $RealAudioCodecFourCClookup['dnet'][79947] = 'RealAudio v3 (80kbps Music Mono)'; + $RealAudioCodecFourCClookup['dnet'][80000] = 'RealAudio v3 (80kbps Music Stereo)'; + + $RealAudioCodecFourCClookup['dnet'][0] = 'RealAudio v3'; + $RealAudioCodecFourCClookup['sipr'][0] = 'RealAudio v4'; + $RealAudioCodecFourCClookup['cook'][0] = 'RealAudio G2'; + $RealAudioCodecFourCClookup['atrc'][0] = 'RealAudio 8'; + } + $roundbitrate = intval(round($bitrate)); + if (isset($RealAudioCodecFourCClookup[$fourcc][$roundbitrate])) { + return $RealAudioCodecFourCClookup[$fourcc][$roundbitrate]; + } elseif (isset($RealAudioCodecFourCClookup[$fourcc][0])) { + return $RealAudioCodecFourCClookup[$fourcc][0]; + } + + return $fourcc; + } } diff --git a/app/Library/getid3/getid3/module.audio-video.riff.php b/app/Library/getid3/getid3/module.audio-video.riff.php index f61f28ab..d752763b 100644 --- a/app/Library/getid3/getid3/module.audio-video.riff.php +++ b/app/Library/getid3/getid3/module.audio-video.riff.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -19,2577 +20,2554 @@ ///////////////////////////////////////////////////////////////// /** -* @todo Parse AC-3/DTS audio inside WAVE correctly -* @todo Rewrite RIFF parser totally -*/ - + * @todo Parse AC-3/DTS audio inside WAVE correctly + * @todo Rewrite RIFF parser totally + */ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, true); getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.dts.php', __FILE__, true); -class getid3_riff extends getid3_handler { - - protected $container = 'riff'; // default - - public function Analyze() { - $info = &$this->getid3->info; - - // initialize these values to an empty array, otherwise they default to NULL - // and you can't append array values to a NULL value - $info['riff'] = array('raw'=>array()); - - // Shortcuts - $thisfile_riff = &$info['riff']; - $thisfile_riff_raw = &$thisfile_riff['raw']; - $thisfile_audio = &$info['audio']; - $thisfile_video = &$info['video']; - $thisfile_audio_dataformat = &$thisfile_audio['dataformat']; - $thisfile_riff_audio = &$thisfile_riff['audio']; - $thisfile_riff_video = &$thisfile_riff['video']; - - $Original['avdataoffset'] = $info['avdataoffset']; - $Original['avdataend'] = $info['avdataend']; - - $this->fseek($info['avdataoffset']); - $RIFFheader = $this->fread(12); - $offset = $this->ftell(); - $RIFFtype = substr($RIFFheader, 0, 4); - $RIFFsize = substr($RIFFheader, 4, 4); - $RIFFsubtype = substr($RIFFheader, 8, 4); - - switch ($RIFFtype) { - - case 'FORM': // AIFF, AIFC - //$info['fileformat'] = 'aiff'; - $this->container = 'aiff'; - $thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize); - $thisfile_riff[$RIFFsubtype] = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4)); - break; - - case 'RIFF': // AVI, WAV, etc - case 'SDSS': // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com) - case 'RMP3': // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s - //$info['fileformat'] = 'riff'; - $this->container = 'riff'; - $thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize); - if ($RIFFsubtype == 'RMP3') { - // RMP3 is identical to WAVE, just renamed. Used by [unknown program] when creating RIFF-MP3s - $RIFFsubtype = 'WAVE'; - } - if ($RIFFsubtype != 'AMV ') { - // AMV files are RIFF-AVI files with parts of the spec deliberately broken, such as chunk size fields hardcoded to zero (because players known in hardware that these fields are always a certain size - // Handled separately in ParseRIFFAMV() - $thisfile_riff[$RIFFsubtype] = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4)); - } - if (($info['avdataend'] - $info['filesize']) == 1) { - // LiteWave appears to incorrectly *not* pad actual output file - // to nearest WORD boundary so may appear to be short by one - // byte, in which case - skip warning - $info['avdataend'] = $info['filesize']; - } - - $nextRIFFoffset = $Original['avdataoffset'] + 8 + $thisfile_riff['header_size']; // 8 = "RIFF" + 32-bit offset - while ($nextRIFFoffset < min($info['filesize'], $info['avdataend'])) { - try { - $this->fseek($nextRIFFoffset); - } catch (getid3_exception $e) { - if ($e->getCode() == 10) { - //$this->warning('RIFF parser: '.$e->getMessage()); - $this->error('AVI extends beyond '.round(PHP_INT_MAX / 1073741824).'GB and PHP filesystem functions cannot read that far, playtime may be wrong'); - $this->warning('[avdataend] value may be incorrect, multiple AVIX chunks may be present'); - break; - } else { - throw $e; - } - } - $nextRIFFheader = $this->fread(12); - if ($nextRIFFoffset == ($info['avdataend'] - 1)) { - if (substr($nextRIFFheader, 0, 1) == "\x00") { - // RIFF padded to WORD boundary, we're actually already at the end - break; - } - } - $nextRIFFheaderID = substr($nextRIFFheader, 0, 4); - $nextRIFFsize = $this->EitherEndian2Int(substr($nextRIFFheader, 4, 4)); - $nextRIFFtype = substr($nextRIFFheader, 8, 4); - $chunkdata = array(); - $chunkdata['offset'] = $nextRIFFoffset + 8; - $chunkdata['size'] = $nextRIFFsize; - $nextRIFFoffset = $chunkdata['offset'] + $chunkdata['size']; - - switch ($nextRIFFheaderID) { - case 'RIFF': - $chunkdata['chunks'] = $this->ParseRIFF($chunkdata['offset'] + 4, $nextRIFFoffset); - if (!isset($thisfile_riff[$nextRIFFtype])) { - $thisfile_riff[$nextRIFFtype] = array(); - } - $thisfile_riff[$nextRIFFtype][] = $chunkdata; - break; - - case 'AMV ': - unset($info['riff']); - $info['amv'] = $this->ParseRIFFAMV($chunkdata['offset'] + 4, $nextRIFFoffset); - break; - - case 'JUNK': - // ignore - $thisfile_riff[$nextRIFFheaderID][] = $chunkdata; - break; - - case 'IDVX': - $info['divxtag']['comments'] = self::ParseDIVXTAG($this->fread($chunkdata['size'])); - break; - - default: - if ($info['filesize'] == ($chunkdata['offset'] - 8 + 128)) { - $DIVXTAG = $nextRIFFheader.$this->fread(128 - 12); - if (substr($DIVXTAG, -7) == 'DIVXTAG') { - // DIVXTAG is supposed to be inside an IDVX chunk in a LIST chunk, but some bad encoders just slap it on the end of a file - $this->warning('Found wrongly-structured DIVXTAG at offset '.($this->ftell() - 128).', parsing anyway'); - $info['divxtag']['comments'] = self::ParseDIVXTAG($DIVXTAG); - break 2; - } - } - $this->warning('Expecting "RIFF|JUNK|IDVX" at '.$nextRIFFoffset.', found "'.$nextRIFFheaderID.'" ('.getid3_lib::PrintHexBytes($nextRIFFheaderID).') - skipping rest of file'); - break 2; - - } - - } - if ($RIFFsubtype == 'WAVE') { - $thisfile_riff_WAVE = &$thisfile_riff['WAVE']; - } - break; - - default: - $this->error('Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?) - expecting "FORM|RIFF|SDSS|RMP3" found "'.$RIFFsubtype.'" instead'); - //unset($info['fileformat']); - return false; - } - - $streamindex = 0; - switch ($RIFFsubtype) { - - // http://en.wikipedia.org/wiki/Wav - case 'WAVE': - $info['fileformat'] = 'wav'; - - if (empty($thisfile_audio['bitrate_mode'])) { - $thisfile_audio['bitrate_mode'] = 'cbr'; - } - if (empty($thisfile_audio_dataformat)) { - $thisfile_audio_dataformat = 'wav'; - } - - if (isset($thisfile_riff_WAVE['data'][0]['offset'])) { - $info['avdataoffset'] = $thisfile_riff_WAVE['data'][0]['offset'] + 8; - $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff_WAVE['data'][0]['size']; - } - if (isset($thisfile_riff_WAVE['fmt '][0]['data'])) { - - $thisfile_riff_audio[$streamindex] = self::parseWAVEFORMATex($thisfile_riff_WAVE['fmt '][0]['data']); - $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag']; - if (!isset($thisfile_riff_audio[$streamindex]['bitrate']) || ($thisfile_riff_audio[$streamindex]['bitrate'] == 0)) { - $this->error('Corrupt RIFF file: bitrate_audio == zero'); - return false; - } - $thisfile_riff_raw['fmt '] = $thisfile_riff_audio[$streamindex]['raw']; - unset($thisfile_riff_audio[$streamindex]['raw']); - $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex]; - - $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]); - if (substr($thisfile_audio['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') { - $this->warning('Audio codec = '.$thisfile_audio['codec']); - } - $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate']; - - if (empty($info['playtime_seconds'])) { // may already be set (e.g. DTS-WAV) - $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']); - } - - $thisfile_audio['lossless'] = false; - if (isset($thisfile_riff_WAVE['data'][0]['offset']) && isset($thisfile_riff_raw['fmt ']['wFormatTag'])) { - switch ($thisfile_riff_raw['fmt ']['wFormatTag']) { - - case 0x0001: // PCM - $thisfile_audio['lossless'] = true; - break; - - case 0x2000: // AC-3 - $thisfile_audio_dataformat = 'ac3'; - break; - - default: - // do nothing - break; - - } - } - $thisfile_audio['streams'][$streamindex]['wformattag'] = $thisfile_audio['wformattag']; - $thisfile_audio['streams'][$streamindex]['bitrate_mode'] = $thisfile_audio['bitrate_mode']; - $thisfile_audio['streams'][$streamindex]['lossless'] = $thisfile_audio['lossless']; - $thisfile_audio['streams'][$streamindex]['dataformat'] = $thisfile_audio_dataformat; - } - - if (isset($thisfile_riff_WAVE['rgad'][0]['data'])) { - - // shortcuts - $rgadData = &$thisfile_riff_WAVE['rgad'][0]['data']; - $thisfile_riff_raw['rgad'] = array('track'=>array(), 'album'=>array()); - $thisfile_riff_raw_rgad = &$thisfile_riff_raw['rgad']; - $thisfile_riff_raw_rgad_track = &$thisfile_riff_raw_rgad['track']; - $thisfile_riff_raw_rgad_album = &$thisfile_riff_raw_rgad['album']; - - $thisfile_riff_raw_rgad['fPeakAmplitude'] = getid3_lib::LittleEndian2Float(substr($rgadData, 0, 4)); - $thisfile_riff_raw_rgad['nRadioRgAdjust'] = $this->EitherEndian2Int(substr($rgadData, 4, 2)); - $thisfile_riff_raw_rgad['nAudiophileRgAdjust'] = $this->EitherEndian2Int(substr($rgadData, 6, 2)); - - $nRadioRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT); - $nAudiophileRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT); - $thisfile_riff_raw_rgad_track['name'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3)); - $thisfile_riff_raw_rgad_track['originator'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3)); - $thisfile_riff_raw_rgad_track['signbit'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1)); - $thisfile_riff_raw_rgad_track['adjustment'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9)); - $thisfile_riff_raw_rgad_album['name'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3)); - $thisfile_riff_raw_rgad_album['originator'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3)); - $thisfile_riff_raw_rgad_album['signbit'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1)); - $thisfile_riff_raw_rgad_album['adjustment'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9)); - - $thisfile_riff['rgad']['peakamplitude'] = $thisfile_riff_raw_rgad['fPeakAmplitude']; - if (($thisfile_riff_raw_rgad_track['name'] != 0) && ($thisfile_riff_raw_rgad_track['originator'] != 0)) { - $thisfile_riff['rgad']['track']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_track['name']); - $thisfile_riff['rgad']['track']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_track['originator']); - $thisfile_riff['rgad']['track']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_track['adjustment'], $thisfile_riff_raw_rgad_track['signbit']); - } - if (($thisfile_riff_raw_rgad_album['name'] != 0) && ($thisfile_riff_raw_rgad_album['originator'] != 0)) { - $thisfile_riff['rgad']['album']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_album['name']); - $thisfile_riff['rgad']['album']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_album['originator']); - $thisfile_riff['rgad']['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_album['adjustment'], $thisfile_riff_raw_rgad_album['signbit']); - } - } - - if (isset($thisfile_riff_WAVE['fact'][0]['data'])) { - $thisfile_riff_raw['fact']['NumberOfSamples'] = $this->EitherEndian2Int(substr($thisfile_riff_WAVE['fact'][0]['data'], 0, 4)); - - // This should be a good way of calculating exact playtime, - // but some sample files have had incorrect number of samples, - // so cannot use this method - - // if (!empty($thisfile_riff_raw['fmt ']['nSamplesPerSec'])) { - // $info['playtime_seconds'] = (float) $thisfile_riff_raw['fact']['NumberOfSamples'] / $thisfile_riff_raw['fmt ']['nSamplesPerSec']; - // } - } - if (!empty($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'])) { - $thisfile_audio['bitrate'] = getid3_lib::CastAsInt($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'] * 8); - } - - if (isset($thisfile_riff_WAVE['bext'][0]['data'])) { - // shortcut - $thisfile_riff_WAVE_bext_0 = &$thisfile_riff_WAVE['bext'][0]; - - $thisfile_riff_WAVE_bext_0['title'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 0, 256)); - $thisfile_riff_WAVE_bext_0['author'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 256, 32)); - $thisfile_riff_WAVE_bext_0['reference'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 288, 32)); - $thisfile_riff_WAVE_bext_0['origin_date'] = substr($thisfile_riff_WAVE_bext_0['data'], 320, 10); - $thisfile_riff_WAVE_bext_0['origin_time'] = substr($thisfile_riff_WAVE_bext_0['data'], 330, 8); - $thisfile_riff_WAVE_bext_0['time_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 338, 8)); - $thisfile_riff_WAVE_bext_0['bwf_version'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 346, 1)); - $thisfile_riff_WAVE_bext_0['reserved'] = substr($thisfile_riff_WAVE_bext_0['data'], 347, 254); - $thisfile_riff_WAVE_bext_0['coding_history'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_bext_0['data'], 601))); - if (preg_match('#^([0-9]{4}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_date'], $matches_bext_date)) { - if (preg_match('#^([0-9]{2}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_time'], $matches_bext_time)) { - list($dummy, $bext_timestamp['year'], $bext_timestamp['month'], $bext_timestamp['day']) = $matches_bext_date; - list($dummy, $bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second']) = $matches_bext_time; - $thisfile_riff_WAVE_bext_0['origin_date_unix'] = gmmktime($bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second'], $bext_timestamp['month'], $bext_timestamp['day'], $bext_timestamp['year']); - } else { - $this->warning('RIFF.WAVE.BEXT.origin_time is invalid'); - } - } else { - $this->warning('RIFF.WAVE.BEXT.origin_date is invalid'); - } - $thisfile_riff['comments']['author'][] = $thisfile_riff_WAVE_bext_0['author']; - $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_bext_0['title']; - } - - if (isset($thisfile_riff_WAVE['MEXT'][0]['data'])) { - // shortcut - $thisfile_riff_WAVE_MEXT_0 = &$thisfile_riff_WAVE['MEXT'][0]; - - $thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 0, 2)); - $thisfile_riff_WAVE_MEXT_0['flags']['homogenous'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0001); - if ($thisfile_riff_WAVE_MEXT_0['flags']['homogenous']) { - $thisfile_riff_WAVE_MEXT_0['flags']['padding'] = ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0002) ? false : true; - $thisfile_riff_WAVE_MEXT_0['flags']['22_or_44'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0004); - $thisfile_riff_WAVE_MEXT_0['flags']['free_format'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0008); - - $thisfile_riff_WAVE_MEXT_0['nominal_frame_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 2, 2)); - } - $thisfile_riff_WAVE_MEXT_0['anciliary_data_length'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 6, 2)); - $thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 8, 2)); - $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_left'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0001); - $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_free'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0002); - $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_right'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0004); - } - - if (isset($thisfile_riff_WAVE['cart'][0]['data'])) { - // shortcut - $thisfile_riff_WAVE_cart_0 = &$thisfile_riff_WAVE['cart'][0]; - - $thisfile_riff_WAVE_cart_0['version'] = substr($thisfile_riff_WAVE_cart_0['data'], 0, 4); - $thisfile_riff_WAVE_cart_0['title'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 4, 64)); - $thisfile_riff_WAVE_cart_0['artist'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 68, 64)); - $thisfile_riff_WAVE_cart_0['cut_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 132, 64)); - $thisfile_riff_WAVE_cart_0['client_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 196, 64)); - $thisfile_riff_WAVE_cart_0['category'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 260, 64)); - $thisfile_riff_WAVE_cart_0['classification'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 324, 64)); - $thisfile_riff_WAVE_cart_0['out_cue'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 388, 64)); - $thisfile_riff_WAVE_cart_0['start_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 452, 10)); - $thisfile_riff_WAVE_cart_0['start_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 462, 8)); - $thisfile_riff_WAVE_cart_0['end_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 470, 10)); - $thisfile_riff_WAVE_cart_0['end_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 480, 8)); - $thisfile_riff_WAVE_cart_0['producer_app_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 488, 64)); - $thisfile_riff_WAVE_cart_0['producer_app_version'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 552, 64)); - $thisfile_riff_WAVE_cart_0['user_defined_text'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 616, 64)); - $thisfile_riff_WAVE_cart_0['zero_db_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 680, 4), true); - for ($i = 0; $i < 8; $i++) { - $thisfile_riff_WAVE_cart_0['post_time'][$i]['usage_fourcc'] = substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8), 4); - $thisfile_riff_WAVE_cart_0['post_time'][$i]['timer_value'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8) + 4, 4)); - } - $thisfile_riff_WAVE_cart_0['url'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 748, 1024)); - $thisfile_riff_WAVE_cart_0['tag_text'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_cart_0['data'], 1772))); - - $thisfile_riff['comments']['artist'][] = $thisfile_riff_WAVE_cart_0['artist']; - $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_cart_0['title']; - } - - if (isset($thisfile_riff_WAVE['SNDM'][0]['data'])) { - // SoundMiner metadata - - // shortcuts - $thisfile_riff_WAVE_SNDM_0 = &$thisfile_riff_WAVE['SNDM'][0]; - $thisfile_riff_WAVE_SNDM_0_data = &$thisfile_riff_WAVE_SNDM_0['data']; - $SNDM_startoffset = 0; - $SNDM_endoffset = $thisfile_riff_WAVE_SNDM_0['size']; - - while ($SNDM_startoffset < $SNDM_endoffset) { - $SNDM_thisTagOffset = 0; - $SNDM_thisTagSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4)); - $SNDM_thisTagOffset += 4; - $SNDM_thisTagKey = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4); - $SNDM_thisTagOffset += 4; - $SNDM_thisTagDataSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2)); - $SNDM_thisTagOffset += 2; - $SNDM_thisTagDataFlags = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2)); - $SNDM_thisTagOffset += 2; - $SNDM_thisTagDataText = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, $SNDM_thisTagDataSize); - $SNDM_thisTagOffset += $SNDM_thisTagDataSize; - - if ($SNDM_thisTagSize != (4 + 4 + 2 + 2 + $SNDM_thisTagDataSize)) { - $this->warning('RIFF.WAVE.SNDM.data contains tag not expected length (expected: '.$SNDM_thisTagSize.', found: '.(4 + 4 + 2 + 2 + $SNDM_thisTagDataSize).') at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')'); - break; - } elseif ($SNDM_thisTagSize <= 0) { - $this->warning('RIFF.WAVE.SNDM.data contains zero-size tag at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')'); - break; - } - $SNDM_startoffset += $SNDM_thisTagSize; - - $thisfile_riff_WAVE_SNDM_0['parsed_raw'][$SNDM_thisTagKey] = $SNDM_thisTagDataText; - if ($parsedkey = self::waveSNDMtagLookup($SNDM_thisTagKey)) { - $thisfile_riff_WAVE_SNDM_0['parsed'][$parsedkey] = $SNDM_thisTagDataText; - } else { - $this->warning('RIFF.WAVE.SNDM contains unknown tag "'.$SNDM_thisTagKey.'" at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')'); - } - } - - $tagmapping = array( - 'tracktitle'=>'title', - 'category' =>'genre', - 'cdtitle' =>'album', - 'tracktitle'=>'title', - ); - foreach ($tagmapping as $fromkey => $tokey) { - if (isset($thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey])) { - $thisfile_riff['comments'][$tokey][] = $thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey]; - } - } - } - - if (isset($thisfile_riff_WAVE['iXML'][0]['data'])) { - // requires functions simplexml_load_string and get_object_vars - if ($parsedXML = getid3_lib::XML2array($thisfile_riff_WAVE['iXML'][0]['data'])) { - $thisfile_riff_WAVE['iXML'][0]['parsed'] = $parsedXML; - if (isset($parsedXML['SPEED']['MASTER_SPEED'])) { - @list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['MASTER_SPEED']); - $thisfile_riff_WAVE['iXML'][0]['master_speed'] = $numerator / ($denominator ? $denominator : 1000); - } - if (isset($parsedXML['SPEED']['TIMECODE_RATE'])) { - @list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['TIMECODE_RATE']); - $thisfile_riff_WAVE['iXML'][0]['timecode_rate'] = $numerator / ($denominator ? $denominator : 1000); - } - if (isset($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO']) && !empty($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) && !empty($thisfile_riff_WAVE['iXML'][0]['timecode_rate'])) { - $samples_since_midnight = floatval(ltrim($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_HI'].$parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO'], '0')); - $timestamp_sample_rate = (is_array($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) ? max($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) : $parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']); // XML could possibly contain more than one TIMESTAMP_SAMPLE_RATE tag, returning as array instead of integer [why? does it make sense? perhaps doesn't matter but getID3 needs to deal with it] - see https://github.com/JamesHeinrich/getID3/issues/105 - $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] = $samples_since_midnight / $timestamp_sample_rate; - $h = floor( $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] / 3600); - $m = floor(($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600)) / 60); - $s = floor( $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60)); - $f = ($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60) - $s) * $thisfile_riff_WAVE['iXML'][0]['timecode_rate']; - $thisfile_riff_WAVE['iXML'][0]['timecode_string'] = sprintf('%02d:%02d:%02d:%05.2f', $h, $m, $s, $f); - $thisfile_riff_WAVE['iXML'][0]['timecode_string_round'] = sprintf('%02d:%02d:%02d:%02d', $h, $m, $s, round($f)); - unset($samples_since_midnight, $timestamp_sample_rate, $h, $m, $s, $f); - } - unset($parsedXML); - } - } - - - - if (!isset($thisfile_audio['bitrate']) && isset($thisfile_riff_audio[$streamindex]['bitrate'])) { - $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate']; - $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']); - } - - if (!empty($info['wavpack'])) { - $thisfile_audio_dataformat = 'wavpack'; - $thisfile_audio['bitrate_mode'] = 'vbr'; - $thisfile_audio['encoder'] = 'WavPack v'.$info['wavpack']['version']; - - // Reset to the way it was - RIFF parsing will have messed this up - $info['avdataend'] = $Original['avdataend']; - $thisfile_audio['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; - - $this->fseek($info['avdataoffset'] - 44); - $RIFFdata = $this->fread(44); - $OrignalRIFFheaderSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 4, 4)) + 8; - $OrignalRIFFdataSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44; - - if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) { - $info['avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize); - $this->fseek($info['avdataend']); - $RIFFdata .= $this->fread($OrignalRIFFheaderSize - $OrignalRIFFdataSize); - } - - // move the data chunk after all other chunks (if any) - // so that the RIFF parser doesn't see EOF when trying - // to skip over the data chunk - $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8); - $getid3_riff = new getid3_riff($this->getid3); - $getid3_riff->ParseRIFFdata($RIFFdata); - unset($getid3_riff); - } - - if (isset($thisfile_riff_raw['fmt ']['wFormatTag'])) { - switch ($thisfile_riff_raw['fmt ']['wFormatTag']) { - case 0x0001: // PCM - if (!empty($info['ac3'])) { - // Dolby Digital WAV files masquerade as PCM-WAV, but they're not - $thisfile_audio['wformattag'] = 0x2000; - $thisfile_audio['codec'] = self::wFormatTagLookup($thisfile_audio['wformattag']); - $thisfile_audio['lossless'] = false; - $thisfile_audio['bitrate'] = $info['ac3']['bitrate']; - $thisfile_audio['sample_rate'] = $info['ac3']['sample_rate']; - } - if (!empty($info['dts'])) { - // Dolby DTS files masquerade as PCM-WAV, but they're not - $thisfile_audio['wformattag'] = 0x2001; - $thisfile_audio['codec'] = self::wFormatTagLookup($thisfile_audio['wformattag']); - $thisfile_audio['lossless'] = false; - $thisfile_audio['bitrate'] = $info['dts']['bitrate']; - $thisfile_audio['sample_rate'] = $info['dts']['sample_rate']; - } - break; - case 0x08AE: // ClearJump LiteWave - $thisfile_audio['bitrate_mode'] = 'vbr'; - $thisfile_audio_dataformat = 'litewave'; - - //typedef struct tagSLwFormat { - // WORD m_wCompFormat; // low byte defines compression method, high byte is compression flags - // DWORD m_dwScale; // scale factor for lossy compression - // DWORD m_dwBlockSize; // number of samples in encoded blocks - // WORD m_wQuality; // alias for the scale factor - // WORD m_wMarkDistance; // distance between marks in bytes - // WORD m_wReserved; - // - // //following paramters are ignored if CF_FILESRC is not set - // DWORD m_dwOrgSize; // original file size in bytes - // WORD m_bFactExists; // indicates if 'fact' chunk exists in the original file - // DWORD m_dwRiffChunkSize; // riff chunk size in the original file - // - // PCMWAVEFORMAT m_OrgWf; // original wave format - // }SLwFormat, *PSLwFormat; - - // shortcut - $thisfile_riff['litewave']['raw'] = array(); - $riff_litewave = &$thisfile_riff['litewave']; - $riff_litewave_raw = &$riff_litewave['raw']; - - $flags = array( - 'compression_method' => 1, - 'compression_flags' => 1, - 'm_dwScale' => 4, - 'm_dwBlockSize' => 4, - 'm_wQuality' => 2, - 'm_wMarkDistance' => 2, - 'm_wReserved' => 2, - 'm_dwOrgSize' => 4, - 'm_bFactExists' => 2, - 'm_dwRiffChunkSize' => 4, - ); - $litewave_offset = 18; - foreach ($flags as $flag => $length) { - $riff_litewave_raw[$flag] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], $litewave_offset, $length)); - $litewave_offset += $length; - } - - //$riff_litewave['quality_factor'] = intval(round((2000 - $riff_litewave_raw['m_dwScale']) / 20)); - $riff_litewave['quality_factor'] = $riff_litewave_raw['m_wQuality']; - - $riff_litewave['flags']['raw_source'] = ($riff_litewave_raw['compression_flags'] & 0x01) ? false : true; - $riff_litewave['flags']['vbr_blocksize'] = ($riff_litewave_raw['compression_flags'] & 0x02) ? false : true; - $riff_litewave['flags']['seekpoints'] = (bool) ($riff_litewave_raw['compression_flags'] & 0x04); - - $thisfile_audio['lossless'] = (($riff_litewave_raw['m_wQuality'] == 100) ? true : false); - $thisfile_audio['encoder_options'] = '-q'.$riff_litewave['quality_factor']; - break; - - default: - break; - } - } - if ($info['avdataend'] > $info['filesize']) { - switch (!empty($thisfile_audio_dataformat) ? $thisfile_audio_dataformat : '') { - case 'wavpack': // WavPack - case 'lpac': // LPAC - case 'ofr': // OptimFROG - case 'ofs': // OptimFROG DualStream - // lossless compressed audio formats that keep original RIFF headers - skip warning - break; - - case 'litewave': - if (($info['avdataend'] - $info['filesize']) == 1) { - // LiteWave appears to incorrectly *not* pad actual output file - // to nearest WORD boundary so may appear to be short by one - // byte, in which case - skip warning - } else { - // Short by more than one byte, throw warning - $this->warning('Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)'); - $info['avdataend'] = $info['filesize']; - } - break; - - default: - if ((($info['avdataend'] - $info['filesize']) == 1) && (($thisfile_riff[$RIFFsubtype]['data'][0]['size'] % 2) == 0) && ((($info['filesize'] - $info['avdataoffset']) % 2) == 1)) { - // output file appears to be incorrectly *not* padded to nearest WORD boundary - // Output less severe warning - $this->warning('File should probably be padded to nearest WORD boundary, but it is not (expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' therefore short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)'); - $info['avdataend'] = $info['filesize']; - } else { - // Short by more than one byte, throw warning - $this->warning('Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)'); - $info['avdataend'] = $info['filesize']; - } - break; - } - } - if (!empty($info['mpeg']['audio']['LAME']['audio_bytes'])) { - if ((($info['avdataend'] - $info['avdataoffset']) - $info['mpeg']['audio']['LAME']['audio_bytes']) == 1) { - $info['avdataend']--; - $this->warning('Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored'); - } - } - if (isset($thisfile_audio_dataformat) && ($thisfile_audio_dataformat == 'ac3')) { - unset($thisfile_audio['bits_per_sample']); - if (!empty($info['ac3']['bitrate']) && ($info['ac3']['bitrate'] != $thisfile_audio['bitrate'])) { - $thisfile_audio['bitrate'] = $info['ac3']['bitrate']; - } - } - break; - - // http://en.wikipedia.org/wiki/Audio_Video_Interleave - case 'AVI ': - $info['fileformat'] = 'avi'; - $info['mime_type'] = 'video/avi'; - - $thisfile_video['bitrate_mode'] = 'vbr'; // maybe not, but probably - $thisfile_video['dataformat'] = 'avi'; - - if (isset($thisfile_riff[$RIFFsubtype]['movi']['offset'])) { - $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['movi']['offset'] + 8; - if (isset($thisfile_riff['AVIX'])) { - $info['avdataend'] = $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['offset'] + $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['size']; - } else { - $info['avdataend'] = $thisfile_riff['AVI ']['movi']['offset'] + $thisfile_riff['AVI ']['movi']['size']; - } - if ($info['avdataend'] > $info['filesize']) { - $this->warning('Probably truncated file - expecting '.($info['avdataend'] - $info['avdataoffset']).' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($info['avdataend'] - $info['filesize']).' bytes)'); - $info['avdataend'] = $info['filesize']; - } - } - - if (isset($thisfile_riff['AVI ']['hdrl']['strl']['indx'])) { - //$bIndexType = array( - // 0x00 => 'AVI_INDEX_OF_INDEXES', - // 0x01 => 'AVI_INDEX_OF_CHUNKS', - // 0x80 => 'AVI_INDEX_IS_DATA', - //); - //$bIndexSubtype = array( - // 0x01 => array( - // 0x01 => 'AVI_INDEX_2FIELD', - // ), - //); - foreach ($thisfile_riff['AVI ']['hdrl']['strl']['indx'] as $streamnumber => $steamdataarray) { - $ahsisd = &$thisfile_riff['AVI ']['hdrl']['strl']['indx'][$streamnumber]['data']; - - $thisfile_riff_raw['indx'][$streamnumber]['wLongsPerEntry'] = $this->EitherEndian2Int(substr($ahsisd, 0, 2)); - $thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType'] = $this->EitherEndian2Int(substr($ahsisd, 2, 1)); - $thisfile_riff_raw['indx'][$streamnumber]['bIndexType'] = $this->EitherEndian2Int(substr($ahsisd, 3, 1)); - $thisfile_riff_raw['indx'][$streamnumber]['nEntriesInUse'] = $this->EitherEndian2Int(substr($ahsisd, 4, 4)); - $thisfile_riff_raw['indx'][$streamnumber]['dwChunkId'] = substr($ahsisd, 8, 4); - $thisfile_riff_raw['indx'][$streamnumber]['dwReserved'] = $this->EitherEndian2Int(substr($ahsisd, 12, 4)); - - //$thisfile_riff_raw['indx'][$streamnumber]['bIndexType_name'] = $bIndexType[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']]; - //$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType_name'] = $bIndexSubtype[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']][$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType']]; - - unset($ahsisd); - } - } - if (isset($thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'])) { - $avihData = $thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data']; - - // shortcut - $thisfile_riff_raw['avih'] = array(); - $thisfile_riff_raw_avih = &$thisfile_riff_raw['avih']; - - $thisfile_riff_raw_avih['dwMicroSecPerFrame'] = $this->EitherEndian2Int(substr($avihData, 0, 4)); // frame display rate (or 0L) - if ($thisfile_riff_raw_avih['dwMicroSecPerFrame'] == 0) { - $this->error('Corrupt RIFF file: avih.dwMicroSecPerFrame == zero'); - return false; - } - - $flags = array( - 'dwMaxBytesPerSec', // max. transfer rate - 'dwPaddingGranularity', // pad to multiples of this size; normally 2K. - 'dwFlags', // the ever-present flags - 'dwTotalFrames', // # frames in file - 'dwInitialFrames', // - 'dwStreams', // - 'dwSuggestedBufferSize', // - 'dwWidth', // - 'dwHeight', // - 'dwScale', // - 'dwRate', // - 'dwStart', // - 'dwLength', // - ); - $avih_offset = 4; - foreach ($flags as $flag) { - $thisfile_riff_raw_avih[$flag] = $this->EitherEndian2Int(substr($avihData, $avih_offset, 4)); - $avih_offset += 4; - } - - $flags = array( - 'hasindex' => 0x00000010, - 'mustuseindex' => 0x00000020, - 'interleaved' => 0x00000100, - 'trustcktype' => 0x00000800, - 'capturedfile' => 0x00010000, - 'copyrighted' => 0x00020010, - ); +class getid3_riff extends getid3_handler +{ + protected $container = 'riff'; // default + + public function Analyze() + { + $info = &$this->getid3->info; + + // initialize these values to an empty array, otherwise they default to NULL + // and you can't append array values to a NULL value + $info['riff'] = ['raw'=>[]]; + + // Shortcuts + $thisfile_riff = &$info['riff']; + $thisfile_riff_raw = &$thisfile_riff['raw']; + $thisfile_audio = &$info['audio']; + $thisfile_video = &$info['video']; + $thisfile_audio_dataformat = &$thisfile_audio['dataformat']; + $thisfile_riff_audio = &$thisfile_riff['audio']; + $thisfile_riff_video = &$thisfile_riff['video']; + + $Original['avdataoffset'] = $info['avdataoffset']; + $Original['avdataend'] = $info['avdataend']; + + $this->fseek($info['avdataoffset']); + $RIFFheader = $this->fread(12); + $offset = $this->ftell(); + $RIFFtype = substr($RIFFheader, 0, 4); + $RIFFsize = substr($RIFFheader, 4, 4); + $RIFFsubtype = substr($RIFFheader, 8, 4); + + switch ($RIFFtype) { + + case 'FORM': // AIFF, AIFC + //$info['fileformat'] = 'aiff'; + $this->container = 'aiff'; + $thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize); + $thisfile_riff[$RIFFsubtype] = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4)); + break; + + case 'RIFF': // AVI, WAV, etc + case 'SDSS': // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com) + case 'RMP3': // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s + //$info['fileformat'] = 'riff'; + $this->container = 'riff'; + $thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize); + if ($RIFFsubtype == 'RMP3') { + // RMP3 is identical to WAVE, just renamed. Used by [unknown program] when creating RIFF-MP3s + $RIFFsubtype = 'WAVE'; + } + if ($RIFFsubtype != 'AMV ') { + // AMV files are RIFF-AVI files with parts of the spec deliberately broken, such as chunk size fields hardcoded to zero (because players known in hardware that these fields are always a certain size + // Handled separately in ParseRIFFAMV() + $thisfile_riff[$RIFFsubtype] = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4)); + } + if (($info['avdataend'] - $info['filesize']) == 1) { + // LiteWave appears to incorrectly *not* pad actual output file + // to nearest WORD boundary so may appear to be short by one + // byte, in which case - skip warning + $info['avdataend'] = $info['filesize']; + } + + $nextRIFFoffset = $Original['avdataoffset'] + 8 + $thisfile_riff['header_size']; // 8 = "RIFF" + 32-bit offset + while ($nextRIFFoffset < min($info['filesize'], $info['avdataend'])) { + try { + $this->fseek($nextRIFFoffset); + } catch (getid3_exception $e) { + if ($e->getCode() == 10) { + //$this->warning('RIFF parser: '.$e->getMessage()); + $this->error('AVI extends beyond '.round(PHP_INT_MAX / 1073741824).'GB and PHP filesystem functions cannot read that far, playtime may be wrong'); + $this->warning('[avdataend] value may be incorrect, multiple AVIX chunks may be present'); + break; + } else { + throw $e; + } + } + $nextRIFFheader = $this->fread(12); + if ($nextRIFFoffset == ($info['avdataend'] - 1)) { + if (substr($nextRIFFheader, 0, 1) == "\x00") { + // RIFF padded to WORD boundary, we're actually already at the end + break; + } + } + $nextRIFFheaderID = substr($nextRIFFheader, 0, 4); + $nextRIFFsize = $this->EitherEndian2Int(substr($nextRIFFheader, 4, 4)); + $nextRIFFtype = substr($nextRIFFheader, 8, 4); + $chunkdata = []; + $chunkdata['offset'] = $nextRIFFoffset + 8; + $chunkdata['size'] = $nextRIFFsize; + $nextRIFFoffset = $chunkdata['offset'] + $chunkdata['size']; + + switch ($nextRIFFheaderID) { + case 'RIFF': + $chunkdata['chunks'] = $this->ParseRIFF($chunkdata['offset'] + 4, $nextRIFFoffset); + if (! isset($thisfile_riff[$nextRIFFtype])) { + $thisfile_riff[$nextRIFFtype] = []; + } + $thisfile_riff[$nextRIFFtype][] = $chunkdata; + break; + + case 'AMV ': + unset($info['riff']); + $info['amv'] = $this->ParseRIFFAMV($chunkdata['offset'] + 4, $nextRIFFoffset); + break; + + case 'JUNK': + // ignore + $thisfile_riff[$nextRIFFheaderID][] = $chunkdata; + break; + + case 'IDVX': + $info['divxtag']['comments'] = self::ParseDIVXTAG($this->fread($chunkdata['size'])); + break; + + default: + if ($info['filesize'] == ($chunkdata['offset'] - 8 + 128)) { + $DIVXTAG = $nextRIFFheader.$this->fread(128 - 12); + if (substr($DIVXTAG, -7) == 'DIVXTAG') { + // DIVXTAG is supposed to be inside an IDVX chunk in a LIST chunk, but some bad encoders just slap it on the end of a file + $this->warning('Found wrongly-structured DIVXTAG at offset '.($this->ftell() - 128).', parsing anyway'); + $info['divxtag']['comments'] = self::ParseDIVXTAG($DIVXTAG); + break 2; + } + } + $this->warning('Expecting "RIFF|JUNK|IDVX" at '.$nextRIFFoffset.', found "'.$nextRIFFheaderID.'" ('.getid3_lib::PrintHexBytes($nextRIFFheaderID).') - skipping rest of file'); + break 2; + + } + } + if ($RIFFsubtype == 'WAVE') { + $thisfile_riff_WAVE = &$thisfile_riff['WAVE']; + } + break; + + default: + $this->error('Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?) - expecting "FORM|RIFF|SDSS|RMP3" found "'.$RIFFsubtype.'" instead'); + //unset($info['fileformat']); + return false; + } + + $streamindex = 0; + switch ($RIFFsubtype) { + + // http://en.wikipedia.org/wiki/Wav + case 'WAVE': + $info['fileformat'] = 'wav'; + + if (empty($thisfile_audio['bitrate_mode'])) { + $thisfile_audio['bitrate_mode'] = 'cbr'; + } + if (empty($thisfile_audio_dataformat)) { + $thisfile_audio_dataformat = 'wav'; + } + + if (isset($thisfile_riff_WAVE['data'][0]['offset'])) { + $info['avdataoffset'] = $thisfile_riff_WAVE['data'][0]['offset'] + 8; + $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff_WAVE['data'][0]['size']; + } + if (isset($thisfile_riff_WAVE['fmt '][0]['data'])) { + $thisfile_riff_audio[$streamindex] = self::parseWAVEFORMATex($thisfile_riff_WAVE['fmt '][0]['data']); + $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag']; + if (! isset($thisfile_riff_audio[$streamindex]['bitrate']) || ($thisfile_riff_audio[$streamindex]['bitrate'] == 0)) { + $this->error('Corrupt RIFF file: bitrate_audio == zero'); + + return false; + } + $thisfile_riff_raw['fmt '] = $thisfile_riff_audio[$streamindex]['raw']; + unset($thisfile_riff_audio[$streamindex]['raw']); + $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex]; + + $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]); + if (substr($thisfile_audio['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') { + $this->warning('Audio codec = '.$thisfile_audio['codec']); + } + $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate']; + + if (empty($info['playtime_seconds'])) { // may already be set (e.g. DTS-WAV) + $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']); + } + + $thisfile_audio['lossless'] = false; + if (isset($thisfile_riff_WAVE['data'][0]['offset']) && isset($thisfile_riff_raw['fmt ']['wFormatTag'])) { + switch ($thisfile_riff_raw['fmt ']['wFormatTag']) { + + case 0x0001: // PCM + $thisfile_audio['lossless'] = true; + break; + + case 0x2000: // AC-3 + $thisfile_audio_dataformat = 'ac3'; + break; + + default: + // do nothing + break; + + } + } + $thisfile_audio['streams'][$streamindex]['wformattag'] = $thisfile_audio['wformattag']; + $thisfile_audio['streams'][$streamindex]['bitrate_mode'] = $thisfile_audio['bitrate_mode']; + $thisfile_audio['streams'][$streamindex]['lossless'] = $thisfile_audio['lossless']; + $thisfile_audio['streams'][$streamindex]['dataformat'] = $thisfile_audio_dataformat; + } + + if (isset($thisfile_riff_WAVE['rgad'][0]['data'])) { + + // shortcuts + $rgadData = &$thisfile_riff_WAVE['rgad'][0]['data']; + $thisfile_riff_raw['rgad'] = ['track'=>[], 'album'=>[]]; + $thisfile_riff_raw_rgad = &$thisfile_riff_raw['rgad']; + $thisfile_riff_raw_rgad_track = &$thisfile_riff_raw_rgad['track']; + $thisfile_riff_raw_rgad_album = &$thisfile_riff_raw_rgad['album']; + + $thisfile_riff_raw_rgad['fPeakAmplitude'] = getid3_lib::LittleEndian2Float(substr($rgadData, 0, 4)); + $thisfile_riff_raw_rgad['nRadioRgAdjust'] = $this->EitherEndian2Int(substr($rgadData, 4, 2)); + $thisfile_riff_raw_rgad['nAudiophileRgAdjust'] = $this->EitherEndian2Int(substr($rgadData, 6, 2)); + + $nRadioRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT); + $nAudiophileRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT); + $thisfile_riff_raw_rgad_track['name'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3)); + $thisfile_riff_raw_rgad_track['originator'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3)); + $thisfile_riff_raw_rgad_track['signbit'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1)); + $thisfile_riff_raw_rgad_track['adjustment'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9)); + $thisfile_riff_raw_rgad_album['name'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3)); + $thisfile_riff_raw_rgad_album['originator'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3)); + $thisfile_riff_raw_rgad_album['signbit'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1)); + $thisfile_riff_raw_rgad_album['adjustment'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9)); + + $thisfile_riff['rgad']['peakamplitude'] = $thisfile_riff_raw_rgad['fPeakAmplitude']; + if (($thisfile_riff_raw_rgad_track['name'] != 0) && ($thisfile_riff_raw_rgad_track['originator'] != 0)) { + $thisfile_riff['rgad']['track']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_track['name']); + $thisfile_riff['rgad']['track']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_track['originator']); + $thisfile_riff['rgad']['track']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_track['adjustment'], $thisfile_riff_raw_rgad_track['signbit']); + } + if (($thisfile_riff_raw_rgad_album['name'] != 0) && ($thisfile_riff_raw_rgad_album['originator'] != 0)) { + $thisfile_riff['rgad']['album']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_album['name']); + $thisfile_riff['rgad']['album']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_album['originator']); + $thisfile_riff['rgad']['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_album['adjustment'], $thisfile_riff_raw_rgad_album['signbit']); + } + } + + if (isset($thisfile_riff_WAVE['fact'][0]['data'])) { + $thisfile_riff_raw['fact']['NumberOfSamples'] = $this->EitherEndian2Int(substr($thisfile_riff_WAVE['fact'][0]['data'], 0, 4)); + + // This should be a good way of calculating exact playtime, + // but some sample files have had incorrect number of samples, + // so cannot use this method + + // if (!empty($thisfile_riff_raw['fmt ']['nSamplesPerSec'])) { + // $info['playtime_seconds'] = (float) $thisfile_riff_raw['fact']['NumberOfSamples'] / $thisfile_riff_raw['fmt ']['nSamplesPerSec']; + // } + } + if (! empty($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'])) { + $thisfile_audio['bitrate'] = getid3_lib::CastAsInt($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'] * 8); + } + + if (isset($thisfile_riff_WAVE['bext'][0]['data'])) { + // shortcut + $thisfile_riff_WAVE_bext_0 = &$thisfile_riff_WAVE['bext'][0]; + + $thisfile_riff_WAVE_bext_0['title'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 0, 256)); + $thisfile_riff_WAVE_bext_0['author'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 256, 32)); + $thisfile_riff_WAVE_bext_0['reference'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 288, 32)); + $thisfile_riff_WAVE_bext_0['origin_date'] = substr($thisfile_riff_WAVE_bext_0['data'], 320, 10); + $thisfile_riff_WAVE_bext_0['origin_time'] = substr($thisfile_riff_WAVE_bext_0['data'], 330, 8); + $thisfile_riff_WAVE_bext_0['time_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 338, 8)); + $thisfile_riff_WAVE_bext_0['bwf_version'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 346, 1)); + $thisfile_riff_WAVE_bext_0['reserved'] = substr($thisfile_riff_WAVE_bext_0['data'], 347, 254); + $thisfile_riff_WAVE_bext_0['coding_history'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_bext_0['data'], 601))); + if (preg_match('#^([0-9]{4}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_date'], $matches_bext_date)) { + if (preg_match('#^([0-9]{2}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_time'], $matches_bext_time)) { + list($dummy, $bext_timestamp['year'], $bext_timestamp['month'], $bext_timestamp['day']) = $matches_bext_date; + list($dummy, $bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second']) = $matches_bext_time; + $thisfile_riff_WAVE_bext_0['origin_date_unix'] = gmmktime($bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second'], $bext_timestamp['month'], $bext_timestamp['day'], $bext_timestamp['year']); + } else { + $this->warning('RIFF.WAVE.BEXT.origin_time is invalid'); + } + } else { + $this->warning('RIFF.WAVE.BEXT.origin_date is invalid'); + } + $thisfile_riff['comments']['author'][] = $thisfile_riff_WAVE_bext_0['author']; + $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_bext_0['title']; + } + + if (isset($thisfile_riff_WAVE['MEXT'][0]['data'])) { + // shortcut + $thisfile_riff_WAVE_MEXT_0 = &$thisfile_riff_WAVE['MEXT'][0]; + + $thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 0, 2)); + $thisfile_riff_WAVE_MEXT_0['flags']['homogenous'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0001); + if ($thisfile_riff_WAVE_MEXT_0['flags']['homogenous']) { + $thisfile_riff_WAVE_MEXT_0['flags']['padding'] = ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0002) ? false : true; + $thisfile_riff_WAVE_MEXT_0['flags']['22_or_44'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0004); + $thisfile_riff_WAVE_MEXT_0['flags']['free_format'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0008); + + $thisfile_riff_WAVE_MEXT_0['nominal_frame_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 2, 2)); + } + $thisfile_riff_WAVE_MEXT_0['anciliary_data_length'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 6, 2)); + $thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 8, 2)); + $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_left'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0001); + $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_free'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0002); + $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_right'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0004); + } + + if (isset($thisfile_riff_WAVE['cart'][0]['data'])) { + // shortcut + $thisfile_riff_WAVE_cart_0 = &$thisfile_riff_WAVE['cart'][0]; + + $thisfile_riff_WAVE_cart_0['version'] = substr($thisfile_riff_WAVE_cart_0['data'], 0, 4); + $thisfile_riff_WAVE_cart_0['title'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 4, 64)); + $thisfile_riff_WAVE_cart_0['artist'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 68, 64)); + $thisfile_riff_WAVE_cart_0['cut_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 132, 64)); + $thisfile_riff_WAVE_cart_0['client_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 196, 64)); + $thisfile_riff_WAVE_cart_0['category'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 260, 64)); + $thisfile_riff_WAVE_cart_0['classification'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 324, 64)); + $thisfile_riff_WAVE_cart_0['out_cue'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 388, 64)); + $thisfile_riff_WAVE_cart_0['start_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 452, 10)); + $thisfile_riff_WAVE_cart_0['start_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 462, 8)); + $thisfile_riff_WAVE_cart_0['end_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 470, 10)); + $thisfile_riff_WAVE_cart_0['end_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 480, 8)); + $thisfile_riff_WAVE_cart_0['producer_app_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 488, 64)); + $thisfile_riff_WAVE_cart_0['producer_app_version'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 552, 64)); + $thisfile_riff_WAVE_cart_0['user_defined_text'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 616, 64)); + $thisfile_riff_WAVE_cart_0['zero_db_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 680, 4), true); + for ($i = 0; $i < 8; $i++) { + $thisfile_riff_WAVE_cart_0['post_time'][$i]['usage_fourcc'] = substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8), 4); + $thisfile_riff_WAVE_cart_0['post_time'][$i]['timer_value'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8) + 4, 4)); + } + $thisfile_riff_WAVE_cart_0['url'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 748, 1024)); + $thisfile_riff_WAVE_cart_0['tag_text'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_cart_0['data'], 1772))); + + $thisfile_riff['comments']['artist'][] = $thisfile_riff_WAVE_cart_0['artist']; + $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_cart_0['title']; + } + + if (isset($thisfile_riff_WAVE['SNDM'][0]['data'])) { + // SoundMiner metadata + + // shortcuts + $thisfile_riff_WAVE_SNDM_0 = &$thisfile_riff_WAVE['SNDM'][0]; + $thisfile_riff_WAVE_SNDM_0_data = &$thisfile_riff_WAVE_SNDM_0['data']; + $SNDM_startoffset = 0; + $SNDM_endoffset = $thisfile_riff_WAVE_SNDM_0['size']; + + while ($SNDM_startoffset < $SNDM_endoffset) { + $SNDM_thisTagOffset = 0; + $SNDM_thisTagSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4)); + $SNDM_thisTagOffset += 4; + $SNDM_thisTagKey = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4); + $SNDM_thisTagOffset += 4; + $SNDM_thisTagDataSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2)); + $SNDM_thisTagOffset += 2; + $SNDM_thisTagDataFlags = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2)); + $SNDM_thisTagOffset += 2; + $SNDM_thisTagDataText = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, $SNDM_thisTagDataSize); + $SNDM_thisTagOffset += $SNDM_thisTagDataSize; + + if ($SNDM_thisTagSize != (4 + 4 + 2 + 2 + $SNDM_thisTagDataSize)) { + $this->warning('RIFF.WAVE.SNDM.data contains tag not expected length (expected: '.$SNDM_thisTagSize.', found: '.(4 + 4 + 2 + 2 + $SNDM_thisTagDataSize).') at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')'); + break; + } elseif ($SNDM_thisTagSize <= 0) { + $this->warning('RIFF.WAVE.SNDM.data contains zero-size tag at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')'); + break; + } + $SNDM_startoffset += $SNDM_thisTagSize; + + $thisfile_riff_WAVE_SNDM_0['parsed_raw'][$SNDM_thisTagKey] = $SNDM_thisTagDataText; + if ($parsedkey = self::waveSNDMtagLookup($SNDM_thisTagKey)) { + $thisfile_riff_WAVE_SNDM_0['parsed'][$parsedkey] = $SNDM_thisTagDataText; + } else { + $this->warning('RIFF.WAVE.SNDM contains unknown tag "'.$SNDM_thisTagKey.'" at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')'); + } + } + + $tagmapping = [ + 'tracktitle'=>'title', + 'category' =>'genre', + 'cdtitle' =>'album', + 'tracktitle'=>'title', + ]; + foreach ($tagmapping as $fromkey => $tokey) { + if (isset($thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey])) { + $thisfile_riff['comments'][$tokey][] = $thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey]; + } + } + } + + if (isset($thisfile_riff_WAVE['iXML'][0]['data'])) { + // requires functions simplexml_load_string and get_object_vars + if ($parsedXML = getid3_lib::XML2array($thisfile_riff_WAVE['iXML'][0]['data'])) { + $thisfile_riff_WAVE['iXML'][0]['parsed'] = $parsedXML; + if (isset($parsedXML['SPEED']['MASTER_SPEED'])) { + @list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['MASTER_SPEED']); + $thisfile_riff_WAVE['iXML'][0]['master_speed'] = $numerator / ($denominator ? $denominator : 1000); + } + if (isset($parsedXML['SPEED']['TIMECODE_RATE'])) { + @list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['TIMECODE_RATE']); + $thisfile_riff_WAVE['iXML'][0]['timecode_rate'] = $numerator / ($denominator ? $denominator : 1000); + } + if (isset($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO']) && ! empty($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) && ! empty($thisfile_riff_WAVE['iXML'][0]['timecode_rate'])) { + $samples_since_midnight = floatval(ltrim($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_HI'].$parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO'], '0')); + $timestamp_sample_rate = (is_array($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) ? max($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) : $parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']); // XML could possibly contain more than one TIMESTAMP_SAMPLE_RATE tag, returning as array instead of integer [why? does it make sense? perhaps doesn't matter but getID3 needs to deal with it] - see https://github.com/JamesHeinrich/getID3/issues/105 + $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] = $samples_since_midnight / $timestamp_sample_rate; + $h = floor($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] / 3600); + $m = floor(($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600)) / 60); + $s = floor($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60)); + $f = ($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60) - $s) * $thisfile_riff_WAVE['iXML'][0]['timecode_rate']; + $thisfile_riff_WAVE['iXML'][0]['timecode_string'] = sprintf('%02d:%02d:%02d:%05.2f', $h, $m, $s, $f); + $thisfile_riff_WAVE['iXML'][0]['timecode_string_round'] = sprintf('%02d:%02d:%02d:%02d', $h, $m, $s, round($f)); + unset($samples_since_midnight, $timestamp_sample_rate, $h, $m, $s, $f); + } + unset($parsedXML); + } + } + + if (! isset($thisfile_audio['bitrate']) && isset($thisfile_riff_audio[$streamindex]['bitrate'])) { + $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate']; + $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']); + } + + if (! empty($info['wavpack'])) { + $thisfile_audio_dataformat = 'wavpack'; + $thisfile_audio['bitrate_mode'] = 'vbr'; + $thisfile_audio['encoder'] = 'WavPack v'.$info['wavpack']['version']; + + // Reset to the way it was - RIFF parsing will have messed this up + $info['avdataend'] = $Original['avdataend']; + $thisfile_audio['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + + $this->fseek($info['avdataoffset'] - 44); + $RIFFdata = $this->fread(44); + $OrignalRIFFheaderSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 4, 4)) + 8; + $OrignalRIFFdataSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44; + + if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) { + $info['avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize); + $this->fseek($info['avdataend']); + $RIFFdata .= $this->fread($OrignalRIFFheaderSize - $OrignalRIFFdataSize); + } + + // move the data chunk after all other chunks (if any) + // so that the RIFF parser doesn't see EOF when trying + // to skip over the data chunk + $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8); + $getid3_riff = new self($this->getid3); + $getid3_riff->ParseRIFFdata($RIFFdata); + unset($getid3_riff); + } + + if (isset($thisfile_riff_raw['fmt ']['wFormatTag'])) { + switch ($thisfile_riff_raw['fmt ']['wFormatTag']) { + case 0x0001: // PCM + if (! empty($info['ac3'])) { + // Dolby Digital WAV files masquerade as PCM-WAV, but they're not + $thisfile_audio['wformattag'] = 0x2000; + $thisfile_audio['codec'] = self::wFormatTagLookup($thisfile_audio['wformattag']); + $thisfile_audio['lossless'] = false; + $thisfile_audio['bitrate'] = $info['ac3']['bitrate']; + $thisfile_audio['sample_rate'] = $info['ac3']['sample_rate']; + } + if (! empty($info['dts'])) { + // Dolby DTS files masquerade as PCM-WAV, but they're not + $thisfile_audio['wformattag'] = 0x2001; + $thisfile_audio['codec'] = self::wFormatTagLookup($thisfile_audio['wformattag']); + $thisfile_audio['lossless'] = false; + $thisfile_audio['bitrate'] = $info['dts']['bitrate']; + $thisfile_audio['sample_rate'] = $info['dts']['sample_rate']; + } + break; + case 0x08AE: // ClearJump LiteWave + $thisfile_audio['bitrate_mode'] = 'vbr'; + $thisfile_audio_dataformat = 'litewave'; + + //typedef struct tagSLwFormat { + // WORD m_wCompFormat; // low byte defines compression method, high byte is compression flags + // DWORD m_dwScale; // scale factor for lossy compression + // DWORD m_dwBlockSize; // number of samples in encoded blocks + // WORD m_wQuality; // alias for the scale factor + // WORD m_wMarkDistance; // distance between marks in bytes + // WORD m_wReserved; + // + // //following paramters are ignored if CF_FILESRC is not set + // DWORD m_dwOrgSize; // original file size in bytes + // WORD m_bFactExists; // indicates if 'fact' chunk exists in the original file + // DWORD m_dwRiffChunkSize; // riff chunk size in the original file + // + // PCMWAVEFORMAT m_OrgWf; // original wave format + // }SLwFormat, *PSLwFormat; + + // shortcut + $thisfile_riff['litewave']['raw'] = []; + $riff_litewave = &$thisfile_riff['litewave']; + $riff_litewave_raw = &$riff_litewave['raw']; + + $flags = [ + 'compression_method' => 1, + 'compression_flags' => 1, + 'm_dwScale' => 4, + 'm_dwBlockSize' => 4, + 'm_wQuality' => 2, + 'm_wMarkDistance' => 2, + 'm_wReserved' => 2, + 'm_dwOrgSize' => 4, + 'm_bFactExists' => 2, + 'm_dwRiffChunkSize' => 4, + ]; + $litewave_offset = 18; + foreach ($flags as $flag => $length) { + $riff_litewave_raw[$flag] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], $litewave_offset, $length)); + $litewave_offset += $length; + } + + //$riff_litewave['quality_factor'] = intval(round((2000 - $riff_litewave_raw['m_dwScale']) / 20)); + $riff_litewave['quality_factor'] = $riff_litewave_raw['m_wQuality']; + + $riff_litewave['flags']['raw_source'] = ($riff_litewave_raw['compression_flags'] & 0x01) ? false : true; + $riff_litewave['flags']['vbr_blocksize'] = ($riff_litewave_raw['compression_flags'] & 0x02) ? false : true; + $riff_litewave['flags']['seekpoints'] = (bool) ($riff_litewave_raw['compression_flags'] & 0x04); + + $thisfile_audio['lossless'] = (($riff_litewave_raw['m_wQuality'] == 100) ? true : false); + $thisfile_audio['encoder_options'] = '-q'.$riff_litewave['quality_factor']; + break; + + default: + break; + } + } + if ($info['avdataend'] > $info['filesize']) { + switch (! empty($thisfile_audio_dataformat) ? $thisfile_audio_dataformat : '') { + case 'wavpack': // WavPack + case 'lpac': // LPAC + case 'ofr': // OptimFROG + case 'ofs': // OptimFROG DualStream + // lossless compressed audio formats that keep original RIFF headers - skip warning + break; + + case 'litewave': + if (($info['avdataend'] - $info['filesize']) == 1) { + // LiteWave appears to incorrectly *not* pad actual output file + // to nearest WORD boundary so may appear to be short by one + // byte, in which case - skip warning + } else { + // Short by more than one byte, throw warning + $this->warning('Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)'); + $info['avdataend'] = $info['filesize']; + } + break; + + default: + if ((($info['avdataend'] - $info['filesize']) == 1) && (($thisfile_riff[$RIFFsubtype]['data'][0]['size'] % 2) == 0) && ((($info['filesize'] - $info['avdataoffset']) % 2) == 1)) { + // output file appears to be incorrectly *not* padded to nearest WORD boundary + // Output less severe warning + $this->warning('File should probably be padded to nearest WORD boundary, but it is not (expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' therefore short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)'); + $info['avdataend'] = $info['filesize']; + } else { + // Short by more than one byte, throw warning + $this->warning('Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)'); + $info['avdataend'] = $info['filesize']; + } + break; + } + } + if (! empty($info['mpeg']['audio']['LAME']['audio_bytes'])) { + if ((($info['avdataend'] - $info['avdataoffset']) - $info['mpeg']['audio']['LAME']['audio_bytes']) == 1) { + $info['avdataend']--; + $this->warning('Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored'); + } + } + if (isset($thisfile_audio_dataformat) && ($thisfile_audio_dataformat == 'ac3')) { + unset($thisfile_audio['bits_per_sample']); + if (! empty($info['ac3']['bitrate']) && ($info['ac3']['bitrate'] != $thisfile_audio['bitrate'])) { + $thisfile_audio['bitrate'] = $info['ac3']['bitrate']; + } + } + break; + + // http://en.wikipedia.org/wiki/Audio_Video_Interleave + case 'AVI ': + $info['fileformat'] = 'avi'; + $info['mime_type'] = 'video/avi'; + + $thisfile_video['bitrate_mode'] = 'vbr'; // maybe not, but probably + $thisfile_video['dataformat'] = 'avi'; + + if (isset($thisfile_riff[$RIFFsubtype]['movi']['offset'])) { + $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['movi']['offset'] + 8; + if (isset($thisfile_riff['AVIX'])) { + $info['avdataend'] = $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['offset'] + $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['size']; + } else { + $info['avdataend'] = $thisfile_riff['AVI ']['movi']['offset'] + $thisfile_riff['AVI ']['movi']['size']; + } + if ($info['avdataend'] > $info['filesize']) { + $this->warning('Probably truncated file - expecting '.($info['avdataend'] - $info['avdataoffset']).' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($info['avdataend'] - $info['filesize']).' bytes)'); + $info['avdataend'] = $info['filesize']; + } + } + + if (isset($thisfile_riff['AVI ']['hdrl']['strl']['indx'])) { + //$bIndexType = array( + // 0x00 => 'AVI_INDEX_OF_INDEXES', + // 0x01 => 'AVI_INDEX_OF_CHUNKS', + // 0x80 => 'AVI_INDEX_IS_DATA', + //); + //$bIndexSubtype = array( + // 0x01 => array( + // 0x01 => 'AVI_INDEX_2FIELD', + // ), + //); + foreach ($thisfile_riff['AVI ']['hdrl']['strl']['indx'] as $streamnumber => $steamdataarray) { + $ahsisd = &$thisfile_riff['AVI ']['hdrl']['strl']['indx'][$streamnumber]['data']; + + $thisfile_riff_raw['indx'][$streamnumber]['wLongsPerEntry'] = $this->EitherEndian2Int(substr($ahsisd, 0, 2)); + $thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType'] = $this->EitherEndian2Int(substr($ahsisd, 2, 1)); + $thisfile_riff_raw['indx'][$streamnumber]['bIndexType'] = $this->EitherEndian2Int(substr($ahsisd, 3, 1)); + $thisfile_riff_raw['indx'][$streamnumber]['nEntriesInUse'] = $this->EitherEndian2Int(substr($ahsisd, 4, 4)); + $thisfile_riff_raw['indx'][$streamnumber]['dwChunkId'] = substr($ahsisd, 8, 4); + $thisfile_riff_raw['indx'][$streamnumber]['dwReserved'] = $this->EitherEndian2Int(substr($ahsisd, 12, 4)); + + //$thisfile_riff_raw['indx'][$streamnumber]['bIndexType_name'] = $bIndexType[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']]; + //$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType_name'] = $bIndexSubtype[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']][$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType']]; + + unset($ahsisd); + } + } + if (isset($thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'])) { + $avihData = $thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data']; + + // shortcut + $thisfile_riff_raw['avih'] = []; + $thisfile_riff_raw_avih = &$thisfile_riff_raw['avih']; + + $thisfile_riff_raw_avih['dwMicroSecPerFrame'] = $this->EitherEndian2Int(substr($avihData, 0, 4)); // frame display rate (or 0L) + if ($thisfile_riff_raw_avih['dwMicroSecPerFrame'] == 0) { + $this->error('Corrupt RIFF file: avih.dwMicroSecPerFrame == zero'); + + return false; + } + + $flags = [ + 'dwMaxBytesPerSec', // max. transfer rate + 'dwPaddingGranularity', // pad to multiples of this size; normally 2K. + 'dwFlags', // the ever-present flags + 'dwTotalFrames', // # frames in file + 'dwInitialFrames', // + 'dwStreams', // + 'dwSuggestedBufferSize', // + 'dwWidth', // + 'dwHeight', // + 'dwScale', // + 'dwRate', // + 'dwStart', // + 'dwLength', // + ]; + $avih_offset = 4; + foreach ($flags as $flag) { + $thisfile_riff_raw_avih[$flag] = $this->EitherEndian2Int(substr($avihData, $avih_offset, 4)); + $avih_offset += 4; + } + + $flags = [ + 'hasindex' => 0x00000010, + 'mustuseindex' => 0x00000020, + 'interleaved' => 0x00000100, + 'trustcktype' => 0x00000800, + 'capturedfile' => 0x00010000, + 'copyrighted' => 0x00020010, + ]; foreach ($flags as $flag => $value) { - $thisfile_riff_raw_avih['flags'][$flag] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & $value); - } + $thisfile_riff_raw_avih['flags'][$flag] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & $value); + } - // shortcut - $thisfile_riff_video[$streamindex] = array(); - $thisfile_riff_video_current = &$thisfile_riff_video[$streamindex]; + // shortcut + $thisfile_riff_video[$streamindex] = []; + $thisfile_riff_video_current = &$thisfile_riff_video[$streamindex]; - if ($thisfile_riff_raw_avih['dwWidth'] > 0) { - $thisfile_riff_video_current['frame_width'] = $thisfile_riff_raw_avih['dwWidth']; - $thisfile_video['resolution_x'] = $thisfile_riff_video_current['frame_width']; - } - if ($thisfile_riff_raw_avih['dwHeight'] > 0) { - $thisfile_riff_video_current['frame_height'] = $thisfile_riff_raw_avih['dwHeight']; - $thisfile_video['resolution_y'] = $thisfile_riff_video_current['frame_height']; - } - if ($thisfile_riff_raw_avih['dwTotalFrames'] > 0) { - $thisfile_riff_video_current['total_frames'] = $thisfile_riff_raw_avih['dwTotalFrames']; - $thisfile_video['total_frames'] = $thisfile_riff_video_current['total_frames']; - } + if ($thisfile_riff_raw_avih['dwWidth'] > 0) { + $thisfile_riff_video_current['frame_width'] = $thisfile_riff_raw_avih['dwWidth']; + $thisfile_video['resolution_x'] = $thisfile_riff_video_current['frame_width']; + } + if ($thisfile_riff_raw_avih['dwHeight'] > 0) { + $thisfile_riff_video_current['frame_height'] = $thisfile_riff_raw_avih['dwHeight']; + $thisfile_video['resolution_y'] = $thisfile_riff_video_current['frame_height']; + } + if ($thisfile_riff_raw_avih['dwTotalFrames'] > 0) { + $thisfile_riff_video_current['total_frames'] = $thisfile_riff_raw_avih['dwTotalFrames']; + $thisfile_video['total_frames'] = $thisfile_riff_video_current['total_frames']; + } - $thisfile_riff_video_current['frame_rate'] = round(1000000 / $thisfile_riff_raw_avih['dwMicroSecPerFrame'], 3); - $thisfile_video['frame_rate'] = $thisfile_riff_video_current['frame_rate']; - } - if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) { - if (is_array($thisfile_riff['AVI ']['hdrl']['strl']['strh'])) { - for ($i = 0; $i < count($thisfile_riff['AVI ']['hdrl']['strl']['strh']); $i++) { - if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'])) { - $strhData = $thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data']; - $strhfccType = substr($strhData, 0, 4); + $thisfile_riff_video_current['frame_rate'] = round(1000000 / $thisfile_riff_raw_avih['dwMicroSecPerFrame'], 3); + $thisfile_video['frame_rate'] = $thisfile_riff_video_current['frame_rate']; + } + if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) { + if (is_array($thisfile_riff['AVI ']['hdrl']['strl']['strh'])) { + for ($i = 0; $i < count($thisfile_riff['AVI ']['hdrl']['strl']['strh']); $i++) { + if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'])) { + $strhData = $thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data']; + $strhfccType = substr($strhData, 0, 4); - if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'])) { - $strfData = $thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data']; + if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'])) { + $strfData = $thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data']; - // shortcut - $thisfile_riff_raw_strf_strhfccType_streamindex = &$thisfile_riff_raw['strf'][$strhfccType][$streamindex]; + // shortcut + $thisfile_riff_raw_strf_strhfccType_streamindex = &$thisfile_riff_raw['strf'][$strhfccType][$streamindex]; - switch ($strhfccType) { - case 'auds': - $thisfile_audio['bitrate_mode'] = 'cbr'; - $thisfile_audio_dataformat = 'wav'; - if (isset($thisfile_riff_audio) && is_array($thisfile_riff_audio)) { - $streamindex = count($thisfile_riff_audio); - } + switch ($strhfccType) { + case 'auds': + $thisfile_audio['bitrate_mode'] = 'cbr'; + $thisfile_audio_dataformat = 'wav'; + if (isset($thisfile_riff_audio) && is_array($thisfile_riff_audio)) { + $streamindex = count($thisfile_riff_audio); + } - $thisfile_riff_audio[$streamindex] = self::parseWAVEFORMATex($strfData); - $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag']; + $thisfile_riff_audio[$streamindex] = self::parseWAVEFORMATex($strfData); + $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag']; - // shortcut - $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex]; - $thisfile_audio_streams_currentstream = &$thisfile_audio['streams'][$streamindex]; + // shortcut + $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex]; + $thisfile_audio_streams_currentstream = &$thisfile_audio['streams'][$streamindex]; - if ($thisfile_audio_streams_currentstream['bits_per_sample'] == 0) { - unset($thisfile_audio_streams_currentstream['bits_per_sample']); - } - $thisfile_audio_streams_currentstream['wformattag'] = $thisfile_audio_streams_currentstream['raw']['wFormatTag']; - unset($thisfile_audio_streams_currentstream['raw']); + if ($thisfile_audio_streams_currentstream['bits_per_sample'] == 0) { + unset($thisfile_audio_streams_currentstream['bits_per_sample']); + } + $thisfile_audio_streams_currentstream['wformattag'] = $thisfile_audio_streams_currentstream['raw']['wFormatTag']; + unset($thisfile_audio_streams_currentstream['raw']); - // shortcut - $thisfile_riff_raw['strf'][$strhfccType][$streamindex] = $thisfile_riff_audio[$streamindex]['raw']; + // shortcut + $thisfile_riff_raw['strf'][$strhfccType][$streamindex] = $thisfile_riff_audio[$streamindex]['raw']; - unset($thisfile_riff_audio[$streamindex]['raw']); - $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]); + unset($thisfile_riff_audio[$streamindex]['raw']); + $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]); - $thisfile_audio['lossless'] = false; - switch ($thisfile_riff_raw_strf_strhfccType_streamindex['wFormatTag']) { - case 0x0001: // PCM - $thisfile_audio_dataformat = 'wav'; - $thisfile_audio['lossless'] = true; - break; + $thisfile_audio['lossless'] = false; + switch ($thisfile_riff_raw_strf_strhfccType_streamindex['wFormatTag']) { + case 0x0001: // PCM + $thisfile_audio_dataformat = 'wav'; + $thisfile_audio['lossless'] = true; + break; - case 0x0050: // MPEG Layer 2 or Layer 1 - $thisfile_audio_dataformat = 'mp2'; // Assume Layer-2 - break; + case 0x0050: // MPEG Layer 2 or Layer 1 + $thisfile_audio_dataformat = 'mp2'; // Assume Layer-2 + break; - case 0x0055: // MPEG Layer 3 - $thisfile_audio_dataformat = 'mp3'; - break; + case 0x0055: // MPEG Layer 3 + $thisfile_audio_dataformat = 'mp3'; + break; - case 0x00FF: // AAC - $thisfile_audio_dataformat = 'aac'; - break; + case 0x00FF: // AAC + $thisfile_audio_dataformat = 'aac'; + break; - case 0x0161: // Windows Media v7 / v8 / v9 - case 0x0162: // Windows Media Professional v9 - case 0x0163: // Windows Media Lossess v9 - $thisfile_audio_dataformat = 'wma'; - break; + case 0x0161: // Windows Media v7 / v8 / v9 + case 0x0162: // Windows Media Professional v9 + case 0x0163: // Windows Media Lossess v9 + $thisfile_audio_dataformat = 'wma'; + break; - case 0x2000: // AC-3 - $thisfile_audio_dataformat = 'ac3'; - break; + case 0x2000: // AC-3 + $thisfile_audio_dataformat = 'ac3'; + break; - case 0x2001: // DTS - $thisfile_audio_dataformat = 'dts'; - break; + case 0x2001: // DTS + $thisfile_audio_dataformat = 'dts'; + break; - default: - $thisfile_audio_dataformat = 'wav'; - break; - } - $thisfile_audio_streams_currentstream['dataformat'] = $thisfile_audio_dataformat; - $thisfile_audio_streams_currentstream['lossless'] = $thisfile_audio['lossless']; - $thisfile_audio_streams_currentstream['bitrate_mode'] = $thisfile_audio['bitrate_mode']; - break; + default: + $thisfile_audio_dataformat = 'wav'; + break; + } + $thisfile_audio_streams_currentstream['dataformat'] = $thisfile_audio_dataformat; + $thisfile_audio_streams_currentstream['lossless'] = $thisfile_audio['lossless']; + $thisfile_audio_streams_currentstream['bitrate_mode'] = $thisfile_audio['bitrate_mode']; + break; + case 'iavs': + case 'vids': + // shortcut + $thisfile_riff_raw['strh'][$i] = []; + $thisfile_riff_raw_strh_current = &$thisfile_riff_raw['strh'][$i]; - case 'iavs': - case 'vids': - // shortcut - $thisfile_riff_raw['strh'][$i] = array(); - $thisfile_riff_raw_strh_current = &$thisfile_riff_raw['strh'][$i]; + $thisfile_riff_raw_strh_current['fccType'] = substr($strhData, 0, 4); // same as $strhfccType; + $thisfile_riff_raw_strh_current['fccHandler'] = substr($strhData, 4, 4); + $thisfile_riff_raw_strh_current['dwFlags'] = $this->EitherEndian2Int(substr($strhData, 8, 4)); // Contains AVITF_* flags + $thisfile_riff_raw_strh_current['wPriority'] = $this->EitherEndian2Int(substr($strhData, 12, 2)); + $thisfile_riff_raw_strh_current['wLanguage'] = $this->EitherEndian2Int(substr($strhData, 14, 2)); + $thisfile_riff_raw_strh_current['dwInitialFrames'] = $this->EitherEndian2Int(substr($strhData, 16, 4)); + $thisfile_riff_raw_strh_current['dwScale'] = $this->EitherEndian2Int(substr($strhData, 20, 4)); + $thisfile_riff_raw_strh_current['dwRate'] = $this->EitherEndian2Int(substr($strhData, 24, 4)); + $thisfile_riff_raw_strh_current['dwStart'] = $this->EitherEndian2Int(substr($strhData, 28, 4)); + $thisfile_riff_raw_strh_current['dwLength'] = $this->EitherEndian2Int(substr($strhData, 32, 4)); + $thisfile_riff_raw_strh_current['dwSuggestedBufferSize'] = $this->EitherEndian2Int(substr($strhData, 36, 4)); + $thisfile_riff_raw_strh_current['dwQuality'] = $this->EitherEndian2Int(substr($strhData, 40, 4)); + $thisfile_riff_raw_strh_current['dwSampleSize'] = $this->EitherEndian2Int(substr($strhData, 44, 4)); + $thisfile_riff_raw_strh_current['rcFrame'] = $this->EitherEndian2Int(substr($strhData, 48, 4)); - $thisfile_riff_raw_strh_current['fccType'] = substr($strhData, 0, 4); // same as $strhfccType; - $thisfile_riff_raw_strh_current['fccHandler'] = substr($strhData, 4, 4); - $thisfile_riff_raw_strh_current['dwFlags'] = $this->EitherEndian2Int(substr($strhData, 8, 4)); // Contains AVITF_* flags - $thisfile_riff_raw_strh_current['wPriority'] = $this->EitherEndian2Int(substr($strhData, 12, 2)); - $thisfile_riff_raw_strh_current['wLanguage'] = $this->EitherEndian2Int(substr($strhData, 14, 2)); - $thisfile_riff_raw_strh_current['dwInitialFrames'] = $this->EitherEndian2Int(substr($strhData, 16, 4)); - $thisfile_riff_raw_strh_current['dwScale'] = $this->EitherEndian2Int(substr($strhData, 20, 4)); - $thisfile_riff_raw_strh_current['dwRate'] = $this->EitherEndian2Int(substr($strhData, 24, 4)); - $thisfile_riff_raw_strh_current['dwStart'] = $this->EitherEndian2Int(substr($strhData, 28, 4)); - $thisfile_riff_raw_strh_current['dwLength'] = $this->EitherEndian2Int(substr($strhData, 32, 4)); - $thisfile_riff_raw_strh_current['dwSuggestedBufferSize'] = $this->EitherEndian2Int(substr($strhData, 36, 4)); - $thisfile_riff_raw_strh_current['dwQuality'] = $this->EitherEndian2Int(substr($strhData, 40, 4)); - $thisfile_riff_raw_strh_current['dwSampleSize'] = $this->EitherEndian2Int(substr($strhData, 44, 4)); - $thisfile_riff_raw_strh_current['rcFrame'] = $this->EitherEndian2Int(substr($strhData, 48, 4)); + $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_riff_raw_strh_current['fccHandler']); + $thisfile_video['fourcc'] = $thisfile_riff_raw_strh_current['fccHandler']; + if (! $thisfile_riff_video_current['codec'] && isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) && self::fourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) { + $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']); + $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']; + } + $thisfile_video['codec'] = $thisfile_riff_video_current['codec']; + $thisfile_video['pixel_aspect_ratio'] = (float) 1; + switch ($thisfile_riff_raw_strh_current['fccHandler']) { + case 'HFYU': // Huffman Lossless Codec + case 'IRAW': // Intel YUV Uncompressed + case 'YUY2': // Uncompressed YUV 4:2:2 + $thisfile_video['lossless'] = true; + break; - $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_riff_raw_strh_current['fccHandler']); - $thisfile_video['fourcc'] = $thisfile_riff_raw_strh_current['fccHandler']; - if (!$thisfile_riff_video_current['codec'] && isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) && self::fourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) { - $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']); - $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']; - } - $thisfile_video['codec'] = $thisfile_riff_video_current['codec']; - $thisfile_video['pixel_aspect_ratio'] = (float) 1; - switch ($thisfile_riff_raw_strh_current['fccHandler']) { - case 'HFYU': // Huffman Lossless Codec - case 'IRAW': // Intel YUV Uncompressed - case 'YUY2': // Uncompressed YUV 4:2:2 - $thisfile_video['lossless'] = true; - break; + default: + $thisfile_video['lossless'] = false; + break; + } - default: - $thisfile_video['lossless'] = false; - break; - } + switch ($strhfccType) { + case 'vids': + $thisfile_riff_raw_strf_strhfccType_streamindex = self::ParseBITMAPINFOHEADER(substr($strfData, 0, 40), ($this->container == 'riff')); + $thisfile_video['bits_per_sample'] = $thisfile_riff_raw_strf_strhfccType_streamindex['biBitCount']; - switch ($strhfccType) { - case 'vids': - $thisfile_riff_raw_strf_strhfccType_streamindex = self::ParseBITMAPINFOHEADER(substr($strfData, 0, 40), ($this->container == 'riff')); - $thisfile_video['bits_per_sample'] = $thisfile_riff_raw_strf_strhfccType_streamindex['biBitCount']; + if ($thisfile_riff_video_current['codec'] == 'DV') { + $thisfile_riff_video_current['dv_type'] = 2; + } + break; - if ($thisfile_riff_video_current['codec'] == 'DV') { - $thisfile_riff_video_current['dv_type'] = 2; - } - break; + case 'iavs': + $thisfile_riff_video_current['dv_type'] = 1; + break; + } + break; - case 'iavs': - $thisfile_riff_video_current['dv_type'] = 1; - break; - } - break; + default: + $this->warning('Unhandled fccType for stream ('.$i.'): "'.$strhfccType.'"'); + break; - default: - $this->warning('Unhandled fccType for stream ('.$i.'): "'.$strhfccType.'"'); - break; + } + } + } - } - } - } + if (isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) { + $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']; + if (self::fourccLookup($thisfile_video['fourcc'])) { + $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_video['fourcc']); + $thisfile_video['codec'] = $thisfile_riff_video_current['codec']; + } - if (isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) { + switch ($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) { + case 'HFYU': // Huffman Lossless Codec + case 'IRAW': // Intel YUV Uncompressed + case 'YUY2': // Uncompressed YUV 4:2:2 + $thisfile_video['lossless'] = true; + //$thisfile_video['bits_per_sample'] = 24; + break; - $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']; - if (self::fourccLookup($thisfile_video['fourcc'])) { - $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_video['fourcc']); - $thisfile_video['codec'] = $thisfile_riff_video_current['codec']; - } + default: + $thisfile_video['lossless'] = false; + //$thisfile_video['bits_per_sample'] = 24; + break; + } + } + } + } + } + break; - switch ($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) { - case 'HFYU': // Huffman Lossless Codec - case 'IRAW': // Intel YUV Uncompressed - case 'YUY2': // Uncompressed YUV 4:2:2 - $thisfile_video['lossless'] = true; - //$thisfile_video['bits_per_sample'] = 24; - break; + case 'AMV ': + $info['fileformat'] = 'amv'; + $info['mime_type'] = 'video/amv'; - default: - $thisfile_video['lossless'] = false; - //$thisfile_video['bits_per_sample'] = 24; - break; - } + $thisfile_video['bitrate_mode'] = 'vbr'; // it's MJPEG, presumably contant-quality encoding, thereby VBR + $thisfile_video['dataformat'] = 'mjpeg'; + $thisfile_video['codec'] = 'mjpeg'; + $thisfile_video['lossless'] = false; + $thisfile_video['bits_per_sample'] = 24; - } - } - } - } - break; + $thisfile_audio['dataformat'] = 'adpcm'; + $thisfile_audio['lossless'] = false; + break; + // http://en.wikipedia.org/wiki/CD-DA + case 'CDDA': + $info['fileformat'] = 'cda'; + unset($info['mime_type']); - case 'AMV ': - $info['fileformat'] = 'amv'; - $info['mime_type'] = 'video/amv'; + $thisfile_audio_dataformat = 'cda'; - $thisfile_video['bitrate_mode'] = 'vbr'; // it's MJPEG, presumably contant-quality encoding, thereby VBR - $thisfile_video['dataformat'] = 'mjpeg'; - $thisfile_video['codec'] = 'mjpeg'; - $thisfile_video['lossless'] = false; - $thisfile_video['bits_per_sample'] = 24; + $info['avdataoffset'] = 44; - $thisfile_audio['dataformat'] = 'adpcm'; - $thisfile_audio['lossless'] = false; - break; + if (isset($thisfile_riff['CDDA']['fmt '][0]['data'])) { + // shortcut + $thisfile_riff_CDDA_fmt_0 = &$thisfile_riff['CDDA']['fmt '][0]; + $thisfile_riff_CDDA_fmt_0['unknown1'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 0, 2)); + $thisfile_riff_CDDA_fmt_0['track_num'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 2, 2)); + $thisfile_riff_CDDA_fmt_0['disc_id'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 4, 4)); + $thisfile_riff_CDDA_fmt_0['start_offset_frame'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 8, 4)); + $thisfile_riff_CDDA_fmt_0['playtime_frames'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 12, 4)); + $thisfile_riff_CDDA_fmt_0['unknown6'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 16, 4)); + $thisfile_riff_CDDA_fmt_0['unknown7'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 20, 4)); - // http://en.wikipedia.org/wiki/CD-DA - case 'CDDA': - $info['fileformat'] = 'cda'; - unset($info['mime_type']); + $thisfile_riff_CDDA_fmt_0['start_offset_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['start_offset_frame'] / 75; + $thisfile_riff_CDDA_fmt_0['playtime_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['playtime_frames'] / 75; + $info['comments']['track'] = $thisfile_riff_CDDA_fmt_0['track_num']; + $info['playtime_seconds'] = $thisfile_riff_CDDA_fmt_0['playtime_seconds']; - $thisfile_audio_dataformat = 'cda'; - - $info['avdataoffset'] = 44; - - if (isset($thisfile_riff['CDDA']['fmt '][0]['data'])) { - // shortcut - $thisfile_riff_CDDA_fmt_0 = &$thisfile_riff['CDDA']['fmt '][0]; - - $thisfile_riff_CDDA_fmt_0['unknown1'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 0, 2)); - $thisfile_riff_CDDA_fmt_0['track_num'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 2, 2)); - $thisfile_riff_CDDA_fmt_0['disc_id'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 4, 4)); - $thisfile_riff_CDDA_fmt_0['start_offset_frame'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 8, 4)); - $thisfile_riff_CDDA_fmt_0['playtime_frames'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 12, 4)); - $thisfile_riff_CDDA_fmt_0['unknown6'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 16, 4)); - $thisfile_riff_CDDA_fmt_0['unknown7'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 20, 4)); - - $thisfile_riff_CDDA_fmt_0['start_offset_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['start_offset_frame'] / 75; - $thisfile_riff_CDDA_fmt_0['playtime_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['playtime_frames'] / 75; - $info['comments']['track'] = $thisfile_riff_CDDA_fmt_0['track_num']; - $info['playtime_seconds'] = $thisfile_riff_CDDA_fmt_0['playtime_seconds']; - - // hardcoded data for CD-audio - $thisfile_audio['lossless'] = true; - $thisfile_audio['sample_rate'] = 44100; - $thisfile_audio['channels'] = 2; - $thisfile_audio['bits_per_sample'] = 16; - $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $thisfile_audio['channels'] * $thisfile_audio['bits_per_sample']; - $thisfile_audio['bitrate_mode'] = 'cbr'; - } - break; + // hardcoded data for CD-audio + $thisfile_audio['lossless'] = true; + $thisfile_audio['sample_rate'] = 44100; + $thisfile_audio['channels'] = 2; + $thisfile_audio['bits_per_sample'] = 16; + $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $thisfile_audio['channels'] * $thisfile_audio['bits_per_sample']; + $thisfile_audio['bitrate_mode'] = 'cbr'; + } + break; // http://en.wikipedia.org/wiki/AIFF - case 'AIFF': - case 'AIFC': - $info['fileformat'] = 'aiff'; - $info['mime_type'] = 'audio/x-aiff'; + case 'AIFF': + case 'AIFC': + $info['fileformat'] = 'aiff'; + $info['mime_type'] = 'audio/x-aiff'; - $thisfile_audio['bitrate_mode'] = 'cbr'; - $thisfile_audio_dataformat = 'aiff'; - $thisfile_audio['lossless'] = true; + $thisfile_audio['bitrate_mode'] = 'cbr'; + $thisfile_audio_dataformat = 'aiff'; + $thisfile_audio['lossless'] = true; - if (isset($thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'])) { - $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'] + 8; - $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['SSND'][0]['size']; - if ($info['avdataend'] > $info['filesize']) { - if (($info['avdataend'] == ($info['filesize'] + 1)) && (($info['filesize'] % 2) == 1)) { - // structures rounded to 2-byte boundary, but dumb encoders - // forget to pad end of file to make this actually work - } else { - $this->warning('Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['SSND'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found'); - } - $info['avdataend'] = $info['filesize']; - } - } + if (isset($thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'])) { + $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'] + 8; + $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['SSND'][0]['size']; + if ($info['avdataend'] > $info['filesize']) { + if (($info['avdataend'] == ($info['filesize'] + 1)) && (($info['filesize'] % 2) == 1)) { + // structures rounded to 2-byte boundary, but dumb encoders + // forget to pad end of file to make this actually work + } else { + $this->warning('Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['SSND'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found'); + } + $info['avdataend'] = $info['filesize']; + } + } - if (isset($thisfile_riff[$RIFFsubtype]['COMM'][0]['data'])) { + if (isset($thisfile_riff[$RIFFsubtype]['COMM'][0]['data'])) { - // shortcut - $thisfile_riff_RIFFsubtype_COMM_0_data = &$thisfile_riff[$RIFFsubtype]['COMM'][0]['data']; + // shortcut + $thisfile_riff_RIFFsubtype_COMM_0_data = &$thisfile_riff[$RIFFsubtype]['COMM'][0]['data']; - $thisfile_riff_audio['channels'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 0, 2), true); - $thisfile_riff_audio['total_samples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 2, 4), false); - $thisfile_riff_audio['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 6, 2), true); - $thisfile_riff_audio['sample_rate'] = (int) getid3_lib::BigEndian2Float(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 8, 10)); + $thisfile_riff_audio['channels'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 0, 2), true); + $thisfile_riff_audio['total_samples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 2, 4), false); + $thisfile_riff_audio['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 6, 2), true); + $thisfile_riff_audio['sample_rate'] = (int) getid3_lib::BigEndian2Float(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 8, 10)); - if ($thisfile_riff[$RIFFsubtype]['COMM'][0]['size'] > 18) { - $thisfile_riff_audio['codec_fourcc'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 18, 4); - $CodecNameSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 22, 1), false); - $thisfile_riff_audio['codec_name'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 23, $CodecNameSize); - switch ($thisfile_riff_audio['codec_name']) { - case 'NONE': - $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)'; - $thisfile_audio['lossless'] = true; - break; + if ($thisfile_riff[$RIFFsubtype]['COMM'][0]['size'] > 18) { + $thisfile_riff_audio['codec_fourcc'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 18, 4); + $CodecNameSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 22, 1), false); + $thisfile_riff_audio['codec_name'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 23, $CodecNameSize); + switch ($thisfile_riff_audio['codec_name']) { + case 'NONE': + $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)'; + $thisfile_audio['lossless'] = true; + break; - case '': - switch ($thisfile_riff_audio['codec_fourcc']) { - // http://developer.apple.com/qa/snd/snd07.html - case 'sowt': - $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Little-Endian PCM'; - $thisfile_audio['lossless'] = true; - break; + case '': + switch ($thisfile_riff_audio['codec_fourcc']) { + // http://developer.apple.com/qa/snd/snd07.html + case 'sowt': + $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Little-Endian PCM'; + $thisfile_audio['lossless'] = true; + break; - case 'twos': - $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Big-Endian PCM'; - $thisfile_audio['lossless'] = true; - break; + case 'twos': + $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Big-Endian PCM'; + $thisfile_audio['lossless'] = true; + break; - default: - break; - } - break; + default: + break; + } + break; - default: - $thisfile_audio['codec'] = $thisfile_riff_audio['codec_name']; - $thisfile_audio['lossless'] = false; - break; - } - } + default: + $thisfile_audio['codec'] = $thisfile_riff_audio['codec_name']; + $thisfile_audio['lossless'] = false; + break; + } + } - $thisfile_audio['channels'] = $thisfile_riff_audio['channels']; - if ($thisfile_riff_audio['bits_per_sample'] > 0) { - $thisfile_audio['bits_per_sample'] = $thisfile_riff_audio['bits_per_sample']; - } - $thisfile_audio['sample_rate'] = $thisfile_riff_audio['sample_rate']; - if ($thisfile_audio['sample_rate'] == 0) { - $this->error('Corrupted AIFF file: sample_rate == zero'); - return false; - } - $info['playtime_seconds'] = $thisfile_riff_audio['total_samples'] / $thisfile_audio['sample_rate']; - } + $thisfile_audio['channels'] = $thisfile_riff_audio['channels']; + if ($thisfile_riff_audio['bits_per_sample'] > 0) { + $thisfile_audio['bits_per_sample'] = $thisfile_riff_audio['bits_per_sample']; + } + $thisfile_audio['sample_rate'] = $thisfile_riff_audio['sample_rate']; + if ($thisfile_audio['sample_rate'] == 0) { + $this->error('Corrupted AIFF file: sample_rate == zero'); - if (isset($thisfile_riff[$RIFFsubtype]['COMT'])) { - $offset = 0; - $CommentCount = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false); - $offset += 2; - for ($i = 0; $i < $CommentCount; $i++) { - $info['comments_raw'][$i]['timestamp'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 4), false); - $offset += 4; - $info['comments_raw'][$i]['marker_id'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), true); - $offset += 2; - $CommentLength = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false); - $offset += 2; - $info['comments_raw'][$i]['comment'] = substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, $CommentLength); - $offset += $CommentLength; + return false; + } + $info['playtime_seconds'] = $thisfile_riff_audio['total_samples'] / $thisfile_audio['sample_rate']; + } - $info['comments_raw'][$i]['timestamp_unix'] = getid3_lib::DateMac2Unix($info['comments_raw'][$i]['timestamp']); - $thisfile_riff['comments']['comment'][] = $info['comments_raw'][$i]['comment']; - } - } + if (isset($thisfile_riff[$RIFFsubtype]['COMT'])) { + $offset = 0; + $CommentCount = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false); + $offset += 2; + for ($i = 0; $i < $CommentCount; $i++) { + $info['comments_raw'][$i]['timestamp'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 4), false); + $offset += 4; + $info['comments_raw'][$i]['marker_id'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), true); + $offset += 2; + $CommentLength = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false); + $offset += 2; + $info['comments_raw'][$i]['comment'] = substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, $CommentLength); + $offset += $CommentLength; - $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment'); - foreach ($CommentsChunkNames as $key => $value) { - if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) { - $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data']; - } - } + $info['comments_raw'][$i]['timestamp_unix'] = getid3_lib::DateMac2Unix($info['comments_raw'][$i]['timestamp']); + $thisfile_riff['comments']['comment'][] = $info['comments_raw'][$i]['comment']; + } + } + + $CommentsChunkNames = ['NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment']; + foreach ($CommentsChunkNames as $key => $value) { + if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) { + $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data']; + } + } /* - if (isset($thisfile_riff[$RIFFsubtype]['ID3 '])) { - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_id3v2 = new getid3_id3v2($getid3_temp); - $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['ID3 '][0]['offset'] + 8; - if ($thisfile_riff[$RIFFsubtype]['ID3 '][0]['valid'] = $getid3_id3v2->Analyze()) { - $info['id3v2'] = $getid3_temp->info['id3v2']; - } - unset($getid3_temp, $getid3_id3v2); - } + if (isset($thisfile_riff[$RIFFsubtype]['ID3 '])) { + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_id3v2 = new getid3_id3v2($getid3_temp); + $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['ID3 '][0]['offset'] + 8; + if ($thisfile_riff[$RIFFsubtype]['ID3 '][0]['valid'] = $getid3_id3v2->Analyze()) { + $info['id3v2'] = $getid3_temp->info['id3v2']; + } + unset($getid3_temp, $getid3_id3v2); + } */ - break; + break; - // http://en.wikipedia.org/wiki/8SVX - case '8SVX': - $info['fileformat'] = '8svx'; - $info['mime_type'] = 'audio/8svx'; + // http://en.wikipedia.org/wiki/8SVX + case '8SVX': + $info['fileformat'] = '8svx'; + $info['mime_type'] = 'audio/8svx'; - $thisfile_audio['bitrate_mode'] = 'cbr'; - $thisfile_audio_dataformat = '8svx'; - $thisfile_audio['bits_per_sample'] = 8; - $thisfile_audio['channels'] = 1; // overridden below, if need be + $thisfile_audio['bitrate_mode'] = 'cbr'; + $thisfile_audio_dataformat = '8svx'; + $thisfile_audio['bits_per_sample'] = 8; + $thisfile_audio['channels'] = 1; // overridden below, if need be - if (isset($thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'])) { - $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'] + 8; - $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['BODY'][0]['size']; - if ($info['avdataend'] > $info['filesize']) { - $this->warning('Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['BODY'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found'); - } - } + if (isset($thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'])) { + $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'] + 8; + $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['BODY'][0]['size']; + if ($info['avdataend'] > $info['filesize']) { + $this->warning('Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['BODY'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found'); + } + } - if (isset($thisfile_riff[$RIFFsubtype]['VHDR'][0]['offset'])) { - // shortcut - $thisfile_riff_RIFFsubtype_VHDR_0 = &$thisfile_riff[$RIFFsubtype]['VHDR'][0]; + if (isset($thisfile_riff[$RIFFsubtype]['VHDR'][0]['offset'])) { + // shortcut + $thisfile_riff_RIFFsubtype_VHDR_0 = &$thisfile_riff[$RIFFsubtype]['VHDR'][0]; - $thisfile_riff_RIFFsubtype_VHDR_0['oneShotHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 0, 4)); - $thisfile_riff_RIFFsubtype_VHDR_0['repeatHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 4, 4)); - $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerHiCycle'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 8, 4)); - $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 12, 2)); - $thisfile_riff_RIFFsubtype_VHDR_0['ctOctave'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 14, 1)); - $thisfile_riff_RIFFsubtype_VHDR_0['sCompression'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 15, 1)); - $thisfile_riff_RIFFsubtype_VHDR_0['Volume'] = getid3_lib::FixedPoint16_16(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 16, 4)); + $thisfile_riff_RIFFsubtype_VHDR_0['oneShotHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 0, 4)); + $thisfile_riff_RIFFsubtype_VHDR_0['repeatHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 4, 4)); + $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerHiCycle'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 8, 4)); + $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 12, 2)); + $thisfile_riff_RIFFsubtype_VHDR_0['ctOctave'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 14, 1)); + $thisfile_riff_RIFFsubtype_VHDR_0['sCompression'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 15, 1)); + $thisfile_riff_RIFFsubtype_VHDR_0['Volume'] = getid3_lib::FixedPoint16_16(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 16, 4)); - $thisfile_audio['sample_rate'] = $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec']; + $thisfile_audio['sample_rate'] = $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec']; - switch ($thisfile_riff_RIFFsubtype_VHDR_0['sCompression']) { - case 0: - $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)'; - $thisfile_audio['lossless'] = true; - $ActualBitsPerSample = 8; - break; + switch ($thisfile_riff_RIFFsubtype_VHDR_0['sCompression']) { + case 0: + $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)'; + $thisfile_audio['lossless'] = true; + $ActualBitsPerSample = 8; + break; - case 1: - $thisfile_audio['codec'] = 'Fibonacci-delta encoding'; - $thisfile_audio['lossless'] = false; - $ActualBitsPerSample = 4; - break; + case 1: + $thisfile_audio['codec'] = 'Fibonacci-delta encoding'; + $thisfile_audio['lossless'] = false; + $ActualBitsPerSample = 4; + break; - default: - $this->warning('Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "'.sCompression.'"'); - break; - } - } + default: + $this->warning('Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "'.sCompression.'"'); + break; + } + } - if (isset($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'])) { - $ChannelsIndex = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'], 0, 4)); - switch ($ChannelsIndex) { - case 6: // Stereo - $thisfile_audio['channels'] = 2; - break; + if (isset($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'])) { + $ChannelsIndex = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'], 0, 4)); + switch ($ChannelsIndex) { + case 6: // Stereo + $thisfile_audio['channels'] = 2; + break; - case 2: // Left channel only - case 4: // Right channel only - $thisfile_audio['channels'] = 1; - break; + case 2: // Left channel only + case 4: // Right channel only + $thisfile_audio['channels'] = 1; + break; - default: - $this->warning('Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "'.$ChannelsIndex.'"'); - break; - } + default: + $this->warning('Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "'.$ChannelsIndex.'"'); + break; + } + } - } + $CommentsChunkNames = ['NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment']; + foreach ($CommentsChunkNames as $key => $value) { + if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) { + $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data']; + } + } - $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment'); - foreach ($CommentsChunkNames as $key => $value) { - if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) { - $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data']; - } - } + $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $ActualBitsPerSample * $thisfile_audio['channels']; + if (! empty($thisfile_audio['bitrate'])) { + $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($thisfile_audio['bitrate'] / 8); + } + break; - $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $ActualBitsPerSample * $thisfile_audio['channels']; - if (!empty($thisfile_audio['bitrate'])) { - $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($thisfile_audio['bitrate'] / 8); - } - break; + case 'CDXA': + $info['fileformat'] = 'vcd'; // Asume Video CD + $info['mime_type'] = 'video/mpeg'; - case 'CDXA': - $info['fileformat'] = 'vcd'; // Asume Video CD - $info['mime_type'] = 'video/mpeg'; + if (! empty($thisfile_riff['CDXA']['data'][0]['size'])) { + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.mpeg.php', __FILE__, true); - if (!empty($thisfile_riff['CDXA']['data'][0]['size'])) { - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.mpeg.php', __FILE__, true); + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_mpeg = new getid3_mpeg($getid3_temp); + $getid3_mpeg->Analyze(); + if (empty($getid3_temp->info['error'])) { + $info['audio'] = $getid3_temp->info['audio']; + $info['video'] = $getid3_temp->info['video']; + $info['mpeg'] = $getid3_temp->info['mpeg']; + $info['warning'] = $getid3_temp->info['warning']; + } + unset($getid3_temp, $getid3_mpeg); + } + break; - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_mpeg = new getid3_mpeg($getid3_temp); - $getid3_mpeg->Analyze(); - if (empty($getid3_temp->info['error'])) { - $info['audio'] = $getid3_temp->info['audio']; - $info['video'] = $getid3_temp->info['video']; - $info['mpeg'] = $getid3_temp->info['mpeg']; - $info['warning'] = $getid3_temp->info['warning']; - } - unset($getid3_temp, $getid3_mpeg); - } - break; - - case 'WEBP': - // https://developers.google.com/speed/webp/docs/riff_container - $info['fileformat'] = 'webp'; - $info['mime_type'] = 'image/webp'; + case 'WEBP': + // https://developers.google.com/speed/webp/docs/riff_container + $info['fileformat'] = 'webp'; + $info['mime_type'] = 'image/webp'; $this->error('WebP image parsing not supported in this version of getID3()'); - break; - - default: - $this->error('Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA|WEBP), found "'.$RIFFsubtype.'" instead'); - //unset($info['fileformat']); - } - - switch ($RIFFsubtype) { - case 'WAVE': - case 'AIFF': - case 'AIFC': - $ID3v2_key_good = 'id3 '; - $ID3v2_keys_bad = array('ID3 ', 'tag '); - foreach ($ID3v2_keys_bad as $ID3v2_key_bad) { - if (isset($thisfile_riff[$RIFFsubtype][$ID3v2_key_bad]) && !array_key_exists($ID3v2_key_good, $thisfile_riff[$RIFFsubtype])) { - $thisfile_riff[$RIFFsubtype][$ID3v2_key_good] = $thisfile_riff[$RIFFsubtype][$ID3v2_key_bad]; - $this->warning('mapping "'.$ID3v2_key_bad.'" chunk to "'.$ID3v2_key_good.'"'); - } - } - - if (isset($thisfile_riff[$RIFFsubtype]['id3 '])) { - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); - - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_id3v2 = new getid3_id3v2($getid3_temp); - $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['id3 '][0]['offset'] + 8; - if ($thisfile_riff[$RIFFsubtype]['id3 '][0]['valid'] = $getid3_id3v2->Analyze()) { - $info['id3v2'] = $getid3_temp->info['id3v2']; - } - unset($getid3_temp, $getid3_id3v2); - } - break; - } - - if (isset($thisfile_riff_WAVE['DISP']) && is_array($thisfile_riff_WAVE['DISP'])) { - $thisfile_riff['comments']['title'][] = trim(substr($thisfile_riff_WAVE['DISP'][count($thisfile_riff_WAVE['DISP']) - 1]['data'], 4)); - } - if (isset($thisfile_riff_WAVE['INFO']) && is_array($thisfile_riff_WAVE['INFO'])) { - self::parseComments($thisfile_riff_WAVE['INFO'], $thisfile_riff['comments']); - } - if (isset($thisfile_riff['AVI ']['INFO']) && is_array($thisfile_riff['AVI ']['INFO'])) { - self::parseComments($thisfile_riff['AVI ']['INFO'], $thisfile_riff['comments']); - } - - if (empty($thisfile_audio['encoder']) && !empty($info['mpeg']['audio']['LAME']['short_version'])) { - $thisfile_audio['encoder'] = $info['mpeg']['audio']['LAME']['short_version']; - } - - if (!isset($info['playtime_seconds'])) { - $info['playtime_seconds'] = 0; - } - if (isset($thisfile_riff_raw['strh'][0]['dwLength']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) { - // needed for >2GB AVIs where 'avih' chunk only lists number of frames in that chunk, not entire movie - $info['playtime_seconds'] = $thisfile_riff_raw['strh'][0]['dwLength'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000); - } elseif (isset($thisfile_riff_raw['avih']['dwTotalFrames']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) { - $info['playtime_seconds'] = $thisfile_riff_raw['avih']['dwTotalFrames'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000); - } - - if ($info['playtime_seconds'] > 0) { - if (isset($thisfile_riff_audio) && isset($thisfile_riff_video)) { - - if (!isset($info['bitrate'])) { - $info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8); - } - - } elseif (isset($thisfile_riff_audio) && !isset($thisfile_riff_video)) { - - if (!isset($thisfile_audio['bitrate'])) { - $thisfile_audio['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8); - } - - } elseif (!isset($thisfile_riff_audio) && isset($thisfile_riff_video)) { - - if (!isset($thisfile_video['bitrate'])) { - $thisfile_video['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8); - } - - } - } - - - if (isset($thisfile_riff_video) && isset($thisfile_audio['bitrate']) && ($thisfile_audio['bitrate'] > 0) && ($info['playtime_seconds'] > 0)) { - - $info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8); - $thisfile_audio['bitrate'] = 0; - $thisfile_video['bitrate'] = $info['bitrate']; - foreach ($thisfile_riff_audio as $channelnumber => $audioinfoarray) { - $thisfile_video['bitrate'] -= $audioinfoarray['bitrate']; - $thisfile_audio['bitrate'] += $audioinfoarray['bitrate']; - } - if ($thisfile_video['bitrate'] <= 0) { - unset($thisfile_video['bitrate']); - } - if ($thisfile_audio['bitrate'] <= 0) { - unset($thisfile_audio['bitrate']); - } - } - - if (isset($info['mpeg']['audio'])) { - $thisfile_audio_dataformat = 'mp'.$info['mpeg']['audio']['layer']; - $thisfile_audio['sample_rate'] = $info['mpeg']['audio']['sample_rate']; - $thisfile_audio['channels'] = $info['mpeg']['audio']['channels']; - $thisfile_audio['bitrate'] = $info['mpeg']['audio']['bitrate']; - $thisfile_audio['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); - if (!empty($info['mpeg']['audio']['codec'])) { - $thisfile_audio['codec'] = $info['mpeg']['audio']['codec'].' '.$thisfile_audio['codec']; - } - if (!empty($thisfile_audio['streams'])) { - foreach ($thisfile_audio['streams'] as $streamnumber => $streamdata) { - if ($streamdata['dataformat'] == $thisfile_audio_dataformat) { - $thisfile_audio['streams'][$streamnumber]['sample_rate'] = $thisfile_audio['sample_rate']; - $thisfile_audio['streams'][$streamnumber]['channels'] = $thisfile_audio['channels']; - $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate']; - $thisfile_audio['streams'][$streamnumber]['bitrate_mode'] = $thisfile_audio['bitrate_mode']; - $thisfile_audio['streams'][$streamnumber]['codec'] = $thisfile_audio['codec']; - } - } - } - $getid3_mp3 = new getid3_mp3($this->getid3); - $thisfile_audio['encoder_options'] = $getid3_mp3->GuessEncoderOptions(); - unset($getid3_mp3); - } - - - if (!empty($thisfile_riff_raw['fmt ']['wBitsPerSample']) && ($thisfile_riff_raw['fmt ']['wBitsPerSample'] > 0)) { - switch ($thisfile_audio_dataformat) { - case 'ac3': - // ignore bits_per_sample - break; - - default: - $thisfile_audio['bits_per_sample'] = $thisfile_riff_raw['fmt ']['wBitsPerSample']; - break; - } - } - - - if (empty($thisfile_riff_raw)) { - unset($thisfile_riff['raw']); - } - if (empty($thisfile_riff_audio)) { - unset($thisfile_riff['audio']); - } - if (empty($thisfile_riff_video)) { - unset($thisfile_riff['video']); - } - - return true; - } - - public function ParseRIFFAMV($startoffset, $maxoffset) { - // AMV files are RIFF-AVI files with parts of the spec deliberately broken, such as chunk size fields hardcoded to zero (because players known in hardware that these fields are always a certain size - - // https://code.google.com/p/amv-codec-tools/wiki/AmvDocumentation - //typedef struct _amvmainheader { - //FOURCC fcc; // 'amvh' - //DWORD cb; - //DWORD dwMicroSecPerFrame; - //BYTE reserve[28]; - //DWORD dwWidth; - //DWORD dwHeight; - //DWORD dwSpeed; - //DWORD reserve0; - //DWORD reserve1; - //BYTE bTimeSec; - //BYTE bTimeMin; - //WORD wTimeHour; - //} AMVMAINHEADER; - - $info = &$this->getid3->info; - $RIFFchunk = false; - - try { - - $this->fseek($startoffset); - $maxoffset = min($maxoffset, $info['avdataend']); - $AMVheader = $this->fread(284); - if (substr($AMVheader, 0, 8) != 'hdrlamvh') { - throw new Exception('expecting "hdrlamv" at offset '.($startoffset + 0).', found "'.substr($AMVheader, 0, 8).'"'); - } - if (substr($AMVheader, 8, 4) != "\x38\x00\x00\x00") { // "amvh" chunk size, hardcoded to 0x38 = 56 bytes - throw new Exception('expecting "0x38000000" at offset '.($startoffset + 8).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 8, 4)).'"'); - } - $RIFFchunk = array(); - $RIFFchunk['amvh']['us_per_frame'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 12, 4)); - $RIFFchunk['amvh']['reserved28'] = substr($AMVheader, 16, 28); // null? reserved? - $RIFFchunk['amvh']['resolution_x'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 44, 4)); - $RIFFchunk['amvh']['resolution_y'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 48, 4)); - $RIFFchunk['amvh']['frame_rate_int'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 52, 4)); - $RIFFchunk['amvh']['reserved0'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 56, 4)); // 1? reserved? - $RIFFchunk['amvh']['reserved1'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 60, 4)); // 0? reserved? - $RIFFchunk['amvh']['runtime_sec'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 64, 1)); - $RIFFchunk['amvh']['runtime_min'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 65, 1)); - $RIFFchunk['amvh']['runtime_hrs'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 66, 2)); - - $info['video']['frame_rate'] = 1000000 / $RIFFchunk['amvh']['us_per_frame']; - $info['video']['resolution_x'] = $RIFFchunk['amvh']['resolution_x']; - $info['video']['resolution_y'] = $RIFFchunk['amvh']['resolution_y']; - $info['playtime_seconds'] = ($RIFFchunk['amvh']['runtime_hrs'] * 3600) + ($RIFFchunk['amvh']['runtime_min'] * 60) + $RIFFchunk['amvh']['runtime_sec']; - - // the rest is all hardcoded(?) and does not appear to be useful until you get to audio info at offset 256, even then everything is probably hardcoded - - if (substr($AMVheader, 68, 20) != 'LIST'."\x00\x00\x00\x00".'strlstrh'."\x38\x00\x00\x00") { - throw new Exception('expecting "LIST<0x00000000>strlstrh<0x38000000>" at offset '.($startoffset + 68).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 68, 20)).'"'); - } - // followed by 56 bytes of null: substr($AMVheader, 88, 56) -> 144 - if (substr($AMVheader, 144, 8) != 'strf'."\x24\x00\x00\x00") { - throw new Exception('expecting "strf<0x24000000>" at offset '.($startoffset + 144).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 144, 8)).'"'); - } - // followed by 36 bytes of null: substr($AMVheader, 144, 36) -> 180 - - if (substr($AMVheader, 188, 20) != 'LIST'."\x00\x00\x00\x00".'strlstrh'."\x30\x00\x00\x00") { - throw new Exception('expecting "LIST<0x00000000>strlstrh<0x30000000>" at offset '.($startoffset + 188).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 188, 20)).'"'); - } - // followed by 48 bytes of null: substr($AMVheader, 208, 48) -> 256 - if (substr($AMVheader, 256, 8) != 'strf'."\x14\x00\x00\x00") { - throw new Exception('expecting "strf<0x14000000>" at offset '.($startoffset + 256).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 256, 8)).'"'); - } - // followed by 20 bytes of a modified WAVEFORMATEX: - // typedef struct { - // WORD wFormatTag; //(Fixme: this is equal to PCM's 0x01 format code) - // WORD nChannels; //(Fixme: this is always 1) - // DWORD nSamplesPerSec; //(Fixme: for all known sample files this is equal to 22050) - // DWORD nAvgBytesPerSec; //(Fixme: for all known sample files this is equal to 44100) - // WORD nBlockAlign; //(Fixme: this seems to be 2 in AMV files, is this correct ?) - // WORD wBitsPerSample; //(Fixme: this seems to be 16 in AMV files instead of the expected 4) - // WORD cbSize; //(Fixme: this seems to be 0 in AMV files) - // WORD reserved; - // } WAVEFORMATEX; - $RIFFchunk['strf']['wformattag'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 264, 2)); - $RIFFchunk['strf']['nchannels'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 266, 2)); - $RIFFchunk['strf']['nsamplespersec'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 268, 4)); - $RIFFchunk['strf']['navgbytespersec'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 272, 4)); - $RIFFchunk['strf']['nblockalign'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 276, 2)); - $RIFFchunk['strf']['wbitspersample'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 278, 2)); - $RIFFchunk['strf']['cbsize'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 280, 2)); - $RIFFchunk['strf']['reserved'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 282, 2)); - - - $info['audio']['lossless'] = false; - $info['audio']['sample_rate'] = $RIFFchunk['strf']['nsamplespersec']; - $info['audio']['channels'] = $RIFFchunk['strf']['nchannels']; - $info['audio']['bits_per_sample'] = $RIFFchunk['strf']['wbitspersample']; - $info['audio']['bitrate'] = $info['audio']['sample_rate'] * $info['audio']['channels'] * $info['audio']['bits_per_sample']; - $info['audio']['bitrate_mode'] = 'cbr'; - - - } catch (getid3_exception $e) { - if ($e->getCode() == 10) { - $this->warning('RIFFAMV parser: '.$e->getMessage()); - } else { - throw $e; - } - } - - return $RIFFchunk; - } - - - public function ParseRIFF($startoffset, $maxoffset) { - $info = &$this->getid3->info; - - $RIFFchunk = false; - $FoundAllChunksWeNeed = false; - - try { - $this->fseek($startoffset); - $maxoffset = min($maxoffset, $info['avdataend']); - while ($this->ftell() < $maxoffset) { - $chunknamesize = $this->fread(8); - //$chunkname = substr($chunknamesize, 0, 4); - $chunkname = str_replace("\x00", '_', substr($chunknamesize, 0, 4)); // note: chunk names of 4 null bytes do appear to be legal (has been observed inside INFO and PRMI chunks, for example), but makes traversing array keys more difficult - $chunksize = $this->EitherEndian2Int(substr($chunknamesize, 4, 4)); - //if (strlen(trim($chunkname, "\x00")) < 4) { - if (strlen($chunkname) < 4) { - $this->error('Expecting chunk name at offset '.($this->ftell() - 8).' but found nothing. Aborting RIFF parsing.'); - break; - } - if (($chunksize == 0) && ($chunkname != 'JUNK')) { - $this->warning('Chunk ('.$chunkname.') size at offset '.($this->ftell() - 4).' is zero. Aborting RIFF parsing.'); - break; - } - if (($chunksize % 2) != 0) { - // all structures are packed on word boundaries - $chunksize++; - } - - switch ($chunkname) { - case 'LIST': - $listname = $this->fread(4); - if (preg_match('#^(movi|rec )$#i', $listname)) { - $RIFFchunk[$listname]['offset'] = $this->ftell() - 4; - $RIFFchunk[$listname]['size'] = $chunksize; - - if (!$FoundAllChunksWeNeed) { - $WhereWeWere = $this->ftell(); - $AudioChunkHeader = $this->fread(12); - $AudioChunkStreamNum = substr($AudioChunkHeader, 0, 2); - $AudioChunkStreamType = substr($AudioChunkHeader, 2, 2); - $AudioChunkSize = getid3_lib::LittleEndian2Int(substr($AudioChunkHeader, 4, 4)); - - if ($AudioChunkStreamType == 'wb') { - $FirstFourBytes = substr($AudioChunkHeader, 8, 4); - if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', $FirstFourBytes)) { - // MP3 - if (getid3_mp3::MPEGaudioHeaderBytesValid($FirstFourBytes)) { - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_temp->info['avdataoffset'] = $this->ftell() - 4; - $getid3_temp->info['avdataend'] = $this->ftell() + $AudioChunkSize; - $getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__); - $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false); - if (isset($getid3_temp->info['mpeg']['audio'])) { - $info['mpeg']['audio'] = $getid3_temp->info['mpeg']['audio']; - $info['audio'] = $getid3_temp->info['audio']; - $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer']; - $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; - $info['audio']['channels'] = $info['mpeg']['audio']['channels']; - $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; - $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); - //$info['bitrate'] = $info['audio']['bitrate']; - } - unset($getid3_temp, $getid3_mp3); - } - - } elseif (strpos($FirstFourBytes, getid3_ac3::syncword) === 0) { - - // AC3 - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_temp->info['avdataoffset'] = $this->ftell() - 4; - $getid3_temp->info['avdataend'] = $this->ftell() + $AudioChunkSize; - $getid3_ac3 = new getid3_ac3($getid3_temp); - $getid3_ac3->Analyze(); - if (empty($getid3_temp->info['error'])) { - $info['audio'] = $getid3_temp->info['audio']; - $info['ac3'] = $getid3_temp->info['ac3']; - if (!empty($getid3_temp->info['warning'])) { - foreach ($getid3_temp->info['warning'] as $key => $value) { - $this->warning($value); - } - } - } - unset($getid3_temp, $getid3_ac3); - } - } - $FoundAllChunksWeNeed = true; - $this->fseek($WhereWeWere); - } - $this->fseek($chunksize - 4, SEEK_CUR); - - } else { - - if (!isset($RIFFchunk[$listname])) { - $RIFFchunk[$listname] = array(); - } - $LISTchunkParent = $listname; - $LISTchunkMaxOffset = $this->ftell() - 4 + $chunksize; - if ($parsedChunk = $this->ParseRIFF($this->ftell(), $LISTchunkMaxOffset)) { - $RIFFchunk[$listname] = array_merge_recursive($RIFFchunk[$listname], $parsedChunk); - } - - } - break; - - default: - if (preg_match('#^[0-9]{2}(wb|pc|dc|db)$#', $chunkname)) { - $this->fseek($chunksize, SEEK_CUR); - break; - } - $thisindex = 0; - if (isset($RIFFchunk[$chunkname]) && is_array($RIFFchunk[$chunkname])) { - $thisindex = count($RIFFchunk[$chunkname]); - } - $RIFFchunk[$chunkname][$thisindex]['offset'] = $this->ftell() - 8; - $RIFFchunk[$chunkname][$thisindex]['size'] = $chunksize; - switch ($chunkname) { - case 'data': - $info['avdataoffset'] = $this->ftell(); - $info['avdataend'] = $info['avdataoffset'] + $chunksize; - - $testData = $this->fread(36); - if ($testData === '') { - break; - } - if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', substr($testData, 0, 4))) { - - // Probably is MP3 data - if (getid3_mp3::MPEGaudioHeaderBytesValid(substr($testData, 0, 4))) { - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; - $getid3_temp->info['avdataend'] = $info['avdataend']; - $getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__); - $getid3_mp3->getOnlyMPEGaudioInfo($info['avdataoffset'], false); - if (empty($getid3_temp->info['error'])) { - $info['audio'] = $getid3_temp->info['audio']; - $info['mpeg'] = $getid3_temp->info['mpeg']; - } - unset($getid3_temp, $getid3_mp3); - } - - } elseif (($isRegularAC3 = (substr($testData, 0, 2) == getid3_ac3::syncword)) || substr($testData, 8, 2) == strrev(getid3_ac3::syncword)) { - - // This is probably AC-3 data - $getid3_temp = new getID3(); - if ($isRegularAC3) { - $getid3_temp->openfile($this->getid3->filename); - $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; - $getid3_temp->info['avdataend'] = $info['avdataend']; - } - $getid3_ac3 = new getid3_ac3($getid3_temp); - if ($isRegularAC3) { - $getid3_ac3->Analyze(); - } else { - // Dolby Digital WAV - // AC-3 content, but not encoded in same format as normal AC-3 file - // For one thing, byte order is swapped - $ac3_data = ''; - for ($i = 0; $i < 28; $i += 2) { - $ac3_data .= substr($testData, 8 + $i + 1, 1); - $ac3_data .= substr($testData, 8 + $i + 0, 1); - } - $getid3_ac3->AnalyzeString($ac3_data); - } - - if (empty($getid3_temp->info['error'])) { - $info['audio'] = $getid3_temp->info['audio']; - $info['ac3'] = $getid3_temp->info['ac3']; - if (!empty($getid3_temp->info['warning'])) { - foreach ($getid3_temp->info['warning'] as $newerror) { - $this->warning('getid3_ac3() says: ['.$newerror.']'); - } - } - } - unset($getid3_temp, $getid3_ac3); - - } elseif (preg_match('/^('.implode('|', array_map('preg_quote', getid3_dts::$syncwords)).')/', $testData)) { - - // This is probably DTS data - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; - $getid3_dts = new getid3_dts($getid3_temp); - $getid3_dts->Analyze(); - if (empty($getid3_temp->info['error'])) { - $info['audio'] = $getid3_temp->info['audio']; - $info['dts'] = $getid3_temp->info['dts']; - $info['playtime_seconds'] = $getid3_temp->info['playtime_seconds']; // may not match RIFF calculations since DTS-WAV often used 14/16 bit-word packing - if (!empty($getid3_temp->info['warning'])) { - foreach ($getid3_temp->info['warning'] as $newerror) { - $this->warning('getid3_dts() says: ['.$newerror.']'); - } - } - } - - unset($getid3_temp, $getid3_dts); - - } elseif (substr($testData, 0, 4) == 'wvpk') { - - // This is WavPack data - $info['wavpack']['offset'] = $info['avdataoffset']; - $info['wavpack']['size'] = getid3_lib::LittleEndian2Int(substr($testData, 4, 4)); - $this->parseWavPackHeader(substr($testData, 8, 28)); - - } else { - // This is some other kind of data (quite possibly just PCM) - // do nothing special, just skip it - } - $nextoffset = $info['avdataend']; - $this->fseek($nextoffset); - break; - - case 'iXML': - case 'bext': - case 'cart': - case 'fmt ': - case 'strh': - case 'strf': - case 'indx': - case 'MEXT': - case 'DISP': - // always read data in - case 'JUNK': - // should be: never read data in - // but some programs write their version strings in a JUNK chunk (e.g. VirtualDub, AVIdemux, etc) - if ($chunksize < 1048576) { - if ($chunksize > 0) { - $RIFFchunk[$chunkname][$thisindex]['data'] = $this->fread($chunksize); - if ($chunkname == 'JUNK') { - if (preg_match('#^([\\x20-\\x7F]+)#', $RIFFchunk[$chunkname][$thisindex]['data'], $matches)) { - // only keep text characters [chr(32)-chr(127)] - $info['riff']['comments']['junk'][] = trim($matches[1]); - } - // but if nothing there, ignore - // remove the key in either case - unset($RIFFchunk[$chunkname][$thisindex]['data']); - } - } - } else { - $this->warning('Chunk "'.$chunkname.'" at offset '.$this->ftell().' is unexpectedly larger than 1MB (claims to be '.number_format($chunksize).' bytes), skipping data'); - $this->fseek($chunksize, SEEK_CUR); - } - break; - - //case 'IDVX': - // $info['divxtag']['comments'] = self::ParseDIVXTAG($this->fread($chunksize)); - // break; - - default: - if (!empty($LISTchunkParent) && (($RIFFchunk[$chunkname][$thisindex]['offset'] + $RIFFchunk[$chunkname][$thisindex]['size']) <= $LISTchunkMaxOffset)) { - $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['offset'] = $RIFFchunk[$chunkname][$thisindex]['offset']; - $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['size'] = $RIFFchunk[$chunkname][$thisindex]['size']; - unset($RIFFchunk[$chunkname][$thisindex]['offset']); - unset($RIFFchunk[$chunkname][$thisindex]['size']); - if (isset($RIFFchunk[$chunkname][$thisindex]) && empty($RIFFchunk[$chunkname][$thisindex])) { - unset($RIFFchunk[$chunkname][$thisindex]); - } - if (isset($RIFFchunk[$chunkname]) && empty($RIFFchunk[$chunkname])) { - unset($RIFFchunk[$chunkname]); - } - $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['data'] = $this->fread($chunksize); - } elseif ($chunksize < 2048) { - // only read data in if smaller than 2kB - $RIFFchunk[$chunkname][$thisindex]['data'] = $this->fread($chunksize); - } else { - $this->fseek($chunksize, SEEK_CUR); - } - break; - } - break; - } - } - - } catch (getid3_exception $e) { - if ($e->getCode() == 10) { - $this->warning('RIFF parser: '.$e->getMessage()); - } else { - throw $e; - } - } - - return $RIFFchunk; - } - - public function ParseRIFFdata(&$RIFFdata) { - $info = &$this->getid3->info; - if ($RIFFdata) { - $tempfile = tempnam(GETID3_TEMP_DIR, 'getID3'); - $fp_temp = fopen($tempfile, 'wb'); - $RIFFdataLength = strlen($RIFFdata); - $NewLengthString = getid3_lib::LittleEndian2String($RIFFdataLength, 4); - for ($i = 0; $i < 4; $i++) { - $RIFFdata[($i + 4)] = $NewLengthString[$i]; - } - fwrite($fp_temp, $RIFFdata); - fclose($fp_temp); - - $getid3_temp = new getID3(); - $getid3_temp->openfile($tempfile); - $getid3_temp->info['filesize'] = $RIFFdataLength; - $getid3_temp->info['filenamepath'] = $info['filenamepath']; - $getid3_temp->info['tags'] = $info['tags']; - $getid3_temp->info['warning'] = $info['warning']; - $getid3_temp->info['error'] = $info['error']; - $getid3_temp->info['comments'] = $info['comments']; - $getid3_temp->info['audio'] = (isset($info['audio']) ? $info['audio'] : array()); - $getid3_temp->info['video'] = (isset($info['video']) ? $info['video'] : array()); - $getid3_riff = new getid3_riff($getid3_temp); - $getid3_riff->Analyze(); - - $info['riff'] = $getid3_temp->info['riff']; - $info['warning'] = $getid3_temp->info['warning']; - $info['error'] = $getid3_temp->info['error']; - $info['tags'] = $getid3_temp->info['tags']; - $info['comments'] = $getid3_temp->info['comments']; - unset($getid3_riff, $getid3_temp); - unlink($tempfile); - } - return false; - } - - public static function parseComments(&$RIFFinfoArray, &$CommentsTargetArray) { - $RIFFinfoKeyLookup = array( - 'IARL'=>'archivallocation', - 'IART'=>'artist', - 'ICDS'=>'costumedesigner', - 'ICMS'=>'commissionedby', - 'ICMT'=>'comment', - 'ICNT'=>'country', - 'ICOP'=>'copyright', - 'ICRD'=>'creationdate', - 'IDIM'=>'dimensions', - 'IDIT'=>'digitizationdate', - 'IDPI'=>'resolution', - 'IDST'=>'distributor', - 'IEDT'=>'editor', - 'IENG'=>'engineers', - 'IFRM'=>'accountofparts', - 'IGNR'=>'genre', - 'IKEY'=>'keywords', - 'ILGT'=>'lightness', - 'ILNG'=>'language', - 'IMED'=>'orignalmedium', - 'IMUS'=>'composer', - 'INAM'=>'title', - 'IPDS'=>'productiondesigner', - 'IPLT'=>'palette', - 'IPRD'=>'product', - 'IPRO'=>'producer', - 'IPRT'=>'part', - 'IRTD'=>'rating', - 'ISBJ'=>'subject', - 'ISFT'=>'software', - 'ISGN'=>'secondarygenre', - 'ISHP'=>'sharpness', - 'ISRC'=>'sourcesupplier', - 'ISRF'=>'digitizationsource', - 'ISTD'=>'productionstudio', - 'ISTR'=>'starring', - 'ITCH'=>'encoded_by', - 'IWEB'=>'url', - 'IWRI'=>'writer', - '____'=>'comment', - ); - foreach ($RIFFinfoKeyLookup as $key => $value) { - if (isset($RIFFinfoArray[$key])) { - foreach ($RIFFinfoArray[$key] as $commentid => $commentdata) { - if (trim($commentdata['data']) != '') { - if (isset($CommentsTargetArray[$value])) { - $CommentsTargetArray[$value][] = trim($commentdata['data']); - } else { - $CommentsTargetArray[$value] = array(trim($commentdata['data'])); - } - } - } - } - } - return true; - } - - public static function parseWAVEFORMATex($WaveFormatExData) { - // shortcut - $WaveFormatEx['raw'] = array(); - $WaveFormatEx_raw = &$WaveFormatEx['raw']; - - $WaveFormatEx_raw['wFormatTag'] = substr($WaveFormatExData, 0, 2); - $WaveFormatEx_raw['nChannels'] = substr($WaveFormatExData, 2, 2); - $WaveFormatEx_raw['nSamplesPerSec'] = substr($WaveFormatExData, 4, 4); - $WaveFormatEx_raw['nAvgBytesPerSec'] = substr($WaveFormatExData, 8, 4); - $WaveFormatEx_raw['nBlockAlign'] = substr($WaveFormatExData, 12, 2); - $WaveFormatEx_raw['wBitsPerSample'] = substr($WaveFormatExData, 14, 2); - if (strlen($WaveFormatExData) > 16) { - $WaveFormatEx_raw['cbSize'] = substr($WaveFormatExData, 16, 2); - } - $WaveFormatEx_raw = array_map('getid3_lib::LittleEndian2Int', $WaveFormatEx_raw); - - $WaveFormatEx['codec'] = self::wFormatTagLookup($WaveFormatEx_raw['wFormatTag']); - $WaveFormatEx['channels'] = $WaveFormatEx_raw['nChannels']; - $WaveFormatEx['sample_rate'] = $WaveFormatEx_raw['nSamplesPerSec']; - $WaveFormatEx['bitrate'] = $WaveFormatEx_raw['nAvgBytesPerSec'] * 8; - $WaveFormatEx['bits_per_sample'] = $WaveFormatEx_raw['wBitsPerSample']; - - return $WaveFormatEx; - } - - public function parseWavPackHeader($WavPackChunkData) { - // typedef struct { - // char ckID [4]; - // long ckSize; - // short version; - // short bits; // added for version 2.00 - // short flags, shift; // added for version 3.00 - // long total_samples, crc, crc2; - // char extension [4], extra_bc, extras [3]; - // } WavpackHeader; - - // shortcut - $info = &$this->getid3->info; - $info['wavpack'] = array(); - $thisfile_wavpack = &$info['wavpack']; - - $thisfile_wavpack['version'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 0, 2)); - if ($thisfile_wavpack['version'] >= 2) { - $thisfile_wavpack['bits'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 2, 2)); - } - if ($thisfile_wavpack['version'] >= 3) { - $thisfile_wavpack['flags_raw'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 4, 2)); - $thisfile_wavpack['shift'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 6, 2)); - $thisfile_wavpack['total_samples'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 8, 4)); - $thisfile_wavpack['crc1'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 12, 4)); - $thisfile_wavpack['crc2'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 16, 4)); - $thisfile_wavpack['extension'] = substr($WavPackChunkData, 20, 4); - $thisfile_wavpack['extra_bc'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 24, 1)); - for ($i = 0; $i <= 2; $i++) { - $thisfile_wavpack['extras'][] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 25 + $i, 1)); - } - - // shortcut - $thisfile_wavpack['flags'] = array(); - $thisfile_wavpack_flags = &$thisfile_wavpack['flags']; - - $thisfile_wavpack_flags['mono'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000001); - $thisfile_wavpack_flags['fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000002); - $thisfile_wavpack_flags['raw_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000004); - $thisfile_wavpack_flags['calc_noise'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000008); - $thisfile_wavpack_flags['high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000010); - $thisfile_wavpack_flags['3_byte_samples'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000020); - $thisfile_wavpack_flags['over_20_bits'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000040); - $thisfile_wavpack_flags['use_wvc'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000080); - $thisfile_wavpack_flags['noiseshaping'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000100); - $thisfile_wavpack_flags['very_fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000200); - $thisfile_wavpack_flags['new_high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000400); - $thisfile_wavpack_flags['cancel_extreme'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000800); - $thisfile_wavpack_flags['cross_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x001000); - $thisfile_wavpack_flags['new_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x002000); - $thisfile_wavpack_flags['joint_stereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x004000); - $thisfile_wavpack_flags['extra_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x008000); - $thisfile_wavpack_flags['override_noiseshape'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x010000); - $thisfile_wavpack_flags['override_jointstereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x020000); - $thisfile_wavpack_flags['copy_source_filetime'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x040000); - $thisfile_wavpack_flags['create_exe'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x080000); - } - - return true; - } - - public static function ParseBITMAPINFOHEADER($BITMAPINFOHEADER, $littleEndian=true) { - - $parsed['biSize'] = substr($BITMAPINFOHEADER, 0, 4); // number of bytes required by the BITMAPINFOHEADER structure - $parsed['biWidth'] = substr($BITMAPINFOHEADER, 4, 4); // width of the bitmap in pixels - $parsed['biHeight'] = substr($BITMAPINFOHEADER, 8, 4); // height of the bitmap in pixels. If biHeight is positive, the bitmap is a 'bottom-up' DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a 'top-down' DIB and its origin is the upper left corner - $parsed['biPlanes'] = substr($BITMAPINFOHEADER, 12, 2); // number of color planes on the target device. In most cases this value must be set to 1 - $parsed['biBitCount'] = substr($BITMAPINFOHEADER, 14, 2); // Specifies the number of bits per pixels - $parsed['biSizeImage'] = substr($BITMAPINFOHEADER, 20, 4); // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures) - $parsed['biXPelsPerMeter'] = substr($BITMAPINFOHEADER, 24, 4); // horizontal resolution, in pixels per metre, of the target device - $parsed['biYPelsPerMeter'] = substr($BITMAPINFOHEADER, 28, 4); // vertical resolution, in pixels per metre, of the target device - $parsed['biClrUsed'] = substr($BITMAPINFOHEADER, 32, 4); // actual number of color indices in the color table used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression - $parsed['biClrImportant'] = substr($BITMAPINFOHEADER, 36, 4); // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important - $parsed = array_map('getid3_lib::'.($littleEndian ? 'Little' : 'Big').'Endian2Int', $parsed); - - $parsed['fourcc'] = substr($BITMAPINFOHEADER, 16, 4); // compression identifier - - return $parsed; - } - - public static function ParseDIVXTAG($DIVXTAG, $raw=false) { - // structure from "IDivX" source, Form1.frm, by "Greg Frazier of Daemonic Software Group", email: gfrazier@icestorm.net, web: http://dsg.cjb.net/ - // source available at http://files.divx-digest.com/download/c663efe7ef8ad2e90bf4af4d3ea6188a/on0SWN2r/edit/IDivX.zip - // 'Byte Layout: '1111111111111111 - // '32 for Movie - 1 '1111111111111111 - // '28 for Author - 6 '6666666666666666 - // '4 for year - 2 '6666666666662222 - // '3 for genre - 3 '7777777777777777 - // '48 for Comments - 7 '7777777777777777 - // '1 for Rating - 4 '7777777777777777 - // '5 for Future Additions - 0 '333400000DIVXTAG - // '128 bytes total - - static $DIVXTAGgenre = array( - 0 => 'Action', - 1 => 'Action/Adventure', - 2 => 'Adventure', - 3 => 'Adult', - 4 => 'Anime', - 5 => 'Cartoon', - 6 => 'Claymation', - 7 => 'Comedy', - 8 => 'Commercial', - 9 => 'Documentary', - 10 => 'Drama', - 11 => 'Home Video', - 12 => 'Horror', - 13 => 'Infomercial', - 14 => 'Interactive', - 15 => 'Mystery', - 16 => 'Music Video', - 17 => 'Other', - 18 => 'Religion', - 19 => 'Sci Fi', - 20 => 'Thriller', - 21 => 'Western', - ), - $DIVXTAGrating = array( - 0 => 'Unrated', - 1 => 'G', - 2 => 'PG', - 3 => 'PG-13', - 4 => 'R', - 5 => 'NC-17', - ); - - $parsed['title'] = trim(substr($DIVXTAG, 0, 32)); - $parsed['artist'] = trim(substr($DIVXTAG, 32, 28)); - $parsed['year'] = intval(trim(substr($DIVXTAG, 60, 4))); - $parsed['comment'] = trim(substr($DIVXTAG, 64, 48)); - $parsed['genre_id'] = intval(trim(substr($DIVXTAG, 112, 3))); - $parsed['rating_id'] = ord(substr($DIVXTAG, 115, 1)); - //$parsed['padding'] = substr($DIVXTAG, 116, 5); // 5-byte null - //$parsed['magic'] = substr($DIVXTAG, 121, 7); // "DIVXTAG" - - $parsed['genre'] = (isset($DIVXTAGgenre[$parsed['genre_id']]) ? $DIVXTAGgenre[$parsed['genre_id']] : $parsed['genre_id']); - $parsed['rating'] = (isset($DIVXTAGrating[$parsed['rating_id']]) ? $DIVXTAGrating[$parsed['rating_id']] : $parsed['rating_id']); - - if (!$raw) { - unset($parsed['genre_id'], $parsed['rating_id']); - foreach ($parsed as $key => $value) { - if (!$value === '') { - unset($parsed['key']); - } - } - } - - foreach ($parsed as $tag => $value) { - $parsed[$tag] = array($value); - } - - return $parsed; - } - - public static function waveSNDMtagLookup($tagshortname) { - $begin = __LINE__; - - /** This is not a comment! - - ©kwd keywords - ©BPM bpm - ©trt tracktitle - ©des description - ©gen category - ©fin featuredinstrument - ©LID longid - ©bex bwdescription - ©pub publisher - ©cdt cdtitle - ©alb library - ©com composer - - */ - - return getid3_lib::EmbeddedLookup($tagshortname, $begin, __LINE__, __FILE__, 'riff-sndm'); - } - - public static function wFormatTagLookup($wFormatTag) { - - $begin = __LINE__; - - /** This is not a comment! - - 0x0000 Microsoft Unknown Wave Format - 0x0001 Pulse Code Modulation (PCM) - 0x0002 Microsoft ADPCM - 0x0003 IEEE Float - 0x0004 Compaq Computer VSELP - 0x0005 IBM CVSD - 0x0006 Microsoft A-Law - 0x0007 Microsoft mu-Law - 0x0008 Microsoft DTS - 0x0010 OKI ADPCM - 0x0011 Intel DVI/IMA ADPCM - 0x0012 Videologic MediaSpace ADPCM - 0x0013 Sierra Semiconductor ADPCM - 0x0014 Antex Electronics G.723 ADPCM - 0x0015 DSP Solutions DigiSTD - 0x0016 DSP Solutions DigiFIX - 0x0017 Dialogic OKI ADPCM - 0x0018 MediaVision ADPCM - 0x0019 Hewlett-Packard CU - 0x0020 Yamaha ADPCM - 0x0021 Speech Compression Sonarc - 0x0022 DSP Group TrueSpeech - 0x0023 Echo Speech EchoSC1 - 0x0024 Audiofile AF36 - 0x0025 Audio Processing Technology APTX - 0x0026 AudioFile AF10 - 0x0027 Prosody 1612 - 0x0028 LRC - 0x0030 Dolby AC2 - 0x0031 Microsoft GSM 6.10 - 0x0032 MSNAudio - 0x0033 Antex Electronics ADPCME - 0x0034 Control Resources VQLPC - 0x0035 DSP Solutions DigiREAL - 0x0036 DSP Solutions DigiADPCM - 0x0037 Control Resources CR10 - 0x0038 Natural MicroSystems VBXADPCM - 0x0039 Crystal Semiconductor IMA ADPCM - 0x003A EchoSC3 - 0x003B Rockwell ADPCM - 0x003C Rockwell Digit LK - 0x003D Xebec - 0x0040 Antex Electronics G.721 ADPCM - 0x0041 G.728 CELP - 0x0042 MSG723 - 0x0050 MPEG Layer-2 or Layer-1 - 0x0052 RT24 - 0x0053 PAC - 0x0055 MPEG Layer-3 - 0x0059 Lucent G.723 - 0x0060 Cirrus - 0x0061 ESPCM - 0x0062 Voxware - 0x0063 Canopus Atrac - 0x0064 G.726 ADPCM - 0x0065 G.722 ADPCM - 0x0066 DSAT - 0x0067 DSAT Display - 0x0069 Voxware Byte Aligned - 0x0070 Voxware AC8 - 0x0071 Voxware AC10 - 0x0072 Voxware AC16 - 0x0073 Voxware AC20 - 0x0074 Voxware MetaVoice - 0x0075 Voxware MetaSound - 0x0076 Voxware RT29HW - 0x0077 Voxware VR12 - 0x0078 Voxware VR18 - 0x0079 Voxware TQ40 - 0x0080 Softsound - 0x0081 Voxware TQ60 - 0x0082 MSRT24 - 0x0083 G.729A - 0x0084 MVI MV12 - 0x0085 DF G.726 - 0x0086 DF GSM610 - 0x0088 ISIAudio - 0x0089 Onlive - 0x0091 SBC24 - 0x0092 Dolby AC3 SPDIF - 0x0093 MediaSonic G.723 - 0x0094 Aculab PLC Prosody 8kbps - 0x0097 ZyXEL ADPCM - 0x0098 Philips LPCBB - 0x0099 Packed - 0x00FF AAC - 0x0100 Rhetorex ADPCM - 0x0101 IBM mu-law - 0x0102 IBM A-law - 0x0103 IBM AVC Adaptive Differential Pulse Code Modulation (ADPCM) - 0x0111 Vivo G.723 - 0x0112 Vivo Siren - 0x0123 Digital G.723 - 0x0125 Sanyo LD ADPCM - 0x0130 Sipro Lab Telecom ACELP NET - 0x0131 Sipro Lab Telecom ACELP 4800 - 0x0132 Sipro Lab Telecom ACELP 8V3 - 0x0133 Sipro Lab Telecom G.729 - 0x0134 Sipro Lab Telecom G.729A - 0x0135 Sipro Lab Telecom Kelvin - 0x0140 Windows Media Video V8 - 0x0150 Qualcomm PureVoice - 0x0151 Qualcomm HalfRate - 0x0155 Ring Zero Systems TUB GSM - 0x0160 Microsoft Audio 1 - 0x0161 Windows Media Audio V7 / V8 / V9 - 0x0162 Windows Media Audio Professional V9 - 0x0163 Windows Media Audio Lossless V9 - 0x0200 Creative Labs ADPCM - 0x0202 Creative Labs Fastspeech8 - 0x0203 Creative Labs Fastspeech10 - 0x0210 UHER Informatic GmbH ADPCM - 0x0220 Quarterdeck - 0x0230 I-link Worldwide VC - 0x0240 Aureal RAW Sport - 0x0250 Interactive Products HSX - 0x0251 Interactive Products RPELP - 0x0260 Consistent Software CS2 - 0x0270 Sony SCX - 0x0300 Fujitsu FM Towns Snd - 0x0400 BTV Digital - 0x0401 Intel Music Coder - 0x0450 QDesign Music - 0x0680 VME VMPCM - 0x0681 AT&T Labs TPC - 0x08AE ClearJump LiteWave - 0x1000 Olivetti GSM - 0x1001 Olivetti ADPCM - 0x1002 Olivetti CELP - 0x1003 Olivetti SBC - 0x1004 Olivetti OPR - 0x1100 Lernout & Hauspie Codec (0x1100) - 0x1101 Lernout & Hauspie CELP Codec (0x1101) - 0x1102 Lernout & Hauspie SBC Codec (0x1102) - 0x1103 Lernout & Hauspie SBC Codec (0x1103) - 0x1104 Lernout & Hauspie SBC Codec (0x1104) - 0x1400 Norris - 0x1401 AT&T ISIAudio - 0x1500 Soundspace Music Compression - 0x181C VoxWare RT24 Speech - 0x1FC4 NCT Soft ALF2CD (www.nctsoft.com) - 0x2000 Dolby AC3 - 0x2001 Dolby DTS - 0x2002 WAVE_FORMAT_14_4 - 0x2003 WAVE_FORMAT_28_8 - 0x2004 WAVE_FORMAT_COOK - 0x2005 WAVE_FORMAT_DNET - 0x674F Ogg Vorbis 1 - 0x6750 Ogg Vorbis 2 - 0x6751 Ogg Vorbis 3 - 0x676F Ogg Vorbis 1+ - 0x6770 Ogg Vorbis 2+ - 0x6771 Ogg Vorbis 3+ - 0x7A21 GSM-AMR (CBR, no SID) - 0x7A22 GSM-AMR (VBR, including SID) - 0xFFFE WAVE_FORMAT_EXTENSIBLE - 0xFFFF WAVE_FORMAT_DEVELOPMENT - - */ - - return getid3_lib::EmbeddedLookup('0x'.str_pad(strtoupper(dechex($wFormatTag)), 4, '0', STR_PAD_LEFT), $begin, __LINE__, __FILE__, 'riff-wFormatTag'); - } - - public static function fourccLookup($fourcc) { - - $begin = __LINE__; - - /** This is not a comment! - - swot http://developer.apple.com/qa/snd/snd07.html - ____ No Codec (____) - _BIT BI_BITFIELDS (Raw RGB) - _JPG JPEG compressed - _PNG PNG compressed W3C/ISO/IEC (RFC-2083) - _RAW Full Frames (Uncompressed) - _RGB Raw RGB Bitmap - _RL4 RLE 4bpp RGB - _RL8 RLE 8bpp RGB - 3IV1 3ivx MPEG-4 v1 - 3IV2 3ivx MPEG-4 v2 - 3IVX 3ivx MPEG-4 - AASC Autodesk Animator - ABYR Kensington ?ABYR? - AEMI Array Microsystems VideoONE MPEG1-I Capture - AFLC Autodesk Animator FLC - AFLI Autodesk Animator FLI - AMPG Array Microsystems VideoONE MPEG - ANIM Intel RDX (ANIM) - AP41 AngelPotion Definitive - ASV1 Asus Video v1 - ASV2 Asus Video v2 - ASVX Asus Video 2.0 (audio) - AUR2 AuraVision Aura 2 Codec - YUV 4:2:2 - AURA AuraVision Aura 1 Codec - YUV 4:1:1 - AVDJ Independent JPEG Group\'s codec (AVDJ) - AVRN Independent JPEG Group\'s codec (AVRN) - AYUV 4:4:4 YUV (AYUV) - AZPR Quicktime Apple Video (AZPR) - BGR Raw RGB32 - BLZ0 Blizzard DivX MPEG-4 - BTVC Conexant Composite Video - BINK RAD Game Tools Bink Video - BT20 Conexant Prosumer Video - BTCV Conexant Composite Video Codec - BW10 Data Translation Broadway MPEG Capture - CC12 Intel YUV12 - CDVC Canopus DV - CFCC Digital Processing Systems DPS Perception - CGDI Microsoft Office 97 Camcorder Video - CHAM Winnov Caviara Champagne - CJPG Creative WebCam JPEG - CLJR Cirrus Logic YUV 4:1:1 - CMYK Common Data Format in Printing (Colorgraph) - CPLA Weitek 4:2:0 YUV Planar - CRAM Microsoft Video 1 (CRAM) - cvid Radius Cinepak - CVID Radius Cinepak - CWLT Microsoft Color WLT DIB - CYUV Creative Labs YUV - CYUY ATI YUV - D261 H.261 - D263 H.263 - DIB Device Independent Bitmap - DIV1 FFmpeg OpenDivX - DIV2 Microsoft MPEG-4 v1/v2 - DIV3 DivX ;-) MPEG-4 v3.x Low-Motion - DIV4 DivX ;-) MPEG-4 v3.x Fast-Motion - DIV5 DivX MPEG-4 v5.x - DIV6 DivX ;-) (MS MPEG-4 v3.x) - DIVX DivX MPEG-4 v4 (OpenDivX / Project Mayo) - divx DivX MPEG-4 - DMB1 Matrox Rainbow Runner hardware MJPEG - DMB2 Paradigm MJPEG - DSVD ?DSVD? - DUCK Duck TrueMotion 1.0 - DPS0 DPS/Leitch Reality Motion JPEG - DPSC DPS/Leitch PAR Motion JPEG - DV25 Matrox DVCPRO codec - DV50 Matrox DVCPRO50 codec - DVC IEC 61834 and SMPTE 314M (DVC/DV Video) - DVCP IEC 61834 and SMPTE 314M (DVC/DV Video) - DVHD IEC Standard DV 1125 lines @ 30fps / 1250 lines @ 25fps - DVMA Darim Vision DVMPEG (dummy for MPEG compressor) (www.darvision.com) - DVSL IEC Standard DV compressed in SD (SDL) - DVAN ?DVAN? - DVE2 InSoft DVE-2 Videoconferencing - dvsd IEC 61834 and SMPTE 314M DVC/DV Video - DVSD IEC 61834 and SMPTE 314M DVC/DV Video - DVX1 Lucent DVX1000SP Video Decoder - DVX2 Lucent DVX2000S Video Decoder - DVX3 Lucent DVX3000S Video Decoder - DX50 DivX v5 - DXT1 Microsoft DirectX Compressed Texture (DXT1) - DXT2 Microsoft DirectX Compressed Texture (DXT2) - DXT3 Microsoft DirectX Compressed Texture (DXT3) - DXT4 Microsoft DirectX Compressed Texture (DXT4) - DXT5 Microsoft DirectX Compressed Texture (DXT5) - DXTC Microsoft DirectX Compressed Texture (DXTC) - DXTn Microsoft DirectX Compressed Texture (DXTn) - EM2V Etymonix MPEG-2 I-frame (www.etymonix.com) - EKQ0 Elsa ?EKQ0? - ELK0 Elsa ?ELK0? - ESCP Eidos Escape - ETV1 eTreppid Video ETV1 - ETV2 eTreppid Video ETV2 - ETVC eTreppid Video ETVC - FLIC Autodesk FLI/FLC Animation - FLV1 Sorenson Spark - FLV4 On2 TrueMotion VP6 - FRWT Darim Vision Forward Motion JPEG (www.darvision.com) - FRWU Darim Vision Forward Uncompressed (www.darvision.com) - FLJP D-Vision Field Encoded Motion JPEG - FPS1 FRAPS v1 - FRWA SoftLab-Nsk Forward Motion JPEG w/ alpha channel - FRWD SoftLab-Nsk Forward Motion JPEG - FVF1 Iterated Systems Fractal Video Frame - GLZW Motion LZW (gabest@freemail.hu) - GPEG Motion JPEG (gabest@freemail.hu) - GWLT Microsoft Greyscale WLT DIB - H260 Intel ITU H.260 Videoconferencing - H261 Intel ITU H.261 Videoconferencing - H262 Intel ITU H.262 Videoconferencing - H263 Intel ITU H.263 Videoconferencing - H264 Intel ITU H.264 Videoconferencing - H265 Intel ITU H.265 Videoconferencing - H266 Intel ITU H.266 Videoconferencing - H267 Intel ITU H.267 Videoconferencing - H268 Intel ITU H.268 Videoconferencing - H269 Intel ITU H.269 Videoconferencing - HFYU Huffman Lossless Codec - HMCR Rendition Motion Compensation Format (HMCR) - HMRR Rendition Motion Compensation Format (HMRR) - I263 FFmpeg I263 decoder - IF09 Indeo YVU9 ("YVU9 with additional delta-frame info after the U plane") - IUYV Interlaced version of UYVY (www.leadtools.com) - IY41 Interlaced version of Y41P (www.leadtools.com) - IYU1 12 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard - IYU2 24 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard - IYUV Planar YUV format (8-bpp Y plane, followed by 8-bpp 2×2 U and V planes) - i263 Intel ITU H.263 Videoconferencing (i263) - I420 Intel Indeo 4 - IAN Intel Indeo 4 (RDX) - ICLB InSoft CellB Videoconferencing - IGOR Power DVD - IJPG Intergraph JPEG - ILVC Intel Layered Video - ILVR ITU-T H.263+ - IPDV I-O Data Device Giga AVI DV Codec - IR21 Intel Indeo 2.1 - IRAW Intel YUV Uncompressed - IV30 Intel Indeo 3.0 - IV31 Intel Indeo 3.1 - IV32 Ligos Indeo 3.2 - IV33 Ligos Indeo 3.3 - IV34 Ligos Indeo 3.4 - IV35 Ligos Indeo 3.5 - IV36 Ligos Indeo 3.6 - IV37 Ligos Indeo 3.7 - IV38 Ligos Indeo 3.8 - IV39 Ligos Indeo 3.9 - IV40 Ligos Indeo Interactive 4.0 - IV41 Ligos Indeo Interactive 4.1 - IV42 Ligos Indeo Interactive 4.2 - IV43 Ligos Indeo Interactive 4.3 - IV44 Ligos Indeo Interactive 4.4 - IV45 Ligos Indeo Interactive 4.5 - IV46 Ligos Indeo Interactive 4.6 - IV47 Ligos Indeo Interactive 4.7 - IV48 Ligos Indeo Interactive 4.8 - IV49 Ligos Indeo Interactive 4.9 - IV50 Ligos Indeo Interactive 5.0 - JBYR Kensington ?JBYR? - JPEG Still Image JPEG DIB - JPGL Pegasus Lossless Motion JPEG - KMVC Team17 Software Karl Morton\'s Video Codec - LSVM Vianet Lighting Strike Vmail (Streaming) (www.vianet.com) - LEAD LEAD Video Codec - Ljpg LEAD MJPEG Codec - MDVD Alex MicroDVD Video (hacked MS MPEG-4) (www.tiasoft.de) - MJPA Morgan Motion JPEG (MJPA) (www.morgan-multimedia.com) - MJPB Morgan Motion JPEG (MJPB) (www.morgan-multimedia.com) - MMES Matrox MPEG-2 I-frame - MP2v Microsoft S-Mpeg 4 version 1 (MP2v) - MP42 Microsoft S-Mpeg 4 version 2 (MP42) - MP43 Microsoft S-Mpeg 4 version 3 (MP43) - MP4S Microsoft S-Mpeg 4 version 3 (MP4S) - MP4V FFmpeg MPEG-4 - MPG1 FFmpeg MPEG 1/2 - MPG2 FFmpeg MPEG 1/2 - MPG3 FFmpeg DivX ;-) (MS MPEG-4 v3) - MPG4 Microsoft MPEG-4 - MPGI Sigma Designs MPEG - MPNG PNG images decoder - MSS1 Microsoft Windows Screen Video - MSZH LCL (Lossless Codec Library) (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm) - M261 Microsoft H.261 - M263 Microsoft H.263 - M4S2 Microsoft Fully Compliant MPEG-4 v2 simple profile (M4S2) - m4s2 Microsoft Fully Compliant MPEG-4 v2 simple profile (m4s2) - MC12 ATI Motion Compensation Format (MC12) - MCAM ATI Motion Compensation Format (MCAM) - MJ2C Morgan Multimedia Motion JPEG2000 - mJPG IBM Motion JPEG w/ Huffman Tables - MJPG Microsoft Motion JPEG DIB - MP42 Microsoft MPEG-4 (low-motion) - MP43 Microsoft MPEG-4 (fast-motion) - MP4S Microsoft MPEG-4 (MP4S) - mp4s Microsoft MPEG-4 (mp4s) - MPEG Chromatic Research MPEG-1 Video I-Frame - MPG4 Microsoft MPEG-4 Video High Speed Compressor - MPGI Sigma Designs MPEG - MRCA FAST Multimedia Martin Regen Codec - MRLE Microsoft Run Length Encoding - MSVC Microsoft Video 1 - MTX1 Matrox ?MTX1? - MTX2 Matrox ?MTX2? - MTX3 Matrox ?MTX3? - MTX4 Matrox ?MTX4? - MTX5 Matrox ?MTX5? - MTX6 Matrox ?MTX6? - MTX7 Matrox ?MTX7? - MTX8 Matrox ?MTX8? - MTX9 Matrox ?MTX9? - MV12 Motion Pixels Codec (old) - MWV1 Aware Motion Wavelets - nAVI SMR Codec (hack of Microsoft MPEG-4) (IRC #shadowrealm) - NT00 NewTek LightWave HDTV YUV w/ Alpha (www.newtek.com) - NUV1 NuppelVideo - NTN1 Nogatech Video Compression 1 - NVS0 nVidia GeForce Texture (NVS0) - NVS1 nVidia GeForce Texture (NVS1) - NVS2 nVidia GeForce Texture (NVS2) - NVS3 nVidia GeForce Texture (NVS3) - NVS4 nVidia GeForce Texture (NVS4) - NVS5 nVidia GeForce Texture (NVS5) - NVT0 nVidia GeForce Texture (NVT0) - NVT1 nVidia GeForce Texture (NVT1) - NVT2 nVidia GeForce Texture (NVT2) - NVT3 nVidia GeForce Texture (NVT3) - NVT4 nVidia GeForce Texture (NVT4) - NVT5 nVidia GeForce Texture (NVT5) - PIXL MiroXL, Pinnacle PCTV - PDVC I-O Data Device Digital Video Capture DV codec - PGVV Radius Video Vision - PHMO IBM Photomotion - PIM1 MPEG Realtime (Pinnacle Cards) - PIM2 Pegasus Imaging ?PIM2? - PIMJ Pegasus Imaging Lossless JPEG - PVEZ Horizons Technology PowerEZ - PVMM PacketVideo Corporation MPEG-4 - PVW2 Pegasus Imaging Wavelet Compression - Q1.0 Q-Team\'s QPEG 1.0 (www.q-team.de) - Q1.1 Q-Team\'s QPEG 1.1 (www.q-team.de) - QPEG Q-Team QPEG 1.0 - qpeq Q-Team QPEG 1.1 - RGB Raw BGR32 - RGBA Raw RGB w/ Alpha - RMP4 REALmagic MPEG-4 (unauthorized XVID copy) (www.sigmadesigns.com) - ROQV Id RoQ File Video Decoder - RPZA Quicktime Apple Video (RPZA) - RUD0 Rududu video codec (http://rududu.ifrance.com/rududu/) - RV10 RealVideo 1.0 (aka RealVideo 5.0) - RV13 RealVideo 1.0 (RV13) - RV20 RealVideo G2 - RV30 RealVideo 8 - RV40 RealVideo 9 - RGBT Raw RGB w/ Transparency - RLE Microsoft Run Length Encoder - RLE4 Run Length Encoded (4bpp, 16-color) - RLE8 Run Length Encoded (8bpp, 256-color) - RT21 Intel Indeo RealTime Video 2.1 - rv20 RealVideo G2 - rv30 RealVideo 8 - RVX Intel RDX (RVX ) - SMC Apple Graphics (SMC ) - SP54 Logitech Sunplus Sp54 Codec for Mustek GSmart Mini 2 - SPIG Radius Spigot - SVQ3 Sorenson Video 3 (Apple Quicktime 5) - s422 Tekram VideoCap C210 YUV 4:2:2 - SDCC Sun Communication Digital Camera Codec - SFMC CrystalNet Surface Fitting Method - SMSC Radius SMSC - SMSD Radius SMSD - smsv WorldConnect Wavelet Video - SPIG Radius Spigot - SPLC Splash Studios ACM Audio Codec (www.splashstudios.net) - SQZ2 Microsoft VXTreme Video Codec V2 - STVA ST Microelectronics CMOS Imager Data (Bayer) - STVB ST Microelectronics CMOS Imager Data (Nudged Bayer) - STVC ST Microelectronics CMOS Imager Data (Bunched) - STVX ST Microelectronics CMOS Imager Data (Extended CODEC Data Format) - STVY ST Microelectronics CMOS Imager Data (Extended CODEC Data Format with Correction Data) - SV10 Sorenson Video R1 - SVQ1 Sorenson Video - T420 Toshiba YUV 4:2:0 - TM2A Duck TrueMotion Archiver 2.0 (www.duck.com) - TVJP Pinnacle/Truevision Targa 2000 board (TVJP) - TVMJ Pinnacle/Truevision Targa 2000 board (TVMJ) - TY0N Tecomac Low-Bit Rate Codec (www.tecomac.com) - TY2C Trident Decompression Driver - TLMS TeraLogic Motion Intraframe Codec (TLMS) - TLST TeraLogic Motion Intraframe Codec (TLST) - TM20 Duck TrueMotion 2.0 - TM2X Duck TrueMotion 2X - TMIC TeraLogic Motion Intraframe Codec (TMIC) - TMOT Horizons Technology TrueMotion S - tmot Horizons TrueMotion Video Compression - TR20 Duck TrueMotion RealTime 2.0 - TSCC TechSmith Screen Capture Codec - TV10 Tecomac Low-Bit Rate Codec - TY2N Trident ?TY2N? - U263 UB Video H.263/H.263+/H.263++ Decoder - UMP4 UB Video MPEG 4 (www.ubvideo.com) - UYNV Nvidia UYVY packed 4:2:2 - UYVP Evans & Sutherland YCbCr 4:2:2 extended precision - UCOD eMajix.com ClearVideo - ULTI IBM Ultimotion - UYVY UYVY packed 4:2:2 - V261 Lucent VX2000S - VIFP VFAPI Reader Codec (www.yks.ne.jp/~hori/) - VIV1 FFmpeg H263+ decoder - VIV2 Vivo H.263 - VQC2 Vector-quantised codec 2 (research) http://eprints.ecs.soton.ac.uk/archive/00001310/01/VTC97-js.pdf) - VTLP Alaris VideoGramPiX - VYU9 ATI YUV (VYU9) - VYUY ATI YUV (VYUY) - V261 Lucent VX2000S - V422 Vitec Multimedia 24-bit YUV 4:2:2 Format - V655 Vitec Multimedia 16-bit YUV 4:2:2 Format - VCR1 ATI Video Codec 1 - VCR2 ATI Video Codec 2 - VCR3 ATI VCR 3.0 - VCR4 ATI VCR 4.0 - VCR5 ATI VCR 5.0 - VCR6 ATI VCR 6.0 - VCR7 ATI VCR 7.0 - VCR8 ATI VCR 8.0 - VCR9 ATI VCR 9.0 - VDCT Vitec Multimedia Video Maker Pro DIB - VDOM VDOnet VDOWave - VDOW VDOnet VDOLive (H.263) - VDTZ Darim Vison VideoTizer YUV - VGPX Alaris VideoGramPiX - VIDS Vitec Multimedia YUV 4:2:2 CCIR 601 for V422 - VIVO Vivo H.263 v2.00 - vivo Vivo H.263 - VIXL Miro/Pinnacle Video XL - VLV1 VideoLogic/PURE Digital Videologic Capture - VP30 On2 VP3.0 - VP31 On2 VP3.1 - VP6F On2 TrueMotion VP6 - VX1K Lucent VX1000S Video Codec - VX2K Lucent VX2000S Video Codec - VXSP Lucent VX1000SP Video Codec - WBVC Winbond W9960 - WHAM Microsoft Video 1 (WHAM) - WINX Winnov Software Compression - WJPG AverMedia Winbond JPEG - WMV1 Windows Media Video V7 - WMV2 Windows Media Video V8 - WMV3 Windows Media Video V9 - WNV1 Winnov Hardware Compression - XYZP Extended PAL format XYZ palette (www.riff.org) - x263 Xirlink H.263 - XLV0 NetXL Video Decoder - XMPG Xing MPEG (I-Frame only) - XVID XviD MPEG-4 (www.xvid.org) - XXAN ?XXAN? - YU92 Intel YUV (YU92) - YUNV Nvidia Uncompressed YUV 4:2:2 - YUVP Extended PAL format YUV palette (www.riff.org) - Y211 YUV 2:1:1 Packed - Y411 YUV 4:1:1 Packed - Y41B Weitek YUV 4:1:1 Planar - Y41P Brooktree PC1 YUV 4:1:1 Packed - Y41T Brooktree PC1 YUV 4:1:1 with transparency - Y42B Weitek YUV 4:2:2 Planar - Y42T Brooktree UYUV 4:2:2 with transparency - Y422 ADS Technologies Copy of UYVY used in Pyro WebCam firewire camera - Y800 Simple, single Y plane for monochrome images - Y8 Grayscale video - YC12 Intel YUV 12 codec - YUV8 Winnov Caviar YUV8 - YUV9 Intel YUV9 - YUY2 Uncompressed YUV 4:2:2 - YUYV Canopus YUV - YV12 YVU12 Planar - YVU9 Intel YVU9 Planar (8-bpp Y plane, followed by 8-bpp 4x4 U and V planes) - YVYU YVYU 4:2:2 Packed - ZLIB Lossless Codec Library zlib compression (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm) - ZPEG Metheus Video Zipper - - */ - - return getid3_lib::EmbeddedLookup($fourcc, $begin, __LINE__, __FILE__, 'riff-fourcc'); - } - - private function EitherEndian2Int($byteword, $signed=false) { - if ($this->container == 'riff') { - return getid3_lib::LittleEndian2Int($byteword, $signed); - } - return getid3_lib::BigEndian2Int($byteword, false, $signed); - } - -} \ No newline at end of file + break; + + default: + $this->error('Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA|WEBP), found "'.$RIFFsubtype.'" instead'); + //unset($info['fileformat']); + } + + switch ($RIFFsubtype) { + case 'WAVE': + case 'AIFF': + case 'AIFC': + $ID3v2_key_good = 'id3 '; + $ID3v2_keys_bad = ['ID3 ', 'tag ']; + foreach ($ID3v2_keys_bad as $ID3v2_key_bad) { + if (isset($thisfile_riff[$RIFFsubtype][$ID3v2_key_bad]) && ! array_key_exists($ID3v2_key_good, $thisfile_riff[$RIFFsubtype])) { + $thisfile_riff[$RIFFsubtype][$ID3v2_key_good] = $thisfile_riff[$RIFFsubtype][$ID3v2_key_bad]; + $this->warning('mapping "'.$ID3v2_key_bad.'" chunk to "'.$ID3v2_key_good.'"'); + } + } + + if (isset($thisfile_riff[$RIFFsubtype]['id3 '])) { + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); + + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_id3v2 = new getid3_id3v2($getid3_temp); + $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['id3 '][0]['offset'] + 8; + if ($thisfile_riff[$RIFFsubtype]['id3 '][0]['valid'] = $getid3_id3v2->Analyze()) { + $info['id3v2'] = $getid3_temp->info['id3v2']; + } + unset($getid3_temp, $getid3_id3v2); + } + break; + } + + if (isset($thisfile_riff_WAVE['DISP']) && is_array($thisfile_riff_WAVE['DISP'])) { + $thisfile_riff['comments']['title'][] = trim(substr($thisfile_riff_WAVE['DISP'][count($thisfile_riff_WAVE['DISP']) - 1]['data'], 4)); + } + if (isset($thisfile_riff_WAVE['INFO']) && is_array($thisfile_riff_WAVE['INFO'])) { + self::parseComments($thisfile_riff_WAVE['INFO'], $thisfile_riff['comments']); + } + if (isset($thisfile_riff['AVI ']['INFO']) && is_array($thisfile_riff['AVI ']['INFO'])) { + self::parseComments($thisfile_riff['AVI ']['INFO'], $thisfile_riff['comments']); + } + + if (empty($thisfile_audio['encoder']) && ! empty($info['mpeg']['audio']['LAME']['short_version'])) { + $thisfile_audio['encoder'] = $info['mpeg']['audio']['LAME']['short_version']; + } + + if (! isset($info['playtime_seconds'])) { + $info['playtime_seconds'] = 0; + } + if (isset($thisfile_riff_raw['strh'][0]['dwLength']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) { + // needed for >2GB AVIs where 'avih' chunk only lists number of frames in that chunk, not entire movie + $info['playtime_seconds'] = $thisfile_riff_raw['strh'][0]['dwLength'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000); + } elseif (isset($thisfile_riff_raw['avih']['dwTotalFrames']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) { + $info['playtime_seconds'] = $thisfile_riff_raw['avih']['dwTotalFrames'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000); + } + + if ($info['playtime_seconds'] > 0) { + if (isset($thisfile_riff_audio) && isset($thisfile_riff_video)) { + if (! isset($info['bitrate'])) { + $info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8); + } + } elseif (isset($thisfile_riff_audio) && ! isset($thisfile_riff_video)) { + if (! isset($thisfile_audio['bitrate'])) { + $thisfile_audio['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8); + } + } elseif (! isset($thisfile_riff_audio) && isset($thisfile_riff_video)) { + if (! isset($thisfile_video['bitrate'])) { + $thisfile_video['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8); + } + } + } + + if (isset($thisfile_riff_video) && isset($thisfile_audio['bitrate']) && ($thisfile_audio['bitrate'] > 0) && ($info['playtime_seconds'] > 0)) { + $info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8); + $thisfile_audio['bitrate'] = 0; + $thisfile_video['bitrate'] = $info['bitrate']; + foreach ($thisfile_riff_audio as $channelnumber => $audioinfoarray) { + $thisfile_video['bitrate'] -= $audioinfoarray['bitrate']; + $thisfile_audio['bitrate'] += $audioinfoarray['bitrate']; + } + if ($thisfile_video['bitrate'] <= 0) { + unset($thisfile_video['bitrate']); + } + if ($thisfile_audio['bitrate'] <= 0) { + unset($thisfile_audio['bitrate']); + } + } + + if (isset($info['mpeg']['audio'])) { + $thisfile_audio_dataformat = 'mp'.$info['mpeg']['audio']['layer']; + $thisfile_audio['sample_rate'] = $info['mpeg']['audio']['sample_rate']; + $thisfile_audio['channels'] = $info['mpeg']['audio']['channels']; + $thisfile_audio['bitrate'] = $info['mpeg']['audio']['bitrate']; + $thisfile_audio['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); + if (! empty($info['mpeg']['audio']['codec'])) { + $thisfile_audio['codec'] = $info['mpeg']['audio']['codec'].' '.$thisfile_audio['codec']; + } + if (! empty($thisfile_audio['streams'])) { + foreach ($thisfile_audio['streams'] as $streamnumber => $streamdata) { + if ($streamdata['dataformat'] == $thisfile_audio_dataformat) { + $thisfile_audio['streams'][$streamnumber]['sample_rate'] = $thisfile_audio['sample_rate']; + $thisfile_audio['streams'][$streamnumber]['channels'] = $thisfile_audio['channels']; + $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate']; + $thisfile_audio['streams'][$streamnumber]['bitrate_mode'] = $thisfile_audio['bitrate_mode']; + $thisfile_audio['streams'][$streamnumber]['codec'] = $thisfile_audio['codec']; + } + } + } + $getid3_mp3 = new getid3_mp3($this->getid3); + $thisfile_audio['encoder_options'] = $getid3_mp3->GuessEncoderOptions(); + unset($getid3_mp3); + } + + if (! empty($thisfile_riff_raw['fmt ']['wBitsPerSample']) && ($thisfile_riff_raw['fmt ']['wBitsPerSample'] > 0)) { + switch ($thisfile_audio_dataformat) { + case 'ac3': + // ignore bits_per_sample + break; + + default: + $thisfile_audio['bits_per_sample'] = $thisfile_riff_raw['fmt ']['wBitsPerSample']; + break; + } + } + + if (empty($thisfile_riff_raw)) { + unset($thisfile_riff['raw']); + } + if (empty($thisfile_riff_audio)) { + unset($thisfile_riff['audio']); + } + if (empty($thisfile_riff_video)) { + unset($thisfile_riff['video']); + } + + return true; + } + + public function ParseRIFFAMV($startoffset, $maxoffset) + { + // AMV files are RIFF-AVI files with parts of the spec deliberately broken, such as chunk size fields hardcoded to zero (because players known in hardware that these fields are always a certain size + + // https://code.google.com/p/amv-codec-tools/wiki/AmvDocumentation + //typedef struct _amvmainheader { + //FOURCC fcc; // 'amvh' + //DWORD cb; + //DWORD dwMicroSecPerFrame; + //BYTE reserve[28]; + //DWORD dwWidth; + //DWORD dwHeight; + //DWORD dwSpeed; + //DWORD reserve0; + //DWORD reserve1; + //BYTE bTimeSec; + //BYTE bTimeMin; + //WORD wTimeHour; + //} AMVMAINHEADER; + + $info = &$this->getid3->info; + $RIFFchunk = false; + + try { + $this->fseek($startoffset); + $maxoffset = min($maxoffset, $info['avdataend']); + $AMVheader = $this->fread(284); + if (substr($AMVheader, 0, 8) != 'hdrlamvh') { + throw new Exception('expecting "hdrlamv" at offset '.($startoffset + 0).', found "'.substr($AMVheader, 0, 8).'"'); + } + if (substr($AMVheader, 8, 4) != "\x38\x00\x00\x00") { // "amvh" chunk size, hardcoded to 0x38 = 56 bytes + throw new Exception('expecting "0x38000000" at offset '.($startoffset + 8).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 8, 4)).'"'); + } + $RIFFchunk = []; + $RIFFchunk['amvh']['us_per_frame'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 12, 4)); + $RIFFchunk['amvh']['reserved28'] = substr($AMVheader, 16, 28); // null? reserved? + $RIFFchunk['amvh']['resolution_x'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 44, 4)); + $RIFFchunk['amvh']['resolution_y'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 48, 4)); + $RIFFchunk['amvh']['frame_rate_int'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 52, 4)); + $RIFFchunk['amvh']['reserved0'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 56, 4)); // 1? reserved? + $RIFFchunk['amvh']['reserved1'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 60, 4)); // 0? reserved? + $RIFFchunk['amvh']['runtime_sec'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 64, 1)); + $RIFFchunk['amvh']['runtime_min'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 65, 1)); + $RIFFchunk['amvh']['runtime_hrs'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 66, 2)); + + $info['video']['frame_rate'] = 1000000 / $RIFFchunk['amvh']['us_per_frame']; + $info['video']['resolution_x'] = $RIFFchunk['amvh']['resolution_x']; + $info['video']['resolution_y'] = $RIFFchunk['amvh']['resolution_y']; + $info['playtime_seconds'] = ($RIFFchunk['amvh']['runtime_hrs'] * 3600) + ($RIFFchunk['amvh']['runtime_min'] * 60) + $RIFFchunk['amvh']['runtime_sec']; + + // the rest is all hardcoded(?) and does not appear to be useful until you get to audio info at offset 256, even then everything is probably hardcoded + + if (substr($AMVheader, 68, 20) != 'LIST'."\x00\x00\x00\x00".'strlstrh'."\x38\x00\x00\x00") { + throw new Exception('expecting "LIST<0x00000000>strlstrh<0x38000000>" at offset '.($startoffset + 68).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 68, 20)).'"'); + } + // followed by 56 bytes of null: substr($AMVheader, 88, 56) -> 144 + if (substr($AMVheader, 144, 8) != 'strf'."\x24\x00\x00\x00") { + throw new Exception('expecting "strf<0x24000000>" at offset '.($startoffset + 144).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 144, 8)).'"'); + } + // followed by 36 bytes of null: substr($AMVheader, 144, 36) -> 180 + + if (substr($AMVheader, 188, 20) != 'LIST'."\x00\x00\x00\x00".'strlstrh'."\x30\x00\x00\x00") { + throw new Exception('expecting "LIST<0x00000000>strlstrh<0x30000000>" at offset '.($startoffset + 188).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 188, 20)).'"'); + } + // followed by 48 bytes of null: substr($AMVheader, 208, 48) -> 256 + if (substr($AMVheader, 256, 8) != 'strf'."\x14\x00\x00\x00") { + throw new Exception('expecting "strf<0x14000000>" at offset '.($startoffset + 256).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 256, 8)).'"'); + } + // followed by 20 bytes of a modified WAVEFORMATEX: + // typedef struct { + // WORD wFormatTag; //(Fixme: this is equal to PCM's 0x01 format code) + // WORD nChannels; //(Fixme: this is always 1) + // DWORD nSamplesPerSec; //(Fixme: for all known sample files this is equal to 22050) + // DWORD nAvgBytesPerSec; //(Fixme: for all known sample files this is equal to 44100) + // WORD nBlockAlign; //(Fixme: this seems to be 2 in AMV files, is this correct ?) + // WORD wBitsPerSample; //(Fixme: this seems to be 16 in AMV files instead of the expected 4) + // WORD cbSize; //(Fixme: this seems to be 0 in AMV files) + // WORD reserved; + // } WAVEFORMATEX; + $RIFFchunk['strf']['wformattag'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 264, 2)); + $RIFFchunk['strf']['nchannels'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 266, 2)); + $RIFFchunk['strf']['nsamplespersec'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 268, 4)); + $RIFFchunk['strf']['navgbytespersec'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 272, 4)); + $RIFFchunk['strf']['nblockalign'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 276, 2)); + $RIFFchunk['strf']['wbitspersample'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 278, 2)); + $RIFFchunk['strf']['cbsize'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 280, 2)); + $RIFFchunk['strf']['reserved'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 282, 2)); + + $info['audio']['lossless'] = false; + $info['audio']['sample_rate'] = $RIFFchunk['strf']['nsamplespersec']; + $info['audio']['channels'] = $RIFFchunk['strf']['nchannels']; + $info['audio']['bits_per_sample'] = $RIFFchunk['strf']['wbitspersample']; + $info['audio']['bitrate'] = $info['audio']['sample_rate'] * $info['audio']['channels'] * $info['audio']['bits_per_sample']; + $info['audio']['bitrate_mode'] = 'cbr'; + } catch (getid3_exception $e) { + if ($e->getCode() == 10) { + $this->warning('RIFFAMV parser: '.$e->getMessage()); + } else { + throw $e; + } + } + + return $RIFFchunk; + } + + public function ParseRIFF($startoffset, $maxoffset) + { + $info = &$this->getid3->info; + + $RIFFchunk = false; + $FoundAllChunksWeNeed = false; + + try { + $this->fseek($startoffset); + $maxoffset = min($maxoffset, $info['avdataend']); + while ($this->ftell() < $maxoffset) { + $chunknamesize = $this->fread(8); + //$chunkname = substr($chunknamesize, 0, 4); + $chunkname = str_replace("\x00", '_', substr($chunknamesize, 0, 4)); // note: chunk names of 4 null bytes do appear to be legal (has been observed inside INFO and PRMI chunks, for example), but makes traversing array keys more difficult + $chunksize = $this->EitherEndian2Int(substr($chunknamesize, 4, 4)); + //if (strlen(trim($chunkname, "\x00")) < 4) { + if (strlen($chunkname) < 4) { + $this->error('Expecting chunk name at offset '.($this->ftell() - 8).' but found nothing. Aborting RIFF parsing.'); + break; + } + if (($chunksize == 0) && ($chunkname != 'JUNK')) { + $this->warning('Chunk ('.$chunkname.') size at offset '.($this->ftell() - 4).' is zero. Aborting RIFF parsing.'); + break; + } + if (($chunksize % 2) != 0) { + // all structures are packed on word boundaries + $chunksize++; + } + + switch ($chunkname) { + case 'LIST': + $listname = $this->fread(4); + if (preg_match('#^(movi|rec )$#i', $listname)) { + $RIFFchunk[$listname]['offset'] = $this->ftell() - 4; + $RIFFchunk[$listname]['size'] = $chunksize; + + if (! $FoundAllChunksWeNeed) { + $WhereWeWere = $this->ftell(); + $AudioChunkHeader = $this->fread(12); + $AudioChunkStreamNum = substr($AudioChunkHeader, 0, 2); + $AudioChunkStreamType = substr($AudioChunkHeader, 2, 2); + $AudioChunkSize = getid3_lib::LittleEndian2Int(substr($AudioChunkHeader, 4, 4)); + + if ($AudioChunkStreamType == 'wb') { + $FirstFourBytes = substr($AudioChunkHeader, 8, 4); + if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', $FirstFourBytes)) { + // MP3 + if (getid3_mp3::MPEGaudioHeaderBytesValid($FirstFourBytes)) { + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_temp->info['avdataoffset'] = $this->ftell() - 4; + $getid3_temp->info['avdataend'] = $this->ftell() + $AudioChunkSize; + $getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__); + $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false); + if (isset($getid3_temp->info['mpeg']['audio'])) { + $info['mpeg']['audio'] = $getid3_temp->info['mpeg']['audio']; + $info['audio'] = $getid3_temp->info['audio']; + $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer']; + $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; + $info['audio']['channels'] = $info['mpeg']['audio']['channels']; + $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; + $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); + //$info['bitrate'] = $info['audio']['bitrate']; + } + unset($getid3_temp, $getid3_mp3); + } + } elseif (strpos($FirstFourBytes, getid3_ac3::syncword) === 0) { + + // AC3 + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_temp->info['avdataoffset'] = $this->ftell() - 4; + $getid3_temp->info['avdataend'] = $this->ftell() + $AudioChunkSize; + $getid3_ac3 = new getid3_ac3($getid3_temp); + $getid3_ac3->Analyze(); + if (empty($getid3_temp->info['error'])) { + $info['audio'] = $getid3_temp->info['audio']; + $info['ac3'] = $getid3_temp->info['ac3']; + if (! empty($getid3_temp->info['warning'])) { + foreach ($getid3_temp->info['warning'] as $key => $value) { + $this->warning($value); + } + } + } + unset($getid3_temp, $getid3_ac3); + } + } + $FoundAllChunksWeNeed = true; + $this->fseek($WhereWeWere); + } + $this->fseek($chunksize - 4, SEEK_CUR); + } else { + if (! isset($RIFFchunk[$listname])) { + $RIFFchunk[$listname] = []; + } + $LISTchunkParent = $listname; + $LISTchunkMaxOffset = $this->ftell() - 4 + $chunksize; + if ($parsedChunk = $this->ParseRIFF($this->ftell(), $LISTchunkMaxOffset)) { + $RIFFchunk[$listname] = array_merge_recursive($RIFFchunk[$listname], $parsedChunk); + } + } + break; + + default: + if (preg_match('#^[0-9]{2}(wb|pc|dc|db)$#', $chunkname)) { + $this->fseek($chunksize, SEEK_CUR); + break; + } + $thisindex = 0; + if (isset($RIFFchunk[$chunkname]) && is_array($RIFFchunk[$chunkname])) { + $thisindex = count($RIFFchunk[$chunkname]); + } + $RIFFchunk[$chunkname][$thisindex]['offset'] = $this->ftell() - 8; + $RIFFchunk[$chunkname][$thisindex]['size'] = $chunksize; + switch ($chunkname) { + case 'data': + $info['avdataoffset'] = $this->ftell(); + $info['avdataend'] = $info['avdataoffset'] + $chunksize; + + $testData = $this->fread(36); + if ($testData === '') { + break; + } + if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', substr($testData, 0, 4))) { + + // Probably is MP3 data + if (getid3_mp3::MPEGaudioHeaderBytesValid(substr($testData, 0, 4))) { + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; + $getid3_temp->info['avdataend'] = $info['avdataend']; + $getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__); + $getid3_mp3->getOnlyMPEGaudioInfo($info['avdataoffset'], false); + if (empty($getid3_temp->info['error'])) { + $info['audio'] = $getid3_temp->info['audio']; + $info['mpeg'] = $getid3_temp->info['mpeg']; + } + unset($getid3_temp, $getid3_mp3); + } + } elseif (($isRegularAC3 = (substr($testData, 0, 2) == getid3_ac3::syncword)) || substr($testData, 8, 2) == strrev(getid3_ac3::syncword)) { + + // This is probably AC-3 data + $getid3_temp = new getID3(); + if ($isRegularAC3) { + $getid3_temp->openfile($this->getid3->filename); + $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; + $getid3_temp->info['avdataend'] = $info['avdataend']; + } + $getid3_ac3 = new getid3_ac3($getid3_temp); + if ($isRegularAC3) { + $getid3_ac3->Analyze(); + } else { + // Dolby Digital WAV + // AC-3 content, but not encoded in same format as normal AC-3 file + // For one thing, byte order is swapped + $ac3_data = ''; + for ($i = 0; $i < 28; $i += 2) { + $ac3_data .= substr($testData, 8 + $i + 1, 1); + $ac3_data .= substr($testData, 8 + $i + 0, 1); + } + $getid3_ac3->AnalyzeString($ac3_data); + } + + if (empty($getid3_temp->info['error'])) { + $info['audio'] = $getid3_temp->info['audio']; + $info['ac3'] = $getid3_temp->info['ac3']; + if (! empty($getid3_temp->info['warning'])) { + foreach ($getid3_temp->info['warning'] as $newerror) { + $this->warning('getid3_ac3() says: ['.$newerror.']'); + } + } + } + unset($getid3_temp, $getid3_ac3); + } elseif (preg_match('/^('.implode('|', array_map('preg_quote', getid3_dts::$syncwords)).')/', $testData)) { + + // This is probably DTS data + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; + $getid3_dts = new getid3_dts($getid3_temp); + $getid3_dts->Analyze(); + if (empty($getid3_temp->info['error'])) { + $info['audio'] = $getid3_temp->info['audio']; + $info['dts'] = $getid3_temp->info['dts']; + $info['playtime_seconds'] = $getid3_temp->info['playtime_seconds']; // may not match RIFF calculations since DTS-WAV often used 14/16 bit-word packing + if (! empty($getid3_temp->info['warning'])) { + foreach ($getid3_temp->info['warning'] as $newerror) { + $this->warning('getid3_dts() says: ['.$newerror.']'); + } + } + } + + unset($getid3_temp, $getid3_dts); + } elseif (substr($testData, 0, 4) == 'wvpk') { + + // This is WavPack data + $info['wavpack']['offset'] = $info['avdataoffset']; + $info['wavpack']['size'] = getid3_lib::LittleEndian2Int(substr($testData, 4, 4)); + $this->parseWavPackHeader(substr($testData, 8, 28)); + } else { + // This is some other kind of data (quite possibly just PCM) + // do nothing special, just skip it + } + $nextoffset = $info['avdataend']; + $this->fseek($nextoffset); + break; + + case 'iXML': + case 'bext': + case 'cart': + case 'fmt ': + case 'strh': + case 'strf': + case 'indx': + case 'MEXT': + case 'DISP': + // always read data in + case 'JUNK': + // should be: never read data in + // but some programs write their version strings in a JUNK chunk (e.g. VirtualDub, AVIdemux, etc) + if ($chunksize < 1048576) { + if ($chunksize > 0) { + $RIFFchunk[$chunkname][$thisindex]['data'] = $this->fread($chunksize); + if ($chunkname == 'JUNK') { + if (preg_match('#^([\\x20-\\x7F]+)#', $RIFFchunk[$chunkname][$thisindex]['data'], $matches)) { + // only keep text characters [chr(32)-chr(127)] + $info['riff']['comments']['junk'][] = trim($matches[1]); + } + // but if nothing there, ignore + // remove the key in either case + unset($RIFFchunk[$chunkname][$thisindex]['data']); + } + } + } else { + $this->warning('Chunk "'.$chunkname.'" at offset '.$this->ftell().' is unexpectedly larger than 1MB (claims to be '.number_format($chunksize).' bytes), skipping data'); + $this->fseek($chunksize, SEEK_CUR); + } + break; + + //case 'IDVX': + // $info['divxtag']['comments'] = self::ParseDIVXTAG($this->fread($chunksize)); + // break; + + default: + if (! empty($LISTchunkParent) && (($RIFFchunk[$chunkname][$thisindex]['offset'] + $RIFFchunk[$chunkname][$thisindex]['size']) <= $LISTchunkMaxOffset)) { + $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['offset'] = $RIFFchunk[$chunkname][$thisindex]['offset']; + $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['size'] = $RIFFchunk[$chunkname][$thisindex]['size']; + unset($RIFFchunk[$chunkname][$thisindex]['offset']); + unset($RIFFchunk[$chunkname][$thisindex]['size']); + if (isset($RIFFchunk[$chunkname][$thisindex]) && empty($RIFFchunk[$chunkname][$thisindex])) { + unset($RIFFchunk[$chunkname][$thisindex]); + } + if (isset($RIFFchunk[$chunkname]) && empty($RIFFchunk[$chunkname])) { + unset($RIFFchunk[$chunkname]); + } + $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['data'] = $this->fread($chunksize); + } elseif ($chunksize < 2048) { + // only read data in if smaller than 2kB + $RIFFchunk[$chunkname][$thisindex]['data'] = $this->fread($chunksize); + } else { + $this->fseek($chunksize, SEEK_CUR); + } + break; + } + break; + } + } + } catch (getid3_exception $e) { + if ($e->getCode() == 10) { + $this->warning('RIFF parser: '.$e->getMessage()); + } else { + throw $e; + } + } + + return $RIFFchunk; + } + + public function ParseRIFFdata(&$RIFFdata) + { + $info = &$this->getid3->info; + if ($RIFFdata) { + $tempfile = tempnam(GETID3_TEMP_DIR, 'getID3'); + $fp_temp = fopen($tempfile, 'wb'); + $RIFFdataLength = strlen($RIFFdata); + $NewLengthString = getid3_lib::LittleEndian2String($RIFFdataLength, 4); + for ($i = 0; $i < 4; $i++) { + $RIFFdata[($i + 4)] = $NewLengthString[$i]; + } + fwrite($fp_temp, $RIFFdata); + fclose($fp_temp); + + $getid3_temp = new getID3(); + $getid3_temp->openfile($tempfile); + $getid3_temp->info['filesize'] = $RIFFdataLength; + $getid3_temp->info['filenamepath'] = $info['filenamepath']; + $getid3_temp->info['tags'] = $info['tags']; + $getid3_temp->info['warning'] = $info['warning']; + $getid3_temp->info['error'] = $info['error']; + $getid3_temp->info['comments'] = $info['comments']; + $getid3_temp->info['audio'] = (isset($info['audio']) ? $info['audio'] : []); + $getid3_temp->info['video'] = (isset($info['video']) ? $info['video'] : []); + $getid3_riff = new self($getid3_temp); + $getid3_riff->Analyze(); + + $info['riff'] = $getid3_temp->info['riff']; + $info['warning'] = $getid3_temp->info['warning']; + $info['error'] = $getid3_temp->info['error']; + $info['tags'] = $getid3_temp->info['tags']; + $info['comments'] = $getid3_temp->info['comments']; + unset($getid3_riff, $getid3_temp); + unlink($tempfile); + } + + return false; + } + + public static function parseComments(&$RIFFinfoArray, &$CommentsTargetArray) + { + $RIFFinfoKeyLookup = [ + 'IARL'=>'archivallocation', + 'IART'=>'artist', + 'ICDS'=>'costumedesigner', + 'ICMS'=>'commissionedby', + 'ICMT'=>'comment', + 'ICNT'=>'country', + 'ICOP'=>'copyright', + 'ICRD'=>'creationdate', + 'IDIM'=>'dimensions', + 'IDIT'=>'digitizationdate', + 'IDPI'=>'resolution', + 'IDST'=>'distributor', + 'IEDT'=>'editor', + 'IENG'=>'engineers', + 'IFRM'=>'accountofparts', + 'IGNR'=>'genre', + 'IKEY'=>'keywords', + 'ILGT'=>'lightness', + 'ILNG'=>'language', + 'IMED'=>'orignalmedium', + 'IMUS'=>'composer', + 'INAM'=>'title', + 'IPDS'=>'productiondesigner', + 'IPLT'=>'palette', + 'IPRD'=>'product', + 'IPRO'=>'producer', + 'IPRT'=>'part', + 'IRTD'=>'rating', + 'ISBJ'=>'subject', + 'ISFT'=>'software', + 'ISGN'=>'secondarygenre', + 'ISHP'=>'sharpness', + 'ISRC'=>'sourcesupplier', + 'ISRF'=>'digitizationsource', + 'ISTD'=>'productionstudio', + 'ISTR'=>'starring', + 'ITCH'=>'encoded_by', + 'IWEB'=>'url', + 'IWRI'=>'writer', + '____'=>'comment', + ]; + foreach ($RIFFinfoKeyLookup as $key => $value) { + if (isset($RIFFinfoArray[$key])) { + foreach ($RIFFinfoArray[$key] as $commentid => $commentdata) { + if (trim($commentdata['data']) != '') { + if (isset($CommentsTargetArray[$value])) { + $CommentsTargetArray[$value][] = trim($commentdata['data']); + } else { + $CommentsTargetArray[$value] = [trim($commentdata['data'])]; + } + } + } + } + } + + return true; + } + + public static function parseWAVEFORMATex($WaveFormatExData) + { + // shortcut + $WaveFormatEx['raw'] = []; + $WaveFormatEx_raw = &$WaveFormatEx['raw']; + + $WaveFormatEx_raw['wFormatTag'] = substr($WaveFormatExData, 0, 2); + $WaveFormatEx_raw['nChannels'] = substr($WaveFormatExData, 2, 2); + $WaveFormatEx_raw['nSamplesPerSec'] = substr($WaveFormatExData, 4, 4); + $WaveFormatEx_raw['nAvgBytesPerSec'] = substr($WaveFormatExData, 8, 4); + $WaveFormatEx_raw['nBlockAlign'] = substr($WaveFormatExData, 12, 2); + $WaveFormatEx_raw['wBitsPerSample'] = substr($WaveFormatExData, 14, 2); + if (strlen($WaveFormatExData) > 16) { + $WaveFormatEx_raw['cbSize'] = substr($WaveFormatExData, 16, 2); + } + $WaveFormatEx_raw = array_map('getid3_lib::LittleEndian2Int', $WaveFormatEx_raw); + + $WaveFormatEx['codec'] = self::wFormatTagLookup($WaveFormatEx_raw['wFormatTag']); + $WaveFormatEx['channels'] = $WaveFormatEx_raw['nChannels']; + $WaveFormatEx['sample_rate'] = $WaveFormatEx_raw['nSamplesPerSec']; + $WaveFormatEx['bitrate'] = $WaveFormatEx_raw['nAvgBytesPerSec'] * 8; + $WaveFormatEx['bits_per_sample'] = $WaveFormatEx_raw['wBitsPerSample']; + + return $WaveFormatEx; + } + + public function parseWavPackHeader($WavPackChunkData) + { + // typedef struct { + // char ckID [4]; + // long ckSize; + // short version; + // short bits; // added for version 2.00 + // short flags, shift; // added for version 3.00 + // long total_samples, crc, crc2; + // char extension [4], extra_bc, extras [3]; + // } WavpackHeader; + + // shortcut + $info = &$this->getid3->info; + $info['wavpack'] = []; + $thisfile_wavpack = &$info['wavpack']; + + $thisfile_wavpack['version'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 0, 2)); + if ($thisfile_wavpack['version'] >= 2) { + $thisfile_wavpack['bits'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 2, 2)); + } + if ($thisfile_wavpack['version'] >= 3) { + $thisfile_wavpack['flags_raw'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 4, 2)); + $thisfile_wavpack['shift'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 6, 2)); + $thisfile_wavpack['total_samples'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 8, 4)); + $thisfile_wavpack['crc1'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 12, 4)); + $thisfile_wavpack['crc2'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 16, 4)); + $thisfile_wavpack['extension'] = substr($WavPackChunkData, 20, 4); + $thisfile_wavpack['extra_bc'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 24, 1)); + for ($i = 0; $i <= 2; $i++) { + $thisfile_wavpack['extras'][] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 25 + $i, 1)); + } + + // shortcut + $thisfile_wavpack['flags'] = []; + $thisfile_wavpack_flags = &$thisfile_wavpack['flags']; + + $thisfile_wavpack_flags['mono'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000001); + $thisfile_wavpack_flags['fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000002); + $thisfile_wavpack_flags['raw_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000004); + $thisfile_wavpack_flags['calc_noise'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000008); + $thisfile_wavpack_flags['high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000010); + $thisfile_wavpack_flags['3_byte_samples'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000020); + $thisfile_wavpack_flags['over_20_bits'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000040); + $thisfile_wavpack_flags['use_wvc'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000080); + $thisfile_wavpack_flags['noiseshaping'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000100); + $thisfile_wavpack_flags['very_fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000200); + $thisfile_wavpack_flags['new_high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000400); + $thisfile_wavpack_flags['cancel_extreme'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000800); + $thisfile_wavpack_flags['cross_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x001000); + $thisfile_wavpack_flags['new_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x002000); + $thisfile_wavpack_flags['joint_stereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x004000); + $thisfile_wavpack_flags['extra_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x008000); + $thisfile_wavpack_flags['override_noiseshape'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x010000); + $thisfile_wavpack_flags['override_jointstereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x020000); + $thisfile_wavpack_flags['copy_source_filetime'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x040000); + $thisfile_wavpack_flags['create_exe'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x080000); + } + + return true; + } + + public static function ParseBITMAPINFOHEADER($BITMAPINFOHEADER, $littleEndian = true) + { + $parsed['biSize'] = substr($BITMAPINFOHEADER, 0, 4); // number of bytes required by the BITMAPINFOHEADER structure + $parsed['biWidth'] = substr($BITMAPINFOHEADER, 4, 4); // width of the bitmap in pixels + $parsed['biHeight'] = substr($BITMAPINFOHEADER, 8, 4); // height of the bitmap in pixels. If biHeight is positive, the bitmap is a 'bottom-up' DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a 'top-down' DIB and its origin is the upper left corner + $parsed['biPlanes'] = substr($BITMAPINFOHEADER, 12, 2); // number of color planes on the target device. In most cases this value must be set to 1 + $parsed['biBitCount'] = substr($BITMAPINFOHEADER, 14, 2); // Specifies the number of bits per pixels + $parsed['biSizeImage'] = substr($BITMAPINFOHEADER, 20, 4); // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures) + $parsed['biXPelsPerMeter'] = substr($BITMAPINFOHEADER, 24, 4); // horizontal resolution, in pixels per metre, of the target device + $parsed['biYPelsPerMeter'] = substr($BITMAPINFOHEADER, 28, 4); // vertical resolution, in pixels per metre, of the target device + $parsed['biClrUsed'] = substr($BITMAPINFOHEADER, 32, 4); // actual number of color indices in the color table used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression + $parsed['biClrImportant'] = substr($BITMAPINFOHEADER, 36, 4); // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important + $parsed = array_map('getid3_lib::'.($littleEndian ? 'Little' : 'Big').'Endian2Int', $parsed); + + $parsed['fourcc'] = substr($BITMAPINFOHEADER, 16, 4); // compression identifier + + return $parsed; + } + + public static function ParseDIVXTAG($DIVXTAG, $raw = false) + { + // structure from "IDivX" source, Form1.frm, by "Greg Frazier of Daemonic Software Group", email: gfrazier@icestorm.net, web: http://dsg.cjb.net/ + // source available at http://files.divx-digest.com/download/c663efe7ef8ad2e90bf4af4d3ea6188a/on0SWN2r/edit/IDivX.zip + // 'Byte Layout: '1111111111111111 + // '32 for Movie - 1 '1111111111111111 + // '28 for Author - 6 '6666666666666666 + // '4 for year - 2 '6666666666662222 + // '3 for genre - 3 '7777777777777777 + // '48 for Comments - 7 '7777777777777777 + // '1 for Rating - 4 '7777777777777777 + // '5 for Future Additions - 0 '333400000DIVXTAG + // '128 bytes total + + static $DIVXTAGgenre = [ + 0 => 'Action', + 1 => 'Action/Adventure', + 2 => 'Adventure', + 3 => 'Adult', + 4 => 'Anime', + 5 => 'Cartoon', + 6 => 'Claymation', + 7 => 'Comedy', + 8 => 'Commercial', + 9 => 'Documentary', + 10 => 'Drama', + 11 => 'Home Video', + 12 => 'Horror', + 13 => 'Infomercial', + 14 => 'Interactive', + 15 => 'Mystery', + 16 => 'Music Video', + 17 => 'Other', + 18 => 'Religion', + 19 => 'Sci Fi', + 20 => 'Thriller', + 21 => 'Western', + ], + $DIVXTAGrating = [ + 0 => 'Unrated', + 1 => 'G', + 2 => 'PG', + 3 => 'PG-13', + 4 => 'R', + 5 => 'NC-17', + ]; + + $parsed['title'] = trim(substr($DIVXTAG, 0, 32)); + $parsed['artist'] = trim(substr($DIVXTAG, 32, 28)); + $parsed['year'] = intval(trim(substr($DIVXTAG, 60, 4))); + $parsed['comment'] = trim(substr($DIVXTAG, 64, 48)); + $parsed['genre_id'] = intval(trim(substr($DIVXTAG, 112, 3))); + $parsed['rating_id'] = ord(substr($DIVXTAG, 115, 1)); + //$parsed['padding'] = substr($DIVXTAG, 116, 5); // 5-byte null + //$parsed['magic'] = substr($DIVXTAG, 121, 7); // "DIVXTAG" + + $parsed['genre'] = (isset($DIVXTAGgenre[$parsed['genre_id']]) ? $DIVXTAGgenre[$parsed['genre_id']] : $parsed['genre_id']); + $parsed['rating'] = (isset($DIVXTAGrating[$parsed['rating_id']]) ? $DIVXTAGrating[$parsed['rating_id']] : $parsed['rating_id']); + + if (! $raw) { + unset($parsed['genre_id'], $parsed['rating_id']); + foreach ($parsed as $key => $value) { + if (! $value === '') { + unset($parsed['key']); + } + } + } + + foreach ($parsed as $tag => $value) { + $parsed[$tag] = [$value]; + } + + return $parsed; + } + + public static function waveSNDMtagLookup($tagshortname) + { + $begin = __LINE__; + + /** This is not a comment! + + ©kwd keywords + ©BPM bpm + ©trt tracktitle + ©des description + ©gen category + ©fin featuredinstrument + ©LID longid + ©bex bwdescription + ©pub publisher + ©cdt cdtitle + ©alb library + ©com composer + */ + + return getid3_lib::EmbeddedLookup($tagshortname, $begin, __LINE__, __FILE__, 'riff-sndm'); + } + + public static function wFormatTagLookup($wFormatTag) + { + $begin = __LINE__; + + /** This is not a comment! + + 0x0000 Microsoft Unknown Wave Format + 0x0001 Pulse Code Modulation (PCM) + 0x0002 Microsoft ADPCM + 0x0003 IEEE Float + 0x0004 Compaq Computer VSELP + 0x0005 IBM CVSD + 0x0006 Microsoft A-Law + 0x0007 Microsoft mu-Law + 0x0008 Microsoft DTS + 0x0010 OKI ADPCM + 0x0011 Intel DVI/IMA ADPCM + 0x0012 Videologic MediaSpace ADPCM + 0x0013 Sierra Semiconductor ADPCM + 0x0014 Antex Electronics G.723 ADPCM + 0x0015 DSP Solutions DigiSTD + 0x0016 DSP Solutions DigiFIX + 0x0017 Dialogic OKI ADPCM + 0x0018 MediaVision ADPCM + 0x0019 Hewlett-Packard CU + 0x0020 Yamaha ADPCM + 0x0021 Speech Compression Sonarc + 0x0022 DSP Group TrueSpeech + 0x0023 Echo Speech EchoSC1 + 0x0024 Audiofile AF36 + 0x0025 Audio Processing Technology APTX + 0x0026 AudioFile AF10 + 0x0027 Prosody 1612 + 0x0028 LRC + 0x0030 Dolby AC2 + 0x0031 Microsoft GSM 6.10 + 0x0032 MSNAudio + 0x0033 Antex Electronics ADPCME + 0x0034 Control Resources VQLPC + 0x0035 DSP Solutions DigiREAL + 0x0036 DSP Solutions DigiADPCM + 0x0037 Control Resources CR10 + 0x0038 Natural MicroSystems VBXADPCM + 0x0039 Crystal Semiconductor IMA ADPCM + 0x003A EchoSC3 + 0x003B Rockwell ADPCM + 0x003C Rockwell Digit LK + 0x003D Xebec + 0x0040 Antex Electronics G.721 ADPCM + 0x0041 G.728 CELP + 0x0042 MSG723 + 0x0050 MPEG Layer-2 or Layer-1 + 0x0052 RT24 + 0x0053 PAC + 0x0055 MPEG Layer-3 + 0x0059 Lucent G.723 + 0x0060 Cirrus + 0x0061 ESPCM + 0x0062 Voxware + 0x0063 Canopus Atrac + 0x0064 G.726 ADPCM + 0x0065 G.722 ADPCM + 0x0066 DSAT + 0x0067 DSAT Display + 0x0069 Voxware Byte Aligned + 0x0070 Voxware AC8 + 0x0071 Voxware AC10 + 0x0072 Voxware AC16 + 0x0073 Voxware AC20 + 0x0074 Voxware MetaVoice + 0x0075 Voxware MetaSound + 0x0076 Voxware RT29HW + 0x0077 Voxware VR12 + 0x0078 Voxware VR18 + 0x0079 Voxware TQ40 + 0x0080 Softsound + 0x0081 Voxware TQ60 + 0x0082 MSRT24 + 0x0083 G.729A + 0x0084 MVI MV12 + 0x0085 DF G.726 + 0x0086 DF GSM610 + 0x0088 ISIAudio + 0x0089 Onlive + 0x0091 SBC24 + 0x0092 Dolby AC3 SPDIF + 0x0093 MediaSonic G.723 + 0x0094 Aculab PLC Prosody 8kbps + 0x0097 ZyXEL ADPCM + 0x0098 Philips LPCBB + 0x0099 Packed + 0x00FF AAC + 0x0100 Rhetorex ADPCM + 0x0101 IBM mu-law + 0x0102 IBM A-law + 0x0103 IBM AVC Adaptive Differential Pulse Code Modulation (ADPCM) + 0x0111 Vivo G.723 + 0x0112 Vivo Siren + 0x0123 Digital G.723 + 0x0125 Sanyo LD ADPCM + 0x0130 Sipro Lab Telecom ACELP NET + 0x0131 Sipro Lab Telecom ACELP 4800 + 0x0132 Sipro Lab Telecom ACELP 8V3 + 0x0133 Sipro Lab Telecom G.729 + 0x0134 Sipro Lab Telecom G.729A + 0x0135 Sipro Lab Telecom Kelvin + 0x0140 Windows Media Video V8 + 0x0150 Qualcomm PureVoice + 0x0151 Qualcomm HalfRate + 0x0155 Ring Zero Systems TUB GSM + 0x0160 Microsoft Audio 1 + 0x0161 Windows Media Audio V7 / V8 / V9 + 0x0162 Windows Media Audio Professional V9 + 0x0163 Windows Media Audio Lossless V9 + 0x0200 Creative Labs ADPCM + 0x0202 Creative Labs Fastspeech8 + 0x0203 Creative Labs Fastspeech10 + 0x0210 UHER Informatic GmbH ADPCM + 0x0220 Quarterdeck + 0x0230 I-link Worldwide VC + 0x0240 Aureal RAW Sport + 0x0250 Interactive Products HSX + 0x0251 Interactive Products RPELP + 0x0260 Consistent Software CS2 + 0x0270 Sony SCX + 0x0300 Fujitsu FM Towns Snd + 0x0400 BTV Digital + 0x0401 Intel Music Coder + 0x0450 QDesign Music + 0x0680 VME VMPCM + 0x0681 AT&T Labs TPC + 0x08AE ClearJump LiteWave + 0x1000 Olivetti GSM + 0x1001 Olivetti ADPCM + 0x1002 Olivetti CELP + 0x1003 Olivetti SBC + 0x1004 Olivetti OPR + 0x1100 Lernout & Hauspie Codec (0x1100) + 0x1101 Lernout & Hauspie CELP Codec (0x1101) + 0x1102 Lernout & Hauspie SBC Codec (0x1102) + 0x1103 Lernout & Hauspie SBC Codec (0x1103) + 0x1104 Lernout & Hauspie SBC Codec (0x1104) + 0x1400 Norris + 0x1401 AT&T ISIAudio + 0x1500 Soundspace Music Compression + 0x181C VoxWare RT24 Speech + 0x1FC4 NCT Soft ALF2CD (www.nctsoft.com) + 0x2000 Dolby AC3 + 0x2001 Dolby DTS + 0x2002 WAVE_FORMAT_14_4 + 0x2003 WAVE_FORMAT_28_8 + 0x2004 WAVE_FORMAT_COOK + 0x2005 WAVE_FORMAT_DNET + 0x674F Ogg Vorbis 1 + 0x6750 Ogg Vorbis 2 + 0x6751 Ogg Vorbis 3 + 0x676F Ogg Vorbis 1+ + 0x6770 Ogg Vorbis 2+ + 0x6771 Ogg Vorbis 3+ + 0x7A21 GSM-AMR (CBR, no SID) + 0x7A22 GSM-AMR (VBR, including SID) + 0xFFFE WAVE_FORMAT_EXTENSIBLE + 0xFFFF WAVE_FORMAT_DEVELOPMENT + */ + + return getid3_lib::EmbeddedLookup('0x'.str_pad(strtoupper(dechex($wFormatTag)), 4, '0', STR_PAD_LEFT), $begin, __LINE__, __FILE__, 'riff-wFormatTag'); + } + + public static function fourccLookup($fourcc) + { + $begin = __LINE__; + + /** This is not a comment! + + swot http://developer.apple.com/qa/snd/snd07.html + ____ No Codec (____) + _BIT BI_BITFIELDS (Raw RGB) + _JPG JPEG compressed + _PNG PNG compressed W3C/ISO/IEC (RFC-2083) + _RAW Full Frames (Uncompressed) + _RGB Raw RGB Bitmap + _RL4 RLE 4bpp RGB + _RL8 RLE 8bpp RGB + 3IV1 3ivx MPEG-4 v1 + 3IV2 3ivx MPEG-4 v2 + 3IVX 3ivx MPEG-4 + AASC Autodesk Animator + ABYR Kensington ?ABYR? + AEMI Array Microsystems VideoONE MPEG1-I Capture + AFLC Autodesk Animator FLC + AFLI Autodesk Animator FLI + AMPG Array Microsystems VideoONE MPEG + ANIM Intel RDX (ANIM) + AP41 AngelPotion Definitive + ASV1 Asus Video v1 + ASV2 Asus Video v2 + ASVX Asus Video 2.0 (audio) + AUR2 AuraVision Aura 2 Codec - YUV 4:2:2 + AURA AuraVision Aura 1 Codec - YUV 4:1:1 + AVDJ Independent JPEG Group\'s codec (AVDJ) + AVRN Independent JPEG Group\'s codec (AVRN) + AYUV 4:4:4 YUV (AYUV) + AZPR Quicktime Apple Video (AZPR) + BGR Raw RGB32 + BLZ0 Blizzard DivX MPEG-4 + BTVC Conexant Composite Video + BINK RAD Game Tools Bink Video + BT20 Conexant Prosumer Video + BTCV Conexant Composite Video Codec + BW10 Data Translation Broadway MPEG Capture + CC12 Intel YUV12 + CDVC Canopus DV + CFCC Digital Processing Systems DPS Perception + CGDI Microsoft Office 97 Camcorder Video + CHAM Winnov Caviara Champagne + CJPG Creative WebCam JPEG + CLJR Cirrus Logic YUV 4:1:1 + CMYK Common Data Format in Printing (Colorgraph) + CPLA Weitek 4:2:0 YUV Planar + CRAM Microsoft Video 1 (CRAM) + cvid Radius Cinepak + CVID Radius Cinepak + CWLT Microsoft Color WLT DIB + CYUV Creative Labs YUV + CYUY ATI YUV + D261 H.261 + D263 H.263 + DIB Device Independent Bitmap + DIV1 FFmpeg OpenDivX + DIV2 Microsoft MPEG-4 v1/v2 + DIV3 DivX ;-) MPEG-4 v3.x Low-Motion + DIV4 DivX ;-) MPEG-4 v3.x Fast-Motion + DIV5 DivX MPEG-4 v5.x + DIV6 DivX ;-) (MS MPEG-4 v3.x) + DIVX DivX MPEG-4 v4 (OpenDivX / Project Mayo) + divx DivX MPEG-4 + DMB1 Matrox Rainbow Runner hardware MJPEG + DMB2 Paradigm MJPEG + DSVD ?DSVD? + DUCK Duck TrueMotion 1.0 + DPS0 DPS/Leitch Reality Motion JPEG + DPSC DPS/Leitch PAR Motion JPEG + DV25 Matrox DVCPRO codec + DV50 Matrox DVCPRO50 codec + DVC IEC 61834 and SMPTE 314M (DVC/DV Video) + DVCP IEC 61834 and SMPTE 314M (DVC/DV Video) + DVHD IEC Standard DV 1125 lines @ 30fps / 1250 lines @ 25fps + DVMA Darim Vision DVMPEG (dummy for MPEG compressor) (www.darvision.com) + DVSL IEC Standard DV compressed in SD (SDL) + DVAN ?DVAN? + DVE2 InSoft DVE-2 Videoconferencing + dvsd IEC 61834 and SMPTE 314M DVC/DV Video + DVSD IEC 61834 and SMPTE 314M DVC/DV Video + DVX1 Lucent DVX1000SP Video Decoder + DVX2 Lucent DVX2000S Video Decoder + DVX3 Lucent DVX3000S Video Decoder + DX50 DivX v5 + DXT1 Microsoft DirectX Compressed Texture (DXT1) + DXT2 Microsoft DirectX Compressed Texture (DXT2) + DXT3 Microsoft DirectX Compressed Texture (DXT3) + DXT4 Microsoft DirectX Compressed Texture (DXT4) + DXT5 Microsoft DirectX Compressed Texture (DXT5) + DXTC Microsoft DirectX Compressed Texture (DXTC) + DXTn Microsoft DirectX Compressed Texture (DXTn) + EM2V Etymonix MPEG-2 I-frame (www.etymonix.com) + EKQ0 Elsa ?EKQ0? + ELK0 Elsa ?ELK0? + ESCP Eidos Escape + ETV1 eTreppid Video ETV1 + ETV2 eTreppid Video ETV2 + ETVC eTreppid Video ETVC + FLIC Autodesk FLI/FLC Animation + FLV1 Sorenson Spark + FLV4 On2 TrueMotion VP6 + FRWT Darim Vision Forward Motion JPEG (www.darvision.com) + FRWU Darim Vision Forward Uncompressed (www.darvision.com) + FLJP D-Vision Field Encoded Motion JPEG + FPS1 FRAPS v1 + FRWA SoftLab-Nsk Forward Motion JPEG w/ alpha channel + FRWD SoftLab-Nsk Forward Motion JPEG + FVF1 Iterated Systems Fractal Video Frame + GLZW Motion LZW (gabest@freemail.hu) + GPEG Motion JPEG (gabest@freemail.hu) + GWLT Microsoft Greyscale WLT DIB + H260 Intel ITU H.260 Videoconferencing + H261 Intel ITU H.261 Videoconferencing + H262 Intel ITU H.262 Videoconferencing + H263 Intel ITU H.263 Videoconferencing + H264 Intel ITU H.264 Videoconferencing + H265 Intel ITU H.265 Videoconferencing + H266 Intel ITU H.266 Videoconferencing + H267 Intel ITU H.267 Videoconferencing + H268 Intel ITU H.268 Videoconferencing + H269 Intel ITU H.269 Videoconferencing + HFYU Huffman Lossless Codec + HMCR Rendition Motion Compensation Format (HMCR) + HMRR Rendition Motion Compensation Format (HMRR) + I263 FFmpeg I263 decoder + IF09 Indeo YVU9 ("YVU9 with additional delta-frame info after the U plane") + IUYV Interlaced version of UYVY (www.leadtools.com) + IY41 Interlaced version of Y41P (www.leadtools.com) + IYU1 12 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard + IYU2 24 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard + IYUV Planar YUV format (8-bpp Y plane, followed by 8-bpp 2×2 U and V planes) + i263 Intel ITU H.263 Videoconferencing (i263) + I420 Intel Indeo 4 + IAN Intel Indeo 4 (RDX) + ICLB InSoft CellB Videoconferencing + IGOR Power DVD + IJPG Intergraph JPEG + ILVC Intel Layered Video + ILVR ITU-T H.263+ + IPDV I-O Data Device Giga AVI DV Codec + IR21 Intel Indeo 2.1 + IRAW Intel YUV Uncompressed + IV30 Intel Indeo 3.0 + IV31 Intel Indeo 3.1 + IV32 Ligos Indeo 3.2 + IV33 Ligos Indeo 3.3 + IV34 Ligos Indeo 3.4 + IV35 Ligos Indeo 3.5 + IV36 Ligos Indeo 3.6 + IV37 Ligos Indeo 3.7 + IV38 Ligos Indeo 3.8 + IV39 Ligos Indeo 3.9 + IV40 Ligos Indeo Interactive 4.0 + IV41 Ligos Indeo Interactive 4.1 + IV42 Ligos Indeo Interactive 4.2 + IV43 Ligos Indeo Interactive 4.3 + IV44 Ligos Indeo Interactive 4.4 + IV45 Ligos Indeo Interactive 4.5 + IV46 Ligos Indeo Interactive 4.6 + IV47 Ligos Indeo Interactive 4.7 + IV48 Ligos Indeo Interactive 4.8 + IV49 Ligos Indeo Interactive 4.9 + IV50 Ligos Indeo Interactive 5.0 + JBYR Kensington ?JBYR? + JPEG Still Image JPEG DIB + JPGL Pegasus Lossless Motion JPEG + KMVC Team17 Software Karl Morton\'s Video Codec + LSVM Vianet Lighting Strike Vmail (Streaming) (www.vianet.com) + LEAD LEAD Video Codec + Ljpg LEAD MJPEG Codec + MDVD Alex MicroDVD Video (hacked MS MPEG-4) (www.tiasoft.de) + MJPA Morgan Motion JPEG (MJPA) (www.morgan-multimedia.com) + MJPB Morgan Motion JPEG (MJPB) (www.morgan-multimedia.com) + MMES Matrox MPEG-2 I-frame + MP2v Microsoft S-Mpeg 4 version 1 (MP2v) + MP42 Microsoft S-Mpeg 4 version 2 (MP42) + MP43 Microsoft S-Mpeg 4 version 3 (MP43) + MP4S Microsoft S-Mpeg 4 version 3 (MP4S) + MP4V FFmpeg MPEG-4 + MPG1 FFmpeg MPEG 1/2 + MPG2 FFmpeg MPEG 1/2 + MPG3 FFmpeg DivX ;-) (MS MPEG-4 v3) + MPG4 Microsoft MPEG-4 + MPGI Sigma Designs MPEG + MPNG PNG images decoder + MSS1 Microsoft Windows Screen Video + MSZH LCL (Lossless Codec Library) (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm) + M261 Microsoft H.261 + M263 Microsoft H.263 + M4S2 Microsoft Fully Compliant MPEG-4 v2 simple profile (M4S2) + m4s2 Microsoft Fully Compliant MPEG-4 v2 simple profile (m4s2) + MC12 ATI Motion Compensation Format (MC12) + MCAM ATI Motion Compensation Format (MCAM) + MJ2C Morgan Multimedia Motion JPEG2000 + mJPG IBM Motion JPEG w/ Huffman Tables + MJPG Microsoft Motion JPEG DIB + MP42 Microsoft MPEG-4 (low-motion) + MP43 Microsoft MPEG-4 (fast-motion) + MP4S Microsoft MPEG-4 (MP4S) + mp4s Microsoft MPEG-4 (mp4s) + MPEG Chromatic Research MPEG-1 Video I-Frame + MPG4 Microsoft MPEG-4 Video High Speed Compressor + MPGI Sigma Designs MPEG + MRCA FAST Multimedia Martin Regen Codec + MRLE Microsoft Run Length Encoding + MSVC Microsoft Video 1 + MTX1 Matrox ?MTX1? + MTX2 Matrox ?MTX2? + MTX3 Matrox ?MTX3? + MTX4 Matrox ?MTX4? + MTX5 Matrox ?MTX5? + MTX6 Matrox ?MTX6? + MTX7 Matrox ?MTX7? + MTX8 Matrox ?MTX8? + MTX9 Matrox ?MTX9? + MV12 Motion Pixels Codec (old) + MWV1 Aware Motion Wavelets + nAVI SMR Codec (hack of Microsoft MPEG-4) (IRC #shadowrealm) + NT00 NewTek LightWave HDTV YUV w/ Alpha (www.newtek.com) + NUV1 NuppelVideo + NTN1 Nogatech Video Compression 1 + NVS0 nVidia GeForce Texture (NVS0) + NVS1 nVidia GeForce Texture (NVS1) + NVS2 nVidia GeForce Texture (NVS2) + NVS3 nVidia GeForce Texture (NVS3) + NVS4 nVidia GeForce Texture (NVS4) + NVS5 nVidia GeForce Texture (NVS5) + NVT0 nVidia GeForce Texture (NVT0) + NVT1 nVidia GeForce Texture (NVT1) + NVT2 nVidia GeForce Texture (NVT2) + NVT3 nVidia GeForce Texture (NVT3) + NVT4 nVidia GeForce Texture (NVT4) + NVT5 nVidia GeForce Texture (NVT5) + PIXL MiroXL, Pinnacle PCTV + PDVC I-O Data Device Digital Video Capture DV codec + PGVV Radius Video Vision + PHMO IBM Photomotion + PIM1 MPEG Realtime (Pinnacle Cards) + PIM2 Pegasus Imaging ?PIM2? + PIMJ Pegasus Imaging Lossless JPEG + PVEZ Horizons Technology PowerEZ + PVMM PacketVideo Corporation MPEG-4 + PVW2 Pegasus Imaging Wavelet Compression + Q1.0 Q-Team\'s QPEG 1.0 (www.q-team.de) + Q1.1 Q-Team\'s QPEG 1.1 (www.q-team.de) + QPEG Q-Team QPEG 1.0 + qpeq Q-Team QPEG 1.1 + RGB Raw BGR32 + RGBA Raw RGB w/ Alpha + RMP4 REALmagic MPEG-4 (unauthorized XVID copy) (www.sigmadesigns.com) + ROQV Id RoQ File Video Decoder + RPZA Quicktime Apple Video (RPZA) + RUD0 Rududu video codec (http://rududu.ifrance.com/rududu/) + RV10 RealVideo 1.0 (aka RealVideo 5.0) + RV13 RealVideo 1.0 (RV13) + RV20 RealVideo G2 + RV30 RealVideo 8 + RV40 RealVideo 9 + RGBT Raw RGB w/ Transparency + RLE Microsoft Run Length Encoder + RLE4 Run Length Encoded (4bpp, 16-color) + RLE8 Run Length Encoded (8bpp, 256-color) + RT21 Intel Indeo RealTime Video 2.1 + rv20 RealVideo G2 + rv30 RealVideo 8 + RVX Intel RDX (RVX ) + SMC Apple Graphics (SMC ) + SP54 Logitech Sunplus Sp54 Codec for Mustek GSmart Mini 2 + SPIG Radius Spigot + SVQ3 Sorenson Video 3 (Apple Quicktime 5) + s422 Tekram VideoCap C210 YUV 4:2:2 + SDCC Sun Communication Digital Camera Codec + SFMC CrystalNet Surface Fitting Method + SMSC Radius SMSC + SMSD Radius SMSD + smsv WorldConnect Wavelet Video + SPIG Radius Spigot + SPLC Splash Studios ACM Audio Codec (www.splashstudios.net) + SQZ2 Microsoft VXTreme Video Codec V2 + STVA ST Microelectronics CMOS Imager Data (Bayer) + STVB ST Microelectronics CMOS Imager Data (Nudged Bayer) + STVC ST Microelectronics CMOS Imager Data (Bunched) + STVX ST Microelectronics CMOS Imager Data (Extended CODEC Data Format) + STVY ST Microelectronics CMOS Imager Data (Extended CODEC Data Format with Correction Data) + SV10 Sorenson Video R1 + SVQ1 Sorenson Video + T420 Toshiba YUV 4:2:0 + TM2A Duck TrueMotion Archiver 2.0 (www.duck.com) + TVJP Pinnacle/Truevision Targa 2000 board (TVJP) + TVMJ Pinnacle/Truevision Targa 2000 board (TVMJ) + TY0N Tecomac Low-Bit Rate Codec (www.tecomac.com) + TY2C Trident Decompression Driver + TLMS TeraLogic Motion Intraframe Codec (TLMS) + TLST TeraLogic Motion Intraframe Codec (TLST) + TM20 Duck TrueMotion 2.0 + TM2X Duck TrueMotion 2X + TMIC TeraLogic Motion Intraframe Codec (TMIC) + TMOT Horizons Technology TrueMotion S + tmot Horizons TrueMotion Video Compression + TR20 Duck TrueMotion RealTime 2.0 + TSCC TechSmith Screen Capture Codec + TV10 Tecomac Low-Bit Rate Codec + TY2N Trident ?TY2N? + U263 UB Video H.263/H.263+/H.263++ Decoder + UMP4 UB Video MPEG 4 (www.ubvideo.com) + UYNV Nvidia UYVY packed 4:2:2 + UYVP Evans & Sutherland YCbCr 4:2:2 extended precision + UCOD eMajix.com ClearVideo + ULTI IBM Ultimotion + UYVY UYVY packed 4:2:2 + V261 Lucent VX2000S + VIFP VFAPI Reader Codec (www.yks.ne.jp/~hori/) + VIV1 FFmpeg H263+ decoder + VIV2 Vivo H.263 + VQC2 Vector-quantised codec 2 (research) http://eprints.ecs.soton.ac.uk/archive/00001310/01/VTC97-js.pdf) + VTLP Alaris VideoGramPiX + VYU9 ATI YUV (VYU9) + VYUY ATI YUV (VYUY) + V261 Lucent VX2000S + V422 Vitec Multimedia 24-bit YUV 4:2:2 Format + V655 Vitec Multimedia 16-bit YUV 4:2:2 Format + VCR1 ATI Video Codec 1 + VCR2 ATI Video Codec 2 + VCR3 ATI VCR 3.0 + VCR4 ATI VCR 4.0 + VCR5 ATI VCR 5.0 + VCR6 ATI VCR 6.0 + VCR7 ATI VCR 7.0 + VCR8 ATI VCR 8.0 + VCR9 ATI VCR 9.0 + VDCT Vitec Multimedia Video Maker Pro DIB + VDOM VDOnet VDOWave + VDOW VDOnet VDOLive (H.263) + VDTZ Darim Vison VideoTizer YUV + VGPX Alaris VideoGramPiX + VIDS Vitec Multimedia YUV 4:2:2 CCIR 601 for V422 + VIVO Vivo H.263 v2.00 + vivo Vivo H.263 + VIXL Miro/Pinnacle Video XL + VLV1 VideoLogic/PURE Digital Videologic Capture + VP30 On2 VP3.0 + VP31 On2 VP3.1 + VP6F On2 TrueMotion VP6 + VX1K Lucent VX1000S Video Codec + VX2K Lucent VX2000S Video Codec + VXSP Lucent VX1000SP Video Codec + WBVC Winbond W9960 + WHAM Microsoft Video 1 (WHAM) + WINX Winnov Software Compression + WJPG AverMedia Winbond JPEG + WMV1 Windows Media Video V7 + WMV2 Windows Media Video V8 + WMV3 Windows Media Video V9 + WNV1 Winnov Hardware Compression + XYZP Extended PAL format XYZ palette (www.riff.org) + x263 Xirlink H.263 + XLV0 NetXL Video Decoder + XMPG Xing MPEG (I-Frame only) + XVID XviD MPEG-4 (www.xvid.org) + XXAN ?XXAN? + YU92 Intel YUV (YU92) + YUNV Nvidia Uncompressed YUV 4:2:2 + YUVP Extended PAL format YUV palette (www.riff.org) + Y211 YUV 2:1:1 Packed + Y411 YUV 4:1:1 Packed + Y41B Weitek YUV 4:1:1 Planar + Y41P Brooktree PC1 YUV 4:1:1 Packed + Y41T Brooktree PC1 YUV 4:1:1 with transparency + Y42B Weitek YUV 4:2:2 Planar + Y42T Brooktree UYUV 4:2:2 with transparency + Y422 ADS Technologies Copy of UYVY used in Pyro WebCam firewire camera + Y800 Simple, single Y plane for monochrome images + Y8 Grayscale video + YC12 Intel YUV 12 codec + YUV8 Winnov Caviar YUV8 + YUV9 Intel YUV9 + YUY2 Uncompressed YUV 4:2:2 + YUYV Canopus YUV + YV12 YVU12 Planar + YVU9 Intel YVU9 Planar (8-bpp Y plane, followed by 8-bpp 4x4 U and V planes) + YVYU YVYU 4:2:2 Packed + ZLIB Lossless Codec Library zlib compression (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm) + ZPEG Metheus Video Zipper + */ + + return getid3_lib::EmbeddedLookup($fourcc, $begin, __LINE__, __FILE__, 'riff-fourcc'); + } + + private function EitherEndian2Int($byteword, $signed = false) + { + if ($this->container == 'riff') { + return getid3_lib::LittleEndian2Int($byteword, $signed); + } + + return getid3_lib::BigEndian2Int($byteword, false, $signed); + } +} diff --git a/app/Library/getid3/getid3/module.audio-video.swf.php b/app/Library/getid3/getid3/module.audio-video.swf.php index 178f439a..836edbe0 100644 --- a/app/Library/getid3/getid3/module.audio-video.swf.php +++ b/app/Library/getid3/getid3/module.audio-video.swf.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,127 +15,127 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_swf extends getid3_handler { - public $ReturnAllTagData = false; + public $ReturnAllTagData = false; - public function Analyze() { - $info = &$this->getid3->info; + public function Analyze() + { + $info = &$this->getid3->info; - $info['fileformat'] = 'swf'; - $info['video']['dataformat'] = 'swf'; + $info['fileformat'] = 'swf'; + $info['video']['dataformat'] = 'swf'; - // http://www.openswf.org/spec/SWFfileformat.html + // http://www.openswf.org/spec/SWFfileformat.html - $this->fseek($info['avdataoffset']); + $this->fseek($info['avdataoffset']); - $SWFfileData = $this->fread($info['avdataend'] - $info['avdataoffset']); // 8 + 2 + 2 + max(9) bytes NOT including Frame_Size RECT data + $SWFfileData = $this->fread($info['avdataend'] - $info['avdataoffset']); // 8 + 2 + 2 + max(9) bytes NOT including Frame_Size RECT data - $info['swf']['header']['signature'] = substr($SWFfileData, 0, 3); - switch ($info['swf']['header']['signature']) { - case 'FWS': - $info['swf']['header']['compressed'] = false; - break; + $info['swf']['header']['signature'] = substr($SWFfileData, 0, 3); + switch ($info['swf']['header']['signature']) { + case 'FWS': + $info['swf']['header']['compressed'] = false; + break; - case 'CWS': - $info['swf']['header']['compressed'] = true; - break; + case 'CWS': + $info['swf']['header']['compressed'] = true; + break; - default: - $this->error('Expecting "FWS" or "CWS" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['swf']['header']['signature']).'"'); - unset($info['swf']); - unset($info['fileformat']); - return false; - break; - } - $info['swf']['header']['version'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 3, 1)); - $info['swf']['header']['length'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 4, 4)); + default: + $this->error('Expecting "FWS" or "CWS" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['swf']['header']['signature']).'"'); + unset($info['swf']); + unset($info['fileformat']); - if ($info['swf']['header']['compressed']) { - $SWFHead = substr($SWFfileData, 0, 8); - $SWFfileData = substr($SWFfileData, 8); - if ($decompressed = @gzuncompress($SWFfileData)) { - $SWFfileData = $SWFHead.$decompressed; - } else { - $this->error('Error decompressing compressed SWF data ('.strlen($SWFfileData).' bytes compressed, should be '.($info['swf']['header']['length'] - 8).' bytes uncompressed)'); - return false; - } - } + return false; + break; + } + $info['swf']['header']['version'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 3, 1)); + $info['swf']['header']['length'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 4, 4)); - $FrameSizeBitsPerValue = (ord(substr($SWFfileData, 8, 1)) & 0xF8) >> 3; - $FrameSizeDataLength = ceil((5 + (4 * $FrameSizeBitsPerValue)) / 8); - $FrameSizeDataString = str_pad(decbin(ord(substr($SWFfileData, 8, 1)) & 0x07), 3, '0', STR_PAD_LEFT); - for ($i = 1; $i < $FrameSizeDataLength; $i++) { - $FrameSizeDataString .= str_pad(decbin(ord(substr($SWFfileData, 8 + $i, 1))), 8, '0', STR_PAD_LEFT); - } - list($X1, $X2, $Y1, $Y2) = explode("\n", wordwrap($FrameSizeDataString, $FrameSizeBitsPerValue, "\n", 1)); - $info['swf']['header']['frame_width'] = getid3_lib::Bin2Dec($X2); - $info['swf']['header']['frame_height'] = getid3_lib::Bin2Dec($Y2); + if ($info['swf']['header']['compressed']) { + $SWFHead = substr($SWFfileData, 0, 8); + $SWFfileData = substr($SWFfileData, 8); + if ($decompressed = @gzuncompress($SWFfileData)) { + $SWFfileData = $SWFHead.$decompressed; + } else { + $this->error('Error decompressing compressed SWF data ('.strlen($SWFfileData).' bytes compressed, should be '.($info['swf']['header']['length'] - 8).' bytes uncompressed)'); - // http://www-lehre.informatik.uni-osnabrueck.de/~fbstark/diplom/docs/swf/Flash_Uncovered.htm - // Next in the header is the frame rate, which is kind of weird. - // It is supposed to be stored as a 16bit integer, but the first byte - // (or last depending on how you look at it) is completely ignored. - // Example: 0x000C -> 0x0C -> 12 So the frame rate is 12 fps. + return false; + } + } - // Byte at (8 + $FrameSizeDataLength) is always zero and ignored - $info['swf']['header']['frame_rate'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 9 + $FrameSizeDataLength, 1)); - $info['swf']['header']['frame_count'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 10 + $FrameSizeDataLength, 2)); + $FrameSizeBitsPerValue = (ord(substr($SWFfileData, 8, 1)) & 0xF8) >> 3; + $FrameSizeDataLength = ceil((5 + (4 * $FrameSizeBitsPerValue)) / 8); + $FrameSizeDataString = str_pad(decbin(ord(substr($SWFfileData, 8, 1)) & 0x07), 3, '0', STR_PAD_LEFT); + for ($i = 1; $i < $FrameSizeDataLength; $i++) { + $FrameSizeDataString .= str_pad(decbin(ord(substr($SWFfileData, 8 + $i, 1))), 8, '0', STR_PAD_LEFT); + } + list($X1, $X2, $Y1, $Y2) = explode("\n", wordwrap($FrameSizeDataString, $FrameSizeBitsPerValue, "\n", 1)); + $info['swf']['header']['frame_width'] = getid3_lib::Bin2Dec($X2); + $info['swf']['header']['frame_height'] = getid3_lib::Bin2Dec($Y2); - $info['video']['frame_rate'] = $info['swf']['header']['frame_rate']; - $info['video']['resolution_x'] = intval(round($info['swf']['header']['frame_width'] / 20)); - $info['video']['resolution_y'] = intval(round($info['swf']['header']['frame_height'] / 20)); - $info['video']['pixel_aspect_ratio'] = (float) 1; + // http://www-lehre.informatik.uni-osnabrueck.de/~fbstark/diplom/docs/swf/Flash_Uncovered.htm + // Next in the header is the frame rate, which is kind of weird. + // It is supposed to be stored as a 16bit integer, but the first byte + // (or last depending on how you look at it) is completely ignored. + // Example: 0x000C -> 0x0C -> 12 So the frame rate is 12 fps. - if (($info['swf']['header']['frame_count'] > 0) && ($info['swf']['header']['frame_rate'] > 0)) { - $info['playtime_seconds'] = $info['swf']['header']['frame_count'] / $info['swf']['header']['frame_rate']; - } -//echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'
    '; + // Byte at (8 + $FrameSizeDataLength) is always zero and ignored + $info['swf']['header']['frame_rate'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 9 + $FrameSizeDataLength, 1)); + $info['swf']['header']['frame_count'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 10 + $FrameSizeDataLength, 2)); + $info['video']['frame_rate'] = $info['swf']['header']['frame_rate']; + $info['video']['resolution_x'] = intval(round($info['swf']['header']['frame_width'] / 20)); + $info['video']['resolution_y'] = intval(round($info['swf']['header']['frame_height'] / 20)); + $info['video']['pixel_aspect_ratio'] = (float) 1; - // SWF tags + if (($info['swf']['header']['frame_count'] > 0) && ($info['swf']['header']['frame_rate'] > 0)) { + $info['playtime_seconds'] = $info['swf']['header']['frame_count'] / $info['swf']['header']['frame_rate']; + } + //echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'
    '; - $CurrentOffset = 12 + $FrameSizeDataLength; - $SWFdataLength = strlen($SWFfileData); + // SWF tags - while ($CurrentOffset < $SWFdataLength) { -//echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'
    '; + $CurrentOffset = 12 + $FrameSizeDataLength; + $SWFdataLength = strlen($SWFfileData); - $TagIDTagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 2)); - $TagID = ($TagIDTagLength & 0xFFFC) >> 6; - $TagLength = ($TagIDTagLength & 0x003F); - $CurrentOffset += 2; - if ($TagLength == 0x3F) { - $TagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 4)); - $CurrentOffset += 4; - } + while ($CurrentOffset < $SWFdataLength) { + //echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'
    '; - unset($TagData); - $TagData['offset'] = $CurrentOffset; - $TagData['size'] = $TagLength; - $TagData['id'] = $TagID; - $TagData['data'] = substr($SWFfileData, $CurrentOffset, $TagLength); - switch ($TagID) { - case 0: // end of movie - break 2; + $TagIDTagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 2)); + $TagID = ($TagIDTagLength & 0xFFFC) >> 6; + $TagLength = ($TagIDTagLength & 0x003F); + $CurrentOffset += 2; + if ($TagLength == 0x3F) { + $TagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 4)); + $CurrentOffset += 4; + } - case 9: // Set background color - //$info['swf']['tags'][] = $TagData; - $info['swf']['bgcolor'] = strtoupper(str_pad(dechex(getid3_lib::BigEndian2Int($TagData['data'])), 6, '0', STR_PAD_LEFT)); - break; + unset($TagData); + $TagData['offset'] = $CurrentOffset; + $TagData['size'] = $TagLength; + $TagData['id'] = $TagID; + $TagData['data'] = substr($SWFfileData, $CurrentOffset, $TagLength); + switch ($TagID) { + case 0: // end of movie + break 2; - default: - if ($this->ReturnAllTagData) { - $info['swf']['tags'][] = $TagData; - } - break; - } + case 9: // Set background color + //$info['swf']['tags'][] = $TagData; + $info['swf']['bgcolor'] = strtoupper(str_pad(dechex(getid3_lib::BigEndian2Int($TagData['data'])), 6, '0', STR_PAD_LEFT)); + break; - $CurrentOffset += $TagLength; - } + default: + if ($this->ReturnAllTagData) { + $info['swf']['tags'][] = $TagData; + } + break; + } - return true; - } + $CurrentOffset += $TagLength; + } + return true; + } } diff --git a/app/Library/getid3/getid3/module.audio-video.ts.php b/app/Library/getid3/getid3/module.audio-video.ts.php index 33620242..c8438e4b 100644 --- a/app/Library/getid3/getid3/module.audio-video.ts.php +++ b/app/Library/getid3/getid3/module.audio-video.ts.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,66 +15,73 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_ts extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $TSheader = $this->fread(19); + $magic = "\x47"; + if (substr($TSheader, 0, 1) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at '.$info['avdataoffset'].', found '.getid3_lib::PrintHexBytes(substr($TSheader, 0, 1)).' instead.'); - $this->fseek($info['avdataoffset']); - $TSheader = $this->fread(19); - $magic = "\x47"; - if (substr($TSheader, 0, 1) != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at '.$info['avdataoffset'].', found '.getid3_lib::PrintHexBytes(substr($TSheader, 0, 1)).' instead.'); - return false; - } - $info['fileformat'] = 'ts'; + return false; + } + $info['fileformat'] = 'ts'; - // http://en.wikipedia.org/wiki/.ts + // http://en.wikipedia.org/wiki/.ts - $offset = 0; - $info['ts']['packet']['sync'] = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 1)); $offset += 1; - $pid_flags_raw = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 2)); $offset += 2; - $SAC_raw = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 1)); $offset += 1; - $info['ts']['packet']['flags']['transport_error_indicator'] = (bool) ($pid_flags_raw & 0x8000); // Set by demodulator if can't correct errors in the stream, to tell the demultiplexer that the packet has an uncorrectable error - $info['ts']['packet']['flags']['payload_unit_start_indicator'] = (bool) ($pid_flags_raw & 0x4000); // 1 means start of PES data or PSI otherwise zero only. - $info['ts']['packet']['flags']['transport_high_priority'] = (bool) ($pid_flags_raw & 0x2000); // 1 means higher priority than other packets with the same PID. - $info['ts']['packet']['packet_id'] = ($pid_flags_raw & 0x1FFF) >> 0; + $offset = 0; + $info['ts']['packet']['sync'] = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 1)); + $offset += 1; + $pid_flags_raw = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 2)); + $offset += 2; + $SAC_raw = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 1)); + $offset += 1; + $info['ts']['packet']['flags']['transport_error_indicator'] = (bool) ($pid_flags_raw & 0x8000); // Set by demodulator if can't correct errors in the stream, to tell the demultiplexer that the packet has an uncorrectable error + $info['ts']['packet']['flags']['payload_unit_start_indicator'] = (bool) ($pid_flags_raw & 0x4000); // 1 means start of PES data or PSI otherwise zero only. + $info['ts']['packet']['flags']['transport_high_priority'] = (bool) ($pid_flags_raw & 0x2000); // 1 means higher priority than other packets with the same PID. + $info['ts']['packet']['packet_id'] = ($pid_flags_raw & 0x1FFF) >> 0; - $info['ts']['packet']['raw']['scrambling_control'] = ($SAC_raw & 0xC0) >> 6; - $info['ts']['packet']['flags']['adaption_field_exists'] = (bool) ($SAC_raw & 0x20); - $info['ts']['packet']['flags']['payload_exists'] = (bool) ($SAC_raw & 0x10); - $info['ts']['packet']['continuity_counter'] = ($SAC_raw & 0x0F) >> 0; // Incremented only when a payload is present - $info['ts']['packet']['scrambling_control'] = $this->TSscramblingControlLookup($info['ts']['packet']['raw']['scrambling_control']); + $info['ts']['packet']['raw']['scrambling_control'] = ($SAC_raw & 0xC0) >> 6; + $info['ts']['packet']['flags']['adaption_field_exists'] = (bool) ($SAC_raw & 0x20); + $info['ts']['packet']['flags']['payload_exists'] = (bool) ($SAC_raw & 0x10); + $info['ts']['packet']['continuity_counter'] = ($SAC_raw & 0x0F) >> 0; // Incremented only when a payload is present + $info['ts']['packet']['scrambling_control'] = $this->TSscramblingControlLookup($info['ts']['packet']['raw']['scrambling_control']); - if ($info['ts']['packet']['flags']['adaption_field_exists']) { - $AdaptionField_raw = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 2)); $offset += 2; - $info['ts']['packet']['adaption']['field_length'] = ($AdaptionField_raw & 0xFF00) >> 8; // Number of bytes in the adaptation field immediately following this byte - $info['ts']['packet']['adaption']['flags']['discontinuity'] = (bool) ($AdaptionField_raw & 0x0080); // Set to 1 if current TS packet is in a discontinuity state with respect to either the continuity counter or the program clock reference - $info['ts']['packet']['adaption']['flags']['random_access'] = (bool) ($AdaptionField_raw & 0x0040); // Set to 1 if the PES packet in this TS packet starts a video/audio sequence - $info['ts']['packet']['adaption']['flags']['high_priority'] = (bool) ($AdaptionField_raw & 0x0020); // 1 = higher priority - $info['ts']['packet']['adaption']['flags']['pcr'] = (bool) ($AdaptionField_raw & 0x0010); // 1 means adaptation field does contain a PCR field - $info['ts']['packet']['adaption']['flags']['opcr'] = (bool) ($AdaptionField_raw & 0x0008); // 1 means adaptation field does contain an OPCR field - $info['ts']['packet']['adaption']['flags']['splice_point'] = (bool) ($AdaptionField_raw & 0x0004); // 1 means presence of splice countdown field in adaptation field - $info['ts']['packet']['adaption']['flags']['private_data'] = (bool) ($AdaptionField_raw & 0x0002); // 1 means presence of private data bytes in adaptation field - $info['ts']['packet']['adaption']['flags']['extension'] = (bool) ($AdaptionField_raw & 0x0001); // 1 means presence of adaptation field extension - if ($info['ts']['packet']['adaption']['flags']['pcr']) { - $info['ts']['packet']['adaption']['raw']['pcr'] = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 6)); $offset += 6; - } - if ($info['ts']['packet']['adaption']['flags']['opcr']) { - $info['ts']['packet']['adaption']['raw']['opcr'] = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 6)); $offset += 6; - } - } + if ($info['ts']['packet']['flags']['adaption_field_exists']) { + $AdaptionField_raw = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 2)); + $offset += 2; + $info['ts']['packet']['adaption']['field_length'] = ($AdaptionField_raw & 0xFF00) >> 8; // Number of bytes in the adaptation field immediately following this byte + $info['ts']['packet']['adaption']['flags']['discontinuity'] = (bool) ($AdaptionField_raw & 0x0080); // Set to 1 if current TS packet is in a discontinuity state with respect to either the continuity counter or the program clock reference + $info['ts']['packet']['adaption']['flags']['random_access'] = (bool) ($AdaptionField_raw & 0x0040); // Set to 1 if the PES packet in this TS packet starts a video/audio sequence + $info['ts']['packet']['adaption']['flags']['high_priority'] = (bool) ($AdaptionField_raw & 0x0020); // 1 = higher priority + $info['ts']['packet']['adaption']['flags']['pcr'] = (bool) ($AdaptionField_raw & 0x0010); // 1 means adaptation field does contain a PCR field + $info['ts']['packet']['adaption']['flags']['opcr'] = (bool) ($AdaptionField_raw & 0x0008); // 1 means adaptation field does contain an OPCR field + $info['ts']['packet']['adaption']['flags']['splice_point'] = (bool) ($AdaptionField_raw & 0x0004); // 1 means presence of splice countdown field in adaptation field + $info['ts']['packet']['adaption']['flags']['private_data'] = (bool) ($AdaptionField_raw & 0x0002); // 1 means presence of private data bytes in adaptation field + $info['ts']['packet']['adaption']['flags']['extension'] = (bool) ($AdaptionField_raw & 0x0001); // 1 means presence of adaptation field extension + if ($info['ts']['packet']['adaption']['flags']['pcr']) { + $info['ts']['packet']['adaption']['raw']['pcr'] = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 6)); + $offset += 6; + } + if ($info['ts']['packet']['adaption']['flags']['opcr']) { + $info['ts']['packet']['adaption']['raw']['opcr'] = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 6)); + $offset += 6; + } + } -$this->error('MPEG Transport Stream (.ts) parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); -return false; + $this->error('MPEG Transport Stream (.ts) parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); - } + return false; + } + public function TSscramblingControlLookup($raw) + { + $TSscramblingControlLookup = [0x00=>'not scrambled', 0x01=>'reserved', 0x02=>'scrambled, even key', 0x03=>'scrambled, odd key']; - public function TSscramblingControlLookup($raw) { - $TSscramblingControlLookup = array(0x00=>'not scrambled', 0x01=>'reserved', 0x02=>'scrambled, even key', 0x03=>'scrambled, odd key'); - return (isset($TSscramblingControlLookup[$raw]) ? $TSscramblingControlLookup[$raw] : 'invalid'); - } + return isset($TSscramblingControlLookup[$raw]) ? $TSscramblingControlLookup[$raw] : 'invalid'; + } } diff --git a/app/Library/getid3/getid3/module.audio.aa.php b/app/Library/getid3/getid3/module.audio.aa.php index 889fd581..d12166bc 100644 --- a/app/Library/getid3/getid3/module.audio.aa.php +++ b/app/Library/getid3/getid3/module.audio.aa.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,46 +15,46 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_aa extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $AAheader = $this->fread(8); - $this->fseek($info['avdataoffset']); - $AAheader = $this->fread(8); + $magic = "\x57\x90\x75\x36"; + if (substr($AAheader, 4, 4) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($AAheader, 4, 4)).'"'); - $magic = "\x57\x90\x75\x36"; - if (substr($AAheader, 4, 4) != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($AAheader, 4, 4)).'"'); - return false; - } + return false; + } - // shortcut - $info['aa'] = array(); - $thisfile_aa = &$info['aa']; + // shortcut + $info['aa'] = []; + $thisfile_aa = &$info['aa']; - $info['fileformat'] = 'aa'; - $info['audio']['dataformat'] = 'aa'; -$this->error('Audible Audiobook (.aa) parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); -return false; - $info['audio']['bitrate_mode'] = 'cbr'; // is it? - $thisfile_aa['encoding'] = 'ISO-8859-1'; + $info['fileformat'] = 'aa'; + $info['audio']['dataformat'] = 'aa'; + $this->error('Audible Audiobook (.aa) parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); - $thisfile_aa['filesize'] = getid3_lib::BigEndian2Int(substr($AUheader, 0, 4)); - if ($thisfile_aa['filesize'] > ($info['avdataend'] - $info['avdataoffset'])) { - $this->warning('Possible truncated file - expecting "'.$thisfile_aa['filesize'].'" bytes of data, only found '.($info['avdataend'] - $info['avdataoffset']).' bytes"'); - } + return false; + $info['audio']['bitrate_mode'] = 'cbr'; // is it? + $thisfile_aa['encoding'] = 'ISO-8859-1'; - $info['audio']['bits_per_sample'] = 16; // is it? - $info['audio']['sample_rate'] = $thisfile_aa['sample_rate']; - $info['audio']['channels'] = $thisfile_aa['channels']; + $thisfile_aa['filesize'] = getid3_lib::BigEndian2Int(substr($AUheader, 0, 4)); + if ($thisfile_aa['filesize'] > ($info['avdataend'] - $info['avdataoffset'])) { + $this->warning('Possible truncated file - expecting "'.$thisfile_aa['filesize'].'" bytes of data, only found '.($info['avdataend'] - $info['avdataoffset']).' bytes"'); + } - //$info['playtime_seconds'] = 0; - //$info['audio']['bitrate'] = 0; + $info['audio']['bits_per_sample'] = 16; // is it? + $info['audio']['sample_rate'] = $thisfile_aa['sample_rate']; + $info['audio']['channels'] = $thisfile_aa['channels']; - return true; - } + //$info['playtime_seconds'] = 0; + //$info['audio']['bitrate'] = 0; + return true; + } } diff --git a/app/Library/getid3/getid3/module.audio.aac.php b/app/Library/getid3/getid3/module.audio.aac.php index 59d79def..30f7fa18 100644 --- a/app/Library/getid3/getid3/module.audio.aac.php +++ b/app/Library/getid3/getid3/module.audio.aac.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,500 +15,500 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_aac extends getid3_handler { - public function Analyze() { - $info = &$this->getid3->info; - $this->fseek($info['avdataoffset']); - if ($this->fread(4) == 'ADIF') { - $this->getAACADIFheaderFilepointer(); - } else { - $this->getAACADTSheaderFilepointer(); - } - return true; - } - - - - public function getAACADIFheaderFilepointer() { - $info = &$this->getid3->info; - $info['fileformat'] = 'aac'; - $info['audio']['dataformat'] = 'aac'; - $info['audio']['lossless'] = false; - - $this->fseek($info['avdataoffset']); - $AACheader = $this->fread(1024); - $offset = 0; - - if (substr($AACheader, 0, 4) == 'ADIF') { - - // http://faac.sourceforge.net/wiki/index.php?page=ADIF - - // http://libmpeg.org/mpeg4/doc/w2203tfs.pdf - // adif_header() { - // adif_id 32 - // copyright_id_present 1 - // if( copyright_id_present ) - // copyright_id 72 - // original_copy 1 - // home 1 - // bitstream_type 1 - // bitrate 23 - // num_program_config_elements 4 - // for (i = 0; i < num_program_config_elements + 1; i++ ) { - // if( bitstream_type == '0' ) - // adif_buffer_fullness 20 - // program_config_element() - // } - // } - - $AACheaderBitstream = getid3_lib::BigEndian2Bin($AACheader); - $bitoffset = 0; - - $info['aac']['header_type'] = 'ADIF'; - $bitoffset += 32; - $info['aac']['header']['mpeg_version'] = 4; - - $info['aac']['header']['copyright'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1'); - $bitoffset += 1; - if ($info['aac']['header']['copyright']) { - $info['aac']['header']['copyright_id'] = getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 72)); - $bitoffset += 72; - } - $info['aac']['header']['original_copy'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1'); - $bitoffset += 1; - $info['aac']['header']['home'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1'); - $bitoffset += 1; - $info['aac']['header']['is_vbr'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1'); - $bitoffset += 1; - if ($info['aac']['header']['is_vbr']) { - $info['audio']['bitrate_mode'] = 'vbr'; - $info['aac']['header']['bitrate_max'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23)); - $bitoffset += 23; - } else { - $info['audio']['bitrate_mode'] = 'cbr'; - $info['aac']['header']['bitrate'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23)); - $bitoffset += 23; - $info['audio']['bitrate'] = $info['aac']['header']['bitrate']; - } - if ($info['audio']['bitrate'] == 0) { - $this->error('Corrupt AAC file: bitrate_audio == zero'); - return false; - } - $info['aac']['header']['num_program_configs'] = 1 + getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - - for ($i = 0; $i < $info['aac']['header']['num_program_configs']; $i++) { - // http://www.audiocoding.com/wiki/index.php?page=program_config_element - - // buffer_fullness 20 - - // element_instance_tag 4 - // object_type 2 - // sampling_frequency_index 4 - // num_front_channel_elements 4 - // num_side_channel_elements 4 - // num_back_channel_elements 4 - // num_lfe_channel_elements 2 - // num_assoc_data_elements 3 - // num_valid_cc_elements 4 - // mono_mixdown_present 1 - // mono_mixdown_element_number 4 if mono_mixdown_present == 1 - // stereo_mixdown_present 1 - // stereo_mixdown_element_number 4 if stereo_mixdown_present == 1 - // matrix_mixdown_idx_present 1 - // matrix_mixdown_idx 2 if matrix_mixdown_idx_present == 1 - // pseudo_surround_enable 1 if matrix_mixdown_idx_present == 1 - // for (i = 0; i < num_front_channel_elements; i++) { - // front_element_is_cpe[i] 1 - // front_element_tag_select[i] 4 - // } - // for (i = 0; i < num_side_channel_elements; i++) { - // side_element_is_cpe[i] 1 - // side_element_tag_select[i] 4 - // } - // for (i = 0; i < num_back_channel_elements; i++) { - // back_element_is_cpe[i] 1 - // back_element_tag_select[i] 4 - // } - // for (i = 0; i < num_lfe_channel_elements; i++) { - // lfe_element_tag_select[i] 4 - // } - // for (i = 0; i < num_assoc_data_elements; i++) { - // assoc_data_element_tag_select[i] 4 - // } - // for (i = 0; i < num_valid_cc_elements; i++) { - // cc_element_is_ind_sw[i] 1 - // valid_cc_element_tag_select[i] 4 - // } - // byte_alignment() VAR - // comment_field_bytes 8 - // for (i = 0; i < comment_field_bytes; i++) { - // comment_field_data[i] 8 - // } - - if (!$info['aac']['header']['is_vbr']) { - $info['aac']['program_configs'][$i]['buffer_fullness'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 20)); - $bitoffset += 20; - } - $info['aac']['program_configs'][$i]['element_instance_tag'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - $info['aac']['program_configs'][$i]['object_type'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2)); - $bitoffset += 2; - $info['aac']['program_configs'][$i]['sampling_frequency_index'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - $info['aac']['program_configs'][$i]['num_front_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - $info['aac']['program_configs'][$i]['num_side_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - $info['aac']['program_configs'][$i]['num_back_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - $info['aac']['program_configs'][$i]['num_lfe_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2)); - $bitoffset += 2; - $info['aac']['program_configs'][$i]['num_assoc_data_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 3)); - $bitoffset += 3; - $info['aac']['program_configs'][$i]['num_valid_cc_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - $info['aac']['program_configs'][$i]['mono_mixdown_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - if ($info['aac']['program_configs'][$i]['mono_mixdown_present']) { - $info['aac']['program_configs'][$i]['mono_mixdown_element_number'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - $info['aac']['program_configs'][$i]['stereo_mixdown_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - if ($info['aac']['program_configs'][$i]['stereo_mixdown_present']) { - $info['aac']['program_configs'][$i]['stereo_mixdown_element_number'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - $info['aac']['program_configs'][$i]['matrix_mixdown_idx_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - if ($info['aac']['program_configs'][$i]['matrix_mixdown_idx_present']) { - $info['aac']['program_configs'][$i]['matrix_mixdown_idx'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2)); - $bitoffset += 2; - $info['aac']['program_configs'][$i]['pseudo_surround_enable'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - } - for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_front_channel_elements']; $j++) { - $info['aac']['program_configs'][$i]['front_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - $info['aac']['program_configs'][$i]['front_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_side_channel_elements']; $j++) { - $info['aac']['program_configs'][$i]['side_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - $info['aac']['program_configs'][$i]['side_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_back_channel_elements']; $j++) { - $info['aac']['program_configs'][$i]['back_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - $info['aac']['program_configs'][$i]['back_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_lfe_channel_elements']; $j++) { - $info['aac']['program_configs'][$i]['lfe_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_assoc_data_elements']; $j++) { - $info['aac']['program_configs'][$i]['assoc_data_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_valid_cc_elements']; $j++) { - $info['aac']['program_configs'][$i]['cc_element_is_ind_sw'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - $info['aac']['program_configs'][$i]['valid_cc_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - - $bitoffset = ceil($bitoffset / 8) * 8; - - $info['aac']['program_configs'][$i]['comment_field_bytes'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 8)); - $bitoffset += 8; - $info['aac']['program_configs'][$i]['comment_field'] = getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 8 * $info['aac']['program_configs'][$i]['comment_field_bytes'])); - $bitoffset += 8 * $info['aac']['program_configs'][$i]['comment_field_bytes']; - - - $info['aac']['header']['profile'] = self::AACprofileLookup($info['aac']['program_configs'][$i]['object_type'], $info['aac']['header']['mpeg_version']); - $info['aac']['program_configs'][$i]['sampling_frequency'] = self::AACsampleRateLookup($info['aac']['program_configs'][$i]['sampling_frequency_index']); - $info['audio']['sample_rate'] = $info['aac']['program_configs'][$i]['sampling_frequency']; - $info['audio']['channels'] = self::AACchannelCountCalculate($info['aac']['program_configs'][$i]); - if ($info['aac']['program_configs'][$i]['comment_field']) { - $info['aac']['comments'][] = $info['aac']['program_configs'][$i]['comment_field']; - } - } - $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['audio']['bitrate']; - - $info['audio']['encoder_options'] = $info['aac']['header_type'].' '.$info['aac']['header']['profile']; - - - - return true; - - } else { - - unset($info['fileformat']); - unset($info['aac']); - $this->error('AAC-ADIF synch not found at offset '.$info['avdataoffset'].' (expected "ADIF", found "'.substr($AACheader, 0, 4).'" instead)'); - return false; - - } - - } - - - public function getAACADTSheaderFilepointer($MaxFramesToScan=1000000, $ReturnExtendedInfo=false) { - $info = &$this->getid3->info; - - // based loosely on code from AACfile by Jurgen Faul - // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html - - - // http://faac.sourceforge.net/wiki/index.php?page=ADTS // dead link - // http://wiki.multimedia.cx/index.php?title=ADTS - - // * ADTS Fixed Header: these don't change from frame to frame - // syncword 12 always: '111111111111' - // ID 1 0: MPEG-4, 1: MPEG-2 - // MPEG layer 2 If you send AAC in MPEG-TS, set to 0 - // protection_absent 1 0: CRC present; 1: no CRC - // profile 2 0: AAC Main; 1: AAC LC (Low Complexity); 2: AAC SSR (Scalable Sample Rate); 3: AAC LTP (Long Term Prediction) - // sampling_frequency_index 4 15 not allowed - // private_bit 1 usually 0 - // channel_configuration 3 - // original/copy 1 0: original; 1: copy - // home 1 usually 0 - // emphasis 2 only if ID == 0 (ie MPEG-4) // not present in some documentation? - - // * ADTS Variable Header: these can change from frame to frame - // copyright_identification_bit 1 - // copyright_identification_start 1 - // aac_frame_length 13 length of the frame including header (in bytes) - // adts_buffer_fullness 11 0x7FF indicates VBR - // no_raw_data_blocks_in_frame 2 - - // * ADTS Error check - // crc_check 16 only if protection_absent == 0 - - $byteoffset = $info['avdataoffset']; - $framenumber = 0; - - // Init bit pattern array - static $decbin = array(); - - // Populate $bindec - for ($i = 0; $i < 256; $i++) { - $decbin[chr($i)] = str_pad(decbin($i), 8, '0', STR_PAD_LEFT); - } - - // used to calculate bitrate below - $BitrateCache = array(); - - - while (true) { - // breaks out when end-of-file encountered, or invalid data found, - // or MaxFramesToScan frames have been scanned - - if (!getid3_lib::intValueSupported($byteoffset)) { - $this->warning('Unable to parse AAC file beyond '.$this->ftell().' (PHP does not support file operations beyond '.round(PHP_INT_MAX / 1073741824).'GB)'); - return false; - } - $this->fseek($byteoffset); - - // First get substring - $substring = $this->fread(9); // header is 7 bytes (or 9 if CRC is present) - $substringlength = strlen($substring); - if ($substringlength != 9) { - $this->error('Failed to read 7 bytes at offset '.($this->ftell() - $substringlength).' (only read '.$substringlength.' bytes)'); - return false; - } - // this would be easier with 64-bit math, but split it up to allow for 32-bit: - $header1 = getid3_lib::BigEndian2Int(substr($substring, 0, 2)); - $header2 = getid3_lib::BigEndian2Int(substr($substring, 2, 4)); - $header3 = getid3_lib::BigEndian2Int(substr($substring, 6, 1)); - - $info['aac']['header']['raw']['syncword'] = ($header1 & 0xFFF0) >> 4; - if ($info['aac']['header']['raw']['syncword'] != 0x0FFF) { - $this->error('Synch pattern (0x0FFF) not found at offset '.($this->ftell() - $substringlength).' (found 0x0'.strtoupper(dechex($info['aac']['header']['raw']['syncword'])).' instead)'); - //if ($info['fileformat'] == 'aac') { - // return true; - //} - unset($info['aac']); - return false; - } - - // Gather info for first frame only - this takes time to do 1000 times! - if ($framenumber == 0) { - $info['aac']['header_type'] = 'ADTS'; - $info['fileformat'] = 'aac'; - $info['audio']['dataformat'] = 'aac'; - - $info['aac']['header']['raw']['mpeg_version'] = ($header1 & 0x0008) >> 3; - $info['aac']['header']['raw']['mpeg_layer'] = ($header1 & 0x0006) >> 1; - $info['aac']['header']['raw']['protection_absent'] = ($header1 & 0x0001) >> 0; - - $info['aac']['header']['raw']['profile_code'] = ($header2 & 0xC0000000) >> 30; - $info['aac']['header']['raw']['sample_rate_code'] = ($header2 & 0x3C000000) >> 26; - $info['aac']['header']['raw']['private_stream'] = ($header2 & 0x02000000) >> 25; - $info['aac']['header']['raw']['channels_code'] = ($header2 & 0x01C00000) >> 22; - $info['aac']['header']['raw']['original'] = ($header2 & 0x00200000) >> 21; - $info['aac']['header']['raw']['home'] = ($header2 & 0x00100000) >> 20; - $info['aac']['header']['raw']['copyright_stream'] = ($header2 & 0x00080000) >> 19; - $info['aac']['header']['raw']['copyright_start'] = ($header2 & 0x00040000) >> 18; - $info['aac']['header']['raw']['frame_length'] = ($header2 & 0x0003FFE0) >> 5; - - $info['aac']['header']['mpeg_version'] = ($info['aac']['header']['raw']['mpeg_version'] ? 2 : 4); - $info['aac']['header']['crc_present'] = ($info['aac']['header']['raw']['protection_absent'] ? false: true); - $info['aac']['header']['profile'] = self::AACprofileLookup($info['aac']['header']['raw']['profile_code'], $info['aac']['header']['mpeg_version']); - $info['aac']['header']['sample_frequency'] = self::AACsampleRateLookup($info['aac']['header']['raw']['sample_rate_code']); - $info['aac']['header']['private'] = (bool) $info['aac']['header']['raw']['private_stream']; - $info['aac']['header']['original'] = (bool) $info['aac']['header']['raw']['original']; - $info['aac']['header']['home'] = (bool) $info['aac']['header']['raw']['home']; - $info['aac']['header']['channels'] = (($info['aac']['header']['raw']['channels_code'] == 7) ? 8 : $info['aac']['header']['raw']['channels_code']); - if ($ReturnExtendedInfo) { - $info['aac'][$framenumber]['copyright_id_bit'] = (bool) $info['aac']['header']['raw']['copyright_stream']; - $info['aac'][$framenumber]['copyright_id_start'] = (bool) $info['aac']['header']['raw']['copyright_start']; - } - - if ($info['aac']['header']['raw']['mpeg_layer'] != 0) { - $this->warning('Layer error - expected "0", found "'.$info['aac']['header']['raw']['mpeg_layer'].'" instead'); - } - if ($info['aac']['header']['sample_frequency'] == 0) { - $this->error('Corrupt AAC file: sample_frequency == zero'); - return false; - } - - $info['audio']['sample_rate'] = $info['aac']['header']['sample_frequency']; - $info['audio']['channels'] = $info['aac']['header']['channels']; - } - - $FrameLength = ($header2 & 0x0003FFE0) >> 5; - - if (!isset($BitrateCache[$FrameLength])) { - $BitrateCache[$FrameLength] = ($info['aac']['header']['sample_frequency'] / 1024) * $FrameLength * 8; - } - getid3_lib::safe_inc($info['aac']['bitrate_distribution'][$BitrateCache[$FrameLength]], 1); - - $info['aac'][$framenumber]['aac_frame_length'] = $FrameLength; - - $info['aac'][$framenumber]['adts_buffer_fullness'] = (($header2 & 0x0000001F) << 6) & (($header3 & 0xFC) >> 2); - if ($info['aac'][$framenumber]['adts_buffer_fullness'] == 0x07FF) { - $info['audio']['bitrate_mode'] = 'vbr'; - } else { - $info['audio']['bitrate_mode'] = 'cbr'; - } - $info['aac'][$framenumber]['num_raw_data_blocks'] = (($header3 & 0x03) >> 0); - - if ($info['aac']['header']['crc_present']) { - //$info['aac'][$framenumber]['crc'] = getid3_lib::BigEndian2Int(substr($substring, 7, 2); - } - - if (!$ReturnExtendedInfo) { - unset($info['aac'][$framenumber]); - } - - /* - $rounded_precision = 5000; - $info['aac']['bitrate_distribution_rounded'] = array(); - foreach ($info['aac']['bitrate_distribution'] as $bitrate => $count) { - $rounded_bitrate = round($bitrate / $rounded_precision) * $rounded_precision; - getid3_lib::safe_inc($info['aac']['bitrate_distribution_rounded'][$rounded_bitrate], $count); - } - ksort($info['aac']['bitrate_distribution_rounded']); - */ - - $byteoffset += $FrameLength; - if ((++$framenumber < $MaxFramesToScan) && (($byteoffset + 10) < $info['avdataend'])) { - - // keep scanning - - } else { - - $info['aac']['frames'] = $framenumber; - $info['playtime_seconds'] = ($info['avdataend'] / $byteoffset) * (($framenumber * 1024) / $info['aac']['header']['sample_frequency']); // (1 / % of file scanned) * (samples / (samples/sec)) = seconds - if ($info['playtime_seconds'] == 0) { - $this->error('Corrupt AAC file: playtime_seconds == zero'); - return false; - } - $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; - ksort($info['aac']['bitrate_distribution']); - - $info['audio']['encoder_options'] = $info['aac']['header_type'].' '.$info['aac']['header']['profile']; - - return true; - - } - } - // should never get here. - } - - public static function AACsampleRateLookup($samplerateid) { - static $AACsampleRateLookup = array(); - if (empty($AACsampleRateLookup)) { - $AACsampleRateLookup[0] = 96000; - $AACsampleRateLookup[1] = 88200; - $AACsampleRateLookup[2] = 64000; - $AACsampleRateLookup[3] = 48000; - $AACsampleRateLookup[4] = 44100; - $AACsampleRateLookup[5] = 32000; - $AACsampleRateLookup[6] = 24000; - $AACsampleRateLookup[7] = 22050; - $AACsampleRateLookup[8] = 16000; - $AACsampleRateLookup[9] = 12000; - $AACsampleRateLookup[10] = 11025; - $AACsampleRateLookup[11] = 8000; - $AACsampleRateLookup[12] = 0; - $AACsampleRateLookup[13] = 0; - $AACsampleRateLookup[14] = 0; - $AACsampleRateLookup[15] = 0; - } - return (isset($AACsampleRateLookup[$samplerateid]) ? $AACsampleRateLookup[$samplerateid] : 'invalid'); - } - - public static function AACprofileLookup($profileid, $mpegversion) { - static $AACprofileLookup = array(); - if (empty($AACprofileLookup)) { - $AACprofileLookup[2][0] = 'Main profile'; - $AACprofileLookup[2][1] = 'Low Complexity profile (LC)'; - $AACprofileLookup[2][2] = 'Scalable Sample Rate profile (SSR)'; - $AACprofileLookup[2][3] = '(reserved)'; - $AACprofileLookup[4][0] = 'AAC_MAIN'; - $AACprofileLookup[4][1] = 'AAC_LC'; - $AACprofileLookup[4][2] = 'AAC_SSR'; - $AACprofileLookup[4][3] = 'AAC_LTP'; - } - return (isset($AACprofileLookup[$mpegversion][$profileid]) ? $AACprofileLookup[$mpegversion][$profileid] : 'invalid'); - } - - public static function AACchannelCountCalculate($program_configs) { - $channels = 0; - for ($i = 0; $i < $program_configs['num_front_channel_elements']; $i++) { - $channels++; - if ($program_configs['front_element_is_cpe'][$i]) { - // each front element is channel pair (CPE = Channel Pair Element) - $channels++; - } - } - for ($i = 0; $i < $program_configs['num_side_channel_elements']; $i++) { - $channels++; - if ($program_configs['side_element_is_cpe'][$i]) { - // each side element is channel pair (CPE = Channel Pair Element) - $channels++; - } - } - for ($i = 0; $i < $program_configs['num_back_channel_elements']; $i++) { - $channels++; - if ($program_configs['back_element_is_cpe'][$i]) { - // each back element is channel pair (CPE = Channel Pair Element) - $channels++; - } - } - for ($i = 0; $i < $program_configs['num_lfe_channel_elements']; $i++) { - $channels++; - } - return $channels; - } - + public function Analyze() + { + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + if ($this->fread(4) == 'ADIF') { + $this->getAACADIFheaderFilepointer(); + } else { + $this->getAACADTSheaderFilepointer(); + } + + return true; + } + + public function getAACADIFheaderFilepointer() + { + $info = &$this->getid3->info; + $info['fileformat'] = 'aac'; + $info['audio']['dataformat'] = 'aac'; + $info['audio']['lossless'] = false; + + $this->fseek($info['avdataoffset']); + $AACheader = $this->fread(1024); + $offset = 0; + + if (substr($AACheader, 0, 4) == 'ADIF') { + + // http://faac.sourceforge.net/wiki/index.php?page=ADIF + + // http://libmpeg.org/mpeg4/doc/w2203tfs.pdf + // adif_header() { + // adif_id 32 + // copyright_id_present 1 + // if( copyright_id_present ) + // copyright_id 72 + // original_copy 1 + // home 1 + // bitstream_type 1 + // bitrate 23 + // num_program_config_elements 4 + // for (i = 0; i < num_program_config_elements + 1; i++ ) { + // if( bitstream_type == '0' ) + // adif_buffer_fullness 20 + // program_config_element() + // } + // } + + $AACheaderBitstream = getid3_lib::BigEndian2Bin($AACheader); + $bitoffset = 0; + + $info['aac']['header_type'] = 'ADIF'; + $bitoffset += 32; + $info['aac']['header']['mpeg_version'] = 4; + + $info['aac']['header']['copyright'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1'); + $bitoffset += 1; + if ($info['aac']['header']['copyright']) { + $info['aac']['header']['copyright_id'] = getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 72)); + $bitoffset += 72; + } + $info['aac']['header']['original_copy'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1'); + $bitoffset += 1; + $info['aac']['header']['home'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1'); + $bitoffset += 1; + $info['aac']['header']['is_vbr'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1'); + $bitoffset += 1; + if ($info['aac']['header']['is_vbr']) { + $info['audio']['bitrate_mode'] = 'vbr'; + $info['aac']['header']['bitrate_max'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23)); + $bitoffset += 23; + } else { + $info['audio']['bitrate_mode'] = 'cbr'; + $info['aac']['header']['bitrate'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23)); + $bitoffset += 23; + $info['audio']['bitrate'] = $info['aac']['header']['bitrate']; + } + if ($info['audio']['bitrate'] == 0) { + $this->error('Corrupt AAC file: bitrate_audio == zero'); + + return false; + } + $info['aac']['header']['num_program_configs'] = 1 + getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + + for ($i = 0; $i < $info['aac']['header']['num_program_configs']; $i++) { + // http://www.audiocoding.com/wiki/index.php?page=program_config_element + + // buffer_fullness 20 + + // element_instance_tag 4 + // object_type 2 + // sampling_frequency_index 4 + // num_front_channel_elements 4 + // num_side_channel_elements 4 + // num_back_channel_elements 4 + // num_lfe_channel_elements 2 + // num_assoc_data_elements 3 + // num_valid_cc_elements 4 + // mono_mixdown_present 1 + // mono_mixdown_element_number 4 if mono_mixdown_present == 1 + // stereo_mixdown_present 1 + // stereo_mixdown_element_number 4 if stereo_mixdown_present == 1 + // matrix_mixdown_idx_present 1 + // matrix_mixdown_idx 2 if matrix_mixdown_idx_present == 1 + // pseudo_surround_enable 1 if matrix_mixdown_idx_present == 1 + // for (i = 0; i < num_front_channel_elements; i++) { + // front_element_is_cpe[i] 1 + // front_element_tag_select[i] 4 + // } + // for (i = 0; i < num_side_channel_elements; i++) { + // side_element_is_cpe[i] 1 + // side_element_tag_select[i] 4 + // } + // for (i = 0; i < num_back_channel_elements; i++) { + // back_element_is_cpe[i] 1 + // back_element_tag_select[i] 4 + // } + // for (i = 0; i < num_lfe_channel_elements; i++) { + // lfe_element_tag_select[i] 4 + // } + // for (i = 0; i < num_assoc_data_elements; i++) { + // assoc_data_element_tag_select[i] 4 + // } + // for (i = 0; i < num_valid_cc_elements; i++) { + // cc_element_is_ind_sw[i] 1 + // valid_cc_element_tag_select[i] 4 + // } + // byte_alignment() VAR + // comment_field_bytes 8 + // for (i = 0; i < comment_field_bytes; i++) { + // comment_field_data[i] 8 + // } + + if (! $info['aac']['header']['is_vbr']) { + $info['aac']['program_configs'][$i]['buffer_fullness'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 20)); + $bitoffset += 20; + } + $info['aac']['program_configs'][$i]['element_instance_tag'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + $info['aac']['program_configs'][$i]['object_type'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2)); + $bitoffset += 2; + $info['aac']['program_configs'][$i]['sampling_frequency_index'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + $info['aac']['program_configs'][$i]['num_front_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + $info['aac']['program_configs'][$i]['num_side_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + $info['aac']['program_configs'][$i]['num_back_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + $info['aac']['program_configs'][$i]['num_lfe_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2)); + $bitoffset += 2; + $info['aac']['program_configs'][$i]['num_assoc_data_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 3)); + $bitoffset += 3; + $info['aac']['program_configs'][$i]['num_valid_cc_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + $info['aac']['program_configs'][$i]['mono_mixdown_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + if ($info['aac']['program_configs'][$i]['mono_mixdown_present']) { + $info['aac']['program_configs'][$i]['mono_mixdown_element_number'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + $info['aac']['program_configs'][$i]['stereo_mixdown_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + if ($info['aac']['program_configs'][$i]['stereo_mixdown_present']) { + $info['aac']['program_configs'][$i]['stereo_mixdown_element_number'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + $info['aac']['program_configs'][$i]['matrix_mixdown_idx_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + if ($info['aac']['program_configs'][$i]['matrix_mixdown_idx_present']) { + $info['aac']['program_configs'][$i]['matrix_mixdown_idx'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2)); + $bitoffset += 2; + $info['aac']['program_configs'][$i]['pseudo_surround_enable'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + } + for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_front_channel_elements']; $j++) { + $info['aac']['program_configs'][$i]['front_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + $info['aac']['program_configs'][$i]['front_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_side_channel_elements']; $j++) { + $info['aac']['program_configs'][$i]['side_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + $info['aac']['program_configs'][$i]['side_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_back_channel_elements']; $j++) { + $info['aac']['program_configs'][$i]['back_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + $info['aac']['program_configs'][$i]['back_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_lfe_channel_elements']; $j++) { + $info['aac']['program_configs'][$i]['lfe_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_assoc_data_elements']; $j++) { + $info['aac']['program_configs'][$i]['assoc_data_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_valid_cc_elements']; $j++) { + $info['aac']['program_configs'][$i]['cc_element_is_ind_sw'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + $info['aac']['program_configs'][$i]['valid_cc_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + + $bitoffset = ceil($bitoffset / 8) * 8; + + $info['aac']['program_configs'][$i]['comment_field_bytes'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 8)); + $bitoffset += 8; + $info['aac']['program_configs'][$i]['comment_field'] = getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 8 * $info['aac']['program_configs'][$i]['comment_field_bytes'])); + $bitoffset += 8 * $info['aac']['program_configs'][$i]['comment_field_bytes']; + + $info['aac']['header']['profile'] = self::AACprofileLookup($info['aac']['program_configs'][$i]['object_type'], $info['aac']['header']['mpeg_version']); + $info['aac']['program_configs'][$i]['sampling_frequency'] = self::AACsampleRateLookup($info['aac']['program_configs'][$i]['sampling_frequency_index']); + $info['audio']['sample_rate'] = $info['aac']['program_configs'][$i]['sampling_frequency']; + $info['audio']['channels'] = self::AACchannelCountCalculate($info['aac']['program_configs'][$i]); + if ($info['aac']['program_configs'][$i]['comment_field']) { + $info['aac']['comments'][] = $info['aac']['program_configs'][$i]['comment_field']; + } + } + $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['audio']['bitrate']; + + $info['audio']['encoder_options'] = $info['aac']['header_type'].' '.$info['aac']['header']['profile']; + + return true; + } else { + unset($info['fileformat']); + unset($info['aac']); + $this->error('AAC-ADIF synch not found at offset '.$info['avdataoffset'].' (expected "ADIF", found "'.substr($AACheader, 0, 4).'" instead)'); + + return false; + } + } + + public function getAACADTSheaderFilepointer($MaxFramesToScan = 1000000, $ReturnExtendedInfo = false) + { + $info = &$this->getid3->info; + + // based loosely on code from AACfile by Jurgen Faul + // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html + + // http://faac.sourceforge.net/wiki/index.php?page=ADTS // dead link + // http://wiki.multimedia.cx/index.php?title=ADTS + + // * ADTS Fixed Header: these don't change from frame to frame + // syncword 12 always: '111111111111' + // ID 1 0: MPEG-4, 1: MPEG-2 + // MPEG layer 2 If you send AAC in MPEG-TS, set to 0 + // protection_absent 1 0: CRC present; 1: no CRC + // profile 2 0: AAC Main; 1: AAC LC (Low Complexity); 2: AAC SSR (Scalable Sample Rate); 3: AAC LTP (Long Term Prediction) + // sampling_frequency_index 4 15 not allowed + // private_bit 1 usually 0 + // channel_configuration 3 + // original/copy 1 0: original; 1: copy + // home 1 usually 0 + // emphasis 2 only if ID == 0 (ie MPEG-4) // not present in some documentation? + + // * ADTS Variable Header: these can change from frame to frame + // copyright_identification_bit 1 + // copyright_identification_start 1 + // aac_frame_length 13 length of the frame including header (in bytes) + // adts_buffer_fullness 11 0x7FF indicates VBR + // no_raw_data_blocks_in_frame 2 + + // * ADTS Error check + // crc_check 16 only if protection_absent == 0 + + $byteoffset = $info['avdataoffset']; + $framenumber = 0; + + // Init bit pattern array + static $decbin = []; + + // Populate $bindec + for ($i = 0; $i < 256; $i++) { + $decbin[chr($i)] = str_pad(decbin($i), 8, '0', STR_PAD_LEFT); + } + + // used to calculate bitrate below + $BitrateCache = []; + + while (true) { + // breaks out when end-of-file encountered, or invalid data found, + // or MaxFramesToScan frames have been scanned + + if (! getid3_lib::intValueSupported($byteoffset)) { + $this->warning('Unable to parse AAC file beyond '.$this->ftell().' (PHP does not support file operations beyond '.round(PHP_INT_MAX / 1073741824).'GB)'); + + return false; + } + $this->fseek($byteoffset); + + // First get substring + $substring = $this->fread(9); // header is 7 bytes (or 9 if CRC is present) + $substringlength = strlen($substring); + if ($substringlength != 9) { + $this->error('Failed to read 7 bytes at offset '.($this->ftell() - $substringlength).' (only read '.$substringlength.' bytes)'); + + return false; + } + // this would be easier with 64-bit math, but split it up to allow for 32-bit: + $header1 = getid3_lib::BigEndian2Int(substr($substring, 0, 2)); + $header2 = getid3_lib::BigEndian2Int(substr($substring, 2, 4)); + $header3 = getid3_lib::BigEndian2Int(substr($substring, 6, 1)); + + $info['aac']['header']['raw']['syncword'] = ($header1 & 0xFFF0) >> 4; + if ($info['aac']['header']['raw']['syncword'] != 0x0FFF) { + $this->error('Synch pattern (0x0FFF) not found at offset '.($this->ftell() - $substringlength).' (found 0x0'.strtoupper(dechex($info['aac']['header']['raw']['syncword'])).' instead)'); + //if ($info['fileformat'] == 'aac') { + // return true; + //} + unset($info['aac']); + + return false; + } + + // Gather info for first frame only - this takes time to do 1000 times! + if ($framenumber == 0) { + $info['aac']['header_type'] = 'ADTS'; + $info['fileformat'] = 'aac'; + $info['audio']['dataformat'] = 'aac'; + + $info['aac']['header']['raw']['mpeg_version'] = ($header1 & 0x0008) >> 3; + $info['aac']['header']['raw']['mpeg_layer'] = ($header1 & 0x0006) >> 1; + $info['aac']['header']['raw']['protection_absent'] = ($header1 & 0x0001) >> 0; + + $info['aac']['header']['raw']['profile_code'] = ($header2 & 0xC0000000) >> 30; + $info['aac']['header']['raw']['sample_rate_code'] = ($header2 & 0x3C000000) >> 26; + $info['aac']['header']['raw']['private_stream'] = ($header2 & 0x02000000) >> 25; + $info['aac']['header']['raw']['channels_code'] = ($header2 & 0x01C00000) >> 22; + $info['aac']['header']['raw']['original'] = ($header2 & 0x00200000) >> 21; + $info['aac']['header']['raw']['home'] = ($header2 & 0x00100000) >> 20; + $info['aac']['header']['raw']['copyright_stream'] = ($header2 & 0x00080000) >> 19; + $info['aac']['header']['raw']['copyright_start'] = ($header2 & 0x00040000) >> 18; + $info['aac']['header']['raw']['frame_length'] = ($header2 & 0x0003FFE0) >> 5; + + $info['aac']['header']['mpeg_version'] = ($info['aac']['header']['raw']['mpeg_version'] ? 2 : 4); + $info['aac']['header']['crc_present'] = ($info['aac']['header']['raw']['protection_absent'] ? false : true); + $info['aac']['header']['profile'] = self::AACprofileLookup($info['aac']['header']['raw']['profile_code'], $info['aac']['header']['mpeg_version']); + $info['aac']['header']['sample_frequency'] = self::AACsampleRateLookup($info['aac']['header']['raw']['sample_rate_code']); + $info['aac']['header']['private'] = (bool) $info['aac']['header']['raw']['private_stream']; + $info['aac']['header']['original'] = (bool) $info['aac']['header']['raw']['original']; + $info['aac']['header']['home'] = (bool) $info['aac']['header']['raw']['home']; + $info['aac']['header']['channels'] = (($info['aac']['header']['raw']['channels_code'] == 7) ? 8 : $info['aac']['header']['raw']['channels_code']); + if ($ReturnExtendedInfo) { + $info['aac'][$framenumber]['copyright_id_bit'] = (bool) $info['aac']['header']['raw']['copyright_stream']; + $info['aac'][$framenumber]['copyright_id_start'] = (bool) $info['aac']['header']['raw']['copyright_start']; + } + + if ($info['aac']['header']['raw']['mpeg_layer'] != 0) { + $this->warning('Layer error - expected "0", found "'.$info['aac']['header']['raw']['mpeg_layer'].'" instead'); + } + if ($info['aac']['header']['sample_frequency'] == 0) { + $this->error('Corrupt AAC file: sample_frequency == zero'); + + return false; + } + + $info['audio']['sample_rate'] = $info['aac']['header']['sample_frequency']; + $info['audio']['channels'] = $info['aac']['header']['channels']; + } + + $FrameLength = ($header2 & 0x0003FFE0) >> 5; + + if (! isset($BitrateCache[$FrameLength])) { + $BitrateCache[$FrameLength] = ($info['aac']['header']['sample_frequency'] / 1024) * $FrameLength * 8; + } + getid3_lib::safe_inc($info['aac']['bitrate_distribution'][$BitrateCache[$FrameLength]], 1); + + $info['aac'][$framenumber]['aac_frame_length'] = $FrameLength; + + $info['aac'][$framenumber]['adts_buffer_fullness'] = (($header2 & 0x0000001F) << 6) & (($header3 & 0xFC) >> 2); + if ($info['aac'][$framenumber]['adts_buffer_fullness'] == 0x07FF) { + $info['audio']['bitrate_mode'] = 'vbr'; + } else { + $info['audio']['bitrate_mode'] = 'cbr'; + } + $info['aac'][$framenumber]['num_raw_data_blocks'] = (($header3 & 0x03) >> 0); + + if ($info['aac']['header']['crc_present']) { + //$info['aac'][$framenumber]['crc'] = getid3_lib::BigEndian2Int(substr($substring, 7, 2); + } + + if (! $ReturnExtendedInfo) { + unset($info['aac'][$framenumber]); + } + + /* + $rounded_precision = 5000; + $info['aac']['bitrate_distribution_rounded'] = array(); + foreach ($info['aac']['bitrate_distribution'] as $bitrate => $count) { + $rounded_bitrate = round($bitrate / $rounded_precision) * $rounded_precision; + getid3_lib::safe_inc($info['aac']['bitrate_distribution_rounded'][$rounded_bitrate], $count); + } + ksort($info['aac']['bitrate_distribution_rounded']); + */ + + $byteoffset += $FrameLength; + if ((++$framenumber < $MaxFramesToScan) && (($byteoffset + 10) < $info['avdataend'])) { + + // keep scanning + } else { + $info['aac']['frames'] = $framenumber; + $info['playtime_seconds'] = ($info['avdataend'] / $byteoffset) * (($framenumber * 1024) / $info['aac']['header']['sample_frequency']); // (1 / % of file scanned) * (samples / (samples/sec)) = seconds + if ($info['playtime_seconds'] == 0) { + $this->error('Corrupt AAC file: playtime_seconds == zero'); + + return false; + } + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + ksort($info['aac']['bitrate_distribution']); + + $info['audio']['encoder_options'] = $info['aac']['header_type'].' '.$info['aac']['header']['profile']; + + return true; + } + } + // should never get here. + } + + public static function AACsampleRateLookup($samplerateid) + { + static $AACsampleRateLookup = []; + if (empty($AACsampleRateLookup)) { + $AACsampleRateLookup[0] = 96000; + $AACsampleRateLookup[1] = 88200; + $AACsampleRateLookup[2] = 64000; + $AACsampleRateLookup[3] = 48000; + $AACsampleRateLookup[4] = 44100; + $AACsampleRateLookup[5] = 32000; + $AACsampleRateLookup[6] = 24000; + $AACsampleRateLookup[7] = 22050; + $AACsampleRateLookup[8] = 16000; + $AACsampleRateLookup[9] = 12000; + $AACsampleRateLookup[10] = 11025; + $AACsampleRateLookup[11] = 8000; + $AACsampleRateLookup[12] = 0; + $AACsampleRateLookup[13] = 0; + $AACsampleRateLookup[14] = 0; + $AACsampleRateLookup[15] = 0; + } + + return isset($AACsampleRateLookup[$samplerateid]) ? $AACsampleRateLookup[$samplerateid] : 'invalid'; + } + + public static function AACprofileLookup($profileid, $mpegversion) + { + static $AACprofileLookup = []; + if (empty($AACprofileLookup)) { + $AACprofileLookup[2][0] = 'Main profile'; + $AACprofileLookup[2][1] = 'Low Complexity profile (LC)'; + $AACprofileLookup[2][2] = 'Scalable Sample Rate profile (SSR)'; + $AACprofileLookup[2][3] = '(reserved)'; + $AACprofileLookup[4][0] = 'AAC_MAIN'; + $AACprofileLookup[4][1] = 'AAC_LC'; + $AACprofileLookup[4][2] = 'AAC_SSR'; + $AACprofileLookup[4][3] = 'AAC_LTP'; + } + + return isset($AACprofileLookup[$mpegversion][$profileid]) ? $AACprofileLookup[$mpegversion][$profileid] : 'invalid'; + } + + public static function AACchannelCountCalculate($program_configs) + { + $channels = 0; + for ($i = 0; $i < $program_configs['num_front_channel_elements']; $i++) { + $channels++; + if ($program_configs['front_element_is_cpe'][$i]) { + // each front element is channel pair (CPE = Channel Pair Element) + $channels++; + } + } + for ($i = 0; $i < $program_configs['num_side_channel_elements']; $i++) { + $channels++; + if ($program_configs['side_element_is_cpe'][$i]) { + // each side element is channel pair (CPE = Channel Pair Element) + $channels++; + } + } + for ($i = 0; $i < $program_configs['num_back_channel_elements']; $i++) { + $channels++; + if ($program_configs['back_element_is_cpe'][$i]) { + // each back element is channel pair (CPE = Channel Pair Element) + $channels++; + } + } + for ($i = 0; $i < $program_configs['num_lfe_channel_elements']; $i++) { + $channels++; + } + + return $channels; + } } diff --git a/app/Library/getid3/getid3/module.audio.ac3.php b/app/Library/getid3/getid3/module.audio.ac3.php index c370c7f6..5d1c31b1 100644 --- a/app/Library/getid3/getid3/module.audio.ac3.php +++ b/app/Library/getid3/getid3/module.audio.ac3.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,720 +15,768 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_ac3 extends getid3_handler { - private $AC3header = array(); + private $AC3header = []; private $BSIoffset = 0; const syncword = 0x0B77; - public function Analyze() { - $info = &$this->getid3->info; + public function Analyze() + { + $info = &$this->getid3->info; - ///AH - $info['ac3']['raw']['bsi'] = array(); - $thisfile_ac3 = &$info['ac3']; - $thisfile_ac3_raw = &$thisfile_ac3['raw']; - $thisfile_ac3_raw_bsi = &$thisfile_ac3_raw['bsi']; + ///AH + $info['ac3']['raw']['bsi'] = []; + $thisfile_ac3 = &$info['ac3']; + $thisfile_ac3_raw = &$thisfile_ac3['raw']; + $thisfile_ac3_raw_bsi = &$thisfile_ac3_raw['bsi']; + // http://www.atsc.org/standards/a_52a.pdf - // http://www.atsc.org/standards/a_52a.pdf + $info['fileformat'] = 'ac3'; - $info['fileformat'] = 'ac3'; + // An AC-3 serial coded audio bit stream is made up of a sequence of synchronization frames + // Each synchronization frame contains 6 coded audio blocks (AB), each of which represent 256 + // new audio samples per channel. A synchronization information (SI) header at the beginning + // of each frame contains information needed to acquire and maintain synchronization. A + // bit stream information (BSI) header follows SI, and contains parameters describing the coded + // audio service. The coded audio blocks may be followed by an auxiliary data (Aux) field. At the + // end of each frame is an error check field that includes a CRC word for error detection. An + // additional CRC word is located in the SI header, the use of which, by a decoder, is optional. + // + // syncinfo() | bsi() | AB0 | AB1 | AB2 | AB3 | AB4 | AB5 | Aux | CRC - // An AC-3 serial coded audio bit stream is made up of a sequence of synchronization frames - // Each synchronization frame contains 6 coded audio blocks (AB), each of which represent 256 - // new audio samples per channel. A synchronization information (SI) header at the beginning - // of each frame contains information needed to acquire and maintain synchronization. A - // bit stream information (BSI) header follows SI, and contains parameters describing the coded - // audio service. The coded audio blocks may be followed by an auxiliary data (Aux) field. At the - // end of each frame is an error check field that includes a CRC word for error detection. An - // additional CRC word is located in the SI header, the use of which, by a decoder, is optional. - // - // syncinfo() | bsi() | AB0 | AB1 | AB2 | AB3 | AB4 | AB5 | Aux | CRC + // syncinfo() { + // syncword 16 + // crc1 16 + // fscod 2 + // frmsizecod 6 + // } /* end of syncinfo */ - // syncinfo() { - // syncword 16 - // crc1 16 - // fscod 2 - // frmsizecod 6 - // } /* end of syncinfo */ + $this->fseek($info['avdataoffset']); + $tempAC3header = $this->fread(100); // should be enough to cover all data, there are some variable-length fields...? + $this->AC3header['syncinfo'] = getid3_lib::BigEndian2Int(substr($tempAC3header, 0, 2)); + $this->AC3header['bsi'] = getid3_lib::BigEndian2Bin(substr($tempAC3header, 2)); + $thisfile_ac3_raw_bsi['bsid'] = (getid3_lib::LittleEndian2Int(substr($tempAC3header, 5, 1)) & 0xF8) >> 3; // AC3 and E-AC3 put the "bsid" version identifier in the same place, but unfortnately the 4 bytes between the syncword and the version identifier are interpreted differently, so grab it here so the following code structure can make sense + unset($tempAC3header); - $this->fseek($info['avdataoffset']); - $tempAC3header = $this->fread(100); // should be enough to cover all data, there are some variable-length fields...? - $this->AC3header['syncinfo'] = getid3_lib::BigEndian2Int(substr($tempAC3header, 0, 2)); - $this->AC3header['bsi'] = getid3_lib::BigEndian2Bin(substr($tempAC3header, 2)); - $thisfile_ac3_raw_bsi['bsid'] = (getid3_lib::LittleEndian2Int(substr($tempAC3header, 5, 1)) & 0xF8) >> 3; // AC3 and E-AC3 put the "bsid" version identifier in the same place, but unfortnately the 4 bytes between the syncword and the version identifier are interpreted differently, so grab it here so the following code structure can make sense - unset($tempAC3header); + if ($this->AC3header['syncinfo'] !== self::syncword) { + if (! $this->isDependencyFor('matroska')) { + unset($info['fileformat'], $info['ac3']); - if ($this->AC3header['syncinfo'] !== self::syncword) { - if (!$this->isDependencyFor('matroska')) { - unset($info['fileformat'], $info['ac3']); - return $this->error('Expecting "'.dechex(self::syncword).'" at offset '.$info['avdataoffset'].', found "'.dechex($this->AC3header['syncinfo']).'"'); - } - } + return $this->error('Expecting "'.dechex(self::syncword).'" at offset '.$info['avdataoffset'].', found "'.dechex($this->AC3header['syncinfo']).'"'); + } + } - $info['audio']['dataformat'] = 'ac3'; - $info['audio']['bitrate_mode'] = 'cbr'; - $info['audio']['lossless'] = false; + $info['audio']['dataformat'] = 'ac3'; + $info['audio']['bitrate_mode'] = 'cbr'; + $info['audio']['lossless'] = false; - if ($thisfile_ac3_raw_bsi['bsid'] <= 8) { + if ($thisfile_ac3_raw_bsi['bsid'] <= 8) { + $thisfile_ac3_raw_bsi['crc1'] = getid3_lib::Bin2Dec($this->readHeaderBSI(16)); + $thisfile_ac3_raw_bsi['fscod'] = $this->readHeaderBSI(2); // 5.4.1.3 + $thisfile_ac3_raw_bsi['frmsizecod'] = $this->readHeaderBSI(6); // 5.4.1.4 + if ($thisfile_ac3_raw_bsi['frmsizecod'] > 37) { // binary: 100101 - see Table 5.18 Frame Size Code Table (1 word = 16 bits) + $this->warning('Unexpected ac3.bsi.frmsizecod value: '.$thisfile_ac3_raw_bsi['frmsizecod'].', bitrate not set correctly'); + } - $thisfile_ac3_raw_bsi['crc1'] = getid3_lib::Bin2Dec($this->readHeaderBSI(16)); - $thisfile_ac3_raw_bsi['fscod'] = $this->readHeaderBSI(2); // 5.4.1.3 - $thisfile_ac3_raw_bsi['frmsizecod'] = $this->readHeaderBSI(6); // 5.4.1.4 - if ($thisfile_ac3_raw_bsi['frmsizecod'] > 37) { // binary: 100101 - see Table 5.18 Frame Size Code Table (1 word = 16 bits) - $this->warning('Unexpected ac3.bsi.frmsizecod value: '.$thisfile_ac3_raw_bsi['frmsizecod'].', bitrate not set correctly'); - } + $thisfile_ac3_raw_bsi['bsid'] = $this->readHeaderBSI(5); // we already know this from pre-parsing the version identifier, but re-read it to let the bitstream flow as intended + $thisfile_ac3_raw_bsi['bsmod'] = $this->readHeaderBSI(3); + $thisfile_ac3_raw_bsi['acmod'] = $this->readHeaderBSI(3); - $thisfile_ac3_raw_bsi['bsid'] = $this->readHeaderBSI(5); // we already know this from pre-parsing the version identifier, but re-read it to let the bitstream flow as intended - $thisfile_ac3_raw_bsi['bsmod'] = $this->readHeaderBSI(3); - $thisfile_ac3_raw_bsi['acmod'] = $this->readHeaderBSI(3); + if ($thisfile_ac3_raw_bsi['acmod'] & 0x01) { + // If the lsb of acmod is a 1, center channel is in use and cmixlev follows in the bit stream. + $thisfile_ac3_raw_bsi['cmixlev'] = $this->readHeaderBSI(2); + $thisfile_ac3['center_mix_level'] = self::centerMixLevelLookup($thisfile_ac3_raw_bsi['cmixlev']); + } - if ($thisfile_ac3_raw_bsi['acmod'] & 0x01) { - // If the lsb of acmod is a 1, center channel is in use and cmixlev follows in the bit stream. - $thisfile_ac3_raw_bsi['cmixlev'] = $this->readHeaderBSI(2); - $thisfile_ac3['center_mix_level'] = self::centerMixLevelLookup($thisfile_ac3_raw_bsi['cmixlev']); - } + if ($thisfile_ac3_raw_bsi['acmod'] & 0x04) { + // If the msb of acmod is a 1, surround channels are in use and surmixlev follows in the bit stream. + $thisfile_ac3_raw_bsi['surmixlev'] = $this->readHeaderBSI(2); + $thisfile_ac3['surround_mix_level'] = self::surroundMixLevelLookup($thisfile_ac3_raw_bsi['surmixlev']); + } - if ($thisfile_ac3_raw_bsi['acmod'] & 0x04) { - // If the msb of acmod is a 1, surround channels are in use and surmixlev follows in the bit stream. - $thisfile_ac3_raw_bsi['surmixlev'] = $this->readHeaderBSI(2); - $thisfile_ac3['surround_mix_level'] = self::surroundMixLevelLookup($thisfile_ac3_raw_bsi['surmixlev']); - } + if ($thisfile_ac3_raw_bsi['acmod'] == 0x02) { + // When operating in the two channel mode, this 2-bit code indicates whether or not the program has been encoded in Dolby Surround. + $thisfile_ac3_raw_bsi['dsurmod'] = $this->readHeaderBSI(2); + $thisfile_ac3['dolby_surround_mode'] = self::dolbySurroundModeLookup($thisfile_ac3_raw_bsi['dsurmod']); + } - if ($thisfile_ac3_raw_bsi['acmod'] == 0x02) { - // When operating in the two channel mode, this 2-bit code indicates whether or not the program has been encoded in Dolby Surround. - $thisfile_ac3_raw_bsi['dsurmod'] = $this->readHeaderBSI(2); - $thisfile_ac3['dolby_surround_mode'] = self::dolbySurroundModeLookup($thisfile_ac3_raw_bsi['dsurmod']); - } + $thisfile_ac3_raw_bsi['flags']['lfeon'] = (bool) $this->readHeaderBSI(1); - $thisfile_ac3_raw_bsi['flags']['lfeon'] = (bool) $this->readHeaderBSI(1); + // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1-31. + // The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent. + $thisfile_ac3_raw_bsi['dialnorm'] = $this->readHeaderBSI(5); // 5.4.2.8 dialnorm: Dialogue Normalization, 5 Bits - // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1-31. - // The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent. - $thisfile_ac3_raw_bsi['dialnorm'] = $this->readHeaderBSI(5); // 5.4.2.8 dialnorm: Dialogue Normalization, 5 Bits + $thisfile_ac3_raw_bsi['flags']['compr'] = (bool) $this->readHeaderBSI(1); // 5.4.2.9 compre: Compression Gain Word Exists, 1 Bit + if ($thisfile_ac3_raw_bsi['flags']['compr']) { + $thisfile_ac3_raw_bsi['compr'] = $this->readHeaderBSI(8); // 5.4.2.10 compr: Compression Gain Word, 8 Bits + $thisfile_ac3['heavy_compression'] = self::heavyCompression($thisfile_ac3_raw_bsi['compr']); + } - $thisfile_ac3_raw_bsi['flags']['compr'] = (bool) $this->readHeaderBSI(1); // 5.4.2.9 compre: Compression Gain Word Exists, 1 Bit - if ($thisfile_ac3_raw_bsi['flags']['compr']) { - $thisfile_ac3_raw_bsi['compr'] = $this->readHeaderBSI(8); // 5.4.2.10 compr: Compression Gain Word, 8 Bits - $thisfile_ac3['heavy_compression'] = self::heavyCompression($thisfile_ac3_raw_bsi['compr']); - } + $thisfile_ac3_raw_bsi['flags']['langcod'] = (bool) $this->readHeaderBSI(1); // 5.4.2.11 langcode: Language Code Exists, 1 Bit + if ($thisfile_ac3_raw_bsi['flags']['langcod']) { + $thisfile_ac3_raw_bsi['langcod'] = $this->readHeaderBSI(8); // 5.4.2.12 langcod: Language Code, 8 Bits + } - $thisfile_ac3_raw_bsi['flags']['langcod'] = (bool) $this->readHeaderBSI(1); // 5.4.2.11 langcode: Language Code Exists, 1 Bit - if ($thisfile_ac3_raw_bsi['flags']['langcod']) { - $thisfile_ac3_raw_bsi['langcod'] = $this->readHeaderBSI(8); // 5.4.2.12 langcod: Language Code, 8 Bits - } + $thisfile_ac3_raw_bsi['flags']['audprodinfo'] = (bool) $this->readHeaderBSI(1); // 5.4.2.13 audprodie: Audio Production Information Exists, 1 Bit + if ($thisfile_ac3_raw_bsi['flags']['audprodinfo']) { + $thisfile_ac3_raw_bsi['mixlevel'] = $this->readHeaderBSI(5); // 5.4.2.14 mixlevel: Mixing Level, 5 Bits + $thisfile_ac3_raw_bsi['roomtyp'] = $this->readHeaderBSI(2); // 5.4.2.15 roomtyp: Room Type, 2 Bits - $thisfile_ac3_raw_bsi['flags']['audprodinfo'] = (bool) $this->readHeaderBSI(1); // 5.4.2.13 audprodie: Audio Production Information Exists, 1 Bit - if ($thisfile_ac3_raw_bsi['flags']['audprodinfo']) { - $thisfile_ac3_raw_bsi['mixlevel'] = $this->readHeaderBSI(5); // 5.4.2.14 mixlevel: Mixing Level, 5 Bits - $thisfile_ac3_raw_bsi['roomtyp'] = $this->readHeaderBSI(2); // 5.4.2.15 roomtyp: Room Type, 2 Bits + $thisfile_ac3['mixing_level'] = (80 + $thisfile_ac3_raw_bsi['mixlevel']).'dB'; + $thisfile_ac3['room_type'] = self::roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp']); + } - $thisfile_ac3['mixing_level'] = (80 + $thisfile_ac3_raw_bsi['mixlevel']).'dB'; - $thisfile_ac3['room_type'] = self::roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp']); - } + $thisfile_ac3_raw_bsi['dialnorm2'] = $this->readHeaderBSI(5); // 5.4.2.16 dialnorm2: Dialogue Normalization, ch2, 5 Bits + $thisfile_ac3['dialogue_normalization2'] = '-'.$thisfile_ac3_raw_bsi['dialnorm2'].'dB'; // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1-31. The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent. + $thisfile_ac3_raw_bsi['flags']['compr2'] = (bool) $this->readHeaderBSI(1); // 5.4.2.17 compr2e: Compression Gain Word Exists, ch2, 1 Bit + if ($thisfile_ac3_raw_bsi['flags']['compr2']) { + $thisfile_ac3_raw_bsi['compr2'] = $this->readHeaderBSI(8); // 5.4.2.18 compr2: Compression Gain Word, ch2, 8 Bits + $thisfile_ac3['heavy_compression2'] = self::heavyCompression($thisfile_ac3_raw_bsi['compr2']); + } - $thisfile_ac3_raw_bsi['dialnorm2'] = $this->readHeaderBSI(5); // 5.4.2.16 dialnorm2: Dialogue Normalization, ch2, 5 Bits - $thisfile_ac3['dialogue_normalization2'] = '-'.$thisfile_ac3_raw_bsi['dialnorm2'].'dB'; // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1-31. The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent. + $thisfile_ac3_raw_bsi['flags']['langcod2'] = (bool) $this->readHeaderBSI(1); // 5.4.2.19 langcod2e: Language Code Exists, ch2, 1 Bit + if ($thisfile_ac3_raw_bsi['flags']['langcod2']) { + $thisfile_ac3_raw_bsi['langcod2'] = $this->readHeaderBSI(8); // 5.4.2.20 langcod2: Language Code, ch2, 8 Bits + } - $thisfile_ac3_raw_bsi['flags']['compr2'] = (bool) $this->readHeaderBSI(1); // 5.4.2.17 compr2e: Compression Gain Word Exists, ch2, 1 Bit - if ($thisfile_ac3_raw_bsi['flags']['compr2']) { - $thisfile_ac3_raw_bsi['compr2'] = $this->readHeaderBSI(8); // 5.4.2.18 compr2: Compression Gain Word, ch2, 8 Bits - $thisfile_ac3['heavy_compression2'] = self::heavyCompression($thisfile_ac3_raw_bsi['compr2']); - } + $thisfile_ac3_raw_bsi['flags']['audprodinfo2'] = (bool) $this->readHeaderBSI(1); // 5.4.2.21 audprodi2e: Audio Production Information Exists, ch2, 1 Bit + if ($thisfile_ac3_raw_bsi['flags']['audprodinfo2']) { + $thisfile_ac3_raw_bsi['mixlevel2'] = $this->readHeaderBSI(5); // 5.4.2.22 mixlevel2: Mixing Level, ch2, 5 Bits + $thisfile_ac3_raw_bsi['roomtyp2'] = $this->readHeaderBSI(2); // 5.4.2.23 roomtyp2: Room Type, ch2, 2 Bits - $thisfile_ac3_raw_bsi['flags']['langcod2'] = (bool) $this->readHeaderBSI(1); // 5.4.2.19 langcod2e: Language Code Exists, ch2, 1 Bit - if ($thisfile_ac3_raw_bsi['flags']['langcod2']) { - $thisfile_ac3_raw_bsi['langcod2'] = $this->readHeaderBSI(8); // 5.4.2.20 langcod2: Language Code, ch2, 8 Bits - } + $thisfile_ac3['mixing_level2'] = (80 + $thisfile_ac3_raw_bsi['mixlevel2']).'dB'; + $thisfile_ac3['room_type2'] = self::roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp2']); + } - $thisfile_ac3_raw_bsi['flags']['audprodinfo2'] = (bool) $this->readHeaderBSI(1); // 5.4.2.21 audprodi2e: Audio Production Information Exists, ch2, 1 Bit - if ($thisfile_ac3_raw_bsi['flags']['audprodinfo2']) { - $thisfile_ac3_raw_bsi['mixlevel2'] = $this->readHeaderBSI(5); // 5.4.2.22 mixlevel2: Mixing Level, ch2, 5 Bits - $thisfile_ac3_raw_bsi['roomtyp2'] = $this->readHeaderBSI(2); // 5.4.2.23 roomtyp2: Room Type, ch2, 2 Bits + $thisfile_ac3_raw_bsi['copyright'] = (bool) $this->readHeaderBSI(1); // 5.4.2.24 copyrightb: Copyright Bit, 1 Bit - $thisfile_ac3['mixing_level2'] = (80 + $thisfile_ac3_raw_bsi['mixlevel2']).'dB'; - $thisfile_ac3['room_type2'] = self::roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp2']); - } + $thisfile_ac3_raw_bsi['original'] = (bool) $this->readHeaderBSI(1); // 5.4.2.25 origbs: Original Bit Stream, 1 Bit - $thisfile_ac3_raw_bsi['copyright'] = (bool) $this->readHeaderBSI(1); // 5.4.2.24 copyrightb: Copyright Bit, 1 Bit + $thisfile_ac3_raw_bsi['flags']['timecod1'] = $this->readHeaderBSI(2); // 5.4.2.26 timecod1e, timcode2e: Time Code (first and second) Halves Exist, 2 Bits + if ($thisfile_ac3_raw_bsi['flags']['timecod1'] & 0x01) { + $thisfile_ac3_raw_bsi['timecod1'] = $this->readHeaderBSI(14); // 5.4.2.27 timecod1: Time code first half, 14 bits + $thisfile_ac3['timecode1'] = 0; + $thisfile_ac3['timecode1'] += (($thisfile_ac3_raw_bsi['timecod1'] & 0x3E00) >> 9) * 3600; // The first 5 bits of this 14-bit field represent the time in hours, with valid values of 0–23 + $thisfile_ac3['timecode1'] += (($thisfile_ac3_raw_bsi['timecod1'] & 0x01F8) >> 3) * 60; // The next 6 bits represent the time in minutes, with valid values of 0–59 + $thisfile_ac3['timecode1'] += (($thisfile_ac3_raw_bsi['timecod1'] & 0x0003) >> 0) * 8; // The final 3 bits represents the time in 8 second increments, with valid values of 0–7 (representing 0, 8, 16, ... 56 seconds) + } + if ($thisfile_ac3_raw_bsi['flags']['timecod1'] & 0x02) { + $thisfile_ac3_raw_bsi['timecod2'] = $this->readHeaderBSI(14); // 5.4.2.28 timecod2: Time code second half, 14 bits + $thisfile_ac3['timecode2'] = 0; + $thisfile_ac3['timecode2'] += (($thisfile_ac3_raw_bsi['timecod2'] & 0x3800) >> 11) * 1; // The first 3 bits of this 14-bit field represent the time in seconds, with valid values from 0–7 (representing 0-7 seconds) + $thisfile_ac3['timecode2'] += (($thisfile_ac3_raw_bsi['timecod2'] & 0x07C0) >> 6) * (1 / 30); // The next 5 bits represents the time in frames, with valid values from 0–29 (one frame = 1/30th of a second) + $thisfile_ac3['timecode2'] += (($thisfile_ac3_raw_bsi['timecod2'] & 0x003F) >> 0) * ((1 / 30) / 60); // The final 6 bits represents fractions of 1/64 of a frame, with valid values from 0–63 + } - $thisfile_ac3_raw_bsi['original'] = (bool) $this->readHeaderBSI(1); // 5.4.2.25 origbs: Original Bit Stream, 1 Bit + $thisfile_ac3_raw_bsi['flags']['addbsi'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['addbsi']) { + $thisfile_ac3_raw_bsi['addbsi_length'] = $this->readHeaderBSI(6) + 1; // This 6-bit code, which exists only if addbside is a 1, indicates the length in bytes of additional bit stream information. The valid range of addbsil is 0–63, indicating 1–64 additional bytes, respectively. - $thisfile_ac3_raw_bsi['flags']['timecod1'] = $this->readHeaderBSI(2); // 5.4.2.26 timecod1e, timcode2e: Time Code (first and second) Halves Exist, 2 Bits - if ($thisfile_ac3_raw_bsi['flags']['timecod1'] & 0x01) { - $thisfile_ac3_raw_bsi['timecod1'] = $this->readHeaderBSI(14); // 5.4.2.27 timecod1: Time code first half, 14 bits - $thisfile_ac3['timecode1'] = 0; - $thisfile_ac3['timecode1'] += (($thisfile_ac3_raw_bsi['timecod1'] & 0x3E00) >> 9) * 3600; // The first 5 bits of this 14-bit field represent the time in hours, with valid values of 0–23 - $thisfile_ac3['timecode1'] += (($thisfile_ac3_raw_bsi['timecod1'] & 0x01F8) >> 3) * 60; // The next 6 bits represent the time in minutes, with valid values of 0–59 - $thisfile_ac3['timecode1'] += (($thisfile_ac3_raw_bsi['timecod1'] & 0x0003) >> 0) * 8; // The final 3 bits represents the time in 8 second increments, with valid values of 0–7 (representing 0, 8, 16, ... 56 seconds) - } - if ($thisfile_ac3_raw_bsi['flags']['timecod1'] & 0x02) { - $thisfile_ac3_raw_bsi['timecod2'] = $this->readHeaderBSI(14); // 5.4.2.28 timecod2: Time code second half, 14 bits - $thisfile_ac3['timecode2'] = 0; - $thisfile_ac3['timecode2'] += (($thisfile_ac3_raw_bsi['timecod2'] & 0x3800) >> 11) * 1; // The first 3 bits of this 14-bit field represent the time in seconds, with valid values from 0–7 (representing 0-7 seconds) - $thisfile_ac3['timecode2'] += (($thisfile_ac3_raw_bsi['timecod2'] & 0x07C0) >> 6) * (1 / 30); // The next 5 bits represents the time in frames, with valid values from 0–29 (one frame = 1/30th of a second) - $thisfile_ac3['timecode2'] += (($thisfile_ac3_raw_bsi['timecod2'] & 0x003F) >> 0) * ((1 / 30) / 60); // The final 6 bits represents fractions of 1/64 of a frame, with valid values from 0–63 - } + $this->AC3header['bsi'] .= getid3_lib::BigEndian2Bin($this->fread($thisfile_ac3_raw_bsi['addbsi_length'])); - $thisfile_ac3_raw_bsi['flags']['addbsi'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['addbsi']) { - $thisfile_ac3_raw_bsi['addbsi_length'] = $this->readHeaderBSI(6) + 1; // This 6-bit code, which exists only if addbside is a 1, indicates the length in bytes of additional bit stream information. The valid range of addbsil is 0–63, indicating 1–64 additional bytes, respectively. + $thisfile_ac3_raw_bsi['addbsi_data'] = substr($this->AC3header['bsi'], $this->BSIoffset, $thisfile_ac3_raw_bsi['addbsi_length'] * 8); + $this->BSIoffset += $thisfile_ac3_raw_bsi['addbsi_length'] * 8; + } + } elseif ($thisfile_ac3_raw_bsi['bsid'] <= 16) { // E-AC3 - $this->AC3header['bsi'] .= getid3_lib::BigEndian2Bin($this->fread($thisfile_ac3_raw_bsi['addbsi_length'])); + $this->error('E-AC3 parsing is incomplete and experimental in this version of getID3 ('.$this->getid3->version().'). Notably the bitrate calculations are wrong -- value might (or not) be correct, but it is not calculated correctly. Email info@getid3.org if you know how to calculate EAC3 bitrate correctly.'); + $info['audio']['dataformat'] = 'eac3'; - $thisfile_ac3_raw_bsi['addbsi_data'] = substr($this->AC3header['bsi'], $this->BSIoffset, $thisfile_ac3_raw_bsi['addbsi_length'] * 8); - $this->BSIoffset += $thisfile_ac3_raw_bsi['addbsi_length'] * 8; - } + $thisfile_ac3_raw_bsi['strmtyp'] = $this->readHeaderBSI(2); + $thisfile_ac3_raw_bsi['substreamid'] = $this->readHeaderBSI(3); + $thisfile_ac3_raw_bsi['frmsiz'] = $this->readHeaderBSI(11); + $thisfile_ac3_raw_bsi['fscod'] = $this->readHeaderBSI(2); + if ($thisfile_ac3_raw_bsi['fscod'] == 3) { + $thisfile_ac3_raw_bsi['fscod2'] = $this->readHeaderBSI(2); + $thisfile_ac3_raw_bsi['numblkscod'] = 3; // six blocks per syncframe + } else { + $thisfile_ac3_raw_bsi['numblkscod'] = $this->readHeaderBSI(2); + } + $thisfile_ac3['bsi']['blocks_per_sync_frame'] = self::blocksPerSyncFrame($thisfile_ac3_raw_bsi['numblkscod']); + $thisfile_ac3_raw_bsi['acmod'] = $this->readHeaderBSI(3); + $thisfile_ac3_raw_bsi['flags']['lfeon'] = (bool) $this->readHeaderBSI(1); + $thisfile_ac3_raw_bsi['bsid'] = $this->readHeaderBSI(5); // we already know this from pre-parsing the version identifier, but re-read it to let the bitstream flow as intended + $thisfile_ac3_raw_bsi['dialnorm'] = $this->readHeaderBSI(5); + $thisfile_ac3_raw_bsi['flags']['compr'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['compr']) { + $thisfile_ac3_raw_bsi['compr'] = $this->readHeaderBSI(8); + } + if ($thisfile_ac3_raw_bsi['acmod'] == 0) { // if 1+1 mode (dual mono, so some items need a second value) + $thisfile_ac3_raw_bsi['dialnorm2'] = $this->readHeaderBSI(5); + $thisfile_ac3_raw_bsi['flags']['compr2'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['compr2']) { + $thisfile_ac3_raw_bsi['compr2'] = $this->readHeaderBSI(8); + } + } + if ($thisfile_ac3_raw_bsi['strmtyp'] == 1) { // if dependent stream + $thisfile_ac3_raw_bsi['flags']['chanmap'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['chanmap']) { + $thisfile_ac3_raw_bsi['chanmap'] = $this->readHeaderBSI(8); + } + } + $thisfile_ac3_raw_bsi['flags']['mixmdat'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['mixmdat']) { // Mixing metadata + if ($thisfile_ac3_raw_bsi['acmod'] > 2) { // if more than 2 channels + $thisfile_ac3_raw_bsi['dmixmod'] = $this->readHeaderBSI(2); + } + if (($thisfile_ac3_raw_bsi['acmod'] & 0x01) && ($thisfile_ac3_raw_bsi['acmod'] > 2)) { // if three front channels exist + $thisfile_ac3_raw_bsi['ltrtcmixlev'] = $this->readHeaderBSI(3); + $thisfile_ac3_raw_bsi['lorocmixlev'] = $this->readHeaderBSI(3); + } + if ($thisfile_ac3_raw_bsi['acmod'] & 0x04) { // if a surround channel exists + $thisfile_ac3_raw_bsi['ltrtsurmixlev'] = $this->readHeaderBSI(3); + $thisfile_ac3_raw_bsi['lorosurmixlev'] = $this->readHeaderBSI(3); + } + if ($thisfile_ac3_raw_bsi['flags']['lfeon']) { // if the LFE channel exists + $thisfile_ac3_raw_bsi['flags']['lfemixlevcod'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['lfemixlevcod']) { + $thisfile_ac3_raw_bsi['lfemixlevcod'] = $this->readHeaderBSI(5); + } + } + if ($thisfile_ac3_raw_bsi['strmtyp'] == 0) { // if independent stream + $thisfile_ac3_raw_bsi['flags']['pgmscl'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['pgmscl']) { + $thisfile_ac3_raw_bsi['pgmscl'] = $this->readHeaderBSI(6); + } + if ($thisfile_ac3_raw_bsi['acmod'] == 0) { // if 1+1 mode (dual mono, so some items need a second value) + $thisfile_ac3_raw_bsi['flags']['pgmscl2'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['pgmscl2']) { + $thisfile_ac3_raw_bsi['pgmscl2'] = $this->readHeaderBSI(6); + } + } + $thisfile_ac3_raw_bsi['flags']['extpgmscl'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['extpgmscl']) { + $thisfile_ac3_raw_bsi['extpgmscl'] = $this->readHeaderBSI(6); + } + $thisfile_ac3_raw_bsi['mixdef'] = $this->readHeaderBSI(2); + if ($thisfile_ac3_raw_bsi['mixdef'] == 1) { // mixing option 2 + $thisfile_ac3_raw_bsi['premixcmpsel'] = (bool) $this->readHeaderBSI(1); + $thisfile_ac3_raw_bsi['drcsrc'] = (bool) $this->readHeaderBSI(1); + $thisfile_ac3_raw_bsi['premixcmpscl'] = $this->readHeaderBSI(3); + } elseif ($thisfile_ac3_raw_bsi['mixdef'] == 2) { // mixing option 3 + $thisfile_ac3_raw_bsi['mixdata'] = $this->readHeaderBSI(12); + } elseif ($thisfile_ac3_raw_bsi['mixdef'] == 3) { // mixing option 4 + $mixdefbitsread = 0; + $thisfile_ac3_raw_bsi['mixdeflen'] = $this->readHeaderBSI(5); + $mixdefbitsread += 5; + $thisfile_ac3_raw_bsi['flags']['mixdata2'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['mixdata2']) { + $thisfile_ac3_raw_bsi['premixcmpsel'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + $thisfile_ac3_raw_bsi['drcsrc'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + $thisfile_ac3_raw_bsi['premixcmpscl'] = $this->readHeaderBSI(3); + $mixdefbitsread += 3; + $thisfile_ac3_raw_bsi['flags']['extpgmlscl'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmlscl']) { + $thisfile_ac3_raw_bsi['extpgmlscl'] = $this->readHeaderBSI(4); + $mixdefbitsread += 4; + } + $thisfile_ac3_raw_bsi['flags']['extpgmcscl'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmcscl']) { + $thisfile_ac3_raw_bsi['extpgmcscl'] = $this->readHeaderBSI(4); + $mixdefbitsread += 4; + } + $thisfile_ac3_raw_bsi['flags']['extpgmrscl'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmrscl']) { + $thisfile_ac3_raw_bsi['extpgmrscl'] = $this->readHeaderBSI(4); + } + $thisfile_ac3_raw_bsi['flags']['extpgmlsscl'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmlsscl']) { + $thisfile_ac3_raw_bsi['extpgmlsscl'] = $this->readHeaderBSI(4); + $mixdefbitsread += 4; + } + $thisfile_ac3_raw_bsi['flags']['extpgmrsscl'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmrsscl']) { + $thisfile_ac3_raw_bsi['extpgmrsscl'] = $this->readHeaderBSI(4); + $mixdefbitsread += 4; + } + $thisfile_ac3_raw_bsi['flags']['extpgmlfescl'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmlfescl']) { + $thisfile_ac3_raw_bsi['extpgmlfescl'] = $this->readHeaderBSI(4); + $mixdefbitsread += 4; + } + $thisfile_ac3_raw_bsi['flags']['dmixscl'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['dmixscl']) { + $thisfile_ac3_raw_bsi['dmixscl'] = $this->readHeaderBSI(4); + $mixdefbitsread += 4; + } + $thisfile_ac3_raw_bsi['flags']['addch'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['addch']) { + $thisfile_ac3_raw_bsi['flags']['extpgmaux1scl'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmaux1scl']) { + $thisfile_ac3_raw_bsi['extpgmaux1scl'] = $this->readHeaderBSI(4); + $mixdefbitsread += 4; + } + $thisfile_ac3_raw_bsi['flags']['extpgmaux2scl'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmaux2scl']) { + $thisfile_ac3_raw_bsi['extpgmaux2scl'] = $this->readHeaderBSI(4); + $mixdefbitsread += 4; + } + } + } + $thisfile_ac3_raw_bsi['flags']['mixdata3'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['mixdata3']) { + $thisfile_ac3_raw_bsi['spchdat'] = $this->readHeaderBSI(5); + $mixdefbitsread += 5; + $thisfile_ac3_raw_bsi['flags']['addspchdat'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['addspchdat']) { + $thisfile_ac3_raw_bsi['spchdat1'] = $this->readHeaderBSI(5); + $mixdefbitsread += 5; + $thisfile_ac3_raw_bsi['spchan1att'] = $this->readHeaderBSI(2); + $mixdefbitsread += 2; + $thisfile_ac3_raw_bsi['flags']['addspchdat1'] = (bool) $this->readHeaderBSI(1); + $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['addspchdat1']) { + $thisfile_ac3_raw_bsi['spchdat2'] = $this->readHeaderBSI(5); + $mixdefbitsread += 5; + $thisfile_ac3_raw_bsi['spchan2att'] = $this->readHeaderBSI(3); + $mixdefbitsread += 3; + } + } + } + $mixdata_bits = (8 * ($thisfile_ac3_raw_bsi['mixdeflen'] + 2)) - $mixdefbitsread; + $mixdata_fill = (($mixdata_bits % 8) ? 8 - ($mixdata_bits % 8) : 0); + $thisfile_ac3_raw_bsi['mixdata'] = $this->readHeaderBSI($mixdata_bits); + $thisfile_ac3_raw_bsi['mixdatafill'] = $this->readHeaderBSI($mixdata_fill); + unset($mixdefbitsread, $mixdata_bits, $mixdata_fill); + } + if ($thisfile_ac3_raw_bsi['acmod'] < 2) { // if mono or dual mono source + $thisfile_ac3_raw_bsi['flags']['paninfo'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['paninfo']) { + $thisfile_ac3_raw_bsi['panmean'] = $this->readHeaderBSI(8); + $thisfile_ac3_raw_bsi['paninfo'] = $this->readHeaderBSI(6); + } + if ($thisfile_ac3_raw_bsi['acmod'] == 0) { // if 1+1 mode (dual mono, so some items need a second value) + $thisfile_ac3_raw_bsi['flags']['paninfo2'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['paninfo2']) { + $thisfile_ac3_raw_bsi['panmean2'] = $this->readHeaderBSI(8); + $thisfile_ac3_raw_bsi['paninfo2'] = $this->readHeaderBSI(6); + } + } + } + $thisfile_ac3_raw_bsi['flags']['frmmixcfginfo'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['frmmixcfginfo']) { // mixing configuration information + if ($thisfile_ac3_raw_bsi['numblkscod'] == 0) { + $thisfile_ac3_raw_bsi['blkmixcfginfo'][0] = $this->readHeaderBSI(5); + } else { + for ($blk = 0; $blk < $thisfile_ac3_raw_bsi['numblkscod']; $blk++) { + $thisfile_ac3_raw_bsi['flags']['blkmixcfginfo'.$blk] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['blkmixcfginfo'.$blk]) { // mixing configuration information + $thisfile_ac3_raw_bsi['blkmixcfginfo'][$blk] = $this->readHeaderBSI(5); + } + } + } + } + } + } + $thisfile_ac3_raw_bsi['flags']['infomdat'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['infomdat']) { // Informational metadata + $thisfile_ac3_raw_bsi['bsmod'] = $this->readHeaderBSI(3); + $thisfile_ac3_raw_bsi['flags']['copyrightb'] = (bool) $this->readHeaderBSI(1); + $thisfile_ac3_raw_bsi['flags']['origbs'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['acmod'] == 2) { // if in 2/0 mode + $thisfile_ac3_raw_bsi['dsurmod'] = $this->readHeaderBSI(2); + $thisfile_ac3_raw_bsi['dheadphonmod'] = $this->readHeaderBSI(2); + } + if ($thisfile_ac3_raw_bsi['acmod'] >= 6) { // if both surround channels exist + $thisfile_ac3_raw_bsi['dsurexmod'] = $this->readHeaderBSI(2); + } + $thisfile_ac3_raw_bsi['flags']['audprodi'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['audprodi']) { + $thisfile_ac3_raw_bsi['mixlevel'] = $this->readHeaderBSI(5); + $thisfile_ac3_raw_bsi['roomtyp'] = $this->readHeaderBSI(2); + $thisfile_ac3_raw_bsi['flags']['adconvtyp'] = (bool) $this->readHeaderBSI(1); + } + if ($thisfile_ac3_raw_bsi['acmod'] == 0) { // if 1+1 mode (dual mono, so some items need a second value) + $thisfile_ac3_raw_bsi['flags']['audprodi2'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['audprodi2']) { + $thisfile_ac3_raw_bsi['mixlevel2'] = $this->readHeaderBSI(5); + $thisfile_ac3_raw_bsi['roomtyp2'] = $this->readHeaderBSI(2); + $thisfile_ac3_raw_bsi['flags']['adconvtyp2'] = (bool) $this->readHeaderBSI(1); + } + } + if ($thisfile_ac3_raw_bsi['fscod'] < 3) { // if not half sample rate + $thisfile_ac3_raw_bsi['flags']['sourcefscod'] = (bool) $this->readHeaderBSI(1); + } + } + if (($thisfile_ac3_raw_bsi['strmtyp'] == 0) && ($thisfile_ac3_raw_bsi['numblkscod'] != 3)) { // if both surround channels exist + $thisfile_ac3_raw_bsi['flags']['convsync'] = (bool) $this->readHeaderBSI(1); + } + if ($thisfile_ac3_raw_bsi['strmtyp'] == 2) { // if bit stream converted from AC-3 + if ($thisfile_ac3_raw_bsi['numblkscod'] != 3) { // 6 blocks per syncframe + $thisfile_ac3_raw_bsi['flags']['blkid'] = 1; + } else { + $thisfile_ac3_raw_bsi['flags']['blkid'] = (bool) $this->readHeaderBSI(1); + } + if ($thisfile_ac3_raw_bsi['flags']['blkid']) { + $thisfile_ac3_raw_bsi['frmsizecod'] = $this->readHeaderBSI(6); + } + } + $thisfile_ac3_raw_bsi['flags']['addbsi'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['addbsi']) { + $thisfile_ac3_raw_bsi['addbsil'] = $this->readHeaderBSI(6); + $thisfile_ac3_raw_bsi['addbsi'] = $this->readHeaderBSI(($thisfile_ac3_raw_bsi['addbsil'] + 1) * 8); + } + } else { + $this->error('Bit stream identification is version '.$thisfile_ac3_raw_bsi['bsid'].', but getID3() only understands up to version 16. Please submit a support ticket with a sample file.'); + unset($info['ac3']); + return false; + } - } elseif ($thisfile_ac3_raw_bsi['bsid'] <= 16) { // E-AC3 - - -$this->error('E-AC3 parsing is incomplete and experimental in this version of getID3 ('.$this->getid3->version().'). Notably the bitrate calculations are wrong -- value might (or not) be correct, but it is not calculated correctly. Email info@getid3.org if you know how to calculate EAC3 bitrate correctly.'); - $info['audio']['dataformat'] = 'eac3'; - - $thisfile_ac3_raw_bsi['strmtyp'] = $this->readHeaderBSI(2); - $thisfile_ac3_raw_bsi['substreamid'] = $this->readHeaderBSI(3); - $thisfile_ac3_raw_bsi['frmsiz'] = $this->readHeaderBSI(11); - $thisfile_ac3_raw_bsi['fscod'] = $this->readHeaderBSI(2); - if ($thisfile_ac3_raw_bsi['fscod'] == 3) { - $thisfile_ac3_raw_bsi['fscod2'] = $this->readHeaderBSI(2); - $thisfile_ac3_raw_bsi['numblkscod'] = 3; // six blocks per syncframe - } else { - $thisfile_ac3_raw_bsi['numblkscod'] = $this->readHeaderBSI(2); - } - $thisfile_ac3['bsi']['blocks_per_sync_frame'] = self::blocksPerSyncFrame($thisfile_ac3_raw_bsi['numblkscod']); - $thisfile_ac3_raw_bsi['acmod'] = $this->readHeaderBSI(3); - $thisfile_ac3_raw_bsi['flags']['lfeon'] = (bool) $this->readHeaderBSI(1); - $thisfile_ac3_raw_bsi['bsid'] = $this->readHeaderBSI(5); // we already know this from pre-parsing the version identifier, but re-read it to let the bitstream flow as intended - $thisfile_ac3_raw_bsi['dialnorm'] = $this->readHeaderBSI(5); - $thisfile_ac3_raw_bsi['flags']['compr'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['compr']) { - $thisfile_ac3_raw_bsi['compr'] = $this->readHeaderBSI(8); - } - if ($thisfile_ac3_raw_bsi['acmod'] == 0) { // if 1+1 mode (dual mono, so some items need a second value) - $thisfile_ac3_raw_bsi['dialnorm2'] = $this->readHeaderBSI(5); - $thisfile_ac3_raw_bsi['flags']['compr2'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['compr2']) { - $thisfile_ac3_raw_bsi['compr2'] = $this->readHeaderBSI(8); - } - } - if ($thisfile_ac3_raw_bsi['strmtyp'] == 1) { // if dependent stream - $thisfile_ac3_raw_bsi['flags']['chanmap'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['chanmap']) { - $thisfile_ac3_raw_bsi['chanmap'] = $this->readHeaderBSI(8); - } - } - $thisfile_ac3_raw_bsi['flags']['mixmdat'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['mixmdat']) { // Mixing metadata - if ($thisfile_ac3_raw_bsi['acmod'] > 2) { // if more than 2 channels - $thisfile_ac3_raw_bsi['dmixmod'] = $this->readHeaderBSI(2); - } - if (($thisfile_ac3_raw_bsi['acmod'] & 0x01) && ($thisfile_ac3_raw_bsi['acmod'] > 2)) { // if three front channels exist - $thisfile_ac3_raw_bsi['ltrtcmixlev'] = $this->readHeaderBSI(3); - $thisfile_ac3_raw_bsi['lorocmixlev'] = $this->readHeaderBSI(3); - } - if ($thisfile_ac3_raw_bsi['acmod'] & 0x04) { // if a surround channel exists - $thisfile_ac3_raw_bsi['ltrtsurmixlev'] = $this->readHeaderBSI(3); - $thisfile_ac3_raw_bsi['lorosurmixlev'] = $this->readHeaderBSI(3); - } - if ($thisfile_ac3_raw_bsi['flags']['lfeon']) { // if the LFE channel exists - $thisfile_ac3_raw_bsi['flags']['lfemixlevcod'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['lfemixlevcod']) { - $thisfile_ac3_raw_bsi['lfemixlevcod'] = $this->readHeaderBSI(5); - } - } - if ($thisfile_ac3_raw_bsi['strmtyp'] == 0) { // if independent stream - $thisfile_ac3_raw_bsi['flags']['pgmscl'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['pgmscl']) { - $thisfile_ac3_raw_bsi['pgmscl'] = $this->readHeaderBSI(6); - } - if ($thisfile_ac3_raw_bsi['acmod'] == 0) { // if 1+1 mode (dual mono, so some items need a second value) - $thisfile_ac3_raw_bsi['flags']['pgmscl2'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['pgmscl2']) { - $thisfile_ac3_raw_bsi['pgmscl2'] = $this->readHeaderBSI(6); - } - } - $thisfile_ac3_raw_bsi['flags']['extpgmscl'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['extpgmscl']) { - $thisfile_ac3_raw_bsi['extpgmscl'] = $this->readHeaderBSI(6); - } - $thisfile_ac3_raw_bsi['mixdef'] = $this->readHeaderBSI(2); - if ($thisfile_ac3_raw_bsi['mixdef'] == 1) { // mixing option 2 - $thisfile_ac3_raw_bsi['premixcmpsel'] = (bool) $this->readHeaderBSI(1); - $thisfile_ac3_raw_bsi['drcsrc'] = (bool) $this->readHeaderBSI(1); - $thisfile_ac3_raw_bsi['premixcmpscl'] = $this->readHeaderBSI(3); - } elseif ($thisfile_ac3_raw_bsi['mixdef'] == 2) { // mixing option 3 - $thisfile_ac3_raw_bsi['mixdata'] = $this->readHeaderBSI(12); - } elseif ($thisfile_ac3_raw_bsi['mixdef'] == 3) { // mixing option 4 - $mixdefbitsread = 0; - $thisfile_ac3_raw_bsi['mixdeflen'] = $this->readHeaderBSI(5); $mixdefbitsread += 5; - $thisfile_ac3_raw_bsi['flags']['mixdata2'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - if ($thisfile_ac3_raw_bsi['flags']['mixdata2']) { - $thisfile_ac3_raw_bsi['premixcmpsel'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - $thisfile_ac3_raw_bsi['drcsrc'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - $thisfile_ac3_raw_bsi['premixcmpscl'] = $this->readHeaderBSI(3); $mixdefbitsread += 3; - $thisfile_ac3_raw_bsi['flags']['extpgmlscl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - if ($thisfile_ac3_raw_bsi['flags']['extpgmlscl']) { - $thisfile_ac3_raw_bsi['extpgmlscl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; - } - $thisfile_ac3_raw_bsi['flags']['extpgmcscl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - if ($thisfile_ac3_raw_bsi['flags']['extpgmcscl']) { - $thisfile_ac3_raw_bsi['extpgmcscl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; - } - $thisfile_ac3_raw_bsi['flags']['extpgmrscl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - if ($thisfile_ac3_raw_bsi['flags']['extpgmrscl']) { - $thisfile_ac3_raw_bsi['extpgmrscl'] = $this->readHeaderBSI(4); - } - $thisfile_ac3_raw_bsi['flags']['extpgmlsscl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - if ($thisfile_ac3_raw_bsi['flags']['extpgmlsscl']) { - $thisfile_ac3_raw_bsi['extpgmlsscl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; - } - $thisfile_ac3_raw_bsi['flags']['extpgmrsscl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - if ($thisfile_ac3_raw_bsi['flags']['extpgmrsscl']) { - $thisfile_ac3_raw_bsi['extpgmrsscl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; - } - $thisfile_ac3_raw_bsi['flags']['extpgmlfescl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - if ($thisfile_ac3_raw_bsi['flags']['extpgmlfescl']) { - $thisfile_ac3_raw_bsi['extpgmlfescl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; - } - $thisfile_ac3_raw_bsi['flags']['dmixscl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - if ($thisfile_ac3_raw_bsi['flags']['dmixscl']) { - $thisfile_ac3_raw_bsi['dmixscl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; - } - $thisfile_ac3_raw_bsi['flags']['addch'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - if ($thisfile_ac3_raw_bsi['flags']['addch']) { - $thisfile_ac3_raw_bsi['flags']['extpgmaux1scl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - if ($thisfile_ac3_raw_bsi['flags']['extpgmaux1scl']) { - $thisfile_ac3_raw_bsi['extpgmaux1scl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; - } - $thisfile_ac3_raw_bsi['flags']['extpgmaux2scl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - if ($thisfile_ac3_raw_bsi['flags']['extpgmaux2scl']) { - $thisfile_ac3_raw_bsi['extpgmaux2scl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; - } - } - } - $thisfile_ac3_raw_bsi['flags']['mixdata3'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - if ($thisfile_ac3_raw_bsi['flags']['mixdata3']) { - $thisfile_ac3_raw_bsi['spchdat'] = $this->readHeaderBSI(5); $mixdefbitsread += 5; - $thisfile_ac3_raw_bsi['flags']['addspchdat'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - if ($thisfile_ac3_raw_bsi['flags']['addspchdat']) { - $thisfile_ac3_raw_bsi['spchdat1'] = $this->readHeaderBSI(5); $mixdefbitsread += 5; - $thisfile_ac3_raw_bsi['spchan1att'] = $this->readHeaderBSI(2); $mixdefbitsread += 2; - $thisfile_ac3_raw_bsi['flags']['addspchdat1'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; - if ($thisfile_ac3_raw_bsi['flags']['addspchdat1']) { - $thisfile_ac3_raw_bsi['spchdat2'] = $this->readHeaderBSI(5); $mixdefbitsread += 5; - $thisfile_ac3_raw_bsi['spchan2att'] = $this->readHeaderBSI(3); $mixdefbitsread += 3; - } - } - } - $mixdata_bits = (8 * ($thisfile_ac3_raw_bsi['mixdeflen'] + 2)) - $mixdefbitsread; - $mixdata_fill = (($mixdata_bits % 8) ? 8 - ($mixdata_bits % 8) : 0); - $thisfile_ac3_raw_bsi['mixdata'] = $this->readHeaderBSI($mixdata_bits); - $thisfile_ac3_raw_bsi['mixdatafill'] = $this->readHeaderBSI($mixdata_fill); - unset($mixdefbitsread, $mixdata_bits, $mixdata_fill); - } - if ($thisfile_ac3_raw_bsi['acmod'] < 2) { // if mono or dual mono source - $thisfile_ac3_raw_bsi['flags']['paninfo'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['paninfo']) { - $thisfile_ac3_raw_bsi['panmean'] = $this->readHeaderBSI(8); - $thisfile_ac3_raw_bsi['paninfo'] = $this->readHeaderBSI(6); - } - if ($thisfile_ac3_raw_bsi['acmod'] == 0) { // if 1+1 mode (dual mono, so some items need a second value) - $thisfile_ac3_raw_bsi['flags']['paninfo2'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['paninfo2']) { - $thisfile_ac3_raw_bsi['panmean2'] = $this->readHeaderBSI(8); - $thisfile_ac3_raw_bsi['paninfo2'] = $this->readHeaderBSI(6); - } - } - } - $thisfile_ac3_raw_bsi['flags']['frmmixcfginfo'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['frmmixcfginfo']) { // mixing configuration information - if ($thisfile_ac3_raw_bsi['numblkscod'] == 0) { - $thisfile_ac3_raw_bsi['blkmixcfginfo'][0] = $this->readHeaderBSI(5); - } else { - for ($blk = 0; $blk < $thisfile_ac3_raw_bsi['numblkscod']; $blk++) { - $thisfile_ac3_raw_bsi['flags']['blkmixcfginfo'.$blk] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['blkmixcfginfo'.$blk]) { // mixing configuration information - $thisfile_ac3_raw_bsi['blkmixcfginfo'][$blk] = $this->readHeaderBSI(5); - } - } - } - } - } - } - $thisfile_ac3_raw_bsi['flags']['infomdat'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['infomdat']) { // Informational metadata - $thisfile_ac3_raw_bsi['bsmod'] = $this->readHeaderBSI(3); - $thisfile_ac3_raw_bsi['flags']['copyrightb'] = (bool) $this->readHeaderBSI(1); - $thisfile_ac3_raw_bsi['flags']['origbs'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['acmod'] == 2) { // if in 2/0 mode - $thisfile_ac3_raw_bsi['dsurmod'] = $this->readHeaderBSI(2); - $thisfile_ac3_raw_bsi['dheadphonmod'] = $this->readHeaderBSI(2); - } - if ($thisfile_ac3_raw_bsi['acmod'] >= 6) { // if both surround channels exist - $thisfile_ac3_raw_bsi['dsurexmod'] = $this->readHeaderBSI(2); - } - $thisfile_ac3_raw_bsi['flags']['audprodi'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['audprodi']) { - $thisfile_ac3_raw_bsi['mixlevel'] = $this->readHeaderBSI(5); - $thisfile_ac3_raw_bsi['roomtyp'] = $this->readHeaderBSI(2); - $thisfile_ac3_raw_bsi['flags']['adconvtyp'] = (bool) $this->readHeaderBSI(1); - } - if ($thisfile_ac3_raw_bsi['acmod'] == 0) { // if 1+1 mode (dual mono, so some items need a second value) - $thisfile_ac3_raw_bsi['flags']['audprodi2'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['audprodi2']) { - $thisfile_ac3_raw_bsi['mixlevel2'] = $this->readHeaderBSI(5); - $thisfile_ac3_raw_bsi['roomtyp2'] = $this->readHeaderBSI(2); - $thisfile_ac3_raw_bsi['flags']['adconvtyp2'] = (bool) $this->readHeaderBSI(1); - } - } - if ($thisfile_ac3_raw_bsi['fscod'] < 3) { // if not half sample rate - $thisfile_ac3_raw_bsi['flags']['sourcefscod'] = (bool) $this->readHeaderBSI(1); - } - } - if (($thisfile_ac3_raw_bsi['strmtyp'] == 0) && ($thisfile_ac3_raw_bsi['numblkscod'] != 3)) { // if both surround channels exist - $thisfile_ac3_raw_bsi['flags']['convsync'] = (bool) $this->readHeaderBSI(1); - } - if ($thisfile_ac3_raw_bsi['strmtyp'] == 2) { // if bit stream converted from AC-3 - if ($thisfile_ac3_raw_bsi['numblkscod'] != 3) { // 6 blocks per syncframe - $thisfile_ac3_raw_bsi['flags']['blkid'] = 1; - } else { - $thisfile_ac3_raw_bsi['flags']['blkid'] = (bool) $this->readHeaderBSI(1); - } - if ($thisfile_ac3_raw_bsi['flags']['blkid']) { - $thisfile_ac3_raw_bsi['frmsizecod'] = $this->readHeaderBSI(6); - } - } - $thisfile_ac3_raw_bsi['flags']['addbsi'] = (bool) $this->readHeaderBSI(1); - if ($thisfile_ac3_raw_bsi['flags']['addbsi']) { - $thisfile_ac3_raw_bsi['addbsil'] = $this->readHeaderBSI(6); - $thisfile_ac3_raw_bsi['addbsi'] = $this->readHeaderBSI(($thisfile_ac3_raw_bsi['addbsil'] + 1) * 8); - } - - } else { - - $this->error('Bit stream identification is version '.$thisfile_ac3_raw_bsi['bsid'].', but getID3() only understands up to version 16. Please submit a support ticket with a sample file.'); - unset($info['ac3']); - return false; - - } - - if (isset($thisfile_ac3_raw_bsi['fscod2'])) { - $thisfile_ac3['sample_rate'] = self::sampleRateCodeLookup2($thisfile_ac3_raw_bsi['fscod2']); - } else { - $thisfile_ac3['sample_rate'] = self::sampleRateCodeLookup($thisfile_ac3_raw_bsi['fscod']); - } - if ($thisfile_ac3_raw_bsi['fscod'] <= 3) { - $info['audio']['sample_rate'] = $thisfile_ac3['sample_rate']; - } else { - $this->warning('Unexpected ac3.bsi.fscod value: '.$thisfile_ac3_raw_bsi['fscod']); - } - if (isset($thisfile_ac3_raw_bsi['frmsizecod'])) { - $thisfile_ac3['frame_length'] = self::frameSizeLookup($thisfile_ac3_raw_bsi['frmsizecod'], $thisfile_ac3_raw_bsi['fscod']); - $thisfile_ac3['bitrate'] = self::bitrateLookup($thisfile_ac3_raw_bsi['frmsizecod']); - } elseif (!empty($thisfile_ac3_raw_bsi['frmsiz'])) { -// this isn't right, but it's (usually) close, roughly 5% less than it should be. + if (isset($thisfile_ac3_raw_bsi['fscod2'])) { + $thisfile_ac3['sample_rate'] = self::sampleRateCodeLookup2($thisfile_ac3_raw_bsi['fscod2']); + } else { + $thisfile_ac3['sample_rate'] = self::sampleRateCodeLookup($thisfile_ac3_raw_bsi['fscod']); + } + if ($thisfile_ac3_raw_bsi['fscod'] <= 3) { + $info['audio']['sample_rate'] = $thisfile_ac3['sample_rate']; + } else { + $this->warning('Unexpected ac3.bsi.fscod value: '.$thisfile_ac3_raw_bsi['fscod']); + } + if (isset($thisfile_ac3_raw_bsi['frmsizecod'])) { + $thisfile_ac3['frame_length'] = self::frameSizeLookup($thisfile_ac3_raw_bsi['frmsizecod'], $thisfile_ac3_raw_bsi['fscod']); + $thisfile_ac3['bitrate'] = self::bitrateLookup($thisfile_ac3_raw_bsi['frmsizecod']); + } elseif (! empty($thisfile_ac3_raw_bsi['frmsiz'])) { + // this isn't right, but it's (usually) close, roughly 5% less than it should be. // but WHERE is the actual bitrate value stored in EAC3?? email info@getid3.org if you know! - $thisfile_ac3['bitrate'] = ($thisfile_ac3_raw_bsi['frmsiz'] + 1) * 16 * 30; // The frmsiz field shall contain a value one less than the overall size of the coded syncframe in 16-bit words. That is, this field may assume a value ranging from 0 to 2047, and these values correspond to syncframe sizes ranging from 1 to 2048. + $thisfile_ac3['bitrate'] = ($thisfile_ac3_raw_bsi['frmsiz'] + 1) * 16 * 30; // The frmsiz field shall contain a value one less than the overall size of the coded syncframe in 16-bit words. That is, this field may assume a value ranging from 0 to 2047, and these values correspond to syncframe sizes ranging from 1 to 2048. // kludge-fix to make it approximately the expected value, still not "right": $thisfile_ac3['bitrate'] = round(($thisfile_ac3['bitrate'] * 1.05) / 16000) * 16000; - } - $info['audio']['bitrate'] = $thisfile_ac3['bitrate']; + } + $info['audio']['bitrate'] = $thisfile_ac3['bitrate']; - $thisfile_ac3['service_type'] = self::serviceTypeLookup($thisfile_ac3_raw_bsi['bsmod'], $thisfile_ac3_raw_bsi['acmod']); - $ac3_coding_mode = self::audioCodingModeLookup($thisfile_ac3_raw_bsi['acmod']); - foreach($ac3_coding_mode as $key => $value) { - $thisfile_ac3[$key] = $value; - } - switch ($thisfile_ac3_raw_bsi['acmod']) { - case 0: - case 1: - $info['audio']['channelmode'] = 'mono'; - break; - case 3: - case 4: - $info['audio']['channelmode'] = 'stereo'; - break; - default: - $info['audio']['channelmode'] = 'surround'; - break; - } - $info['audio']['channels'] = $thisfile_ac3['num_channels']; + $thisfile_ac3['service_type'] = self::serviceTypeLookup($thisfile_ac3_raw_bsi['bsmod'], $thisfile_ac3_raw_bsi['acmod']); + $ac3_coding_mode = self::audioCodingModeLookup($thisfile_ac3_raw_bsi['acmod']); + foreach ($ac3_coding_mode as $key => $value) { + $thisfile_ac3[$key] = $value; + } + switch ($thisfile_ac3_raw_bsi['acmod']) { + case 0: + case 1: + $info['audio']['channelmode'] = 'mono'; + break; + case 3: + case 4: + $info['audio']['channelmode'] = 'stereo'; + break; + default: + $info['audio']['channelmode'] = 'surround'; + break; + } + $info['audio']['channels'] = $thisfile_ac3['num_channels']; - $thisfile_ac3['lfe_enabled'] = $thisfile_ac3_raw_bsi['flags']['lfeon']; - if ($thisfile_ac3_raw_bsi['flags']['lfeon']) { - $info['audio']['channels'] .= '.1'; - } + $thisfile_ac3['lfe_enabled'] = $thisfile_ac3_raw_bsi['flags']['lfeon']; + if ($thisfile_ac3_raw_bsi['flags']['lfeon']) { + $info['audio']['channels'] .= '.1'; + } - $thisfile_ac3['channels_enabled'] = self::channelsEnabledLookup($thisfile_ac3_raw_bsi['acmod'], $thisfile_ac3_raw_bsi['flags']['lfeon']); - $thisfile_ac3['dialogue_normalization'] = '-'.$thisfile_ac3_raw_bsi['dialnorm'].'dB'; + $thisfile_ac3['channels_enabled'] = self::channelsEnabledLookup($thisfile_ac3_raw_bsi['acmod'], $thisfile_ac3_raw_bsi['flags']['lfeon']); + $thisfile_ac3['dialogue_normalization'] = '-'.$thisfile_ac3_raw_bsi['dialnorm'].'dB'; - return true; - } + return true; + } - private function readHeaderBSI($length) { - $data = substr($this->AC3header['bsi'], $this->BSIoffset, $length); - $this->BSIoffset += $length; + private function readHeaderBSI($length) + { + $data = substr($this->AC3header['bsi'], $this->BSIoffset, $length); + $this->BSIoffset += $length; - return bindec($data); - } + return bindec($data); + } - public static function sampleRateCodeLookup($fscod) { - static $sampleRateCodeLookup = array( - 0 => 48000, - 1 => 44100, - 2 => 32000, - 3 => 'reserved' // If the reserved code is indicated, the decoder should not attempt to decode audio and should mute. - ); - return (isset($sampleRateCodeLookup[$fscod]) ? $sampleRateCodeLookup[$fscod] : false); - } + public static function sampleRateCodeLookup($fscod) + { + static $sampleRateCodeLookup = [ + 0 => 48000, + 1 => 44100, + 2 => 32000, + 3 => 'reserved', // If the reserved code is indicated, the decoder should not attempt to decode audio and should mute. + ]; - public static function sampleRateCodeLookup2($fscod2) { - static $sampleRateCodeLookup2 = array( - 0 => 24000, - 1 => 22050, - 2 => 16000, - 3 => 'reserved' // If the reserved code is indicated, the decoder should not attempt to decode audio and should mute. - ); - return (isset($sampleRateCodeLookup2[$fscod2]) ? $sampleRateCodeLookup2[$fscod2] : false); - } + return isset($sampleRateCodeLookup[$fscod]) ? $sampleRateCodeLookup[$fscod] : false; + } - public static function serviceTypeLookup($bsmod, $acmod) { - static $serviceTypeLookup = array(); - if (empty($serviceTypeLookup)) { - for ($i = 0; $i <= 7; $i++) { - $serviceTypeLookup[0][$i] = 'main audio service: complete main (CM)'; - $serviceTypeLookup[1][$i] = 'main audio service: music and effects (ME)'; - $serviceTypeLookup[2][$i] = 'associated service: visually impaired (VI)'; - $serviceTypeLookup[3][$i] = 'associated service: hearing impaired (HI)'; - $serviceTypeLookup[4][$i] = 'associated service: dialogue (D)'; - $serviceTypeLookup[5][$i] = 'associated service: commentary (C)'; - $serviceTypeLookup[6][$i] = 'associated service: emergency (E)'; - } + public static function sampleRateCodeLookup2($fscod2) + { + static $sampleRateCodeLookup2 = [ + 0 => 24000, + 1 => 22050, + 2 => 16000, + 3 => 'reserved', // If the reserved code is indicated, the decoder should not attempt to decode audio and should mute. + ]; - $serviceTypeLookup[7][1] = 'associated service: voice over (VO)'; - for ($i = 2; $i <= 7; $i++) { - $serviceTypeLookup[7][$i] = 'main audio service: karaoke'; - } - } - return (isset($serviceTypeLookup[$bsmod][$acmod]) ? $serviceTypeLookup[$bsmod][$acmod] : false); - } + return isset($sampleRateCodeLookup2[$fscod2]) ? $sampleRateCodeLookup2[$fscod2] : false; + } - public static function audioCodingModeLookup($acmod) { - // array(channel configuration, # channels (not incl LFE), channel order) - static $audioCodingModeLookup = array ( - 0 => array('channel_config'=>'1+1', 'num_channels'=>2, 'channel_order'=>'Ch1,Ch2'), - 1 => array('channel_config'=>'1/0', 'num_channels'=>1, 'channel_order'=>'C'), - 2 => array('channel_config'=>'2/0', 'num_channels'=>2, 'channel_order'=>'L,R'), - 3 => array('channel_config'=>'3/0', 'num_channels'=>3, 'channel_order'=>'L,C,R'), - 4 => array('channel_config'=>'2/1', 'num_channels'=>3, 'channel_order'=>'L,R,S'), - 5 => array('channel_config'=>'3/1', 'num_channels'=>4, 'channel_order'=>'L,C,R,S'), - 6 => array('channel_config'=>'2/2', 'num_channels'=>4, 'channel_order'=>'L,R,SL,SR'), - 7 => array('channel_config'=>'3/2', 'num_channels'=>5, 'channel_order'=>'L,C,R,SL,SR'), - ); - return (isset($audioCodingModeLookup[$acmod]) ? $audioCodingModeLookup[$acmod] : false); - } + public static function serviceTypeLookup($bsmod, $acmod) + { + static $serviceTypeLookup = []; + if (empty($serviceTypeLookup)) { + for ($i = 0; $i <= 7; $i++) { + $serviceTypeLookup[0][$i] = 'main audio service: complete main (CM)'; + $serviceTypeLookup[1][$i] = 'main audio service: music and effects (ME)'; + $serviceTypeLookup[2][$i] = 'associated service: visually impaired (VI)'; + $serviceTypeLookup[3][$i] = 'associated service: hearing impaired (HI)'; + $serviceTypeLookup[4][$i] = 'associated service: dialogue (D)'; + $serviceTypeLookup[5][$i] = 'associated service: commentary (C)'; + $serviceTypeLookup[6][$i] = 'associated service: emergency (E)'; + } - public static function centerMixLevelLookup($cmixlev) { - static $centerMixLevelLookup; - if (empty($centerMixLevelLookup)) { - $centerMixLevelLookup = array( - 0 => pow(2, -3.0 / 6), // 0.707 (-3.0 dB) - 1 => pow(2, -4.5 / 6), // 0.595 (-4.5 dB) - 2 => pow(2, -6.0 / 6), // 0.500 (-6.0 dB) - 3 => 'reserved' - ); - } - return (isset($centerMixLevelLookup[$cmixlev]) ? $centerMixLevelLookup[$cmixlev] : false); - } + $serviceTypeLookup[7][1] = 'associated service: voice over (VO)'; + for ($i = 2; $i <= 7; $i++) { + $serviceTypeLookup[7][$i] = 'main audio service: karaoke'; + } + } - public static function surroundMixLevelLookup($surmixlev) { - static $surroundMixLevelLookup; - if (empty($surroundMixLevelLookup)) { - $surroundMixLevelLookup = array( - 0 => pow(2, -3.0 / 6), - 1 => pow(2, -6.0 / 6), - 2 => 0, - 3 => 'reserved' - ); - } - return (isset($surroundMixLevelLookup[$surmixlev]) ? $surroundMixLevelLookup[$surmixlev] : false); - } + return isset($serviceTypeLookup[$bsmod][$acmod]) ? $serviceTypeLookup[$bsmod][$acmod] : false; + } - public static function dolbySurroundModeLookup($dsurmod) { - static $dolbySurroundModeLookup = array( - 0 => 'not indicated', - 1 => 'Not Dolby Surround encoded', - 2 => 'Dolby Surround encoded', - 3 => 'reserved' - ); - return (isset($dolbySurroundModeLookup[$dsurmod]) ? $dolbySurroundModeLookup[$dsurmod] : false); - } + public static function audioCodingModeLookup($acmod) + { + // array(channel configuration, # channels (not incl LFE), channel order) + static $audioCodingModeLookup = [ + 0 => ['channel_config'=>'1+1', 'num_channels'=>2, 'channel_order'=>'Ch1,Ch2'], + 1 => ['channel_config'=>'1/0', 'num_channels'=>1, 'channel_order'=>'C'], + 2 => ['channel_config'=>'2/0', 'num_channels'=>2, 'channel_order'=>'L,R'], + 3 => ['channel_config'=>'3/0', 'num_channels'=>3, 'channel_order'=>'L,C,R'], + 4 => ['channel_config'=>'2/1', 'num_channels'=>3, 'channel_order'=>'L,R,S'], + 5 => ['channel_config'=>'3/1', 'num_channels'=>4, 'channel_order'=>'L,C,R,S'], + 6 => ['channel_config'=>'2/2', 'num_channels'=>4, 'channel_order'=>'L,R,SL,SR'], + 7 => ['channel_config'=>'3/2', 'num_channels'=>5, 'channel_order'=>'L,C,R,SL,SR'], + ]; - public static function channelsEnabledLookup($acmod, $lfeon) { - $lookup = array( - 'ch1'=>(bool) ($acmod == 0), - 'ch2'=>(bool) ($acmod == 0), - 'left'=>(bool) ($acmod > 1), - 'right'=>(bool) ($acmod > 1), - 'center'=>(bool) ($acmod & 0x01), - 'surround_mono'=>false, - 'surround_left'=>false, - 'surround_right'=>false, - 'lfe'=>$lfeon); - switch ($acmod) { - case 4: - case 5: - $lookup['surround_mono'] = true; - break; - case 6: - case 7: - $lookup['surround_left'] = true; - $lookup['surround_right'] = true; - break; - } - return $lookup; - } + return isset($audioCodingModeLookup[$acmod]) ? $audioCodingModeLookup[$acmod] : false; + } - public static function heavyCompression($compre) { - // The first four bits indicate gain changes in 6.02dB increments which can be - // implemented with an arithmetic shift operation. The following four bits - // indicate linear gain changes, and require a 5-bit multiply. - // We will represent the two 4-bit fields of compr as follows: - // X0 X1 X2 X3 . Y4 Y5 Y6 Y7 - // The meaning of the X values is most simply described by considering X to represent a 4-bit - // signed integer with values from -8 to +7. The gain indicated by X is then (X + 1) * 6.02 dB. The - // following table shows this in detail. + public static function centerMixLevelLookup($cmixlev) + { + static $centerMixLevelLookup; + if (empty($centerMixLevelLookup)) { + $centerMixLevelLookup = [ + 0 => pow(2, -3.0 / 6), // 0.707 (-3.0 dB) + 1 => pow(2, -4.5 / 6), // 0.595 (-4.5 dB) + 2 => pow(2, -6.0 / 6), // 0.500 (-6.0 dB) + 3 => 'reserved', + ]; + } - // Meaning of 4 msb of compr - // 7 +48.16 dB - // 6 +42.14 dB - // 5 +36.12 dB - // 4 +30.10 dB - // 3 +24.08 dB - // 2 +18.06 dB - // 1 +12.04 dB - // 0 +6.02 dB - // -1 0 dB - // -2 -6.02 dB - // -3 -12.04 dB - // -4 -18.06 dB - // -5 -24.08 dB - // -6 -30.10 dB - // -7 -36.12 dB - // -8 -42.14 dB + return isset($centerMixLevelLookup[$cmixlev]) ? $centerMixLevelLookup[$cmixlev] : false; + } - $fourbit = str_pad(decbin(($compre & 0xF0) >> 4), 4, '0', STR_PAD_LEFT); - if ($fourbit{0} == '1') { - $log_gain = -8 + bindec(substr($fourbit, 1)); - } else { - $log_gain = bindec(substr($fourbit, 1)); - } - $log_gain = ($log_gain + 1) * getid3_lib::RGADamplitude2dB(2); + public static function surroundMixLevelLookup($surmixlev) + { + static $surroundMixLevelLookup; + if (empty($surroundMixLevelLookup)) { + $surroundMixLevelLookup = [ + 0 => pow(2, -3.0 / 6), + 1 => pow(2, -6.0 / 6), + 2 => 0, + 3 => 'reserved', + ]; + } - // The value of Y is a linear representation of a gain change of up to -6 dB. Y is considered to - // be an unsigned fractional integer, with a leading value of 1, or: 0.1 Y4 Y5 Y6 Y7 (base 2). Y can - // represent values between 0.111112 (or 31/32) and 0.100002 (or 1/2). Thus, Y can represent gain - // changes from -0.28 dB to -6.02 dB. + return isset($surroundMixLevelLookup[$surmixlev]) ? $surroundMixLevelLookup[$surmixlev] : false; + } - $lin_gain = (16 + ($compre & 0x0F)) / 32; + public static function dolbySurroundModeLookup($dsurmod) + { + static $dolbySurroundModeLookup = [ + 0 => 'not indicated', + 1 => 'Not Dolby Surround encoded', + 2 => 'Dolby Surround encoded', + 3 => 'reserved', + ]; - // The combination of X and Y values allows compr to indicate gain changes from - // 48.16 - 0.28 = +47.89 dB, to - // -42.14 - 6.02 = -48.16 dB. + return isset($dolbySurroundModeLookup[$dsurmod]) ? $dolbySurroundModeLookup[$dsurmod] : false; + } - return $log_gain - $lin_gain; - } + public static function channelsEnabledLookup($acmod, $lfeon) + { + $lookup = [ + 'ch1'=>(bool) ($acmod == 0), + 'ch2'=>(bool) ($acmod == 0), + 'left'=>(bool) ($acmod > 1), + 'right'=>(bool) ($acmod > 1), + 'center'=>(bool) ($acmod & 0x01), + 'surround_mono'=>false, + 'surround_left'=>false, + 'surround_right'=>false, + 'lfe'=>$lfeon, ]; + switch ($acmod) { + case 4: + case 5: + $lookup['surround_mono'] = true; + break; + case 6: + case 7: + $lookup['surround_left'] = true; + $lookup['surround_right'] = true; + break; + } - public static function roomTypeLookup($roomtyp) { - static $roomTypeLookup = array( - 0 => 'not indicated', - 1 => 'large room, X curve monitor', - 2 => 'small room, flat monitor', - 3 => 'reserved' - ); - return (isset($roomTypeLookup[$roomtyp]) ? $roomTypeLookup[$roomtyp] : false); - } + return $lookup; + } - public static function frameSizeLookup($frmsizecod, $fscod) { - // LSB is whether padding is used or not - $padding = (bool) ($frmsizecod & 0x01); - $framesizeid = ($frmsizecod & 0x3E) >> 1; + public static function heavyCompression($compre) + { + // The first four bits indicate gain changes in 6.02dB increments which can be + // implemented with an arithmetic shift operation. The following four bits + // indicate linear gain changes, and require a 5-bit multiply. + // We will represent the two 4-bit fields of compr as follows: + // X0 X1 X2 X3 . Y4 Y5 Y6 Y7 + // The meaning of the X values is most simply described by considering X to represent a 4-bit + // signed integer with values from -8 to +7. The gain indicated by X is then (X + 1) * 6.02 dB. The + // following table shows this in detail. - static $frameSizeLookup = array(); - if (empty($frameSizeLookup)) { - $frameSizeLookup = array ( - 0 => array( 128, 138, 192), // 32 kbps - 1 => array( 160, 174, 240), // 40 kbps - 2 => array( 192, 208, 288), // 48 kbps - 3 => array( 224, 242, 336), // 56 kbps - 4 => array( 256, 278, 384), // 64 kbps - 5 => array( 320, 348, 480), // 80 kbps - 6 => array( 384, 416, 576), // 96 kbps - 7 => array( 448, 486, 672), // 112 kbps - 8 => array( 512, 556, 768), // 128 kbps - 9 => array( 640, 696, 960), // 160 kbps - 10 => array( 768, 834, 1152), // 192 kbps - 11 => array( 896, 974, 1344), // 224 kbps - 12 => array(1024, 1114, 1536), // 256 kbps - 13 => array(1280, 1392, 1920), // 320 kbps - 14 => array(1536, 1670, 2304), // 384 kbps - 15 => array(1792, 1950, 2688), // 448 kbps - 16 => array(2048, 2228, 3072), // 512 kbps - 17 => array(2304, 2506, 3456), // 576 kbps - 18 => array(2560, 2786, 3840) // 640 kbps - ); - } - if (($fscod == 1) && $padding) { - // frame lengths are padded by 1 word (16 bits) at 44100 - $frameSizeLookup[$frmsizecod] += 2; - } - return (isset($frameSizeLookup[$framesizeid][$fscod]) ? $frameSizeLookup[$framesizeid][$fscod] : false); - } + // Meaning of 4 msb of compr + // 7 +48.16 dB + // 6 +42.14 dB + // 5 +36.12 dB + // 4 +30.10 dB + // 3 +24.08 dB + // 2 +18.06 dB + // 1 +12.04 dB + // 0 +6.02 dB + // -1 0 dB + // -2 -6.02 dB + // -3 -12.04 dB + // -4 -18.06 dB + // -5 -24.08 dB + // -6 -30.10 dB + // -7 -36.12 dB + // -8 -42.14 dB - public static function bitrateLookup($frmsizecod) { - // LSB is whether padding is used or not - $padding = (bool) ($frmsizecod & 0x01); - $framesizeid = ($frmsizecod & 0x3E) >> 1; + $fourbit = str_pad(decbin(($compre & 0xF0) >> 4), 4, '0', STR_PAD_LEFT); + if ($fourbit[0] == '1') { + $log_gain = -8 + bindec(substr($fourbit, 1)); + } else { + $log_gain = bindec(substr($fourbit, 1)); + } + $log_gain = ($log_gain + 1) * getid3_lib::RGADamplitude2dB(2); - static $bitrateLookup = array( - 0 => 32000, - 1 => 40000, - 2 => 48000, - 3 => 56000, - 4 => 64000, - 5 => 80000, - 6 => 96000, - 7 => 112000, - 8 => 128000, - 9 => 160000, - 10 => 192000, - 11 => 224000, - 12 => 256000, - 13 => 320000, - 14 => 384000, - 15 => 448000, - 16 => 512000, - 17 => 576000, - 18 => 640000, - ); - return (isset($bitrateLookup[$framesizeid]) ? $bitrateLookup[$framesizeid] : false); - } + // The value of Y is a linear representation of a gain change of up to -6 dB. Y is considered to + // be an unsigned fractional integer, with a leading value of 1, or: 0.1 Y4 Y5 Y6 Y7 (base 2). Y can + // represent values between 0.111112 (or 31/32) and 0.100002 (or 1/2). Thus, Y can represent gain + // changes from -0.28 dB to -6.02 dB. - public static function blocksPerSyncFrame($numblkscod) { - static $blocksPerSyncFrameLookup = array( - 0 => 1, - 1 => 2, - 2 => 3, - 3 => 6, - ); - return (isset($blocksPerSyncFrameLookup[$numblkscod]) ? $blocksPerSyncFrameLookup[$numblkscod] : false); - } + $lin_gain = (16 + ($compre & 0x0F)) / 32; + // The combination of X and Y values allows compr to indicate gain changes from + // 48.16 - 0.28 = +47.89 dB, to + // -42.14 - 6.02 = -48.16 dB. + return $log_gain - $lin_gain; + } + + public static function roomTypeLookup($roomtyp) + { + static $roomTypeLookup = [ + 0 => 'not indicated', + 1 => 'large room, X curve monitor', + 2 => 'small room, flat monitor', + 3 => 'reserved', + ]; + + return isset($roomTypeLookup[$roomtyp]) ? $roomTypeLookup[$roomtyp] : false; + } + + public static function frameSizeLookup($frmsizecod, $fscod) + { + // LSB is whether padding is used or not + $padding = (bool) ($frmsizecod & 0x01); + $framesizeid = ($frmsizecod & 0x3E) >> 1; + + static $frameSizeLookup = []; + if (empty($frameSizeLookup)) { + $frameSizeLookup = [ + 0 => [128, 138, 192], // 32 kbps + 1 => [160, 174, 240], // 40 kbps + 2 => [192, 208, 288], // 48 kbps + 3 => [224, 242, 336], // 56 kbps + 4 => [256, 278, 384], // 64 kbps + 5 => [320, 348, 480], // 80 kbps + 6 => [384, 416, 576], // 96 kbps + 7 => [448, 486, 672], // 112 kbps + 8 => [512, 556, 768], // 128 kbps + 9 => [640, 696, 960], // 160 kbps + 10 => [768, 834, 1152], // 192 kbps + 11 => [896, 974, 1344], // 224 kbps + 12 => [1024, 1114, 1536], // 256 kbps + 13 => [1280, 1392, 1920], // 320 kbps + 14 => [1536, 1670, 2304], // 384 kbps + 15 => [1792, 1950, 2688], // 448 kbps + 16 => [2048, 2228, 3072], // 512 kbps + 17 => [2304, 2506, 3456], // 576 kbps + 18 => [2560, 2786, 3840], // 640 kbps + ]; + } + if (($fscod == 1) && $padding) { + // frame lengths are padded by 1 word (16 bits) at 44100 + $frameSizeLookup[$frmsizecod] += 2; + } + + return isset($frameSizeLookup[$framesizeid][$fscod]) ? $frameSizeLookup[$framesizeid][$fscod] : false; + } + + public static function bitrateLookup($frmsizecod) + { + // LSB is whether padding is used or not + $padding = (bool) ($frmsizecod & 0x01); + $framesizeid = ($frmsizecod & 0x3E) >> 1; + + static $bitrateLookup = [ + 0 => 32000, + 1 => 40000, + 2 => 48000, + 3 => 56000, + 4 => 64000, + 5 => 80000, + 6 => 96000, + 7 => 112000, + 8 => 128000, + 9 => 160000, + 10 => 192000, + 11 => 224000, + 12 => 256000, + 13 => 320000, + 14 => 384000, + 15 => 448000, + 16 => 512000, + 17 => 576000, + 18 => 640000, + ]; + + return isset($bitrateLookup[$framesizeid]) ? $bitrateLookup[$framesizeid] : false; + } + + public static function blocksPerSyncFrame($numblkscod) + { + static $blocksPerSyncFrameLookup = [ + 0 => 1, + 1 => 2, + 2 => 3, + 3 => 6, + ]; + + return isset($blocksPerSyncFrameLookup[$numblkscod]) ? $blocksPerSyncFrameLookup[$numblkscod] : false; + } } diff --git a/app/Library/getid3/getid3/module.audio.amr.php b/app/Library/getid3/getid3/module.audio.amr.php index ff505796..454721d8 100644 --- a/app/Library/getid3/getid3/module.audio.amr.php +++ b/app/Library/getid3/getid3/module.audio.amr.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,83 +15,84 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_amr extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $AMRheader = $this->fread(6); - $this->fseek($info['avdataoffset']); - $AMRheader = $this->fread(6); + $magic = '#!AMR'."\x0A"; + if (substr($AMRheader, 0, 6) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($AMRheader, 0, 6)).'"'); - $magic = '#!AMR'."\x0A"; - if (substr($AMRheader, 0, 6) != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($AMRheader, 0, 6)).'"'); - return false; - } + return false; + } - // shortcut - $info['amr'] = array(); - $thisfile_amr = &$info['amr']; + // shortcut + $info['amr'] = []; + $thisfile_amr = &$info['amr']; - $info['fileformat'] = 'amr'; - $info['audio']['dataformat'] = 'amr'; - $info['audio']['bitrate_mode'] = 'vbr'; // within a small predefined range: 4.75kbps to 12.2kbps - $info['audio']['bits_per_sample'] = 13; // http://en.wikipedia.org/wiki/Adaptive_Multi-Rate_audio_codec: "Sampling frequency 8 kHz/13-bit (160 samples for 20 ms frames), filtered to 200–3400 Hz" - $info['audio']['sample_rate'] = 8000; // http://en.wikipedia.org/wiki/Adaptive_Multi-Rate_audio_codec: "Sampling frequency 8 kHz/13-bit (160 samples for 20 ms frames), filtered to 200–3400 Hz" - $info['audio']['channels'] = 1; - $thisfile_amr['frame_mode_count'] = array(0=>0, 1=>0, 2=>0, 3=>0, 4=>0, 5=>0, 6=>0, 7=>0); + $info['fileformat'] = 'amr'; + $info['audio']['dataformat'] = 'amr'; + $info['audio']['bitrate_mode'] = 'vbr'; // within a small predefined range: 4.75kbps to 12.2kbps + $info['audio']['bits_per_sample'] = 13; // http://en.wikipedia.org/wiki/Adaptive_Multi-Rate_audio_codec: "Sampling frequency 8 kHz/13-bit (160 samples for 20 ms frames), filtered to 200–3400 Hz" + $info['audio']['sample_rate'] = 8000; // http://en.wikipedia.org/wiki/Adaptive_Multi-Rate_audio_codec: "Sampling frequency 8 kHz/13-bit (160 samples for 20 ms frames), filtered to 200–3400 Hz" + $info['audio']['channels'] = 1; + $thisfile_amr['frame_mode_count'] = [0=>0, 1=>0, 2=>0, 3=>0, 4=>0, 5=>0, 6=>0, 7=>0]; - $buffer = ''; - do { - if ((strlen($buffer) < $this->getid3->fread_buffer_size()) && !feof($this->getid3->fp)) { - $buffer .= $this->fread($this->getid3->fread_buffer_size() * 2); - } - $AMR_frame_header = ord(substr($buffer, 0, 1)); - $codec_mode_request = ($AMR_frame_header & 0x78) >> 3; // The 2nd bit through 5th bit (counting the most significant bit as the first bit) comprise the CMR (Codec Mode Request), values 0-7 being valid for AMR. The top bit of the CMR can actually be ignored, though it is used when AMR forms RTP payloads. The lower 3-bits of the header are reserved and are not used. Viewing the header from most significant bit to least significant bit, the encoding is XCCCCXXX, where Xs are reserved (typically 0) and the Cs are the CMR. - if ($codec_mode_request > 7) { - break; - } - $thisfile_amr['frame_mode_count'][$codec_mode_request]++; - $buffer = substr($buffer, $this->amr_mode_bytes_per_frame($codec_mode_request)); - } while (strlen($buffer) > 0); + $buffer = ''; + do { + if ((strlen($buffer) < $this->getid3->fread_buffer_size()) && ! feof($this->getid3->fp)) { + $buffer .= $this->fread($this->getid3->fread_buffer_size() * 2); + } + $AMR_frame_header = ord(substr($buffer, 0, 1)); + $codec_mode_request = ($AMR_frame_header & 0x78) >> 3; // The 2nd bit through 5th bit (counting the most significant bit as the first bit) comprise the CMR (Codec Mode Request), values 0-7 being valid for AMR. The top bit of the CMR can actually be ignored, though it is used when AMR forms RTP payloads. The lower 3-bits of the header are reserved and are not used. Viewing the header from most significant bit to least significant bit, the encoding is XCCCCXXX, where Xs are reserved (typically 0) and the Cs are the CMR. + if ($codec_mode_request > 7) { + break; + } + $thisfile_amr['frame_mode_count'][$codec_mode_request]++; + $buffer = substr($buffer, $this->amr_mode_bytes_per_frame($codec_mode_request)); + } while (strlen($buffer) > 0); - $info['playtime_seconds'] = array_sum($thisfile_amr['frame_mode_count']) * 0.020; // each frame contain 160 samples and is 20 milliseconds long - $info['audio']['bitrate'] = (8 * ($info['avdataend'] - $info['avdataoffset'])) / $info['playtime_seconds']; // bitrate could be calculated from average bitrate by distributation of frame types. That would give effective audio bitrate, this gives overall file bitrate which will be a little bit higher since every frame will waste 8 bits for header, plus a few bits for octet padding - $info['bitrate'] = $info['audio']['bitrate']; + $info['playtime_seconds'] = array_sum($thisfile_amr['frame_mode_count']) * 0.020; // each frame contain 160 samples and is 20 milliseconds long + $info['audio']['bitrate'] = (8 * ($info['avdataend'] - $info['avdataoffset'])) / $info['playtime_seconds']; // bitrate could be calculated from average bitrate by distributation of frame types. That would give effective audio bitrate, this gives overall file bitrate which will be a little bit higher since every frame will waste 8 bits for header, plus a few bits for octet padding + $info['bitrate'] = $info['audio']['bitrate']; - return true; - } + return true; + } + public function amr_mode_bitrate($key) + { + static $amr_mode_bitrate = [ + 0 => 4750, + 1 => 5150, + 2 => 5900, + 3 => 6700, + 4 => 7400, + 5 => 7950, + 6 => 10200, + 7 => 12200, + ]; - public function amr_mode_bitrate($key) { - static $amr_mode_bitrate = array( - 0 => 4750, - 1 => 5150, - 2 => 5900, - 3 => 6700, - 4 => 7400, - 5 => 7950, - 6 => 10200, - 7 => 12200, - ); - return (isset($amr_mode_bitrate[$key]) ? $amr_mode_bitrate[$key] : false); - } - - public function amr_mode_bytes_per_frame($key) { - static $amr_mode_bitrate = array( - 0 => 13, // 1-byte frame header + 95 bits [padded to: 12 bytes] audio data - 1 => 14, // 1-byte frame header + 103 bits [padded to: 13 bytes] audio data - 2 => 16, // 1-byte frame header + 118 bits [padded to: 15 bytes] audio data - 3 => 18, // 1-byte frame header + 134 bits [padded to: 17 bytes] audio data - 4 => 20, // 1-byte frame header + 148 bits [padded to: 19 bytes] audio data - 5 => 21, // 1-byte frame header + 159 bits [padded to: 20 bytes] audio data - 6 => 27, // 1-byte frame header + 204 bits [padded to: 26 bytes] audio data - 7 => 32, // 1-byte frame header + 244 bits [padded to: 31 bytes] audio data - ); - return (isset($amr_mode_bitrate[$key]) ? $amr_mode_bitrate[$key] : false); - } + return isset($amr_mode_bitrate[$key]) ? $amr_mode_bitrate[$key] : false; + } + public function amr_mode_bytes_per_frame($key) + { + static $amr_mode_bitrate = [ + 0 => 13, // 1-byte frame header + 95 bits [padded to: 12 bytes] audio data + 1 => 14, // 1-byte frame header + 103 bits [padded to: 13 bytes] audio data + 2 => 16, // 1-byte frame header + 118 bits [padded to: 15 bytes] audio data + 3 => 18, // 1-byte frame header + 134 bits [padded to: 17 bytes] audio data + 4 => 20, // 1-byte frame header + 148 bits [padded to: 19 bytes] audio data + 5 => 21, // 1-byte frame header + 159 bits [padded to: 20 bytes] audio data + 6 => 27, // 1-byte frame header + 204 bits [padded to: 26 bytes] audio data + 7 => 32, // 1-byte frame header + 244 bits [padded to: 31 bytes] audio data + ]; + return isset($amr_mode_bitrate[$key]) ? $amr_mode_bitrate[$key] : false; + } } diff --git a/app/Library/getid3/getid3/module.audio.au.php b/app/Library/getid3/getid3/module.audio.au.php index 075ee8c7..654cc430 100644 --- a/app/Library/getid3/getid3/module.audio.au.php +++ b/app/Library/getid3/getid3/module.audio.au.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,150 +15,155 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_au extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $AUheader = $this->fread(8); - $this->fseek($info['avdataoffset']); - $AUheader = $this->fread(8); + $magic = '.snd'; + if (substr($AUheader, 0, 4) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" (".snd") at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($AUheader, 0, 4)).'"'); - $magic = '.snd'; - if (substr($AUheader, 0, 4) != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" (".snd") at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($AUheader, 0, 4)).'"'); - return false; - } + return false; + } - // shortcut - $info['au'] = array(); - $thisfile_au = &$info['au']; + // shortcut + $info['au'] = []; + $thisfile_au = &$info['au']; - $info['fileformat'] = 'au'; - $info['audio']['dataformat'] = 'au'; - $info['audio']['bitrate_mode'] = 'cbr'; - $thisfile_au['encoding'] = 'ISO-8859-1'; + $info['fileformat'] = 'au'; + $info['audio']['dataformat'] = 'au'; + $info['audio']['bitrate_mode'] = 'cbr'; + $thisfile_au['encoding'] = 'ISO-8859-1'; - $thisfile_au['header_length'] = getid3_lib::BigEndian2Int(substr($AUheader, 4, 4)); - $AUheader .= $this->fread($thisfile_au['header_length'] - 8); - $info['avdataoffset'] += $thisfile_au['header_length']; + $thisfile_au['header_length'] = getid3_lib::BigEndian2Int(substr($AUheader, 4, 4)); + $AUheader .= $this->fread($thisfile_au['header_length'] - 8); + $info['avdataoffset'] += $thisfile_au['header_length']; - $thisfile_au['data_size'] = getid3_lib::BigEndian2Int(substr($AUheader, 8, 4)); - $thisfile_au['data_format_id'] = getid3_lib::BigEndian2Int(substr($AUheader, 12, 4)); - $thisfile_au['sample_rate'] = getid3_lib::BigEndian2Int(substr($AUheader, 16, 4)); - $thisfile_au['channels'] = getid3_lib::BigEndian2Int(substr($AUheader, 20, 4)); - $thisfile_au['comments']['comment'][] = trim(substr($AUheader, 24)); + $thisfile_au['data_size'] = getid3_lib::BigEndian2Int(substr($AUheader, 8, 4)); + $thisfile_au['data_format_id'] = getid3_lib::BigEndian2Int(substr($AUheader, 12, 4)); + $thisfile_au['sample_rate'] = getid3_lib::BigEndian2Int(substr($AUheader, 16, 4)); + $thisfile_au['channels'] = getid3_lib::BigEndian2Int(substr($AUheader, 20, 4)); + $thisfile_au['comments']['comment'][] = trim(substr($AUheader, 24)); - $thisfile_au['data_format'] = $this->AUdataFormatNameLookup($thisfile_au['data_format_id']); - $thisfile_au['used_bits_per_sample'] = $this->AUdataFormatUsedBitsPerSampleLookup($thisfile_au['data_format_id']); - if ($thisfile_au['bits_per_sample'] = $this->AUdataFormatBitsPerSampleLookup($thisfile_au['data_format_id'])) { - $info['audio']['bits_per_sample'] = $thisfile_au['bits_per_sample']; - } else { - unset($thisfile_au['bits_per_sample']); - } + $thisfile_au['data_format'] = $this->AUdataFormatNameLookup($thisfile_au['data_format_id']); + $thisfile_au['used_bits_per_sample'] = $this->AUdataFormatUsedBitsPerSampleLookup($thisfile_au['data_format_id']); + if ($thisfile_au['bits_per_sample'] = $this->AUdataFormatBitsPerSampleLookup($thisfile_au['data_format_id'])) { + $info['audio']['bits_per_sample'] = $thisfile_au['bits_per_sample']; + } else { + unset($thisfile_au['bits_per_sample']); + } - $info['audio']['sample_rate'] = $thisfile_au['sample_rate']; - $info['audio']['channels'] = $thisfile_au['channels']; + $info['audio']['sample_rate'] = $thisfile_au['sample_rate']; + $info['audio']['channels'] = $thisfile_au['channels']; - if (($info['avdataoffset'] + $thisfile_au['data_size']) > $info['avdataend']) { - $this->warning('Possible truncated file - expecting "'.$thisfile_au['data_size'].'" bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' bytes"'); - } + if (($info['avdataoffset'] + $thisfile_au['data_size']) > $info['avdataend']) { + $this->warning('Possible truncated file - expecting "'.$thisfile_au['data_size'].'" bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' bytes"'); + } - $info['playtime_seconds'] = $thisfile_au['data_size'] / ($thisfile_au['sample_rate'] * $thisfile_au['channels'] * ($thisfile_au['used_bits_per_sample'] / 8)); - $info['audio']['bitrate'] = ($thisfile_au['data_size'] * 8) / $info['playtime_seconds']; + $info['playtime_seconds'] = $thisfile_au['data_size'] / ($thisfile_au['sample_rate'] * $thisfile_au['channels'] * ($thisfile_au['used_bits_per_sample'] / 8)); + $info['audio']['bitrate'] = ($thisfile_au['data_size'] * 8) / $info['playtime_seconds']; - return true; - } + return true; + } - public function AUdataFormatNameLookup($id) { - static $AUdataFormatNameLookup = array( - 0 => 'unspecified format', - 1 => '8-bit mu-law', - 2 => '8-bit linear', - 3 => '16-bit linear', - 4 => '24-bit linear', - 5 => '32-bit linear', - 6 => 'floating-point', - 7 => 'double-precision float', - 8 => 'fragmented sampled data', - 9 => 'SUN_FORMAT_NESTED', - 10 => 'DSP program', - 11 => '8-bit fixed-point', - 12 => '16-bit fixed-point', - 13 => '24-bit fixed-point', - 14 => '32-bit fixed-point', + public function AUdataFormatNameLookup($id) + { + static $AUdataFormatNameLookup = [ + 0 => 'unspecified format', + 1 => '8-bit mu-law', + 2 => '8-bit linear', + 3 => '16-bit linear', + 4 => '24-bit linear', + 5 => '32-bit linear', + 6 => 'floating-point', + 7 => 'double-precision float', + 8 => 'fragmented sampled data', + 9 => 'SUN_FORMAT_NESTED', + 10 => 'DSP program', + 11 => '8-bit fixed-point', + 12 => '16-bit fixed-point', + 13 => '24-bit fixed-point', + 14 => '32-bit fixed-point', - 16 => 'non-audio display data', - 17 => 'SND_FORMAT_MULAW_SQUELCH', - 18 => '16-bit linear with emphasis', - 19 => '16-bit linear with compression', - 20 => '16-bit linear with emphasis + compression', - 21 => 'Music Kit DSP commands', - 22 => 'SND_FORMAT_DSP_COMMANDS_SAMPLES', - 23 => 'CCITT g.721 4-bit ADPCM', - 24 => 'CCITT g.722 ADPCM', - 25 => 'CCITT g.723 3-bit ADPCM', - 26 => 'CCITT g.723 5-bit ADPCM', - 27 => 'A-Law 8-bit' - ); - return (isset($AUdataFormatNameLookup[$id]) ? $AUdataFormatNameLookup[$id] : false); - } + 16 => 'non-audio display data', + 17 => 'SND_FORMAT_MULAW_SQUELCH', + 18 => '16-bit linear with emphasis', + 19 => '16-bit linear with compression', + 20 => '16-bit linear with emphasis + compression', + 21 => 'Music Kit DSP commands', + 22 => 'SND_FORMAT_DSP_COMMANDS_SAMPLES', + 23 => 'CCITT g.721 4-bit ADPCM', + 24 => 'CCITT g.722 ADPCM', + 25 => 'CCITT g.723 3-bit ADPCM', + 26 => 'CCITT g.723 5-bit ADPCM', + 27 => 'A-Law 8-bit', + ]; - public function AUdataFormatBitsPerSampleLookup($id) { - static $AUdataFormatBitsPerSampleLookup = array( - 1 => 8, - 2 => 8, - 3 => 16, - 4 => 24, - 5 => 32, - 6 => 32, - 7 => 64, + return isset($AUdataFormatNameLookup[$id]) ? $AUdataFormatNameLookup[$id] : false; + } - 11 => 8, - 12 => 16, - 13 => 24, - 14 => 32, + public function AUdataFormatBitsPerSampleLookup($id) + { + static $AUdataFormatBitsPerSampleLookup = [ + 1 => 8, + 2 => 8, + 3 => 16, + 4 => 24, + 5 => 32, + 6 => 32, + 7 => 64, - 18 => 16, - 19 => 16, - 20 => 16, + 11 => 8, + 12 => 16, + 13 => 24, + 14 => 32, - 23 => 16, + 18 => 16, + 19 => 16, + 20 => 16, - 25 => 16, - 26 => 16, - 27 => 8 - ); - return (isset($AUdataFormatBitsPerSampleLookup[$id]) ? $AUdataFormatBitsPerSampleLookup[$id] : false); - } + 23 => 16, - public function AUdataFormatUsedBitsPerSampleLookup($id) { - static $AUdataFormatUsedBitsPerSampleLookup = array( - 1 => 8, - 2 => 8, - 3 => 16, - 4 => 24, - 5 => 32, - 6 => 32, - 7 => 64, + 25 => 16, + 26 => 16, + 27 => 8, + ]; - 11 => 8, - 12 => 16, - 13 => 24, - 14 => 32, + return isset($AUdataFormatBitsPerSampleLookup[$id]) ? $AUdataFormatBitsPerSampleLookup[$id] : false; + } - 18 => 16, - 19 => 16, - 20 => 16, + public function AUdataFormatUsedBitsPerSampleLookup($id) + { + static $AUdataFormatUsedBitsPerSampleLookup = [ + 1 => 8, + 2 => 8, + 3 => 16, + 4 => 24, + 5 => 32, + 6 => 32, + 7 => 64, - 23 => 4, + 11 => 8, + 12 => 16, + 13 => 24, + 14 => 32, - 25 => 3, - 26 => 5, - 27 => 8, - ); - return (isset($AUdataFormatUsedBitsPerSampleLookup[$id]) ? $AUdataFormatUsedBitsPerSampleLookup[$id] : false); - } + 18 => 16, + 19 => 16, + 20 => 16, + 23 => 4, + + 25 => 3, + 26 => 5, + 27 => 8, + ]; + + return isset($AUdataFormatUsedBitsPerSampleLookup[$id]) ? $AUdataFormatUsedBitsPerSampleLookup[$id] : false; + } } diff --git a/app/Library/getid3/getid3/module.audio.avr.php b/app/Library/getid3/getid3/module.audio.avr.php index 98666cf0..30fc6e67 100644 --- a/app/Library/getid3/getid3/module.audio.avr.php +++ b/app/Library/getid3/getid3/module.audio.avr.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,112 +15,110 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_avr extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + // http://cui.unige.ch/OSG/info/AudioFormats/ap11.html + // http://www.btinternet.com/~AnthonyJ/Atari/programming/avr_format.html + // offset type length name comments + // --------------------------------------------------------------------- + // 0 char 4 ID format ID == "2BIT" + // 4 char 8 name sample name (unused space filled with 0) + // 12 short 1 mono/stereo 0=mono, -1 (0xFFFF)=stereo + // With stereo, samples are alternated, + // the first voice is the left : + // (LRLRLRLRLRLRLRLRLR...) + // 14 short 1 resolution 8, 12 or 16 (bits) + // 16 short 1 signed or not 0=unsigned, -1 (0xFFFF)=signed + // 18 short 1 loop or not 0=no loop, -1 (0xFFFF)=loop on + // 20 short 1 MIDI note 0xFFnn, where 0 <= nn <= 127 + // 0xFFFF means "no MIDI note defined" + // 22 byte 1 Replay speed Frequence in the Replay software + // 0=5.485 Khz, 1=8.084 Khz, 2=10.971 Khz, + // 3=16.168 Khz, 4=21.942 Khz, 5=32.336 Khz + // 6=43.885 Khz, 7=47.261 Khz + // -1 (0xFF)=no defined Frequence + // 23 byte 3 sample rate in Hertz + // 26 long 1 size in bytes (2 * bytes in stereo) + // 30 long 1 loop begin 0 for no loop + // 34 long 1 loop size equal to 'size' for no loop + // 38 short 2 Reserved, MIDI keyboard split */ + // 40 short 2 Reserved, sample compression */ + // 42 short 2 Reserved */ + // 44 char 20; Additional filename space, used if (name[7] != 0) + // 64 byte 64 user data + // 128 bytes ? sample data (12 bits samples are coded on 16 bits: + // 0000 xxxx xxxx xxxx) + // --------------------------------------------------------------------- - // http://cui.unige.ch/OSG/info/AudioFormats/ap11.html - // http://www.btinternet.com/~AnthonyJ/Atari/programming/avr_format.html - // offset type length name comments - // --------------------------------------------------------------------- - // 0 char 4 ID format ID == "2BIT" - // 4 char 8 name sample name (unused space filled with 0) - // 12 short 1 mono/stereo 0=mono, -1 (0xFFFF)=stereo - // With stereo, samples are alternated, - // the first voice is the left : - // (LRLRLRLRLRLRLRLRLR...) - // 14 short 1 resolution 8, 12 or 16 (bits) - // 16 short 1 signed or not 0=unsigned, -1 (0xFFFF)=signed - // 18 short 1 loop or not 0=no loop, -1 (0xFFFF)=loop on - // 20 short 1 MIDI note 0xFFnn, where 0 <= nn <= 127 - // 0xFFFF means "no MIDI note defined" - // 22 byte 1 Replay speed Frequence in the Replay software - // 0=5.485 Khz, 1=8.084 Khz, 2=10.971 Khz, - // 3=16.168 Khz, 4=21.942 Khz, 5=32.336 Khz - // 6=43.885 Khz, 7=47.261 Khz - // -1 (0xFF)=no defined Frequence - // 23 byte 3 sample rate in Hertz - // 26 long 1 size in bytes (2 * bytes in stereo) - // 30 long 1 loop begin 0 for no loop - // 34 long 1 loop size equal to 'size' for no loop - // 38 short 2 Reserved, MIDI keyboard split */ - // 40 short 2 Reserved, sample compression */ - // 42 short 2 Reserved */ - // 44 char 20; Additional filename space, used if (name[7] != 0) - // 64 byte 64 user data - // 128 bytes ? sample data (12 bits samples are coded on 16 bits: - // 0000 xxxx xxxx xxxx) - // --------------------------------------------------------------------- + // Note that all values are in motorola (big-endian) format, and that long is + // assumed to be 4 bytes, and short 2 bytes. + // When reading the samples, you should handle both signed and unsigned data, + // and be prepared to convert 16->8 bit, or mono->stereo if needed. To convert + // 8-bit data between signed/unsigned just add 127 to the sample values. + // Simularly for 16-bit data you should add 32769 - // Note that all values are in motorola (big-endian) format, and that long is - // assumed to be 4 bytes, and short 2 bytes. - // When reading the samples, you should handle both signed and unsigned data, - // and be prepared to convert 16->8 bit, or mono->stereo if needed. To convert - // 8-bit data between signed/unsigned just add 127 to the sample values. - // Simularly for 16-bit data you should add 32769 + $info['fileformat'] = 'avr'; - $info['fileformat'] = 'avr'; + $this->fseek($info['avdataoffset']); + $AVRheader = $this->fread(128); - $this->fseek($info['avdataoffset']); - $AVRheader = $this->fread(128); + $info['avr']['raw']['magic'] = substr($AVRheader, 0, 4); + $magic = '2BIT'; + if ($info['avr']['raw']['magic'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['avr']['raw']['magic']).'"'); + unset($info['fileformat']); + unset($info['avr']); - $info['avr']['raw']['magic'] = substr($AVRheader, 0, 4); - $magic = '2BIT'; - if ($info['avr']['raw']['magic'] != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['avr']['raw']['magic']).'"'); - unset($info['fileformat']); - unset($info['avr']); - return false; - } - $info['avdataoffset'] += 128; + return false; + } + $info['avdataoffset'] += 128; - $info['avr']['sample_name'] = rtrim(substr($AVRheader, 4, 8)); - $info['avr']['raw']['mono'] = getid3_lib::BigEndian2Int(substr($AVRheader, 12, 2)); - $info['avr']['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($AVRheader, 14, 2)); - $info['avr']['raw']['signed'] = getid3_lib::BigEndian2Int(substr($AVRheader, 16, 2)); - $info['avr']['raw']['loop'] = getid3_lib::BigEndian2Int(substr($AVRheader, 18, 2)); - $info['avr']['raw']['midi'] = getid3_lib::BigEndian2Int(substr($AVRheader, 20, 2)); - $info['avr']['raw']['replay_freq'] = getid3_lib::BigEndian2Int(substr($AVRheader, 22, 1)); - $info['avr']['sample_rate'] = getid3_lib::BigEndian2Int(substr($AVRheader, 23, 3)); - $info['avr']['sample_length'] = getid3_lib::BigEndian2Int(substr($AVRheader, 26, 4)); - $info['avr']['loop_start'] = getid3_lib::BigEndian2Int(substr($AVRheader, 30, 4)); - $info['avr']['loop_end'] = getid3_lib::BigEndian2Int(substr($AVRheader, 34, 4)); - $info['avr']['midi_split'] = getid3_lib::BigEndian2Int(substr($AVRheader, 38, 2)); - $info['avr']['sample_compression'] = getid3_lib::BigEndian2Int(substr($AVRheader, 40, 2)); - $info['avr']['reserved'] = getid3_lib::BigEndian2Int(substr($AVRheader, 42, 2)); - $info['avr']['sample_name_extra'] = rtrim(substr($AVRheader, 44, 20)); - $info['avr']['comment'] = rtrim(substr($AVRheader, 64, 64)); + $info['avr']['sample_name'] = rtrim(substr($AVRheader, 4, 8)); + $info['avr']['raw']['mono'] = getid3_lib::BigEndian2Int(substr($AVRheader, 12, 2)); + $info['avr']['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($AVRheader, 14, 2)); + $info['avr']['raw']['signed'] = getid3_lib::BigEndian2Int(substr($AVRheader, 16, 2)); + $info['avr']['raw']['loop'] = getid3_lib::BigEndian2Int(substr($AVRheader, 18, 2)); + $info['avr']['raw']['midi'] = getid3_lib::BigEndian2Int(substr($AVRheader, 20, 2)); + $info['avr']['raw']['replay_freq'] = getid3_lib::BigEndian2Int(substr($AVRheader, 22, 1)); + $info['avr']['sample_rate'] = getid3_lib::BigEndian2Int(substr($AVRheader, 23, 3)); + $info['avr']['sample_length'] = getid3_lib::BigEndian2Int(substr($AVRheader, 26, 4)); + $info['avr']['loop_start'] = getid3_lib::BigEndian2Int(substr($AVRheader, 30, 4)); + $info['avr']['loop_end'] = getid3_lib::BigEndian2Int(substr($AVRheader, 34, 4)); + $info['avr']['midi_split'] = getid3_lib::BigEndian2Int(substr($AVRheader, 38, 2)); + $info['avr']['sample_compression'] = getid3_lib::BigEndian2Int(substr($AVRheader, 40, 2)); + $info['avr']['reserved'] = getid3_lib::BigEndian2Int(substr($AVRheader, 42, 2)); + $info['avr']['sample_name_extra'] = rtrim(substr($AVRheader, 44, 20)); + $info['avr']['comment'] = rtrim(substr($AVRheader, 64, 64)); - $info['avr']['flags']['stereo'] = (($info['avr']['raw']['mono'] == 0) ? false : true); - $info['avr']['flags']['signed'] = (($info['avr']['raw']['signed'] == 0) ? false : true); - $info['avr']['flags']['loop'] = (($info['avr']['raw']['loop'] == 0) ? false : true); + $info['avr']['flags']['stereo'] = (($info['avr']['raw']['mono'] == 0) ? false : true); + $info['avr']['flags']['signed'] = (($info['avr']['raw']['signed'] == 0) ? false : true); + $info['avr']['flags']['loop'] = (($info['avr']['raw']['loop'] == 0) ? false : true); - $info['avr']['midi_notes'] = array(); - if (($info['avr']['raw']['midi'] & 0xFF00) != 0xFF00) { - $info['avr']['midi_notes'][] = ($info['avr']['raw']['midi'] & 0xFF00) >> 8; - } - if (($info['avr']['raw']['midi'] & 0x00FF) != 0x00FF) { - $info['avr']['midi_notes'][] = ($info['avr']['raw']['midi'] & 0x00FF); - } + $info['avr']['midi_notes'] = []; + if (($info['avr']['raw']['midi'] & 0xFF00) != 0xFF00) { + $info['avr']['midi_notes'][] = ($info['avr']['raw']['midi'] & 0xFF00) >> 8; + } + if (($info['avr']['raw']['midi'] & 0x00FF) != 0x00FF) { + $info['avr']['midi_notes'][] = ($info['avr']['raw']['midi'] & 0x00FF); + } - if (($info['avdataend'] - $info['avdataoffset']) != ($info['avr']['sample_length'] * (($info['avr']['bits_per_sample'] == 8) ? 1 : 2))) { - $this->warning('Probable truncated file: expecting '.($info['avr']['sample_length'] * (($info['avr']['bits_per_sample'] == 8) ? 1 : 2)).' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset'])); - } + if (($info['avdataend'] - $info['avdataoffset']) != ($info['avr']['sample_length'] * (($info['avr']['bits_per_sample'] == 8) ? 1 : 2))) { + $this->warning('Probable truncated file: expecting '.($info['avr']['sample_length'] * (($info['avr']['bits_per_sample'] == 8) ? 1 : 2)).' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset'])); + } - $info['audio']['dataformat'] = 'avr'; - $info['audio']['lossless'] = true; - $info['audio']['bitrate_mode'] = 'cbr'; - $info['audio']['bits_per_sample'] = $info['avr']['bits_per_sample']; - $info['audio']['sample_rate'] = $info['avr']['sample_rate']; - $info['audio']['channels'] = ($info['avr']['flags']['stereo'] ? 2 : 1); - $info['playtime_seconds'] = ($info['avr']['sample_length'] / $info['audio']['channels']) / $info['avr']['sample_rate']; - $info['audio']['bitrate'] = ($info['avr']['sample_length'] * (($info['avr']['bits_per_sample'] == 8) ? 8 : 16)) / $info['playtime_seconds']; - - - return true; - } + $info['audio']['dataformat'] = 'avr'; + $info['audio']['lossless'] = true; + $info['audio']['bitrate_mode'] = 'cbr'; + $info['audio']['bits_per_sample'] = $info['avr']['bits_per_sample']; + $info['audio']['sample_rate'] = $info['avr']['sample_rate']; + $info['audio']['channels'] = ($info['avr']['flags']['stereo'] ? 2 : 1); + $info['playtime_seconds'] = ($info['avr']['sample_length'] / $info['audio']['channels']) / $info['avr']['sample_rate']; + $info['audio']['bitrate'] = ($info['avr']['sample_length'] * (($info['avr']['bits_per_sample'] == 8) ? 8 : 16)) / $info['playtime_seconds']; + return true; + } } diff --git a/app/Library/getid3/getid3/module.audio.bonk.php b/app/Library/getid3/getid3/module.audio.bonk.php index f314a9f5..95ab46f2 100644 --- a/app/Library/getid3/getid3/module.audio.bonk.php +++ b/app/Library/getid3/getid3/module.audio.bonk.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,215 +15,215 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_bonk extends getid3_handler { - public function Analyze() { - $info = &$this->getid3->info; + public function Analyze() + { + $info = &$this->getid3->info; - // shortcut - $info['bonk'] = array(); - $thisfile_bonk = &$info['bonk']; + // shortcut + $info['bonk'] = []; + $thisfile_bonk = &$info['bonk']; - $thisfile_bonk['dataoffset'] = $info['avdataoffset']; - $thisfile_bonk['dataend'] = $info['avdataend']; + $thisfile_bonk['dataoffset'] = $info['avdataoffset']; + $thisfile_bonk['dataend'] = $info['avdataend']; - if (!getid3_lib::intValueSupported($thisfile_bonk['dataend'])) { + if (! getid3_lib::intValueSupported($thisfile_bonk['dataend'])) { + $this->warning('Unable to parse BONK file from end (v0.6+ preferred method) because PHP filesystem functions only support up to '.round(PHP_INT_MAX / 1073741824).'GB'); + } else { - $this->warning('Unable to parse BONK file from end (v0.6+ preferred method) because PHP filesystem functions only support up to '.round(PHP_INT_MAX / 1073741824).'GB'); + // scan-from-end method, for v0.6 and higher + $this->fseek($thisfile_bonk['dataend'] - 8); + $PossibleBonkTag = $this->fread(8); + while ($this->BonkIsValidTagName(substr($PossibleBonkTag, 4, 4), true)) { + $BonkTagSize = getid3_lib::LittleEndian2Int(substr($PossibleBonkTag, 0, 4)); + $this->fseek(0 - $BonkTagSize, SEEK_CUR); + $BonkTagOffset = $this->ftell(); + $TagHeaderTest = $this->fread(5); + if (($TagHeaderTest[0] != "\x00") || (substr($PossibleBonkTag, 4, 4) != strtolower(substr($PossibleBonkTag, 4, 4)))) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes("\x00".strtoupper(substr($PossibleBonkTag, 4, 4))).'" at offset '.$BonkTagOffset.', found "'.getid3_lib::PrintHexBytes($TagHeaderTest).'"'); - } else { + return false; + } + $BonkTagName = substr($TagHeaderTest, 1, 4); - // scan-from-end method, for v0.6 and higher - $this->fseek($thisfile_bonk['dataend'] - 8); - $PossibleBonkTag = $this->fread(8); - while ($this->BonkIsValidTagName(substr($PossibleBonkTag, 4, 4), true)) { - $BonkTagSize = getid3_lib::LittleEndian2Int(substr($PossibleBonkTag, 0, 4)); - $this->fseek(0 - $BonkTagSize, SEEK_CUR); - $BonkTagOffset = $this->ftell(); - $TagHeaderTest = $this->fread(5); - if (($TagHeaderTest{0} != "\x00") || (substr($PossibleBonkTag, 4, 4) != strtolower(substr($PossibleBonkTag, 4, 4)))) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes("\x00".strtoupper(substr($PossibleBonkTag, 4, 4))).'" at offset '.$BonkTagOffset.', found "'.getid3_lib::PrintHexBytes($TagHeaderTest).'"'); - return false; - } - $BonkTagName = substr($TagHeaderTest, 1, 4); + $thisfile_bonk[$BonkTagName]['size'] = $BonkTagSize; + $thisfile_bonk[$BonkTagName]['offset'] = $BonkTagOffset; + $this->HandleBonkTags($BonkTagName); + $NextTagEndOffset = $BonkTagOffset - 8; + if ($NextTagEndOffset < $thisfile_bonk['dataoffset']) { + if (empty($info['audio']['encoder'])) { + $info['audio']['encoder'] = 'Extended BONK v0.9+'; + } - $thisfile_bonk[$BonkTagName]['size'] = $BonkTagSize; - $thisfile_bonk[$BonkTagName]['offset'] = $BonkTagOffset; - $this->HandleBonkTags($BonkTagName); - $NextTagEndOffset = $BonkTagOffset - 8; - if ($NextTagEndOffset < $thisfile_bonk['dataoffset']) { - if (empty($info['audio']['encoder'])) { - $info['audio']['encoder'] = 'Extended BONK v0.9+'; - } - return true; - } - $this->fseek($NextTagEndOffset); - $PossibleBonkTag = $this->fread(8); - } + return true; + } + $this->fseek($NextTagEndOffset); + $PossibleBonkTag = $this->fread(8); + } + } - } + // seek-from-beginning method for v0.4 and v0.5 + if (empty($thisfile_bonk['BONK'])) { + $this->fseek($thisfile_bonk['dataoffset']); + do { + $TagHeaderTest = $this->fread(5); + switch ($TagHeaderTest) { + case "\x00".'BONK': + if (empty($info['audio']['encoder'])) { + $info['audio']['encoder'] = 'BONK v0.4'; + } + break; - // seek-from-beginning method for v0.4 and v0.5 - if (empty($thisfile_bonk['BONK'])) { - $this->fseek($thisfile_bonk['dataoffset']); - do { - $TagHeaderTest = $this->fread(5); - switch ($TagHeaderTest) { - case "\x00".'BONK': - if (empty($info['audio']['encoder'])) { - $info['audio']['encoder'] = 'BONK v0.4'; - } - break; + case "\x00".'INFO': + $info['audio']['encoder'] = 'Extended BONK v0.5'; + break; - case "\x00".'INFO': - $info['audio']['encoder'] = 'Extended BONK v0.5'; - break; + default: + break 2; + } + $BonkTagName = substr($TagHeaderTest, 1, 4); + $thisfile_bonk[$BonkTagName]['size'] = $thisfile_bonk['dataend'] - $thisfile_bonk['dataoffset']; + $thisfile_bonk[$BonkTagName]['offset'] = $thisfile_bonk['dataoffset']; + $this->HandleBonkTags($BonkTagName); + } while (true); + } - default: - break 2; - } - $BonkTagName = substr($TagHeaderTest, 1, 4); - $thisfile_bonk[$BonkTagName]['size'] = $thisfile_bonk['dataend'] - $thisfile_bonk['dataoffset']; - $thisfile_bonk[$BonkTagName]['offset'] = $thisfile_bonk['dataoffset']; - $this->HandleBonkTags($BonkTagName); + // parse META block for v0.6 - v0.8 + if (empty($thisfile_bonk['INFO']) && isset($thisfile_bonk['META']['tags']['info'])) { + $this->fseek($thisfile_bonk['META']['tags']['info']); + $TagHeaderTest = $this->fread(5); + if ($TagHeaderTest == "\x00".'INFO') { + $info['audio']['encoder'] = 'Extended BONK v0.6 - v0.8'; - } while (true); - } + $BonkTagName = substr($TagHeaderTest, 1, 4); + $thisfile_bonk[$BonkTagName]['size'] = $thisfile_bonk['dataend'] - $thisfile_bonk['dataoffset']; + $thisfile_bonk[$BonkTagName]['offset'] = $thisfile_bonk['dataoffset']; + $this->HandleBonkTags($BonkTagName); + } + } - // parse META block for v0.6 - v0.8 - if (empty($thisfile_bonk['INFO']) && isset($thisfile_bonk['META']['tags']['info'])) { - $this->fseek($thisfile_bonk['META']['tags']['info']); - $TagHeaderTest = $this->fread(5); - if ($TagHeaderTest == "\x00".'INFO') { - $info['audio']['encoder'] = 'Extended BONK v0.6 - v0.8'; + if (empty($info['audio']['encoder'])) { + $info['audio']['encoder'] = 'Extended BONK v0.9+'; + } + if (empty($thisfile_bonk['BONK'])) { + unset($info['bonk']); + } - $BonkTagName = substr($TagHeaderTest, 1, 4); - $thisfile_bonk[$BonkTagName]['size'] = $thisfile_bonk['dataend'] - $thisfile_bonk['dataoffset']; - $thisfile_bonk[$BonkTagName]['offset'] = $thisfile_bonk['dataoffset']; - $this->HandleBonkTags($BonkTagName); - } - } + return true; + } - if (empty($info['audio']['encoder'])) { - $info['audio']['encoder'] = 'Extended BONK v0.9+'; - } - if (empty($thisfile_bonk['BONK'])) { - unset($info['bonk']); - } - return true; + public function HandleBonkTags($BonkTagName) + { + $info = &$this->getid3->info; + switch ($BonkTagName) { + case 'BONK': + // shortcut + $thisfile_bonk_BONK = &$info['bonk']['BONK']; - } + $BonkData = "\x00".'BONK'.$this->fread(17); + $thisfile_bonk_BONK['version'] = getid3_lib::LittleEndian2Int(substr($BonkData, 5, 1)); + $thisfile_bonk_BONK['number_samples'] = getid3_lib::LittleEndian2Int(substr($BonkData, 6, 4)); + $thisfile_bonk_BONK['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BonkData, 10, 4)); - public function HandleBonkTags($BonkTagName) { - $info = &$this->getid3->info; - switch ($BonkTagName) { - case 'BONK': - // shortcut - $thisfile_bonk_BONK = &$info['bonk']['BONK']; + $thisfile_bonk_BONK['channels'] = getid3_lib::LittleEndian2Int(substr($BonkData, 14, 1)); + $thisfile_bonk_BONK['lossless'] = (bool) getid3_lib::LittleEndian2Int(substr($BonkData, 15, 1)); + $thisfile_bonk_BONK['joint_stereo'] = (bool) getid3_lib::LittleEndian2Int(substr($BonkData, 16, 1)); + $thisfile_bonk_BONK['number_taps'] = getid3_lib::LittleEndian2Int(substr($BonkData, 17, 2)); + $thisfile_bonk_BONK['downsampling_ratio'] = getid3_lib::LittleEndian2Int(substr($BonkData, 19, 1)); + $thisfile_bonk_BONK['samples_per_packet'] = getid3_lib::LittleEndian2Int(substr($BonkData, 20, 2)); - $BonkData = "\x00".'BONK'.$this->fread(17); - $thisfile_bonk_BONK['version'] = getid3_lib::LittleEndian2Int(substr($BonkData, 5, 1)); - $thisfile_bonk_BONK['number_samples'] = getid3_lib::LittleEndian2Int(substr($BonkData, 6, 4)); - $thisfile_bonk_BONK['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BonkData, 10, 4)); + $info['avdataoffset'] = $thisfile_bonk_BONK['offset'] + 5 + 17; + $info['avdataend'] = $thisfile_bonk_BONK['offset'] + $thisfile_bonk_BONK['size']; - $thisfile_bonk_BONK['channels'] = getid3_lib::LittleEndian2Int(substr($BonkData, 14, 1)); - $thisfile_bonk_BONK['lossless'] = (bool) getid3_lib::LittleEndian2Int(substr($BonkData, 15, 1)); - $thisfile_bonk_BONK['joint_stereo'] = (bool) getid3_lib::LittleEndian2Int(substr($BonkData, 16, 1)); - $thisfile_bonk_BONK['number_taps'] = getid3_lib::LittleEndian2Int(substr($BonkData, 17, 2)); - $thisfile_bonk_BONK['downsampling_ratio'] = getid3_lib::LittleEndian2Int(substr($BonkData, 19, 1)); - $thisfile_bonk_BONK['samples_per_packet'] = getid3_lib::LittleEndian2Int(substr($BonkData, 20, 2)); + $info['fileformat'] = 'bonk'; + $info['audio']['dataformat'] = 'bonk'; + $info['audio']['bitrate_mode'] = 'vbr'; // assumed + $info['audio']['channels'] = $thisfile_bonk_BONK['channels']; + $info['audio']['sample_rate'] = $thisfile_bonk_BONK['sample_rate']; + $info['audio']['channelmode'] = ($thisfile_bonk_BONK['joint_stereo'] ? 'joint stereo' : 'stereo'); + $info['audio']['lossless'] = $thisfile_bonk_BONK['lossless']; + $info['audio']['codec'] = 'bonk'; - $info['avdataoffset'] = $thisfile_bonk_BONK['offset'] + 5 + 17; - $info['avdataend'] = $thisfile_bonk_BONK['offset'] + $thisfile_bonk_BONK['size']; + $info['playtime_seconds'] = $thisfile_bonk_BONK['number_samples'] / ($thisfile_bonk_BONK['sample_rate'] * $thisfile_bonk_BONK['channels']); + if ($info['playtime_seconds'] > 0) { + $info['audio']['bitrate'] = (($info['bonk']['dataend'] - $info['bonk']['dataoffset']) * 8) / $info['playtime_seconds']; + } + break; - $info['fileformat'] = 'bonk'; - $info['audio']['dataformat'] = 'bonk'; - $info['audio']['bitrate_mode'] = 'vbr'; // assumed - $info['audio']['channels'] = $thisfile_bonk_BONK['channels']; - $info['audio']['sample_rate'] = $thisfile_bonk_BONK['sample_rate']; - $info['audio']['channelmode'] = ($thisfile_bonk_BONK['joint_stereo'] ? 'joint stereo' : 'stereo'); - $info['audio']['lossless'] = $thisfile_bonk_BONK['lossless']; - $info['audio']['codec'] = 'bonk'; + case 'INFO': + // shortcut + $thisfile_bonk_INFO = &$info['bonk']['INFO']; - $info['playtime_seconds'] = $thisfile_bonk_BONK['number_samples'] / ($thisfile_bonk_BONK['sample_rate'] * $thisfile_bonk_BONK['channels']); - if ($info['playtime_seconds'] > 0) { - $info['audio']['bitrate'] = (($info['bonk']['dataend'] - $info['bonk']['dataoffset']) * 8) / $info['playtime_seconds']; - } - break; + $thisfile_bonk_INFO['version'] = getid3_lib::LittleEndian2Int($this->fread(1)); + $thisfile_bonk_INFO['entries_count'] = 0; + $NextInfoDataPair = $this->fread(5); + if (! $this->BonkIsValidTagName(substr($NextInfoDataPair, 1, 4))) { + while (! feof($this->getid3->fp)) { + //$CurrentSeekInfo['offset'] = getid3_lib::LittleEndian2Int(substr($NextInfoDataPair, 0, 4)); + //$CurrentSeekInfo['nextbit'] = getid3_lib::LittleEndian2Int(substr($NextInfoDataPair, 4, 1)); + //$thisfile_bonk_INFO[] = $CurrentSeekInfo; - case 'INFO': - // shortcut - $thisfile_bonk_INFO = &$info['bonk']['INFO']; + $NextInfoDataPair = $this->fread(5); + if ($this->BonkIsValidTagName(substr($NextInfoDataPair, 1, 4))) { + $this->fseek(-5, SEEK_CUR); + break; + } + $thisfile_bonk_INFO['entries_count']++; + } + } + break; - $thisfile_bonk_INFO['version'] = getid3_lib::LittleEndian2Int($this->fread(1)); - $thisfile_bonk_INFO['entries_count'] = 0; - $NextInfoDataPair = $this->fread(5); - if (!$this->BonkIsValidTagName(substr($NextInfoDataPair, 1, 4))) { - while (!feof($this->getid3->fp)) { - //$CurrentSeekInfo['offset'] = getid3_lib::LittleEndian2Int(substr($NextInfoDataPair, 0, 4)); - //$CurrentSeekInfo['nextbit'] = getid3_lib::LittleEndian2Int(substr($NextInfoDataPair, 4, 1)); - //$thisfile_bonk_INFO[] = $CurrentSeekInfo; + case 'META': + $BonkData = "\x00".'META'.$this->fread($info['bonk']['META']['size'] - 5); + $info['bonk']['META']['version'] = getid3_lib::LittleEndian2Int(substr($BonkData, 5, 1)); - $NextInfoDataPair = $this->fread(5); - if ($this->BonkIsValidTagName(substr($NextInfoDataPair, 1, 4))) { - $this->fseek(-5, SEEK_CUR); - break; - } - $thisfile_bonk_INFO['entries_count']++; - } - } - break; + $MetaTagEntries = floor(((strlen($BonkData) - 8) - 6) / 8); // BonkData - xxxxmeta - ØMETA + $offset = 6; + for ($i = 0; $i < $MetaTagEntries; $i++) { + $MetaEntryTagName = substr($BonkData, $offset, 4); + $offset += 4; + $MetaEntryTagOffset = getid3_lib::LittleEndian2Int(substr($BonkData, $offset, 4)); + $offset += 4; + $info['bonk']['META']['tags'][$MetaEntryTagName] = $MetaEntryTagOffset; + } + break; - case 'META': - $BonkData = "\x00".'META'.$this->fread($info['bonk']['META']['size'] - 5); - $info['bonk']['META']['version'] = getid3_lib::LittleEndian2Int(substr($BonkData, 5, 1)); + case ' ID3': + $info['audio']['encoder'] = 'Extended BONK v0.9+'; - $MetaTagEntries = floor(((strlen($BonkData) - 8) - 6) / 8); // BonkData - xxxxmeta - ØMETA - $offset = 6; - for ($i = 0; $i < $MetaTagEntries; $i++) { - $MetaEntryTagName = substr($BonkData, $offset, 4); - $offset += 4; - $MetaEntryTagOffset = getid3_lib::LittleEndian2Int(substr($BonkData, $offset, 4)); - $offset += 4; - $info['bonk']['META']['tags'][$MetaEntryTagName] = $MetaEntryTagOffset; - } - break; + // ID3v2 checking is optional + if (class_exists('getid3_id3v2')) { + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_id3v2 = new getid3_id3v2($getid3_temp); + $getid3_id3v2->StartingOffset = $info['bonk'][' ID3']['offset'] + 2; + $info['bonk'][' ID3']['valid'] = $getid3_id3v2->Analyze(); + if ($info['bonk'][' ID3']['valid']) { + $info['id3v2'] = $getid3_temp->info['id3v2']; + } + unset($getid3_temp, $getid3_id3v2); + } + break; - case ' ID3': - $info['audio']['encoder'] = 'Extended BONK v0.9+'; + default: + $this->warning('Unexpected Bonk tag "'.$BonkTagName.'" at offset '.$info['bonk'][$BonkTagName]['offset']); + break; - // ID3v2 checking is optional - if (class_exists('getid3_id3v2')) { - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_id3v2 = new getid3_id3v2($getid3_temp); - $getid3_id3v2->StartingOffset = $info['bonk'][' ID3']['offset'] + 2; - $info['bonk'][' ID3']['valid'] = $getid3_id3v2->Analyze(); - if ($info['bonk'][' ID3']['valid']) { - $info['id3v2'] = $getid3_temp->info['id3v2']; - } - unset($getid3_temp, $getid3_id3v2); - } - break; + } + } - default: - $this->warning('Unexpected Bonk tag "'.$BonkTagName.'" at offset '.$info['bonk'][$BonkTagName]['offset']); - break; - - } - } - - public static function BonkIsValidTagName($PossibleBonkTag, $ignorecase=false) { - static $BonkIsValidTagName = array('BONK', 'INFO', ' ID3', 'META'); - foreach ($BonkIsValidTagName as $validtagname) { - if ($validtagname == $PossibleBonkTag) { - return true; - } elseif ($ignorecase && (strtolower($validtagname) == strtolower($PossibleBonkTag))) { - return true; - } - } - return false; - } + public static function BonkIsValidTagName($PossibleBonkTag, $ignorecase = false) + { + static $BonkIsValidTagName = ['BONK', 'INFO', ' ID3', 'META']; + foreach ($BonkIsValidTagName as $validtagname) { + if ($validtagname == $PossibleBonkTag) { + return true; + } elseif ($ignorecase && (strtolower($validtagname) == strtolower($PossibleBonkTag))) { + return true; + } + } + return false; + } } diff --git a/app/Library/getid3/getid3/module.audio.dsf.php b/app/Library/getid3/getid3/module.audio.dsf.php index 50be37c3..94157369 100644 --- a/app/Library/getid3/getid3/module.audio.dsf.php +++ b/app/Library/getid3/getid3/module.audio.dsf.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -18,116 +19,116 @@ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE_ class getid3_dsf extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $info['fileformat'] = 'dsf'; + $info['audio']['dataformat'] = 'dsf'; + $info['audio']['lossless'] = true; + $info['audio']['bitrate_mode'] = 'cbr'; - $info['fileformat'] = 'dsf'; - $info['audio']['dataformat'] = 'dsf'; - $info['audio']['lossless'] = true; - $info['audio']['bitrate_mode'] = 'cbr'; + $this->fseek($info['avdataoffset']); + $dsfheader = $this->fread(28 + 12); - $this->fseek($info['avdataoffset']); - $dsfheader = $this->fread(28 + 12); + $headeroffset = 0; + $info['dsf']['dsd']['magic'] = substr($dsfheader, $headeroffset, 4); + $headeroffset += 4; + $magic = 'DSD '; + if ($info['dsf']['dsd']['magic'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['dsf']['dsd']['magic']).'"'); + unset($info['fileformat']); + unset($info['audio']); + unset($info['dsf']); - $headeroffset = 0; - $info['dsf']['dsd']['magic'] = substr($dsfheader, $headeroffset, 4); - $headeroffset += 4; - $magic = 'DSD '; - if ($info['dsf']['dsd']['magic'] != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['dsf']['dsd']['magic']).'"'); - unset($info['fileformat']); - unset($info['audio']); - unset($info['dsf']); - return false; - } - $info['dsf']['dsd']['dsd_chunk_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); // should be 28 - $headeroffset += 8; - $info['dsf']['dsd']['dsf_file_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); - $headeroffset += 8; - $info['dsf']['dsd']['meta_chunk_offset'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); - $headeroffset += 8; + return false; + } + $info['dsf']['dsd']['dsd_chunk_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); // should be 28 + $headeroffset += 8; + $info['dsf']['dsd']['dsf_file_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); + $headeroffset += 8; + $info['dsf']['dsd']['meta_chunk_offset'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); + $headeroffset += 8; + $info['dsf']['fmt']['magic'] = substr($dsfheader, $headeroffset, 4); + $headeroffset += 4; + $magic = 'fmt '; + if ($info['dsf']['fmt']['magic'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$headeroffset.', found "'.getid3_lib::PrintHexBytes($info['dsf']['fmt']['magic']).'"'); - $info['dsf']['fmt']['magic'] = substr($dsfheader, $headeroffset, 4); - $headeroffset += 4; - $magic = 'fmt '; - if ($info['dsf']['fmt']['magic'] != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$headeroffset.', found "'.getid3_lib::PrintHexBytes($info['dsf']['fmt']['magic']).'"'); - return false; - } - $info['dsf']['fmt']['fmt_chunk_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); // usually 52 bytes - $headeroffset += 8; - $dsfheader .= $this->fread($info['dsf']['fmt']['fmt_chunk_size'] - 12 + 12); // we have already read the entire DSD chunk, plus 12 bytes of FMT. We now want to read the size of FMT, plus 12 bytes into the next chunk to get magic and size. - if (strlen($dsfheader) != ($info['dsf']['dsd']['dsd_chunk_size'] + $info['dsf']['fmt']['fmt_chunk_size'] + 12)) { - $this->error('Expecting '.($info['dsf']['dsd']['dsd_chunk_size'] + $info['dsf']['fmt']['fmt_chunk_size']).' bytes header, found '.strlen($dsfheader).' bytes'); - return false; - } - $info['dsf']['fmt']['format_version'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); // usually "1" - $headeroffset += 4; - $info['dsf']['fmt']['format_id'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); // usually "0" = "DSD Raw" - $headeroffset += 4; - $info['dsf']['fmt']['channel_type_id'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); - $headeroffset += 4; - $info['dsf']['fmt']['channels'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); - $headeroffset += 4; - $info['dsf']['fmt']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); - $headeroffset += 4; - $info['dsf']['fmt']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); - $headeroffset += 4; - $info['dsf']['fmt']['sample_count'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); - $headeroffset += 8; - $info['dsf']['fmt']['channel_block_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); - $headeroffset += 4; - $info['dsf']['fmt']['reserved'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); // zero-filled - $headeroffset += 4; + return false; + } + $info['dsf']['fmt']['fmt_chunk_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); // usually 52 bytes + $headeroffset += 8; + $dsfheader .= $this->fread($info['dsf']['fmt']['fmt_chunk_size'] - 12 + 12); // we have already read the entire DSD chunk, plus 12 bytes of FMT. We now want to read the size of FMT, plus 12 bytes into the next chunk to get magic and size. + if (strlen($dsfheader) != ($info['dsf']['dsd']['dsd_chunk_size'] + $info['dsf']['fmt']['fmt_chunk_size'] + 12)) { + $this->error('Expecting '.($info['dsf']['dsd']['dsd_chunk_size'] + $info['dsf']['fmt']['fmt_chunk_size']).' bytes header, found '.strlen($dsfheader).' bytes'); + return false; + } + $info['dsf']['fmt']['format_version'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); // usually "1" + $headeroffset += 4; + $info['dsf']['fmt']['format_id'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); // usually "0" = "DSD Raw" + $headeroffset += 4; + $info['dsf']['fmt']['channel_type_id'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); + $headeroffset += 4; + $info['dsf']['fmt']['channels'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); + $headeroffset += 4; + $info['dsf']['fmt']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); + $headeroffset += 4; + $info['dsf']['fmt']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); + $headeroffset += 4; + $info['dsf']['fmt']['sample_count'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); + $headeroffset += 8; + $info['dsf']['fmt']['channel_block_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); + $headeroffset += 4; + $info['dsf']['fmt']['reserved'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); // zero-filled + $headeroffset += 4; - $info['dsf']['data']['magic'] = substr($dsfheader, $headeroffset, 4); - $headeroffset += 4; - $magic = 'data'; - if ($info['dsf']['data']['magic'] != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$headeroffset.', found "'.getid3_lib::PrintHexBytes($info['dsf']['data']['magic']).'"'); - return false; - } - $info['dsf']['data']['data_chunk_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); - $headeroffset += 8; - $info['avdataoffset'] = $headeroffset; - $info['avdataend'] = $info['avdataoffset'] + $info['dsf']['data']['data_chunk_size']; + $info['dsf']['data']['magic'] = substr($dsfheader, $headeroffset, 4); + $headeroffset += 4; + $magic = 'data'; + if ($info['dsf']['data']['magic'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$headeroffset.', found "'.getid3_lib::PrintHexBytes($info['dsf']['data']['magic']).'"'); + return false; + } + $info['dsf']['data']['data_chunk_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); + $headeroffset += 8; + $info['avdataoffset'] = $headeroffset; + $info['avdataend'] = $info['avdataoffset'] + $info['dsf']['data']['data_chunk_size']; - if ($info['dsf']['dsd']['meta_chunk_offset'] > 0) { - $getid3_id3v2 = new getid3_id3v2($this->getid3); - $getid3_id3v2->StartingOffset = $info['dsf']['dsd']['meta_chunk_offset']; - $getid3_id3v2->Analyze(); - unset($getid3_id3v2); - } + if ($info['dsf']['dsd']['meta_chunk_offset'] > 0) { + $getid3_id3v2 = new getid3_id3v2($this->getid3); + $getid3_id3v2->StartingOffset = $info['dsf']['dsd']['meta_chunk_offset']; + $getid3_id3v2->Analyze(); + unset($getid3_id3v2); + } + $info['dsf']['fmt']['channel_type'] = $this->DSFchannelTypeLookup($info['dsf']['fmt']['channel_type_id']); + $info['audio']['channelmode'] = $info['dsf']['fmt']['channel_type']; + $info['audio']['bits_per_sample'] = $info['dsf']['fmt']['bits_per_sample']; + $info['audio']['sample_rate'] = $info['dsf']['fmt']['sample_rate']; + $info['audio']['channels'] = $info['dsf']['fmt']['channels']; + $info['audio']['bitrate'] = $info['audio']['bits_per_sample'] * $info['audio']['sample_rate'] * $info['audio']['channels']; + $info['playtime_seconds'] = ($info['dsf']['data']['data_chunk_size'] * 8) / $info['audio']['bitrate']; - $info['dsf']['fmt']['channel_type'] = $this->DSFchannelTypeLookup($info['dsf']['fmt']['channel_type_id']); - $info['audio']['channelmode'] = $info['dsf']['fmt']['channel_type']; - $info['audio']['bits_per_sample'] = $info['dsf']['fmt']['bits_per_sample']; - $info['audio']['sample_rate'] = $info['dsf']['fmt']['sample_rate']; - $info['audio']['channels'] = $info['dsf']['fmt']['channels']; - $info['audio']['bitrate'] = $info['audio']['bits_per_sample'] * $info['audio']['sample_rate'] * $info['audio']['channels']; - $info['playtime_seconds'] = ($info['dsf']['data']['data_chunk_size'] * 8) / $info['audio']['bitrate']; + return true; + } - return true; - } - - - public static function DSFchannelTypeLookup($channel_type_id) { - static $DSFchannelTypeLookup = array( - // interleaving order: - 1 => 'mono', // 1: Mono - 2 => 'stereo', // 1: Front-Left; 2: Front-Right - 3 => '3-channel', // 1: Front-Left; 2: Front-Right; 3: Center - 4 => 'quad', // 1: Front-Left; 2: Front-Right; 3: Back-Left; 4: Back-Right - 5 => '4-channel', // 1: Front-Left; 2: Front-Right; 3: Center; 4: Low-Frequency - 6 => '5-channel', // 1: Front-Left; 2: Front-Right; 3: Center; 4: Back-Left 5: Back-Right - 7 => '5.1', // 1: Front-Left; 2: Front-Right; 3: Center; 4: Low-Frequency; 5: Back-Left; 6: Back-Right - ); - return (isset($DSFchannelTypeLookup[$channel_type_id]) ? $DSFchannelTypeLookup[$channel_type_id] : ''); - } + public static function DSFchannelTypeLookup($channel_type_id) + { + static $DSFchannelTypeLookup = [ + // interleaving order: + 1 => 'mono', // 1: Mono + 2 => 'stereo', // 1: Front-Left; 2: Front-Right + 3 => '3-channel', // 1: Front-Left; 2: Front-Right; 3: Center + 4 => 'quad', // 1: Front-Left; 2: Front-Right; 3: Back-Left; 4: Back-Right + 5 => '4-channel', // 1: Front-Left; 2: Front-Right; 3: Center; 4: Low-Frequency + 6 => '5-channel', // 1: Front-Left; 2: Front-Right; 3: Center; 4: Back-Left 5: Back-Right + 7 => '5.1', // 1: Front-Left; 2: Front-Right; 3: Center; 4: Low-Frequency; 5: Back-Left; 6: Back-Right + ]; + return isset($DSFchannelTypeLookup[$channel_type_id]) ? $DSFchannelTypeLookup[$channel_type_id] : ''; + } } diff --git a/app/Library/getid3/getid3/module.audio.dss.php b/app/Library/getid3/getid3/module.audio.dss.php index 6bd96682..06580e77 100644 --- a/app/Library/getid3/getid3/module.audio.dss.php +++ b/app/Library/getid3/getid3/module.audio.dss.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,86 +15,90 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_dss extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $DSSheader = $this->fread(1540); - $this->fseek($info['avdataoffset']); - $DSSheader = $this->fread(1540); + if (! preg_match('#^[\\x02-\\x06]ds[s2]#', $DSSheader)) { + $this->error('Expecting "[02-06] 64 73 [73|32]" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($DSSheader, 0, 4)).'"'); - if (!preg_match('#^[\\x02-\\x06]ds[s2]#', $DSSheader)) { - $this->error('Expecting "[02-06] 64 73 [73|32]" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($DSSheader, 0, 4)).'"'); - return false; - } + return false; + } - // some structure information taken from http://cpansearch.perl.org/src/RGIBSON/Audio-DSS-0.02/lib/Audio/DSS.pm - $info['encoding'] = 'ISO-8859-1'; // not certain, but assumed - $info['dss'] = array(); + // some structure information taken from http://cpansearch.perl.org/src/RGIBSON/Audio-DSS-0.02/lib/Audio/DSS.pm + $info['encoding'] = 'ISO-8859-1'; // not certain, but assumed + $info['dss'] = []; - $info['fileformat'] = 'dss'; - $info['mime_type'] = 'audio/x-'.substr($DSSheader, 1, 3); // "audio/x-dss" or "audio/x-ds2" - $info['audio']['dataformat'] = substr($DSSheader, 1, 3); // "dss" or "ds2" - $info['audio']['bitrate_mode'] = 'cbr'; + $info['fileformat'] = 'dss'; + $info['mime_type'] = 'audio/x-'.substr($DSSheader, 1, 3); // "audio/x-dss" or "audio/x-ds2" + $info['audio']['dataformat'] = substr($DSSheader, 1, 3); // "dss" or "ds2" + $info['audio']['bitrate_mode'] = 'cbr'; - $info['dss']['version'] = ord(substr($DSSheader, 0, 1)); - $info['dss']['hardware'] = trim(substr($DSSheader, 12, 16)); // identification string for hardware used to create the file, e.g. "DPM 9600", "DS2400" - $info['dss']['unknown1'] = getid3_lib::LittleEndian2Int(substr($DSSheader, 28, 4)); - // 32-37 = "FE FF FE FF F7 FF" in all the sample files I've seen - $info['dss']['date_create_unix'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 38, 12)); - $info['dss']['date_complete_unix'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 50, 12)); - $info['dss']['playtime_sec'] = intval((substr($DSSheader, 62, 2) * 3600) + (substr($DSSheader, 64, 2) * 60) + substr($DSSheader, 66, 2)); // approximate file playtime in HHMMSS - if ($info['dss']['version'] <= 3) { - $info['dss']['playtime_ms'] = getid3_lib::LittleEndian2Int(substr($DSSheader, 512, 4)); // exact file playtime in milliseconds. Has also been observed at offset 530 in one sample file, with something else (unknown) at offset 512 - $info['dss']['priority'] = ord(substr($DSSheader, 793, 1)); - $info['dss']['comments'] = trim(substr($DSSheader, 798, 100)); - $info['dss']['sample_rate_index'] = ord(substr($DSSheader, 1538, 1)); // this isn't certain, this may or may not be where the sample rate info is stored, but it seems consistent on my small selection of sample files - $info['audio']['sample_rate'] = $this->DSSsampleRateLookup($info['dss']['sample_rate_index']); - } else { - $this->getid3->warning('DSS above version 3 not fully supported in this version of getID3. Any additional documentation or format specifications would be welcome. This file is version '.$info['dss']['version']); - } + $info['dss']['version'] = ord(substr($DSSheader, 0, 1)); + $info['dss']['hardware'] = trim(substr($DSSheader, 12, 16)); // identification string for hardware used to create the file, e.g. "DPM 9600", "DS2400" + $info['dss']['unknown1'] = getid3_lib::LittleEndian2Int(substr($DSSheader, 28, 4)); + // 32-37 = "FE FF FE FF F7 FF" in all the sample files I've seen + $info['dss']['date_create_unix'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 38, 12)); + $info['dss']['date_complete_unix'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 50, 12)); + $info['dss']['playtime_sec'] = intval((substr($DSSheader, 62, 2) * 3600) + (substr($DSSheader, 64, 2) * 60) + substr($DSSheader, 66, 2)); // approximate file playtime in HHMMSS + if ($info['dss']['version'] <= 3) { + $info['dss']['playtime_ms'] = getid3_lib::LittleEndian2Int(substr($DSSheader, 512, 4)); // exact file playtime in milliseconds. Has also been observed at offset 530 in one sample file, with something else (unknown) at offset 512 + $info['dss']['priority'] = ord(substr($DSSheader, 793, 1)); + $info['dss']['comments'] = trim(substr($DSSheader, 798, 100)); + $info['dss']['sample_rate_index'] = ord(substr($DSSheader, 1538, 1)); // this isn't certain, this may or may not be where the sample rate info is stored, but it seems consistent on my small selection of sample files + $info['audio']['sample_rate'] = $this->DSSsampleRateLookup($info['dss']['sample_rate_index']); + } else { + $this->getid3->warning('DSS above version 3 not fully supported in this version of getID3. Any additional documentation or format specifications would be welcome. This file is version '.$info['dss']['version']); + } - $info['audio']['bits_per_sample'] = 16; // maybe, maybe not -- most compressed audio formats don't have a fixed bits-per-sample value, but this is a reasonable approximation - $info['audio']['channels'] = 1; + $info['audio']['bits_per_sample'] = 16; // maybe, maybe not -- most compressed audio formats don't have a fixed bits-per-sample value, but this is a reasonable approximation + $info['audio']['channels'] = 1; - if (!empty($info['dss']['playtime_ms']) && (floor($info['dss']['playtime_ms'] / 1000) == $info['dss']['playtime_sec'])) { // *should* just be playtime_ms / 1000 but at least one sample file has playtime_ms at offset 530 instead of offset 512, so safety check - $info['playtime_seconds'] = $info['dss']['playtime_ms'] / 1000; - } else { - $info['playtime_seconds'] = $info['dss']['playtime_sec']; - if (!empty($info['dss']['playtime_ms'])) { - $this->getid3->warning('playtime_ms ('.number_format($info['dss']['playtime_ms'] / 1000, 3).') does not match playtime_sec ('.number_format($info['dss']['playtime_sec']).') - using playtime_sec value'); - } - } - $info['audio']['bitrate'] = ($info['filesize'] * 8) / $info['playtime_seconds']; + if (! empty($info['dss']['playtime_ms']) && (floor($info['dss']['playtime_ms'] / 1000) == $info['dss']['playtime_sec'])) { // *should* just be playtime_ms / 1000 but at least one sample file has playtime_ms at offset 530 instead of offset 512, so safety check + $info['playtime_seconds'] = $info['dss']['playtime_ms'] / 1000; + } else { + $info['playtime_seconds'] = $info['dss']['playtime_sec']; + if (! empty($info['dss']['playtime_ms'])) { + $this->getid3->warning('playtime_ms ('.number_format($info['dss']['playtime_ms'] / 1000, 3).') does not match playtime_sec ('.number_format($info['dss']['playtime_sec']).') - using playtime_sec value'); + } + } + $info['audio']['bitrate'] = ($info['filesize'] * 8) / $info['playtime_seconds']; - return true; - } + return true; + } - public function DSSdateStringToUnixDate($datestring) { - $y = substr($datestring, 0, 2); - $m = substr($datestring, 2, 2); - $d = substr($datestring, 4, 2); - $h = substr($datestring, 6, 2); - $i = substr($datestring, 8, 2); - $s = substr($datestring, 10, 2); - $y += (($y < 95) ? 2000 : 1900); - return mktime($h, $i, $s, $m, $d, $y); - } + public function DSSdateStringToUnixDate($datestring) + { + $y = substr($datestring, 0, 2); + $m = substr($datestring, 2, 2); + $d = substr($datestring, 4, 2); + $h = substr($datestring, 6, 2); + $i = substr($datestring, 8, 2); + $s = substr($datestring, 10, 2); + $y += (($y < 95) ? 2000 : 1900); - public function DSSsampleRateLookup($sample_rate_index) { - static $dssSampleRateLookup = array( - 0x0A => 16000, - 0x0C => 11025, - 0x0D => 12000, - 0x15 => 8000, - ); - if (!array_key_exists($sample_rate_index, $dssSampleRateLookup)) { - $this->getid3->warning('unknown sample_rate_index: 0x'.strtoupper(dechex($sample_rate_index))); - return false; - } - return $dssSampleRateLookup[$sample_rate_index]; - } + return mktime($h, $i, $s, $m, $d, $y); + } + public function DSSsampleRateLookup($sample_rate_index) + { + static $dssSampleRateLookup = [ + 0x0A => 16000, + 0x0C => 11025, + 0x0D => 12000, + 0x15 => 8000, + ]; + if (! array_key_exists($sample_rate_index, $dssSampleRateLookup)) { + $this->getid3->warning('unknown sample_rate_index: 0x'.strtoupper(dechex($sample_rate_index))); + + return false; + } + + return $dssSampleRateLookup[$sample_rate_index]; + } } diff --git a/app/Library/getid3/getid3/module.audio.dts.php b/app/Library/getid3/getid3/module.audio.dts.php index bdc78f0b..13e0c2b4 100644 --- a/app/Library/getid3/getid3/module.audio.dts.php +++ b/app/Library/getid3/getid3/module.audio.dts.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,278 +15,286 @@ // // ///////////////////////////////////////////////////////////////// - /** -* @tutorial http://wiki.multimedia.cx/index.php?title=DTS -*/ + * @tutorial http://wiki.multimedia.cx/index.php?title=DTS + */ class getid3_dts extends getid3_handler { - /** - * Default DTS syncword used in native .cpt or .dts formats - */ + /** + * Default DTS syncword used in native .cpt or .dts formats. + */ const syncword = "\x7F\xFE\x80\x01"; - private $readBinDataOffset = 0; + private $readBinDataOffset = 0; /** - * Possible syncwords indicating bitstream encoding - */ - public static $syncwords = array( - 0 => "\x7F\xFE\x80\x01", // raw big-endian - 1 => "\xFE\x7F\x01\x80", // raw little-endian - 2 => "\x1F\xFF\xE8\x00", // 14-bit big-endian - 3 => "\xFF\x1F\x00\xE8"); // 14-bit little-endian + * Possible syncwords indicating bitstream encoding. + */ + public static $syncwords = [ + 0 => "\x7F\xFE\x80\x01", // raw big-endian + 1 => "\xFE\x7F\x01\x80", // raw little-endian + 2 => "\x1F\xFF\xE8\x00", // 14-bit big-endian + 3 => "\xFF\x1F\x00\xE8", ]; // 14-bit little-endian - public function Analyze() { - $info = &$this->getid3->info; - $info['fileformat'] = 'dts'; + public function Analyze() + { + $info = &$this->getid3->info; + $info['fileformat'] = 'dts'; - $this->fseek($info['avdataoffset']); - $DTSheader = $this->fread(20); // we only need 2 words magic + 6 words frame header, but these words may be normal 16-bit words OR 14-bit words with 2 highest bits set to zero, so 8 words can be either 8*16/8 = 16 bytes OR 8*16*(16/14)/8 = 18.3 bytes + $this->fseek($info['avdataoffset']); + $DTSheader = $this->fread(20); // we only need 2 words magic + 6 words frame header, but these words may be normal 16-bit words OR 14-bit words with 2 highest bits set to zero, so 8 words can be either 8*16/8 = 16 bytes OR 8*16*(16/14)/8 = 18.3 bytes - // check syncword - $sync = substr($DTSheader, 0, 4); + // check syncword + $sync = substr($DTSheader, 0, 4); if (($encoding = array_search($sync, self::$syncwords)) !== false) { - - $info['dts']['raw']['magic'] = $sync; - $this->readBinDataOffset = 32; - + $info['dts']['raw']['magic'] = $sync; + $this->readBinDataOffset = 32; } elseif ($this->isDependencyFor('matroska')) { - // Matroska contains DTS without syncword encoded as raw big-endian format - $encoding = 0; - $this->readBinDataOffset = 0; - + // Matroska contains DTS without syncword encoded as raw big-endian format + $encoding = 0; + $this->readBinDataOffset = 0; } else { + unset($info['fileformat']); - unset($info['fileformat']); - return $this->error('Expecting "'.implode('| ', array_map('getid3_lib::PrintHexBytes', self::$syncwords)).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($sync).'"'); + return $this->error('Expecting "'.implode('| ', array_map('getid3_lib::PrintHexBytes', self::$syncwords)).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($sync).'"'); + } - } + // decode header + $fhBS = ''; + for ($word_offset = 0; $word_offset <= strlen($DTSheader); $word_offset += 2) { + switch ($encoding) { + case 0: // raw big-endian + $fhBS .= getid3_lib::BigEndian2Bin(substr($DTSheader, $word_offset, 2)); + break; + case 1: // raw little-endian + $fhBS .= getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2))); + break; + case 2: // 14-bit big-endian + $fhBS .= substr(getid3_lib::BigEndian2Bin(substr($DTSheader, $word_offset, 2)), 2, 14); + break; + case 3: // 14-bit little-endian + $fhBS .= substr(getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2))), 2, 14); + break; + } + } - // decode header - $fhBS = ''; - for ($word_offset = 0; $word_offset <= strlen($DTSheader); $word_offset += 2) { - switch ($encoding) { - case 0: // raw big-endian - $fhBS .= getid3_lib::BigEndian2Bin( substr($DTSheader, $word_offset, 2) ); - break; - case 1: // raw little-endian - $fhBS .= getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2))); - break; - case 2: // 14-bit big-endian - $fhBS .= substr(getid3_lib::BigEndian2Bin( substr($DTSheader, $word_offset, 2) ), 2, 14); - break; - case 3: // 14-bit little-endian - $fhBS .= substr(getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2))), 2, 14); - break; - } - } + $info['dts']['raw']['frame_type'] = $this->readBinData($fhBS, 1); + $info['dts']['raw']['deficit_samples'] = $this->readBinData($fhBS, 5); + $info['dts']['flags']['crc_present'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['raw']['pcm_sample_blocks'] = $this->readBinData($fhBS, 7); + $info['dts']['raw']['frame_byte_size'] = $this->readBinData($fhBS, 14); + $info['dts']['raw']['channel_arrangement'] = $this->readBinData($fhBS, 6); + $info['dts']['raw']['sample_frequency'] = $this->readBinData($fhBS, 4); + $info['dts']['raw']['bitrate'] = $this->readBinData($fhBS, 5); + $info['dts']['flags']['embedded_downmix'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['flags']['dynamicrange'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['flags']['timestamp'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['flags']['auxdata'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['flags']['hdcd'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['raw']['extension_audio'] = $this->readBinData($fhBS, 3); + $info['dts']['flags']['extended_coding'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['flags']['audio_sync_insertion'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['raw']['lfe_effects'] = $this->readBinData($fhBS, 2); + $info['dts']['flags']['predictor_history'] = (bool) $this->readBinData($fhBS, 1); + if ($info['dts']['flags']['crc_present']) { + $info['dts']['raw']['crc16'] = $this->readBinData($fhBS, 16); + } + $info['dts']['flags']['mri_perfect_reconst'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['raw']['encoder_soft_version'] = $this->readBinData($fhBS, 4); + $info['dts']['raw']['copy_history'] = $this->readBinData($fhBS, 2); + $info['dts']['raw']['bits_per_sample'] = $this->readBinData($fhBS, 2); + $info['dts']['flags']['surround_es'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['flags']['front_sum_diff'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['flags']['surround_sum_diff'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['raw']['dialog_normalization'] = $this->readBinData($fhBS, 4); - $info['dts']['raw']['frame_type'] = $this->readBinData($fhBS, 1); - $info['dts']['raw']['deficit_samples'] = $this->readBinData($fhBS, 5); - $info['dts']['flags']['crc_present'] = (bool) $this->readBinData($fhBS, 1); - $info['dts']['raw']['pcm_sample_blocks'] = $this->readBinData($fhBS, 7); - $info['dts']['raw']['frame_byte_size'] = $this->readBinData($fhBS, 14); - $info['dts']['raw']['channel_arrangement'] = $this->readBinData($fhBS, 6); - $info['dts']['raw']['sample_frequency'] = $this->readBinData($fhBS, 4); - $info['dts']['raw']['bitrate'] = $this->readBinData($fhBS, 5); - $info['dts']['flags']['embedded_downmix'] = (bool) $this->readBinData($fhBS, 1); - $info['dts']['flags']['dynamicrange'] = (bool) $this->readBinData($fhBS, 1); - $info['dts']['flags']['timestamp'] = (bool) $this->readBinData($fhBS, 1); - $info['dts']['flags']['auxdata'] = (bool) $this->readBinData($fhBS, 1); - $info['dts']['flags']['hdcd'] = (bool) $this->readBinData($fhBS, 1); - $info['dts']['raw']['extension_audio'] = $this->readBinData($fhBS, 3); - $info['dts']['flags']['extended_coding'] = (bool) $this->readBinData($fhBS, 1); - $info['dts']['flags']['audio_sync_insertion'] = (bool) $this->readBinData($fhBS, 1); - $info['dts']['raw']['lfe_effects'] = $this->readBinData($fhBS, 2); - $info['dts']['flags']['predictor_history'] = (bool) $this->readBinData($fhBS, 1); - if ($info['dts']['flags']['crc_present']) { - $info['dts']['raw']['crc16'] = $this->readBinData($fhBS, 16); - } - $info['dts']['flags']['mri_perfect_reconst'] = (bool) $this->readBinData($fhBS, 1); - $info['dts']['raw']['encoder_soft_version'] = $this->readBinData($fhBS, 4); - $info['dts']['raw']['copy_history'] = $this->readBinData($fhBS, 2); - $info['dts']['raw']['bits_per_sample'] = $this->readBinData($fhBS, 2); - $info['dts']['flags']['surround_es'] = (bool) $this->readBinData($fhBS, 1); - $info['dts']['flags']['front_sum_diff'] = (bool) $this->readBinData($fhBS, 1); - $info['dts']['flags']['surround_sum_diff'] = (bool) $this->readBinData($fhBS, 1); - $info['dts']['raw']['dialog_normalization'] = $this->readBinData($fhBS, 4); + $info['dts']['bitrate'] = self::bitrateLookup($info['dts']['raw']['bitrate']); + $info['dts']['bits_per_sample'] = self::bitPerSampleLookup($info['dts']['raw']['bits_per_sample']); + $info['dts']['sample_rate'] = self::sampleRateLookup($info['dts']['raw']['sample_frequency']); + $info['dts']['dialog_normalization'] = self::dialogNormalization($info['dts']['raw']['dialog_normalization'], $info['dts']['raw']['encoder_soft_version']); + $info['dts']['flags']['lossless'] = (($info['dts']['raw']['bitrate'] == 31) ? true : false); + $info['dts']['bitrate_mode'] = (($info['dts']['raw']['bitrate'] == 30) ? 'vbr' : 'cbr'); + $info['dts']['channels'] = self::numChannelsLookup($info['dts']['raw']['channel_arrangement']); + $info['dts']['channel_arrangement'] = self::channelArrangementLookup($info['dts']['raw']['channel_arrangement']); + $info['audio']['dataformat'] = 'dts'; + $info['audio']['lossless'] = $info['dts']['flags']['lossless']; + $info['audio']['bitrate_mode'] = $info['dts']['bitrate_mode']; + $info['audio']['bits_per_sample'] = $info['dts']['bits_per_sample']; + $info['audio']['sample_rate'] = $info['dts']['sample_rate']; + $info['audio']['channels'] = $info['dts']['channels']; + $info['audio']['bitrate'] = $info['dts']['bitrate']; + if (isset($info['avdataend']) && ! empty($info['dts']['bitrate']) && is_numeric($info['dts']['bitrate'])) { + $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($info['dts']['bitrate'] / 8); + if (($encoding == 2) || ($encoding == 3)) { + // 14-bit data packed into 16-bit words, so the playtime is wrong because only (14/16) of the bytes in the data portion of the file are used at the specified bitrate + $info['playtime_seconds'] *= (14 / 16); + } + } - $info['dts']['bitrate'] = self::bitrateLookup($info['dts']['raw']['bitrate']); - $info['dts']['bits_per_sample'] = self::bitPerSampleLookup($info['dts']['raw']['bits_per_sample']); - $info['dts']['sample_rate'] = self::sampleRateLookup($info['dts']['raw']['sample_frequency']); - $info['dts']['dialog_normalization'] = self::dialogNormalization($info['dts']['raw']['dialog_normalization'], $info['dts']['raw']['encoder_soft_version']); - $info['dts']['flags']['lossless'] = (($info['dts']['raw']['bitrate'] == 31) ? true : false); - $info['dts']['bitrate_mode'] = (($info['dts']['raw']['bitrate'] == 30) ? 'vbr' : 'cbr'); - $info['dts']['channels'] = self::numChannelsLookup($info['dts']['raw']['channel_arrangement']); - $info['dts']['channel_arrangement'] = self::channelArrangementLookup($info['dts']['raw']['channel_arrangement']); + return true; + } - $info['audio']['dataformat'] = 'dts'; - $info['audio']['lossless'] = $info['dts']['flags']['lossless']; - $info['audio']['bitrate_mode'] = $info['dts']['bitrate_mode']; - $info['audio']['bits_per_sample'] = $info['dts']['bits_per_sample']; - $info['audio']['sample_rate'] = $info['dts']['sample_rate']; - $info['audio']['channels'] = $info['dts']['channels']; - $info['audio']['bitrate'] = $info['dts']['bitrate']; - if (isset($info['avdataend']) && !empty($info['dts']['bitrate']) && is_numeric($info['dts']['bitrate'])) { - $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($info['dts']['bitrate'] / 8); - if (($encoding == 2) || ($encoding == 3)) { - // 14-bit data packed into 16-bit words, so the playtime is wrong because only (14/16) of the bytes in the data portion of the file are used at the specified bitrate - $info['playtime_seconds'] *= (14 / 16); - } - } - return true; - } + private function readBinData($bin, $length) + { + $data = substr($bin, $this->readBinDataOffset, $length); + $this->readBinDataOffset += $length; - private function readBinData($bin, $length) { - $data = substr($bin, $this->readBinDataOffset, $length); - $this->readBinDataOffset += $length; + return bindec($data); + } - return bindec($data); - } + public static function bitrateLookup($index) + { + static $lookup = [ + 0 => 32000, + 1 => 56000, + 2 => 64000, + 3 => 96000, + 4 => 112000, + 5 => 128000, + 6 => 192000, + 7 => 224000, + 8 => 256000, + 9 => 320000, + 10 => 384000, + 11 => 448000, + 12 => 512000, + 13 => 576000, + 14 => 640000, + 15 => 768000, + 16 => 960000, + 17 => 1024000, + 18 => 1152000, + 19 => 1280000, + 20 => 1344000, + 21 => 1408000, + 22 => 1411200, + 23 => 1472000, + 24 => 1536000, + 25 => 1920000, + 26 => 2048000, + 27 => 3072000, + 28 => 3840000, + 29 => 'open', + 30 => 'variable', + 31 => 'lossless', + ]; - public static function bitrateLookup($index) { - static $lookup = array( - 0 => 32000, - 1 => 56000, - 2 => 64000, - 3 => 96000, - 4 => 112000, - 5 => 128000, - 6 => 192000, - 7 => 224000, - 8 => 256000, - 9 => 320000, - 10 => 384000, - 11 => 448000, - 12 => 512000, - 13 => 576000, - 14 => 640000, - 15 => 768000, - 16 => 960000, - 17 => 1024000, - 18 => 1152000, - 19 => 1280000, - 20 => 1344000, - 21 => 1408000, - 22 => 1411200, - 23 => 1472000, - 24 => 1536000, - 25 => 1920000, - 26 => 2048000, - 27 => 3072000, - 28 => 3840000, - 29 => 'open', - 30 => 'variable', - 31 => 'lossless', - ); - return (isset($lookup[$index]) ? $lookup[$index] : false); - } + return isset($lookup[$index]) ? $lookup[$index] : false; + } - public static function sampleRateLookup($index) { - static $lookup = array( - 0 => 'invalid', - 1 => 8000, - 2 => 16000, - 3 => 32000, - 4 => 'invalid', - 5 => 'invalid', - 6 => 11025, - 7 => 22050, - 8 => 44100, - 9 => 'invalid', - 10 => 'invalid', - 11 => 12000, - 12 => 24000, - 13 => 48000, - 14 => 'invalid', - 15 => 'invalid', - ); - return (isset($lookup[$index]) ? $lookup[$index] : false); - } + public static function sampleRateLookup($index) + { + static $lookup = [ + 0 => 'invalid', + 1 => 8000, + 2 => 16000, + 3 => 32000, + 4 => 'invalid', + 5 => 'invalid', + 6 => 11025, + 7 => 22050, + 8 => 44100, + 9 => 'invalid', + 10 => 'invalid', + 11 => 12000, + 12 => 24000, + 13 => 48000, + 14 => 'invalid', + 15 => 'invalid', + ]; - public static function bitPerSampleLookup($index) { - static $lookup = array( - 0 => 16, - 1 => 20, - 2 => 24, - 3 => 24, - ); - return (isset($lookup[$index]) ? $lookup[$index] : false); - } + return isset($lookup[$index]) ? $lookup[$index] : false; + } - public static function numChannelsLookup($index) { - switch ($index) { - case 0: - return 1; - break; - case 1: - case 2: - case 3: - case 4: - return 2; - break; - case 5: - case 6: - return 3; - break; - case 7: - case 8: - return 4; - break; - case 9: - return 5; - break; - case 10: - case 11: - case 12: - return 6; - break; - case 13: - return 7; - break; - case 14: - case 15: - return 8; - break; - } - return false; - } + public static function bitPerSampleLookup($index) + { + static $lookup = [ + 0 => 16, + 1 => 20, + 2 => 24, + 3 => 24, + ]; - public static function channelArrangementLookup($index) { - static $lookup = array( - 0 => 'A', - 1 => 'A + B (dual mono)', - 2 => 'L + R (stereo)', - 3 => '(L+R) + (L-R) (sum-difference)', - 4 => 'LT + RT (left and right total)', - 5 => 'C + L + R', - 6 => 'L + R + S', - 7 => 'C + L + R + S', - 8 => 'L + R + SL + SR', - 9 => 'C + L + R + SL + SR', - 10 => 'CL + CR + L + R + SL + SR', - 11 => 'C + L + R+ LR + RR + OV', - 12 => 'CF + CR + LF + RF + LR + RR', - 13 => 'CL + C + CR + L + R + SL + SR', - 14 => 'CL + CR + L + R + SL1 + SL2 + SR1 + SR2', - 15 => 'CL + C+ CR + L + R + SL + S + SR', - ); - return (isset($lookup[$index]) ? $lookup[$index] : 'user-defined'); - } + return isset($lookup[$index]) ? $lookup[$index] : false; + } - public static function dialogNormalization($index, $version) { - switch ($version) { - case 7: - return 0 - $index; - break; - case 6: - return 0 - 16 - $index; - break; - } - return false; - } + public static function numChannelsLookup($index) + { + switch ($index) { + case 0: + return 1; + break; + case 1: + case 2: + case 3: + case 4: + return 2; + break; + case 5: + case 6: + return 3; + break; + case 7: + case 8: + return 4; + break; + case 9: + return 5; + break; + case 10: + case 11: + case 12: + return 6; + break; + case 13: + return 7; + break; + case 14: + case 15: + return 8; + break; + } + return false; + } + + public static function channelArrangementLookup($index) + { + static $lookup = [ + 0 => 'A', + 1 => 'A + B (dual mono)', + 2 => 'L + R (stereo)', + 3 => '(L+R) + (L-R) (sum-difference)', + 4 => 'LT + RT (left and right total)', + 5 => 'C + L + R', + 6 => 'L + R + S', + 7 => 'C + L + R + S', + 8 => 'L + R + SL + SR', + 9 => 'C + L + R + SL + SR', + 10 => 'CL + CR + L + R + SL + SR', + 11 => 'C + L + R+ LR + RR + OV', + 12 => 'CF + CR + LF + RF + LR + RR', + 13 => 'CL + C + CR + L + R + SL + SR', + 14 => 'CL + CR + L + R + SL1 + SL2 + SR1 + SR2', + 15 => 'CL + C+ CR + L + R + SL + S + SR', + ]; + + return isset($lookup[$index]) ? $lookup[$index] : 'user-defined'; + } + + public static function dialogNormalization($index, $version) + { + switch ($version) { + case 7: + return 0 - $index; + break; + case 6: + return 0 - 16 - $index; + break; + } + + return false; + } } diff --git a/app/Library/getid3/getid3/module.audio.flac.php b/app/Library/getid3/getid3/module.audio.flac.php index 348cce32..9c42a75e 100644 --- a/app/Library/getid3/getid3/module.audio.flac.php +++ b/app/Library/getid3/getid3/module.audio.flac.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,440 +15,443 @@ // /// ///////////////////////////////////////////////////////////////// - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, true); /** -* @tutorial http://flac.sourceforge.net/format.html -*/ + * @tutorial http://flac.sourceforge.net/format.html + */ class getid3_flac extends getid3_handler { - const syncword = 'fLaC'; + const syncword = 'fLaC'; - public function Analyze() { - $info = &$this->getid3->info; + public function Analyze() + { + $info = &$this->getid3->info; - $this->fseek($info['avdataoffset']); - $StreamMarker = $this->fread(4); - if ($StreamMarker != self::syncword) { - return $this->error('Expecting "'.getid3_lib::PrintHexBytes(self::syncword).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($StreamMarker).'"'); - } - $info['fileformat'] = 'flac'; - $info['audio']['dataformat'] = 'flac'; - $info['audio']['bitrate_mode'] = 'vbr'; - $info['audio']['lossless'] = true; + $this->fseek($info['avdataoffset']); + $StreamMarker = $this->fread(4); + if ($StreamMarker != self::syncword) { + return $this->error('Expecting "'.getid3_lib::PrintHexBytes(self::syncword).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($StreamMarker).'"'); + } + $info['fileformat'] = 'flac'; + $info['audio']['dataformat'] = 'flac'; + $info['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['lossless'] = true; - // parse flac container - return $this->parseMETAdata(); - } + // parse flac container + return $this->parseMETAdata(); + } - public function parseMETAdata() { - $info = &$this->getid3->info; - do { - $BlockOffset = $this->ftell(); - $BlockHeader = $this->fread(4); - $LBFBT = getid3_lib::BigEndian2Int(substr($BlockHeader, 0, 1)); - $LastBlockFlag = (bool) ($LBFBT & 0x80); - $BlockType = ($LBFBT & 0x7F); - $BlockLength = getid3_lib::BigEndian2Int(substr($BlockHeader, 1, 3)); - $BlockTypeText = self::metaBlockTypeLookup($BlockType); + public function parseMETAdata() + { + $info = &$this->getid3->info; + do { + $BlockOffset = $this->ftell(); + $BlockHeader = $this->fread(4); + $LBFBT = getid3_lib::BigEndian2Int(substr($BlockHeader, 0, 1)); + $LastBlockFlag = (bool) ($LBFBT & 0x80); + $BlockType = ($LBFBT & 0x7F); + $BlockLength = getid3_lib::BigEndian2Int(substr($BlockHeader, 1, 3)); + $BlockTypeText = self::metaBlockTypeLookup($BlockType); - if (($BlockOffset + 4 + $BlockLength) > $info['avdataend']) { - $this->error('METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$BlockTypeText.') at offset '.$BlockOffset.' extends beyond end of file'); - break; - } - if ($BlockLength < 1) { - $this->error('METADATA_BLOCK_HEADER.BLOCK_LENGTH ('.$BlockLength.') at offset '.$BlockOffset.' is invalid'); - break; - } + if (($BlockOffset + 4 + $BlockLength) > $info['avdataend']) { + $this->error('METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$BlockTypeText.') at offset '.$BlockOffset.' extends beyond end of file'); + break; + } + if ($BlockLength < 1) { + $this->error('METADATA_BLOCK_HEADER.BLOCK_LENGTH ('.$BlockLength.') at offset '.$BlockOffset.' is invalid'); + break; + } - $info['flac'][$BlockTypeText]['raw'] = array(); - $BlockTypeText_raw = &$info['flac'][$BlockTypeText]['raw']; + $info['flac'][$BlockTypeText]['raw'] = []; + $BlockTypeText_raw = &$info['flac'][$BlockTypeText]['raw']; - $BlockTypeText_raw['offset'] = $BlockOffset; - $BlockTypeText_raw['last_meta_block'] = $LastBlockFlag; - $BlockTypeText_raw['block_type'] = $BlockType; - $BlockTypeText_raw['block_type_text'] = $BlockTypeText; - $BlockTypeText_raw['block_length'] = $BlockLength; - if ($BlockTypeText_raw['block_type'] != 0x06) { // do not read attachment data automatically - $BlockTypeText_raw['block_data'] = $this->fread($BlockLength); - } + $BlockTypeText_raw['offset'] = $BlockOffset; + $BlockTypeText_raw['last_meta_block'] = $LastBlockFlag; + $BlockTypeText_raw['block_type'] = $BlockType; + $BlockTypeText_raw['block_type_text'] = $BlockTypeText; + $BlockTypeText_raw['block_length'] = $BlockLength; + if ($BlockTypeText_raw['block_type'] != 0x06) { // do not read attachment data automatically + $BlockTypeText_raw['block_data'] = $this->fread($BlockLength); + } - switch ($BlockTypeText) { - case 'STREAMINFO': // 0x00 - if (!$this->parseSTREAMINFO($BlockTypeText_raw['block_data'])) { - return false; - } - break; + switch ($BlockTypeText) { + case 'STREAMINFO': // 0x00 + if (! $this->parseSTREAMINFO($BlockTypeText_raw['block_data'])) { + return false; + } + break; - case 'PADDING': // 0x01 - unset($info['flac']['PADDING']); // ignore - break; + case 'PADDING': // 0x01 + unset($info['flac']['PADDING']); // ignore + break; - case 'APPLICATION': // 0x02 - if (!$this->parseAPPLICATION($BlockTypeText_raw['block_data'])) { - return false; - } - break; + case 'APPLICATION': // 0x02 + if (! $this->parseAPPLICATION($BlockTypeText_raw['block_data'])) { + return false; + } + break; - case 'SEEKTABLE': // 0x03 - if (!$this->parseSEEKTABLE($BlockTypeText_raw['block_data'])) { - return false; - } - break; + case 'SEEKTABLE': // 0x03 + if (! $this->parseSEEKTABLE($BlockTypeText_raw['block_data'])) { + return false; + } + break; - case 'VORBIS_COMMENT': // 0x04 - if (!$this->parseVORBIS_COMMENT($BlockTypeText_raw['block_data'])) { - return false; - } - break; + case 'VORBIS_COMMENT': // 0x04 + if (! $this->parseVORBIS_COMMENT($BlockTypeText_raw['block_data'])) { + return false; + } + break; - case 'CUESHEET': // 0x05 - if (!$this->parseCUESHEET($BlockTypeText_raw['block_data'])) { - return false; - } - break; + case 'CUESHEET': // 0x05 + if (! $this->parseCUESHEET($BlockTypeText_raw['block_data'])) { + return false; + } + break; - case 'PICTURE': // 0x06 - if (!$this->parsePICTURE()) { - return false; - } - break; + case 'PICTURE': // 0x06 + if (! $this->parsePICTURE()) { + return false; + } + break; - default: - $this->warning('Unhandled METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$BlockType.') at offset '.$BlockOffset); - } + default: + $this->warning('Unhandled METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$BlockType.') at offset '.$BlockOffset); + } - unset($info['flac'][$BlockTypeText]['raw']); - $info['avdataoffset'] = $this->ftell(); - } - while ($LastBlockFlag === false); + unset($info['flac'][$BlockTypeText]['raw']); + $info['avdataoffset'] = $this->ftell(); + } while ($LastBlockFlag === false); - // handle tags - if (!empty($info['flac']['VORBIS_COMMENT']['comments'])) { - $info['flac']['comments'] = $info['flac']['VORBIS_COMMENT']['comments']; - } - if (!empty($info['flac']['VORBIS_COMMENT']['vendor'])) { - $info['audio']['encoder'] = str_replace('reference ', '', $info['flac']['VORBIS_COMMENT']['vendor']); - } + // handle tags + if (! empty($info['flac']['VORBIS_COMMENT']['comments'])) { + $info['flac']['comments'] = $info['flac']['VORBIS_COMMENT']['comments']; + } + if (! empty($info['flac']['VORBIS_COMMENT']['vendor'])) { + $info['audio']['encoder'] = str_replace('reference ', '', $info['flac']['VORBIS_COMMENT']['vendor']); + } - // copy attachments to 'comments' array if nesesary - if (isset($info['flac']['PICTURE']) && ($this->getid3->option_save_attachments !== getID3::ATTACHMENTS_NONE)) { - foreach ($info['flac']['PICTURE'] as $entry) { - if (!empty($entry['data'])) { - if (!isset($info['flac']['comments']['picture'])) { - $info['flac']['comments']['picture'] = array(); - } - $comments_picture_data = array(); - foreach (array('data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength') as $picture_key) { - if (isset($entry[$picture_key])) { - $comments_picture_data[$picture_key] = $entry[$picture_key]; - } - } - $info['flac']['comments']['picture'][] = $comments_picture_data; - unset($comments_picture_data); - } - } - } + // copy attachments to 'comments' array if nesesary + if (isset($info['flac']['PICTURE']) && ($this->getid3->option_save_attachments !== getID3::ATTACHMENTS_NONE)) { + foreach ($info['flac']['PICTURE'] as $entry) { + if (! empty($entry['data'])) { + if (! isset($info['flac']['comments']['picture'])) { + $info['flac']['comments']['picture'] = []; + } + $comments_picture_data = []; + foreach (['data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength'] as $picture_key) { + if (isset($entry[$picture_key])) { + $comments_picture_data[$picture_key] = $entry[$picture_key]; + } + } + $info['flac']['comments']['picture'][] = $comments_picture_data; + unset($comments_picture_data); + } + } + } - if (isset($info['flac']['STREAMINFO'])) { - if (!$this->isDependencyFor('matroska')) { - $info['flac']['compressed_audio_bytes'] = $info['avdataend'] - $info['avdataoffset']; - } - $info['flac']['uncompressed_audio_bytes'] = $info['flac']['STREAMINFO']['samples_stream'] * $info['flac']['STREAMINFO']['channels'] * ($info['flac']['STREAMINFO']['bits_per_sample'] / 8); - if ($info['flac']['uncompressed_audio_bytes'] == 0) { - return $this->error('Corrupt FLAC file: uncompressed_audio_bytes == zero'); - } - if (!empty($info['flac']['compressed_audio_bytes'])) { - $info['flac']['compression_ratio'] = $info['flac']['compressed_audio_bytes'] / $info['flac']['uncompressed_audio_bytes']; - } - } + if (isset($info['flac']['STREAMINFO'])) { + if (! $this->isDependencyFor('matroska')) { + $info['flac']['compressed_audio_bytes'] = $info['avdataend'] - $info['avdataoffset']; + } + $info['flac']['uncompressed_audio_bytes'] = $info['flac']['STREAMINFO']['samples_stream'] * $info['flac']['STREAMINFO']['channels'] * ($info['flac']['STREAMINFO']['bits_per_sample'] / 8); + if ($info['flac']['uncompressed_audio_bytes'] == 0) { + return $this->error('Corrupt FLAC file: uncompressed_audio_bytes == zero'); + } + if (! empty($info['flac']['compressed_audio_bytes'])) { + $info['flac']['compression_ratio'] = $info['flac']['compressed_audio_bytes'] / $info['flac']['uncompressed_audio_bytes']; + } + } - // set md5_data_source - built into flac 0.5+ - if (isset($info['flac']['STREAMINFO']['audio_signature'])) { - - if ($info['flac']['STREAMINFO']['audio_signature'] === str_repeat("\x00", 16)) { + // set md5_data_source - built into flac 0.5+ + if (isset($info['flac']['STREAMINFO']['audio_signature'])) { + if ($info['flac']['STREAMINFO']['audio_signature'] === str_repeat("\x00", 16)) { $this->warning('FLAC STREAMINFO.audio_signature is null (known issue with libOggFLAC)'); - } - else { - $info['md5_data_source'] = ''; - $md5 = $info['flac']['STREAMINFO']['audio_signature']; - for ($i = 0; $i < strlen($md5); $i++) { - $info['md5_data_source'] .= str_pad(dechex(ord($md5[$i])), 2, '00', STR_PAD_LEFT); - } - if (!preg_match('/^[0-9a-f]{32}$/', $info['md5_data_source'])) { - unset($info['md5_data_source']); - } - } - } + } else { + $info['md5_data_source'] = ''; + $md5 = $info['flac']['STREAMINFO']['audio_signature']; + for ($i = 0; $i < strlen($md5); $i++) { + $info['md5_data_source'] .= str_pad(dechex(ord($md5[$i])), 2, '00', STR_PAD_LEFT); + } + if (! preg_match('/^[0-9a-f]{32}$/', $info['md5_data_source'])) { + unset($info['md5_data_source']); + } + } + } - if (isset($info['flac']['STREAMINFO']['bits_per_sample'])) { - $info['audio']['bits_per_sample'] = $info['flac']['STREAMINFO']['bits_per_sample']; - if ($info['audio']['bits_per_sample'] == 8) { - // special case - // must invert sign bit on all data bytes before MD5'ing to match FLAC's calculated value - // MD5sum calculates on unsigned bytes, but FLAC calculated MD5 on 8-bit audio data as signed - $this->warning('FLAC calculates MD5 data strangely on 8-bit audio, so the stored md5_data_source value will not match the decoded WAV file'); - } - } + if (isset($info['flac']['STREAMINFO']['bits_per_sample'])) { + $info['audio']['bits_per_sample'] = $info['flac']['STREAMINFO']['bits_per_sample']; + if ($info['audio']['bits_per_sample'] == 8) { + // special case + // must invert sign bit on all data bytes before MD5'ing to match FLAC's calculated value + // MD5sum calculates on unsigned bytes, but FLAC calculated MD5 on 8-bit audio data as signed + $this->warning('FLAC calculates MD5 data strangely on 8-bit audio, so the stored md5_data_source value will not match the decoded WAV file'); + } + } - return true; - } + return true; + } - private function parseSTREAMINFO($BlockData) { - $info = &$this->getid3->info; + private function parseSTREAMINFO($BlockData) + { + $info = &$this->getid3->info; - $info['flac']['STREAMINFO'] = array(); - $streaminfo = &$info['flac']['STREAMINFO']; + $info['flac']['STREAMINFO'] = []; + $streaminfo = &$info['flac']['STREAMINFO']; - $streaminfo['min_block_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 0, 2)); - $streaminfo['max_block_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 2, 2)); - $streaminfo['min_frame_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 4, 3)); - $streaminfo['max_frame_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 7, 3)); + $streaminfo['min_block_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 0, 2)); + $streaminfo['max_block_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 2, 2)); + $streaminfo['min_frame_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 4, 3)); + $streaminfo['max_frame_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 7, 3)); - $SRCSBSS = getid3_lib::BigEndian2Bin(substr($BlockData, 10, 8)); - $streaminfo['sample_rate'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 0, 20)); - $streaminfo['channels'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 20, 3)) + 1; - $streaminfo['bits_per_sample'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 23, 5)) + 1; - $streaminfo['samples_stream'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 28, 36)); + $SRCSBSS = getid3_lib::BigEndian2Bin(substr($BlockData, 10, 8)); + $streaminfo['sample_rate'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 0, 20)); + $streaminfo['channels'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 20, 3)) + 1; + $streaminfo['bits_per_sample'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 23, 5)) + 1; + $streaminfo['samples_stream'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 28, 36)); - $streaminfo['audio_signature'] = substr($BlockData, 18, 16); + $streaminfo['audio_signature'] = substr($BlockData, 18, 16); - if (!empty($streaminfo['sample_rate'])) { + if (! empty($streaminfo['sample_rate'])) { + $info['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['sample_rate'] = $streaminfo['sample_rate']; + $info['audio']['channels'] = $streaminfo['channels']; + $info['audio']['bits_per_sample'] = $streaminfo['bits_per_sample']; + $info['playtime_seconds'] = $streaminfo['samples_stream'] / $streaminfo['sample_rate']; + if ($info['playtime_seconds'] > 0) { + if (! $this->isDependencyFor('matroska')) { + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + } else { + $this->warning('Cannot determine audio bitrate because total stream size is unknown'); + } + } + } else { + return $this->error('Corrupt METAdata block: STREAMINFO'); + } - $info['audio']['bitrate_mode'] = 'vbr'; - $info['audio']['sample_rate'] = $streaminfo['sample_rate']; - $info['audio']['channels'] = $streaminfo['channels']; - $info['audio']['bits_per_sample'] = $streaminfo['bits_per_sample']; - $info['playtime_seconds'] = $streaminfo['samples_stream'] / $streaminfo['sample_rate']; - if ($info['playtime_seconds'] > 0) { - if (!$this->isDependencyFor('matroska')) { - $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; - } - else { - $this->warning('Cannot determine audio bitrate because total stream size is unknown'); - } - } + return true; + } - } else { - return $this->error('Corrupt METAdata block: STREAMINFO'); - } + private function parseAPPLICATION($BlockData) + { + $info = &$this->getid3->info; - return true; - } + $ApplicationID = getid3_lib::BigEndian2Int(substr($BlockData, 0, 4)); + $info['flac']['APPLICATION'][$ApplicationID]['name'] = self::applicationIDLookup($ApplicationID); + $info['flac']['APPLICATION'][$ApplicationID]['data'] = substr($BlockData, 4); - private function parseAPPLICATION($BlockData) { - $info = &$this->getid3->info; + return true; + } - $ApplicationID = getid3_lib::BigEndian2Int(substr($BlockData, 0, 4)); - $info['flac']['APPLICATION'][$ApplicationID]['name'] = self::applicationIDLookup($ApplicationID); - $info['flac']['APPLICATION'][$ApplicationID]['data'] = substr($BlockData, 4); + private function parseSEEKTABLE($BlockData) + { + $info = &$this->getid3->info; - return true; - } + $offset = 0; + $BlockLength = strlen($BlockData); + $placeholderpattern = str_repeat("\xFF", 8); + while ($offset < $BlockLength) { + $SampleNumberString = substr($BlockData, $offset, 8); + $offset += 8; + if ($SampleNumberString == $placeholderpattern) { - private function parseSEEKTABLE($BlockData) { - $info = &$this->getid3->info; + // placeholder point + getid3_lib::safe_inc($info['flac']['SEEKTABLE']['placeholders'], 1); + $offset += 10; + } else { + $SampleNumber = getid3_lib::BigEndian2Int($SampleNumberString); + $info['flac']['SEEKTABLE'][$SampleNumber]['offset'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8)); + $offset += 8; + $info['flac']['SEEKTABLE'][$SampleNumber]['samples'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 2)); + $offset += 2; + } + } - $offset = 0; - $BlockLength = strlen($BlockData); - $placeholderpattern = str_repeat("\xFF", 8); - while ($offset < $BlockLength) { - $SampleNumberString = substr($BlockData, $offset, 8); - $offset += 8; - if ($SampleNumberString == $placeholderpattern) { + return true; + } - // placeholder point - getid3_lib::safe_inc($info['flac']['SEEKTABLE']['placeholders'], 1); - $offset += 10; + private function parseVORBIS_COMMENT($BlockData) + { + $info = &$this->getid3->info; - } else { + $getid3_ogg = new getid3_ogg($this->getid3); + if ($this->isDependencyFor('matroska')) { + $getid3_ogg->setStringMode($this->data_string); + } + $getid3_ogg->ParseVorbisComments(); + if (isset($info['ogg'])) { + unset($info['ogg']['comments_raw']); + $info['flac']['VORBIS_COMMENT'] = $info['ogg']; + unset($info['ogg']); + } - $SampleNumber = getid3_lib::BigEndian2Int($SampleNumberString); - $info['flac']['SEEKTABLE'][$SampleNumber]['offset'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8)); - $offset += 8; - $info['flac']['SEEKTABLE'][$SampleNumber]['samples'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 2)); - $offset += 2; + unset($getid3_ogg); - } - } + return true; + } - return true; - } + private function parseCUESHEET($BlockData) + { + $info = &$this->getid3->info; + $offset = 0; + $info['flac']['CUESHEET']['media_catalog_number'] = trim(substr($BlockData, $offset, 128), "\0"); + $offset += 128; + $info['flac']['CUESHEET']['lead_in_samples'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8)); + $offset += 8; + $info['flac']['CUESHEET']['flags']['is_cd'] = (bool) (getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)) & 0x80); + $offset += 1; - private function parseVORBIS_COMMENT($BlockData) { - $info = &$this->getid3->info; + $offset += 258; // reserved - $getid3_ogg = new getid3_ogg($this->getid3); - if ($this->isDependencyFor('matroska')) { - $getid3_ogg->setStringMode($this->data_string); - } - $getid3_ogg->ParseVorbisComments(); - if (isset($info['ogg'])) { - unset($info['ogg']['comments_raw']); - $info['flac']['VORBIS_COMMENT'] = $info['ogg']; - unset($info['ogg']); - } + $info['flac']['CUESHEET']['number_tracks'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)); + $offset += 1; - unset($getid3_ogg); + for ($track = 0; $track < $info['flac']['CUESHEET']['number_tracks']; $track++) { + $TrackSampleOffset = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8)); + $offset += 8; + $TrackNumber = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)); + $offset += 1; - return true; - } + $info['flac']['CUESHEET']['tracks'][$TrackNumber]['sample_offset'] = $TrackSampleOffset; - private function parseCUESHEET($BlockData) { - $info = &$this->getid3->info; - $offset = 0; - $info['flac']['CUESHEET']['media_catalog_number'] = trim(substr($BlockData, $offset, 128), "\0"); - $offset += 128; - $info['flac']['CUESHEET']['lead_in_samples'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8)); - $offset += 8; - $info['flac']['CUESHEET']['flags']['is_cd'] = (bool) (getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)) & 0x80); - $offset += 1; + $info['flac']['CUESHEET']['tracks'][$TrackNumber]['isrc'] = substr($BlockData, $offset, 12); + $offset += 12; - $offset += 258; // reserved + $TrackFlagsRaw = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)); + $offset += 1; + $info['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['is_audio'] = (bool) ($TrackFlagsRaw & 0x80); + $info['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['pre_emphasis'] = (bool) ($TrackFlagsRaw & 0x40); - $info['flac']['CUESHEET']['number_tracks'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)); - $offset += 1; + $offset += 13; // reserved - for ($track = 0; $track < $info['flac']['CUESHEET']['number_tracks']; $track++) { - $TrackSampleOffset = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8)); - $offset += 8; - $TrackNumber = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)); - $offset += 1; + $info['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)); + $offset += 1; - $info['flac']['CUESHEET']['tracks'][$TrackNumber]['sample_offset'] = $TrackSampleOffset; + for ($index = 0; $index < $info['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points']; $index++) { + $IndexSampleOffset = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8)); + $offset += 8; + $IndexNumber = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)); + $offset += 1; - $info['flac']['CUESHEET']['tracks'][$TrackNumber]['isrc'] = substr($BlockData, $offset, 12); - $offset += 12; + $offset += 3; // reserved - $TrackFlagsRaw = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)); - $offset += 1; - $info['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['is_audio'] = (bool) ($TrackFlagsRaw & 0x80); - $info['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['pre_emphasis'] = (bool) ($TrackFlagsRaw & 0x40); + $info['flac']['CUESHEET']['tracks'][$TrackNumber]['indexes'][$IndexNumber] = $IndexSampleOffset; + } + } - $offset += 13; // reserved + return true; + } - $info['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)); - $offset += 1; + /** + * Parse METADATA_BLOCK_PICTURE flac structure and extract attachment + * External usage: audio.ogg. + */ + public function parsePICTURE() + { + $info = &$this->getid3->info; - for ($index = 0; $index < $info['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points']; $index++) { - $IndexSampleOffset = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8)); - $offset += 8; - $IndexNumber = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)); - $offset += 1; + $picture['typeid'] = getid3_lib::BigEndian2Int($this->fread(4)); + $picture['picturetype'] = self::pictureTypeLookup($picture['typeid']); + $picture['image_mime'] = $this->fread(getid3_lib::BigEndian2Int($this->fread(4))); + $descr_length = getid3_lib::BigEndian2Int($this->fread(4)); + if ($descr_length) { + $picture['description'] = $this->fread($descr_length); + } + $picture['image_width'] = getid3_lib::BigEndian2Int($this->fread(4)); + $picture['image_height'] = getid3_lib::BigEndian2Int($this->fread(4)); + $picture['color_depth'] = getid3_lib::BigEndian2Int($this->fread(4)); + $picture['colors_indexed'] = getid3_lib::BigEndian2Int($this->fread(4)); + $picture['datalength'] = getid3_lib::BigEndian2Int($this->fread(4)); - $offset += 3; // reserved + if ($picture['image_mime'] == '-->') { + $picture['data'] = $this->fread($picture['datalength']); + } else { + $picture['data'] = $this->saveAttachment( + str_replace('/', '_', $picture['picturetype']).'_'.$this->ftell(), + $this->ftell(), + $picture['datalength'], + $picture['image_mime']); + } - $info['flac']['CUESHEET']['tracks'][$TrackNumber]['indexes'][$IndexNumber] = $IndexSampleOffset; - } - } + $info['flac']['PICTURE'][] = $picture; - return true; - } + return true; + } - /** - * Parse METADATA_BLOCK_PICTURE flac structure and extract attachment - * External usage: audio.ogg - */ - public function parsePICTURE() { - $info = &$this->getid3->info; + public static function metaBlockTypeLookup($blocktype) + { + static $lookup = [ + 0 => 'STREAMINFO', + 1 => 'PADDING', + 2 => 'APPLICATION', + 3 => 'SEEKTABLE', + 4 => 'VORBIS_COMMENT', + 5 => 'CUESHEET', + 6 => 'PICTURE', + ]; - $picture['typeid'] = getid3_lib::BigEndian2Int($this->fread(4)); - $picture['picturetype'] = self::pictureTypeLookup($picture['typeid']); - $picture['image_mime'] = $this->fread(getid3_lib::BigEndian2Int($this->fread(4))); - $descr_length = getid3_lib::BigEndian2Int($this->fread(4)); - if ($descr_length) { - $picture['description'] = $this->fread($descr_length); - } - $picture['image_width'] = getid3_lib::BigEndian2Int($this->fread(4)); - $picture['image_height'] = getid3_lib::BigEndian2Int($this->fread(4)); - $picture['color_depth'] = getid3_lib::BigEndian2Int($this->fread(4)); - $picture['colors_indexed'] = getid3_lib::BigEndian2Int($this->fread(4)); - $picture['datalength'] = getid3_lib::BigEndian2Int($this->fread(4)); + return isset($lookup[$blocktype]) ? $lookup[$blocktype] : 'reserved'; + } - if ($picture['image_mime'] == '-->') { - $picture['data'] = $this->fread($picture['datalength']); - } else { - $picture['data'] = $this->saveAttachment( - str_replace('/', '_', $picture['picturetype']).'_'.$this->ftell(), - $this->ftell(), - $picture['datalength'], - $picture['image_mime']); - } + public static function applicationIDLookup($applicationid) + { + // http://flac.sourceforge.net/id.html + static $lookup = [ + 0x41544348 => 'FlacFile', // "ATCH" + 0x42534F4C => 'beSolo', // "BSOL" + 0x42554753 => 'Bugs Player', // "BUGS" + 0x43756573 => 'GoldWave cue points (specification)', // "Cues" + 0x46696361 => 'CUE Splitter', // "Fica" + 0x46746F6C => 'flac-tools', // "Ftol" + 0x4D4F5442 => 'MOTB MetaCzar', // "MOTB" + 0x4D505345 => 'MP3 Stream Editor', // "MPSE" + 0x4D754D4C => 'MusicML: Music Metadata Language', // "MuML" + 0x52494646 => 'Sound Devices RIFF chunk storage', // "RIFF" + 0x5346464C => 'Sound Font FLAC', // "SFFL" + 0x534F4E59 => 'Sony Creative Software', // "SONY" + 0x5351455A => 'flacsqueeze', // "SQEZ" + 0x54745776 => 'TwistedWave', // "TtWv" + 0x55495453 => 'UITS Embedding tools', // "UITS" + 0x61696666 => 'FLAC AIFF chunk storage', // "aiff" + 0x696D6167 => 'flac-image application for storing arbitrary files in APPLICATION metadata blocks', // "imag" + 0x7065656D => 'Parseable Embedded Extensible Metadata (specification)', // "peem" + 0x71667374 => 'QFLAC Studio', // "qfst" + 0x72696666 => 'FLAC RIFF chunk storage', // "riff" + 0x74756E65 => 'TagTuner', // "tune" + 0x78626174 => 'XBAT', // "xbat" + 0x786D6364 => 'xmcd', // "xmcd" + ]; - $info['flac']['PICTURE'][] = $picture; + return isset($lookup[$applicationid]) ? $lookup[$applicationid] : 'reserved'; + } - return true; - } - - public static function metaBlockTypeLookup($blocktype) { - static $lookup = array( - 0 => 'STREAMINFO', - 1 => 'PADDING', - 2 => 'APPLICATION', - 3 => 'SEEKTABLE', - 4 => 'VORBIS_COMMENT', - 5 => 'CUESHEET', - 6 => 'PICTURE', - ); - return (isset($lookup[$blocktype]) ? $lookup[$blocktype] : 'reserved'); - } - - public static function applicationIDLookup($applicationid) { - // http://flac.sourceforge.net/id.html - static $lookup = array( - 0x41544348 => 'FlacFile', // "ATCH" - 0x42534F4C => 'beSolo', // "BSOL" - 0x42554753 => 'Bugs Player', // "BUGS" - 0x43756573 => 'GoldWave cue points (specification)', // "Cues" - 0x46696361 => 'CUE Splitter', // "Fica" - 0x46746F6C => 'flac-tools', // "Ftol" - 0x4D4F5442 => 'MOTB MetaCzar', // "MOTB" - 0x4D505345 => 'MP3 Stream Editor', // "MPSE" - 0x4D754D4C => 'MusicML: Music Metadata Language', // "MuML" - 0x52494646 => 'Sound Devices RIFF chunk storage', // "RIFF" - 0x5346464C => 'Sound Font FLAC', // "SFFL" - 0x534F4E59 => 'Sony Creative Software', // "SONY" - 0x5351455A => 'flacsqueeze', // "SQEZ" - 0x54745776 => 'TwistedWave', // "TtWv" - 0x55495453 => 'UITS Embedding tools', // "UITS" - 0x61696666 => 'FLAC AIFF chunk storage', // "aiff" - 0x696D6167 => 'flac-image application for storing arbitrary files in APPLICATION metadata blocks', // "imag" - 0x7065656D => 'Parseable Embedded Extensible Metadata (specification)', // "peem" - 0x71667374 => 'QFLAC Studio', // "qfst" - 0x72696666 => 'FLAC RIFF chunk storage', // "riff" - 0x74756E65 => 'TagTuner', // "tune" - 0x78626174 => 'XBAT', // "xbat" - 0x786D6364 => 'xmcd', // "xmcd" - ); - return (isset($lookup[$applicationid]) ? $lookup[$applicationid] : 'reserved'); - } - - public static function pictureTypeLookup($type_id) { - static $lookup = array ( - 0 => 'Other', - 1 => '32x32 pixels \'file icon\' (PNG only)', - 2 => 'Other file icon', - 3 => 'Cover (front)', - 4 => 'Cover (back)', - 5 => 'Leaflet page', - 6 => 'Media (e.g. label side of CD)', - 7 => 'Lead artist/lead performer/soloist', - 8 => 'Artist/performer', - 9 => 'Conductor', - 10 => 'Band/Orchestra', - 11 => 'Composer', - 12 => 'Lyricist/text writer', - 13 => 'Recording Location', - 14 => 'During recording', - 15 => 'During performance', - 16 => 'Movie/video screen capture', - 17 => 'A bright coloured fish', - 18 => 'Illustration', - 19 => 'Band/artist logotype', - 20 => 'Publisher/Studio logotype', - ); - return (isset($lookup[$type_id]) ? $lookup[$type_id] : 'reserved'); - } + public static function pictureTypeLookup($type_id) + { + static $lookup = [ + 0 => 'Other', + 1 => '32x32 pixels \'file icon\' (PNG only)', + 2 => 'Other file icon', + 3 => 'Cover (front)', + 4 => 'Cover (back)', + 5 => 'Leaflet page', + 6 => 'Media (e.g. label side of CD)', + 7 => 'Lead artist/lead performer/soloist', + 8 => 'Artist/performer', + 9 => 'Conductor', + 10 => 'Band/Orchestra', + 11 => 'Composer', + 12 => 'Lyricist/text writer', + 13 => 'Recording Location', + 14 => 'During recording', + 15 => 'During performance', + 16 => 'Movie/video screen capture', + 17 => 'A bright coloured fish', + 18 => 'Illustration', + 19 => 'Band/artist logotype', + 20 => 'Publisher/Studio logotype', + ]; + return isset($lookup[$type_id]) ? $lookup[$type_id] : 'reserved'; + } } diff --git a/app/Library/getid3/getid3/module.audio.la.php b/app/Library/getid3/getid3/module.audio.la.php index f46c9aa0..aa3af6fb 100644 --- a/app/Library/getid3/getid3/module.audio.la.php +++ b/app/Library/getid3/getid3/module.audio.la.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -18,209 +19,210 @@ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', class getid3_la extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $offset = 0; + $this->fseek($info['avdataoffset']); + $rawdata = $this->fread($this->getid3->fread_buffer_size()); - $offset = 0; - $this->fseek($info['avdataoffset']); - $rawdata = $this->fread($this->getid3->fread_buffer_size()); + switch (substr($rawdata, $offset, 4)) { + case 'LA02': + case 'LA03': + case 'LA04': + $info['fileformat'] = 'la'; + $info['audio']['dataformat'] = 'la'; + $info['audio']['lossless'] = true; - switch (substr($rawdata, $offset, 4)) { - case 'LA02': - case 'LA03': - case 'LA04': - $info['fileformat'] = 'la'; - $info['audio']['dataformat'] = 'la'; - $info['audio']['lossless'] = true; + $info['la']['version_major'] = (int) substr($rawdata, $offset + 2, 1); + $info['la']['version_minor'] = (int) substr($rawdata, $offset + 3, 1); + $info['la']['version'] = (float) $info['la']['version_major'] + ($info['la']['version_minor'] / 10); + $offset += 4; - $info['la']['version_major'] = (int) substr($rawdata, $offset + 2, 1); - $info['la']['version_minor'] = (int) substr($rawdata, $offset + 3, 1); - $info['la']['version'] = (float) $info['la']['version_major'] + ($info['la']['version_minor'] / 10); - $offset += 4; + $info['la']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; + if ($info['la']['uncompressed_size'] == 0) { + $this->error('Corrupt LA file: uncompressed_size == zero'); - $info['la']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; - if ($info['la']['uncompressed_size'] == 0) { - $this->error('Corrupt LA file: uncompressed_size == zero'); - return false; - } + return false; + } - $WAVEchunk = substr($rawdata, $offset, 4); - if ($WAVEchunk !== 'WAVE') { - $this->error('Expected "WAVE" ('.getid3_lib::PrintHexBytes('WAVE').') at offset '.$offset.', found "'.$WAVEchunk.'" ('.getid3_lib::PrintHexBytes($WAVEchunk).') instead.'); - return false; - } - $offset += 4; + $WAVEchunk = substr($rawdata, $offset, 4); + if ($WAVEchunk !== 'WAVE') { + $this->error('Expected "WAVE" ('.getid3_lib::PrintHexBytes('WAVE').') at offset '.$offset.', found "'.$WAVEchunk.'" ('.getid3_lib::PrintHexBytes($WAVEchunk).') instead.'); - $info['la']['fmt_size'] = 24; - if ($info['la']['version'] >= 0.3) { + return false; + } + $offset += 4; - $info['la']['fmt_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $info['la']['header_size'] = 49 + $info['la']['fmt_size'] - 24; - $offset += 4; + $info['la']['fmt_size'] = 24; + if ($info['la']['version'] >= 0.3) { + $info['la']['fmt_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $info['la']['header_size'] = 49 + $info['la']['fmt_size'] - 24; + $offset += 4; + } else { - } else { + // version 0.2 didn't support additional data blocks + $info['la']['header_size'] = 41; + } - // version 0.2 didn't support additional data blocks - $info['la']['header_size'] = 41; + $fmt_chunk = substr($rawdata, $offset, 4); + if ($fmt_chunk !== 'fmt ') { + $this->error('Expected "fmt " ('.getid3_lib::PrintHexBytes('fmt ').') at offset '.$offset.', found "'.$fmt_chunk.'" ('.getid3_lib::PrintHexBytes($fmt_chunk).') instead.'); - } + return false; + } + $offset += 4; + $fmt_size = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; - $fmt_chunk = substr($rawdata, $offset, 4); - if ($fmt_chunk !== 'fmt ') { - $this->error('Expected "fmt " ('.getid3_lib::PrintHexBytes('fmt ').') at offset '.$offset.', found "'.$fmt_chunk.'" ('.getid3_lib::PrintHexBytes($fmt_chunk).') instead.'); - return false; - } - $offset += 4; - $fmt_size = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; + $info['la']['raw']['format'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); + $offset += 2; - $info['la']['raw']['format'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); - $offset += 2; + $info['la']['channels'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); + $offset += 2; + if ($info['la']['channels'] == 0) { + $this->error('Corrupt LA file: channels == zero'); - $info['la']['channels'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); - $offset += 2; - if ($info['la']['channels'] == 0) { - $this->error('Corrupt LA file: channels == zero'); - return false; - } + return false; + } - $info['la']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; - if ($info['la']['sample_rate'] == 0) { - $this->error('Corrupt LA file: sample_rate == zero'); - return false; - } + $info['la']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; + if ($info['la']['sample_rate'] == 0) { + $this->error('Corrupt LA file: sample_rate == zero'); - $info['la']['bytes_per_second'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; - $info['la']['bytes_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); - $offset += 2; - $info['la']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); - $offset += 2; + return false; + } - $info['la']['samples'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; + $info['la']['bytes_per_second'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; + $info['la']['bytes_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); + $offset += 2; + $info['la']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); + $offset += 2; - $info['la']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 1)); - $offset += 1; - $info['la']['flags']['seekable'] = (bool) ($info['la']['raw']['flags'] & 0x01); - if ($info['la']['version'] >= 0.4) { - $info['la']['flags']['high_compression'] = (bool) ($info['la']['raw']['flags'] & 0x02); - } + $info['la']['samples'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; - $info['la']['original_crc'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; + $info['la']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 1)); + $offset += 1; + $info['la']['flags']['seekable'] = (bool) ($info['la']['raw']['flags'] & 0x01); + if ($info['la']['version'] >= 0.4) { + $info['la']['flags']['high_compression'] = (bool) ($info['la']['raw']['flags'] & 0x02); + } - // mikeØbevin*de - // Basically, the blocksize/seekevery are 61440/19 in La0.4 and 73728/16 - // in earlier versions. A seekpoint is added every blocksize * seekevery - // samples, so 4 * int(totalSamples / (blockSize * seekEvery)) should - // give the number of bytes used for the seekpoints. Of course, if seeking - // is disabled, there are no seekpoints stored. - if ($info['la']['version'] >= 0.4) { - $info['la']['blocksize'] = 61440; - $info['la']['seekevery'] = 19; - } else { - $info['la']['blocksize'] = 73728; - $info['la']['seekevery'] = 16; - } + $info['la']['original_crc'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; - $info['la']['seekpoint_count'] = 0; - if ($info['la']['flags']['seekable']) { - $info['la']['seekpoint_count'] = floor($info['la']['samples'] / ($info['la']['blocksize'] * $info['la']['seekevery'])); + // mikeØbevin*de + // Basically, the blocksize/seekevery are 61440/19 in La0.4 and 73728/16 + // in earlier versions. A seekpoint is added every blocksize * seekevery + // samples, so 4 * int(totalSamples / (blockSize * seekEvery)) should + // give the number of bytes used for the seekpoints. Of course, if seeking + // is disabled, there are no seekpoints stored. + if ($info['la']['version'] >= 0.4) { + $info['la']['blocksize'] = 61440; + $info['la']['seekevery'] = 19; + } else { + $info['la']['blocksize'] = 73728; + $info['la']['seekevery'] = 16; + } - for ($i = 0; $i < $info['la']['seekpoint_count']; $i++) { - $info['la']['seekpoints'][] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; - } - } + $info['la']['seekpoint_count'] = 0; + if ($info['la']['flags']['seekable']) { + $info['la']['seekpoint_count'] = floor($info['la']['samples'] / ($info['la']['blocksize'] * $info['la']['seekevery'])); - if ($info['la']['version'] >= 0.3) { + for ($i = 0; $i < $info['la']['seekpoint_count']; $i++) { + $info['la']['seekpoints'][] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; + } + } - // Following the main header information, the program outputs all of the - // seekpoints. Following these is what I called the 'footer start', - // i.e. the position immediately after the La audio data is finished. - $info['la']['footerstart'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; + if ($info['la']['version'] >= 0.3) { - if ($info['la']['footerstart'] > $info['filesize']) { - $this->warning('FooterStart value points to offset '.$info['la']['footerstart'].' which is beyond end-of-file ('.$info['filesize'].')'); - $info['la']['footerstart'] = $info['filesize']; - } + // Following the main header information, the program outputs all of the + // seekpoints. Following these is what I called the 'footer start', + // i.e. the position immediately after the La audio data is finished. + $info['la']['footerstart'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; - } else { + if ($info['la']['footerstart'] > $info['filesize']) { + $this->warning('FooterStart value points to offset '.$info['la']['footerstart'].' which is beyond end-of-file ('.$info['filesize'].')'); + $info['la']['footerstart'] = $info['filesize']; + } + } else { - // La v0.2 didn't have FooterStart value - $info['la']['footerstart'] = $info['avdataend']; + // La v0.2 didn't have FooterStart value + $info['la']['footerstart'] = $info['avdataend']; + } - } + if ($info['la']['footerstart'] < $info['avdataend']) { + if ($RIFFtempfilename = tempnam(GETID3_TEMP_DIR, 'id3')) { + if ($RIFF_fp = fopen($RIFFtempfilename, 'w+b')) { + $RIFFdata = 'WAVE'; + if ($info['la']['version'] == 0.2) { + $RIFFdata .= substr($rawdata, 12, 24); + } else { + $RIFFdata .= substr($rawdata, 16, 24); + } + if ($info['la']['footerstart'] < $info['avdataend']) { + $this->fseek($info['la']['footerstart']); + $RIFFdata .= $this->fread($info['avdataend'] - $info['la']['footerstart']); + } + $RIFFdata = 'RIFF'.getid3_lib::LittleEndian2String(strlen($RIFFdata), 4, false).$RIFFdata; + fwrite($RIFF_fp, $RIFFdata, strlen($RIFFdata)); + fclose($RIFF_fp); - if ($info['la']['footerstart'] < $info['avdataend']) { - if ($RIFFtempfilename = tempnam(GETID3_TEMP_DIR, 'id3')) { - if ($RIFF_fp = fopen($RIFFtempfilename, 'w+b')) { - $RIFFdata = 'WAVE'; - if ($info['la']['version'] == 0.2) { - $RIFFdata .= substr($rawdata, 12, 24); - } else { - $RIFFdata .= substr($rawdata, 16, 24); - } - if ($info['la']['footerstart'] < $info['avdataend']) { - $this->fseek($info['la']['footerstart']); - $RIFFdata .= $this->fread($info['avdataend'] - $info['la']['footerstart']); - } - $RIFFdata = 'RIFF'.getid3_lib::LittleEndian2String(strlen($RIFFdata), 4, false).$RIFFdata; - fwrite($RIFF_fp, $RIFFdata, strlen($RIFFdata)); - fclose($RIFF_fp); + $getid3_temp = new getID3(); + $getid3_temp->openfile($RIFFtempfilename); + $getid3_riff = new getid3_riff($getid3_temp); + $getid3_riff->Analyze(); - $getid3_temp = new getID3(); - $getid3_temp->openfile($RIFFtempfilename); - $getid3_riff = new getid3_riff($getid3_temp); - $getid3_riff->Analyze(); + if (empty($getid3_temp->info['error'])) { + $info['riff'] = $getid3_temp->info['riff']; + } else { + $this->warning('Error parsing RIFF portion of La file: '.implode($getid3_temp->info['error'])); + } + unset($getid3_temp, $getid3_riff); + } + unlink($RIFFtempfilename); + } + } - if (empty($getid3_temp->info['error'])) { - $info['riff'] = $getid3_temp->info['riff']; - } else { - $this->warning('Error parsing RIFF portion of La file: '.implode($getid3_temp->info['error'])); - } - unset($getid3_temp, $getid3_riff); - } - unlink($RIFFtempfilename); - } - } + // $info['avdataoffset'] should be zero to begin with, but just in case it's not, include the addition anyway + $info['avdataend'] = $info['avdataoffset'] + $info['la']['footerstart']; + $info['avdataoffset'] = $info['avdataoffset'] + $offset; - // $info['avdataoffset'] should be zero to begin with, but just in case it's not, include the addition anyway - $info['avdataend'] = $info['avdataoffset'] + $info['la']['footerstart']; - $info['avdataoffset'] = $info['avdataoffset'] + $offset; + $info['la']['compression_ratio'] = (float) (($info['avdataend'] - $info['avdataoffset']) / $info['la']['uncompressed_size']); + $info['playtime_seconds'] = (float) ($info['la']['samples'] / $info['la']['sample_rate']) / $info['la']['channels']; + if ($info['playtime_seconds'] == 0) { + $this->error('Corrupt LA file: playtime_seconds == zero'); - $info['la']['compression_ratio'] = (float) (($info['avdataend'] - $info['avdataoffset']) / $info['la']['uncompressed_size']); - $info['playtime_seconds'] = (float) ($info['la']['samples'] / $info['la']['sample_rate']) / $info['la']['channels']; - if ($info['playtime_seconds'] == 0) { - $this->error('Corrupt LA file: playtime_seconds == zero'); - return false; - } + return false; + } - $info['audio']['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['playtime_seconds']; - //$info['audio']['codec'] = $info['la']['codec']; - $info['audio']['bits_per_sample'] = $info['la']['bits_per_sample']; - break; + $info['audio']['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['playtime_seconds']; + //$info['audio']['codec'] = $info['la']['codec']; + $info['audio']['bits_per_sample'] = $info['la']['bits_per_sample']; + break; - default: - if (substr($rawdata, $offset, 2) == 'LA') { - $this->error('This version of getID3() ['.$this->getid3->version().'] does not support LA version '.substr($rawdata, $offset + 2, 1).'.'.substr($rawdata, $offset + 3, 1).' which this appears to be - check http://getid3.sourceforge.net for updates.'); - } else { - $this->error('Not a LA (Lossless-Audio) file'); - } - return false; - break; - } + default: + if (substr($rawdata, $offset, 2) == 'LA') { + $this->error('This version of getID3() ['.$this->getid3->version().'] does not support LA version '.substr($rawdata, $offset + 2, 1).'.'.substr($rawdata, $offset + 3, 1).' which this appears to be - check http://getid3.sourceforge.net for updates.'); + } else { + $this->error('Not a LA (Lossless-Audio) file'); + } - $info['audio']['channels'] = $info['la']['channels']; - $info['audio']['sample_rate'] = (int) $info['la']['sample_rate']; - $info['audio']['encoder'] = 'LA v'.$info['la']['version']; + return false; + break; + } - return true; - } + $info['audio']['channels'] = $info['la']['channels']; + $info['audio']['sample_rate'] = (int) $info['la']['sample_rate']; + $info['audio']['encoder'] = 'LA v'.$info['la']['version']; + return true; + } } diff --git a/app/Library/getid3/getid3/module.audio.lpac.php b/app/Library/getid3/getid3/module.audio.lpac.php index 447cc2d6..045874b9 100644 --- a/app/Library/getid3/getid3/module.audio.lpac.php +++ b/app/Library/getid3/getid3/module.audio.lpac.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -18,111 +19,111 @@ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', class getid3_lpac extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $LPACheader = $this->fread(14); + if (substr($LPACheader, 0, 4) != 'LPAC') { + $this->error('Expected "LPAC" at offset '.$info['avdataoffset'].', found "'.$StreamMarker.'"'); - $this->fseek($info['avdataoffset']); - $LPACheader = $this->fread(14); - if (substr($LPACheader, 0, 4) != 'LPAC') { - $this->error('Expected "LPAC" at offset '.$info['avdataoffset'].', found "'.$StreamMarker.'"'); - return false; - } - $info['avdataoffset'] += 14; + return false; + } + $info['avdataoffset'] += 14; - $info['fileformat'] = 'lpac'; - $info['audio']['dataformat'] = 'lpac'; - $info['audio']['lossless'] = true; - $info['audio']['bitrate_mode'] = 'vbr'; + $info['fileformat'] = 'lpac'; + $info['audio']['dataformat'] = 'lpac'; + $info['audio']['lossless'] = true; + $info['audio']['bitrate_mode'] = 'vbr'; - $info['lpac']['file_version'] = getid3_lib::BigEndian2Int(substr($LPACheader, 4, 1)); - $flags['audio_type'] = getid3_lib::BigEndian2Int(substr($LPACheader, 5, 1)); - $info['lpac']['total_samples']= getid3_lib::BigEndian2Int(substr($LPACheader, 6, 4)); - $flags['parameters'] = getid3_lib::BigEndian2Int(substr($LPACheader, 10, 4)); + $info['lpac']['file_version'] = getid3_lib::BigEndian2Int(substr($LPACheader, 4, 1)); + $flags['audio_type'] = getid3_lib::BigEndian2Int(substr($LPACheader, 5, 1)); + $info['lpac']['total_samples'] = getid3_lib::BigEndian2Int(substr($LPACheader, 6, 4)); + $flags['parameters'] = getid3_lib::BigEndian2Int(substr($LPACheader, 10, 4)); - $info['lpac']['flags']['is_wave'] = (bool) ($flags['audio_type'] & 0x40); - $info['lpac']['flags']['stereo'] = (bool) ($flags['audio_type'] & 0x04); - $info['lpac']['flags']['24_bit'] = (bool) ($flags['audio_type'] & 0x02); - $info['lpac']['flags']['16_bit'] = (bool) ($flags['audio_type'] & 0x01); + $info['lpac']['flags']['is_wave'] = (bool) ($flags['audio_type'] & 0x40); + $info['lpac']['flags']['stereo'] = (bool) ($flags['audio_type'] & 0x04); + $info['lpac']['flags']['24_bit'] = (bool) ($flags['audio_type'] & 0x02); + $info['lpac']['flags']['16_bit'] = (bool) ($flags['audio_type'] & 0x01); - if ($info['lpac']['flags']['24_bit'] && $info['lpac']['flags']['16_bit']) { - $this->warning('24-bit and 16-bit flags cannot both be set'); - } + if ($info['lpac']['flags']['24_bit'] && $info['lpac']['flags']['16_bit']) { + $this->warning('24-bit and 16-bit flags cannot both be set'); + } - $info['lpac']['flags']['fast_compress'] = (bool) ($flags['parameters'] & 0x40000000); - $info['lpac']['flags']['random_access'] = (bool) ($flags['parameters'] & 0x08000000); - $info['lpac']['block_length'] = pow(2, (($flags['parameters'] & 0x07000000) >> 24)) * 256; - $info['lpac']['flags']['adaptive_prediction_order'] = (bool) ($flags['parameters'] & 0x00800000); - $info['lpac']['flags']['adaptive_quantization'] = (bool) ($flags['parameters'] & 0x00400000); - $info['lpac']['flags']['joint_stereo'] = (bool) ($flags['parameters'] & 0x00040000); - $info['lpac']['quantization'] = ($flags['parameters'] & 0x00001F00) >> 8; - $info['lpac']['max_prediction_order'] = ($flags['parameters'] & 0x0000003F); + $info['lpac']['flags']['fast_compress'] = (bool) ($flags['parameters'] & 0x40000000); + $info['lpac']['flags']['random_access'] = (bool) ($flags['parameters'] & 0x08000000); + $info['lpac']['block_length'] = pow(2, (($flags['parameters'] & 0x07000000) >> 24)) * 256; + $info['lpac']['flags']['adaptive_prediction_order'] = (bool) ($flags['parameters'] & 0x00800000); + $info['lpac']['flags']['adaptive_quantization'] = (bool) ($flags['parameters'] & 0x00400000); + $info['lpac']['flags']['joint_stereo'] = (bool) ($flags['parameters'] & 0x00040000); + $info['lpac']['quantization'] = ($flags['parameters'] & 0x00001F00) >> 8; + $info['lpac']['max_prediction_order'] = ($flags['parameters'] & 0x0000003F); - if ($info['lpac']['flags']['fast_compress'] && ($info['lpac']['max_prediction_order'] != 3)) { - $this->warning('max_prediction_order expected to be "3" if fast_compress is true, actual value is "'.$info['lpac']['max_prediction_order'].'"'); - } - switch ($info['lpac']['file_version']) { - case 6: - if ($info['lpac']['flags']['adaptive_quantization']) { - $this->warning('adaptive_quantization expected to be false in LPAC file stucture v6, actually true'); - } - if ($info['lpac']['quantization'] != 20) { - $this->warning('Quantization expected to be 20 in LPAC file stucture v6, actually '.$info['lpac']['flags']['Q']); - } - break; + if ($info['lpac']['flags']['fast_compress'] && ($info['lpac']['max_prediction_order'] != 3)) { + $this->warning('max_prediction_order expected to be "3" if fast_compress is true, actual value is "'.$info['lpac']['max_prediction_order'].'"'); + } + switch ($info['lpac']['file_version']) { + case 6: + if ($info['lpac']['flags']['adaptive_quantization']) { + $this->warning('adaptive_quantization expected to be false in LPAC file stucture v6, actually true'); + } + if ($info['lpac']['quantization'] != 20) { + $this->warning('Quantization expected to be 20 in LPAC file stucture v6, actually '.$info['lpac']['flags']['Q']); + } + break; - default: - //$this->warning('This version of getID3() ['.$this->getid3->version().'] only supports LPAC file format version 6, this file is version '.$info['lpac']['file_version'].' - please report to info@getid3.org'); - break; - } + default: + //$this->warning('This version of getID3() ['.$this->getid3->version().'] only supports LPAC file format version 6, this file is version '.$info['lpac']['file_version'].' - please report to info@getid3.org'); + break; + } - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_temp->info = $info; - $getid3_riff = new getid3_riff($getid3_temp); - $getid3_riff->Analyze(); - $info['avdataoffset'] = $getid3_temp->info['avdataoffset']; - $info['riff'] = $getid3_temp->info['riff']; - $info['error'] = $getid3_temp->info['error']; - $info['warning'] = $getid3_temp->info['warning']; - $info['lpac']['comments']['comment'] = $getid3_temp->info['comments']; - $info['audio']['sample_rate'] = $getid3_temp->info['audio']['sample_rate']; - unset($getid3_temp, $getid3_riff); + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_temp->info = $info; + $getid3_riff = new getid3_riff($getid3_temp); + $getid3_riff->Analyze(); + $info['avdataoffset'] = $getid3_temp->info['avdataoffset']; + $info['riff'] = $getid3_temp->info['riff']; + $info['error'] = $getid3_temp->info['error']; + $info['warning'] = $getid3_temp->info['warning']; + $info['lpac']['comments']['comment'] = $getid3_temp->info['comments']; + $info['audio']['sample_rate'] = $getid3_temp->info['audio']['sample_rate']; + unset($getid3_temp, $getid3_riff); - $info['audio']['channels'] = ($info['lpac']['flags']['stereo'] ? 2 : 1); + $info['audio']['channels'] = ($info['lpac']['flags']['stereo'] ? 2 : 1); - if ($info['lpac']['flags']['24_bit']) { - $info['audio']['bits_per_sample'] = $info['riff']['audio'][0]['bits_per_sample']; - } elseif ($info['lpac']['flags']['16_bit']) { - $info['audio']['bits_per_sample'] = 16; - } else { - $info['audio']['bits_per_sample'] = 8; - } + if ($info['lpac']['flags']['24_bit']) { + $info['audio']['bits_per_sample'] = $info['riff']['audio'][0]['bits_per_sample']; + } elseif ($info['lpac']['flags']['16_bit']) { + $info['audio']['bits_per_sample'] = 16; + } else { + $info['audio']['bits_per_sample'] = 8; + } - if ($info['lpac']['flags']['fast_compress']) { - // fast - $info['audio']['encoder_options'] = '-1'; - } else { - switch ($info['lpac']['max_prediction_order']) { - case 20: // simple - $info['audio']['encoder_options'] = '-2'; - break; - case 30: // medium - $info['audio']['encoder_options'] = '-3'; - break; - case 40: // high - $info['audio']['encoder_options'] = '-4'; - break; - case 60: // extrahigh - $info['audio']['encoder_options'] = '-5'; - break; - } - } + if ($info['lpac']['flags']['fast_compress']) { + // fast + $info['audio']['encoder_options'] = '-1'; + } else { + switch ($info['lpac']['max_prediction_order']) { + case 20: // simple + $info['audio']['encoder_options'] = '-2'; + break; + case 30: // medium + $info['audio']['encoder_options'] = '-3'; + break; + case 40: // high + $info['audio']['encoder_options'] = '-4'; + break; + case 60: // extrahigh + $info['audio']['encoder_options'] = '-5'; + break; + } + } - $info['playtime_seconds'] = $info['lpac']['total_samples'] / $info['audio']['sample_rate']; - $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; - - return true; - } + $info['playtime_seconds'] = $info['lpac']['total_samples'] / $info['audio']['sample_rate']; + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + return true; + } } diff --git a/app/Library/getid3/getid3/module.audio.midi.php b/app/Library/getid3/getid3/module.audio.midi.php index 359aca26..72d397cc 100644 --- a/app/Library/getid3/getid3/module.audio.midi.php +++ b/app/Library/getid3/getid3/module.audio.midi.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -19,512 +20,501 @@ define('GETID3_MIDI_MAGIC_MTRK', 'MTrk'); // MIDI track header magic class getid3_midi extends getid3_handler { - public $scanwholefile = true; - - public function Analyze() { - $info = &$this->getid3->info; - - // shortcut - $info['midi']['raw'] = array(); - $thisfile_midi = &$info['midi']; - $thisfile_midi_raw = &$thisfile_midi['raw']; - - $info['fileformat'] = 'midi'; - $info['audio']['dataformat'] = 'midi'; - - $this->fseek($info['avdataoffset']); - $MIDIdata = $this->fread($this->getid3->fread_buffer_size()); - $offset = 0; - $MIDIheaderID = substr($MIDIdata, $offset, 4); // 'MThd' - if ($MIDIheaderID != GETID3_MIDI_MAGIC_MTHD) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes(GETID3_MIDI_MAGIC_MTHD).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($MIDIheaderID).'"'); - unset($info['fileformat']); - return false; - } - $offset += 4; - $thisfile_midi_raw['headersize'] = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 4)); - $offset += 4; - $thisfile_midi_raw['fileformat'] = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 2)); - $offset += 2; - $thisfile_midi_raw['tracks'] = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 2)); - $offset += 2; - $thisfile_midi_raw['ticksperqnote'] = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 2)); - $offset += 2; - - for ($i = 0; $i < $thisfile_midi_raw['tracks']; $i++) { - while ((strlen($MIDIdata) - $offset) < 8) { - if ($buffer = $this->fread($this->getid3->fread_buffer_size())) { - $MIDIdata .= $buffer; - } else { - $this->warning('only processed '.($i - 1).' of '.$thisfile_midi_raw['tracks'].' tracks'); - $this->error('Unabled to read more file data at '.$this->ftell().' (trying to seek to : '.$offset.'), was expecting at least 8 more bytes'); - return false; - } - } - $trackID = substr($MIDIdata, $offset, 4); - $offset += 4; - if ($trackID == GETID3_MIDI_MAGIC_MTRK) { - $tracksize = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 4)); - $offset += 4; - //$thisfile_midi['tracks'][$i]['size'] = $tracksize; - $trackdataarray[$i] = substr($MIDIdata, $offset, $tracksize); - $offset += $tracksize; - } else { - $this->error('Expecting "'.getid3_lib::PrintHexBytes(GETID3_MIDI_MAGIC_MTRK).'" at '.($offset - 4).', found "'.getid3_lib::PrintHexBytes($trackID).'" instead'); - return false; - } - } - - if (!isset($trackdataarray) || !is_array($trackdataarray)) { - $this->error('Cannot find MIDI track information'); - unset($thisfile_midi); - unset($info['fileformat']); - return false; - } - - if ($this->scanwholefile) { // this can take quite a long time, so have the option to bypass it if speed is very important - $thisfile_midi['totalticks'] = 0; - $info['playtime_seconds'] = 0; - $CurrentMicroSecondsPerBeat = 500000; // 120 beats per minute; 60,000,000 microseconds per minute -> 500,000 microseconds per beat - $CurrentBeatsPerMinute = 120; // 120 beats per minute; 60,000,000 microseconds per minute -> 500,000 microseconds per beat - $MicroSecondsPerQuarterNoteAfter = array (); - - foreach ($trackdataarray as $tracknumber => $trackdata) { - - $eventsoffset = 0; - $LastIssuedMIDIcommand = 0; - $LastIssuedMIDIchannel = 0; - $CumulativeDeltaTime = 0; - $TicksAtCurrentBPM = 0; - while ($eventsoffset < strlen($trackdata)) { - $eventid = 0; - if (isset($MIDIevents[$tracknumber]) && is_array($MIDIevents[$tracknumber])) { - $eventid = count($MIDIevents[$tracknumber]); - } - $deltatime = 0; - for ($i = 0; $i < 4; $i++) { - $deltatimebyte = ord(substr($trackdata, $eventsoffset++, 1)); - $deltatime = ($deltatime << 7) + ($deltatimebyte & 0x7F); - if ($deltatimebyte & 0x80) { - // another byte follows - } else { - break; - } - } - $CumulativeDeltaTime += $deltatime; - $TicksAtCurrentBPM += $deltatime; - $MIDIevents[$tracknumber][$eventid]['deltatime'] = $deltatime; - $MIDI_event_channel = ord(substr($trackdata, $eventsoffset++, 1)); - if ($MIDI_event_channel & 0x80) { - // OK, normal event - MIDI command has MSB set - $LastIssuedMIDIcommand = $MIDI_event_channel >> 4; - $LastIssuedMIDIchannel = $MIDI_event_channel & 0x0F; - } else { - // running event - assume last command - $eventsoffset--; - } - $MIDIevents[$tracknumber][$eventid]['eventid'] = $LastIssuedMIDIcommand; - $MIDIevents[$tracknumber][$eventid]['channel'] = $LastIssuedMIDIchannel; - if ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x08) { // Note off (key is released) - - $notenumber = ord(substr($trackdata, $eventsoffset++, 1)); - $velocity = ord(substr($trackdata, $eventsoffset++, 1)); - - } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x09) { // Note on (key is pressed) - - $notenumber = ord(substr($trackdata, $eventsoffset++, 1)); - $velocity = ord(substr($trackdata, $eventsoffset++, 1)); - - } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0A) { // Key after-touch - - $notenumber = ord(substr($trackdata, $eventsoffset++, 1)); - $velocity = ord(substr($trackdata, $eventsoffset++, 1)); - - } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0B) { // Control Change - - $controllernum = ord(substr($trackdata, $eventsoffset++, 1)); - $newvalue = ord(substr($trackdata, $eventsoffset++, 1)); - - } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0C) { // Program (patch) change - - $newprogramnum = ord(substr($trackdata, $eventsoffset++, 1)); - - $thisfile_midi_raw['track'][$tracknumber]['instrumentid'] = $newprogramnum; - if ($tracknumber == 10) { - $thisfile_midi_raw['track'][$tracknumber]['instrument'] = $this->GeneralMIDIpercussionLookup($newprogramnum); - } else { - $thisfile_midi_raw['track'][$tracknumber]['instrument'] = $this->GeneralMIDIinstrumentLookup($newprogramnum); - } - - } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0D) { // Channel after-touch - - $channelnumber = ord(substr($trackdata, $eventsoffset++, 1)); - - } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0E) { // Pitch wheel change (2000H is normal or no change) - - $changeLSB = ord(substr($trackdata, $eventsoffset++, 1)); - $changeMSB = ord(substr($trackdata, $eventsoffset++, 1)); - $pitchwheelchange = (($changeMSB & 0x7F) << 7) & ($changeLSB & 0x7F); - - } elseif (($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0F) && ($MIDIevents[$tracknumber][$eventid]['channel'] == 0x0F)) { - - $METAeventCommand = ord(substr($trackdata, $eventsoffset++, 1)); - $METAeventLength = ord(substr($trackdata, $eventsoffset++, 1)); - $METAeventData = substr($trackdata, $eventsoffset, $METAeventLength); - $eventsoffset += $METAeventLength; - switch ($METAeventCommand) { - case 0x00: // Set track sequence number - $track_sequence_number = getid3_lib::BigEndian2Int(substr($METAeventData, 0, $METAeventLength)); - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['seqno'] = $track_sequence_number; - break; - - case 0x01: // Text: generic - $text_generic = substr($METAeventData, 0, $METAeventLength); - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['text'] = $text_generic; - $thisfile_midi['comments']['comment'][] = $text_generic; - break; - - case 0x02: // Text: copyright - $text_copyright = substr($METAeventData, 0, $METAeventLength); - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['copyright'] = $text_copyright; - $thisfile_midi['comments']['copyright'][] = $text_copyright; - break; - - case 0x03: // Text: track name - $text_trackname = substr($METAeventData, 0, $METAeventLength); - $thisfile_midi_raw['track'][$tracknumber]['name'] = $text_trackname; - break; - - case 0x04: // Text: track instrument name - $text_instrument = substr($METAeventData, 0, $METAeventLength); - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['instrument'] = $text_instrument; - break; - - case 0x05: // Text: lyrics - $text_lyrics = substr($METAeventData, 0, $METAeventLength); - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['lyrics'] = $text_lyrics; - if (!isset($thisfile_midi['lyrics'])) { - $thisfile_midi['lyrics'] = ''; - } - $thisfile_midi['lyrics'] .= $text_lyrics."\n"; - break; - - case 0x06: // Text: marker - $text_marker = substr($METAeventData, 0, $METAeventLength); - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['marker'] = $text_marker; - break; - - case 0x07: // Text: cue point - $text_cuepoint = substr($METAeventData, 0, $METAeventLength); - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['cuepoint'] = $text_cuepoint; - break; - - case 0x2F: // End Of Track - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['EOT'] = $CumulativeDeltaTime; - break; - - case 0x51: // Tempo: microseconds / quarter note - $CurrentMicroSecondsPerBeat = getid3_lib::BigEndian2Int(substr($METAeventData, 0, $METAeventLength)); - if ($CurrentMicroSecondsPerBeat == 0) { - $this->error('Corrupt MIDI file: CurrentMicroSecondsPerBeat == zero'); - return false; - } - $thisfile_midi_raw['events'][$tracknumber][$CumulativeDeltaTime]['us_qnote'] = $CurrentMicroSecondsPerBeat; - $CurrentBeatsPerMinute = (1000000 / $CurrentMicroSecondsPerBeat) * 60; - $MicroSecondsPerQuarterNoteAfter[$CumulativeDeltaTime] = $CurrentMicroSecondsPerBeat; - $TicksAtCurrentBPM = 0; - break; - - case 0x58: // Time signature - $timesig_numerator = getid3_lib::BigEndian2Int($METAeventData{0}); - $timesig_denominator = pow(2, getid3_lib::BigEndian2Int($METAeventData{1})); // $02 -> x/4, $03 -> x/8, etc - $timesig_32inqnote = getid3_lib::BigEndian2Int($METAeventData{2}); // number of 32nd notes to the quarter note - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['timesig_32inqnote'] = $timesig_32inqnote; - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['timesig_numerator'] = $timesig_numerator; - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['timesig_denominator'] = $timesig_denominator; - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['timesig_text'] = $timesig_numerator.'/'.$timesig_denominator; - $thisfile_midi['timesignature'][] = $timesig_numerator.'/'.$timesig_denominator; - break; - - case 0x59: // Keysignature - $keysig_sharpsflats = getid3_lib::BigEndian2Int($METAeventData{0}); - if ($keysig_sharpsflats & 0x80) { - // (-7 -> 7 flats, 0 ->key of C, 7 -> 7 sharps) - $keysig_sharpsflats -= 256; - } - - $keysig_majorminor = getid3_lib::BigEndian2Int($METAeventData{1}); // 0 -> major, 1 -> minor - $keysigs = array(-7=>'Cb', -6=>'Gb', -5=>'Db', -4=>'Ab', -3=>'Eb', -2=>'Bb', -1=>'F', 0=>'C', 1=>'G', 2=>'D', 3=>'A', 4=>'E', 5=>'B', 6=>'F#', 7=>'C#'); - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_sharps'] = (($keysig_sharpsflats > 0) ? abs($keysig_sharpsflats) : 0); - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_flats'] = (($keysig_sharpsflats < 0) ? abs($keysig_sharpsflats) : 0); - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_minor'] = (bool) $keysig_majorminor; - //$thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_text'] = $keysigs[$keysig_sharpsflats].' '.($thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_minor'] ? 'minor' : 'major'); - - // $keysigs[$keysig_sharpsflats] gets an int key (correct) - $keysigs["$keysig_sharpsflats"] gets a string key (incorrect) - $thisfile_midi['keysignature'][] = $keysigs[$keysig_sharpsflats].' '.((bool) $keysig_majorminor ? 'minor' : 'major'); - break; - - case 0x7F: // Sequencer specific information - $custom_data = substr($METAeventData, 0, $METAeventLength); - break; - - default: - $this->warning('Unhandled META Event Command: '.$METAeventCommand); - break; - } - - } else { - - $this->warning('Unhandled MIDI Event ID: '.$MIDIevents[$tracknumber][$eventid]['eventid'].' + Channel ID: '.$MIDIevents[$tracknumber][$eventid]['channel']); - - } - } - if (($tracknumber > 0) || (count($trackdataarray) == 1)) { - $thisfile_midi['totalticks'] = max($thisfile_midi['totalticks'], $CumulativeDeltaTime); - } - } - $previoustickoffset = null; - - ksort($MicroSecondsPerQuarterNoteAfter); - foreach ($MicroSecondsPerQuarterNoteAfter as $tickoffset => $microsecondsperbeat) { - if (is_null($previoustickoffset)) { - $prevmicrosecondsperbeat = $microsecondsperbeat; - $previoustickoffset = $tickoffset; - continue; - } - if ($thisfile_midi['totalticks'] > $tickoffset) { - - if ($thisfile_midi_raw['ticksperqnote'] == 0) { - $this->error('Corrupt MIDI file: ticksperqnote == zero'); - return false; - } - - $info['playtime_seconds'] += (($tickoffset - $previoustickoffset) / $thisfile_midi_raw['ticksperqnote']) * ($prevmicrosecondsperbeat / 1000000); - - $prevmicrosecondsperbeat = $microsecondsperbeat; - $previoustickoffset = $tickoffset; - } - } - if ($thisfile_midi['totalticks'] > $previoustickoffset) { - - if ($thisfile_midi_raw['ticksperqnote'] == 0) { - $this->error('Corrupt MIDI file: ticksperqnote == zero'); - return false; - } - - $info['playtime_seconds'] += (($thisfile_midi['totalticks'] - $previoustickoffset) / $thisfile_midi_raw['ticksperqnote']) * ($microsecondsperbeat / 1000000); - - } - } - - - if (!empty($info['playtime_seconds'])) { - $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; - } - - if (!empty($thisfile_midi['lyrics'])) { - $thisfile_midi['comments']['lyrics'][] = $thisfile_midi['lyrics']; - } - - return true; - } - - public function GeneralMIDIinstrumentLookup($instrumentid) { - - $begin = __LINE__; - - /** This is not a comment! - - 0 Acoustic Grand - 1 Bright Acoustic - 2 Electric Grand - 3 Honky-Tonk - 4 Electric Piano 1 - 5 Electric Piano 2 - 6 Harpsichord - 7 Clavier - 8 Celesta - 9 Glockenspiel - 10 Music Box - 11 Vibraphone - 12 Marimba - 13 Xylophone - 14 Tubular Bells - 15 Dulcimer - 16 Drawbar Organ - 17 Percussive Organ - 18 Rock Organ - 19 Church Organ - 20 Reed Organ - 21 Accordian - 22 Harmonica - 23 Tango Accordian - 24 Acoustic Guitar (nylon) - 25 Acoustic Guitar (steel) - 26 Electric Guitar (jazz) - 27 Electric Guitar (clean) - 28 Electric Guitar (muted) - 29 Overdriven Guitar - 30 Distortion Guitar - 31 Guitar Harmonics - 32 Acoustic Bass - 33 Electric Bass (finger) - 34 Electric Bass (pick) - 35 Fretless Bass - 36 Slap Bass 1 - 37 Slap Bass 2 - 38 Synth Bass 1 - 39 Synth Bass 2 - 40 Violin - 41 Viola - 42 Cello - 43 Contrabass - 44 Tremolo Strings - 45 Pizzicato Strings - 46 Orchestral Strings - 47 Timpani - 48 String Ensemble 1 - 49 String Ensemble 2 - 50 SynthStrings 1 - 51 SynthStrings 2 - 52 Choir Aahs - 53 Voice Oohs - 54 Synth Voice - 55 Orchestra Hit - 56 Trumpet - 57 Trombone - 58 Tuba - 59 Muted Trumpet - 60 French Horn - 61 Brass Section - 62 SynthBrass 1 - 63 SynthBrass 2 - 64 Soprano Sax - 65 Alto Sax - 66 Tenor Sax - 67 Baritone Sax - 68 Oboe - 69 English Horn - 70 Bassoon - 71 Clarinet - 72 Piccolo - 73 Flute - 74 Recorder - 75 Pan Flute - 76 Blown Bottle - 77 Shakuhachi - 78 Whistle - 79 Ocarina - 80 Lead 1 (square) - 81 Lead 2 (sawtooth) - 82 Lead 3 (calliope) - 83 Lead 4 (chiff) - 84 Lead 5 (charang) - 85 Lead 6 (voice) - 86 Lead 7 (fifths) - 87 Lead 8 (bass + lead) - 88 Pad 1 (new age) - 89 Pad 2 (warm) - 90 Pad 3 (polysynth) - 91 Pad 4 (choir) - 92 Pad 5 (bowed) - 93 Pad 6 (metallic) - 94 Pad 7 (halo) - 95 Pad 8 (sweep) - 96 FX 1 (rain) - 97 FX 2 (soundtrack) - 98 FX 3 (crystal) - 99 FX 4 (atmosphere) - 100 FX 5 (brightness) - 101 FX 6 (goblins) - 102 FX 7 (echoes) - 103 FX 8 (sci-fi) - 104 Sitar - 105 Banjo - 106 Shamisen - 107 Koto - 108 Kalimba - 109 Bagpipe - 110 Fiddle - 111 Shanai - 112 Tinkle Bell - 113 Agogo - 114 Steel Drums - 115 Woodblock - 116 Taiko Drum - 117 Melodic Tom - 118 Synth Drum - 119 Reverse Cymbal - 120 Guitar Fret Noise - 121 Breath Noise - 122 Seashore - 123 Bird Tweet - 124 Telephone Ring - 125 Helicopter - 126 Applause - 127 Gunshot - - */ - - return getid3_lib::EmbeddedLookup($instrumentid, $begin, __LINE__, __FILE__, 'GeneralMIDIinstrument'); - } - - public function GeneralMIDIpercussionLookup($instrumentid) { - - $begin = __LINE__; - - /** This is not a comment! - - 35 Acoustic Bass Drum - 36 Bass Drum 1 - 37 Side Stick - 38 Acoustic Snare - 39 Hand Clap - 40 Electric Snare - 41 Low Floor Tom - 42 Closed Hi-Hat - 43 High Floor Tom - 44 Pedal Hi-Hat - 45 Low Tom - 46 Open Hi-Hat - 47 Low-Mid Tom - 48 Hi-Mid Tom - 49 Crash Cymbal 1 - 50 High Tom - 51 Ride Cymbal 1 - 52 Chinese Cymbal - 53 Ride Bell - 54 Tambourine - 55 Splash Cymbal - 56 Cowbell - 57 Crash Cymbal 2 - 59 Ride Cymbal 2 - 60 Hi Bongo - 61 Low Bongo - 62 Mute Hi Conga - 63 Open Hi Conga - 64 Low Conga - 65 High Timbale - 66 Low Timbale - 67 High Agogo - 68 Low Agogo - 69 Cabasa - 70 Maracas - 71 Short Whistle - 72 Long Whistle - 73 Short Guiro - 74 Long Guiro - 75 Claves - 76 Hi Wood Block - 77 Low Wood Block - 78 Mute Cuica - 79 Open Cuica - 80 Mute Triangle - 81 Open Triangle - - */ - - return getid3_lib::EmbeddedLookup($instrumentid, $begin, __LINE__, __FILE__, 'GeneralMIDIpercussion'); - } - + public $scanwholefile = true; + + public function Analyze() + { + $info = &$this->getid3->info; + + // shortcut + $info['midi']['raw'] = []; + $thisfile_midi = &$info['midi']; + $thisfile_midi_raw = &$thisfile_midi['raw']; + + $info['fileformat'] = 'midi'; + $info['audio']['dataformat'] = 'midi'; + + $this->fseek($info['avdataoffset']); + $MIDIdata = $this->fread($this->getid3->fread_buffer_size()); + $offset = 0; + $MIDIheaderID = substr($MIDIdata, $offset, 4); // 'MThd' + if ($MIDIheaderID != GETID3_MIDI_MAGIC_MTHD) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes(GETID3_MIDI_MAGIC_MTHD).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($MIDIheaderID).'"'); + unset($info['fileformat']); + + return false; + } + $offset += 4; + $thisfile_midi_raw['headersize'] = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 4)); + $offset += 4; + $thisfile_midi_raw['fileformat'] = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 2)); + $offset += 2; + $thisfile_midi_raw['tracks'] = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 2)); + $offset += 2; + $thisfile_midi_raw['ticksperqnote'] = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 2)); + $offset += 2; + + for ($i = 0; $i < $thisfile_midi_raw['tracks']; $i++) { + while ((strlen($MIDIdata) - $offset) < 8) { + if ($buffer = $this->fread($this->getid3->fread_buffer_size())) { + $MIDIdata .= $buffer; + } else { + $this->warning('only processed '.($i - 1).' of '.$thisfile_midi_raw['tracks'].' tracks'); + $this->error('Unabled to read more file data at '.$this->ftell().' (trying to seek to : '.$offset.'), was expecting at least 8 more bytes'); + + return false; + } + } + $trackID = substr($MIDIdata, $offset, 4); + $offset += 4; + if ($trackID == GETID3_MIDI_MAGIC_MTRK) { + $tracksize = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 4)); + $offset += 4; + //$thisfile_midi['tracks'][$i]['size'] = $tracksize; + $trackdataarray[$i] = substr($MIDIdata, $offset, $tracksize); + $offset += $tracksize; + } else { + $this->error('Expecting "'.getid3_lib::PrintHexBytes(GETID3_MIDI_MAGIC_MTRK).'" at '.($offset - 4).', found "'.getid3_lib::PrintHexBytes($trackID).'" instead'); + + return false; + } + } + + if (! isset($trackdataarray) || ! is_array($trackdataarray)) { + $this->error('Cannot find MIDI track information'); + unset($thisfile_midi); + unset($info['fileformat']); + + return false; + } + + if ($this->scanwholefile) { // this can take quite a long time, so have the option to bypass it if speed is very important + $thisfile_midi['totalticks'] = 0; + $info['playtime_seconds'] = 0; + $CurrentMicroSecondsPerBeat = 500000; // 120 beats per minute; 60,000,000 microseconds per minute -> 500,000 microseconds per beat + $CurrentBeatsPerMinute = 120; // 120 beats per minute; 60,000,000 microseconds per minute -> 500,000 microseconds per beat + $MicroSecondsPerQuarterNoteAfter = []; + + foreach ($trackdataarray as $tracknumber => $trackdata) { + $eventsoffset = 0; + $LastIssuedMIDIcommand = 0; + $LastIssuedMIDIchannel = 0; + $CumulativeDeltaTime = 0; + $TicksAtCurrentBPM = 0; + while ($eventsoffset < strlen($trackdata)) { + $eventid = 0; + if (isset($MIDIevents[$tracknumber]) && is_array($MIDIevents[$tracknumber])) { + $eventid = count($MIDIevents[$tracknumber]); + } + $deltatime = 0; + for ($i = 0; $i < 4; $i++) { + $deltatimebyte = ord(substr($trackdata, $eventsoffset++, 1)); + $deltatime = ($deltatime << 7) + ($deltatimebyte & 0x7F); + if ($deltatimebyte & 0x80) { + // another byte follows + } else { + break; + } + } + $CumulativeDeltaTime += $deltatime; + $TicksAtCurrentBPM += $deltatime; + $MIDIevents[$tracknumber][$eventid]['deltatime'] = $deltatime; + $MIDI_event_channel = ord(substr($trackdata, $eventsoffset++, 1)); + if ($MIDI_event_channel & 0x80) { + // OK, normal event - MIDI command has MSB set + $LastIssuedMIDIcommand = $MIDI_event_channel >> 4; + $LastIssuedMIDIchannel = $MIDI_event_channel & 0x0F; + } else { + // running event - assume last command + $eventsoffset--; + } + $MIDIevents[$tracknumber][$eventid]['eventid'] = $LastIssuedMIDIcommand; + $MIDIevents[$tracknumber][$eventid]['channel'] = $LastIssuedMIDIchannel; + if ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x08) { // Note off (key is released) + + $notenumber = ord(substr($trackdata, $eventsoffset++, 1)); + $velocity = ord(substr($trackdata, $eventsoffset++, 1)); + } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x09) { // Note on (key is pressed) + + $notenumber = ord(substr($trackdata, $eventsoffset++, 1)); + $velocity = ord(substr($trackdata, $eventsoffset++, 1)); + } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0A) { // Key after-touch + + $notenumber = ord(substr($trackdata, $eventsoffset++, 1)); + $velocity = ord(substr($trackdata, $eventsoffset++, 1)); + } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0B) { // Control Change + + $controllernum = ord(substr($trackdata, $eventsoffset++, 1)); + $newvalue = ord(substr($trackdata, $eventsoffset++, 1)); + } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0C) { // Program (patch) change + + $newprogramnum = ord(substr($trackdata, $eventsoffset++, 1)); + + $thisfile_midi_raw['track'][$tracknumber]['instrumentid'] = $newprogramnum; + if ($tracknumber == 10) { + $thisfile_midi_raw['track'][$tracknumber]['instrument'] = $this->GeneralMIDIpercussionLookup($newprogramnum); + } else { + $thisfile_midi_raw['track'][$tracknumber]['instrument'] = $this->GeneralMIDIinstrumentLookup($newprogramnum); + } + } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0D) { // Channel after-touch + + $channelnumber = ord(substr($trackdata, $eventsoffset++, 1)); + } elseif ($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0E) { // Pitch wheel change (2000H is normal or no change) + + $changeLSB = ord(substr($trackdata, $eventsoffset++, 1)); + $changeMSB = ord(substr($trackdata, $eventsoffset++, 1)); + $pitchwheelchange = (($changeMSB & 0x7F) << 7) & ($changeLSB & 0x7F); + } elseif (($MIDIevents[$tracknumber][$eventid]['eventid'] == 0x0F) && ($MIDIevents[$tracknumber][$eventid]['channel'] == 0x0F)) { + $METAeventCommand = ord(substr($trackdata, $eventsoffset++, 1)); + $METAeventLength = ord(substr($trackdata, $eventsoffset++, 1)); + $METAeventData = substr($trackdata, $eventsoffset, $METAeventLength); + $eventsoffset += $METAeventLength; + switch ($METAeventCommand) { + case 0x00: // Set track sequence number + $track_sequence_number = getid3_lib::BigEndian2Int(substr($METAeventData, 0, $METAeventLength)); + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['seqno'] = $track_sequence_number; + break; + + case 0x01: // Text: generic + $text_generic = substr($METAeventData, 0, $METAeventLength); + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['text'] = $text_generic; + $thisfile_midi['comments']['comment'][] = $text_generic; + break; + + case 0x02: // Text: copyright + $text_copyright = substr($METAeventData, 0, $METAeventLength); + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['copyright'] = $text_copyright; + $thisfile_midi['comments']['copyright'][] = $text_copyright; + break; + + case 0x03: // Text: track name + $text_trackname = substr($METAeventData, 0, $METAeventLength); + $thisfile_midi_raw['track'][$tracknumber]['name'] = $text_trackname; + break; + + case 0x04: // Text: track instrument name + $text_instrument = substr($METAeventData, 0, $METAeventLength); + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['instrument'] = $text_instrument; + break; + + case 0x05: // Text: lyrics + $text_lyrics = substr($METAeventData, 0, $METAeventLength); + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['lyrics'] = $text_lyrics; + if (! isset($thisfile_midi['lyrics'])) { + $thisfile_midi['lyrics'] = ''; + } + $thisfile_midi['lyrics'] .= $text_lyrics."\n"; + break; + + case 0x06: // Text: marker + $text_marker = substr($METAeventData, 0, $METAeventLength); + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['marker'] = $text_marker; + break; + + case 0x07: // Text: cue point + $text_cuepoint = substr($METAeventData, 0, $METAeventLength); + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['cuepoint'] = $text_cuepoint; + break; + + case 0x2F: // End Of Track + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['EOT'] = $CumulativeDeltaTime; + break; + + case 0x51: // Tempo: microseconds / quarter note + $CurrentMicroSecondsPerBeat = getid3_lib::BigEndian2Int(substr($METAeventData, 0, $METAeventLength)); + if ($CurrentMicroSecondsPerBeat == 0) { + $this->error('Corrupt MIDI file: CurrentMicroSecondsPerBeat == zero'); + + return false; + } + $thisfile_midi_raw['events'][$tracknumber][$CumulativeDeltaTime]['us_qnote'] = $CurrentMicroSecondsPerBeat; + $CurrentBeatsPerMinute = (1000000 / $CurrentMicroSecondsPerBeat) * 60; + $MicroSecondsPerQuarterNoteAfter[$CumulativeDeltaTime] = $CurrentMicroSecondsPerBeat; + $TicksAtCurrentBPM = 0; + break; + + case 0x58: // Time signature + $timesig_numerator = getid3_lib::BigEndian2Int($METAeventData[0]); + $timesig_denominator = pow(2, getid3_lib::BigEndian2Int($METAeventData[1])); // $02 -> x/4, $03 -> x/8, etc + $timesig_32inqnote = getid3_lib::BigEndian2Int($METAeventData[2]); // number of 32nd notes to the quarter note + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['timesig_32inqnote'] = $timesig_32inqnote; + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['timesig_numerator'] = $timesig_numerator; + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['timesig_denominator'] = $timesig_denominator; + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['timesig_text'] = $timesig_numerator.'/'.$timesig_denominator; + $thisfile_midi['timesignature'][] = $timesig_numerator.'/'.$timesig_denominator; + break; + + case 0x59: // Keysignature + $keysig_sharpsflats = getid3_lib::BigEndian2Int($METAeventData[0]); + if ($keysig_sharpsflats & 0x80) { + // (-7 -> 7 flats, 0 ->key of C, 7 -> 7 sharps) + $keysig_sharpsflats -= 256; + } + + $keysig_majorminor = getid3_lib::BigEndian2Int($METAeventData[1]); // 0 -> major, 1 -> minor + $keysigs = [-7=>'Cb', -6=>'Gb', -5=>'Db', -4=>'Ab', -3=>'Eb', -2=>'Bb', -1=>'F', 0=>'C', 1=>'G', 2=>'D', 3=>'A', 4=>'E', 5=>'B', 6=>'F#', 7=>'C#']; + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_sharps'] = (($keysig_sharpsflats > 0) ? abs($keysig_sharpsflats) : 0); + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_flats'] = (($keysig_sharpsflats < 0) ? abs($keysig_sharpsflats) : 0); + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_minor'] = (bool) $keysig_majorminor; + //$thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_text'] = $keysigs[$keysig_sharpsflats].' '.($thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_minor'] ? 'minor' : 'major'); + + // $keysigs[$keysig_sharpsflats] gets an int key (correct) - $keysigs["$keysig_sharpsflats"] gets a string key (incorrect) + $thisfile_midi['keysignature'][] = $keysigs[$keysig_sharpsflats].' '.((bool) $keysig_majorminor ? 'minor' : 'major'); + break; + + case 0x7F: // Sequencer specific information + $custom_data = substr($METAeventData, 0, $METAeventLength); + break; + + default: + $this->warning('Unhandled META Event Command: '.$METAeventCommand); + break; + } + } else { + $this->warning('Unhandled MIDI Event ID: '.$MIDIevents[$tracknumber][$eventid]['eventid'].' + Channel ID: '.$MIDIevents[$tracknumber][$eventid]['channel']); + } + } + if (($tracknumber > 0) || (count($trackdataarray) == 1)) { + $thisfile_midi['totalticks'] = max($thisfile_midi['totalticks'], $CumulativeDeltaTime); + } + } + $previoustickoffset = null; + + ksort($MicroSecondsPerQuarterNoteAfter); + foreach ($MicroSecondsPerQuarterNoteAfter as $tickoffset => $microsecondsperbeat) { + if (is_null($previoustickoffset)) { + $prevmicrosecondsperbeat = $microsecondsperbeat; + $previoustickoffset = $tickoffset; + continue; + } + if ($thisfile_midi['totalticks'] > $tickoffset) { + if ($thisfile_midi_raw['ticksperqnote'] == 0) { + $this->error('Corrupt MIDI file: ticksperqnote == zero'); + + return false; + } + + $info['playtime_seconds'] += (($tickoffset - $previoustickoffset) / $thisfile_midi_raw['ticksperqnote']) * ($prevmicrosecondsperbeat / 1000000); + + $prevmicrosecondsperbeat = $microsecondsperbeat; + $previoustickoffset = $tickoffset; + } + } + if ($thisfile_midi['totalticks'] > $previoustickoffset) { + if ($thisfile_midi_raw['ticksperqnote'] == 0) { + $this->error('Corrupt MIDI file: ticksperqnote == zero'); + + return false; + } + + $info['playtime_seconds'] += (($thisfile_midi['totalticks'] - $previoustickoffset) / $thisfile_midi_raw['ticksperqnote']) * ($microsecondsperbeat / 1000000); + } + } + + if (! empty($info['playtime_seconds'])) { + $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + } + + if (! empty($thisfile_midi['lyrics'])) { + $thisfile_midi['comments']['lyrics'][] = $thisfile_midi['lyrics']; + } + + return true; + } + + public function GeneralMIDIinstrumentLookup($instrumentid) + { + $begin = __LINE__; + + /** This is not a comment! + + 0 Acoustic Grand + 1 Bright Acoustic + 2 Electric Grand + 3 Honky-Tonk + 4 Electric Piano 1 + 5 Electric Piano 2 + 6 Harpsichord + 7 Clavier + 8 Celesta + 9 Glockenspiel + 10 Music Box + 11 Vibraphone + 12 Marimba + 13 Xylophone + 14 Tubular Bells + 15 Dulcimer + 16 Drawbar Organ + 17 Percussive Organ + 18 Rock Organ + 19 Church Organ + 20 Reed Organ + 21 Accordian + 22 Harmonica + 23 Tango Accordian + 24 Acoustic Guitar (nylon) + 25 Acoustic Guitar (steel) + 26 Electric Guitar (jazz) + 27 Electric Guitar (clean) + 28 Electric Guitar (muted) + 29 Overdriven Guitar + 30 Distortion Guitar + 31 Guitar Harmonics + 32 Acoustic Bass + 33 Electric Bass (finger) + 34 Electric Bass (pick) + 35 Fretless Bass + 36 Slap Bass 1 + 37 Slap Bass 2 + 38 Synth Bass 1 + 39 Synth Bass 2 + 40 Violin + 41 Viola + 42 Cello + 43 Contrabass + 44 Tremolo Strings + 45 Pizzicato Strings + 46 Orchestral Strings + 47 Timpani + 48 String Ensemble 1 + 49 String Ensemble 2 + 50 SynthStrings 1 + 51 SynthStrings 2 + 52 Choir Aahs + 53 Voice Oohs + 54 Synth Voice + 55 Orchestra Hit + 56 Trumpet + 57 Trombone + 58 Tuba + 59 Muted Trumpet + 60 French Horn + 61 Brass Section + 62 SynthBrass 1 + 63 SynthBrass 2 + 64 Soprano Sax + 65 Alto Sax + 66 Tenor Sax + 67 Baritone Sax + 68 Oboe + 69 English Horn + 70 Bassoon + 71 Clarinet + 72 Piccolo + 73 Flute + 74 Recorder + 75 Pan Flute + 76 Blown Bottle + 77 Shakuhachi + 78 Whistle + 79 Ocarina + 80 Lead 1 (square) + 81 Lead 2 (sawtooth) + 82 Lead 3 (calliope) + 83 Lead 4 (chiff) + 84 Lead 5 (charang) + 85 Lead 6 (voice) + 86 Lead 7 (fifths) + 87 Lead 8 (bass + lead) + 88 Pad 1 (new age) + 89 Pad 2 (warm) + 90 Pad 3 (polysynth) + 91 Pad 4 (choir) + 92 Pad 5 (bowed) + 93 Pad 6 (metallic) + 94 Pad 7 (halo) + 95 Pad 8 (sweep) + 96 FX 1 (rain) + 97 FX 2 (soundtrack) + 98 FX 3 (crystal) + 99 FX 4 (atmosphere) + 100 FX 5 (brightness) + 101 FX 6 (goblins) + 102 FX 7 (echoes) + 103 FX 8 (sci-fi) + 104 Sitar + 105 Banjo + 106 Shamisen + 107 Koto + 108 Kalimba + 109 Bagpipe + 110 Fiddle + 111 Shanai + 112 Tinkle Bell + 113 Agogo + 114 Steel Drums + 115 Woodblock + 116 Taiko Drum + 117 Melodic Tom + 118 Synth Drum + 119 Reverse Cymbal + 120 Guitar Fret Noise + 121 Breath Noise + 122 Seashore + 123 Bird Tweet + 124 Telephone Ring + 125 Helicopter + 126 Applause + 127 Gunshot + */ + + return getid3_lib::EmbeddedLookup($instrumentid, $begin, __LINE__, __FILE__, 'GeneralMIDIinstrument'); + } + + public function GeneralMIDIpercussionLookup($instrumentid) + { + $begin = __LINE__; + + /** This is not a comment! + + 35 Acoustic Bass Drum + 36 Bass Drum 1 + 37 Side Stick + 38 Acoustic Snare + 39 Hand Clap + 40 Electric Snare + 41 Low Floor Tom + 42 Closed Hi-Hat + 43 High Floor Tom + 44 Pedal Hi-Hat + 45 Low Tom + 46 Open Hi-Hat + 47 Low-Mid Tom + 48 Hi-Mid Tom + 49 Crash Cymbal 1 + 50 High Tom + 51 Ride Cymbal 1 + 52 Chinese Cymbal + 53 Ride Bell + 54 Tambourine + 55 Splash Cymbal + 56 Cowbell + 57 Crash Cymbal 2 + 59 Ride Cymbal 2 + 60 Hi Bongo + 61 Low Bongo + 62 Mute Hi Conga + 63 Open Hi Conga + 64 Low Conga + 65 High Timbale + 66 Low Timbale + 67 High Agogo + 68 Low Agogo + 69 Cabasa + 70 Maracas + 71 Short Whistle + 72 Long Whistle + 73 Short Guiro + 74 Long Guiro + 75 Claves + 76 Hi Wood Block + 77 Low Wood Block + 78 Mute Cuica + 79 Open Cuica + 80 Mute Triangle + 81 Open Triangle + */ + + return getid3_lib::EmbeddedLookup($instrumentid, $begin, __LINE__, __FILE__, 'GeneralMIDIpercussion'); + } } diff --git a/app/Library/getid3/getid3/module.audio.mod.php b/app/Library/getid3/getid3/module.audio.mod.php index 4b888ecd..e6b41327 100644 --- a/app/Library/getid3/getid3/module.audio.mod.php +++ b/app/Library/getid3/getid3/module.audio.mod.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,86 +15,96 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_mod extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $fileheader = $this->fread(1088); + if (preg_match('#^IMPM#', $fileheader)) { + return $this->getITheaderFilepointer(); + } elseif (preg_match('#^Extended Module#', $fileheader)) { + return $this->getXMheaderFilepointer(); + } elseif (preg_match('#^.{44}SCRM#', $fileheader)) { + return $this->getS3MheaderFilepointer(); + } elseif (preg_match('#^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)#', $fileheader)) { + return $this->getMODheaderFilepointer(); + } + $this->error('This is not a known type of MOD file'); - public function Analyze() { - $info = &$this->getid3->info; - $this->fseek($info['avdataoffset']); - $fileheader = $this->fread(1088); - if (preg_match('#^IMPM#', $fileheader)) { - return $this->getITheaderFilepointer(); - } elseif (preg_match('#^Extended Module#', $fileheader)) { - return $this->getXMheaderFilepointer(); - } elseif (preg_match('#^.{44}SCRM#', $fileheader)) { - return $this->getS3MheaderFilepointer(); - } elseif (preg_match('#^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)#', $fileheader)) { - return $this->getMODheaderFilepointer(); - } - $this->error('This is not a known type of MOD file'); - return false; - } + return false; + } + public function getMODheaderFilepointer() + { + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset'] + 1080); + $FormatID = $this->fread(4); + if (! preg_match('#^(M.K.|[5-9]CHN|[1-3][0-9]CH)$#', $FormatID)) { + $this->error('This is not a known type of MOD file'); - public function getMODheaderFilepointer() { - $info = &$this->getid3->info; - $this->fseek($info['avdataoffset'] + 1080); - $FormatID = $this->fread(4); - if (!preg_match('#^(M.K.|[5-9]CHN|[1-3][0-9]CH)$#', $FormatID)) { - $this->error('This is not a known type of MOD file'); - return false; - } + return false; + } - $info['fileformat'] = 'mod'; + $info['fileformat'] = 'mod'; - $this->error('MOD parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); - return false; - } + $this->error('MOD parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); - public function getXMheaderFilepointer() { - $info = &$this->getid3->info; - $this->fseek($info['avdataoffset']); - $FormatID = $this->fread(15); - if (!preg_match('#^Extended Module$#', $FormatID)) { - $this->error('This is not a known type of XM-MOD file'); - return false; - } + return false; + } - $info['fileformat'] = 'xm'; + public function getXMheaderFilepointer() + { + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $FormatID = $this->fread(15); + if (! preg_match('#^Extended Module$#', $FormatID)) { + $this->error('This is not a known type of XM-MOD file'); - $this->error('XM-MOD parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); - return false; - } + return false; + } - public function getS3MheaderFilepointer() { - $info = &$this->getid3->info; - $this->fseek($info['avdataoffset'] + 44); - $FormatID = $this->fread(4); - if (!preg_match('#^SCRM$#', $FormatID)) { - $this->error('This is not a ScreamTracker MOD file'); - return false; - } + $info['fileformat'] = 'xm'; - $info['fileformat'] = 's3m'; + $this->error('XM-MOD parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); - $this->error('ScreamTracker parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); - return false; - } + return false; + } - public function getITheaderFilepointer() { - $info = &$this->getid3->info; - $this->fseek($info['avdataoffset']); - $FormatID = $this->fread(4); - if (!preg_match('#^IMPM$#', $FormatID)) { - $this->error('This is not an ImpulseTracker MOD file'); - return false; - } + public function getS3MheaderFilepointer() + { + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset'] + 44); + $FormatID = $this->fread(4); + if (! preg_match('#^SCRM$#', $FormatID)) { + $this->error('This is not a ScreamTracker MOD file'); - $info['fileformat'] = 'it'; + return false; + } - $this->error('ImpulseTracker parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); - return false; - } + $info['fileformat'] = 's3m'; + $this->error('ScreamTracker parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); + + return false; + } + + public function getITheaderFilepointer() + { + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $FormatID = $this->fread(4); + if (! preg_match('#^IMPM$#', $FormatID)) { + $this->error('This is not an ImpulseTracker MOD file'); + + return false; + } + + $info['fileformat'] = 'it'; + + $this->error('ImpulseTracker parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); + + return false; + } } diff --git a/app/Library/getid3/getid3/module.audio.monkey.php b/app/Library/getid3/getid3/module.audio.monkey.php index afa2eaf2..e5fbd32c 100644 --- a/app/Library/getid3/getid3/module.audio.monkey.php +++ b/app/Library/getid3/getid3/module.audio.monkey.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,191 +15,194 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_monkey extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + // based loosely on code from TMonkey by Jurgen Faul + // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html - // based loosely on code from TMonkey by Jurgen Faul - // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html + $info['fileformat'] = 'mac'; + $info['audio']['dataformat'] = 'mac'; + $info['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['lossless'] = true; - $info['fileformat'] = 'mac'; - $info['audio']['dataformat'] = 'mac'; - $info['audio']['bitrate_mode'] = 'vbr'; - $info['audio']['lossless'] = true; + $info['monkeys_audio']['raw'] = []; + $thisfile_monkeysaudio = &$info['monkeys_audio']; + $thisfile_monkeysaudio_raw = &$thisfile_monkeysaudio['raw']; - $info['monkeys_audio']['raw'] = array(); - $thisfile_monkeysaudio = &$info['monkeys_audio']; - $thisfile_monkeysaudio_raw = &$thisfile_monkeysaudio['raw']; + $this->fseek($info['avdataoffset']); + $MACheaderData = $this->fread(74); - $this->fseek($info['avdataoffset']); - $MACheaderData = $this->fread(74); + $thisfile_monkeysaudio_raw['magic'] = substr($MACheaderData, 0, 4); + $magic = 'MAC '; + if ($thisfile_monkeysaudio_raw['magic'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($thisfile_monkeysaudio_raw['magic']).'"'); + unset($info['fileformat']); - $thisfile_monkeysaudio_raw['magic'] = substr($MACheaderData, 0, 4); - $magic = 'MAC '; - if ($thisfile_monkeysaudio_raw['magic'] != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($thisfile_monkeysaudio_raw['magic']).'"'); - unset($info['fileformat']); - return false; - } - $thisfile_monkeysaudio_raw['nVersion'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 4, 2)); // appears to be uint32 in 3.98+ + return false; + } + $thisfile_monkeysaudio_raw['nVersion'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 4, 2)); // appears to be uint32 in 3.98+ - if ($thisfile_monkeysaudio_raw['nVersion'] < 3980) { - $thisfile_monkeysaudio_raw['nCompressionLevel'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 6, 2)); - $thisfile_monkeysaudio_raw['nFormatFlags'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 8, 2)); - $thisfile_monkeysaudio_raw['nChannels'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 10, 2)); - $thisfile_monkeysaudio_raw['nSampleRate'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 12, 4)); - $thisfile_monkeysaudio_raw['nHeaderDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 16, 4)); - $thisfile_monkeysaudio_raw['nWAVTerminatingBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 20, 4)); - $thisfile_monkeysaudio_raw['nTotalFrames'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 24, 4)); - $thisfile_monkeysaudio_raw['nFinalFrameSamples'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 28, 4)); - $thisfile_monkeysaudio_raw['nPeakLevel'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 32, 4)); - $thisfile_monkeysaudio_raw['nSeekElements'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 38, 2)); - $offset = 8; - } else { - $offset = 8; - // APE_DESCRIPTOR - $thisfile_monkeysaudio_raw['nDescriptorBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); - $offset += 4; - $thisfile_monkeysaudio_raw['nHeaderBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); - $offset += 4; - $thisfile_monkeysaudio_raw['nSeekTableBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); - $offset += 4; - $thisfile_monkeysaudio_raw['nHeaderDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); - $offset += 4; - $thisfile_monkeysaudio_raw['nAPEFrameDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); - $offset += 4; - $thisfile_monkeysaudio_raw['nAPEFrameDataBytesHigh'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); - $offset += 4; - $thisfile_monkeysaudio_raw['nTerminatingDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); - $offset += 4; - $thisfile_monkeysaudio_raw['cFileMD5'] = substr($MACheaderData, $offset, 16); - $offset += 16; + if ($thisfile_monkeysaudio_raw['nVersion'] < 3980) { + $thisfile_monkeysaudio_raw['nCompressionLevel'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 6, 2)); + $thisfile_monkeysaudio_raw['nFormatFlags'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 8, 2)); + $thisfile_monkeysaudio_raw['nChannels'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 10, 2)); + $thisfile_monkeysaudio_raw['nSampleRate'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 12, 4)); + $thisfile_monkeysaudio_raw['nHeaderDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 16, 4)); + $thisfile_monkeysaudio_raw['nWAVTerminatingBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 20, 4)); + $thisfile_monkeysaudio_raw['nTotalFrames'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 24, 4)); + $thisfile_monkeysaudio_raw['nFinalFrameSamples'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 28, 4)); + $thisfile_monkeysaudio_raw['nPeakLevel'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 32, 4)); + $thisfile_monkeysaudio_raw['nSeekElements'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 38, 2)); + $offset = 8; + } else { + $offset = 8; + // APE_DESCRIPTOR + $thisfile_monkeysaudio_raw['nDescriptorBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); + $offset += 4; + $thisfile_monkeysaudio_raw['nHeaderBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); + $offset += 4; + $thisfile_monkeysaudio_raw['nSeekTableBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); + $offset += 4; + $thisfile_monkeysaudio_raw['nHeaderDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); + $offset += 4; + $thisfile_monkeysaudio_raw['nAPEFrameDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); + $offset += 4; + $thisfile_monkeysaudio_raw['nAPEFrameDataBytesHigh'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); + $offset += 4; + $thisfile_monkeysaudio_raw['nTerminatingDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); + $offset += 4; + $thisfile_monkeysaudio_raw['cFileMD5'] = substr($MACheaderData, $offset, 16); + $offset += 16; - // APE_HEADER - $thisfile_monkeysaudio_raw['nCompressionLevel'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2)); - $offset += 2; - $thisfile_monkeysaudio_raw['nFormatFlags'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2)); - $offset += 2; - $thisfile_monkeysaudio_raw['nBlocksPerFrame'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); - $offset += 4; - $thisfile_monkeysaudio_raw['nFinalFrameBlocks'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); - $offset += 4; - $thisfile_monkeysaudio_raw['nTotalFrames'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); - $offset += 4; - $thisfile_monkeysaudio_raw['nBitsPerSample'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2)); - $offset += 2; - $thisfile_monkeysaudio_raw['nChannels'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2)); - $offset += 2; - $thisfile_monkeysaudio_raw['nSampleRate'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); - $offset += 4; - } + // APE_HEADER + $thisfile_monkeysaudio_raw['nCompressionLevel'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2)); + $offset += 2; + $thisfile_monkeysaudio_raw['nFormatFlags'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2)); + $offset += 2; + $thisfile_monkeysaudio_raw['nBlocksPerFrame'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); + $offset += 4; + $thisfile_monkeysaudio_raw['nFinalFrameBlocks'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); + $offset += 4; + $thisfile_monkeysaudio_raw['nTotalFrames'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); + $offset += 4; + $thisfile_monkeysaudio_raw['nBitsPerSample'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2)); + $offset += 2; + $thisfile_monkeysaudio_raw['nChannels'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2)); + $offset += 2; + $thisfile_monkeysaudio_raw['nSampleRate'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4)); + $offset += 4; + } - $thisfile_monkeysaudio['flags']['8-bit'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0001); - $thisfile_monkeysaudio['flags']['crc-32'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0002); - $thisfile_monkeysaudio['flags']['peak_level'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0004); - $thisfile_monkeysaudio['flags']['24-bit'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0008); - $thisfile_monkeysaudio['flags']['seek_elements'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0010); - $thisfile_monkeysaudio['flags']['no_wav_header'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0020); - $thisfile_monkeysaudio['version'] = $thisfile_monkeysaudio_raw['nVersion'] / 1000; - $thisfile_monkeysaudio['compression'] = $this->MonkeyCompressionLevelNameLookup($thisfile_monkeysaudio_raw['nCompressionLevel']); - if ($thisfile_monkeysaudio_raw['nVersion'] < 3980) { - $thisfile_monkeysaudio['samples_per_frame'] = $this->MonkeySamplesPerFrame($thisfile_monkeysaudio_raw['nVersion'], $thisfile_monkeysaudio_raw['nCompressionLevel']); - } - $thisfile_monkeysaudio['bits_per_sample'] = ($thisfile_monkeysaudio['flags']['24-bit'] ? 24 : ($thisfile_monkeysaudio['flags']['8-bit'] ? 8 : 16)); - $thisfile_monkeysaudio['channels'] = $thisfile_monkeysaudio_raw['nChannels']; - $info['audio']['channels'] = $thisfile_monkeysaudio['channels']; - $thisfile_monkeysaudio['sample_rate'] = $thisfile_monkeysaudio_raw['nSampleRate']; - if ($thisfile_monkeysaudio['sample_rate'] == 0) { - $this->error('Corrupt MAC file: frequency == zero'); - return false; - } - $info['audio']['sample_rate'] = $thisfile_monkeysaudio['sample_rate']; - if ($thisfile_monkeysaudio['flags']['peak_level']) { - $thisfile_monkeysaudio['peak_level'] = $thisfile_monkeysaudio_raw['nPeakLevel']; - $thisfile_monkeysaudio['peak_ratio'] = $thisfile_monkeysaudio['peak_level'] / pow(2, $thisfile_monkeysaudio['bits_per_sample'] - 1); - } - if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) { - $thisfile_monkeysaudio['samples'] = (($thisfile_monkeysaudio_raw['nTotalFrames'] - 1) * $thisfile_monkeysaudio_raw['nBlocksPerFrame']) + $thisfile_monkeysaudio_raw['nFinalFrameBlocks']; - } else { - $thisfile_monkeysaudio['samples'] = (($thisfile_monkeysaudio_raw['nTotalFrames'] - 1) * $thisfile_monkeysaudio['samples_per_frame']) + $thisfile_monkeysaudio_raw['nFinalFrameSamples']; - } - $thisfile_monkeysaudio['playtime'] = $thisfile_monkeysaudio['samples'] / $thisfile_monkeysaudio['sample_rate']; - if ($thisfile_monkeysaudio['playtime'] == 0) { - $this->error('Corrupt MAC file: playtime == zero'); - return false; - } - $info['playtime_seconds'] = $thisfile_monkeysaudio['playtime']; - $thisfile_monkeysaudio['compressed_size'] = $info['avdataend'] - $info['avdataoffset']; - $thisfile_monkeysaudio['uncompressed_size'] = $thisfile_monkeysaudio['samples'] * $thisfile_monkeysaudio['channels'] * ($thisfile_monkeysaudio['bits_per_sample'] / 8); - if ($thisfile_monkeysaudio['uncompressed_size'] == 0) { - $this->error('Corrupt MAC file: uncompressed_size == zero'); - return false; - } - $thisfile_monkeysaudio['compression_ratio'] = $thisfile_monkeysaudio['compressed_size'] / ($thisfile_monkeysaudio['uncompressed_size'] + $thisfile_monkeysaudio_raw['nHeaderDataBytes']); - $thisfile_monkeysaudio['bitrate'] = (($thisfile_monkeysaudio['samples'] * $thisfile_monkeysaudio['channels'] * $thisfile_monkeysaudio['bits_per_sample']) / $thisfile_monkeysaudio['playtime']) * $thisfile_monkeysaudio['compression_ratio']; - $info['audio']['bitrate'] = $thisfile_monkeysaudio['bitrate']; + $thisfile_monkeysaudio['flags']['8-bit'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0001); + $thisfile_monkeysaudio['flags']['crc-32'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0002); + $thisfile_monkeysaudio['flags']['peak_level'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0004); + $thisfile_monkeysaudio['flags']['24-bit'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0008); + $thisfile_monkeysaudio['flags']['seek_elements'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0010); + $thisfile_monkeysaudio['flags']['no_wav_header'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0020); + $thisfile_monkeysaudio['version'] = $thisfile_monkeysaudio_raw['nVersion'] / 1000; + $thisfile_monkeysaudio['compression'] = $this->MonkeyCompressionLevelNameLookup($thisfile_monkeysaudio_raw['nCompressionLevel']); + if ($thisfile_monkeysaudio_raw['nVersion'] < 3980) { + $thisfile_monkeysaudio['samples_per_frame'] = $this->MonkeySamplesPerFrame($thisfile_monkeysaudio_raw['nVersion'], $thisfile_monkeysaudio_raw['nCompressionLevel']); + } + $thisfile_monkeysaudio['bits_per_sample'] = ($thisfile_monkeysaudio['flags']['24-bit'] ? 24 : ($thisfile_monkeysaudio['flags']['8-bit'] ? 8 : 16)); + $thisfile_monkeysaudio['channels'] = $thisfile_monkeysaudio_raw['nChannels']; + $info['audio']['channels'] = $thisfile_monkeysaudio['channels']; + $thisfile_monkeysaudio['sample_rate'] = $thisfile_monkeysaudio_raw['nSampleRate']; + if ($thisfile_monkeysaudio['sample_rate'] == 0) { + $this->error('Corrupt MAC file: frequency == zero'); - // add size of MAC header to avdataoffset - if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) { - $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nDescriptorBytes']; - $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nHeaderBytes']; - $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nSeekTableBytes']; - $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nHeaderDataBytes']; + return false; + } + $info['audio']['sample_rate'] = $thisfile_monkeysaudio['sample_rate']; + if ($thisfile_monkeysaudio['flags']['peak_level']) { + $thisfile_monkeysaudio['peak_level'] = $thisfile_monkeysaudio_raw['nPeakLevel']; + $thisfile_monkeysaudio['peak_ratio'] = $thisfile_monkeysaudio['peak_level'] / pow(2, $thisfile_monkeysaudio['bits_per_sample'] - 1); + } + if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) { + $thisfile_monkeysaudio['samples'] = (($thisfile_monkeysaudio_raw['nTotalFrames'] - 1) * $thisfile_monkeysaudio_raw['nBlocksPerFrame']) + $thisfile_monkeysaudio_raw['nFinalFrameBlocks']; + } else { + $thisfile_monkeysaudio['samples'] = (($thisfile_monkeysaudio_raw['nTotalFrames'] - 1) * $thisfile_monkeysaudio['samples_per_frame']) + $thisfile_monkeysaudio_raw['nFinalFrameSamples']; + } + $thisfile_monkeysaudio['playtime'] = $thisfile_monkeysaudio['samples'] / $thisfile_monkeysaudio['sample_rate']; + if ($thisfile_monkeysaudio['playtime'] == 0) { + $this->error('Corrupt MAC file: playtime == zero'); - $info['avdataend'] -= $thisfile_monkeysaudio_raw['nTerminatingDataBytes']; - } else { - $info['avdataoffset'] += $offset; - } + return false; + } + $info['playtime_seconds'] = $thisfile_monkeysaudio['playtime']; + $thisfile_monkeysaudio['compressed_size'] = $info['avdataend'] - $info['avdataoffset']; + $thisfile_monkeysaudio['uncompressed_size'] = $thisfile_monkeysaudio['samples'] * $thisfile_monkeysaudio['channels'] * ($thisfile_monkeysaudio['bits_per_sample'] / 8); + if ($thisfile_monkeysaudio['uncompressed_size'] == 0) { + $this->error('Corrupt MAC file: uncompressed_size == zero'); - if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) { - if ($thisfile_monkeysaudio_raw['cFileMD5'] === str_repeat("\x00", 16)) { - //$this->warning('cFileMD5 is null'); - } else { - $info['md5_data_source'] = ''; - $md5 = $thisfile_monkeysaudio_raw['cFileMD5']; - for ($i = 0; $i < strlen($md5); $i++) { - $info['md5_data_source'] .= str_pad(dechex(ord($md5{$i})), 2, '00', STR_PAD_LEFT); - } - if (!preg_match('/^[0-9a-f]{32}$/', $info['md5_data_source'])) { - unset($info['md5_data_source']); - } - } - } + return false; + } + $thisfile_monkeysaudio['compression_ratio'] = $thisfile_monkeysaudio['compressed_size'] / ($thisfile_monkeysaudio['uncompressed_size'] + $thisfile_monkeysaudio_raw['nHeaderDataBytes']); + $thisfile_monkeysaudio['bitrate'] = (($thisfile_monkeysaudio['samples'] * $thisfile_monkeysaudio['channels'] * $thisfile_monkeysaudio['bits_per_sample']) / $thisfile_monkeysaudio['playtime']) * $thisfile_monkeysaudio['compression_ratio']; + $info['audio']['bitrate'] = $thisfile_monkeysaudio['bitrate']; + // add size of MAC header to avdataoffset + if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) { + $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nDescriptorBytes']; + $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nHeaderBytes']; + $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nSeekTableBytes']; + $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nHeaderDataBytes']; + $info['avdataend'] -= $thisfile_monkeysaudio_raw['nTerminatingDataBytes']; + } else { + $info['avdataoffset'] += $offset; + } - $info['audio']['bits_per_sample'] = $thisfile_monkeysaudio['bits_per_sample']; - $info['audio']['encoder'] = 'MAC v'.number_format($thisfile_monkeysaudio['version'], 2); - $info['audio']['encoder_options'] = ucfirst($thisfile_monkeysaudio['compression']).' compression'; + if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) { + if ($thisfile_monkeysaudio_raw['cFileMD5'] === str_repeat("\x00", 16)) { + //$this->warning('cFileMD5 is null'); + } else { + $info['md5_data_source'] = ''; + $md5 = $thisfile_monkeysaudio_raw['cFileMD5']; + for ($i = 0; $i < strlen($md5); $i++) { + $info['md5_data_source'] .= str_pad(dechex(ord($md5[$i])), 2, '00', STR_PAD_LEFT); + } + if (! preg_match('/^[0-9a-f]{32}$/', $info['md5_data_source'])) { + unset($info['md5_data_source']); + } + } + } - return true; - } + $info['audio']['bits_per_sample'] = $thisfile_monkeysaudio['bits_per_sample']; + $info['audio']['encoder'] = 'MAC v'.number_format($thisfile_monkeysaudio['version'], 2); + $info['audio']['encoder_options'] = ucfirst($thisfile_monkeysaudio['compression']).' compression'; - public function MonkeyCompressionLevelNameLookup($compressionlevel) { - static $MonkeyCompressionLevelNameLookup = array( - 0 => 'unknown', - 1000 => 'fast', - 2000 => 'normal', - 3000 => 'high', - 4000 => 'extra-high', - 5000 => 'insane' - ); - return (isset($MonkeyCompressionLevelNameLookup[$compressionlevel]) ? $MonkeyCompressionLevelNameLookup[$compressionlevel] : 'invalid'); - } + return true; + } - public function MonkeySamplesPerFrame($versionid, $compressionlevel) { - if ($versionid >= 3950) { - return 73728 * 4; - } elseif ($versionid >= 3900) { - return 73728; - } elseif (($versionid >= 3800) && ($compressionlevel == 4000)) { - return 73728; - } else { - return 9216; - } - } + public function MonkeyCompressionLevelNameLookup($compressionlevel) + { + static $MonkeyCompressionLevelNameLookup = [ + 0 => 'unknown', + 1000 => 'fast', + 2000 => 'normal', + 3000 => 'high', + 4000 => 'extra-high', + 5000 => 'insane', + ]; + return isset($MonkeyCompressionLevelNameLookup[$compressionlevel]) ? $MonkeyCompressionLevelNameLookup[$compressionlevel] : 'invalid'; + } + + public function MonkeySamplesPerFrame($versionid, $compressionlevel) + { + if ($versionid >= 3950) { + return 73728 * 4; + } elseif ($versionid >= 3900) { + return 73728; + } elseif (($versionid >= 3800) && ($compressionlevel == 4000)) { + return 73728; + } else { + return 9216; + } + } } diff --git a/app/Library/getid3/getid3/module.audio.mp3.php b/app/Library/getid3/getid3/module.audio.mp3.php index ca3ec545..c33d2014 100644 --- a/app/Library/getid3/getid3/module.audio.mp3.php +++ b/app/Library/getid3/getid3/module.audio.mp3.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,2009 +15,1982 @@ // /// ///////////////////////////////////////////////////////////////// - // number of frames to scan to determine if MPEG-audio sequence is valid // Lower this number to 5-20 for faster scanning // Increase this number to 50+ for most accurate detection of valid VBR/CBR // mpeg-audio streams define('GETID3_MP3_VALID_CHECK_FRAMES', 35); - class getid3_mp3 extends getid3_handler { - - public $allow_bruteforce = false; // forces getID3() to scan the file byte-by-byte and log all the valid audio frame headers - extremely slow, unrecommended, but may provide data from otherwise-unusuable files - - public function Analyze() { - $info = &$this->getid3->info; - - $initialOffset = $info['avdataoffset']; - - if (!$this->getOnlyMPEGaudioInfo($info['avdataoffset'])) { - if ($this->allow_bruteforce) { - $this->error('Rescanning file in BruteForce mode'); - $this->getOnlyMPEGaudioInfoBruteForce($this->getid3->fp, $info); - } - } - - - if (isset($info['mpeg']['audio']['bitrate_mode'])) { - $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); - } - - if (((isset($info['id3v2']['headerlength']) && ($info['avdataoffset'] > $info['id3v2']['headerlength'])) || (!isset($info['id3v2']) && ($info['avdataoffset'] > 0) && ($info['avdataoffset'] != $initialOffset)))) { - - $synchoffsetwarning = 'Unknown data before synch '; - if (isset($info['id3v2']['headerlength'])) { - $synchoffsetwarning .= '(ID3v2 header ends at '.$info['id3v2']['headerlength'].', then '.($info['avdataoffset'] - $info['id3v2']['headerlength']).' bytes garbage, '; - } elseif ($initialOffset > 0) { - $synchoffsetwarning .= '(should be at '.$initialOffset.', '; - } else { - $synchoffsetwarning .= '(should be at beginning of file, '; - } - $synchoffsetwarning .= 'synch detected at '.$info['avdataoffset'].')'; - if (isset($info['audio']['bitrate_mode']) && ($info['audio']['bitrate_mode'] == 'cbr')) { - - if (!empty($info['id3v2']['headerlength']) && (($info['avdataoffset'] - $info['id3v2']['headerlength']) == $info['mpeg']['audio']['framelength'])) { - - $synchoffsetwarning .= '. This is a known problem with some versions of LAME (3.90-3.92) DLL in CBR mode.'; - $info['audio']['codec'] = 'LAME'; - $CurrentDataLAMEversionString = 'LAME3.'; - - } elseif (empty($info['id3v2']['headerlength']) && ($info['avdataoffset'] == $info['mpeg']['audio']['framelength'])) { - - $synchoffsetwarning .= '. This is a known problem with some versions of LAME (3.90 - 3.92) DLL in CBR mode.'; - $info['audio']['codec'] = 'LAME'; - $CurrentDataLAMEversionString = 'LAME3.'; - - } - - } - $this->warning($synchoffsetwarning); - - } - - if (isset($info['mpeg']['audio']['LAME'])) { - $info['audio']['codec'] = 'LAME'; - if (!empty($info['mpeg']['audio']['LAME']['long_version'])) { - $info['audio']['encoder'] = rtrim($info['mpeg']['audio']['LAME']['long_version'], "\x00"); - } elseif (!empty($info['mpeg']['audio']['LAME']['short_version'])) { - $info['audio']['encoder'] = rtrim($info['mpeg']['audio']['LAME']['short_version'], "\x00"); - } - } - - $CurrentDataLAMEversionString = (!empty($CurrentDataLAMEversionString) ? $CurrentDataLAMEversionString : (isset($info['audio']['encoder']) ? $info['audio']['encoder'] : '')); - if (!empty($CurrentDataLAMEversionString) && (substr($CurrentDataLAMEversionString, 0, 6) == 'LAME3.') && !preg_match('[0-9\)]', substr($CurrentDataLAMEversionString, -1))) { - // a version number of LAME that does not end with a number like "LAME3.92" - // or with a closing parenthesis like "LAME3.88 (alpha)" - // or a version of LAME with the LAMEtag-not-filled-in-DLL-mode bug (3.90-3.92) - - // not sure what the actual last frame length will be, but will be less than or equal to 1441 - $PossiblyLongerLAMEversion_FrameLength = 1441; - - // Not sure what version of LAME this is - look in padding of last frame for longer version string - $PossibleLAMEversionStringOffset = $info['avdataend'] - $PossiblyLongerLAMEversion_FrameLength; - $this->fseek($PossibleLAMEversionStringOffset); - $PossiblyLongerLAMEversion_Data = $this->fread($PossiblyLongerLAMEversion_FrameLength); - switch (substr($CurrentDataLAMEversionString, -1)) { - case 'a': - case 'b': - // "LAME3.94a" will have a longer version string of "LAME3.94 (alpha)" for example - // need to trim off "a" to match longer string - $CurrentDataLAMEversionString = substr($CurrentDataLAMEversionString, 0, -1); - break; - } - if (($PossiblyLongerLAMEversion_String = strstr($PossiblyLongerLAMEversion_Data, $CurrentDataLAMEversionString)) !== false) { - if (substr($PossiblyLongerLAMEversion_String, 0, strlen($CurrentDataLAMEversionString)) == $CurrentDataLAMEversionString) { - $PossiblyLongerLAMEversion_NewString = substr($PossiblyLongerLAMEversion_String, 0, strspn($PossiblyLongerLAMEversion_String, 'LAME0123456789., (abcdefghijklmnopqrstuvwxyzJFSOND)')); //"LAME3.90.3" "LAME3.87 (beta 1, Sep 27 2000)" "LAME3.88 (beta)" - if (empty($info['audio']['encoder']) || (strlen($PossiblyLongerLAMEversion_NewString) > strlen($info['audio']['encoder']))) { - $info['audio']['encoder'] = $PossiblyLongerLAMEversion_NewString; - } - } - } - } - if (!empty($info['audio']['encoder'])) { - $info['audio']['encoder'] = rtrim($info['audio']['encoder'], "\x00 "); - } - - switch (isset($info['mpeg']['audio']['layer']) ? $info['mpeg']['audio']['layer'] : '') { - case 1: - case 2: - $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer']; - break; - } - if (isset($info['fileformat']) && ($info['fileformat'] == 'mp3')) { - switch ($info['audio']['dataformat']) { - case 'mp1': - case 'mp2': - case 'mp3': - $info['fileformat'] = $info['audio']['dataformat']; - break; - - default: - $this->warning('Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$info['audio']['dataformat'].'"'); - break; - } - } - - if (empty($info['fileformat'])) { - unset($info['fileformat']); - unset($info['audio']['bitrate_mode']); - unset($info['avdataoffset']); - unset($info['avdataend']); - return false; - } - - $info['mime_type'] = 'audio/mpeg'; - $info['audio']['lossless'] = false; - - // Calculate playtime - if (!isset($info['playtime_seconds']) && isset($info['audio']['bitrate']) && ($info['audio']['bitrate'] > 0)) { - $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['audio']['bitrate']; - } - - $info['audio']['encoder_options'] = $this->GuessEncoderOptions(); - - return true; - } - - - public function GuessEncoderOptions() { - // shortcuts - $info = &$this->getid3->info; - if (!empty($info['mpeg']['audio'])) { - $thisfile_mpeg_audio = &$info['mpeg']['audio']; - if (!empty($thisfile_mpeg_audio['LAME'])) { - $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio['LAME']; - } - } - - $encoder_options = ''; - static $NamedPresetBitrates = array(16, 24, 40, 56, 112, 128, 160, 192, 256); - - if (isset($thisfile_mpeg_audio['VBR_method']) && ($thisfile_mpeg_audio['VBR_method'] == 'Fraunhofer') && !empty($thisfile_mpeg_audio['VBR_quality'])) { - - $encoder_options = 'VBR q'.$thisfile_mpeg_audio['VBR_quality']; - - } elseif (!empty($thisfile_mpeg_audio_lame['preset_used']) && (!in_array($thisfile_mpeg_audio_lame['preset_used_id'], $NamedPresetBitrates))) { - - $encoder_options = $thisfile_mpeg_audio_lame['preset_used']; - - } elseif (!empty($thisfile_mpeg_audio_lame['vbr_quality'])) { - - static $KnownEncoderValues = array(); - if (empty($KnownEncoderValues)) { - - //$KnownEncoderValues[abrbitrate_minbitrate][vbr_quality][raw_vbr_method][raw_noise_shaping][raw_stereo_mode][ath_type][lowpass_frequency] = 'preset name'; - $KnownEncoderValues[0xFF][58][1][1][3][2][20500] = '--alt-preset insane'; // 3.90, 3.90.1, 3.92 - $KnownEncoderValues[0xFF][58][1][1][3][2][20600] = '--alt-preset insane'; // 3.90.2, 3.90.3, 3.91 - $KnownEncoderValues[0xFF][57][1][1][3][4][20500] = '--alt-preset insane'; // 3.94, 3.95 - $KnownEncoderValues['**'][78][3][2][3][2][19500] = '--alt-preset extreme'; // 3.90, 3.90.1, 3.92 - $KnownEncoderValues['**'][78][3][2][3][2][19600] = '--alt-preset extreme'; // 3.90.2, 3.91 - $KnownEncoderValues['**'][78][3][1][3][2][19600] = '--alt-preset extreme'; // 3.90.3 - $KnownEncoderValues['**'][78][4][2][3][2][19500] = '--alt-preset fast extreme'; // 3.90, 3.90.1, 3.92 - $KnownEncoderValues['**'][78][4][2][3][2][19600] = '--alt-preset fast extreme'; // 3.90.2, 3.90.3, 3.91 - $KnownEncoderValues['**'][78][3][2][3][4][19000] = '--alt-preset standard'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 - $KnownEncoderValues['**'][78][3][1][3][4][19000] = '--alt-preset standard'; // 3.90.3 - $KnownEncoderValues['**'][78][4][2][3][4][19000] = '--alt-preset fast standard'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 - $KnownEncoderValues['**'][78][4][1][3][4][19000] = '--alt-preset fast standard'; // 3.90.3 - $KnownEncoderValues['**'][88][4][1][3][3][19500] = '--r3mix'; // 3.90, 3.90.1, 3.92 - $KnownEncoderValues['**'][88][4][1][3][3][19600] = '--r3mix'; // 3.90.2, 3.90.3, 3.91 - $KnownEncoderValues['**'][67][4][1][3][4][18000] = '--r3mix'; // 3.94, 3.95 - $KnownEncoderValues['**'][68][3][2][3][4][18000] = '--alt-preset medium'; // 3.90.3 - $KnownEncoderValues['**'][68][4][2][3][4][18000] = '--alt-preset fast medium'; // 3.90.3 - - $KnownEncoderValues[0xFF][99][1][1][1][2][0] = '--preset studio'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 - $KnownEncoderValues[0xFF][58][2][1][3][2][20600] = '--preset studio'; // 3.90.3, 3.93.1 - $KnownEncoderValues[0xFF][58][2][1][3][2][20500] = '--preset studio'; // 3.93 - $KnownEncoderValues[0xFF][57][2][1][3][4][20500] = '--preset studio'; // 3.94, 3.95 - $KnownEncoderValues[0xC0][88][1][1][1][2][0] = '--preset cd'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 - $KnownEncoderValues[0xC0][58][2][2][3][2][19600] = '--preset cd'; // 3.90.3, 3.93.1 - $KnownEncoderValues[0xC0][58][2][2][3][2][19500] = '--preset cd'; // 3.93 - $KnownEncoderValues[0xC0][57][2][1][3][4][19500] = '--preset cd'; // 3.94, 3.95 - $KnownEncoderValues[0xA0][78][1][1][3][2][18000] = '--preset hifi'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 - $KnownEncoderValues[0xA0][58][2][2][3][2][18000] = '--preset hifi'; // 3.90.3, 3.93, 3.93.1 - $KnownEncoderValues[0xA0][57][2][1][3][4][18000] = '--preset hifi'; // 3.94, 3.95 - $KnownEncoderValues[0x80][67][1][1][3][2][18000] = '--preset tape'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 - $KnownEncoderValues[0x80][67][1][1][3][2][15000] = '--preset radio'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 - $KnownEncoderValues[0x70][67][1][1][3][2][15000] = '--preset fm'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 - $KnownEncoderValues[0x70][58][2][2][3][2][16000] = '--preset tape/radio/fm'; // 3.90.3, 3.93, 3.93.1 - $KnownEncoderValues[0x70][57][2][1][3][4][16000] = '--preset tape/radio/fm'; // 3.94, 3.95 - $KnownEncoderValues[0x38][58][2][2][0][2][10000] = '--preset voice'; // 3.90.3, 3.93, 3.93.1 - $KnownEncoderValues[0x38][57][2][1][0][4][15000] = '--preset voice'; // 3.94, 3.95 - $KnownEncoderValues[0x38][57][2][1][0][4][16000] = '--preset voice'; // 3.94a14 - $KnownEncoderValues[0x28][65][1][1][0][2][7500] = '--preset mw-us'; // 3.90, 3.90.1, 3.92 - $KnownEncoderValues[0x28][65][1][1][0][2][7600] = '--preset mw-us'; // 3.90.2, 3.91 - $KnownEncoderValues[0x28][58][2][2][0][2][7000] = '--preset mw-us'; // 3.90.3, 3.93, 3.93.1 - $KnownEncoderValues[0x28][57][2][1][0][4][10500] = '--preset mw-us'; // 3.94, 3.95 - $KnownEncoderValues[0x28][57][2][1][0][4][11200] = '--preset mw-us'; // 3.94a14 - $KnownEncoderValues[0x28][57][2][1][0][4][8800] = '--preset mw-us'; // 3.94a15 - $KnownEncoderValues[0x18][58][2][2][0][2][4000] = '--preset phon+/lw/mw-eu/sw'; // 3.90.3, 3.93.1 - $KnownEncoderValues[0x18][58][2][2][0][2][3900] = '--preset phon+/lw/mw-eu/sw'; // 3.93 - $KnownEncoderValues[0x18][57][2][1][0][4][5900] = '--preset phon+/lw/mw-eu/sw'; // 3.94, 3.95 - $KnownEncoderValues[0x18][57][2][1][0][4][6200] = '--preset phon+/lw/mw-eu/sw'; // 3.94a14 - $KnownEncoderValues[0x18][57][2][1][0][4][3200] = '--preset phon+/lw/mw-eu/sw'; // 3.94a15 - $KnownEncoderValues[0x10][58][2][2][0][2][3800] = '--preset phone'; // 3.90.3, 3.93.1 - $KnownEncoderValues[0x10][58][2][2][0][2][3700] = '--preset phone'; // 3.93 - $KnownEncoderValues[0x10][57][2][1][0][4][5600] = '--preset phone'; // 3.94, 3.95 - } - - if (isset($KnownEncoderValues[$thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']])) { - - $encoder_options = $KnownEncoderValues[$thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']]; - - } elseif (isset($KnownEncoderValues['**'][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']])) { - - $encoder_options = $KnownEncoderValues['**'][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']]; - - } elseif ($info['audio']['bitrate_mode'] == 'vbr') { - - // http://gabriel.mp3-tech.org/mp3infotag.html - // int Quality = (100 - 10 * gfp->VBR_q - gfp->quality)h - - - $LAME_V_value = 10 - ceil($thisfile_mpeg_audio_lame['vbr_quality'] / 10); - $LAME_q_value = 100 - $thisfile_mpeg_audio_lame['vbr_quality'] - ($LAME_V_value * 10); - $encoder_options = '-V'.$LAME_V_value.' -q'.$LAME_q_value; - - } elseif ($info['audio']['bitrate_mode'] == 'cbr') { - - $encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000); - - } else { - - $encoder_options = strtoupper($info['audio']['bitrate_mode']); - - } - - } elseif (!empty($thisfile_mpeg_audio_lame['bitrate_abr'])) { - - $encoder_options = 'ABR'.$thisfile_mpeg_audio_lame['bitrate_abr']; - - } elseif (!empty($info['audio']['bitrate'])) { - - if ($info['audio']['bitrate_mode'] == 'cbr') { - $encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000); - } else { - $encoder_options = strtoupper($info['audio']['bitrate_mode']); - } - - } - if (!empty($thisfile_mpeg_audio_lame['bitrate_min'])) { - $encoder_options .= ' -b'.$thisfile_mpeg_audio_lame['bitrate_min']; - } - - if (!empty($thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev']) || !empty($thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'])) { - $encoder_options .= ' --nogap'; - } - - if (!empty($thisfile_mpeg_audio_lame['lowpass_frequency'])) { - $ExplodedOptions = explode(' ', $encoder_options, 4); - if ($ExplodedOptions[0] == '--r3mix') { - $ExplodedOptions[1] = 'r3mix'; - } - switch ($ExplodedOptions[0]) { - case '--preset': - case '--alt-preset': - case '--r3mix': - if ($ExplodedOptions[1] == 'fast') { - $ExplodedOptions[1] .= ' '.$ExplodedOptions[2]; - } - switch ($ExplodedOptions[1]) { - case 'portable': - case 'medium': - case 'standard': - case 'extreme': - case 'insane': - case 'fast portable': - case 'fast medium': - case 'fast standard': - case 'fast extreme': - case 'fast insane': - case 'r3mix': - static $ExpectedLowpass = array( - 'insane|20500' => 20500, - 'insane|20600' => 20600, // 3.90.2, 3.90.3, 3.91 - 'medium|18000' => 18000, - 'fast medium|18000' => 18000, - 'extreme|19500' => 19500, // 3.90, 3.90.1, 3.92, 3.95 - 'extreme|19600' => 19600, // 3.90.2, 3.90.3, 3.91, 3.93.1 - 'fast extreme|19500' => 19500, // 3.90, 3.90.1, 3.92, 3.95 - 'fast extreme|19600' => 19600, // 3.90.2, 3.90.3, 3.91, 3.93.1 - 'standard|19000' => 19000, - 'fast standard|19000' => 19000, - 'r3mix|19500' => 19500, // 3.90, 3.90.1, 3.92 - 'r3mix|19600' => 19600, // 3.90.2, 3.90.3, 3.91 - 'r3mix|18000' => 18000, // 3.94, 3.95 - ); - if (!isset($ExpectedLowpass[$ExplodedOptions[1].'|'.$thisfile_mpeg_audio_lame['lowpass_frequency']]) && ($thisfile_mpeg_audio_lame['lowpass_frequency'] < 22050) && (round($thisfile_mpeg_audio_lame['lowpass_frequency'] / 1000) < round($thisfile_mpeg_audio['sample_rate'] / 2000))) { - $encoder_options .= ' --lowpass '.$thisfile_mpeg_audio_lame['lowpass_frequency']; - } - break; - - default: - break; - } - break; - } - } - - if (isset($thisfile_mpeg_audio_lame['raw']['source_sample_freq'])) { - if (($thisfile_mpeg_audio['sample_rate'] == 44100) && ($thisfile_mpeg_audio_lame['raw']['source_sample_freq'] != 1)) { - $encoder_options .= ' --resample 44100'; - } elseif (($thisfile_mpeg_audio['sample_rate'] == 48000) && ($thisfile_mpeg_audio_lame['raw']['source_sample_freq'] != 2)) { - $encoder_options .= ' --resample 48000'; - } elseif ($thisfile_mpeg_audio['sample_rate'] < 44100) { - switch ($thisfile_mpeg_audio_lame['raw']['source_sample_freq']) { - case 0: // <= 32000 - // may or may not be same as source frequency - ignore - break; - case 1: // 44100 - case 2: // 48000 - case 3: // 48000+ - $ExplodedOptions = explode(' ', $encoder_options, 4); - switch ($ExplodedOptions[0]) { - case '--preset': - case '--alt-preset': - switch ($ExplodedOptions[1]) { - case 'fast': - case 'portable': - case 'medium': - case 'standard': - case 'extreme': - case 'insane': - $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate']; - break; - - default: - static $ExpectedResampledRate = array( - 'phon+/lw/mw-eu/sw|16000' => 16000, - 'mw-us|24000' => 24000, // 3.95 - 'mw-us|32000' => 32000, // 3.93 - 'mw-us|16000' => 16000, // 3.92 - 'phone|16000' => 16000, - 'phone|11025' => 11025, // 3.94a15 - 'radio|32000' => 32000, // 3.94a15 - 'fm/radio|32000' => 32000, // 3.92 - 'fm|32000' => 32000, // 3.90 - 'voice|32000' => 32000); - if (!isset($ExpectedResampledRate[$ExplodedOptions[1].'|'.$thisfile_mpeg_audio['sample_rate']])) { - $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate']; - } - break; - } - break; - - case '--r3mix': - default: - $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate']; - break; - } - break; - } - } - } - if (empty($encoder_options) && !empty($info['audio']['bitrate']) && !empty($info['audio']['bitrate_mode'])) { - //$encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000); - $encoder_options = strtoupper($info['audio']['bitrate_mode']); - } - - return $encoder_options; - } - - - public function decodeMPEGaudioHeader($offset, &$info, $recursivesearch=true, $ScanAsCBR=false, $FastMPEGheaderScan=false) { - static $MPEGaudioVersionLookup; - static $MPEGaudioLayerLookup; - static $MPEGaudioBitrateLookup; - static $MPEGaudioFrequencyLookup; - static $MPEGaudioChannelModeLookup; - static $MPEGaudioModeExtensionLookup; - static $MPEGaudioEmphasisLookup; - if (empty($MPEGaudioVersionLookup)) { - $MPEGaudioVersionLookup = self::MPEGaudioVersionArray(); - $MPEGaudioLayerLookup = self::MPEGaudioLayerArray(); - $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray(); - $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray(); - $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray(); - $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray(); - $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray(); - } - - if ($this->fseek($offset) != 0) { - $this->error('decodeMPEGaudioHeader() failed to seek to next offset at '.$offset); - return false; - } - //$headerstring = $this->fread(1441); // worst-case max length = 32kHz @ 320kbps layer 3 = 1441 bytes/frame - $headerstring = $this->fread(226); // LAME header at offset 36 + 190 bytes of Xing/LAME data - - // MP3 audio frame structure: - // $aa $aa $aa $aa [$bb $bb] $cc... - // where $aa..$aa is the four-byte mpeg-audio header (below) - // $bb $bb is the optional 2-byte CRC - // and $cc... is the audio data - - $head4 = substr($headerstring, 0, 4); - static $MPEGaudioHeaderDecodeCache = array(); - if (isset($MPEGaudioHeaderDecodeCache[$head4])) { - $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4]; - } else { - $MPEGheaderRawArray = self::MPEGaudioHeaderDecode($head4); - $MPEGaudioHeaderDecodeCache[$head4] = $MPEGheaderRawArray; - } - - static $MPEGaudioHeaderValidCache = array(); - if (!isset($MPEGaudioHeaderValidCache[$head4])) { // Not in cache - //$MPEGaudioHeaderValidCache[$head4] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, true); // allow badly-formatted freeformat (from LAME 3.90 - 3.93.1) - $MPEGaudioHeaderValidCache[$head4] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, false); - } - - // shortcut - if (!isset($info['mpeg']['audio'])) { - $info['mpeg']['audio'] = array(); - } - $thisfile_mpeg_audio = &$info['mpeg']['audio']; - - - if ($MPEGaudioHeaderValidCache[$head4]) { - $thisfile_mpeg_audio['raw'] = $MPEGheaderRawArray; - } else { - $this->error('Invalid MPEG audio header ('.getid3_lib::PrintHexBytes($head4).') at offset '.$offset); - return false; - } - - if (!$FastMPEGheaderScan) { - $thisfile_mpeg_audio['version'] = $MPEGaudioVersionLookup[$thisfile_mpeg_audio['raw']['version']]; - $thisfile_mpeg_audio['layer'] = $MPEGaudioLayerLookup[$thisfile_mpeg_audio['raw']['layer']]; - - $thisfile_mpeg_audio['channelmode'] = $MPEGaudioChannelModeLookup[$thisfile_mpeg_audio['raw']['channelmode']]; - $thisfile_mpeg_audio['channels'] = (($thisfile_mpeg_audio['channelmode'] == 'mono') ? 1 : 2); - $thisfile_mpeg_audio['sample_rate'] = $MPEGaudioFrequencyLookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['raw']['sample_rate']]; - $thisfile_mpeg_audio['protection'] = !$thisfile_mpeg_audio['raw']['protection']; - $thisfile_mpeg_audio['private'] = (bool) $thisfile_mpeg_audio['raw']['private']; - $thisfile_mpeg_audio['modeextension'] = $MPEGaudioModeExtensionLookup[$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['modeextension']]; - $thisfile_mpeg_audio['copyright'] = (bool) $thisfile_mpeg_audio['raw']['copyright']; - $thisfile_mpeg_audio['original'] = (bool) $thisfile_mpeg_audio['raw']['original']; - $thisfile_mpeg_audio['emphasis'] = $MPEGaudioEmphasisLookup[$thisfile_mpeg_audio['raw']['emphasis']]; - - $info['audio']['channels'] = $thisfile_mpeg_audio['channels']; - $info['audio']['sample_rate'] = $thisfile_mpeg_audio['sample_rate']; - - if ($thisfile_mpeg_audio['protection']) { - $thisfile_mpeg_audio['crc'] = getid3_lib::BigEndian2Int(substr($headerstring, 4, 2)); - } - } - - if ($thisfile_mpeg_audio['raw']['bitrate'] == 15) { - // http://www.hydrogenaudio.org/?act=ST&f=16&t=9682&st=0 - $this->warning('Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1'); - $thisfile_mpeg_audio['raw']['bitrate'] = 0; - } - $thisfile_mpeg_audio['padding'] = (bool) $thisfile_mpeg_audio['raw']['padding']; - $thisfile_mpeg_audio['bitrate'] = $MPEGaudioBitrateLookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['bitrate']]; - - if (($thisfile_mpeg_audio['bitrate'] == 'free') && ($offset == $info['avdataoffset'])) { - // only skip multiple frame check if free-format bitstream found at beginning of file - // otherwise is quite possibly simply corrupted data - $recursivesearch = false; - } - - // For Layer 2 there are some combinations of bitrate and mode which are not allowed. - if (!$FastMPEGheaderScan && ($thisfile_mpeg_audio['layer'] == '2')) { - - $info['audio']['dataformat'] = 'mp2'; - switch ($thisfile_mpeg_audio['channelmode']) { - - case 'mono': - if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] <= 192000)) { - // these are ok - } else { - $this->error($thisfile_mpeg_audio['bitrate'].'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.'); - return false; - } - break; - - case 'stereo': - case 'joint stereo': - case 'dual channel': - if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] == 64000) || ($thisfile_mpeg_audio['bitrate'] >= 96000)) { - // these are ok - } else { - $this->error(intval(round($thisfile_mpeg_audio['bitrate'] / 1000)).'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.'); - return false; - } - break; - - } - - } - - - if ($info['audio']['sample_rate'] > 0) { - $thisfile_mpeg_audio['framelength'] = self::MPEGaudioFrameLength($thisfile_mpeg_audio['bitrate'], $thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['layer'], (int) $thisfile_mpeg_audio['padding'], $info['audio']['sample_rate']); - } - - $nextframetestoffset = $offset + 1; - if ($thisfile_mpeg_audio['bitrate'] != 'free') { - - $info['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate']; - - if (isset($thisfile_mpeg_audio['framelength'])) { - $nextframetestoffset = $offset + $thisfile_mpeg_audio['framelength']; - } else { - $this->error('Frame at offset('.$offset.') is has an invalid frame length.'); - return false; - } - - } - - $ExpectedNumberOfAudioBytes = 0; - - //////////////////////////////////////////////////////////////////////////////////// - // Variable-bitrate headers - - if (substr($headerstring, 4 + 32, 4) == 'VBRI') { - // Fraunhofer VBR header is hardcoded 'VBRI' at offset 0x24 (36) - // specs taken from http://minnie.tuhs.org/pipermail/mp3encoder/2001-January/001800.html - - $thisfile_mpeg_audio['bitrate_mode'] = 'vbr'; - $thisfile_mpeg_audio['VBR_method'] = 'Fraunhofer'; - $info['audio']['codec'] = 'Fraunhofer'; - - $SideInfoData = substr($headerstring, 4 + 2, 32); - - $FraunhoferVBROffset = 36; - - $thisfile_mpeg_audio['VBR_encoder_version'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 4, 2)); // VbriVersion - $thisfile_mpeg_audio['VBR_encoder_delay'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 6, 2)); // VbriDelay - $thisfile_mpeg_audio['VBR_quality'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 8, 2)); // VbriQuality - $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 10, 4)); // VbriStreamBytes - $thisfile_mpeg_audio['VBR_frames'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 14, 4)); // VbriStreamFrames - $thisfile_mpeg_audio['VBR_seek_offsets'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 18, 2)); // VbriTableSize - $thisfile_mpeg_audio['VBR_seek_scale'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 20, 2)); // VbriTableScale - $thisfile_mpeg_audio['VBR_entry_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 22, 2)); // VbriEntryBytes - $thisfile_mpeg_audio['VBR_entry_frames'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 24, 2)); // VbriEntryFrames - - $ExpectedNumberOfAudioBytes = $thisfile_mpeg_audio['VBR_bytes']; - - $previousbyteoffset = $offset; - for ($i = 0; $i < $thisfile_mpeg_audio['VBR_seek_offsets']; $i++) { - $Fraunhofer_OffsetN = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset, $thisfile_mpeg_audio['VBR_entry_bytes'])); - $FraunhoferVBROffset += $thisfile_mpeg_audio['VBR_entry_bytes']; - $thisfile_mpeg_audio['VBR_offsets_relative'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio['VBR_seek_scale']); - $thisfile_mpeg_audio['VBR_offsets_absolute'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio['VBR_seek_scale']) + $previousbyteoffset; - $previousbyteoffset += $Fraunhofer_OffsetN; - } - - - } else { - - // Xing VBR header is hardcoded 'Xing' at a offset 0x0D (13), 0x15 (21) or 0x24 (36) - // depending on MPEG layer and number of channels - - $VBRidOffset = self::XingVBRidOffset($thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['channelmode']); - $SideInfoData = substr($headerstring, 4 + 2, $VBRidOffset - 4); - - if ((substr($headerstring, $VBRidOffset, strlen('Xing')) == 'Xing') || (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Info')) { - // 'Xing' is traditional Xing VBR frame - // 'Info' is LAME-encoded CBR (This was done to avoid CBR files to be recognized as traditional Xing VBR files by some decoders.) - // 'Info' *can* legally be used to specify a VBR file as well, however. - - // http://www.multiweb.cz/twoinches/MP3inside.htm - //00..03 = "Xing" or "Info" - //04..07 = Flags: - // 0x01 Frames Flag set if value for number of frames in file is stored - // 0x02 Bytes Flag set if value for filesize in bytes is stored - // 0x04 TOC Flag set if values for TOC are stored - // 0x08 VBR Scale Flag set if values for VBR scale is stored - //08..11 Frames: Number of frames in file (including the first Xing/Info one) - //12..15 Bytes: File length in Bytes - //16..115 TOC (Table of Contents): - // Contains of 100 indexes (one Byte length) for easier lookup in file. Approximately solves problem with moving inside file. - // Each Byte has a value according this formula: - // (TOC[i] / 256) * fileLenInBytes - // So if song lasts eg. 240 sec. and you want to jump to 60. sec. (and file is 5 000 000 Bytes length) you can use: - // TOC[(60/240)*100] = TOC[25] - // and corresponding Byte in file is then approximately at: - // (TOC[25]/256) * 5000000 - //116..119 VBR Scale - - - // should be safe to leave this at 'vbr' and let it be overriden to 'cbr' if a CBR preset/mode is used by LAME -// if (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Xing') { - $thisfile_mpeg_audio['bitrate_mode'] = 'vbr'; - $thisfile_mpeg_audio['VBR_method'] = 'Xing'; -// } else { -// $ScanAsCBR = true; -// $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; -// } - - $thisfile_mpeg_audio['xing_flags_raw'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 4, 4)); - - $thisfile_mpeg_audio['xing_flags']['frames'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000001); - $thisfile_mpeg_audio['xing_flags']['bytes'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000002); - $thisfile_mpeg_audio['xing_flags']['toc'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000004); - $thisfile_mpeg_audio['xing_flags']['vbr_scale'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000008); - - if ($thisfile_mpeg_audio['xing_flags']['frames']) { - $thisfile_mpeg_audio['VBR_frames'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 8, 4)); - //$thisfile_mpeg_audio['VBR_frames']--; // don't count header Xing/Info frame - } - if ($thisfile_mpeg_audio['xing_flags']['bytes']) { - $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 12, 4)); - } - - //if (($thisfile_mpeg_audio['bitrate'] == 'free') && !empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) { - //if (!empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) { - if (!empty($thisfile_mpeg_audio['VBR_frames'])) { - $used_filesize = 0; - if (!empty($thisfile_mpeg_audio['VBR_bytes'])) { - $used_filesize = $thisfile_mpeg_audio['VBR_bytes']; - } elseif (!empty($info['filesize'])) { - $used_filesize = $info['filesize']; - $used_filesize -= intval(@$info['id3v2']['headerlength']); - $used_filesize -= (isset($info['id3v1']) ? 128 : 0); - $used_filesize -= (isset($info['tag_offset_end']) ? $info['tag_offset_end'] - $info['tag_offset_start'] : 0); - $this->warning('MP3.Xing header missing VBR_bytes, assuming MPEG audio portion of file is '.number_format($used_filesize).' bytes'); - } - - $framelengthfloat = $used_filesize / $thisfile_mpeg_audio['VBR_frames']; - - if ($thisfile_mpeg_audio['layer'] == '1') { - // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12 - //$info['audio']['bitrate'] = ((($framelengthfloat / 4) - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 12; - $info['audio']['bitrate'] = ($framelengthfloat / 4) * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 12; - } else { - // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144 - //$info['audio']['bitrate'] = (($framelengthfloat - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144; - $info['audio']['bitrate'] = $framelengthfloat * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 144; - } - $thisfile_mpeg_audio['framelength'] = floor($framelengthfloat); - } - - if ($thisfile_mpeg_audio['xing_flags']['toc']) { - $LAMEtocData = substr($headerstring, $VBRidOffset + 16, 100); - for ($i = 0; $i < 100; $i++) { - $thisfile_mpeg_audio['toc'][$i] = ord($LAMEtocData{$i}); - } - } - if ($thisfile_mpeg_audio['xing_flags']['vbr_scale']) { - $thisfile_mpeg_audio['VBR_scale'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 116, 4)); - } - - - // http://gabriel.mp3-tech.org/mp3infotag.html - if (substr($headerstring, $VBRidOffset + 120, 4) == 'LAME') { - - // shortcut - $thisfile_mpeg_audio['LAME'] = array(); - $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio['LAME']; - - - $thisfile_mpeg_audio_lame['long_version'] = substr($headerstring, $VBRidOffset + 120, 20); - $thisfile_mpeg_audio_lame['short_version'] = substr($thisfile_mpeg_audio_lame['long_version'], 0, 9); - - if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.90') { - - // extra 11 chars are not part of version string when LAMEtag present - unset($thisfile_mpeg_audio_lame['long_version']); - - // It the LAME tag was only introduced in LAME v3.90 - // http://www.hydrogenaudio.org/?act=ST&f=15&t=9933 - - // Offsets of various bytes in http://gabriel.mp3-tech.org/mp3infotag.html - // are assuming a 'Xing' identifier offset of 0x24, which is the case for - // MPEG-1 non-mono, but not for other combinations - $LAMEtagOffsetContant = $VBRidOffset - 0x24; - - // shortcuts - $thisfile_mpeg_audio_lame['RGAD'] = array('track'=>array(), 'album'=>array()); - $thisfile_mpeg_audio_lame_RGAD = &$thisfile_mpeg_audio_lame['RGAD']; - $thisfile_mpeg_audio_lame_RGAD_track = &$thisfile_mpeg_audio_lame_RGAD['track']; - $thisfile_mpeg_audio_lame_RGAD_album = &$thisfile_mpeg_audio_lame_RGAD['album']; - $thisfile_mpeg_audio_lame['raw'] = array(); - $thisfile_mpeg_audio_lame_raw = &$thisfile_mpeg_audio_lame['raw']; - - // byte $9B VBR Quality - // This field is there to indicate a quality level, although the scale was not precised in the original Xing specifications. - // Actually overwrites original Xing bytes - unset($thisfile_mpeg_audio['VBR_scale']); - $thisfile_mpeg_audio_lame['vbr_quality'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0x9B, 1)); - - // bytes $9C-$A4 Encoder short VersionString - $thisfile_mpeg_audio_lame['short_version'] = substr($headerstring, $LAMEtagOffsetContant + 0x9C, 9); - - // byte $A5 Info Tag revision + VBR method - $LAMEtagRevisionVBRmethod = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA5, 1)); - - $thisfile_mpeg_audio_lame['tag_revision'] = ($LAMEtagRevisionVBRmethod & 0xF0) >> 4; - $thisfile_mpeg_audio_lame_raw['vbr_method'] = $LAMEtagRevisionVBRmethod & 0x0F; - $thisfile_mpeg_audio_lame['vbr_method'] = self::LAMEvbrMethodLookup($thisfile_mpeg_audio_lame_raw['vbr_method']); - $thisfile_mpeg_audio['bitrate_mode'] = substr($thisfile_mpeg_audio_lame['vbr_method'], 0, 3); // usually either 'cbr' or 'vbr', but truncates 'vbr-old / vbr-rh' to 'vbr' - - // byte $A6 Lowpass filter value - $thisfile_mpeg_audio_lame['lowpass_frequency'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100; - - // bytes $A7-$AE Replay Gain - // http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html - // bytes $A7-$AA : 32 bit floating point "Peak signal amplitude" - if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.94b') { - // LAME 3.94a16 and later - 9.23 fixed point - // ie 0x0059E2EE / (2^23) = 5890798 / 8388608 = 0.7022378444671630859375 - $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = (float) ((getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4))) / 8388608); - } else { - // LAME 3.94a15 and earlier - 32-bit floating point - // Actually 3.94a16 will fall in here too and be WRONG, but is hard to detect 3.94a16 vs 3.94a15 - $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = getid3_lib::LittleEndian2Float(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4)); - } - if ($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] == 0) { - unset($thisfile_mpeg_audio_lame_RGAD['peak_amplitude']); - } else { - $thisfile_mpeg_audio_lame_RGAD['peak_db'] = getid3_lib::RGADamplitude2dB($thisfile_mpeg_audio_lame_RGAD['peak_amplitude']); - } - - $thisfile_mpeg_audio_lame_raw['RGAD_track'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAB, 2)); - $thisfile_mpeg_audio_lame_raw['RGAD_album'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAD, 2)); - - - if ($thisfile_mpeg_audio_lame_raw['RGAD_track'] != 0) { - - $thisfile_mpeg_audio_lame_RGAD_track['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0xE000) >> 13; - $thisfile_mpeg_audio_lame_RGAD_track['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x1C00) >> 10; - $thisfile_mpeg_audio_lame_RGAD_track['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x0200) >> 9; - $thisfile_mpeg_audio_lame_RGAD_track['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x01FF; - $thisfile_mpeg_audio_lame_RGAD_track['name'] = getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['name']); - $thisfile_mpeg_audio_lame_RGAD_track['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['originator']); - $thisfile_mpeg_audio_lame_RGAD_track['gain_db'] = getid3_lib::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_RGAD_track['raw']['sign_bit']); - - if (!empty($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'])) { - $info['replay_gain']['track']['peak'] = $thisfile_mpeg_audio_lame_RGAD['peak_amplitude']; - } - $info['replay_gain']['track']['originator'] = $thisfile_mpeg_audio_lame_RGAD_track['originator']; - $info['replay_gain']['track']['adjustment'] = $thisfile_mpeg_audio_lame_RGAD_track['gain_db']; - } else { - unset($thisfile_mpeg_audio_lame_RGAD['track']); - } - if ($thisfile_mpeg_audio_lame_raw['RGAD_album'] != 0) { - - $thisfile_mpeg_audio_lame_RGAD_album['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0xE000) >> 13; - $thisfile_mpeg_audio_lame_RGAD_album['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x1C00) >> 10; - $thisfile_mpeg_audio_lame_RGAD_album['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x0200) >> 9; - $thisfile_mpeg_audio_lame_RGAD_album['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x01FF; - $thisfile_mpeg_audio_lame_RGAD_album['name'] = getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['name']); - $thisfile_mpeg_audio_lame_RGAD_album['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['originator']); - $thisfile_mpeg_audio_lame_RGAD_album['gain_db'] = getid3_lib::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_RGAD_album['raw']['sign_bit']); - - if (!empty($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'])) { - $info['replay_gain']['album']['peak'] = $thisfile_mpeg_audio_lame_RGAD['peak_amplitude']; - } - $info['replay_gain']['album']['originator'] = $thisfile_mpeg_audio_lame_RGAD_album['originator']; - $info['replay_gain']['album']['adjustment'] = $thisfile_mpeg_audio_lame_RGAD_album['gain_db']; - } else { - unset($thisfile_mpeg_audio_lame_RGAD['album']); - } - if (empty($thisfile_mpeg_audio_lame_RGAD)) { - unset($thisfile_mpeg_audio_lame['RGAD']); - } - - - // byte $AF Encoding flags + ATH Type - $EncodingFlagsATHtype = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAF, 1)); - $thisfile_mpeg_audio_lame['encoding_flags']['nspsytune'] = (bool) ($EncodingFlagsATHtype & 0x10); - $thisfile_mpeg_audio_lame['encoding_flags']['nssafejoint'] = (bool) ($EncodingFlagsATHtype & 0x20); - $thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'] = (bool) ($EncodingFlagsATHtype & 0x40); - $thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev'] = (bool) ($EncodingFlagsATHtype & 0x80); - $thisfile_mpeg_audio_lame['ath_type'] = $EncodingFlagsATHtype & 0x0F; - - // byte $B0 if ABR {specified bitrate} else {minimal bitrate} - $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB0, 1)); - if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 2) { // Average BitRate (ABR) - $thisfile_mpeg_audio_lame['bitrate_abr'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']; - } elseif ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) { // Constant BitRate (CBR) - // ignore - } elseif ($thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] > 0) { // Variable BitRate (VBR) - minimum bitrate - $thisfile_mpeg_audio_lame['bitrate_min'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']; - } - - // bytes $B1-$B3 Encoder delays - $EncoderDelays = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB1, 3)); - $thisfile_mpeg_audio_lame['encoder_delay'] = ($EncoderDelays & 0xFFF000) >> 12; - $thisfile_mpeg_audio_lame['end_padding'] = $EncoderDelays & 0x000FFF; - - // byte $B4 Misc - $MiscByte = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB4, 1)); - $thisfile_mpeg_audio_lame_raw['noise_shaping'] = ($MiscByte & 0x03); - $thisfile_mpeg_audio_lame_raw['stereo_mode'] = ($MiscByte & 0x1C) >> 2; - $thisfile_mpeg_audio_lame_raw['not_optimal_quality'] = ($MiscByte & 0x20) >> 5; - $thisfile_mpeg_audio_lame_raw['source_sample_freq'] = ($MiscByte & 0xC0) >> 6; - $thisfile_mpeg_audio_lame['noise_shaping'] = $thisfile_mpeg_audio_lame_raw['noise_shaping']; - $thisfile_mpeg_audio_lame['stereo_mode'] = self::LAMEmiscStereoModeLookup($thisfile_mpeg_audio_lame_raw['stereo_mode']); - $thisfile_mpeg_audio_lame['not_optimal_quality'] = (bool) $thisfile_mpeg_audio_lame_raw['not_optimal_quality']; - $thisfile_mpeg_audio_lame['source_sample_freq'] = self::LAMEmiscSourceSampleFrequencyLookup($thisfile_mpeg_audio_lame_raw['source_sample_freq']); - - // byte $B5 MP3 Gain - $thisfile_mpeg_audio_lame_raw['mp3_gain'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB5, 1), false, true); - $thisfile_mpeg_audio_lame['mp3_gain_db'] = (getid3_lib::RGADamplitude2dB(2) / 4) * $thisfile_mpeg_audio_lame_raw['mp3_gain']; - $thisfile_mpeg_audio_lame['mp3_gain_factor'] = pow(2, ($thisfile_mpeg_audio_lame['mp3_gain_db'] / 6)); - - // bytes $B6-$B7 Preset and surround info - $PresetSurroundBytes = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB6, 2)); - // Reserved = ($PresetSurroundBytes & 0xC000); - $thisfile_mpeg_audio_lame_raw['surround_info'] = ($PresetSurroundBytes & 0x3800); - $thisfile_mpeg_audio_lame['surround_info'] = self::LAMEsurroundInfoLookup($thisfile_mpeg_audio_lame_raw['surround_info']); - $thisfile_mpeg_audio_lame['preset_used_id'] = ($PresetSurroundBytes & 0x07FF); - $thisfile_mpeg_audio_lame['preset_used'] = self::LAMEpresetUsedLookup($thisfile_mpeg_audio_lame); - if (!empty($thisfile_mpeg_audio_lame['preset_used_id']) && empty($thisfile_mpeg_audio_lame['preset_used'])) { - $this->warning('Unknown LAME preset used ('.$thisfile_mpeg_audio_lame['preset_used_id'].') - please report to info@getid3.org'); - } - if (($thisfile_mpeg_audio_lame['short_version'] == 'LAME3.90.') && !empty($thisfile_mpeg_audio_lame['preset_used_id'])) { - // this may change if 3.90.4 ever comes out - $thisfile_mpeg_audio_lame['short_version'] = 'LAME3.90.3'; - } - - // bytes $B8-$BB MusicLength - $thisfile_mpeg_audio_lame['audio_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB8, 4)); - $ExpectedNumberOfAudioBytes = (($thisfile_mpeg_audio_lame['audio_bytes'] > 0) ? $thisfile_mpeg_audio_lame['audio_bytes'] : $thisfile_mpeg_audio['VBR_bytes']); - - // bytes $BC-$BD MusicCRC - $thisfile_mpeg_audio_lame['music_crc'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBC, 2)); - - // bytes $BE-$BF CRC-16 of Info Tag - $thisfile_mpeg_audio_lame['lame_tag_crc'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBE, 2)); - - - // LAME CBR - if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) { - - $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; - $thisfile_mpeg_audio['bitrate'] = self::ClosestStandardMP3Bitrate($thisfile_mpeg_audio['bitrate']); - $info['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate']; - //if (empty($thisfile_mpeg_audio['bitrate']) || (!empty($thisfile_mpeg_audio_lame['bitrate_min']) && ($thisfile_mpeg_audio_lame['bitrate_min'] != 255))) { - // $thisfile_mpeg_audio['bitrate'] = $thisfile_mpeg_audio_lame['bitrate_min']; - //} - - } - - } - } - - } else { - - // not Fraunhofer or Xing VBR methods, most likely CBR (but could be VBR with no header) - $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; - if ($recursivesearch) { - $thisfile_mpeg_audio['bitrate_mode'] = 'vbr'; - if ($this->RecursiveFrameScanning($offset, $nextframetestoffset, true)) { - $recursivesearch = false; - $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; - } - if ($thisfile_mpeg_audio['bitrate_mode'] == 'vbr') { - $this->warning('VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.'); - } - } - - } - - } - - if (($ExpectedNumberOfAudioBytes > 0) && ($ExpectedNumberOfAudioBytes != ($info['avdataend'] - $info['avdataoffset']))) { - if ($ExpectedNumberOfAudioBytes > ($info['avdataend'] - $info['avdataoffset'])) { - if ($this->isDependencyFor('matroska') || $this->isDependencyFor('riff')) { - // ignore, audio data is broken into chunks so will always be data "missing" - } - elseif (($ExpectedNumberOfAudioBytes - ($info['avdataend'] - $info['avdataoffset'])) == 1) { - $this->warning('Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)'); - } - else { - $this->warning('Probable truncated file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' (short by '.($ExpectedNumberOfAudioBytes - ($info['avdataend'] - $info['avdataoffset'])).' bytes)'); - } - } else { - if ((($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes) == 1) { - // $prenullbytefileoffset = $this->ftell(); - // $this->fseek($info['avdataend']); - // $PossibleNullByte = $this->fread(1); - // $this->fseek($prenullbytefileoffset); - // if ($PossibleNullByte === "\x00") { - $info['avdataend']--; - // $this->warning('Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored'); - // } else { - // $this->warning('Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)'); - // } - } else { - $this->warning('Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)'); - } - } - } - - if (($thisfile_mpeg_audio['bitrate'] == 'free') && empty($info['audio']['bitrate'])) { - if (($offset == $info['avdataoffset']) && empty($thisfile_mpeg_audio['VBR_frames'])) { - $framebytelength = $this->FreeFormatFrameLength($offset, true); - if ($framebytelength > 0) { - $thisfile_mpeg_audio['framelength'] = $framebytelength; - if ($thisfile_mpeg_audio['layer'] == '1') { - // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12 - $info['audio']['bitrate'] = ((($framebytelength / 4) - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 12; - } else { - // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144 - $info['audio']['bitrate'] = (($framebytelength - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144; - } - } else { - $this->error('Error calculating frame length of free-format MP3 without Xing/LAME header'); - } - } - } - - if (isset($thisfile_mpeg_audio['VBR_frames']) ? $thisfile_mpeg_audio['VBR_frames'] : '') { - switch ($thisfile_mpeg_audio['bitrate_mode']) { - case 'vbr': - case 'abr': - $bytes_per_frame = 1152; - if (($thisfile_mpeg_audio['version'] == '1') && ($thisfile_mpeg_audio['layer'] == 1)) { - $bytes_per_frame = 384; - } elseif ((($thisfile_mpeg_audio['version'] == '2') || ($thisfile_mpeg_audio['version'] == '2.5')) && ($thisfile_mpeg_audio['layer'] == 3)) { - $bytes_per_frame = 576; - } - $thisfile_mpeg_audio['VBR_bitrate'] = (isset($thisfile_mpeg_audio['VBR_bytes']) ? (($thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames']) * 8) * ($info['audio']['sample_rate'] / $bytes_per_frame) : 0); - if ($thisfile_mpeg_audio['VBR_bitrate'] > 0) { - $info['audio']['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate']; - $thisfile_mpeg_audio['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate']; // to avoid confusion - } - break; - } - } - - // End variable-bitrate headers - //////////////////////////////////////////////////////////////////////////////////// - - if ($recursivesearch) { - - if (!$this->RecursiveFrameScanning($offset, $nextframetestoffset, $ScanAsCBR)) { - return false; - } - - } - - - //if (false) { - // // experimental side info parsing section - not returning anything useful yet - // - // $SideInfoBitstream = getid3_lib::BigEndian2Bin($SideInfoData); - // $SideInfoOffset = 0; - // - // if ($thisfile_mpeg_audio['version'] == '1') { - // if ($thisfile_mpeg_audio['channelmode'] == 'mono') { - // // MPEG-1 (mono) - // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 9); - // $SideInfoOffset += 9; - // $SideInfoOffset += 5; - // } else { - // // MPEG-1 (stereo, joint-stereo, dual-channel) - // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 9); - // $SideInfoOffset += 9; - // $SideInfoOffset += 3; - // } - // } else { // 2 or 2.5 - // if ($thisfile_mpeg_audio['channelmode'] == 'mono') { - // // MPEG-2, MPEG-2.5 (mono) - // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 8); - // $SideInfoOffset += 8; - // $SideInfoOffset += 1; - // } else { - // // MPEG-2, MPEG-2.5 (stereo, joint-stereo, dual-channel) - // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 8); - // $SideInfoOffset += 8; - // $SideInfoOffset += 2; - // } - // } - // - // if ($thisfile_mpeg_audio['version'] == '1') { - // for ($channel = 0; $channel < $info['audio']['channels']; $channel++) { - // for ($scfsi_band = 0; $scfsi_band < 4; $scfsi_band++) { - // $thisfile_mpeg_audio['scfsi'][$channel][$scfsi_band] = substr($SideInfoBitstream, $SideInfoOffset, 1); - // $SideInfoOffset += 2; - // } - // } - // } - // for ($granule = 0; $granule < (($thisfile_mpeg_audio['version'] == '1') ? 2 : 1); $granule++) { - // for ($channel = 0; $channel < $info['audio']['channels']; $channel++) { - // $thisfile_mpeg_audio['part2_3_length'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 12); - // $SideInfoOffset += 12; - // $thisfile_mpeg_audio['big_values'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 9); - // $SideInfoOffset += 9; - // $thisfile_mpeg_audio['global_gain'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 8); - // $SideInfoOffset += 8; - // if ($thisfile_mpeg_audio['version'] == '1') { - // $thisfile_mpeg_audio['scalefac_compress'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 4); - // $SideInfoOffset += 4; - // } else { - // $thisfile_mpeg_audio['scalefac_compress'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 9); - // $SideInfoOffset += 9; - // } - // $thisfile_mpeg_audio['window_switching_flag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); - // $SideInfoOffset += 1; - // - // if ($thisfile_mpeg_audio['window_switching_flag'][$granule][$channel] == '1') { - // - // $thisfile_mpeg_audio['block_type'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 2); - // $SideInfoOffset += 2; - // $thisfile_mpeg_audio['mixed_block_flag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); - // $SideInfoOffset += 1; - // - // for ($region = 0; $region < 2; $region++) { - // $thisfile_mpeg_audio['table_select'][$granule][$channel][$region] = substr($SideInfoBitstream, $SideInfoOffset, 5); - // $SideInfoOffset += 5; - // } - // $thisfile_mpeg_audio['table_select'][$granule][$channel][2] = 0; - // - // for ($window = 0; $window < 3; $window++) { - // $thisfile_mpeg_audio['subblock_gain'][$granule][$channel][$window] = substr($SideInfoBitstream, $SideInfoOffset, 3); - // $SideInfoOffset += 3; - // } - // - // } else { - // - // for ($region = 0; $region < 3; $region++) { - // $thisfile_mpeg_audio['table_select'][$granule][$channel][$region] = substr($SideInfoBitstream, $SideInfoOffset, 5); - // $SideInfoOffset += 5; - // } - // - // $thisfile_mpeg_audio['region0_count'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 4); - // $SideInfoOffset += 4; - // $thisfile_mpeg_audio['region1_count'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 3); - // $SideInfoOffset += 3; - // $thisfile_mpeg_audio['block_type'][$granule][$channel] = 0; - // } - // - // if ($thisfile_mpeg_audio['version'] == '1') { - // $thisfile_mpeg_audio['preflag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); - // $SideInfoOffset += 1; - // } - // $thisfile_mpeg_audio['scalefac_scale'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); - // $SideInfoOffset += 1; - // $thisfile_mpeg_audio['count1table_select'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); - // $SideInfoOffset += 1; - // } - // } - //} - - return true; - } - - public function RecursiveFrameScanning(&$offset, &$nextframetestoffset, $ScanAsCBR) { - $info = &$this->getid3->info; - $firstframetestarray = array('error' => array(), 'warning'=> array(), 'avdataend' => $info['avdataend'], 'avdataoffset' => $info['avdataoffset']); - $this->decodeMPEGaudioHeader($offset, $firstframetestarray, false); - - for ($i = 0; $i < GETID3_MP3_VALID_CHECK_FRAMES; $i++) { - // check next GETID3_MP3_VALID_CHECK_FRAMES frames for validity, to make sure we haven't run across a false synch - if (($nextframetestoffset + 4) >= $info['avdataend']) { - // end of file - return true; - } - - $nextframetestarray = array('error' => array(), 'warning' => array(), 'avdataend' => $info['avdataend'], 'avdataoffset'=>$info['avdataoffset']); - if ($this->decodeMPEGaudioHeader($nextframetestoffset, $nextframetestarray, false)) { - if ($ScanAsCBR) { - // force CBR mode, used for trying to pick out invalid audio streams with valid(?) VBR headers, or VBR streams with no VBR header - if (!isset($nextframetestarray['mpeg']['audio']['bitrate']) || !isset($firstframetestarray['mpeg']['audio']['bitrate']) || ($nextframetestarray['mpeg']['audio']['bitrate'] != $firstframetestarray['mpeg']['audio']['bitrate'])) { - return false; - } - } - - - // next frame is OK, get ready to check the one after that - if (isset($nextframetestarray['mpeg']['audio']['framelength']) && ($nextframetestarray['mpeg']['audio']['framelength'] > 0)) { - $nextframetestoffset += $nextframetestarray['mpeg']['audio']['framelength']; - } else { - $this->error('Frame at offset ('.$offset.') is has an invalid frame length.'); - return false; - } - - } elseif (!empty($firstframetestarray['mpeg']['audio']['framelength']) && (($nextframetestoffset + $firstframetestarray['mpeg']['audio']['framelength']) > $info['avdataend'])) { - - // it's not the end of the file, but there's not enough data left for another frame, so assume it's garbage/padding and return OK - return true; - - } else { - - // next frame is not valid, note the error and fail, so scanning can contiue for a valid frame sequence - $this->warning('Frame at offset ('.$offset.') is valid, but the next one at ('.$nextframetestoffset.') is not.'); - - return false; - } - } - return true; - } - - public function FreeFormatFrameLength($offset, $deepscan=false) { - $info = &$this->getid3->info; - - $this->fseek($offset); - $MPEGaudioData = $this->fread(32768); - - $SyncPattern1 = substr($MPEGaudioData, 0, 4); - // may be different pattern due to padding - $SyncPattern2 = $SyncPattern1{0}.$SyncPattern1{1}.chr(ord($SyncPattern1{2}) | 0x02).$SyncPattern1{3}; - if ($SyncPattern2 === $SyncPattern1) { - $SyncPattern2 = $SyncPattern1{0}.$SyncPattern1{1}.chr(ord($SyncPattern1{2}) & 0xFD).$SyncPattern1{3}; - } - - $framelength = false; - $framelength1 = strpos($MPEGaudioData, $SyncPattern1, 4); - $framelength2 = strpos($MPEGaudioData, $SyncPattern2, 4); - if ($framelength1 > 4) { - $framelength = $framelength1; - } - if (($framelength2 > 4) && ($framelength2 < $framelength1)) { - $framelength = $framelength2; - } - if (!$framelength) { - - // LAME 3.88 has a different value for modeextension on the first frame vs the rest - $framelength1 = strpos($MPEGaudioData, substr($SyncPattern1, 0, 3), 4); - $framelength2 = strpos($MPEGaudioData, substr($SyncPattern2, 0, 3), 4); - - if ($framelength1 > 4) { - $framelength = $framelength1; - } - if (($framelength2 > 4) && ($framelength2 < $framelength1)) { - $framelength = $framelength2; - } - if (!$framelength) { - $this->error('Cannot find next free-format synch pattern ('.getid3_lib::PrintHexBytes($SyncPattern1).' or '.getid3_lib::PrintHexBytes($SyncPattern2).') after offset '.$offset); - return false; - } else { - $this->warning('ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)'); - $info['audio']['codec'] = 'LAME'; - $info['audio']['encoder'] = 'LAME3.88'; - $SyncPattern1 = substr($SyncPattern1, 0, 3); - $SyncPattern2 = substr($SyncPattern2, 0, 3); - } - } - - if ($deepscan) { - - $ActualFrameLengthValues = array(); - $nextoffset = $offset + $framelength; - while ($nextoffset < ($info['avdataend'] - 6)) { - $this->fseek($nextoffset - 1); - $NextSyncPattern = $this->fread(6); - if ((substr($NextSyncPattern, 1, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 1, strlen($SyncPattern2)) == $SyncPattern2)) { - // good - found where expected - $ActualFrameLengthValues[] = $framelength; - } elseif ((substr($NextSyncPattern, 0, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 0, strlen($SyncPattern2)) == $SyncPattern2)) { - // ok - found one byte earlier than expected (last frame wasn't padded, first frame was) - $ActualFrameLengthValues[] = ($framelength - 1); - $nextoffset--; - } elseif ((substr($NextSyncPattern, 2, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 2, strlen($SyncPattern2)) == $SyncPattern2)) { - // ok - found one byte later than expected (last frame was padded, first frame wasn't) - $ActualFrameLengthValues[] = ($framelength + 1); - $nextoffset++; - } else { - $this->error('Did not find expected free-format sync pattern at offset '.$nextoffset); - return false; - } - $nextoffset += $framelength; - } - if (count($ActualFrameLengthValues) > 0) { - $framelength = intval(round(array_sum($ActualFrameLengthValues) / count($ActualFrameLengthValues))); - } - } - return $framelength; - } - - public function getOnlyMPEGaudioInfoBruteForce() { - $MPEGaudioHeaderDecodeCache = array(); - $MPEGaudioHeaderValidCache = array(); - $MPEGaudioHeaderLengthCache = array(); - $MPEGaudioVersionLookup = self::MPEGaudioVersionArray(); - $MPEGaudioLayerLookup = self::MPEGaudioLayerArray(); - $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray(); - $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray(); - $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray(); - $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray(); - $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray(); - $LongMPEGversionLookup = array(); - $LongMPEGlayerLookup = array(); - $LongMPEGbitrateLookup = array(); - $LongMPEGpaddingLookup = array(); - $LongMPEGfrequencyLookup = array(); - $Distribution['bitrate'] = array(); - $Distribution['frequency'] = array(); - $Distribution['layer'] = array(); - $Distribution['version'] = array(); - $Distribution['padding'] = array(); - - $info = &$this->getid3->info; - $this->fseek($info['avdataoffset']); - - $max_frames_scan = 5000; - $frames_scanned = 0; - - $previousvalidframe = $info['avdataoffset']; - while ($this->ftell() < $info['avdataend']) { - set_time_limit(30); - $head4 = $this->fread(4); - if (strlen($head4) < 4) { - break; - } - if ($head4{0} != "\xFF") { - for ($i = 1; $i < 4; $i++) { - if ($head4{$i} == "\xFF") { - $this->fseek($i - 4, SEEK_CUR); - continue 2; - } - } - continue; - } - if (!isset($MPEGaudioHeaderDecodeCache[$head4])) { - $MPEGaudioHeaderDecodeCache[$head4] = self::MPEGaudioHeaderDecode($head4); - } - if (!isset($MPEGaudioHeaderValidCache[$head4])) { - $MPEGaudioHeaderValidCache[$head4] = self::MPEGaudioHeaderValid($MPEGaudioHeaderDecodeCache[$head4], false, false); - } - if ($MPEGaudioHeaderValidCache[$head4]) { - - if (!isset($MPEGaudioHeaderLengthCache[$head4])) { - $LongMPEGversionLookup[$head4] = $MPEGaudioVersionLookup[$MPEGaudioHeaderDecodeCache[$head4]['version']]; - $LongMPEGlayerLookup[$head4] = $MPEGaudioLayerLookup[$MPEGaudioHeaderDecodeCache[$head4]['layer']]; - $LongMPEGbitrateLookup[$head4] = $MPEGaudioBitrateLookup[$LongMPEGversionLookup[$head4]][$LongMPEGlayerLookup[$head4]][$MPEGaudioHeaderDecodeCache[$head4]['bitrate']]; - $LongMPEGpaddingLookup[$head4] = (bool) $MPEGaudioHeaderDecodeCache[$head4]['padding']; - $LongMPEGfrequencyLookup[$head4] = $MPEGaudioFrequencyLookup[$LongMPEGversionLookup[$head4]][$MPEGaudioHeaderDecodeCache[$head4]['sample_rate']]; - $MPEGaudioHeaderLengthCache[$head4] = self::MPEGaudioFrameLength( - $LongMPEGbitrateLookup[$head4], - $LongMPEGversionLookup[$head4], - $LongMPEGlayerLookup[$head4], - $LongMPEGpaddingLookup[$head4], - $LongMPEGfrequencyLookup[$head4]); - } - if ($MPEGaudioHeaderLengthCache[$head4] > 4) { - $WhereWeWere = $this->ftell(); - $this->fseek($MPEGaudioHeaderLengthCache[$head4] - 4, SEEK_CUR); - $next4 = $this->fread(4); - if ($next4{0} == "\xFF") { - if (!isset($MPEGaudioHeaderDecodeCache[$next4])) { - $MPEGaudioHeaderDecodeCache[$next4] = self::MPEGaudioHeaderDecode($next4); - } - if (!isset($MPEGaudioHeaderValidCache[$next4])) { - $MPEGaudioHeaderValidCache[$next4] = self::MPEGaudioHeaderValid($MPEGaudioHeaderDecodeCache[$next4], false, false); - } - if ($MPEGaudioHeaderValidCache[$next4]) { - $this->fseek(-4, SEEK_CUR); - - getid3_lib::safe_inc($Distribution['bitrate'][$LongMPEGbitrateLookup[$head4]]); - getid3_lib::safe_inc($Distribution['layer'][$LongMPEGlayerLookup[$head4]]); - getid3_lib::safe_inc($Distribution['version'][$LongMPEGversionLookup[$head4]]); - getid3_lib::safe_inc($Distribution['padding'][intval($LongMPEGpaddingLookup[$head4])]); - getid3_lib::safe_inc($Distribution['frequency'][$LongMPEGfrequencyLookup[$head4]]); - if ($max_frames_scan && (++$frames_scanned >= $max_frames_scan)) { - $pct_data_scanned = ($this->ftell() - $info['avdataoffset']) / ($info['avdataend'] - $info['avdataoffset']); - $this->warning('too many MPEG audio frames to scan, only scanned first '.$max_frames_scan.' frames ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.'); - foreach ($Distribution as $key1 => $value1) { - foreach ($value1 as $key2 => $value2) { - $Distribution[$key1][$key2] = round($value2 / $pct_data_scanned); - } - } - break; - } - continue; - } - } - unset($next4); - $this->fseek($WhereWeWere - 3); - } - - } - } - foreach ($Distribution as $key => $value) { - ksort($Distribution[$key], SORT_NUMERIC); - } - ksort($Distribution['version'], SORT_STRING); - $info['mpeg']['audio']['bitrate_distribution'] = $Distribution['bitrate']; - $info['mpeg']['audio']['frequency_distribution'] = $Distribution['frequency']; - $info['mpeg']['audio']['layer_distribution'] = $Distribution['layer']; - $info['mpeg']['audio']['version_distribution'] = $Distribution['version']; - $info['mpeg']['audio']['padding_distribution'] = $Distribution['padding']; - if (count($Distribution['version']) > 1) { - $this->error('Corrupt file - more than one MPEG version detected'); - } - if (count($Distribution['layer']) > 1) { - $this->error('Corrupt file - more than one MPEG layer detected'); - } - if (count($Distribution['frequency']) > 1) { - $this->error('Corrupt file - more than one MPEG sample rate detected'); - } - - - $bittotal = 0; - foreach ($Distribution['bitrate'] as $bitratevalue => $bitratecount) { - if ($bitratevalue != 'free') { - $bittotal += ($bitratevalue * $bitratecount); - } - } - $info['mpeg']['audio']['frame_count'] = array_sum($Distribution['bitrate']); - if ($info['mpeg']['audio']['frame_count'] == 0) { - $this->error('no MPEG audio frames found'); - return false; - } - $info['mpeg']['audio']['bitrate'] = ($bittotal / $info['mpeg']['audio']['frame_count']); - $info['mpeg']['audio']['bitrate_mode'] = ((count($Distribution['bitrate']) > 0) ? 'vbr' : 'cbr'); - $info['mpeg']['audio']['sample_rate'] = getid3_lib::array_max($Distribution['frequency'], true); - - $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; - $info['audio']['bitrate_mode'] = $info['mpeg']['audio']['bitrate_mode']; - $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; - $info['audio']['dataformat'] = 'mp'.getid3_lib::array_max($Distribution['layer'], true); - $info['fileformat'] = $info['audio']['dataformat']; - - return true; - } - - - public function getOnlyMPEGaudioInfo($avdataoffset, $BitrateHistogram=false) { - // looks for synch, decodes MPEG audio header - - $info = &$this->getid3->info; - - static $MPEGaudioVersionLookup; - static $MPEGaudioLayerLookup; - static $MPEGaudioBitrateLookup; - if (empty($MPEGaudioVersionLookup)) { - $MPEGaudioVersionLookup = self::MPEGaudioVersionArray(); - $MPEGaudioLayerLookup = self::MPEGaudioLayerArray(); - $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray(); - - } - - $this->fseek($avdataoffset); - $sync_seek_buffer_size = min(128 * 1024, $info['avdataend'] - $avdataoffset); - if ($sync_seek_buffer_size <= 0) { - $this->error('Invalid $sync_seek_buffer_size at offset '.$avdataoffset); - return false; - } - $header = $this->fread($sync_seek_buffer_size); - $sync_seek_buffer_size = strlen($header); - $SynchSeekOffset = 0; - while ($SynchSeekOffset < $sync_seek_buffer_size) { - if ((($avdataoffset + $SynchSeekOffset) < $info['avdataend']) && !feof($this->getid3->fp)) { - - if ($SynchSeekOffset > $sync_seek_buffer_size) { - // if a synch's not found within the first 128k bytes, then give up - $this->error('Could not find valid MPEG audio synch within the first '.round($sync_seek_buffer_size / 1024).'kB'); - if (isset($info['audio']['bitrate'])) { - unset($info['audio']['bitrate']); - } - if (isset($info['mpeg']['audio'])) { - unset($info['mpeg']['audio']); - } - if (empty($info['mpeg'])) { - unset($info['mpeg']); - } - return false; - - } elseif (feof($this->getid3->fp)) { - - $this->error('Could not find valid MPEG audio synch before end of file'); - if (isset($info['audio']['bitrate'])) { - unset($info['audio']['bitrate']); - } - if (isset($info['mpeg']['audio'])) { - unset($info['mpeg']['audio']); - } - if (isset($info['mpeg']) && (!is_array($info['mpeg']) || (count($info['mpeg']) == 0))) { - unset($info['mpeg']); - } - return false; - } - } - - if (($SynchSeekOffset + 1) >= strlen($header)) { - $this->error('Could not find valid MPEG synch before end of file'); - return false; - } - - if (($header{$SynchSeekOffset} == "\xFF") && ($header{($SynchSeekOffset + 1)} > "\xE0")) { // synch detected - if (!isset($FirstFrameThisfileInfo) && !isset($info['mpeg']['audio'])) { - $FirstFrameThisfileInfo = $info; - $FirstFrameAVDataOffset = $avdataoffset + $SynchSeekOffset; - if (!$this->decodeMPEGaudioHeader($FirstFrameAVDataOffset, $FirstFrameThisfileInfo, false)) { - // if this is the first valid MPEG-audio frame, save it in case it's a VBR header frame and there's - // garbage between this frame and a valid sequence of MPEG-audio frames, to be restored below - unset($FirstFrameThisfileInfo); - } - } - - $dummy = $info; // only overwrite real data if valid header found - if ($this->decodeMPEGaudioHeader($avdataoffset + $SynchSeekOffset, $dummy, true)) { - $info = $dummy; - $info['avdataoffset'] = $avdataoffset + $SynchSeekOffset; - switch (isset($info['fileformat']) ? $info['fileformat'] : '') { - case '': - case 'id3': - case 'ape': - case 'mp3': - $info['fileformat'] = 'mp3'; - $info['audio']['dataformat'] = 'mp3'; - break; - } - if (isset($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode']) && ($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr')) { - if (!(abs($info['audio']['bitrate'] - $FirstFrameThisfileInfo['audio']['bitrate']) <= 1)) { - // If there is garbage data between a valid VBR header frame and a sequence - // of valid MPEG-audio frames the VBR data is no longer discarded. - $info = $FirstFrameThisfileInfo; - $info['avdataoffset'] = $FirstFrameAVDataOffset; - $info['fileformat'] = 'mp3'; - $info['audio']['dataformat'] = 'mp3'; - $dummy = $info; - unset($dummy['mpeg']['audio']); - $GarbageOffsetStart = $FirstFrameAVDataOffset + $FirstFrameThisfileInfo['mpeg']['audio']['framelength']; - $GarbageOffsetEnd = $avdataoffset + $SynchSeekOffset; - if ($this->decodeMPEGaudioHeader($GarbageOffsetEnd, $dummy, true, true)) { - $info = $dummy; - $info['avdataoffset'] = $GarbageOffsetEnd; - $this->warning('apparently-valid VBR header not used because could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.'), but did find valid CBR stream starting at '.$GarbageOffsetEnd); - } else { - $this->warning('using data from VBR header even though could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.')'); - } - } - } - if (isset($info['mpeg']['audio']['bitrate_mode']) && ($info['mpeg']['audio']['bitrate_mode'] == 'vbr') && !isset($info['mpeg']['audio']['VBR_method'])) { - // VBR file with no VBR header - $BitrateHistogram = true; - } - - if ($BitrateHistogram) { - - $info['mpeg']['audio']['stereo_distribution'] = array('stereo'=>0, 'joint stereo'=>0, 'dual channel'=>0, 'mono'=>0); - $info['mpeg']['audio']['version_distribution'] = array('1'=>0, '2'=>0, '2.5'=>0); - - if ($info['mpeg']['audio']['version'] == '1') { - if ($info['mpeg']['audio']['layer'] == 3) { - $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 40000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 320000=>0); - } elseif ($info['mpeg']['audio']['layer'] == 2) { - $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 320000=>0, 384000=>0); - } elseif ($info['mpeg']['audio']['layer'] == 1) { - $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 64000=>0, 96000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 288000=>0, 320000=>0, 352000=>0, 384000=>0, 416000=>0, 448000=>0); - } - } elseif ($info['mpeg']['audio']['layer'] == 1) { - $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 144000=>0, 160000=>0, 176000=>0, 192000=>0, 224000=>0, 256000=>0); - } else { - $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 8000=>0, 16000=>0, 24000=>0, 32000=>0, 40000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 144000=>0, 160000=>0); - } - - $dummy = array('error'=>$info['error'], 'warning'=>$info['warning'], 'avdataend'=>$info['avdataend'], 'avdataoffset'=>$info['avdataoffset']); - $synchstartoffset = $info['avdataoffset']; - $this->fseek($info['avdataoffset']); - - // you can play with these numbers: - $max_frames_scan = 50000; - $max_scan_segments = 10; - - // don't play with these numbers: - $FastMode = false; - $SynchErrorsFound = 0; - $frames_scanned = 0; - $this_scan_segment = 0; - $frames_scan_per_segment = ceil($max_frames_scan / $max_scan_segments); - $pct_data_scanned = 0; - for ($current_segment = 0; $current_segment < $max_scan_segments; $current_segment++) { - $frames_scanned_this_segment = 0; - if ($this->ftell() >= $info['avdataend']) { - break; - } - $scan_start_offset[$current_segment] = max($this->ftell(), $info['avdataoffset'] + round($current_segment * (($info['avdataend'] - $info['avdataoffset']) / $max_scan_segments))); - if ($current_segment > 0) { - $this->fseek($scan_start_offset[$current_segment]); - $buffer_4k = $this->fread(4096); - for ($j = 0; $j < (strlen($buffer_4k) - 4); $j++) { - if (($buffer_4k{$j} == "\xFF") && ($buffer_4k{($j + 1)} > "\xE0")) { // synch detected - if ($this->decodeMPEGaudioHeader($scan_start_offset[$current_segment] + $j, $dummy, false, false, $FastMode)) { - $calculated_next_offset = $scan_start_offset[$current_segment] + $j + $dummy['mpeg']['audio']['framelength']; - if ($this->decodeMPEGaudioHeader($calculated_next_offset, $dummy, false, false, $FastMode)) { - $scan_start_offset[$current_segment] += $j; - break; - } - } - } - } - } - $synchstartoffset = $scan_start_offset[$current_segment]; - while ($this->decodeMPEGaudioHeader($synchstartoffset, $dummy, false, false, $FastMode)) { - $FastMode = true; - $thisframebitrate = $MPEGaudioBitrateLookup[$MPEGaudioVersionLookup[$dummy['mpeg']['audio']['raw']['version']]][$MPEGaudioLayerLookup[$dummy['mpeg']['audio']['raw']['layer']]][$dummy['mpeg']['audio']['raw']['bitrate']]; - - if (empty($dummy['mpeg']['audio']['framelength'])) { - $SynchErrorsFound++; - $synchstartoffset++; - } else { - getid3_lib::safe_inc($info['mpeg']['audio']['bitrate_distribution'][$thisframebitrate]); - getid3_lib::safe_inc($info['mpeg']['audio']['stereo_distribution'][$dummy['mpeg']['audio']['channelmode']]); - getid3_lib::safe_inc($info['mpeg']['audio']['version_distribution'][$dummy['mpeg']['audio']['version']]); - $synchstartoffset += $dummy['mpeg']['audio']['framelength']; - } - $frames_scanned++; - if ($frames_scan_per_segment && (++$frames_scanned_this_segment >= $frames_scan_per_segment)) { - $this_pct_scanned = ($this->ftell() - $scan_start_offset[$current_segment]) / ($info['avdataend'] - $info['avdataoffset']); - if (($current_segment == 0) && (($this_pct_scanned * $max_scan_segments) >= 1)) { - // file likely contains < $max_frames_scan, just scan as one segment - $max_scan_segments = 1; - $frames_scan_per_segment = $max_frames_scan; - } else { - $pct_data_scanned += $this_pct_scanned; - break; - } - } - } - } - if ($pct_data_scanned > 0) { - $this->warning('too many MPEG audio frames to scan, only scanned '.$frames_scanned.' frames in '.$max_scan_segments.' segments ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.'); - foreach ($info['mpeg']['audio'] as $key1 => $value1) { - if (!preg_match('#_distribution$#i', $key1)) { - continue; - } - foreach ($value1 as $key2 => $value2) { - $info['mpeg']['audio'][$key1][$key2] = round($value2 / $pct_data_scanned); - } - } - } - - if ($SynchErrorsFound > 0) { - $this->warning('Found '.$SynchErrorsFound.' synch errors in histogram analysis'); - //return false; - } - - $bittotal = 0; - $framecounter = 0; - foreach ($info['mpeg']['audio']['bitrate_distribution'] as $bitratevalue => $bitratecount) { - $framecounter += $bitratecount; - if ($bitratevalue != 'free') { - $bittotal += ($bitratevalue * $bitratecount); - } - } - if ($framecounter == 0) { - $this->error('Corrupt MP3 file: framecounter == zero'); - return false; - } - $info['mpeg']['audio']['frame_count'] = getid3_lib::CastAsInt($framecounter); - $info['mpeg']['audio']['bitrate'] = ($bittotal / $framecounter); - - $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; - - - // Definitively set VBR vs CBR, even if the Xing/LAME/VBRI header says differently - $distinct_bitrates = 0; - foreach ($info['mpeg']['audio']['bitrate_distribution'] as $bitrate_value => $bitrate_count) { - if ($bitrate_count > 0) { - $distinct_bitrates++; - } - } - if ($distinct_bitrates > 1) { - $info['mpeg']['audio']['bitrate_mode'] = 'vbr'; - } else { - $info['mpeg']['audio']['bitrate_mode'] = 'cbr'; - } - $info['audio']['bitrate_mode'] = $info['mpeg']['audio']['bitrate_mode']; - - } - - break; // exit while() - } - } - - $SynchSeekOffset++; - if (($avdataoffset + $SynchSeekOffset) >= $info['avdataend']) { - // end of file/data - - if (empty($info['mpeg']['audio'])) { - - $this->error('could not find valid MPEG synch before end of file'); - if (isset($info['audio']['bitrate'])) { - unset($info['audio']['bitrate']); - } - if (isset($info['mpeg']['audio'])) { - unset($info['mpeg']['audio']); - } - if (isset($info['mpeg']) && (!is_array($info['mpeg']) || empty($info['mpeg']))) { - unset($info['mpeg']); - } - return false; - - } - break; - } - - } - $info['audio']['channels'] = $info['mpeg']['audio']['channels']; - $info['audio']['channelmode'] = $info['mpeg']['audio']['channelmode']; - $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; - return true; - } - - - public static function MPEGaudioVersionArray() { - static $MPEGaudioVersion = array('2.5', false, '2', '1'); - return $MPEGaudioVersion; - } - - public static function MPEGaudioLayerArray() { - static $MPEGaudioLayer = array(false, 3, 2, 1); - return $MPEGaudioLayer; - } - - public static function MPEGaudioBitrateArray() { - static $MPEGaudioBitrate; - if (empty($MPEGaudioBitrate)) { - $MPEGaudioBitrate = array ( - '1' => array (1 => array('free', 32000, 64000, 96000, 128000, 160000, 192000, 224000, 256000, 288000, 320000, 352000, 384000, 416000, 448000), - 2 => array('free', 32000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000, 384000), - 3 => array('free', 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000) - ), - - '2' => array (1 => array('free', 32000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 176000, 192000, 224000, 256000), - 2 => array('free', 8000, 16000, 24000, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000), - ) - ); - $MPEGaudioBitrate['2'][3] = $MPEGaudioBitrate['2'][2]; - $MPEGaudioBitrate['2.5'] = $MPEGaudioBitrate['2']; - } - return $MPEGaudioBitrate; - } - - public static function MPEGaudioFrequencyArray() { - static $MPEGaudioFrequency; - if (empty($MPEGaudioFrequency)) { - $MPEGaudioFrequency = array ( - '1' => array(44100, 48000, 32000), - '2' => array(22050, 24000, 16000), - '2.5' => array(11025, 12000, 8000) - ); - } - return $MPEGaudioFrequency; - } - - public static function MPEGaudioChannelModeArray() { - static $MPEGaudioChannelMode = array('stereo', 'joint stereo', 'dual channel', 'mono'); - return $MPEGaudioChannelMode; - } - - public static function MPEGaudioModeExtensionArray() { - static $MPEGaudioModeExtension; - if (empty($MPEGaudioModeExtension)) { - $MPEGaudioModeExtension = array ( - 1 => array('4-31', '8-31', '12-31', '16-31'), - 2 => array('4-31', '8-31', '12-31', '16-31'), - 3 => array('', 'IS', 'MS', 'IS+MS') - ); - } - return $MPEGaudioModeExtension; - } - - public static function MPEGaudioEmphasisArray() { - static $MPEGaudioEmphasis = array('none', '50/15ms', false, 'CCIT J.17'); - return $MPEGaudioEmphasis; - } - - public static function MPEGaudioHeaderBytesValid($head4, $allowBitrate15=false) { - return self::MPEGaudioHeaderValid(self::MPEGaudioHeaderDecode($head4), false, $allowBitrate15); - } - - public static function MPEGaudioHeaderValid($rawarray, $echoerrors=false, $allowBitrate15=false) { - if (($rawarray['synch'] & 0x0FFE) != 0x0FFE) { - return false; - } - - static $MPEGaudioVersionLookup; - static $MPEGaudioLayerLookup; - static $MPEGaudioBitrateLookup; - static $MPEGaudioFrequencyLookup; - static $MPEGaudioChannelModeLookup; - static $MPEGaudioModeExtensionLookup; - static $MPEGaudioEmphasisLookup; - if (empty($MPEGaudioVersionLookup)) { - $MPEGaudioVersionLookup = self::MPEGaudioVersionArray(); - $MPEGaudioLayerLookup = self::MPEGaudioLayerArray(); - $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray(); - $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray(); - $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray(); - $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray(); - $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray(); - } - - if (isset($MPEGaudioVersionLookup[$rawarray['version']])) { - $decodedVersion = $MPEGaudioVersionLookup[$rawarray['version']]; - } else { - echo ($echoerrors ? "\n".'invalid Version ('.$rawarray['version'].')' : ''); - return false; - } - if (isset($MPEGaudioLayerLookup[$rawarray['layer']])) { - $decodedLayer = $MPEGaudioLayerLookup[$rawarray['layer']]; - } else { - echo ($echoerrors ? "\n".'invalid Layer ('.$rawarray['layer'].')' : ''); - return false; - } - if (!isset($MPEGaudioBitrateLookup[$decodedVersion][$decodedLayer][$rawarray['bitrate']])) { - echo ($echoerrors ? "\n".'invalid Bitrate ('.$rawarray['bitrate'].')' : ''); - if ($rawarray['bitrate'] == 15) { - // known issue in LAME 3.90 - 3.93.1 where free-format has bitrate ID of 15 instead of 0 - // let it go through here otherwise file will not be identified - if (!$allowBitrate15) { - return false; - } - } else { - return false; - } - } - if (!isset($MPEGaudioFrequencyLookup[$decodedVersion][$rawarray['sample_rate']])) { - echo ($echoerrors ? "\n".'invalid Frequency ('.$rawarray['sample_rate'].')' : ''); - return false; - } - if (!isset($MPEGaudioChannelModeLookup[$rawarray['channelmode']])) { - echo ($echoerrors ? "\n".'invalid ChannelMode ('.$rawarray['channelmode'].')' : ''); - return false; - } - if (!isset($MPEGaudioModeExtensionLookup[$decodedLayer][$rawarray['modeextension']])) { - echo ($echoerrors ? "\n".'invalid Mode Extension ('.$rawarray['modeextension'].')' : ''); - return false; - } - if (!isset($MPEGaudioEmphasisLookup[$rawarray['emphasis']])) { - echo ($echoerrors ? "\n".'invalid Emphasis ('.$rawarray['emphasis'].')' : ''); - return false; - } - // These are just either set or not set, you can't mess that up :) - // $rawarray['protection']; - // $rawarray['padding']; - // $rawarray['private']; - // $rawarray['copyright']; - // $rawarray['original']; - - return true; - } - - public static function MPEGaudioHeaderDecode($Header4Bytes) { - // AAAA AAAA AAAB BCCD EEEE FFGH IIJJ KLMM - // A - Frame sync (all bits set) - // B - MPEG Audio version ID - // C - Layer description - // D - Protection bit - // E - Bitrate index - // F - Sampling rate frequency index - // G - Padding bit - // H - Private bit - // I - Channel Mode - // J - Mode extension (Only if Joint stereo) - // K - Copyright - // L - Original - // M - Emphasis - - if (strlen($Header4Bytes) != 4) { - return false; - } - - $MPEGrawHeader['synch'] = (getid3_lib::BigEndian2Int(substr($Header4Bytes, 0, 2)) & 0xFFE0) >> 4; - $MPEGrawHeader['version'] = (ord($Header4Bytes{1}) & 0x18) >> 3; // BB - $MPEGrawHeader['layer'] = (ord($Header4Bytes{1}) & 0x06) >> 1; // CC - $MPEGrawHeader['protection'] = (ord($Header4Bytes{1}) & 0x01); // D - $MPEGrawHeader['bitrate'] = (ord($Header4Bytes{2}) & 0xF0) >> 4; // EEEE - $MPEGrawHeader['sample_rate'] = (ord($Header4Bytes{2}) & 0x0C) >> 2; // FF - $MPEGrawHeader['padding'] = (ord($Header4Bytes{2}) & 0x02) >> 1; // G - $MPEGrawHeader['private'] = (ord($Header4Bytes{2}) & 0x01); // H - $MPEGrawHeader['channelmode'] = (ord($Header4Bytes{3}) & 0xC0) >> 6; // II - $MPEGrawHeader['modeextension'] = (ord($Header4Bytes{3}) & 0x30) >> 4; // JJ - $MPEGrawHeader['copyright'] = (ord($Header4Bytes{3}) & 0x08) >> 3; // K - $MPEGrawHeader['original'] = (ord($Header4Bytes{3}) & 0x04) >> 2; // L - $MPEGrawHeader['emphasis'] = (ord($Header4Bytes{3}) & 0x03); // MM - - return $MPEGrawHeader; - } - - public static function MPEGaudioFrameLength(&$bitrate, &$version, &$layer, $padding, &$samplerate) { - static $AudioFrameLengthCache = array(); - - if (!isset($AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate])) { - $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] = false; - if ($bitrate != 'free') { - - if ($version == '1') { - - if ($layer == '1') { - - // For Layer I slot is 32 bits long - $FrameLengthCoefficient = 48; - $SlotLength = 4; - - } else { // Layer 2 / 3 - - // for Layer 2 and Layer 3 slot is 8 bits long. - $FrameLengthCoefficient = 144; - $SlotLength = 1; - - } - - } else { // MPEG-2 / MPEG-2.5 - - if ($layer == '1') { - - // For Layer I slot is 32 bits long - $FrameLengthCoefficient = 24; - $SlotLength = 4; - - } elseif ($layer == '2') { - - // for Layer 2 and Layer 3 slot is 8 bits long. - $FrameLengthCoefficient = 144; - $SlotLength = 1; - - } else { // layer 3 - - // for Layer 2 and Layer 3 slot is 8 bits long. - $FrameLengthCoefficient = 72; - $SlotLength = 1; - - } - - } - - // FrameLengthInBytes = ((Coefficient * BitRate) / SampleRate) + Padding - if ($samplerate > 0) { - $NewFramelength = ($FrameLengthCoefficient * $bitrate) / $samplerate; - $NewFramelength = floor($NewFramelength / $SlotLength) * $SlotLength; // round to next-lower multiple of SlotLength (1 byte for Layer 2/3, 4 bytes for Layer I) - if ($padding) { - $NewFramelength += $SlotLength; - } - $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] = (int) $NewFramelength; - } - } - } - return $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate]; - } - - public static function ClosestStandardMP3Bitrate($bit_rate) { - static $standard_bit_rates = array (320000, 256000, 224000, 192000, 160000, 128000, 112000, 96000, 80000, 64000, 56000, 48000, 40000, 32000, 24000, 16000, 8000); - static $bit_rate_table = array (0=>'-'); - $round_bit_rate = intval(round($bit_rate, -3)); - if (!isset($bit_rate_table[$round_bit_rate])) { - if ($round_bit_rate > max($standard_bit_rates)) { - $bit_rate_table[$round_bit_rate] = round($bit_rate, 2 - strlen($bit_rate)); - } else { - $bit_rate_table[$round_bit_rate] = max($standard_bit_rates); - foreach ($standard_bit_rates as $standard_bit_rate) { - if ($round_bit_rate >= $standard_bit_rate + (($bit_rate_table[$round_bit_rate] - $standard_bit_rate) / 2)) { - break; - } - $bit_rate_table[$round_bit_rate] = $standard_bit_rate; - } - } - } - return $bit_rate_table[$round_bit_rate]; - } - - public static function XingVBRidOffset($version, $channelmode) { - static $XingVBRidOffsetCache = array(); - if (empty($XingVBRidOffset)) { - $XingVBRidOffset = array ( - '1' => array ('mono' => 0x15, // 4 + 17 = 21 - 'stereo' => 0x24, // 4 + 32 = 36 - 'joint stereo' => 0x24, - 'dual channel' => 0x24 - ), - - '2' => array ('mono' => 0x0D, // 4 + 9 = 13 - 'stereo' => 0x15, // 4 + 17 = 21 - 'joint stereo' => 0x15, - 'dual channel' => 0x15 - ), - - '2.5' => array ('mono' => 0x15, - 'stereo' => 0x15, - 'joint stereo' => 0x15, - 'dual channel' => 0x15 - ) - ); - } - return $XingVBRidOffset[$version][$channelmode]; - } - - public static function LAMEvbrMethodLookup($VBRmethodID) { - static $LAMEvbrMethodLookup = array( - 0x00 => 'unknown', - 0x01 => 'cbr', - 0x02 => 'abr', - 0x03 => 'vbr-old / vbr-rh', - 0x04 => 'vbr-new / vbr-mtrh', - 0x05 => 'vbr-mt', - 0x06 => 'vbr (full vbr method 4)', - 0x08 => 'cbr (constant bitrate 2 pass)', - 0x09 => 'abr (2 pass)', - 0x0F => 'reserved' - ); - return (isset($LAMEvbrMethodLookup[$VBRmethodID]) ? $LAMEvbrMethodLookup[$VBRmethodID] : ''); - } - - public static function LAMEmiscStereoModeLookup($StereoModeID) { - static $LAMEmiscStereoModeLookup = array( - 0 => 'mono', - 1 => 'stereo', - 2 => 'dual mono', - 3 => 'joint stereo', - 4 => 'forced stereo', - 5 => 'auto', - 6 => 'intensity stereo', - 7 => 'other' - ); - return (isset($LAMEmiscStereoModeLookup[$StereoModeID]) ? $LAMEmiscStereoModeLookup[$StereoModeID] : ''); - } - - public static function LAMEmiscSourceSampleFrequencyLookup($SourceSampleFrequencyID) { - static $LAMEmiscSourceSampleFrequencyLookup = array( - 0 => '<= 32 kHz', - 1 => '44.1 kHz', - 2 => '48 kHz', - 3 => '> 48kHz' - ); - return (isset($LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID]) ? $LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID] : ''); - } - - public static function LAMEsurroundInfoLookup($SurroundInfoID) { - static $LAMEsurroundInfoLookup = array( - 0 => 'no surround info', - 1 => 'DPL encoding', - 2 => 'DPL2 encoding', - 3 => 'Ambisonic encoding' - ); - return (isset($LAMEsurroundInfoLookup[$SurroundInfoID]) ? $LAMEsurroundInfoLookup[$SurroundInfoID] : 'reserved'); - } - - public static function LAMEpresetUsedLookup($LAMEtag) { - - if ($LAMEtag['preset_used_id'] == 0) { - // no preset used (LAME >=3.93) - // no preset recorded (LAME <3.93) - return ''; - } - $LAMEpresetUsedLookup = array(); - - ///// THIS PART CANNOT BE STATIC . - for ($i = 8; $i <= 320; $i++) { - switch ($LAMEtag['vbr_method']) { - case 'cbr': - $LAMEpresetUsedLookup[$i] = '--alt-preset '.$LAMEtag['vbr_method'].' '.$i; - break; - case 'abr': - default: // other VBR modes shouldn't be here(?) - $LAMEpresetUsedLookup[$i] = '--alt-preset '.$i; - break; - } - } - - // named old-style presets (studio, phone, voice, etc) are handled in GuessEncoderOptions() - - // named alt-presets - $LAMEpresetUsedLookup[1000] = '--r3mix'; - $LAMEpresetUsedLookup[1001] = '--alt-preset standard'; - $LAMEpresetUsedLookup[1002] = '--alt-preset extreme'; - $LAMEpresetUsedLookup[1003] = '--alt-preset insane'; - $LAMEpresetUsedLookup[1004] = '--alt-preset fast standard'; - $LAMEpresetUsedLookup[1005] = '--alt-preset fast extreme'; - $LAMEpresetUsedLookup[1006] = '--alt-preset medium'; - $LAMEpresetUsedLookup[1007] = '--alt-preset fast medium'; - - // LAME 3.94 additions/changes - $LAMEpresetUsedLookup[1010] = '--preset portable'; // 3.94a15 Oct 21 2003 - $LAMEpresetUsedLookup[1015] = '--preset radio'; // 3.94a15 Oct 21 2003 - - $LAMEpresetUsedLookup[320] = '--preset insane'; // 3.94a15 Nov 12 2003 - $LAMEpresetUsedLookup[410] = '-V9'; - $LAMEpresetUsedLookup[420] = '-V8'; - $LAMEpresetUsedLookup[440] = '-V6'; - $LAMEpresetUsedLookup[430] = '--preset radio'; // 3.94a15 Nov 12 2003 - $LAMEpresetUsedLookup[450] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'portable'; // 3.94a15 Nov 12 2003 - $LAMEpresetUsedLookup[460] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'medium'; // 3.94a15 Nov 12 2003 - $LAMEpresetUsedLookup[470] = '--r3mix'; // 3.94b1 Dec 18 2003 - $LAMEpresetUsedLookup[480] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'standard'; // 3.94a15 Nov 12 2003 - $LAMEpresetUsedLookup[490] = '-V1'; - $LAMEpresetUsedLookup[500] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'extreme'; // 3.94a15 Nov 12 2003 - - return (isset($LAMEpresetUsedLookup[$LAMEtag['preset_used_id']]) ? $LAMEpresetUsedLookup[$LAMEtag['preset_used_id']] : 'new/unknown preset: '.$LAMEtag['preset_used_id'].' - report to info@getid3.org'); - } - + public $allow_bruteforce = false; // forces getID3() to scan the file byte-by-byte and log all the valid audio frame headers - extremely slow, unrecommended, but may provide data from otherwise-unusuable files + + public function Analyze() + { + $info = &$this->getid3->info; + + $initialOffset = $info['avdataoffset']; + + if (! $this->getOnlyMPEGaudioInfo($info['avdataoffset'])) { + if ($this->allow_bruteforce) { + $this->error('Rescanning file in BruteForce mode'); + $this->getOnlyMPEGaudioInfoBruteForce($this->getid3->fp, $info); + } + } + + if (isset($info['mpeg']['audio']['bitrate_mode'])) { + $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); + } + + if (((isset($info['id3v2']['headerlength']) && ($info['avdataoffset'] > $info['id3v2']['headerlength'])) || (! isset($info['id3v2']) && ($info['avdataoffset'] > 0) && ($info['avdataoffset'] != $initialOffset)))) { + $synchoffsetwarning = 'Unknown data before synch '; + if (isset($info['id3v2']['headerlength'])) { + $synchoffsetwarning .= '(ID3v2 header ends at '.$info['id3v2']['headerlength'].', then '.($info['avdataoffset'] - $info['id3v2']['headerlength']).' bytes garbage, '; + } elseif ($initialOffset > 0) { + $synchoffsetwarning .= '(should be at '.$initialOffset.', '; + } else { + $synchoffsetwarning .= '(should be at beginning of file, '; + } + $synchoffsetwarning .= 'synch detected at '.$info['avdataoffset'].')'; + if (isset($info['audio']['bitrate_mode']) && ($info['audio']['bitrate_mode'] == 'cbr')) { + if (! empty($info['id3v2']['headerlength']) && (($info['avdataoffset'] - $info['id3v2']['headerlength']) == $info['mpeg']['audio']['framelength'])) { + $synchoffsetwarning .= '. This is a known problem with some versions of LAME (3.90-3.92) DLL in CBR mode.'; + $info['audio']['codec'] = 'LAME'; + $CurrentDataLAMEversionString = 'LAME3.'; + } elseif (empty($info['id3v2']['headerlength']) && ($info['avdataoffset'] == $info['mpeg']['audio']['framelength'])) { + $synchoffsetwarning .= '. This is a known problem with some versions of LAME (3.90 - 3.92) DLL in CBR mode.'; + $info['audio']['codec'] = 'LAME'; + $CurrentDataLAMEversionString = 'LAME3.'; + } + } + $this->warning($synchoffsetwarning); + } + + if (isset($info['mpeg']['audio']['LAME'])) { + $info['audio']['codec'] = 'LAME'; + if (! empty($info['mpeg']['audio']['LAME']['long_version'])) { + $info['audio']['encoder'] = rtrim($info['mpeg']['audio']['LAME']['long_version'], "\x00"); + } elseif (! empty($info['mpeg']['audio']['LAME']['short_version'])) { + $info['audio']['encoder'] = rtrim($info['mpeg']['audio']['LAME']['short_version'], "\x00"); + } + } + + $CurrentDataLAMEversionString = (! empty($CurrentDataLAMEversionString) ? $CurrentDataLAMEversionString : (isset($info['audio']['encoder']) ? $info['audio']['encoder'] : '')); + if (! empty($CurrentDataLAMEversionString) && (substr($CurrentDataLAMEversionString, 0, 6) == 'LAME3.') && ! preg_match('[0-9\)]', substr($CurrentDataLAMEversionString, -1))) { + // a version number of LAME that does not end with a number like "LAME3.92" + // or with a closing parenthesis like "LAME3.88 (alpha)" + // or a version of LAME with the LAMEtag-not-filled-in-DLL-mode bug (3.90-3.92) + + // not sure what the actual last frame length will be, but will be less than or equal to 1441 + $PossiblyLongerLAMEversion_FrameLength = 1441; + + // Not sure what version of LAME this is - look in padding of last frame for longer version string + $PossibleLAMEversionStringOffset = $info['avdataend'] - $PossiblyLongerLAMEversion_FrameLength; + $this->fseek($PossibleLAMEversionStringOffset); + $PossiblyLongerLAMEversion_Data = $this->fread($PossiblyLongerLAMEversion_FrameLength); + switch (substr($CurrentDataLAMEversionString, -1)) { + case 'a': + case 'b': + // "LAME3.94a" will have a longer version string of "LAME3.94 (alpha)" for example + // need to trim off "a" to match longer string + $CurrentDataLAMEversionString = substr($CurrentDataLAMEversionString, 0, -1); + break; + } + if (($PossiblyLongerLAMEversion_String = strstr($PossiblyLongerLAMEversion_Data, $CurrentDataLAMEversionString)) !== false) { + if (substr($PossiblyLongerLAMEversion_String, 0, strlen($CurrentDataLAMEversionString)) == $CurrentDataLAMEversionString) { + $PossiblyLongerLAMEversion_NewString = substr($PossiblyLongerLAMEversion_String, 0, strspn($PossiblyLongerLAMEversion_String, 'LAME0123456789., (abcdefghijklmnopqrstuvwxyzJFSOND)')); //"LAME3.90.3" "LAME3.87 (beta 1, Sep 27 2000)" "LAME3.88 (beta)" + if (empty($info['audio']['encoder']) || (strlen($PossiblyLongerLAMEversion_NewString) > strlen($info['audio']['encoder']))) { + $info['audio']['encoder'] = $PossiblyLongerLAMEversion_NewString; + } + } + } + } + if (! empty($info['audio']['encoder'])) { + $info['audio']['encoder'] = rtrim($info['audio']['encoder'], "\x00 "); + } + + switch (isset($info['mpeg']['audio']['layer']) ? $info['mpeg']['audio']['layer'] : '') { + case 1: + case 2: + $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer']; + break; + } + if (isset($info['fileformat']) && ($info['fileformat'] == 'mp3')) { + switch ($info['audio']['dataformat']) { + case 'mp1': + case 'mp2': + case 'mp3': + $info['fileformat'] = $info['audio']['dataformat']; + break; + + default: + $this->warning('Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$info['audio']['dataformat'].'"'); + break; + } + } + + if (empty($info['fileformat'])) { + unset($info['fileformat']); + unset($info['audio']['bitrate_mode']); + unset($info['avdataoffset']); + unset($info['avdataend']); + + return false; + } + + $info['mime_type'] = 'audio/mpeg'; + $info['audio']['lossless'] = false; + + // Calculate playtime + if (! isset($info['playtime_seconds']) && isset($info['audio']['bitrate']) && ($info['audio']['bitrate'] > 0)) { + $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['audio']['bitrate']; + } + + $info['audio']['encoder_options'] = $this->GuessEncoderOptions(); + + return true; + } + + public function GuessEncoderOptions() + { + // shortcuts + $info = &$this->getid3->info; + if (! empty($info['mpeg']['audio'])) { + $thisfile_mpeg_audio = &$info['mpeg']['audio']; + if (! empty($thisfile_mpeg_audio['LAME'])) { + $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio['LAME']; + } + } + + $encoder_options = ''; + static $NamedPresetBitrates = [16, 24, 40, 56, 112, 128, 160, 192, 256]; + + if (isset($thisfile_mpeg_audio['VBR_method']) && ($thisfile_mpeg_audio['VBR_method'] == 'Fraunhofer') && ! empty($thisfile_mpeg_audio['VBR_quality'])) { + $encoder_options = 'VBR q'.$thisfile_mpeg_audio['VBR_quality']; + } elseif (! empty($thisfile_mpeg_audio_lame['preset_used']) && (! in_array($thisfile_mpeg_audio_lame['preset_used_id'], $NamedPresetBitrates))) { + $encoder_options = $thisfile_mpeg_audio_lame['preset_used']; + } elseif (! empty($thisfile_mpeg_audio_lame['vbr_quality'])) { + static $KnownEncoderValues = []; + if (empty($KnownEncoderValues)) { + + //$KnownEncoderValues[abrbitrate_minbitrate][vbr_quality][raw_vbr_method][raw_noise_shaping][raw_stereo_mode][ath_type][lowpass_frequency] = 'preset name'; + $KnownEncoderValues[0xFF][58][1][1][3][2][20500] = '--alt-preset insane'; // 3.90, 3.90.1, 3.92 + $KnownEncoderValues[0xFF][58][1][1][3][2][20600] = '--alt-preset insane'; // 3.90.2, 3.90.3, 3.91 + $KnownEncoderValues[0xFF][57][1][1][3][4][20500] = '--alt-preset insane'; // 3.94, 3.95 + $KnownEncoderValues['**'][78][3][2][3][2][19500] = '--alt-preset extreme'; // 3.90, 3.90.1, 3.92 + $KnownEncoderValues['**'][78][3][2][3][2][19600] = '--alt-preset extreme'; // 3.90.2, 3.91 + $KnownEncoderValues['**'][78][3][1][3][2][19600] = '--alt-preset extreme'; // 3.90.3 + $KnownEncoderValues['**'][78][4][2][3][2][19500] = '--alt-preset fast extreme'; // 3.90, 3.90.1, 3.92 + $KnownEncoderValues['**'][78][4][2][3][2][19600] = '--alt-preset fast extreme'; // 3.90.2, 3.90.3, 3.91 + $KnownEncoderValues['**'][78][3][2][3][4][19000] = '--alt-preset standard'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 + $KnownEncoderValues['**'][78][3][1][3][4][19000] = '--alt-preset standard'; // 3.90.3 + $KnownEncoderValues['**'][78][4][2][3][4][19000] = '--alt-preset fast standard'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 + $KnownEncoderValues['**'][78][4][1][3][4][19000] = '--alt-preset fast standard'; // 3.90.3 + $KnownEncoderValues['**'][88][4][1][3][3][19500] = '--r3mix'; // 3.90, 3.90.1, 3.92 + $KnownEncoderValues['**'][88][4][1][3][3][19600] = '--r3mix'; // 3.90.2, 3.90.3, 3.91 + $KnownEncoderValues['**'][67][4][1][3][4][18000] = '--r3mix'; // 3.94, 3.95 + $KnownEncoderValues['**'][68][3][2][3][4][18000] = '--alt-preset medium'; // 3.90.3 + $KnownEncoderValues['**'][68][4][2][3][4][18000] = '--alt-preset fast medium'; // 3.90.3 + + $KnownEncoderValues[0xFF][99][1][1][1][2][0] = '--preset studio'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 + $KnownEncoderValues[0xFF][58][2][1][3][2][20600] = '--preset studio'; // 3.90.3, 3.93.1 + $KnownEncoderValues[0xFF][58][2][1][3][2][20500] = '--preset studio'; // 3.93 + $KnownEncoderValues[0xFF][57][2][1][3][4][20500] = '--preset studio'; // 3.94, 3.95 + $KnownEncoderValues[0xC0][88][1][1][1][2][0] = '--preset cd'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 + $KnownEncoderValues[0xC0][58][2][2][3][2][19600] = '--preset cd'; // 3.90.3, 3.93.1 + $KnownEncoderValues[0xC0][58][2][2][3][2][19500] = '--preset cd'; // 3.93 + $KnownEncoderValues[0xC0][57][2][1][3][4][19500] = '--preset cd'; // 3.94, 3.95 + $KnownEncoderValues[0xA0][78][1][1][3][2][18000] = '--preset hifi'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 + $KnownEncoderValues[0xA0][58][2][2][3][2][18000] = '--preset hifi'; // 3.90.3, 3.93, 3.93.1 + $KnownEncoderValues[0xA0][57][2][1][3][4][18000] = '--preset hifi'; // 3.94, 3.95 + $KnownEncoderValues[0x80][67][1][1][3][2][18000] = '--preset tape'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 + $KnownEncoderValues[0x80][67][1][1][3][2][15000] = '--preset radio'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 + $KnownEncoderValues[0x70][67][1][1][3][2][15000] = '--preset fm'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92 + $KnownEncoderValues[0x70][58][2][2][3][2][16000] = '--preset tape/radio/fm'; // 3.90.3, 3.93, 3.93.1 + $KnownEncoderValues[0x70][57][2][1][3][4][16000] = '--preset tape/radio/fm'; // 3.94, 3.95 + $KnownEncoderValues[0x38][58][2][2][0][2][10000] = '--preset voice'; // 3.90.3, 3.93, 3.93.1 + $KnownEncoderValues[0x38][57][2][1][0][4][15000] = '--preset voice'; // 3.94, 3.95 + $KnownEncoderValues[0x38][57][2][1][0][4][16000] = '--preset voice'; // 3.94a14 + $KnownEncoderValues[0x28][65][1][1][0][2][7500] = '--preset mw-us'; // 3.90, 3.90.1, 3.92 + $KnownEncoderValues[0x28][65][1][1][0][2][7600] = '--preset mw-us'; // 3.90.2, 3.91 + $KnownEncoderValues[0x28][58][2][2][0][2][7000] = '--preset mw-us'; // 3.90.3, 3.93, 3.93.1 + $KnownEncoderValues[0x28][57][2][1][0][4][10500] = '--preset mw-us'; // 3.94, 3.95 + $KnownEncoderValues[0x28][57][2][1][0][4][11200] = '--preset mw-us'; // 3.94a14 + $KnownEncoderValues[0x28][57][2][1][0][4][8800] = '--preset mw-us'; // 3.94a15 + $KnownEncoderValues[0x18][58][2][2][0][2][4000] = '--preset phon+/lw/mw-eu/sw'; // 3.90.3, 3.93.1 + $KnownEncoderValues[0x18][58][2][2][0][2][3900] = '--preset phon+/lw/mw-eu/sw'; // 3.93 + $KnownEncoderValues[0x18][57][2][1][0][4][5900] = '--preset phon+/lw/mw-eu/sw'; // 3.94, 3.95 + $KnownEncoderValues[0x18][57][2][1][0][4][6200] = '--preset phon+/lw/mw-eu/sw'; // 3.94a14 + $KnownEncoderValues[0x18][57][2][1][0][4][3200] = '--preset phon+/lw/mw-eu/sw'; // 3.94a15 + $KnownEncoderValues[0x10][58][2][2][0][2][3800] = '--preset phone'; // 3.90.3, 3.93.1 + $KnownEncoderValues[0x10][58][2][2][0][2][3700] = '--preset phone'; // 3.93 + $KnownEncoderValues[0x10][57][2][1][0][4][5600] = '--preset phone'; // 3.94, 3.95 + } + + if (isset($KnownEncoderValues[$thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']])) { + $encoder_options = $KnownEncoderValues[$thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']]; + } elseif (isset($KnownEncoderValues['**'][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']])) { + $encoder_options = $KnownEncoderValues['**'][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']]; + } elseif ($info['audio']['bitrate_mode'] == 'vbr') { + + // http://gabriel.mp3-tech.org/mp3infotag.html + // int Quality = (100 - 10 * gfp->VBR_q - gfp->quality)h + + $LAME_V_value = 10 - ceil($thisfile_mpeg_audio_lame['vbr_quality'] / 10); + $LAME_q_value = 100 - $thisfile_mpeg_audio_lame['vbr_quality'] - ($LAME_V_value * 10); + $encoder_options = '-V'.$LAME_V_value.' -q'.$LAME_q_value; + } elseif ($info['audio']['bitrate_mode'] == 'cbr') { + $encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000); + } else { + $encoder_options = strtoupper($info['audio']['bitrate_mode']); + } + } elseif (! empty($thisfile_mpeg_audio_lame['bitrate_abr'])) { + $encoder_options = 'ABR'.$thisfile_mpeg_audio_lame['bitrate_abr']; + } elseif (! empty($info['audio']['bitrate'])) { + if ($info['audio']['bitrate_mode'] == 'cbr') { + $encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000); + } else { + $encoder_options = strtoupper($info['audio']['bitrate_mode']); + } + } + if (! empty($thisfile_mpeg_audio_lame['bitrate_min'])) { + $encoder_options .= ' -b'.$thisfile_mpeg_audio_lame['bitrate_min']; + } + + if (! empty($thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev']) || ! empty($thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'])) { + $encoder_options .= ' --nogap'; + } + + if (! empty($thisfile_mpeg_audio_lame['lowpass_frequency'])) { + $ExplodedOptions = explode(' ', $encoder_options, 4); + if ($ExplodedOptions[0] == '--r3mix') { + $ExplodedOptions[1] = 'r3mix'; + } + switch ($ExplodedOptions[0]) { + case '--preset': + case '--alt-preset': + case '--r3mix': + if ($ExplodedOptions[1] == 'fast') { + $ExplodedOptions[1] .= ' '.$ExplodedOptions[2]; + } + switch ($ExplodedOptions[1]) { + case 'portable': + case 'medium': + case 'standard': + case 'extreme': + case 'insane': + case 'fast portable': + case 'fast medium': + case 'fast standard': + case 'fast extreme': + case 'fast insane': + case 'r3mix': + static $ExpectedLowpass = [ + 'insane|20500' => 20500, + 'insane|20600' => 20600, // 3.90.2, 3.90.3, 3.91 + 'medium|18000' => 18000, + 'fast medium|18000' => 18000, + 'extreme|19500' => 19500, // 3.90, 3.90.1, 3.92, 3.95 + 'extreme|19600' => 19600, // 3.90.2, 3.90.3, 3.91, 3.93.1 + 'fast extreme|19500' => 19500, // 3.90, 3.90.1, 3.92, 3.95 + 'fast extreme|19600' => 19600, // 3.90.2, 3.90.3, 3.91, 3.93.1 + 'standard|19000' => 19000, + 'fast standard|19000' => 19000, + 'r3mix|19500' => 19500, // 3.90, 3.90.1, 3.92 + 'r3mix|19600' => 19600, // 3.90.2, 3.90.3, 3.91 + 'r3mix|18000' => 18000, // 3.94, 3.95 + ]; + if (! isset($ExpectedLowpass[$ExplodedOptions[1].'|'.$thisfile_mpeg_audio_lame['lowpass_frequency']]) && ($thisfile_mpeg_audio_lame['lowpass_frequency'] < 22050) && (round($thisfile_mpeg_audio_lame['lowpass_frequency'] / 1000) < round($thisfile_mpeg_audio['sample_rate'] / 2000))) { + $encoder_options .= ' --lowpass '.$thisfile_mpeg_audio_lame['lowpass_frequency']; + } + break; + + default: + break; + } + break; + } + } + + if (isset($thisfile_mpeg_audio_lame['raw']['source_sample_freq'])) { + if (($thisfile_mpeg_audio['sample_rate'] == 44100) && ($thisfile_mpeg_audio_lame['raw']['source_sample_freq'] != 1)) { + $encoder_options .= ' --resample 44100'; + } elseif (($thisfile_mpeg_audio['sample_rate'] == 48000) && ($thisfile_mpeg_audio_lame['raw']['source_sample_freq'] != 2)) { + $encoder_options .= ' --resample 48000'; + } elseif ($thisfile_mpeg_audio['sample_rate'] < 44100) { + switch ($thisfile_mpeg_audio_lame['raw']['source_sample_freq']) { + case 0: // <= 32000 + // may or may not be same as source frequency - ignore + break; + case 1: // 44100 + case 2: // 48000 + case 3: // 48000+ + $ExplodedOptions = explode(' ', $encoder_options, 4); + switch ($ExplodedOptions[0]) { + case '--preset': + case '--alt-preset': + switch ($ExplodedOptions[1]) { + case 'fast': + case 'portable': + case 'medium': + case 'standard': + case 'extreme': + case 'insane': + $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate']; + break; + + default: + static $ExpectedResampledRate = [ + 'phon+/lw/mw-eu/sw|16000' => 16000, + 'mw-us|24000' => 24000, // 3.95 + 'mw-us|32000' => 32000, // 3.93 + 'mw-us|16000' => 16000, // 3.92 + 'phone|16000' => 16000, + 'phone|11025' => 11025, // 3.94a15 + 'radio|32000' => 32000, // 3.94a15 + 'fm/radio|32000' => 32000, // 3.92 + 'fm|32000' => 32000, // 3.90 + 'voice|32000' => 32000, ]; + if (! isset($ExpectedResampledRate[$ExplodedOptions[1].'|'.$thisfile_mpeg_audio['sample_rate']])) { + $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate']; + } + break; + } + break; + + case '--r3mix': + default: + $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate']; + break; + } + break; + } + } + } + if (empty($encoder_options) && ! empty($info['audio']['bitrate']) && ! empty($info['audio']['bitrate_mode'])) { + //$encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000); + $encoder_options = strtoupper($info['audio']['bitrate_mode']); + } + + return $encoder_options; + } + + public function decodeMPEGaudioHeader($offset, &$info, $recursivesearch = true, $ScanAsCBR = false, $FastMPEGheaderScan = false) + { + static $MPEGaudioVersionLookup; + static $MPEGaudioLayerLookup; + static $MPEGaudioBitrateLookup; + static $MPEGaudioFrequencyLookup; + static $MPEGaudioChannelModeLookup; + static $MPEGaudioModeExtensionLookup; + static $MPEGaudioEmphasisLookup; + if (empty($MPEGaudioVersionLookup)) { + $MPEGaudioVersionLookup = self::MPEGaudioVersionArray(); + $MPEGaudioLayerLookup = self::MPEGaudioLayerArray(); + $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray(); + $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray(); + $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray(); + $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray(); + $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray(); + } + + if ($this->fseek($offset) != 0) { + $this->error('decodeMPEGaudioHeader() failed to seek to next offset at '.$offset); + + return false; + } + //$headerstring = $this->fread(1441); // worst-case max length = 32kHz @ 320kbps layer 3 = 1441 bytes/frame + $headerstring = $this->fread(226); // LAME header at offset 36 + 190 bytes of Xing/LAME data + + // MP3 audio frame structure: + // $aa $aa $aa $aa [$bb $bb] $cc... + // where $aa..$aa is the four-byte mpeg-audio header (below) + // $bb $bb is the optional 2-byte CRC + // and $cc... is the audio data + + $head4 = substr($headerstring, 0, 4); + static $MPEGaudioHeaderDecodeCache = []; + if (isset($MPEGaudioHeaderDecodeCache[$head4])) { + $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4]; + } else { + $MPEGheaderRawArray = self::MPEGaudioHeaderDecode($head4); + $MPEGaudioHeaderDecodeCache[$head4] = $MPEGheaderRawArray; + } + + static $MPEGaudioHeaderValidCache = []; + if (! isset($MPEGaudioHeaderValidCache[$head4])) { // Not in cache + //$MPEGaudioHeaderValidCache[$head4] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, true); // allow badly-formatted freeformat (from LAME 3.90 - 3.93.1) + $MPEGaudioHeaderValidCache[$head4] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, false); + } + + // shortcut + if (! isset($info['mpeg']['audio'])) { + $info['mpeg']['audio'] = []; + } + $thisfile_mpeg_audio = &$info['mpeg']['audio']; + + if ($MPEGaudioHeaderValidCache[$head4]) { + $thisfile_mpeg_audio['raw'] = $MPEGheaderRawArray; + } else { + $this->error('Invalid MPEG audio header ('.getid3_lib::PrintHexBytes($head4).') at offset '.$offset); + + return false; + } + + if (! $FastMPEGheaderScan) { + $thisfile_mpeg_audio['version'] = $MPEGaudioVersionLookup[$thisfile_mpeg_audio['raw']['version']]; + $thisfile_mpeg_audio['layer'] = $MPEGaudioLayerLookup[$thisfile_mpeg_audio['raw']['layer']]; + + $thisfile_mpeg_audio['channelmode'] = $MPEGaudioChannelModeLookup[$thisfile_mpeg_audio['raw']['channelmode']]; + $thisfile_mpeg_audio['channels'] = (($thisfile_mpeg_audio['channelmode'] == 'mono') ? 1 : 2); + $thisfile_mpeg_audio['sample_rate'] = $MPEGaudioFrequencyLookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['raw']['sample_rate']]; + $thisfile_mpeg_audio['protection'] = ! $thisfile_mpeg_audio['raw']['protection']; + $thisfile_mpeg_audio['private'] = (bool) $thisfile_mpeg_audio['raw']['private']; + $thisfile_mpeg_audio['modeextension'] = $MPEGaudioModeExtensionLookup[$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['modeextension']]; + $thisfile_mpeg_audio['copyright'] = (bool) $thisfile_mpeg_audio['raw']['copyright']; + $thisfile_mpeg_audio['original'] = (bool) $thisfile_mpeg_audio['raw']['original']; + $thisfile_mpeg_audio['emphasis'] = $MPEGaudioEmphasisLookup[$thisfile_mpeg_audio['raw']['emphasis']]; + + $info['audio']['channels'] = $thisfile_mpeg_audio['channels']; + $info['audio']['sample_rate'] = $thisfile_mpeg_audio['sample_rate']; + + if ($thisfile_mpeg_audio['protection']) { + $thisfile_mpeg_audio['crc'] = getid3_lib::BigEndian2Int(substr($headerstring, 4, 2)); + } + } + + if ($thisfile_mpeg_audio['raw']['bitrate'] == 15) { + // http://www.hydrogenaudio.org/?act=ST&f=16&t=9682&st=0 + $this->warning('Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1'); + $thisfile_mpeg_audio['raw']['bitrate'] = 0; + } + $thisfile_mpeg_audio['padding'] = (bool) $thisfile_mpeg_audio['raw']['padding']; + $thisfile_mpeg_audio['bitrate'] = $MPEGaudioBitrateLookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['bitrate']]; + + if (($thisfile_mpeg_audio['bitrate'] == 'free') && ($offset == $info['avdataoffset'])) { + // only skip multiple frame check if free-format bitstream found at beginning of file + // otherwise is quite possibly simply corrupted data + $recursivesearch = false; + } + + // For Layer 2 there are some combinations of bitrate and mode which are not allowed. + if (! $FastMPEGheaderScan && ($thisfile_mpeg_audio['layer'] == '2')) { + $info['audio']['dataformat'] = 'mp2'; + switch ($thisfile_mpeg_audio['channelmode']) { + + case 'mono': + if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] <= 192000)) { + // these are ok + } else { + $this->error($thisfile_mpeg_audio['bitrate'].'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.'); + + return false; + } + break; + + case 'stereo': + case 'joint stereo': + case 'dual channel': + if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] == 64000) || ($thisfile_mpeg_audio['bitrate'] >= 96000)) { + // these are ok + } else { + $this->error(intval(round($thisfile_mpeg_audio['bitrate'] / 1000)).'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.'); + + return false; + } + break; + + } + } + + if ($info['audio']['sample_rate'] > 0) { + $thisfile_mpeg_audio['framelength'] = self::MPEGaudioFrameLength($thisfile_mpeg_audio['bitrate'], $thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['layer'], (int) $thisfile_mpeg_audio['padding'], $info['audio']['sample_rate']); + } + + $nextframetestoffset = $offset + 1; + if ($thisfile_mpeg_audio['bitrate'] != 'free') { + $info['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate']; + + if (isset($thisfile_mpeg_audio['framelength'])) { + $nextframetestoffset = $offset + $thisfile_mpeg_audio['framelength']; + } else { + $this->error('Frame at offset('.$offset.') is has an invalid frame length.'); + + return false; + } + } + + $ExpectedNumberOfAudioBytes = 0; + + //////////////////////////////////////////////////////////////////////////////////// + // Variable-bitrate headers + + if (substr($headerstring, 4 + 32, 4) == 'VBRI') { + // Fraunhofer VBR header is hardcoded 'VBRI' at offset 0x24 (36) + // specs taken from http://minnie.tuhs.org/pipermail/mp3encoder/2001-January/001800.html + + $thisfile_mpeg_audio['bitrate_mode'] = 'vbr'; + $thisfile_mpeg_audio['VBR_method'] = 'Fraunhofer'; + $info['audio']['codec'] = 'Fraunhofer'; + + $SideInfoData = substr($headerstring, 4 + 2, 32); + + $FraunhoferVBROffset = 36; + + $thisfile_mpeg_audio['VBR_encoder_version'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 4, 2)); // VbriVersion + $thisfile_mpeg_audio['VBR_encoder_delay'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 6, 2)); // VbriDelay + $thisfile_mpeg_audio['VBR_quality'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 8, 2)); // VbriQuality + $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 10, 4)); // VbriStreamBytes + $thisfile_mpeg_audio['VBR_frames'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 14, 4)); // VbriStreamFrames + $thisfile_mpeg_audio['VBR_seek_offsets'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 18, 2)); // VbriTableSize + $thisfile_mpeg_audio['VBR_seek_scale'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 20, 2)); // VbriTableScale + $thisfile_mpeg_audio['VBR_entry_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 22, 2)); // VbriEntryBytes + $thisfile_mpeg_audio['VBR_entry_frames'] = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 24, 2)); // VbriEntryFrames + + $ExpectedNumberOfAudioBytes = $thisfile_mpeg_audio['VBR_bytes']; + + $previousbyteoffset = $offset; + for ($i = 0; $i < $thisfile_mpeg_audio['VBR_seek_offsets']; $i++) { + $Fraunhofer_OffsetN = getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset, $thisfile_mpeg_audio['VBR_entry_bytes'])); + $FraunhoferVBROffset += $thisfile_mpeg_audio['VBR_entry_bytes']; + $thisfile_mpeg_audio['VBR_offsets_relative'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio['VBR_seek_scale']); + $thisfile_mpeg_audio['VBR_offsets_absolute'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio['VBR_seek_scale']) + $previousbyteoffset; + $previousbyteoffset += $Fraunhofer_OffsetN; + } + } else { + + // Xing VBR header is hardcoded 'Xing' at a offset 0x0D (13), 0x15 (21) or 0x24 (36) + // depending on MPEG layer and number of channels + + $VBRidOffset = self::XingVBRidOffset($thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['channelmode']); + $SideInfoData = substr($headerstring, 4 + 2, $VBRidOffset - 4); + + if ((substr($headerstring, $VBRidOffset, strlen('Xing')) == 'Xing') || (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Info')) { + // 'Xing' is traditional Xing VBR frame + // 'Info' is LAME-encoded CBR (This was done to avoid CBR files to be recognized as traditional Xing VBR files by some decoders.) + // 'Info' *can* legally be used to specify a VBR file as well, however. + + // http://www.multiweb.cz/twoinches/MP3inside.htm + //00..03 = "Xing" or "Info" + //04..07 = Flags: + // 0x01 Frames Flag set if value for number of frames in file is stored + // 0x02 Bytes Flag set if value for filesize in bytes is stored + // 0x04 TOC Flag set if values for TOC are stored + // 0x08 VBR Scale Flag set if values for VBR scale is stored + //08..11 Frames: Number of frames in file (including the first Xing/Info one) + //12..15 Bytes: File length in Bytes + //16..115 TOC (Table of Contents): + // Contains of 100 indexes (one Byte length) for easier lookup in file. Approximately solves problem with moving inside file. + // Each Byte has a value according this formula: + // (TOC[i] / 256) * fileLenInBytes + // So if song lasts eg. 240 sec. and you want to jump to 60. sec. (and file is 5 000 000 Bytes length) you can use: + // TOC[(60/240)*100] = TOC[25] + // and corresponding Byte in file is then approximately at: + // (TOC[25]/256) * 5000000 + //116..119 VBR Scale + + // should be safe to leave this at 'vbr' and let it be overriden to 'cbr' if a CBR preset/mode is used by LAME + // if (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Xing') { + $thisfile_mpeg_audio['bitrate_mode'] = 'vbr'; + $thisfile_mpeg_audio['VBR_method'] = 'Xing'; + // } else { + // $ScanAsCBR = true; + // $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; + // } + + $thisfile_mpeg_audio['xing_flags_raw'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 4, 4)); + + $thisfile_mpeg_audio['xing_flags']['frames'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000001); + $thisfile_mpeg_audio['xing_flags']['bytes'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000002); + $thisfile_mpeg_audio['xing_flags']['toc'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000004); + $thisfile_mpeg_audio['xing_flags']['vbr_scale'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000008); + + if ($thisfile_mpeg_audio['xing_flags']['frames']) { + $thisfile_mpeg_audio['VBR_frames'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 8, 4)); + //$thisfile_mpeg_audio['VBR_frames']--; // don't count header Xing/Info frame + } + if ($thisfile_mpeg_audio['xing_flags']['bytes']) { + $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 12, 4)); + } + + //if (($thisfile_mpeg_audio['bitrate'] == 'free') && !empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) { + //if (!empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) { + if (! empty($thisfile_mpeg_audio['VBR_frames'])) { + $used_filesize = 0; + if (! empty($thisfile_mpeg_audio['VBR_bytes'])) { + $used_filesize = $thisfile_mpeg_audio['VBR_bytes']; + } elseif (! empty($info['filesize'])) { + $used_filesize = $info['filesize']; + $used_filesize -= intval(@$info['id3v2']['headerlength']); + $used_filesize -= (isset($info['id3v1']) ? 128 : 0); + $used_filesize -= (isset($info['tag_offset_end']) ? $info['tag_offset_end'] - $info['tag_offset_start'] : 0); + $this->warning('MP3.Xing header missing VBR_bytes, assuming MPEG audio portion of file is '.number_format($used_filesize).' bytes'); + } + + $framelengthfloat = $used_filesize / $thisfile_mpeg_audio['VBR_frames']; + + if ($thisfile_mpeg_audio['layer'] == '1') { + // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12 + //$info['audio']['bitrate'] = ((($framelengthfloat / 4) - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 12; + $info['audio']['bitrate'] = ($framelengthfloat / 4) * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 12; + } else { + // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144 + //$info['audio']['bitrate'] = (($framelengthfloat - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144; + $info['audio']['bitrate'] = $framelengthfloat * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 144; + } + $thisfile_mpeg_audio['framelength'] = floor($framelengthfloat); + } + + if ($thisfile_mpeg_audio['xing_flags']['toc']) { + $LAMEtocData = substr($headerstring, $VBRidOffset + 16, 100); + for ($i = 0; $i < 100; $i++) { + $thisfile_mpeg_audio['toc'][$i] = ord($LAMEtocData[$i]); + } + } + if ($thisfile_mpeg_audio['xing_flags']['vbr_scale']) { + $thisfile_mpeg_audio['VBR_scale'] = getid3_lib::BigEndian2Int(substr($headerstring, $VBRidOffset + 116, 4)); + } + + // http://gabriel.mp3-tech.org/mp3infotag.html + if (substr($headerstring, $VBRidOffset + 120, 4) == 'LAME') { + + // shortcut + $thisfile_mpeg_audio['LAME'] = []; + $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio['LAME']; + + $thisfile_mpeg_audio_lame['long_version'] = substr($headerstring, $VBRidOffset + 120, 20); + $thisfile_mpeg_audio_lame['short_version'] = substr($thisfile_mpeg_audio_lame['long_version'], 0, 9); + + if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.90') { + + // extra 11 chars are not part of version string when LAMEtag present + unset($thisfile_mpeg_audio_lame['long_version']); + + // It the LAME tag was only introduced in LAME v3.90 + // http://www.hydrogenaudio.org/?act=ST&f=15&t=9933 + + // Offsets of various bytes in http://gabriel.mp3-tech.org/mp3infotag.html + // are assuming a 'Xing' identifier offset of 0x24, which is the case for + // MPEG-1 non-mono, but not for other combinations + $LAMEtagOffsetContant = $VBRidOffset - 0x24; + + // shortcuts + $thisfile_mpeg_audio_lame['RGAD'] = ['track'=>[], 'album'=>[]]; + $thisfile_mpeg_audio_lame_RGAD = &$thisfile_mpeg_audio_lame['RGAD']; + $thisfile_mpeg_audio_lame_RGAD_track = &$thisfile_mpeg_audio_lame_RGAD['track']; + $thisfile_mpeg_audio_lame_RGAD_album = &$thisfile_mpeg_audio_lame_RGAD['album']; + $thisfile_mpeg_audio_lame['raw'] = []; + $thisfile_mpeg_audio_lame_raw = &$thisfile_mpeg_audio_lame['raw']; + + // byte $9B VBR Quality + // This field is there to indicate a quality level, although the scale was not precised in the original Xing specifications. + // Actually overwrites original Xing bytes + unset($thisfile_mpeg_audio['VBR_scale']); + $thisfile_mpeg_audio_lame['vbr_quality'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0x9B, 1)); + + // bytes $9C-$A4 Encoder short VersionString + $thisfile_mpeg_audio_lame['short_version'] = substr($headerstring, $LAMEtagOffsetContant + 0x9C, 9); + + // byte $A5 Info Tag revision + VBR method + $LAMEtagRevisionVBRmethod = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA5, 1)); + + $thisfile_mpeg_audio_lame['tag_revision'] = ($LAMEtagRevisionVBRmethod & 0xF0) >> 4; + $thisfile_mpeg_audio_lame_raw['vbr_method'] = $LAMEtagRevisionVBRmethod & 0x0F; + $thisfile_mpeg_audio_lame['vbr_method'] = self::LAMEvbrMethodLookup($thisfile_mpeg_audio_lame_raw['vbr_method']); + $thisfile_mpeg_audio['bitrate_mode'] = substr($thisfile_mpeg_audio_lame['vbr_method'], 0, 3); // usually either 'cbr' or 'vbr', but truncates 'vbr-old / vbr-rh' to 'vbr' + + // byte $A6 Lowpass filter value + $thisfile_mpeg_audio_lame['lowpass_frequency'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100; + + // bytes $A7-$AE Replay Gain + // http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html + // bytes $A7-$AA : 32 bit floating point "Peak signal amplitude" + if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.94b') { + // LAME 3.94a16 and later - 9.23 fixed point + // ie 0x0059E2EE / (2^23) = 5890798 / 8388608 = 0.7022378444671630859375 + $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = (float) ((getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4))) / 8388608); + } else { + // LAME 3.94a15 and earlier - 32-bit floating point + // Actually 3.94a16 will fall in here too and be WRONG, but is hard to detect 3.94a16 vs 3.94a15 + $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = getid3_lib::LittleEndian2Float(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4)); + } + if ($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] == 0) { + unset($thisfile_mpeg_audio_lame_RGAD['peak_amplitude']); + } else { + $thisfile_mpeg_audio_lame_RGAD['peak_db'] = getid3_lib::RGADamplitude2dB($thisfile_mpeg_audio_lame_RGAD['peak_amplitude']); + } + + $thisfile_mpeg_audio_lame_raw['RGAD_track'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAB, 2)); + $thisfile_mpeg_audio_lame_raw['RGAD_album'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAD, 2)); + + if ($thisfile_mpeg_audio_lame_raw['RGAD_track'] != 0) { + $thisfile_mpeg_audio_lame_RGAD_track['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0xE000) >> 13; + $thisfile_mpeg_audio_lame_RGAD_track['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x1C00) >> 10; + $thisfile_mpeg_audio_lame_RGAD_track['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x0200) >> 9; + $thisfile_mpeg_audio_lame_RGAD_track['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x01FF; + $thisfile_mpeg_audio_lame_RGAD_track['name'] = getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['name']); + $thisfile_mpeg_audio_lame_RGAD_track['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['originator']); + $thisfile_mpeg_audio_lame_RGAD_track['gain_db'] = getid3_lib::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_RGAD_track['raw']['sign_bit']); + + if (! empty($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'])) { + $info['replay_gain']['track']['peak'] = $thisfile_mpeg_audio_lame_RGAD['peak_amplitude']; + } + $info['replay_gain']['track']['originator'] = $thisfile_mpeg_audio_lame_RGAD_track['originator']; + $info['replay_gain']['track']['adjustment'] = $thisfile_mpeg_audio_lame_RGAD_track['gain_db']; + } else { + unset($thisfile_mpeg_audio_lame_RGAD['track']); + } + if ($thisfile_mpeg_audio_lame_raw['RGAD_album'] != 0) { + $thisfile_mpeg_audio_lame_RGAD_album['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0xE000) >> 13; + $thisfile_mpeg_audio_lame_RGAD_album['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x1C00) >> 10; + $thisfile_mpeg_audio_lame_RGAD_album['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x0200) >> 9; + $thisfile_mpeg_audio_lame_RGAD_album['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x01FF; + $thisfile_mpeg_audio_lame_RGAD_album['name'] = getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['name']); + $thisfile_mpeg_audio_lame_RGAD_album['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['originator']); + $thisfile_mpeg_audio_lame_RGAD_album['gain_db'] = getid3_lib::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_RGAD_album['raw']['sign_bit']); + + if (! empty($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'])) { + $info['replay_gain']['album']['peak'] = $thisfile_mpeg_audio_lame_RGAD['peak_amplitude']; + } + $info['replay_gain']['album']['originator'] = $thisfile_mpeg_audio_lame_RGAD_album['originator']; + $info['replay_gain']['album']['adjustment'] = $thisfile_mpeg_audio_lame_RGAD_album['gain_db']; + } else { + unset($thisfile_mpeg_audio_lame_RGAD['album']); + } + if (empty($thisfile_mpeg_audio_lame_RGAD)) { + unset($thisfile_mpeg_audio_lame['RGAD']); + } + + // byte $AF Encoding flags + ATH Type + $EncodingFlagsATHtype = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAF, 1)); + $thisfile_mpeg_audio_lame['encoding_flags']['nspsytune'] = (bool) ($EncodingFlagsATHtype & 0x10); + $thisfile_mpeg_audio_lame['encoding_flags']['nssafejoint'] = (bool) ($EncodingFlagsATHtype & 0x20); + $thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'] = (bool) ($EncodingFlagsATHtype & 0x40); + $thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev'] = (bool) ($EncodingFlagsATHtype & 0x80); + $thisfile_mpeg_audio_lame['ath_type'] = $EncodingFlagsATHtype & 0x0F; + + // byte $B0 if ABR {specified bitrate} else {minimal bitrate} + $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB0, 1)); + if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 2) { // Average BitRate (ABR) + $thisfile_mpeg_audio_lame['bitrate_abr'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']; + } elseif ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) { // Constant BitRate (CBR) + // ignore + } elseif ($thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] > 0) { // Variable BitRate (VBR) - minimum bitrate + $thisfile_mpeg_audio_lame['bitrate_min'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']; + } + + // bytes $B1-$B3 Encoder delays + $EncoderDelays = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB1, 3)); + $thisfile_mpeg_audio_lame['encoder_delay'] = ($EncoderDelays & 0xFFF000) >> 12; + $thisfile_mpeg_audio_lame['end_padding'] = $EncoderDelays & 0x000FFF; + + // byte $B4 Misc + $MiscByte = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB4, 1)); + $thisfile_mpeg_audio_lame_raw['noise_shaping'] = ($MiscByte & 0x03); + $thisfile_mpeg_audio_lame_raw['stereo_mode'] = ($MiscByte & 0x1C) >> 2; + $thisfile_mpeg_audio_lame_raw['not_optimal_quality'] = ($MiscByte & 0x20) >> 5; + $thisfile_mpeg_audio_lame_raw['source_sample_freq'] = ($MiscByte & 0xC0) >> 6; + $thisfile_mpeg_audio_lame['noise_shaping'] = $thisfile_mpeg_audio_lame_raw['noise_shaping']; + $thisfile_mpeg_audio_lame['stereo_mode'] = self::LAMEmiscStereoModeLookup($thisfile_mpeg_audio_lame_raw['stereo_mode']); + $thisfile_mpeg_audio_lame['not_optimal_quality'] = (bool) $thisfile_mpeg_audio_lame_raw['not_optimal_quality']; + $thisfile_mpeg_audio_lame['source_sample_freq'] = self::LAMEmiscSourceSampleFrequencyLookup($thisfile_mpeg_audio_lame_raw['source_sample_freq']); + + // byte $B5 MP3 Gain + $thisfile_mpeg_audio_lame_raw['mp3_gain'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB5, 1), false, true); + $thisfile_mpeg_audio_lame['mp3_gain_db'] = (getid3_lib::RGADamplitude2dB(2) / 4) * $thisfile_mpeg_audio_lame_raw['mp3_gain']; + $thisfile_mpeg_audio_lame['mp3_gain_factor'] = pow(2, ($thisfile_mpeg_audio_lame['mp3_gain_db'] / 6)); + + // bytes $B6-$B7 Preset and surround info + $PresetSurroundBytes = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB6, 2)); + // Reserved = ($PresetSurroundBytes & 0xC000); + $thisfile_mpeg_audio_lame_raw['surround_info'] = ($PresetSurroundBytes & 0x3800); + $thisfile_mpeg_audio_lame['surround_info'] = self::LAMEsurroundInfoLookup($thisfile_mpeg_audio_lame_raw['surround_info']); + $thisfile_mpeg_audio_lame['preset_used_id'] = ($PresetSurroundBytes & 0x07FF); + $thisfile_mpeg_audio_lame['preset_used'] = self::LAMEpresetUsedLookup($thisfile_mpeg_audio_lame); + if (! empty($thisfile_mpeg_audio_lame['preset_used_id']) && empty($thisfile_mpeg_audio_lame['preset_used'])) { + $this->warning('Unknown LAME preset used ('.$thisfile_mpeg_audio_lame['preset_used_id'].') - please report to info@getid3.org'); + } + if (($thisfile_mpeg_audio_lame['short_version'] == 'LAME3.90.') && ! empty($thisfile_mpeg_audio_lame['preset_used_id'])) { + // this may change if 3.90.4 ever comes out + $thisfile_mpeg_audio_lame['short_version'] = 'LAME3.90.3'; + } + + // bytes $B8-$BB MusicLength + $thisfile_mpeg_audio_lame['audio_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB8, 4)); + $ExpectedNumberOfAudioBytes = (($thisfile_mpeg_audio_lame['audio_bytes'] > 0) ? $thisfile_mpeg_audio_lame['audio_bytes'] : $thisfile_mpeg_audio['VBR_bytes']); + + // bytes $BC-$BD MusicCRC + $thisfile_mpeg_audio_lame['music_crc'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBC, 2)); + + // bytes $BE-$BF CRC-16 of Info Tag + $thisfile_mpeg_audio_lame['lame_tag_crc'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBE, 2)); + + // LAME CBR + if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) { + $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; + $thisfile_mpeg_audio['bitrate'] = self::ClosestStandardMP3Bitrate($thisfile_mpeg_audio['bitrate']); + $info['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate']; + //if (empty($thisfile_mpeg_audio['bitrate']) || (!empty($thisfile_mpeg_audio_lame['bitrate_min']) && ($thisfile_mpeg_audio_lame['bitrate_min'] != 255))) { + // $thisfile_mpeg_audio['bitrate'] = $thisfile_mpeg_audio_lame['bitrate_min']; + //} + } + } + } + } else { + + // not Fraunhofer or Xing VBR methods, most likely CBR (but could be VBR with no header) + $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; + if ($recursivesearch) { + $thisfile_mpeg_audio['bitrate_mode'] = 'vbr'; + if ($this->RecursiveFrameScanning($offset, $nextframetestoffset, true)) { + $recursivesearch = false; + $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; + } + if ($thisfile_mpeg_audio['bitrate_mode'] == 'vbr') { + $this->warning('VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.'); + } + } + } + } + + if (($ExpectedNumberOfAudioBytes > 0) && ($ExpectedNumberOfAudioBytes != ($info['avdataend'] - $info['avdataoffset']))) { + if ($ExpectedNumberOfAudioBytes > ($info['avdataend'] - $info['avdataoffset'])) { + if ($this->isDependencyFor('matroska') || $this->isDependencyFor('riff')) { + // ignore, audio data is broken into chunks so will always be data "missing" + } elseif (($ExpectedNumberOfAudioBytes - ($info['avdataend'] - $info['avdataoffset'])) == 1) { + $this->warning('Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)'); + } else { + $this->warning('Probable truncated file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' (short by '.($ExpectedNumberOfAudioBytes - ($info['avdataend'] - $info['avdataoffset'])).' bytes)'); + } + } else { + if ((($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes) == 1) { + // $prenullbytefileoffset = $this->ftell(); + // $this->fseek($info['avdataend']); + // $PossibleNullByte = $this->fread(1); + // $this->fseek($prenullbytefileoffset); + // if ($PossibleNullByte === "\x00") { + $info['avdataend']--; + // $this->warning('Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored'); + // } else { + // $this->warning('Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)'); + // } + } else { + $this->warning('Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)'); + } + } + } + + if (($thisfile_mpeg_audio['bitrate'] == 'free') && empty($info['audio']['bitrate'])) { + if (($offset == $info['avdataoffset']) && empty($thisfile_mpeg_audio['VBR_frames'])) { + $framebytelength = $this->FreeFormatFrameLength($offset, true); + if ($framebytelength > 0) { + $thisfile_mpeg_audio['framelength'] = $framebytelength; + if ($thisfile_mpeg_audio['layer'] == '1') { + // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12 + $info['audio']['bitrate'] = ((($framebytelength / 4) - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 12; + } else { + // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144 + $info['audio']['bitrate'] = (($framebytelength - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144; + } + } else { + $this->error('Error calculating frame length of free-format MP3 without Xing/LAME header'); + } + } + } + + if (isset($thisfile_mpeg_audio['VBR_frames']) ? $thisfile_mpeg_audio['VBR_frames'] : '') { + switch ($thisfile_mpeg_audio['bitrate_mode']) { + case 'vbr': + case 'abr': + $bytes_per_frame = 1152; + if (($thisfile_mpeg_audio['version'] == '1') && ($thisfile_mpeg_audio['layer'] == 1)) { + $bytes_per_frame = 384; + } elseif ((($thisfile_mpeg_audio['version'] == '2') || ($thisfile_mpeg_audio['version'] == '2.5')) && ($thisfile_mpeg_audio['layer'] == 3)) { + $bytes_per_frame = 576; + } + $thisfile_mpeg_audio['VBR_bitrate'] = (isset($thisfile_mpeg_audio['VBR_bytes']) ? (($thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames']) * 8) * ($info['audio']['sample_rate'] / $bytes_per_frame) : 0); + if ($thisfile_mpeg_audio['VBR_bitrate'] > 0) { + $info['audio']['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate']; + $thisfile_mpeg_audio['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate']; // to avoid confusion + } + break; + } + } + + // End variable-bitrate headers + //////////////////////////////////////////////////////////////////////////////////// + + if ($recursivesearch) { + if (! $this->RecursiveFrameScanning($offset, $nextframetestoffset, $ScanAsCBR)) { + return false; + } + } + + //if (false) { + // // experimental side info parsing section - not returning anything useful yet + // + // $SideInfoBitstream = getid3_lib::BigEndian2Bin($SideInfoData); + // $SideInfoOffset = 0; + // + // if ($thisfile_mpeg_audio['version'] == '1') { + // if ($thisfile_mpeg_audio['channelmode'] == 'mono') { + // // MPEG-1 (mono) + // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 9); + // $SideInfoOffset += 9; + // $SideInfoOffset += 5; + // } else { + // // MPEG-1 (stereo, joint-stereo, dual-channel) + // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 9); + // $SideInfoOffset += 9; + // $SideInfoOffset += 3; + // } + // } else { // 2 or 2.5 + // if ($thisfile_mpeg_audio['channelmode'] == 'mono') { + // // MPEG-2, MPEG-2.5 (mono) + // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 8); + // $SideInfoOffset += 8; + // $SideInfoOffset += 1; + // } else { + // // MPEG-2, MPEG-2.5 (stereo, joint-stereo, dual-channel) + // $thisfile_mpeg_audio['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 8); + // $SideInfoOffset += 8; + // $SideInfoOffset += 2; + // } + // } + // + // if ($thisfile_mpeg_audio['version'] == '1') { + // for ($channel = 0; $channel < $info['audio']['channels']; $channel++) { + // for ($scfsi_band = 0; $scfsi_band < 4; $scfsi_band++) { + // $thisfile_mpeg_audio['scfsi'][$channel][$scfsi_band] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 2; + // } + // } + // } + // for ($granule = 0; $granule < (($thisfile_mpeg_audio['version'] == '1') ? 2 : 1); $granule++) { + // for ($channel = 0; $channel < $info['audio']['channels']; $channel++) { + // $thisfile_mpeg_audio['part2_3_length'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 12); + // $SideInfoOffset += 12; + // $thisfile_mpeg_audio['big_values'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 9); + // $SideInfoOffset += 9; + // $thisfile_mpeg_audio['global_gain'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 8); + // $SideInfoOffset += 8; + // if ($thisfile_mpeg_audio['version'] == '1') { + // $thisfile_mpeg_audio['scalefac_compress'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 4); + // $SideInfoOffset += 4; + // } else { + // $thisfile_mpeg_audio['scalefac_compress'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 9); + // $SideInfoOffset += 9; + // } + // $thisfile_mpeg_audio['window_switching_flag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 1; + // + // if ($thisfile_mpeg_audio['window_switching_flag'][$granule][$channel] == '1') { + // + // $thisfile_mpeg_audio['block_type'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 2); + // $SideInfoOffset += 2; + // $thisfile_mpeg_audio['mixed_block_flag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 1; + // + // for ($region = 0; $region < 2; $region++) { + // $thisfile_mpeg_audio['table_select'][$granule][$channel][$region] = substr($SideInfoBitstream, $SideInfoOffset, 5); + // $SideInfoOffset += 5; + // } + // $thisfile_mpeg_audio['table_select'][$granule][$channel][2] = 0; + // + // for ($window = 0; $window < 3; $window++) { + // $thisfile_mpeg_audio['subblock_gain'][$granule][$channel][$window] = substr($SideInfoBitstream, $SideInfoOffset, 3); + // $SideInfoOffset += 3; + // } + // + // } else { + // + // for ($region = 0; $region < 3; $region++) { + // $thisfile_mpeg_audio['table_select'][$granule][$channel][$region] = substr($SideInfoBitstream, $SideInfoOffset, 5); + // $SideInfoOffset += 5; + // } + // + // $thisfile_mpeg_audio['region0_count'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 4); + // $SideInfoOffset += 4; + // $thisfile_mpeg_audio['region1_count'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 3); + // $SideInfoOffset += 3; + // $thisfile_mpeg_audio['block_type'][$granule][$channel] = 0; + // } + // + // if ($thisfile_mpeg_audio['version'] == '1') { + // $thisfile_mpeg_audio['preflag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 1; + // } + // $thisfile_mpeg_audio['scalefac_scale'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 1; + // $thisfile_mpeg_audio['count1table_select'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 1; + // } + // } + //} + + return true; + } + + public function RecursiveFrameScanning(&$offset, &$nextframetestoffset, $ScanAsCBR) + { + $info = &$this->getid3->info; + $firstframetestarray = ['error' => [], 'warning'=> [], 'avdataend' => $info['avdataend'], 'avdataoffset' => $info['avdataoffset']]; + $this->decodeMPEGaudioHeader($offset, $firstframetestarray, false); + + for ($i = 0; $i < GETID3_MP3_VALID_CHECK_FRAMES; $i++) { + // check next GETID3_MP3_VALID_CHECK_FRAMES frames for validity, to make sure we haven't run across a false synch + if (($nextframetestoffset + 4) >= $info['avdataend']) { + // end of file + return true; + } + + $nextframetestarray = ['error' => [], 'warning' => [], 'avdataend' => $info['avdataend'], 'avdataoffset'=>$info['avdataoffset']]; + if ($this->decodeMPEGaudioHeader($nextframetestoffset, $nextframetestarray, false)) { + if ($ScanAsCBR) { + // force CBR mode, used for trying to pick out invalid audio streams with valid(?) VBR headers, or VBR streams with no VBR header + if (! isset($nextframetestarray['mpeg']['audio']['bitrate']) || ! isset($firstframetestarray['mpeg']['audio']['bitrate']) || ($nextframetestarray['mpeg']['audio']['bitrate'] != $firstframetestarray['mpeg']['audio']['bitrate'])) { + return false; + } + } + + // next frame is OK, get ready to check the one after that + if (isset($nextframetestarray['mpeg']['audio']['framelength']) && ($nextframetestarray['mpeg']['audio']['framelength'] > 0)) { + $nextframetestoffset += $nextframetestarray['mpeg']['audio']['framelength']; + } else { + $this->error('Frame at offset ('.$offset.') is has an invalid frame length.'); + + return false; + } + } elseif (! empty($firstframetestarray['mpeg']['audio']['framelength']) && (($nextframetestoffset + $firstframetestarray['mpeg']['audio']['framelength']) > $info['avdataend'])) { + + // it's not the end of the file, but there's not enough data left for another frame, so assume it's garbage/padding and return OK + return true; + } else { + + // next frame is not valid, note the error and fail, so scanning can contiue for a valid frame sequence + $this->warning('Frame at offset ('.$offset.') is valid, but the next one at ('.$nextframetestoffset.') is not.'); + + return false; + } + } + + return true; + } + + public function FreeFormatFrameLength($offset, $deepscan = false) + { + $info = &$this->getid3->info; + + $this->fseek($offset); + $MPEGaudioData = $this->fread(32768); + + $SyncPattern1 = substr($MPEGaudioData, 0, 4); + // may be different pattern due to padding + $SyncPattern2 = $SyncPattern1[0].$SyncPattern1[1].chr(ord($SyncPattern1[2]) | 0x02).$SyncPattern1[3]; + if ($SyncPattern2 === $SyncPattern1) { + $SyncPattern2 = $SyncPattern1[0].$SyncPattern1[1].chr(ord($SyncPattern1[2]) & 0xFD).$SyncPattern1[3]; + } + + $framelength = false; + $framelength1 = strpos($MPEGaudioData, $SyncPattern1, 4); + $framelength2 = strpos($MPEGaudioData, $SyncPattern2, 4); + if ($framelength1 > 4) { + $framelength = $framelength1; + } + if (($framelength2 > 4) && ($framelength2 < $framelength1)) { + $framelength = $framelength2; + } + if (! $framelength) { + + // LAME 3.88 has a different value for modeextension on the first frame vs the rest + $framelength1 = strpos($MPEGaudioData, substr($SyncPattern1, 0, 3), 4); + $framelength2 = strpos($MPEGaudioData, substr($SyncPattern2, 0, 3), 4); + + if ($framelength1 > 4) { + $framelength = $framelength1; + } + if (($framelength2 > 4) && ($framelength2 < $framelength1)) { + $framelength = $framelength2; + } + if (! $framelength) { + $this->error('Cannot find next free-format synch pattern ('.getid3_lib::PrintHexBytes($SyncPattern1).' or '.getid3_lib::PrintHexBytes($SyncPattern2).') after offset '.$offset); + + return false; + } else { + $this->warning('ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)'); + $info['audio']['codec'] = 'LAME'; + $info['audio']['encoder'] = 'LAME3.88'; + $SyncPattern1 = substr($SyncPattern1, 0, 3); + $SyncPattern2 = substr($SyncPattern2, 0, 3); + } + } + + if ($deepscan) { + $ActualFrameLengthValues = []; + $nextoffset = $offset + $framelength; + while ($nextoffset < ($info['avdataend'] - 6)) { + $this->fseek($nextoffset - 1); + $NextSyncPattern = $this->fread(6); + if ((substr($NextSyncPattern, 1, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 1, strlen($SyncPattern2)) == $SyncPattern2)) { + // good - found where expected + $ActualFrameLengthValues[] = $framelength; + } elseif ((substr($NextSyncPattern, 0, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 0, strlen($SyncPattern2)) == $SyncPattern2)) { + // ok - found one byte earlier than expected (last frame wasn't padded, first frame was) + $ActualFrameLengthValues[] = ($framelength - 1); + $nextoffset--; + } elseif ((substr($NextSyncPattern, 2, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 2, strlen($SyncPattern2)) == $SyncPattern2)) { + // ok - found one byte later than expected (last frame was padded, first frame wasn't) + $ActualFrameLengthValues[] = ($framelength + 1); + $nextoffset++; + } else { + $this->error('Did not find expected free-format sync pattern at offset '.$nextoffset); + + return false; + } + $nextoffset += $framelength; + } + if (count($ActualFrameLengthValues) > 0) { + $framelength = intval(round(array_sum($ActualFrameLengthValues) / count($ActualFrameLengthValues))); + } + } + + return $framelength; + } + + public function getOnlyMPEGaudioInfoBruteForce() + { + $MPEGaudioHeaderDecodeCache = []; + $MPEGaudioHeaderValidCache = []; + $MPEGaudioHeaderLengthCache = []; + $MPEGaudioVersionLookup = self::MPEGaudioVersionArray(); + $MPEGaudioLayerLookup = self::MPEGaudioLayerArray(); + $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray(); + $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray(); + $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray(); + $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray(); + $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray(); + $LongMPEGversionLookup = []; + $LongMPEGlayerLookup = []; + $LongMPEGbitrateLookup = []; + $LongMPEGpaddingLookup = []; + $LongMPEGfrequencyLookup = []; + $Distribution['bitrate'] = []; + $Distribution['frequency'] = []; + $Distribution['layer'] = []; + $Distribution['version'] = []; + $Distribution['padding'] = []; + + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + + $max_frames_scan = 5000; + $frames_scanned = 0; + + $previousvalidframe = $info['avdataoffset']; + while ($this->ftell() < $info['avdataend']) { + set_time_limit(30); + $head4 = $this->fread(4); + if (strlen($head4) < 4) { + break; + } + if ($head4[0] != "\xFF") { + for ($i = 1; $i < 4; $i++) { + if ($head4[$i] == "\xFF") { + $this->fseek($i - 4, SEEK_CUR); + continue 2; + } + } + continue; + } + if (! isset($MPEGaudioHeaderDecodeCache[$head4])) { + $MPEGaudioHeaderDecodeCache[$head4] = self::MPEGaudioHeaderDecode($head4); + } + if (! isset($MPEGaudioHeaderValidCache[$head4])) { + $MPEGaudioHeaderValidCache[$head4] = self::MPEGaudioHeaderValid($MPEGaudioHeaderDecodeCache[$head4], false, false); + } + if ($MPEGaudioHeaderValidCache[$head4]) { + if (! isset($MPEGaudioHeaderLengthCache[$head4])) { + $LongMPEGversionLookup[$head4] = $MPEGaudioVersionLookup[$MPEGaudioHeaderDecodeCache[$head4]['version']]; + $LongMPEGlayerLookup[$head4] = $MPEGaudioLayerLookup[$MPEGaudioHeaderDecodeCache[$head4]['layer']]; + $LongMPEGbitrateLookup[$head4] = $MPEGaudioBitrateLookup[$LongMPEGversionLookup[$head4]][$LongMPEGlayerLookup[$head4]][$MPEGaudioHeaderDecodeCache[$head4]['bitrate']]; + $LongMPEGpaddingLookup[$head4] = (bool) $MPEGaudioHeaderDecodeCache[$head4]['padding']; + $LongMPEGfrequencyLookup[$head4] = $MPEGaudioFrequencyLookup[$LongMPEGversionLookup[$head4]][$MPEGaudioHeaderDecodeCache[$head4]['sample_rate']]; + $MPEGaudioHeaderLengthCache[$head4] = self::MPEGaudioFrameLength( + $LongMPEGbitrateLookup[$head4], + $LongMPEGversionLookup[$head4], + $LongMPEGlayerLookup[$head4], + $LongMPEGpaddingLookup[$head4], + $LongMPEGfrequencyLookup[$head4]); + } + if ($MPEGaudioHeaderLengthCache[$head4] > 4) { + $WhereWeWere = $this->ftell(); + $this->fseek($MPEGaudioHeaderLengthCache[$head4] - 4, SEEK_CUR); + $next4 = $this->fread(4); + if ($next4[0] == "\xFF") { + if (! isset($MPEGaudioHeaderDecodeCache[$next4])) { + $MPEGaudioHeaderDecodeCache[$next4] = self::MPEGaudioHeaderDecode($next4); + } + if (! isset($MPEGaudioHeaderValidCache[$next4])) { + $MPEGaudioHeaderValidCache[$next4] = self::MPEGaudioHeaderValid($MPEGaudioHeaderDecodeCache[$next4], false, false); + } + if ($MPEGaudioHeaderValidCache[$next4]) { + $this->fseek(-4, SEEK_CUR); + + getid3_lib::safe_inc($Distribution['bitrate'][$LongMPEGbitrateLookup[$head4]]); + getid3_lib::safe_inc($Distribution['layer'][$LongMPEGlayerLookup[$head4]]); + getid3_lib::safe_inc($Distribution['version'][$LongMPEGversionLookup[$head4]]); + getid3_lib::safe_inc($Distribution['padding'][intval($LongMPEGpaddingLookup[$head4])]); + getid3_lib::safe_inc($Distribution['frequency'][$LongMPEGfrequencyLookup[$head4]]); + if ($max_frames_scan && (++$frames_scanned >= $max_frames_scan)) { + $pct_data_scanned = ($this->ftell() - $info['avdataoffset']) / ($info['avdataend'] - $info['avdataoffset']); + $this->warning('too many MPEG audio frames to scan, only scanned first '.$max_frames_scan.' frames ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.'); + foreach ($Distribution as $key1 => $value1) { + foreach ($value1 as $key2 => $value2) { + $Distribution[$key1][$key2] = round($value2 / $pct_data_scanned); + } + } + break; + } + continue; + } + } + unset($next4); + $this->fseek($WhereWeWere - 3); + } + } + } + foreach ($Distribution as $key => $value) { + ksort($Distribution[$key], SORT_NUMERIC); + } + ksort($Distribution['version'], SORT_STRING); + $info['mpeg']['audio']['bitrate_distribution'] = $Distribution['bitrate']; + $info['mpeg']['audio']['frequency_distribution'] = $Distribution['frequency']; + $info['mpeg']['audio']['layer_distribution'] = $Distribution['layer']; + $info['mpeg']['audio']['version_distribution'] = $Distribution['version']; + $info['mpeg']['audio']['padding_distribution'] = $Distribution['padding']; + if (count($Distribution['version']) > 1) { + $this->error('Corrupt file - more than one MPEG version detected'); + } + if (count($Distribution['layer']) > 1) { + $this->error('Corrupt file - more than one MPEG layer detected'); + } + if (count($Distribution['frequency']) > 1) { + $this->error('Corrupt file - more than one MPEG sample rate detected'); + } + + $bittotal = 0; + foreach ($Distribution['bitrate'] as $bitratevalue => $bitratecount) { + if ($bitratevalue != 'free') { + $bittotal += ($bitratevalue * $bitratecount); + } + } + $info['mpeg']['audio']['frame_count'] = array_sum($Distribution['bitrate']); + if ($info['mpeg']['audio']['frame_count'] == 0) { + $this->error('no MPEG audio frames found'); + + return false; + } + $info['mpeg']['audio']['bitrate'] = ($bittotal / $info['mpeg']['audio']['frame_count']); + $info['mpeg']['audio']['bitrate_mode'] = ((count($Distribution['bitrate']) > 0) ? 'vbr' : 'cbr'); + $info['mpeg']['audio']['sample_rate'] = getid3_lib::array_max($Distribution['frequency'], true); + + $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; + $info['audio']['bitrate_mode'] = $info['mpeg']['audio']['bitrate_mode']; + $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; + $info['audio']['dataformat'] = 'mp'.getid3_lib::array_max($Distribution['layer'], true); + $info['fileformat'] = $info['audio']['dataformat']; + + return true; + } + + public function getOnlyMPEGaudioInfo($avdataoffset, $BitrateHistogram = false) + { + // looks for synch, decodes MPEG audio header + + $info = &$this->getid3->info; + + static $MPEGaudioVersionLookup; + static $MPEGaudioLayerLookup; + static $MPEGaudioBitrateLookup; + if (empty($MPEGaudioVersionLookup)) { + $MPEGaudioVersionLookup = self::MPEGaudioVersionArray(); + $MPEGaudioLayerLookup = self::MPEGaudioLayerArray(); + $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray(); + } + + $this->fseek($avdataoffset); + $sync_seek_buffer_size = min(128 * 1024, $info['avdataend'] - $avdataoffset); + if ($sync_seek_buffer_size <= 0) { + $this->error('Invalid $sync_seek_buffer_size at offset '.$avdataoffset); + + return false; + } + $header = $this->fread($sync_seek_buffer_size); + $sync_seek_buffer_size = strlen($header); + $SynchSeekOffset = 0; + while ($SynchSeekOffset < $sync_seek_buffer_size) { + if ((($avdataoffset + $SynchSeekOffset) < $info['avdataend']) && ! feof($this->getid3->fp)) { + if ($SynchSeekOffset > $sync_seek_buffer_size) { + // if a synch's not found within the first 128k bytes, then give up + $this->error('Could not find valid MPEG audio synch within the first '.round($sync_seek_buffer_size / 1024).'kB'); + if (isset($info['audio']['bitrate'])) { + unset($info['audio']['bitrate']); + } + if (isset($info['mpeg']['audio'])) { + unset($info['mpeg']['audio']); + } + if (empty($info['mpeg'])) { + unset($info['mpeg']); + } + + return false; + } elseif (feof($this->getid3->fp)) { + $this->error('Could not find valid MPEG audio synch before end of file'); + if (isset($info['audio']['bitrate'])) { + unset($info['audio']['bitrate']); + } + if (isset($info['mpeg']['audio'])) { + unset($info['mpeg']['audio']); + } + if (isset($info['mpeg']) && (! is_array($info['mpeg']) || (count($info['mpeg']) == 0))) { + unset($info['mpeg']); + } + + return false; + } + } + + if (($SynchSeekOffset + 1) >= strlen($header)) { + $this->error('Could not find valid MPEG synch before end of file'); + + return false; + } + + if (($header[$SynchSeekOffset] == "\xFF") && ($header[($SynchSeekOffset + 1)] > "\xE0")) { // synch detected + if (! isset($FirstFrameThisfileInfo) && ! isset($info['mpeg']['audio'])) { + $FirstFrameThisfileInfo = $info; + $FirstFrameAVDataOffset = $avdataoffset + $SynchSeekOffset; + if (! $this->decodeMPEGaudioHeader($FirstFrameAVDataOffset, $FirstFrameThisfileInfo, false)) { + // if this is the first valid MPEG-audio frame, save it in case it's a VBR header frame and there's + // garbage between this frame and a valid sequence of MPEG-audio frames, to be restored below + unset($FirstFrameThisfileInfo); + } + } + + $dummy = $info; // only overwrite real data if valid header found + if ($this->decodeMPEGaudioHeader($avdataoffset + $SynchSeekOffset, $dummy, true)) { + $info = $dummy; + $info['avdataoffset'] = $avdataoffset + $SynchSeekOffset; + switch (isset($info['fileformat']) ? $info['fileformat'] : '') { + case '': + case 'id3': + case 'ape': + case 'mp3': + $info['fileformat'] = 'mp3'; + $info['audio']['dataformat'] = 'mp3'; + break; + } + if (isset($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode']) && ($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr')) { + if (! (abs($info['audio']['bitrate'] - $FirstFrameThisfileInfo['audio']['bitrate']) <= 1)) { + // If there is garbage data between a valid VBR header frame and a sequence + // of valid MPEG-audio frames the VBR data is no longer discarded. + $info = $FirstFrameThisfileInfo; + $info['avdataoffset'] = $FirstFrameAVDataOffset; + $info['fileformat'] = 'mp3'; + $info['audio']['dataformat'] = 'mp3'; + $dummy = $info; + unset($dummy['mpeg']['audio']); + $GarbageOffsetStart = $FirstFrameAVDataOffset + $FirstFrameThisfileInfo['mpeg']['audio']['framelength']; + $GarbageOffsetEnd = $avdataoffset + $SynchSeekOffset; + if ($this->decodeMPEGaudioHeader($GarbageOffsetEnd, $dummy, true, true)) { + $info = $dummy; + $info['avdataoffset'] = $GarbageOffsetEnd; + $this->warning('apparently-valid VBR header not used because could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.'), but did find valid CBR stream starting at '.$GarbageOffsetEnd); + } else { + $this->warning('using data from VBR header even though could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.')'); + } + } + } + if (isset($info['mpeg']['audio']['bitrate_mode']) && ($info['mpeg']['audio']['bitrate_mode'] == 'vbr') && ! isset($info['mpeg']['audio']['VBR_method'])) { + // VBR file with no VBR header + $BitrateHistogram = true; + } + + if ($BitrateHistogram) { + $info['mpeg']['audio']['stereo_distribution'] = ['stereo'=>0, 'joint stereo'=>0, 'dual channel'=>0, 'mono'=>0]; + $info['mpeg']['audio']['version_distribution'] = ['1'=>0, '2'=>0, '2.5'=>0]; + + if ($info['mpeg']['audio']['version'] == '1') { + if ($info['mpeg']['audio']['layer'] == 3) { + $info['mpeg']['audio']['bitrate_distribution'] = ['free'=>0, 32000=>0, 40000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 320000=>0]; + } elseif ($info['mpeg']['audio']['layer'] == 2) { + $info['mpeg']['audio']['bitrate_distribution'] = ['free'=>0, 32000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 320000=>0, 384000=>0]; + } elseif ($info['mpeg']['audio']['layer'] == 1) { + $info['mpeg']['audio']['bitrate_distribution'] = ['free'=>0, 32000=>0, 64000=>0, 96000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 288000=>0, 320000=>0, 352000=>0, 384000=>0, 416000=>0, 448000=>0]; + } + } elseif ($info['mpeg']['audio']['layer'] == 1) { + $info['mpeg']['audio']['bitrate_distribution'] = ['free'=>0, 32000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 144000=>0, 160000=>0, 176000=>0, 192000=>0, 224000=>0, 256000=>0]; + } else { + $info['mpeg']['audio']['bitrate_distribution'] = ['free'=>0, 8000=>0, 16000=>0, 24000=>0, 32000=>0, 40000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 144000=>0, 160000=>0]; + } + + $dummy = ['error'=>$info['error'], 'warning'=>$info['warning'], 'avdataend'=>$info['avdataend'], 'avdataoffset'=>$info['avdataoffset']]; + $synchstartoffset = $info['avdataoffset']; + $this->fseek($info['avdataoffset']); + + // you can play with these numbers: + $max_frames_scan = 50000; + $max_scan_segments = 10; + + // don't play with these numbers: + $FastMode = false; + $SynchErrorsFound = 0; + $frames_scanned = 0; + $this_scan_segment = 0; + $frames_scan_per_segment = ceil($max_frames_scan / $max_scan_segments); + $pct_data_scanned = 0; + for ($current_segment = 0; $current_segment < $max_scan_segments; $current_segment++) { + $frames_scanned_this_segment = 0; + if ($this->ftell() >= $info['avdataend']) { + break; + } + $scan_start_offset[$current_segment] = max($this->ftell(), $info['avdataoffset'] + round($current_segment * (($info['avdataend'] - $info['avdataoffset']) / $max_scan_segments))); + if ($current_segment > 0) { + $this->fseek($scan_start_offset[$current_segment]); + $buffer_4k = $this->fread(4096); + for ($j = 0; $j < (strlen($buffer_4k) - 4); $j++) { + if (($buffer_4k[$j] == "\xFF") && ($buffer_4k[($j + 1)] > "\xE0")) { // synch detected + if ($this->decodeMPEGaudioHeader($scan_start_offset[$current_segment] + $j, $dummy, false, false, $FastMode)) { + $calculated_next_offset = $scan_start_offset[$current_segment] + $j + $dummy['mpeg']['audio']['framelength']; + if ($this->decodeMPEGaudioHeader($calculated_next_offset, $dummy, false, false, $FastMode)) { + $scan_start_offset[$current_segment] += $j; + break; + } + } + } + } + } + $synchstartoffset = $scan_start_offset[$current_segment]; + while ($this->decodeMPEGaudioHeader($synchstartoffset, $dummy, false, false, $FastMode)) { + $FastMode = true; + $thisframebitrate = $MPEGaudioBitrateLookup[$MPEGaudioVersionLookup[$dummy['mpeg']['audio']['raw']['version']]][$MPEGaudioLayerLookup[$dummy['mpeg']['audio']['raw']['layer']]][$dummy['mpeg']['audio']['raw']['bitrate']]; + + if (empty($dummy['mpeg']['audio']['framelength'])) { + $SynchErrorsFound++; + $synchstartoffset++; + } else { + getid3_lib::safe_inc($info['mpeg']['audio']['bitrate_distribution'][$thisframebitrate]); + getid3_lib::safe_inc($info['mpeg']['audio']['stereo_distribution'][$dummy['mpeg']['audio']['channelmode']]); + getid3_lib::safe_inc($info['mpeg']['audio']['version_distribution'][$dummy['mpeg']['audio']['version']]); + $synchstartoffset += $dummy['mpeg']['audio']['framelength']; + } + $frames_scanned++; + if ($frames_scan_per_segment && (++$frames_scanned_this_segment >= $frames_scan_per_segment)) { + $this_pct_scanned = ($this->ftell() - $scan_start_offset[$current_segment]) / ($info['avdataend'] - $info['avdataoffset']); + if (($current_segment == 0) && (($this_pct_scanned * $max_scan_segments) >= 1)) { + // file likely contains < $max_frames_scan, just scan as one segment + $max_scan_segments = 1; + $frames_scan_per_segment = $max_frames_scan; + } else { + $pct_data_scanned += $this_pct_scanned; + break; + } + } + } + } + if ($pct_data_scanned > 0) { + $this->warning('too many MPEG audio frames to scan, only scanned '.$frames_scanned.' frames in '.$max_scan_segments.' segments ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.'); + foreach ($info['mpeg']['audio'] as $key1 => $value1) { + if (! preg_match('#_distribution$#i', $key1)) { + continue; + } + foreach ($value1 as $key2 => $value2) { + $info['mpeg']['audio'][$key1][$key2] = round($value2 / $pct_data_scanned); + } + } + } + + if ($SynchErrorsFound > 0) { + $this->warning('Found '.$SynchErrorsFound.' synch errors in histogram analysis'); + //return false; + } + + $bittotal = 0; + $framecounter = 0; + foreach ($info['mpeg']['audio']['bitrate_distribution'] as $bitratevalue => $bitratecount) { + $framecounter += $bitratecount; + if ($bitratevalue != 'free') { + $bittotal += ($bitratevalue * $bitratecount); + } + } + if ($framecounter == 0) { + $this->error('Corrupt MP3 file: framecounter == zero'); + + return false; + } + $info['mpeg']['audio']['frame_count'] = getid3_lib::CastAsInt($framecounter); + $info['mpeg']['audio']['bitrate'] = ($bittotal / $framecounter); + + $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; + + // Definitively set VBR vs CBR, even if the Xing/LAME/VBRI header says differently + $distinct_bitrates = 0; + foreach ($info['mpeg']['audio']['bitrate_distribution'] as $bitrate_value => $bitrate_count) { + if ($bitrate_count > 0) { + $distinct_bitrates++; + } + } + if ($distinct_bitrates > 1) { + $info['mpeg']['audio']['bitrate_mode'] = 'vbr'; + } else { + $info['mpeg']['audio']['bitrate_mode'] = 'cbr'; + } + $info['audio']['bitrate_mode'] = $info['mpeg']['audio']['bitrate_mode']; + } + + break; // exit while() + } + } + + $SynchSeekOffset++; + if (($avdataoffset + $SynchSeekOffset) >= $info['avdataend']) { + // end of file/data + + if (empty($info['mpeg']['audio'])) { + $this->error('could not find valid MPEG synch before end of file'); + if (isset($info['audio']['bitrate'])) { + unset($info['audio']['bitrate']); + } + if (isset($info['mpeg']['audio'])) { + unset($info['mpeg']['audio']); + } + if (isset($info['mpeg']) && (! is_array($info['mpeg']) || empty($info['mpeg']))) { + unset($info['mpeg']); + } + + return false; + } + break; + } + } + $info['audio']['channels'] = $info['mpeg']['audio']['channels']; + $info['audio']['channelmode'] = $info['mpeg']['audio']['channelmode']; + $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; + + return true; + } + + public static function MPEGaudioVersionArray() + { + static $MPEGaudioVersion = ['2.5', false, '2', '1']; + + return $MPEGaudioVersion; + } + + public static function MPEGaudioLayerArray() + { + static $MPEGaudioLayer = [false, 3, 2, 1]; + + return $MPEGaudioLayer; + } + + public static function MPEGaudioBitrateArray() + { + static $MPEGaudioBitrate; + if (empty($MPEGaudioBitrate)) { + $MPEGaudioBitrate = [ + '1' => [1 => ['free', 32000, 64000, 96000, 128000, 160000, 192000, 224000, 256000, 288000, 320000, 352000, 384000, 416000, 448000], + 2 => ['free', 32000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000, 384000], + 3 => ['free', 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000], + ], + + '2' => [1 => ['free', 32000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 176000, 192000, 224000, 256000], + 2 => ['free', 8000, 16000, 24000, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000], + ], + ]; + $MPEGaudioBitrate['2'][3] = $MPEGaudioBitrate['2'][2]; + $MPEGaudioBitrate['2.5'] = $MPEGaudioBitrate['2']; + } + + return $MPEGaudioBitrate; + } + + public static function MPEGaudioFrequencyArray() + { + static $MPEGaudioFrequency; + if (empty($MPEGaudioFrequency)) { + $MPEGaudioFrequency = [ + '1' => [44100, 48000, 32000], + '2' => [22050, 24000, 16000], + '2.5' => [11025, 12000, 8000], + ]; + } + + return $MPEGaudioFrequency; + } + + public static function MPEGaudioChannelModeArray() + { + static $MPEGaudioChannelMode = ['stereo', 'joint stereo', 'dual channel', 'mono']; + + return $MPEGaudioChannelMode; + } + + public static function MPEGaudioModeExtensionArray() + { + static $MPEGaudioModeExtension; + if (empty($MPEGaudioModeExtension)) { + $MPEGaudioModeExtension = [ + 1 => ['4-31', '8-31', '12-31', '16-31'], + 2 => ['4-31', '8-31', '12-31', '16-31'], + 3 => ['', 'IS', 'MS', 'IS+MS'], + ]; + } + + return $MPEGaudioModeExtension; + } + + public static function MPEGaudioEmphasisArray() + { + static $MPEGaudioEmphasis = ['none', '50/15ms', false, 'CCIT J.17']; + + return $MPEGaudioEmphasis; + } + + public static function MPEGaudioHeaderBytesValid($head4, $allowBitrate15 = false) + { + return self::MPEGaudioHeaderValid(self::MPEGaudioHeaderDecode($head4), false, $allowBitrate15); + } + + public static function MPEGaudioHeaderValid($rawarray, $echoerrors = false, $allowBitrate15 = false) + { + if (($rawarray['synch'] & 0x0FFE) != 0x0FFE) { + return false; + } + + static $MPEGaudioVersionLookup; + static $MPEGaudioLayerLookup; + static $MPEGaudioBitrateLookup; + static $MPEGaudioFrequencyLookup; + static $MPEGaudioChannelModeLookup; + static $MPEGaudioModeExtensionLookup; + static $MPEGaudioEmphasisLookup; + if (empty($MPEGaudioVersionLookup)) { + $MPEGaudioVersionLookup = self::MPEGaudioVersionArray(); + $MPEGaudioLayerLookup = self::MPEGaudioLayerArray(); + $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray(); + $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray(); + $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray(); + $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray(); + $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray(); + } + + if (isset($MPEGaudioVersionLookup[$rawarray['version']])) { + $decodedVersion = $MPEGaudioVersionLookup[$rawarray['version']]; + } else { + echo $echoerrors ? "\n".'invalid Version ('.$rawarray['version'].')' : ''; + + return false; + } + if (isset($MPEGaudioLayerLookup[$rawarray['layer']])) { + $decodedLayer = $MPEGaudioLayerLookup[$rawarray['layer']]; + } else { + echo $echoerrors ? "\n".'invalid Layer ('.$rawarray['layer'].')' : ''; + + return false; + } + if (! isset($MPEGaudioBitrateLookup[$decodedVersion][$decodedLayer][$rawarray['bitrate']])) { + echo $echoerrors ? "\n".'invalid Bitrate ('.$rawarray['bitrate'].')' : ''; + if ($rawarray['bitrate'] == 15) { + // known issue in LAME 3.90 - 3.93.1 where free-format has bitrate ID of 15 instead of 0 + // let it go through here otherwise file will not be identified + if (! $allowBitrate15) { + return false; + } + } else { + return false; + } + } + if (! isset($MPEGaudioFrequencyLookup[$decodedVersion][$rawarray['sample_rate']])) { + echo $echoerrors ? "\n".'invalid Frequency ('.$rawarray['sample_rate'].')' : ''; + + return false; + } + if (! isset($MPEGaudioChannelModeLookup[$rawarray['channelmode']])) { + echo $echoerrors ? "\n".'invalid ChannelMode ('.$rawarray['channelmode'].')' : ''; + + return false; + } + if (! isset($MPEGaudioModeExtensionLookup[$decodedLayer][$rawarray['modeextension']])) { + echo $echoerrors ? "\n".'invalid Mode Extension ('.$rawarray['modeextension'].')' : ''; + + return false; + } + if (! isset($MPEGaudioEmphasisLookup[$rawarray['emphasis']])) { + echo $echoerrors ? "\n".'invalid Emphasis ('.$rawarray['emphasis'].')' : ''; + + return false; + } + // These are just either set or not set, you can't mess that up :) + // $rawarray['protection']; + // $rawarray['padding']; + // $rawarray['private']; + // $rawarray['copyright']; + // $rawarray['original']; + + return true; + } + + public static function MPEGaudioHeaderDecode($Header4Bytes) + { + // AAAA AAAA AAAB BCCD EEEE FFGH IIJJ KLMM + // A - Frame sync (all bits set) + // B - MPEG Audio version ID + // C - Layer description + // D - Protection bit + // E - Bitrate index + // F - Sampling rate frequency index + // G - Padding bit + // H - Private bit + // I - Channel Mode + // J - Mode extension (Only if Joint stereo) + // K - Copyright + // L - Original + // M - Emphasis + + if (strlen($Header4Bytes) != 4) { + return false; + } + + $MPEGrawHeader['synch'] = (getid3_lib::BigEndian2Int(substr($Header4Bytes, 0, 2)) & 0xFFE0) >> 4; + $MPEGrawHeader['version'] = (ord($Header4Bytes[1]) & 0x18) >> 3; // BB + $MPEGrawHeader['layer'] = (ord($Header4Bytes[1]) & 0x06) >> 1; // CC + $MPEGrawHeader['protection'] = (ord($Header4Bytes[1]) & 0x01); // D + $MPEGrawHeader['bitrate'] = (ord($Header4Bytes[2]) & 0xF0) >> 4; // EEEE + $MPEGrawHeader['sample_rate'] = (ord($Header4Bytes[2]) & 0x0C) >> 2; // FF + $MPEGrawHeader['padding'] = (ord($Header4Bytes[2]) & 0x02) >> 1; // G + $MPEGrawHeader['private'] = (ord($Header4Bytes[2]) & 0x01); // H + $MPEGrawHeader['channelmode'] = (ord($Header4Bytes[3]) & 0xC0) >> 6; // II + $MPEGrawHeader['modeextension'] = (ord($Header4Bytes[3]) & 0x30) >> 4; // JJ + $MPEGrawHeader['copyright'] = (ord($Header4Bytes[3]) & 0x08) >> 3; // K + $MPEGrawHeader['original'] = (ord($Header4Bytes[3]) & 0x04) >> 2; // L + $MPEGrawHeader['emphasis'] = (ord($Header4Bytes[3]) & 0x03); // MM + + return $MPEGrawHeader; + } + + public static function MPEGaudioFrameLength(&$bitrate, &$version, &$layer, $padding, &$samplerate) + { + static $AudioFrameLengthCache = []; + + if (! isset($AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate])) { + $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] = false; + if ($bitrate != 'free') { + if ($version == '1') { + if ($layer == '1') { + + // For Layer I slot is 32 bits long + $FrameLengthCoefficient = 48; + $SlotLength = 4; + } else { // Layer 2 / 3 + + // for Layer 2 and Layer 3 slot is 8 bits long. + $FrameLengthCoefficient = 144; + $SlotLength = 1; + } + } else { // MPEG-2 / MPEG-2.5 + + if ($layer == '1') { + + // For Layer I slot is 32 bits long + $FrameLengthCoefficient = 24; + $SlotLength = 4; + } elseif ($layer == '2') { + + // for Layer 2 and Layer 3 slot is 8 bits long. + $FrameLengthCoefficient = 144; + $SlotLength = 1; + } else { // layer 3 + + // for Layer 2 and Layer 3 slot is 8 bits long. + $FrameLengthCoefficient = 72; + $SlotLength = 1; + } + } + + // FrameLengthInBytes = ((Coefficient * BitRate) / SampleRate) + Padding + if ($samplerate > 0) { + $NewFramelength = ($FrameLengthCoefficient * $bitrate) / $samplerate; + $NewFramelength = floor($NewFramelength / $SlotLength) * $SlotLength; // round to next-lower multiple of SlotLength (1 byte for Layer 2/3, 4 bytes for Layer I) + if ($padding) { + $NewFramelength += $SlotLength; + } + $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] = (int) $NewFramelength; + } + } + } + + return $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate]; + } + + public static function ClosestStandardMP3Bitrate($bit_rate) + { + static $standard_bit_rates = [320000, 256000, 224000, 192000, 160000, 128000, 112000, 96000, 80000, 64000, 56000, 48000, 40000, 32000, 24000, 16000, 8000]; + static $bit_rate_table = [0=>'-']; + $round_bit_rate = intval(round($bit_rate, -3)); + if (! isset($bit_rate_table[$round_bit_rate])) { + if ($round_bit_rate > max($standard_bit_rates)) { + $bit_rate_table[$round_bit_rate] = round($bit_rate, 2 - strlen($bit_rate)); + } else { + $bit_rate_table[$round_bit_rate] = max($standard_bit_rates); + foreach ($standard_bit_rates as $standard_bit_rate) { + if ($round_bit_rate >= $standard_bit_rate + (($bit_rate_table[$round_bit_rate] - $standard_bit_rate) / 2)) { + break; + } + $bit_rate_table[$round_bit_rate] = $standard_bit_rate; + } + } + } + + return $bit_rate_table[$round_bit_rate]; + } + + public static function XingVBRidOffset($version, $channelmode) + { + static $XingVBRidOffsetCache = []; + if (empty($XingVBRidOffset)) { + $XingVBRidOffset = [ + '1' => ['mono' => 0x15, // 4 + 17 = 21 + 'stereo' => 0x24, // 4 + 32 = 36 + 'joint stereo' => 0x24, + 'dual channel' => 0x24, + ], + + '2' => ['mono' => 0x0D, // 4 + 9 = 13 + 'stereo' => 0x15, // 4 + 17 = 21 + 'joint stereo' => 0x15, + 'dual channel' => 0x15, + ], + + '2.5' => ['mono' => 0x15, + 'stereo' => 0x15, + 'joint stereo' => 0x15, + 'dual channel' => 0x15, + ], + ]; + } + + return $XingVBRidOffset[$version][$channelmode]; + } + + public static function LAMEvbrMethodLookup($VBRmethodID) + { + static $LAMEvbrMethodLookup = [ + 0x00 => 'unknown', + 0x01 => 'cbr', + 0x02 => 'abr', + 0x03 => 'vbr-old / vbr-rh', + 0x04 => 'vbr-new / vbr-mtrh', + 0x05 => 'vbr-mt', + 0x06 => 'vbr (full vbr method 4)', + 0x08 => 'cbr (constant bitrate 2 pass)', + 0x09 => 'abr (2 pass)', + 0x0F => 'reserved', + ]; + + return isset($LAMEvbrMethodLookup[$VBRmethodID]) ? $LAMEvbrMethodLookup[$VBRmethodID] : ''; + } + + public static function LAMEmiscStereoModeLookup($StereoModeID) + { + static $LAMEmiscStereoModeLookup = [ + 0 => 'mono', + 1 => 'stereo', + 2 => 'dual mono', + 3 => 'joint stereo', + 4 => 'forced stereo', + 5 => 'auto', + 6 => 'intensity stereo', + 7 => 'other', + ]; + + return isset($LAMEmiscStereoModeLookup[$StereoModeID]) ? $LAMEmiscStereoModeLookup[$StereoModeID] : ''; + } + + public static function LAMEmiscSourceSampleFrequencyLookup($SourceSampleFrequencyID) + { + static $LAMEmiscSourceSampleFrequencyLookup = [ + 0 => '<= 32 kHz', + 1 => '44.1 kHz', + 2 => '48 kHz', + 3 => '> 48kHz', + ]; + + return isset($LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID]) ? $LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID] : ''; + } + + public static function LAMEsurroundInfoLookup($SurroundInfoID) + { + static $LAMEsurroundInfoLookup = [ + 0 => 'no surround info', + 1 => 'DPL encoding', + 2 => 'DPL2 encoding', + 3 => 'Ambisonic encoding', + ]; + + return isset($LAMEsurroundInfoLookup[$SurroundInfoID]) ? $LAMEsurroundInfoLookup[$SurroundInfoID] : 'reserved'; + } + + public static function LAMEpresetUsedLookup($LAMEtag) + { + if ($LAMEtag['preset_used_id'] == 0) { + // no preset used (LAME >=3.93) + // no preset recorded (LAME <3.93) + return ''; + } + $LAMEpresetUsedLookup = []; + + ///// THIS PART CANNOT BE STATIC . + for ($i = 8; $i <= 320; $i++) { + switch ($LAMEtag['vbr_method']) { + case 'cbr': + $LAMEpresetUsedLookup[$i] = '--alt-preset '.$LAMEtag['vbr_method'].' '.$i; + break; + case 'abr': + default: // other VBR modes shouldn't be here(?) + $LAMEpresetUsedLookup[$i] = '--alt-preset '.$i; + break; + } + } + + // named old-style presets (studio, phone, voice, etc) are handled in GuessEncoderOptions() + + // named alt-presets + $LAMEpresetUsedLookup[1000] = '--r3mix'; + $LAMEpresetUsedLookup[1001] = '--alt-preset standard'; + $LAMEpresetUsedLookup[1002] = '--alt-preset extreme'; + $LAMEpresetUsedLookup[1003] = '--alt-preset insane'; + $LAMEpresetUsedLookup[1004] = '--alt-preset fast standard'; + $LAMEpresetUsedLookup[1005] = '--alt-preset fast extreme'; + $LAMEpresetUsedLookup[1006] = '--alt-preset medium'; + $LAMEpresetUsedLookup[1007] = '--alt-preset fast medium'; + + // LAME 3.94 additions/changes + $LAMEpresetUsedLookup[1010] = '--preset portable'; // 3.94a15 Oct 21 2003 + $LAMEpresetUsedLookup[1015] = '--preset radio'; // 3.94a15 Oct 21 2003 + + $LAMEpresetUsedLookup[320] = '--preset insane'; // 3.94a15 Nov 12 2003 + $LAMEpresetUsedLookup[410] = '-V9'; + $LAMEpresetUsedLookup[420] = '-V8'; + $LAMEpresetUsedLookup[440] = '-V6'; + $LAMEpresetUsedLookup[430] = '--preset radio'; // 3.94a15 Nov 12 2003 + $LAMEpresetUsedLookup[450] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'portable'; // 3.94a15 Nov 12 2003 + $LAMEpresetUsedLookup[460] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'medium'; // 3.94a15 Nov 12 2003 + $LAMEpresetUsedLookup[470] = '--r3mix'; // 3.94b1 Dec 18 2003 + $LAMEpresetUsedLookup[480] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'standard'; // 3.94a15 Nov 12 2003 + $LAMEpresetUsedLookup[490] = '-V1'; + $LAMEpresetUsedLookup[500] = '--preset '.(($LAMEtag['raw']['vbr_method'] == 4) ? 'fast ' : '').'extreme'; // 3.94a15 Nov 12 2003 + + return isset($LAMEpresetUsedLookup[$LAMEtag['preset_used_id']]) ? $LAMEpresetUsedLookup[$LAMEtag['preset_used_id']] : 'new/unknown preset: '.$LAMEtag['preset_used_id'].' - report to info@getid3.org'; + } } diff --git a/app/Library/getid3/getid3/module.audio.mpc.php b/app/Library/getid3/getid3/module.audio.mpc.php index 14e829d9..ae170d63 100644 --- a/app/Library/getid3/getid3/module.audio.mpc.php +++ b/app/Library/getid3/getid3/module.audio.mpc.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,494 +15,514 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_mpc extends getid3_handler { - - public function Analyze() { - $info = &$this->getid3->info; - - $info['mpc']['header'] = array(); - $thisfile_mpc_header = &$info['mpc']['header']; - - $info['fileformat'] = 'mpc'; - $info['audio']['dataformat'] = 'mpc'; - $info['audio']['bitrate_mode'] = 'vbr'; - $info['audio']['channels'] = 2; // up to SV7 the format appears to have been hardcoded for stereo only - $info['audio']['lossless'] = false; - - $this->fseek($info['avdataoffset']); - $MPCheaderData = $this->fread(4); - $info['mpc']['header']['preamble'] = substr($MPCheaderData, 0, 4); // should be 'MPCK' (SV8) or 'MP+' (SV7), otherwise possible stream data (SV4-SV6) - if (preg_match('#^MPCK#', $info['mpc']['header']['preamble'])) { - - // this is SV8 - return $this->ParseMPCsv8(); - - } elseif (preg_match('#^MP\+#', $info['mpc']['header']['preamble'])) { - - // this is SV7 - return $this->ParseMPCsv7(); - - } elseif (preg_match('/^[\x00\x01\x10\x11\x40\x41\x50\x51\x80\x81\x90\x91\xC0\xC1\xD0\xD1][\x20-37][\x00\x20\x40\x60\x80\xA0\xC0\xE0]/s', $MPCheaderData)) { - - // this is SV4 - SV6, handle seperately - return $this->ParseMPCsv6(); - - } else { - - $this->error('Expecting "MP+" or "MPCK" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($MPCheaderData, 0, 4)).'"'); - unset($info['fileformat']); - unset($info['mpc']); - return false; - - } - return false; - } - - - public function ParseMPCsv8() { - // this is SV8 - // http://trac.musepack.net/trac/wiki/SV8Specification - - $info = &$this->getid3->info; - $thisfile_mpc_header = &$info['mpc']['header']; - - $keyNameSize = 2; - $maxHandledPacketLength = 9; // specs say: "n*8; 0 < n < 10" - - $offset = $this->ftell(); - while ($offset < $info['avdataend']) { - $thisPacket = array(); - $thisPacket['offset'] = $offset; - $packet_offset = 0; - - // Size is a variable-size field, could be 1-4 bytes (possibly more?) - // read enough data in and figure out the exact size later - $MPCheaderData = $this->fread($keyNameSize + $maxHandledPacketLength); - $packet_offset += $keyNameSize; - $thisPacket['key'] = substr($MPCheaderData, 0, $keyNameSize); - $thisPacket['key_name'] = $this->MPCsv8PacketName($thisPacket['key']); - if ($thisPacket['key'] == $thisPacket['key_name']) { - $this->error('Found unexpected key value "'.$thisPacket['key'].'" at offset '.$thisPacket['offset']); - return false; - } - $packetLength = 0; - $thisPacket['packet_size'] = $this->SV8variableLengthInteger(substr($MPCheaderData, $keyNameSize), $packetLength); // includes keyname and packet_size field - if ($thisPacket['packet_size'] === false) { - $this->error('Did not find expected packet length within '.$maxHandledPacketLength.' bytes at offset '.($thisPacket['offset'] + $keyNameSize)); - return false; - } - $packet_offset += $packetLength; - $offset += $thisPacket['packet_size']; - - switch ($thisPacket['key']) { - case 'SH': // Stream Header - $moreBytesToRead = $thisPacket['packet_size'] - $keyNameSize - $maxHandledPacketLength; - if ($moreBytesToRead > 0) { - $MPCheaderData .= $this->fread($moreBytesToRead); - } - $thisPacket['crc'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 4)); - $packet_offset += 4; - $thisPacket['stream_version'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1)); - $packet_offset += 1; - - $packetLength = 0; - $thisPacket['sample_count'] = $this->SV8variableLengthInteger(substr($MPCheaderData, $packet_offset, $maxHandledPacketLength), $packetLength); - $packet_offset += $packetLength; - - $packetLength = 0; - $thisPacket['beginning_silence'] = $this->SV8variableLengthInteger(substr($MPCheaderData, $packet_offset, $maxHandledPacketLength), $packetLength); - $packet_offset += $packetLength; - - $otherUsefulData = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2)); - $packet_offset += 2; - $thisPacket['sample_frequency_raw'] = (($otherUsefulData & 0xE000) >> 13); - $thisPacket['max_bands_used'] = (($otherUsefulData & 0x1F00) >> 8); - $thisPacket['channels'] = (($otherUsefulData & 0x00F0) >> 4) + 1; - $thisPacket['ms_used'] = (bool) (($otherUsefulData & 0x0008) >> 3); - $thisPacket['audio_block_frames'] = (($otherUsefulData & 0x0007) >> 0); - $thisPacket['sample_frequency'] = $this->MPCfrequencyLookup($thisPacket['sample_frequency_raw']); - - $thisfile_mpc_header['mid_side_stereo'] = $thisPacket['ms_used']; - $thisfile_mpc_header['sample_rate'] = $thisPacket['sample_frequency']; - $thisfile_mpc_header['samples'] = $thisPacket['sample_count']; - $thisfile_mpc_header['stream_version_major'] = $thisPacket['stream_version']; - - $info['audio']['channels'] = $thisPacket['channels']; - $info['audio']['sample_rate'] = $thisPacket['sample_frequency']; - $info['playtime_seconds'] = $thisPacket['sample_count'] / $thisPacket['sample_frequency']; - $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; - break; - - case 'RG': // Replay Gain - $moreBytesToRead = $thisPacket['packet_size'] - $keyNameSize - $maxHandledPacketLength; - if ($moreBytesToRead > 0) { - $MPCheaderData .= $this->fread($moreBytesToRead); - } - $thisPacket['replaygain_version'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1)); - $packet_offset += 1; - $thisPacket['replaygain_title_gain'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2)); - $packet_offset += 2; - $thisPacket['replaygain_title_peak'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2)); - $packet_offset += 2; - $thisPacket['replaygain_album_gain'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2)); - $packet_offset += 2; - $thisPacket['replaygain_album_peak'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2)); - $packet_offset += 2; - - if ($thisPacket['replaygain_title_gain']) { $info['replay_gain']['title']['gain'] = $thisPacket['replaygain_title_gain']; } - if ($thisPacket['replaygain_title_peak']) { $info['replay_gain']['title']['peak'] = $thisPacket['replaygain_title_peak']; } - if ($thisPacket['replaygain_album_gain']) { $info['replay_gain']['album']['gain'] = $thisPacket['replaygain_album_gain']; } - if ($thisPacket['replaygain_album_peak']) { $info['replay_gain']['album']['peak'] = $thisPacket['replaygain_album_peak']; } - break; - - case 'EI': // Encoder Info - $moreBytesToRead = $thisPacket['packet_size'] - $keyNameSize - $maxHandledPacketLength; - if ($moreBytesToRead > 0) { - $MPCheaderData .= $this->fread($moreBytesToRead); - } - $profile_pns = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1)); - $packet_offset += 1; - $quality_int = (($profile_pns & 0xF0) >> 4); - $quality_dec = (($profile_pns & 0x0E) >> 3); - $thisPacket['quality'] = (float) $quality_int + ($quality_dec / 8); - $thisPacket['pns_tool'] = (bool) (($profile_pns & 0x01) >> 0); - $thisPacket['version_major'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1)); - $packet_offset += 1; - $thisPacket['version_minor'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1)); - $packet_offset += 1; - $thisPacket['version_build'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1)); - $packet_offset += 1; - $thisPacket['version'] = $thisPacket['version_major'].'.'.$thisPacket['version_minor'].'.'.$thisPacket['version_build']; - - $info['audio']['encoder'] = 'MPC v'.$thisPacket['version'].' ('.(($thisPacket['version_minor'] % 2) ? 'unstable' : 'stable').')'; - $thisfile_mpc_header['encoder_version'] = $info['audio']['encoder']; - //$thisfile_mpc_header['quality'] = (float) ($thisPacket['quality'] / 1.5875); // values can range from 0.000 to 15.875, mapped to qualities of 0.0 to 10.0 - $thisfile_mpc_header['quality'] = (float) ($thisPacket['quality'] - 5); // values can range from 0.000 to 15.875, of which 0..4 are "reserved/experimental", and 5..15 are mapped to qualities of 0.0 to 10.0 - break; - - case 'SO': // Seek Table Offset - $packetLength = 0; - $thisPacket['seek_table_offset'] = $thisPacket['offset'] + $this->SV8variableLengthInteger(substr($MPCheaderData, $packet_offset, $maxHandledPacketLength), $packetLength); - $packet_offset += $packetLength; - break; - - case 'ST': // Seek Table - case 'SE': // Stream End - case 'AP': // Audio Data - // nothing useful here, just skip this packet - $thisPacket = array(); - break; - - default: - $this->error('Found unhandled key type "'.$thisPacket['key'].'" at offset '.$thisPacket['offset']); - return false; - break; - } - if (!empty($thisPacket)) { - $info['mpc']['packets'][] = $thisPacket; - } - $this->fseek($offset); - } - $thisfile_mpc_header['size'] = $offset; - return true; - } - - public function ParseMPCsv7() { - // this is SV7 - // http://www.uni-jena.de/~pfk/mpp/sv8/header.html - - $info = &$this->getid3->info; - $thisfile_mpc_header = &$info['mpc']['header']; - $offset = 0; - - $thisfile_mpc_header['size'] = 28; - $MPCheaderData = $info['mpc']['header']['preamble']; - $MPCheaderData .= $this->fread($thisfile_mpc_header['size'] - strlen($info['mpc']['header']['preamble'])); - $offset = strlen('MP+'); - - $StreamVersionByte = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 1)); - $offset += 1; - $thisfile_mpc_header['stream_version_major'] = ($StreamVersionByte & 0x0F) >> 0; - $thisfile_mpc_header['stream_version_minor'] = ($StreamVersionByte & 0xF0) >> 4; // should always be 0, subversions no longer exist in SV8 - $thisfile_mpc_header['frame_count'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 4)); - $offset += 4; - - if ($thisfile_mpc_header['stream_version_major'] != 7) { - $this->error('Only Musepack SV7 supported (this file claims to be v'.$thisfile_mpc_header['stream_version_major'].')'); - return false; - } - - $FlagsDWORD1 = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 4)); - $offset += 4; - $thisfile_mpc_header['intensity_stereo'] = (bool) (($FlagsDWORD1 & 0x80000000) >> 31); - $thisfile_mpc_header['mid_side_stereo'] = (bool) (($FlagsDWORD1 & 0x40000000) >> 30); - $thisfile_mpc_header['max_subband'] = ($FlagsDWORD1 & 0x3F000000) >> 24; - $thisfile_mpc_header['raw']['profile'] = ($FlagsDWORD1 & 0x00F00000) >> 20; - $thisfile_mpc_header['begin_loud'] = (bool) (($FlagsDWORD1 & 0x00080000) >> 19); - $thisfile_mpc_header['end_loud'] = (bool) (($FlagsDWORD1 & 0x00040000) >> 18); - $thisfile_mpc_header['raw']['sample_rate'] = ($FlagsDWORD1 & 0x00030000) >> 16; - $thisfile_mpc_header['max_level'] = ($FlagsDWORD1 & 0x0000FFFF); - - $thisfile_mpc_header['raw']['title_peak'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 2)); - $offset += 2; - $thisfile_mpc_header['raw']['title_gain'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 2), true); - $offset += 2; - - $thisfile_mpc_header['raw']['album_peak'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 2)); - $offset += 2; - $thisfile_mpc_header['raw']['album_gain'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 2), true); - $offset += 2; - - $FlagsDWORD2 = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 4)); - $offset += 4; - $thisfile_mpc_header['true_gapless'] = (bool) (($FlagsDWORD2 & 0x80000000) >> 31); - $thisfile_mpc_header['last_frame_length'] = ($FlagsDWORD2 & 0x7FF00000) >> 20; - - - $thisfile_mpc_header['raw']['not_sure_what'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 3)); - $offset += 3; - $thisfile_mpc_header['raw']['encoder_version'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 1)); - $offset += 1; - - $thisfile_mpc_header['profile'] = $this->MPCprofileNameLookup($thisfile_mpc_header['raw']['profile']); - $thisfile_mpc_header['sample_rate'] = $this->MPCfrequencyLookup($thisfile_mpc_header['raw']['sample_rate']); - if ($thisfile_mpc_header['sample_rate'] == 0) { - $this->error('Corrupt MPC file: frequency == zero'); - return false; - } - $info['audio']['sample_rate'] = $thisfile_mpc_header['sample_rate']; - $thisfile_mpc_header['samples'] = ((($thisfile_mpc_header['frame_count'] - 1) * 1152) + $thisfile_mpc_header['last_frame_length']) * $info['audio']['channels']; - - $info['playtime_seconds'] = ($thisfile_mpc_header['samples'] / $info['audio']['channels']) / $info['audio']['sample_rate']; - if ($info['playtime_seconds'] == 0) { - $this->error('Corrupt MPC file: playtime_seconds == zero'); - return false; - } - - // add size of file header to avdataoffset - calc bitrate correctly + MD5 data - $info['avdataoffset'] += $thisfile_mpc_header['size']; - - $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; - - $thisfile_mpc_header['title_peak'] = $thisfile_mpc_header['raw']['title_peak']; - $thisfile_mpc_header['title_peak_db'] = $this->MPCpeakDBLookup($thisfile_mpc_header['title_peak']); - if ($thisfile_mpc_header['raw']['title_gain'] < 0) { - $thisfile_mpc_header['title_gain_db'] = (float) (32768 + $thisfile_mpc_header['raw']['title_gain']) / -100; - } else { - $thisfile_mpc_header['title_gain_db'] = (float) $thisfile_mpc_header['raw']['title_gain'] / 100; - } - - $thisfile_mpc_header['album_peak'] = $thisfile_mpc_header['raw']['album_peak']; - $thisfile_mpc_header['album_peak_db'] = $this->MPCpeakDBLookup($thisfile_mpc_header['album_peak']); - if ($thisfile_mpc_header['raw']['album_gain'] < 0) { - $thisfile_mpc_header['album_gain_db'] = (float) (32768 + $thisfile_mpc_header['raw']['album_gain']) / -100; - } else { - $thisfile_mpc_header['album_gain_db'] = (float) $thisfile_mpc_header['raw']['album_gain'] / 100;; - } - $thisfile_mpc_header['encoder_version'] = $this->MPCencoderVersionLookup($thisfile_mpc_header['raw']['encoder_version']); - - $info['replay_gain']['track']['adjustment'] = $thisfile_mpc_header['title_gain_db']; - $info['replay_gain']['album']['adjustment'] = $thisfile_mpc_header['album_gain_db']; - - if ($thisfile_mpc_header['title_peak'] > 0) { - $info['replay_gain']['track']['peak'] = $thisfile_mpc_header['title_peak']; - } elseif (round($thisfile_mpc_header['max_level'] * 1.18) > 0) { - $info['replay_gain']['track']['peak'] = getid3_lib::CastAsInt(round($thisfile_mpc_header['max_level'] * 1.18)); // why? I don't know - see mppdec.c - } - if ($thisfile_mpc_header['album_peak'] > 0) { - $info['replay_gain']['album']['peak'] = $thisfile_mpc_header['album_peak']; - } - - //$info['audio']['encoder'] = 'SV'.$thisfile_mpc_header['stream_version_major'].'.'.$thisfile_mpc_header['stream_version_minor'].', '.$thisfile_mpc_header['encoder_version']; - $info['audio']['encoder'] = $thisfile_mpc_header['encoder_version']; - $info['audio']['encoder_options'] = $thisfile_mpc_header['profile']; - $thisfile_mpc_header['quality'] = (float) ($thisfile_mpc_header['raw']['profile'] - 5); // values can range from 0 to 15, of which 0..4 are "reserved/experimental", and 5..15 are mapped to qualities of 0.0 to 10.0 - - return true; - } - - public function ParseMPCsv6() { - // this is SV4 - SV6 - - $info = &$this->getid3->info; - $thisfile_mpc_header = &$info['mpc']['header']; - $offset = 0; - - $thisfile_mpc_header['size'] = 8; - $this->fseek($info['avdataoffset']); - $MPCheaderData = $this->fread($thisfile_mpc_header['size']); - - // add size of file header to avdataoffset - calc bitrate correctly + MD5 data - $info['avdataoffset'] += $thisfile_mpc_header['size']; - - // Most of this code adapted from Jurgen Faul's MPEGplus source code - thanks Jurgen! :) - $HeaderDWORD[0] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, 0, 4)); - $HeaderDWORD[1] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, 4, 4)); - - - // DDDD DDDD CCCC CCCC BBBB BBBB AAAA AAAA - // aaaa aaaa abcd dddd dddd deee eeff ffff - // - // a = bitrate = anything - // b = IS = anything - // c = MS = anything - // d = streamversion = 0000000004 or 0000000005 or 0000000006 - // e = maxband = anything - // f = blocksize = 000001 for SV5+, anything(?) for SV4 - - $thisfile_mpc_header['target_bitrate'] = (($HeaderDWORD[0] & 0xFF800000) >> 23); - $thisfile_mpc_header['intensity_stereo'] = (bool) (($HeaderDWORD[0] & 0x00400000) >> 22); - $thisfile_mpc_header['mid_side_stereo'] = (bool) (($HeaderDWORD[0] & 0x00200000) >> 21); - $thisfile_mpc_header['stream_version_major'] = ($HeaderDWORD[0] & 0x001FF800) >> 11; - $thisfile_mpc_header['stream_version_minor'] = 0; // no sub-version numbers before SV7 - $thisfile_mpc_header['max_band'] = ($HeaderDWORD[0] & 0x000007C0) >> 6; // related to lowpass frequency, not sure how it translates exactly - $thisfile_mpc_header['block_size'] = ($HeaderDWORD[0] & 0x0000003F); - - switch ($thisfile_mpc_header['stream_version_major']) { - case 4: - $thisfile_mpc_header['frame_count'] = ($HeaderDWORD[1] >> 16); - break; - - case 5: - case 6: - $thisfile_mpc_header['frame_count'] = $HeaderDWORD[1]; - break; - - default: - $info['error'] = 'Expecting 4, 5 or 6 in version field, found '.$thisfile_mpc_header['stream_version_major'].' instead'; - unset($info['mpc']); - return false; - break; - } - - if (($thisfile_mpc_header['stream_version_major'] > 4) && ($thisfile_mpc_header['block_size'] != 1)) { - $this->warning('Block size expected to be 1, actual value found: '.$thisfile_mpc_header['block_size']); - } - - $thisfile_mpc_header['sample_rate'] = 44100; // AB: used by all files up to SV7 - $info['audio']['sample_rate'] = $thisfile_mpc_header['sample_rate']; - $thisfile_mpc_header['samples'] = $thisfile_mpc_header['frame_count'] * 1152 * $info['audio']['channels']; - - if ($thisfile_mpc_header['target_bitrate'] == 0) { - $info['audio']['bitrate_mode'] = 'vbr'; - } else { - $info['audio']['bitrate_mode'] = 'cbr'; - } - - $info['mpc']['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) * 8 * 44100 / $thisfile_mpc_header['frame_count'] / 1152; - $info['audio']['bitrate'] = $info['mpc']['bitrate']; - $info['audio']['encoder'] = 'SV'.$thisfile_mpc_header['stream_version_major']; - - return true; - } - - - public function MPCprofileNameLookup($profileid) { - static $MPCprofileNameLookup = array( - 0 => 'no profile', - 1 => 'Experimental', - 2 => 'unused', - 3 => 'unused', - 4 => 'unused', - 5 => 'below Telephone (q = 0.0)', - 6 => 'below Telephone (q = 1.0)', - 7 => 'Telephone (q = 2.0)', - 8 => 'Thumb (q = 3.0)', - 9 => 'Radio (q = 4.0)', - 10 => 'Standard (q = 5.0)', - 11 => 'Extreme (q = 6.0)', - 12 => 'Insane (q = 7.0)', - 13 => 'BrainDead (q = 8.0)', - 14 => 'above BrainDead (q = 9.0)', - 15 => 'above BrainDead (q = 10.0)' - ); - return (isset($MPCprofileNameLookup[$profileid]) ? $MPCprofileNameLookup[$profileid] : 'invalid'); - } - - public function MPCfrequencyLookup($frequencyid) { - static $MPCfrequencyLookup = array( - 0 => 44100, - 1 => 48000, - 2 => 37800, - 3 => 32000 - ); - return (isset($MPCfrequencyLookup[$frequencyid]) ? $MPCfrequencyLookup[$frequencyid] : 'invalid'); - } - - public function MPCpeakDBLookup($intvalue) { - if ($intvalue > 0) { - return ((log10($intvalue) / log10(2)) - 15) * 6; - } - return false; - } - - public function MPCencoderVersionLookup($encoderversion) { - //Encoder version * 100 (106 = 1.06) - //EncoderVersion % 10 == 0 Release (1.0) - //EncoderVersion % 2 == 0 Beta (1.06) - //EncoderVersion % 2 == 1 Alpha (1.05a...z) - - if ($encoderversion == 0) { - // very old version, not known exactly which - return 'Buschmann v1.7.0-v1.7.9 or Klemm v0.90-v1.05'; - } - - if (($encoderversion % 10) == 0) { - - // release version - return number_format($encoderversion / 100, 2); - - } elseif (($encoderversion % 2) == 0) { - - // beta version - return number_format($encoderversion / 100, 2).' beta'; - - } - - // alpha version - return number_format($encoderversion / 100, 2).' alpha'; - } - - public function SV8variableLengthInteger($data, &$packetLength, $maxHandledPacketLength=9) { - $packet_size = 0; - for ($packetLength = 1; $packetLength <= $maxHandledPacketLength; $packetLength++) { - // variable-length size field: - // bits, big-endian - // 0xxx xxxx - value 0 to 2^7-1 - // 1xxx xxxx 0xxx xxxx - value 0 to 2^14-1 - // 1xxx xxxx 1xxx xxxx 0xxx xxxx - value 0 to 2^21-1 - // 1xxx xxxx 1xxx xxxx 1xxx xxxx 0xxx xxxx - value 0 to 2^28-1 - // ... - $thisbyte = ord(substr($data, ($packetLength - 1), 1)); - // look through bytes until find a byte with MSB==0 - $packet_size = ($packet_size << 7); - $packet_size = ($packet_size | ($thisbyte & 0x7F)); - if (($thisbyte & 0x80) === 0) { - break; - } - if ($packetLength >= $maxHandledPacketLength) { - return false; - } - } - return $packet_size; - } - - public function MPCsv8PacketName($packetKey) { - static $MPCsv8PacketName = array(); - if (empty($MPCsv8PacketName)) { - $MPCsv8PacketName = array( - 'AP' => 'Audio Packet', - 'CT' => 'Chapter Tag', - 'EI' => 'Encoder Info', - 'RG' => 'Replay Gain', - 'SE' => 'Stream End', - 'SH' => 'Stream Header', - 'SO' => 'Seek Table Offset', - 'ST' => 'Seek Table', - ); - } - return (isset($MPCsv8PacketName[$packetKey]) ? $MPCsv8PacketName[$packetKey] : $packetKey); - } + public function Analyze() + { + $info = &$this->getid3->info; + + $info['mpc']['header'] = []; + $thisfile_mpc_header = &$info['mpc']['header']; + + $info['fileformat'] = 'mpc'; + $info['audio']['dataformat'] = 'mpc'; + $info['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['channels'] = 2; // up to SV7 the format appears to have been hardcoded for stereo only + $info['audio']['lossless'] = false; + + $this->fseek($info['avdataoffset']); + $MPCheaderData = $this->fread(4); + $info['mpc']['header']['preamble'] = substr($MPCheaderData, 0, 4); // should be 'MPCK' (SV8) or 'MP+' (SV7), otherwise possible stream data (SV4-SV6) + if (preg_match('#^MPCK#', $info['mpc']['header']['preamble'])) { + + // this is SV8 + return $this->ParseMPCsv8(); + } elseif (preg_match('#^MP\+#', $info['mpc']['header']['preamble'])) { + + // this is SV7 + return $this->ParseMPCsv7(); + } elseif (preg_match('/^[\x00\x01\x10\x11\x40\x41\x50\x51\x80\x81\x90\x91\xC0\xC1\xD0\xD1][\x20-37][\x00\x20\x40\x60\x80\xA0\xC0\xE0]/s', $MPCheaderData)) { + + // this is SV4 - SV6, handle seperately + return $this->ParseMPCsv6(); + } else { + $this->error('Expecting "MP+" or "MPCK" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($MPCheaderData, 0, 4)).'"'); + unset($info['fileformat']); + unset($info['mpc']); + + return false; + } + + return false; + } + + public function ParseMPCsv8() + { + // this is SV8 + // http://trac.musepack.net/trac/wiki/SV8Specification + + $info = &$this->getid3->info; + $thisfile_mpc_header = &$info['mpc']['header']; + + $keyNameSize = 2; + $maxHandledPacketLength = 9; // specs say: "n*8; 0 < n < 10" + + $offset = $this->ftell(); + while ($offset < $info['avdataend']) { + $thisPacket = []; + $thisPacket['offset'] = $offset; + $packet_offset = 0; + + // Size is a variable-size field, could be 1-4 bytes (possibly more?) + // read enough data in and figure out the exact size later + $MPCheaderData = $this->fread($keyNameSize + $maxHandledPacketLength); + $packet_offset += $keyNameSize; + $thisPacket['key'] = substr($MPCheaderData, 0, $keyNameSize); + $thisPacket['key_name'] = $this->MPCsv8PacketName($thisPacket['key']); + if ($thisPacket['key'] == $thisPacket['key_name']) { + $this->error('Found unexpected key value "'.$thisPacket['key'].'" at offset '.$thisPacket['offset']); + + return false; + } + $packetLength = 0; + $thisPacket['packet_size'] = $this->SV8variableLengthInteger(substr($MPCheaderData, $keyNameSize), $packetLength); // includes keyname and packet_size field + if ($thisPacket['packet_size'] === false) { + $this->error('Did not find expected packet length within '.$maxHandledPacketLength.' bytes at offset '.($thisPacket['offset'] + $keyNameSize)); + + return false; + } + $packet_offset += $packetLength; + $offset += $thisPacket['packet_size']; + + switch ($thisPacket['key']) { + case 'SH': // Stream Header + $moreBytesToRead = $thisPacket['packet_size'] - $keyNameSize - $maxHandledPacketLength; + if ($moreBytesToRead > 0) { + $MPCheaderData .= $this->fread($moreBytesToRead); + } + $thisPacket['crc'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 4)); + $packet_offset += 4; + $thisPacket['stream_version'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1)); + $packet_offset += 1; + + $packetLength = 0; + $thisPacket['sample_count'] = $this->SV8variableLengthInteger(substr($MPCheaderData, $packet_offset, $maxHandledPacketLength), $packetLength); + $packet_offset += $packetLength; + + $packetLength = 0; + $thisPacket['beginning_silence'] = $this->SV8variableLengthInteger(substr($MPCheaderData, $packet_offset, $maxHandledPacketLength), $packetLength); + $packet_offset += $packetLength; + + $otherUsefulData = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2)); + $packet_offset += 2; + $thisPacket['sample_frequency_raw'] = (($otherUsefulData & 0xE000) >> 13); + $thisPacket['max_bands_used'] = (($otherUsefulData & 0x1F00) >> 8); + $thisPacket['channels'] = (($otherUsefulData & 0x00F0) >> 4) + 1; + $thisPacket['ms_used'] = (bool) (($otherUsefulData & 0x0008) >> 3); + $thisPacket['audio_block_frames'] = (($otherUsefulData & 0x0007) >> 0); + $thisPacket['sample_frequency'] = $this->MPCfrequencyLookup($thisPacket['sample_frequency_raw']); + + $thisfile_mpc_header['mid_side_stereo'] = $thisPacket['ms_used']; + $thisfile_mpc_header['sample_rate'] = $thisPacket['sample_frequency']; + $thisfile_mpc_header['samples'] = $thisPacket['sample_count']; + $thisfile_mpc_header['stream_version_major'] = $thisPacket['stream_version']; + + $info['audio']['channels'] = $thisPacket['channels']; + $info['audio']['sample_rate'] = $thisPacket['sample_frequency']; + $info['playtime_seconds'] = $thisPacket['sample_count'] / $thisPacket['sample_frequency']; + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + break; + + case 'RG': // Replay Gain + $moreBytesToRead = $thisPacket['packet_size'] - $keyNameSize - $maxHandledPacketLength; + if ($moreBytesToRead > 0) { + $MPCheaderData .= $this->fread($moreBytesToRead); + } + $thisPacket['replaygain_version'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1)); + $packet_offset += 1; + $thisPacket['replaygain_title_gain'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2)); + $packet_offset += 2; + $thisPacket['replaygain_title_peak'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2)); + $packet_offset += 2; + $thisPacket['replaygain_album_gain'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2)); + $packet_offset += 2; + $thisPacket['replaygain_album_peak'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2)); + $packet_offset += 2; + + if ($thisPacket['replaygain_title_gain']) { + $info['replay_gain']['title']['gain'] = $thisPacket['replaygain_title_gain']; + } + if ($thisPacket['replaygain_title_peak']) { + $info['replay_gain']['title']['peak'] = $thisPacket['replaygain_title_peak']; + } + if ($thisPacket['replaygain_album_gain']) { + $info['replay_gain']['album']['gain'] = $thisPacket['replaygain_album_gain']; + } + if ($thisPacket['replaygain_album_peak']) { + $info['replay_gain']['album']['peak'] = $thisPacket['replaygain_album_peak']; + } + break; + + case 'EI': // Encoder Info + $moreBytesToRead = $thisPacket['packet_size'] - $keyNameSize - $maxHandledPacketLength; + if ($moreBytesToRead > 0) { + $MPCheaderData .= $this->fread($moreBytesToRead); + } + $profile_pns = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1)); + $packet_offset += 1; + $quality_int = (($profile_pns & 0xF0) >> 4); + $quality_dec = (($profile_pns & 0x0E) >> 3); + $thisPacket['quality'] = (float) $quality_int + ($quality_dec / 8); + $thisPacket['pns_tool'] = (bool) (($profile_pns & 0x01) >> 0); + $thisPacket['version_major'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1)); + $packet_offset += 1; + $thisPacket['version_minor'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1)); + $packet_offset += 1; + $thisPacket['version_build'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1)); + $packet_offset += 1; + $thisPacket['version'] = $thisPacket['version_major'].'.'.$thisPacket['version_minor'].'.'.$thisPacket['version_build']; + + $info['audio']['encoder'] = 'MPC v'.$thisPacket['version'].' ('.(($thisPacket['version_minor'] % 2) ? 'unstable' : 'stable').')'; + $thisfile_mpc_header['encoder_version'] = $info['audio']['encoder']; + //$thisfile_mpc_header['quality'] = (float) ($thisPacket['quality'] / 1.5875); // values can range from 0.000 to 15.875, mapped to qualities of 0.0 to 10.0 + $thisfile_mpc_header['quality'] = (float) ($thisPacket['quality'] - 5); // values can range from 0.000 to 15.875, of which 0..4 are "reserved/experimental", and 5..15 are mapped to qualities of 0.0 to 10.0 + break; + + case 'SO': // Seek Table Offset + $packetLength = 0; + $thisPacket['seek_table_offset'] = $thisPacket['offset'] + $this->SV8variableLengthInteger(substr($MPCheaderData, $packet_offset, $maxHandledPacketLength), $packetLength); + $packet_offset += $packetLength; + break; + + case 'ST': // Seek Table + case 'SE': // Stream End + case 'AP': // Audio Data + // nothing useful here, just skip this packet + $thisPacket = []; + break; + + default: + $this->error('Found unhandled key type "'.$thisPacket['key'].'" at offset '.$thisPacket['offset']); + + return false; + break; + } + if (! empty($thisPacket)) { + $info['mpc']['packets'][] = $thisPacket; + } + $this->fseek($offset); + } + $thisfile_mpc_header['size'] = $offset; + + return true; + } + + public function ParseMPCsv7() + { + // this is SV7 + // http://www.uni-jena.de/~pfk/mpp/sv8/header.html + + $info = &$this->getid3->info; + $thisfile_mpc_header = &$info['mpc']['header']; + $offset = 0; + + $thisfile_mpc_header['size'] = 28; + $MPCheaderData = $info['mpc']['header']['preamble']; + $MPCheaderData .= $this->fread($thisfile_mpc_header['size'] - strlen($info['mpc']['header']['preamble'])); + $offset = strlen('MP+'); + + $StreamVersionByte = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 1)); + $offset += 1; + $thisfile_mpc_header['stream_version_major'] = ($StreamVersionByte & 0x0F) >> 0; + $thisfile_mpc_header['stream_version_minor'] = ($StreamVersionByte & 0xF0) >> 4; // should always be 0, subversions no longer exist in SV8 + $thisfile_mpc_header['frame_count'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 4)); + $offset += 4; + + if ($thisfile_mpc_header['stream_version_major'] != 7) { + $this->error('Only Musepack SV7 supported (this file claims to be v'.$thisfile_mpc_header['stream_version_major'].')'); + + return false; + } + + $FlagsDWORD1 = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 4)); + $offset += 4; + $thisfile_mpc_header['intensity_stereo'] = (bool) (($FlagsDWORD1 & 0x80000000) >> 31); + $thisfile_mpc_header['mid_side_stereo'] = (bool) (($FlagsDWORD1 & 0x40000000) >> 30); + $thisfile_mpc_header['max_subband'] = ($FlagsDWORD1 & 0x3F000000) >> 24; + $thisfile_mpc_header['raw']['profile'] = ($FlagsDWORD1 & 0x00F00000) >> 20; + $thisfile_mpc_header['begin_loud'] = (bool) (($FlagsDWORD1 & 0x00080000) >> 19); + $thisfile_mpc_header['end_loud'] = (bool) (($FlagsDWORD1 & 0x00040000) >> 18); + $thisfile_mpc_header['raw']['sample_rate'] = ($FlagsDWORD1 & 0x00030000) >> 16; + $thisfile_mpc_header['max_level'] = ($FlagsDWORD1 & 0x0000FFFF); + + $thisfile_mpc_header['raw']['title_peak'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 2)); + $offset += 2; + $thisfile_mpc_header['raw']['title_gain'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 2), true); + $offset += 2; + + $thisfile_mpc_header['raw']['album_peak'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 2)); + $offset += 2; + $thisfile_mpc_header['raw']['album_gain'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 2), true); + $offset += 2; + + $FlagsDWORD2 = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 4)); + $offset += 4; + $thisfile_mpc_header['true_gapless'] = (bool) (($FlagsDWORD2 & 0x80000000) >> 31); + $thisfile_mpc_header['last_frame_length'] = ($FlagsDWORD2 & 0x7FF00000) >> 20; + + $thisfile_mpc_header['raw']['not_sure_what'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 3)); + $offset += 3; + $thisfile_mpc_header['raw']['encoder_version'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 1)); + $offset += 1; + + $thisfile_mpc_header['profile'] = $this->MPCprofileNameLookup($thisfile_mpc_header['raw']['profile']); + $thisfile_mpc_header['sample_rate'] = $this->MPCfrequencyLookup($thisfile_mpc_header['raw']['sample_rate']); + if ($thisfile_mpc_header['sample_rate'] == 0) { + $this->error('Corrupt MPC file: frequency == zero'); + + return false; + } + $info['audio']['sample_rate'] = $thisfile_mpc_header['sample_rate']; + $thisfile_mpc_header['samples'] = ((($thisfile_mpc_header['frame_count'] - 1) * 1152) + $thisfile_mpc_header['last_frame_length']) * $info['audio']['channels']; + + $info['playtime_seconds'] = ($thisfile_mpc_header['samples'] / $info['audio']['channels']) / $info['audio']['sample_rate']; + if ($info['playtime_seconds'] == 0) { + $this->error('Corrupt MPC file: playtime_seconds == zero'); + + return false; + } + + // add size of file header to avdataoffset - calc bitrate correctly + MD5 data + $info['avdataoffset'] += $thisfile_mpc_header['size']; + + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + + $thisfile_mpc_header['title_peak'] = $thisfile_mpc_header['raw']['title_peak']; + $thisfile_mpc_header['title_peak_db'] = $this->MPCpeakDBLookup($thisfile_mpc_header['title_peak']); + if ($thisfile_mpc_header['raw']['title_gain'] < 0) { + $thisfile_mpc_header['title_gain_db'] = (float) (32768 + $thisfile_mpc_header['raw']['title_gain']) / -100; + } else { + $thisfile_mpc_header['title_gain_db'] = (float) $thisfile_mpc_header['raw']['title_gain'] / 100; + } + + $thisfile_mpc_header['album_peak'] = $thisfile_mpc_header['raw']['album_peak']; + $thisfile_mpc_header['album_peak_db'] = $this->MPCpeakDBLookup($thisfile_mpc_header['album_peak']); + if ($thisfile_mpc_header['raw']['album_gain'] < 0) { + $thisfile_mpc_header['album_gain_db'] = (float) (32768 + $thisfile_mpc_header['raw']['album_gain']) / -100; + } else { + $thisfile_mpc_header['album_gain_db'] = (float) $thisfile_mpc_header['raw']['album_gain'] / 100; + } + $thisfile_mpc_header['encoder_version'] = $this->MPCencoderVersionLookup($thisfile_mpc_header['raw']['encoder_version']); + + $info['replay_gain']['track']['adjustment'] = $thisfile_mpc_header['title_gain_db']; + $info['replay_gain']['album']['adjustment'] = $thisfile_mpc_header['album_gain_db']; + + if ($thisfile_mpc_header['title_peak'] > 0) { + $info['replay_gain']['track']['peak'] = $thisfile_mpc_header['title_peak']; + } elseif (round($thisfile_mpc_header['max_level'] * 1.18) > 0) { + $info['replay_gain']['track']['peak'] = getid3_lib::CastAsInt(round($thisfile_mpc_header['max_level'] * 1.18)); // why? I don't know - see mppdec.c + } + if ($thisfile_mpc_header['album_peak'] > 0) { + $info['replay_gain']['album']['peak'] = $thisfile_mpc_header['album_peak']; + } + + //$info['audio']['encoder'] = 'SV'.$thisfile_mpc_header['stream_version_major'].'.'.$thisfile_mpc_header['stream_version_minor'].', '.$thisfile_mpc_header['encoder_version']; + $info['audio']['encoder'] = $thisfile_mpc_header['encoder_version']; + $info['audio']['encoder_options'] = $thisfile_mpc_header['profile']; + $thisfile_mpc_header['quality'] = (float) ($thisfile_mpc_header['raw']['profile'] - 5); // values can range from 0 to 15, of which 0..4 are "reserved/experimental", and 5..15 are mapped to qualities of 0.0 to 10.0 + + return true; + } + + public function ParseMPCsv6() + { + // this is SV4 - SV6 + + $info = &$this->getid3->info; + $thisfile_mpc_header = &$info['mpc']['header']; + $offset = 0; + + $thisfile_mpc_header['size'] = 8; + $this->fseek($info['avdataoffset']); + $MPCheaderData = $this->fread($thisfile_mpc_header['size']); + + // add size of file header to avdataoffset - calc bitrate correctly + MD5 data + $info['avdataoffset'] += $thisfile_mpc_header['size']; + + // Most of this code adapted from Jurgen Faul's MPEGplus source code - thanks Jurgen! :) + $HeaderDWORD[0] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, 0, 4)); + $HeaderDWORD[1] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, 4, 4)); + + // DDDD DDDD CCCC CCCC BBBB BBBB AAAA AAAA + // aaaa aaaa abcd dddd dddd deee eeff ffff + // + // a = bitrate = anything + // b = IS = anything + // c = MS = anything + // d = streamversion = 0000000004 or 0000000005 or 0000000006 + // e = maxband = anything + // f = blocksize = 000001 for SV5+, anything(?) for SV4 + + $thisfile_mpc_header['target_bitrate'] = (($HeaderDWORD[0] & 0xFF800000) >> 23); + $thisfile_mpc_header['intensity_stereo'] = (bool) (($HeaderDWORD[0] & 0x00400000) >> 22); + $thisfile_mpc_header['mid_side_stereo'] = (bool) (($HeaderDWORD[0] & 0x00200000) >> 21); + $thisfile_mpc_header['stream_version_major'] = ($HeaderDWORD[0] & 0x001FF800) >> 11; + $thisfile_mpc_header['stream_version_minor'] = 0; // no sub-version numbers before SV7 + $thisfile_mpc_header['max_band'] = ($HeaderDWORD[0] & 0x000007C0) >> 6; // related to lowpass frequency, not sure how it translates exactly + $thisfile_mpc_header['block_size'] = ($HeaderDWORD[0] & 0x0000003F); + + switch ($thisfile_mpc_header['stream_version_major']) { + case 4: + $thisfile_mpc_header['frame_count'] = ($HeaderDWORD[1] >> 16); + break; + + case 5: + case 6: + $thisfile_mpc_header['frame_count'] = $HeaderDWORD[1]; + break; + + default: + $info['error'] = 'Expecting 4, 5 or 6 in version field, found '.$thisfile_mpc_header['stream_version_major'].' instead'; + unset($info['mpc']); + + return false; + break; + } + + if (($thisfile_mpc_header['stream_version_major'] > 4) && ($thisfile_mpc_header['block_size'] != 1)) { + $this->warning('Block size expected to be 1, actual value found: '.$thisfile_mpc_header['block_size']); + } + + $thisfile_mpc_header['sample_rate'] = 44100; // AB: used by all files up to SV7 + $info['audio']['sample_rate'] = $thisfile_mpc_header['sample_rate']; + $thisfile_mpc_header['samples'] = $thisfile_mpc_header['frame_count'] * 1152 * $info['audio']['channels']; + + if ($thisfile_mpc_header['target_bitrate'] == 0) { + $info['audio']['bitrate_mode'] = 'vbr'; + } else { + $info['audio']['bitrate_mode'] = 'cbr'; + } + + $info['mpc']['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) * 8 * 44100 / $thisfile_mpc_header['frame_count'] / 1152; + $info['audio']['bitrate'] = $info['mpc']['bitrate']; + $info['audio']['encoder'] = 'SV'.$thisfile_mpc_header['stream_version_major']; + + return true; + } + + public function MPCprofileNameLookup($profileid) + { + static $MPCprofileNameLookup = [ + 0 => 'no profile', + 1 => 'Experimental', + 2 => 'unused', + 3 => 'unused', + 4 => 'unused', + 5 => 'below Telephone (q = 0.0)', + 6 => 'below Telephone (q = 1.0)', + 7 => 'Telephone (q = 2.0)', + 8 => 'Thumb (q = 3.0)', + 9 => 'Radio (q = 4.0)', + 10 => 'Standard (q = 5.0)', + 11 => 'Extreme (q = 6.0)', + 12 => 'Insane (q = 7.0)', + 13 => 'BrainDead (q = 8.0)', + 14 => 'above BrainDead (q = 9.0)', + 15 => 'above BrainDead (q = 10.0)', + ]; + + return isset($MPCprofileNameLookup[$profileid]) ? $MPCprofileNameLookup[$profileid] : 'invalid'; + } + + public function MPCfrequencyLookup($frequencyid) + { + static $MPCfrequencyLookup = [ + 0 => 44100, + 1 => 48000, + 2 => 37800, + 3 => 32000, + ]; + + return isset($MPCfrequencyLookup[$frequencyid]) ? $MPCfrequencyLookup[$frequencyid] : 'invalid'; + } + + public function MPCpeakDBLookup($intvalue) + { + if ($intvalue > 0) { + return ((log10($intvalue) / log10(2)) - 15) * 6; + } + + return false; + } + + public function MPCencoderVersionLookup($encoderversion) + { + //Encoder version * 100 (106 = 1.06) + //EncoderVersion % 10 == 0 Release (1.0) + //EncoderVersion % 2 == 0 Beta (1.06) + //EncoderVersion % 2 == 1 Alpha (1.05a...z) + + if ($encoderversion == 0) { + // very old version, not known exactly which + return 'Buschmann v1.7.0-v1.7.9 or Klemm v0.90-v1.05'; + } + + if (($encoderversion % 10) == 0) { + + // release version + return number_format($encoderversion / 100, 2); + } elseif (($encoderversion % 2) == 0) { + + // beta version + return number_format($encoderversion / 100, 2).' beta'; + } + + // alpha version + return number_format($encoderversion / 100, 2).' alpha'; + } + + public function SV8variableLengthInteger($data, &$packetLength, $maxHandledPacketLength = 9) + { + $packet_size = 0; + for ($packetLength = 1; $packetLength <= $maxHandledPacketLength; $packetLength++) { + // variable-length size field: + // bits, big-endian + // 0xxx xxxx - value 0 to 2^7-1 + // 1xxx xxxx 0xxx xxxx - value 0 to 2^14-1 + // 1xxx xxxx 1xxx xxxx 0xxx xxxx - value 0 to 2^21-1 + // 1xxx xxxx 1xxx xxxx 1xxx xxxx 0xxx xxxx - value 0 to 2^28-1 + // ... + $thisbyte = ord(substr($data, ($packetLength - 1), 1)); + // look through bytes until find a byte with MSB==0 + $packet_size = ($packet_size << 7); + $packet_size = ($packet_size | ($thisbyte & 0x7F)); + if (($thisbyte & 0x80) === 0) { + break; + } + if ($packetLength >= $maxHandledPacketLength) { + return false; + } + } + + return $packet_size; + } + + public function MPCsv8PacketName($packetKey) + { + static $MPCsv8PacketName = []; + if (empty($MPCsv8PacketName)) { + $MPCsv8PacketName = [ + 'AP' => 'Audio Packet', + 'CT' => 'Chapter Tag', + 'EI' => 'Encoder Info', + 'RG' => 'Replay Gain', + 'SE' => 'Stream End', + 'SH' => 'Stream Header', + 'SO' => 'Seek Table Offset', + 'ST' => 'Seek Table', + ]; + } + + return isset($MPCsv8PacketName[$packetKey]) ? $MPCsv8PacketName[$packetKey] : $packetKey; + } } diff --git a/app/Library/getid3/getid3/module.audio.ogg.php b/app/Library/getid3/getid3/module.audio.ogg.php index e41c96c4..8c19c20c 100644 --- a/app/Library/getid3/getid3/module.audio.ogg.php +++ b/app/Library/getid3/getid3/module.audio.ogg.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -18,823 +19,803 @@ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.flac.php', __FILE class getid3_ogg extends getid3_handler { - // http://xiph.org/vorbis/doc/Vorbis_I_spec.html - public function Analyze() { - $info = &$this->getid3->info; - - $info['fileformat'] = 'ogg'; - - // Warn about illegal tags - only vorbiscomments are allowed - if (isset($info['id3v2'])) { - $this->warning('Illegal ID3v2 tag present.'); - } - if (isset($info['id3v1'])) { - $this->warning('Illegal ID3v1 tag present.'); - } - if (isset($info['ape'])) { - $this->warning('Illegal APE tag present.'); - } - - - // Page 1 - Stream Header - - $this->fseek($info['avdataoffset']); - - $oggpageinfo = $this->ParseOggPageHeader(); - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; - - if ($this->ftell() >= $this->getid3->fread_buffer_size()) { - $this->error('Could not find start of Ogg page in the first '.$this->getid3->fread_buffer_size().' bytes (this might not be an Ogg-Vorbis file?)'); - unset($info['fileformat']); - unset($info['ogg']); - return false; - } - - $filedata = $this->fread($oggpageinfo['page_length']); - $filedataoffset = 0; - - if (substr($filedata, 0, 4) == 'fLaC') { - - $info['audio']['dataformat'] = 'flac'; - $info['audio']['bitrate_mode'] = 'vbr'; - $info['audio']['lossless'] = true; - - } elseif (substr($filedata, 1, 6) == 'vorbis') { - - $this->ParseVorbisPageHeader($filedata, $filedataoffset, $oggpageinfo); - - } elseif (substr($filedata, 0, 8) == 'OpusHead') { - - if( $this->ParseOpusPageHeader($filedata, $filedataoffset, $oggpageinfo) == false ) { - return false; - } - - } elseif (substr($filedata, 0, 8) == 'Speex ') { - - // http://www.speex.org/manual/node10.html - - $info['audio']['dataformat'] = 'speex'; - $info['mime_type'] = 'audio/speex'; - $info['audio']['bitrate_mode'] = 'abr'; - $info['audio']['lossless'] = false; - - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_string'] = substr($filedata, $filedataoffset, 8); // hard-coded to 'Speex ' - $filedataoffset += 8; - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version'] = substr($filedata, $filedataoffset, 20); - $filedataoffset += 20; - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version_id'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['header_size'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['rate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode_bitstream_version'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['nb_channels'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['bitrate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['framesize'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['vbr'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['frames_per_packet'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['extra_headers'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['reserved1'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['reserved2'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - - $info['speex']['speex_version'] = trim($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version']); - $info['speex']['sample_rate'] = $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['rate']; - $info['speex']['channels'] = $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['nb_channels']; - $info['speex']['vbr'] = (bool) $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['vbr']; - $info['speex']['band_type'] = $this->SpeexBandModeLookup($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode']); - - $info['audio']['sample_rate'] = $info['speex']['sample_rate']; - $info['audio']['channels'] = $info['speex']['channels']; - if ($info['speex']['vbr']) { - $info['audio']['bitrate_mode'] = 'vbr'; - } - - } elseif (substr($filedata, 0, 7) == "\x80".'theora') { - - // http://www.theora.org/doc/Theora.pdf (section 6.2) - - $info['ogg']['pageheader']['theora']['theora_magic'] = substr($filedata, $filedataoffset, 7); // hard-coded to "\x80.'theora' - $filedataoffset += 7; - $info['ogg']['pageheader']['theora']['version_major'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $info['ogg']['pageheader']['theora']['version_minor'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $info['ogg']['pageheader']['theora']['version_revision'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $info['ogg']['pageheader']['theora']['frame_width_macroblocks'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 2)); - $filedataoffset += 2; - $info['ogg']['pageheader']['theora']['frame_height_macroblocks'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 2)); - $filedataoffset += 2; - $info['ogg']['pageheader']['theora']['resolution_x'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3)); - $filedataoffset += 3; - $info['ogg']['pageheader']['theora']['resolution_y'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3)); - $filedataoffset += 3; - $info['ogg']['pageheader']['theora']['picture_offset_x'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $info['ogg']['pageheader']['theora']['picture_offset_y'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $info['ogg']['pageheader']['theora']['frame_rate_numerator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['pageheader']['theora']['frame_rate_denominator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['pageheader']['theora']['pixel_aspect_numerator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3)); - $filedataoffset += 3; - $info['ogg']['pageheader']['theora']['pixel_aspect_denominator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3)); - $filedataoffset += 3; - $info['ogg']['pageheader']['theora']['color_space_id'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $info['ogg']['pageheader']['theora']['nominal_bitrate'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3)); - $filedataoffset += 3; - $info['ogg']['pageheader']['theora']['flags'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 2)); - $filedataoffset += 2; - - $info['ogg']['pageheader']['theora']['quality'] = ($info['ogg']['pageheader']['theora']['flags'] & 0xFC00) >> 10; - $info['ogg']['pageheader']['theora']['kfg_shift'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x03E0) >> 5; - $info['ogg']['pageheader']['theora']['pixel_format_id'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x0018) >> 3; - $info['ogg']['pageheader']['theora']['reserved'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x0007) >> 0; // should be 0 - $info['ogg']['pageheader']['theora']['color_space'] = self::TheoraColorSpace($info['ogg']['pageheader']['theora']['color_space_id']); - $info['ogg']['pageheader']['theora']['pixel_format'] = self::TheoraPixelFormat($info['ogg']['pageheader']['theora']['pixel_format_id']); - - $info['video']['dataformat'] = 'theora'; - $info['mime_type'] = 'video/ogg'; - //$info['audio']['bitrate_mode'] = 'abr'; - //$info['audio']['lossless'] = false; - $info['video']['resolution_x'] = $info['ogg']['pageheader']['theora']['resolution_x']; - $info['video']['resolution_y'] = $info['ogg']['pageheader']['theora']['resolution_y']; - if ($info['ogg']['pageheader']['theora']['frame_rate_denominator'] > 0) { - $info['video']['frame_rate'] = (float) $info['ogg']['pageheader']['theora']['frame_rate_numerator'] / $info['ogg']['pageheader']['theora']['frame_rate_denominator']; - } - if ($info['ogg']['pageheader']['theora']['pixel_aspect_denominator'] > 0) { - $info['video']['pixel_aspect_ratio'] = (float) $info['ogg']['pageheader']['theora']['pixel_aspect_numerator'] / $info['ogg']['pageheader']['theora']['pixel_aspect_denominator']; - } -$this->warning('Ogg Theora (v3) not fully supported in this version of getID3 ['.$this->getid3->version().'] -- bitrate, playtime and all audio data are currently unavailable'); - - - } elseif (substr($filedata, 0, 8) == "fishead\x00") { - - // Ogg Skeleton version 3.0 Format Specification - // http://xiph.org/ogg/doc/skeleton.html - $filedataoffset += 8; - $info['ogg']['skeleton']['fishead']['raw']['version_major'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2)); - $filedataoffset += 2; - $info['ogg']['skeleton']['fishead']['raw']['version_minor'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2)); - $filedataoffset += 2; - $info['ogg']['skeleton']['fishead']['raw']['presentationtime_numerator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); - $filedataoffset += 8; - $info['ogg']['skeleton']['fishead']['raw']['presentationtime_denominator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); - $filedataoffset += 8; - $info['ogg']['skeleton']['fishead']['raw']['basetime_numerator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); - $filedataoffset += 8; - $info['ogg']['skeleton']['fishead']['raw']['basetime_denominator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); - $filedataoffset += 8; - $info['ogg']['skeleton']['fishead']['raw']['utc'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 20)); - $filedataoffset += 20; - - $info['ogg']['skeleton']['fishead']['version'] = $info['ogg']['skeleton']['fishead']['raw']['version_major'].'.'.$info['ogg']['skeleton']['fishead']['raw']['version_minor']; - $info['ogg']['skeleton']['fishead']['presentationtime'] = $info['ogg']['skeleton']['fishead']['raw']['presentationtime_numerator'] / $info['ogg']['skeleton']['fishead']['raw']['presentationtime_denominator']; - $info['ogg']['skeleton']['fishead']['basetime'] = $info['ogg']['skeleton']['fishead']['raw']['basetime_numerator'] / $info['ogg']['skeleton']['fishead']['raw']['basetime_denominator']; - $info['ogg']['skeleton']['fishead']['utc'] = $info['ogg']['skeleton']['fishead']['raw']['utc']; - - - $counter = 0; - do { - $oggpageinfo = $this->ParseOggPageHeader(); - $info['ogg']['pageheader'][$oggpageinfo['page_seqno'].'.'.$counter++] = $oggpageinfo; - $filedata = $this->fread($oggpageinfo['page_length']); - $this->fseek($oggpageinfo['page_end_offset']); - - if (substr($filedata, 0, 8) == "fisbone\x00") { - - $filedataoffset = 8; - $info['ogg']['skeleton']['fisbone']['raw']['message_header_offset'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['skeleton']['fisbone']['raw']['serial_number'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['skeleton']['fisbone']['raw']['number_header_packets'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['skeleton']['fisbone']['raw']['granulerate_numerator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); - $filedataoffset += 8; - $info['ogg']['skeleton']['fisbone']['raw']['granulerate_denominator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); - $filedataoffset += 8; - $info['ogg']['skeleton']['fisbone']['raw']['basegranule'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); - $filedataoffset += 8; - $info['ogg']['skeleton']['fisbone']['raw']['preroll'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['skeleton']['fisbone']['raw']['granuleshift'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $info['ogg']['skeleton']['fisbone']['raw']['padding'] = substr($filedata, $filedataoffset, 3); - $filedataoffset += 3; - - } elseif (substr($filedata, 1, 6) == 'theora') { - - $info['video']['dataformat'] = 'theora1'; - $this->error('Ogg Theora (v1) not correctly handled in this version of getID3 ['.$this->getid3->version().']'); - //break; - - } elseif (substr($filedata, 1, 6) == 'vorbis') { - - $this->ParseVorbisPageHeader($filedata, $filedataoffset, $oggpageinfo); - - } else { - $this->error('unexpected'); - //break; - } - //} while ($oggpageinfo['page_seqno'] == 0); - } while (($oggpageinfo['page_seqno'] == 0) && (substr($filedata, 0, 8) != "fisbone\x00")); - - $this->fseek($oggpageinfo['page_start_offset']); - - $this->error('Ogg Skeleton not correctly handled in this version of getID3 ['.$this->getid3->version().']'); - //return false; - - } else { - - $this->error('Expecting either "Speex ", "OpusHead" or "vorbis" identifier strings, found "'.substr($filedata, 0, 8).'"'); - unset($info['ogg']); - unset($info['mime_type']); - return false; - - } - - // Page 2 - Comment Header - $oggpageinfo = $this->ParseOggPageHeader(); - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; - - switch ($info['audio']['dataformat']) { - case 'vorbis': - $filedata = $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']); - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['packet_type'] = getid3_lib::LittleEndian2Int(substr($filedata, 0, 1)); - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, 1, 6); // hard-coded to 'vorbis' - - $this->ParseVorbisComments(); - break; - - case 'flac': - $flac = new getid3_flac($this->getid3); - if (!$flac->parseMETAdata()) { - $this->error('Failed to parse FLAC headers'); - return false; - } - unset($flac); - break; - - case 'speex': - $this->fseek($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length'], SEEK_CUR); - $this->ParseVorbisComments(); - break; - - case 'opus': - $filedata = $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']); - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, 0, 8); // hard-coded to 'OpusTags' - if(substr($filedata, 0, 8) != 'OpusTags') { - $this->error('Expected "OpusTags" as header but got "'.substr($filedata, 0, 8).'"'); - return false; - } - - $this->ParseVorbisComments(); - break; - - } - - // Last Page - Number of Samples - if (!getid3_lib::intValueSupported($info['avdataend'])) { - - $this->warning('Unable to parse Ogg end chunk file (PHP does not support file operations beyond '.round(PHP_INT_MAX / 1073741824).'GB)'); - - } else { - - $this->fseek(max($info['avdataend'] - $this->getid3->fread_buffer_size(), 0)); - $LastChunkOfOgg = strrev($this->fread($this->getid3->fread_buffer_size())); - if ($LastOggSpostion = strpos($LastChunkOfOgg, 'SggO')) { - $this->fseek($info['avdataend'] - ($LastOggSpostion + strlen('SggO'))); - $info['avdataend'] = $this->ftell(); - $info['ogg']['pageheader']['eos'] = $this->ParseOggPageHeader(); - $info['ogg']['samples'] = $info['ogg']['pageheader']['eos']['pcm_abs_position']; - if ($info['ogg']['samples'] == 0) { - $this->error('Corrupt Ogg file: eos.number of samples == zero'); - return false; - } - if (!empty($info['audio']['sample_rate'])) { - $info['ogg']['bitrate_average'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / ($info['ogg']['samples'] / $info['audio']['sample_rate']); - } - } - - } - - if (!empty($info['ogg']['bitrate_average'])) { - $info['audio']['bitrate'] = $info['ogg']['bitrate_average']; - } elseif (!empty($info['ogg']['bitrate_nominal'])) { - $info['audio']['bitrate'] = $info['ogg']['bitrate_nominal']; - } elseif (!empty($info['ogg']['bitrate_min']) && !empty($info['ogg']['bitrate_max'])) { - $info['audio']['bitrate'] = ($info['ogg']['bitrate_min'] + $info['ogg']['bitrate_max']) / 2; - } - if (isset($info['audio']['bitrate']) && !isset($info['playtime_seconds'])) { - if ($info['audio']['bitrate'] == 0) { - $this->error('Corrupt Ogg file: bitrate_audio == zero'); - return false; - } - $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $info['audio']['bitrate']); - } - - if (isset($info['ogg']['vendor'])) { - $info['audio']['encoder'] = preg_replace('/^Encoded with /', '', $info['ogg']['vendor']); - - // Vorbis only - if ($info['audio']['dataformat'] == 'vorbis') { - - // Vorbis 1.0 starts with Xiph.Org - if (preg_match('/^Xiph.Org/', $info['audio']['encoder'])) { - - if ($info['audio']['bitrate_mode'] == 'abr') { - - // Set -b 128 on abr files - $info['audio']['encoder_options'] = '-b '.round($info['ogg']['bitrate_nominal'] / 1000); - - } elseif (($info['audio']['bitrate_mode'] == 'vbr') && ($info['audio']['channels'] == 2) && ($info['audio']['sample_rate'] >= 44100) && ($info['audio']['sample_rate'] <= 48000)) { - // Set -q N on vbr files - $info['audio']['encoder_options'] = '-q '.$this->get_quality_from_nominal_bitrate($info['ogg']['bitrate_nominal']); - - } - } - - if (empty($info['audio']['encoder_options']) && !empty($info['ogg']['bitrate_nominal'])) { - $info['audio']['encoder_options'] = 'Nominal bitrate: '.intval(round($info['ogg']['bitrate_nominal'] / 1000)).'kbps'; - } - } - } - - return true; - } - - public function ParseVorbisPageHeader(&$filedata, &$filedataoffset, &$oggpageinfo) { - $info = &$this->getid3->info; - $info['audio']['dataformat'] = 'vorbis'; - $info['audio']['lossless'] = false; - - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['packet_type'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, $filedataoffset, 6); // hard-coded to 'vorbis' - $filedataoffset += 6; - $info['ogg']['bitstreamversion'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['numberofchannels'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $info['audio']['channels'] = $info['ogg']['numberofchannels']; - $info['ogg']['samplerate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - if ($info['ogg']['samplerate'] == 0) { - $this->error('Corrupt Ogg file: sample rate == zero'); - return false; - } - $info['audio']['sample_rate'] = $info['ogg']['samplerate']; - $info['ogg']['samples'] = 0; // filled in later - $info['ogg']['bitrate_average'] = 0; // filled in later - $info['ogg']['bitrate_max'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['bitrate_nominal'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['bitrate_min'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $info['ogg']['blocksize_small'] = pow(2, getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)) & 0x0F); - $info['ogg']['blocksize_large'] = pow(2, (getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)) & 0xF0) >> 4); - $info['ogg']['stop_bit'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); // must be 1, marks end of packet - - $info['audio']['bitrate_mode'] = 'vbr'; // overridden if actually abr - if ($info['ogg']['bitrate_max'] == 0xFFFFFFFF) { - unset($info['ogg']['bitrate_max']); - $info['audio']['bitrate_mode'] = 'abr'; - } - if ($info['ogg']['bitrate_nominal'] == 0xFFFFFFFF) { - unset($info['ogg']['bitrate_nominal']); - } - if ($info['ogg']['bitrate_min'] == 0xFFFFFFFF) { - unset($info['ogg']['bitrate_min']); - $info['audio']['bitrate_mode'] = 'abr'; - } - return true; - } - - // http://tools.ietf.org/html/draft-ietf-codec-oggopus-03 - public function ParseOpusPageHeader(&$filedata, &$filedataoffset, &$oggpageinfo) { - $info = &$this->getid3->info; - $info['audio']['dataformat'] = 'opus'; - $info['mime_type'] = 'audio/ogg; codecs=opus'; - - /** @todo find a usable way to detect abr (vbr that is padded to be abr) */ - $info['audio']['bitrate_mode'] = 'vbr'; - - $info['audio']['lossless'] = false; - - $info['ogg']['pageheader']['opus']['opus_magic'] = substr($filedata, $filedataoffset, 8); // hard-coded to 'OpusHead' - $filedataoffset += 8; - $info['ogg']['pageheader']['opus']['version'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - - if ($info['ogg']['pageheader']['opus']['version'] < 1 || $info['ogg']['pageheader']['opus']['version'] > 15) { - $this->error('Unknown opus version number (only accepting 1-15)'); - return false; - } - - $info['ogg']['pageheader']['opus']['out_channel_count'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - - if ($info['ogg']['pageheader']['opus']['out_channel_count'] == 0) { - $this->error('Invalid channel count in opus header (must not be zero)'); - return false; - } - - $info['ogg']['pageheader']['opus']['pre_skip'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2)); - $filedataoffset += 2; - - $info['ogg']['pageheader']['opus']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - - //$info['ogg']['pageheader']['opus']['output_gain'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2)); - //$filedataoffset += 2; - - //$info['ogg']['pageheader']['opus']['channel_mapping_family'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - //$filedataoffset += 1; - - $info['opus']['opus_version'] = $info['ogg']['pageheader']['opus']['version']; - $info['opus']['sample_rate'] = $info['ogg']['pageheader']['opus']['sample_rate']; - $info['opus']['out_channel_count'] = $info['ogg']['pageheader']['opus']['out_channel_count']; - - $info['audio']['channels'] = $info['opus']['out_channel_count']; - $info['audio']['sample_rate'] = $info['opus']['sample_rate']; - return true; - } - - - public function ParseOggPageHeader() { - // http://xiph.org/ogg/vorbis/doc/framing.html - $oggheader['page_start_offset'] = $this->ftell(); // where we started from in the file - - $filedata = $this->fread($this->getid3->fread_buffer_size()); - $filedataoffset = 0; - while ((substr($filedata, $filedataoffset++, 4) != 'OggS')) { - if (($this->ftell() - $oggheader['page_start_offset']) >= $this->getid3->fread_buffer_size()) { - // should be found before here - return false; - } - if ((($filedataoffset + 28) > strlen($filedata)) || (strlen($filedata) < 28)) { - if ($this->feof() || (($filedata .= $this->fread($this->getid3->fread_buffer_size())) === false)) { - // get some more data, unless eof, in which case fail - return false; - } - } - } - $filedataoffset += strlen('OggS') - 1; // page, delimited by 'OggS' - - $oggheader['stream_structver'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $oggheader['flags_raw'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $oggheader['flags']['fresh'] = (bool) ($oggheader['flags_raw'] & 0x01); // fresh packet - $oggheader['flags']['bos'] = (bool) ($oggheader['flags_raw'] & 0x02); // first page of logical bitstream (bos) - $oggheader['flags']['eos'] = (bool) ($oggheader['flags_raw'] & 0x04); // last page of logical bitstream (eos) - - $oggheader['pcm_abs_position'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); - $filedataoffset += 8; - $oggheader['stream_serialno'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $oggheader['page_seqno'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $oggheader['page_checksum'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $oggheader['page_segments'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $oggheader['page_length'] = 0; - for ($i = 0; $i < $oggheader['page_segments']; $i++) { - $oggheader['segment_table'][$i] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $oggheader['page_length'] += $oggheader['segment_table'][$i]; - } - $oggheader['header_end_offset'] = $oggheader['page_start_offset'] + $filedataoffset; - $oggheader['page_end_offset'] = $oggheader['header_end_offset'] + $oggheader['page_length']; - $this->fseek($oggheader['header_end_offset']); - - return $oggheader; - } + // http://xiph.org/vorbis/doc/Vorbis_I_spec.html + public function Analyze() + { + $info = &$this->getid3->info; + + $info['fileformat'] = 'ogg'; + + // Warn about illegal tags - only vorbiscomments are allowed + if (isset($info['id3v2'])) { + $this->warning('Illegal ID3v2 tag present.'); + } + if (isset($info['id3v1'])) { + $this->warning('Illegal ID3v1 tag present.'); + } + if (isset($info['ape'])) { + $this->warning('Illegal APE tag present.'); + } + + // Page 1 - Stream Header + + $this->fseek($info['avdataoffset']); + + $oggpageinfo = $this->ParseOggPageHeader(); + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; + + if ($this->ftell() >= $this->getid3->fread_buffer_size()) { + $this->error('Could not find start of Ogg page in the first '.$this->getid3->fread_buffer_size().' bytes (this might not be an Ogg-Vorbis file?)'); + unset($info['fileformat']); + unset($info['ogg']); + + return false; + } + + $filedata = $this->fread($oggpageinfo['page_length']); + $filedataoffset = 0; + + if (substr($filedata, 0, 4) == 'fLaC') { + $info['audio']['dataformat'] = 'flac'; + $info['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['lossless'] = true; + } elseif (substr($filedata, 1, 6) == 'vorbis') { + $this->ParseVorbisPageHeader($filedata, $filedataoffset, $oggpageinfo); + } elseif (substr($filedata, 0, 8) == 'OpusHead') { + if ($this->ParseOpusPageHeader($filedata, $filedataoffset, $oggpageinfo) == false) { + return false; + } + } elseif (substr($filedata, 0, 8) == 'Speex ') { + + // http://www.speex.org/manual/node10.html + + $info['audio']['dataformat'] = 'speex'; + $info['mime_type'] = 'audio/speex'; + $info['audio']['bitrate_mode'] = 'abr'; + $info['audio']['lossless'] = false; + + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_string'] = substr($filedata, $filedataoffset, 8); // hard-coded to 'Speex ' + $filedataoffset += 8; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version'] = substr($filedata, $filedataoffset, 20); + $filedataoffset += 20; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version_id'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['header_size'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['rate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode_bitstream_version'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['nb_channels'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['bitrate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['framesize'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['vbr'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['frames_per_packet'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['extra_headers'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['reserved1'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['reserved2'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + + $info['speex']['speex_version'] = trim($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version']); + $info['speex']['sample_rate'] = $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['rate']; + $info['speex']['channels'] = $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['nb_channels']; + $info['speex']['vbr'] = (bool) $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['vbr']; + $info['speex']['band_type'] = $this->SpeexBandModeLookup($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode']); + + $info['audio']['sample_rate'] = $info['speex']['sample_rate']; + $info['audio']['channels'] = $info['speex']['channels']; + if ($info['speex']['vbr']) { + $info['audio']['bitrate_mode'] = 'vbr'; + } + } elseif (substr($filedata, 0, 7) == "\x80".'theora') { + + // http://www.theora.org/doc/Theora.pdf (section 6.2) + + $info['ogg']['pageheader']['theora']['theora_magic'] = substr($filedata, $filedataoffset, 7); // hard-coded to "\x80.'theora' + $filedataoffset += 7; + $info['ogg']['pageheader']['theora']['version_major'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['pageheader']['theora']['version_minor'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['pageheader']['theora']['version_revision'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['pageheader']['theora']['frame_width_macroblocks'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 2)); + $filedataoffset += 2; + $info['ogg']['pageheader']['theora']['frame_height_macroblocks'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 2)); + $filedataoffset += 2; + $info['ogg']['pageheader']['theora']['resolution_x'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3)); + $filedataoffset += 3; + $info['ogg']['pageheader']['theora']['resolution_y'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3)); + $filedataoffset += 3; + $info['ogg']['pageheader']['theora']['picture_offset_x'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['pageheader']['theora']['picture_offset_y'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['pageheader']['theora']['frame_rate_numerator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader']['theora']['frame_rate_denominator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader']['theora']['pixel_aspect_numerator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3)); + $filedataoffset += 3; + $info['ogg']['pageheader']['theora']['pixel_aspect_denominator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3)); + $filedataoffset += 3; + $info['ogg']['pageheader']['theora']['color_space_id'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['pageheader']['theora']['nominal_bitrate'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3)); + $filedataoffset += 3; + $info['ogg']['pageheader']['theora']['flags'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 2)); + $filedataoffset += 2; + + $info['ogg']['pageheader']['theora']['quality'] = ($info['ogg']['pageheader']['theora']['flags'] & 0xFC00) >> 10; + $info['ogg']['pageheader']['theora']['kfg_shift'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x03E0) >> 5; + $info['ogg']['pageheader']['theora']['pixel_format_id'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x0018) >> 3; + $info['ogg']['pageheader']['theora']['reserved'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x0007) >> 0; // should be 0 + $info['ogg']['pageheader']['theora']['color_space'] = self::TheoraColorSpace($info['ogg']['pageheader']['theora']['color_space_id']); + $info['ogg']['pageheader']['theora']['pixel_format'] = self::TheoraPixelFormat($info['ogg']['pageheader']['theora']['pixel_format_id']); + + $info['video']['dataformat'] = 'theora'; + $info['mime_type'] = 'video/ogg'; + //$info['audio']['bitrate_mode'] = 'abr'; + //$info['audio']['lossless'] = false; + $info['video']['resolution_x'] = $info['ogg']['pageheader']['theora']['resolution_x']; + $info['video']['resolution_y'] = $info['ogg']['pageheader']['theora']['resolution_y']; + if ($info['ogg']['pageheader']['theora']['frame_rate_denominator'] > 0) { + $info['video']['frame_rate'] = (float) $info['ogg']['pageheader']['theora']['frame_rate_numerator'] / $info['ogg']['pageheader']['theora']['frame_rate_denominator']; + } + if ($info['ogg']['pageheader']['theora']['pixel_aspect_denominator'] > 0) { + $info['video']['pixel_aspect_ratio'] = (float) $info['ogg']['pageheader']['theora']['pixel_aspect_numerator'] / $info['ogg']['pageheader']['theora']['pixel_aspect_denominator']; + } + $this->warning('Ogg Theora (v3) not fully supported in this version of getID3 ['.$this->getid3->version().'] -- bitrate, playtime and all audio data are currently unavailable'); + } elseif (substr($filedata, 0, 8) == "fishead\x00") { + + // Ogg Skeleton version 3.0 Format Specification + // http://xiph.org/ogg/doc/skeleton.html + $filedataoffset += 8; + $info['ogg']['skeleton']['fishead']['raw']['version_major'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2)); + $filedataoffset += 2; + $info['ogg']['skeleton']['fishead']['raw']['version_minor'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2)); + $filedataoffset += 2; + $info['ogg']['skeleton']['fishead']['raw']['presentationtime_numerator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $info['ogg']['skeleton']['fishead']['raw']['presentationtime_denominator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $info['ogg']['skeleton']['fishead']['raw']['basetime_numerator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $info['ogg']['skeleton']['fishead']['raw']['basetime_denominator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $info['ogg']['skeleton']['fishead']['raw']['utc'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 20)); + $filedataoffset += 20; + + $info['ogg']['skeleton']['fishead']['version'] = $info['ogg']['skeleton']['fishead']['raw']['version_major'].'.'.$info['ogg']['skeleton']['fishead']['raw']['version_minor']; + $info['ogg']['skeleton']['fishead']['presentationtime'] = $info['ogg']['skeleton']['fishead']['raw']['presentationtime_numerator'] / $info['ogg']['skeleton']['fishead']['raw']['presentationtime_denominator']; + $info['ogg']['skeleton']['fishead']['basetime'] = $info['ogg']['skeleton']['fishead']['raw']['basetime_numerator'] / $info['ogg']['skeleton']['fishead']['raw']['basetime_denominator']; + $info['ogg']['skeleton']['fishead']['utc'] = $info['ogg']['skeleton']['fishead']['raw']['utc']; + + $counter = 0; + do { + $oggpageinfo = $this->ParseOggPageHeader(); + $info['ogg']['pageheader'][$oggpageinfo['page_seqno'].'.'.$counter++] = $oggpageinfo; + $filedata = $this->fread($oggpageinfo['page_length']); + $this->fseek($oggpageinfo['page_end_offset']); + + if (substr($filedata, 0, 8) == "fisbone\x00") { + $filedataoffset = 8; + $info['ogg']['skeleton']['fisbone']['raw']['message_header_offset'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['skeleton']['fisbone']['raw']['serial_number'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['skeleton']['fisbone']['raw']['number_header_packets'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['skeleton']['fisbone']['raw']['granulerate_numerator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $info['ogg']['skeleton']['fisbone']['raw']['granulerate_denominator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $info['ogg']['skeleton']['fisbone']['raw']['basegranule'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $info['ogg']['skeleton']['fisbone']['raw']['preroll'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['skeleton']['fisbone']['raw']['granuleshift'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['skeleton']['fisbone']['raw']['padding'] = substr($filedata, $filedataoffset, 3); + $filedataoffset += 3; + } elseif (substr($filedata, 1, 6) == 'theora') { + $info['video']['dataformat'] = 'theora1'; + $this->error('Ogg Theora (v1) not correctly handled in this version of getID3 ['.$this->getid3->version().']'); + //break; + } elseif (substr($filedata, 1, 6) == 'vorbis') { + $this->ParseVorbisPageHeader($filedata, $filedataoffset, $oggpageinfo); + } else { + $this->error('unexpected'); + //break; + } + //} while ($oggpageinfo['page_seqno'] == 0); + } while (($oggpageinfo['page_seqno'] == 0) && (substr($filedata, 0, 8) != "fisbone\x00")); + + $this->fseek($oggpageinfo['page_start_offset']); + + $this->error('Ogg Skeleton not correctly handled in this version of getID3 ['.$this->getid3->version().']'); + //return false; + } else { + $this->error('Expecting either "Speex ", "OpusHead" or "vorbis" identifier strings, found "'.substr($filedata, 0, 8).'"'); + unset($info['ogg']); + unset($info['mime_type']); + + return false; + } + + // Page 2 - Comment Header + $oggpageinfo = $this->ParseOggPageHeader(); + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; + + switch ($info['audio']['dataformat']) { + case 'vorbis': + $filedata = $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']); + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['packet_type'] = getid3_lib::LittleEndian2Int(substr($filedata, 0, 1)); + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, 1, 6); // hard-coded to 'vorbis' + + $this->ParseVorbisComments(); + break; + + case 'flac': + $flac = new getid3_flac($this->getid3); + if (! $flac->parseMETAdata()) { + $this->error('Failed to parse FLAC headers'); + + return false; + } + unset($flac); + break; + + case 'speex': + $this->fseek($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length'], SEEK_CUR); + $this->ParseVorbisComments(); + break; + + case 'opus': + $filedata = $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']); + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, 0, 8); // hard-coded to 'OpusTags' + if (substr($filedata, 0, 8) != 'OpusTags') { + $this->error('Expected "OpusTags" as header but got "'.substr($filedata, 0, 8).'"'); + + return false; + } + + $this->ParseVorbisComments(); + break; + + } + + // Last Page - Number of Samples + if (! getid3_lib::intValueSupported($info['avdataend'])) { + $this->warning('Unable to parse Ogg end chunk file (PHP does not support file operations beyond '.round(PHP_INT_MAX / 1073741824).'GB)'); + } else { + $this->fseek(max($info['avdataend'] - $this->getid3->fread_buffer_size(), 0)); + $LastChunkOfOgg = strrev($this->fread($this->getid3->fread_buffer_size())); + if ($LastOggSpostion = strpos($LastChunkOfOgg, 'SggO')) { + $this->fseek($info['avdataend'] - ($LastOggSpostion + strlen('SggO'))); + $info['avdataend'] = $this->ftell(); + $info['ogg']['pageheader']['eos'] = $this->ParseOggPageHeader(); + $info['ogg']['samples'] = $info['ogg']['pageheader']['eos']['pcm_abs_position']; + if ($info['ogg']['samples'] == 0) { + $this->error('Corrupt Ogg file: eos.number of samples == zero'); + + return false; + } + if (! empty($info['audio']['sample_rate'])) { + $info['ogg']['bitrate_average'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / ($info['ogg']['samples'] / $info['audio']['sample_rate']); + } + } + } + + if (! empty($info['ogg']['bitrate_average'])) { + $info['audio']['bitrate'] = $info['ogg']['bitrate_average']; + } elseif (! empty($info['ogg']['bitrate_nominal'])) { + $info['audio']['bitrate'] = $info['ogg']['bitrate_nominal']; + } elseif (! empty($info['ogg']['bitrate_min']) && ! empty($info['ogg']['bitrate_max'])) { + $info['audio']['bitrate'] = ($info['ogg']['bitrate_min'] + $info['ogg']['bitrate_max']) / 2; + } + if (isset($info['audio']['bitrate']) && ! isset($info['playtime_seconds'])) { + if ($info['audio']['bitrate'] == 0) { + $this->error('Corrupt Ogg file: bitrate_audio == zero'); + + return false; + } + $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $info['audio']['bitrate']); + } + + if (isset($info['ogg']['vendor'])) { + $info['audio']['encoder'] = preg_replace('/^Encoded with /', '', $info['ogg']['vendor']); + + // Vorbis only + if ($info['audio']['dataformat'] == 'vorbis') { + + // Vorbis 1.0 starts with Xiph.Org + if (preg_match('/^Xiph.Org/', $info['audio']['encoder'])) { + if ($info['audio']['bitrate_mode'] == 'abr') { + + // Set -b 128 on abr files + $info['audio']['encoder_options'] = '-b '.round($info['ogg']['bitrate_nominal'] / 1000); + } elseif (($info['audio']['bitrate_mode'] == 'vbr') && ($info['audio']['channels'] == 2) && ($info['audio']['sample_rate'] >= 44100) && ($info['audio']['sample_rate'] <= 48000)) { + // Set -q N on vbr files + $info['audio']['encoder_options'] = '-q '.$this->get_quality_from_nominal_bitrate($info['ogg']['bitrate_nominal']); + } + } + + if (empty($info['audio']['encoder_options']) && ! empty($info['ogg']['bitrate_nominal'])) { + $info['audio']['encoder_options'] = 'Nominal bitrate: '.intval(round($info['ogg']['bitrate_nominal'] / 1000)).'kbps'; + } + } + } + + return true; + } + + public function ParseVorbisPageHeader(&$filedata, &$filedataoffset, &$oggpageinfo) + { + $info = &$this->getid3->info; + $info['audio']['dataformat'] = 'vorbis'; + $info['audio']['lossless'] = false; + + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['packet_type'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, $filedataoffset, 6); // hard-coded to 'vorbis' + $filedataoffset += 6; + $info['ogg']['bitstreamversion'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['numberofchannels'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['audio']['channels'] = $info['ogg']['numberofchannels']; + $info['ogg']['samplerate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + if ($info['ogg']['samplerate'] == 0) { + $this->error('Corrupt Ogg file: sample rate == zero'); + + return false; + } + $info['audio']['sample_rate'] = $info['ogg']['samplerate']; + $info['ogg']['samples'] = 0; // filled in later + $info['ogg']['bitrate_average'] = 0; // filled in later + $info['ogg']['bitrate_max'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['bitrate_nominal'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['bitrate_min'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['blocksize_small'] = pow(2, getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)) & 0x0F); + $info['ogg']['blocksize_large'] = pow(2, (getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)) & 0xF0) >> 4); + $info['ogg']['stop_bit'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); // must be 1, marks end of packet + + $info['audio']['bitrate_mode'] = 'vbr'; // overridden if actually abr + if ($info['ogg']['bitrate_max'] == 0xFFFFFFFF) { + unset($info['ogg']['bitrate_max']); + $info['audio']['bitrate_mode'] = 'abr'; + } + if ($info['ogg']['bitrate_nominal'] == 0xFFFFFFFF) { + unset($info['ogg']['bitrate_nominal']); + } + if ($info['ogg']['bitrate_min'] == 0xFFFFFFFF) { + unset($info['ogg']['bitrate_min']); + $info['audio']['bitrate_mode'] = 'abr'; + } + + return true; + } + + // http://tools.ietf.org/html/draft-ietf-codec-oggopus-03 + public function ParseOpusPageHeader(&$filedata, &$filedataoffset, &$oggpageinfo) + { + $info = &$this->getid3->info; + $info['audio']['dataformat'] = 'opus'; + $info['mime_type'] = 'audio/ogg; codecs=opus'; + + /** @todo find a usable way to detect abr (vbr that is padded to be abr) */ + $info['audio']['bitrate_mode'] = 'vbr'; + + $info['audio']['lossless'] = false; + + $info['ogg']['pageheader']['opus']['opus_magic'] = substr($filedata, $filedataoffset, 8); // hard-coded to 'OpusHead' + $filedataoffset += 8; + $info['ogg']['pageheader']['opus']['version'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + + if ($info['ogg']['pageheader']['opus']['version'] < 1 || $info['ogg']['pageheader']['opus']['version'] > 15) { + $this->error('Unknown opus version number (only accepting 1-15)'); + + return false; + } + + $info['ogg']['pageheader']['opus']['out_channel_count'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + + if ($info['ogg']['pageheader']['opus']['out_channel_count'] == 0) { + $this->error('Invalid channel count in opus header (must not be zero)'); + + return false; + } + + $info['ogg']['pageheader']['opus']['pre_skip'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2)); + $filedataoffset += 2; + + $info['ogg']['pageheader']['opus']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + + //$info['ogg']['pageheader']['opus']['output_gain'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2)); + //$filedataoffset += 2; + + //$info['ogg']['pageheader']['opus']['channel_mapping_family'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + //$filedataoffset += 1; + + $info['opus']['opus_version'] = $info['ogg']['pageheader']['opus']['version']; + $info['opus']['sample_rate'] = $info['ogg']['pageheader']['opus']['sample_rate']; + $info['opus']['out_channel_count'] = $info['ogg']['pageheader']['opus']['out_channel_count']; + + $info['audio']['channels'] = $info['opus']['out_channel_count']; + $info['audio']['sample_rate'] = $info['opus']['sample_rate']; + + return true; + } + + public function ParseOggPageHeader() + { + // http://xiph.org/ogg/vorbis/doc/framing.html + $oggheader['page_start_offset'] = $this->ftell(); // where we started from in the file + + $filedata = $this->fread($this->getid3->fread_buffer_size()); + $filedataoffset = 0; + while ((substr($filedata, $filedataoffset++, 4) != 'OggS')) { + if (($this->ftell() - $oggheader['page_start_offset']) >= $this->getid3->fread_buffer_size()) { + // should be found before here + return false; + } + if ((($filedataoffset + 28) > strlen($filedata)) || (strlen($filedata) < 28)) { + if ($this->feof() || (($filedata .= $this->fread($this->getid3->fread_buffer_size())) === false)) { + // get some more data, unless eof, in which case fail + return false; + } + } + } + $filedataoffset += strlen('OggS') - 1; // page, delimited by 'OggS' + + $oggheader['stream_structver'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $oggheader['flags_raw'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $oggheader['flags']['fresh'] = (bool) ($oggheader['flags_raw'] & 0x01); // fresh packet + $oggheader['flags']['bos'] = (bool) ($oggheader['flags_raw'] & 0x02); // first page of logical bitstream (bos) + $oggheader['flags']['eos'] = (bool) ($oggheader['flags_raw'] & 0x04); // last page of logical bitstream (eos) + + $oggheader['pcm_abs_position'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $oggheader['stream_serialno'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $oggheader['page_seqno'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $oggheader['page_checksum'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $oggheader['page_segments'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $oggheader['page_length'] = 0; + for ($i = 0; $i < $oggheader['page_segments']; $i++) { + $oggheader['segment_table'][$i] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $oggheader['page_length'] += $oggheader['segment_table'][$i]; + } + $oggheader['header_end_offset'] = $oggheader['page_start_offset'] + $filedataoffset; + $oggheader['page_end_offset'] = $oggheader['header_end_offset'] + $oggheader['page_length']; + $this->fseek($oggheader['header_end_offset']); + + return $oggheader; + } // http://xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-810005 - public function ParseVorbisComments() { - $info = &$this->getid3->info; + public function ParseVorbisComments() + { + $info = &$this->getid3->info; - $OriginalOffset = $this->ftell(); - $commentdataoffset = 0; - $VorbisCommentPage = 1; + $OriginalOffset = $this->ftell(); + $commentdataoffset = 0; + $VorbisCommentPage = 1; - switch ($info['audio']['dataformat']) { - case 'vorbis': - case 'speex': - case 'opus': - $CommentStartOffset = $info['ogg']['pageheader'][$VorbisCommentPage]['page_start_offset']; // Second Ogg page, after header block - $this->fseek($CommentStartOffset); - $commentdataoffset = 27 + $info['ogg']['pageheader'][$VorbisCommentPage]['page_segments']; - $commentdata = $this->fread(self::OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1) + $commentdataoffset); + switch ($info['audio']['dataformat']) { + case 'vorbis': + case 'speex': + case 'opus': + $CommentStartOffset = $info['ogg']['pageheader'][$VorbisCommentPage]['page_start_offset']; // Second Ogg page, after header block + $this->fseek($CommentStartOffset); + $commentdataoffset = 27 + $info['ogg']['pageheader'][$VorbisCommentPage]['page_segments']; + $commentdata = $this->fread(self::OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1) + $commentdataoffset); - if ($info['audio']['dataformat'] == 'vorbis') { - $commentdataoffset += (strlen('vorbis') + 1); - } - else if ($info['audio']['dataformat'] == 'opus') { - $commentdataoffset += strlen('OpusTags'); - } + if ($info['audio']['dataformat'] == 'vorbis') { + $commentdataoffset += (strlen('vorbis') + 1); + } elseif ($info['audio']['dataformat'] == 'opus') { + $commentdataoffset += strlen('OpusTags'); + } - break; + break; - case 'flac': - $CommentStartOffset = $info['flac']['VORBIS_COMMENT']['raw']['offset'] + 4; - $this->fseek($CommentStartOffset); - $commentdata = $this->fread($info['flac']['VORBIS_COMMENT']['raw']['block_length']); - break; + case 'flac': + $CommentStartOffset = $info['flac']['VORBIS_COMMENT']['raw']['offset'] + 4; + $this->fseek($CommentStartOffset); + $commentdata = $this->fread($info['flac']['VORBIS_COMMENT']['raw']['block_length']); + break; - default: - return false; - break; - } + default: + return false; + break; + } - $VendorSize = getid3_lib::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4)); - $commentdataoffset += 4; + $VendorSize = getid3_lib::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4)); + $commentdataoffset += 4; - $info['ogg']['vendor'] = substr($commentdata, $commentdataoffset, $VendorSize); - $commentdataoffset += $VendorSize; + $info['ogg']['vendor'] = substr($commentdata, $commentdataoffset, $VendorSize); + $commentdataoffset += $VendorSize; - $CommentsCount = getid3_lib::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4)); - $commentdataoffset += 4; - $info['avdataoffset'] = $CommentStartOffset + $commentdataoffset; + $CommentsCount = getid3_lib::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4)); + $commentdataoffset += 4; + $info['avdataoffset'] = $CommentStartOffset + $commentdataoffset; - $basicfields = array('TITLE', 'ARTIST', 'ALBUM', 'TRACKNUMBER', 'GENRE', 'DATE', 'DESCRIPTION', 'COMMENT'); - $ThisFileInfo_ogg_comments_raw = &$info['ogg']['comments_raw']; - for ($i = 0; $i < $CommentsCount; $i++) { + $basicfields = ['TITLE', 'ARTIST', 'ALBUM', 'TRACKNUMBER', 'GENRE', 'DATE', 'DESCRIPTION', 'COMMENT']; + $ThisFileInfo_ogg_comments_raw = &$info['ogg']['comments_raw']; + for ($i = 0; $i < $CommentsCount; $i++) { + if ($i >= 10000) { + // https://github.com/owncloud/music/issues/212#issuecomment-43082336 + $this->warning('Unexpectedly large number ('.$CommentsCount.') of Ogg comments - breaking after reading '.$i.' comments'); + break; + } - if ($i >= 10000) { - // https://github.com/owncloud/music/issues/212#issuecomment-43082336 - $this->warning('Unexpectedly large number ('.$CommentsCount.') of Ogg comments - breaking after reading '.$i.' comments'); - break; - } + $ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] = $CommentStartOffset + $commentdataoffset; - $ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] = $CommentStartOffset + $commentdataoffset; + if ($this->ftell() < ($ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] + 4)) { + if ($oggpageinfo = $this->ParseOggPageHeader()) { + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; - if ($this->ftell() < ($ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] + 4)) { - if ($oggpageinfo = $this->ParseOggPageHeader()) { - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; + $VorbisCommentPage++; - $VorbisCommentPage++; + // First, save what we haven't read yet + $AsYetUnusedData = substr($commentdata, $commentdataoffset); - // First, save what we haven't read yet - $AsYetUnusedData = substr($commentdata, $commentdataoffset); + // Then take that data off the end + $commentdata = substr($commentdata, 0, $commentdataoffset); - // Then take that data off the end - $commentdata = substr($commentdata, 0, $commentdataoffset); + // Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct + $commentdata .= str_repeat("\x00", 27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); + $commentdataoffset += (27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); - // Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct - $commentdata .= str_repeat("\x00", 27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); - $commentdataoffset += (27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); + // Finally, stick the unused data back on the end + $commentdata .= $AsYetUnusedData; - // Finally, stick the unused data back on the end - $commentdata .= $AsYetUnusedData; + //$commentdata .= $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']); + $commentdata .= $this->fread($this->OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1)); + } + } + $ThisFileInfo_ogg_comments_raw[$i]['size'] = getid3_lib::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4)); - //$commentdata .= $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']); - $commentdata .= $this->fread($this->OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1)); - } + // replace avdataoffset with position just after the last vorbiscomment + $info['avdataoffset'] = $ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] + $ThisFileInfo_ogg_comments_raw[$i]['size'] + 4; - } - $ThisFileInfo_ogg_comments_raw[$i]['size'] = getid3_lib::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4)); + $commentdataoffset += 4; + while ((strlen($commentdata) - $commentdataoffset) < $ThisFileInfo_ogg_comments_raw[$i]['size']) { + if (($ThisFileInfo_ogg_comments_raw[$i]['size'] > $info['avdataend']) || ($ThisFileInfo_ogg_comments_raw[$i]['size'] < 0)) { + $this->warning('Invalid Ogg comment size (comment #'.$i.', claims to be '.number_format($ThisFileInfo_ogg_comments_raw[$i]['size']).' bytes) - aborting reading comments'); + break 2; + } - // replace avdataoffset with position just after the last vorbiscomment - $info['avdataoffset'] = $ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] + $ThisFileInfo_ogg_comments_raw[$i]['size'] + 4; + $VorbisCommentPage++; - $commentdataoffset += 4; - while ((strlen($commentdata) - $commentdataoffset) < $ThisFileInfo_ogg_comments_raw[$i]['size']) { - if (($ThisFileInfo_ogg_comments_raw[$i]['size'] > $info['avdataend']) || ($ThisFileInfo_ogg_comments_raw[$i]['size'] < 0)) { - $this->warning('Invalid Ogg comment size (comment #'.$i.', claims to be '.number_format($ThisFileInfo_ogg_comments_raw[$i]['size']).' bytes) - aborting reading comments'); - break 2; - } + $oggpageinfo = $this->ParseOggPageHeader(); + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; - $VorbisCommentPage++; + // First, save what we haven't read yet + $AsYetUnusedData = substr($commentdata, $commentdataoffset); - $oggpageinfo = $this->ParseOggPageHeader(); - $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; + // Then take that data off the end + $commentdata = substr($commentdata, 0, $commentdataoffset); - // First, save what we haven't read yet - $AsYetUnusedData = substr($commentdata, $commentdataoffset); + // Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct + $commentdata .= str_repeat("\x00", 27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); + $commentdataoffset += (27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); - // Then take that data off the end - $commentdata = substr($commentdata, 0, $commentdataoffset); + // Finally, stick the unused data back on the end + $commentdata .= $AsYetUnusedData; - // Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct - $commentdata .= str_repeat("\x00", 27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); - $commentdataoffset += (27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); + //$commentdata .= $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']); + if (! isset($info['ogg']['pageheader'][$VorbisCommentPage])) { + $this->warning('undefined Vorbis Comment page "'.$VorbisCommentPage.'" at offset '.$this->ftell()); + break; + } + $readlength = self::OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1); + if ($readlength <= 0) { + $this->warning('invalid length Vorbis Comment page "'.$VorbisCommentPage.'" at offset '.$this->ftell()); + break; + } + $commentdata .= $this->fread($readlength); - // Finally, stick the unused data back on the end - $commentdata .= $AsYetUnusedData; + //$filebaseoffset += $oggpageinfo['header_end_offset'] - $oggpageinfo['page_start_offset']; + } + $ThisFileInfo_ogg_comments_raw[$i]['offset'] = $commentdataoffset; + $commentstring = substr($commentdata, $commentdataoffset, $ThisFileInfo_ogg_comments_raw[$i]['size']); + $commentdataoffset += $ThisFileInfo_ogg_comments_raw[$i]['size']; - //$commentdata .= $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']); - if (!isset($info['ogg']['pageheader'][$VorbisCommentPage])) { - $this->warning('undefined Vorbis Comment page "'.$VorbisCommentPage.'" at offset '.$this->ftell()); - break; - } - $readlength = self::OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1); - if ($readlength <= 0) { - $this->warning('invalid length Vorbis Comment page "'.$VorbisCommentPage.'" at offset '.$this->ftell()); - break; - } - $commentdata .= $this->fread($readlength); + if (! $commentstring) { - //$filebaseoffset += $oggpageinfo['header_end_offset'] - $oggpageinfo['page_start_offset']; - } - $ThisFileInfo_ogg_comments_raw[$i]['offset'] = $commentdataoffset; - $commentstring = substr($commentdata, $commentdataoffset, $ThisFileInfo_ogg_comments_raw[$i]['size']); - $commentdataoffset += $ThisFileInfo_ogg_comments_raw[$i]['size']; + // no comment? + $this->warning('Blank Ogg comment ['.$i.']'); + } elseif (strstr($commentstring, '=')) { + $commentexploded = explode('=', $commentstring, 2); + $ThisFileInfo_ogg_comments_raw[$i]['key'] = strtoupper($commentexploded[0]); + $ThisFileInfo_ogg_comments_raw[$i]['value'] = (isset($commentexploded[1]) ? $commentexploded[1] : ''); - if (!$commentstring) { + if ($ThisFileInfo_ogg_comments_raw[$i]['key'] == 'METADATA_BLOCK_PICTURE') { - // no comment? - $this->warning('Blank Ogg comment ['.$i.']'); + // http://wiki.xiph.org/VorbisComment#METADATA_BLOCK_PICTURE + // The unencoded format is that of the FLAC picture block. The fields are stored in big endian order as in FLAC, picture data is stored according to the relevant standard. + // http://flac.sourceforge.net/format.html#metadata_block_picture + $flac = new getid3_flac($this->getid3); + $flac->setStringMode(base64_decode($ThisFileInfo_ogg_comments_raw[$i]['value'])); + $flac->parsePICTURE(); + $info['ogg']['comments']['picture'][] = $flac->getid3->info['flac']['PICTURE'][0]; + unset($flac); + } elseif ($ThisFileInfo_ogg_comments_raw[$i]['key'] == 'COVERART') { + $data = base64_decode($ThisFileInfo_ogg_comments_raw[$i]['value']); + $this->notice('Found deprecated COVERART tag, it should be replaced in honor of METADATA_BLOCK_PICTURE structure'); + /** @todo use 'coverartmime' where available */ + $imageinfo = getid3_lib::GetDataImageSize($data); + if ($imageinfo === false || ! isset($imageinfo['mime'])) { + $this->warning('COVERART vorbiscomment tag contains invalid image'); + continue; + } - } elseif (strstr($commentstring, '=')) { + $ogg = new self($this->getid3); + $ogg->setStringMode($data); + $info['ogg']['comments']['picture'][] = [ + 'image_mime' => $imageinfo['mime'], + 'datalength' => strlen($data), + 'picturetype' => 'cover art', + 'image_height' => $imageinfo['height'], + 'image_width' => $imageinfo['width'], + 'data' => $ogg->saveAttachment('coverart', 0, strlen($data), $imageinfo['mime']), + ]; + unset($ogg); + } else { + $info['ogg']['comments'][strtolower($ThisFileInfo_ogg_comments_raw[$i]['key'])][] = $ThisFileInfo_ogg_comments_raw[$i]['value']; + } + } else { + $this->warning('[known problem with CDex >= v1.40, < v1.50b7] Invalid Ogg comment name/value pair ['.$i.']: '.$commentstring); + } + unset($ThisFileInfo_ogg_comments_raw[$i]); + } + unset($ThisFileInfo_ogg_comments_raw); - $commentexploded = explode('=', $commentstring, 2); - $ThisFileInfo_ogg_comments_raw[$i]['key'] = strtoupper($commentexploded[0]); - $ThisFileInfo_ogg_comments_raw[$i]['value'] = (isset($commentexploded[1]) ? $commentexploded[1] : ''); + // Replay Gain Adjustment + // http://privatewww.essex.ac.uk/~djmrob/replaygain/ + if (isset($info['ogg']['comments']) && is_array($info['ogg']['comments'])) { + foreach ($info['ogg']['comments'] as $index => $commentvalue) { + switch ($index) { + case 'rg_audiophile': + case 'replaygain_album_gain': + $info['replay_gain']['album']['adjustment'] = (float) $commentvalue[0]; + unset($info['ogg']['comments'][$index]); + break; - if ($ThisFileInfo_ogg_comments_raw[$i]['key'] == 'METADATA_BLOCK_PICTURE') { + case 'rg_radio': + case 'replaygain_track_gain': + $info['replay_gain']['track']['adjustment'] = (float) $commentvalue[0]; + unset($info['ogg']['comments'][$index]); + break; - // http://wiki.xiph.org/VorbisComment#METADATA_BLOCK_PICTURE - // The unencoded format is that of the FLAC picture block. The fields are stored in big endian order as in FLAC, picture data is stored according to the relevant standard. - // http://flac.sourceforge.net/format.html#metadata_block_picture - $flac = new getid3_flac($this->getid3); - $flac->setStringMode(base64_decode($ThisFileInfo_ogg_comments_raw[$i]['value'])); - $flac->parsePICTURE(); - $info['ogg']['comments']['picture'][] = $flac->getid3->info['flac']['PICTURE'][0]; - unset($flac); + case 'replaygain_album_peak': + $info['replay_gain']['album']['peak'] = (float) $commentvalue[0]; + unset($info['ogg']['comments'][$index]); + break; - } elseif ($ThisFileInfo_ogg_comments_raw[$i]['key'] == 'COVERART') { + case 'rg_peak': + case 'replaygain_track_peak': + $info['replay_gain']['track']['peak'] = (float) $commentvalue[0]; + unset($info['ogg']['comments'][$index]); + break; - $data = base64_decode($ThisFileInfo_ogg_comments_raw[$i]['value']); - $this->notice('Found deprecated COVERART tag, it should be replaced in honor of METADATA_BLOCK_PICTURE structure'); - /** @todo use 'coverartmime' where available */ - $imageinfo = getid3_lib::GetDataImageSize($data); - if ($imageinfo === false || !isset($imageinfo['mime'])) { - $this->warning('COVERART vorbiscomment tag contains invalid image'); - continue; - } + case 'replaygain_reference_loudness': + $info['replay_gain']['reference_volume'] = (float) $commentvalue[0]; + unset($info['ogg']['comments'][$index]); + break; - $ogg = new self($this->getid3); - $ogg->setStringMode($data); - $info['ogg']['comments']['picture'][] = array( - 'image_mime' => $imageinfo['mime'], - 'datalength' => strlen($data), - 'picturetype' => 'cover art', - 'image_height' => $imageinfo['height'], - 'image_width' => $imageinfo['width'], - 'data' => $ogg->saveAttachment('coverart', 0, strlen($data), $imageinfo['mime']), - ); - unset($ogg); + default: + // do nothing + break; + } + } + } - } else { + $this->fseek($OriginalOffset); - $info['ogg']['comments'][strtolower($ThisFileInfo_ogg_comments_raw[$i]['key'])][] = $ThisFileInfo_ogg_comments_raw[$i]['value']; + return true; + } - } + public static function SpeexBandModeLookup($mode) + { + static $SpeexBandModeLookup = []; + if (empty($SpeexBandModeLookup)) { + $SpeexBandModeLookup[0] = 'narrow'; + $SpeexBandModeLookup[1] = 'wide'; + $SpeexBandModeLookup[2] = 'ultra-wide'; + } - } else { + return isset($SpeexBandModeLookup[$mode]) ? $SpeexBandModeLookup[$mode] : null; + } - $this->warning('[known problem with CDex >= v1.40, < v1.50b7] Invalid Ogg comment name/value pair ['.$i.']: '.$commentstring); + public static function OggPageSegmentLength($OggInfoArray, $SegmentNumber = 1) + { + for ($i = 0; $i < $SegmentNumber; $i++) { + $segmentlength = 0; + foreach ($OggInfoArray['segment_table'] as $key => $value) { + $segmentlength += $value; + if ($value < 255) { + break; + } + } + } - } - unset($ThisFileInfo_ogg_comments_raw[$i]); - } - unset($ThisFileInfo_ogg_comments_raw); + return $segmentlength; + } + public static function get_quality_from_nominal_bitrate($nominal_bitrate) + { - // Replay Gain Adjustment - // http://privatewww.essex.ac.uk/~djmrob/replaygain/ - if (isset($info['ogg']['comments']) && is_array($info['ogg']['comments'])) { - foreach ($info['ogg']['comments'] as $index => $commentvalue) { - switch ($index) { - case 'rg_audiophile': - case 'replaygain_album_gain': - $info['replay_gain']['album']['adjustment'] = (double) $commentvalue[0]; - unset($info['ogg']['comments'][$index]); - break; + // decrease precision + $nominal_bitrate = $nominal_bitrate / 1000; - case 'rg_radio': - case 'replaygain_track_gain': - $info['replay_gain']['track']['adjustment'] = (double) $commentvalue[0]; - unset($info['ogg']['comments'][$index]); - break; + if ($nominal_bitrate < 128) { + // q-1 to q4 + $qval = ($nominal_bitrate - 64) / 16; + } elseif ($nominal_bitrate < 256) { + // q4 to q8 + $qval = $nominal_bitrate / 32; + } elseif ($nominal_bitrate < 320) { + // q8 to q9 + $qval = ($nominal_bitrate + 256) / 64; + } else { + // q9 to q10 + $qval = ($nominal_bitrate + 1300) / 180; + } + //return $qval; // 5.031324 + //return intval($qval); // 5 + return round($qval, 1); // 5 or 4.9 + } - case 'replaygain_album_peak': - $info['replay_gain']['album']['peak'] = (double) $commentvalue[0]; - unset($info['ogg']['comments'][$index]); - break; + public static function TheoraColorSpace($colorspace_id) + { + // http://www.theora.org/doc/Theora.pdf (table 6.3) + static $TheoraColorSpaceLookup = []; + if (empty($TheoraColorSpaceLookup)) { + $TheoraColorSpaceLookup[0] = 'Undefined'; + $TheoraColorSpaceLookup[1] = 'Rec. 470M'; + $TheoraColorSpaceLookup[2] = 'Rec. 470BG'; + $TheoraColorSpaceLookup[3] = 'Reserved'; + } - case 'rg_peak': - case 'replaygain_track_peak': - $info['replay_gain']['track']['peak'] = (double) $commentvalue[0]; - unset($info['ogg']['comments'][$index]); - break; + return isset($TheoraColorSpaceLookup[$colorspace_id]) ? $TheoraColorSpaceLookup[$colorspace_id] : null; + } - case 'replaygain_reference_loudness': - $info['replay_gain']['reference_volume'] = (double) $commentvalue[0]; - unset($info['ogg']['comments'][$index]); - break; - - default: - // do nothing - break; - } - } - } - - $this->fseek($OriginalOffset); - - return true; - } - - public static function SpeexBandModeLookup($mode) { - static $SpeexBandModeLookup = array(); - if (empty($SpeexBandModeLookup)) { - $SpeexBandModeLookup[0] = 'narrow'; - $SpeexBandModeLookup[1] = 'wide'; - $SpeexBandModeLookup[2] = 'ultra-wide'; - } - return (isset($SpeexBandModeLookup[$mode]) ? $SpeexBandModeLookup[$mode] : null); - } - - - public static function OggPageSegmentLength($OggInfoArray, $SegmentNumber=1) { - for ($i = 0; $i < $SegmentNumber; $i++) { - $segmentlength = 0; - foreach ($OggInfoArray['segment_table'] as $key => $value) { - $segmentlength += $value; - if ($value < 255) { - break; - } - } - } - return $segmentlength; - } - - - public static function get_quality_from_nominal_bitrate($nominal_bitrate) { - - // decrease precision - $nominal_bitrate = $nominal_bitrate / 1000; - - if ($nominal_bitrate < 128) { - // q-1 to q4 - $qval = ($nominal_bitrate - 64) / 16; - } elseif ($nominal_bitrate < 256) { - // q4 to q8 - $qval = $nominal_bitrate / 32; - } elseif ($nominal_bitrate < 320) { - // q8 to q9 - $qval = ($nominal_bitrate + 256) / 64; - } else { - // q9 to q10 - $qval = ($nominal_bitrate + 1300) / 180; - } - //return $qval; // 5.031324 - //return intval($qval); // 5 - return round($qval, 1); // 5 or 4.9 - } - - public static function TheoraColorSpace($colorspace_id) { - // http://www.theora.org/doc/Theora.pdf (table 6.3) - static $TheoraColorSpaceLookup = array(); - if (empty($TheoraColorSpaceLookup)) { - $TheoraColorSpaceLookup[0] = 'Undefined'; - $TheoraColorSpaceLookup[1] = 'Rec. 470M'; - $TheoraColorSpaceLookup[2] = 'Rec. 470BG'; - $TheoraColorSpaceLookup[3] = 'Reserved'; - } - return (isset($TheoraColorSpaceLookup[$colorspace_id]) ? $TheoraColorSpaceLookup[$colorspace_id] : null); - } - - public static function TheoraPixelFormat($pixelformat_id) { - // http://www.theora.org/doc/Theora.pdf (table 6.4) - static $TheoraPixelFormatLookup = array(); - if (empty($TheoraPixelFormatLookup)) { - $TheoraPixelFormatLookup[0] = '4:2:0'; - $TheoraPixelFormatLookup[1] = 'Reserved'; - $TheoraPixelFormatLookup[2] = '4:2:2'; - $TheoraPixelFormatLookup[3] = '4:4:4'; - } - return (isset($TheoraPixelFormatLookup[$pixelformat_id]) ? $TheoraPixelFormatLookup[$pixelformat_id] : null); - } + public static function TheoraPixelFormat($pixelformat_id) + { + // http://www.theora.org/doc/Theora.pdf (table 6.4) + static $TheoraPixelFormatLookup = []; + if (empty($TheoraPixelFormatLookup)) { + $TheoraPixelFormatLookup[0] = '4:2:0'; + $TheoraPixelFormatLookup[1] = 'Reserved'; + $TheoraPixelFormatLookup[2] = '4:2:2'; + $TheoraPixelFormatLookup[3] = '4:4:4'; + } + return isset($TheoraPixelFormatLookup[$pixelformat_id]) ? $TheoraPixelFormatLookup[$pixelformat_id] : null; + } } diff --git a/app/Library/getid3/getid3/module.audio.optimfrog.php b/app/Library/getid3/getid3/module.audio.optimfrog.php index 50e0ffd6..36dd2e81 100644 --- a/app/Library/getid3/getid3/module.audio.optimfrog.php +++ b/app/Library/getid3/getid3/module.audio.optimfrog.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -18,410 +19,406 @@ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', class getid3_optimfrog extends getid3_handler { - - public function Analyze() { - $info = &$this->getid3->info; - - $info['fileformat'] = 'ofr'; - $info['audio']['dataformat'] = 'ofr'; - $info['audio']['bitrate_mode'] = 'vbr'; - $info['audio']['lossless'] = true; - - $this->fseek($info['avdataoffset']); - $OFRheader = $this->fread(8); - if (substr($OFRheader, 0, 5) == '*RIFF') { - - return $this->ParseOptimFROGheader42(); - - } elseif (substr($OFRheader, 0, 3) == 'OFR') { - - return $this->ParseOptimFROGheader45(); - - } - - $this->error('Expecting "*RIFF" or "OFR " at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($OFRheader).'"'); - unset($info['fileformat']); - return false; - } - - - public function ParseOptimFROGheader42() { - // for fileformat of v4.21 and older - - $info = &$this->getid3->info; - $this->fseek($info['avdataoffset']); - $OptimFROGheaderData = $this->fread(45); - $info['avdataoffset'] = 45; - - $OptimFROGencoderVersion_raw = getid3_lib::LittleEndian2Int(substr($OptimFROGheaderData, 0, 1)); - $OptimFROGencoderVersion_major = floor($OptimFROGencoderVersion_raw / 10); - $OptimFROGencoderVersion_minor = $OptimFROGencoderVersion_raw - ($OptimFROGencoderVersion_major * 10); - $RIFFdata = substr($OptimFROGheaderData, 1, 44); - $OrignalRIFFheaderSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 4, 4)) + 8; - $OrignalRIFFdataSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44; - - if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) { - $info['avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize); - $this->fseek($info['avdataend']); - $RIFFdata .= $this->fread($OrignalRIFFheaderSize - $OrignalRIFFdataSize); - } - - // move the data chunk after all other chunks (if any) - // so that the RIFF parser doesn't see EOF when trying - // to skip over the data chunk - $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8); - - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; - $getid3_temp->info['avdataend'] = $info['avdataend']; - $getid3_riff = new getid3_riff($getid3_temp); - $getid3_riff->ParseRIFFdata($RIFFdata); - $info['riff'] = $getid3_temp->info['riff']; - - $info['audio']['encoder'] = 'OptimFROG '.$OptimFROGencoderVersion_major.'.'.$OptimFROGencoderVersion_minor; - $info['audio']['channels'] = $info['riff']['audio'][0]['channels']; - $info['audio']['sample_rate'] = $info['riff']['audio'][0]['sample_rate']; - $info['audio']['bits_per_sample'] = $info['riff']['audio'][0]['bits_per_sample']; - $info['playtime_seconds'] = $OrignalRIFFdataSize / ($info['audio']['channels'] * $info['audio']['sample_rate'] * ($info['audio']['bits_per_sample'] / 8)); - $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; - - unset($getid3_riff, $getid3_temp, $RIFFdata); - - return true; - } - - - public function ParseOptimFROGheader45() { - // for fileformat of v4.50a and higher - - $info = &$this->getid3->info; - $RIFFdata = ''; - $this->fseek($info['avdataoffset']); - while (!feof($this->getid3->fp) && ($this->ftell() < $info['avdataend'])) { - $BlockOffset = $this->ftell(); - $BlockData = $this->fread(8); - $offset = 8; - $BlockName = substr($BlockData, 0, 4); - $BlockSize = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 4)); - - if ($BlockName == 'OFRX') { - $BlockName = 'OFR '; - } - if (!isset($info['ofr'][$BlockName])) { - $info['ofr'][$BlockName] = array(); - } - $thisfile_ofr_thisblock = &$info['ofr'][$BlockName]; - - switch ($BlockName) { - case 'OFR ': - - // shortcut - $thisfile_ofr_thisblock['offset'] = $BlockOffset; - $thisfile_ofr_thisblock['size'] = $BlockSize; - - $info['audio']['encoder'] = 'OptimFROG 4.50 alpha'; - switch ($BlockSize) { - case 12: - case 15: - // good - break; - - default: - $this->warning('"'.$BlockName.'" contains more data than expected (expected 12 or 15 bytes, found '.$BlockSize.' bytes)'); - break; - } - $BlockData .= $this->fread($BlockSize); - - $thisfile_ofr_thisblock['total_samples'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 6)); - $offset += 6; - $thisfile_ofr_thisblock['raw']['sample_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1)); - $thisfile_ofr_thisblock['sample_type'] = $this->OptimFROGsampleTypeLookup($thisfile_ofr_thisblock['raw']['sample_type']); - $offset += 1; - $thisfile_ofr_thisblock['channel_config'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1)); - $thisfile_ofr_thisblock['channels'] = $thisfile_ofr_thisblock['channel_config']; - $offset += 1; - $thisfile_ofr_thisblock['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4)); - $offset += 4; - - if ($BlockSize > 12) { - - // OFR 4.504b or higher - $thisfile_ofr_thisblock['channels'] = $this->OptimFROGchannelConfigNumChannelsLookup($thisfile_ofr_thisblock['channel_config']); - $thisfile_ofr_thisblock['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2)); - $thisfile_ofr_thisblock['encoder'] = $this->OptimFROGencoderNameLookup($thisfile_ofr_thisblock['raw']['encoder_id']); - $offset += 2; - $thisfile_ofr_thisblock['raw']['compression'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1)); - $thisfile_ofr_thisblock['compression'] = $this->OptimFROGcompressionLookup($thisfile_ofr_thisblock['raw']['compression']); - $thisfile_ofr_thisblock['speedup'] = $this->OptimFROGspeedupLookup($thisfile_ofr_thisblock['raw']['compression']); - $offset += 1; - - $info['audio']['encoder'] = 'OptimFROG '.$thisfile_ofr_thisblock['encoder']; - $info['audio']['encoder_options'] = '--mode '.$thisfile_ofr_thisblock['compression']; - - if ((($thisfile_ofr_thisblock['raw']['encoder_id'] & 0xF0) >> 4) == 7) { // v4.507 - if (strtolower(getid3_lib::fileextension($info['filename'])) == 'ofs') { - // OptimFROG DualStream format is lossy, but as of v4.507 there is no way to tell the difference - // between lossless and lossy other than the file extension. - $info['audio']['dataformat'] = 'ofs'; - $info['audio']['lossless'] = true; - } - } - - } - - $info['audio']['channels'] = $thisfile_ofr_thisblock['channels']; - $info['audio']['sample_rate'] = $thisfile_ofr_thisblock['sample_rate']; - $info['audio']['bits_per_sample'] = $this->OptimFROGbitsPerSampleTypeLookup($thisfile_ofr_thisblock['raw']['sample_type']); - break; - - - case 'COMP': - // unlike other block types, there CAN be multiple COMP blocks - - $COMPdata['offset'] = $BlockOffset; - $COMPdata['size'] = $BlockSize; - - if ($info['avdataoffset'] == 0) { - $info['avdataoffset'] = $BlockOffset; - } - - // Only interested in first 14 bytes (only first 12 needed for v4.50 alpha), not actual audio data - $BlockData .= $this->fread(14); - $this->fseek($BlockSize - 14, SEEK_CUR); - - $COMPdata['crc_32'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4)); - $offset += 4; - $COMPdata['sample_count'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4)); - $offset += 4; - $COMPdata['raw']['sample_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1)); - $COMPdata['sample_type'] = $this->OptimFROGsampleTypeLookup($COMPdata['raw']['sample_type']); - $offset += 1; - $COMPdata['raw']['channel_configuration'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1)); - $COMPdata['channel_configuration'] = $this->OptimFROGchannelConfigurationLookup($COMPdata['raw']['channel_configuration']); - $offset += 1; - $COMPdata['raw']['algorithm_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2)); - //$COMPdata['algorithm'] = OptimFROGalgorithmNameLookup($COMPdata['raw']['algorithm_id']); - $offset += 2; - - if ($info['ofr']['OFR ']['size'] > 12) { - - // OFR 4.504b or higher - $COMPdata['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2)); - $COMPdata['encoder'] = $this->OptimFROGencoderNameLookup($COMPdata['raw']['encoder_id']); - $offset += 2; - - } - - if ($COMPdata['crc_32'] == 0x454E4F4E) { - // ASCII value of 'NONE' - placeholder value in v4.50a - $COMPdata['crc_32'] = false; - } - - $thisfile_ofr_thisblock[] = $COMPdata; - break; - - case 'HEAD': - $thisfile_ofr_thisblock['offset'] = $BlockOffset; - $thisfile_ofr_thisblock['size'] = $BlockSize; - - $RIFFdata .= $this->fread($BlockSize); - break; - - case 'TAIL': - $thisfile_ofr_thisblock['offset'] = $BlockOffset; - $thisfile_ofr_thisblock['size'] = $BlockSize; - - if ($BlockSize > 0) { - $RIFFdata .= $this->fread($BlockSize); - } - break; - - case 'RECV': - // block contains no useful meta data - simply note and skip - - $thisfile_ofr_thisblock['offset'] = $BlockOffset; - $thisfile_ofr_thisblock['size'] = $BlockSize; - - $this->fseek($BlockSize, SEEK_CUR); - break; - - - case 'APET': - // APEtag v2 - - $thisfile_ofr_thisblock['offset'] = $BlockOffset; - $thisfile_ofr_thisblock['size'] = $BlockSize; - $this->warning('APEtag processing inside OptimFROG not supported in this version ('.$this->getid3->version().') of getID3()'); - - $this->fseek($BlockSize, SEEK_CUR); - break; - - - case 'MD5 ': - // APEtag v2 - - $thisfile_ofr_thisblock['offset'] = $BlockOffset; - $thisfile_ofr_thisblock['size'] = $BlockSize; - - if ($BlockSize == 16) { - - $thisfile_ofr_thisblock['md5_binary'] = $this->fread($BlockSize); - $thisfile_ofr_thisblock['md5_string'] = getid3_lib::PrintHexBytes($thisfile_ofr_thisblock['md5_binary'], true, false, false); - $info['md5_data_source'] = $thisfile_ofr_thisblock['md5_string']; - - } else { - - $this->warning('Expecting block size of 16 in "MD5 " chunk, found '.$BlockSize.' instead'); - $this->fseek($BlockSize, SEEK_CUR); - - } - break; - - - default: - $thisfile_ofr_thisblock['offset'] = $BlockOffset; - $thisfile_ofr_thisblock['size'] = $BlockSize; - - $this->warning('Unhandled OptimFROG block type "'.$BlockName.'" at offset '.$thisfile_ofr_thisblock['offset']); - $this->fseek($BlockSize, SEEK_CUR); - break; - } - } - if (isset($info['ofr']['TAIL']['offset'])) { - $info['avdataend'] = $info['ofr']['TAIL']['offset']; - } - - $info['playtime_seconds'] = (float) $info['ofr']['OFR ']['total_samples'] / ($info['audio']['channels'] * $info['audio']['sample_rate']); - $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; - - // move the data chunk after all other chunks (if any) - // so that the RIFF parser doesn't see EOF when trying - // to skip over the data chunk - $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8); - - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; - $getid3_temp->info['avdataend'] = $info['avdataend']; - $getid3_riff = new getid3_riff($getid3_temp); - $getid3_riff->ParseRIFFdata($RIFFdata); - $info['riff'] = $getid3_temp->info['riff']; - - unset($getid3_riff, $getid3_temp, $RIFFdata); - - return true; - } - - - public static function OptimFROGsampleTypeLookup($SampleType) { - static $OptimFROGsampleTypeLookup = array( - 0 => 'unsigned int (8-bit)', - 1 => 'signed int (8-bit)', - 2 => 'unsigned int (16-bit)', - 3 => 'signed int (16-bit)', - 4 => 'unsigned int (24-bit)', - 5 => 'signed int (24-bit)', - 6 => 'unsigned int (32-bit)', - 7 => 'signed int (32-bit)', - 8 => 'float 0.24 (32-bit)', - 9 => 'float 16.8 (32-bit)', - 10 => 'float 24.0 (32-bit)' - ); - return (isset($OptimFROGsampleTypeLookup[$SampleType]) ? $OptimFROGsampleTypeLookup[$SampleType] : false); - } - - public static function OptimFROGbitsPerSampleTypeLookup($SampleType) { - static $OptimFROGbitsPerSampleTypeLookup = array( - 0 => 8, - 1 => 8, - 2 => 16, - 3 => 16, - 4 => 24, - 5 => 24, - 6 => 32, - 7 => 32, - 8 => 32, - 9 => 32, - 10 => 32 - ); - return (isset($OptimFROGbitsPerSampleTypeLookup[$SampleType]) ? $OptimFROGbitsPerSampleTypeLookup[$SampleType] : false); - } - - public static function OptimFROGchannelConfigurationLookup($ChannelConfiguration) { - static $OptimFROGchannelConfigurationLookup = array( - 0 => 'mono', - 1 => 'stereo' - ); - return (isset($OptimFROGchannelConfigurationLookup[$ChannelConfiguration]) ? $OptimFROGchannelConfigurationLookup[$ChannelConfiguration] : false); - } - - public static function OptimFROGchannelConfigNumChannelsLookup($ChannelConfiguration) { - static $OptimFROGchannelConfigNumChannelsLookup = array( - 0 => 1, - 1 => 2 - ); - return (isset($OptimFROGchannelConfigNumChannelsLookup[$ChannelConfiguration]) ? $OptimFROGchannelConfigNumChannelsLookup[$ChannelConfiguration] : false); - } - - - - // static function OptimFROGalgorithmNameLookup($AlgorithID) { - // static $OptimFROGalgorithmNameLookup = array(); - // return (isset($OptimFROGalgorithmNameLookup[$AlgorithID]) ? $OptimFROGalgorithmNameLookup[$AlgorithID] : false); - // } - - - public static function OptimFROGencoderNameLookup($EncoderID) { - // version = (encoderID >> 4) + 4500 - // system = encoderID & 0xF - - $EncoderVersion = number_format(((($EncoderID & 0xF0) >> 4) + 4500) / 1000, 3); - $EncoderSystemID = ($EncoderID & 0x0F); - - static $OptimFROGencoderSystemLookup = array( - 0x00 => 'Windows console', - 0x01 => 'Linux console', - 0x0F => 'unknown' - ); - return $EncoderVersion.' ('.(isset($OptimFROGencoderSystemLookup[$EncoderSystemID]) ? $OptimFROGencoderSystemLookup[$EncoderSystemID] : 'undefined encoder type (0x'.dechex($EncoderSystemID).')').')'; - } - - public static function OptimFROGcompressionLookup($CompressionID) { - // mode = compression >> 3 - // speedup = compression & 0x07 - - $CompressionModeID = ($CompressionID & 0xF8) >> 3; - //$CompressionSpeedupID = ($CompressionID & 0x07); - - static $OptimFROGencoderModeLookup = array( - 0x00 => 'fast', - 0x01 => 'normal', - 0x02 => 'high', - 0x03 => 'extra', // extranew (some versions) - 0x04 => 'best', // bestnew (some versions) - 0x05 => 'ultra', - 0x06 => 'insane', - 0x07 => 'highnew', - 0x08 => 'extranew', - 0x09 => 'bestnew' - ); - return (isset($OptimFROGencoderModeLookup[$CompressionModeID]) ? $OptimFROGencoderModeLookup[$CompressionModeID] : 'undefined mode (0x'.str_pad(dechex($CompressionModeID), 2, '0', STR_PAD_LEFT).')'); - } - - public static function OptimFROGspeedupLookup($CompressionID) { - // mode = compression >> 3 - // speedup = compression & 0x07 - - //$CompressionModeID = ($CompressionID & 0xF8) >> 3; - $CompressionSpeedupID = ($CompressionID & 0x07); - - static $OptimFROGencoderSpeedupLookup = array( - 0x00 => '1x', - 0x01 => '2x', - 0x02 => '4x' - ); - return (isset($OptimFROGencoderSpeedupLookup[$CompressionSpeedupID]) ? $OptimFROGencoderSpeedupLookup[$CompressionSpeedupID] : 'undefined mode (0x'.dechex($CompressionSpeedupID)); - } - + public function Analyze() + { + $info = &$this->getid3->info; + + $info['fileformat'] = 'ofr'; + $info['audio']['dataformat'] = 'ofr'; + $info['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['lossless'] = true; + + $this->fseek($info['avdataoffset']); + $OFRheader = $this->fread(8); + if (substr($OFRheader, 0, 5) == '*RIFF') { + return $this->ParseOptimFROGheader42(); + } elseif (substr($OFRheader, 0, 3) == 'OFR') { + return $this->ParseOptimFROGheader45(); + } + + $this->error('Expecting "*RIFF" or "OFR " at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($OFRheader).'"'); + unset($info['fileformat']); + + return false; + } + + public function ParseOptimFROGheader42() + { + // for fileformat of v4.21 and older + + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $OptimFROGheaderData = $this->fread(45); + $info['avdataoffset'] = 45; + + $OptimFROGencoderVersion_raw = getid3_lib::LittleEndian2Int(substr($OptimFROGheaderData, 0, 1)); + $OptimFROGencoderVersion_major = floor($OptimFROGencoderVersion_raw / 10); + $OptimFROGencoderVersion_minor = $OptimFROGencoderVersion_raw - ($OptimFROGencoderVersion_major * 10); + $RIFFdata = substr($OptimFROGheaderData, 1, 44); + $OrignalRIFFheaderSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 4, 4)) + 8; + $OrignalRIFFdataSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44; + + if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) { + $info['avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize); + $this->fseek($info['avdataend']); + $RIFFdata .= $this->fread($OrignalRIFFheaderSize - $OrignalRIFFdataSize); + } + + // move the data chunk after all other chunks (if any) + // so that the RIFF parser doesn't see EOF when trying + // to skip over the data chunk + $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8); + + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; + $getid3_temp->info['avdataend'] = $info['avdataend']; + $getid3_riff = new getid3_riff($getid3_temp); + $getid3_riff->ParseRIFFdata($RIFFdata); + $info['riff'] = $getid3_temp->info['riff']; + + $info['audio']['encoder'] = 'OptimFROG '.$OptimFROGencoderVersion_major.'.'.$OptimFROGencoderVersion_minor; + $info['audio']['channels'] = $info['riff']['audio'][0]['channels']; + $info['audio']['sample_rate'] = $info['riff']['audio'][0]['sample_rate']; + $info['audio']['bits_per_sample'] = $info['riff']['audio'][0]['bits_per_sample']; + $info['playtime_seconds'] = $OrignalRIFFdataSize / ($info['audio']['channels'] * $info['audio']['sample_rate'] * ($info['audio']['bits_per_sample'] / 8)); + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + + unset($getid3_riff, $getid3_temp, $RIFFdata); + + return true; + } + + public function ParseOptimFROGheader45() + { + // for fileformat of v4.50a and higher + + $info = &$this->getid3->info; + $RIFFdata = ''; + $this->fseek($info['avdataoffset']); + while (! feof($this->getid3->fp) && ($this->ftell() < $info['avdataend'])) { + $BlockOffset = $this->ftell(); + $BlockData = $this->fread(8); + $offset = 8; + $BlockName = substr($BlockData, 0, 4); + $BlockSize = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 4)); + + if ($BlockName == 'OFRX') { + $BlockName = 'OFR '; + } + if (! isset($info['ofr'][$BlockName])) { + $info['ofr'][$BlockName] = []; + } + $thisfile_ofr_thisblock = &$info['ofr'][$BlockName]; + + switch ($BlockName) { + case 'OFR ': + + // shortcut + $thisfile_ofr_thisblock['offset'] = $BlockOffset; + $thisfile_ofr_thisblock['size'] = $BlockSize; + + $info['audio']['encoder'] = 'OptimFROG 4.50 alpha'; + switch ($BlockSize) { + case 12: + case 15: + // good + break; + + default: + $this->warning('"'.$BlockName.'" contains more data than expected (expected 12 or 15 bytes, found '.$BlockSize.' bytes)'); + break; + } + $BlockData .= $this->fread($BlockSize); + + $thisfile_ofr_thisblock['total_samples'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 6)); + $offset += 6; + $thisfile_ofr_thisblock['raw']['sample_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1)); + $thisfile_ofr_thisblock['sample_type'] = $this->OptimFROGsampleTypeLookup($thisfile_ofr_thisblock['raw']['sample_type']); + $offset += 1; + $thisfile_ofr_thisblock['channel_config'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1)); + $thisfile_ofr_thisblock['channels'] = $thisfile_ofr_thisblock['channel_config']; + $offset += 1; + $thisfile_ofr_thisblock['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4)); + $offset += 4; + + if ($BlockSize > 12) { + + // OFR 4.504b or higher + $thisfile_ofr_thisblock['channels'] = $this->OptimFROGchannelConfigNumChannelsLookup($thisfile_ofr_thisblock['channel_config']); + $thisfile_ofr_thisblock['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2)); + $thisfile_ofr_thisblock['encoder'] = $this->OptimFROGencoderNameLookup($thisfile_ofr_thisblock['raw']['encoder_id']); + $offset += 2; + $thisfile_ofr_thisblock['raw']['compression'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1)); + $thisfile_ofr_thisblock['compression'] = $this->OptimFROGcompressionLookup($thisfile_ofr_thisblock['raw']['compression']); + $thisfile_ofr_thisblock['speedup'] = $this->OptimFROGspeedupLookup($thisfile_ofr_thisblock['raw']['compression']); + $offset += 1; + + $info['audio']['encoder'] = 'OptimFROG '.$thisfile_ofr_thisblock['encoder']; + $info['audio']['encoder_options'] = '--mode '.$thisfile_ofr_thisblock['compression']; + + if ((($thisfile_ofr_thisblock['raw']['encoder_id'] & 0xF0) >> 4) == 7) { // v4.507 + if (strtolower(getid3_lib::fileextension($info['filename'])) == 'ofs') { + // OptimFROG DualStream format is lossy, but as of v4.507 there is no way to tell the difference + // between lossless and lossy other than the file extension. + $info['audio']['dataformat'] = 'ofs'; + $info['audio']['lossless'] = true; + } + } + } + + $info['audio']['channels'] = $thisfile_ofr_thisblock['channels']; + $info['audio']['sample_rate'] = $thisfile_ofr_thisblock['sample_rate']; + $info['audio']['bits_per_sample'] = $this->OptimFROGbitsPerSampleTypeLookup($thisfile_ofr_thisblock['raw']['sample_type']); + break; + + case 'COMP': + // unlike other block types, there CAN be multiple COMP blocks + + $COMPdata['offset'] = $BlockOffset; + $COMPdata['size'] = $BlockSize; + + if ($info['avdataoffset'] == 0) { + $info['avdataoffset'] = $BlockOffset; + } + + // Only interested in first 14 bytes (only first 12 needed for v4.50 alpha), not actual audio data + $BlockData .= $this->fread(14); + $this->fseek($BlockSize - 14, SEEK_CUR); + + $COMPdata['crc_32'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4)); + $offset += 4; + $COMPdata['sample_count'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4)); + $offset += 4; + $COMPdata['raw']['sample_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1)); + $COMPdata['sample_type'] = $this->OptimFROGsampleTypeLookup($COMPdata['raw']['sample_type']); + $offset += 1; + $COMPdata['raw']['channel_configuration'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1)); + $COMPdata['channel_configuration'] = $this->OptimFROGchannelConfigurationLookup($COMPdata['raw']['channel_configuration']); + $offset += 1; + $COMPdata['raw']['algorithm_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2)); + //$COMPdata['algorithm'] = OptimFROGalgorithmNameLookup($COMPdata['raw']['algorithm_id']); + $offset += 2; + + if ($info['ofr']['OFR ']['size'] > 12) { + + // OFR 4.504b or higher + $COMPdata['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2)); + $COMPdata['encoder'] = $this->OptimFROGencoderNameLookup($COMPdata['raw']['encoder_id']); + $offset += 2; + } + + if ($COMPdata['crc_32'] == 0x454E4F4E) { + // ASCII value of 'NONE' - placeholder value in v4.50a + $COMPdata['crc_32'] = false; + } + + $thisfile_ofr_thisblock[] = $COMPdata; + break; + + case 'HEAD': + $thisfile_ofr_thisblock['offset'] = $BlockOffset; + $thisfile_ofr_thisblock['size'] = $BlockSize; + + $RIFFdata .= $this->fread($BlockSize); + break; + + case 'TAIL': + $thisfile_ofr_thisblock['offset'] = $BlockOffset; + $thisfile_ofr_thisblock['size'] = $BlockSize; + + if ($BlockSize > 0) { + $RIFFdata .= $this->fread($BlockSize); + } + break; + + case 'RECV': + // block contains no useful meta data - simply note and skip + + $thisfile_ofr_thisblock['offset'] = $BlockOffset; + $thisfile_ofr_thisblock['size'] = $BlockSize; + + $this->fseek($BlockSize, SEEK_CUR); + break; + + case 'APET': + // APEtag v2 + + $thisfile_ofr_thisblock['offset'] = $BlockOffset; + $thisfile_ofr_thisblock['size'] = $BlockSize; + $this->warning('APEtag processing inside OptimFROG not supported in this version ('.$this->getid3->version().') of getID3()'); + + $this->fseek($BlockSize, SEEK_CUR); + break; + + case 'MD5 ': + // APEtag v2 + + $thisfile_ofr_thisblock['offset'] = $BlockOffset; + $thisfile_ofr_thisblock['size'] = $BlockSize; + + if ($BlockSize == 16) { + $thisfile_ofr_thisblock['md5_binary'] = $this->fread($BlockSize); + $thisfile_ofr_thisblock['md5_string'] = getid3_lib::PrintHexBytes($thisfile_ofr_thisblock['md5_binary'], true, false, false); + $info['md5_data_source'] = $thisfile_ofr_thisblock['md5_string']; + } else { + $this->warning('Expecting block size of 16 in "MD5 " chunk, found '.$BlockSize.' instead'); + $this->fseek($BlockSize, SEEK_CUR); + } + break; + + default: + $thisfile_ofr_thisblock['offset'] = $BlockOffset; + $thisfile_ofr_thisblock['size'] = $BlockSize; + + $this->warning('Unhandled OptimFROG block type "'.$BlockName.'" at offset '.$thisfile_ofr_thisblock['offset']); + $this->fseek($BlockSize, SEEK_CUR); + break; + } + } + if (isset($info['ofr']['TAIL']['offset'])) { + $info['avdataend'] = $info['ofr']['TAIL']['offset']; + } + + $info['playtime_seconds'] = (float) $info['ofr']['OFR ']['total_samples'] / ($info['audio']['channels'] * $info['audio']['sample_rate']); + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + + // move the data chunk after all other chunks (if any) + // so that the RIFF parser doesn't see EOF when trying + // to skip over the data chunk + $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8); + + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; + $getid3_temp->info['avdataend'] = $info['avdataend']; + $getid3_riff = new getid3_riff($getid3_temp); + $getid3_riff->ParseRIFFdata($RIFFdata); + $info['riff'] = $getid3_temp->info['riff']; + + unset($getid3_riff, $getid3_temp, $RIFFdata); + + return true; + } + + public static function OptimFROGsampleTypeLookup($SampleType) + { + static $OptimFROGsampleTypeLookup = [ + 0 => 'unsigned int (8-bit)', + 1 => 'signed int (8-bit)', + 2 => 'unsigned int (16-bit)', + 3 => 'signed int (16-bit)', + 4 => 'unsigned int (24-bit)', + 5 => 'signed int (24-bit)', + 6 => 'unsigned int (32-bit)', + 7 => 'signed int (32-bit)', + 8 => 'float 0.24 (32-bit)', + 9 => 'float 16.8 (32-bit)', + 10 => 'float 24.0 (32-bit)', + ]; + + return isset($OptimFROGsampleTypeLookup[$SampleType]) ? $OptimFROGsampleTypeLookup[$SampleType] : false; + } + + public static function OptimFROGbitsPerSampleTypeLookup($SampleType) + { + static $OptimFROGbitsPerSampleTypeLookup = [ + 0 => 8, + 1 => 8, + 2 => 16, + 3 => 16, + 4 => 24, + 5 => 24, + 6 => 32, + 7 => 32, + 8 => 32, + 9 => 32, + 10 => 32, + ]; + + return isset($OptimFROGbitsPerSampleTypeLookup[$SampleType]) ? $OptimFROGbitsPerSampleTypeLookup[$SampleType] : false; + } + + public static function OptimFROGchannelConfigurationLookup($ChannelConfiguration) + { + static $OptimFROGchannelConfigurationLookup = [ + 0 => 'mono', + 1 => 'stereo', + ]; + + return isset($OptimFROGchannelConfigurationLookup[$ChannelConfiguration]) ? $OptimFROGchannelConfigurationLookup[$ChannelConfiguration] : false; + } + + public static function OptimFROGchannelConfigNumChannelsLookup($ChannelConfiguration) + { + static $OptimFROGchannelConfigNumChannelsLookup = [ + 0 => 1, + 1 => 2, + ]; + + return isset($OptimFROGchannelConfigNumChannelsLookup[$ChannelConfiguration]) ? $OptimFROGchannelConfigNumChannelsLookup[$ChannelConfiguration] : false; + } + + // static function OptimFROGalgorithmNameLookup($AlgorithID) { + // static $OptimFROGalgorithmNameLookup = array(); + // return (isset($OptimFROGalgorithmNameLookup[$AlgorithID]) ? $OptimFROGalgorithmNameLookup[$AlgorithID] : false); + // } + + public static function OptimFROGencoderNameLookup($EncoderID) + { + // version = (encoderID >> 4) + 4500 + // system = encoderID & 0xF + + $EncoderVersion = number_format(((($EncoderID & 0xF0) >> 4) + 4500) / 1000, 3); + $EncoderSystemID = ($EncoderID & 0x0F); + + static $OptimFROGencoderSystemLookup = [ + 0x00 => 'Windows console', + 0x01 => 'Linux console', + 0x0F => 'unknown', + ]; + + return $EncoderVersion.' ('.(isset($OptimFROGencoderSystemLookup[$EncoderSystemID]) ? $OptimFROGencoderSystemLookup[$EncoderSystemID] : 'undefined encoder type (0x'.dechex($EncoderSystemID).')').')'; + } + + public static function OptimFROGcompressionLookup($CompressionID) + { + // mode = compression >> 3 + // speedup = compression & 0x07 + + $CompressionModeID = ($CompressionID & 0xF8) >> 3; + //$CompressionSpeedupID = ($CompressionID & 0x07); + + static $OptimFROGencoderModeLookup = [ + 0x00 => 'fast', + 0x01 => 'normal', + 0x02 => 'high', + 0x03 => 'extra', // extranew (some versions) + 0x04 => 'best', // bestnew (some versions) + 0x05 => 'ultra', + 0x06 => 'insane', + 0x07 => 'highnew', + 0x08 => 'extranew', + 0x09 => 'bestnew', + ]; + + return isset($OptimFROGencoderModeLookup[$CompressionModeID]) ? $OptimFROGencoderModeLookup[$CompressionModeID] : 'undefined mode (0x'.str_pad(dechex($CompressionModeID), 2, '0', STR_PAD_LEFT).')'; + } + + public static function OptimFROGspeedupLookup($CompressionID) + { + // mode = compression >> 3 + // speedup = compression & 0x07 + + //$CompressionModeID = ($CompressionID & 0xF8) >> 3; + $CompressionSpeedupID = ($CompressionID & 0x07); + + static $OptimFROGencoderSpeedupLookup = [ + 0x00 => '1x', + 0x01 => '2x', + 0x02 => '4x', + ]; + + return isset($OptimFROGencoderSpeedupLookup[$CompressionSpeedupID]) ? $OptimFROGencoderSpeedupLookup[$CompressionSpeedupID] : 'undefined mode (0x'.dechex($CompressionSpeedupID); + } } diff --git a/app/Library/getid3/getid3/module.audio.rkau.php b/app/Library/getid3/getid3/module.audio.rkau.php index d7c2f09a..44ca2d6d 100644 --- a/app/Library/getid3/getid3/module.audio.rkau.php +++ b/app/Library/getid3/getid3/module.audio.rkau.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,80 +15,79 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_rkau extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $RKAUHeader = $this->fread(20); + $magic = 'RKA'; + if (substr($RKAUHeader, 0, 3) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($RKAUHeader, 0, 3)).'"'); - $this->fseek($info['avdataoffset']); - $RKAUHeader = $this->fread(20); - $magic = 'RKA'; - if (substr($RKAUHeader, 0, 3) != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($RKAUHeader, 0, 3)).'"'); - return false; - } + return false; + } - $info['fileformat'] = 'rkau'; - $info['audio']['dataformat'] = 'rkau'; - $info['audio']['bitrate_mode'] = 'vbr'; + $info['fileformat'] = 'rkau'; + $info['audio']['dataformat'] = 'rkau'; + $info['audio']['bitrate_mode'] = 'vbr'; - $info['rkau']['raw']['version'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 3, 1)); - $info['rkau']['version'] = '1.'.str_pad($info['rkau']['raw']['version'] & 0x0F, 2, '0', STR_PAD_LEFT); - if (($info['rkau']['version'] > 1.07) || ($info['rkau']['version'] < 1.06)) { - $this->error('This version of getID3() ['.$this->getid3->version().'] can only parse RKAU files v1.06 and 1.07 (this file is v'.$info['rkau']['version'].')'); - unset($info['rkau']); - return false; - } + $info['rkau']['raw']['version'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 3, 1)); + $info['rkau']['version'] = '1.'.str_pad($info['rkau']['raw']['version'] & 0x0F, 2, '0', STR_PAD_LEFT); + if (($info['rkau']['version'] > 1.07) || ($info['rkau']['version'] < 1.06)) { + $this->error('This version of getID3() ['.$this->getid3->version().'] can only parse RKAU files v1.06 and 1.07 (this file is v'.$info['rkau']['version'].')'); + unset($info['rkau']); - $info['rkau']['source_bytes'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 4, 4)); - $info['rkau']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 8, 4)); - $info['rkau']['channels'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 12, 1)); - $info['rkau']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 13, 1)); + return false; + } - $info['rkau']['raw']['quality'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 14, 1)); - $this->RKAUqualityLookup($info['rkau']); + $info['rkau']['source_bytes'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 4, 4)); + $info['rkau']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 8, 4)); + $info['rkau']['channels'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 12, 1)); + $info['rkau']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 13, 1)); - $info['rkau']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 15, 1)); - $info['rkau']['flags']['joint_stereo'] = (bool) (!($info['rkau']['raw']['flags'] & 0x01)); - $info['rkau']['flags']['streaming'] = (bool) ($info['rkau']['raw']['flags'] & 0x02); - $info['rkau']['flags']['vrq_lossy_mode'] = (bool) ($info['rkau']['raw']['flags'] & 0x04); + $info['rkau']['raw']['quality'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 14, 1)); + $this->RKAUqualityLookup($info['rkau']); - if ($info['rkau']['flags']['streaming']) { - $info['avdataoffset'] += 20; - $info['rkau']['compressed_bytes'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 16, 4)); - } else { - $info['avdataoffset'] += 16; - $info['rkau']['compressed_bytes'] = $info['avdataend'] - $info['avdataoffset'] - 1; - } - // Note: compressed_bytes does not always equal what appears to be the actual number of compressed bytes, - // sometimes it's more, sometimes less. No idea why(?) + $info['rkau']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 15, 1)); + $info['rkau']['flags']['joint_stereo'] = (bool) (! ($info['rkau']['raw']['flags'] & 0x01)); + $info['rkau']['flags']['streaming'] = (bool) ($info['rkau']['raw']['flags'] & 0x02); + $info['rkau']['flags']['vrq_lossy_mode'] = (bool) ($info['rkau']['raw']['flags'] & 0x04); - $info['audio']['lossless'] = $info['rkau']['lossless']; - $info['audio']['channels'] = $info['rkau']['channels']; - $info['audio']['bits_per_sample'] = $info['rkau']['bits_per_sample']; - $info['audio']['sample_rate'] = $info['rkau']['sample_rate']; + if ($info['rkau']['flags']['streaming']) { + $info['avdataoffset'] += 20; + $info['rkau']['compressed_bytes'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 16, 4)); + } else { + $info['avdataoffset'] += 16; + $info['rkau']['compressed_bytes'] = $info['avdataend'] - $info['avdataoffset'] - 1; + } + // Note: compressed_bytes does not always equal what appears to be the actual number of compressed bytes, + // sometimes it's more, sometimes less. No idea why(?) - $info['playtime_seconds'] = $info['rkau']['source_bytes'] / ($info['rkau']['sample_rate'] * $info['rkau']['channels'] * ($info['rkau']['bits_per_sample'] / 8)); - $info['audio']['bitrate'] = ($info['rkau']['compressed_bytes'] * 8) / $info['playtime_seconds']; + $info['audio']['lossless'] = $info['rkau']['lossless']; + $info['audio']['channels'] = $info['rkau']['channels']; + $info['audio']['bits_per_sample'] = $info['rkau']['bits_per_sample']; + $info['audio']['sample_rate'] = $info['rkau']['sample_rate']; - return true; + $info['playtime_seconds'] = $info['rkau']['source_bytes'] / ($info['rkau']['sample_rate'] * $info['rkau']['channels'] * ($info['rkau']['bits_per_sample'] / 8)); + $info['audio']['bitrate'] = ($info['rkau']['compressed_bytes'] * 8) / $info['playtime_seconds']; - } + return true; + } + public function RKAUqualityLookup(&$RKAUdata) + { + $level = ($RKAUdata['raw']['quality'] & 0xF0) >> 4; + $quality = $RKAUdata['raw']['quality'] & 0x0F; - public function RKAUqualityLookup(&$RKAUdata) { - $level = ($RKAUdata['raw']['quality'] & 0xF0) >> 4; - $quality = $RKAUdata['raw']['quality'] & 0x0F; - - $RKAUdata['lossless'] = (($quality == 0) ? true : false); - $RKAUdata['compression_level'] = $level + 1; - if (!$RKAUdata['lossless']) { - $RKAUdata['quality_setting'] = $quality; - } - - return true; - } + $RKAUdata['lossless'] = (($quality == 0) ? true : false); + $RKAUdata['compression_level'] = $level + 1; + if (! $RKAUdata['lossless']) { + $RKAUdata['quality_setting'] = $quality; + } + return true; + } } diff --git a/app/Library/getid3/getid3/module.audio.shorten.php b/app/Library/getid3/getid3/module.audio.shorten.php index 8d5c5d4b..a3a0aa17 100644 --- a/app/Library/getid3/getid3/module.audio.shorten.php +++ b/app/Library/getid3/getid3/module.audio.shorten.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,169 +15,158 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_shorten extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); - $this->fseek($info['avdataoffset']); + $ShortenHeader = $this->fread(8); + $magic = 'ajkg'; + if (substr($ShortenHeader, 0, 4) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($ShortenHeader, 0, 4)).'"'); - $ShortenHeader = $this->fread(8); - $magic = 'ajkg'; - if (substr($ShortenHeader, 0, 4) != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($ShortenHeader, 0, 4)).'"'); - return false; - } - $info['fileformat'] = 'shn'; - $info['audio']['dataformat'] = 'shn'; - $info['audio']['lossless'] = true; - $info['audio']['bitrate_mode'] = 'vbr'; + return false; + } + $info['fileformat'] = 'shn'; + $info['audio']['dataformat'] = 'shn'; + $info['audio']['lossless'] = true; + $info['audio']['bitrate_mode'] = 'vbr'; - $info['shn']['version'] = getid3_lib::LittleEndian2Int(substr($ShortenHeader, 4, 1)); + $info['shn']['version'] = getid3_lib::LittleEndian2Int(substr($ShortenHeader, 4, 1)); - $this->fseek($info['avdataend'] - 12); - $SeekTableSignatureTest = $this->fread(12); - $info['shn']['seektable']['present'] = (bool) (substr($SeekTableSignatureTest, 4, 8) == 'SHNAMPSK'); - if ($info['shn']['seektable']['present']) { - $info['shn']['seektable']['length'] = getid3_lib::LittleEndian2Int(substr($SeekTableSignatureTest, 0, 4)); - $info['shn']['seektable']['offset'] = $info['avdataend'] - $info['shn']['seektable']['length']; - $this->fseek($info['shn']['seektable']['offset']); - $SeekTableMagic = $this->fread(4); - $magic = 'SEEK'; - if ($SeekTableMagic != $magic) { + $this->fseek($info['avdataend'] - 12); + $SeekTableSignatureTest = $this->fread(12); + $info['shn']['seektable']['present'] = (bool) (substr($SeekTableSignatureTest, 4, 8) == 'SHNAMPSK'); + if ($info['shn']['seektable']['present']) { + $info['shn']['seektable']['length'] = getid3_lib::LittleEndian2Int(substr($SeekTableSignatureTest, 0, 4)); + $info['shn']['seektable']['offset'] = $info['avdataend'] - $info['shn']['seektable']['length']; + $this->fseek($info['shn']['seektable']['offset']); + $SeekTableMagic = $this->fread(4); + $magic = 'SEEK'; + if ($SeekTableMagic != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['shn']['seektable']['offset'].', found "'.getid3_lib::PrintHexBytes($SeekTableMagic).'"'); - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['shn']['seektable']['offset'].', found "'.getid3_lib::PrintHexBytes($SeekTableMagic).'"'); - return false; + return false; + } else { - } else { + // typedef struct tag_TSeekEntry + // { + // unsigned long SampleNumber; + // unsigned long SHNFileByteOffset; + // unsigned long SHNLastBufferReadPosition; + // unsigned short SHNByteGet; + // unsigned short SHNBufferOffset; + // unsigned short SHNFileBitOffset; + // unsigned long SHNGBuffer; + // unsigned short SHNBitShift; + // long CBuf0[3]; + // long CBuf1[3]; + // long Offset0[4]; + // long Offset1[4]; + // }TSeekEntry; - // typedef struct tag_TSeekEntry - // { - // unsigned long SampleNumber; - // unsigned long SHNFileByteOffset; - // unsigned long SHNLastBufferReadPosition; - // unsigned short SHNByteGet; - // unsigned short SHNBufferOffset; - // unsigned short SHNFileBitOffset; - // unsigned long SHNGBuffer; - // unsigned short SHNBitShift; - // long CBuf0[3]; - // long CBuf1[3]; - // long Offset0[4]; - // long Offset1[4]; - // }TSeekEntry; + $SeekTableData = $this->fread($info['shn']['seektable']['length'] - 16); + $info['shn']['seektable']['entry_count'] = floor(strlen($SeekTableData) / 80); + //$info['shn']['seektable']['entries'] = array(); + //$SeekTableOffset = 0; + //for ($i = 0; $i < $info['shn']['seektable']['entry_count']; $i++) { + // $SeekTableEntry['sample_number'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); + // $SeekTableOffset += 4; + // $SeekTableEntry['shn_file_byte_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); + // $SeekTableOffset += 4; + // $SeekTableEntry['shn_last_buffer_read_position'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); + // $SeekTableOffset += 4; + // $SeekTableEntry['shn_byte_get'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2)); + // $SeekTableOffset += 2; + // $SeekTableEntry['shn_buffer_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2)); + // $SeekTableOffset += 2; + // $SeekTableEntry['shn_file_bit_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2)); + // $SeekTableOffset += 2; + // $SeekTableEntry['shn_gbuffer'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); + // $SeekTableOffset += 4; + // $SeekTableEntry['shn_bit_shift'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2)); + // $SeekTableOffset += 2; + // for ($j = 0; $j < 3; $j++) { + // $SeekTableEntry['cbuf0'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); + // $SeekTableOffset += 4; + // } + // for ($j = 0; $j < 3; $j++) { + // $SeekTableEntry['cbuf1'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); + // $SeekTableOffset += 4; + // } + // for ($j = 0; $j < 4; $j++) { + // $SeekTableEntry['offset0'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); + // $SeekTableOffset += 4; + // } + // for ($j = 0; $j < 4; $j++) { + // $SeekTableEntry['offset1'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); + // $SeekTableOffset += 4; + // } + // + // $info['shn']['seektable']['entries'][] = $SeekTableEntry; + //} + } + } - $SeekTableData = $this->fread($info['shn']['seektable']['length'] - 16); - $info['shn']['seektable']['entry_count'] = floor(strlen($SeekTableData) / 80); - //$info['shn']['seektable']['entries'] = array(); - //$SeekTableOffset = 0; - //for ($i = 0; $i < $info['shn']['seektable']['entry_count']; $i++) { - // $SeekTableEntry['sample_number'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); - // $SeekTableOffset += 4; - // $SeekTableEntry['shn_file_byte_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); - // $SeekTableOffset += 4; - // $SeekTableEntry['shn_last_buffer_read_position'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); - // $SeekTableOffset += 4; - // $SeekTableEntry['shn_byte_get'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2)); - // $SeekTableOffset += 2; - // $SeekTableEntry['shn_buffer_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2)); - // $SeekTableOffset += 2; - // $SeekTableEntry['shn_file_bit_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2)); - // $SeekTableOffset += 2; - // $SeekTableEntry['shn_gbuffer'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); - // $SeekTableOffset += 4; - // $SeekTableEntry['shn_bit_shift'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2)); - // $SeekTableOffset += 2; - // for ($j = 0; $j < 3; $j++) { - // $SeekTableEntry['cbuf0'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); - // $SeekTableOffset += 4; - // } - // for ($j = 0; $j < 3; $j++) { - // $SeekTableEntry['cbuf1'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); - // $SeekTableOffset += 4; - // } - // for ($j = 0; $j < 4; $j++) { - // $SeekTableEntry['offset0'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); - // $SeekTableOffset += 4; - // } - // for ($j = 0; $j < 4; $j++) { - // $SeekTableEntry['offset1'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); - // $SeekTableOffset += 4; - // } - // - // $info['shn']['seektable']['entries'][] = $SeekTableEntry; - //} + if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { + $this->error('PHP running in Safe Mode - backtick operator not available, cannot run shntool to analyze Shorten files'); - } + return false; + } - } + if (GETID3_OS_ISWINDOWS) { + $RequiredFiles = ['shorten.exe', 'cygwin1.dll', 'head.exe']; + foreach ($RequiredFiles as $required_file) { + if (! is_readable(GETID3_HELPERAPPSDIR.$required_file)) { + $this->error(GETID3_HELPERAPPSDIR.$required_file.' does not exist'); - if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { - $this->error('PHP running in Safe Mode - backtick operator not available, cannot run shntool to analyze Shorten files'); - return false; - } + return false; + } + } + $commandline = GETID3_HELPERAPPSDIR.'shorten.exe -x "'.$info['filenamepath'].'" - | '.GETID3_HELPERAPPSDIR.'head.exe -c 64'; + $commandline = str_replace('/', '\\', $commandline); + } else { + static $shorten_present; + if (! isset($shorten_present)) { + $shorten_present = file_exists('/usr/local/bin/shorten') || `which shorten`; + } + if (! $shorten_present) { + $this->error('shorten binary was not found in path or /usr/local/bin'); - if (GETID3_OS_ISWINDOWS) { + return false; + } + $commandline = (file_exists('/usr/local/bin/shorten') ? '/usr/local/bin/' : '').'shorten -x '.escapeshellarg($info['filenamepath']).' - | head -c 64'; + } - $RequiredFiles = array('shorten.exe', 'cygwin1.dll', 'head.exe'); - foreach ($RequiredFiles as $required_file) { - if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) { - $this->error(GETID3_HELPERAPPSDIR.$required_file.' does not exist'); - return false; - } - } - $commandline = GETID3_HELPERAPPSDIR.'shorten.exe -x "'.$info['filenamepath'].'" - | '.GETID3_HELPERAPPSDIR.'head.exe -c 64'; - $commandline = str_replace('/', '\\', $commandline); + $output = `$commandline`; - } else { + if (! empty($output) && (substr($output, 12, 4) == 'fmt ')) { + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); - static $shorten_present; - if (!isset($shorten_present)) { - $shorten_present = file_exists('/usr/local/bin/shorten') || `which shorten`; - } - if (!$shorten_present) { - $this->error('shorten binary was not found in path or /usr/local/bin'); - return false; - } - $commandline = (file_exists('/usr/local/bin/shorten') ? '/usr/local/bin/' : '' ) . 'shorten -x '.escapeshellarg($info['filenamepath']).' - | head -c 64'; + $fmt_size = getid3_lib::LittleEndian2Int(substr($output, 16, 4)); + $DecodedWAVFORMATEX = getid3_riff::parseWAVEFORMATex(substr($output, 20, $fmt_size)); + $info['audio']['channels'] = $DecodedWAVFORMATEX['channels']; + $info['audio']['bits_per_sample'] = $DecodedWAVFORMATEX['bits_per_sample']; + $info['audio']['sample_rate'] = $DecodedWAVFORMATEX['sample_rate']; - } + if (substr($output, 20 + $fmt_size, 4) == 'data') { + $info['playtime_seconds'] = getid3_lib::LittleEndian2Int(substr($output, 20 + 4 + $fmt_size, 4)) / $DecodedWAVFORMATEX['raw']['nAvgBytesPerSec']; + } else { + $this->error('shorten failed to decode DATA chunk to expected location, cannot determine playtime'); - $output = `$commandline`; + return false; + } - if (!empty($output) && (substr($output, 12, 4) == 'fmt ')) { + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8; + } else { + $this->error('shorten failed to decode file to WAV for parsing'); - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); - - $fmt_size = getid3_lib::LittleEndian2Int(substr($output, 16, 4)); - $DecodedWAVFORMATEX = getid3_riff::parseWAVEFORMATex(substr($output, 20, $fmt_size)); - $info['audio']['channels'] = $DecodedWAVFORMATEX['channels']; - $info['audio']['bits_per_sample'] = $DecodedWAVFORMATEX['bits_per_sample']; - $info['audio']['sample_rate'] = $DecodedWAVFORMATEX['sample_rate']; - - if (substr($output, 20 + $fmt_size, 4) == 'data') { - - $info['playtime_seconds'] = getid3_lib::LittleEndian2Int(substr($output, 20 + 4 + $fmt_size, 4)) / $DecodedWAVFORMATEX['raw']['nAvgBytesPerSec']; - - } else { - - $this->error('shorten failed to decode DATA chunk to expected location, cannot determine playtime'); - return false; - - } - - $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8; - - } else { - - $this->error('shorten failed to decode file to WAV for parsing'); - return false; - - } - - return true; - } + return false; + } + return true; + } } diff --git a/app/Library/getid3/getid3/module.audio.tta.php b/app/Library/getid3/getid3/module.audio.tta.php index 78d27b0f..6974bc2a 100644 --- a/app/Library/getid3/getid3/module.audio.tta.php +++ b/app/Library/getid3/getid3/module.audio.tta.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,94 +15,94 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_tta extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $info['fileformat'] = 'tta'; + $info['audio']['dataformat'] = 'tta'; + $info['audio']['lossless'] = true; + $info['audio']['bitrate_mode'] = 'vbr'; - $info['fileformat'] = 'tta'; - $info['audio']['dataformat'] = 'tta'; - $info['audio']['lossless'] = true; - $info['audio']['bitrate_mode'] = 'vbr'; + $this->fseek($info['avdataoffset']); + $ttaheader = $this->fread(26); - $this->fseek($info['avdataoffset']); - $ttaheader = $this->fread(26); + $info['tta']['magic'] = substr($ttaheader, 0, 3); + $magic = 'TTA'; + if ($info['tta']['magic'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['tta']['magic']).'"'); + unset($info['fileformat']); + unset($info['audio']); + unset($info['tta']); - $info['tta']['magic'] = substr($ttaheader, 0, 3); - $magic = 'TTA'; - if ($info['tta']['magic'] != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['tta']['magic']).'"'); - unset($info['fileformat']); - unset($info['audio']); - unset($info['tta']); - return false; - } + return false; + } - switch ($ttaheader{3}) { - case "\x01": // TTA v1.x - case "\x02": // TTA v1.x - case "\x03": // TTA v1.x - // "It was the demo-version of the TTA encoder. There is no released format with such header. TTA encoder v1 is not supported about a year." - $info['tta']['major_version'] = 1; - $info['avdataoffset'] += 16; + switch ($ttaheader[3]) { + case "\x01": // TTA v1.x + case "\x02": // TTA v1.x + case "\x03": // TTA v1.x + // "It was the demo-version of the TTA encoder. There is no released format with such header. TTA encoder v1 is not supported about a year." + $info['tta']['major_version'] = 1; + $info['avdataoffset'] += 16; - $info['tta']['compression_level'] = ord($ttaheader{3}); - $info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); - $info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2)); - $info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 4)); - $info['tta']['samples_per_channel'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 12, 4)); + $info['tta']['compression_level'] = ord($ttaheader[3]); + $info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); + $info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2)); + $info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 4)); + $info['tta']['samples_per_channel'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 12, 4)); - $info['audio']['encoder_options'] = '-e'.$info['tta']['compression_level']; - $info['playtime_seconds'] = $info['tta']['samples_per_channel'] / $info['tta']['sample_rate']; - break; + $info['audio']['encoder_options'] = '-e'.$info['tta']['compression_level']; + $info['playtime_seconds'] = $info['tta']['samples_per_channel'] / $info['tta']['sample_rate']; + break; - case '2': // TTA v2.x - // "I have hurried to release the TTA 2.0 encoder. Format documentation is removed from our site. This format still in development. Please wait the TTA2 format, encoder v4." - $info['tta']['major_version'] = 2; - $info['avdataoffset'] += 20; + case '2': // TTA v2.x + // "I have hurried to release the TTA 2.0 encoder. Format documentation is removed from our site. This format still in development. Please wait the TTA2 format, encoder v4." + $info['tta']['major_version'] = 2; + $info['avdataoffset'] += 20; - $info['tta']['compression_level'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); - $info['tta']['audio_format'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2)); - $info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 2)); - $info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 10, 2)); - $info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 12, 4)); - $info['tta']['data_length'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 16, 4)); + $info['tta']['compression_level'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); + $info['tta']['audio_format'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2)); + $info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 2)); + $info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 10, 2)); + $info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 12, 4)); + $info['tta']['data_length'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 16, 4)); - $info['audio']['encoder_options'] = '-e'.$info['tta']['compression_level']; - $info['playtime_seconds'] = $info['tta']['data_length'] / $info['tta']['sample_rate']; - break; + $info['audio']['encoder_options'] = '-e'.$info['tta']['compression_level']; + $info['playtime_seconds'] = $info['tta']['data_length'] / $info['tta']['sample_rate']; + break; - case '1': // TTA v3.x - // "This is a first stable release of the TTA format. It will be supported by the encoders v3 or higher." - $info['tta']['major_version'] = 3; - $info['avdataoffset'] += 26; + case '1': // TTA v3.x + // "This is a first stable release of the TTA format. It will be supported by the encoders v3 or higher." + $info['tta']['major_version'] = 3; + $info['avdataoffset'] += 26; - $info['tta']['audio_format'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); // getid3_riff::wFormatTagLookup() - $info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2)); - $info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 2)); - $info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 10, 4)); - $info['tta']['data_length'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 14, 4)); - $info['tta']['crc32_footer'] = substr($ttaheader, 18, 4); - $info['tta']['seek_point'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 22, 4)); + $info['tta']['audio_format'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); // getid3_riff::wFormatTagLookup() + $info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2)); + $info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 2)); + $info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 10, 4)); + $info['tta']['data_length'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 14, 4)); + $info['tta']['crc32_footer'] = substr($ttaheader, 18, 4); + $info['tta']['seek_point'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 22, 4)); - $info['playtime_seconds'] = $info['tta']['data_length'] / $info['tta']['sample_rate']; - break; + $info['playtime_seconds'] = $info['tta']['data_length'] / $info['tta']['sample_rate']; + break; - default: - $this->error('This version of getID3() ['.$this->getid3->version().'] only knows how to handle TTA v1 and v2 - it may not work correctly with this file which appears to be TTA v'.$ttaheader{3}); - return false; - break; - } + default: + $this->error('This version of getID3() ['.$this->getid3->version().'] only knows how to handle TTA v1 and v2 - it may not work correctly with this file which appears to be TTA v'.$ttaheader[3]); - $info['audio']['encoder'] = 'TTA v'.$info['tta']['major_version']; - $info['audio']['bits_per_sample'] = $info['tta']['bits_per_sample']; - $info['audio']['sample_rate'] = $info['tta']['sample_rate']; - $info['audio']['channels'] = $info['tta']['channels']; - $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + return false; + break; + } - return true; - } + $info['audio']['encoder'] = 'TTA v'.$info['tta']['major_version']; + $info['audio']['bits_per_sample'] = $info['tta']['bits_per_sample']; + $info['audio']['sample_rate'] = $info['tta']['sample_rate']; + $info['audio']['channels'] = $info['tta']['channels']; + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + return true; + } } diff --git a/app/Library/getid3/getid3/module.audio.voc.php b/app/Library/getid3/getid3/module.audio.voc.php index 3803d8a1..87ded79e 100644 --- a/app/Library/getid3/getid3/module.audio.voc.php +++ b/app/Library/getid3/getid3/module.audio.voc.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,192 +15,195 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_voc extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $OriginalAVdataOffset = $info['avdataoffset']; + $this->fseek($info['avdataoffset']); + $VOCheader = $this->fread(26); - $OriginalAVdataOffset = $info['avdataoffset']; - $this->fseek($info['avdataoffset']); - $VOCheader = $this->fread(26); + $magic = 'Creative Voice File'; + if (substr($VOCheader, 0, 19) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($VOCheader, 0, 19)).'"'); - $magic = 'Creative Voice File'; - if (substr($VOCheader, 0, 19) != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($VOCheader, 0, 19)).'"'); - return false; - } + return false; + } - // shortcuts - $thisfile_audio = &$info['audio']; - $info['voc'] = array(); - $thisfile_voc = &$info['voc']; + // shortcuts + $thisfile_audio = &$info['audio']; + $info['voc'] = []; + $thisfile_voc = &$info['voc']; - $info['fileformat'] = 'voc'; - $thisfile_audio['dataformat'] = 'voc'; - $thisfile_audio['bitrate_mode'] = 'cbr'; - $thisfile_audio['lossless'] = true; - $thisfile_audio['channels'] = 1; // might be overriden below - $thisfile_audio['bits_per_sample'] = 8; // might be overriden below + $info['fileformat'] = 'voc'; + $thisfile_audio['dataformat'] = 'voc'; + $thisfile_audio['bitrate_mode'] = 'cbr'; + $thisfile_audio['lossless'] = true; + $thisfile_audio['channels'] = 1; // might be overriden below + $thisfile_audio['bits_per_sample'] = 8; // might be overriden below - // byte # Description - // ------ ------------------------------------------ - // 00-12 'Creative Voice File' - // 13 1A (eof to abort printing of file) - // 14-15 Offset of first datablock in .voc file (std 1A 00 in Intel Notation) - // 16-17 Version number (minor,major) (VOC-HDR puts 0A 01) - // 18-19 2's Comp of Ver. # + 1234h (VOC-HDR puts 29 11) + // byte # Description + // ------ ------------------------------------------ + // 00-12 'Creative Voice File' + // 13 1A (eof to abort printing of file) + // 14-15 Offset of first datablock in .voc file (std 1A 00 in Intel Notation) + // 16-17 Version number (minor,major) (VOC-HDR puts 0A 01) + // 18-19 2's Comp of Ver. # + 1234h (VOC-HDR puts 29 11) - $thisfile_voc['header']['datablock_offset'] = getid3_lib::LittleEndian2Int(substr($VOCheader, 20, 2)); - $thisfile_voc['header']['minor_version'] = getid3_lib::LittleEndian2Int(substr($VOCheader, 22, 1)); - $thisfile_voc['header']['major_version'] = getid3_lib::LittleEndian2Int(substr($VOCheader, 23, 1)); + $thisfile_voc['header']['datablock_offset'] = getid3_lib::LittleEndian2Int(substr($VOCheader, 20, 2)); + $thisfile_voc['header']['minor_version'] = getid3_lib::LittleEndian2Int(substr($VOCheader, 22, 1)); + $thisfile_voc['header']['major_version'] = getid3_lib::LittleEndian2Int(substr($VOCheader, 23, 1)); - do { + do { + $BlockOffset = $this->ftell(); + $BlockData = $this->fread(4); + $BlockType = ord($BlockData[0]); + $BlockSize = getid3_lib::LittleEndian2Int(substr($BlockData, 1, 3)); + $ThisBlock = []; - $BlockOffset = $this->ftell(); - $BlockData = $this->fread(4); - $BlockType = ord($BlockData{0}); - $BlockSize = getid3_lib::LittleEndian2Int(substr($BlockData, 1, 3)); - $ThisBlock = array(); + getid3_lib::safe_inc($thisfile_voc['blocktypes'][$BlockType], 1); + switch ($BlockType) { + case 0: // Terminator + // do nothing, we'll break out of the loop down below + break; - getid3_lib::safe_inc($thisfile_voc['blocktypes'][$BlockType], 1); - switch ($BlockType) { - case 0: // Terminator - // do nothing, we'll break out of the loop down below - break; + case 1: // Sound data + $BlockData .= $this->fread(2); + if ($info['avdataoffset'] <= $OriginalAVdataOffset) { + $info['avdataoffset'] = $this->ftell(); + } + $this->fseek($BlockSize - 2, SEEK_CUR); - case 1: // Sound data - $BlockData .= $this->fread(2); - if ($info['avdataoffset'] <= $OriginalAVdataOffset) { - $info['avdataoffset'] = $this->ftell(); - } - $this->fseek($BlockSize - 2, SEEK_CUR); + $ThisBlock['sample_rate_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 1)); + $ThisBlock['compression_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, 5, 1)); - $ThisBlock['sample_rate_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 1)); - $ThisBlock['compression_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, 5, 1)); + $ThisBlock['compression_name'] = $this->VOCcompressionTypeLookup($ThisBlock['compression_type']); + if ($ThisBlock['compression_type'] <= 3) { + $thisfile_voc['compressed_bits_per_sample'] = getid3_lib::CastAsInt(str_replace('-bit', '', $ThisBlock['compression_name'])); + } - $ThisBlock['compression_name'] = $this->VOCcompressionTypeLookup($ThisBlock['compression_type']); - if ($ThisBlock['compression_type'] <= 3) { - $thisfile_voc['compressed_bits_per_sample'] = getid3_lib::CastAsInt(str_replace('-bit', '', $ThisBlock['compression_name'])); - } + // Less accurate sample_rate calculation than the Extended block (#8) data (but better than nothing if Extended Block is not available) + if (empty($thisfile_audio['sample_rate'])) { + // SR byte = 256 - (1000000 / sample_rate) + $thisfile_audio['sample_rate'] = getid3_lib::trunc((1000000 / (256 - $ThisBlock['sample_rate_id'])) / $thisfile_audio['channels']); + } + break; - // Less accurate sample_rate calculation than the Extended block (#8) data (but better than nothing if Extended Block is not available) - if (empty($thisfile_audio['sample_rate'])) { - // SR byte = 256 - (1000000 / sample_rate) - $thisfile_audio['sample_rate'] = getid3_lib::trunc((1000000 / (256 - $ThisBlock['sample_rate_id'])) / $thisfile_audio['channels']); - } - break; + case 2: // Sound continue + case 3: // Silence + case 4: // Marker + case 6: // Repeat + case 7: // End repeat + // nothing useful, just skip + $this->fseek($BlockSize, SEEK_CUR); + break; - case 2: // Sound continue - case 3: // Silence - case 4: // Marker - case 6: // Repeat - case 7: // End repeat - // nothing useful, just skip - $this->fseek($BlockSize, SEEK_CUR); - break; + case 8: // Extended + $BlockData .= $this->fread(4); - case 8: // Extended - $BlockData .= $this->fread(4); + //00-01 Time Constant: + // Mono: 65536 - (256000000 / sample_rate) + // Stereo: 65536 - (256000000 / (sample_rate * 2)) + $ThisBlock['time_constant'] = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 2)); + $ThisBlock['pack_method'] = getid3_lib::LittleEndian2Int(substr($BlockData, 6, 1)); + $ThisBlock['stereo'] = (bool) getid3_lib::LittleEndian2Int(substr($BlockData, 7, 1)); - //00-01 Time Constant: - // Mono: 65536 - (256000000 / sample_rate) - // Stereo: 65536 - (256000000 / (sample_rate * 2)) - $ThisBlock['time_constant'] = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 2)); - $ThisBlock['pack_method'] = getid3_lib::LittleEndian2Int(substr($BlockData, 6, 1)); - $ThisBlock['stereo'] = (bool) getid3_lib::LittleEndian2Int(substr($BlockData, 7, 1)); + $thisfile_audio['channels'] = ($ThisBlock['stereo'] ? 2 : 1); + $thisfile_audio['sample_rate'] = getid3_lib::trunc((256000000 / (65536 - $ThisBlock['time_constant'])) / $thisfile_audio['channels']); + break; - $thisfile_audio['channels'] = ($ThisBlock['stereo'] ? 2 : 1); - $thisfile_audio['sample_rate'] = getid3_lib::trunc((256000000 / (65536 - $ThisBlock['time_constant'])) / $thisfile_audio['channels']); - break; + case 9: // data block that supersedes blocks 1 and 8. Used for stereo, 16 bit + $BlockData .= $this->fread(12); + if ($info['avdataoffset'] <= $OriginalAVdataOffset) { + $info['avdataoffset'] = $this->ftell(); + } + $this->fseek($BlockSize - 12, SEEK_CUR); - case 9: // data block that supersedes blocks 1 and 8. Used for stereo, 16 bit - $BlockData .= $this->fread(12); - if ($info['avdataoffset'] <= $OriginalAVdataOffset) { - $info['avdataoffset'] = $this->ftell(); - } - $this->fseek($BlockSize - 12, SEEK_CUR); + $ThisBlock['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 4)); + $ThisBlock['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($BlockData, 8, 1)); + $ThisBlock['channels'] = getid3_lib::LittleEndian2Int(substr($BlockData, 9, 1)); + $ThisBlock['wFormat'] = getid3_lib::LittleEndian2Int(substr($BlockData, 10, 2)); - $ThisBlock['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 4)); - $ThisBlock['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($BlockData, 8, 1)); - $ThisBlock['channels'] = getid3_lib::LittleEndian2Int(substr($BlockData, 9, 1)); - $ThisBlock['wFormat'] = getid3_lib::LittleEndian2Int(substr($BlockData, 10, 2)); + $ThisBlock['compression_name'] = $this->VOCwFormatLookup($ThisBlock['wFormat']); + if ($this->VOCwFormatActualBitsPerSampleLookup($ThisBlock['wFormat'])) { + $thisfile_voc['compressed_bits_per_sample'] = $this->VOCwFormatActualBitsPerSampleLookup($ThisBlock['wFormat']); + } - $ThisBlock['compression_name'] = $this->VOCwFormatLookup($ThisBlock['wFormat']); - if ($this->VOCwFormatActualBitsPerSampleLookup($ThisBlock['wFormat'])) { - $thisfile_voc['compressed_bits_per_sample'] = $this->VOCwFormatActualBitsPerSampleLookup($ThisBlock['wFormat']); - } + $thisfile_audio['sample_rate'] = $ThisBlock['sample_rate']; + $thisfile_audio['bits_per_sample'] = $ThisBlock['bits_per_sample']; + $thisfile_audio['channels'] = $ThisBlock['channels']; + break; - $thisfile_audio['sample_rate'] = $ThisBlock['sample_rate']; - $thisfile_audio['bits_per_sample'] = $ThisBlock['bits_per_sample']; - $thisfile_audio['channels'] = $ThisBlock['channels']; - break; + default: + $this->warning('Unhandled block type "'.$BlockType.'" at offset '.$BlockOffset); + $this->fseek($BlockSize, SEEK_CUR); + break; + } - default: - $this->warning('Unhandled block type "'.$BlockType.'" at offset '.$BlockOffset); - $this->fseek($BlockSize, SEEK_CUR); - break; - } + if (! empty($ThisBlock)) { + $ThisBlock['block_offset'] = $BlockOffset; + $ThisBlock['block_size'] = $BlockSize; + $ThisBlock['block_type_id'] = $BlockType; + $thisfile_voc['blocks'][] = $ThisBlock; + } + } while (! feof($this->getid3->fp) && ($BlockType != 0)); - if (!empty($ThisBlock)) { - $ThisBlock['block_offset'] = $BlockOffset; - $ThisBlock['block_size'] = $BlockSize; - $ThisBlock['block_type_id'] = $BlockType; - $thisfile_voc['blocks'][] = $ThisBlock; - } + // Terminator block doesn't have size field, so seek back 3 spaces + $this->fseek(-3, SEEK_CUR); - } while (!feof($this->getid3->fp) && ($BlockType != 0)); + ksort($thisfile_voc['blocktypes']); - // Terminator block doesn't have size field, so seek back 3 spaces - $this->fseek(-3, SEEK_CUR); + if (! empty($thisfile_voc['compressed_bits_per_sample'])) { + $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / ($thisfile_voc['compressed_bits_per_sample'] * $thisfile_audio['channels'] * $thisfile_audio['sample_rate']); + $thisfile_audio['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + } - ksort($thisfile_voc['blocktypes']); + return true; + } - if (!empty($thisfile_voc['compressed_bits_per_sample'])) { - $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / ($thisfile_voc['compressed_bits_per_sample'] * $thisfile_audio['channels'] * $thisfile_audio['sample_rate']); - $thisfile_audio['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; - } + public function VOCcompressionTypeLookup($index) + { + static $VOCcompressionTypeLookup = [ + 0 => '8-bit', + 1 => '4-bit', + 2 => '2.6-bit', + 3 => '2-bit', + ]; - return true; - } + return isset($VOCcompressionTypeLookup[$index]) ? $VOCcompressionTypeLookup[$index] : 'Multi DAC ('.($index - 3).') channels'; + } - public function VOCcompressionTypeLookup($index) { - static $VOCcompressionTypeLookup = array( - 0 => '8-bit', - 1 => '4-bit', - 2 => '2.6-bit', - 3 => '2-bit' - ); - return (isset($VOCcompressionTypeLookup[$index]) ? $VOCcompressionTypeLookup[$index] : 'Multi DAC ('.($index - 3).') channels'); - } + public function VOCwFormatLookup($index) + { + static $VOCwFormatLookup = [ + 0x0000 => '8-bit unsigned PCM', + 0x0001 => 'Creative 8-bit to 4-bit ADPCM', + 0x0002 => 'Creative 8-bit to 3-bit ADPCM', + 0x0003 => 'Creative 8-bit to 2-bit ADPCM', + 0x0004 => '16-bit signed PCM', + 0x0006 => 'CCITT a-Law', + 0x0007 => 'CCITT u-Law', + 0x2000 => 'Creative 16-bit to 4-bit ADPCM', + ]; - public function VOCwFormatLookup($index) { - static $VOCwFormatLookup = array( - 0x0000 => '8-bit unsigned PCM', - 0x0001 => 'Creative 8-bit to 4-bit ADPCM', - 0x0002 => 'Creative 8-bit to 3-bit ADPCM', - 0x0003 => 'Creative 8-bit to 2-bit ADPCM', - 0x0004 => '16-bit signed PCM', - 0x0006 => 'CCITT a-Law', - 0x0007 => 'CCITT u-Law', - 0x2000 => 'Creative 16-bit to 4-bit ADPCM' - ); - return (isset($VOCwFormatLookup[$index]) ? $VOCwFormatLookup[$index] : false); - } + return isset($VOCwFormatLookup[$index]) ? $VOCwFormatLookup[$index] : false; + } - public function VOCwFormatActualBitsPerSampleLookup($index) { - static $VOCwFormatLookup = array( - 0x0000 => 8, - 0x0001 => 4, - 0x0002 => 3, - 0x0003 => 2, - 0x0004 => 16, - 0x0006 => 8, - 0x0007 => 8, - 0x2000 => 4 - ); - return (isset($VOCwFormatLookup[$index]) ? $VOCwFormatLookup[$index] : false); - } + public function VOCwFormatActualBitsPerSampleLookup($index) + { + static $VOCwFormatLookup = [ + 0x0000 => 8, + 0x0001 => 4, + 0x0002 => 3, + 0x0003 => 2, + 0x0004 => 16, + 0x0006 => 8, + 0x0007 => 8, + 0x2000 => 4, + ]; + return isset($VOCwFormatLookup[$index]) ? $VOCwFormatLookup[$index] : false; + } } diff --git a/app/Library/getid3/getid3/module.audio.vqf.php b/app/Library/getid3/getid3/module.audio.vqf.php index a6a391c4..7bebc17d 100644 --- a/app/Library/getid3/getid3/module.audio.vqf.php +++ b/app/Library/getid3/getid3/module.audio.vqf.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,147 +15,151 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_vqf extends getid3_handler { - public function Analyze() { - $info = &$this->getid3->info; + public function Analyze() + { + $info = &$this->getid3->info; - // based loosely on code from TTwinVQ by Jurgen Faul - // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html + // based loosely on code from TTwinVQ by Jurgen Faul + // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html - $info['fileformat'] = 'vqf'; - $info['audio']['dataformat'] = 'vqf'; - $info['audio']['bitrate_mode'] = 'cbr'; - $info['audio']['lossless'] = false; + $info['fileformat'] = 'vqf'; + $info['audio']['dataformat'] = 'vqf'; + $info['audio']['bitrate_mode'] = 'cbr'; + $info['audio']['lossless'] = false; - // shortcut - $info['vqf']['raw'] = array(); - $thisfile_vqf = &$info['vqf']; - $thisfile_vqf_raw = &$thisfile_vqf['raw']; + // shortcut + $info['vqf']['raw'] = []; + $thisfile_vqf = &$info['vqf']; + $thisfile_vqf_raw = &$thisfile_vqf['raw']; - $this->fseek($info['avdataoffset']); - $VQFheaderData = $this->fread(16); + $this->fseek($info['avdataoffset']); + $VQFheaderData = $this->fread(16); - $offset = 0; - $thisfile_vqf_raw['header_tag'] = substr($VQFheaderData, $offset, 4); - $magic = 'TWIN'; - if ($thisfile_vqf_raw['header_tag'] != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($thisfile_vqf_raw['header_tag']).'"'); - unset($info['vqf']); - unset($info['fileformat']); - return false; - } - $offset += 4; - $thisfile_vqf_raw['version'] = substr($VQFheaderData, $offset, 8); - $offset += 8; - $thisfile_vqf_raw['size'] = getid3_lib::BigEndian2Int(substr($VQFheaderData, $offset, 4)); - $offset += 4; + $offset = 0; + $thisfile_vqf_raw['header_tag'] = substr($VQFheaderData, $offset, 4); + $magic = 'TWIN'; + if ($thisfile_vqf_raw['header_tag'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($thisfile_vqf_raw['header_tag']).'"'); + unset($info['vqf']); + unset($info['fileformat']); - while ($this->ftell() < $info['avdataend']) { + return false; + } + $offset += 4; + $thisfile_vqf_raw['version'] = substr($VQFheaderData, $offset, 8); + $offset += 8; + $thisfile_vqf_raw['size'] = getid3_lib::BigEndian2Int(substr($VQFheaderData, $offset, 4)); + $offset += 4; - $ChunkBaseOffset = $this->ftell(); - $chunkoffset = 0; - $ChunkData = $this->fread(8); - $ChunkName = substr($ChunkData, $chunkoffset, 4); - if ($ChunkName == 'DATA') { - $info['avdataoffset'] = $ChunkBaseOffset; - break; - } - $chunkoffset += 4; - $ChunkSize = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); - $chunkoffset += 4; - if ($ChunkSize > ($info['avdataend'] - $this->ftell())) { - $this->error('Invalid chunk size ('.$ChunkSize.') for chunk "'.$ChunkName.'" at offset '.$ChunkBaseOffset); - break; - } - if ($ChunkSize > 0) { - $ChunkData .= $this->fread($ChunkSize); - } + while ($this->ftell() < $info['avdataend']) { + $ChunkBaseOffset = $this->ftell(); + $chunkoffset = 0; + $ChunkData = $this->fread(8); + $ChunkName = substr($ChunkData, $chunkoffset, 4); + if ($ChunkName == 'DATA') { + $info['avdataoffset'] = $ChunkBaseOffset; + break; + } + $chunkoffset += 4; + $ChunkSize = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); + $chunkoffset += 4; + if ($ChunkSize > ($info['avdataend'] - $this->ftell())) { + $this->error('Invalid chunk size ('.$ChunkSize.') for chunk "'.$ChunkName.'" at offset '.$ChunkBaseOffset); + break; + } + if ($ChunkSize > 0) { + $ChunkData .= $this->fread($ChunkSize); + } - switch ($ChunkName) { - case 'COMM': - // shortcut - $thisfile_vqf['COMM'] = array(); - $thisfile_vqf_COMM = &$thisfile_vqf['COMM']; + switch ($ChunkName) { + case 'COMM': + // shortcut + $thisfile_vqf['COMM'] = []; + $thisfile_vqf_COMM = &$thisfile_vqf['COMM']; - $thisfile_vqf_COMM['channel_mode'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); - $chunkoffset += 4; - $thisfile_vqf_COMM['bitrate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); - $chunkoffset += 4; - $thisfile_vqf_COMM['sample_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); - $chunkoffset += 4; - $thisfile_vqf_COMM['security_level'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); - $chunkoffset += 4; + $thisfile_vqf_COMM['channel_mode'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); + $chunkoffset += 4; + $thisfile_vqf_COMM['bitrate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); + $chunkoffset += 4; + $thisfile_vqf_COMM['sample_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); + $chunkoffset += 4; + $thisfile_vqf_COMM['security_level'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); + $chunkoffset += 4; - $info['audio']['channels'] = $thisfile_vqf_COMM['channel_mode'] + 1; - $info['audio']['sample_rate'] = $this->VQFchannelFrequencyLookup($thisfile_vqf_COMM['sample_rate']); - $info['audio']['bitrate'] = $thisfile_vqf_COMM['bitrate'] * 1000; - $info['audio']['encoder_options'] = 'CBR' . ceil($info['audio']['bitrate']/1000); + $info['audio']['channels'] = $thisfile_vqf_COMM['channel_mode'] + 1; + $info['audio']['sample_rate'] = $this->VQFchannelFrequencyLookup($thisfile_vqf_COMM['sample_rate']); + $info['audio']['bitrate'] = $thisfile_vqf_COMM['bitrate'] * 1000; + $info['audio']['encoder_options'] = 'CBR'.ceil($info['audio']['bitrate'] / 1000); - if ($info['audio']['bitrate'] == 0) { - $this->error('Corrupt VQF file: bitrate_audio == zero'); - return false; - } - break; + if ($info['audio']['bitrate'] == 0) { + $this->error('Corrupt VQF file: bitrate_audio == zero'); - case 'NAME': - case 'AUTH': - case '(c) ': - case 'FILE': - case 'COMT': - case 'ALBM': - $thisfile_vqf['comments'][$this->VQFcommentNiceNameLookup($ChunkName)][] = trim(substr($ChunkData, 8)); - break; + return false; + } + break; - case 'DSIZ': - $thisfile_vqf['DSIZ'] = getid3_lib::BigEndian2Int(substr($ChunkData, 8, 4)); - break; + case 'NAME': + case 'AUTH': + case '(c) ': + case 'FILE': + case 'COMT': + case 'ALBM': + $thisfile_vqf['comments'][$this->VQFcommentNiceNameLookup($ChunkName)][] = trim(substr($ChunkData, 8)); + break; - default: - $this->warning('Unhandled chunk type "'.$ChunkName.'" at offset '.$ChunkBaseOffset); - break; - } - } + case 'DSIZ': + $thisfile_vqf['DSIZ'] = getid3_lib::BigEndian2Int(substr($ChunkData, 8, 4)); + break; - $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['audio']['bitrate']; + default: + $this->warning('Unhandled chunk type "'.$ChunkName.'" at offset '.$ChunkBaseOffset); + break; + } + } - if (isset($thisfile_vqf['DSIZ']) && (($thisfile_vqf['DSIZ'] != ($info['avdataend'] - $info['avdataoffset'] - strlen('DATA'))))) { - switch ($thisfile_vqf['DSIZ']) { - case 0: - case 1: - $this->warning('Invalid DSIZ value "'.$thisfile_vqf['DSIZ'].'". This is known to happen with VQF files encoded by Ahead Nero, and seems to be its way of saying this is TwinVQF v'.($thisfile_vqf['DSIZ'] + 1).'.0'); - $info['audio']['encoder'] = 'Ahead Nero'; - break; + $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['audio']['bitrate']; - default: - $this->warning('Probable corrupted file - should be '.$thisfile_vqf['DSIZ'].' bytes, actually '.($info['avdataend'] - $info['avdataoffset'] - strlen('DATA'))); - break; - } - } + if (isset($thisfile_vqf['DSIZ']) && (($thisfile_vqf['DSIZ'] != ($info['avdataend'] - $info['avdataoffset'] - strlen('DATA'))))) { + switch ($thisfile_vqf['DSIZ']) { + case 0: + case 1: + $this->warning('Invalid DSIZ value "'.$thisfile_vqf['DSIZ'].'". This is known to happen with VQF files encoded by Ahead Nero, and seems to be its way of saying this is TwinVQF v'.($thisfile_vqf['DSIZ'] + 1).'.0'); + $info['audio']['encoder'] = 'Ahead Nero'; + break; - return true; - } + default: + $this->warning('Probable corrupted file - should be '.$thisfile_vqf['DSIZ'].' bytes, actually '.($info['avdataend'] - $info['avdataoffset'] - strlen('DATA'))); + break; + } + } - public function VQFchannelFrequencyLookup($frequencyid) { - static $VQFchannelFrequencyLookup = array( - 11 => 11025, - 22 => 22050, - 44 => 44100 - ); - return (isset($VQFchannelFrequencyLookup[$frequencyid]) ? $VQFchannelFrequencyLookup[$frequencyid] : $frequencyid * 1000); - } + return true; + } - public function VQFcommentNiceNameLookup($shortname) { - static $VQFcommentNiceNameLookup = array( - 'NAME' => 'title', - 'AUTH' => 'artist', - '(c) ' => 'copyright', - 'FILE' => 'filename', - 'COMT' => 'comment', - 'ALBM' => 'album' - ); - return (isset($VQFcommentNiceNameLookup[$shortname]) ? $VQFcommentNiceNameLookup[$shortname] : $shortname); - } + public function VQFchannelFrequencyLookup($frequencyid) + { + static $VQFchannelFrequencyLookup = [ + 11 => 11025, + 22 => 22050, + 44 => 44100, + ]; + return isset($VQFchannelFrequencyLookup[$frequencyid]) ? $VQFchannelFrequencyLookup[$frequencyid] : $frequencyid * 1000; + } + + public function VQFcommentNiceNameLookup($shortname) + { + static $VQFcommentNiceNameLookup = [ + 'NAME' => 'title', + 'AUTH' => 'artist', + '(c) ' => 'copyright', + 'FILE' => 'filename', + 'COMT' => 'comment', + 'ALBM' => 'album', + ]; + + return isset($VQFcommentNiceNameLookup[$shortname]) ? $VQFcommentNiceNameLookup[$shortname] : $shortname; + } } diff --git a/app/Library/getid3/getid3/module.audio.wavpack.php b/app/Library/getid3/getid3/module.audio.wavpack.php index b54c179f..96dd5646 100644 --- a/app/Library/getid3/getid3/module.audio.wavpack.php +++ b/app/Library/getid3/getid3/module.audio.wavpack.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,385 +15,369 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_wavpack extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); - $this->fseek($info['avdataoffset']); + while (true) { + $wavpackheader = $this->fread(32); - while (true) { + if ($this->ftell() >= $info['avdataend']) { + break; + } elseif (feof($this->getid3->fp)) { + break; + } elseif ( + isset($info['wavpack']['blockheader']['total_samples']) && + isset($info['wavpack']['blockheader']['block_samples']) && + ($info['wavpack']['blockheader']['total_samples'] > 0) && + ($info['wavpack']['blockheader']['block_samples'] > 0) && + (! isset($info['wavpack']['riff_trailer_size']) || ($info['wavpack']['riff_trailer_size'] <= 0)) && + ((isset($info['wavpack']['config_flags']['md5_checksum']) && ($info['wavpack']['config_flags']['md5_checksum'] === false)) || ! empty($info['md5_data_source']))) { + break; + } - $wavpackheader = $this->fread(32); + $blockheader_offset = $this->ftell() - 32; + $blockheader_magic = substr($wavpackheader, 0, 4); + $blockheader_size = getid3_lib::LittleEndian2Int(substr($wavpackheader, 4, 4)); - if ($this->ftell() >= $info['avdataend']) { - break; - } elseif (feof($this->getid3->fp)) { - break; - } elseif ( - isset($info['wavpack']['blockheader']['total_samples']) && - isset($info['wavpack']['blockheader']['block_samples']) && - ($info['wavpack']['blockheader']['total_samples'] > 0) && - ($info['wavpack']['blockheader']['block_samples'] > 0) && - (!isset($info['wavpack']['riff_trailer_size']) || ($info['wavpack']['riff_trailer_size'] <= 0)) && - ((isset($info['wavpack']['config_flags']['md5_checksum']) && ($info['wavpack']['config_flags']['md5_checksum'] === false)) || !empty($info['md5_data_source']))) { - break; - } + $magic = 'wvpk'; + if ($blockheader_magic != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$blockheader_offset.', found "'.getid3_lib::PrintHexBytes($blockheader_magic).'"'); + switch (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '') { + case 'wavpack': + case 'wvc': + break; + default: + unset($info['fileformat']); + unset($info['audio']); + unset($info['wavpack']); + break; + } - $blockheader_offset = $this->ftell() - 32; - $blockheader_magic = substr($wavpackheader, 0, 4); - $blockheader_size = getid3_lib::LittleEndian2Int(substr($wavpackheader, 4, 4)); + return false; + } - $magic = 'wvpk'; - if ($blockheader_magic != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$blockheader_offset.', found "'.getid3_lib::PrintHexBytes($blockheader_magic).'"'); - switch (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '') { - case 'wavpack': - case 'wvc': - break; - default: - unset($info['fileformat']); - unset($info['audio']); - unset($info['wavpack']); - break; - } - return false; - } + if (empty($info['wavpack']['blockheader']['block_samples']) || + empty($info['wavpack']['blockheader']['total_samples']) || + ($info['wavpack']['blockheader']['block_samples'] <= 0) || + ($info['wavpack']['blockheader']['total_samples'] <= 0)) { + // Also, it is possible that the first block might not have + // any samples (block_samples == 0) and in this case you should skip blocks + // until you find one with samples because the other information (like + // total_samples) are not guaranteed to be correct until (block_samples > 0) - if (empty($info['wavpack']['blockheader']['block_samples']) || - empty($info['wavpack']['blockheader']['total_samples']) || - ($info['wavpack']['blockheader']['block_samples'] <= 0) || - ($info['wavpack']['blockheader']['total_samples'] <= 0)) { - // Also, it is possible that the first block might not have - // any samples (block_samples == 0) and in this case you should skip blocks - // until you find one with samples because the other information (like - // total_samples) are not guaranteed to be correct until (block_samples > 0) + // Finally, I have defined a format for files in which the length is not known + // (for example when raw files are created using pipes). In these cases + // total_samples will be -1 and you must seek to the final block to determine + // the total number of samples. - // Finally, I have defined a format for files in which the length is not known - // (for example when raw files are created using pipes). In these cases - // total_samples will be -1 and you must seek to the final block to determine - // the total number of samples. + $info['audio']['dataformat'] = 'wavpack'; + $info['fileformat'] = 'wavpack'; + $info['audio']['lossless'] = true; + $info['audio']['bitrate_mode'] = 'vbr'; + $info['wavpack']['blockheader']['offset'] = $blockheader_offset; + $info['wavpack']['blockheader']['magic'] = $blockheader_magic; + $info['wavpack']['blockheader']['size'] = $blockheader_size; - $info['audio']['dataformat'] = 'wavpack'; - $info['fileformat'] = 'wavpack'; - $info['audio']['lossless'] = true; - $info['audio']['bitrate_mode'] = 'vbr'; + if ($info['wavpack']['blockheader']['size'] >= 0x100000) { + $this->error('Expecting WavPack block size less than "0x100000", found "'.$info['wavpack']['blockheader']['size'].'" at offset '.$info['wavpack']['blockheader']['offset']); + switch (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '') { + case 'wavpack': + case 'wvc': + break; + default: + unset($info['fileformat']); + unset($info['audio']); + unset($info['wavpack']); + break; + } - $info['wavpack']['blockheader']['offset'] = $blockheader_offset; - $info['wavpack']['blockheader']['magic'] = $blockheader_magic; - $info['wavpack']['blockheader']['size'] = $blockheader_size; + return false; + } - if ($info['wavpack']['blockheader']['size'] >= 0x100000) { - $this->error('Expecting WavPack block size less than "0x100000", found "'.$info['wavpack']['blockheader']['size'].'" at offset '.$info['wavpack']['blockheader']['offset']); - switch (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '') { - case 'wavpack': - case 'wvc': - break; - default: - unset($info['fileformat']); - unset($info['audio']); - unset($info['wavpack']); - break; - } - return false; - } + $info['wavpack']['blockheader']['minor_version'] = ord($wavpackheader[8]); + $info['wavpack']['blockheader']['major_version'] = ord($wavpackheader[9]); - $info['wavpack']['blockheader']['minor_version'] = ord($wavpackheader{8}); - $info['wavpack']['blockheader']['major_version'] = ord($wavpackheader{9}); + if (($info['wavpack']['blockheader']['major_version'] != 4) || + (($info['wavpack']['blockheader']['minor_version'] < 4) && + ($info['wavpack']['blockheader']['minor_version'] > 16))) { + $this->error('Expecting WavPack version between "4.2" and "4.16", found version "'.$info['wavpack']['blockheader']['major_version'].'.'.$info['wavpack']['blockheader']['minor_version'].'" at offset '.$info['wavpack']['blockheader']['offset']); + switch (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '') { + case 'wavpack': + case 'wvc': + break; + default: + unset($info['fileformat']); + unset($info['audio']); + unset($info['wavpack']); + break; + } - if (($info['wavpack']['blockheader']['major_version'] != 4) || - (($info['wavpack']['blockheader']['minor_version'] < 4) && - ($info['wavpack']['blockheader']['minor_version'] > 16))) { - $this->error('Expecting WavPack version between "4.2" and "4.16", found version "'.$info['wavpack']['blockheader']['major_version'].'.'.$info['wavpack']['blockheader']['minor_version'].'" at offset '.$info['wavpack']['blockheader']['offset']); - switch (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '') { - case 'wavpack': - case 'wvc': - break; - default: - unset($info['fileformat']); - unset($info['audio']); - unset($info['wavpack']); - break; - } - return false; - } + return false; + } - $info['wavpack']['blockheader']['track_number'] = ord($wavpackheader{10}); // unused - $info['wavpack']['blockheader']['index_number'] = ord($wavpackheader{11}); // unused - $info['wavpack']['blockheader']['total_samples'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 12, 4)); - $info['wavpack']['blockheader']['block_index'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 16, 4)); - $info['wavpack']['blockheader']['block_samples'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 20, 4)); - $info['wavpack']['blockheader']['flags_raw'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 24, 4)); - $info['wavpack']['blockheader']['crc'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 28, 4)); + $info['wavpack']['blockheader']['track_number'] = ord($wavpackheader[10]); // unused + $info['wavpack']['blockheader']['index_number'] = ord($wavpackheader[11]); // unused + $info['wavpack']['blockheader']['total_samples'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 12, 4)); + $info['wavpack']['blockheader']['block_index'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 16, 4)); + $info['wavpack']['blockheader']['block_samples'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 20, 4)); + $info['wavpack']['blockheader']['flags_raw'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 24, 4)); + $info['wavpack']['blockheader']['crc'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 28, 4)); - $info['wavpack']['blockheader']['flags']['bytes_per_sample'] = 1 + ($info['wavpack']['blockheader']['flags_raw'] & 0x00000003); - $info['wavpack']['blockheader']['flags']['mono'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000004); - $info['wavpack']['blockheader']['flags']['hybrid'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000008); - $info['wavpack']['blockheader']['flags']['joint_stereo'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000010); - $info['wavpack']['blockheader']['flags']['cross_decorrelation'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000020); - $info['wavpack']['blockheader']['flags']['hybrid_noiseshape'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000040); - $info['wavpack']['blockheader']['flags']['ieee_32bit_float'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000080); - $info['wavpack']['blockheader']['flags']['int_32bit'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000100); - $info['wavpack']['blockheader']['flags']['hybrid_bitrate_noise'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000200); - $info['wavpack']['blockheader']['flags']['hybrid_balance_noise'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000400); - $info['wavpack']['blockheader']['flags']['multichannel_initial'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000800); - $info['wavpack']['blockheader']['flags']['multichannel_final'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00001000); + $info['wavpack']['blockheader']['flags']['bytes_per_sample'] = 1 + ($info['wavpack']['blockheader']['flags_raw'] & 0x00000003); + $info['wavpack']['blockheader']['flags']['mono'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000004); + $info['wavpack']['blockheader']['flags']['hybrid'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000008); + $info['wavpack']['blockheader']['flags']['joint_stereo'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000010); + $info['wavpack']['blockheader']['flags']['cross_decorrelation'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000020); + $info['wavpack']['blockheader']['flags']['hybrid_noiseshape'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000040); + $info['wavpack']['blockheader']['flags']['ieee_32bit_float'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000080); + $info['wavpack']['blockheader']['flags']['int_32bit'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000100); + $info['wavpack']['blockheader']['flags']['hybrid_bitrate_noise'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000200); + $info['wavpack']['blockheader']['flags']['hybrid_balance_noise'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000400); + $info['wavpack']['blockheader']['flags']['multichannel_initial'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000800); + $info['wavpack']['blockheader']['flags']['multichannel_final'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00001000); - $info['audio']['lossless'] = !$info['wavpack']['blockheader']['flags']['hybrid']; - } + $info['audio']['lossless'] = ! $info['wavpack']['blockheader']['flags']['hybrid']; + } - while (!feof($this->getid3->fp) && ($this->ftell() < ($blockheader_offset + $blockheader_size + 8))) { + while (! feof($this->getid3->fp) && ($this->ftell() < ($blockheader_offset + $blockheader_size + 8))) { + $metablock = ['offset'=>$this->ftell()]; + $metablockheader = $this->fread(2); + if (feof($this->getid3->fp)) { + break; + } + $metablock['id'] = ord($metablockheader[0]); + $metablock['function_id'] = ($metablock['id'] & 0x3F); + $metablock['function_name'] = $this->WavPackMetablockNameLookup($metablock['function_id']); - $metablock = array('offset'=>$this->ftell()); - $metablockheader = $this->fread(2); - if (feof($this->getid3->fp)) { - break; - } - $metablock['id'] = ord($metablockheader{0}); - $metablock['function_id'] = ($metablock['id'] & 0x3F); - $metablock['function_name'] = $this->WavPackMetablockNameLookup($metablock['function_id']); + // The 0x20 bit in the id of the meta subblocks (which is defined as + // ID_OPTIONAL_DATA) is a permanent part of the id. The idea is that + // if a decoder encounters an id that it does not know about, it uses + // that "ID_OPTIONAL_DATA" flag to determine what to do. If it is set + // then the decoder simply ignores the metadata, but if it is zero + // then the decoder should quit because it means that an understanding + // of the metadata is required to correctly decode the audio. + $metablock['non_decoder'] = (bool) ($metablock['id'] & 0x20); - // The 0x20 bit in the id of the meta subblocks (which is defined as - // ID_OPTIONAL_DATA) is a permanent part of the id. The idea is that - // if a decoder encounters an id that it does not know about, it uses - // that "ID_OPTIONAL_DATA" flag to determine what to do. If it is set - // then the decoder simply ignores the metadata, but if it is zero - // then the decoder should quit because it means that an understanding - // of the metadata is required to correctly decode the audio. - $metablock['non_decoder'] = (bool) ($metablock['id'] & 0x20); + $metablock['padded_data'] = (bool) ($metablock['id'] & 0x40); + $metablock['large_block'] = (bool) ($metablock['id'] & 0x80); + if ($metablock['large_block']) { + $metablockheader .= $this->fread(2); + } + $metablock['size'] = getid3_lib::LittleEndian2Int(substr($metablockheader, 1)) * 2; // size is stored in words + $metablock['data'] = null; - $metablock['padded_data'] = (bool) ($metablock['id'] & 0x40); - $metablock['large_block'] = (bool) ($metablock['id'] & 0x80); - if ($metablock['large_block']) { - $metablockheader .= $this->fread(2); - } - $metablock['size'] = getid3_lib::LittleEndian2Int(substr($metablockheader, 1)) * 2; // size is stored in words - $metablock['data'] = null; + if ($metablock['size'] > 0) { + switch ($metablock['function_id']) { + case 0x21: // ID_RIFF_HEADER + case 0x22: // ID_RIFF_TRAILER + case 0x23: // ID_REPLAY_GAIN + case 0x24: // ID_CUESHEET + case 0x25: // ID_CONFIG_BLOCK + case 0x26: // ID_MD5_CHECKSUM + $metablock['data'] = $this->fread($metablock['size']); - if ($metablock['size'] > 0) { + if ($metablock['padded_data']) { + // padded to the nearest even byte + $metablock['size']--; + $metablock['data'] = substr($metablock['data'], 0, -1); + } + break; - switch ($metablock['function_id']) { - case 0x21: // ID_RIFF_HEADER - case 0x22: // ID_RIFF_TRAILER - case 0x23: // ID_REPLAY_GAIN - case 0x24: // ID_CUESHEET - case 0x25: // ID_CONFIG_BLOCK - case 0x26: // ID_MD5_CHECKSUM - $metablock['data'] = $this->fread($metablock['size']); + case 0x00: // ID_DUMMY + case 0x01: // ID_ENCODER_INFO + case 0x02: // ID_DECORR_TERMS + case 0x03: // ID_DECORR_WEIGHTS + case 0x04: // ID_DECORR_SAMPLES + case 0x05: // ID_ENTROPY_VARS + case 0x06: // ID_HYBRID_PROFILE + case 0x07: // ID_SHAPING_WEIGHTS + case 0x08: // ID_FLOAT_INFO + case 0x09: // ID_INT32_INFO + case 0x0A: // ID_WV_BITSTREAM + case 0x0B: // ID_WVC_BITSTREAM + case 0x0C: // ID_WVX_BITSTREAM + case 0x0D: // ID_CHANNEL_INFO + $this->fseek($metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size']); + break; - if ($metablock['padded_data']) { - // padded to the nearest even byte - $metablock['size']--; - $metablock['data'] = substr($metablock['data'], 0, -1); - } - break; + default: + $this->warning('Unexpected metablock type "0x'.str_pad(dechex($metablock['function_id']), 2, '0', STR_PAD_LEFT).'" at offset '.$metablock['offset']); + $this->fseek($metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size']); + break; + } - case 0x00: // ID_DUMMY - case 0x01: // ID_ENCODER_INFO - case 0x02: // ID_DECORR_TERMS - case 0x03: // ID_DECORR_WEIGHTS - case 0x04: // ID_DECORR_SAMPLES - case 0x05: // ID_ENTROPY_VARS - case 0x06: // ID_HYBRID_PROFILE - case 0x07: // ID_SHAPING_WEIGHTS - case 0x08: // ID_FLOAT_INFO - case 0x09: // ID_INT32_INFO - case 0x0A: // ID_WV_BITSTREAM - case 0x0B: // ID_WVC_BITSTREAM - case 0x0C: // ID_WVX_BITSTREAM - case 0x0D: // ID_CHANNEL_INFO - $this->fseek($metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size']); - break; + switch ($metablock['function_id']) { + case 0x21: // ID_RIFF_HEADER + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); + $original_wav_filesize = getid3_lib::LittleEndian2Int(substr($metablock['data'], 4, 4)); - default: - $this->warning('Unexpected metablock type "0x'.str_pad(dechex($metablock['function_id']), 2, '0', STR_PAD_LEFT).'" at offset '.$metablock['offset']); - $this->fseek($metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size']); - break; - } + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_riff = new getid3_riff($getid3_temp); + $getid3_riff->ParseRIFFdata($metablock['data']); + $metablock['riff'] = $getid3_temp->info['riff']; + $info['audio']['sample_rate'] = $getid3_temp->info['riff']['raw']['fmt ']['nSamplesPerSec']; + unset($getid3_riff, $getid3_temp); - switch ($metablock['function_id']) { - case 0x21: // ID_RIFF_HEADER - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); - $original_wav_filesize = getid3_lib::LittleEndian2Int(substr($metablock['data'], 4, 4)); + $metablock['riff']['original_filesize'] = $original_wav_filesize; + $info['wavpack']['riff_trailer_size'] = $original_wav_filesize - $metablock['riff']['WAVE']['data'][0]['size'] - $metablock['riff']['header_size']; + $info['playtime_seconds'] = $info['wavpack']['blockheader']['total_samples'] / $info['audio']['sample_rate']; - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_riff = new getid3_riff($getid3_temp); - $getid3_riff->ParseRIFFdata($metablock['data']); - $metablock['riff'] = $getid3_temp->info['riff']; - $info['audio']['sample_rate'] = $getid3_temp->info['riff']['raw']['fmt ']['nSamplesPerSec']; - unset($getid3_riff, $getid3_temp); + // Safe RIFF header in case there's a RIFF footer later + $metablockRIFFheader = $metablock['data']; + break; - $metablock['riff']['original_filesize'] = $original_wav_filesize; - $info['wavpack']['riff_trailer_size'] = $original_wav_filesize - $metablock['riff']['WAVE']['data'][0]['size'] - $metablock['riff']['header_size']; - $info['playtime_seconds'] = $info['wavpack']['blockheader']['total_samples'] / $info['audio']['sample_rate']; + case 0x22: // ID_RIFF_TRAILER + $metablockRIFFfooter = $metablockRIFFheader.$metablock['data']; + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); - // Safe RIFF header in case there's a RIFF footer later - $metablockRIFFheader = $metablock['data']; - break; + $startoffset = $metablock['offset'] + ($metablock['large_block'] ? 4 : 2); + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_temp->info['avdataend'] = $info['avdataend']; + //$getid3_temp->info['fileformat'] = 'riff'; + $getid3_riff = new getid3_riff($getid3_temp); + $metablock['riff'] = $getid3_riff->ParseRIFF($startoffset, $startoffset + $metablock['size']); + if (! empty($metablock['riff']['INFO'])) { + getid3_riff::parseComments($metablock['riff']['INFO'], $metablock['comments']); + $info['tags']['riff'] = $metablock['comments']; + } + unset($getid3_temp, $getid3_riff); + break; - case 0x22: // ID_RIFF_TRAILER - $metablockRIFFfooter = $metablockRIFFheader.$metablock['data']; - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); + case 0x23: // ID_REPLAY_GAIN + $this->warning('WavPack "Replay Gain" contents not yet handled by getID3() in metablock at offset '.$metablock['offset']); + break; - $startoffset = $metablock['offset'] + ($metablock['large_block'] ? 4 : 2); - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_temp->info['avdataend'] = $info['avdataend']; - //$getid3_temp->info['fileformat'] = 'riff'; - $getid3_riff = new getid3_riff($getid3_temp); - $metablock['riff'] = $getid3_riff->ParseRIFF($startoffset, $startoffset + $metablock['size']); + case 0x24: // ID_CUESHEET + $this->warning('WavPack "Cuesheet" contents not yet handled by getID3() in metablock at offset '.$metablock['offset']); + break; - if (!empty($metablock['riff']['INFO'])) { - getid3_riff::parseComments($metablock['riff']['INFO'], $metablock['comments']); - $info['tags']['riff'] = $metablock['comments']; - } - unset($getid3_temp, $getid3_riff); - break; + case 0x25: // ID_CONFIG_BLOCK + $metablock['flags_raw'] = getid3_lib::LittleEndian2Int(substr($metablock['data'], 0, 3)); + $metablock['flags']['adobe_mode'] = (bool) ($metablock['flags_raw'] & 0x000001); // "adobe" mode for 32-bit floats + $metablock['flags']['fast_flag'] = (bool) ($metablock['flags_raw'] & 0x000002); // fast mode + $metablock['flags']['very_fast_flag'] = (bool) ($metablock['flags_raw'] & 0x000004); // double fast + $metablock['flags']['high_flag'] = (bool) ($metablock['flags_raw'] & 0x000008); // high quality mode + $metablock['flags']['very_high_flag'] = (bool) ($metablock['flags_raw'] & 0x000010); // double high (not used yet) + $metablock['flags']['bitrate_kbps'] = (bool) ($metablock['flags_raw'] & 0x000020); // bitrate is kbps, not bits / sample + $metablock['flags']['auto_shaping'] = (bool) ($metablock['flags_raw'] & 0x000040); // automatic noise shaping + $metablock['flags']['shape_override'] = (bool) ($metablock['flags_raw'] & 0x000080); // shaping mode specified + $metablock['flags']['joint_override'] = (bool) ($metablock['flags_raw'] & 0x000100); // joint-stereo mode specified + $metablock['flags']['copy_time'] = (bool) ($metablock['flags_raw'] & 0x000200); // copy file-time from source + $metablock['flags']['create_exe'] = (bool) ($metablock['flags_raw'] & 0x000400); // create executable + $metablock['flags']['create_wvc'] = (bool) ($metablock['flags_raw'] & 0x000800); // create correction file + $metablock['flags']['optimize_wvc'] = (bool) ($metablock['flags_raw'] & 0x001000); // maximize bybrid compression + $metablock['flags']['quality_mode'] = (bool) ($metablock['flags_raw'] & 0x002000); // psychoacoustic quality mode + $metablock['flags']['raw_flag'] = (bool) ($metablock['flags_raw'] & 0x004000); // raw mode (not implemented yet) + $metablock['flags']['calc_noise'] = (bool) ($metablock['flags_raw'] & 0x008000); // calc noise in hybrid mode + $metablock['flags']['lossy_mode'] = (bool) ($metablock['flags_raw'] & 0x010000); // obsolete (for information) + $metablock['flags']['extra_mode'] = (bool) ($metablock['flags_raw'] & 0x020000); // extra processing mode + $metablock['flags']['skip_wvx'] = (bool) ($metablock['flags_raw'] & 0x040000); // no wvx stream w/ floats & big ints + $metablock['flags']['md5_checksum'] = (bool) ($metablock['flags_raw'] & 0x080000); // compute & store MD5 signature + $metablock['flags']['quiet_mode'] = (bool) ($metablock['flags_raw'] & 0x100000); // don't report progress % - case 0x23: // ID_REPLAY_GAIN - $this->warning('WavPack "Replay Gain" contents not yet handled by getID3() in metablock at offset '.$metablock['offset']); - break; + $info['wavpack']['config_flags'] = $metablock['flags']; + $info['audio']['encoder_options'] = ''; + if ($info['wavpack']['blockheader']['flags']['hybrid']) { + $info['audio']['encoder_options'] .= ' -b???'; + } + $info['audio']['encoder_options'] .= ($metablock['flags']['adobe_mode'] ? ' -a' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['optimize_wvc'] ? ' -cc' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['create_exe'] ? ' -e' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['fast_flag'] ? ' -f' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['joint_override'] ? ' -j?' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['high_flag'] ? ' -h' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['md5_checksum'] ? ' -m' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['calc_noise'] ? ' -n' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['shape_override'] ? ' -s?' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['extra_mode'] ? ' -x?' : ''); + if (! empty($info['audio']['encoder_options'])) { + $info['audio']['encoder_options'] = trim($info['audio']['encoder_options']); + } elseif (isset($info['audio']['encoder_options'])) { + unset($info['audio']['encoder_options']); + } + break; - case 0x24: // ID_CUESHEET - $this->warning('WavPack "Cuesheet" contents not yet handled by getID3() in metablock at offset '.$metablock['offset']); - break; + case 0x26: // ID_MD5_CHECKSUM + if (strlen($metablock['data']) == 16) { + $info['md5_data_source'] = strtolower(getid3_lib::PrintHexBytes($metablock['data'], true, false, false)); + } else { + $this->warning('Expecting 16 bytes of WavPack "MD5 Checksum" in metablock at offset '.$metablock['offset'].', but found '.strlen($metablock['data']).' bytes'); + } + break; + case 0x00: // ID_DUMMY + case 0x01: // ID_ENCODER_INFO + case 0x02: // ID_DECORR_TERMS + case 0x03: // ID_DECORR_WEIGHTS + case 0x04: // ID_DECORR_SAMPLES + case 0x05: // ID_ENTROPY_VARS + case 0x06: // ID_HYBRID_PROFILE + case 0x07: // ID_SHAPING_WEIGHTS + case 0x08: // ID_FLOAT_INFO + case 0x09: // ID_INT32_INFO + case 0x0A: // ID_WV_BITSTREAM + case 0x0B: // ID_WVC_BITSTREAM + case 0x0C: // ID_WVX_BITSTREAM + case 0x0D: // ID_CHANNEL_INFO + unset($metablock); + break; + } + } + if (! empty($metablock)) { + $info['wavpack']['metablocks'][] = $metablock; + } + } + } - case 0x25: // ID_CONFIG_BLOCK - $metablock['flags_raw'] = getid3_lib::LittleEndian2Int(substr($metablock['data'], 0, 3)); + $info['audio']['encoder'] = 'WavPack v'.$info['wavpack']['blockheader']['major_version'].'.'.str_pad($info['wavpack']['blockheader']['minor_version'], 2, '0', STR_PAD_LEFT); + $info['audio']['bits_per_sample'] = $info['wavpack']['blockheader']['flags']['bytes_per_sample'] * 8; + $info['audio']['channels'] = ($info['wavpack']['blockheader']['flags']['mono'] ? 1 : 2); - $metablock['flags']['adobe_mode'] = (bool) ($metablock['flags_raw'] & 0x000001); // "adobe" mode for 32-bit floats - $metablock['flags']['fast_flag'] = (bool) ($metablock['flags_raw'] & 0x000002); // fast mode - $metablock['flags']['very_fast_flag'] = (bool) ($metablock['flags_raw'] & 0x000004); // double fast - $metablock['flags']['high_flag'] = (bool) ($metablock['flags_raw'] & 0x000008); // high quality mode - $metablock['flags']['very_high_flag'] = (bool) ($metablock['flags_raw'] & 0x000010); // double high (not used yet) - $metablock['flags']['bitrate_kbps'] = (bool) ($metablock['flags_raw'] & 0x000020); // bitrate is kbps, not bits / sample - $metablock['flags']['auto_shaping'] = (bool) ($metablock['flags_raw'] & 0x000040); // automatic noise shaping - $metablock['flags']['shape_override'] = (bool) ($metablock['flags_raw'] & 0x000080); // shaping mode specified - $metablock['flags']['joint_override'] = (bool) ($metablock['flags_raw'] & 0x000100); // joint-stereo mode specified - $metablock['flags']['copy_time'] = (bool) ($metablock['flags_raw'] & 0x000200); // copy file-time from source - $metablock['flags']['create_exe'] = (bool) ($metablock['flags_raw'] & 0x000400); // create executable - $metablock['flags']['create_wvc'] = (bool) ($metablock['flags_raw'] & 0x000800); // create correction file - $metablock['flags']['optimize_wvc'] = (bool) ($metablock['flags_raw'] & 0x001000); // maximize bybrid compression - $metablock['flags']['quality_mode'] = (bool) ($metablock['flags_raw'] & 0x002000); // psychoacoustic quality mode - $metablock['flags']['raw_flag'] = (bool) ($metablock['flags_raw'] & 0x004000); // raw mode (not implemented yet) - $metablock['flags']['calc_noise'] = (bool) ($metablock['flags_raw'] & 0x008000); // calc noise in hybrid mode - $metablock['flags']['lossy_mode'] = (bool) ($metablock['flags_raw'] & 0x010000); // obsolete (for information) - $metablock['flags']['extra_mode'] = (bool) ($metablock['flags_raw'] & 0x020000); // extra processing mode - $metablock['flags']['skip_wvx'] = (bool) ($metablock['flags_raw'] & 0x040000); // no wvx stream w/ floats & big ints - $metablock['flags']['md5_checksum'] = (bool) ($metablock['flags_raw'] & 0x080000); // compute & store MD5 signature - $metablock['flags']['quiet_mode'] = (bool) ($metablock['flags_raw'] & 0x100000); // don't report progress % + if (! empty($info['playtime_seconds'])) { + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + } else { + $info['audio']['dataformat'] = 'wvc'; + } - $info['wavpack']['config_flags'] = $metablock['flags']; + return true; + } + public function WavPackMetablockNameLookup(&$id) + { + static $WavPackMetablockNameLookup = [ + 0x00 => 'Dummy', + 0x01 => 'Encoder Info', + 0x02 => 'Decorrelation Terms', + 0x03 => 'Decorrelation Weights', + 0x04 => 'Decorrelation Samples', + 0x05 => 'Entropy Variables', + 0x06 => 'Hybrid Profile', + 0x07 => 'Shaping Weights', + 0x08 => 'Float Info', + 0x09 => 'Int32 Info', + 0x0A => 'WV Bitstream', + 0x0B => 'WVC Bitstream', + 0x0C => 'WVX Bitstream', + 0x0D => 'Channel Info', + 0x21 => 'RIFF header', + 0x22 => 'RIFF trailer', + 0x23 => 'Replay Gain', + 0x24 => 'Cuesheet', + 0x25 => 'Config Block', + 0x26 => 'MD5 Checksum', + ]; - $info['audio']['encoder_options'] = ''; - if ($info['wavpack']['blockheader']['flags']['hybrid']) { - $info['audio']['encoder_options'] .= ' -b???'; - } - $info['audio']['encoder_options'] .= ($metablock['flags']['adobe_mode'] ? ' -a' : ''); - $info['audio']['encoder_options'] .= ($metablock['flags']['optimize_wvc'] ? ' -cc' : ''); - $info['audio']['encoder_options'] .= ($metablock['flags']['create_exe'] ? ' -e' : ''); - $info['audio']['encoder_options'] .= ($metablock['flags']['fast_flag'] ? ' -f' : ''); - $info['audio']['encoder_options'] .= ($metablock['flags']['joint_override'] ? ' -j?' : ''); - $info['audio']['encoder_options'] .= ($metablock['flags']['high_flag'] ? ' -h' : ''); - $info['audio']['encoder_options'] .= ($metablock['flags']['md5_checksum'] ? ' -m' : ''); - $info['audio']['encoder_options'] .= ($metablock['flags']['calc_noise'] ? ' -n' : ''); - $info['audio']['encoder_options'] .= ($metablock['flags']['shape_override'] ? ' -s?' : ''); - $info['audio']['encoder_options'] .= ($metablock['flags']['extra_mode'] ? ' -x?' : ''); - if (!empty($info['audio']['encoder_options'])) { - $info['audio']['encoder_options'] = trim($info['audio']['encoder_options']); - } elseif (isset($info['audio']['encoder_options'])) { - unset($info['audio']['encoder_options']); - } - break; - - - case 0x26: // ID_MD5_CHECKSUM - if (strlen($metablock['data']) == 16) { - $info['md5_data_source'] = strtolower(getid3_lib::PrintHexBytes($metablock['data'], true, false, false)); - } else { - $this->warning('Expecting 16 bytes of WavPack "MD5 Checksum" in metablock at offset '.$metablock['offset'].', but found '.strlen($metablock['data']).' bytes'); - } - break; - - - case 0x00: // ID_DUMMY - case 0x01: // ID_ENCODER_INFO - case 0x02: // ID_DECORR_TERMS - case 0x03: // ID_DECORR_WEIGHTS - case 0x04: // ID_DECORR_SAMPLES - case 0x05: // ID_ENTROPY_VARS - case 0x06: // ID_HYBRID_PROFILE - case 0x07: // ID_SHAPING_WEIGHTS - case 0x08: // ID_FLOAT_INFO - case 0x09: // ID_INT32_INFO - case 0x0A: // ID_WV_BITSTREAM - case 0x0B: // ID_WVC_BITSTREAM - case 0x0C: // ID_WVX_BITSTREAM - case 0x0D: // ID_CHANNEL_INFO - unset($metablock); - break; - } - - } - if (!empty($metablock)) { - $info['wavpack']['metablocks'][] = $metablock; - } - - } - - } - - $info['audio']['encoder'] = 'WavPack v'.$info['wavpack']['blockheader']['major_version'].'.'.str_pad($info['wavpack']['blockheader']['minor_version'], 2, '0', STR_PAD_LEFT); - $info['audio']['bits_per_sample'] = $info['wavpack']['blockheader']['flags']['bytes_per_sample'] * 8; - $info['audio']['channels'] = ($info['wavpack']['blockheader']['flags']['mono'] ? 1 : 2); - - if (!empty($info['playtime_seconds'])) { - - $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; - - } else { - - $info['audio']['dataformat'] = 'wvc'; - - } - - return true; - } - - - public function WavPackMetablockNameLookup(&$id) { - static $WavPackMetablockNameLookup = array( - 0x00 => 'Dummy', - 0x01 => 'Encoder Info', - 0x02 => 'Decorrelation Terms', - 0x03 => 'Decorrelation Weights', - 0x04 => 'Decorrelation Samples', - 0x05 => 'Entropy Variables', - 0x06 => 'Hybrid Profile', - 0x07 => 'Shaping Weights', - 0x08 => 'Float Info', - 0x09 => 'Int32 Info', - 0x0A => 'WV Bitstream', - 0x0B => 'WVC Bitstream', - 0x0C => 'WVX Bitstream', - 0x0D => 'Channel Info', - 0x21 => 'RIFF header', - 0x22 => 'RIFF trailer', - 0x23 => 'Replay Gain', - 0x24 => 'Cuesheet', - 0x25 => 'Config Block', - 0x26 => 'MD5 Checksum', - ); - return (isset($WavPackMetablockNameLookup[$id]) ? $WavPackMetablockNameLookup[$id] : ''); - } - + return isset($WavPackMetablockNameLookup[$id]) ? $WavPackMetablockNameLookup[$id] : ''; + } } diff --git a/app/Library/getid3/getid3/module.graphic.bmp.php b/app/Library/getid3/getid3/module.graphic.bmp.php index 90cbb38f..3afb77b0 100644 --- a/app/Library/getid3/getid3/module.graphic.bmp.php +++ b/app/Library/getid3/getid3/module.graphic.bmp.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,675 +15,669 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_bmp extends getid3_handler { - public $ExtractPalette = false; - public $ExtractData = false; - - public function Analyze() { - $info = &$this->getid3->info; - - // shortcuts - $info['bmp']['header']['raw'] = array(); - $thisfile_bmp = &$info['bmp']; - $thisfile_bmp_header = &$thisfile_bmp['header']; - $thisfile_bmp_header_raw = &$thisfile_bmp_header['raw']; - - // BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp - // all versions - // WORD bfType; - // DWORD bfSize; - // WORD bfReserved1; - // WORD bfReserved2; - // DWORD bfOffBits; - - $this->fseek($info['avdataoffset']); - $offset = 0; - $BMPheader = $this->fread(14 + 40); - - $thisfile_bmp_header_raw['identifier'] = substr($BMPheader, $offset, 2); - $offset += 2; - - $magic = 'BM'; - if ($thisfile_bmp_header_raw['identifier'] != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($thisfile_bmp_header_raw['identifier']).'"'); - unset($info['fileformat']); - unset($info['bmp']); - return false; - } - - $thisfile_bmp_header_raw['filesize'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['reserved1'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); - $offset += 2; - $thisfile_bmp_header_raw['reserved2'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); - $offset += 2; - $thisfile_bmp_header_raw['data_offset'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['header_size'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - - - // check if the hardcoded-to-1 "planes" is at offset 22 or 26 - $planes22 = getid3_lib::LittleEndian2Int(substr($BMPheader, 22, 2)); - $planes26 = getid3_lib::LittleEndian2Int(substr($BMPheader, 26, 2)); - if (($planes22 == 1) && ($planes26 != 1)) { - $thisfile_bmp['type_os'] = 'OS/2'; - $thisfile_bmp['type_version'] = 1; - } elseif (($planes26 == 1) && ($planes22 != 1)) { - $thisfile_bmp['type_os'] = 'Windows'; - $thisfile_bmp['type_version'] = 1; - } elseif ($thisfile_bmp_header_raw['header_size'] == 12) { - $thisfile_bmp['type_os'] = 'OS/2'; - $thisfile_bmp['type_version'] = 1; - } elseif ($thisfile_bmp_header_raw['header_size'] == 40) { - $thisfile_bmp['type_os'] = 'Windows'; - $thisfile_bmp['type_version'] = 1; - } elseif ($thisfile_bmp_header_raw['header_size'] == 84) { - $thisfile_bmp['type_os'] = 'Windows'; - $thisfile_bmp['type_version'] = 4; - } elseif ($thisfile_bmp_header_raw['header_size'] == 100) { - $thisfile_bmp['type_os'] = 'Windows'; - $thisfile_bmp['type_version'] = 5; - } else { - $this->error('Unknown BMP subtype (or not a BMP file)'); - unset($info['fileformat']); - unset($info['bmp']); - return false; - } - - $info['fileformat'] = 'bmp'; - $info['video']['dataformat'] = 'bmp'; - $info['video']['lossless'] = true; - $info['video']['pixel_aspect_ratio'] = (float) 1; - - if ($thisfile_bmp['type_os'] == 'OS/2') { - - // OS/2-format BMP - // http://netghost.narod.ru/gff/graphics/summary/os2bmp.htm - - // DWORD Size; /* Size of this structure in bytes */ - // DWORD Width; /* Bitmap width in pixels */ - // DWORD Height; /* Bitmap height in pixel */ - // WORD NumPlanes; /* Number of bit planes (color depth) */ - // WORD BitsPerPixel; /* Number of bits per pixel per plane */ - - $thisfile_bmp_header_raw['width'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); - $offset += 2; - $thisfile_bmp_header_raw['height'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); - $offset += 2; - $thisfile_bmp_header_raw['planes'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); - $offset += 2; - $thisfile_bmp_header_raw['bits_per_pixel'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); - $offset += 2; - - $info['video']['resolution_x'] = $thisfile_bmp_header_raw['width']; - $info['video']['resolution_y'] = $thisfile_bmp_header_raw['height']; - $info['video']['codec'] = 'BI_RGB '.$thisfile_bmp_header_raw['bits_per_pixel'].'-bit'; - $info['video']['bits_per_sample'] = $thisfile_bmp_header_raw['bits_per_pixel']; - - if ($thisfile_bmp['type_version'] >= 2) { - // DWORD Compression; /* Bitmap compression scheme */ - // DWORD ImageDataSize; /* Size of bitmap data in bytes */ - // DWORD XResolution; /* X resolution of display device */ - // DWORD YResolution; /* Y resolution of display device */ - // DWORD ColorsUsed; /* Number of color table indices used */ - // DWORD ColorsImportant; /* Number of important color indices */ - // WORD Units; /* Type of units used to measure resolution */ - // WORD Reserved; /* Pad structure to 4-byte boundary */ - // WORD Recording; /* Recording algorithm */ - // WORD Rendering; /* Halftoning algorithm used */ - // DWORD Size1; /* Reserved for halftoning algorithm use */ - // DWORD Size2; /* Reserved for halftoning algorithm use */ - // DWORD ColorEncoding; /* Color model used in bitmap */ - // DWORD Identifier; /* Reserved for application use */ - - $thisfile_bmp_header_raw['compression'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['bmp_data_size'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['resolution_h'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['resolution_v'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['colors_used'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['colors_important'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['resolution_units'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); - $offset += 2; - $thisfile_bmp_header_raw['reserved1'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); - $offset += 2; - $thisfile_bmp_header_raw['recording'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); - $offset += 2; - $thisfile_bmp_header_raw['rendering'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); - $offset += 2; - $thisfile_bmp_header_raw['size1'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['size2'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['color_encoding'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['identifier'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - - $thisfile_bmp_header['compression'] = $this->BMPcompressionOS2Lookup($thisfile_bmp_header_raw['compression']); - - $info['video']['codec'] = $thisfile_bmp_header['compression'].' '.$thisfile_bmp_header_raw['bits_per_pixel'].'-bit'; - } - - } elseif ($thisfile_bmp['type_os'] == 'Windows') { - - // Windows-format BMP - - // BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp - // all versions - // DWORD biSize; - // LONG biWidth; - // LONG biHeight; - // WORD biPlanes; - // WORD biBitCount; - // DWORD biCompression; - // DWORD biSizeImage; - // LONG biXPelsPerMeter; - // LONG biYPelsPerMeter; - // DWORD biClrUsed; - // DWORD biClrImportant; - - // possibly integrate this section and module.audio-video.riff.php::ParseBITMAPINFOHEADER() ? - - $thisfile_bmp_header_raw['width'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4), true); - $offset += 4; - $thisfile_bmp_header_raw['height'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4), true); - $offset += 4; - $thisfile_bmp_header_raw['planes'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); - $offset += 2; - $thisfile_bmp_header_raw['bits_per_pixel'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); - $offset += 2; - $thisfile_bmp_header_raw['compression'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['bmp_data_size'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['resolution_h'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4), true); - $offset += 4; - $thisfile_bmp_header_raw['resolution_v'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4), true); - $offset += 4; - $thisfile_bmp_header_raw['colors_used'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['colors_important'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - - $thisfile_bmp_header['compression'] = $this->BMPcompressionWindowsLookup($thisfile_bmp_header_raw['compression']); - $info['video']['resolution_x'] = $thisfile_bmp_header_raw['width']; - $info['video']['resolution_y'] = $thisfile_bmp_header_raw['height']; - $info['video']['codec'] = $thisfile_bmp_header['compression'].' '.$thisfile_bmp_header_raw['bits_per_pixel'].'-bit'; - $info['video']['bits_per_sample'] = $thisfile_bmp_header_raw['bits_per_pixel']; - - if (($thisfile_bmp['type_version'] >= 4) || ($thisfile_bmp_header_raw['compression'] == 3)) { - // should only be v4+, but BMPs with type_version==1 and BI_BITFIELDS compression have been seen - $BMPheader .= $this->fread(44); - - // BITMAPV4HEADER - [44 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_2k1e.asp - // Win95+, WinNT4.0+ - // DWORD bV4RedMask; - // DWORD bV4GreenMask; - // DWORD bV4BlueMask; - // DWORD bV4AlphaMask; - // DWORD bV4CSType; - // CIEXYZTRIPLE bV4Endpoints; - // DWORD bV4GammaRed; - // DWORD bV4GammaGreen; - // DWORD bV4GammaBlue; - $thisfile_bmp_header_raw['red_mask'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['green_mask'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['blue_mask'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['alpha_mask'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['cs_type'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['ciexyz_red'] = substr($BMPheader, $offset, 4); - $offset += 4; - $thisfile_bmp_header_raw['ciexyz_green'] = substr($BMPheader, $offset, 4); - $offset += 4; - $thisfile_bmp_header_raw['ciexyz_blue'] = substr($BMPheader, $offset, 4); - $offset += 4; - $thisfile_bmp_header_raw['gamma_red'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['gamma_green'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['gamma_blue'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - - $thisfile_bmp_header['ciexyz_red'] = getid3_lib::FixedPoint2_30(strrev($thisfile_bmp_header_raw['ciexyz_red'])); - $thisfile_bmp_header['ciexyz_green'] = getid3_lib::FixedPoint2_30(strrev($thisfile_bmp_header_raw['ciexyz_green'])); - $thisfile_bmp_header['ciexyz_blue'] = getid3_lib::FixedPoint2_30(strrev($thisfile_bmp_header_raw['ciexyz_blue'])); - } - - if ($thisfile_bmp['type_version'] >= 5) { - $BMPheader .= $this->fread(16); - - // BITMAPV5HEADER - [16 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_7c36.asp - // Win98+, Win2000+ - // DWORD bV5Intent; - // DWORD bV5ProfileData; - // DWORD bV5ProfileSize; - // DWORD bV5Reserved; - $thisfile_bmp_header_raw['intent'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['profile_data_offset'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['profile_data_size'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - $thisfile_bmp_header_raw['reserved3'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); - $offset += 4; - } - - } else { - - $this->error('Unknown BMP format in header.'); - return false; - - } - - - if ($this->ExtractPalette || $this->ExtractData) { - $PaletteEntries = 0; - if ($thisfile_bmp_header_raw['bits_per_pixel'] < 16) { - $PaletteEntries = pow(2, $thisfile_bmp_header_raw['bits_per_pixel']); - } elseif (isset($thisfile_bmp_header_raw['colors_used']) && ($thisfile_bmp_header_raw['colors_used'] > 0) && ($thisfile_bmp_header_raw['colors_used'] <= 256)) { - $PaletteEntries = $thisfile_bmp_header_raw['colors_used']; - } - if ($PaletteEntries > 0) { - $BMPpalette = $this->fread(4 * $PaletteEntries); - $paletteoffset = 0; - for ($i = 0; $i < $PaletteEntries; $i++) { - // RGBQUAD - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_5f8y.asp - // BYTE rgbBlue; - // BYTE rgbGreen; - // BYTE rgbRed; - // BYTE rgbReserved; - $blue = getid3_lib::LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1)); - $green = getid3_lib::LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1)); - $red = getid3_lib::LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1)); - if (($thisfile_bmp['type_os'] == 'OS/2') && ($thisfile_bmp['type_version'] == 1)) { - // no padding byte - } else { - $paletteoffset++; // padding byte - } - $thisfile_bmp['palette'][$i] = (($red << 16) | ($green << 8) | $blue); - } - } - } - - if ($this->ExtractData) { - $this->fseek($thisfile_bmp_header_raw['data_offset']); - $RowByteLength = ceil(($thisfile_bmp_header_raw['width'] * ($thisfile_bmp_header_raw['bits_per_pixel'] / 8)) / 4) * 4; // round up to nearest DWORD boundry - $BMPpixelData = $this->fread($thisfile_bmp_header_raw['height'] * $RowByteLength); - $pixeldataoffset = 0; - $thisfile_bmp_header_raw['compression'] = (isset($thisfile_bmp_header_raw['compression']) ? $thisfile_bmp_header_raw['compression'] : ''); - switch ($thisfile_bmp_header_raw['compression']) { - - case 0: // BI_RGB - switch ($thisfile_bmp_header_raw['bits_per_pixel']) { - case 1: - for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { - for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col = $col) { - $paletteindexbyte = ord($BMPpixelData{$pixeldataoffset++}); - for ($i = 7; $i >= 0; $i--) { - $paletteindex = ($paletteindexbyte & (0x01 << $i)) >> $i; - $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; - $col++; - } - } - while (($pixeldataoffset % 4) != 0) { - // lines are padded to nearest DWORD - $pixeldataoffset++; - } - } - break; - - case 4: - for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { - for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col = $col) { - $paletteindexbyte = ord($BMPpixelData{$pixeldataoffset++}); - for ($i = 1; $i >= 0; $i--) { - $paletteindex = ($paletteindexbyte & (0x0F << (4 * $i))) >> (4 * $i); - $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; - $col++; - } - } - while (($pixeldataoffset % 4) != 0) { - // lines are padded to nearest DWORD - $pixeldataoffset++; - } - } - break; - - case 8: - for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { - for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) { - $paletteindex = ord($BMPpixelData{$pixeldataoffset++}); - $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; - } - while (($pixeldataoffset % 4) != 0) { - // lines are padded to nearest DWORD - $pixeldataoffset++; - } - } - break; - - case 24: - for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { - for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) { - $thisfile_bmp['data'][$row][$col] = (ord($BMPpixelData{$pixeldataoffset+2}) << 16) | (ord($BMPpixelData{$pixeldataoffset+1}) << 8) | ord($BMPpixelData{$pixeldataoffset}); - $pixeldataoffset += 3; - } - while (($pixeldataoffset % 4) != 0) { - // lines are padded to nearest DWORD - $pixeldataoffset++; - } - } - break; - - case 32: - for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { - for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) { - $thisfile_bmp['data'][$row][$col] = (ord($BMPpixelData{$pixeldataoffset+3}) << 24) | (ord($BMPpixelData{$pixeldataoffset+2}) << 16) | (ord($BMPpixelData{$pixeldataoffset+1}) << 8) | ord($BMPpixelData{$pixeldataoffset}); - $pixeldataoffset += 4; - } - while (($pixeldataoffset % 4) != 0) { - // lines are padded to nearest DWORD - $pixeldataoffset++; - } - } - break; - - case 16: - // ? - break; - - default: - $this->error('Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'); - break; - } - break; - - - case 1: // BI_RLE8 - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_6x0u.asp - switch ($thisfile_bmp_header_raw['bits_per_pixel']) { - case 8: - $pixelcounter = 0; - while ($pixeldataoffset < strlen($BMPpixelData)) { - $firstbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); - $secondbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); - if ($firstbyte == 0) { - - // escaped/absolute mode - the first byte of the pair can be set to zero to - // indicate an escape character that denotes the end of a line, the end of - // a bitmap, or a delta, depending on the value of the second byte. - switch ($secondbyte) { - case 0: - // end of line - // no need for special processing, just ignore - break; - - case 1: - // end of bitmap - $pixeldataoffset = strlen($BMPpixelData); // force to exit loop just in case - break; - - case 2: - // delta - The 2 bytes following the escape contain unsigned values - // indicating the horizontal and vertical offsets of the next pixel - // from the current position. - $colincrement = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); - $rowincrement = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); - $col = ($pixelcounter % $thisfile_bmp_header_raw['width']) + $colincrement; - $row = ($thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width'])) - $rowincrement; - $pixelcounter = ($row * $thisfile_bmp_header_raw['width']) + $col; - break; - - default: - // In absolute mode, the first byte is zero and the second byte is a - // value in the range 03H through FFH. The second byte represents the - // number of bytes that follow, each of which contains the color index - // of a single pixel. Each run must be aligned on a word boundary. - for ($i = 0; $i < $secondbyte; $i++) { - $paletteindex = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); - $col = $pixelcounter % $thisfile_bmp_header_raw['width']; - $row = $thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width']); - $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; - $pixelcounter++; - } - while (($pixeldataoffset % 2) != 0) { - // Each run must be aligned on a word boundary. - $pixeldataoffset++; - } - break; - } - - } else { - - // encoded mode - the first byte specifies the number of consecutive pixels - // to be drawn using the color index contained in the second byte. - for ($i = 0; $i < $firstbyte; $i++) { - $col = $pixelcounter % $thisfile_bmp_header_raw['width']; - $row = $thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width']); - $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$secondbyte]; - $pixelcounter++; - } - - } - } - break; - - default: - $this->error('Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'); - break; - } - break; - - - - case 2: // BI_RLE4 - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_6x0u.asp - switch ($thisfile_bmp_header_raw['bits_per_pixel']) { - case 4: - $pixelcounter = 0; - while ($pixeldataoffset < strlen($BMPpixelData)) { - $firstbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); - $secondbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); - if ($firstbyte == 0) { - - // escaped/absolute mode - the first byte of the pair can be set to zero to - // indicate an escape character that denotes the end of a line, the end of - // a bitmap, or a delta, depending on the value of the second byte. - switch ($secondbyte) { - case 0: - // end of line - // no need for special processing, just ignore - break; - - case 1: - // end of bitmap - $pixeldataoffset = strlen($BMPpixelData); // force to exit loop just in case - break; - - case 2: - // delta - The 2 bytes following the escape contain unsigned values - // indicating the horizontal and vertical offsets of the next pixel - // from the current position. - $colincrement = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); - $rowincrement = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); - $col = ($pixelcounter % $thisfile_bmp_header_raw['width']) + $colincrement; - $row = ($thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width'])) - $rowincrement; - $pixelcounter = ($row * $thisfile_bmp_header_raw['width']) + $col; - break; - - default: - // In absolute mode, the first byte is zero. The second byte contains the number - // of color indexes that follow. Subsequent bytes contain color indexes in their - // high- and low-order 4 bits, one color index for each pixel. In absolute mode, - // each run must be aligned on a word boundary. - unset($paletteindexes); - for ($i = 0; $i < ceil($secondbyte / 2); $i++) { - $paletteindexbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); - $paletteindexes[] = ($paletteindexbyte & 0xF0) >> 4; - $paletteindexes[] = ($paletteindexbyte & 0x0F); - } - while (($pixeldataoffset % 2) != 0) { - // Each run must be aligned on a word boundary. - $pixeldataoffset++; - } - - foreach ($paletteindexes as $paletteindex) { - $col = $pixelcounter % $thisfile_bmp_header_raw['width']; - $row = $thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width']); - $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; - $pixelcounter++; - } - break; - } - - } else { - - // encoded mode - the first byte of the pair contains the number of pixels to be - // drawn using the color indexes in the second byte. The second byte contains two - // color indexes, one in its high-order 4 bits and one in its low-order 4 bits. - // The first of the pixels is drawn using the color specified by the high-order - // 4 bits, the second is drawn using the color in the low-order 4 bits, the third - // is drawn using the color in the high-order 4 bits, and so on, until all the - // pixels specified by the first byte have been drawn. - $paletteindexes[0] = ($secondbyte & 0xF0) >> 4; - $paletteindexes[1] = ($secondbyte & 0x0F); - for ($i = 0; $i < $firstbyte; $i++) { - $col = $pixelcounter % $thisfile_bmp_header_raw['width']; - $row = $thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width']); - $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindexes[($i % 2)]]; - $pixelcounter++; - } - - } - } - break; - - default: - $this->error('Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'); - break; - } - break; - - - case 3: // BI_BITFIELDS - switch ($thisfile_bmp_header_raw['bits_per_pixel']) { - case 16: - case 32: - $redshift = 0; - $greenshift = 0; - $blueshift = 0; - while ((($thisfile_bmp_header_raw['red_mask'] >> $redshift) & 0x01) == 0) { - $redshift++; - } - while ((($thisfile_bmp_header_raw['green_mask'] >> $greenshift) & 0x01) == 0) { - $greenshift++; - } - while ((($thisfile_bmp_header_raw['blue_mask'] >> $blueshift) & 0x01) == 0) { - $blueshift++; - } - for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { - for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) { - $pixelvalue = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset, $thisfile_bmp_header_raw['bits_per_pixel'] / 8)); - $pixeldataoffset += $thisfile_bmp_header_raw['bits_per_pixel'] / 8; - - $red = intval(round(((($pixelvalue & $thisfile_bmp_header_raw['red_mask']) >> $redshift) / ($thisfile_bmp_header_raw['red_mask'] >> $redshift)) * 255)); - $green = intval(round(((($pixelvalue & $thisfile_bmp_header_raw['green_mask']) >> $greenshift) / ($thisfile_bmp_header_raw['green_mask'] >> $greenshift)) * 255)); - $blue = intval(round(((($pixelvalue & $thisfile_bmp_header_raw['blue_mask']) >> $blueshift) / ($thisfile_bmp_header_raw['blue_mask'] >> $blueshift)) * 255)); - $thisfile_bmp['data'][$row][$col] = (($red << 16) | ($green << 8) | ($blue)); - } - while (($pixeldataoffset % 4) != 0) { - // lines are padded to nearest DWORD - $pixeldataoffset++; - } - } - break; - - default: - $this->error('Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'); - break; - } - break; - - - default: // unhandled compression type - $this->error('Unknown/unhandled compression type value ('.$thisfile_bmp_header_raw['compression'].') - cannot decompress pixel data'); - break; - } - } - - return true; - } - - - public function PlotBMP(&$BMPinfo) { - $starttime = time(); - if (!isset($BMPinfo['bmp']['data']) || !is_array($BMPinfo['bmp']['data'])) { - echo 'ERROR: no pixel data
    '; - return false; - } - set_time_limit(intval(round($BMPinfo['resolution_x'] * $BMPinfo['resolution_y'] / 10000))); - if ($im = ImageCreateTrueColor($BMPinfo['resolution_x'], $BMPinfo['resolution_y'])) { - for ($row = 0; $row < $BMPinfo['resolution_y']; $row++) { - for ($col = 0; $col < $BMPinfo['resolution_x']; $col++) { - if (isset($BMPinfo['bmp']['data'][$row][$col])) { - $red = ($BMPinfo['bmp']['data'][$row][$col] & 0x00FF0000) >> 16; - $green = ($BMPinfo['bmp']['data'][$row][$col] & 0x0000FF00) >> 8; - $blue = ($BMPinfo['bmp']['data'][$row][$col] & 0x000000FF); - $pixelcolor = ImageColorAllocate($im, $red, $green, $blue); - ImageSetPixel($im, $col, $row, $pixelcolor); - } else { - //echo 'ERROR: no data for pixel '.$row.' x '.$col.'
    '; - //return false; - } - } - } - if (headers_sent()) { - echo 'plotted '.($BMPinfo['resolution_x'] * $BMPinfo['resolution_y']).' pixels in '.(time() - $starttime).' seconds
    '; - ImageDestroy($im); - exit; - } else { - header('Content-type: image/png'); - ImagePNG($im); - ImageDestroy($im); - return true; - } - } - return false; - } - - public function BMPcompressionWindowsLookup($compressionid) { - static $BMPcompressionWindowsLookup = array( - 0 => 'BI_RGB', - 1 => 'BI_RLE8', - 2 => 'BI_RLE4', - 3 => 'BI_BITFIELDS', - 4 => 'BI_JPEG', - 5 => 'BI_PNG' - ); - return (isset($BMPcompressionWindowsLookup[$compressionid]) ? $BMPcompressionWindowsLookup[$compressionid] : 'invalid'); - } - - public function BMPcompressionOS2Lookup($compressionid) { - static $BMPcompressionOS2Lookup = array( - 0 => 'BI_RGB', - 1 => 'BI_RLE8', - 2 => 'BI_RLE4', - 3 => 'Huffman 1D', - 4 => 'BI_RLE24', - ); - return (isset($BMPcompressionOS2Lookup[$compressionid]) ? $BMPcompressionOS2Lookup[$compressionid] : 'invalid'); - } - + public $ExtractPalette = false; + public $ExtractData = false; + + public function Analyze() + { + $info = &$this->getid3->info; + + // shortcuts + $info['bmp']['header']['raw'] = []; + $thisfile_bmp = &$info['bmp']; + $thisfile_bmp_header = &$thisfile_bmp['header']; + $thisfile_bmp_header_raw = &$thisfile_bmp_header['raw']; + + // BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp + // all versions + // WORD bfType; + // DWORD bfSize; + // WORD bfReserved1; + // WORD bfReserved2; + // DWORD bfOffBits; + + $this->fseek($info['avdataoffset']); + $offset = 0; + $BMPheader = $this->fread(14 + 40); + + $thisfile_bmp_header_raw['identifier'] = substr($BMPheader, $offset, 2); + $offset += 2; + + $magic = 'BM'; + if ($thisfile_bmp_header_raw['identifier'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($thisfile_bmp_header_raw['identifier']).'"'); + unset($info['fileformat']); + unset($info['bmp']); + + return false; + } + + $thisfile_bmp_header_raw['filesize'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['reserved1'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); + $offset += 2; + $thisfile_bmp_header_raw['reserved2'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); + $offset += 2; + $thisfile_bmp_header_raw['data_offset'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['header_size'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + + // check if the hardcoded-to-1 "planes" is at offset 22 or 26 + $planes22 = getid3_lib::LittleEndian2Int(substr($BMPheader, 22, 2)); + $planes26 = getid3_lib::LittleEndian2Int(substr($BMPheader, 26, 2)); + if (($planes22 == 1) && ($planes26 != 1)) { + $thisfile_bmp['type_os'] = 'OS/2'; + $thisfile_bmp['type_version'] = 1; + } elseif (($planes26 == 1) && ($planes22 != 1)) { + $thisfile_bmp['type_os'] = 'Windows'; + $thisfile_bmp['type_version'] = 1; + } elseif ($thisfile_bmp_header_raw['header_size'] == 12) { + $thisfile_bmp['type_os'] = 'OS/2'; + $thisfile_bmp['type_version'] = 1; + } elseif ($thisfile_bmp_header_raw['header_size'] == 40) { + $thisfile_bmp['type_os'] = 'Windows'; + $thisfile_bmp['type_version'] = 1; + } elseif ($thisfile_bmp_header_raw['header_size'] == 84) { + $thisfile_bmp['type_os'] = 'Windows'; + $thisfile_bmp['type_version'] = 4; + } elseif ($thisfile_bmp_header_raw['header_size'] == 100) { + $thisfile_bmp['type_os'] = 'Windows'; + $thisfile_bmp['type_version'] = 5; + } else { + $this->error('Unknown BMP subtype (or not a BMP file)'); + unset($info['fileformat']); + unset($info['bmp']); + + return false; + } + + $info['fileformat'] = 'bmp'; + $info['video']['dataformat'] = 'bmp'; + $info['video']['lossless'] = true; + $info['video']['pixel_aspect_ratio'] = (float) 1; + + if ($thisfile_bmp['type_os'] == 'OS/2') { + + // OS/2-format BMP + // http://netghost.narod.ru/gff/graphics/summary/os2bmp.htm + + // DWORD Size; /* Size of this structure in bytes */ + // DWORD Width; /* Bitmap width in pixels */ + // DWORD Height; /* Bitmap height in pixel */ + // WORD NumPlanes; /* Number of bit planes (color depth) */ + // WORD BitsPerPixel; /* Number of bits per pixel per plane */ + + $thisfile_bmp_header_raw['width'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); + $offset += 2; + $thisfile_bmp_header_raw['height'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); + $offset += 2; + $thisfile_bmp_header_raw['planes'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); + $offset += 2; + $thisfile_bmp_header_raw['bits_per_pixel'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); + $offset += 2; + + $info['video']['resolution_x'] = $thisfile_bmp_header_raw['width']; + $info['video']['resolution_y'] = $thisfile_bmp_header_raw['height']; + $info['video']['codec'] = 'BI_RGB '.$thisfile_bmp_header_raw['bits_per_pixel'].'-bit'; + $info['video']['bits_per_sample'] = $thisfile_bmp_header_raw['bits_per_pixel']; + + if ($thisfile_bmp['type_version'] >= 2) { + // DWORD Compression; /* Bitmap compression scheme */ + // DWORD ImageDataSize; /* Size of bitmap data in bytes */ + // DWORD XResolution; /* X resolution of display device */ + // DWORD YResolution; /* Y resolution of display device */ + // DWORD ColorsUsed; /* Number of color table indices used */ + // DWORD ColorsImportant; /* Number of important color indices */ + // WORD Units; /* Type of units used to measure resolution */ + // WORD Reserved; /* Pad structure to 4-byte boundary */ + // WORD Recording; /* Recording algorithm */ + // WORD Rendering; /* Halftoning algorithm used */ + // DWORD Size1; /* Reserved for halftoning algorithm use */ + // DWORD Size2; /* Reserved for halftoning algorithm use */ + // DWORD ColorEncoding; /* Color model used in bitmap */ + // DWORD Identifier; /* Reserved for application use */ + + $thisfile_bmp_header_raw['compression'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['bmp_data_size'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['resolution_h'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['resolution_v'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['colors_used'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['colors_important'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['resolution_units'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); + $offset += 2; + $thisfile_bmp_header_raw['reserved1'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); + $offset += 2; + $thisfile_bmp_header_raw['recording'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); + $offset += 2; + $thisfile_bmp_header_raw['rendering'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); + $offset += 2; + $thisfile_bmp_header_raw['size1'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['size2'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['color_encoding'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['identifier'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + + $thisfile_bmp_header['compression'] = $this->BMPcompressionOS2Lookup($thisfile_bmp_header_raw['compression']); + + $info['video']['codec'] = $thisfile_bmp_header['compression'].' '.$thisfile_bmp_header_raw['bits_per_pixel'].'-bit'; + } + } elseif ($thisfile_bmp['type_os'] == 'Windows') { + + // Windows-format BMP + + // BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp + // all versions + // DWORD biSize; + // LONG biWidth; + // LONG biHeight; + // WORD biPlanes; + // WORD biBitCount; + // DWORD biCompression; + // DWORD biSizeImage; + // LONG biXPelsPerMeter; + // LONG biYPelsPerMeter; + // DWORD biClrUsed; + // DWORD biClrImportant; + + // possibly integrate this section and module.audio-video.riff.php::ParseBITMAPINFOHEADER() ? + + $thisfile_bmp_header_raw['width'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4), true); + $offset += 4; + $thisfile_bmp_header_raw['height'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4), true); + $offset += 4; + $thisfile_bmp_header_raw['planes'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); + $offset += 2; + $thisfile_bmp_header_raw['bits_per_pixel'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); + $offset += 2; + $thisfile_bmp_header_raw['compression'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['bmp_data_size'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['resolution_h'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4), true); + $offset += 4; + $thisfile_bmp_header_raw['resolution_v'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4), true); + $offset += 4; + $thisfile_bmp_header_raw['colors_used'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['colors_important'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + + $thisfile_bmp_header['compression'] = $this->BMPcompressionWindowsLookup($thisfile_bmp_header_raw['compression']); + $info['video']['resolution_x'] = $thisfile_bmp_header_raw['width']; + $info['video']['resolution_y'] = $thisfile_bmp_header_raw['height']; + $info['video']['codec'] = $thisfile_bmp_header['compression'].' '.$thisfile_bmp_header_raw['bits_per_pixel'].'-bit'; + $info['video']['bits_per_sample'] = $thisfile_bmp_header_raw['bits_per_pixel']; + + if (($thisfile_bmp['type_version'] >= 4) || ($thisfile_bmp_header_raw['compression'] == 3)) { + // should only be v4+, but BMPs with type_version==1 and BI_BITFIELDS compression have been seen + $BMPheader .= $this->fread(44); + + // BITMAPV4HEADER - [44 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_2k1e.asp + // Win95+, WinNT4.0+ + // DWORD bV4RedMask; + // DWORD bV4GreenMask; + // DWORD bV4BlueMask; + // DWORD bV4AlphaMask; + // DWORD bV4CSType; + // CIEXYZTRIPLE bV4Endpoints; + // DWORD bV4GammaRed; + // DWORD bV4GammaGreen; + // DWORD bV4GammaBlue; + $thisfile_bmp_header_raw['red_mask'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['green_mask'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['blue_mask'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['alpha_mask'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['cs_type'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['ciexyz_red'] = substr($BMPheader, $offset, 4); + $offset += 4; + $thisfile_bmp_header_raw['ciexyz_green'] = substr($BMPheader, $offset, 4); + $offset += 4; + $thisfile_bmp_header_raw['ciexyz_blue'] = substr($BMPheader, $offset, 4); + $offset += 4; + $thisfile_bmp_header_raw['gamma_red'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['gamma_green'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['gamma_blue'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + + $thisfile_bmp_header['ciexyz_red'] = getid3_lib::FixedPoint2_30(strrev($thisfile_bmp_header_raw['ciexyz_red'])); + $thisfile_bmp_header['ciexyz_green'] = getid3_lib::FixedPoint2_30(strrev($thisfile_bmp_header_raw['ciexyz_green'])); + $thisfile_bmp_header['ciexyz_blue'] = getid3_lib::FixedPoint2_30(strrev($thisfile_bmp_header_raw['ciexyz_blue'])); + } + + if ($thisfile_bmp['type_version'] >= 5) { + $BMPheader .= $this->fread(16); + + // BITMAPV5HEADER - [16 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_7c36.asp + // Win98+, Win2000+ + // DWORD bV5Intent; + // DWORD bV5ProfileData; + // DWORD bV5ProfileSize; + // DWORD bV5Reserved; + $thisfile_bmp_header_raw['intent'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['profile_data_offset'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['profile_data_size'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + $thisfile_bmp_header_raw['reserved3'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 4)); + $offset += 4; + } + } else { + $this->error('Unknown BMP format in header.'); + + return false; + } + + if ($this->ExtractPalette || $this->ExtractData) { + $PaletteEntries = 0; + if ($thisfile_bmp_header_raw['bits_per_pixel'] < 16) { + $PaletteEntries = pow(2, $thisfile_bmp_header_raw['bits_per_pixel']); + } elseif (isset($thisfile_bmp_header_raw['colors_used']) && ($thisfile_bmp_header_raw['colors_used'] > 0) && ($thisfile_bmp_header_raw['colors_used'] <= 256)) { + $PaletteEntries = $thisfile_bmp_header_raw['colors_used']; + } + if ($PaletteEntries > 0) { + $BMPpalette = $this->fread(4 * $PaletteEntries); + $paletteoffset = 0; + for ($i = 0; $i < $PaletteEntries; $i++) { + // RGBQUAD - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_5f8y.asp + // BYTE rgbBlue; + // BYTE rgbGreen; + // BYTE rgbRed; + // BYTE rgbReserved; + $blue = getid3_lib::LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1)); + $green = getid3_lib::LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1)); + $red = getid3_lib::LittleEndian2Int(substr($BMPpalette, $paletteoffset++, 1)); + if (($thisfile_bmp['type_os'] == 'OS/2') && ($thisfile_bmp['type_version'] == 1)) { + // no padding byte + } else { + $paletteoffset++; // padding byte + } + $thisfile_bmp['palette'][$i] = (($red << 16) | ($green << 8) | $blue); + } + } + } + + if ($this->ExtractData) { + $this->fseek($thisfile_bmp_header_raw['data_offset']); + $RowByteLength = ceil(($thisfile_bmp_header_raw['width'] * ($thisfile_bmp_header_raw['bits_per_pixel'] / 8)) / 4) * 4; // round up to nearest DWORD boundry + $BMPpixelData = $this->fread($thisfile_bmp_header_raw['height'] * $RowByteLength); + $pixeldataoffset = 0; + $thisfile_bmp_header_raw['compression'] = (isset($thisfile_bmp_header_raw['compression']) ? $thisfile_bmp_header_raw['compression'] : ''); + switch ($thisfile_bmp_header_raw['compression']) { + + case 0: // BI_RGB + switch ($thisfile_bmp_header_raw['bits_per_pixel']) { + case 1: + for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { + for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col = $col) { + $paletteindexbyte = ord($BMPpixelData[$pixeldataoffset++]); + for ($i = 7; $i >= 0; $i--) { + $paletteindex = ($paletteindexbyte & (0x01 << $i)) >> $i; + $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; + $col++; + } + } + while (($pixeldataoffset % 4) != 0) { + // lines are padded to nearest DWORD + $pixeldataoffset++; + } + } + break; + + case 4: + for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { + for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col = $col) { + $paletteindexbyte = ord($BMPpixelData[$pixeldataoffset++]); + for ($i = 1; $i >= 0; $i--) { + $paletteindex = ($paletteindexbyte & (0x0F << (4 * $i))) >> (4 * $i); + $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; + $col++; + } + } + while (($pixeldataoffset % 4) != 0) { + // lines are padded to nearest DWORD + $pixeldataoffset++; + } + } + break; + + case 8: + for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { + for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) { + $paletteindex = ord($BMPpixelData[$pixeldataoffset++]); + $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; + } + while (($pixeldataoffset % 4) != 0) { + // lines are padded to nearest DWORD + $pixeldataoffset++; + } + } + break; + + case 24: + for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { + for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) { + $thisfile_bmp['data'][$row][$col] = (ord($BMPpixelData[$pixeldataoffset + 2]) << 16) | (ord($BMPpixelData[$pixeldataoffset + 1]) << 8) | ord($BMPpixelData[$pixeldataoffset]); + $pixeldataoffset += 3; + } + while (($pixeldataoffset % 4) != 0) { + // lines are padded to nearest DWORD + $pixeldataoffset++; + } + } + break; + + case 32: + for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { + for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) { + $thisfile_bmp['data'][$row][$col] = (ord($BMPpixelData[$pixeldataoffset + 3]) << 24) | (ord($BMPpixelData[$pixeldataoffset + 2]) << 16) | (ord($BMPpixelData[$pixeldataoffset + 1]) << 8) | ord($BMPpixelData[$pixeldataoffset]); + $pixeldataoffset += 4; + } + while (($pixeldataoffset % 4) != 0) { + // lines are padded to nearest DWORD + $pixeldataoffset++; + } + } + break; + + case 16: + // ? + break; + + default: + $this->error('Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'); + break; + } + break; + + case 1: // BI_RLE8 - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_6x0u.asp + switch ($thisfile_bmp_header_raw['bits_per_pixel']) { + case 8: + $pixelcounter = 0; + while ($pixeldataoffset < strlen($BMPpixelData)) { + $firstbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); + $secondbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); + if ($firstbyte == 0) { + + // escaped/absolute mode - the first byte of the pair can be set to zero to + // indicate an escape character that denotes the end of a line, the end of + // a bitmap, or a delta, depending on the value of the second byte. + switch ($secondbyte) { + case 0: + // end of line + // no need for special processing, just ignore + break; + + case 1: + // end of bitmap + $pixeldataoffset = strlen($BMPpixelData); // force to exit loop just in case + break; + + case 2: + // delta - The 2 bytes following the escape contain unsigned values + // indicating the horizontal and vertical offsets of the next pixel + // from the current position. + $colincrement = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); + $rowincrement = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); + $col = ($pixelcounter % $thisfile_bmp_header_raw['width']) + $colincrement; + $row = ($thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width'])) - $rowincrement; + $pixelcounter = ($row * $thisfile_bmp_header_raw['width']) + $col; + break; + + default: + // In absolute mode, the first byte is zero and the second byte is a + // value in the range 03H through FFH. The second byte represents the + // number of bytes that follow, each of which contains the color index + // of a single pixel. Each run must be aligned on a word boundary. + for ($i = 0; $i < $secondbyte; $i++) { + $paletteindex = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); + $col = $pixelcounter % $thisfile_bmp_header_raw['width']; + $row = $thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width']); + $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; + $pixelcounter++; + } + while (($pixeldataoffset % 2) != 0) { + // Each run must be aligned on a word boundary. + $pixeldataoffset++; + } + break; + } + } else { + + // encoded mode - the first byte specifies the number of consecutive pixels + // to be drawn using the color index contained in the second byte. + for ($i = 0; $i < $firstbyte; $i++) { + $col = $pixelcounter % $thisfile_bmp_header_raw['width']; + $row = $thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width']); + $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$secondbyte]; + $pixelcounter++; + } + } + } + break; + + default: + $this->error('Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'); + break; + } + break; + + case 2: // BI_RLE4 - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_6x0u.asp + switch ($thisfile_bmp_header_raw['bits_per_pixel']) { + case 4: + $pixelcounter = 0; + while ($pixeldataoffset < strlen($BMPpixelData)) { + $firstbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); + $secondbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); + if ($firstbyte == 0) { + + // escaped/absolute mode - the first byte of the pair can be set to zero to + // indicate an escape character that denotes the end of a line, the end of + // a bitmap, or a delta, depending on the value of the second byte. + switch ($secondbyte) { + case 0: + // end of line + // no need for special processing, just ignore + break; + + case 1: + // end of bitmap + $pixeldataoffset = strlen($BMPpixelData); // force to exit loop just in case + break; + + case 2: + // delta - The 2 bytes following the escape contain unsigned values + // indicating the horizontal and vertical offsets of the next pixel + // from the current position. + $colincrement = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); + $rowincrement = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); + $col = ($pixelcounter % $thisfile_bmp_header_raw['width']) + $colincrement; + $row = ($thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width'])) - $rowincrement; + $pixelcounter = ($row * $thisfile_bmp_header_raw['width']) + $col; + break; + + default: + // In absolute mode, the first byte is zero. The second byte contains the number + // of color indexes that follow. Subsequent bytes contain color indexes in their + // high- and low-order 4 bits, one color index for each pixel. In absolute mode, + // each run must be aligned on a word boundary. + unset($paletteindexes); + for ($i = 0; $i < ceil($secondbyte / 2); $i++) { + $paletteindexbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); + $paletteindexes[] = ($paletteindexbyte & 0xF0) >> 4; + $paletteindexes[] = ($paletteindexbyte & 0x0F); + } + while (($pixeldataoffset % 2) != 0) { + // Each run must be aligned on a word boundary. + $pixeldataoffset++; + } + + foreach ($paletteindexes as $paletteindex) { + $col = $pixelcounter % $thisfile_bmp_header_raw['width']; + $row = $thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width']); + $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; + $pixelcounter++; + } + break; + } + } else { + + // encoded mode - the first byte of the pair contains the number of pixels to be + // drawn using the color indexes in the second byte. The second byte contains two + // color indexes, one in its high-order 4 bits and one in its low-order 4 bits. + // The first of the pixels is drawn using the color specified by the high-order + // 4 bits, the second is drawn using the color in the low-order 4 bits, the third + // is drawn using the color in the high-order 4 bits, and so on, until all the + // pixels specified by the first byte have been drawn. + $paletteindexes[0] = ($secondbyte & 0xF0) >> 4; + $paletteindexes[1] = ($secondbyte & 0x0F); + for ($i = 0; $i < $firstbyte; $i++) { + $col = $pixelcounter % $thisfile_bmp_header_raw['width']; + $row = $thisfile_bmp_header_raw['height'] - 1 - (($pixelcounter - $col) / $thisfile_bmp_header_raw['width']); + $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindexes[($i % 2)]]; + $pixelcounter++; + } + } + } + break; + + default: + $this->error('Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'); + break; + } + break; + + case 3: // BI_BITFIELDS + switch ($thisfile_bmp_header_raw['bits_per_pixel']) { + case 16: + case 32: + $redshift = 0; + $greenshift = 0; + $blueshift = 0; + while ((($thisfile_bmp_header_raw['red_mask'] >> $redshift) & 0x01) == 0) { + $redshift++; + } + while ((($thisfile_bmp_header_raw['green_mask'] >> $greenshift) & 0x01) == 0) { + $greenshift++; + } + while ((($thisfile_bmp_header_raw['blue_mask'] >> $blueshift) & 0x01) == 0) { + $blueshift++; + } + for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { + for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) { + $pixelvalue = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset, $thisfile_bmp_header_raw['bits_per_pixel'] / 8)); + $pixeldataoffset += $thisfile_bmp_header_raw['bits_per_pixel'] / 8; + + $red = intval(round(((($pixelvalue & $thisfile_bmp_header_raw['red_mask']) >> $redshift) / ($thisfile_bmp_header_raw['red_mask'] >> $redshift)) * 255)); + $green = intval(round(((($pixelvalue & $thisfile_bmp_header_raw['green_mask']) >> $greenshift) / ($thisfile_bmp_header_raw['green_mask'] >> $greenshift)) * 255)); + $blue = intval(round(((($pixelvalue & $thisfile_bmp_header_raw['blue_mask']) >> $blueshift) / ($thisfile_bmp_header_raw['blue_mask'] >> $blueshift)) * 255)); + $thisfile_bmp['data'][$row][$col] = (($red << 16) | ($green << 8) | ($blue)); + } + while (($pixeldataoffset % 4) != 0) { + // lines are padded to nearest DWORD + $pixeldataoffset++; + } + } + break; + + default: + $this->error('Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'); + break; + } + break; + + default: // unhandled compression type + $this->error('Unknown/unhandled compression type value ('.$thisfile_bmp_header_raw['compression'].') - cannot decompress pixel data'); + break; + } + } + + return true; + } + + public function PlotBMP(&$BMPinfo) + { + $starttime = time(); + if (! isset($BMPinfo['bmp']['data']) || ! is_array($BMPinfo['bmp']['data'])) { + echo 'ERROR: no pixel data
    '; + + return false; + } + set_time_limit(intval(round($BMPinfo['resolution_x'] * $BMPinfo['resolution_y'] / 10000))); + if ($im = imagecreatetruecolor($BMPinfo['resolution_x'], $BMPinfo['resolution_y'])) { + for ($row = 0; $row < $BMPinfo['resolution_y']; $row++) { + for ($col = 0; $col < $BMPinfo['resolution_x']; $col++) { + if (isset($BMPinfo['bmp']['data'][$row][$col])) { + $red = ($BMPinfo['bmp']['data'][$row][$col] & 0x00FF0000) >> 16; + $green = ($BMPinfo['bmp']['data'][$row][$col] & 0x0000FF00) >> 8; + $blue = ($BMPinfo['bmp']['data'][$row][$col] & 0x000000FF); + $pixelcolor = imagecolorallocate($im, $red, $green, $blue); + imagesetpixel($im, $col, $row, $pixelcolor); + } else { + //echo 'ERROR: no data for pixel '.$row.' x '.$col.'
    '; + //return false; + } + } + } + if (headers_sent()) { + echo 'plotted '.($BMPinfo['resolution_x'] * $BMPinfo['resolution_y']).' pixels in '.(time() - $starttime).' seconds
    '; + imagedestroy($im); + exit; + } else { + header('Content-type: image/png'); + imagepng($im); + imagedestroy($im); + + return true; + } + } + + return false; + } + + public function BMPcompressionWindowsLookup($compressionid) + { + static $BMPcompressionWindowsLookup = [ + 0 => 'BI_RGB', + 1 => 'BI_RLE8', + 2 => 'BI_RLE4', + 3 => 'BI_BITFIELDS', + 4 => 'BI_JPEG', + 5 => 'BI_PNG', + ]; + + return isset($BMPcompressionWindowsLookup[$compressionid]) ? $BMPcompressionWindowsLookup[$compressionid] : 'invalid'; + } + + public function BMPcompressionOS2Lookup($compressionid) + { + static $BMPcompressionOS2Lookup = [ + 0 => 'BI_RGB', + 1 => 'BI_RLE8', + 2 => 'BI_RLE4', + 3 => 'Huffman 1D', + 4 => 'BI_RLE24', + ]; + + return isset($BMPcompressionOS2Lookup[$compressionid]) ? $BMPcompressionOS2Lookup[$compressionid] : 'invalid'; + } } diff --git a/app/Library/getid3/getid3/module.graphic.efax.php b/app/Library/getid3/getid3/module.graphic.efax.php index 8c628543..80338f24 100644 --- a/app/Library/getid3/getid3/module.graphic.efax.php +++ b/app/Library/getid3/getid3/module.graphic.efax.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,38 +15,38 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_efax extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $efaxheader = $this->fread(1024); - $this->fseek($info['avdataoffset']); - $efaxheader = $this->fread(1024); + $info['efax']['header']['magic'] = substr($efaxheader, 0, 2); + if ($info['efax']['header']['magic'] != "\xDC\xFE") { + $this->error('Invalid eFax byte order identifier (expecting DC FE, found '.getid3_lib::PrintHexBytes($info['efax']['header']['magic']).') at offset '.$info['avdataoffset']); - $info['efax']['header']['magic'] = substr($efaxheader, 0, 2); - if ($info['efax']['header']['magic'] != "\xDC\xFE") { - $this->error('Invalid eFax byte order identifier (expecting DC FE, found '.getid3_lib::PrintHexBytes($info['efax']['header']['magic']).') at offset '.$info['avdataoffset']); - return false; - } - $info['fileformat'] = 'efax'; + return false; + } + $info['fileformat'] = 'efax'; - $info['efax']['header']['filesize'] = getid3_lib::LittleEndian2Int(substr($efaxheader, 2, 4)); - if ($info['efax']['header']['filesize'] != $info['filesize']) { - $this->error('Probable '.(($info['efax']['header']['filesize'] > $info['filesize']) ? 'truncated' : 'corrupt').' file, expecting '.$info['efax']['header']['filesize'].' bytes, found '.$info['filesize'].' bytes'); - } - $info['efax']['header']['software1'] = rtrim(substr($efaxheader, 26, 32), "\x00"); - $info['efax']['header']['software2'] = rtrim(substr($efaxheader, 58, 32), "\x00"); - $info['efax']['header']['software3'] = rtrim(substr($efaxheader, 90, 32), "\x00"); + $info['efax']['header']['filesize'] = getid3_lib::LittleEndian2Int(substr($efaxheader, 2, 4)); + if ($info['efax']['header']['filesize'] != $info['filesize']) { + $this->error('Probable '.(($info['efax']['header']['filesize'] > $info['filesize']) ? 'truncated' : 'corrupt').' file, expecting '.$info['efax']['header']['filesize'].' bytes, found '.$info['filesize'].' bytes'); + } + $info['efax']['header']['software1'] = rtrim(substr($efaxheader, 26, 32), "\x00"); + $info['efax']['header']['software2'] = rtrim(substr($efaxheader, 58, 32), "\x00"); + $info['efax']['header']['software3'] = rtrim(substr($efaxheader, 90, 32), "\x00"); - $info['efax']['header']['pages'] = getid3_lib::LittleEndian2Int(substr($efaxheader, 198, 2)); - $info['efax']['header']['data_bytes'] = getid3_lib::LittleEndian2Int(substr($efaxheader, 202, 4)); + $info['efax']['header']['pages'] = getid3_lib::LittleEndian2Int(substr($efaxheader, 198, 2)); + $info['efax']['header']['data_bytes'] = getid3_lib::LittleEndian2Int(substr($efaxheader, 202, 4)); -$this->error('eFax parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); -return false; + $this->error('eFax parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); - return true; - } + return false; + return true; + } } diff --git a/app/Library/getid3/getid3/module.graphic.gif.php b/app/Library/getid3/getid3/module.graphic.gif.php index ab7d62ae..20b23454 100644 --- a/app/Library/getid3/getid3/module.graphic.gif.php +++ b/app/Library/getid3/getid3/module.graphic.gif.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,169 +15,168 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_gif extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $info['fileformat'] = 'gif'; + $info['video']['dataformat'] = 'gif'; + $info['video']['lossless'] = true; + $info['video']['pixel_aspect_ratio'] = (float) 1; - $info['fileformat'] = 'gif'; - $info['video']['dataformat'] = 'gif'; - $info['video']['lossless'] = true; - $info['video']['pixel_aspect_ratio'] = (float) 1; + $this->fseek($info['avdataoffset']); + $GIFheader = $this->fread(13); + $offset = 0; - $this->fseek($info['avdataoffset']); - $GIFheader = $this->fread(13); - $offset = 0; + $info['gif']['header']['raw']['identifier'] = substr($GIFheader, $offset, 3); + $offset += 3; - $info['gif']['header']['raw']['identifier'] = substr($GIFheader, $offset, 3); - $offset += 3; + $magic = 'GIF'; + if ($info['gif']['header']['raw']['identifier'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['gif']['header']['raw']['identifier']).'"'); + unset($info['fileformat']); + unset($info['gif']); - $magic = 'GIF'; - if ($info['gif']['header']['raw']['identifier'] != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['gif']['header']['raw']['identifier']).'"'); - unset($info['fileformat']); - unset($info['gif']); - return false; - } + return false; + } - $info['gif']['header']['raw']['version'] = substr($GIFheader, $offset, 3); - $offset += 3; - $info['gif']['header']['raw']['width'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 2)); - $offset += 2; - $info['gif']['header']['raw']['height'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 2)); - $offset += 2; - $info['gif']['header']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1)); - $offset += 1; - $info['gif']['header']['raw']['bg_color_index'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1)); - $offset += 1; - $info['gif']['header']['raw']['aspect_ratio'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1)); - $offset += 1; + $info['gif']['header']['raw']['version'] = substr($GIFheader, $offset, 3); + $offset += 3; + $info['gif']['header']['raw']['width'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 2)); + $offset += 2; + $info['gif']['header']['raw']['height'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 2)); + $offset += 2; + $info['gif']['header']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1)); + $offset += 1; + $info['gif']['header']['raw']['bg_color_index'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1)); + $offset += 1; + $info['gif']['header']['raw']['aspect_ratio'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1)); + $offset += 1; - $info['video']['resolution_x'] = $info['gif']['header']['raw']['width']; - $info['video']['resolution_y'] = $info['gif']['header']['raw']['height']; - $info['gif']['version'] = $info['gif']['header']['raw']['version']; - $info['gif']['header']['flags']['global_color_table'] = (bool) ($info['gif']['header']['raw']['flags'] & 0x80); - if ($info['gif']['header']['raw']['flags'] & 0x80) { - // Number of bits per primary color available to the original image, minus 1 - $info['gif']['header']['bits_per_pixel'] = 3 * ((($info['gif']['header']['raw']['flags'] & 0x70) >> 4) + 1); - } else { - $info['gif']['header']['bits_per_pixel'] = 0; - } - $info['gif']['header']['flags']['global_color_sorted'] = (bool) ($info['gif']['header']['raw']['flags'] & 0x40); - if ($info['gif']['header']['flags']['global_color_table']) { - // the number of bytes contained in the Global Color Table. To determine that - // actual size of the color table, raise 2 to [the value of the field + 1] - $info['gif']['header']['global_color_size'] = pow(2, ($info['gif']['header']['raw']['flags'] & 0x07) + 1); - $info['video']['bits_per_sample'] = ($info['gif']['header']['raw']['flags'] & 0x07) + 1; - } else { - $info['gif']['header']['global_color_size'] = 0; - } - if ($info['gif']['header']['raw']['aspect_ratio'] != 0) { - // Aspect Ratio = (Pixel Aspect Ratio + 15) / 64 - $info['gif']['header']['aspect_ratio'] = ($info['gif']['header']['raw']['aspect_ratio'] + 15) / 64; - } + $info['video']['resolution_x'] = $info['gif']['header']['raw']['width']; + $info['video']['resolution_y'] = $info['gif']['header']['raw']['height']; + $info['gif']['version'] = $info['gif']['header']['raw']['version']; + $info['gif']['header']['flags']['global_color_table'] = (bool) ($info['gif']['header']['raw']['flags'] & 0x80); + if ($info['gif']['header']['raw']['flags'] & 0x80) { + // Number of bits per primary color available to the original image, minus 1 + $info['gif']['header']['bits_per_pixel'] = 3 * ((($info['gif']['header']['raw']['flags'] & 0x70) >> 4) + 1); + } else { + $info['gif']['header']['bits_per_pixel'] = 0; + } + $info['gif']['header']['flags']['global_color_sorted'] = (bool) ($info['gif']['header']['raw']['flags'] & 0x40); + if ($info['gif']['header']['flags']['global_color_table']) { + // the number of bytes contained in the Global Color Table. To determine that + // actual size of the color table, raise 2 to [the value of the field + 1] + $info['gif']['header']['global_color_size'] = pow(2, ($info['gif']['header']['raw']['flags'] & 0x07) + 1); + $info['video']['bits_per_sample'] = ($info['gif']['header']['raw']['flags'] & 0x07) + 1; + } else { + $info['gif']['header']['global_color_size'] = 0; + } + if ($info['gif']['header']['raw']['aspect_ratio'] != 0) { + // Aspect Ratio = (Pixel Aspect Ratio + 15) / 64 + $info['gif']['header']['aspect_ratio'] = ($info['gif']['header']['raw']['aspect_ratio'] + 15) / 64; + } -// if ($info['gif']['header']['flags']['global_color_table']) { -// $GIFcolorTable = $this->fread(3 * $info['gif']['header']['global_color_size']); -// $offset = 0; -// for ($i = 0; $i < $info['gif']['header']['global_color_size']; $i++) { -// $red = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1)); -// $green = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1)); -// $blue = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1)); -// $info['gif']['global_color_table'][$i] = (($red << 16) | ($green << 8) | ($blue)); -// } -// } + // if ($info['gif']['header']['flags']['global_color_table']) { + // $GIFcolorTable = $this->fread(3 * $info['gif']['header']['global_color_size']); + // $offset = 0; + // for ($i = 0; $i < $info['gif']['header']['global_color_size']; $i++) { + // $red = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1)); + // $green = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1)); + // $blue = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1)); + // $info['gif']['global_color_table'][$i] = (($red << 16) | ($green << 8) | ($blue)); + // } + // } // -// // Image Descriptor -// while (!feof($this->getid3->fp)) { -// $NextBlockTest = $this->fread(1); -// switch ($NextBlockTest) { + // // Image Descriptor + // while (!feof($this->getid3->fp)) { + // $NextBlockTest = $this->fread(1); + // switch ($NextBlockTest) { // -// case ',': // ',' - Image separator character + // case ',': // ',' - Image separator character // -// $ImageDescriptorData = $NextBlockTest.$this->fread(9); -// $ImageDescriptor = array(); -// $ImageDescriptor['image_left'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 1, 2)); -// $ImageDescriptor['image_top'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 3, 2)); -// $ImageDescriptor['image_width'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 5, 2)); -// $ImageDescriptor['image_height'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 7, 2)); -// $ImageDescriptor['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 9, 1)); -// $ImageDescriptor['flags']['use_local_color_map'] = (bool) ($ImageDescriptor['flags_raw'] & 0x80); -// $ImageDescriptor['flags']['image_interlaced'] = (bool) ($ImageDescriptor['flags_raw'] & 0x40); -// $info['gif']['image_descriptor'][] = $ImageDescriptor; + // $ImageDescriptorData = $NextBlockTest.$this->fread(9); + // $ImageDescriptor = array(); + // $ImageDescriptor['image_left'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 1, 2)); + // $ImageDescriptor['image_top'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 3, 2)); + // $ImageDescriptor['image_width'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 5, 2)); + // $ImageDescriptor['image_height'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 7, 2)); + // $ImageDescriptor['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 9, 1)); + // $ImageDescriptor['flags']['use_local_color_map'] = (bool) ($ImageDescriptor['flags_raw'] & 0x80); + // $ImageDescriptor['flags']['image_interlaced'] = (bool) ($ImageDescriptor['flags_raw'] & 0x40); + // $info['gif']['image_descriptor'][] = $ImageDescriptor; // -// if ($ImageDescriptor['flags']['use_local_color_map']) { + // if ($ImageDescriptor['flags']['use_local_color_map']) { // -// $this->warning('This version of getID3() cannot parse local color maps for GIFs'); -// return true; + // $this->warning('This version of getID3() cannot parse local color maps for GIFs'); + // return true; // -// } -//echo 'Start of raster data: '.$this->ftell().'
    '; -// $RasterData = array(); -// $RasterData['code_size'] = getid3_lib::LittleEndian2Int($this->fread(1)); -// $RasterData['block_byte_count'] = getid3_lib::LittleEndian2Int($this->fread(1)); -// $info['gif']['raster_data'][count($info['gif']['image_descriptor']) - 1] = $RasterData; + // } + //echo 'Start of raster data: '.$this->ftell().'
    '; + // $RasterData = array(); + // $RasterData['code_size'] = getid3_lib::LittleEndian2Int($this->fread(1)); + // $RasterData['block_byte_count'] = getid3_lib::LittleEndian2Int($this->fread(1)); + // $info['gif']['raster_data'][count($info['gif']['image_descriptor']) - 1] = $RasterData; // -// $CurrentCodeSize = $RasterData['code_size'] + 1; -// for ($i = 0; $i < pow(2, $RasterData['code_size']); $i++) { -// $DefaultDataLookupTable[$i] = chr($i); -// } -// $DefaultDataLookupTable[pow(2, $RasterData['code_size']) + 0] = ''; // Clear Code -// $DefaultDataLookupTable[pow(2, $RasterData['code_size']) + 1] = ''; // End Of Image Code + // $CurrentCodeSize = $RasterData['code_size'] + 1; + // for ($i = 0; $i < pow(2, $RasterData['code_size']); $i++) { + // $DefaultDataLookupTable[$i] = chr($i); + // } + // $DefaultDataLookupTable[pow(2, $RasterData['code_size']) + 0] = ''; // Clear Code + // $DefaultDataLookupTable[pow(2, $RasterData['code_size']) + 1] = ''; // End Of Image Code // // -// $NextValue = $this->GetLSBits($CurrentCodeSize); -// echo 'Clear Code: '.$NextValue.'
    '; + // $NextValue = $this->GetLSBits($CurrentCodeSize); + // echo 'Clear Code: '.$NextValue.'
    '; // -// $NextValue = $this->GetLSBits($CurrentCodeSize); -// echo 'First Color: '.$NextValue.'
    '; + // $NextValue = $this->GetLSBits($CurrentCodeSize); + // echo 'First Color: '.$NextValue.'
    '; // -// $Prefix = $NextValue; -//$i = 0; -// while ($i++ < 20) { -// $NextValue = $this->GetLSBits($CurrentCodeSize); -// echo $NextValue.'
    '; -// } -//return true; -// break; + // $Prefix = $NextValue; + //$i = 0; + // while ($i++ < 20) { + // $NextValue = $this->GetLSBits($CurrentCodeSize); + // echo $NextValue.'
    '; + // } + //return true; + // break; // -// case '!': -// // GIF Extension Block -// $ExtensionBlockData = $NextBlockTest.$this->fread(2); -// $ExtensionBlock = array(); -// $ExtensionBlock['function_code'] = getid3_lib::LittleEndian2Int(substr($ExtensionBlockData, 1, 1)); -// $ExtensionBlock['byte_length'] = getid3_lib::LittleEndian2Int(substr($ExtensionBlockData, 2, 1)); -// $ExtensionBlock['data'] = $this->fread($ExtensionBlock['byte_length']); -// $info['gif']['extension_blocks'][] = $ExtensionBlock; -// break; + // case '!': + // // GIF Extension Block + // $ExtensionBlockData = $NextBlockTest.$this->fread(2); + // $ExtensionBlock = array(); + // $ExtensionBlock['function_code'] = getid3_lib::LittleEndian2Int(substr($ExtensionBlockData, 1, 1)); + // $ExtensionBlock['byte_length'] = getid3_lib::LittleEndian2Int(substr($ExtensionBlockData, 2, 1)); + // $ExtensionBlock['data'] = $this->fread($ExtensionBlock['byte_length']); + // $info['gif']['extension_blocks'][] = $ExtensionBlock; + // break; // -// case ';': -// $info['gif']['terminator_offset'] = $this->ftell() - 1; -// // GIF Terminator -// break; + // case ';': + // $info['gif']['terminator_offset'] = $this->ftell() - 1; + // // GIF Terminator + // break; // -// default: -// break; + // default: + // break; // // -// } -// } + // } + // } - return true; - } + return true; + } + public function GetLSBits($bits) + { + static $bitbuffer = ''; + while (strlen($bitbuffer) < $bits) { + $bitbuffer = str_pad(decbin(ord($this->fread(1))), 8, '0', STR_PAD_LEFT).$bitbuffer; + } + $value = bindec(substr($bitbuffer, 0 - $bits)); + $bitbuffer = substr($bitbuffer, 0, 0 - $bits); - public function GetLSBits($bits) { - static $bitbuffer = ''; - while (strlen($bitbuffer) < $bits) { - $bitbuffer = str_pad(decbin(ord($this->fread(1))), 8, '0', STR_PAD_LEFT).$bitbuffer; - } - $value = bindec(substr($bitbuffer, 0 - $bits)); - $bitbuffer = substr($bitbuffer, 0, 0 - $bits); - - return $value; - } - + return $value; + } } diff --git a/app/Library/getid3/getid3/module.graphic.jpg.php b/app/Library/getid3/getid3/module.graphic.jpg.php index 76edf145..c75f616d 100644 --- a/app/Library/getid3/getid3/module.graphic.jpg.php +++ b/app/Library/getid3/getid3/module.graphic.jpg.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -15,335 +16,330 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_jpg extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; + $info['fileformat'] = 'jpg'; + $info['video']['dataformat'] = 'jpg'; + $info['video']['lossless'] = false; + $info['video']['bits_per_sample'] = 24; + $info['video']['pixel_aspect_ratio'] = (float) 1; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); - $info['fileformat'] = 'jpg'; - $info['video']['dataformat'] = 'jpg'; - $info['video']['lossless'] = false; - $info['video']['bits_per_sample'] = 24; - $info['video']['pixel_aspect_ratio'] = (float) 1; + $imageinfo = []; + //list($width, $height, $type) = getid3_lib::GetDataImageSize($this->fread($info['filesize']), $imageinfo); + list($width, $height, $type) = getimagesize($info['filenamepath'], $imageinfo); // http://www.getid3.org/phpBB3/viewtopic.php?t=1474 - $this->fseek($info['avdataoffset']); + if (isset($imageinfo['APP13'])) { + // http://php.net/iptcparse + // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html + $iptc_parsed = iptcparse($imageinfo['APP13']); + if (is_array($iptc_parsed)) { + foreach ($iptc_parsed as $iptc_key_raw => $iptc_values) { + list($iptc_record, $iptc_tagkey) = explode('#', $iptc_key_raw); + $iptc_tagkey = intval(ltrim($iptc_tagkey, '0')); + foreach ($iptc_values as $key => $value) { + $IPTCrecordName = $this->IPTCrecordName($iptc_record); + $IPTCrecordTagName = $this->IPTCrecordTagName($iptc_record, $iptc_tagkey); + if (isset($info['iptc']['comments'][$IPTCrecordName][$IPTCrecordTagName])) { + $info['iptc']['comments'][$IPTCrecordName][$IPTCrecordTagName][] = $value; + } else { + $info['iptc']['comments'][$IPTCrecordName][$IPTCrecordTagName] = [$value]; + } + } + } + } + } - $imageinfo = array(); - //list($width, $height, $type) = getid3_lib::GetDataImageSize($this->fread($info['filesize']), $imageinfo); - list($width, $height, $type) = getimagesize($info['filenamepath'], $imageinfo); // http://www.getid3.org/phpBB3/viewtopic.php?t=1474 + $returnOK = false; + switch ($type) { + case IMG_JPG: + $info['video']['resolution_x'] = $width; + $info['video']['resolution_y'] = $height; + if (isset($imageinfo['APP1'])) { + if (function_exists('exif_read_data')) { + if (substr($imageinfo['APP1'], 0, 4) == 'Exif') { + //$this->warning('known issue: https://bugs.php.net/bug.php?id=62523'); + //return false; + set_error_handler(function ($errno, $errstr, $errfile, $errline, array $errcontext) { + if (! (error_reporting() & $errno)) { + // error is not specified in the error_reporting setting, so we ignore it + return false; + } - if (isset($imageinfo['APP13'])) { - // http://php.net/iptcparse - // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html - $iptc_parsed = iptcparse($imageinfo['APP13']); - if (is_array($iptc_parsed)) { - foreach ($iptc_parsed as $iptc_key_raw => $iptc_values) { - list($iptc_record, $iptc_tagkey) = explode('#', $iptc_key_raw); - $iptc_tagkey = intval(ltrim($iptc_tagkey, '0')); - foreach ($iptc_values as $key => $value) { - $IPTCrecordName = $this->IPTCrecordName($iptc_record); - $IPTCrecordTagName = $this->IPTCrecordTagName($iptc_record, $iptc_tagkey); - if (isset($info['iptc']['comments'][$IPTCrecordName][$IPTCrecordTagName])) { - $info['iptc']['comments'][$IPTCrecordName][$IPTCrecordTagName][] = $value; - } else { - $info['iptc']['comments'][$IPTCrecordName][$IPTCrecordTagName] = array($value); - } - } - } - } - } + $errcontext['info']['warning'][] = 'Error parsing EXIF data ('.$errstr.')'; + }); - $returnOK = false; - switch ($type) { - case IMG_JPG: - $info['video']['resolution_x'] = $width; - $info['video']['resolution_y'] = $height; + $info['jpg']['exif'] = exif_read_data($info['filenamepath'], null, true, false); - if (isset($imageinfo['APP1'])) { - if (function_exists('exif_read_data')) { - if (substr($imageinfo['APP1'], 0, 4) == 'Exif') { -//$this->warning('known issue: https://bugs.php.net/bug.php?id=62523'); -//return false; - set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) { - if (!(error_reporting() & $errno)) { - // error is not specified in the error_reporting setting, so we ignore it - return false; - } + restore_error_handler(); + } else { + $this->warning('exif_read_data() cannot parse non-EXIF data in APP1 (expected "Exif", found "'.substr($imageinfo['APP1'], 0, 4).'")'); + } + } else { + $this->warning('EXIF parsing only available when '.(GETID3_OS_ISWINDOWS ? 'php_exif.dll enabled' : 'compiled with --enable-exif')); + } + } + $returnOK = true; + break; - $errcontext['info']['warning'][] = 'Error parsing EXIF data ('.$errstr.')'; - }); + default: + break; + } - $info['jpg']['exif'] = exif_read_data($info['filenamepath'], null, true, false); + $cast_as_appropriate_keys = ['EXIF', 'IFD0', 'THUMBNAIL']; + foreach ($cast_as_appropriate_keys as $exif_key) { + if (isset($info['jpg']['exif'][$exif_key])) { + foreach ($info['jpg']['exif'][$exif_key] as $key => $value) { + $info['jpg']['exif'][$exif_key][$key] = $this->CastAsAppropriate($value); + } + } + } - restore_error_handler(); - } else { - $this->warning('exif_read_data() cannot parse non-EXIF data in APP1 (expected "Exif", found "'.substr($imageinfo['APP1'], 0, 4).'")'); - } - } else { - $this->warning('EXIF parsing only available when '.(GETID3_OS_ISWINDOWS ? 'php_exif.dll enabled' : 'compiled with --enable-exif')); - } - } - $returnOK = true; - break; + if (isset($info['jpg']['exif']['GPS'])) { + if (isset($info['jpg']['exif']['GPS']['GPSVersion'])) { + for ($i = 0; $i < 4; $i++) { + $version_subparts[$i] = ord(substr($info['jpg']['exif']['GPS']['GPSVersion'], $i, 1)); + } + $info['jpg']['exif']['GPS']['computed']['version'] = 'v'.implode('.', $version_subparts); + } - default: - break; - } + if (isset($info['jpg']['exif']['GPS']['GPSDateStamp'])) { + $explodedGPSDateStamp = explode(':', $info['jpg']['exif']['GPS']['GPSDateStamp']); + $computed_time[5] = (isset($explodedGPSDateStamp[0]) ? $explodedGPSDateStamp[0] : ''); + $computed_time[3] = (isset($explodedGPSDateStamp[1]) ? $explodedGPSDateStamp[1] : ''); + $computed_time[4] = (isset($explodedGPSDateStamp[2]) ? $explodedGPSDateStamp[2] : ''); + $computed_time = [0=>0, 1=>0, 2=>0, 3=>0, 4=>0, 5=>0]; + if (isset($info['jpg']['exif']['GPS']['GPSTimeStamp']) && is_array($info['jpg']['exif']['GPS']['GPSTimeStamp'])) { + foreach ($info['jpg']['exif']['GPS']['GPSTimeStamp'] as $key => $value) { + $computed_time[$key] = getid3_lib::DecimalizeFraction($value); + } + } + $info['jpg']['exif']['GPS']['computed']['timestamp'] = gmmktime($computed_time[0], $computed_time[1], $computed_time[2], $computed_time[3], $computed_time[4], $computed_time[5]); + } - $cast_as_appropriate_keys = array('EXIF', 'IFD0', 'THUMBNAIL'); - foreach ($cast_as_appropriate_keys as $exif_key) { - if (isset($info['jpg']['exif'][$exif_key])) { - foreach ($info['jpg']['exif'][$exif_key] as $key => $value) { - $info['jpg']['exif'][$exif_key][$key] = $this->CastAsAppropriate($value); - } - } - } + if (isset($info['jpg']['exif']['GPS']['GPSLatitude']) && is_array($info['jpg']['exif']['GPS']['GPSLatitude'])) { + $direction_multiplier = ((isset($info['jpg']['exif']['GPS']['GPSLatitudeRef']) && ($info['jpg']['exif']['GPS']['GPSLatitudeRef'] == 'S')) ? -1 : 1); + foreach ($info['jpg']['exif']['GPS']['GPSLatitude'] as $key => $value) { + $computed_latitude[$key] = getid3_lib::DecimalizeFraction($value); + } + $info['jpg']['exif']['GPS']['computed']['latitude'] = $direction_multiplier * ($computed_latitude[0] + ($computed_latitude[1] / 60) + ($computed_latitude[2] / 3600)); + } + if (isset($info['jpg']['exif']['GPS']['GPSLongitude']) && is_array($info['jpg']['exif']['GPS']['GPSLongitude'])) { + $direction_multiplier = ((isset($info['jpg']['exif']['GPS']['GPSLongitudeRef']) && ($info['jpg']['exif']['GPS']['GPSLongitudeRef'] == 'W')) ? -1 : 1); + foreach ($info['jpg']['exif']['GPS']['GPSLongitude'] as $key => $value) { + $computed_longitude[$key] = getid3_lib::DecimalizeFraction($value); + } + $info['jpg']['exif']['GPS']['computed']['longitude'] = $direction_multiplier * ($computed_longitude[0] + ($computed_longitude[1] / 60) + ($computed_longitude[2] / 3600)); + } + if (isset($info['jpg']['exif']['GPS']['GPSAltitudeRef'])) { + $info['jpg']['exif']['GPS']['GPSAltitudeRef'] = ord($info['jpg']['exif']['GPS']['GPSAltitudeRef']); // 0 = above sea level; 1 = below sea level + } + if (isset($info['jpg']['exif']['GPS']['GPSAltitude'])) { + $direction_multiplier = (! empty($info['jpg']['exif']['GPS']['GPSAltitudeRef']) ? -1 : 1); // 0 = above sea level; 1 = below sea level + $info['jpg']['exif']['GPS']['computed']['altitude'] = $direction_multiplier * getid3_lib::DecimalizeFraction($info['jpg']['exif']['GPS']['GPSAltitude']); + } + } - if (isset($info['jpg']['exif']['GPS'])) { + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.xmp.php', __FILE__, true); + if (isset($info['filenamepath'])) { + $image_xmp = new Image_XMP($info['filenamepath']); + $xmp_raw = $image_xmp->getAllTags(); + foreach ($xmp_raw as $key => $value) { + if (strpos($key, ':')) { + list($subsection, $tagname) = explode(':', $key); + $info['xmp'][$subsection][$tagname] = $this->CastAsAppropriate($value); + } else { + $this->warning('XMP: expecting ":", found "'.$key.'"'); + } + } + } - if (isset($info['jpg']['exif']['GPS']['GPSVersion'])) { - for ($i = 0; $i < 4; $i++) { - $version_subparts[$i] = ord(substr($info['jpg']['exif']['GPS']['GPSVersion'], $i, 1)); - } - $info['jpg']['exif']['GPS']['computed']['version'] = 'v'.implode('.', $version_subparts); - } + if (! $returnOK) { + unset($info['fileformat']); - if (isset($info['jpg']['exif']['GPS']['GPSDateStamp'])) { - $explodedGPSDateStamp = explode(':', $info['jpg']['exif']['GPS']['GPSDateStamp']); - $computed_time[5] = (isset($explodedGPSDateStamp[0]) ? $explodedGPSDateStamp[0] : ''); - $computed_time[3] = (isset($explodedGPSDateStamp[1]) ? $explodedGPSDateStamp[1] : ''); - $computed_time[4] = (isset($explodedGPSDateStamp[2]) ? $explodedGPSDateStamp[2] : ''); + return false; + } - $computed_time = array(0=>0, 1=>0, 2=>0, 3=>0, 4=>0, 5=>0); - if (isset($info['jpg']['exif']['GPS']['GPSTimeStamp']) && is_array($info['jpg']['exif']['GPS']['GPSTimeStamp'])) { - foreach ($info['jpg']['exif']['GPS']['GPSTimeStamp'] as $key => $value) { - $computed_time[$key] = getid3_lib::DecimalizeFraction($value); - } - } - $info['jpg']['exif']['GPS']['computed']['timestamp'] = gmmktime($computed_time[0], $computed_time[1], $computed_time[2], $computed_time[3], $computed_time[4], $computed_time[5]); - } + return true; + } - if (isset($info['jpg']['exif']['GPS']['GPSLatitude']) && is_array($info['jpg']['exif']['GPS']['GPSLatitude'])) { - $direction_multiplier = ((isset($info['jpg']['exif']['GPS']['GPSLatitudeRef']) && ($info['jpg']['exif']['GPS']['GPSLatitudeRef'] == 'S')) ? -1 : 1); - foreach ($info['jpg']['exif']['GPS']['GPSLatitude'] as $key => $value) { - $computed_latitude[$key] = getid3_lib::DecimalizeFraction($value); - } - $info['jpg']['exif']['GPS']['computed']['latitude'] = $direction_multiplier * ($computed_latitude[0] + ($computed_latitude[1] / 60) + ($computed_latitude[2] / 3600)); - } + public function CastAsAppropriate($value) + { + if (is_array($value)) { + return $value; + } elseif (preg_match('#^[0-9]+/[0-9]+$#', $value)) { + return getid3_lib::DecimalizeFraction($value); + } elseif (preg_match('#^[0-9]+$#', $value)) { + return getid3_lib::CastAsInt($value); + } elseif (preg_match('#^[0-9\.]+$#', $value)) { + return (float) $value; + } - if (isset($info['jpg']['exif']['GPS']['GPSLongitude']) && is_array($info['jpg']['exif']['GPS']['GPSLongitude'])) { - $direction_multiplier = ((isset($info['jpg']['exif']['GPS']['GPSLongitudeRef']) && ($info['jpg']['exif']['GPS']['GPSLongitudeRef'] == 'W')) ? -1 : 1); - foreach ($info['jpg']['exif']['GPS']['GPSLongitude'] as $key => $value) { - $computed_longitude[$key] = getid3_lib::DecimalizeFraction($value); - } - $info['jpg']['exif']['GPS']['computed']['longitude'] = $direction_multiplier * ($computed_longitude[0] + ($computed_longitude[1] / 60) + ($computed_longitude[2] / 3600)); - } - if (isset($info['jpg']['exif']['GPS']['GPSAltitudeRef'])) { - $info['jpg']['exif']['GPS']['GPSAltitudeRef'] = ord($info['jpg']['exif']['GPS']['GPSAltitudeRef']); // 0 = above sea level; 1 = below sea level - } - if (isset($info['jpg']['exif']['GPS']['GPSAltitude'])) { - $direction_multiplier = (!empty($info['jpg']['exif']['GPS']['GPSAltitudeRef']) ? -1 : 1); // 0 = above sea level; 1 = below sea level - $info['jpg']['exif']['GPS']['computed']['altitude'] = $direction_multiplier * getid3_lib::DecimalizeFraction($info['jpg']['exif']['GPS']['GPSAltitude']); - } + return $value; + } - } + public function IPTCrecordName($iptc_record) + { + // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html + static $IPTCrecordName = []; + if (empty($IPTCrecordName)) { + $IPTCrecordName = [ + 1 => 'IPTCEnvelope', + 2 => 'IPTCApplication', + 3 => 'IPTCNewsPhoto', + 7 => 'IPTCPreObjectData', + 8 => 'IPTCObjectData', + 9 => 'IPTCPostObjectData', + ]; + } + return isset($IPTCrecordName[$iptc_record]) ? $IPTCrecordName[$iptc_record] : ''; + } - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.xmp.php', __FILE__, true); - if (isset($info['filenamepath'])) { - $image_xmp = new Image_XMP($info['filenamepath']); - $xmp_raw = $image_xmp->getAllTags(); - foreach ($xmp_raw as $key => $value) { - if (strpos($key, ':')) { - list($subsection, $tagname) = explode(':', $key); - $info['xmp'][$subsection][$tagname] = $this->CastAsAppropriate($value); - } else { - $this->warning('XMP: expecting ":", found "'.$key.'"'); - } - } - } - - if (!$returnOK) { - unset($info['fileformat']); - return false; - } - return true; - } - - - public function CastAsAppropriate($value) { - if (is_array($value)) { - return $value; - } elseif (preg_match('#^[0-9]+/[0-9]+$#', $value)) { - return getid3_lib::DecimalizeFraction($value); - } elseif (preg_match('#^[0-9]+$#', $value)) { - return getid3_lib::CastAsInt($value); - } elseif (preg_match('#^[0-9\.]+$#', $value)) { - return (float) $value; - } - return $value; - } - - - public function IPTCrecordName($iptc_record) { - // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html - static $IPTCrecordName = array(); - if (empty($IPTCrecordName)) { - $IPTCrecordName = array( - 1 => 'IPTCEnvelope', - 2 => 'IPTCApplication', - 3 => 'IPTCNewsPhoto', - 7 => 'IPTCPreObjectData', - 8 => 'IPTCObjectData', - 9 => 'IPTCPostObjectData', - ); - } - return (isset($IPTCrecordName[$iptc_record]) ? $IPTCrecordName[$iptc_record] : ''); - } - - - public function IPTCrecordTagName($iptc_record, $iptc_tagkey) { - // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html - static $IPTCrecordTagName = array(); - if (empty($IPTCrecordTagName)) { - $IPTCrecordTagName = array( - 1 => array( // IPTC EnvelopeRecord Tags - 0 => 'EnvelopeRecordVersion', - 5 => 'Destination', - 20 => 'FileFormat', - 22 => 'FileVersion', - 30 => 'ServiceIdentifier', - 40 => 'EnvelopeNumber', - 50 => 'ProductID', - 60 => 'EnvelopePriority', - 70 => 'DateSent', - 80 => 'TimeSent', - 90 => 'CodedCharacterSet', - 100 => 'UniqueObjectName', - 120 => 'ARMIdentifier', - 122 => 'ARMVersion', - ), - 2 => array( // IPTC ApplicationRecord Tags - 0 => 'ApplicationRecordVersion', - 3 => 'ObjectTypeReference', - 4 => 'ObjectAttributeReference', - 5 => 'ObjectName', - 7 => 'EditStatus', - 8 => 'EditorialUpdate', - 10 => 'Urgency', - 12 => 'SubjectReference', - 15 => 'Category', - 20 => 'SupplementalCategories', - 22 => 'FixtureIdentifier', - 25 => 'Keywords', - 26 => 'ContentLocationCode', - 27 => 'ContentLocationName', - 30 => 'ReleaseDate', - 35 => 'ReleaseTime', - 37 => 'ExpirationDate', - 38 => 'ExpirationTime', - 40 => 'SpecialInstructions', - 42 => 'ActionAdvised', - 45 => 'ReferenceService', - 47 => 'ReferenceDate', - 50 => 'ReferenceNumber', - 55 => 'DateCreated', - 60 => 'TimeCreated', - 62 => 'DigitalCreationDate', - 63 => 'DigitalCreationTime', - 65 => 'OriginatingProgram', - 70 => 'ProgramVersion', - 75 => 'ObjectCycle', - 80 => 'By-line', - 85 => 'By-lineTitle', - 90 => 'City', - 92 => 'Sub-location', - 95 => 'Province-State', - 100 => 'Country-PrimaryLocationCode', - 101 => 'Country-PrimaryLocationName', - 103 => 'OriginalTransmissionReference', - 105 => 'Headline', - 110 => 'Credit', - 115 => 'Source', - 116 => 'CopyrightNotice', - 118 => 'Contact', - 120 => 'Caption-Abstract', - 121 => 'LocalCaption', - 122 => 'Writer-Editor', - 125 => 'RasterizedCaption', - 130 => 'ImageType', - 131 => 'ImageOrientation', - 135 => 'LanguageIdentifier', - 150 => 'AudioType', - 151 => 'AudioSamplingRate', - 152 => 'AudioSamplingResolution', - 153 => 'AudioDuration', - 154 => 'AudioOutcue', - 184 => 'JobID', - 185 => 'MasterDocumentID', - 186 => 'ShortDocumentID', - 187 => 'UniqueDocumentID', - 188 => 'OwnerID', - 200 => 'ObjectPreviewFileFormat', - 201 => 'ObjectPreviewFileVersion', - 202 => 'ObjectPreviewData', - 221 => 'Prefs', - 225 => 'ClassifyState', - 228 => 'SimilarityIndex', - 230 => 'DocumentNotes', - 231 => 'DocumentHistory', - 232 => 'ExifCameraInfo', - ), - 3 => array( // IPTC NewsPhoto Tags - 0 => 'NewsPhotoVersion', - 10 => 'IPTCPictureNumber', - 20 => 'IPTCImageWidth', - 30 => 'IPTCImageHeight', - 40 => 'IPTCPixelWidth', - 50 => 'IPTCPixelHeight', - 55 => 'SupplementalType', - 60 => 'ColorRepresentation', - 64 => 'InterchangeColorSpace', - 65 => 'ColorSequence', - 66 => 'ICC_Profile', - 70 => 'ColorCalibrationMatrix', - 80 => 'LookupTable', - 84 => 'NumIndexEntries', - 85 => 'ColorPalette', - 86 => 'IPTCBitsPerSample', - 90 => 'SampleStructure', - 100 => 'ScanningDirection', - 102 => 'IPTCImageRotation', - 110 => 'DataCompressionMethod', - 120 => 'QuantizationMethod', - 125 => 'EndPoints', - 130 => 'ExcursionTolerance', - 135 => 'BitsPerComponent', - 140 => 'MaximumDensityRange', - 145 => 'GammaCompensatedValue', - ), - 7 => array( // IPTC PreObjectData Tags - 10 => 'SizeMode', - 20 => 'MaxSubfileSize', - 90 => 'ObjectSizeAnnounced', - 95 => 'MaximumObjectSize', - ), - 8 => array( // IPTC ObjectData Tags - 10 => 'SubFile', - ), - 9 => array( // IPTC PostObjectData Tags - 10 => 'ConfirmedObjectSize', - ), - ); - - } - return (isset($IPTCrecordTagName[$iptc_record][$iptc_tagkey]) ? $IPTCrecordTagName[$iptc_record][$iptc_tagkey] : $iptc_tagkey); - } + public function IPTCrecordTagName($iptc_record, $iptc_tagkey) + { + // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html + static $IPTCrecordTagName = []; + if (empty($IPTCrecordTagName)) { + $IPTCrecordTagName = [ + 1 => [ // IPTC EnvelopeRecord Tags + 0 => 'EnvelopeRecordVersion', + 5 => 'Destination', + 20 => 'FileFormat', + 22 => 'FileVersion', + 30 => 'ServiceIdentifier', + 40 => 'EnvelopeNumber', + 50 => 'ProductID', + 60 => 'EnvelopePriority', + 70 => 'DateSent', + 80 => 'TimeSent', + 90 => 'CodedCharacterSet', + 100 => 'UniqueObjectName', + 120 => 'ARMIdentifier', + 122 => 'ARMVersion', + ], + 2 => [ // IPTC ApplicationRecord Tags + 0 => 'ApplicationRecordVersion', + 3 => 'ObjectTypeReference', + 4 => 'ObjectAttributeReference', + 5 => 'ObjectName', + 7 => 'EditStatus', + 8 => 'EditorialUpdate', + 10 => 'Urgency', + 12 => 'SubjectReference', + 15 => 'Category', + 20 => 'SupplementalCategories', + 22 => 'FixtureIdentifier', + 25 => 'Keywords', + 26 => 'ContentLocationCode', + 27 => 'ContentLocationName', + 30 => 'ReleaseDate', + 35 => 'ReleaseTime', + 37 => 'ExpirationDate', + 38 => 'ExpirationTime', + 40 => 'SpecialInstructions', + 42 => 'ActionAdvised', + 45 => 'ReferenceService', + 47 => 'ReferenceDate', + 50 => 'ReferenceNumber', + 55 => 'DateCreated', + 60 => 'TimeCreated', + 62 => 'DigitalCreationDate', + 63 => 'DigitalCreationTime', + 65 => 'OriginatingProgram', + 70 => 'ProgramVersion', + 75 => 'ObjectCycle', + 80 => 'By-line', + 85 => 'By-lineTitle', + 90 => 'City', + 92 => 'Sub-location', + 95 => 'Province-State', + 100 => 'Country-PrimaryLocationCode', + 101 => 'Country-PrimaryLocationName', + 103 => 'OriginalTransmissionReference', + 105 => 'Headline', + 110 => 'Credit', + 115 => 'Source', + 116 => 'CopyrightNotice', + 118 => 'Contact', + 120 => 'Caption-Abstract', + 121 => 'LocalCaption', + 122 => 'Writer-Editor', + 125 => 'RasterizedCaption', + 130 => 'ImageType', + 131 => 'ImageOrientation', + 135 => 'LanguageIdentifier', + 150 => 'AudioType', + 151 => 'AudioSamplingRate', + 152 => 'AudioSamplingResolution', + 153 => 'AudioDuration', + 154 => 'AudioOutcue', + 184 => 'JobID', + 185 => 'MasterDocumentID', + 186 => 'ShortDocumentID', + 187 => 'UniqueDocumentID', + 188 => 'OwnerID', + 200 => 'ObjectPreviewFileFormat', + 201 => 'ObjectPreviewFileVersion', + 202 => 'ObjectPreviewData', + 221 => 'Prefs', + 225 => 'ClassifyState', + 228 => 'SimilarityIndex', + 230 => 'DocumentNotes', + 231 => 'DocumentHistory', + 232 => 'ExifCameraInfo', + ], + 3 => [ // IPTC NewsPhoto Tags + 0 => 'NewsPhotoVersion', + 10 => 'IPTCPictureNumber', + 20 => 'IPTCImageWidth', + 30 => 'IPTCImageHeight', + 40 => 'IPTCPixelWidth', + 50 => 'IPTCPixelHeight', + 55 => 'SupplementalType', + 60 => 'ColorRepresentation', + 64 => 'InterchangeColorSpace', + 65 => 'ColorSequence', + 66 => 'ICC_Profile', + 70 => 'ColorCalibrationMatrix', + 80 => 'LookupTable', + 84 => 'NumIndexEntries', + 85 => 'ColorPalette', + 86 => 'IPTCBitsPerSample', + 90 => 'SampleStructure', + 100 => 'ScanningDirection', + 102 => 'IPTCImageRotation', + 110 => 'DataCompressionMethod', + 120 => 'QuantizationMethod', + 125 => 'EndPoints', + 130 => 'ExcursionTolerance', + 135 => 'BitsPerComponent', + 140 => 'MaximumDensityRange', + 145 => 'GammaCompensatedValue', + ], + 7 => [ // IPTC PreObjectData Tags + 10 => 'SizeMode', + 20 => 'MaxSubfileSize', + 90 => 'ObjectSizeAnnounced', + 95 => 'MaximumObjectSize', + ], + 8 => [ // IPTC ObjectData Tags + 10 => 'SubFile', + ], + 9 => [ // IPTC PostObjectData Tags + 10 => 'ConfirmedObjectSize', + ], + ]; + } + return isset($IPTCrecordTagName[$iptc_record][$iptc_tagkey]) ? $IPTCrecordTagName[$iptc_record][$iptc_tagkey] : $iptc_tagkey; + } } diff --git a/app/Library/getid3/getid3/module.graphic.pcd.php b/app/Library/getid3/getid3/module.graphic.pcd.php index c1efaa21..38e073d9 100644 --- a/app/Library/getid3/getid3/module.graphic.pcd.php +++ b/app/Library/getid3/getid3/module.graphic.pcd.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,120 +15,113 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_pcd extends getid3_handler { - public $ExtractData = 0; + public $ExtractData = 0; - public function Analyze() { - $info = &$this->getid3->info; + public function Analyze() + { + $info = &$this->getid3->info; - $info['fileformat'] = 'pcd'; - $info['video']['dataformat'] = 'pcd'; - $info['video']['lossless'] = false; + $info['fileformat'] = 'pcd'; + $info['video']['dataformat'] = 'pcd'; + $info['video']['lossless'] = false; + $this->fseek($info['avdataoffset'] + 72); - $this->fseek($info['avdataoffset'] + 72); + $PCDflags = $this->fread(1); + $PCDisVertical = ((ord($PCDflags) & 0x01) ? true : false); - $PCDflags = $this->fread(1); - $PCDisVertical = ((ord($PCDflags) & 0x01) ? true : false); + if ($PCDisVertical) { + $info['video']['resolution_x'] = 3072; + $info['video']['resolution_y'] = 2048; + } else { + $info['video']['resolution_x'] = 2048; + $info['video']['resolution_y'] = 3072; + } + if ($this->ExtractData > 3) { + $this->error('Cannot extract PSD image data for detail levels above BASE (level-3) because encrypted with Kodak-proprietary compression/encryption.'); + } elseif ($this->ExtractData > 0) { + $PCD_levels[1] = [192, 128, 0x02000]; // BASE/16 + $PCD_levels[2] = [384, 256, 0x0B800]; // BASE/4 + $PCD_levels[3] = [768, 512, 0x30000]; // BASE + //$PCD_levels[4] = array(1536, 1024, ??); // BASE*4 - encrypted with Kodak-proprietary compression/encryption + //$PCD_levels[5] = array(3072, 2048, ??); // BASE*16 - encrypted with Kodak-proprietary compression/encryption + //$PCD_levels[6] = array(6144, 4096, ??); // BASE*64 - encrypted with Kodak-proprietary compression/encryption; PhotoCD-Pro only - if ($PCDisVertical) { - $info['video']['resolution_x'] = 3072; - $info['video']['resolution_y'] = 2048; - } else { - $info['video']['resolution_x'] = 2048; - $info['video']['resolution_y'] = 3072; - } + list($PCD_width, $PCD_height, $PCD_dataOffset) = $PCD_levels[3]; + $this->fseek($info['avdataoffset'] + $PCD_dataOffset); - if ($this->ExtractData > 3) { + for ($y = 0; $y < $PCD_height; $y += 2) { + // The image-data of these subtypes start at the respective offsets of 02000h, 0b800h and 30000h. + // To decode the YcbYr to the more usual RGB-code, three lines of data have to be read, each + // consisting of ‘w’ bytes, where ‘w’ is the width of the image-subtype. The first ‘w’ bytes and + // the first half of the third ‘w’ bytes contain data for the first RGB-line, the second ‘w’ bytes + // and the second half of the third ‘w’ bytes contain data for a second RGB-line. - $this->error('Cannot extract PSD image data for detail levels above BASE (level-3) because encrypted with Kodak-proprietary compression/encryption.'); + $PCD_data_Y1 = $this->fread($PCD_width); + $PCD_data_Y2 = $this->fread($PCD_width); + $PCD_data_Cb = $this->fread(intval(round($PCD_width / 2))); + $PCD_data_Cr = $this->fread(intval(round($PCD_width / 2))); - } elseif ($this->ExtractData > 0) { + for ($x = 0; $x < $PCD_width; $x++) { + if ($PCDisVertical) { + $info['pcd']['data'][$PCD_width - $x][$y] = $this->YCbCr2RGB(ord($PCD_data_Y1[$x]), ord($PCD_data_Cb[floor($x / 2)]), ord($PCD_data_Cr[floor($x / 2)])); + $info['pcd']['data'][$PCD_width - $x][$y + 1] = $this->YCbCr2RGB(ord($PCD_data_Y2[$x]), ord($PCD_data_Cb[floor($x / 2)]), ord($PCD_data_Cr[floor($x / 2)])); + } else { + $info['pcd']['data'][$y][$x] = $this->YCbCr2RGB(ord($PCD_data_Y1[$x]), ord($PCD_data_Cb[floor($x / 2)]), ord($PCD_data_Cr[floor($x / 2)])); + $info['pcd']['data'][$y + 1][$x] = $this->YCbCr2RGB(ord($PCD_data_Y2[$x]), ord($PCD_data_Cb[floor($x / 2)]), ord($PCD_data_Cr[floor($x / 2)])); + } + } + } - $PCD_levels[1] = array( 192, 128, 0x02000); // BASE/16 - $PCD_levels[2] = array( 384, 256, 0x0B800); // BASE/4 - $PCD_levels[3] = array( 768, 512, 0x30000); // BASE - //$PCD_levels[4] = array(1536, 1024, ??); // BASE*4 - encrypted with Kodak-proprietary compression/encryption - //$PCD_levels[5] = array(3072, 2048, ??); // BASE*16 - encrypted with Kodak-proprietary compression/encryption - //$PCD_levels[6] = array(6144, 4096, ??); // BASE*64 - encrypted with Kodak-proprietary compression/encryption; PhotoCD-Pro only + // Example for plotting extracted data + //getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, true); + //if ($PCDisVertical) { + // $BMPinfo['resolution_x'] = $PCD_height; + // $BMPinfo['resolution_y'] = $PCD_width; + //} else { + // $BMPinfo['resolution_x'] = $PCD_width; + // $BMPinfo['resolution_y'] = $PCD_height; + //} + //$BMPinfo['bmp']['data'] = $info['pcd']['data']; + //getid3_bmp::PlotBMP($BMPinfo); + //exit; + } + } - list($PCD_width, $PCD_height, $PCD_dataOffset) = $PCD_levels[3]; + public function YCbCr2RGB($Y, $Cb, $Cr) + { + static $YCbCr_constants = []; + if (empty($YCbCr_constants)) { + $YCbCr_constants['red']['Y'] = 0.0054980 * 256; + $YCbCr_constants['red']['Cb'] = 0.0000000 * 256; + $YCbCr_constants['red']['Cr'] = 0.0051681 * 256; + $YCbCr_constants['green']['Y'] = 0.0054980 * 256; + $YCbCr_constants['green']['Cb'] = -0.0015446 * 256; + $YCbCr_constants['green']['Cr'] = -0.0026325 * 256; + $YCbCr_constants['blue']['Y'] = 0.0054980 * 256; + $YCbCr_constants['blue']['Cb'] = 0.0079533 * 256; + $YCbCr_constants['blue']['Cr'] = 0.0000000 * 256; + } - $this->fseek($info['avdataoffset'] + $PCD_dataOffset); - - for ($y = 0; $y < $PCD_height; $y += 2) { - // The image-data of these subtypes start at the respective offsets of 02000h, 0b800h and 30000h. - // To decode the YcbYr to the more usual RGB-code, three lines of data have to be read, each - // consisting of ‘w’ bytes, where ‘w’ is the width of the image-subtype. The first ‘w’ bytes and - // the first half of the third ‘w’ bytes contain data for the first RGB-line, the second ‘w’ bytes - // and the second half of the third ‘w’ bytes contain data for a second RGB-line. - - $PCD_data_Y1 = $this->fread($PCD_width); - $PCD_data_Y2 = $this->fread($PCD_width); - $PCD_data_Cb = $this->fread(intval(round($PCD_width / 2))); - $PCD_data_Cr = $this->fread(intval(round($PCD_width / 2))); - - for ($x = 0; $x < $PCD_width; $x++) { - if ($PCDisVertical) { - $info['pcd']['data'][$PCD_width - $x][$y] = $this->YCbCr2RGB(ord($PCD_data_Y1{$x}), ord($PCD_data_Cb{floor($x / 2)}), ord($PCD_data_Cr{floor($x / 2)})); - $info['pcd']['data'][$PCD_width - $x][$y + 1] = $this->YCbCr2RGB(ord($PCD_data_Y2{$x}), ord($PCD_data_Cb{floor($x / 2)}), ord($PCD_data_Cr{floor($x / 2)})); - } else { - $info['pcd']['data'][$y][$x] = $this->YCbCr2RGB(ord($PCD_data_Y1{$x}), ord($PCD_data_Cb{floor($x / 2)}), ord($PCD_data_Cr{floor($x / 2)})); - $info['pcd']['data'][$y + 1][$x] = $this->YCbCr2RGB(ord($PCD_data_Y2{$x}), ord($PCD_data_Cb{floor($x / 2)}), ord($PCD_data_Cr{floor($x / 2)})); - } - } - } - - // Example for plotting extracted data - //getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, true); - //if ($PCDisVertical) { - // $BMPinfo['resolution_x'] = $PCD_height; - // $BMPinfo['resolution_y'] = $PCD_width; - //} else { - // $BMPinfo['resolution_x'] = $PCD_width; - // $BMPinfo['resolution_y'] = $PCD_height; - //} - //$BMPinfo['bmp']['data'] = $info['pcd']['data']; - //getid3_bmp::PlotBMP($BMPinfo); - //exit; - - } - - } - - public function YCbCr2RGB($Y, $Cb, $Cr) { - static $YCbCr_constants = array(); - if (empty($YCbCr_constants)) { - $YCbCr_constants['red']['Y'] = 0.0054980 * 256; - $YCbCr_constants['red']['Cb'] = 0.0000000 * 256; - $YCbCr_constants['red']['Cr'] = 0.0051681 * 256; - $YCbCr_constants['green']['Y'] = 0.0054980 * 256; - $YCbCr_constants['green']['Cb'] = -0.0015446 * 256; - $YCbCr_constants['green']['Cr'] = -0.0026325 * 256; - $YCbCr_constants['blue']['Y'] = 0.0054980 * 256; - $YCbCr_constants['blue']['Cb'] = 0.0079533 * 256; - $YCbCr_constants['blue']['Cr'] = 0.0000000 * 256; - } - - $RGBcolor = array('red'=>0, 'green'=>0, 'blue'=>0); - foreach ($RGBcolor as $rgbname => $dummy) { - $RGBcolor[$rgbname] = max(0, - min(255, - intval( - round( - ($YCbCr_constants[$rgbname]['Y'] * $Y) + - ($YCbCr_constants[$rgbname]['Cb'] * ($Cb - 156)) + - ($YCbCr_constants[$rgbname]['Cr'] * ($Cr - 137)) - ) - ) - ) - ); - } - return (($RGBcolor['red'] * 65536) + ($RGBcolor['green'] * 256) + $RGBcolor['blue']); - } + $RGBcolor = ['red'=>0, 'green'=>0, 'blue'=>0]; + foreach ($RGBcolor as $rgbname => $dummy) { + $RGBcolor[$rgbname] = max(0, + min(255, + intval( + round( + ($YCbCr_constants[$rgbname]['Y'] * $Y) + + ($YCbCr_constants[$rgbname]['Cb'] * ($Cb - 156)) + + ($YCbCr_constants[$rgbname]['Cr'] * ($Cr - 137)) + ) + ) + ) + ); + } + return ($RGBcolor['red'] * 65536) + ($RGBcolor['green'] * 256) + $RGBcolor['blue']; + } } diff --git a/app/Library/getid3/getid3/module.graphic.png.php b/app/Library/getid3/getid3/module.graphic.png.php index c30caa43..5ae7c716 100644 --- a/app/Library/getid3/getid3/module.graphic.png.php +++ b/app/Library/getid3/getid3/module.graphic.png.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,517 +15,504 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_png extends getid3_handler { - public $max_data_bytes = 10000000; // if data chunk is larger than this do not read it completely (getID3 only needs the first few dozen bytes for parsing) - - public function Analyze() { - - $info = &$this->getid3->info; - - // shortcut - $info['png'] = array(); - $thisfile_png = &$info['png']; - - $info['fileformat'] = 'png'; - $info['video']['dataformat'] = 'png'; - $info['video']['lossless'] = false; - - $this->fseek($info['avdataoffset']); - $PNGfiledata = $this->fread($this->getid3->fread_buffer_size()); - $offset = 0; - - $PNGidentifier = substr($PNGfiledata, $offset, 8); // $89 $50 $4E $47 $0D $0A $1A $0A - $offset += 8; - - if ($PNGidentifier != "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") { - $this->error('First 8 bytes of file ('.getid3_lib::PrintHexBytes($PNGidentifier).') did not match expected PNG identifier'); - unset($info['fileformat']); - return false; - } - - while ((($this->ftell() - (strlen($PNGfiledata) - $offset)) < $info['filesize'])) { - $chunk['data_length'] = getid3_lib::BigEndian2Int(substr($PNGfiledata, $offset, 4)); - if ($chunk['data_length'] === false) { - $this->error('Failed to read data_length at offset '.$offset); - return false; - } - $offset += 4; - $truncated_data = false; - while (((strlen($PNGfiledata) - $offset) < ($chunk['data_length'] + 4)) && ($this->ftell() < $info['filesize'])) { - if (strlen($PNGfiledata) < $this->max_data_bytes) { - $PNGfiledata .= $this->fread($this->getid3->fread_buffer_size()); - } else { - $this->warning('At offset '.$offset.' chunk "'.substr($PNGfiledata, $offset, 4).'" exceeded max_data_bytes value of '.$this->max_data_bytes.', data chunk will be truncated at '.(strlen($PNGfiledata) - 8).' bytes'); - break; - } - } - $chunk['type_text'] = substr($PNGfiledata, $offset, 4); - $offset += 4; - $chunk['type_raw'] = getid3_lib::BigEndian2Int($chunk['type_text']); - $chunk['data'] = substr($PNGfiledata, $offset, $chunk['data_length']); - $offset += $chunk['data_length']; - $chunk['crc'] = getid3_lib::BigEndian2Int(substr($PNGfiledata, $offset, 4)); - $offset += 4; - - $chunk['flags']['ancilliary'] = (bool) ($chunk['type_raw'] & 0x20000000); - $chunk['flags']['private'] = (bool) ($chunk['type_raw'] & 0x00200000); - $chunk['flags']['reserved'] = (bool) ($chunk['type_raw'] & 0x00002000); - $chunk['flags']['safe_to_copy'] = (bool) ($chunk['type_raw'] & 0x00000020); - - // shortcut - $thisfile_png[$chunk['type_text']] = array(); - $thisfile_png_chunk_type_text = &$thisfile_png[$chunk['type_text']]; - - switch ($chunk['type_text']) { - - case 'IHDR': // Image Header - $thisfile_png_chunk_type_text['header'] = $chunk; - $thisfile_png_chunk_type_text['width'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4)); - $thisfile_png_chunk_type_text['height'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4)); - $thisfile_png_chunk_type_text['raw']['bit_depth'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 8, 1)); - $thisfile_png_chunk_type_text['raw']['color_type'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 9, 1)); - $thisfile_png_chunk_type_text['raw']['compression_method'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 10, 1)); - $thisfile_png_chunk_type_text['raw']['filter_method'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 11, 1)); - $thisfile_png_chunk_type_text['raw']['interlace_method'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 12, 1)); - - $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['raw']['compression_method']); - $thisfile_png_chunk_type_text['color_type']['palette'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x01); - $thisfile_png_chunk_type_text['color_type']['true_color'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x02); - $thisfile_png_chunk_type_text['color_type']['alpha'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x04); - - $info['video']['resolution_x'] = $thisfile_png_chunk_type_text['width']; - $info['video']['resolution_y'] = $thisfile_png_chunk_type_text['height']; - - $info['video']['bits_per_sample'] = $this->IHDRcalculateBitsPerSample($thisfile_png_chunk_type_text['raw']['color_type'], $thisfile_png_chunk_type_text['raw']['bit_depth']); - break; - - - case 'PLTE': // Palette - $thisfile_png_chunk_type_text['header'] = $chunk; - $paletteoffset = 0; - for ($i = 0; $i <= 255; $i++) { - //$thisfile_png_chunk_type_text['red'][$i] = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1)); - //$thisfile_png_chunk_type_text['green'][$i] = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1)); - //$thisfile_png_chunk_type_text['blue'][$i] = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1)); - $red = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1)); - $green = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1)); - $blue = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1)); - $thisfile_png_chunk_type_text[$i] = (($red << 16) | ($green << 8) | ($blue)); - } - break; - - - case 'tRNS': // Transparency - $thisfile_png_chunk_type_text['header'] = $chunk; - switch ($thisfile_png['IHDR']['raw']['color_type']) { - case 0: - $thisfile_png_chunk_type_text['transparent_color_gray'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 2)); - break; - - case 2: - $thisfile_png_chunk_type_text['transparent_color_red'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 2)); - $thisfile_png_chunk_type_text['transparent_color_green'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2, 2)); - $thisfile_png_chunk_type_text['transparent_color_blue'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 2)); - break; - - case 3: - for ($i = 0; $i < strlen($chunk['data']); $i++) { - $thisfile_png_chunk_type_text['palette_opacity'][$i] = getid3_lib::BigEndian2Int(substr($chunk['data'], $i, 1)); - } - break; - - case 4: - case 6: - $this->error('Invalid color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']); - - default: - $this->warning('Unhandled color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']); - break; - } - break; - - - case 'gAMA': // Image Gamma - $thisfile_png_chunk_type_text['header'] = $chunk; - $thisfile_png_chunk_type_text['gamma'] = getid3_lib::BigEndian2Int($chunk['data']) / 100000; - break; - - - case 'cHRM': // Primary Chromaticities - $thisfile_png_chunk_type_text['header'] = $chunk; - $thisfile_png_chunk_type_text['white_x'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4)) / 100000; - $thisfile_png_chunk_type_text['white_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4)) / 100000; - $thisfile_png_chunk_type_text['red_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 8, 4)) / 100000; - $thisfile_png_chunk_type_text['red_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 12, 4)) / 100000; - $thisfile_png_chunk_type_text['green_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 16, 4)) / 100000; - $thisfile_png_chunk_type_text['green_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 20, 4)) / 100000; - $thisfile_png_chunk_type_text['blue_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 24, 4)) / 100000; - $thisfile_png_chunk_type_text['blue_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 28, 4)) / 100000; - break; - - - case 'sRGB': // Standard RGB Color Space - $thisfile_png_chunk_type_text['header'] = $chunk; - $thisfile_png_chunk_type_text['reindering_intent'] = getid3_lib::BigEndian2Int($chunk['data']); - $thisfile_png_chunk_type_text['reindering_intent_text'] = $this->PNGsRGBintentLookup($thisfile_png_chunk_type_text['reindering_intent']); - break; - - - case 'iCCP': // Embedded ICC Profile - $thisfile_png_chunk_type_text['header'] = $chunk; - list($profilename, $compressiondata) = explode("\x00", $chunk['data'], 2); - $thisfile_png_chunk_type_text['profile_name'] = $profilename; - $thisfile_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int(substr($compressiondata, 0, 1)); - $thisfile_png_chunk_type_text['compression_profile'] = substr($compressiondata, 1); - - $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']); - break; - - - case 'tEXt': // Textual Data - $thisfile_png_chunk_type_text['header'] = $chunk; - list($keyword, $text) = explode("\x00", $chunk['data'], 2); - $thisfile_png_chunk_type_text['keyword'] = $keyword; - $thisfile_png_chunk_type_text['text'] = $text; - - $thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text']; - break; - - - case 'zTXt': // Compressed Textual Data - $thisfile_png_chunk_type_text['header'] = $chunk; - list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2); - $thisfile_png_chunk_type_text['keyword'] = $keyword; - $thisfile_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int(substr($otherdata, 0, 1)); - $thisfile_png_chunk_type_text['compressed_text'] = substr($otherdata, 1); - $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']); - switch ($thisfile_png_chunk_type_text['compression_method']) { - case 0: - $thisfile_png_chunk_type_text['text'] = gzuncompress($thisfile_png_chunk_type_text['compressed_text']); - break; - - default: - // unknown compression method - break; - } - - if (isset($thisfile_png_chunk_type_text['text'])) { - $thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text']; - } - break; - - - case 'iTXt': // International Textual Data - $thisfile_png_chunk_type_text['header'] = $chunk; - list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2); - $thisfile_png_chunk_type_text['keyword'] = $keyword; - $thisfile_png_chunk_type_text['compression'] = (bool) getid3_lib::BigEndian2Int(substr($otherdata, 0, 1)); - $thisfile_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int(substr($otherdata, 1, 1)); - $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']); - list($languagetag, $translatedkeyword, $text) = explode("\x00", substr($otherdata, 2), 3); - $thisfile_png_chunk_type_text['language_tag'] = $languagetag; - $thisfile_png_chunk_type_text['translated_keyword'] = $translatedkeyword; - - if ($thisfile_png_chunk_type_text['compression']) { - - switch ($thisfile_png_chunk_type_text['compression_method']) { - case 0: - $thisfile_png_chunk_type_text['text'] = gzuncompress($text); - break; - - default: - // unknown compression method - break; - } - - } else { - - $thisfile_png_chunk_type_text['text'] = $text; - - } - - if (isset($thisfile_png_chunk_type_text['text'])) { - $thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text']; - } - break; - - - case 'bKGD': // Background Color - $thisfile_png_chunk_type_text['header'] = $chunk; - switch ($thisfile_png['IHDR']['raw']['color_type']) { - case 0: - case 4: - $thisfile_png_chunk_type_text['background_gray'] = getid3_lib::BigEndian2Int($chunk['data']); - break; - - case 2: - case 6: - $thisfile_png_chunk_type_text['background_red'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth'])); - $thisfile_png_chunk_type_text['background_green'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 1 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth'])); - $thisfile_png_chunk_type_text['background_blue'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth'])); - break; - - case 3: - $thisfile_png_chunk_type_text['background_index'] = getid3_lib::BigEndian2Int($chunk['data']); - break; - - default: - break; - } - break; - - - case 'pHYs': // Physical Pixel Dimensions - $thisfile_png_chunk_type_text['header'] = $chunk; - $thisfile_png_chunk_type_text['pixels_per_unit_x'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4)); - $thisfile_png_chunk_type_text['pixels_per_unit_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4)); - $thisfile_png_chunk_type_text['unit_specifier'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 8, 1)); - $thisfile_png_chunk_type_text['unit'] = $this->PNGpHYsUnitLookup($thisfile_png_chunk_type_text['unit_specifier']); - break; - - - case 'sBIT': // Significant Bits - $thisfile_png_chunk_type_text['header'] = $chunk; - switch ($thisfile_png['IHDR']['raw']['color_type']) { - case 0: - $thisfile_png_chunk_type_text['significant_bits_gray'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1)); - break; - - case 2: - case 3: - $thisfile_png_chunk_type_text['significant_bits_red'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1)); - $thisfile_png_chunk_type_text['significant_bits_green'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 1, 1)); - $thisfile_png_chunk_type_text['significant_bits_blue'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2, 1)); - break; - - case 4: - $thisfile_png_chunk_type_text['significant_bits_gray'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1)); - $thisfile_png_chunk_type_text['significant_bits_alpha'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 1, 1)); - break; - - case 6: - $thisfile_png_chunk_type_text['significant_bits_red'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1)); - $thisfile_png_chunk_type_text['significant_bits_green'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 1, 1)); - $thisfile_png_chunk_type_text['significant_bits_blue'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2, 1)); - $thisfile_png_chunk_type_text['significant_bits_alpha'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 3, 1)); - break; - - default: - break; - } - break; - - - case 'sPLT': // Suggested Palette - $thisfile_png_chunk_type_text['header'] = $chunk; - list($palettename, $otherdata) = explode("\x00", $chunk['data'], 2); - $thisfile_png_chunk_type_text['palette_name'] = $palettename; - $sPLToffset = 0; - $thisfile_png_chunk_type_text['sample_depth_bits'] = getid3_lib::BigEndian2Int(substr($otherdata, $sPLToffset, 1)); - $sPLToffset += 1; - $thisfile_png_chunk_type_text['sample_depth_bytes'] = $thisfile_png_chunk_type_text['sample_depth_bits'] / 8; - $paletteCounter = 0; - while ($sPLToffset < strlen($otherdata)) { - $thisfile_png_chunk_type_text['red'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes'])); - $sPLToffset += $thisfile_png_chunk_type_text['sample_depth_bytes']; - $thisfile_png_chunk_type_text['green'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes'])); - $sPLToffset += $thisfile_png_chunk_type_text['sample_depth_bytes']; - $thisfile_png_chunk_type_text['blue'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes'])); - $sPLToffset += $thisfile_png_chunk_type_text['sample_depth_bytes']; - $thisfile_png_chunk_type_text['alpha'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes'])); - $sPLToffset += $thisfile_png_chunk_type_text['sample_depth_bytes']; - $thisfile_png_chunk_type_text['frequency'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $sPLToffset, 2)); - $sPLToffset += 2; - $paletteCounter++; - } - break; - - - case 'hIST': // Palette Histogram - $thisfile_png_chunk_type_text['header'] = $chunk; - $hISTcounter = 0; - while ($hISTcounter < strlen($chunk['data'])) { - $thisfile_png_chunk_type_text[$hISTcounter] = getid3_lib::BigEndian2Int(substr($chunk['data'], $hISTcounter / 2, 2)); - $hISTcounter += 2; - } - break; - - - case 'tIME': // Image Last-Modification Time - $thisfile_png_chunk_type_text['header'] = $chunk; - $thisfile_png_chunk_type_text['year'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 2)); - $thisfile_png_chunk_type_text['month'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2, 1)); - $thisfile_png_chunk_type_text['day'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 3, 1)); - $thisfile_png_chunk_type_text['hour'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 1)); - $thisfile_png_chunk_type_text['minute'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 5, 1)); - $thisfile_png_chunk_type_text['second'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 6, 1)); - $thisfile_png_chunk_type_text['unix'] = gmmktime($thisfile_png_chunk_type_text['hour'], $thisfile_png_chunk_type_text['minute'], $thisfile_png_chunk_type_text['second'], $thisfile_png_chunk_type_text['month'], $thisfile_png_chunk_type_text['day'], $thisfile_png_chunk_type_text['year']); - break; - - - case 'oFFs': // Image Offset - $thisfile_png_chunk_type_text['header'] = $chunk; - $thisfile_png_chunk_type_text['position_x'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4), false, true); - $thisfile_png_chunk_type_text['position_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4), false, true); - $thisfile_png_chunk_type_text['unit_specifier'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 8, 1)); - $thisfile_png_chunk_type_text['unit'] = $this->PNGoFFsUnitLookup($thisfile_png_chunk_type_text['unit_specifier']); - break; - - - case 'pCAL': // Calibration Of Pixel Values - $thisfile_png_chunk_type_text['header'] = $chunk; - list($calibrationname, $otherdata) = explode("\x00", $chunk['data'], 2); - $thisfile_png_chunk_type_text['calibration_name'] = $calibrationname; - $pCALoffset = 0; - $thisfile_png_chunk_type_text['original_zero'] = getid3_lib::BigEndian2Int(substr($chunk['data'], $pCALoffset, 4), false, true); - $pCALoffset += 4; - $thisfile_png_chunk_type_text['original_max'] = getid3_lib::BigEndian2Int(substr($chunk['data'], $pCALoffset, 4), false, true); - $pCALoffset += 4; - $thisfile_png_chunk_type_text['equation_type'] = getid3_lib::BigEndian2Int(substr($chunk['data'], $pCALoffset, 1)); - $pCALoffset += 1; - $thisfile_png_chunk_type_text['equation_type_text'] = $this->PNGpCALequationTypeLookup($thisfile_png_chunk_type_text['equation_type']); - $thisfile_png_chunk_type_text['parameter_count'] = getid3_lib::BigEndian2Int(substr($chunk['data'], $pCALoffset, 1)); - $pCALoffset += 1; - $thisfile_png_chunk_type_text['parameters'] = explode("\x00", substr($chunk['data'], $pCALoffset)); - break; - - - case 'sCAL': // Physical Scale Of Image Subject - $thisfile_png_chunk_type_text['header'] = $chunk; - $thisfile_png_chunk_type_text['unit_specifier'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1)); - $thisfile_png_chunk_type_text['unit'] = $this->PNGsCALUnitLookup($thisfile_png_chunk_type_text['unit_specifier']); - list($pixelwidth, $pixelheight) = explode("\x00", substr($chunk['data'], 1)); - $thisfile_png_chunk_type_text['pixel_width'] = $pixelwidth; - $thisfile_png_chunk_type_text['pixel_height'] = $pixelheight; - break; - - - case 'gIFg': // GIF Graphic Control Extension - $gIFgCounter = 0; - if (isset($thisfile_png_chunk_type_text) && is_array($thisfile_png_chunk_type_text)) { - $gIFgCounter = count($thisfile_png_chunk_type_text); - } - $thisfile_png_chunk_type_text[$gIFgCounter]['header'] = $chunk; - $thisfile_png_chunk_type_text[$gIFgCounter]['disposal_method'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1)); - $thisfile_png_chunk_type_text[$gIFgCounter]['user_input_flag'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 1, 1)); - $thisfile_png_chunk_type_text[$gIFgCounter]['delay_time'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2, 2)); - break; - - - case 'gIFx': // GIF Application Extension - $gIFxCounter = 0; - if (isset($thisfile_png_chunk_type_text) && is_array($thisfile_png_chunk_type_text)) { - $gIFxCounter = count($thisfile_png_chunk_type_text); - } - $thisfile_png_chunk_type_text[$gIFxCounter]['header'] = $chunk; - $thisfile_png_chunk_type_text[$gIFxCounter]['application_identifier'] = substr($chunk['data'], 0, 8); - $thisfile_png_chunk_type_text[$gIFxCounter]['authentication_code'] = substr($chunk['data'], 8, 3); - $thisfile_png_chunk_type_text[$gIFxCounter]['application_data'] = substr($chunk['data'], 11); - break; - - - case 'IDAT': // Image Data - $idatinformationfieldindex = 0; - if (isset($thisfile_png['IDAT']) && is_array($thisfile_png['IDAT'])) { - $idatinformationfieldindex = count($thisfile_png['IDAT']); - } - unset($chunk['data']); - $thisfile_png_chunk_type_text[$idatinformationfieldindex]['header'] = $chunk; - break; - - - case 'IEND': // Image Trailer - $thisfile_png_chunk_type_text['header'] = $chunk; - break; - - - default: - //unset($chunk['data']); - $thisfile_png_chunk_type_text['header'] = $chunk; - $this->warning('Unhandled chunk type: '.$chunk['type_text']); - break; - } - } - - return true; - } - - public function PNGsRGBintentLookup($sRGB) { - static $PNGsRGBintentLookup = array( - 0 => 'Perceptual', - 1 => 'Relative colorimetric', - 2 => 'Saturation', - 3 => 'Absolute colorimetric' - ); - return (isset($PNGsRGBintentLookup[$sRGB]) ? $PNGsRGBintentLookup[$sRGB] : 'invalid'); - } - - public function PNGcompressionMethodLookup($compressionmethod) { - static $PNGcompressionMethodLookup = array( - 0 => 'deflate/inflate' - ); - return (isset($PNGcompressionMethodLookup[$compressionmethod]) ? $PNGcompressionMethodLookup[$compressionmethod] : 'invalid'); - } - - public function PNGpHYsUnitLookup($unitid) { - static $PNGpHYsUnitLookup = array( - 0 => 'unknown', - 1 => 'meter' - ); - return (isset($PNGpHYsUnitLookup[$unitid]) ? $PNGpHYsUnitLookup[$unitid] : 'invalid'); - } - - public function PNGoFFsUnitLookup($unitid) { - static $PNGoFFsUnitLookup = array( - 0 => 'pixel', - 1 => 'micrometer' - ); - return (isset($PNGoFFsUnitLookup[$unitid]) ? $PNGoFFsUnitLookup[$unitid] : 'invalid'); - } - - public function PNGpCALequationTypeLookup($equationtype) { - static $PNGpCALequationTypeLookup = array( - 0 => 'Linear mapping', - 1 => 'Base-e exponential mapping', - 2 => 'Arbitrary-base exponential mapping', - 3 => 'Hyperbolic mapping' - ); - return (isset($PNGpCALequationTypeLookup[$equationtype]) ? $PNGpCALequationTypeLookup[$equationtype] : 'invalid'); - } - - public function PNGsCALUnitLookup($unitid) { - static $PNGsCALUnitLookup = array( - 0 => 'meter', - 1 => 'radian' - ); - return (isset($PNGsCALUnitLookup[$unitid]) ? $PNGsCALUnitLookup[$unitid] : 'invalid'); - } - - public function IHDRcalculateBitsPerSample($color_type, $bit_depth) { - switch ($color_type) { - case 0: // Each pixel is a grayscale sample. - return $bit_depth; - break; - - case 2: // Each pixel is an R,G,B triple - return 3 * $bit_depth; - break; - - case 3: // Each pixel is a palette index; a PLTE chunk must appear. - return $bit_depth; - break; - - case 4: // Each pixel is a grayscale sample, followed by an alpha sample. - return 2 * $bit_depth; - break; - - case 6: // Each pixel is an R,G,B triple, followed by an alpha sample. - return 4 * $bit_depth; - break; - } - return false; - } - + public $max_data_bytes = 10000000; // if data chunk is larger than this do not read it completely (getID3 only needs the first few dozen bytes for parsing) + + public function Analyze() + { + $info = &$this->getid3->info; + + // shortcut + $info['png'] = []; + $thisfile_png = &$info['png']; + + $info['fileformat'] = 'png'; + $info['video']['dataformat'] = 'png'; + $info['video']['lossless'] = false; + + $this->fseek($info['avdataoffset']); + $PNGfiledata = $this->fread($this->getid3->fread_buffer_size()); + $offset = 0; + + $PNGidentifier = substr($PNGfiledata, $offset, 8); // $89 $50 $4E $47 $0D $0A $1A $0A + $offset += 8; + + if ($PNGidentifier != "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") { + $this->error('First 8 bytes of file ('.getid3_lib::PrintHexBytes($PNGidentifier).') did not match expected PNG identifier'); + unset($info['fileformat']); + + return false; + } + + while ((($this->ftell() - (strlen($PNGfiledata) - $offset)) < $info['filesize'])) { + $chunk['data_length'] = getid3_lib::BigEndian2Int(substr($PNGfiledata, $offset, 4)); + if ($chunk['data_length'] === false) { + $this->error('Failed to read data_length at offset '.$offset); + + return false; + } + $offset += 4; + $truncated_data = false; + while (((strlen($PNGfiledata) - $offset) < ($chunk['data_length'] + 4)) && ($this->ftell() < $info['filesize'])) { + if (strlen($PNGfiledata) < $this->max_data_bytes) { + $PNGfiledata .= $this->fread($this->getid3->fread_buffer_size()); + } else { + $this->warning('At offset '.$offset.' chunk "'.substr($PNGfiledata, $offset, 4).'" exceeded max_data_bytes value of '.$this->max_data_bytes.', data chunk will be truncated at '.(strlen($PNGfiledata) - 8).' bytes'); + break; + } + } + $chunk['type_text'] = substr($PNGfiledata, $offset, 4); + $offset += 4; + $chunk['type_raw'] = getid3_lib::BigEndian2Int($chunk['type_text']); + $chunk['data'] = substr($PNGfiledata, $offset, $chunk['data_length']); + $offset += $chunk['data_length']; + $chunk['crc'] = getid3_lib::BigEndian2Int(substr($PNGfiledata, $offset, 4)); + $offset += 4; + + $chunk['flags']['ancilliary'] = (bool) ($chunk['type_raw'] & 0x20000000); + $chunk['flags']['private'] = (bool) ($chunk['type_raw'] & 0x00200000); + $chunk['flags']['reserved'] = (bool) ($chunk['type_raw'] & 0x00002000); + $chunk['flags']['safe_to_copy'] = (bool) ($chunk['type_raw'] & 0x00000020); + + // shortcut + $thisfile_png[$chunk['type_text']] = []; + $thisfile_png_chunk_type_text = &$thisfile_png[$chunk['type_text']]; + + switch ($chunk['type_text']) { + + case 'IHDR': // Image Header + $thisfile_png_chunk_type_text['header'] = $chunk; + $thisfile_png_chunk_type_text['width'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4)); + $thisfile_png_chunk_type_text['height'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4)); + $thisfile_png_chunk_type_text['raw']['bit_depth'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 8, 1)); + $thisfile_png_chunk_type_text['raw']['color_type'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 9, 1)); + $thisfile_png_chunk_type_text['raw']['compression_method'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 10, 1)); + $thisfile_png_chunk_type_text['raw']['filter_method'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 11, 1)); + $thisfile_png_chunk_type_text['raw']['interlace_method'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 12, 1)); + + $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['raw']['compression_method']); + $thisfile_png_chunk_type_text['color_type']['palette'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x01); + $thisfile_png_chunk_type_text['color_type']['true_color'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x02); + $thisfile_png_chunk_type_text['color_type']['alpha'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x04); + + $info['video']['resolution_x'] = $thisfile_png_chunk_type_text['width']; + $info['video']['resolution_y'] = $thisfile_png_chunk_type_text['height']; + + $info['video']['bits_per_sample'] = $this->IHDRcalculateBitsPerSample($thisfile_png_chunk_type_text['raw']['color_type'], $thisfile_png_chunk_type_text['raw']['bit_depth']); + break; + + case 'PLTE': // Palette + $thisfile_png_chunk_type_text['header'] = $chunk; + $paletteoffset = 0; + for ($i = 0; $i <= 255; $i++) { + //$thisfile_png_chunk_type_text['red'][$i] = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1)); + //$thisfile_png_chunk_type_text['green'][$i] = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1)); + //$thisfile_png_chunk_type_text['blue'][$i] = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1)); + $red = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1)); + $green = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1)); + $blue = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1)); + $thisfile_png_chunk_type_text[$i] = (($red << 16) | ($green << 8) | ($blue)); + } + break; + + case 'tRNS': // Transparency + $thisfile_png_chunk_type_text['header'] = $chunk; + switch ($thisfile_png['IHDR']['raw']['color_type']) { + case 0: + $thisfile_png_chunk_type_text['transparent_color_gray'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 2)); + break; + + case 2: + $thisfile_png_chunk_type_text['transparent_color_red'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 2)); + $thisfile_png_chunk_type_text['transparent_color_green'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2, 2)); + $thisfile_png_chunk_type_text['transparent_color_blue'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 2)); + break; + + case 3: + for ($i = 0; $i < strlen($chunk['data']); $i++) { + $thisfile_png_chunk_type_text['palette_opacity'][$i] = getid3_lib::BigEndian2Int(substr($chunk['data'], $i, 1)); + } + break; + + case 4: + case 6: + $this->error('Invalid color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']); + + default: + $this->warning('Unhandled color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']); + break; + } + break; + + case 'gAMA': // Image Gamma + $thisfile_png_chunk_type_text['header'] = $chunk; + $thisfile_png_chunk_type_text['gamma'] = getid3_lib::BigEndian2Int($chunk['data']) / 100000; + break; + + case 'cHRM': // Primary Chromaticities + $thisfile_png_chunk_type_text['header'] = $chunk; + $thisfile_png_chunk_type_text['white_x'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4)) / 100000; + $thisfile_png_chunk_type_text['white_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4)) / 100000; + $thisfile_png_chunk_type_text['red_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 8, 4)) / 100000; + $thisfile_png_chunk_type_text['red_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 12, 4)) / 100000; + $thisfile_png_chunk_type_text['green_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 16, 4)) / 100000; + $thisfile_png_chunk_type_text['green_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 20, 4)) / 100000; + $thisfile_png_chunk_type_text['blue_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 24, 4)) / 100000; + $thisfile_png_chunk_type_text['blue_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 28, 4)) / 100000; + break; + + case 'sRGB': // Standard RGB Color Space + $thisfile_png_chunk_type_text['header'] = $chunk; + $thisfile_png_chunk_type_text['reindering_intent'] = getid3_lib::BigEndian2Int($chunk['data']); + $thisfile_png_chunk_type_text['reindering_intent_text'] = $this->PNGsRGBintentLookup($thisfile_png_chunk_type_text['reindering_intent']); + break; + + case 'iCCP': // Embedded ICC Profile + $thisfile_png_chunk_type_text['header'] = $chunk; + list($profilename, $compressiondata) = explode("\x00", $chunk['data'], 2); + $thisfile_png_chunk_type_text['profile_name'] = $profilename; + $thisfile_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int(substr($compressiondata, 0, 1)); + $thisfile_png_chunk_type_text['compression_profile'] = substr($compressiondata, 1); + + $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']); + break; + + case 'tEXt': // Textual Data + $thisfile_png_chunk_type_text['header'] = $chunk; + list($keyword, $text) = explode("\x00", $chunk['data'], 2); + $thisfile_png_chunk_type_text['keyword'] = $keyword; + $thisfile_png_chunk_type_text['text'] = $text; + + $thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text']; + break; + + case 'zTXt': // Compressed Textual Data + $thisfile_png_chunk_type_text['header'] = $chunk; + list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2); + $thisfile_png_chunk_type_text['keyword'] = $keyword; + $thisfile_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int(substr($otherdata, 0, 1)); + $thisfile_png_chunk_type_text['compressed_text'] = substr($otherdata, 1); + $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']); + switch ($thisfile_png_chunk_type_text['compression_method']) { + case 0: + $thisfile_png_chunk_type_text['text'] = gzuncompress($thisfile_png_chunk_type_text['compressed_text']); + break; + + default: + // unknown compression method + break; + } + + if (isset($thisfile_png_chunk_type_text['text'])) { + $thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text']; + } + break; + + case 'iTXt': // International Textual Data + $thisfile_png_chunk_type_text['header'] = $chunk; + list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2); + $thisfile_png_chunk_type_text['keyword'] = $keyword; + $thisfile_png_chunk_type_text['compression'] = (bool) getid3_lib::BigEndian2Int(substr($otherdata, 0, 1)); + $thisfile_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int(substr($otherdata, 1, 1)); + $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']); + list($languagetag, $translatedkeyword, $text) = explode("\x00", substr($otherdata, 2), 3); + $thisfile_png_chunk_type_text['language_tag'] = $languagetag; + $thisfile_png_chunk_type_text['translated_keyword'] = $translatedkeyword; + + if ($thisfile_png_chunk_type_text['compression']) { + switch ($thisfile_png_chunk_type_text['compression_method']) { + case 0: + $thisfile_png_chunk_type_text['text'] = gzuncompress($text); + break; + + default: + // unknown compression method + break; + } + } else { + $thisfile_png_chunk_type_text['text'] = $text; + } + + if (isset($thisfile_png_chunk_type_text['text'])) { + $thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text']; + } + break; + + case 'bKGD': // Background Color + $thisfile_png_chunk_type_text['header'] = $chunk; + switch ($thisfile_png['IHDR']['raw']['color_type']) { + case 0: + case 4: + $thisfile_png_chunk_type_text['background_gray'] = getid3_lib::BigEndian2Int($chunk['data']); + break; + + case 2: + case 6: + $thisfile_png_chunk_type_text['background_red'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth'])); + $thisfile_png_chunk_type_text['background_green'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 1 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth'])); + $thisfile_png_chunk_type_text['background_blue'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth'])); + break; + + case 3: + $thisfile_png_chunk_type_text['background_index'] = getid3_lib::BigEndian2Int($chunk['data']); + break; + + default: + break; + } + break; + + case 'pHYs': // Physical Pixel Dimensions + $thisfile_png_chunk_type_text['header'] = $chunk; + $thisfile_png_chunk_type_text['pixels_per_unit_x'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4)); + $thisfile_png_chunk_type_text['pixels_per_unit_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4)); + $thisfile_png_chunk_type_text['unit_specifier'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 8, 1)); + $thisfile_png_chunk_type_text['unit'] = $this->PNGpHYsUnitLookup($thisfile_png_chunk_type_text['unit_specifier']); + break; + + case 'sBIT': // Significant Bits + $thisfile_png_chunk_type_text['header'] = $chunk; + switch ($thisfile_png['IHDR']['raw']['color_type']) { + case 0: + $thisfile_png_chunk_type_text['significant_bits_gray'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1)); + break; + + case 2: + case 3: + $thisfile_png_chunk_type_text['significant_bits_red'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1)); + $thisfile_png_chunk_type_text['significant_bits_green'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 1, 1)); + $thisfile_png_chunk_type_text['significant_bits_blue'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2, 1)); + break; + + case 4: + $thisfile_png_chunk_type_text['significant_bits_gray'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1)); + $thisfile_png_chunk_type_text['significant_bits_alpha'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 1, 1)); + break; + + case 6: + $thisfile_png_chunk_type_text['significant_bits_red'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1)); + $thisfile_png_chunk_type_text['significant_bits_green'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 1, 1)); + $thisfile_png_chunk_type_text['significant_bits_blue'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2, 1)); + $thisfile_png_chunk_type_text['significant_bits_alpha'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 3, 1)); + break; + + default: + break; + } + break; + + case 'sPLT': // Suggested Palette + $thisfile_png_chunk_type_text['header'] = $chunk; + list($palettename, $otherdata) = explode("\x00", $chunk['data'], 2); + $thisfile_png_chunk_type_text['palette_name'] = $palettename; + $sPLToffset = 0; + $thisfile_png_chunk_type_text['sample_depth_bits'] = getid3_lib::BigEndian2Int(substr($otherdata, $sPLToffset, 1)); + $sPLToffset += 1; + $thisfile_png_chunk_type_text['sample_depth_bytes'] = $thisfile_png_chunk_type_text['sample_depth_bits'] / 8; + $paletteCounter = 0; + while ($sPLToffset < strlen($otherdata)) { + $thisfile_png_chunk_type_text['red'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes'])); + $sPLToffset += $thisfile_png_chunk_type_text['sample_depth_bytes']; + $thisfile_png_chunk_type_text['green'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes'])); + $sPLToffset += $thisfile_png_chunk_type_text['sample_depth_bytes']; + $thisfile_png_chunk_type_text['blue'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes'])); + $sPLToffset += $thisfile_png_chunk_type_text['sample_depth_bytes']; + $thisfile_png_chunk_type_text['alpha'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes'])); + $sPLToffset += $thisfile_png_chunk_type_text['sample_depth_bytes']; + $thisfile_png_chunk_type_text['frequency'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $sPLToffset, 2)); + $sPLToffset += 2; + $paletteCounter++; + } + break; + + case 'hIST': // Palette Histogram + $thisfile_png_chunk_type_text['header'] = $chunk; + $hISTcounter = 0; + while ($hISTcounter < strlen($chunk['data'])) { + $thisfile_png_chunk_type_text[$hISTcounter] = getid3_lib::BigEndian2Int(substr($chunk['data'], $hISTcounter / 2, 2)); + $hISTcounter += 2; + } + break; + + case 'tIME': // Image Last-Modification Time + $thisfile_png_chunk_type_text['header'] = $chunk; + $thisfile_png_chunk_type_text['year'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 2)); + $thisfile_png_chunk_type_text['month'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2, 1)); + $thisfile_png_chunk_type_text['day'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 3, 1)); + $thisfile_png_chunk_type_text['hour'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 1)); + $thisfile_png_chunk_type_text['minute'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 5, 1)); + $thisfile_png_chunk_type_text['second'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 6, 1)); + $thisfile_png_chunk_type_text['unix'] = gmmktime($thisfile_png_chunk_type_text['hour'], $thisfile_png_chunk_type_text['minute'], $thisfile_png_chunk_type_text['second'], $thisfile_png_chunk_type_text['month'], $thisfile_png_chunk_type_text['day'], $thisfile_png_chunk_type_text['year']); + break; + + case 'oFFs': // Image Offset + $thisfile_png_chunk_type_text['header'] = $chunk; + $thisfile_png_chunk_type_text['position_x'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4), false, true); + $thisfile_png_chunk_type_text['position_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4), false, true); + $thisfile_png_chunk_type_text['unit_specifier'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 8, 1)); + $thisfile_png_chunk_type_text['unit'] = $this->PNGoFFsUnitLookup($thisfile_png_chunk_type_text['unit_specifier']); + break; + + case 'pCAL': // Calibration Of Pixel Values + $thisfile_png_chunk_type_text['header'] = $chunk; + list($calibrationname, $otherdata) = explode("\x00", $chunk['data'], 2); + $thisfile_png_chunk_type_text['calibration_name'] = $calibrationname; + $pCALoffset = 0; + $thisfile_png_chunk_type_text['original_zero'] = getid3_lib::BigEndian2Int(substr($chunk['data'], $pCALoffset, 4), false, true); + $pCALoffset += 4; + $thisfile_png_chunk_type_text['original_max'] = getid3_lib::BigEndian2Int(substr($chunk['data'], $pCALoffset, 4), false, true); + $pCALoffset += 4; + $thisfile_png_chunk_type_text['equation_type'] = getid3_lib::BigEndian2Int(substr($chunk['data'], $pCALoffset, 1)); + $pCALoffset += 1; + $thisfile_png_chunk_type_text['equation_type_text'] = $this->PNGpCALequationTypeLookup($thisfile_png_chunk_type_text['equation_type']); + $thisfile_png_chunk_type_text['parameter_count'] = getid3_lib::BigEndian2Int(substr($chunk['data'], $pCALoffset, 1)); + $pCALoffset += 1; + $thisfile_png_chunk_type_text['parameters'] = explode("\x00", substr($chunk['data'], $pCALoffset)); + break; + + case 'sCAL': // Physical Scale Of Image Subject + $thisfile_png_chunk_type_text['header'] = $chunk; + $thisfile_png_chunk_type_text['unit_specifier'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1)); + $thisfile_png_chunk_type_text['unit'] = $this->PNGsCALUnitLookup($thisfile_png_chunk_type_text['unit_specifier']); + list($pixelwidth, $pixelheight) = explode("\x00", substr($chunk['data'], 1)); + $thisfile_png_chunk_type_text['pixel_width'] = $pixelwidth; + $thisfile_png_chunk_type_text['pixel_height'] = $pixelheight; + break; + + case 'gIFg': // GIF Graphic Control Extension + $gIFgCounter = 0; + if (isset($thisfile_png_chunk_type_text) && is_array($thisfile_png_chunk_type_text)) { + $gIFgCounter = count($thisfile_png_chunk_type_text); + } + $thisfile_png_chunk_type_text[$gIFgCounter]['header'] = $chunk; + $thisfile_png_chunk_type_text[$gIFgCounter]['disposal_method'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1)); + $thisfile_png_chunk_type_text[$gIFgCounter]['user_input_flag'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 1, 1)); + $thisfile_png_chunk_type_text[$gIFgCounter]['delay_time'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2, 2)); + break; + + case 'gIFx': // GIF Application Extension + $gIFxCounter = 0; + if (isset($thisfile_png_chunk_type_text) && is_array($thisfile_png_chunk_type_text)) { + $gIFxCounter = count($thisfile_png_chunk_type_text); + } + $thisfile_png_chunk_type_text[$gIFxCounter]['header'] = $chunk; + $thisfile_png_chunk_type_text[$gIFxCounter]['application_identifier'] = substr($chunk['data'], 0, 8); + $thisfile_png_chunk_type_text[$gIFxCounter]['authentication_code'] = substr($chunk['data'], 8, 3); + $thisfile_png_chunk_type_text[$gIFxCounter]['application_data'] = substr($chunk['data'], 11); + break; + + case 'IDAT': // Image Data + $idatinformationfieldindex = 0; + if (isset($thisfile_png['IDAT']) && is_array($thisfile_png['IDAT'])) { + $idatinformationfieldindex = count($thisfile_png['IDAT']); + } + unset($chunk['data']); + $thisfile_png_chunk_type_text[$idatinformationfieldindex]['header'] = $chunk; + break; + + case 'IEND': // Image Trailer + $thisfile_png_chunk_type_text['header'] = $chunk; + break; + + default: + //unset($chunk['data']); + $thisfile_png_chunk_type_text['header'] = $chunk; + $this->warning('Unhandled chunk type: '.$chunk['type_text']); + break; + } + } + + return true; + } + + public function PNGsRGBintentLookup($sRGB) + { + static $PNGsRGBintentLookup = [ + 0 => 'Perceptual', + 1 => 'Relative colorimetric', + 2 => 'Saturation', + 3 => 'Absolute colorimetric', + ]; + + return isset($PNGsRGBintentLookup[$sRGB]) ? $PNGsRGBintentLookup[$sRGB] : 'invalid'; + } + + public function PNGcompressionMethodLookup($compressionmethod) + { + static $PNGcompressionMethodLookup = [ + 0 => 'deflate/inflate', + ]; + + return isset($PNGcompressionMethodLookup[$compressionmethod]) ? $PNGcompressionMethodLookup[$compressionmethod] : 'invalid'; + } + + public function PNGpHYsUnitLookup($unitid) + { + static $PNGpHYsUnitLookup = [ + 0 => 'unknown', + 1 => 'meter', + ]; + + return isset($PNGpHYsUnitLookup[$unitid]) ? $PNGpHYsUnitLookup[$unitid] : 'invalid'; + } + + public function PNGoFFsUnitLookup($unitid) + { + static $PNGoFFsUnitLookup = [ + 0 => 'pixel', + 1 => 'micrometer', + ]; + + return isset($PNGoFFsUnitLookup[$unitid]) ? $PNGoFFsUnitLookup[$unitid] : 'invalid'; + } + + public function PNGpCALequationTypeLookup($equationtype) + { + static $PNGpCALequationTypeLookup = [ + 0 => 'Linear mapping', + 1 => 'Base-e exponential mapping', + 2 => 'Arbitrary-base exponential mapping', + 3 => 'Hyperbolic mapping', + ]; + + return isset($PNGpCALequationTypeLookup[$equationtype]) ? $PNGpCALequationTypeLookup[$equationtype] : 'invalid'; + } + + public function PNGsCALUnitLookup($unitid) + { + static $PNGsCALUnitLookup = [ + 0 => 'meter', + 1 => 'radian', + ]; + + return isset($PNGsCALUnitLookup[$unitid]) ? $PNGsCALUnitLookup[$unitid] : 'invalid'; + } + + public function IHDRcalculateBitsPerSample($color_type, $bit_depth) + { + switch ($color_type) { + case 0: // Each pixel is a grayscale sample. + return $bit_depth; + break; + + case 2: // Each pixel is an R,G,B triple + return 3 * $bit_depth; + break; + + case 3: // Each pixel is a palette index; a PLTE chunk must appear. + return $bit_depth; + break; + + case 4: // Each pixel is a grayscale sample, followed by an alpha sample. + return 2 * $bit_depth; + break; + + case 6: // Each pixel is an R,G,B triple, followed by an alpha sample. + return 4 * $bit_depth; + break; + } + + return false; + } } diff --git a/app/Library/getid3/getid3/module.graphic.svg.php b/app/Library/getid3/getid3/module.graphic.svg.php index e4502aae..debfed8f 100644 --- a/app/Library/getid3/getid3/module.graphic.svg.php +++ b/app/Library/getid3/getid3/module.graphic.svg.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,89 +15,86 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_svg extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); - public function Analyze() { - $info = &$this->getid3->info; + $SVGheader = $this->fread(4096); + if (preg_match('#\<\?xml([^\>]+)\?\>#i', $SVGheader, $matches)) { + $info['svg']['xml']['raw'] = $matches; + } + if (preg_match('#\<\!DOCTYPE([^\>]+)\>#i', $SVGheader, $matches)) { + $info['svg']['doctype']['raw'] = $matches; + } + if (preg_match('#\]+)\>#i', $SVGheader, $matches)) { + $info['svg']['svg']['raw'] = $matches; + } + if (isset($info['svg']['svg']['raw'])) { + $sections_to_fix = ['xml', 'doctype', 'svg']; + foreach ($sections_to_fix as $section_to_fix) { + if (! isset($info['svg'][$section_to_fix])) { + continue; + } + $section_data = []; + while (preg_match('/ "([^"]+)"/', $info['svg'][$section_to_fix]['raw'][1], $matches)) { + $section_data[] = $matches[1]; + $info['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $info['svg'][$section_to_fix]['raw'][1]); + } + while (preg_match('/([^\s]+)="([^"]+)"/', $info['svg'][$section_to_fix]['raw'][1], $matches)) { + $section_data[] = $matches[0]; + $info['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $info['svg'][$section_to_fix]['raw'][1]); + } + $section_data = array_merge($section_data, preg_split('/[\s,]+/', $info['svg'][$section_to_fix]['raw'][1])); + foreach ($section_data as $keyvaluepair) { + $keyvaluepair = trim($keyvaluepair); + if ($keyvaluepair) { + $keyvalueexploded = explode('=', $keyvaluepair); + $key = (isset($keyvalueexploded[0]) ? $keyvalueexploded[0] : ''); + $value = (isset($keyvalueexploded[1]) ? $keyvalueexploded[1] : ''); + $info['svg'][$section_to_fix]['sections'][$key] = trim($value, '"'); + } + } + } - $this->fseek($info['avdataoffset']); + $info['fileformat'] = 'svg'; + $info['video']['dataformat'] = 'svg'; + $info['video']['lossless'] = true; + //$info['video']['bits_per_sample'] = 24; + $info['video']['pixel_aspect_ratio'] = (float) 1; - $SVGheader = $this->fread(4096); - if (preg_match('#\<\?xml([^\>]+)\?\>#i', $SVGheader, $matches)) { - $info['svg']['xml']['raw'] = $matches; - } - if (preg_match('#\<\!DOCTYPE([^\>]+)\>#i', $SVGheader, $matches)) { - $info['svg']['doctype']['raw'] = $matches; - } - if (preg_match('#\]+)\>#i', $SVGheader, $matches)) { - $info['svg']['svg']['raw'] = $matches; - } - if (isset($info['svg']['svg']['raw'])) { + if (! empty($info['svg']['svg']['sections']['width'])) { + $info['svg']['width'] = intval($info['svg']['svg']['sections']['width']); + } + if (! empty($info['svg']['svg']['sections']['height'])) { + $info['svg']['height'] = intval($info['svg']['svg']['sections']['height']); + } + if (! empty($info['svg']['svg']['sections']['version'])) { + $info['svg']['version'] = $info['svg']['svg']['sections']['version']; + } + if (! isset($info['svg']['version']) && isset($info['svg']['doctype']['sections'])) { + foreach ($info['svg']['doctype']['sections'] as $key => $value) { + if (preg_match('#//W3C//DTD SVG ([0-9\.]+)//#i', $key, $matches)) { + $info['svg']['version'] = $matches[1]; + break; + } + } + } - $sections_to_fix = array('xml', 'doctype', 'svg'); - foreach ($sections_to_fix as $section_to_fix) { - if (!isset($info['svg'][$section_to_fix])) { - continue; - } - $section_data = array(); - while (preg_match('/ "([^"]+)"/', $info['svg'][$section_to_fix]['raw'][1], $matches)) { - $section_data[] = $matches[1]; - $info['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $info['svg'][$section_to_fix]['raw'][1]); - } - while (preg_match('/([^\s]+)="([^"]+)"/', $info['svg'][$section_to_fix]['raw'][1], $matches)) { - $section_data[] = $matches[0]; - $info['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $info['svg'][$section_to_fix]['raw'][1]); - } - $section_data = array_merge($section_data, preg_split('/[\s,]+/', $info['svg'][$section_to_fix]['raw'][1])); - foreach ($section_data as $keyvaluepair) { - $keyvaluepair = trim($keyvaluepair); - if ($keyvaluepair) { - $keyvalueexploded = explode('=', $keyvaluepair); - $key = (isset($keyvalueexploded[0]) ? $keyvalueexploded[0] : ''); - $value = (isset($keyvalueexploded[1]) ? $keyvalueexploded[1] : ''); - $info['svg'][$section_to_fix]['sections'][$key] = trim($value, '"'); - } - } - } + if (! empty($info['svg']['width'])) { + $info['video']['resolution_x'] = $info['svg']['width']; + } + if (! empty($info['svg']['height'])) { + $info['video']['resolution_y'] = $info['svg']['height']; + } - $info['fileformat'] = 'svg'; - $info['video']['dataformat'] = 'svg'; - $info['video']['lossless'] = true; - //$info['video']['bits_per_sample'] = 24; - $info['video']['pixel_aspect_ratio'] = (float) 1; - - if (!empty($info['svg']['svg']['sections']['width'])) { - $info['svg']['width'] = intval($info['svg']['svg']['sections']['width']); - } - if (!empty($info['svg']['svg']['sections']['height'])) { - $info['svg']['height'] = intval($info['svg']['svg']['sections']['height']); - } - if (!empty($info['svg']['svg']['sections']['version'])) { - $info['svg']['version'] = $info['svg']['svg']['sections']['version']; - } - if (!isset($info['svg']['version']) && isset($info['svg']['doctype']['sections'])) { - foreach ($info['svg']['doctype']['sections'] as $key => $value) { - if (preg_match('#//W3C//DTD SVG ([0-9\.]+)//#i', $key, $matches)) { - $info['svg']['version'] = $matches[1]; - break; - } - } - } - - if (!empty($info['svg']['width'])) { - $info['video']['resolution_x'] = $info['svg']['width']; - } - if (!empty($info['svg']['height'])) { - $info['video']['resolution_y'] = $info['svg']['height']; - } - - return true; - } - $this->error('Did not find expected tag'); - return false; - } + return true; + } + $this->error('Did not find expected tag'); + return false; + } } diff --git a/app/Library/getid3/getid3/module.graphic.tiff.php b/app/Library/getid3/getid3/module.graphic.tiff.php index 90dcb5c8..0108a378 100644 --- a/app/Library/getid3/getid3/module.graphic.tiff.php +++ b/app/Library/getid3/getid3/module.graphic.tiff.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,212 +15,212 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_tiff extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $TIFFheader = $this->fread(4); - $this->fseek($info['avdataoffset']); - $TIFFheader = $this->fread(4); + switch (substr($TIFFheader, 0, 2)) { + case 'II': + $info['tiff']['byte_order'] = 'Intel'; + break; + case 'MM': + $info['tiff']['byte_order'] = 'Motorola'; + break; + default: + $this->error('Invalid TIFF byte order identifier ('.substr($TIFFheader, 0, 2).') at offset '.$info['avdataoffset']); - switch (substr($TIFFheader, 0, 2)) { - case 'II': - $info['tiff']['byte_order'] = 'Intel'; - break; - case 'MM': - $info['tiff']['byte_order'] = 'Motorola'; - break; - default: - $this->error('Invalid TIFF byte order identifier ('.substr($TIFFheader, 0, 2).') at offset '.$info['avdataoffset']); - return false; - break; - } + return false; + break; + } - $info['fileformat'] = 'tiff'; - $info['video']['dataformat'] = 'tiff'; - $info['video']['lossless'] = true; - $info['tiff']['ifd'] = array(); - $CurrentIFD = array(); + $info['fileformat'] = 'tiff'; + $info['video']['dataformat'] = 'tiff'; + $info['video']['lossless'] = true; + $info['tiff']['ifd'] = []; + $CurrentIFD = []; - $FieldTypeByteLength = array(1=>1, 2=>1, 3=>2, 4=>4, 5=>8); + $FieldTypeByteLength = [1=>1, 2=>1, 3=>2, 4=>4, 5=>8]; - $nextIFDoffset = $this->TIFFendian2Int($this->fread(4), $info['tiff']['byte_order']); + $nextIFDoffset = $this->TIFFendian2Int($this->fread(4), $info['tiff']['byte_order']); - while ($nextIFDoffset > 0) { + while ($nextIFDoffset > 0) { + $CurrentIFD['offset'] = $nextIFDoffset; - $CurrentIFD['offset'] = $nextIFDoffset; + $this->fseek($info['avdataoffset'] + $nextIFDoffset); + $CurrentIFD['fieldcount'] = $this->TIFFendian2Int($this->fread(2), $info['tiff']['byte_order']); - $this->fseek($info['avdataoffset'] + $nextIFDoffset); - $CurrentIFD['fieldcount'] = $this->TIFFendian2Int($this->fread(2), $info['tiff']['byte_order']); + for ($i = 0; $i < $CurrentIFD['fieldcount']; $i++) { + $CurrentIFD['fields'][$i]['raw']['tag'] = $this->TIFFendian2Int($this->fread(2), $info['tiff']['byte_order']); + $CurrentIFD['fields'][$i]['raw']['type'] = $this->TIFFendian2Int($this->fread(2), $info['tiff']['byte_order']); + $CurrentIFD['fields'][$i]['raw']['length'] = $this->TIFFendian2Int($this->fread(4), $info['tiff']['byte_order']); + $CurrentIFD['fields'][$i]['raw']['offset'] = $this->fread(4); - for ($i = 0; $i < $CurrentIFD['fieldcount']; $i++) { - $CurrentIFD['fields'][$i]['raw']['tag'] = $this->TIFFendian2Int($this->fread(2), $info['tiff']['byte_order']); - $CurrentIFD['fields'][$i]['raw']['type'] = $this->TIFFendian2Int($this->fread(2), $info['tiff']['byte_order']); - $CurrentIFD['fields'][$i]['raw']['length'] = $this->TIFFendian2Int($this->fread(4), $info['tiff']['byte_order']); - $CurrentIFD['fields'][$i]['raw']['offset'] = $this->fread(4); + switch ($CurrentIFD['fields'][$i]['raw']['type']) { + case 1: // BYTE An 8-bit unsigned integer. + if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) { + $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['offset'], 0, 1), $info['tiff']['byte_order']); + } else { + $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']); + } + break; - switch ($CurrentIFD['fields'][$i]['raw']['type']) { - case 1: // BYTE An 8-bit unsigned integer. - if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) { - $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['offset'], 0, 1), $info['tiff']['byte_order']); - } else { - $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']); - } - break; + case 2: // ASCII 8-bit bytes that store ASCII codes; the last byte must be null. + if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) { + $CurrentIFD['fields'][$i]['value'] = substr($CurrentIFD['fields'][$i]['raw']['offset'], 3); + } else { + $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']); + } + break; - case 2: // ASCII 8-bit bytes that store ASCII codes; the last byte must be null. - if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) { - $CurrentIFD['fields'][$i]['value'] = substr($CurrentIFD['fields'][$i]['raw']['offset'], 3); - } else { - $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']); - } - break; + case 3: // SHORT A 16-bit (2-byte) unsigned integer. + if ($CurrentIFD['fields'][$i]['raw']['length'] <= 2) { + $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['offset'], 0, 2), $info['tiff']['byte_order']); + } else { + $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']); + } + break; - case 3: // SHORT A 16-bit (2-byte) unsigned integer. - if ($CurrentIFD['fields'][$i]['raw']['length'] <= 2) { - $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['offset'], 0, 2), $info['tiff']['byte_order']); - } else { - $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']); - } - break; + case 4: // LONG A 32-bit (4-byte) unsigned integer. + if ($CurrentIFD['fields'][$i]['raw']['length'] <= 1) { + $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']); + } else { + $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']); + } + break; - case 4: // LONG A 32-bit (4-byte) unsigned integer. - if ($CurrentIFD['fields'][$i]['raw']['length'] <= 1) { - $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']); - } else { - $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $info['tiff']['byte_order']); - } - break; + case 5: // RATIONAL Two LONG_s: the first represents the numerator of a fraction, the second the denominator. + break; + } + } - case 5: // RATIONAL Two LONG_s: the first represents the numerator of a fraction, the second the denominator. - break; - } - } + $info['tiff']['ifd'][] = $CurrentIFD; + $CurrentIFD = []; + $nextIFDoffset = $this->TIFFendian2Int($this->fread(4), $info['tiff']['byte_order']); + } - $info['tiff']['ifd'][] = $CurrentIFD; - $CurrentIFD = array(); - $nextIFDoffset = $this->TIFFendian2Int($this->fread(4), $info['tiff']['byte_order']); + foreach ($info['tiff']['ifd'] as $IFDid => $IFDarray) { + foreach ($IFDarray['fields'] as $key => $fieldarray) { + switch ($fieldarray['raw']['tag']) { + case 256: // ImageWidth + case 257: // ImageLength + case 258: // BitsPerSample + case 259: // Compression + if (! isset($fieldarray['value'])) { + $this->fseek($fieldarray['offset']); + $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $this->fread($fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]); + } + break; - } + case 270: // ImageDescription + case 271: // Make + case 272: // Model + case 305: // Software + case 306: // DateTime + case 315: // Artist + case 316: // HostComputer + if (isset($fieldarray['value'])) { + $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $fieldarray['value']; + } else { + $this->fseek($fieldarray['offset']); + $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $this->fread($fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]); + } + break; + } + switch ($fieldarray['raw']['tag']) { + case 256: // ImageWidth + $info['video']['resolution_x'] = $fieldarray['value']; + break; - foreach ($info['tiff']['ifd'] as $IFDid => $IFDarray) { - foreach ($IFDarray['fields'] as $key => $fieldarray) { - switch ($fieldarray['raw']['tag']) { - case 256: // ImageWidth - case 257: // ImageLength - case 258: // BitsPerSample - case 259: // Compression - if (!isset($fieldarray['value'])) { - $this->fseek($fieldarray['offset']); - $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $this->fread($fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]); + case 257: // ImageLength + $info['video']['resolution_y'] = $fieldarray['value']; + break; - } - break; + case 258: // BitsPerSample + if (isset($fieldarray['value'])) { + $info['video']['bits_per_sample'] = $fieldarray['value']; + } else { + $info['video']['bits_per_sample'] = 0; + for ($i = 0; $i < $fieldarray['raw']['length']; $i++) { + $info['video']['bits_per_sample'] += $this->TIFFendian2Int(substr($info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'], $i * $FieldTypeByteLength[$fieldarray['raw']['type']], $FieldTypeByteLength[$fieldarray['raw']['type']]), $info['tiff']['byte_order']); + } + } + break; - case 270: // ImageDescription - case 271: // Make - case 272: // Model - case 305: // Software - case 306: // DateTime - case 315: // Artist - case 316: // HostComputer - if (isset($fieldarray['value'])) { - $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $fieldarray['value']; - } else { - $this->fseek($fieldarray['offset']); - $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $this->fread($fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]); + case 259: // Compression + $info['video']['codec'] = $this->TIFFcompressionMethod($fieldarray['value']); + break; - } - break; - } - switch ($fieldarray['raw']['tag']) { - case 256: // ImageWidth - $info['video']['resolution_x'] = $fieldarray['value']; - break; + case 270: // ImageDescription + case 271: // Make + case 272: // Model + case 305: // Software + case 306: // DateTime + case 315: // Artist + case 316: // HostComputer + $TIFFcommentName = $this->TIFFcommentName($fieldarray['raw']['tag']); + if (isset($info['tiff']['comments'][$TIFFcommentName])) { + $info['tiff']['comments'][$TIFFcommentName][] = $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data']; + } else { + $info['tiff']['comments'][$TIFFcommentName] = [$info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data']]; + } + break; - case 257: // ImageLength - $info['video']['resolution_y'] = $fieldarray['value']; - break; + default: + break; + } + } + } - case 258: // BitsPerSample - if (isset($fieldarray['value'])) { - $info['video']['bits_per_sample'] = $fieldarray['value']; - } else { - $info['video']['bits_per_sample'] = 0; - for ($i = 0; $i < $fieldarray['raw']['length']; $i++) { - $info['video']['bits_per_sample'] += $this->TIFFendian2Int(substr($info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'], $i * $FieldTypeByteLength[$fieldarray['raw']['type']], $FieldTypeByteLength[$fieldarray['raw']['type']]), $info['tiff']['byte_order']); - } - } - break; + return true; + } - case 259: // Compression - $info['video']['codec'] = $this->TIFFcompressionMethod($fieldarray['value']); - break; + public function TIFFendian2Int($bytestring, $byteorder) + { + if ($byteorder == 'Intel') { + return getid3_lib::LittleEndian2Int($bytestring); + } elseif ($byteorder == 'Motorola') { + return getid3_lib::BigEndian2Int($bytestring); + } - case 270: // ImageDescription - case 271: // Make - case 272: // Model - case 305: // Software - case 306: // DateTime - case 315: // Artist - case 316: // HostComputer - $TIFFcommentName = $this->TIFFcommentName($fieldarray['raw']['tag']); - if (isset($info['tiff']['comments'][$TIFFcommentName])) { - $info['tiff']['comments'][$TIFFcommentName][] = $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data']; - } else { - $info['tiff']['comments'][$TIFFcommentName] = array($info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data']); - } - break; + return false; + } - default: - break; - } - } - } + public function TIFFcompressionMethod($id) + { + static $TIFFcompressionMethod = []; + if (empty($TIFFcompressionMethod)) { + $TIFFcompressionMethod = [ + 1 => 'Uncompressed', + 2 => 'Huffman', + 3 => 'Fax - CCITT 3', + 5 => 'LZW', + 32773 => 'PackBits', + ]; + } - return true; - } + return isset($TIFFcompressionMethod[$id]) ? $TIFFcompressionMethod[$id] : 'unknown/invalid ('.$id.')'; + } + public function TIFFcommentName($id) + { + static $TIFFcommentName = []; + if (empty($TIFFcommentName)) { + $TIFFcommentName = [ + 270 => 'imagedescription', + 271 => 'make', + 272 => 'model', + 305 => 'software', + 306 => 'datetime', + 315 => 'artist', + 316 => 'hostcomputer', + ]; + } - public function TIFFendian2Int($bytestring, $byteorder) { - if ($byteorder == 'Intel') { - return getid3_lib::LittleEndian2Int($bytestring); - } elseif ($byteorder == 'Motorola') { - return getid3_lib::BigEndian2Int($bytestring); - } - return false; - } - - public function TIFFcompressionMethod($id) { - static $TIFFcompressionMethod = array(); - if (empty($TIFFcompressionMethod)) { - $TIFFcompressionMethod = array( - 1 => 'Uncompressed', - 2 => 'Huffman', - 3 => 'Fax - CCITT 3', - 5 => 'LZW', - 32773 => 'PackBits', - ); - } - return (isset($TIFFcompressionMethod[$id]) ? $TIFFcompressionMethod[$id] : 'unknown/invalid ('.$id.')'); - } - - public function TIFFcommentName($id) { - static $TIFFcommentName = array(); - if (empty($TIFFcommentName)) { - $TIFFcommentName = array( - 270 => 'imagedescription', - 271 => 'make', - 272 => 'model', - 305 => 'software', - 306 => 'datetime', - 315 => 'artist', - 316 => 'hostcomputer', - ); - } - return (isset($TIFFcommentName[$id]) ? $TIFFcommentName[$id] : 'unknown/invalid ('.$id.')'); - } - + return isset($TIFFcommentName[$id]) ? $TIFFcommentName[$id] : 'unknown/invalid ('.$id.')'; + } } diff --git a/app/Library/getid3/getid3/module.misc.cue.php b/app/Library/getid3/getid3/module.misc.cue.php index 9c42799e..d25e5f19 100644 --- a/app/Library/getid3/getid3/module.misc.cue.php +++ b/app/Library/getid3/getid3/module.misc.cue.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -29,284 +30,266 @@ /** * A CueSheet class used to open and parse cuesheets. - * */ class getid3_cue extends getid3_handler { - public $cuesheet = array(); + public $cuesheet = []; - public function Analyze() { - $info = &$this->getid3->info; + public function Analyze() + { + $info = &$this->getid3->info; - $info['fileformat'] = 'cue'; - $this->readCueSheetFilename($info['filenamepath']); - $info['cue'] = $this->cuesheet; - return true; - } + $info['fileformat'] = 'cue'; + $this->readCueSheetFilename($info['filenamepath']); + $info['cue'] = $this->cuesheet; + return true; + } + public function readCueSheetFilename($filename) + { + $filedata = file_get_contents($filename); - public function readCueSheetFilename($filename) - { - $filedata = file_get_contents($filename); - return $this->readCueSheet($filedata); - } - /** - * Parses a cue sheet file. - * - * @param string $filename - The filename for the cue sheet to open. - */ - public function readCueSheet(&$filedata) - { - $cue_lines = array(); - foreach (explode("\n", str_replace("\r", null, $filedata)) as $line) - { - if ( (strlen($line) > 0) && ($line[0] != '#')) - { - $cue_lines[] = trim($line); - } - } - $this->parseCueSheet($cue_lines); + return $this->readCueSheet($filedata); + } - return $this->cuesheet; - } + /** + * Parses a cue sheet file. + * + * @param string $filename - The filename for the cue sheet to open. + */ + public function readCueSheet(&$filedata) + { + $cue_lines = []; + foreach (explode("\n", str_replace("\r", null, $filedata)) as $line) { + if ((strlen($line) > 0) && ($line[0] != '#')) { + $cue_lines[] = trim($line); + } + } + $this->parseCueSheet($cue_lines); - /** - * Parses the cue sheet array. - * - * @param array $file - The cuesheet as an array of each line. - */ - public function parseCueSheet($file) - { - //-1 means still global, all others are track specific - $track_on = -1; + return $this->cuesheet; + } - for ($i=0; $i < count($file); $i++) - { - list($key) = explode(' ', strtolower($file[$i]), 2); - switch ($key) - { - case 'catalog': - case 'cdtextfile': - case 'isrc': - case 'performer': - case 'songwriter': - case 'title': - $this->parseString($file[$i], $track_on); - break; - case 'file': - $currentFile = $this->parseFile($file[$i]); - break; - case 'flags': - $this->parseFlags($file[$i], $track_on); - break; - case 'index': - case 'postgap': - case 'pregap': - $this->parseIndex($file[$i], $track_on); - break; - case 'rem': - $this->parseComment($file[$i], $track_on); - break; - case 'track': - $track_on++; - $this->parseTrack($file[$i], $track_on); - if (isset($currentFile)) // if there's a file - { - $this->cuesheet['tracks'][$track_on]['datafile'] = $currentFile; - } - break; - default: - //save discarded junk and place string[] with track it was found in - $this->parseGarbage($file[$i], $track_on); - break; - } - } - } + /** + * Parses the cue sheet array. + * + * @param array $file - The cuesheet as an array of each line. + */ + public function parseCueSheet($file) + { + //-1 means still global, all others are track specific + $track_on = -1; - /** - * Parses the REM command. - * - * @param string $line - The line in the cue file that contains the TRACK command. - * @param integer $track_on - The track currently processing. - */ - public function parseComment($line, $track_on) - { - $explodedline = explode(' ', $line, 3); - $comment_REM = (isset($explodedline[0]) ? $explodedline[0] : ''); - $comment_type = (isset($explodedline[1]) ? $explodedline[1] : ''); - $comment_data = (isset($explodedline[2]) ? $explodedline[2] : ''); - if (($comment_REM == 'REM') && $comment_type) { - $comment_type = strtolower($comment_type); - $commment_data = trim($comment_data, ' "'); - if ($track_on != -1) { - $this->cuesheet['tracks'][$track_on]['comments'][$comment_type][] = $comment_data; - } else { - $this->cuesheet['comments'][$comment_type][] = $comment_data; - } - } - } + for ($i = 0; $i < count($file); $i++) { + list($key) = explode(' ', strtolower($file[$i]), 2); + switch ($key) { + case 'catalog': + case 'cdtextfile': + case 'isrc': + case 'performer': + case 'songwriter': + case 'title': + $this->parseString($file[$i], $track_on); + break; + case 'file': + $currentFile = $this->parseFile($file[$i]); + break; + case 'flags': + $this->parseFlags($file[$i], $track_on); + break; + case 'index': + case 'postgap': + case 'pregap': + $this->parseIndex($file[$i], $track_on); + break; + case 'rem': + $this->parseComment($file[$i], $track_on); + break; + case 'track': + $track_on++; + $this->parseTrack($file[$i], $track_on); + if (isset($currentFile)) { // if there's a file + $this->cuesheet['tracks'][$track_on]['datafile'] = $currentFile; + } + break; + default: + //save discarded junk and place string[] with track it was found in + $this->parseGarbage($file[$i], $track_on); + break; + } + } + } - /** - * Parses the FILE command. - * - * @param string $line - The line in the cue file that contains the FILE command. - * @return array - Array of FILENAME and TYPE of file.. - */ - public function parseFile($line) - { - $line = substr($line, strpos($line, ' ') + 1); - $type = strtolower(substr($line, strrpos($line, ' '))); + /** + * Parses the REM command. + * + * @param string $line - The line in the cue file that contains the TRACK command. + * @param int $track_on - The track currently processing. + */ + public function parseComment($line, $track_on) + { + $explodedline = explode(' ', $line, 3); + $comment_REM = (isset($explodedline[0]) ? $explodedline[0] : ''); + $comment_type = (isset($explodedline[1]) ? $explodedline[1] : ''); + $comment_data = (isset($explodedline[2]) ? $explodedline[2] : ''); + if (($comment_REM == 'REM') && $comment_type) { + $comment_type = strtolower($comment_type); + $commment_data = trim($comment_data, ' "'); + if ($track_on != -1) { + $this->cuesheet['tracks'][$track_on]['comments'][$comment_type][] = $comment_data; + } else { + $this->cuesheet['comments'][$comment_type][] = $comment_data; + } + } + } - //remove type - $line = substr($line, 0, strrpos($line, ' ') - 1); + /** + * Parses the FILE command. + * + * @param string $line - The line in the cue file that contains the FILE command. + * @return array - Array of FILENAME and TYPE of file.. + */ + public function parseFile($line) + { + $line = substr($line, strpos($line, ' ') + 1); + $type = strtolower(substr($line, strrpos($line, ' '))); - //if quotes around it, remove them. - $line = trim($line, '"'); + //remove type + $line = substr($line, 0, strrpos($line, ' ') - 1); - return array('filename'=>$line, 'type'=>$type); - } + //if quotes around it, remove them. + $line = trim($line, '"'); - /** - * Parses the FLAG command. - * - * @param string $line - The line in the cue file that contains the TRACK command. - * @param integer $track_on - The track currently processing. - */ - public function parseFlags($line, $track_on) - { - if ($track_on != -1) - { - foreach (explode(' ', strtolower($line)) as $type) - { - switch ($type) - { - case 'flags': - // first entry in this line - $this->cuesheet['tracks'][$track_on]['flags'] = array( - '4ch' => false, - 'data' => false, - 'dcp' => false, - 'pre' => false, - 'scms' => false, - ); - break; - case 'data': - case 'dcp': - case '4ch': - case 'pre': - case 'scms': - $this->cuesheet['tracks'][$track_on]['flags'][$type] = true; - break; - default: - break; - } - } - } - } + return ['filename'=>$line, 'type'=>$type]; + } - /** - * Collect any unidentified data. - * - * @param string $line - The line in the cue file that contains the TRACK command. - * @param integer $track_on - The track currently processing. - */ - public function parseGarbage($line, $track_on) - { - if ( strlen($line) > 0 ) - { - if ($track_on == -1) - { - $this->cuesheet['garbage'][] = $line; - } - else - { - $this->cuesheet['tracks'][$track_on]['garbage'][] = $line; - } - } - } + /** + * Parses the FLAG command. + * + * @param string $line - The line in the cue file that contains the TRACK command. + * @param int $track_on - The track currently processing. + */ + public function parseFlags($line, $track_on) + { + if ($track_on != -1) { + foreach (explode(' ', strtolower($line)) as $type) { + switch ($type) { + case 'flags': + // first entry in this line + $this->cuesheet['tracks'][$track_on]['flags'] = [ + '4ch' => false, + 'data' => false, + 'dcp' => false, + 'pre' => false, + 'scms' => false, + ]; + break; + case 'data': + case 'dcp': + case '4ch': + case 'pre': + case 'scms': + $this->cuesheet['tracks'][$track_on]['flags'][$type] = true; + break; + default: + break; + } + } + } + } - /** - * Parses the INDEX command of a TRACK. - * - * @param string $line - The line in the cue file that contains the TRACK command. - * @param integer $track_on - The track currently processing. - */ - public function parseIndex($line, $track_on) - { - $type = strtolower(substr($line, 0, strpos($line, ' '))); - $line = substr($line, strpos($line, ' ') + 1); + /** + * Collect any unidentified data. + * + * @param string $line - The line in the cue file that contains the TRACK command. + * @param int $track_on - The track currently processing. + */ + public function parseGarbage($line, $track_on) + { + if (strlen($line) > 0) { + if ($track_on == -1) { + $this->cuesheet['garbage'][] = $line; + } else { + $this->cuesheet['tracks'][$track_on]['garbage'][] = $line; + } + } + } - if ($type == 'index') - { - //read the index number - $number = intval(substr($line, 0, strpos($line, ' '))); - $line = substr($line, strpos($line, ' ') + 1); - } + /** + * Parses the INDEX command of a TRACK. + * + * @param string $line - The line in the cue file that contains the TRACK command. + * @param int $track_on - The track currently processing. + */ + public function parseIndex($line, $track_on) + { + $type = strtolower(substr($line, 0, strpos($line, ' '))); + $line = substr($line, strpos($line, ' ') + 1); - //extract the minutes, seconds, and frames - $explodedline = explode(':', $line); - $minutes = (isset($explodedline[0]) ? $explodedline[0] : ''); - $seconds = (isset($explodedline[1]) ? $explodedline[1] : ''); - $frames = (isset($explodedline[2]) ? $explodedline[2] : ''); + if ($type == 'index') { + //read the index number + $number = intval(substr($line, 0, strpos($line, ' '))); + $line = substr($line, strpos($line, ' ') + 1); + } - switch ($type) { - case 'index': - $this->cuesheet['tracks'][$track_on][$type][$number] = array('minutes'=>intval($minutes), 'seconds'=>intval($seconds), 'frames'=>intval($frames)); - break; - case 'pregap': - case 'postgap': - $this->cuesheet['tracks'][$track_on][$type] = array('minutes'=>intval($minutes), 'seconds'=>intval($seconds), 'frames'=>intval($frames)); - break; - } - } + //extract the minutes, seconds, and frames + $explodedline = explode(':', $line); + $minutes = (isset($explodedline[0]) ? $explodedline[0] : ''); + $seconds = (isset($explodedline[1]) ? $explodedline[1] : ''); + $frames = (isset($explodedline[2]) ? $explodedline[2] : ''); - public function parseString($line, $track_on) - { - $category = strtolower(substr($line, 0, strpos($line, ' '))); - $line = substr($line, strpos($line, ' ') + 1); + switch ($type) { + case 'index': + $this->cuesheet['tracks'][$track_on][$type][$number] = ['minutes'=>intval($minutes), 'seconds'=>intval($seconds), 'frames'=>intval($frames)]; + break; + case 'pregap': + case 'postgap': + $this->cuesheet['tracks'][$track_on][$type] = ['minutes'=>intval($minutes), 'seconds'=>intval($seconds), 'frames'=>intval($frames)]; + break; + } + } - //get rid of the quotes - $line = trim($line, '"'); + public function parseString($line, $track_on) + { + $category = strtolower(substr($line, 0, strpos($line, ' '))); + $line = substr($line, strpos($line, ' ') + 1); - switch ($category) - { - case 'catalog': - case 'cdtextfile': - case 'isrc': - case 'performer': - case 'songwriter': - case 'title': - if ($track_on == -1) - { - $this->cuesheet[$category] = $line; - } - else - { - $this->cuesheet['tracks'][$track_on][$category] = $line; - } - break; - default: - break; - } - } + //get rid of the quotes + $line = trim($line, '"'); - /** - * Parses the TRACK command. - * - * @param string $line - The line in the cue file that contains the TRACK command. - * @param integer $track_on - The track currently processing. - */ - public function parseTrack($line, $track_on) - { - $line = substr($line, strpos($line, ' ') + 1); - $track = ltrim(substr($line, 0, strpos($line, ' ')), '0'); + switch ($category) { + case 'catalog': + case 'cdtextfile': + case 'isrc': + case 'performer': + case 'songwriter': + case 'title': + if ($track_on == -1) { + $this->cuesheet[$category] = $line; + } else { + $this->cuesheet['tracks'][$track_on][$category] = $line; + } + break; + default: + break; + } + } - //find the data type. - $datatype = strtolower(substr($line, strpos($line, ' ') + 1)); + /** + * Parses the TRACK command. + * + * @param string $line - The line in the cue file that contains the TRACK command. + * @param int $track_on - The track currently processing. + */ + public function parseTrack($line, $track_on) + { + $line = substr($line, strpos($line, ' ') + 1); + $track = ltrim(substr($line, 0, strpos($line, ' ')), '0'); - $this->cuesheet['tracks'][$track_on] = array('track_number'=>$track, 'datatype'=>$datatype); - } + //find the data type. + $datatype = strtolower(substr($line, strpos($line, ' ') + 1)); + $this->cuesheet['tracks'][$track_on] = ['track_number'=>$track, 'datatype'=>$datatype]; + } } - diff --git a/app/Library/getid3/getid3/module.misc.exe.php b/app/Library/getid3/getid3/module.misc.exe.php index 4f04ad72..3795f259 100644 --- a/app/Library/getid3/getid3/module.misc.exe.php +++ b/app/Library/getid3/getid3/module.misc.exe.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,46 +15,45 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_exe extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $EXEheader = $this->fread(28); - $this->fseek($info['avdataoffset']); - $EXEheader = $this->fread(28); + $magic = 'MZ'; + if (substr($EXEheader, 0, 2) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($EXEheader, 0, 2)).'"'); - $magic = 'MZ'; - if (substr($EXEheader, 0, 2) != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($EXEheader, 0, 2)).'"'); - return false; - } + return false; + } - $info['fileformat'] = 'exe'; - $info['exe']['mz']['magic'] = 'MZ'; + $info['fileformat'] = 'exe'; + $info['exe']['mz']['magic'] = 'MZ'; - $info['exe']['mz']['raw']['last_page_size'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 2, 2)); - $info['exe']['mz']['raw']['page_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 4, 2)); - $info['exe']['mz']['raw']['relocation_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 6, 2)); - $info['exe']['mz']['raw']['header_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 8, 2)); - $info['exe']['mz']['raw']['min_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 10, 2)); - $info['exe']['mz']['raw']['max_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 12, 2)); - $info['exe']['mz']['raw']['initial_ss'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 14, 2)); - $info['exe']['mz']['raw']['initial_sp'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 16, 2)); - $info['exe']['mz']['raw']['checksum'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 18, 2)); - $info['exe']['mz']['raw']['cs_ip'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 20, 4)); - $info['exe']['mz']['raw']['relocation_table_offset'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 24, 2)); - $info['exe']['mz']['raw']['overlay_number'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 26, 2)); + $info['exe']['mz']['raw']['last_page_size'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 2, 2)); + $info['exe']['mz']['raw']['page_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 4, 2)); + $info['exe']['mz']['raw']['relocation_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 6, 2)); + $info['exe']['mz']['raw']['header_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 8, 2)); + $info['exe']['mz']['raw']['min_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 10, 2)); + $info['exe']['mz']['raw']['max_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 12, 2)); + $info['exe']['mz']['raw']['initial_ss'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 14, 2)); + $info['exe']['mz']['raw']['initial_sp'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 16, 2)); + $info['exe']['mz']['raw']['checksum'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 18, 2)); + $info['exe']['mz']['raw']['cs_ip'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 20, 4)); + $info['exe']['mz']['raw']['relocation_table_offset'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 24, 2)); + $info['exe']['mz']['raw']['overlay_number'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 26, 2)); - $info['exe']['mz']['byte_size'] = (($info['exe']['mz']['raw']['page_count'] - 1)) * 512 + $info['exe']['mz']['raw']['last_page_size']; - $info['exe']['mz']['header_size'] = $info['exe']['mz']['raw']['header_paragraphs'] * 16; - $info['exe']['mz']['memory_minimum'] = $info['exe']['mz']['raw']['min_memory_paragraphs'] * 16; - $info['exe']['mz']['memory_recommended'] = $info['exe']['mz']['raw']['max_memory_paragraphs'] * 16; + $info['exe']['mz']['byte_size'] = (($info['exe']['mz']['raw']['page_count'] - 1)) * 512 + $info['exe']['mz']['raw']['last_page_size']; + $info['exe']['mz']['header_size'] = $info['exe']['mz']['raw']['header_paragraphs'] * 16; + $info['exe']['mz']['memory_minimum'] = $info['exe']['mz']['raw']['min_memory_paragraphs'] * 16; + $info['exe']['mz']['memory_recommended'] = $info['exe']['mz']['raw']['max_memory_paragraphs'] * 16; -$this->error('EXE parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); -return false; - - } + $this->error('EXE parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); + return false; + } } diff --git a/app/Library/getid3/getid3/module.misc.iso.php b/app/Library/getid3/getid3/module.misc.iso.php index 04772856..01cd203f 100644 --- a/app/Library/getid3/getid3/module.misc.iso.php +++ b/app/Library/getid3/getid3/module.misc.iso.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,375 +15,377 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_iso extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $info['fileformat'] = 'iso'; - $info['fileformat'] = 'iso'; + for ($i = 16; $i <= 19; $i++) { + $this->fseek(2048 * $i); + $ISOheader = $this->fread(2048); + if (substr($ISOheader, 1, 5) == 'CD001') { + switch (ord($ISOheader[0])) { + case 1: + $info['iso']['primary_volume_descriptor']['offset'] = 2048 * $i; + $this->ParsePrimaryVolumeDescriptor($ISOheader); + break; - for ($i = 16; $i <= 19; $i++) { - $this->fseek(2048 * $i); - $ISOheader = $this->fread(2048); - if (substr($ISOheader, 1, 5) == 'CD001') { - switch (ord($ISOheader{0})) { - case 1: - $info['iso']['primary_volume_descriptor']['offset'] = 2048 * $i; - $this->ParsePrimaryVolumeDescriptor($ISOheader); - break; + case 2: + $info['iso']['supplementary_volume_descriptor']['offset'] = 2048 * $i; + $this->ParseSupplementaryVolumeDescriptor($ISOheader); + break; - case 2: - $info['iso']['supplementary_volume_descriptor']['offset'] = 2048 * $i; - $this->ParseSupplementaryVolumeDescriptor($ISOheader); - break; + default: + // skip + break; + } + } + } - default: - // skip - break; - } - } - } + $this->ParsePathTable(); - $this->ParsePathTable(); + $info['iso']['files'] = []; + foreach ($info['iso']['path_table']['directories'] as $directorynum => $directorydata) { + $info['iso']['directories'][$directorynum] = $this->ParseDirectoryRecord($directorydata); + } - $info['iso']['files'] = array(); - foreach ($info['iso']['path_table']['directories'] as $directorynum => $directorydata) { - $info['iso']['directories'][$directorynum] = $this->ParseDirectoryRecord($directorydata); - } + return true; + } - return true; - } + public function ParsePrimaryVolumeDescriptor(&$ISOheader) + { + // ISO integer values are stored *BOTH* Little-Endian AND Big-Endian format!! + // ie 12345 == 0x3039 is stored as $39 $30 $30 $39 in a 4-byte field + // shortcuts + $info = &$this->getid3->info; + $info['iso']['primary_volume_descriptor']['raw'] = []; + $thisfile_iso_primaryVD = &$info['iso']['primary_volume_descriptor']; + $thisfile_iso_primaryVD_raw = &$thisfile_iso_primaryVD['raw']; - public function ParsePrimaryVolumeDescriptor(&$ISOheader) { - // ISO integer values are stored *BOTH* Little-Endian AND Big-Endian format!! - // ie 12345 == 0x3039 is stored as $39 $30 $30 $39 in a 4-byte field + $thisfile_iso_primaryVD_raw['volume_descriptor_type'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 0, 1)); + $thisfile_iso_primaryVD_raw['standard_identifier'] = substr($ISOheader, 1, 5); + if ($thisfile_iso_primaryVD_raw['standard_identifier'] != 'CD001') { + $this->error('Expected "CD001" at offset ('.($thisfile_iso_primaryVD['offset'] + 1).'), found "'.$thisfile_iso_primaryVD_raw['standard_identifier'].'" instead'); + unset($info['fileformat']); + unset($info['iso']); - // shortcuts - $info = &$this->getid3->info; - $info['iso']['primary_volume_descriptor']['raw'] = array(); - $thisfile_iso_primaryVD = &$info['iso']['primary_volume_descriptor']; - $thisfile_iso_primaryVD_raw = &$thisfile_iso_primaryVD['raw']; + return false; + } - $thisfile_iso_primaryVD_raw['volume_descriptor_type'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 0, 1)); - $thisfile_iso_primaryVD_raw['standard_identifier'] = substr($ISOheader, 1, 5); - if ($thisfile_iso_primaryVD_raw['standard_identifier'] != 'CD001') { - $this->error('Expected "CD001" at offset ('.($thisfile_iso_primaryVD['offset'] + 1).'), found "'.$thisfile_iso_primaryVD_raw['standard_identifier'].'" instead'); - unset($info['fileformat']); - unset($info['iso']); - return false; - } + $thisfile_iso_primaryVD_raw['volume_descriptor_version'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 6, 1)); + //$thisfile_iso_primaryVD_raw['unused_1'] = substr($ISOheader, 7, 1); + $thisfile_iso_primaryVD_raw['system_identifier'] = substr($ISOheader, 8, 32); + $thisfile_iso_primaryVD_raw['volume_identifier'] = substr($ISOheader, 40, 32); + //$thisfile_iso_primaryVD_raw['unused_2'] = substr($ISOheader, 72, 8); + $thisfile_iso_primaryVD_raw['volume_space_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 80, 4)); + //$thisfile_iso_primaryVD_raw['unused_3'] = substr($ISOheader, 88, 32); + $thisfile_iso_primaryVD_raw['volume_set_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 120, 2)); + $thisfile_iso_primaryVD_raw['volume_sequence_number'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 124, 2)); + $thisfile_iso_primaryVD_raw['logical_block_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 128, 2)); + $thisfile_iso_primaryVD_raw['path_table_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 132, 4)); + $thisfile_iso_primaryVD_raw['path_table_l_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 140, 2)); + $thisfile_iso_primaryVD_raw['path_table_l_opt_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 144, 2)); + $thisfile_iso_primaryVD_raw['path_table_m_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 148, 2)); + $thisfile_iso_primaryVD_raw['path_table_m_opt_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 152, 2)); + $thisfile_iso_primaryVD_raw['root_directory_record'] = substr($ISOheader, 156, 34); + $thisfile_iso_primaryVD_raw['volume_set_identifier'] = substr($ISOheader, 190, 128); + $thisfile_iso_primaryVD_raw['publisher_identifier'] = substr($ISOheader, 318, 128); + $thisfile_iso_primaryVD_raw['data_preparer_identifier'] = substr($ISOheader, 446, 128); + $thisfile_iso_primaryVD_raw['application_identifier'] = substr($ISOheader, 574, 128); + $thisfile_iso_primaryVD_raw['copyright_file_identifier'] = substr($ISOheader, 702, 37); + $thisfile_iso_primaryVD_raw['abstract_file_identifier'] = substr($ISOheader, 739, 37); + $thisfile_iso_primaryVD_raw['bibliographic_file_identifier'] = substr($ISOheader, 776, 37); + $thisfile_iso_primaryVD_raw['volume_creation_date_time'] = substr($ISOheader, 813, 17); + $thisfile_iso_primaryVD_raw['volume_modification_date_time'] = substr($ISOheader, 830, 17); + $thisfile_iso_primaryVD_raw['volume_expiration_date_time'] = substr($ISOheader, 847, 17); + $thisfile_iso_primaryVD_raw['volume_effective_date_time'] = substr($ISOheader, 864, 17); + $thisfile_iso_primaryVD_raw['file_structure_version'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 881, 1)); + //$thisfile_iso_primaryVD_raw['unused_4'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 882, 1)); + $thisfile_iso_primaryVD_raw['application_data'] = substr($ISOheader, 883, 512); + //$thisfile_iso_primaryVD_raw['unused_5'] = substr($ISOheader, 1395, 653); + $thisfile_iso_primaryVD['system_identifier'] = trim($thisfile_iso_primaryVD_raw['system_identifier']); + $thisfile_iso_primaryVD['volume_identifier'] = trim($thisfile_iso_primaryVD_raw['volume_identifier']); + $thisfile_iso_primaryVD['volume_set_identifier'] = trim($thisfile_iso_primaryVD_raw['volume_set_identifier']); + $thisfile_iso_primaryVD['publisher_identifier'] = trim($thisfile_iso_primaryVD_raw['publisher_identifier']); + $thisfile_iso_primaryVD['data_preparer_identifier'] = trim($thisfile_iso_primaryVD_raw['data_preparer_identifier']); + $thisfile_iso_primaryVD['application_identifier'] = trim($thisfile_iso_primaryVD_raw['application_identifier']); + $thisfile_iso_primaryVD['copyright_file_identifier'] = trim($thisfile_iso_primaryVD_raw['copyright_file_identifier']); + $thisfile_iso_primaryVD['abstract_file_identifier'] = trim($thisfile_iso_primaryVD_raw['abstract_file_identifier']); + $thisfile_iso_primaryVD['bibliographic_file_identifier'] = trim($thisfile_iso_primaryVD_raw['bibliographic_file_identifier']); + $thisfile_iso_primaryVD['volume_creation_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_creation_date_time']); + $thisfile_iso_primaryVD['volume_modification_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_modification_date_time']); + $thisfile_iso_primaryVD['volume_expiration_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_expiration_date_time']); + $thisfile_iso_primaryVD['volume_effective_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_effective_date_time']); - $thisfile_iso_primaryVD_raw['volume_descriptor_version'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 6, 1)); - //$thisfile_iso_primaryVD_raw['unused_1'] = substr($ISOheader, 7, 1); - $thisfile_iso_primaryVD_raw['system_identifier'] = substr($ISOheader, 8, 32); - $thisfile_iso_primaryVD_raw['volume_identifier'] = substr($ISOheader, 40, 32); - //$thisfile_iso_primaryVD_raw['unused_2'] = substr($ISOheader, 72, 8); - $thisfile_iso_primaryVD_raw['volume_space_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 80, 4)); - //$thisfile_iso_primaryVD_raw['unused_3'] = substr($ISOheader, 88, 32); - $thisfile_iso_primaryVD_raw['volume_set_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 120, 2)); - $thisfile_iso_primaryVD_raw['volume_sequence_number'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 124, 2)); - $thisfile_iso_primaryVD_raw['logical_block_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 128, 2)); - $thisfile_iso_primaryVD_raw['path_table_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 132, 4)); - $thisfile_iso_primaryVD_raw['path_table_l_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 140, 2)); - $thisfile_iso_primaryVD_raw['path_table_l_opt_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 144, 2)); - $thisfile_iso_primaryVD_raw['path_table_m_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 148, 2)); - $thisfile_iso_primaryVD_raw['path_table_m_opt_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 152, 2)); - $thisfile_iso_primaryVD_raw['root_directory_record'] = substr($ISOheader, 156, 34); - $thisfile_iso_primaryVD_raw['volume_set_identifier'] = substr($ISOheader, 190, 128); - $thisfile_iso_primaryVD_raw['publisher_identifier'] = substr($ISOheader, 318, 128); - $thisfile_iso_primaryVD_raw['data_preparer_identifier'] = substr($ISOheader, 446, 128); - $thisfile_iso_primaryVD_raw['application_identifier'] = substr($ISOheader, 574, 128); - $thisfile_iso_primaryVD_raw['copyright_file_identifier'] = substr($ISOheader, 702, 37); - $thisfile_iso_primaryVD_raw['abstract_file_identifier'] = substr($ISOheader, 739, 37); - $thisfile_iso_primaryVD_raw['bibliographic_file_identifier'] = substr($ISOheader, 776, 37); - $thisfile_iso_primaryVD_raw['volume_creation_date_time'] = substr($ISOheader, 813, 17); - $thisfile_iso_primaryVD_raw['volume_modification_date_time'] = substr($ISOheader, 830, 17); - $thisfile_iso_primaryVD_raw['volume_expiration_date_time'] = substr($ISOheader, 847, 17); - $thisfile_iso_primaryVD_raw['volume_effective_date_time'] = substr($ISOheader, 864, 17); - $thisfile_iso_primaryVD_raw['file_structure_version'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 881, 1)); - //$thisfile_iso_primaryVD_raw['unused_4'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 882, 1)); - $thisfile_iso_primaryVD_raw['application_data'] = substr($ISOheader, 883, 512); - //$thisfile_iso_primaryVD_raw['unused_5'] = substr($ISOheader, 1395, 653); + if (($thisfile_iso_primaryVD_raw['volume_space_size'] * 2048) > $info['filesize']) { + $this->error('Volume Space Size ('.($thisfile_iso_primaryVD_raw['volume_space_size'] * 2048).' bytes) is larger than the file size ('.$info['filesize'].' bytes) (truncated file?)'); + } - $thisfile_iso_primaryVD['system_identifier'] = trim($thisfile_iso_primaryVD_raw['system_identifier']); - $thisfile_iso_primaryVD['volume_identifier'] = trim($thisfile_iso_primaryVD_raw['volume_identifier']); - $thisfile_iso_primaryVD['volume_set_identifier'] = trim($thisfile_iso_primaryVD_raw['volume_set_identifier']); - $thisfile_iso_primaryVD['publisher_identifier'] = trim($thisfile_iso_primaryVD_raw['publisher_identifier']); - $thisfile_iso_primaryVD['data_preparer_identifier'] = trim($thisfile_iso_primaryVD_raw['data_preparer_identifier']); - $thisfile_iso_primaryVD['application_identifier'] = trim($thisfile_iso_primaryVD_raw['application_identifier']); - $thisfile_iso_primaryVD['copyright_file_identifier'] = trim($thisfile_iso_primaryVD_raw['copyright_file_identifier']); - $thisfile_iso_primaryVD['abstract_file_identifier'] = trim($thisfile_iso_primaryVD_raw['abstract_file_identifier']); - $thisfile_iso_primaryVD['bibliographic_file_identifier'] = trim($thisfile_iso_primaryVD_raw['bibliographic_file_identifier']); - $thisfile_iso_primaryVD['volume_creation_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_creation_date_time']); - $thisfile_iso_primaryVD['volume_modification_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_modification_date_time']); - $thisfile_iso_primaryVD['volume_expiration_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_expiration_date_time']); - $thisfile_iso_primaryVD['volume_effective_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_effective_date_time']); + return true; + } - if (($thisfile_iso_primaryVD_raw['volume_space_size'] * 2048) > $info['filesize']) { - $this->error('Volume Space Size ('.($thisfile_iso_primaryVD_raw['volume_space_size'] * 2048).' bytes) is larger than the file size ('.$info['filesize'].' bytes) (truncated file?)'); - } + public function ParseSupplementaryVolumeDescriptor(&$ISOheader) + { + // ISO integer values are stored Both-Endian format!! + // ie 12345 == 0x3039 is stored as $39 $30 $30 $39 in a 4-byte field - return true; - } + // shortcuts + $info = &$this->getid3->info; + $info['iso']['supplementary_volume_descriptor']['raw'] = []; + $thisfile_iso_supplementaryVD = &$info['iso']['supplementary_volume_descriptor']; + $thisfile_iso_supplementaryVD_raw = &$thisfile_iso_supplementaryVD['raw']; + $thisfile_iso_supplementaryVD_raw['volume_descriptor_type'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 0, 1)); + $thisfile_iso_supplementaryVD_raw['standard_identifier'] = substr($ISOheader, 1, 5); + if ($thisfile_iso_supplementaryVD_raw['standard_identifier'] != 'CD001') { + $this->error('Expected "CD001" at offset ('.($thisfile_iso_supplementaryVD['offset'] + 1).'), found "'.$thisfile_iso_supplementaryVD_raw['standard_identifier'].'" instead'); + unset($info['fileformat']); + unset($info['iso']); - public function ParseSupplementaryVolumeDescriptor(&$ISOheader) { - // ISO integer values are stored Both-Endian format!! - // ie 12345 == 0x3039 is stored as $39 $30 $30 $39 in a 4-byte field + return false; + } - // shortcuts - $info = &$this->getid3->info; - $info['iso']['supplementary_volume_descriptor']['raw'] = array(); - $thisfile_iso_supplementaryVD = &$info['iso']['supplementary_volume_descriptor']; - $thisfile_iso_supplementaryVD_raw = &$thisfile_iso_supplementaryVD['raw']; + $thisfile_iso_supplementaryVD_raw['volume_descriptor_version'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 6, 1)); + //$thisfile_iso_supplementaryVD_raw['unused_1'] = substr($ISOheader, 7, 1); + $thisfile_iso_supplementaryVD_raw['system_identifier'] = substr($ISOheader, 8, 32); + $thisfile_iso_supplementaryVD_raw['volume_identifier'] = substr($ISOheader, 40, 32); + //$thisfile_iso_supplementaryVD_raw['unused_2'] = substr($ISOheader, 72, 8); + $thisfile_iso_supplementaryVD_raw['volume_space_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 80, 4)); + if ($thisfile_iso_supplementaryVD_raw['volume_space_size'] == 0) { + // Supplementary Volume Descriptor not used + //unset($thisfile_iso_supplementaryVD); + //return false; + } - $thisfile_iso_supplementaryVD_raw['volume_descriptor_type'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 0, 1)); - $thisfile_iso_supplementaryVD_raw['standard_identifier'] = substr($ISOheader, 1, 5); - if ($thisfile_iso_supplementaryVD_raw['standard_identifier'] != 'CD001') { - $this->error('Expected "CD001" at offset ('.($thisfile_iso_supplementaryVD['offset'] + 1).'), found "'.$thisfile_iso_supplementaryVD_raw['standard_identifier'].'" instead'); - unset($info['fileformat']); - unset($info['iso']); - return false; - } + //$thisfile_iso_supplementaryVD_raw['unused_3'] = substr($ISOheader, 88, 32); + $thisfile_iso_supplementaryVD_raw['volume_set_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 120, 2)); + $thisfile_iso_supplementaryVD_raw['volume_sequence_number'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 124, 2)); + $thisfile_iso_supplementaryVD_raw['logical_block_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 128, 2)); + $thisfile_iso_supplementaryVD_raw['path_table_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 132, 4)); + $thisfile_iso_supplementaryVD_raw['path_table_l_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 140, 2)); + $thisfile_iso_supplementaryVD_raw['path_table_l_opt_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 144, 2)); + $thisfile_iso_supplementaryVD_raw['path_table_m_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 148, 2)); + $thisfile_iso_supplementaryVD_raw['path_table_m_opt_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 152, 2)); + $thisfile_iso_supplementaryVD_raw['root_directory_record'] = substr($ISOheader, 156, 34); + $thisfile_iso_supplementaryVD_raw['volume_set_identifier'] = substr($ISOheader, 190, 128); + $thisfile_iso_supplementaryVD_raw['publisher_identifier'] = substr($ISOheader, 318, 128); + $thisfile_iso_supplementaryVD_raw['data_preparer_identifier'] = substr($ISOheader, 446, 128); + $thisfile_iso_supplementaryVD_raw['application_identifier'] = substr($ISOheader, 574, 128); + $thisfile_iso_supplementaryVD_raw['copyright_file_identifier'] = substr($ISOheader, 702, 37); + $thisfile_iso_supplementaryVD_raw['abstract_file_identifier'] = substr($ISOheader, 739, 37); + $thisfile_iso_supplementaryVD_raw['bibliographic_file_identifier'] = substr($ISOheader, 776, 37); + $thisfile_iso_supplementaryVD_raw['volume_creation_date_time'] = substr($ISOheader, 813, 17); + $thisfile_iso_supplementaryVD_raw['volume_modification_date_time'] = substr($ISOheader, 830, 17); + $thisfile_iso_supplementaryVD_raw['volume_expiration_date_time'] = substr($ISOheader, 847, 17); + $thisfile_iso_supplementaryVD_raw['volume_effective_date_time'] = substr($ISOheader, 864, 17); + $thisfile_iso_supplementaryVD_raw['file_structure_version'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 881, 1)); + //$thisfile_iso_supplementaryVD_raw['unused_4'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 882, 1)); + $thisfile_iso_supplementaryVD_raw['application_data'] = substr($ISOheader, 883, 512); + //$thisfile_iso_supplementaryVD_raw['unused_5'] = substr($ISOheader, 1395, 653); - $thisfile_iso_supplementaryVD_raw['volume_descriptor_version'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 6, 1)); - //$thisfile_iso_supplementaryVD_raw['unused_1'] = substr($ISOheader, 7, 1); - $thisfile_iso_supplementaryVD_raw['system_identifier'] = substr($ISOheader, 8, 32); - $thisfile_iso_supplementaryVD_raw['volume_identifier'] = substr($ISOheader, 40, 32); - //$thisfile_iso_supplementaryVD_raw['unused_2'] = substr($ISOheader, 72, 8); - $thisfile_iso_supplementaryVD_raw['volume_space_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 80, 4)); - if ($thisfile_iso_supplementaryVD_raw['volume_space_size'] == 0) { - // Supplementary Volume Descriptor not used - //unset($thisfile_iso_supplementaryVD); - //return false; - } + $thisfile_iso_supplementaryVD['system_identifier'] = trim($thisfile_iso_supplementaryVD_raw['system_identifier']); + $thisfile_iso_supplementaryVD['volume_identifier'] = trim($thisfile_iso_supplementaryVD_raw['volume_identifier']); + $thisfile_iso_supplementaryVD['volume_set_identifier'] = trim($thisfile_iso_supplementaryVD_raw['volume_set_identifier']); + $thisfile_iso_supplementaryVD['publisher_identifier'] = trim($thisfile_iso_supplementaryVD_raw['publisher_identifier']); + $thisfile_iso_supplementaryVD['data_preparer_identifier'] = trim($thisfile_iso_supplementaryVD_raw['data_preparer_identifier']); + $thisfile_iso_supplementaryVD['application_identifier'] = trim($thisfile_iso_supplementaryVD_raw['application_identifier']); + $thisfile_iso_supplementaryVD['copyright_file_identifier'] = trim($thisfile_iso_supplementaryVD_raw['copyright_file_identifier']); + $thisfile_iso_supplementaryVD['abstract_file_identifier'] = trim($thisfile_iso_supplementaryVD_raw['abstract_file_identifier']); + $thisfile_iso_supplementaryVD['bibliographic_file_identifier'] = trim($thisfile_iso_supplementaryVD_raw['bibliographic_file_identifier']); + $thisfile_iso_supplementaryVD['volume_creation_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_creation_date_time']); + $thisfile_iso_supplementaryVD['volume_modification_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_modification_date_time']); + $thisfile_iso_supplementaryVD['volume_expiration_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_expiration_date_time']); + $thisfile_iso_supplementaryVD['volume_effective_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_effective_date_time']); - //$thisfile_iso_supplementaryVD_raw['unused_3'] = substr($ISOheader, 88, 32); - $thisfile_iso_supplementaryVD_raw['volume_set_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 120, 2)); - $thisfile_iso_supplementaryVD_raw['volume_sequence_number'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 124, 2)); - $thisfile_iso_supplementaryVD_raw['logical_block_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 128, 2)); - $thisfile_iso_supplementaryVD_raw['path_table_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 132, 4)); - $thisfile_iso_supplementaryVD_raw['path_table_l_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 140, 2)); - $thisfile_iso_supplementaryVD_raw['path_table_l_opt_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 144, 2)); - $thisfile_iso_supplementaryVD_raw['path_table_m_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 148, 2)); - $thisfile_iso_supplementaryVD_raw['path_table_m_opt_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 152, 2)); - $thisfile_iso_supplementaryVD_raw['root_directory_record'] = substr($ISOheader, 156, 34); - $thisfile_iso_supplementaryVD_raw['volume_set_identifier'] = substr($ISOheader, 190, 128); - $thisfile_iso_supplementaryVD_raw['publisher_identifier'] = substr($ISOheader, 318, 128); - $thisfile_iso_supplementaryVD_raw['data_preparer_identifier'] = substr($ISOheader, 446, 128); - $thisfile_iso_supplementaryVD_raw['application_identifier'] = substr($ISOheader, 574, 128); - $thisfile_iso_supplementaryVD_raw['copyright_file_identifier'] = substr($ISOheader, 702, 37); - $thisfile_iso_supplementaryVD_raw['abstract_file_identifier'] = substr($ISOheader, 739, 37); - $thisfile_iso_supplementaryVD_raw['bibliographic_file_identifier'] = substr($ISOheader, 776, 37); - $thisfile_iso_supplementaryVD_raw['volume_creation_date_time'] = substr($ISOheader, 813, 17); - $thisfile_iso_supplementaryVD_raw['volume_modification_date_time'] = substr($ISOheader, 830, 17); - $thisfile_iso_supplementaryVD_raw['volume_expiration_date_time'] = substr($ISOheader, 847, 17); - $thisfile_iso_supplementaryVD_raw['volume_effective_date_time'] = substr($ISOheader, 864, 17); - $thisfile_iso_supplementaryVD_raw['file_structure_version'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 881, 1)); - //$thisfile_iso_supplementaryVD_raw['unused_4'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 882, 1)); - $thisfile_iso_supplementaryVD_raw['application_data'] = substr($ISOheader, 883, 512); - //$thisfile_iso_supplementaryVD_raw['unused_5'] = substr($ISOheader, 1395, 653); + if (($thisfile_iso_supplementaryVD_raw['volume_space_size'] * $thisfile_iso_supplementaryVD_raw['logical_block_size']) > $info['filesize']) { + $this->error('Volume Space Size ('.($thisfile_iso_supplementaryVD_raw['volume_space_size'] * $thisfile_iso_supplementaryVD_raw['logical_block_size']).' bytes) is larger than the file size ('.$info['filesize'].' bytes) (truncated file?)'); + } - $thisfile_iso_supplementaryVD['system_identifier'] = trim($thisfile_iso_supplementaryVD_raw['system_identifier']); - $thisfile_iso_supplementaryVD['volume_identifier'] = trim($thisfile_iso_supplementaryVD_raw['volume_identifier']); - $thisfile_iso_supplementaryVD['volume_set_identifier'] = trim($thisfile_iso_supplementaryVD_raw['volume_set_identifier']); - $thisfile_iso_supplementaryVD['publisher_identifier'] = trim($thisfile_iso_supplementaryVD_raw['publisher_identifier']); - $thisfile_iso_supplementaryVD['data_preparer_identifier'] = trim($thisfile_iso_supplementaryVD_raw['data_preparer_identifier']); - $thisfile_iso_supplementaryVD['application_identifier'] = trim($thisfile_iso_supplementaryVD_raw['application_identifier']); - $thisfile_iso_supplementaryVD['copyright_file_identifier'] = trim($thisfile_iso_supplementaryVD_raw['copyright_file_identifier']); - $thisfile_iso_supplementaryVD['abstract_file_identifier'] = trim($thisfile_iso_supplementaryVD_raw['abstract_file_identifier']); - $thisfile_iso_supplementaryVD['bibliographic_file_identifier'] = trim($thisfile_iso_supplementaryVD_raw['bibliographic_file_identifier']); - $thisfile_iso_supplementaryVD['volume_creation_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_creation_date_time']); - $thisfile_iso_supplementaryVD['volume_modification_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_modification_date_time']); - $thisfile_iso_supplementaryVD['volume_expiration_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_expiration_date_time']); - $thisfile_iso_supplementaryVD['volume_effective_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_effective_date_time']); + return true; + } - if (($thisfile_iso_supplementaryVD_raw['volume_space_size'] * $thisfile_iso_supplementaryVD_raw['logical_block_size']) > $info['filesize']) { - $this->error('Volume Space Size ('.($thisfile_iso_supplementaryVD_raw['volume_space_size'] * $thisfile_iso_supplementaryVD_raw['logical_block_size']).' bytes) is larger than the file size ('.$info['filesize'].' bytes) (truncated file?)'); - } + public function ParsePathTable() + { + $info = &$this->getid3->info; + if (! isset($info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location']) && ! isset($info['iso']['primary_volume_descriptor']['raw']['path_table_l_location'])) { + return false; + } + if (isset($info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location'])) { + $PathTableLocation = $info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location']; + $PathTableSize = $info['iso']['supplementary_volume_descriptor']['raw']['path_table_size']; + $TextEncoding = 'UTF-16BE'; // Big-Endian Unicode + } else { + $PathTableLocation = $info['iso']['primary_volume_descriptor']['raw']['path_table_l_location']; + $PathTableSize = $info['iso']['primary_volume_descriptor']['raw']['path_table_size']; + $TextEncoding = 'ISO-8859-1'; // Latin-1 + } - return true; - } + if (($PathTableLocation * 2048) > $info['filesize']) { + $this->error('Path Table Location specifies an offset ('.($PathTableLocation * 2048).') beyond the end-of-file ('.$info['filesize'].')'); + return false; + } - public function ParsePathTable() { - $info = &$this->getid3->info; - if (!isset($info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location']) && !isset($info['iso']['primary_volume_descriptor']['raw']['path_table_l_location'])) { - return false; - } - if (isset($info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location'])) { - $PathTableLocation = $info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location']; - $PathTableSize = $info['iso']['supplementary_volume_descriptor']['raw']['path_table_size']; - $TextEncoding = 'UTF-16BE'; // Big-Endian Unicode - } else { - $PathTableLocation = $info['iso']['primary_volume_descriptor']['raw']['path_table_l_location']; - $PathTableSize = $info['iso']['primary_volume_descriptor']['raw']['path_table_size']; - $TextEncoding = 'ISO-8859-1'; // Latin-1 - } + $info['iso']['path_table']['offset'] = $PathTableLocation * 2048; + $this->fseek($info['iso']['path_table']['offset']); + $info['iso']['path_table']['raw'] = $this->fread($PathTableSize); - if (($PathTableLocation * 2048) > $info['filesize']) { - $this->error('Path Table Location specifies an offset ('.($PathTableLocation * 2048).') beyond the end-of-file ('.$info['filesize'].')'); - return false; - } + $offset = 0; + $pathcounter = 1; + while ($offset < $PathTableSize) { + // shortcut + $info['iso']['path_table']['directories'][$pathcounter] = []; + $thisfile_iso_pathtable_directories_current = &$info['iso']['path_table']['directories'][$pathcounter]; - $info['iso']['path_table']['offset'] = $PathTableLocation * 2048; - $this->fseek($info['iso']['path_table']['offset']); - $info['iso']['path_table']['raw'] = $this->fread($PathTableSize); + $thisfile_iso_pathtable_directories_current['length'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 1)); + $offset += 1; + $thisfile_iso_pathtable_directories_current['extended_length'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 1)); + $offset += 1; + $thisfile_iso_pathtable_directories_current['location_logical'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 4)); + $offset += 4; + $thisfile_iso_pathtable_directories_current['parent_directory'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 2)); + $offset += 2; + $thisfile_iso_pathtable_directories_current['name'] = substr($info['iso']['path_table']['raw'], $offset, $thisfile_iso_pathtable_directories_current['length']); + $offset += $thisfile_iso_pathtable_directories_current['length'] + ($thisfile_iso_pathtable_directories_current['length'] % 2); - $offset = 0; - $pathcounter = 1; - while ($offset < $PathTableSize) { - // shortcut - $info['iso']['path_table']['directories'][$pathcounter] = array(); - $thisfile_iso_pathtable_directories_current = &$info['iso']['path_table']['directories'][$pathcounter]; + $thisfile_iso_pathtable_directories_current['name_ascii'] = getid3_lib::iconv_fallback($TextEncoding, $info['encoding'], $thisfile_iso_pathtable_directories_current['name']); - $thisfile_iso_pathtable_directories_current['length'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 1)); - $offset += 1; - $thisfile_iso_pathtable_directories_current['extended_length'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 1)); - $offset += 1; - $thisfile_iso_pathtable_directories_current['location_logical'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 4)); - $offset += 4; - $thisfile_iso_pathtable_directories_current['parent_directory'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 2)); - $offset += 2; - $thisfile_iso_pathtable_directories_current['name'] = substr($info['iso']['path_table']['raw'], $offset, $thisfile_iso_pathtable_directories_current['length']); - $offset += $thisfile_iso_pathtable_directories_current['length'] + ($thisfile_iso_pathtable_directories_current['length'] % 2); + $thisfile_iso_pathtable_directories_current['location_bytes'] = $thisfile_iso_pathtable_directories_current['location_logical'] * 2048; + if ($pathcounter == 1) { + $thisfile_iso_pathtable_directories_current['full_path'] = '/'; + } else { + $thisfile_iso_pathtable_directories_current['full_path'] = $info['iso']['path_table']['directories'][$thisfile_iso_pathtable_directories_current['parent_directory']]['full_path'].$thisfile_iso_pathtable_directories_current['name_ascii'].'/'; + } + $FullPathArray[] = $thisfile_iso_pathtable_directories_current['full_path']; - $thisfile_iso_pathtable_directories_current['name_ascii'] = getid3_lib::iconv_fallback($TextEncoding, $info['encoding'], $thisfile_iso_pathtable_directories_current['name']); + $pathcounter++; + } - $thisfile_iso_pathtable_directories_current['location_bytes'] = $thisfile_iso_pathtable_directories_current['location_logical'] * 2048; - if ($pathcounter == 1) { - $thisfile_iso_pathtable_directories_current['full_path'] = '/'; - } else { - $thisfile_iso_pathtable_directories_current['full_path'] = $info['iso']['path_table']['directories'][$thisfile_iso_pathtable_directories_current['parent_directory']]['full_path'].$thisfile_iso_pathtable_directories_current['name_ascii'].'/'; - } - $FullPathArray[] = $thisfile_iso_pathtable_directories_current['full_path']; + return true; + } - $pathcounter++; - } + public function ParseDirectoryRecord($directorydata) + { + $info = &$this->getid3->info; + if (isset($info['iso']['supplementary_volume_descriptor'])) { + $TextEncoding = 'UTF-16BE'; // Big-Endian Unicode + } else { + $TextEncoding = 'ISO-8859-1'; // Latin-1 + } - return true; - } + $this->fseek($directorydata['location_bytes']); + $DirectoryRecordData = $this->fread(1); + while (ord($DirectoryRecordData[0]) > 33) { + $DirectoryRecordData .= $this->fread(ord($DirectoryRecordData[0]) - 1); - public function ParseDirectoryRecord($directorydata) { - $info = &$this->getid3->info; - if (isset($info['iso']['supplementary_volume_descriptor'])) { - $TextEncoding = 'UTF-16BE'; // Big-Endian Unicode - } else { - $TextEncoding = 'ISO-8859-1'; // Latin-1 - } + $ThisDirectoryRecord['raw']['length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 0, 1)); + $ThisDirectoryRecord['raw']['extended_attribute_length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 1, 1)); + $ThisDirectoryRecord['raw']['offset_logical'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 2, 4)); + $ThisDirectoryRecord['raw']['filesize'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 10, 4)); + $ThisDirectoryRecord['raw']['recording_date_time'] = substr($DirectoryRecordData, 18, 7); + $ThisDirectoryRecord['raw']['file_flags'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 25, 1)); + $ThisDirectoryRecord['raw']['file_unit_size'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 26, 1)); + $ThisDirectoryRecord['raw']['interleave_gap_size'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 27, 1)); + $ThisDirectoryRecord['raw']['volume_sequence_number'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 28, 2)); + $ThisDirectoryRecord['raw']['file_identifier_length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 32, 1)); + $ThisDirectoryRecord['raw']['file_identifier'] = substr($DirectoryRecordData, 33, $ThisDirectoryRecord['raw']['file_identifier_length']); - $this->fseek($directorydata['location_bytes']); - $DirectoryRecordData = $this->fread(1); + $ThisDirectoryRecord['file_identifier_ascii'] = getid3_lib::iconv_fallback($TextEncoding, $info['encoding'], $ThisDirectoryRecord['raw']['file_identifier']); - while (ord($DirectoryRecordData{0}) > 33) { + $ThisDirectoryRecord['filesize'] = $ThisDirectoryRecord['raw']['filesize']; + $ThisDirectoryRecord['offset_bytes'] = $ThisDirectoryRecord['raw']['offset_logical'] * 2048; + $ThisDirectoryRecord['file_flags']['hidden'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x01); + $ThisDirectoryRecord['file_flags']['directory'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x02); + $ThisDirectoryRecord['file_flags']['associated'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x04); + $ThisDirectoryRecord['file_flags']['extended'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x08); + $ThisDirectoryRecord['file_flags']['permissions'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x10); + $ThisDirectoryRecord['file_flags']['multiple'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x80); + $ThisDirectoryRecord['recording_timestamp'] = $this->ISOtime2UNIXtime($ThisDirectoryRecord['raw']['recording_date_time']); - $DirectoryRecordData .= $this->fread(ord($DirectoryRecordData{0}) - 1); + if ($ThisDirectoryRecord['file_flags']['directory']) { + $ThisDirectoryRecord['filename'] = $directorydata['full_path']; + } else { + $ThisDirectoryRecord['filename'] = $directorydata['full_path'].$this->ISOstripFilenameVersion($ThisDirectoryRecord['file_identifier_ascii']); + $info['iso']['files'] = getid3_lib::array_merge_clobber($info['iso']['files'], getid3_lib::CreateDeepArray($ThisDirectoryRecord['filename'], '/', $ThisDirectoryRecord['filesize'])); + } - $ThisDirectoryRecord['raw']['length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 0, 1)); - $ThisDirectoryRecord['raw']['extended_attribute_length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 1, 1)); - $ThisDirectoryRecord['raw']['offset_logical'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 2, 4)); - $ThisDirectoryRecord['raw']['filesize'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 10, 4)); - $ThisDirectoryRecord['raw']['recording_date_time'] = substr($DirectoryRecordData, 18, 7); - $ThisDirectoryRecord['raw']['file_flags'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 25, 1)); - $ThisDirectoryRecord['raw']['file_unit_size'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 26, 1)); - $ThisDirectoryRecord['raw']['interleave_gap_size'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 27, 1)); - $ThisDirectoryRecord['raw']['volume_sequence_number'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 28, 2)); - $ThisDirectoryRecord['raw']['file_identifier_length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 32, 1)); - $ThisDirectoryRecord['raw']['file_identifier'] = substr($DirectoryRecordData, 33, $ThisDirectoryRecord['raw']['file_identifier_length']); + $DirectoryRecord[] = $ThisDirectoryRecord; + $DirectoryRecordData = $this->fread(1); + } - $ThisDirectoryRecord['file_identifier_ascii'] = getid3_lib::iconv_fallback($TextEncoding, $info['encoding'], $ThisDirectoryRecord['raw']['file_identifier']); + return $DirectoryRecord; + } - $ThisDirectoryRecord['filesize'] = $ThisDirectoryRecord['raw']['filesize']; - $ThisDirectoryRecord['offset_bytes'] = $ThisDirectoryRecord['raw']['offset_logical'] * 2048; - $ThisDirectoryRecord['file_flags']['hidden'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x01); - $ThisDirectoryRecord['file_flags']['directory'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x02); - $ThisDirectoryRecord['file_flags']['associated'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x04); - $ThisDirectoryRecord['file_flags']['extended'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x08); - $ThisDirectoryRecord['file_flags']['permissions'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x10); - $ThisDirectoryRecord['file_flags']['multiple'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x80); - $ThisDirectoryRecord['recording_timestamp'] = $this->ISOtime2UNIXtime($ThisDirectoryRecord['raw']['recording_date_time']); + public function ISOstripFilenameVersion($ISOfilename) + { + // convert 'filename.ext;1' to 'filename.ext' + if (! strstr($ISOfilename, ';')) { + return $ISOfilename; + } else { + return substr($ISOfilename, 0, strpos($ISOfilename, ';')); + } + } - if ($ThisDirectoryRecord['file_flags']['directory']) { - $ThisDirectoryRecord['filename'] = $directorydata['full_path']; - } else { - $ThisDirectoryRecord['filename'] = $directorydata['full_path'].$this->ISOstripFilenameVersion($ThisDirectoryRecord['file_identifier_ascii']); - $info['iso']['files'] = getid3_lib::array_merge_clobber($info['iso']['files'], getid3_lib::CreateDeepArray($ThisDirectoryRecord['filename'], '/', $ThisDirectoryRecord['filesize'])); - } + public function ISOtimeText2UNIXtime($ISOtime) + { + $UNIXyear = (int) substr($ISOtime, 0, 4); + $UNIXmonth = (int) substr($ISOtime, 4, 2); + $UNIXday = (int) substr($ISOtime, 6, 2); + $UNIXhour = (int) substr($ISOtime, 8, 2); + $UNIXminute = (int) substr($ISOtime, 10, 2); + $UNIXsecond = (int) substr($ISOtime, 12, 2); - $DirectoryRecord[] = $ThisDirectoryRecord; - $DirectoryRecordData = $this->fread(1); - } + if (! $UNIXyear) { + return false; + } - return $DirectoryRecord; - } + return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear); + } - public function ISOstripFilenameVersion($ISOfilename) { - // convert 'filename.ext;1' to 'filename.ext' - if (!strstr($ISOfilename, ';')) { - return $ISOfilename; - } else { - return substr($ISOfilename, 0, strpos($ISOfilename, ';')); - } - } + public function ISOtime2UNIXtime($ISOtime) + { + // Represented by seven bytes: + // 1: Number of years since 1900 + // 2: Month of the year from 1 to 12 + // 3: Day of the Month from 1 to 31 + // 4: Hour of the day from 0 to 23 + // 5: Minute of the hour from 0 to 59 + // 6: second of the minute from 0 to 59 + // 7: Offset from Greenwich Mean Time in number of 15 minute intervals from -48 (West) to +52 (East) - public function ISOtimeText2UNIXtime($ISOtime) { + $UNIXyear = ord($ISOtime[0]) + 1900; + $UNIXmonth = ord($ISOtime[1]); + $UNIXday = ord($ISOtime[2]); + $UNIXhour = ord($ISOtime[3]); + $UNIXminute = ord($ISOtime[4]); + $UNIXsecond = ord($ISOtime[5]); + $GMToffset = $this->TwosCompliment2Decimal(ord($ISOtime[5])); - $UNIXyear = (int) substr($ISOtime, 0, 4); - $UNIXmonth = (int) substr($ISOtime, 4, 2); - $UNIXday = (int) substr($ISOtime, 6, 2); - $UNIXhour = (int) substr($ISOtime, 8, 2); - $UNIXminute = (int) substr($ISOtime, 10, 2); - $UNIXsecond = (int) substr($ISOtime, 12, 2); + return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear); + } - if (!$UNIXyear) { - return false; - } - return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear); - } - - public function ISOtime2UNIXtime($ISOtime) { - // Represented by seven bytes: - // 1: Number of years since 1900 - // 2: Month of the year from 1 to 12 - // 3: Day of the Month from 1 to 31 - // 4: Hour of the day from 0 to 23 - // 5: Minute of the hour from 0 to 59 - // 6: second of the minute from 0 to 59 - // 7: Offset from Greenwich Mean Time in number of 15 minute intervals from -48 (West) to +52 (East) - - $UNIXyear = ord($ISOtime{0}) + 1900; - $UNIXmonth = ord($ISOtime{1}); - $UNIXday = ord($ISOtime{2}); - $UNIXhour = ord($ISOtime{3}); - $UNIXminute = ord($ISOtime{4}); - $UNIXsecond = ord($ISOtime{5}); - $GMToffset = $this->TwosCompliment2Decimal(ord($ISOtime{5})); - - return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear); - } - - public function TwosCompliment2Decimal($BinaryValue) { - // http://sandbox.mc.edu/~bennet/cs110/tc/tctod.html - // First check if the number is negative or positive by looking at the sign bit. - // If it is positive, simply convert it to decimal. - // If it is negative, make it positive by inverting the bits and adding one. - // Then, convert the result to decimal. - // The negative of this number is the value of the original binary. - - if ($BinaryValue & 0x80) { - - // negative number - return (0 - ((~$BinaryValue & 0xFF) + 1)); - } else { - // positive number - return $BinaryValue; - } - } + public function TwosCompliment2Decimal($BinaryValue) + { + // http://sandbox.mc.edu/~bennet/cs110/tc/tctod.html + // First check if the number is negative or positive by looking at the sign bit. + // If it is positive, simply convert it to decimal. + // If it is negative, make it positive by inverting the bits and adding one. + // Then, convert the result to decimal. + // The negative of this number is the value of the original binary. + if ($BinaryValue & 0x80) { + // negative number + return 0 - ((~$BinaryValue & 0xFF) + 1); + } else { + // positive number + return $BinaryValue; + } + } } diff --git a/app/Library/getid3/getid3/module.misc.msoffice.php b/app/Library/getid3/getid3/module.misc.msoffice.php index 099e6fc9..86ce6ff4 100644 --- a/app/Library/getid3/getid3/module.misc.msoffice.php +++ b/app/Library/getid3/getid3/module.misc.msoffice.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,25 +15,24 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_msoffice extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $DOCFILEheader = $this->fread(8); + $magic = "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"; + if (substr($DOCFILEheader, 0, 8) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at '.$info['avdataoffset'].', found '.getid3_lib::PrintHexBytes(substr($DOCFILEheader, 0, 8)).' instead.'); - $this->fseek($info['avdataoffset']); - $DOCFILEheader = $this->fread(8); - $magic = "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"; - if (substr($DOCFILEheader, 0, 8) != $magic) { - $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at '.$info['avdataoffset'].', found '.getid3_lib::PrintHexBytes(substr($DOCFILEheader, 0, 8)).' instead.'); - return false; - } - $info['fileformat'] = 'msoffice'; + return false; + } + $info['fileformat'] = 'msoffice'; -$this->error('MS Office (.doc, .xls, etc) parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); -return false; - - } + $this->error('MS Office (.doc, .xls, etc) parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); + return false; + } } diff --git a/app/Library/getid3/getid3/module.misc.par2.php b/app/Library/getid3/getid3/module.misc.par2.php index 2312bb84..36f5907e 100644 --- a/app/Library/getid3/getid3/module.misc.par2.php +++ b/app/Library/getid3/getid3/module.misc.par2.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,18 +15,16 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_par2 extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $info['fileformat'] = 'par2'; - $info['fileformat'] = 'par2'; - - $this->error('PAR2 parsing not enabled in this version of getID3()'); - return false; - - } + $this->error('PAR2 parsing not enabled in this version of getID3()'); + return false; + } } diff --git a/app/Library/getid3/getid3/module.misc.pdf.php b/app/Library/getid3/getid3/module.misc.pdf.php index e8d25cba..afc62a72 100644 --- a/app/Library/getid3/getid3/module.misc.pdf.php +++ b/app/Library/getid3/getid3/module.misc.pdf.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,18 +15,16 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_pdf extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + $info['fileformat'] = 'pdf'; - $info['fileformat'] = 'pdf'; - - $this->error('PDF parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); - return false; - - } + $this->error('PDF parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); + return false; + } } diff --git a/app/Library/getid3/getid3/module.tag.apetag.php b/app/Library/getid3/getid3/module.tag.apetag.php index 938625a8..077a5b79 100644 --- a/app/Library/getid3/getid3/module.tag.apetag.php +++ b/app/Library/getid3/getid3/module.tag.apetag.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -16,401 +17,407 @@ class getid3_apetag extends getid3_handler { - public $inline_attachments = true; // true: return full data for all attachments; false: return no data for all attachments; integer: return data for attachments <= than this; string: save as file to this directory - public $overrideendoffset = 0; + public $inline_attachments = true; // true: return full data for all attachments; false: return no data for all attachments; integer: return data for attachments <= than this; string: save as file to this directory + public $overrideendoffset = 0; - public function Analyze() { - $info = &$this->getid3->info; + public function Analyze() + { + $info = &$this->getid3->info; - if (!getid3_lib::intValueSupported($info['filesize'])) { - $this->warning('Unable to check for APEtags because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'); - return false; - } + if (! getid3_lib::intValueSupported($info['filesize'])) { + $this->warning('Unable to check for APEtags because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'); - $id3v1tagsize = 128; - $apetagheadersize = 32; - $lyrics3tagsize = 10; + return false; + } - if ($this->overrideendoffset == 0) { + $id3v1tagsize = 128; + $apetagheadersize = 32; + $lyrics3tagsize = 10; - $this->fseek(0 - $id3v1tagsize - $apetagheadersize - $lyrics3tagsize, SEEK_END); - $APEfooterID3v1 = $this->fread($id3v1tagsize + $apetagheadersize + $lyrics3tagsize); + if ($this->overrideendoffset == 0) { + $this->fseek(0 - $id3v1tagsize - $apetagheadersize - $lyrics3tagsize, SEEK_END); + $APEfooterID3v1 = $this->fread($id3v1tagsize + $apetagheadersize + $lyrics3tagsize); - //if (preg_match('/APETAGEX.{24}TAG.{125}$/i', $APEfooterID3v1)) { - if (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $id3v1tagsize - $apetagheadersize, 8) == 'APETAGEX') { + //if (preg_match('/APETAGEX.{24}TAG.{125}$/i', $APEfooterID3v1)) { + if (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $id3v1tagsize - $apetagheadersize, 8) == 'APETAGEX') { - // APE tag found before ID3v1 - $info['ape']['tag_offset_end'] = $info['filesize'] - $id3v1tagsize; + // APE tag found before ID3v1 + $info['ape']['tag_offset_end'] = $info['filesize'] - $id3v1tagsize; - //} elseif (preg_match('/APETAGEX.{24}$/i', $APEfooterID3v1)) { - } elseif (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $apetagheadersize, 8) == 'APETAGEX') { + //} elseif (preg_match('/APETAGEX.{24}$/i', $APEfooterID3v1)) { + } elseif (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $apetagheadersize, 8) == 'APETAGEX') { - // APE tag found, no ID3v1 - $info['ape']['tag_offset_end'] = $info['filesize']; + // APE tag found, no ID3v1 + $info['ape']['tag_offset_end'] = $info['filesize']; + } + } else { + $this->fseek($this->overrideendoffset - $apetagheadersize); + if ($this->fread(8) == 'APETAGEX') { + $info['ape']['tag_offset_end'] = $this->overrideendoffset; + } + } + if (! isset($info['ape']['tag_offset_end'])) { - } + // APE tag not found + unset($info['ape']); - } else { + return false; + } - $this->fseek($this->overrideendoffset - $apetagheadersize); - if ($this->fread(8) == 'APETAGEX') { - $info['ape']['tag_offset_end'] = $this->overrideendoffset; - } + // shortcut + $thisfile_ape = &$info['ape']; - } - if (!isset($info['ape']['tag_offset_end'])) { + $this->fseek($thisfile_ape['tag_offset_end'] - $apetagheadersize); + $APEfooterData = $this->fread(32); + if (! ($thisfile_ape['footer'] = $this->parseAPEheaderFooter($APEfooterData))) { + $this->error('Error parsing APE footer at offset '.$thisfile_ape['tag_offset_end']); - // APE tag not found - unset($info['ape']); - return false; + return false; + } - } + if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) { + $this->fseek($thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'] - $apetagheadersize); + $thisfile_ape['tag_offset_start'] = $this->ftell(); + $APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize'] + $apetagheadersize); + } else { + $thisfile_ape['tag_offset_start'] = $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize']; + $this->fseek($thisfile_ape['tag_offset_start']); + $APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize']); + } + $info['avdataend'] = $thisfile_ape['tag_offset_start']; - // shortcut - $thisfile_ape = &$info['ape']; + if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] < $thisfile_ape['tag_offset_end'])) { + $this->warning('ID3v1 tag information ignored since it appears to be a false synch in APEtag data'); + unset($info['id3v1']); + foreach ($info['warning'] as $key => $value) { + if ($value == 'Some ID3v1 fields do not use NULL characters for padding') { + unset($info['warning'][$key]); + sort($info['warning']); + break; + } + } + } - $this->fseek($thisfile_ape['tag_offset_end'] - $apetagheadersize); - $APEfooterData = $this->fread(32); - if (!($thisfile_ape['footer'] = $this->parseAPEheaderFooter($APEfooterData))) { - $this->error('Error parsing APE footer at offset '.$thisfile_ape['tag_offset_end']); - return false; - } + $offset = 0; + if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) { + if ($thisfile_ape['header'] = $this->parseAPEheaderFooter(substr($APEtagData, 0, $apetagheadersize))) { + $offset += $apetagheadersize; + } else { + $this->error('Error parsing APE header at offset '.$thisfile_ape['tag_offset_start']); - if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) { - $this->fseek($thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'] - $apetagheadersize); - $thisfile_ape['tag_offset_start'] = $this->ftell(); - $APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize'] + $apetagheadersize); - } else { - $thisfile_ape['tag_offset_start'] = $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize']; - $this->fseek($thisfile_ape['tag_offset_start']); - $APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize']); - } - $info['avdataend'] = $thisfile_ape['tag_offset_start']; + return false; + } + } - if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] < $thisfile_ape['tag_offset_end'])) { - $this->warning('ID3v1 tag information ignored since it appears to be a false synch in APEtag data'); - unset($info['id3v1']); - foreach ($info['warning'] as $key => $value) { - if ($value == 'Some ID3v1 fields do not use NULL characters for padding') { - unset($info['warning'][$key]); - sort($info['warning']); - break; - } - } - } + // shortcut + $info['replay_gain'] = []; + $thisfile_replaygain = &$info['replay_gain']; - $offset = 0; - if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) { - if ($thisfile_ape['header'] = $this->parseAPEheaderFooter(substr($APEtagData, 0, $apetagheadersize))) { - $offset += $apetagheadersize; - } else { - $this->error('Error parsing APE header at offset '.$thisfile_ape['tag_offset_start']); - return false; - } - } + for ($i = 0; $i < $thisfile_ape['footer']['raw']['tag_items']; $i++) { + $value_size = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4)); + $offset += 4; + $item_flags = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4)); + $offset += 4; + if (strstr(substr($APEtagData, $offset), "\x00") === false) { + $this->error('Cannot find null-byte (0x00) separator between ItemKey #'.$i.' and value. ItemKey starts '.$offset.' bytes into the APE tag, at file offset '.($thisfile_ape['tag_offset_start'] + $offset)); - // shortcut - $info['replay_gain'] = array(); - $thisfile_replaygain = &$info['replay_gain']; + return false; + } + $ItemKeyLength = strpos($APEtagData, "\x00", $offset) - $offset; + $item_key = strtolower(substr($APEtagData, $offset, $ItemKeyLength)); - for ($i = 0; $i < $thisfile_ape['footer']['raw']['tag_items']; $i++) { - $value_size = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4)); - $offset += 4; - $item_flags = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4)); - $offset += 4; - if (strstr(substr($APEtagData, $offset), "\x00") === false) { - $this->error('Cannot find null-byte (0x00) separator between ItemKey #'.$i.' and value. ItemKey starts '.$offset.' bytes into the APE tag, at file offset '.($thisfile_ape['tag_offset_start'] + $offset)); - return false; - } - $ItemKeyLength = strpos($APEtagData, "\x00", $offset) - $offset; - $item_key = strtolower(substr($APEtagData, $offset, $ItemKeyLength)); + // shortcut + $thisfile_ape['items'][$item_key] = []; + $thisfile_ape_items_current = &$thisfile_ape['items'][$item_key]; - // shortcut - $thisfile_ape['items'][$item_key] = array(); - $thisfile_ape_items_current = &$thisfile_ape['items'][$item_key]; + $thisfile_ape_items_current['offset'] = $thisfile_ape['tag_offset_start'] + $offset; - $thisfile_ape_items_current['offset'] = $thisfile_ape['tag_offset_start'] + $offset; + $offset += ($ItemKeyLength + 1); // skip 0x00 terminator + $thisfile_ape_items_current['data'] = substr($APEtagData, $offset, $value_size); + $offset += $value_size; - $offset += ($ItemKeyLength + 1); // skip 0x00 terminator - $thisfile_ape_items_current['data'] = substr($APEtagData, $offset, $value_size); - $offset += $value_size; + $thisfile_ape_items_current['flags'] = $this->parseAPEtagFlags($item_flags); + switch ($thisfile_ape_items_current['flags']['item_contents_raw']) { + case 0: // UTF-8 + case 2: // Locator (URL, filename, etc), UTF-8 encoded + $thisfile_ape_items_current['data'] = explode("\x00", $thisfile_ape_items_current['data']); + break; - $thisfile_ape_items_current['flags'] = $this->parseAPEtagFlags($item_flags); - switch ($thisfile_ape_items_current['flags']['item_contents_raw']) { - case 0: // UTF-8 - case 2: // Locator (URL, filename, etc), UTF-8 encoded - $thisfile_ape_items_current['data'] = explode("\x00", $thisfile_ape_items_current['data']); - break; + case 1: // binary data + default: + break; + } - case 1: // binary data - default: - break; - } + switch (strtolower($item_key)) { + // http://wiki.hydrogenaud.io/index.php?title=ReplayGain#MP3Gain + case 'replaygain_track_gain': + if (preg_match('#^[\\-\\+][0-9\\.,]{8}$#', $thisfile_ape_items_current['data'][0])) { + $thisfile_replaygain['track']['adjustment'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero! + $thisfile_replaygain['track']['originator'] = 'unspecified'; + } else { + $this->warning('MP3gainTrackGain value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); + } + break; - switch (strtolower($item_key)) { - // http://wiki.hydrogenaud.io/index.php?title=ReplayGain#MP3Gain - case 'replaygain_track_gain': - if (preg_match('#^[\\-\\+][0-9\\.,]{8}$#', $thisfile_ape_items_current['data'][0])) { - $thisfile_replaygain['track']['adjustment'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero! - $thisfile_replaygain['track']['originator'] = 'unspecified'; - } else { - $this->warning('MP3gainTrackGain value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); - } - break; + case 'replaygain_track_peak': + if (preg_match('#^[0-9\\.,]{8}$#', $thisfile_ape_items_current['data'][0])) { + $thisfile_replaygain['track']['peak'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero! + $thisfile_replaygain['track']['originator'] = 'unspecified'; + if ($thisfile_replaygain['track']['peak'] <= 0) { + $this->warning('ReplayGain Track peak from APEtag appears invalid: '.$thisfile_replaygain['track']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")'); + } + } else { + $this->warning('MP3gainTrackPeak value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); + } + break; - case 'replaygain_track_peak': - if (preg_match('#^[0-9\\.,]{8}$#', $thisfile_ape_items_current['data'][0])) { - $thisfile_replaygain['track']['peak'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero! - $thisfile_replaygain['track']['originator'] = 'unspecified'; - if ($thisfile_replaygain['track']['peak'] <= 0) { - $this->warning('ReplayGain Track peak from APEtag appears invalid: '.$thisfile_replaygain['track']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")'); - } - } else { - $this->warning('MP3gainTrackPeak value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); - } - break; + case 'replaygain_album_gain': + if (preg_match('#^[\\-\\+][0-9\\.,]{8}$#', $thisfile_ape_items_current['data'][0])) { + $thisfile_replaygain['album']['adjustment'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero! + $thisfile_replaygain['album']['originator'] = 'unspecified'; + } else { + $this->warning('MP3gainAlbumGain value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); + } + break; - case 'replaygain_album_gain': - if (preg_match('#^[\\-\\+][0-9\\.,]{8}$#', $thisfile_ape_items_current['data'][0])) { - $thisfile_replaygain['album']['adjustment'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero! - $thisfile_replaygain['album']['originator'] = 'unspecified'; - } else { - $this->warning('MP3gainAlbumGain value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); - } - break; + case 'replaygain_album_peak': + if (preg_match('#^[0-9\\.,]{8}$#', $thisfile_ape_items_current['data'][0])) { + $thisfile_replaygain['album']['peak'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero! + $thisfile_replaygain['album']['originator'] = 'unspecified'; + if ($thisfile_replaygain['album']['peak'] <= 0) { + $this->warning('ReplayGain Album peak from APEtag appears invalid: '.$thisfile_replaygain['album']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")'); + } + } else { + $this->warning('MP3gainAlbumPeak value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); + } + break; - case 'replaygain_album_peak': - if (preg_match('#^[0-9\\.,]{8}$#', $thisfile_ape_items_current['data'][0])) { - $thisfile_replaygain['album']['peak'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero! - $thisfile_replaygain['album']['originator'] = 'unspecified'; - if ($thisfile_replaygain['album']['peak'] <= 0) { - $this->warning('ReplayGain Album peak from APEtag appears invalid: '.$thisfile_replaygain['album']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")'); - } - } else { - $this->warning('MP3gainAlbumPeak value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); - } - break; + case 'mp3gain_undo': + if (preg_match('#^[\\-\\+][0-9]{3},[\\-\\+][0-9]{3},[NW]$#', $thisfile_ape_items_current['data'][0])) { + list($mp3gain_undo_left, $mp3gain_undo_right, $mp3gain_undo_wrap) = explode(',', $thisfile_ape_items_current['data'][0]); + $thisfile_replaygain['mp3gain']['undo_left'] = intval($mp3gain_undo_left); + $thisfile_replaygain['mp3gain']['undo_right'] = intval($mp3gain_undo_right); + $thisfile_replaygain['mp3gain']['undo_wrap'] = (($mp3gain_undo_wrap == 'Y') ? true : false); + } else { + $this->warning('MP3gainUndo value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); + } + break; - case 'mp3gain_undo': - if (preg_match('#^[\\-\\+][0-9]{3},[\\-\\+][0-9]{3},[NW]$#', $thisfile_ape_items_current['data'][0])) { - list($mp3gain_undo_left, $mp3gain_undo_right, $mp3gain_undo_wrap) = explode(',', $thisfile_ape_items_current['data'][0]); - $thisfile_replaygain['mp3gain']['undo_left'] = intval($mp3gain_undo_left); - $thisfile_replaygain['mp3gain']['undo_right'] = intval($mp3gain_undo_right); - $thisfile_replaygain['mp3gain']['undo_wrap'] = (($mp3gain_undo_wrap == 'Y') ? true : false); - } else { - $this->warning('MP3gainUndo value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); - } - break; + case 'mp3gain_minmax': + if (preg_match('#^[0-9]{3},[0-9]{3}$#', $thisfile_ape_items_current['data'][0])) { + list($mp3gain_globalgain_min, $mp3gain_globalgain_max) = explode(',', $thisfile_ape_items_current['data'][0]); + $thisfile_replaygain['mp3gain']['globalgain_track_min'] = intval($mp3gain_globalgain_min); + $thisfile_replaygain['mp3gain']['globalgain_track_max'] = intval($mp3gain_globalgain_max); + } else { + $this->warning('MP3gainMinMax value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); + } + break; - case 'mp3gain_minmax': - if (preg_match('#^[0-9]{3},[0-9]{3}$#', $thisfile_ape_items_current['data'][0])) { - list($mp3gain_globalgain_min, $mp3gain_globalgain_max) = explode(',', $thisfile_ape_items_current['data'][0]); - $thisfile_replaygain['mp3gain']['globalgain_track_min'] = intval($mp3gain_globalgain_min); - $thisfile_replaygain['mp3gain']['globalgain_track_max'] = intval($mp3gain_globalgain_max); - } else { - $this->warning('MP3gainMinMax value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); - } - break; + case 'mp3gain_album_minmax': + if (preg_match('#^[0-9]{3},[0-9]{3}$#', $thisfile_ape_items_current['data'][0])) { + list($mp3gain_globalgain_album_min, $mp3gain_globalgain_album_max) = explode(',', $thisfile_ape_items_current['data'][0]); + $thisfile_replaygain['mp3gain']['globalgain_album_min'] = intval($mp3gain_globalgain_album_min); + $thisfile_replaygain['mp3gain']['globalgain_album_max'] = intval($mp3gain_globalgain_album_max); + } else { + $this->warning('MP3gainAlbumMinMax value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); + } + break; - case 'mp3gain_album_minmax': - if (preg_match('#^[0-9]{3},[0-9]{3}$#', $thisfile_ape_items_current['data'][0])) { - list($mp3gain_globalgain_album_min, $mp3gain_globalgain_album_max) = explode(',', $thisfile_ape_items_current['data'][0]); - $thisfile_replaygain['mp3gain']['globalgain_album_min'] = intval($mp3gain_globalgain_album_min); - $thisfile_replaygain['mp3gain']['globalgain_album_max'] = intval($mp3gain_globalgain_album_max); - } else { - $this->warning('MP3gainAlbumMinMax value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); - } - break; + case 'tracknumber': + if (is_array($thisfile_ape_items_current['data'])) { + foreach ($thisfile_ape_items_current['data'] as $comment) { + $thisfile_ape['comments']['track'][] = $comment; + } + } + break; - case 'tracknumber': - if (is_array($thisfile_ape_items_current['data'])) { - foreach ($thisfile_ape_items_current['data'] as $comment) { - $thisfile_ape['comments']['track'][] = $comment; - } - } - break; + case 'cover art (artist)': + case 'cover art (back)': + case 'cover art (band logo)': + case 'cover art (band)': + case 'cover art (colored fish)': + case 'cover art (composer)': + case 'cover art (conductor)': + case 'cover art (front)': + case 'cover art (icon)': + case 'cover art (illustration)': + case 'cover art (lead)': + case 'cover art (leaflet)': + case 'cover art (lyricist)': + case 'cover art (media)': + case 'cover art (movie scene)': + case 'cover art (other icon)': + case 'cover art (other)': + case 'cover art (performance)': + case 'cover art (publisher logo)': + case 'cover art (recording)': + case 'cover art (studio)': + // list of possible cover arts from http://taglib-sharp.sourcearchive.com/documentation/2.0.3.0-2/Ape_2Tag_8cs-source.html + if (is_array($thisfile_ape_items_current['data'])) { + $this->warning('APEtag "'.$item_key.'" should be flagged as Binary data, but was incorrectly flagged as UTF-8'); + $thisfile_ape_items_current['data'] = implode("\x00", $thisfile_ape_items_current['data']); + } + list($thisfile_ape_items_current['filename'], $thisfile_ape_items_current['data']) = explode("\x00", $thisfile_ape_items_current['data'], 2); + $thisfile_ape_items_current['data_offset'] = $thisfile_ape_items_current['offset'] + strlen($thisfile_ape_items_current['filename']."\x00"); + $thisfile_ape_items_current['data_length'] = strlen($thisfile_ape_items_current['data']); - case 'cover art (artist)': - case 'cover art (back)': - case 'cover art (band logo)': - case 'cover art (band)': - case 'cover art (colored fish)': - case 'cover art (composer)': - case 'cover art (conductor)': - case 'cover art (front)': - case 'cover art (icon)': - case 'cover art (illustration)': - case 'cover art (lead)': - case 'cover art (leaflet)': - case 'cover art (lyricist)': - case 'cover art (media)': - case 'cover art (movie scene)': - case 'cover art (other icon)': - case 'cover art (other)': - case 'cover art (performance)': - case 'cover art (publisher logo)': - case 'cover art (recording)': - case 'cover art (studio)': - // list of possible cover arts from http://taglib-sharp.sourcearchive.com/documentation/2.0.3.0-2/Ape_2Tag_8cs-source.html - if (is_array($thisfile_ape_items_current['data'])) { - $this->warning('APEtag "'.$item_key.'" should be flagged as Binary data, but was incorrectly flagged as UTF-8'); - $thisfile_ape_items_current['data'] = implode("\x00", $thisfile_ape_items_current['data']); - } - list($thisfile_ape_items_current['filename'], $thisfile_ape_items_current['data']) = explode("\x00", $thisfile_ape_items_current['data'], 2); - $thisfile_ape_items_current['data_offset'] = $thisfile_ape_items_current['offset'] + strlen($thisfile_ape_items_current['filename']."\x00"); - $thisfile_ape_items_current['data_length'] = strlen($thisfile_ape_items_current['data']); + do { + $thisfile_ape_items_current['image_mime'] = ''; + $imageinfo = []; + $imagechunkcheck = getid3_lib::GetDataImageSize($thisfile_ape_items_current['data'], $imageinfo); + if (($imagechunkcheck === false) || ! isset($imagechunkcheck[2])) { + $this->warning('APEtag "'.$item_key.'" contains invalid image data'); + break; + } + $thisfile_ape_items_current['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]); - do { - $thisfile_ape_items_current['image_mime'] = ''; - $imageinfo = array(); - $imagechunkcheck = getid3_lib::GetDataImageSize($thisfile_ape_items_current['data'], $imageinfo); - if (($imagechunkcheck === false) || !isset($imagechunkcheck[2])) { - $this->warning('APEtag "'.$item_key.'" contains invalid image data'); - break; - } - $thisfile_ape_items_current['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]); + if ($this->inline_attachments === false) { + // skip entirely + unset($thisfile_ape_items_current['data']); + break; + } + if ($this->inline_attachments === true) { + // great + } elseif (is_int($this->inline_attachments)) { + if ($this->inline_attachments < $thisfile_ape_items_current['data_length']) { + // too big, skip + $this->warning('attachment at '.$thisfile_ape_items_current['offset'].' is too large to process inline ('.number_format($thisfile_ape_items_current['data_length']).' bytes)'); + unset($thisfile_ape_items_current['data']); + break; + } + } elseif (is_string($this->inline_attachments)) { + $this->inline_attachments = rtrim(str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $this->inline_attachments), DIRECTORY_SEPARATOR); + if (! is_dir($this->inline_attachments) || ! is_writable($this->inline_attachments)) { + // cannot write, skip + $this->warning('attachment at '.$thisfile_ape_items_current['offset'].' cannot be saved to "'.$this->inline_attachments.'" (not writable)'); + unset($thisfile_ape_items_current['data']); + break; + } + } + // if we get this far, must be OK + if (is_string($this->inline_attachments)) { + $destination_filename = $this->inline_attachments.DIRECTORY_SEPARATOR.md5($info['filenamepath']).'_'.$thisfile_ape_items_current['data_offset']; + if (! file_exists($destination_filename) || is_writable($destination_filename)) { + file_put_contents($destination_filename, $thisfile_ape_items_current['data']); + } else { + $this->warning('attachment at '.$thisfile_ape_items_current['offset'].' cannot be saved to "'.$destination_filename.'" (not writable)'); + } + $thisfile_ape_items_current['data_filename'] = $destination_filename; + unset($thisfile_ape_items_current['data']); + } else { + if (! isset($info['ape']['comments']['picture'])) { + $info['ape']['comments']['picture'] = []; + } + $comments_picture_data = []; + foreach (['data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength'] as $picture_key) { + if (isset($thisfile_ape_items_current[$picture_key])) { + $comments_picture_data[$picture_key] = $thisfile_ape_items_current[$picture_key]; + } + } + $info['ape']['comments']['picture'][] = $comments_picture_data; + unset($comments_picture_data); + } + } while (false); + break; - if ($this->inline_attachments === false) { - // skip entirely - unset($thisfile_ape_items_current['data']); - break; - } - if ($this->inline_attachments === true) { - // great - } elseif (is_int($this->inline_attachments)) { - if ($this->inline_attachments < $thisfile_ape_items_current['data_length']) { - // too big, skip - $this->warning('attachment at '.$thisfile_ape_items_current['offset'].' is too large to process inline ('.number_format($thisfile_ape_items_current['data_length']).' bytes)'); - unset($thisfile_ape_items_current['data']); - break; - } - } elseif (is_string($this->inline_attachments)) { - $this->inline_attachments = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->inline_attachments), DIRECTORY_SEPARATOR); - if (!is_dir($this->inline_attachments) || !is_writable($this->inline_attachments)) { - // cannot write, skip - $this->warning('attachment at '.$thisfile_ape_items_current['offset'].' cannot be saved to "'.$this->inline_attachments.'" (not writable)'); - unset($thisfile_ape_items_current['data']); - break; - } - } - // if we get this far, must be OK - if (is_string($this->inline_attachments)) { - $destination_filename = $this->inline_attachments.DIRECTORY_SEPARATOR.md5($info['filenamepath']).'_'.$thisfile_ape_items_current['data_offset']; - if (!file_exists($destination_filename) || is_writable($destination_filename)) { - file_put_contents($destination_filename, $thisfile_ape_items_current['data']); - } else { - $this->warning('attachment at '.$thisfile_ape_items_current['offset'].' cannot be saved to "'.$destination_filename.'" (not writable)'); - } - $thisfile_ape_items_current['data_filename'] = $destination_filename; - unset($thisfile_ape_items_current['data']); - } else { - if (!isset($info['ape']['comments']['picture'])) { - $info['ape']['comments']['picture'] = array(); - } - $comments_picture_data = array(); - foreach (array('data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength') as $picture_key) { - if (isset($thisfile_ape_items_current[$picture_key])) { - $comments_picture_data[$picture_key] = $thisfile_ape_items_current[$picture_key]; - } - } - $info['ape']['comments']['picture'][] = $comments_picture_data; - unset($comments_picture_data); - } - } while (false); - break; + default: + if (is_array($thisfile_ape_items_current['data'])) { + foreach ($thisfile_ape_items_current['data'] as $comment) { + $thisfile_ape['comments'][strtolower($item_key)][] = $comment; + } + } + break; + } + } + if (empty($thisfile_replaygain)) { + unset($info['replay_gain']); + } - default: - if (is_array($thisfile_ape_items_current['data'])) { - foreach ($thisfile_ape_items_current['data'] as $comment) { - $thisfile_ape['comments'][strtolower($item_key)][] = $comment; - } - } - break; - } + return true; + } - } - if (empty($thisfile_replaygain)) { - unset($info['replay_gain']); - } - return true; - } + public function parseAPEheaderFooter($APEheaderFooterData) + { + // http://www.uni-jena.de/~pfk/mpp/sv8/apeheader.html - public function parseAPEheaderFooter($APEheaderFooterData) { - // http://www.uni-jena.de/~pfk/mpp/sv8/apeheader.html + // shortcut + $headerfooterinfo['raw'] = []; + $headerfooterinfo_raw = &$headerfooterinfo['raw']; - // shortcut - $headerfooterinfo['raw'] = array(); - $headerfooterinfo_raw = &$headerfooterinfo['raw']; + $headerfooterinfo_raw['footer_tag'] = substr($APEheaderFooterData, 0, 8); + if ($headerfooterinfo_raw['footer_tag'] != 'APETAGEX') { + return false; + } + $headerfooterinfo_raw['version'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 8, 4)); + $headerfooterinfo_raw['tagsize'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 12, 4)); + $headerfooterinfo_raw['tag_items'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 16, 4)); + $headerfooterinfo_raw['global_flags'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 20, 4)); + $headerfooterinfo_raw['reserved'] = substr($APEheaderFooterData, 24, 8); - $headerfooterinfo_raw['footer_tag'] = substr($APEheaderFooterData, 0, 8); - if ($headerfooterinfo_raw['footer_tag'] != 'APETAGEX') { - return false; - } - $headerfooterinfo_raw['version'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 8, 4)); - $headerfooterinfo_raw['tagsize'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 12, 4)); - $headerfooterinfo_raw['tag_items'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 16, 4)); - $headerfooterinfo_raw['global_flags'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 20, 4)); - $headerfooterinfo_raw['reserved'] = substr($APEheaderFooterData, 24, 8); + $headerfooterinfo['tag_version'] = $headerfooterinfo_raw['version'] / 1000; + if ($headerfooterinfo['tag_version'] >= 2) { + $headerfooterinfo['flags'] = $this->parseAPEtagFlags($headerfooterinfo_raw['global_flags']); + } - $headerfooterinfo['tag_version'] = $headerfooterinfo_raw['version'] / 1000; - if ($headerfooterinfo['tag_version'] >= 2) { - $headerfooterinfo['flags'] = $this->parseAPEtagFlags($headerfooterinfo_raw['global_flags']); - } - return $headerfooterinfo; - } + return $headerfooterinfo; + } - public function parseAPEtagFlags($rawflagint) { - // "Note: APE Tags 1.0 do not use any of the APE Tag flags. - // All are set to zero on creation and ignored on reading." - // http://wiki.hydrogenaud.io/index.php?title=Ape_Tags_Flags - $flags['header'] = (bool) ($rawflagint & 0x80000000); - $flags['footer'] = (bool) ($rawflagint & 0x40000000); - $flags['this_is_header'] = (bool) ($rawflagint & 0x20000000); - $flags['item_contents_raw'] = ($rawflagint & 0x00000006) >> 1; - $flags['read_only'] = (bool) ($rawflagint & 0x00000001); + public function parseAPEtagFlags($rawflagint) + { + // "Note: APE Tags 1.0 do not use any of the APE Tag flags. + // All are set to zero on creation and ignored on reading." + // http://wiki.hydrogenaud.io/index.php?title=Ape_Tags_Flags + $flags['header'] = (bool) ($rawflagint & 0x80000000); + $flags['footer'] = (bool) ($rawflagint & 0x40000000); + $flags['this_is_header'] = (bool) ($rawflagint & 0x20000000); + $flags['item_contents_raw'] = ($rawflagint & 0x00000006) >> 1; + $flags['read_only'] = (bool) ($rawflagint & 0x00000001); - $flags['item_contents'] = $this->APEcontentTypeFlagLookup($flags['item_contents_raw']); + $flags['item_contents'] = $this->APEcontentTypeFlagLookup($flags['item_contents_raw']); - return $flags; - } + return $flags; + } - public function APEcontentTypeFlagLookup($contenttypeid) { - static $APEcontentTypeFlagLookup = array( - 0 => 'utf-8', - 1 => 'binary', - 2 => 'external', - 3 => 'reserved' - ); - return (isset($APEcontentTypeFlagLookup[$contenttypeid]) ? $APEcontentTypeFlagLookup[$contenttypeid] : 'invalid'); - } + public function APEcontentTypeFlagLookup($contenttypeid) + { + static $APEcontentTypeFlagLookup = [ + 0 => 'utf-8', + 1 => 'binary', + 2 => 'external', + 3 => 'reserved', + ]; - public function APEtagItemIsUTF8Lookup($itemkey) { - static $APEtagItemIsUTF8Lookup = array( - 'title', - 'subtitle', - 'artist', - 'album', - 'debut album', - 'publisher', - 'conductor', - 'track', - 'composer', - 'comment', - 'copyright', - 'publicationright', - 'file', - 'year', - 'record date', - 'record location', - 'genre', - 'media', - 'related', - 'isrc', - 'abstract', - 'language', - 'bibliography' - ); - return in_array(strtolower($itemkey), $APEtagItemIsUTF8Lookup); - } + return isset($APEcontentTypeFlagLookup[$contenttypeid]) ? $APEcontentTypeFlagLookup[$contenttypeid] : 'invalid'; + } + public function APEtagItemIsUTF8Lookup($itemkey) + { + static $APEtagItemIsUTF8Lookup = [ + 'title', + 'subtitle', + 'artist', + 'album', + 'debut album', + 'publisher', + 'conductor', + 'track', + 'composer', + 'comment', + 'copyright', + 'publicationright', + 'file', + 'year', + 'record date', + 'record location', + 'genre', + 'media', + 'related', + 'isrc', + 'abstract', + 'language', + 'bibliography', + ]; + + return in_array(strtolower($itemkey), $APEtagItemIsUTF8Lookup); + } } diff --git a/app/Library/getid3/getid3/module.tag.id3v1.php b/app/Library/getid3/getid3/module.tag.id3v1.php index d160e9b4..72fae138 100644 --- a/app/Library/getid3/getid3/module.tag.id3v1.php +++ b/app/Library/getid3/getid3/module.tag.id3v1.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,368 +15,375 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_id3v1 extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + if (! getid3_lib::intValueSupported($info['filesize'])) { + $this->warning('Unable to check for ID3v1 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'); - if (!getid3_lib::intValueSupported($info['filesize'])) { - $this->warning('Unable to check for ID3v1 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'); - return false; - } + return false; + } - $this->fseek(-256, SEEK_END); - $preid3v1 = $this->fread(128); - $id3v1tag = $this->fread(128); + $this->fseek(-256, SEEK_END); + $preid3v1 = $this->fread(128); + $id3v1tag = $this->fread(128); - if (substr($id3v1tag, 0, 3) == 'TAG') { + if (substr($id3v1tag, 0, 3) == 'TAG') { + $info['avdataend'] = $info['filesize'] - 128; - $info['avdataend'] = $info['filesize'] - 128; + $ParsedID3v1['title'] = $this->cutfield(substr($id3v1tag, 3, 30)); + $ParsedID3v1['artist'] = $this->cutfield(substr($id3v1tag, 33, 30)); + $ParsedID3v1['album'] = $this->cutfield(substr($id3v1tag, 63, 30)); + $ParsedID3v1['year'] = $this->cutfield(substr($id3v1tag, 93, 4)); + $ParsedID3v1['comment'] = substr($id3v1tag, 97, 30); // can't remove nulls yet, track detection depends on them + $ParsedID3v1['genreid'] = ord(substr($id3v1tag, 127, 1)); - $ParsedID3v1['title'] = $this->cutfield(substr($id3v1tag, 3, 30)); - $ParsedID3v1['artist'] = $this->cutfield(substr($id3v1tag, 33, 30)); - $ParsedID3v1['album'] = $this->cutfield(substr($id3v1tag, 63, 30)); - $ParsedID3v1['year'] = $this->cutfield(substr($id3v1tag, 93, 4)); - $ParsedID3v1['comment'] = substr($id3v1tag, 97, 30); // can't remove nulls yet, track detection depends on them - $ParsedID3v1['genreid'] = ord(substr($id3v1tag, 127, 1)); + // If second-last byte of comment field is null and last byte of comment field is non-null + // then this is ID3v1.1 and the comment field is 28 bytes long and the 30th byte is the track number + if (($id3v1tag[125] === "\x00") && ($id3v1tag[126] !== "\x00")) { + $ParsedID3v1['track'] = ord(substr($ParsedID3v1['comment'], 29, 1)); + $ParsedID3v1['comment'] = substr($ParsedID3v1['comment'], 0, 28); + } + $ParsedID3v1['comment'] = $this->cutfield($ParsedID3v1['comment']); - // If second-last byte of comment field is null and last byte of comment field is non-null - // then this is ID3v1.1 and the comment field is 28 bytes long and the 30th byte is the track number - if (($id3v1tag{125} === "\x00") && ($id3v1tag{126} !== "\x00")) { - $ParsedID3v1['track'] = ord(substr($ParsedID3v1['comment'], 29, 1)); - $ParsedID3v1['comment'] = substr($ParsedID3v1['comment'], 0, 28); - } - $ParsedID3v1['comment'] = $this->cutfield($ParsedID3v1['comment']); + $ParsedID3v1['genre'] = $this->LookupGenreName($ParsedID3v1['genreid']); + if (! empty($ParsedID3v1['genre'])) { + unset($ParsedID3v1['genreid']); + } + if (isset($ParsedID3v1['genre']) && (empty($ParsedID3v1['genre']) || ($ParsedID3v1['genre'] == 'Unknown'))) { + unset($ParsedID3v1['genre']); + } - $ParsedID3v1['genre'] = $this->LookupGenreName($ParsedID3v1['genreid']); - if (!empty($ParsedID3v1['genre'])) { - unset($ParsedID3v1['genreid']); - } - if (isset($ParsedID3v1['genre']) && (empty($ParsedID3v1['genre']) || ($ParsedID3v1['genre'] == 'Unknown'))) { - unset($ParsedID3v1['genre']); - } + foreach ($ParsedID3v1 as $key => $value) { + $ParsedID3v1['comments'][$key][0] = $value; + } + // ID3v1 encoding detection hack START + // ID3v1 is defined as always using ISO-8859-1 encoding, but it is not uncommon to find files tagged with ID3v1 using Windows-1251 or other character sets + // Since ID3v1 has no concept of character sets there is no certain way to know we have the correct non-ISO-8859-1 character set, but we can guess + $ID3v1encoding = 'ISO-8859-1'; + foreach ($ParsedID3v1['comments'] as $tag_key => $valuearray) { + foreach ($valuearray as $key => $value) { + if (preg_match('#^[\\x00-\\x40\\xA8\\B8\\x80-\\xFF]+$#', $value)) { + foreach (['Windows-1251', 'KOI8-R'] as $id3v1_bad_encoding) { + if (function_exists('mb_convert_encoding') && @mb_convert_encoding($value, $id3v1_bad_encoding, $id3v1_bad_encoding) === $value) { + $ID3v1encoding = $id3v1_bad_encoding; + break 3; + } elseif (function_exists('iconv') && @iconv($id3v1_bad_encoding, $id3v1_bad_encoding, $value) === $value) { + $ID3v1encoding = $id3v1_bad_encoding; + break 3; + } + } + } + } + } + // ID3v1 encoding detection hack END - foreach ($ParsedID3v1 as $key => $value) { - $ParsedID3v1['comments'][$key][0] = $value; - } - // ID3v1 encoding detection hack START - // ID3v1 is defined as always using ISO-8859-1 encoding, but it is not uncommon to find files tagged with ID3v1 using Windows-1251 or other character sets - // Since ID3v1 has no concept of character sets there is no certain way to know we have the correct non-ISO-8859-1 character set, but we can guess - $ID3v1encoding = 'ISO-8859-1'; - foreach ($ParsedID3v1['comments'] as $tag_key => $valuearray) { - foreach ($valuearray as $key => $value) { - if (preg_match('#^[\\x00-\\x40\\xA8\\B8\\x80-\\xFF]+$#', $value)) { - foreach (array('Windows-1251', 'KOI8-R') as $id3v1_bad_encoding) { - if (function_exists('mb_convert_encoding') && @mb_convert_encoding($value, $id3v1_bad_encoding, $id3v1_bad_encoding) === $value) { - $ID3v1encoding = $id3v1_bad_encoding; - break 3; - } elseif (function_exists('iconv') && @iconv($id3v1_bad_encoding, $id3v1_bad_encoding, $value) === $value) { - $ID3v1encoding = $id3v1_bad_encoding; - break 3; - } - } - } - } - } - // ID3v1 encoding detection hack END + // ID3v1 data is supposed to be padded with NULL characters, but some taggers pad with spaces + $GoodFormatID3v1tag = $this->GenerateID3v1Tag( + $ParsedID3v1['title'], + $ParsedID3v1['artist'], + $ParsedID3v1['album'], + $ParsedID3v1['year'], + (isset($ParsedID3v1['genre']) ? $this->LookupGenreID($ParsedID3v1['genre']) : false), + $ParsedID3v1['comment'], + (! empty($ParsedID3v1['track']) ? $ParsedID3v1['track'] : '')); + $ParsedID3v1['padding_valid'] = true; + if ($id3v1tag !== $GoodFormatID3v1tag) { + $ParsedID3v1['padding_valid'] = false; + $this->warning('Some ID3v1 fields do not use NULL characters for padding'); + } - // ID3v1 data is supposed to be padded with NULL characters, but some taggers pad with spaces - $GoodFormatID3v1tag = $this->GenerateID3v1Tag( - $ParsedID3v1['title'], - $ParsedID3v1['artist'], - $ParsedID3v1['album'], - $ParsedID3v1['year'], - (isset($ParsedID3v1['genre']) ? $this->LookupGenreID($ParsedID3v1['genre']) : false), - $ParsedID3v1['comment'], - (!empty($ParsedID3v1['track']) ? $ParsedID3v1['track'] : '')); - $ParsedID3v1['padding_valid'] = true; - if ($id3v1tag !== $GoodFormatID3v1tag) { - $ParsedID3v1['padding_valid'] = false; - $this->warning('Some ID3v1 fields do not use NULL characters for padding'); - } + $ParsedID3v1['tag_offset_end'] = $info['filesize']; + $ParsedID3v1['tag_offset_start'] = $ParsedID3v1['tag_offset_end'] - 128; - $ParsedID3v1['tag_offset_end'] = $info['filesize']; - $ParsedID3v1['tag_offset_start'] = $ParsedID3v1['tag_offset_end'] - 128; + $info['id3v1'] = $ParsedID3v1; + $info['id3v1']['encoding'] = $ID3v1encoding; + } - $info['id3v1'] = $ParsedID3v1; - $info['id3v1']['encoding'] = $ID3v1encoding; - } + if (substr($preid3v1, 0, 3) == 'TAG') { + // The way iTunes handles tags is, well, brain-damaged. + // It completely ignores v1 if ID3v2 is present. + // This goes as far as adding a new v1 tag *even if there already is one* - if (substr($preid3v1, 0, 3) == 'TAG') { - // The way iTunes handles tags is, well, brain-damaged. - // It completely ignores v1 if ID3v2 is present. - // This goes as far as adding a new v1 tag *even if there already is one* + // A suspected double-ID3v1 tag has been detected, but it could be that + // the "TAG" identifier is a legitimate part of an APE or Lyrics3 tag + if (substr($preid3v1, 96, 8) == 'APETAGEX') { + // an APE tag footer was found before the last ID3v1, assume false "TAG" synch + } elseif (substr($preid3v1, 119, 6) == 'LYRICS') { + // a Lyrics3 tag footer was found before the last ID3v1, assume false "TAG" synch + } else { + // APE and Lyrics3 footers not found - assume double ID3v1 + $this->warning('Duplicate ID3v1 tag detected - this has been known to happen with iTunes'); + $info['avdataend'] -= 128; + } + } - // A suspected double-ID3v1 tag has been detected, but it could be that - // the "TAG" identifier is a legitimate part of an APE or Lyrics3 tag - if (substr($preid3v1, 96, 8) == 'APETAGEX') { - // an APE tag footer was found before the last ID3v1, assume false "TAG" synch - } elseif (substr($preid3v1, 119, 6) == 'LYRICS') { - // a Lyrics3 tag footer was found before the last ID3v1, assume false "TAG" synch - } else { - // APE and Lyrics3 footers not found - assume double ID3v1 - $this->warning('Duplicate ID3v1 tag detected - this has been known to happen with iTunes'); - $info['avdataend'] -= 128; - } - } + return true; + } - return true; - } + public static function cutfield($str) + { + return trim(substr($str, 0, strcspn($str, "\x00"))); + } - public static function cutfield($str) { - return trim(substr($str, 0, strcspn($str, "\x00"))); - } + public static function ArrayOfGenres($allowSCMPXextended = false) + { + static $GenreLookup = [ + 0 => 'Blues', + 1 => 'Classic Rock', + 2 => 'Country', + 3 => 'Dance', + 4 => 'Disco', + 5 => 'Funk', + 6 => 'Grunge', + 7 => 'Hip-Hop', + 8 => 'Jazz', + 9 => 'Metal', + 10 => 'New Age', + 11 => 'Oldies', + 12 => 'Other', + 13 => 'Pop', + 14 => 'R&B', + 15 => 'Rap', + 16 => 'Reggae', + 17 => 'Rock', + 18 => 'Techno', + 19 => 'Industrial', + 20 => 'Alternative', + 21 => 'Ska', + 22 => 'Death Metal', + 23 => 'Pranks', + 24 => 'Soundtrack', + 25 => 'Euro-Techno', + 26 => 'Ambient', + 27 => 'Trip-Hop', + 28 => 'Vocal', + 29 => 'Jazz+Funk', + 30 => 'Fusion', + 31 => 'Trance', + 32 => 'Classical', + 33 => 'Instrumental', + 34 => 'Acid', + 35 => 'House', + 36 => 'Game', + 37 => 'Sound Clip', + 38 => 'Gospel', + 39 => 'Noise', + 40 => 'Alt. Rock', + 41 => 'Bass', + 42 => 'Soul', + 43 => 'Punk', + 44 => 'Space', + 45 => 'Meditative', + 46 => 'Instrumental Pop', + 47 => 'Instrumental Rock', + 48 => 'Ethnic', + 49 => 'Gothic', + 50 => 'Darkwave', + 51 => 'Techno-Industrial', + 52 => 'Electronic', + 53 => 'Pop-Folk', + 54 => 'Eurodance', + 55 => 'Dream', + 56 => 'Southern Rock', + 57 => 'Comedy', + 58 => 'Cult', + 59 => 'Gangsta Rap', + 60 => 'Top 40', + 61 => 'Christian Rap', + 62 => 'Pop/Funk', + 63 => 'Jungle', + 64 => 'Native American', + 65 => 'Cabaret', + 66 => 'New Wave', + 67 => 'Psychedelic', + 68 => 'Rave', + 69 => 'Showtunes', + 70 => 'Trailer', + 71 => 'Lo-Fi', + 72 => 'Tribal', + 73 => 'Acid Punk', + 74 => 'Acid Jazz', + 75 => 'Polka', + 76 => 'Retro', + 77 => 'Musical', + 78 => 'Rock & Roll', + 79 => 'Hard Rock', + 80 => 'Folk', + 81 => 'Folk/Rock', + 82 => 'National Folk', + 83 => 'Swing', + 84 => 'Fast-Fusion', + 85 => 'Bebob', + 86 => 'Latin', + 87 => 'Revival', + 88 => 'Celtic', + 89 => 'Bluegrass', + 90 => 'Avantgarde', + 91 => 'Gothic Rock', + 92 => 'Progressive Rock', + 93 => 'Psychedelic Rock', + 94 => 'Symphonic Rock', + 95 => 'Slow Rock', + 96 => 'Big Band', + 97 => 'Chorus', + 98 => 'Easy Listening', + 99 => 'Acoustic', + 100 => 'Humour', + 101 => 'Speech', + 102 => 'Chanson', + 103 => 'Opera', + 104 => 'Chamber Music', + 105 => 'Sonata', + 106 => 'Symphony', + 107 => 'Booty Bass', + 108 => 'Primus', + 109 => 'Porn Groove', + 110 => 'Satire', + 111 => 'Slow Jam', + 112 => 'Club', + 113 => 'Tango', + 114 => 'Samba', + 115 => 'Folklore', + 116 => 'Ballad', + 117 => 'Power Ballad', + 118 => 'Rhythmic Soul', + 119 => 'Freestyle', + 120 => 'Duet', + 121 => 'Punk Rock', + 122 => 'Drum Solo', + 123 => 'A Cappella', + 124 => 'Euro-House', + 125 => 'Dance Hall', + 126 => 'Goa', + 127 => 'Drum & Bass', + 128 => 'Club-House', + 129 => 'Hardcore', + 130 => 'Terror', + 131 => 'Indie', + 132 => 'BritPop', + 133 => 'Negerpunk', + 134 => 'Polsk Punk', + 135 => 'Beat', + 136 => 'Christian Gangsta Rap', + 137 => 'Heavy Metal', + 138 => 'Black Metal', + 139 => 'Crossover', + 140 => 'Contemporary Christian', + 141 => 'Christian Rock', + 142 => 'Merengue', + 143 => 'Salsa', + 144 => 'Thrash Metal', + 145 => 'Anime', + 146 => 'JPop', + 147 => 'Synthpop', - public static function ArrayOfGenres($allowSCMPXextended=false) { - static $GenreLookup = array( - 0 => 'Blues', - 1 => 'Classic Rock', - 2 => 'Country', - 3 => 'Dance', - 4 => 'Disco', - 5 => 'Funk', - 6 => 'Grunge', - 7 => 'Hip-Hop', - 8 => 'Jazz', - 9 => 'Metal', - 10 => 'New Age', - 11 => 'Oldies', - 12 => 'Other', - 13 => 'Pop', - 14 => 'R&B', - 15 => 'Rap', - 16 => 'Reggae', - 17 => 'Rock', - 18 => 'Techno', - 19 => 'Industrial', - 20 => 'Alternative', - 21 => 'Ska', - 22 => 'Death Metal', - 23 => 'Pranks', - 24 => 'Soundtrack', - 25 => 'Euro-Techno', - 26 => 'Ambient', - 27 => 'Trip-Hop', - 28 => 'Vocal', - 29 => 'Jazz+Funk', - 30 => 'Fusion', - 31 => 'Trance', - 32 => 'Classical', - 33 => 'Instrumental', - 34 => 'Acid', - 35 => 'House', - 36 => 'Game', - 37 => 'Sound Clip', - 38 => 'Gospel', - 39 => 'Noise', - 40 => 'Alt. Rock', - 41 => 'Bass', - 42 => 'Soul', - 43 => 'Punk', - 44 => 'Space', - 45 => 'Meditative', - 46 => 'Instrumental Pop', - 47 => 'Instrumental Rock', - 48 => 'Ethnic', - 49 => 'Gothic', - 50 => 'Darkwave', - 51 => 'Techno-Industrial', - 52 => 'Electronic', - 53 => 'Pop-Folk', - 54 => 'Eurodance', - 55 => 'Dream', - 56 => 'Southern Rock', - 57 => 'Comedy', - 58 => 'Cult', - 59 => 'Gangsta Rap', - 60 => 'Top 40', - 61 => 'Christian Rap', - 62 => 'Pop/Funk', - 63 => 'Jungle', - 64 => 'Native American', - 65 => 'Cabaret', - 66 => 'New Wave', - 67 => 'Psychedelic', - 68 => 'Rave', - 69 => 'Showtunes', - 70 => 'Trailer', - 71 => 'Lo-Fi', - 72 => 'Tribal', - 73 => 'Acid Punk', - 74 => 'Acid Jazz', - 75 => 'Polka', - 76 => 'Retro', - 77 => 'Musical', - 78 => 'Rock & Roll', - 79 => 'Hard Rock', - 80 => 'Folk', - 81 => 'Folk/Rock', - 82 => 'National Folk', - 83 => 'Swing', - 84 => 'Fast-Fusion', - 85 => 'Bebob', - 86 => 'Latin', - 87 => 'Revival', - 88 => 'Celtic', - 89 => 'Bluegrass', - 90 => 'Avantgarde', - 91 => 'Gothic Rock', - 92 => 'Progressive Rock', - 93 => 'Psychedelic Rock', - 94 => 'Symphonic Rock', - 95 => 'Slow Rock', - 96 => 'Big Band', - 97 => 'Chorus', - 98 => 'Easy Listening', - 99 => 'Acoustic', - 100 => 'Humour', - 101 => 'Speech', - 102 => 'Chanson', - 103 => 'Opera', - 104 => 'Chamber Music', - 105 => 'Sonata', - 106 => 'Symphony', - 107 => 'Booty Bass', - 108 => 'Primus', - 109 => 'Porn Groove', - 110 => 'Satire', - 111 => 'Slow Jam', - 112 => 'Club', - 113 => 'Tango', - 114 => 'Samba', - 115 => 'Folklore', - 116 => 'Ballad', - 117 => 'Power Ballad', - 118 => 'Rhythmic Soul', - 119 => 'Freestyle', - 120 => 'Duet', - 121 => 'Punk Rock', - 122 => 'Drum Solo', - 123 => 'A Cappella', - 124 => 'Euro-House', - 125 => 'Dance Hall', - 126 => 'Goa', - 127 => 'Drum & Bass', - 128 => 'Club-House', - 129 => 'Hardcore', - 130 => 'Terror', - 131 => 'Indie', - 132 => 'BritPop', - 133 => 'Negerpunk', - 134 => 'Polsk Punk', - 135 => 'Beat', - 136 => 'Christian Gangsta Rap', - 137 => 'Heavy Metal', - 138 => 'Black Metal', - 139 => 'Crossover', - 140 => 'Contemporary Christian', - 141 => 'Christian Rock', - 142 => 'Merengue', - 143 => 'Salsa', - 144 => 'Thrash Metal', - 145 => 'Anime', - 146 => 'JPop', - 147 => 'Synthpop', + 255 => 'Unknown', - 255 => 'Unknown', + 'CR' => 'Cover', + 'RX' => 'Remix', + ]; - 'CR' => 'Cover', - 'RX' => 'Remix' - ); + static $GenreLookupSCMPX = []; + if ($allowSCMPXextended && empty($GenreLookupSCMPX)) { + $GenreLookupSCMPX = $GenreLookup; + // http://www.geocities.co.jp/SiliconValley-Oakland/3664/alittle.html#GenreExtended + // Extended ID3v1 genres invented by SCMPX + // Note that 255 "Japanese Anime" conflicts with standard "Unknown" + $GenreLookupSCMPX[240] = 'Sacred'; + $GenreLookupSCMPX[241] = 'Northern Europe'; + $GenreLookupSCMPX[242] = 'Irish & Scottish'; + $GenreLookupSCMPX[243] = 'Scotland'; + $GenreLookupSCMPX[244] = 'Ethnic Europe'; + $GenreLookupSCMPX[245] = 'Enka'; + $GenreLookupSCMPX[246] = 'Children\'s Song'; + $GenreLookupSCMPX[247] = 'Japanese Sky'; + $GenreLookupSCMPX[248] = 'Japanese Heavy Rock'; + $GenreLookupSCMPX[249] = 'Japanese Doom Rock'; + $GenreLookupSCMPX[250] = 'Japanese J-POP'; + $GenreLookupSCMPX[251] = 'Japanese Seiyu'; + $GenreLookupSCMPX[252] = 'Japanese Ambient Techno'; + $GenreLookupSCMPX[253] = 'Japanese Moemoe'; + $GenreLookupSCMPX[254] = 'Japanese Tokusatsu'; + //$GenreLookupSCMPX[255] = 'Japanese Anime'; + } - static $GenreLookupSCMPX = array(); - if ($allowSCMPXextended && empty($GenreLookupSCMPX)) { - $GenreLookupSCMPX = $GenreLookup; - // http://www.geocities.co.jp/SiliconValley-Oakland/3664/alittle.html#GenreExtended - // Extended ID3v1 genres invented by SCMPX - // Note that 255 "Japanese Anime" conflicts with standard "Unknown" - $GenreLookupSCMPX[240] = 'Sacred'; - $GenreLookupSCMPX[241] = 'Northern Europe'; - $GenreLookupSCMPX[242] = 'Irish & Scottish'; - $GenreLookupSCMPX[243] = 'Scotland'; - $GenreLookupSCMPX[244] = 'Ethnic Europe'; - $GenreLookupSCMPX[245] = 'Enka'; - $GenreLookupSCMPX[246] = 'Children\'s Song'; - $GenreLookupSCMPX[247] = 'Japanese Sky'; - $GenreLookupSCMPX[248] = 'Japanese Heavy Rock'; - $GenreLookupSCMPX[249] = 'Japanese Doom Rock'; - $GenreLookupSCMPX[250] = 'Japanese J-POP'; - $GenreLookupSCMPX[251] = 'Japanese Seiyu'; - $GenreLookupSCMPX[252] = 'Japanese Ambient Techno'; - $GenreLookupSCMPX[253] = 'Japanese Moemoe'; - $GenreLookupSCMPX[254] = 'Japanese Tokusatsu'; - //$GenreLookupSCMPX[255] = 'Japanese Anime'; - } + return $allowSCMPXextended ? $GenreLookupSCMPX : $GenreLookup; + } - return ($allowSCMPXextended ? $GenreLookupSCMPX : $GenreLookup); - } + public static function LookupGenreName($genreid, $allowSCMPXextended = true) + { + switch ($genreid) { + case 'RX': + case 'CR': + break; + default: + if (! is_numeric($genreid)) { + return false; + } + $genreid = intval($genreid); // to handle 3 or '3' or '03' + break; + } + $GenreLookup = self::ArrayOfGenres($allowSCMPXextended); - public static function LookupGenreName($genreid, $allowSCMPXextended=true) { - switch ($genreid) { - case 'RX': - case 'CR': - break; - default: - if (!is_numeric($genreid)) { - return false; - } - $genreid = intval($genreid); // to handle 3 or '3' or '03' - break; - } - $GenreLookup = self::ArrayOfGenres($allowSCMPXextended); - return (isset($GenreLookup[$genreid]) ? $GenreLookup[$genreid] : false); - } + return isset($GenreLookup[$genreid]) ? $GenreLookup[$genreid] : false; + } - public static function LookupGenreID($genre, $allowSCMPXextended=false) { - $GenreLookup = self::ArrayOfGenres($allowSCMPXextended); - $LowerCaseNoSpaceSearchTerm = strtolower(str_replace(' ', '', $genre)); - foreach ($GenreLookup as $key => $value) { - if (strtolower(str_replace(' ', '', $value)) == $LowerCaseNoSpaceSearchTerm) { - return $key; - } - } - return false; - } + public static function LookupGenreID($genre, $allowSCMPXextended = false) + { + $GenreLookup = self::ArrayOfGenres($allowSCMPXextended); + $LowerCaseNoSpaceSearchTerm = strtolower(str_replace(' ', '', $genre)); + foreach ($GenreLookup as $key => $value) { + if (strtolower(str_replace(' ', '', $value)) == $LowerCaseNoSpaceSearchTerm) { + return $key; + } + } - public static function StandardiseID3v1GenreName($OriginalGenre) { - if (($GenreID = self::LookupGenreID($OriginalGenre)) !== false) { - return self::LookupGenreName($GenreID); - } - return $OriginalGenre; - } + return false; + } - public static function GenerateID3v1Tag($title, $artist, $album, $year, $genreid, $comment, $track='') { - $ID3v1Tag = 'TAG'; - $ID3v1Tag .= str_pad(trim(substr($title, 0, 30)), 30, "\x00", STR_PAD_RIGHT); - $ID3v1Tag .= str_pad(trim(substr($artist, 0, 30)), 30, "\x00", STR_PAD_RIGHT); - $ID3v1Tag .= str_pad(trim(substr($album, 0, 30)), 30, "\x00", STR_PAD_RIGHT); - $ID3v1Tag .= str_pad(trim(substr($year, 0, 4)), 4, "\x00", STR_PAD_LEFT); - if (!empty($track) && ($track > 0) && ($track <= 255)) { - $ID3v1Tag .= str_pad(trim(substr($comment, 0, 28)), 28, "\x00", STR_PAD_RIGHT); - $ID3v1Tag .= "\x00"; - if (gettype($track) == 'string') { - $track = (int) $track; - } - $ID3v1Tag .= chr($track); - } else { - $ID3v1Tag .= str_pad(trim(substr($comment, 0, 30)), 30, "\x00", STR_PAD_RIGHT); - } - if (($genreid < 0) || ($genreid > 147)) { - $genreid = 255; // 'unknown' genre - } - switch (gettype($genreid)) { - case 'string': - case 'integer': - $ID3v1Tag .= chr(intval($genreid)); - break; - default: - $ID3v1Tag .= chr(255); // 'unknown' genre - break; - } + public static function StandardiseID3v1GenreName($OriginalGenre) + { + if (($GenreID = self::LookupGenreID($OriginalGenre)) !== false) { + return self::LookupGenreName($GenreID); + } - return $ID3v1Tag; - } + return $OriginalGenre; + } + public static function GenerateID3v1Tag($title, $artist, $album, $year, $genreid, $comment, $track = '') + { + $ID3v1Tag = 'TAG'; + $ID3v1Tag .= str_pad(trim(substr($title, 0, 30)), 30, "\x00", STR_PAD_RIGHT); + $ID3v1Tag .= str_pad(trim(substr($artist, 0, 30)), 30, "\x00", STR_PAD_RIGHT); + $ID3v1Tag .= str_pad(trim(substr($album, 0, 30)), 30, "\x00", STR_PAD_RIGHT); + $ID3v1Tag .= str_pad(trim(substr($year, 0, 4)), 4, "\x00", STR_PAD_LEFT); + if (! empty($track) && ($track > 0) && ($track <= 255)) { + $ID3v1Tag .= str_pad(trim(substr($comment, 0, 28)), 28, "\x00", STR_PAD_RIGHT); + $ID3v1Tag .= "\x00"; + if (gettype($track) == 'string') { + $track = (int) $track; + } + $ID3v1Tag .= chr($track); + } else { + $ID3v1Tag .= str_pad(trim(substr($comment, 0, 30)), 30, "\x00", STR_PAD_RIGHT); + } + if (($genreid < 0) || ($genreid > 147)) { + $genreid = 255; // 'unknown' genre + } + switch (gettype($genreid)) { + case 'string': + case 'integer': + $ID3v1Tag .= chr(intval($genreid)); + break; + default: + $ID3v1Tag .= chr(255); // 'unknown' genre + break; + } + + return $ID3v1Tag; + } } diff --git a/app/Library/getid3/getid3/module.tag.id3v2.php b/app/Library/getid3/getid3/module.tag.id3v2.php index 829f5ee2..7abea603 100644 --- a/app/Library/getid3/getid3/module.tag.id3v2.php +++ b/app/Library/getid3/getid3/module.tag.id3v2.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -18,3725 +19,3628 @@ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE_ class getid3_id3v2 extends getid3_handler { - public $StartingOffset = 0; - - public function Analyze() { - $info = &$this->getid3->info; - - // Overall tag structure: - // +-----------------------------+ - // | Header (10 bytes) | - // +-----------------------------+ - // | Extended Header | - // | (variable length, OPTIONAL) | - // +-----------------------------+ - // | Frames (variable length) | - // +-----------------------------+ - // | Padding | - // | (variable length, OPTIONAL) | - // +-----------------------------+ - // | Footer (10 bytes, OPTIONAL) | - // +-----------------------------+ - - // Header - // ID3v2/file identifier "ID3" - // ID3v2 version $04 00 - // ID3v2 flags (%ab000000 in v2.2, %abc00000 in v2.3, %abcd0000 in v2.4.x) - // ID3v2 size 4 * %0xxxxxxx - - - // shortcuts - $info['id3v2']['header'] = true; - $thisfile_id3v2 = &$info['id3v2']; - $thisfile_id3v2['flags'] = array(); - $thisfile_id3v2_flags = &$thisfile_id3v2['flags']; - - - $this->fseek($this->StartingOffset); - $header = $this->fread(10); - if (substr($header, 0, 3) == 'ID3' && strlen($header) == 10) { - - $thisfile_id3v2['majorversion'] = ord($header{3}); - $thisfile_id3v2['minorversion'] = ord($header{4}); - - // shortcut - $id3v2_majorversion = &$thisfile_id3v2['majorversion']; - - } else { - - unset($info['id3v2']); - return false; - - } - - if ($id3v2_majorversion > 4) { // this script probably won't correctly parse ID3v2.5.x and above (if it ever exists) - - $this->error('this script only parses up to ID3v2.4.x - this tag is ID3v2.'.$id3v2_majorversion.'.'.$thisfile_id3v2['minorversion']); - return false; - - } - - $id3_flags = ord($header{5}); - switch ($id3v2_majorversion) { - case 2: - // %ab000000 in v2.2 - $thisfile_id3v2_flags['unsynch'] = (bool) ($id3_flags & 0x80); // a - Unsynchronisation - $thisfile_id3v2_flags['compression'] = (bool) ($id3_flags & 0x40); // b - Compression - break; - - case 3: - // %abc00000 in v2.3 - $thisfile_id3v2_flags['unsynch'] = (bool) ($id3_flags & 0x80); // a - Unsynchronisation - $thisfile_id3v2_flags['exthead'] = (bool) ($id3_flags & 0x40); // b - Extended header - $thisfile_id3v2_flags['experim'] = (bool) ($id3_flags & 0x20); // c - Experimental indicator - break; - - case 4: - // %abcd0000 in v2.4 - $thisfile_id3v2_flags['unsynch'] = (bool) ($id3_flags & 0x80); // a - Unsynchronisation - $thisfile_id3v2_flags['exthead'] = (bool) ($id3_flags & 0x40); // b - Extended header - $thisfile_id3v2_flags['experim'] = (bool) ($id3_flags & 0x20); // c - Experimental indicator - $thisfile_id3v2_flags['isfooter'] = (bool) ($id3_flags & 0x10); // d - Footer present - break; - } - - $thisfile_id3v2['headerlength'] = getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length - - $thisfile_id3v2['tag_offset_start'] = $this->StartingOffset; - $thisfile_id3v2['tag_offset_end'] = $thisfile_id3v2['tag_offset_start'] + $thisfile_id3v2['headerlength']; - - - - // create 'encoding' key - used by getid3::HandleAllTags() - // in ID3v2 every field can have it's own encoding type - // so force everything to UTF-8 so it can be handled consistantly - $thisfile_id3v2['encoding'] = 'UTF-8'; - - - // Frames - - // All ID3v2 frames consists of one frame header followed by one or more - // fields containing the actual information. The header is always 10 - // bytes and laid out as follows: - // - // Frame ID $xx xx xx xx (four characters) - // Size 4 * %0xxxxxxx - // Flags $xx xx - - $sizeofframes = $thisfile_id3v2['headerlength'] - 10; // not including 10-byte initial header - if (!empty($thisfile_id3v2['exthead']['length'])) { - $sizeofframes -= ($thisfile_id3v2['exthead']['length'] + 4); - } - if (!empty($thisfile_id3v2_flags['isfooter'])) { - $sizeofframes -= 10; // footer takes last 10 bytes of ID3v2 header, after frame data, before audio - } - if ($sizeofframes > 0) { - - $framedata = $this->fread($sizeofframes); // read all frames from file into $framedata variable - - // if entire frame data is unsynched, de-unsynch it now (ID3v2.3.x) - if (!empty($thisfile_id3v2_flags['unsynch']) && ($id3v2_majorversion <= 3)) { - $framedata = $this->DeUnsynchronise($framedata); - } - // [in ID3v2.4.0] Unsynchronisation [S:6.1] is done on frame level, instead - // of on tag level, making it easier to skip frames, increasing the streamability - // of the tag. The unsynchronisation flag in the header [S:3.1] indicates that - // there exists an unsynchronised frame, while the new unsynchronisation flag in - // the frame header [S:4.1.2] indicates unsynchronisation. - - - //$framedataoffset = 10 + ($thisfile_id3v2['exthead']['length'] ? $thisfile_id3v2['exthead']['length'] + 4 : 0); // how many bytes into the stream - start from after the 10-byte header (and extended header length+4, if present) - $framedataoffset = 10; // how many bytes into the stream - start from after the 10-byte header - - - // Extended Header - if (!empty($thisfile_id3v2_flags['exthead'])) { - $extended_header_offset = 0; - - if ($id3v2_majorversion == 3) { - - // v2.3 definition: - //Extended header size $xx xx xx xx // 32-bit integer - //Extended Flags $xx xx - // %x0000000 %00000000 // v2.3 - // x - CRC data present - //Size of padding $xx xx xx xx - - $thisfile_id3v2['exthead']['length'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4), 0); - $extended_header_offset += 4; - - $thisfile_id3v2['exthead']['flag_bytes'] = 2; - $thisfile_id3v2['exthead']['flag_raw'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, $thisfile_id3v2['exthead']['flag_bytes'])); - $extended_header_offset += $thisfile_id3v2['exthead']['flag_bytes']; - - $thisfile_id3v2['exthead']['flags']['crc'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x8000); - - $thisfile_id3v2['exthead']['padding_size'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4)); - $extended_header_offset += 4; - - if ($thisfile_id3v2['exthead']['flags']['crc']) { - $thisfile_id3v2['exthead']['flag_data']['crc'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4)); - $extended_header_offset += 4; - } - $extended_header_offset += $thisfile_id3v2['exthead']['padding_size']; - - } elseif ($id3v2_majorversion == 4) { - - // v2.4 definition: - //Extended header size 4 * %0xxxxxxx // 28-bit synchsafe integer - //Number of flag bytes $01 - //Extended Flags $xx - // %0bcd0000 // v2.4 - // b - Tag is an update - // Flag data length $00 - // c - CRC data present - // Flag data length $05 - // Total frame CRC 5 * %0xxxxxxx - // d - Tag restrictions - // Flag data length $01 - - $thisfile_id3v2['exthead']['length'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4), true); - $extended_header_offset += 4; - - $thisfile_id3v2['exthead']['flag_bytes'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should always be 1 - $extended_header_offset += 1; - - $thisfile_id3v2['exthead']['flag_raw'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, $thisfile_id3v2['exthead']['flag_bytes'])); - $extended_header_offset += $thisfile_id3v2['exthead']['flag_bytes']; - - $thisfile_id3v2['exthead']['flags']['update'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x40); - $thisfile_id3v2['exthead']['flags']['crc'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x20); - $thisfile_id3v2['exthead']['flags']['restrictions'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x10); - - if ($thisfile_id3v2['exthead']['flags']['update']) { - $ext_header_chunk_length = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should be 0 - $extended_header_offset += 1; - } - - if ($thisfile_id3v2['exthead']['flags']['crc']) { - $ext_header_chunk_length = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should be 5 - $extended_header_offset += 1; - $thisfile_id3v2['exthead']['flag_data']['crc'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, $ext_header_chunk_length), true, false); - $extended_header_offset += $ext_header_chunk_length; - } - - if ($thisfile_id3v2['exthead']['flags']['restrictions']) { - $ext_header_chunk_length = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should be 1 - $extended_header_offset += 1; - - // %ppqrrstt - $restrictions_raw = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); - $extended_header_offset += 1; - $thisfile_id3v2['exthead']['flags']['restrictions']['tagsize'] = ($restrictions_raw & 0xC0) >> 6; // p - Tag size restrictions - $thisfile_id3v2['exthead']['flags']['restrictions']['textenc'] = ($restrictions_raw & 0x20) >> 5; // q - Text encoding restrictions - $thisfile_id3v2['exthead']['flags']['restrictions']['textsize'] = ($restrictions_raw & 0x18) >> 3; // r - Text fields size restrictions - $thisfile_id3v2['exthead']['flags']['restrictions']['imgenc'] = ($restrictions_raw & 0x04) >> 2; // s - Image encoding restrictions - $thisfile_id3v2['exthead']['flags']['restrictions']['imgsize'] = ($restrictions_raw & 0x03) >> 0; // t - Image size restrictions - - $thisfile_id3v2['exthead']['flags']['restrictions_text']['tagsize'] = $this->LookupExtendedHeaderRestrictionsTagSizeLimits($thisfile_id3v2['exthead']['flags']['restrictions']['tagsize']); - $thisfile_id3v2['exthead']['flags']['restrictions_text']['textenc'] = $this->LookupExtendedHeaderRestrictionsTextEncodings($thisfile_id3v2['exthead']['flags']['restrictions']['textenc']); - $thisfile_id3v2['exthead']['flags']['restrictions_text']['textsize'] = $this->LookupExtendedHeaderRestrictionsTextFieldSize($thisfile_id3v2['exthead']['flags']['restrictions']['textsize']); - $thisfile_id3v2['exthead']['flags']['restrictions_text']['imgenc'] = $this->LookupExtendedHeaderRestrictionsImageEncoding($thisfile_id3v2['exthead']['flags']['restrictions']['imgenc']); - $thisfile_id3v2['exthead']['flags']['restrictions_text']['imgsize'] = $this->LookupExtendedHeaderRestrictionsImageSizeSize($thisfile_id3v2['exthead']['flags']['restrictions']['imgsize']); - } - - if ($thisfile_id3v2['exthead']['length'] != $extended_header_offset) { - $this->warning('ID3v2.4 extended header length mismatch (expecting '.intval($thisfile_id3v2['exthead']['length']).', found '.intval($extended_header_offset).')'); - } - } - - $framedataoffset += $extended_header_offset; - $framedata = substr($framedata, $extended_header_offset); - } // end extended header - - - while (isset($framedata) && (strlen($framedata) > 0)) { // cycle through until no more frame data is left to parse - if (strlen($framedata) <= $this->ID3v2HeaderLength($id3v2_majorversion)) { - // insufficient room left in ID3v2 header for actual data - must be padding - $thisfile_id3v2['padding']['start'] = $framedataoffset; - $thisfile_id3v2['padding']['length'] = strlen($framedata); - $thisfile_id3v2['padding']['valid'] = true; - for ($i = 0; $i < $thisfile_id3v2['padding']['length']; $i++) { - if ($framedata{$i} != "\x00") { - $thisfile_id3v2['padding']['valid'] = false; - $thisfile_id3v2['padding']['errorpos'] = $thisfile_id3v2['padding']['start'] + $i; - $this->warning('Invalid ID3v2 padding found at offset '.$thisfile_id3v2['padding']['errorpos'].' (the remaining '.($thisfile_id3v2['padding']['length'] - $i).' bytes are considered invalid)'); - break; - } - } - break; // skip rest of ID3v2 header - } - if ($id3v2_majorversion == 2) { - // Frame ID $xx xx xx (three characters) - // Size $xx xx xx (24-bit integer) - // Flags $xx xx - - $frame_header = substr($framedata, 0, 6); // take next 6 bytes for header - $framedata = substr($framedata, 6); // and leave the rest in $framedata - $frame_name = substr($frame_header, 0, 3); - $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 3, 3), 0); - $frame_flags = 0; // not used for anything in ID3v2.2, just set to avoid E_NOTICEs - - } elseif ($id3v2_majorversion > 2) { - - // Frame ID $xx xx xx xx (four characters) - // Size $xx xx xx xx (32-bit integer in v2.3, 28-bit synchsafe in v2.4+) - // Flags $xx xx - - $frame_header = substr($framedata, 0, 10); // take next 10 bytes for header - $framedata = substr($framedata, 10); // and leave the rest in $framedata - - $frame_name = substr($frame_header, 0, 4); - if ($id3v2_majorversion == 3) { - $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 0); // 32-bit integer - } else { // ID3v2.4+ - $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 1); // 32-bit synchsafe integer (28-bit value) - } - - if ($frame_size < (strlen($framedata) + 4)) { - $nextFrameID = substr($framedata, $frame_size, 4); - if ($this->IsValidID3v2FrameName($nextFrameID, $id3v2_majorversion)) { - // next frame is OK - } elseif (($frame_name == "\x00".'MP3') || ($frame_name == "\x00\x00".'MP') || ($frame_name == ' MP3') || ($frame_name == 'MP3e')) { - // MP3ext known broken frames - "ok" for the purposes of this test - } elseif (($id3v2_majorversion == 4) && ($this->IsValidID3v2FrameName(substr($framedata, getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 0), 4), 3))) { - $this->warning('ID3v2 tag written as ID3v2.4, but with non-synchsafe integers (ID3v2.3 style). Older versions of (Helium2; iTunes) are known culprits of this. Tag has been parsed as ID3v2.3'); - $id3v2_majorversion = 3; - $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 0); // 32-bit integer - } - } - - - $frame_flags = getid3_lib::BigEndian2Int(substr($frame_header, 8, 2)); - } - - if ((($id3v2_majorversion == 2) && ($frame_name == "\x00\x00\x00")) || ($frame_name == "\x00\x00\x00\x00")) { - // padding encountered - - $thisfile_id3v2['padding']['start'] = $framedataoffset; - $thisfile_id3v2['padding']['length'] = strlen($frame_header) + strlen($framedata); - $thisfile_id3v2['padding']['valid'] = true; - - $len = strlen($framedata); - for ($i = 0; $i < $len; $i++) { - if ($framedata{$i} != "\x00") { - $thisfile_id3v2['padding']['valid'] = false; - $thisfile_id3v2['padding']['errorpos'] = $thisfile_id3v2['padding']['start'] + $i; - $this->warning('Invalid ID3v2 padding found at offset '.$thisfile_id3v2['padding']['errorpos'].' (the remaining '.($thisfile_id3v2['padding']['length'] - $i).' bytes are considered invalid)'); - break; - } - } - break; // skip rest of ID3v2 header - } - - if ($iTunesBrokenFrameNameFixed = self::ID3v22iTunesBrokenFrameName($frame_name)) { - $this->warning('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))). [Note: this particular error has been known to happen with tags edited by iTunes (versions "X v2.0.3", "v3.0.1", "v7.0.0.70" are known-guilty, probably others too)]. Translated frame name from "'.str_replace("\x00", ' ', $frame_name).'" to "'.$iTunesBrokenFrameNameFixed.'" for parsing.'); - $frame_name = $iTunesBrokenFrameNameFixed; - } - if (($frame_size <= strlen($framedata)) && ($this->IsValidID3v2FrameName($frame_name, $id3v2_majorversion))) { - - unset($parsedFrame); - $parsedFrame['frame_name'] = $frame_name; - $parsedFrame['frame_flags_raw'] = $frame_flags; - $parsedFrame['data'] = substr($framedata, 0, $frame_size); - $parsedFrame['datalength'] = getid3_lib::CastAsInt($frame_size); - $parsedFrame['dataoffset'] = $framedataoffset; - - $this->ParseID3v2Frame($parsedFrame); - $thisfile_id3v2[$frame_name][] = $parsedFrame; - - $framedata = substr($framedata, $frame_size); - - } else { // invalid frame length or FrameID - - if ($frame_size <= strlen($framedata)) { - - if ($this->IsValidID3v2FrameName(substr($framedata, $frame_size, 4), $id3v2_majorversion)) { - - // next frame is valid, just skip the current frame - $framedata = substr($framedata, $frame_size); - $this->warning('Next ID3v2 frame is valid, skipping current frame.'); - - } else { - - // next frame is invalid too, abort processing - //unset($framedata); - $framedata = null; - $this->error('Next ID3v2 frame is also invalid, aborting processing.'); - - } - - } elseif ($frame_size == strlen($framedata)) { - - // this is the last frame, just skip - $this->warning('This was the last ID3v2 frame.'); - - } else { - - // next frame is invalid too, abort processing - //unset($framedata); - $framedata = null; - $this->warning('Invalid ID3v2 frame size, aborting.'); - - } - if (!$this->IsValidID3v2FrameName($frame_name, $id3v2_majorversion)) { - - switch ($frame_name) { - case "\x00\x00".'MP': - case "\x00".'MP3': - case ' MP3': - case 'MP3e': - case "\x00".'MP': - case ' MP': - case 'MP3': - $this->warning('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: !IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))). [Note: this particular error has been known to happen with tags edited by "MP3ext (www.mutschler.de/mp3ext/)"]'); - break; - - default: - $this->warning('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: !IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))).'); - break; - } - - } elseif (!isset($framedata) || ($frame_size > strlen($framedata))) { - - $this->error('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: $frame_size ('.$frame_size.') > strlen($framedata) ('.(isset($framedata) ? strlen($framedata) : 'null').')).'); - - } else { - - $this->error('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag).'); - - } - - } - $framedataoffset += ($frame_size + $this->ID3v2HeaderLength($id3v2_majorversion)); - - } - - } - - - // Footer - - // The footer is a copy of the header, but with a different identifier. - // ID3v2 identifier "3DI" - // ID3v2 version $04 00 - // ID3v2 flags %abcd0000 - // ID3v2 size 4 * %0xxxxxxx - - if (isset($thisfile_id3v2_flags['isfooter']) && $thisfile_id3v2_flags['isfooter']) { - $footer = $this->fread(10); - if (substr($footer, 0, 3) == '3DI') { - $thisfile_id3v2['footer'] = true; - $thisfile_id3v2['majorversion_footer'] = ord($footer{3}); - $thisfile_id3v2['minorversion_footer'] = ord($footer{4}); - } - if ($thisfile_id3v2['majorversion_footer'] <= 4) { - $id3_flags = ord(substr($footer{5})); - $thisfile_id3v2_flags['unsynch_footer'] = (bool) ($id3_flags & 0x80); - $thisfile_id3v2_flags['extfoot_footer'] = (bool) ($id3_flags & 0x40); - $thisfile_id3v2_flags['experim_footer'] = (bool) ($id3_flags & 0x20); - $thisfile_id3v2_flags['isfooter_footer'] = (bool) ($id3_flags & 0x10); - - $thisfile_id3v2['footerlength'] = getid3_lib::BigEndian2Int(substr($footer, 6, 4), 1); - } - } // end footer - - if (isset($thisfile_id3v2['comments']['genre'])) { - $genres = array(); - foreach ($thisfile_id3v2['comments']['genre'] as $key => $value) { - foreach ($this->ParseID3v2GenreString($value) as $genre) { - $genres[] = $genre; - } - } - $thisfile_id3v2['comments']['genre'] = array_unique($genres); - unset($key, $value, $genres, $genre); - } - - if (isset($thisfile_id3v2['comments']['track'])) { - foreach ($thisfile_id3v2['comments']['track'] as $key => $value) { - if (strstr($value, '/')) { - list($thisfile_id3v2['comments']['tracknum'][$key], $thisfile_id3v2['comments']['totaltracks'][$key]) = explode('/', $thisfile_id3v2['comments']['track'][$key]); - } - } - } - - if (!isset($thisfile_id3v2['comments']['year']) && !empty($thisfile_id3v2['comments']['recording_time'][0]) && preg_match('#^([0-9]{4})#', trim($thisfile_id3v2['comments']['recording_time'][0]), $matches)) { - $thisfile_id3v2['comments']['year'] = array($matches[1]); - } - - - if (!empty($thisfile_id3v2['TXXX'])) { - // MediaMonkey does this, maybe others: write a blank RGAD frame, but put replay-gain adjustment values in TXXX frames - foreach ($thisfile_id3v2['TXXX'] as $txxx_array) { - switch ($txxx_array['description']) { - case 'replaygain_track_gain': - if (empty($info['replay_gain']['track']['adjustment']) && !empty($txxx_array['data'])) { - $info['replay_gain']['track']['adjustment'] = floatval(trim(str_replace('dB', '', $txxx_array['data']))); - } - break; - case 'replaygain_track_peak': - if (empty($info['replay_gain']['track']['peak']) && !empty($txxx_array['data'])) { - $info['replay_gain']['track']['peak'] = floatval($txxx_array['data']); - } - break; - case 'replaygain_album_gain': - if (empty($info['replay_gain']['album']['adjustment']) && !empty($txxx_array['data'])) { - $info['replay_gain']['album']['adjustment'] = floatval(trim(str_replace('dB', '', $txxx_array['data']))); - } - break; - } - } - } - - - // Set avdataoffset - $info['avdataoffset'] = $thisfile_id3v2['headerlength']; - if (isset($thisfile_id3v2['footer'])) { - $info['avdataoffset'] += 10; - } - - return true; - } - - - public function ParseID3v2GenreString($genrestring) { - // Parse genres into arrays of genreName and genreID - // ID3v2.2.x, ID3v2.3.x: '(21)' or '(4)Eurodisco' or '(51)(39)' or '(55)((I think...)' - // ID3v2.4.x: '21' $00 'Eurodisco' $00 - $clean_genres = array(); - - // hack-fixes for some badly-written ID3v2.3 taggers, while trying not to break correctly-written tags - if (($this->getid3->info['id3v2']['majorversion'] == 3) && !preg_match('#[\x00]#', $genrestring)) { - // note: MusicBrainz Picard incorrectly stores plaintext genres separated by "/" when writing in ID3v2.3 mode, hack-fix here: - // replace / with NULL, then replace back the two ID3v1 genres that legitimately have "/" as part of the single genre name - if (preg_match('#/#', $genrestring)) { - $genrestring = str_replace('/', "\x00", $genrestring); - $genrestring = str_replace('Pop'."\x00".'Funk', 'Pop/Funk', $genrestring); - $genrestring = str_replace('Rock'."\x00".'Rock', 'Folk/Rock', $genrestring); - } - - // some other taggers separate multiple genres with semicolon, e.g. "Heavy Metal;Thrash Metal;Metal" - if (preg_match('#;#', $genrestring)) { - $genrestring = str_replace(';', "\x00", $genrestring); - } - } - - - if (strpos($genrestring, "\x00") === false) { - $genrestring = preg_replace('#\(([0-9]{1,3})\)#', '$1'."\x00", $genrestring); - } - - $genre_elements = explode("\x00", $genrestring); - foreach ($genre_elements as $element) { - $element = trim($element); - if ($element) { - if (preg_match('#^[0-9]{1,3}#', $element)) { - $clean_genres[] = getid3_id3v1::LookupGenreName($element); - } else { - $clean_genres[] = str_replace('((', '(', $element); - } - } - } - return $clean_genres; - } - - - public function ParseID3v2Frame(&$parsedFrame) { - - // shortcuts - $info = &$this->getid3->info; - $id3v2_majorversion = $info['id3v2']['majorversion']; - - $parsedFrame['framenamelong'] = $this->FrameNameLongLookup($parsedFrame['frame_name']); - if (empty($parsedFrame['framenamelong'])) { - unset($parsedFrame['framenamelong']); - } - $parsedFrame['framenameshort'] = $this->FrameNameShortLookup($parsedFrame['frame_name']); - if (empty($parsedFrame['framenameshort'])) { - unset($parsedFrame['framenameshort']); - } - - if ($id3v2_majorversion >= 3) { // frame flags are not part of the ID3v2.2 standard - if ($id3v2_majorversion == 3) { - // Frame Header Flags - // %abc00000 %ijk00000 - $parsedFrame['flags']['TagAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x8000); // a - Tag alter preservation - $parsedFrame['flags']['FileAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x4000); // b - File alter preservation - $parsedFrame['flags']['ReadOnly'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x2000); // c - Read only - $parsedFrame['flags']['compression'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0080); // i - Compression - $parsedFrame['flags']['Encryption'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0040); // j - Encryption - $parsedFrame['flags']['GroupingIdentity'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0020); // k - Grouping identity - - } elseif ($id3v2_majorversion == 4) { - // Frame Header Flags - // %0abc0000 %0h00kmnp - $parsedFrame['flags']['TagAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x4000); // a - Tag alter preservation - $parsedFrame['flags']['FileAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x2000); // b - File alter preservation - $parsedFrame['flags']['ReadOnly'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x1000); // c - Read only - $parsedFrame['flags']['GroupingIdentity'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0040); // h - Grouping identity - $parsedFrame['flags']['compression'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0008); // k - Compression - $parsedFrame['flags']['Encryption'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0004); // m - Encryption - $parsedFrame['flags']['Unsynchronisation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0002); // n - Unsynchronisation - $parsedFrame['flags']['DataLengthIndicator'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0001); // p - Data length indicator - - // Frame-level de-unsynchronisation - ID3v2.4 - if ($parsedFrame['flags']['Unsynchronisation']) { - $parsedFrame['data'] = $this->DeUnsynchronise($parsedFrame['data']); - } - - if ($parsedFrame['flags']['DataLengthIndicator']) { - $parsedFrame['data_length_indicator'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 4), 1); - $parsedFrame['data'] = substr($parsedFrame['data'], 4); - } - } - - // Frame-level de-compression - if ($parsedFrame['flags']['compression']) { - $parsedFrame['decompressed_size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 4)); - if (!function_exists('gzuncompress')) { - $this->warning('gzuncompress() support required to decompress ID3v2 frame "'.$parsedFrame['frame_name'].'"'); - } else { - if ($decompresseddata = @gzuncompress(substr($parsedFrame['data'], 4))) { - //if ($decompresseddata = @gzuncompress($parsedFrame['data'])) { - $parsedFrame['data'] = $decompresseddata; - unset($decompresseddata); - } else { - $this->warning('gzuncompress() failed on compressed contents of ID3v2 frame "'.$parsedFrame['frame_name'].'"'); - } - } - } - } - - if (!empty($parsedFrame['flags']['DataLengthIndicator'])) { - if ($parsedFrame['data_length_indicator'] != strlen($parsedFrame['data'])) { - $this->warning('ID3v2 frame "'.$parsedFrame['frame_name'].'" should be '.$parsedFrame['data_length_indicator'].' bytes long according to DataLengthIndicator, but found '.strlen($parsedFrame['data']).' bytes of data'); - } - } - - if (isset($parsedFrame['datalength']) && ($parsedFrame['datalength'] == 0)) { - - $warning = 'Frame "'.$parsedFrame['frame_name'].'" at offset '.$parsedFrame['dataoffset'].' has no data portion'; - switch ($parsedFrame['frame_name']) { - case 'WCOM': - $warning .= ' (this is known to happen with files tagged by RioPort)'; - break; - - default: - break; - } - $this->warning($warning); - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'UFID')) || // 4.1 UFID Unique file identifier - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'UFI'))) { // 4.1 UFI Unique file identifier - // There may be more than one 'UFID' frame in a tag, - // but only one with the same 'Owner identifier'. - //
    - // Owner identifier $00 - // Identifier - $exploded = explode("\x00", $parsedFrame['data'], 2); - $parsedFrame['ownerid'] = (isset($exploded[0]) ? $exploded[0] : ''); - $parsedFrame['data'] = (isset($exploded[1]) ? $exploded[1] : ''); - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'TXXX')) || // 4.2.2 TXXX User defined text information frame - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'TXX'))) { // 4.2.2 TXX User defined text information frame - // There may be more than one 'TXXX' frame in each tag, - // but only one with the same description. - //
    - // Text encoding $xx - // Description $00 (00) - // Value - - $frame_offset = 0; - $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); - if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); - $frame_textencoding_terminator = "\x00"; - } - $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { - $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 - } - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (in_array($frame_description, array("\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"))) { - // if description only contains a BOM or terminator then make it blank - $frame_description = ''; - } - $parsedFrame['encodingid'] = $frame_textencoding; - $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - - $parsedFrame['description'] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $frame_description)); - $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); - if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - $commentkey = ($parsedFrame['description'] ? $parsedFrame['description'] : (isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) ? count($info['id3v2']['comments'][$parsedFrame['framenameshort']]) : 0)); - if (!isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) || !array_key_exists($commentkey, $info['id3v2']['comments'][$parsedFrame['framenameshort']])) { - $info['id3v2']['comments'][$parsedFrame['framenameshort']][$commentkey] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data'])); - } else { - $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data'])); - } - } - //unset($parsedFrame['data']); do not unset, may be needed elsewhere, e.g. for replaygain - - - } elseif ($parsedFrame['frame_name']{0} == 'T') { // 4.2. T??[?] Text information frame - // There may only be one text information frame of its kind in an tag. - //
    - // Text encoding $xx - // Information - - $frame_offset = 0; - $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); - } - - $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); - - $parsedFrame['encodingid'] = $frame_textencoding; - $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - - if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - // ID3v2.3 specs say that TPE1 (and others) can contain multiple artist values separated with / - // This of course breaks when an artist name contains slash character, e.g. "AC/DC" - // MP3tag (maybe others) implement alternative system where multiple artists are null-separated, which makes more sense - // getID3 will split null-separated artists into multiple artists and leave slash-separated ones to the user - switch ($parsedFrame['encoding']) { - case 'UTF-16': - case 'UTF-16BE': - case 'UTF-16LE': - $wordsize = 2; - break; - case 'ISO-8859-1': - case 'UTF-8': - default: - $wordsize = 1; - break; - } - $Txxx_elements = array(); - $Txxx_elements_start_offset = 0; - for ($i = 0; $i < strlen($parsedFrame['data']); $i += $wordsize) { - if (substr($parsedFrame['data'], $i, $wordsize) == str_repeat("\x00", $wordsize)) { - $Txxx_elements[] = substr($parsedFrame['data'], $Txxx_elements_start_offset, $i - $Txxx_elements_start_offset); - $Txxx_elements_start_offset = $i + $wordsize; - } - } - $Txxx_elements[] = substr($parsedFrame['data'], $Txxx_elements_start_offset, $i - $Txxx_elements_start_offset); - foreach ($Txxx_elements as $Txxx_element) { - $string = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $Txxx_element); - if (!empty($string)) { - $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $string; - } - } - unset($string, $wordsize, $i, $Txxx_elements, $Txxx_element, $Txxx_elements_start_offset); - } - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'WXXX')) || // 4.3.2 WXXX User defined URL link frame - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'WXX'))) { // 4.3.2 WXX User defined URL link frame - // There may be more than one 'WXXX' frame in each tag, - // but only one with the same description - //
    - // Text encoding $xx - // Description $00 (00) - // URL - - $frame_offset = 0; - $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); - if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); - $frame_textencoding_terminator = "\x00"; - } - $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { - $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 - } - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (in_array($frame_description, array("\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"))) { - // if description only contains a BOM or terminator then make it blank - $frame_description = ''; - } - $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); - - $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { - $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 - } - if ($frame_terminatorpos) { - // there are null bytes after the data - this is not according to spec - // only use data up to first null byte - $frame_urldata = (string) substr($parsedFrame['data'], 0, $frame_terminatorpos); - } else { - // no null bytes following data, just use all data - $frame_urldata = (string) $parsedFrame['data']; - } - - $parsedFrame['encodingid'] = $frame_textencoding; - $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - - $parsedFrame['url'] = $frame_urldata; - $parsedFrame['description'] = $frame_description; - if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { - $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['url']); - } - unset($parsedFrame['data']); - - - } elseif ($parsedFrame['frame_name']{0} == 'W') { // 4.3. W??? URL link frames - // There may only be one URL link frame of its kind in a tag, - // except when stated otherwise in the frame description - //
    - // URL - - $parsedFrame['url'] = trim($parsedFrame['data']); - if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { - $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['url']; - } - unset($parsedFrame['data']); - - - } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'IPLS')) || // 4.4 IPLS Involved people list (ID3v2.3 only) - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'IPL'))) { // 4.4 IPL Involved people list (ID3v2.2 only) - // http://id3.org/id3v2.3.0#sec4.4 - // There may only be one 'IPL' frame in each tag - //
    - // Text encoding $xx - // People list strings - - $frame_offset = 0; - $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); - } - $parsedFrame['encodingid'] = $frame_textencoding; - $parsedFrame['encoding'] = $this->TextEncodingNameLookup($parsedFrame['encodingid']); - $parsedFrame['data_raw'] = (string) substr($parsedFrame['data'], $frame_offset); - - // http://www.getid3.org/phpBB3/viewtopic.php?t=1369 - // "this tag typically contains null terminated strings, which are associated in pairs" - // "there are users that use the tag incorrectly" - $IPLS_parts = array(); - if (strpos($parsedFrame['data_raw'], "\x00") !== false) { - $IPLS_parts_unsorted = array(); - if (((strlen($parsedFrame['data_raw']) % 2) == 0) && ((substr($parsedFrame['data_raw'], 0, 2) == "\xFF\xFE") || (substr($parsedFrame['data_raw'], 0, 2) == "\xFE\xFF"))) { - // UTF-16, be careful looking for null bytes since most 2-byte characters may contain one; you need to find twin null bytes, and on even padding - $thisILPS = ''; - for ($i = 0; $i < strlen($parsedFrame['data_raw']); $i += 2) { - $twobytes = substr($parsedFrame['data_raw'], $i, 2); - if ($twobytes === "\x00\x00") { - $IPLS_parts_unsorted[] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $thisILPS); - $thisILPS = ''; - } else { - $thisILPS .= $twobytes; - } - } - if (strlen($thisILPS) > 2) { // 2-byte BOM - $IPLS_parts_unsorted[] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $thisILPS); - } - } else { - // ISO-8859-1 or UTF-8 or other single-byte-null character set - $IPLS_parts_unsorted = explode("\x00", $parsedFrame['data_raw']); - } - if (count($IPLS_parts_unsorted) == 1) { - // just a list of names, e.g. "Dino Baptiste, Jimmy Copley, John Gordon, Bernie Marsden, Sharon Watson" - foreach ($IPLS_parts_unsorted as $key => $value) { - $IPLS_parts_sorted = preg_split('#[;,\\r\\n\\t]#', $value); - $position = ''; - foreach ($IPLS_parts_sorted as $person) { - $IPLS_parts[] = array('position'=>$position, 'person'=>$person); - } - } - } elseif ((count($IPLS_parts_unsorted) % 2) == 0) { - $position = ''; - $person = ''; - foreach ($IPLS_parts_unsorted as $key => $value) { - if (($key % 2) == 0) { - $position = $value; - } else { - $person = $value; - $IPLS_parts[] = array('position'=>$position, 'person'=>$person); - $position = ''; - $person = ''; - } - } - } else { - foreach ($IPLS_parts_unsorted as $key => $value) { - $IPLS_parts[] = array($value); - } - } - - } else { - $IPLS_parts = preg_split('#[;,\\r\\n\\t]#', $parsedFrame['data_raw']); - } - $parsedFrame['data'] = $IPLS_parts; - - if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['data']; - } - - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'MCDI')) || // 4.4 MCDI Music CD identifier - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'MCI'))) { // 4.5 MCI Music CD identifier - // There may only be one 'MCDI' frame in each tag - //
    - // CD TOC - - if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['data']; - } - - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'ETCO')) || // 4.5 ETCO Event timing codes - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'ETC'))) { // 4.6 ETC Event timing codes - // There may only be one 'ETCO' frame in each tag - //
    - // Time stamp format $xx - // Where time stamp format is: - // $01 (32-bit value) MPEG frames from beginning of file - // $02 (32-bit value) milliseconds from beginning of file - // Followed by a list of key events in the following format: - // Type of event $xx - // Time stamp $xx (xx ...) - // The 'Time stamp' is set to zero if directly at the beginning of the sound - // or after the previous event. All events MUST be sorted in chronological order. - - $frame_offset = 0; - $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - - while ($frame_offset < strlen($parsedFrame['data'])) { - $parsedFrame['typeid'] = substr($parsedFrame['data'], $frame_offset++, 1); - $parsedFrame['type'] = $this->ETCOEventLookup($parsedFrame['typeid']); - $parsedFrame['timestamp'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); - $frame_offset += 4; - } - unset($parsedFrame['data']); - - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'MLLT')) || // 4.6 MLLT MPEG location lookup table - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'MLL'))) { // 4.7 MLL MPEG location lookup table - // There may only be one 'MLLT' frame in each tag - //
    - // MPEG frames between reference $xx xx - // Bytes between reference $xx xx xx - // Milliseconds between reference $xx xx xx - // Bits for bytes deviation $xx - // Bits for milliseconds dev. $xx - // Then for every reference the following data is included; - // Deviation in bytes %xxx.... - // Deviation in milliseconds %xxx.... - - $frame_offset = 0; - $parsedFrame['framesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 2)); - $parsedFrame['bytesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 2, 3)); - $parsedFrame['msbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 5, 3)); - $parsedFrame['bitsforbytesdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 8, 1)); - $parsedFrame['bitsformsdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 9, 1)); - $parsedFrame['data'] = substr($parsedFrame['data'], 10); - while ($frame_offset < strlen($parsedFrame['data'])) { - $deviationbitstream .= getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1)); - } - $reference_counter = 0; - while (strlen($deviationbitstream) > 0) { - $parsedFrame[$reference_counter]['bytedeviation'] = bindec(substr($deviationbitstream, 0, $parsedFrame['bitsforbytesdeviation'])); - $parsedFrame[$reference_counter]['msdeviation'] = bindec(substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'], $parsedFrame['bitsformsdeviation'])); - $deviationbitstream = substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'] + $parsedFrame['bitsformsdeviation']); - $reference_counter++; - } - unset($parsedFrame['data']); - - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'SYTC')) || // 4.7 SYTC Synchronised tempo codes - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'STC'))) { // 4.8 STC Synchronised tempo codes - // There may only be one 'SYTC' frame in each tag - //
    - // Time stamp format $xx - // Tempo data - // Where time stamp format is: - // $01 (32-bit value) MPEG frames from beginning of file - // $02 (32-bit value) milliseconds from beginning of file - - $frame_offset = 0; - $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $timestamp_counter = 0; - while ($frame_offset < strlen($parsedFrame['data'])) { - $parsedFrame[$timestamp_counter]['tempo'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - if ($parsedFrame[$timestamp_counter]['tempo'] == 255) { - $parsedFrame[$timestamp_counter]['tempo'] += ord(substr($parsedFrame['data'], $frame_offset++, 1)); - } - $parsedFrame[$timestamp_counter]['timestamp'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); - $frame_offset += 4; - $timestamp_counter++; - } - unset($parsedFrame['data']); - - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'USLT')) || // 4.8 USLT Unsynchronised lyric/text transcription - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'ULT'))) { // 4.9 ULT Unsynchronised lyric/text transcription - // There may be more than one 'Unsynchronised lyrics/text transcription' frame - // in each tag, but only one with the same language and content descriptor. - //
    - // Text encoding $xx - // Language $xx xx xx - // Content descriptor $00 (00) - // Lyrics/text - - $frame_offset = 0; - $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); - if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); - $frame_textencoding_terminator = "\x00"; - } - $frame_language = substr($parsedFrame['data'], $frame_offset, 3); - $frame_offset += 3; - $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { - $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 - } - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (in_array($frame_description, array("\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"))) { - // if description only contains a BOM or terminator then make it blank - $frame_description = ''; - } - $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); - - $parsedFrame['encodingid'] = $frame_textencoding; - $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - - $parsedFrame['language'] = $frame_language; - $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); - $parsedFrame['description'] = $frame_description; - if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); - } - unset($parsedFrame['data']); - - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'SYLT')) || // 4.9 SYLT Synchronised lyric/text - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'SLT'))) { // 4.10 SLT Synchronised lyric/text - // There may be more than one 'SYLT' frame in each tag, - // but only one with the same language and content descriptor. - //
    - // Text encoding $xx - // Language $xx xx xx - // Time stamp format $xx - // $01 (32-bit value) MPEG frames from beginning of file - // $02 (32-bit value) milliseconds from beginning of file - // Content type $xx - // Content descriptor $00 (00) - // Terminated text to be synced (typically a syllable) - // Sync identifier (terminator to above string) $00 (00) - // Time stamp $xx (xx ...) - - $frame_offset = 0; - $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); - if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); - $frame_textencoding_terminator = "\x00"; - } - $frame_language = substr($parsedFrame['data'], $frame_offset, 3); - $frame_offset += 3; - $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['contenttypeid'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['contenttype'] = $this->SYTLContentTypeLookup($parsedFrame['contenttypeid']); - $parsedFrame['encodingid'] = $frame_textencoding; - $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - - $parsedFrame['language'] = $frame_language; - $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); - - $timestampindex = 0; - $frame_remainingdata = substr($parsedFrame['data'], $frame_offset); - while (strlen($frame_remainingdata)) { - $frame_offset = 0; - $frame_terminatorpos = strpos($frame_remainingdata, $frame_textencoding_terminator); - if ($frame_terminatorpos === false) { - $frame_remainingdata = ''; - } else { - if (ord(substr($frame_remainingdata, $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { - $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 - } - $parsedFrame['lyrics'][$timestampindex]['data'] = substr($frame_remainingdata, $frame_offset, $frame_terminatorpos - $frame_offset); - - $frame_remainingdata = substr($frame_remainingdata, $frame_terminatorpos + strlen($frame_textencoding_terminator)); - if (($timestampindex == 0) && (ord($frame_remainingdata{0}) != 0)) { - // timestamp probably omitted for first data item - } else { - $parsedFrame['lyrics'][$timestampindex]['timestamp'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 0, 4)); - $frame_remainingdata = substr($frame_remainingdata, 4); - } - $timestampindex++; - } - } - unset($parsedFrame['data']); - - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'COMM')) || // 4.10 COMM Comments - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'COM'))) { // 4.11 COM Comments - // There may be more than one comment frame in each tag, - // but only one with the same language and content descriptor. - //
    - // Text encoding $xx - // Language $xx xx xx - // Short content descrip. $00 (00) - // The actual text - - if (strlen($parsedFrame['data']) < 5) { - - $this->warning('Invalid data (too short) for "'.$parsedFrame['frame_name'].'" frame at offset '.$parsedFrame['dataoffset']); - - } else { - - $frame_offset = 0; - $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); - if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); - $frame_textencoding_terminator = "\x00"; - } - $frame_language = substr($parsedFrame['data'], $frame_offset, 3); - $frame_offset += 3; - $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { - $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 - } - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (in_array($frame_description, array("\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"))) { - // if description only contains a BOM or terminator then make it blank - $frame_description = ''; - } - $frame_text = (string) substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); - - $parsedFrame['encodingid'] = $frame_textencoding; - $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - - $parsedFrame['language'] = $frame_language; - $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); - $parsedFrame['description'] = $frame_description; - $parsedFrame['data'] = $frame_text; - if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - $commentkey = ($parsedFrame['description'] ? $parsedFrame['description'] : (!empty($info['id3v2']['comments'][$parsedFrame['framenameshort']]) ? count($info['id3v2']['comments'][$parsedFrame['framenameshort']]) : 0)); - if (!isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) || !array_key_exists($commentkey, $info['id3v2']['comments'][$parsedFrame['framenameshort']])) { - $info['id3v2']['comments'][$parsedFrame['framenameshort']][$commentkey] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); - } else { - $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); - } - } - - } - - } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'RVA2')) { // 4.11 RVA2 Relative volume adjustment (2) (ID3v2.4+ only) - // There may be more than one 'RVA2' frame in each tag, - // but only one with the same identification string - //
    - // Identification $00 - // The 'identification' string is used to identify the situation and/or - // device where this adjustment should apply. The following is then - // repeated for every channel: - // Type of channel $xx - // Volume adjustment $xx xx - // Bits representing peak $xx - // Peak volume $xx (xx ...) - - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00"); - $frame_idstring = substr($parsedFrame['data'], 0, $frame_terminatorpos); - if (ord($frame_idstring) === 0) { - $frame_idstring = ''; - } - $frame_remainingdata = substr($parsedFrame['data'], $frame_terminatorpos + strlen("\x00")); - $parsedFrame['description'] = $frame_idstring; - $RVA2channelcounter = 0; - while (strlen($frame_remainingdata) >= 5) { - $frame_offset = 0; - $frame_channeltypeid = ord(substr($frame_remainingdata, $frame_offset++, 1)); - $parsedFrame[$RVA2channelcounter]['channeltypeid'] = $frame_channeltypeid; - $parsedFrame[$RVA2channelcounter]['channeltype'] = $this->RVA2ChannelTypeLookup($frame_channeltypeid); - $parsedFrame[$RVA2channelcounter]['volumeadjust'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, $frame_offset, 2), false, true); // 16-bit signed - $frame_offset += 2; - $parsedFrame[$RVA2channelcounter]['bitspeakvolume'] = ord(substr($frame_remainingdata, $frame_offset++, 1)); - if (($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] < 1) || ($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] > 4)) { - $this->warning('ID3v2::RVA2 frame['.$RVA2channelcounter.'] contains invalid '.$parsedFrame[$RVA2channelcounter]['bitspeakvolume'].'-byte bits-representing-peak value'); - break; - } - $frame_bytespeakvolume = ceil($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] / 8); - $parsedFrame[$RVA2channelcounter]['peakvolume'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, $frame_offset, $frame_bytespeakvolume)); - $frame_remainingdata = substr($frame_remainingdata, $frame_offset + $frame_bytespeakvolume); - $RVA2channelcounter++; - } - unset($parsedFrame['data']); - - - } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'RVAD')) || // 4.12 RVAD Relative volume adjustment (ID3v2.3 only) - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'RVA'))) { // 4.12 RVA Relative volume adjustment (ID3v2.2 only) - // There may only be one 'RVA' frame in each tag - //
    - // ID3v2.2 => Increment/decrement %000000ba - // ID3v2.3 => Increment/decrement %00fedcba - // Bits used for volume descr. $xx - // Relative volume change, right $xx xx (xx ...) // a - // Relative volume change, left $xx xx (xx ...) // b - // Peak volume right $xx xx (xx ...) - // Peak volume left $xx xx (xx ...) - // ID3v2.3 only, optional (not present in ID3v2.2): - // Relative volume change, right back $xx xx (xx ...) // c - // Relative volume change, left back $xx xx (xx ...) // d - // Peak volume right back $xx xx (xx ...) - // Peak volume left back $xx xx (xx ...) - // ID3v2.3 only, optional (not present in ID3v2.2): - // Relative volume change, center $xx xx (xx ...) // e - // Peak volume center $xx xx (xx ...) - // ID3v2.3 only, optional (not present in ID3v2.2): - // Relative volume change, bass $xx xx (xx ...) // f - // Peak volume bass $xx xx (xx ...) - - $frame_offset = 0; - $frame_incrdecrflags = getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['incdec']['right'] = (bool) substr($frame_incrdecrflags, 6, 1); - $parsedFrame['incdec']['left'] = (bool) substr($frame_incrdecrflags, 7, 1); - $parsedFrame['bitsvolume'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $frame_bytesvolume = ceil($parsedFrame['bitsvolume'] / 8); - $parsedFrame['volumechange']['right'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); - if ($parsedFrame['incdec']['right'] === false) { - $parsedFrame['volumechange']['right'] *= -1; - } - $frame_offset += $frame_bytesvolume; - $parsedFrame['volumechange']['left'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); - if ($parsedFrame['incdec']['left'] === false) { - $parsedFrame['volumechange']['left'] *= -1; - } - $frame_offset += $frame_bytesvolume; - $parsedFrame['peakvolume']['right'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); - $frame_offset += $frame_bytesvolume; - $parsedFrame['peakvolume']['left'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); - $frame_offset += $frame_bytesvolume; - if ($id3v2_majorversion == 3) { - $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset); - if (strlen($parsedFrame['data']) > 0) { - $parsedFrame['incdec']['rightrear'] = (bool) substr($frame_incrdecrflags, 4, 1); - $parsedFrame['incdec']['leftrear'] = (bool) substr($frame_incrdecrflags, 5, 1); - $parsedFrame['volumechange']['rightrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); - if ($parsedFrame['incdec']['rightrear'] === false) { - $parsedFrame['volumechange']['rightrear'] *= -1; - } - $frame_offset += $frame_bytesvolume; - $parsedFrame['volumechange']['leftrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); - if ($parsedFrame['incdec']['leftrear'] === false) { - $parsedFrame['volumechange']['leftrear'] *= -1; - } - $frame_offset += $frame_bytesvolume; - $parsedFrame['peakvolume']['rightrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); - $frame_offset += $frame_bytesvolume; - $parsedFrame['peakvolume']['leftrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); - $frame_offset += $frame_bytesvolume; - } - $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset); - if (strlen($parsedFrame['data']) > 0) { - $parsedFrame['incdec']['center'] = (bool) substr($frame_incrdecrflags, 3, 1); - $parsedFrame['volumechange']['center'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); - if ($parsedFrame['incdec']['center'] === false) { - $parsedFrame['volumechange']['center'] *= -1; - } - $frame_offset += $frame_bytesvolume; - $parsedFrame['peakvolume']['center'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); - $frame_offset += $frame_bytesvolume; - } - $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset); - if (strlen($parsedFrame['data']) > 0) { - $parsedFrame['incdec']['bass'] = (bool) substr($frame_incrdecrflags, 2, 1); - $parsedFrame['volumechange']['bass'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); - if ($parsedFrame['incdec']['bass'] === false) { - $parsedFrame['volumechange']['bass'] *= -1; - } - $frame_offset += $frame_bytesvolume; - $parsedFrame['peakvolume']['bass'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); - $frame_offset += $frame_bytesvolume; - } - } - unset($parsedFrame['data']); - - - } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'EQU2')) { // 4.12 EQU2 Equalisation (2) (ID3v2.4+ only) - // There may be more than one 'EQU2' frame in each tag, - // but only one with the same identification string - //
    - // Interpolation method $xx - // $00 Band - // $01 Linear - // Identification $00 - // The following is then repeated for every adjustment point - // Frequency $xx xx - // Volume adjustment $xx xx - - $frame_offset = 0; - $frame_interpolationmethod = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_idstring = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_idstring) === 0) { - $frame_idstring = ''; - } - $parsedFrame['description'] = $frame_idstring; - $frame_remainingdata = substr($parsedFrame['data'], $frame_terminatorpos + strlen("\x00")); - while (strlen($frame_remainingdata)) { - $frame_frequency = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 0, 2)) / 2; - $parsedFrame['data'][$frame_frequency] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 2, 2), false, true); - $frame_remainingdata = substr($frame_remainingdata, 4); - } - $parsedFrame['interpolationmethod'] = $frame_interpolationmethod; - unset($parsedFrame['data']); - - - } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'EQUA')) || // 4.12 EQUA Equalisation (ID3v2.3 only) - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'EQU'))) { // 4.13 EQU Equalisation (ID3v2.2 only) - // There may only be one 'EQUA' frame in each tag - //
    - // Adjustment bits $xx - // This is followed by 2 bytes + ('adjustment bits' rounded up to the - // nearest byte) for every equalisation band in the following format, - // giving a frequency range of 0 - 32767Hz: - // Increment/decrement %x (MSB of the Frequency) - // Frequency (lower 15 bits) - // Adjustment $xx (xx ...) - - $frame_offset = 0; - $parsedFrame['adjustmentbits'] = substr($parsedFrame['data'], $frame_offset++, 1); - $frame_adjustmentbytes = ceil($parsedFrame['adjustmentbits'] / 8); - - $frame_remainingdata = (string) substr($parsedFrame['data'], $frame_offset); - while (strlen($frame_remainingdata) > 0) { - $frame_frequencystr = getid3_lib::BigEndian2Bin(substr($frame_remainingdata, 0, 2)); - $frame_incdec = (bool) substr($frame_frequencystr, 0, 1); - $frame_frequency = bindec(substr($frame_frequencystr, 1, 15)); - $parsedFrame[$frame_frequency]['incdec'] = $frame_incdec; - $parsedFrame[$frame_frequency]['adjustment'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 2, $frame_adjustmentbytes)); - if ($parsedFrame[$frame_frequency]['incdec'] === false) { - $parsedFrame[$frame_frequency]['adjustment'] *= -1; - } - $frame_remainingdata = substr($frame_remainingdata, 2 + $frame_adjustmentbytes); - } - unset($parsedFrame['data']); - - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'RVRB')) || // 4.13 RVRB Reverb - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'REV'))) { // 4.14 REV Reverb - // There may only be one 'RVRB' frame in each tag. - //
    - // Reverb left (ms) $xx xx - // Reverb right (ms) $xx xx - // Reverb bounces, left $xx - // Reverb bounces, right $xx - // Reverb feedback, left to left $xx - // Reverb feedback, left to right $xx - // Reverb feedback, right to right $xx - // Reverb feedback, right to left $xx - // Premix left to right $xx - // Premix right to left $xx - - $frame_offset = 0; - $parsedFrame['left'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); - $frame_offset += 2; - $parsedFrame['right'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); - $frame_offset += 2; - $parsedFrame['bouncesL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['bouncesR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['feedbackLL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['feedbackLR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['feedbackRR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['feedbackRL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['premixLR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['premixRL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - unset($parsedFrame['data']); - - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'APIC')) || // 4.14 APIC Attached picture - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'PIC'))) { // 4.15 PIC Attached picture - // There may be several pictures attached to one file, - // each in their individual 'APIC' frame, but only one - // with the same content descriptor - //
    - // Text encoding $xx - // ID3v2.3+ => MIME type $00 - // ID3v2.2 => Image format $xx xx xx - // Picture type $xx - // Description $00 (00) - // Picture data - - $frame_offset = 0; - $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); - if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); - $frame_textencoding_terminator = "\x00"; - } - - if ($id3v2_majorversion == 2 && strlen($parsedFrame['data']) > $frame_offset) { - $frame_imagetype = substr($parsedFrame['data'], $frame_offset, 3); - if (strtolower($frame_imagetype) == 'ima') { - // complete hack for mp3Rage (www.chaoticsoftware.com) that puts ID3v2.3-formatted - // MIME type instead of 3-char ID3v2.2-format image type (thanks xbhoffØpacbell*net) - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_mimetype) === 0) { - $frame_mimetype = ''; - } - $frame_imagetype = strtoupper(str_replace('image/', '', strtolower($frame_mimetype))); - if ($frame_imagetype == 'JPEG') { - $frame_imagetype = 'JPG'; - } - $frame_offset = $frame_terminatorpos + strlen("\x00"); - } else { - $frame_offset += 3; - } - } - if ($id3v2_majorversion > 2 && strlen($parsedFrame['data']) > $frame_offset) { - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_mimetype) === 0) { - $frame_mimetype = ''; - } - $frame_offset = $frame_terminatorpos + strlen("\x00"); - } - - $frame_picturetype = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - - if ($frame_offset >= $parsedFrame['datalength']) { - $this->warning('data portion of APIC frame is missing at offset '.($parsedFrame['dataoffset'] + 8 + $frame_offset)); - } else { - $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { - $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 - } - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (in_array($frame_description, array("\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"))) { - // if description only contains a BOM or terminator then make it blank - $frame_description = ''; - } - $parsedFrame['encodingid'] = $frame_textencoding; - $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - - if ($id3v2_majorversion == 2) { - $parsedFrame['imagetype'] = $frame_imagetype; - } else { - $parsedFrame['mime'] = $frame_mimetype; - } - $parsedFrame['picturetypeid'] = $frame_picturetype; - $parsedFrame['picturetype'] = $this->APICPictureTypeLookup($frame_picturetype); - $parsedFrame['description'] = $frame_description; - $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); - $parsedFrame['datalength'] = strlen($parsedFrame['data']); - - $parsedFrame['image_mime'] = ''; - $imageinfo = array(); - if ($imagechunkcheck = getid3_lib::GetDataImageSize($parsedFrame['data'], $imageinfo)) { - if (($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) { - $parsedFrame['image_mime'] = 'image/'.getid3_lib::ImageTypesLookup($imagechunkcheck[2]); - if ($imagechunkcheck[0]) { - $parsedFrame['image_width'] = $imagechunkcheck[0]; - } - if ($imagechunkcheck[1]) { - $parsedFrame['image_height'] = $imagechunkcheck[1]; - } - } - } - - do { - if ($this->getid3->option_save_attachments === false) { - // skip entirely - unset($parsedFrame['data']); - break; - } - if ($this->getid3->option_save_attachments === true) { - // great + public $StartingOffset = 0; + + public function Analyze() + { + $info = &$this->getid3->info; + + // Overall tag structure: + // +-----------------------------+ + // | Header (10 bytes) | + // +-----------------------------+ + // | Extended Header | + // | (variable length, OPTIONAL) | + // +-----------------------------+ + // | Frames (variable length) | + // +-----------------------------+ + // | Padding | + // | (variable length, OPTIONAL) | + // +-----------------------------+ + // | Footer (10 bytes, OPTIONAL) | + // +-----------------------------+ + + // Header + // ID3v2/file identifier "ID3" + // ID3v2 version $04 00 + // ID3v2 flags (%ab000000 in v2.2, %abc00000 in v2.3, %abcd0000 in v2.4.x) + // ID3v2 size 4 * %0xxxxxxx + + // shortcuts + $info['id3v2']['header'] = true; + $thisfile_id3v2 = &$info['id3v2']; + $thisfile_id3v2['flags'] = []; + $thisfile_id3v2_flags = &$thisfile_id3v2['flags']; + + $this->fseek($this->StartingOffset); + $header = $this->fread(10); + if (substr($header, 0, 3) == 'ID3' && strlen($header) == 10) { + $thisfile_id3v2['majorversion'] = ord($header[3]); + $thisfile_id3v2['minorversion'] = ord($header[4]); + + // shortcut + $id3v2_majorversion = &$thisfile_id3v2['majorversion']; + } else { + unset($info['id3v2']); + + return false; + } + + if ($id3v2_majorversion > 4) { // this script probably won't correctly parse ID3v2.5.x and above (if it ever exists) + + $this->error('this script only parses up to ID3v2.4.x - this tag is ID3v2.'.$id3v2_majorversion.'.'.$thisfile_id3v2['minorversion']); + + return false; + } + + $id3_flags = ord($header[5]); + switch ($id3v2_majorversion) { + case 2: + // %ab000000 in v2.2 + $thisfile_id3v2_flags['unsynch'] = (bool) ($id3_flags & 0x80); // a - Unsynchronisation + $thisfile_id3v2_flags['compression'] = (bool) ($id3_flags & 0x40); // b - Compression + break; + + case 3: + // %abc00000 in v2.3 + $thisfile_id3v2_flags['unsynch'] = (bool) ($id3_flags & 0x80); // a - Unsynchronisation + $thisfile_id3v2_flags['exthead'] = (bool) ($id3_flags & 0x40); // b - Extended header + $thisfile_id3v2_flags['experim'] = (bool) ($id3_flags & 0x20); // c - Experimental indicator + break; + + case 4: + // %abcd0000 in v2.4 + $thisfile_id3v2_flags['unsynch'] = (bool) ($id3_flags & 0x80); // a - Unsynchronisation + $thisfile_id3v2_flags['exthead'] = (bool) ($id3_flags & 0x40); // b - Extended header + $thisfile_id3v2_flags['experim'] = (bool) ($id3_flags & 0x20); // c - Experimental indicator + $thisfile_id3v2_flags['isfooter'] = (bool) ($id3_flags & 0x10); // d - Footer present + break; + } + + $thisfile_id3v2['headerlength'] = getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length + + $thisfile_id3v2['tag_offset_start'] = $this->StartingOffset; + $thisfile_id3v2['tag_offset_end'] = $thisfile_id3v2['tag_offset_start'] + $thisfile_id3v2['headerlength']; + + // create 'encoding' key - used by getid3::HandleAllTags() + // in ID3v2 every field can have it's own encoding type + // so force everything to UTF-8 so it can be handled consistantly + $thisfile_id3v2['encoding'] = 'UTF-8'; + + // Frames + + // All ID3v2 frames consists of one frame header followed by one or more + // fields containing the actual information. The header is always 10 + // bytes and laid out as follows: + // + // Frame ID $xx xx xx xx (four characters) + // Size 4 * %0xxxxxxx + // Flags $xx xx + + $sizeofframes = $thisfile_id3v2['headerlength'] - 10; // not including 10-byte initial header + if (! empty($thisfile_id3v2['exthead']['length'])) { + $sizeofframes -= ($thisfile_id3v2['exthead']['length'] + 4); + } + if (! empty($thisfile_id3v2_flags['isfooter'])) { + $sizeofframes -= 10; // footer takes last 10 bytes of ID3v2 header, after frame data, before audio + } + if ($sizeofframes > 0) { + $framedata = $this->fread($sizeofframes); // read all frames from file into $framedata variable + + // if entire frame data is unsynched, de-unsynch it now (ID3v2.3.x) + if (! empty($thisfile_id3v2_flags['unsynch']) && ($id3v2_majorversion <= 3)) { + $framedata = $this->DeUnsynchronise($framedata); + } + // [in ID3v2.4.0] Unsynchronisation [S:6.1] is done on frame level, instead + // of on tag level, making it easier to skip frames, increasing the streamability + // of the tag. The unsynchronisation flag in the header [S:3.1] indicates that + // there exists an unsynchronised frame, while the new unsynchronisation flag in + // the frame header [S:4.1.2] indicates unsynchronisation. + + //$framedataoffset = 10 + ($thisfile_id3v2['exthead']['length'] ? $thisfile_id3v2['exthead']['length'] + 4 : 0); // how many bytes into the stream - start from after the 10-byte header (and extended header length+4, if present) + $framedataoffset = 10; // how many bytes into the stream - start from after the 10-byte header + + // Extended Header + if (! empty($thisfile_id3v2_flags['exthead'])) { + $extended_header_offset = 0; + + if ($id3v2_majorversion == 3) { + + // v2.3 definition: + //Extended header size $xx xx xx xx // 32-bit integer + //Extended Flags $xx xx + // %x0000000 %00000000 // v2.3 + // x - CRC data present + //Size of padding $xx xx xx xx + + $thisfile_id3v2['exthead']['length'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4), 0); + $extended_header_offset += 4; + + $thisfile_id3v2['exthead']['flag_bytes'] = 2; + $thisfile_id3v2['exthead']['flag_raw'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, $thisfile_id3v2['exthead']['flag_bytes'])); + $extended_header_offset += $thisfile_id3v2['exthead']['flag_bytes']; + + $thisfile_id3v2['exthead']['flags']['crc'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x8000); + + $thisfile_id3v2['exthead']['padding_size'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4)); + $extended_header_offset += 4; + + if ($thisfile_id3v2['exthead']['flags']['crc']) { + $thisfile_id3v2['exthead']['flag_data']['crc'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4)); + $extended_header_offset += 4; + } + $extended_header_offset += $thisfile_id3v2['exthead']['padding_size']; + } elseif ($id3v2_majorversion == 4) { + + // v2.4 definition: + //Extended header size 4 * %0xxxxxxx // 28-bit synchsafe integer + //Number of flag bytes $01 + //Extended Flags $xx + // %0bcd0000 // v2.4 + // b - Tag is an update + // Flag data length $00 + // c - CRC data present + // Flag data length $05 + // Total frame CRC 5 * %0xxxxxxx + // d - Tag restrictions + // Flag data length $01 + + $thisfile_id3v2['exthead']['length'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4), true); + $extended_header_offset += 4; + + $thisfile_id3v2['exthead']['flag_bytes'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should always be 1 + $extended_header_offset += 1; + + $thisfile_id3v2['exthead']['flag_raw'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, $thisfile_id3v2['exthead']['flag_bytes'])); + $extended_header_offset += $thisfile_id3v2['exthead']['flag_bytes']; + + $thisfile_id3v2['exthead']['flags']['update'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x40); + $thisfile_id3v2['exthead']['flags']['crc'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x20); + $thisfile_id3v2['exthead']['flags']['restrictions'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x10); + + if ($thisfile_id3v2['exthead']['flags']['update']) { + $ext_header_chunk_length = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should be 0 + $extended_header_offset += 1; + } + + if ($thisfile_id3v2['exthead']['flags']['crc']) { + $ext_header_chunk_length = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should be 5 + $extended_header_offset += 1; + $thisfile_id3v2['exthead']['flag_data']['crc'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, $ext_header_chunk_length), true, false); + $extended_header_offset += $ext_header_chunk_length; + } + + if ($thisfile_id3v2['exthead']['flags']['restrictions']) { + $ext_header_chunk_length = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should be 1 + $extended_header_offset += 1; + + // %ppqrrstt + $restrictions_raw = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); + $extended_header_offset += 1; + $thisfile_id3v2['exthead']['flags']['restrictions']['tagsize'] = ($restrictions_raw & 0xC0) >> 6; // p - Tag size restrictions + $thisfile_id3v2['exthead']['flags']['restrictions']['textenc'] = ($restrictions_raw & 0x20) >> 5; // q - Text encoding restrictions + $thisfile_id3v2['exthead']['flags']['restrictions']['textsize'] = ($restrictions_raw & 0x18) >> 3; // r - Text fields size restrictions + $thisfile_id3v2['exthead']['flags']['restrictions']['imgenc'] = ($restrictions_raw & 0x04) >> 2; // s - Image encoding restrictions + $thisfile_id3v2['exthead']['flags']['restrictions']['imgsize'] = ($restrictions_raw & 0x03) >> 0; // t - Image size restrictions + + $thisfile_id3v2['exthead']['flags']['restrictions_text']['tagsize'] = $this->LookupExtendedHeaderRestrictionsTagSizeLimits($thisfile_id3v2['exthead']['flags']['restrictions']['tagsize']); + $thisfile_id3v2['exthead']['flags']['restrictions_text']['textenc'] = $this->LookupExtendedHeaderRestrictionsTextEncodings($thisfile_id3v2['exthead']['flags']['restrictions']['textenc']); + $thisfile_id3v2['exthead']['flags']['restrictions_text']['textsize'] = $this->LookupExtendedHeaderRestrictionsTextFieldSize($thisfile_id3v2['exthead']['flags']['restrictions']['textsize']); + $thisfile_id3v2['exthead']['flags']['restrictions_text']['imgenc'] = $this->LookupExtendedHeaderRestrictionsImageEncoding($thisfile_id3v2['exthead']['flags']['restrictions']['imgenc']); + $thisfile_id3v2['exthead']['flags']['restrictions_text']['imgsize'] = $this->LookupExtendedHeaderRestrictionsImageSizeSize($thisfile_id3v2['exthead']['flags']['restrictions']['imgsize']); + } + + if ($thisfile_id3v2['exthead']['length'] != $extended_header_offset) { + $this->warning('ID3v2.4 extended header length mismatch (expecting '.intval($thisfile_id3v2['exthead']['length']).', found '.intval($extended_header_offset).')'); + } + } + + $framedataoffset += $extended_header_offset; + $framedata = substr($framedata, $extended_header_offset); + } // end extended header + + while (isset($framedata) && (strlen($framedata) > 0)) { // cycle through until no more frame data is left to parse + if (strlen($framedata) <= $this->ID3v2HeaderLength($id3v2_majorversion)) { + // insufficient room left in ID3v2 header for actual data - must be padding + $thisfile_id3v2['padding']['start'] = $framedataoffset; + $thisfile_id3v2['padding']['length'] = strlen($framedata); + $thisfile_id3v2['padding']['valid'] = true; + for ($i = 0; $i < $thisfile_id3v2['padding']['length']; $i++) { + if ($framedata[$i] != "\x00") { + $thisfile_id3v2['padding']['valid'] = false; + $thisfile_id3v2['padding']['errorpos'] = $thisfile_id3v2['padding']['start'] + $i; + $this->warning('Invalid ID3v2 padding found at offset '.$thisfile_id3v2['padding']['errorpos'].' (the remaining '.($thisfile_id3v2['padding']['length'] - $i).' bytes are considered invalid)'); + break; + } + } + break; // skip rest of ID3v2 header + } + if ($id3v2_majorversion == 2) { + // Frame ID $xx xx xx (three characters) + // Size $xx xx xx (24-bit integer) + // Flags $xx xx + + $frame_header = substr($framedata, 0, 6); // take next 6 bytes for header + $framedata = substr($framedata, 6); // and leave the rest in $framedata + $frame_name = substr($frame_header, 0, 3); + $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 3, 3), 0); + $frame_flags = 0; // not used for anything in ID3v2.2, just set to avoid E_NOTICEs + } elseif ($id3v2_majorversion > 2) { + + // Frame ID $xx xx xx xx (four characters) + // Size $xx xx xx xx (32-bit integer in v2.3, 28-bit synchsafe in v2.4+) + // Flags $xx xx + + $frame_header = substr($framedata, 0, 10); // take next 10 bytes for header + $framedata = substr($framedata, 10); // and leave the rest in $framedata + + $frame_name = substr($frame_header, 0, 4); + if ($id3v2_majorversion == 3) { + $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 0); // 32-bit integer + } else { // ID3v2.4+ + $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 1); // 32-bit synchsafe integer (28-bit value) + } + + if ($frame_size < (strlen($framedata) + 4)) { + $nextFrameID = substr($framedata, $frame_size, 4); + if ($this->IsValidID3v2FrameName($nextFrameID, $id3v2_majorversion)) { + // next frame is OK + } elseif (($frame_name == "\x00".'MP3') || ($frame_name == "\x00\x00".'MP') || ($frame_name == ' MP3') || ($frame_name == 'MP3e')) { + // MP3ext known broken frames - "ok" for the purposes of this test + } elseif (($id3v2_majorversion == 4) && ($this->IsValidID3v2FrameName(substr($framedata, getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 0), 4), 3))) { + $this->warning('ID3v2 tag written as ID3v2.4, but with non-synchsafe integers (ID3v2.3 style). Older versions of (Helium2; iTunes) are known culprits of this. Tag has been parsed as ID3v2.3'); + $id3v2_majorversion = 3; + $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 0); // 32-bit integer + } + } + + $frame_flags = getid3_lib::BigEndian2Int(substr($frame_header, 8, 2)); + } + + if ((($id3v2_majorversion == 2) && ($frame_name == "\x00\x00\x00")) || ($frame_name == "\x00\x00\x00\x00")) { + // padding encountered + + $thisfile_id3v2['padding']['start'] = $framedataoffset; + $thisfile_id3v2['padding']['length'] = strlen($frame_header) + strlen($framedata); + $thisfile_id3v2['padding']['valid'] = true; + + $len = strlen($framedata); + for ($i = 0; $i < $len; $i++) { + if ($framedata[$i] != "\x00") { + $thisfile_id3v2['padding']['valid'] = false; + $thisfile_id3v2['padding']['errorpos'] = $thisfile_id3v2['padding']['start'] + $i; + $this->warning('Invalid ID3v2 padding found at offset '.$thisfile_id3v2['padding']['errorpos'].' (the remaining '.($thisfile_id3v2['padding']['length'] - $i).' bytes are considered invalid)'); + break; + } + } + break; // skip rest of ID3v2 header + } + + if ($iTunesBrokenFrameNameFixed = self::ID3v22iTunesBrokenFrameName($frame_name)) { + $this->warning('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))). [Note: this particular error has been known to happen with tags edited by iTunes (versions "X v2.0.3", "v3.0.1", "v7.0.0.70" are known-guilty, probably others too)]. Translated frame name from "'.str_replace("\x00", ' ', $frame_name).'" to "'.$iTunesBrokenFrameNameFixed.'" for parsing.'); + $frame_name = $iTunesBrokenFrameNameFixed; + } + if (($frame_size <= strlen($framedata)) && ($this->IsValidID3v2FrameName($frame_name, $id3v2_majorversion))) { + unset($parsedFrame); + $parsedFrame['frame_name'] = $frame_name; + $parsedFrame['frame_flags_raw'] = $frame_flags; + $parsedFrame['data'] = substr($framedata, 0, $frame_size); + $parsedFrame['datalength'] = getid3_lib::CastAsInt($frame_size); + $parsedFrame['dataoffset'] = $framedataoffset; + + $this->ParseID3v2Frame($parsedFrame); + $thisfile_id3v2[$frame_name][] = $parsedFrame; + + $framedata = substr($framedata, $frame_size); + } else { // invalid frame length or FrameID + + if ($frame_size <= strlen($framedata)) { + if ($this->IsValidID3v2FrameName(substr($framedata, $frame_size, 4), $id3v2_majorversion)) { + + // next frame is valid, just skip the current frame + $framedata = substr($framedata, $frame_size); + $this->warning('Next ID3v2 frame is valid, skipping current frame.'); + } else { + + // next frame is invalid too, abort processing + //unset($framedata); + $framedata = null; + $this->error('Next ID3v2 frame is also invalid, aborting processing.'); + } + } elseif ($frame_size == strlen($framedata)) { + + // this is the last frame, just skip + $this->warning('This was the last ID3v2 frame.'); + } else { + + // next frame is invalid too, abort processing + //unset($framedata); + $framedata = null; + $this->warning('Invalid ID3v2 frame size, aborting.'); + } + if (! $this->IsValidID3v2FrameName($frame_name, $id3v2_majorversion)) { + switch ($frame_name) { + case "\x00\x00".'MP': + case "\x00".'MP3': + case ' MP3': + case 'MP3e': + case "\x00".'MP': + case ' MP': + case 'MP3': + $this->warning('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: !IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))). [Note: this particular error has been known to happen with tags edited by "MP3ext (www.mutschler.de/mp3ext/)"]'); + break; + + default: + $this->warning('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: !IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))).'); + break; + } + } elseif (! isset($framedata) || ($frame_size > strlen($framedata))) { + $this->error('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: $frame_size ('.$frame_size.') > strlen($framedata) ('.(isset($framedata) ? strlen($framedata) : 'null').')).'); + } else { + $this->error('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag).'); + } + } + $framedataoffset += ($frame_size + $this->ID3v2HeaderLength($id3v2_majorversion)); + } + } + + // Footer + + // The footer is a copy of the header, but with a different identifier. + // ID3v2 identifier "3DI" + // ID3v2 version $04 00 + // ID3v2 flags %abcd0000 + // ID3v2 size 4 * %0xxxxxxx + + if (isset($thisfile_id3v2_flags['isfooter']) && $thisfile_id3v2_flags['isfooter']) { + $footer = $this->fread(10); + if (substr($footer, 0, 3) == '3DI') { + $thisfile_id3v2['footer'] = true; + $thisfile_id3v2['majorversion_footer'] = ord($footer[3]); + $thisfile_id3v2['minorversion_footer'] = ord($footer[4]); + } + if ($thisfile_id3v2['majorversion_footer'] <= 4) { + $id3_flags = ord(substr($footer[5])); + $thisfile_id3v2_flags['unsynch_footer'] = (bool) ($id3_flags & 0x80); + $thisfile_id3v2_flags['extfoot_footer'] = (bool) ($id3_flags & 0x40); + $thisfile_id3v2_flags['experim_footer'] = (bool) ($id3_flags & 0x20); + $thisfile_id3v2_flags['isfooter_footer'] = (bool) ($id3_flags & 0x10); + + $thisfile_id3v2['footerlength'] = getid3_lib::BigEndian2Int(substr($footer, 6, 4), 1); + } + } // end footer + + if (isset($thisfile_id3v2['comments']['genre'])) { + $genres = []; + foreach ($thisfile_id3v2['comments']['genre'] as $key => $value) { + foreach ($this->ParseID3v2GenreString($value) as $genre) { + $genres[] = $genre; + } + } + $thisfile_id3v2['comments']['genre'] = array_unique($genres); + unset($key, $value, $genres, $genre); + } + + if (isset($thisfile_id3v2['comments']['track'])) { + foreach ($thisfile_id3v2['comments']['track'] as $key => $value) { + if (strstr($value, '/')) { + list($thisfile_id3v2['comments']['tracknum'][$key], $thisfile_id3v2['comments']['totaltracks'][$key]) = explode('/', $thisfile_id3v2['comments']['track'][$key]); + } + } + } + + if (! isset($thisfile_id3v2['comments']['year']) && ! empty($thisfile_id3v2['comments']['recording_time'][0]) && preg_match('#^([0-9]{4})#', trim($thisfile_id3v2['comments']['recording_time'][0]), $matches)) { + $thisfile_id3v2['comments']['year'] = [$matches[1]]; + } + + if (! empty($thisfile_id3v2['TXXX'])) { + // MediaMonkey does this, maybe others: write a blank RGAD frame, but put replay-gain adjustment values in TXXX frames + foreach ($thisfile_id3v2['TXXX'] as $txxx_array) { + switch ($txxx_array['description']) { + case 'replaygain_track_gain': + if (empty($info['replay_gain']['track']['adjustment']) && ! empty($txxx_array['data'])) { + $info['replay_gain']['track']['adjustment'] = floatval(trim(str_replace('dB', '', $txxx_array['data']))); + } + break; + case 'replaygain_track_peak': + if (empty($info['replay_gain']['track']['peak']) && ! empty($txxx_array['data'])) { + $info['replay_gain']['track']['peak'] = floatval($txxx_array['data']); + } + break; + case 'replaygain_album_gain': + if (empty($info['replay_gain']['album']['adjustment']) && ! empty($txxx_array['data'])) { + $info['replay_gain']['album']['adjustment'] = floatval(trim(str_replace('dB', '', $txxx_array['data']))); + } + break; + } + } + } + + // Set avdataoffset + $info['avdataoffset'] = $thisfile_id3v2['headerlength']; + if (isset($thisfile_id3v2['footer'])) { + $info['avdataoffset'] += 10; + } + + return true; + } + + public function ParseID3v2GenreString($genrestring) + { + // Parse genres into arrays of genreName and genreID + // ID3v2.2.x, ID3v2.3.x: '(21)' or '(4)Eurodisco' or '(51)(39)' or '(55)((I think...)' + // ID3v2.4.x: '21' $00 'Eurodisco' $00 + $clean_genres = []; + + // hack-fixes for some badly-written ID3v2.3 taggers, while trying not to break correctly-written tags + if (($this->getid3->info['id3v2']['majorversion'] == 3) && ! preg_match('#[\x00]#', $genrestring)) { + // note: MusicBrainz Picard incorrectly stores plaintext genres separated by "/" when writing in ID3v2.3 mode, hack-fix here: + // replace / with NULL, then replace back the two ID3v1 genres that legitimately have "/" as part of the single genre name + if (preg_match('#/#', $genrestring)) { + $genrestring = str_replace('/', "\x00", $genrestring); + $genrestring = str_replace('Pop'."\x00".'Funk', 'Pop/Funk', $genrestring); + $genrestring = str_replace('Rock'."\x00".'Rock', 'Folk/Rock', $genrestring); + } + + // some other taggers separate multiple genres with semicolon, e.g. "Heavy Metal;Thrash Metal;Metal" + if (preg_match('#;#', $genrestring)) { + $genrestring = str_replace(';', "\x00", $genrestring); + } + } + + if (strpos($genrestring, "\x00") === false) { + $genrestring = preg_replace('#\(([0-9]{1,3})\)#', '$1'."\x00", $genrestring); + } + + $genre_elements = explode("\x00", $genrestring); + foreach ($genre_elements as $element) { + $element = trim($element); + if ($element) { + if (preg_match('#^[0-9]{1,3}#', $element)) { + $clean_genres[] = getid3_id3v1::LookupGenreName($element); + } else { + $clean_genres[] = str_replace('((', '(', $element); + } + } + } + + return $clean_genres; + } + + public function ParseID3v2Frame(&$parsedFrame) + { + + // shortcuts + $info = &$this->getid3->info; + $id3v2_majorversion = $info['id3v2']['majorversion']; + + $parsedFrame['framenamelong'] = $this->FrameNameLongLookup($parsedFrame['frame_name']); + if (empty($parsedFrame['framenamelong'])) { + unset($parsedFrame['framenamelong']); + } + $parsedFrame['framenameshort'] = $this->FrameNameShortLookup($parsedFrame['frame_name']); + if (empty($parsedFrame['framenameshort'])) { + unset($parsedFrame['framenameshort']); + } + + if ($id3v2_majorversion >= 3) { // frame flags are not part of the ID3v2.2 standard + if ($id3v2_majorversion == 3) { + // Frame Header Flags + // %abc00000 %ijk00000 + $parsedFrame['flags']['TagAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x8000); // a - Tag alter preservation + $parsedFrame['flags']['FileAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x4000); // b - File alter preservation + $parsedFrame['flags']['ReadOnly'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x2000); // c - Read only + $parsedFrame['flags']['compression'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0080); // i - Compression + $parsedFrame['flags']['Encryption'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0040); // j - Encryption + $parsedFrame['flags']['GroupingIdentity'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0020); // k - Grouping identity + } elseif ($id3v2_majorversion == 4) { + // Frame Header Flags + // %0abc0000 %0h00kmnp + $parsedFrame['flags']['TagAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x4000); // a - Tag alter preservation + $parsedFrame['flags']['FileAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x2000); // b - File alter preservation + $parsedFrame['flags']['ReadOnly'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x1000); // c - Read only + $parsedFrame['flags']['GroupingIdentity'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0040); // h - Grouping identity + $parsedFrame['flags']['compression'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0008); // k - Compression + $parsedFrame['flags']['Encryption'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0004); // m - Encryption + $parsedFrame['flags']['Unsynchronisation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0002); // n - Unsynchronisation + $parsedFrame['flags']['DataLengthIndicator'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x0001); // p - Data length indicator + + // Frame-level de-unsynchronisation - ID3v2.4 + if ($parsedFrame['flags']['Unsynchronisation']) { + $parsedFrame['data'] = $this->DeUnsynchronise($parsedFrame['data']); + } + + if ($parsedFrame['flags']['DataLengthIndicator']) { + $parsedFrame['data_length_indicator'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 4), 1); + $parsedFrame['data'] = substr($parsedFrame['data'], 4); + } + } + + // Frame-level de-compression + if ($parsedFrame['flags']['compression']) { + $parsedFrame['decompressed_size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 4)); + if (! function_exists('gzuncompress')) { + $this->warning('gzuncompress() support required to decompress ID3v2 frame "'.$parsedFrame['frame_name'].'"'); + } else { + if ($decompresseddata = @gzuncompress(substr($parsedFrame['data'], 4))) { + //if ($decompresseddata = @gzuncompress($parsedFrame['data'])) { + $parsedFrame['data'] = $decompresseddata; + unset($decompresseddata); + } else { + $this->warning('gzuncompress() failed on compressed contents of ID3v2 frame "'.$parsedFrame['frame_name'].'"'); + } + } + } + } + + if (! empty($parsedFrame['flags']['DataLengthIndicator'])) { + if ($parsedFrame['data_length_indicator'] != strlen($parsedFrame['data'])) { + $this->warning('ID3v2 frame "'.$parsedFrame['frame_name'].'" should be '.$parsedFrame['data_length_indicator'].' bytes long according to DataLengthIndicator, but found '.strlen($parsedFrame['data']).' bytes of data'); + } + } + + if (isset($parsedFrame['datalength']) && ($parsedFrame['datalength'] == 0)) { + $warning = 'Frame "'.$parsedFrame['frame_name'].'" at offset '.$parsedFrame['dataoffset'].' has no data portion'; + switch ($parsedFrame['frame_name']) { + case 'WCOM': + $warning .= ' (this is known to happen with files tagged by RioPort)'; + break; + + default: + break; + } + $this->warning($warning); + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'UFID')) || // 4.1 UFID Unique file identifier + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'UFI'))) { // 4.1 UFI Unique file identifier + // There may be more than one 'UFID' frame in a tag, + // but only one with the same 'Owner identifier'. + //
    + // Owner identifier $00 + // Identifier + $exploded = explode("\x00", $parsedFrame['data'], 2); + $parsedFrame['ownerid'] = (isset($exploded[0]) ? $exploded[0] : ''); + $parsedFrame['data'] = (isset($exploded[1]) ? $exploded[1] : ''); + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'TXXX')) || // 4.2.2 TXXX User defined text information frame + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'TXX'))) { // 4.2.2 TXX User defined text information frame + // There may be more than one 'TXXX' frame in each tag, + // but only one with the same description. + //
    + // Text encoding $xx + // Description $00 (00) + // Value + + $frame_offset = 0; + $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); + if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; + } + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { + $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 + } + $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (in_array($frame_description, ["\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"])) { + // if description only contains a BOM or terminator then make it blank + $frame_description = ''; + } + $parsedFrame['encodingid'] = $frame_textencoding; + $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); + + $parsedFrame['description'] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $frame_description)); + $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); + if (! empty($parsedFrame['framenameshort']) && ! empty($parsedFrame['data'])) { + $commentkey = ($parsedFrame['description'] ? $parsedFrame['description'] : (isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) ? count($info['id3v2']['comments'][$parsedFrame['framenameshort']]) : 0)); + if (! isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) || ! array_key_exists($commentkey, $info['id3v2']['comments'][$parsedFrame['framenameshort']])) { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][$commentkey] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data'])); + } else { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data'])); + } + } + //unset($parsedFrame['data']); do not unset, may be needed elsewhere, e.g. for replaygain + } elseif ($parsedFrame['frame_name'][0] == 'T') { // 4.2. T??[?] Text information frame + // There may only be one text information frame of its kind in an tag. + //
    + // Text encoding $xx + // Information + + $frame_offset = 0; + $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + } + + $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); + + $parsedFrame['encodingid'] = $frame_textencoding; + $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); + + if (! empty($parsedFrame['framenameshort']) && ! empty($parsedFrame['data'])) { + // ID3v2.3 specs say that TPE1 (and others) can contain multiple artist values separated with / + // This of course breaks when an artist name contains slash character, e.g. "AC/DC" + // MP3tag (maybe others) implement alternative system where multiple artists are null-separated, which makes more sense + // getID3 will split null-separated artists into multiple artists and leave slash-separated ones to the user + switch ($parsedFrame['encoding']) { + case 'UTF-16': + case 'UTF-16BE': + case 'UTF-16LE': + $wordsize = 2; + break; + case 'ISO-8859-1': + case 'UTF-8': + default: + $wordsize = 1; + break; + } + $Txxx_elements = []; + $Txxx_elements_start_offset = 0; + for ($i = 0; $i < strlen($parsedFrame['data']); $i += $wordsize) { + if (substr($parsedFrame['data'], $i, $wordsize) == str_repeat("\x00", $wordsize)) { + $Txxx_elements[] = substr($parsedFrame['data'], $Txxx_elements_start_offset, $i - $Txxx_elements_start_offset); + $Txxx_elements_start_offset = $i + $wordsize; + } + } + $Txxx_elements[] = substr($parsedFrame['data'], $Txxx_elements_start_offset, $i - $Txxx_elements_start_offset); + foreach ($Txxx_elements as $Txxx_element) { + $string = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $Txxx_element); + if (! empty($string)) { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $string; + } + } + unset($string, $wordsize, $i, $Txxx_elements, $Txxx_element, $Txxx_elements_start_offset); + } + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'WXXX')) || // 4.3.2 WXXX User defined URL link frame + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'WXX'))) { // 4.3.2 WXX User defined URL link frame + // There may be more than one 'WXXX' frame in each tag, + // but only one with the same description + //
    + // Text encoding $xx + // Description $00 (00) + // URL + + $frame_offset = 0; + $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); + if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; + } + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { + $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 + } + $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (in_array($frame_description, ["\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"])) { + // if description only contains a BOM or terminator then make it blank + $frame_description = ''; + } + $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); + + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { + $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 + } + if ($frame_terminatorpos) { + // there are null bytes after the data - this is not according to spec + // only use data up to first null byte + $frame_urldata = (string) substr($parsedFrame['data'], 0, $frame_terminatorpos); + } else { + // no null bytes following data, just use all data + $frame_urldata = (string) $parsedFrame['data']; + } + + $parsedFrame['encodingid'] = $frame_textencoding; + $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); + + $parsedFrame['url'] = $frame_urldata; + $parsedFrame['description'] = $frame_description; + if (! empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['url']); + } + unset($parsedFrame['data']); + } elseif ($parsedFrame['frame_name'][0] == 'W') { // 4.3. W??? URL link frames + // There may only be one URL link frame of its kind in a tag, + // except when stated otherwise in the frame description + //
    + // URL + + $parsedFrame['url'] = trim($parsedFrame['data']); + if (! empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['url']; + } + unset($parsedFrame['data']); + } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'IPLS')) || // 4.4 IPLS Involved people list (ID3v2.3 only) + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'IPL'))) { // 4.4 IPL Involved people list (ID3v2.2 only) + // http://id3.org/id3v2.3.0#sec4.4 + // There may only be one 'IPL' frame in each tag + //
    + // Text encoding $xx + // People list strings + + $frame_offset = 0; + $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + } + $parsedFrame['encodingid'] = $frame_textencoding; + $parsedFrame['encoding'] = $this->TextEncodingNameLookup($parsedFrame['encodingid']); + $parsedFrame['data_raw'] = (string) substr($parsedFrame['data'], $frame_offset); + + // http://www.getid3.org/phpBB3/viewtopic.php?t=1369 + // "this tag typically contains null terminated strings, which are associated in pairs" + // "there are users that use the tag incorrectly" + $IPLS_parts = []; + if (strpos($parsedFrame['data_raw'], "\x00") !== false) { + $IPLS_parts_unsorted = []; + if (((strlen($parsedFrame['data_raw']) % 2) == 0) && ((substr($parsedFrame['data_raw'], 0, 2) == "\xFF\xFE") || (substr($parsedFrame['data_raw'], 0, 2) == "\xFE\xFF"))) { + // UTF-16, be careful looking for null bytes since most 2-byte characters may contain one; you need to find twin null bytes, and on even padding + $thisILPS = ''; + for ($i = 0; $i < strlen($parsedFrame['data_raw']); $i += 2) { + $twobytes = substr($parsedFrame['data_raw'], $i, 2); + if ($twobytes === "\x00\x00") { + $IPLS_parts_unsorted[] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $thisILPS); + $thisILPS = ''; + } else { + $thisILPS .= $twobytes; + } + } + if (strlen($thisILPS) > 2) { // 2-byte BOM + $IPLS_parts_unsorted[] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $thisILPS); + } + } else { + // ISO-8859-1 or UTF-8 or other single-byte-null character set + $IPLS_parts_unsorted = explode("\x00", $parsedFrame['data_raw']); + } + if (count($IPLS_parts_unsorted) == 1) { + // just a list of names, e.g. "Dino Baptiste, Jimmy Copley, John Gordon, Bernie Marsden, Sharon Watson" + foreach ($IPLS_parts_unsorted as $key => $value) { + $IPLS_parts_sorted = preg_split('#[;,\\r\\n\\t]#', $value); + $position = ''; + foreach ($IPLS_parts_sorted as $person) { + $IPLS_parts[] = ['position'=>$position, 'person'=>$person]; + } + } + } elseif ((count($IPLS_parts_unsorted) % 2) == 0) { + $position = ''; + $person = ''; + foreach ($IPLS_parts_unsorted as $key => $value) { + if (($key % 2) == 0) { + $position = $value; + } else { + $person = $value; + $IPLS_parts[] = ['position'=>$position, 'person'=>$person]; + $position = ''; + $person = ''; + } + } + } else { + foreach ($IPLS_parts_unsorted as $key => $value) { + $IPLS_parts[] = [$value]; + } + } + } else { + $IPLS_parts = preg_split('#[;,\\r\\n\\t]#', $parsedFrame['data_raw']); + } + $parsedFrame['data'] = $IPLS_parts; + + if (! empty($parsedFrame['framenameshort']) && ! empty($parsedFrame['data'])) { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['data']; + } + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'MCDI')) || // 4.4 MCDI Music CD identifier + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'MCI'))) { // 4.5 MCI Music CD identifier + // There may only be one 'MCDI' frame in each tag + //
    + // CD TOC + + if (! empty($parsedFrame['framenameshort']) && ! empty($parsedFrame['data'])) { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['data']; + } + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'ETCO')) || // 4.5 ETCO Event timing codes + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'ETC'))) { // 4.6 ETC Event timing codes + // There may only be one 'ETCO' frame in each tag + //
    + // Time stamp format $xx + // Where time stamp format is: + // $01 (32-bit value) MPEG frames from beginning of file + // $02 (32-bit value) milliseconds from beginning of file + // Followed by a list of key events in the following format: + // Type of event $xx + // Time stamp $xx (xx ...) + // The 'Time stamp' is set to zero if directly at the beginning of the sound + // or after the previous event. All events MUST be sorted in chronological order. + + $frame_offset = 0; + $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + + while ($frame_offset < strlen($parsedFrame['data'])) { + $parsedFrame['typeid'] = substr($parsedFrame['data'], $frame_offset++, 1); + $parsedFrame['type'] = $this->ETCOEventLookup($parsedFrame['typeid']); + $parsedFrame['timestamp'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + $frame_offset += 4; + } + unset($parsedFrame['data']); + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'MLLT')) || // 4.6 MLLT MPEG location lookup table + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'MLL'))) { // 4.7 MLL MPEG location lookup table + // There may only be one 'MLLT' frame in each tag + //
    + // MPEG frames between reference $xx xx + // Bytes between reference $xx xx xx + // Milliseconds between reference $xx xx xx + // Bits for bytes deviation $xx + // Bits for milliseconds dev. $xx + // Then for every reference the following data is included; + // Deviation in bytes %xxx.... + // Deviation in milliseconds %xxx.... + + $frame_offset = 0; + $parsedFrame['framesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 2)); + $parsedFrame['bytesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 2, 3)); + $parsedFrame['msbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 5, 3)); + $parsedFrame['bitsforbytesdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 8, 1)); + $parsedFrame['bitsformsdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 9, 1)); + $parsedFrame['data'] = substr($parsedFrame['data'], 10); + while ($frame_offset < strlen($parsedFrame['data'])) { + $deviationbitstream .= getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1)); + } + $reference_counter = 0; + while (strlen($deviationbitstream) > 0) { + $parsedFrame[$reference_counter]['bytedeviation'] = bindec(substr($deviationbitstream, 0, $parsedFrame['bitsforbytesdeviation'])); + $parsedFrame[$reference_counter]['msdeviation'] = bindec(substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'], $parsedFrame['bitsformsdeviation'])); + $deviationbitstream = substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'] + $parsedFrame['bitsformsdeviation']); + $reference_counter++; + } + unset($parsedFrame['data']); + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'SYTC')) || // 4.7 SYTC Synchronised tempo codes + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'STC'))) { // 4.8 STC Synchronised tempo codes + // There may only be one 'SYTC' frame in each tag + //
    + // Time stamp format $xx + // Tempo data + // Where time stamp format is: + // $01 (32-bit value) MPEG frames from beginning of file + // $02 (32-bit value) milliseconds from beginning of file + + $frame_offset = 0; + $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $timestamp_counter = 0; + while ($frame_offset < strlen($parsedFrame['data'])) { + $parsedFrame[$timestamp_counter]['tempo'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + if ($parsedFrame[$timestamp_counter]['tempo'] == 255) { + $parsedFrame[$timestamp_counter]['tempo'] += ord(substr($parsedFrame['data'], $frame_offset++, 1)); + } + $parsedFrame[$timestamp_counter]['timestamp'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + $frame_offset += 4; + $timestamp_counter++; + } + unset($parsedFrame['data']); + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'USLT')) || // 4.8 USLT Unsynchronised lyric/text transcription + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'ULT'))) { // 4.9 ULT Unsynchronised lyric/text transcription + // There may be more than one 'Unsynchronised lyrics/text transcription' frame + // in each tag, but only one with the same language and content descriptor. + //
    + // Text encoding $xx + // Language $xx xx xx + // Content descriptor $00 (00) + // Lyrics/text + + $frame_offset = 0; + $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); + if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; + } + $frame_language = substr($parsedFrame['data'], $frame_offset, 3); + $frame_offset += 3; + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { + $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 + } + $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (in_array($frame_description, ["\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"])) { + // if description only contains a BOM or terminator then make it blank + $frame_description = ''; + } + $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); + + $parsedFrame['encodingid'] = $frame_textencoding; + $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); + + $parsedFrame['language'] = $frame_language; + $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); + $parsedFrame['description'] = $frame_description; + if (! empty($parsedFrame['framenameshort']) && ! empty($parsedFrame['data'])) { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); + } + unset($parsedFrame['data']); + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'SYLT')) || // 4.9 SYLT Synchronised lyric/text + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'SLT'))) { // 4.10 SLT Synchronised lyric/text + // There may be more than one 'SYLT' frame in each tag, + // but only one with the same language and content descriptor. + //
    + // Text encoding $xx + // Language $xx xx xx + // Time stamp format $xx + // $01 (32-bit value) MPEG frames from beginning of file + // $02 (32-bit value) milliseconds from beginning of file + // Content type $xx + // Content descriptor $00 (00) + // Terminated text to be synced (typically a syllable) + // Sync identifier (terminator to above string) $00 (00) + // Time stamp $xx (xx ...) + + $frame_offset = 0; + $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); + if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; + } + $frame_language = substr($parsedFrame['data'], $frame_offset, 3); + $frame_offset += 3; + $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['contenttypeid'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['contenttype'] = $this->SYTLContentTypeLookup($parsedFrame['contenttypeid']); + $parsedFrame['encodingid'] = $frame_textencoding; + $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); + + $parsedFrame['language'] = $frame_language; + $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); + + $timestampindex = 0; + $frame_remainingdata = substr($parsedFrame['data'], $frame_offset); + while (strlen($frame_remainingdata)) { + $frame_offset = 0; + $frame_terminatorpos = strpos($frame_remainingdata, $frame_textencoding_terminator); + if ($frame_terminatorpos === false) { + $frame_remainingdata = ''; + } else { + if (ord(substr($frame_remainingdata, $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { + $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 + } + $parsedFrame['lyrics'][$timestampindex]['data'] = substr($frame_remainingdata, $frame_offset, $frame_terminatorpos - $frame_offset); + + $frame_remainingdata = substr($frame_remainingdata, $frame_terminatorpos + strlen($frame_textencoding_terminator)); + if (($timestampindex == 0) && (ord($frame_remainingdata[0]) != 0)) { + // timestamp probably omitted for first data item + } else { + $parsedFrame['lyrics'][$timestampindex]['timestamp'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 0, 4)); + $frame_remainingdata = substr($frame_remainingdata, 4); + } + $timestampindex++; + } + } + unset($parsedFrame['data']); + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'COMM')) || // 4.10 COMM Comments + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'COM'))) { // 4.11 COM Comments + // There may be more than one comment frame in each tag, + // but only one with the same language and content descriptor. + //
    + // Text encoding $xx + // Language $xx xx xx + // Short content descrip. $00 (00) + // The actual text + + if (strlen($parsedFrame['data']) < 5) { + $this->warning('Invalid data (too short) for "'.$parsedFrame['frame_name'].'" frame at offset '.$parsedFrame['dataoffset']); + } else { + $frame_offset = 0; + $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); + if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; + } + $frame_language = substr($parsedFrame['data'], $frame_offset, 3); + $frame_offset += 3; + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { + $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 + } + $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (in_array($frame_description, ["\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"])) { + // if description only contains a BOM or terminator then make it blank + $frame_description = ''; + } + $frame_text = (string) substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); + + $parsedFrame['encodingid'] = $frame_textencoding; + $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); + + $parsedFrame['language'] = $frame_language; + $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); + $parsedFrame['description'] = $frame_description; + $parsedFrame['data'] = $frame_text; + if (! empty($parsedFrame['framenameshort']) && ! empty($parsedFrame['data'])) { + $commentkey = ($parsedFrame['description'] ? $parsedFrame['description'] : (! empty($info['id3v2']['comments'][$parsedFrame['framenameshort']]) ? count($info['id3v2']['comments'][$parsedFrame['framenameshort']]) : 0)); + if (! isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) || ! array_key_exists($commentkey, $info['id3v2']['comments'][$parsedFrame['framenameshort']])) { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][$commentkey] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); + } else { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); + } + } + } + } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'RVA2')) { // 4.11 RVA2 Relative volume adjustment (2) (ID3v2.4+ only) + // There may be more than one 'RVA2' frame in each tag, + // but only one with the same identification string + //
    + // Identification $00 + // The 'identification' string is used to identify the situation and/or + // device where this adjustment should apply. The following is then + // repeated for every channel: + // Type of channel $xx + // Volume adjustment $xx xx + // Bits representing peak $xx + // Peak volume $xx (xx ...) + + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00"); + $frame_idstring = substr($parsedFrame['data'], 0, $frame_terminatorpos); + if (ord($frame_idstring) === 0) { + $frame_idstring = ''; + } + $frame_remainingdata = substr($parsedFrame['data'], $frame_terminatorpos + strlen("\x00")); + $parsedFrame['description'] = $frame_idstring; + $RVA2channelcounter = 0; + while (strlen($frame_remainingdata) >= 5) { + $frame_offset = 0; + $frame_channeltypeid = ord(substr($frame_remainingdata, $frame_offset++, 1)); + $parsedFrame[$RVA2channelcounter]['channeltypeid'] = $frame_channeltypeid; + $parsedFrame[$RVA2channelcounter]['channeltype'] = $this->RVA2ChannelTypeLookup($frame_channeltypeid); + $parsedFrame[$RVA2channelcounter]['volumeadjust'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, $frame_offset, 2), false, true); // 16-bit signed + $frame_offset += 2; + $parsedFrame[$RVA2channelcounter]['bitspeakvolume'] = ord(substr($frame_remainingdata, $frame_offset++, 1)); + if (($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] < 1) || ($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] > 4)) { + $this->warning('ID3v2::RVA2 frame['.$RVA2channelcounter.'] contains invalid '.$parsedFrame[$RVA2channelcounter]['bitspeakvolume'].'-byte bits-representing-peak value'); + break; + } + $frame_bytespeakvolume = ceil($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] / 8); + $parsedFrame[$RVA2channelcounter]['peakvolume'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, $frame_offset, $frame_bytespeakvolume)); + $frame_remainingdata = substr($frame_remainingdata, $frame_offset + $frame_bytespeakvolume); + $RVA2channelcounter++; + } + unset($parsedFrame['data']); + } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'RVAD')) || // 4.12 RVAD Relative volume adjustment (ID3v2.3 only) + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'RVA'))) { // 4.12 RVA Relative volume adjustment (ID3v2.2 only) + // There may only be one 'RVA' frame in each tag + //
    + // ID3v2.2 => Increment/decrement %000000ba + // ID3v2.3 => Increment/decrement %00fedcba + // Bits used for volume descr. $xx + // Relative volume change, right $xx xx (xx ...) // a + // Relative volume change, left $xx xx (xx ...) // b + // Peak volume right $xx xx (xx ...) + // Peak volume left $xx xx (xx ...) + // ID3v2.3 only, optional (not present in ID3v2.2): + // Relative volume change, right back $xx xx (xx ...) // c + // Relative volume change, left back $xx xx (xx ...) // d + // Peak volume right back $xx xx (xx ...) + // Peak volume left back $xx xx (xx ...) + // ID3v2.3 only, optional (not present in ID3v2.2): + // Relative volume change, center $xx xx (xx ...) // e + // Peak volume center $xx xx (xx ...) + // ID3v2.3 only, optional (not present in ID3v2.2): + // Relative volume change, bass $xx xx (xx ...) // f + // Peak volume bass $xx xx (xx ...) + + $frame_offset = 0; + $frame_incrdecrflags = getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['incdec']['right'] = (bool) substr($frame_incrdecrflags, 6, 1); + $parsedFrame['incdec']['left'] = (bool) substr($frame_incrdecrflags, 7, 1); + $parsedFrame['bitsvolume'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_bytesvolume = ceil($parsedFrame['bitsvolume'] / 8); + $parsedFrame['volumechange']['right'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); + if ($parsedFrame['incdec']['right'] === false) { + $parsedFrame['volumechange']['right'] *= -1; + } + $frame_offset += $frame_bytesvolume; + $parsedFrame['volumechange']['left'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); + if ($parsedFrame['incdec']['left'] === false) { + $parsedFrame['volumechange']['left'] *= -1; + } + $frame_offset += $frame_bytesvolume; + $parsedFrame['peakvolume']['right'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); + $frame_offset += $frame_bytesvolume; + $parsedFrame['peakvolume']['left'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); + $frame_offset += $frame_bytesvolume; + if ($id3v2_majorversion == 3) { + $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset); + if (strlen($parsedFrame['data']) > 0) { + $parsedFrame['incdec']['rightrear'] = (bool) substr($frame_incrdecrflags, 4, 1); + $parsedFrame['incdec']['leftrear'] = (bool) substr($frame_incrdecrflags, 5, 1); + $parsedFrame['volumechange']['rightrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); + if ($parsedFrame['incdec']['rightrear'] === false) { + $parsedFrame['volumechange']['rightrear'] *= -1; + } + $frame_offset += $frame_bytesvolume; + $parsedFrame['volumechange']['leftrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); + if ($parsedFrame['incdec']['leftrear'] === false) { + $parsedFrame['volumechange']['leftrear'] *= -1; + } + $frame_offset += $frame_bytesvolume; + $parsedFrame['peakvolume']['rightrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); + $frame_offset += $frame_bytesvolume; + $parsedFrame['peakvolume']['leftrear'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); + $frame_offset += $frame_bytesvolume; + } + $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset); + if (strlen($parsedFrame['data']) > 0) { + $parsedFrame['incdec']['center'] = (bool) substr($frame_incrdecrflags, 3, 1); + $parsedFrame['volumechange']['center'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); + if ($parsedFrame['incdec']['center'] === false) { + $parsedFrame['volumechange']['center'] *= -1; + } + $frame_offset += $frame_bytesvolume; + $parsedFrame['peakvolume']['center'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); + $frame_offset += $frame_bytesvolume; + } + $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset); + if (strlen($parsedFrame['data']) > 0) { + $parsedFrame['incdec']['bass'] = (bool) substr($frame_incrdecrflags, 2, 1); + $parsedFrame['volumechange']['bass'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); + if ($parsedFrame['incdec']['bass'] === false) { + $parsedFrame['volumechange']['bass'] *= -1; + } + $frame_offset += $frame_bytesvolume; + $parsedFrame['peakvolume']['bass'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume)); + $frame_offset += $frame_bytesvolume; + } + } + unset($parsedFrame['data']); + } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'EQU2')) { // 4.12 EQU2 Equalisation (2) (ID3v2.4+ only) + // There may be more than one 'EQU2' frame in each tag, + // but only one with the same identification string + //
    + // Interpolation method $xx + // $00 Band + // $01 Linear + // Identification $00 + // The following is then repeated for every adjustment point + // Frequency $xx xx + // Volume adjustment $xx xx + + $frame_offset = 0; + $frame_interpolationmethod = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_idstring = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (ord($frame_idstring) === 0) { + $frame_idstring = ''; + } + $parsedFrame['description'] = $frame_idstring; + $frame_remainingdata = substr($parsedFrame['data'], $frame_terminatorpos + strlen("\x00")); + while (strlen($frame_remainingdata)) { + $frame_frequency = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 0, 2)) / 2; + $parsedFrame['data'][$frame_frequency] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 2, 2), false, true); + $frame_remainingdata = substr($frame_remainingdata, 4); + } + $parsedFrame['interpolationmethod'] = $frame_interpolationmethod; + unset($parsedFrame['data']); + } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'EQUA')) || // 4.12 EQUA Equalisation (ID3v2.3 only) + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'EQU'))) { // 4.13 EQU Equalisation (ID3v2.2 only) + // There may only be one 'EQUA' frame in each tag + //
    + // Adjustment bits $xx + // This is followed by 2 bytes + ('adjustment bits' rounded up to the + // nearest byte) for every equalisation band in the following format, + // giving a frequency range of 0 - 32767Hz: + // Increment/decrement %x (MSB of the Frequency) + // Frequency (lower 15 bits) + // Adjustment $xx (xx ...) + + $frame_offset = 0; + $parsedFrame['adjustmentbits'] = substr($parsedFrame['data'], $frame_offset++, 1); + $frame_adjustmentbytes = ceil($parsedFrame['adjustmentbits'] / 8); + + $frame_remainingdata = (string) substr($parsedFrame['data'], $frame_offset); + while (strlen($frame_remainingdata) > 0) { + $frame_frequencystr = getid3_lib::BigEndian2Bin(substr($frame_remainingdata, 0, 2)); + $frame_incdec = (bool) substr($frame_frequencystr, 0, 1); + $frame_frequency = bindec(substr($frame_frequencystr, 1, 15)); + $parsedFrame[$frame_frequency]['incdec'] = $frame_incdec; + $parsedFrame[$frame_frequency]['adjustment'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 2, $frame_adjustmentbytes)); + if ($parsedFrame[$frame_frequency]['incdec'] === false) { + $parsedFrame[$frame_frequency]['adjustment'] *= -1; + } + $frame_remainingdata = substr($frame_remainingdata, 2 + $frame_adjustmentbytes); + } + unset($parsedFrame['data']); + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'RVRB')) || // 4.13 RVRB Reverb + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'REV'))) { // 4.14 REV Reverb + // There may only be one 'RVRB' frame in each tag. + //
    + // Reverb left (ms) $xx xx + // Reverb right (ms) $xx xx + // Reverb bounces, left $xx + // Reverb bounces, right $xx + // Reverb feedback, left to left $xx + // Reverb feedback, left to right $xx + // Reverb feedback, right to right $xx + // Reverb feedback, right to left $xx + // Premix left to right $xx + // Premix right to left $xx + + $frame_offset = 0; + $parsedFrame['left'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); + $frame_offset += 2; + $parsedFrame['right'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); + $frame_offset += 2; + $parsedFrame['bouncesL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['bouncesR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['feedbackLL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['feedbackLR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['feedbackRR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['feedbackRL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['premixLR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['premixRL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + unset($parsedFrame['data']); + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'APIC')) || // 4.14 APIC Attached picture + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'PIC'))) { // 4.15 PIC Attached picture + // There may be several pictures attached to one file, + // each in their individual 'APIC' frame, but only one + // with the same content descriptor + //
    + // Text encoding $xx + // ID3v2.3+ => MIME type $00 + // ID3v2.2 => Image format $xx xx xx + // Picture type $xx + // Description $00 (00) + // Picture data + + $frame_offset = 0; + $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); + if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; + } + + if ($id3v2_majorversion == 2 && strlen($parsedFrame['data']) > $frame_offset) { + $frame_imagetype = substr($parsedFrame['data'], $frame_offset, 3); + if (strtolower($frame_imagetype) == 'ima') { + // complete hack for mp3Rage (www.chaoticsoftware.com) that puts ID3v2.3-formatted + // MIME type instead of 3-char ID3v2.2-format image type (thanks xbhoffØpacbell*net) + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (ord($frame_mimetype) === 0) { + $frame_mimetype = ''; + } + $frame_imagetype = strtoupper(str_replace('image/', '', strtolower($frame_mimetype))); + if ($frame_imagetype == 'JPEG') { + $frame_imagetype = 'JPG'; + } + $frame_offset = $frame_terminatorpos + strlen("\x00"); + } else { + $frame_offset += 3; + } + } + if ($id3v2_majorversion > 2 && strlen($parsedFrame['data']) > $frame_offset) { + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (ord($frame_mimetype) === 0) { + $frame_mimetype = ''; + } + $frame_offset = $frame_terminatorpos + strlen("\x00"); + } + + $frame_picturetype = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + + if ($frame_offset >= $parsedFrame['datalength']) { + $this->warning('data portion of APIC frame is missing at offset '.($parsedFrame['dataoffset'] + 8 + $frame_offset)); + } else { + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { + $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 + } + $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (in_array($frame_description, ["\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"])) { + // if description only contains a BOM or terminator then make it blank + $frame_description = ''; + } + $parsedFrame['encodingid'] = $frame_textencoding; + $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); + + if ($id3v2_majorversion == 2) { + $parsedFrame['imagetype'] = $frame_imagetype; + } else { + $parsedFrame['mime'] = $frame_mimetype; + } + $parsedFrame['picturetypeid'] = $frame_picturetype; + $parsedFrame['picturetype'] = $this->APICPictureTypeLookup($frame_picturetype); + $parsedFrame['description'] = $frame_description; + $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); + $parsedFrame['datalength'] = strlen($parsedFrame['data']); + + $parsedFrame['image_mime'] = ''; + $imageinfo = []; + if ($imagechunkcheck = getid3_lib::GetDataImageSize($parsedFrame['data'], $imageinfo)) { + if (($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) { + $parsedFrame['image_mime'] = 'image/'.getid3_lib::ImageTypesLookup($imagechunkcheck[2]); + if ($imagechunkcheck[0]) { + $parsedFrame['image_width'] = $imagechunkcheck[0]; + } + if ($imagechunkcheck[1]) { + $parsedFrame['image_height'] = $imagechunkcheck[1]; + } + } + } + + do { + if ($this->getid3->option_save_attachments === false) { + // skip entirely + unset($parsedFrame['data']); + break; + } + if ($this->getid3->option_save_attachments === true) { + // great /* - } elseif (is_int($this->getid3->option_save_attachments)) { - if ($this->getid3->option_save_attachments < $parsedFrame['data_length']) { - // too big, skip - $this->warning('attachment at '.$frame_offset.' is too large to process inline ('.number_format($parsedFrame['data_length']).' bytes)'); - unset($parsedFrame['data']); - break; - } + } elseif (is_int($this->getid3->option_save_attachments)) { + if ($this->getid3->option_save_attachments < $parsedFrame['data_length']) { + // too big, skip + $this->warning('attachment at '.$frame_offset.' is too large to process inline ('.number_format($parsedFrame['data_length']).' bytes)'); + unset($parsedFrame['data']); + break; + } */ - } elseif (is_string($this->getid3->option_save_attachments)) { - $dir = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->getid3->option_save_attachments), DIRECTORY_SEPARATOR); - if (!is_dir($dir) || !is_writable($dir)) { - // cannot write, skip - $this->warning('attachment at '.$frame_offset.' cannot be saved to "'.$dir.'" (not writable)'); - unset($parsedFrame['data']); - break; - } - } - // if we get this far, must be OK - if (is_string($this->getid3->option_save_attachments)) { - $destination_filename = $dir.DIRECTORY_SEPARATOR.md5($info['filenamepath']).'_'.$frame_offset; - if (!file_exists($destination_filename) || is_writable($destination_filename)) { - file_put_contents($destination_filename, $parsedFrame['data']); - } else { - $this->warning('attachment at '.$frame_offset.' cannot be saved to "'.$destination_filename.'" (not writable)'); - } - $parsedFrame['data_filename'] = $destination_filename; - unset($parsedFrame['data']); - } else { - if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - if (!isset($info['id3v2']['comments']['picture'])) { - $info['id3v2']['comments']['picture'] = array(); - } - $comments_picture_data = array(); - foreach (array('data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength') as $picture_key) { - if (isset($parsedFrame[$picture_key])) { - $comments_picture_data[$picture_key] = $parsedFrame[$picture_key]; - } - } - $info['id3v2']['comments']['picture'][] = $comments_picture_data; - unset($comments_picture_data); - } - } - } while (false); - } - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'GEOB')) || // 4.15 GEOB General encapsulated object - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'GEO'))) { // 4.16 GEO General encapsulated object - // There may be more than one 'GEOB' frame in each tag, - // but only one with the same content descriptor - //
    - // Text encoding $xx - // MIME type $00 - // Filename $00 (00) - // Content description $00 (00) - // Encapsulated object - - $frame_offset = 0; - $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); - if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); - $frame_textencoding_terminator = "\x00"; - } - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_mimetype) === 0) { - $frame_mimetype = ''; - } - $frame_offset = $frame_terminatorpos + strlen("\x00"); - - $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { - $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 - } - $frame_filename = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_filename) === 0) { - $frame_filename = ''; - } - $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); - - $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { - $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 - } - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (in_array($frame_description, array("\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"))) { - // if description only contains a BOM or terminator then make it blank - $frame_description = ''; - } - $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); - - $parsedFrame['objectdata'] = (string) substr($parsedFrame['data'], $frame_offset); - $parsedFrame['encodingid'] = $frame_textencoding; - $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - - $parsedFrame['mime'] = $frame_mimetype; - $parsedFrame['filename'] = $frame_filename; - $parsedFrame['description'] = $frame_description; - unset($parsedFrame['data']); - - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'PCNT')) || // 4.16 PCNT Play counter - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'CNT'))) { // 4.17 CNT Play counter - // There may only be one 'PCNT' frame in each tag. - // When the counter reaches all one's, one byte is inserted in - // front of the counter thus making the counter eight bits bigger - //
    - // Counter $xx xx xx xx (xx ...) - - $parsedFrame['data'] = getid3_lib::BigEndian2Int($parsedFrame['data']); - - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'POPM')) || // 4.17 POPM Popularimeter - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'POP'))) { // 4.18 POP Popularimeter - // There may be more than one 'POPM' frame in each tag, - // but only one with the same email address - //
    - // Email to user $00 - // Rating $xx - // Counter $xx xx xx xx (xx ...) - - $frame_offset = 0; - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_emailaddress = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_emailaddress) === 0) { - $frame_emailaddress = ''; - } - $frame_offset = $frame_terminatorpos + strlen("\x00"); - $frame_rating = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['counter'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset)); - $parsedFrame['email'] = $frame_emailaddress; - $parsedFrame['rating'] = $frame_rating; - unset($parsedFrame['data']); - - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'RBUF')) || // 4.18 RBUF Recommended buffer size - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'BUF'))) { // 4.19 BUF Recommended buffer size - // There may only be one 'RBUF' frame in each tag - //
    - // Buffer size $xx xx xx - // Embedded info flag %0000000x - // Offset to next tag $xx xx xx xx - - $frame_offset = 0; - $parsedFrame['buffersize'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 3)); - $frame_offset += 3; - - $frame_embeddedinfoflags = getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['flags']['embededinfo'] = (bool) substr($frame_embeddedinfoflags, 7, 1); - $parsedFrame['nexttagoffset'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); - unset($parsedFrame['data']); - - - } elseif (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'CRM')) { // 4.20 Encrypted meta frame (ID3v2.2 only) - // There may be more than one 'CRM' frame in a tag, - // but only one with the same 'owner identifier' - //
    - // Owner identifier $00 (00) - // Content/explanation $00 (00) - // Encrypted datablock - - $frame_offset = 0; - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - $frame_offset = $frame_terminatorpos + strlen("\x00"); - - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (in_array($frame_description, array("\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"))) { - // if description only contains a BOM or terminator then make it blank - $frame_description = ''; - } - $frame_offset = $frame_terminatorpos + strlen("\x00"); - - $parsedFrame['ownerid'] = $frame_ownerid; - $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); - $parsedFrame['description'] = $frame_description; - unset($parsedFrame['data']); - - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'AENC')) || // 4.19 AENC Audio encryption - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'CRA'))) { // 4.21 CRA Audio encryption - // There may be more than one 'AENC' frames in a tag, - // but only one with the same 'Owner identifier' - //
    - // Owner identifier $00 - // Preview start $xx xx - // Preview length $xx xx - // Encryption info - - $frame_offset = 0; - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_ownerid) === 0) { - $frame_ownerid = ''; - } - $frame_offset = $frame_terminatorpos + strlen("\x00"); - $parsedFrame['ownerid'] = $frame_ownerid; - $parsedFrame['previewstart'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); - $frame_offset += 2; - $parsedFrame['previewlength'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); - $frame_offset += 2; - $parsedFrame['encryptioninfo'] = (string) substr($parsedFrame['data'], $frame_offset); - unset($parsedFrame['data']); - - - } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'LINK')) || // 4.20 LINK Linked information - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'LNK'))) { // 4.22 LNK Linked information - // There may be more than one 'LINK' frame in a tag, - // but only one with the same contents - //
    - // ID3v2.3+ => Frame identifier $xx xx xx xx - // ID3v2.2 => Frame identifier $xx xx xx - // URL $00 - // ID and additional data - - $frame_offset = 0; - if ($id3v2_majorversion == 2) { - $parsedFrame['frameid'] = substr($parsedFrame['data'], $frame_offset, 3); - $frame_offset += 3; - } else { - $parsedFrame['frameid'] = substr($parsedFrame['data'], $frame_offset, 4); - $frame_offset += 4; - } - - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_url = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_url) === 0) { - $frame_url = ''; - } - $frame_offset = $frame_terminatorpos + strlen("\x00"); - $parsedFrame['url'] = $frame_url; - - $parsedFrame['additionaldata'] = (string) substr($parsedFrame['data'], $frame_offset); - if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { - $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback_iso88591_utf8($parsedFrame['url']); - } - unset($parsedFrame['data']); - - - } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'POSS')) { // 4.21 POSS Position synchronisation frame (ID3v2.3+ only) - // There may only be one 'POSS' frame in each tag - //
    - // Time stamp format $xx - // Position $xx (xx ...) - - $frame_offset = 0; - $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['position'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset)); - unset($parsedFrame['data']); - - - } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'USER')) { // 4.22 USER Terms of use (ID3v2.3+ only) - // There may be more than one 'Terms of use' frame in a tag, - // but only one with the same 'Language' - //
    - // Text encoding $xx - // Language $xx xx xx - // The actual text - - $frame_offset = 0; - $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); - } - $frame_language = substr($parsedFrame['data'], $frame_offset, 3); - $frame_offset += 3; - $parsedFrame['language'] = $frame_language; - $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); - $parsedFrame['encodingid'] = $frame_textencoding; - $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - - $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); - if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); - } - unset($parsedFrame['data']); - - - } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'OWNE')) { // 4.23 OWNE Ownership frame (ID3v2.3+ only) - // There may only be one 'OWNE' frame in a tag - //
    - // Text encoding $xx - // Price paid $00 - // Date of purch. - // Seller - - $frame_offset = 0; - $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); - } - $parsedFrame['encodingid'] = $frame_textencoding; - $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_pricepaid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - $frame_offset = $frame_terminatorpos + strlen("\x00"); - - $parsedFrame['pricepaid']['currencyid'] = substr($frame_pricepaid, 0, 3); - $parsedFrame['pricepaid']['currency'] = $this->LookupCurrencyUnits($parsedFrame['pricepaid']['currencyid']); - $parsedFrame['pricepaid']['value'] = substr($frame_pricepaid, 3); - - $parsedFrame['purchasedate'] = substr($parsedFrame['data'], $frame_offset, 8); - if ($this->IsValidDateStampString($parsedFrame['purchasedate'])) { - $parsedFrame['purchasedateunix'] = mktime (0, 0, 0, substr($parsedFrame['purchasedate'], 4, 2), substr($parsedFrame['purchasedate'], 6, 2), substr($parsedFrame['purchasedate'], 0, 4)); - } - $frame_offset += 8; - - $parsedFrame['seller'] = (string) substr($parsedFrame['data'], $frame_offset); - unset($parsedFrame['data']); - - - } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'COMR')) { // 4.24 COMR Commercial frame (ID3v2.3+ only) - // There may be more than one 'commercial frame' in a tag, - // but no two may be identical - //
    - // Text encoding $xx - // Price string $00 - // Valid until - // Contact URL $00 - // Received as $xx - // Name of seller $00 (00) - // Description $00 (00) - // Picture MIME type $00 - // Seller logo - - $frame_offset = 0; - $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); - if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); - $frame_textencoding_terminator = "\x00"; - } - - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_pricestring = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - $frame_offset = $frame_terminatorpos + strlen("\x00"); - $frame_rawpricearray = explode('/', $frame_pricestring); - foreach ($frame_rawpricearray as $key => $val) { - $frame_currencyid = substr($val, 0, 3); - $parsedFrame['price'][$frame_currencyid]['currency'] = $this->LookupCurrencyUnits($frame_currencyid); - $parsedFrame['price'][$frame_currencyid]['value'] = substr($val, 3); - } - - $frame_datestring = substr($parsedFrame['data'], $frame_offset, 8); - $frame_offset += 8; - - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_contacturl = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - $frame_offset = $frame_terminatorpos + strlen("\x00"); - - $frame_receivedasid = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - - $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { - $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 - } - $frame_sellername = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_sellername) === 0) { - $frame_sellername = ''; - } - $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); - - $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { - $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 - } - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (in_array($frame_description, array("\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"))) { - // if description only contains a BOM or terminator then make it blank - $frame_description = ''; - } - $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); - - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - $frame_offset = $frame_terminatorpos + strlen("\x00"); - - $frame_sellerlogo = substr($parsedFrame['data'], $frame_offset); - - $parsedFrame['encodingid'] = $frame_textencoding; - $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - - $parsedFrame['pricevaliduntil'] = $frame_datestring; - $parsedFrame['contacturl'] = $frame_contacturl; - $parsedFrame['receivedasid'] = $frame_receivedasid; - $parsedFrame['receivedas'] = $this->COMRReceivedAsLookup($frame_receivedasid); - $parsedFrame['sellername'] = $frame_sellername; - $parsedFrame['description'] = $frame_description; - $parsedFrame['mime'] = $frame_mimetype; - $parsedFrame['logo'] = $frame_sellerlogo; - unset($parsedFrame['data']); - - - } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'ENCR')) { // 4.25 ENCR Encryption method registration (ID3v2.3+ only) - // There may be several 'ENCR' frames in a tag, - // but only one containing the same symbol - // and only one containing the same owner identifier - //
    - // Owner identifier $00 - // Method symbol $xx - // Encryption data - - $frame_offset = 0; - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_ownerid) === 0) { - $frame_ownerid = ''; - } - $frame_offset = $frame_terminatorpos + strlen("\x00"); - - $parsedFrame['ownerid'] = $frame_ownerid; - $parsedFrame['methodsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); - - - } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'GRID')) { // 4.26 GRID Group identification registration (ID3v2.3+ only) - - // There may be several 'GRID' frames in a tag, - // but only one containing the same symbol - // and only one containing the same owner identifier - //
    - // Owner identifier $00 - // Group symbol $xx - // Group dependent data - - $frame_offset = 0; - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_ownerid) === 0) { - $frame_ownerid = ''; - } - $frame_offset = $frame_terminatorpos + strlen("\x00"); - - $parsedFrame['ownerid'] = $frame_ownerid; - $parsedFrame['groupsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); - - - } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'PRIV')) { // 4.27 PRIV Private frame (ID3v2.3+ only) - // The tag may contain more than one 'PRIV' frame - // but only with different contents - //
    - // Owner identifier $00 - // The private data - - $frame_offset = 0; - $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_ownerid) === 0) { - $frame_ownerid = ''; - } - $frame_offset = $frame_terminatorpos + strlen("\x00"); - - $parsedFrame['ownerid'] = $frame_ownerid; - $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); - - - } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'SIGN')) { // 4.28 SIGN Signature frame (ID3v2.4+ only) - // There may be more than one 'signature frame' in a tag, - // but no two may be identical - //
    - // Group symbol $xx - // Signature - - $frame_offset = 0; - $parsedFrame['groupsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); - - - } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'SEEK')) { // 4.29 SEEK Seek frame (ID3v2.4+ only) - // There may only be one 'seek frame' in a tag - //
    - // Minimum offset to next tag $xx xx xx xx - - $frame_offset = 0; - $parsedFrame['data'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); - - - } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'ASPI')) { // 4.30 ASPI Audio seek point index (ID3v2.4+ only) - // There may only be one 'audio seek point index' frame in a tag - //
    - // Indexed data start (S) $xx xx xx xx - // Indexed data length (L) $xx xx xx xx - // Number of index points (N) $xx xx - // Bits per index point (b) $xx - // Then for every index point the following data is included: - // Fraction at index (Fi) $xx (xx) - - $frame_offset = 0; - $parsedFrame['datastart'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); - $frame_offset += 4; - $parsedFrame['indexeddatalength'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); - $frame_offset += 4; - $parsedFrame['indexpoints'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); - $frame_offset += 2; - $parsedFrame['bitsperpoint'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $frame_bytesperpoint = ceil($parsedFrame['bitsperpoint'] / 8); - for ($i = 0; $i < $parsedFrame['indexpoints']; $i++) { - $parsedFrame['indexes'][$i] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesperpoint)); - $frame_offset += $frame_bytesperpoint; - } - unset($parsedFrame['data']); - - } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'RGAD')) { // Replay Gain Adjustment - // http://privatewww.essex.ac.uk/~djmrob/replaygain/file_format_id3v2.html - // There may only be one 'RGAD' frame in a tag - //
    - // Peak Amplitude $xx $xx $xx $xx - // Radio Replay Gain Adjustment %aaabbbcd %dddddddd - // Audiophile Replay Gain Adjustment %aaabbbcd %dddddddd - // a - name code - // b - originator code - // c - sign bit - // d - replay gain adjustment - - $frame_offset = 0; - $parsedFrame['peakamplitude'] = getid3_lib::BigEndian2Float(substr($parsedFrame['data'], $frame_offset, 4)); - $frame_offset += 4; - $rg_track_adjustment = getid3_lib::Dec2Bin(substr($parsedFrame['data'], $frame_offset, 2)); - $frame_offset += 2; - $rg_album_adjustment = getid3_lib::Dec2Bin(substr($parsedFrame['data'], $frame_offset, 2)); - $frame_offset += 2; - $parsedFrame['raw']['track']['name'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 0, 3)); - $parsedFrame['raw']['track']['originator'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 3, 3)); - $parsedFrame['raw']['track']['signbit'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 6, 1)); - $parsedFrame['raw']['track']['adjustment'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 7, 9)); - $parsedFrame['raw']['album']['name'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 0, 3)); - $parsedFrame['raw']['album']['originator'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 3, 3)); - $parsedFrame['raw']['album']['signbit'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 6, 1)); - $parsedFrame['raw']['album']['adjustment'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 7, 9)); - $parsedFrame['track']['name'] = getid3_lib::RGADnameLookup($parsedFrame['raw']['track']['name']); - $parsedFrame['track']['originator'] = getid3_lib::RGADoriginatorLookup($parsedFrame['raw']['track']['originator']); - $parsedFrame['track']['adjustment'] = getid3_lib::RGADadjustmentLookup($parsedFrame['raw']['track']['adjustment'], $parsedFrame['raw']['track']['signbit']); - $parsedFrame['album']['name'] = getid3_lib::RGADnameLookup($parsedFrame['raw']['album']['name']); - $parsedFrame['album']['originator'] = getid3_lib::RGADoriginatorLookup($parsedFrame['raw']['album']['originator']); - $parsedFrame['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($parsedFrame['raw']['album']['adjustment'], $parsedFrame['raw']['album']['signbit']); - - $info['replay_gain']['track']['peak'] = $parsedFrame['peakamplitude']; - $info['replay_gain']['track']['originator'] = $parsedFrame['track']['originator']; - $info['replay_gain']['track']['adjustment'] = $parsedFrame['track']['adjustment']; - $info['replay_gain']['album']['originator'] = $parsedFrame['album']['originator']; - $info['replay_gain']['album']['adjustment'] = $parsedFrame['album']['adjustment']; - - unset($parsedFrame['data']); - - } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'CHAP')) { // CHAP Chapters frame (ID3v2.3+ only) - // http://id3.org/id3v2-chapters-1.0 - // (10 bytes) - // Element ID $00 - // Start time $xx xx xx xx - // End time $xx xx xx xx + } elseif (is_string($this->getid3->option_save_attachments)) { + $dir = rtrim(str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $this->getid3->option_save_attachments), DIRECTORY_SEPARATOR); + if (! is_dir($dir) || ! is_writable($dir)) { + // cannot write, skip + $this->warning('attachment at '.$frame_offset.' cannot be saved to "'.$dir.'" (not writable)'); + unset($parsedFrame['data']); + break; + } + } + // if we get this far, must be OK + if (is_string($this->getid3->option_save_attachments)) { + $destination_filename = $dir.DIRECTORY_SEPARATOR.md5($info['filenamepath']).'_'.$frame_offset; + if (! file_exists($destination_filename) || is_writable($destination_filename)) { + file_put_contents($destination_filename, $parsedFrame['data']); + } else { + $this->warning('attachment at '.$frame_offset.' cannot be saved to "'.$destination_filename.'" (not writable)'); + } + $parsedFrame['data_filename'] = $destination_filename; + unset($parsedFrame['data']); + } else { + if (! empty($parsedFrame['framenameshort']) && ! empty($parsedFrame['data'])) { + if (! isset($info['id3v2']['comments']['picture'])) { + $info['id3v2']['comments']['picture'] = []; + } + $comments_picture_data = []; + foreach (['data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength'] as $picture_key) { + if (isset($parsedFrame[$picture_key])) { + $comments_picture_data[$picture_key] = $parsedFrame[$picture_key]; + } + } + $info['id3v2']['comments']['picture'][] = $comments_picture_data; + unset($comments_picture_data); + } + } + } while (false); + } + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'GEOB')) || // 4.15 GEOB General encapsulated object + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'GEO'))) { // 4.16 GEO General encapsulated object + // There may be more than one 'GEOB' frame in each tag, + // but only one with the same content descriptor + //
    + // Text encoding $xx + // MIME type $00 + // Filename $00 (00) + // Content description $00 (00) + // Encapsulated object + + $frame_offset = 0; + $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); + if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; + } + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (ord($frame_mimetype) === 0) { + $frame_mimetype = ''; + } + $frame_offset = $frame_terminatorpos + strlen("\x00"); + + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { + $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 + } + $frame_filename = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (ord($frame_filename) === 0) { + $frame_filename = ''; + } + $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); + + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { + $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 + } + $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (in_array($frame_description, ["\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"])) { + // if description only contains a BOM or terminator then make it blank + $frame_description = ''; + } + $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); + + $parsedFrame['objectdata'] = (string) substr($parsedFrame['data'], $frame_offset); + $parsedFrame['encodingid'] = $frame_textencoding; + $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); + + $parsedFrame['mime'] = $frame_mimetype; + $parsedFrame['filename'] = $frame_filename; + $parsedFrame['description'] = $frame_description; + unset($parsedFrame['data']); + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'PCNT')) || // 4.16 PCNT Play counter + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'CNT'))) { // 4.17 CNT Play counter + // There may only be one 'PCNT' frame in each tag. + // When the counter reaches all one's, one byte is inserted in + // front of the counter thus making the counter eight bits bigger + //
    + // Counter $xx xx xx xx (xx ...) + + $parsedFrame['data'] = getid3_lib::BigEndian2Int($parsedFrame['data']); + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'POPM')) || // 4.17 POPM Popularimeter + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'POP'))) { // 4.18 POP Popularimeter + // There may be more than one 'POPM' frame in each tag, + // but only one with the same email address + //
    + // Email to user $00 + // Rating $xx + // Counter $xx xx xx xx (xx ...) + + $frame_offset = 0; + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_emailaddress = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (ord($frame_emailaddress) === 0) { + $frame_emailaddress = ''; + } + $frame_offset = $frame_terminatorpos + strlen("\x00"); + $frame_rating = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['counter'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset)); + $parsedFrame['email'] = $frame_emailaddress; + $parsedFrame['rating'] = $frame_rating; + unset($parsedFrame['data']); + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'RBUF')) || // 4.18 RBUF Recommended buffer size + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'BUF'))) { // 4.19 BUF Recommended buffer size + // There may only be one 'RBUF' frame in each tag + //
    + // Buffer size $xx xx xx + // Embedded info flag %0000000x + // Offset to next tag $xx xx xx xx + + $frame_offset = 0; + $parsedFrame['buffersize'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 3)); + $frame_offset += 3; + + $frame_embeddedinfoflags = getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['flags']['embededinfo'] = (bool) substr($frame_embeddedinfoflags, 7, 1); + $parsedFrame['nexttagoffset'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + unset($parsedFrame['data']); + } elseif (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'CRM')) { // 4.20 Encrypted meta frame (ID3v2.2 only) + // There may be more than one 'CRM' frame in a tag, + // but only one with the same 'owner identifier' + //
    + // Owner identifier $00 (00) + // Content/explanation $00 (00) + // Encrypted datablock + + $frame_offset = 0; + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + $frame_offset = $frame_terminatorpos + strlen("\x00"); + + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (in_array($frame_description, ["\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"])) { + // if description only contains a BOM or terminator then make it blank + $frame_description = ''; + } + $frame_offset = $frame_terminatorpos + strlen("\x00"); + + $parsedFrame['ownerid'] = $frame_ownerid; + $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); + $parsedFrame['description'] = $frame_description; + unset($parsedFrame['data']); + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'AENC')) || // 4.19 AENC Audio encryption + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'CRA'))) { // 4.21 CRA Audio encryption + // There may be more than one 'AENC' frames in a tag, + // but only one with the same 'Owner identifier' + //
    + // Owner identifier $00 + // Preview start $xx xx + // Preview length $xx xx + // Encryption info + + $frame_offset = 0; + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (ord($frame_ownerid) === 0) { + $frame_ownerid = ''; + } + $frame_offset = $frame_terminatorpos + strlen("\x00"); + $parsedFrame['ownerid'] = $frame_ownerid; + $parsedFrame['previewstart'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); + $frame_offset += 2; + $parsedFrame['previewlength'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); + $frame_offset += 2; + $parsedFrame['encryptioninfo'] = (string) substr($parsedFrame['data'], $frame_offset); + unset($parsedFrame['data']); + } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'LINK')) || // 4.20 LINK Linked information + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'LNK'))) { // 4.22 LNK Linked information + // There may be more than one 'LINK' frame in a tag, + // but only one with the same contents + //
    + // ID3v2.3+ => Frame identifier $xx xx xx xx + // ID3v2.2 => Frame identifier $xx xx xx + // URL $00 + // ID and additional data + + $frame_offset = 0; + if ($id3v2_majorversion == 2) { + $parsedFrame['frameid'] = substr($parsedFrame['data'], $frame_offset, 3); + $frame_offset += 3; + } else { + $parsedFrame['frameid'] = substr($parsedFrame['data'], $frame_offset, 4); + $frame_offset += 4; + } + + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_url = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (ord($frame_url) === 0) { + $frame_url = ''; + } + $frame_offset = $frame_terminatorpos + strlen("\x00"); + $parsedFrame['url'] = $frame_url; + + $parsedFrame['additionaldata'] = (string) substr($parsedFrame['data'], $frame_offset); + if (! empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback_iso88591_utf8($parsedFrame['url']); + } + unset($parsedFrame['data']); + } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'POSS')) { // 4.21 POSS Position synchronisation frame (ID3v2.3+ only) + // There may only be one 'POSS' frame in each tag + // + // Time stamp format $xx + // Position $xx (xx ...) + + $frame_offset = 0; + $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['position'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset)); + unset($parsedFrame['data']); + } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'USER')) { // 4.22 USER Terms of use (ID3v2.3+ only) + // There may be more than one 'Terms of use' frame in a tag, + // but only one with the same 'Language' + //
    + // Text encoding $xx + // Language $xx xx xx + // The actual text + + $frame_offset = 0; + $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + } + $frame_language = substr($parsedFrame['data'], $frame_offset, 3); + $frame_offset += 3; + $parsedFrame['language'] = $frame_language; + $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); + $parsedFrame['encodingid'] = $frame_textencoding; + $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); + + $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); + if (! empty($parsedFrame['framenameshort']) && ! empty($parsedFrame['data'])) { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); + } + unset($parsedFrame['data']); + } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'OWNE')) { // 4.23 OWNE Ownership frame (ID3v2.3+ only) + // There may only be one 'OWNE' frame in a tag + //
    + // Text encoding $xx + // Price paid $00 + // Date of purch. + // Seller + + $frame_offset = 0; + $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + } + $parsedFrame['encodingid'] = $frame_textencoding; + $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); + + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_pricepaid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + $frame_offset = $frame_terminatorpos + strlen("\x00"); + + $parsedFrame['pricepaid']['currencyid'] = substr($frame_pricepaid, 0, 3); + $parsedFrame['pricepaid']['currency'] = $this->LookupCurrencyUnits($parsedFrame['pricepaid']['currencyid']); + $parsedFrame['pricepaid']['value'] = substr($frame_pricepaid, 3); + + $parsedFrame['purchasedate'] = substr($parsedFrame['data'], $frame_offset, 8); + if ($this->IsValidDateStampString($parsedFrame['purchasedate'])) { + $parsedFrame['purchasedateunix'] = mktime(0, 0, 0, substr($parsedFrame['purchasedate'], 4, 2), substr($parsedFrame['purchasedate'], 6, 2), substr($parsedFrame['purchasedate'], 0, 4)); + } + $frame_offset += 8; + + $parsedFrame['seller'] = (string) substr($parsedFrame['data'], $frame_offset); + unset($parsedFrame['data']); + } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'COMR')) { // 4.24 COMR Commercial frame (ID3v2.3+ only) + // There may be more than one 'commercial frame' in a tag, + // but no two may be identical + //
    + // Text encoding $xx + // Price string $00 + // Valid until + // Contact URL $00 + // Received as $xx + // Name of seller $00 (00) + // Description $00 (00) + // Picture MIME type $00 + // Seller logo + + $frame_offset = 0; + $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); + if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; + } + + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_pricestring = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + $frame_offset = $frame_terminatorpos + strlen("\x00"); + $frame_rawpricearray = explode('/', $frame_pricestring); + foreach ($frame_rawpricearray as $key => $val) { + $frame_currencyid = substr($val, 0, 3); + $parsedFrame['price'][$frame_currencyid]['currency'] = $this->LookupCurrencyUnits($frame_currencyid); + $parsedFrame['price'][$frame_currencyid]['value'] = substr($val, 3); + } + + $frame_datestring = substr($parsedFrame['data'], $frame_offset, 8); + $frame_offset += 8; + + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_contacturl = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + $frame_offset = $frame_terminatorpos + strlen("\x00"); + + $frame_receivedasid = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { + $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 + } + $frame_sellername = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (ord($frame_sellername) === 0) { + $frame_sellername = ''; + } + $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); + + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { + $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 + } + $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (in_array($frame_description, ["\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"])) { + // if description only contains a BOM or terminator then make it blank + $frame_description = ''; + } + $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); + + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + $frame_offset = $frame_terminatorpos + strlen("\x00"); + + $frame_sellerlogo = substr($parsedFrame['data'], $frame_offset); + + $parsedFrame['encodingid'] = $frame_textencoding; + $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); + + $parsedFrame['pricevaliduntil'] = $frame_datestring; + $parsedFrame['contacturl'] = $frame_contacturl; + $parsedFrame['receivedasid'] = $frame_receivedasid; + $parsedFrame['receivedas'] = $this->COMRReceivedAsLookup($frame_receivedasid); + $parsedFrame['sellername'] = $frame_sellername; + $parsedFrame['description'] = $frame_description; + $parsedFrame['mime'] = $frame_mimetype; + $parsedFrame['logo'] = $frame_sellerlogo; + unset($parsedFrame['data']); + } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'ENCR')) { // 4.25 ENCR Encryption method registration (ID3v2.3+ only) + // There may be several 'ENCR' frames in a tag, + // but only one containing the same symbol + // and only one containing the same owner identifier + //
    + // Owner identifier $00 + // Method symbol $xx + // Encryption data + + $frame_offset = 0; + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (ord($frame_ownerid) === 0) { + $frame_ownerid = ''; + } + $frame_offset = $frame_terminatorpos + strlen("\x00"); + + $parsedFrame['ownerid'] = $frame_ownerid; + $parsedFrame['methodsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); + } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'GRID')) { // 4.26 GRID Group identification registration (ID3v2.3+ only) + + // There may be several 'GRID' frames in a tag, + // but only one containing the same symbol + // and only one containing the same owner identifier + //
    + // Owner identifier $00 + // Group symbol $xx + // Group dependent data + + $frame_offset = 0; + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (ord($frame_ownerid) === 0) { + $frame_ownerid = ''; + } + $frame_offset = $frame_terminatorpos + strlen("\x00"); + + $parsedFrame['ownerid'] = $frame_ownerid; + $parsedFrame['groupsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); + } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'PRIV')) { // 4.27 PRIV Private frame (ID3v2.3+ only) + // The tag may contain more than one 'PRIV' frame + // but only with different contents + //
    + // Owner identifier $00 + // The private data + + $frame_offset = 0; + $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); + $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + if (ord($frame_ownerid) === 0) { + $frame_ownerid = ''; + } + $frame_offset = $frame_terminatorpos + strlen("\x00"); + + $parsedFrame['ownerid'] = $frame_ownerid; + $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); + } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'SIGN')) { // 4.28 SIGN Signature frame (ID3v2.4+ only) + // There may be more than one 'signature frame' in a tag, + // but no two may be identical + //
    + // Group symbol $xx + // Signature + + $frame_offset = 0; + $parsedFrame['groupsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); + } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'SEEK')) { // 4.29 SEEK Seek frame (ID3v2.4+ only) + // There may only be one 'seek frame' in a tag + //
    + // Minimum offset to next tag $xx xx xx xx + + $frame_offset = 0; + $parsedFrame['data'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + } elseif (($id3v2_majorversion >= 4) && ($parsedFrame['frame_name'] == 'ASPI')) { // 4.30 ASPI Audio seek point index (ID3v2.4+ only) + // There may only be one 'audio seek point index' frame in a tag + //
    + // Indexed data start (S) $xx xx xx xx + // Indexed data length (L) $xx xx xx xx + // Number of index points (N) $xx xx + // Bits per index point (b) $xx + // Then for every index point the following data is included: + // Fraction at index (Fi) $xx (xx) + + $frame_offset = 0; + $parsedFrame['datastart'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + $frame_offset += 4; + $parsedFrame['indexeddatalength'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + $frame_offset += 4; + $parsedFrame['indexpoints'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); + $frame_offset += 2; + $parsedFrame['bitsperpoint'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_bytesperpoint = ceil($parsedFrame['bitsperpoint'] / 8); + for ($i = 0; $i < $parsedFrame['indexpoints']; $i++) { + $parsedFrame['indexes'][$i] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesperpoint)); + $frame_offset += $frame_bytesperpoint; + } + unset($parsedFrame['data']); + } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'RGAD')) { // Replay Gain Adjustment + // http://privatewww.essex.ac.uk/~djmrob/replaygain/file_format_id3v2.html + // There may only be one 'RGAD' frame in a tag + //
    + // Peak Amplitude $xx $xx $xx $xx + // Radio Replay Gain Adjustment %aaabbbcd %dddddddd + // Audiophile Replay Gain Adjustment %aaabbbcd %dddddddd + // a - name code + // b - originator code + // c - sign bit + // d - replay gain adjustment + + $frame_offset = 0; + $parsedFrame['peakamplitude'] = getid3_lib::BigEndian2Float(substr($parsedFrame['data'], $frame_offset, 4)); + $frame_offset += 4; + $rg_track_adjustment = getid3_lib::Dec2Bin(substr($parsedFrame['data'], $frame_offset, 2)); + $frame_offset += 2; + $rg_album_adjustment = getid3_lib::Dec2Bin(substr($parsedFrame['data'], $frame_offset, 2)); + $frame_offset += 2; + $parsedFrame['raw']['track']['name'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 0, 3)); + $parsedFrame['raw']['track']['originator'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 3, 3)); + $parsedFrame['raw']['track']['signbit'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 6, 1)); + $parsedFrame['raw']['track']['adjustment'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 7, 9)); + $parsedFrame['raw']['album']['name'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 0, 3)); + $parsedFrame['raw']['album']['originator'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 3, 3)); + $parsedFrame['raw']['album']['signbit'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 6, 1)); + $parsedFrame['raw']['album']['adjustment'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 7, 9)); + $parsedFrame['track']['name'] = getid3_lib::RGADnameLookup($parsedFrame['raw']['track']['name']); + $parsedFrame['track']['originator'] = getid3_lib::RGADoriginatorLookup($parsedFrame['raw']['track']['originator']); + $parsedFrame['track']['adjustment'] = getid3_lib::RGADadjustmentLookup($parsedFrame['raw']['track']['adjustment'], $parsedFrame['raw']['track']['signbit']); + $parsedFrame['album']['name'] = getid3_lib::RGADnameLookup($parsedFrame['raw']['album']['name']); + $parsedFrame['album']['originator'] = getid3_lib::RGADoriginatorLookup($parsedFrame['raw']['album']['originator']); + $parsedFrame['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($parsedFrame['raw']['album']['adjustment'], $parsedFrame['raw']['album']['signbit']); + + $info['replay_gain']['track']['peak'] = $parsedFrame['peakamplitude']; + $info['replay_gain']['track']['originator'] = $parsedFrame['track']['originator']; + $info['replay_gain']['track']['adjustment'] = $parsedFrame['track']['adjustment']; + $info['replay_gain']['album']['originator'] = $parsedFrame['album']['originator']; + $info['replay_gain']['album']['adjustment'] = $parsedFrame['album']['adjustment']; + + unset($parsedFrame['data']); + } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'CHAP')) { // CHAP Chapters frame (ID3v2.3+ only) + // http://id3.org/id3v2-chapters-1.0 + // (10 bytes) + // Element ID $00 + // Start time $xx xx xx xx + // End time $xx xx xx xx // Start offset $xx xx xx xx // End offset $xx xx xx xx // - $frame_offset = 0; - @list($parsedFrame['element_id']) = explode("\x00", $parsedFrame['data'], 2); - $frame_offset += strlen($parsedFrame['element_id']."\x00"); - $parsedFrame['time_begin'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); - $frame_offset += 4; - $parsedFrame['time_end'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); - $frame_offset += 4; - if (substr($parsedFrame['data'], $frame_offset, 4) != "\xFF\xFF\xFF\xFF") { - // "If these bytes are all set to 0xFF then the value should be ignored and the start time value should be utilized." - $parsedFrame['offset_begin'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); - } - $frame_offset += 4; - if (substr($parsedFrame['data'], $frame_offset, 4) != "\xFF\xFF\xFF\xFF") { - // "If these bytes are all set to 0xFF then the value should be ignored and the start time value should be utilized." - $parsedFrame['offset_end'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); - } - $frame_offset += 4; + $frame_offset = 0; + @list($parsedFrame['element_id']) = explode("\x00", $parsedFrame['data'], 2); + $frame_offset += strlen($parsedFrame['element_id']."\x00"); + $parsedFrame['time_begin'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + $frame_offset += 4; + $parsedFrame['time_end'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + $frame_offset += 4; + if (substr($parsedFrame['data'], $frame_offset, 4) != "\xFF\xFF\xFF\xFF") { + // "If these bytes are all set to 0xFF then the value should be ignored and the start time value should be utilized." + $parsedFrame['offset_begin'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + } + $frame_offset += 4; + if (substr($parsedFrame['data'], $frame_offset, 4) != "\xFF\xFF\xFF\xFF") { + // "If these bytes are all set to 0xFF then the value should be ignored and the start time value should be utilized." + $parsedFrame['offset_end'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + } + $frame_offset += 4; - if ($frame_offset < strlen($parsedFrame['data'])) { - $parsedFrame['subframes'] = array(); - while ($frame_offset < strlen($parsedFrame['data'])) { - // - $subframe = array(); - $subframe['name'] = substr($parsedFrame['data'], $frame_offset, 4); - $frame_offset += 4; - $subframe['size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); - $frame_offset += 4; - $subframe['flags_raw'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); - $frame_offset += 2; - if ($subframe['size'] > (strlen($parsedFrame['data']) - $frame_offset)) { - $this->warning('CHAP subframe "'.$subframe['name'].'" at frame offset '.$frame_offset.' claims to be "'.$subframe['size'].'" bytes, which is more than the available data ('.(strlen($parsedFrame['data']) - $frame_offset).' bytes)'); - break; - } - $subframe_rawdata = substr($parsedFrame['data'], $frame_offset, $subframe['size']); - $frame_offset += $subframe['size']; + if ($frame_offset < strlen($parsedFrame['data'])) { + $parsedFrame['subframes'] = []; + while ($frame_offset < strlen($parsedFrame['data'])) { + // + $subframe = []; + $subframe['name'] = substr($parsedFrame['data'], $frame_offset, 4); + $frame_offset += 4; + $subframe['size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + $frame_offset += 4; + $subframe['flags_raw'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); + $frame_offset += 2; + if ($subframe['size'] > (strlen($parsedFrame['data']) - $frame_offset)) { + $this->warning('CHAP subframe "'.$subframe['name'].'" at frame offset '.$frame_offset.' claims to be "'.$subframe['size'].'" bytes, which is more than the available data ('.(strlen($parsedFrame['data']) - $frame_offset).' bytes)'); + break; + } + $subframe_rawdata = substr($parsedFrame['data'], $frame_offset, $subframe['size']); + $frame_offset += $subframe['size']; - $subframe['encodingid'] = ord(substr($subframe_rawdata, 0, 1)); - $subframe['text'] = substr($subframe_rawdata, 1); - $subframe['encoding'] = $this->TextEncodingNameLookup($subframe['encodingid']); - $encoding_converted_text = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe['text']));; - switch (substr($encoding_converted_text, 0, 2)) { - case "\xFF\xFE": - case "\xFE\xFF": - switch (strtoupper($info['id3v2']['encoding'])) { - case 'ISO-8859-1': - case 'UTF-8': - $encoding_converted_text = substr($encoding_converted_text, 2); - // remove unwanted byte-order-marks - break; - default: - // ignore - break; - } - break; - default: - // do not remove BOM - break; - } + $subframe['encodingid'] = ord(substr($subframe_rawdata, 0, 1)); + $subframe['text'] = substr($subframe_rawdata, 1); + $subframe['encoding'] = $this->TextEncodingNameLookup($subframe['encodingid']); + $encoding_converted_text = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe['text'])); + switch (substr($encoding_converted_text, 0, 2)) { + case "\xFF\xFE": + case "\xFE\xFF": + switch (strtoupper($info['id3v2']['encoding'])) { + case 'ISO-8859-1': + case 'UTF-8': + $encoding_converted_text = substr($encoding_converted_text, 2); + // remove unwanted byte-order-marks + break; + default: + // ignore + break; + } + break; + default: + // do not remove BOM + break; + } - if (($subframe['name'] == 'TIT2') || ($subframe['name'] == 'TIT3')) { - if ($subframe['name'] == 'TIT2') { - $parsedFrame['chapter_name'] = $encoding_converted_text; - } elseif ($subframe['name'] == 'TIT3') { - $parsedFrame['chapter_description'] = $encoding_converted_text; - } - $parsedFrame['subframes'][] = $subframe; - } else { - $this->warning('ID3v2.CHAP subframe "'.$subframe['name'].'" not handled (only TIT2 and TIT3)'); - } - } - unset($subframe_rawdata, $subframe, $encoding_converted_text); - } + if (($subframe['name'] == 'TIT2') || ($subframe['name'] == 'TIT3')) { + if ($subframe['name'] == 'TIT2') { + $parsedFrame['chapter_name'] = $encoding_converted_text; + } elseif ($subframe['name'] == 'TIT3') { + $parsedFrame['chapter_description'] = $encoding_converted_text; + } + $parsedFrame['subframes'][] = $subframe; + } else { + $this->warning('ID3v2.CHAP subframe "'.$subframe['name'].'" not handled (only TIT2 and TIT3)'); + } + } + unset($subframe_rawdata, $subframe, $encoding_converted_text); + } - $id3v2_chapter_entry = array(); - foreach (array('id', 'time_begin', 'time_end', 'offset_begin', 'offset_end', 'chapter_name', 'chapter_description') as $id3v2_chapter_key) { - if (isset($parsedFrame[$id3v2_chapter_key])) { - $id3v2_chapter_entry[$id3v2_chapter_key] = $parsedFrame[$id3v2_chapter_key]; - } - } - if (!isset($info['id3v2']['chapters'])) { - $info['id3v2']['chapters'] = array(); - } - $info['id3v2']['chapters'][] = $id3v2_chapter_entry; - unset($id3v2_chapter_entry, $id3v2_chapter_key); - - - } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'CTOC')) { // CTOC Chapters Table Of Contents frame (ID3v2.3+ only) - // http://id3.org/id3v2-chapters-1.0 - // (10 bytes) - // Element ID $00 - // CTOC flags %xx - // Entry count $xx - // Child Element ID $00 /* zero or more child CHAP or CTOC entries */ + $id3v2_chapter_entry = []; + foreach (['id', 'time_begin', 'time_end', 'offset_begin', 'offset_end', 'chapter_name', 'chapter_description'] as $id3v2_chapter_key) { + if (isset($parsedFrame[$id3v2_chapter_key])) { + $id3v2_chapter_entry[$id3v2_chapter_key] = $parsedFrame[$id3v2_chapter_key]; + } + } + if (! isset($info['id3v2']['chapters'])) { + $info['id3v2']['chapters'] = []; + } + $info['id3v2']['chapters'][] = $id3v2_chapter_entry; + unset($id3v2_chapter_entry, $id3v2_chapter_key); + } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'CTOC')) { // CTOC Chapters Table Of Contents frame (ID3v2.3+ only) + // http://id3.org/id3v2-chapters-1.0 + // (10 bytes) + // Element ID $00 + // CTOC flags %xx + // Entry count $xx + // Child Element ID $00 /* zero or more child CHAP or CTOC entries */ // - $frame_offset = 0; - @list($parsedFrame['element_id']) = explode("\x00", $parsedFrame['data'], 2); - $frame_offset += strlen($parsedFrame['element_id']."\x00"); - $ctoc_flags_raw = ord(substr($parsedFrame['data'], $frame_offset, 1)); - $frame_offset += 1; - $parsedFrame['entry_count'] = ord(substr($parsedFrame['data'], $frame_offset, 1)); - $frame_offset += 1; - - $terminator_position = null; - for ($i = 0; $i < $parsedFrame['entry_count']; $i++) { - $terminator_position = strpos($parsedFrame['data'], "\x00", $frame_offset); - $parsedFrame['child_element_ids'][$i] = substr($parsedFrame['data'], $frame_offset, $terminator_position - $frame_offset); - $frame_offset = $terminator_position + 1; - } - - $parsedFrame['ctoc_flags']['ordered'] = (bool) ($ctoc_flags_raw & 0x01); - $parsedFrame['ctoc_flags']['top_level'] = (bool) ($ctoc_flags_raw & 0x03); - - unset($ctoc_flags_raw, $terminator_position); - - if ($frame_offset < strlen($parsedFrame['data'])) { - $parsedFrame['subframes'] = array(); - while ($frame_offset < strlen($parsedFrame['data'])) { - // - $subframe = array(); - $subframe['name'] = substr($parsedFrame['data'], $frame_offset, 4); - $frame_offset += 4; - $subframe['size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); - $frame_offset += 4; - $subframe['flags_raw'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); - $frame_offset += 2; - if ($subframe['size'] > (strlen($parsedFrame['data']) - $frame_offset)) { - $this->warning('CTOS subframe "'.$subframe['name'].'" at frame offset '.$frame_offset.' claims to be "'.$subframe['size'].'" bytes, which is more than the available data ('.(strlen($parsedFrame['data']) - $frame_offset).' bytes)'); - break; - } - $subframe_rawdata = substr($parsedFrame['data'], $frame_offset, $subframe['size']); - $frame_offset += $subframe['size']; - - $subframe['encodingid'] = ord(substr($subframe_rawdata, 0, 1)); - $subframe['text'] = substr($subframe_rawdata, 1); - $subframe['encoding'] = $this->TextEncodingNameLookup($subframe['encodingid']); - $encoding_converted_text = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe['text']));; - switch (substr($encoding_converted_text, 0, 2)) { - case "\xFF\xFE": - case "\xFE\xFF": - switch (strtoupper($info['id3v2']['encoding'])) { - case 'ISO-8859-1': - case 'UTF-8': - $encoding_converted_text = substr($encoding_converted_text, 2); - // remove unwanted byte-order-marks - break; - default: - // ignore - break; - } - break; - default: - // do not remove BOM - break; - } - - if (($subframe['name'] == 'TIT2') || ($subframe['name'] == 'TIT3')) { - if ($subframe['name'] == 'TIT2') { - $parsedFrame['toc_name'] = $encoding_converted_text; - } elseif ($subframe['name'] == 'TIT3') { - $parsedFrame['toc_description'] = $encoding_converted_text; - } - $parsedFrame['subframes'][] = $subframe; - } else { - $this->warning('ID3v2.CTOC subframe "'.$subframe['name'].'" not handled (only TIT2 and TIT3)'); - } - } - unset($subframe_rawdata, $subframe, $encoding_converted_text); - } - - } - - return true; - } - - - public function DeUnsynchronise($data) { - return str_replace("\xFF\x00", "\xFF", $data); - } - - public function LookupExtendedHeaderRestrictionsTagSizeLimits($index) { - static $LookupExtendedHeaderRestrictionsTagSizeLimits = array( - 0x00 => 'No more than 128 frames and 1 MB total tag size', - 0x01 => 'No more than 64 frames and 128 KB total tag size', - 0x02 => 'No more than 32 frames and 40 KB total tag size', - 0x03 => 'No more than 32 frames and 4 KB total tag size', - ); - return (isset($LookupExtendedHeaderRestrictionsTagSizeLimits[$index]) ? $LookupExtendedHeaderRestrictionsTagSizeLimits[$index] : ''); - } - - public function LookupExtendedHeaderRestrictionsTextEncodings($index) { - static $LookupExtendedHeaderRestrictionsTextEncodings = array( - 0x00 => 'No restrictions', - 0x01 => 'Strings are only encoded with ISO-8859-1 or UTF-8', - ); - return (isset($LookupExtendedHeaderRestrictionsTextEncodings[$index]) ? $LookupExtendedHeaderRestrictionsTextEncodings[$index] : ''); - } - - public function LookupExtendedHeaderRestrictionsTextFieldSize($index) { - static $LookupExtendedHeaderRestrictionsTextFieldSize = array( - 0x00 => 'No restrictions', - 0x01 => 'No string is longer than 1024 characters', - 0x02 => 'No string is longer than 128 characters', - 0x03 => 'No string is longer than 30 characters', - ); - return (isset($LookupExtendedHeaderRestrictionsTextFieldSize[$index]) ? $LookupExtendedHeaderRestrictionsTextFieldSize[$index] : ''); - } - - public function LookupExtendedHeaderRestrictionsImageEncoding($index) { - static $LookupExtendedHeaderRestrictionsImageEncoding = array( - 0x00 => 'No restrictions', - 0x01 => 'Images are encoded only with PNG or JPEG', - ); - return (isset($LookupExtendedHeaderRestrictionsImageEncoding[$index]) ? $LookupExtendedHeaderRestrictionsImageEncoding[$index] : ''); - } - - public function LookupExtendedHeaderRestrictionsImageSizeSize($index) { - static $LookupExtendedHeaderRestrictionsImageSizeSize = array( - 0x00 => 'No restrictions', - 0x01 => 'All images are 256x256 pixels or smaller', - 0x02 => 'All images are 64x64 pixels or smaller', - 0x03 => 'All images are exactly 64x64 pixels, unless required otherwise', - ); - return (isset($LookupExtendedHeaderRestrictionsImageSizeSize[$index]) ? $LookupExtendedHeaderRestrictionsImageSizeSize[$index] : ''); - } - - public function LookupCurrencyUnits($currencyid) { - - $begin = __LINE__; - - /** This is not a comment! - - - AED Dirhams - AFA Afghanis - ALL Leke - AMD Drams - ANG Guilders - AOA Kwanza - ARS Pesos - ATS Schillings - AUD Dollars - AWG Guilders - AZM Manats - BAM Convertible Marka - BBD Dollars - BDT Taka - BEF Francs - BGL Leva - BHD Dinars - BIF Francs - BMD Dollars - BND Dollars - BOB Bolivianos - BRL Brazil Real - BSD Dollars - BTN Ngultrum - BWP Pulas - BYR Rubles - BZD Dollars - CAD Dollars - CDF Congolese Francs - CHF Francs - CLP Pesos - CNY Yuan Renminbi - COP Pesos - CRC Colones - CUP Pesos - CVE Escudos - CYP Pounds - CZK Koruny - DEM Deutsche Marks - DJF Francs - DKK Kroner - DOP Pesos - DZD Algeria Dinars - EEK Krooni - EGP Pounds - ERN Nakfa - ESP Pesetas - ETB Birr - EUR Euro - FIM Markkaa - FJD Dollars - FKP Pounds - FRF Francs - GBP Pounds - GEL Lari - GGP Pounds - GHC Cedis - GIP Pounds - GMD Dalasi - GNF Francs - GRD Drachmae - GTQ Quetzales - GYD Dollars - HKD Dollars - HNL Lempiras - HRK Kuna - HTG Gourdes - HUF Forints - IDR Rupiahs - IEP Pounds - ILS New Shekels - IMP Pounds - INR Rupees - IQD Dinars - IRR Rials - ISK Kronur - ITL Lire - JEP Pounds - JMD Dollars - JOD Dinars - JPY Yen - KES Shillings - KGS Soms - KHR Riels - KMF Francs - KPW Won - KWD Dinars - KYD Dollars - KZT Tenge - LAK Kips - LBP Pounds - LKR Rupees - LRD Dollars - LSL Maloti - LTL Litai - LUF Francs - LVL Lati - LYD Dinars - MAD Dirhams - MDL Lei - MGF Malagasy Francs - MKD Denars - MMK Kyats - MNT Tugriks - MOP Patacas - MRO Ouguiyas - MTL Liri - MUR Rupees - MVR Rufiyaa - MWK Kwachas - MXN Pesos - MYR Ringgits - MZM Meticais - NAD Dollars - NGN Nairas - NIO Gold Cordobas - NLG Guilders - NOK Krone - NPR Nepal Rupees - NZD Dollars - OMR Rials - PAB Balboa - PEN Nuevos Soles - PGK Kina - PHP Pesos - PKR Rupees - PLN Zlotych - PTE Escudos - PYG Guarani - QAR Rials - ROL Lei - RUR Rubles - RWF Rwanda Francs - SAR Riyals - SBD Dollars - SCR Rupees - SDD Dinars - SEK Kronor - SGD Dollars - SHP Pounds - SIT Tolars - SKK Koruny - SLL Leones - SOS Shillings - SPL Luigini - SRG Guilders - STD Dobras - SVC Colones - SYP Pounds - SZL Emalangeni - THB Baht - TJR Rubles - TMM Manats - TND Dinars - TOP Pa'anga - TRL Liras - TTD Dollars - TVD Tuvalu Dollars - TWD New Dollars - TZS Shillings - UAH Hryvnia - UGX Shillings - USD Dollars - UYU Pesos - UZS Sums - VAL Lire - VEB Bolivares - VND Dong - VUV Vatu - WST Tala - XAF Francs - XAG Ounces - XAU Ounces - XCD Dollars - XDR Special Drawing Rights - XPD Ounces - XPF Francs - XPT Ounces - YER Rials - YUM New Dinars - ZAR Rand - ZMK Kwacha - ZWD Zimbabwe Dollars - - */ - - return getid3_lib::EmbeddedLookup($currencyid, $begin, __LINE__, __FILE__, 'id3v2-currency-units'); - } - - - public function LookupCurrencyCountry($currencyid) { - - $begin = __LINE__; - - /** This is not a comment! - - AED United Arab Emirates - AFA Afghanistan - ALL Albania - AMD Armenia - ANG Netherlands Antilles - AOA Angola - ARS Argentina - ATS Austria - AUD Australia - AWG Aruba - AZM Azerbaijan - BAM Bosnia and Herzegovina - BBD Barbados - BDT Bangladesh - BEF Belgium - BGL Bulgaria - BHD Bahrain - BIF Burundi - BMD Bermuda - BND Brunei Darussalam - BOB Bolivia - BRL Brazil - BSD Bahamas - BTN Bhutan - BWP Botswana - BYR Belarus - BZD Belize - CAD Canada - CDF Congo/Kinshasa - CHF Switzerland - CLP Chile - CNY China - COP Colombia - CRC Costa Rica - CUP Cuba - CVE Cape Verde - CYP Cyprus - CZK Czech Republic - DEM Germany - DJF Djibouti - DKK Denmark - DOP Dominican Republic - DZD Algeria - EEK Estonia - EGP Egypt - ERN Eritrea - ESP Spain - ETB Ethiopia - EUR Euro Member Countries - FIM Finland - FJD Fiji - FKP Falkland Islands (Malvinas) - FRF France - GBP United Kingdom - GEL Georgia - GGP Guernsey - GHC Ghana - GIP Gibraltar - GMD Gambia - GNF Guinea - GRD Greece - GTQ Guatemala - GYD Guyana - HKD Hong Kong - HNL Honduras - HRK Croatia - HTG Haiti - HUF Hungary - IDR Indonesia - IEP Ireland (Eire) - ILS Israel - IMP Isle of Man - INR India - IQD Iraq - IRR Iran - ISK Iceland - ITL Italy - JEP Jersey - JMD Jamaica - JOD Jordan - JPY Japan - KES Kenya - KGS Kyrgyzstan - KHR Cambodia - KMF Comoros - KPW Korea - KWD Kuwait - KYD Cayman Islands - KZT Kazakstan - LAK Laos - LBP Lebanon - LKR Sri Lanka - LRD Liberia - LSL Lesotho - LTL Lithuania - LUF Luxembourg - LVL Latvia - LYD Libya - MAD Morocco - MDL Moldova - MGF Madagascar - MKD Macedonia - MMK Myanmar (Burma) - MNT Mongolia - MOP Macau - MRO Mauritania - MTL Malta - MUR Mauritius - MVR Maldives (Maldive Islands) - MWK Malawi - MXN Mexico - MYR Malaysia - MZM Mozambique - NAD Namibia - NGN Nigeria - NIO Nicaragua - NLG Netherlands (Holland) - NOK Norway - NPR Nepal - NZD New Zealand - OMR Oman - PAB Panama - PEN Peru - PGK Papua New Guinea - PHP Philippines - PKR Pakistan - PLN Poland - PTE Portugal - PYG Paraguay - QAR Qatar - ROL Romania - RUR Russia - RWF Rwanda - SAR Saudi Arabia - SBD Solomon Islands - SCR Seychelles - SDD Sudan - SEK Sweden - SGD Singapore - SHP Saint Helena - SIT Slovenia - SKK Slovakia - SLL Sierra Leone - SOS Somalia - SPL Seborga - SRG Suriname - STD São Tome and Principe - SVC El Salvador - SYP Syria - SZL Swaziland - THB Thailand - TJR Tajikistan - TMM Turkmenistan - TND Tunisia - TOP Tonga - TRL Turkey - TTD Trinidad and Tobago - TVD Tuvalu - TWD Taiwan - TZS Tanzania - UAH Ukraine - UGX Uganda - USD United States of America - UYU Uruguay - UZS Uzbekistan - VAL Vatican City - VEB Venezuela - VND Viet Nam - VUV Vanuatu - WST Samoa - XAF Communauté Financière Africaine - XAG Silver - XAU Gold - XCD East Caribbean - XDR International Monetary Fund - XPD Palladium - XPF Comptoirs Français du Pacifique - XPT Platinum - YER Yemen - YUM Yugoslavia - ZAR South Africa - ZMK Zambia - ZWD Zimbabwe - - */ - - return getid3_lib::EmbeddedLookup($currencyid, $begin, __LINE__, __FILE__, 'id3v2-currency-country'); - } - - - - public static function LanguageLookup($languagecode, $casesensitive=false) { - - if (!$casesensitive) { - $languagecode = strtolower($languagecode); - } - - // http://www.id3.org/id3v2.4.0-structure.txt - // [4. ID3v2 frame overview] - // The three byte language field, present in several frames, is used to - // describe the language of the frame's content, according to ISO-639-2 - // [ISO-639-2]. The language should be represented in lower case. If the - // language is not known the string "XXX" should be used. - - - // ISO 639-2 - http://www.id3.org/iso639-2.html - - $begin = __LINE__; - - /** This is not a comment! - - XXX unknown - xxx unknown - aar Afar - abk Abkhazian - ace Achinese - ach Acoli - ada Adangme - afa Afro-Asiatic (Other) - afh Afrihili - afr Afrikaans - aka Akan - akk Akkadian - alb Albanian - ale Aleut - alg Algonquian Languages - amh Amharic - ang English, Old (ca. 450-1100) - apa Apache Languages - ara Arabic - arc Aramaic - arm Armenian - arn Araucanian - arp Arapaho - art Artificial (Other) - arw Arawak - asm Assamese - ath Athapascan Languages - ava Avaric - ave Avestan - awa Awadhi - aym Aymara - aze Azerbaijani - bad Banda - bai Bamileke Languages - bak Bashkir - bal Baluchi - bam Bambara - ban Balinese - baq Basque - bas Basa - bat Baltic (Other) - bej Beja - bel Byelorussian - bem Bemba - ben Bengali - ber Berber (Other) - bho Bhojpuri - bih Bihari - bik Bikol - bin Bini - bis Bislama - bla Siksika - bnt Bantu (Other) - bod Tibetan - bra Braj - bre Breton - bua Buriat - bug Buginese - bul Bulgarian - bur Burmese - cad Caddo - cai Central American Indian (Other) - car Carib - cat Catalan - cau Caucasian (Other) - ceb Cebuano - cel Celtic (Other) - ces Czech - cha Chamorro - chb Chibcha - che Chechen - chg Chagatai - chi Chinese - chm Mari - chn Chinook jargon - cho Choctaw - chr Cherokee - chu Church Slavic - chv Chuvash - chy Cheyenne - cop Coptic - cor Cornish - cos Corsican - cpe Creoles and Pidgins, English-based (Other) - cpf Creoles and Pidgins, French-based (Other) - cpp Creoles and Pidgins, Portuguese-based (Other) - cre Cree - crp Creoles and Pidgins (Other) - cus Cushitic (Other) - cym Welsh - cze Czech - dak Dakota - dan Danish - del Delaware - deu German - din Dinka - div Divehi - doi Dogri - dra Dravidian (Other) - dua Duala - dum Dutch, Middle (ca. 1050-1350) - dut Dutch - dyu Dyula - dzo Dzongkha - efi Efik - egy Egyptian (Ancient) - eka Ekajuk - ell Greek, Modern (1453-) - elx Elamite - eng English - enm English, Middle (ca. 1100-1500) - epo Esperanto - esk Eskimo (Other) - esl Spanish - est Estonian - eus Basque - ewe Ewe - ewo Ewondo - fan Fang - fao Faroese - fas Persian - fat Fanti - fij Fijian - fin Finnish - fiu Finno-Ugrian (Other) - fon Fon - fra French - fre French - frm French, Middle (ca. 1400-1600) - fro French, Old (842- ca. 1400) - fry Frisian - ful Fulah - gaa Ga - gae Gaelic (Scots) - gai Irish - gay Gayo - gdh Gaelic (Scots) - gem Germanic (Other) - geo Georgian - ger German - gez Geez - gil Gilbertese - glg Gallegan - gmh German, Middle High (ca. 1050-1500) - goh German, Old High (ca. 750-1050) - gon Gondi - got Gothic - grb Grebo - grc Greek, Ancient (to 1453) - gre Greek, Modern (1453-) - grn Guarani - guj Gujarati - hai Haida - hau Hausa - haw Hawaiian - heb Hebrew - her Herero - hil Hiligaynon - him Himachali - hin Hindi - hmo Hiri Motu - hun Hungarian - hup Hupa - hye Armenian - iba Iban - ibo Igbo - ice Icelandic - ijo Ijo - iku Inuktitut - ilo Iloko - ina Interlingua (International Auxiliary language Association) - inc Indic (Other) - ind Indonesian - ine Indo-European (Other) - ine Interlingue - ipk Inupiak - ira Iranian (Other) - iri Irish - iro Iroquoian uages - isl Icelandic - ita Italian - jav Javanese - jaw Javanese - jpn Japanese - jpr Judeo-Persian - jrb Judeo-Arabic - kaa Kara-Kalpak - kab Kabyle - kac Kachin - kal Greenlandic - kam Kamba - kan Kannada - kar Karen - kas Kashmiri - kat Georgian - kau Kanuri - kaw Kawi - kaz Kazakh - kha Khasi - khi Khoisan (Other) - khm Khmer - kho Khotanese - kik Kikuyu - kin Kinyarwanda - kir Kirghiz - kok Konkani - kom Komi - kon Kongo - kor Korean - kpe Kpelle - kro Kru - kru Kurukh - kua Kuanyama - kum Kumyk - kur Kurdish - kus Kusaie - kut Kutenai - lad Ladino - lah Lahnda - lam Lamba - lao Lao - lat Latin - lav Latvian - lez Lezghian - lin Lingala - lit Lithuanian - lol Mongo - loz Lozi - ltz Letzeburgesch - lub Luba-Katanga - lug Ganda - lui Luiseno - lun Lunda - luo Luo (Kenya and Tanzania) - mac Macedonian - mad Madurese - mag Magahi - mah Marshall - mai Maithili - mak Macedonian - mak Makasar - mal Malayalam - man Mandingo - mao Maori - map Austronesian (Other) - mar Marathi - mas Masai - max Manx - may Malay - men Mende - mga Irish, Middle (900 - 1200) - mic Micmac - min Minangkabau - mis Miscellaneous (Other) - mkh Mon-Kmer (Other) - mlg Malagasy - mlt Maltese - mni Manipuri - mno Manobo Languages - moh Mohawk - mol Moldavian - mon Mongolian - mos Mossi - mri Maori - msa Malay - mul Multiple Languages - mun Munda Languages - mus Creek - mwr Marwari - mya Burmese - myn Mayan Languages - nah Aztec - nai North American Indian (Other) - nau Nauru - nav Navajo - nbl Ndebele, South - nde Ndebele, North - ndo Ndongo - nep Nepali - new Newari - nic Niger-Kordofanian (Other) - niu Niuean - nla Dutch - nno Norwegian (Nynorsk) - non Norse, Old - nor Norwegian - nso Sotho, Northern - nub Nubian Languages - nya Nyanja - nym Nyamwezi - nyn Nyankole - nyo Nyoro - nzi Nzima - oci Langue d'Oc (post 1500) - oji Ojibwa - ori Oriya - orm Oromo - osa Osage - oss Ossetic - ota Turkish, Ottoman (1500 - 1928) - oto Otomian Languages - paa Papuan-Australian (Other) - pag Pangasinan - pal Pahlavi - pam Pampanga - pan Panjabi - pap Papiamento - pau Palauan - peo Persian, Old (ca 600 - 400 B.C.) - per Persian - phn Phoenician - pli Pali - pol Polish - pon Ponape - por Portuguese - pra Prakrit uages - pro Provencal, Old (to 1500) - pus Pushto - que Quechua - raj Rajasthani - rar Rarotongan - roa Romance (Other) - roh Rhaeto-Romance - rom Romany - ron Romanian - rum Romanian - run Rundi - rus Russian - sad Sandawe - sag Sango - sah Yakut - sai South American Indian (Other) - sal Salishan Languages - sam Samaritan Aramaic - san Sanskrit - sco Scots - scr Serbo-Croatian - sel Selkup - sem Semitic (Other) - sga Irish, Old (to 900) - shn Shan - sid Sidamo - sin Singhalese - sio Siouan Languages - sit Sino-Tibetan (Other) - sla Slavic (Other) - slk Slovak - slo Slovak - slv Slovenian - smi Sami Languages - smo Samoan - sna Shona - snd Sindhi - sog Sogdian - som Somali - son Songhai - sot Sotho, Southern - spa Spanish - sqi Albanian - srd Sardinian - srr Serer - ssa Nilo-Saharan (Other) - ssw Siswant - ssw Swazi - suk Sukuma - sun Sudanese - sus Susu - sux Sumerian - sve Swedish - swa Swahili - swe Swedish - syr Syriac - tah Tahitian - tam Tamil - tat Tatar - tel Telugu - tem Timne - ter Tereno - tgk Tajik - tgl Tagalog - tha Thai - tib Tibetan - tig Tigre - tir Tigrinya - tiv Tivi - tli Tlingit - tmh Tamashek - tog Tonga (Nyasa) - ton Tonga (Tonga Islands) - tru Truk - tsi Tsimshian - tsn Tswana - tso Tsonga - tuk Turkmen - tum Tumbuka - tur Turkish - tut Altaic (Other) - twi Twi - tyv Tuvinian - uga Ugaritic - uig Uighur - ukr Ukrainian - umb Umbundu - und Undetermined - urd Urdu - uzb Uzbek - vai Vai - ven Venda - vie Vietnamese - vol Volapük - vot Votic - wak Wakashan Languages - wal Walamo - war Waray - was Washo - wel Welsh - wen Sorbian Languages - wol Wolof - xho Xhosa - yao Yao - yap Yap - yid Yiddish - yor Yoruba - zap Zapotec - zen Zenaga - zha Zhuang - zho Chinese - zul Zulu - zun Zuni - - */ - - return getid3_lib::EmbeddedLookup($languagecode, $begin, __LINE__, __FILE__, 'id3v2-languagecode'); - } - - - public static function ETCOEventLookup($index) { - if (($index >= 0x17) && ($index <= 0xDF)) { - return 'reserved for future use'; - } - if (($index >= 0xE0) && ($index <= 0xEF)) { - return 'not predefined synch 0-F'; - } - if (($index >= 0xF0) && ($index <= 0xFC)) { - return 'reserved for future use'; - } - - static $EventLookup = array( - 0x00 => 'padding (has no meaning)', - 0x01 => 'end of initial silence', - 0x02 => 'intro start', - 0x03 => 'main part start', - 0x04 => 'outro start', - 0x05 => 'outro end', - 0x06 => 'verse start', - 0x07 => 'refrain start', - 0x08 => 'interlude start', - 0x09 => 'theme start', - 0x0A => 'variation start', - 0x0B => 'key change', - 0x0C => 'time change', - 0x0D => 'momentary unwanted noise (Snap, Crackle & Pop)', - 0x0E => 'sustained noise', - 0x0F => 'sustained noise end', - 0x10 => 'intro end', - 0x11 => 'main part end', - 0x12 => 'verse end', - 0x13 => 'refrain end', - 0x14 => 'theme end', - 0x15 => 'profanity', - 0x16 => 'profanity end', - 0xFD => 'audio end (start of silence)', - 0xFE => 'audio file ends', - 0xFF => 'one more byte of events follows' - ); - - return (isset($EventLookup[$index]) ? $EventLookup[$index] : ''); - } - - public static function SYTLContentTypeLookup($index) { - static $SYTLContentTypeLookup = array( - 0x00 => 'other', - 0x01 => 'lyrics', - 0x02 => 'text transcription', - 0x03 => 'movement/part name', // (e.g. 'Adagio') - 0x04 => 'events', // (e.g. 'Don Quijote enters the stage') - 0x05 => 'chord', // (e.g. 'Bb F Fsus') - 0x06 => 'trivia/\'pop up\' information', - 0x07 => 'URLs to webpages', - 0x08 => 'URLs to images' - ); - - return (isset($SYTLContentTypeLookup[$index]) ? $SYTLContentTypeLookup[$index] : ''); - } - - public static function APICPictureTypeLookup($index, $returnarray=false) { - static $APICPictureTypeLookup = array( - 0x00 => 'Other', - 0x01 => '32x32 pixels \'file icon\' (PNG only)', - 0x02 => 'Other file icon', - 0x03 => 'Cover (front)', - 0x04 => 'Cover (back)', - 0x05 => 'Leaflet page', - 0x06 => 'Media (e.g. label side of CD)', - 0x07 => 'Lead artist/lead performer/soloist', - 0x08 => 'Artist/performer', - 0x09 => 'Conductor', - 0x0A => 'Band/Orchestra', - 0x0B => 'Composer', - 0x0C => 'Lyricist/text writer', - 0x0D => 'Recording Location', - 0x0E => 'During recording', - 0x0F => 'During performance', - 0x10 => 'Movie/video screen capture', - 0x11 => 'A bright coloured fish', - 0x12 => 'Illustration', - 0x13 => 'Band/artist logotype', - 0x14 => 'Publisher/Studio logotype' - ); - if ($returnarray) { - return $APICPictureTypeLookup; - } - return (isset($APICPictureTypeLookup[$index]) ? $APICPictureTypeLookup[$index] : ''); - } - - public static function COMRReceivedAsLookup($index) { - static $COMRReceivedAsLookup = array( - 0x00 => 'Other', - 0x01 => 'Standard CD album with other songs', - 0x02 => 'Compressed audio on CD', - 0x03 => 'File over the Internet', - 0x04 => 'Stream over the Internet', - 0x05 => 'As note sheets', - 0x06 => 'As note sheets in a book with other sheets', - 0x07 => 'Music on other media', - 0x08 => 'Non-musical merchandise' - ); - - return (isset($COMRReceivedAsLookup[$index]) ? $COMRReceivedAsLookup[$index] : ''); - } - - public static function RVA2ChannelTypeLookup($index) { - static $RVA2ChannelTypeLookup = array( - 0x00 => 'Other', - 0x01 => 'Master volume', - 0x02 => 'Front right', - 0x03 => 'Front left', - 0x04 => 'Back right', - 0x05 => 'Back left', - 0x06 => 'Front centre', - 0x07 => 'Back centre', - 0x08 => 'Subwoofer' - ); - - return (isset($RVA2ChannelTypeLookup[$index]) ? $RVA2ChannelTypeLookup[$index] : ''); - } - - public static function FrameNameLongLookup($framename) { - - $begin = __LINE__; - - /** This is not a comment! - - AENC Audio encryption - APIC Attached picture - ASPI Audio seek point index - BUF Recommended buffer size - CNT Play counter - COM Comments - COMM Comments - COMR Commercial frame - CRA Audio encryption - CRM Encrypted meta frame - ENCR Encryption method registration - EQU Equalisation - EQU2 Equalisation (2) - EQUA Equalisation - ETC Event timing codes - ETCO Event timing codes - GEO General encapsulated object - GEOB General encapsulated object - GRID Group identification registration - IPL Involved people list - IPLS Involved people list - LINK Linked information - LNK Linked information - MCDI Music CD identifier - MCI Music CD Identifier - MLL MPEG location lookup table - MLLT MPEG location lookup table - OWNE Ownership frame - PCNT Play counter - PIC Attached picture - POP Popularimeter - POPM Popularimeter - POSS Position synchronisation frame - PRIV Private frame - RBUF Recommended buffer size - REV Reverb - RVA Relative volume adjustment - RVA2 Relative volume adjustment (2) - RVAD Relative volume adjustment - RVRB Reverb - SEEK Seek frame - SIGN Signature frame - SLT Synchronised lyric/text - STC Synced tempo codes - SYLT Synchronised lyric/text - SYTC Synchronised tempo codes - TAL Album/Movie/Show title - TALB Album/Movie/Show title - TBP BPM (Beats Per Minute) - TBPM BPM (beats per minute) - TCM Composer - TCMP Part of a compilation - TCO Content type - TCOM Composer - TCON Content type - TCOP Copyright message - TCP Part of a compilation - TCR Copyright message - TDA Date - TDAT Date - TDEN Encoding time - TDLY Playlist delay - TDOR Original release time - TDRC Recording time - TDRL Release time - TDTG Tagging time - TDY Playlist delay - TEN Encoded by - TENC Encoded by - TEXT Lyricist/Text writer - TFLT File type - TFT File type - TIM Time - TIME Time - TIPL Involved people list - TIT1 Content group description - TIT2 Title/songname/content description - TIT3 Subtitle/Description refinement - TKE Initial key - TKEY Initial key - TLA Language(s) - TLAN Language(s) - TLE Length - TLEN Length - TMCL Musician credits list - TMED Media type - TMOO Mood - TMT Media type - TOA Original artist(s)/performer(s) - TOAL Original album/movie/show title - TOF Original filename - TOFN Original filename - TOL Original Lyricist(s)/text writer(s) - TOLY Original lyricist(s)/text writer(s) - TOPE Original artist(s)/performer(s) - TOR Original release year - TORY Original release year - TOT Original album/Movie/Show title - TOWN File owner/licensee - TP1 Lead artist(s)/Lead performer(s)/Soloist(s)/Performing group - TP2 Band/Orchestra/Accompaniment - TP3 Conductor/Performer refinement - TP4 Interpreted, remixed, or otherwise modified by - TPA Part of a set - TPB Publisher - TPE1 Lead performer(s)/Soloist(s) - TPE2 Band/orchestra/accompaniment - TPE3 Conductor/performer refinement - TPE4 Interpreted, remixed, or otherwise modified by - TPOS Part of a set - TPRO Produced notice - TPUB Publisher - TRC ISRC (International Standard Recording Code) - TRCK Track number/Position in set - TRD Recording dates - TRDA Recording dates - TRK Track number/Position in set - TRSN Internet radio station name - TRSO Internet radio station owner - TS2 Album-Artist sort order - TSA Album sort order - TSC Composer sort order - TSI Size - TSIZ Size - TSO2 Album-Artist sort order - TSOA Album sort order - TSOC Composer sort order - TSOP Performer sort order - TSOT Title sort order - TSP Performer sort order - TSRC ISRC (international standard recording code) - TSS Software/hardware and settings used for encoding - TSSE Software/Hardware and settings used for encoding - TSST Set subtitle - TST Title sort order - TT1 Content group description - TT2 Title/Songname/Content description - TT3 Subtitle/Description refinement - TXT Lyricist/text writer - TXX User defined text information frame - TXXX User defined text information frame - TYE Year - TYER Year - UFI Unique file identifier - UFID Unique file identifier - ULT Unsychronised lyric/text transcription - USER Terms of use - USLT Unsynchronised lyric/text transcription - WAF Official audio file webpage - WAR Official artist/performer webpage - WAS Official audio source webpage - WCM Commercial information - WCOM Commercial information - WCOP Copyright/Legal information - WCP Copyright/Legal information - WOAF Official audio file webpage - WOAR Official artist/performer webpage - WOAS Official audio source webpage - WORS Official Internet radio station homepage - WPAY Payment - WPB Publishers official webpage - WPUB Publishers official webpage - WXX User defined URL link frame - WXXX User defined URL link frame - TFEA Featured Artist - TSTU Recording Studio - rgad Replay Gain Adjustment - - */ - - return getid3_lib::EmbeddedLookup($framename, $begin, __LINE__, __FILE__, 'id3v2-framename_long'); - - // Last three: - // from Helium2 [www.helium2.com] - // from http://privatewww.essex.ac.uk/~djmrob/replaygain/file_format_id3v2.html - } - - - public static function FrameNameShortLookup($framename) { - - $begin = __LINE__; - - /** This is not a comment! - - AENC audio_encryption - APIC attached_picture - ASPI audio_seek_point_index - BUF recommended_buffer_size - CNT play_counter - COM comment - COMM comment - COMR commercial_frame - CRA audio_encryption - CRM encrypted_meta_frame - ENCR encryption_method_registration - EQU equalisation - EQU2 equalisation - EQUA equalisation - ETC event_timing_codes - ETCO event_timing_codes - GEO general_encapsulated_object - GEOB general_encapsulated_object - GRID group_identification_registration - IPL involved_people_list - IPLS involved_people_list - LINK linked_information - LNK linked_information - MCDI music_cd_identifier - MCI music_cd_identifier - MLL mpeg_location_lookup_table - MLLT mpeg_location_lookup_table - OWNE ownership_frame - PCNT play_counter - PIC attached_picture - POP popularimeter - POPM popularimeter - POSS position_synchronisation_frame - PRIV private_frame - RBUF recommended_buffer_size - REV reverb - RVA relative_volume_adjustment - RVA2 relative_volume_adjustment - RVAD relative_volume_adjustment - RVRB reverb - SEEK seek_frame - SIGN signature_frame - SLT synchronised_lyric - STC synced_tempo_codes - SYLT synchronised_lyric - SYTC synchronised_tempo_codes - TAL album - TALB album - TBP bpm - TBPM bpm - TCM composer - TCMP part_of_a_compilation - TCO genre - TCOM composer - TCON genre - TCOP copyright_message - TCP part_of_a_compilation - TCR copyright_message - TDA date - TDAT date - TDEN encoding_time - TDLY playlist_delay - TDOR original_release_time - TDRC recording_time - TDRL release_time - TDTG tagging_time - TDY playlist_delay - TEN encoded_by - TENC encoded_by - TEXT lyricist - TFLT file_type - TFT file_type - TIM time - TIME time - TIPL involved_people_list - TIT1 content_group_description - TIT2 title - TIT3 subtitle - TKE initial_key - TKEY initial_key - TLA language - TLAN language - TLE length - TLEN length - TMCL musician_credits_list - TMED media_type - TMOO mood - TMT media_type - TOA original_artist - TOAL original_album - TOF original_filename - TOFN original_filename - TOL original_lyricist - TOLY original_lyricist - TOPE original_artist - TOR original_year - TORY original_year - TOT original_album - TOWN file_owner - TP1 artist - TP2 band - TP3 conductor - TP4 remixer - TPA part_of_a_set - TPB publisher - TPE1 artist - TPE2 band - TPE3 conductor - TPE4 remixer - TPOS part_of_a_set - TPRO produced_notice - TPUB publisher - TRC isrc - TRCK track_number - TRD recording_dates - TRDA recording_dates - TRK track_number - TRSN internet_radio_station_name - TRSO internet_radio_station_owner - TS2 album_artist_sort_order - TSA album_sort_order - TSC composer_sort_order - TSI size - TSIZ size - TSO2 album_artist_sort_order - TSOA album_sort_order - TSOC composer_sort_order - TSOP performer_sort_order - TSOT title_sort_order - TSP performer_sort_order - TSRC isrc - TSS encoder_settings - TSSE encoder_settings - TSST set_subtitle - TST title_sort_order - TT1 content_group_description - TT2 title - TT3 subtitle - TXT lyricist - TXX text - TXXX text - TYE year - TYER year - UFI unique_file_identifier - UFID unique_file_identifier - ULT unsychronised_lyric - USER terms_of_use - USLT unsynchronised_lyric - WAF url_file - WAR url_artist - WAS url_source - WCM commercial_information - WCOM commercial_information - WCOP copyright - WCP copyright - WOAF url_file - WOAR url_artist - WOAS url_source - WORS url_station - WPAY url_payment - WPB url_publisher - WPUB url_publisher - WXX url_user - WXXX url_user - TFEA featured_artist - TSTU recording_studio - rgad replay_gain_adjustment - - */ - - return getid3_lib::EmbeddedLookup($framename, $begin, __LINE__, __FILE__, 'id3v2-framename_short'); - } - - public static function TextEncodingTerminatorLookup($encoding) { - // http://www.id3.org/id3v2.4.0-structure.txt - // Frames that allow different types of text encoding contains a text encoding description byte. Possible encodings: - static $TextEncodingTerminatorLookup = array( - 0 => "\x00", // $00 ISO-8859-1. Terminated with $00. - 1 => "\x00\x00", // $01 UTF-16 encoded Unicode with BOM. All strings in the same frame SHALL have the same byteorder. Terminated with $00 00. - 2 => "\x00\x00", // $02 UTF-16BE encoded Unicode without BOM. Terminated with $00 00. - 3 => "\x00", // $03 UTF-8 encoded Unicode. Terminated with $00. - 255 => "\x00\x00" - ); - return (isset($TextEncodingTerminatorLookup[$encoding]) ? $TextEncodingTerminatorLookup[$encoding] : "\x00"); - } - - public static function TextEncodingNameLookup($encoding) { - // http://www.id3.org/id3v2.4.0-structure.txt - // Frames that allow different types of text encoding contains a text encoding description byte. Possible encodings: - static $TextEncodingNameLookup = array( - 0 => 'ISO-8859-1', // $00 ISO-8859-1. Terminated with $00. - 1 => 'UTF-16', // $01 UTF-16 encoded Unicode with BOM. All strings in the same frame SHALL have the same byteorder. Terminated with $00 00. - 2 => 'UTF-16BE', // $02 UTF-16BE encoded Unicode without BOM. Terminated with $00 00. - 3 => 'UTF-8', // $03 UTF-8 encoded Unicode. Terminated with $00. - 255 => 'UTF-16BE' - ); - return (isset($TextEncodingNameLookup[$encoding]) ? $TextEncodingNameLookup[$encoding] : 'ISO-8859-1'); - } - - public static function IsValidID3v2FrameName($framename, $id3v2majorversion) { - switch ($id3v2majorversion) { - case 2: - return preg_match('#[A-Z][A-Z0-9]{2}#', $framename); - break; - - case 3: - case 4: - return preg_match('#[A-Z][A-Z0-9]{3}#', $framename); - break; - } - return false; - } - - public static function IsANumber($numberstring, $allowdecimal=false, $allownegative=false) { - for ($i = 0; $i < strlen($numberstring); $i++) { - if ((chr($numberstring{$i}) < chr('0')) || (chr($numberstring{$i}) > chr('9'))) { - if (($numberstring{$i} == '.') && $allowdecimal) { - // allowed - } elseif (($numberstring{$i} == '-') && $allownegative && ($i == 0)) { - // allowed - } else { - return false; - } - } - } - return true; - } - - public static function IsValidDateStampString($datestamp) { - if (strlen($datestamp) != 8) { - return false; - } - if (!self::IsANumber($datestamp, false)) { - return false; - } - $year = substr($datestamp, 0, 4); - $month = substr($datestamp, 4, 2); - $day = substr($datestamp, 6, 2); - if (($year == 0) || ($month == 0) || ($day == 0)) { - return false; - } - if ($month > 12) { - return false; - } - if ($day > 31) { - return false; - } - if (($day > 30) && (($month == 4) || ($month == 6) || ($month == 9) || ($month == 11))) { - return false; - } - if (($day > 29) && ($month == 2)) { - return false; - } - return true; - } - - public static function ID3v2HeaderLength($majorversion) { - return (($majorversion == 2) ? 6 : 10); - } - - public static function ID3v22iTunesBrokenFrameName($frame_name) { - // iTunes (multiple versions) has been known to write ID3v2.3 style frames - // but use ID3v2.2 frame names, right-padded using either [space] or [null] - // to make them fit in the 4-byte frame name space of the ID3v2.3 frame. - // This function will detect and translate the corrupt frame name into ID3v2.3 standard. - static $ID3v22_iTunes_BrokenFrames = array( - 'BUF' => 'RBUF', // Recommended buffer size - 'CNT' => 'PCNT', // Play counter - 'COM' => 'COMM', // Comments - 'CRA' => 'AENC', // Audio encryption - 'EQU' => 'EQUA', // Equalisation - 'ETC' => 'ETCO', // Event timing codes - 'GEO' => 'GEOB', // General encapsulated object - 'IPL' => 'IPLS', // Involved people list - 'LNK' => 'LINK', // Linked information - 'MCI' => 'MCDI', // Music CD identifier - 'MLL' => 'MLLT', // MPEG location lookup table - 'PIC' => 'APIC', // Attached picture - 'POP' => 'POPM', // Popularimeter - 'REV' => 'RVRB', // Reverb - 'RVA' => 'RVAD', // Relative volume adjustment - 'SLT' => 'SYLT', // Synchronised lyric/text - 'STC' => 'SYTC', // Synchronised tempo codes - 'TAL' => 'TALB', // Album/Movie/Show title - 'TBP' => 'TBPM', // BPM (beats per minute) - 'TCM' => 'TCOM', // Composer - 'TCO' => 'TCON', // Content type - 'TCP' => 'TCMP', // Part of a compilation - 'TCR' => 'TCOP', // Copyright message - 'TDA' => 'TDAT', // Date - 'TDY' => 'TDLY', // Playlist delay - 'TEN' => 'TENC', // Encoded by - 'TFT' => 'TFLT', // File type - 'TIM' => 'TIME', // Time - 'TKE' => 'TKEY', // Initial key - 'TLA' => 'TLAN', // Language(s) - 'TLE' => 'TLEN', // Length - 'TMT' => 'TMED', // Media type - 'TOA' => 'TOPE', // Original artist(s)/performer(s) - 'TOF' => 'TOFN', // Original filename - 'TOL' => 'TOLY', // Original lyricist(s)/text writer(s) - 'TOR' => 'TORY', // Original release year - 'TOT' => 'TOAL', // Original album/movie/show title - 'TP1' => 'TPE1', // Lead performer(s)/Soloist(s) - 'TP2' => 'TPE2', // Band/orchestra/accompaniment - 'TP3' => 'TPE3', // Conductor/performer refinement - 'TP4' => 'TPE4', // Interpreted, remixed, or otherwise modified by - 'TPA' => 'TPOS', // Part of a set - 'TPB' => 'TPUB', // Publisher - 'TRC' => 'TSRC', // ISRC (international standard recording code) - 'TRD' => 'TRDA', // Recording dates - 'TRK' => 'TRCK', // Track number/Position in set - 'TS2' => 'TSO2', // Album-Artist sort order - 'TSA' => 'TSOA', // Album sort order - 'TSC' => 'TSOC', // Composer sort order - 'TSI' => 'TSIZ', // Size - 'TSP' => 'TSOP', // Performer sort order - 'TSS' => 'TSSE', // Software/Hardware and settings used for encoding - 'TST' => 'TSOT', // Title sort order - 'TT1' => 'TIT1', // Content group description - 'TT2' => 'TIT2', // Title/songname/content description - 'TT3' => 'TIT3', // Subtitle/Description refinement - 'TXT' => 'TEXT', // Lyricist/Text writer - 'TXX' => 'TXXX', // User defined text information frame - 'TYE' => 'TYER', // Year - 'UFI' => 'UFID', // Unique file identifier - 'ULT' => 'USLT', // Unsynchronised lyric/text transcription - 'WAF' => 'WOAF', // Official audio file webpage - 'WAR' => 'WOAR', // Official artist/performer webpage - 'WAS' => 'WOAS', // Official audio source webpage - 'WCM' => 'WCOM', // Commercial information - 'WCP' => 'WCOP', // Copyright/Legal information - 'WPB' => 'WPUB', // Publishers official webpage - 'WXX' => 'WXXX', // User defined URL link frame - ); - if (strlen($frame_name) == 4) { - if ((substr($frame_name, 3, 1) == ' ') || (substr($frame_name, 3, 1) == "\x00")) { - if (isset($ID3v22_iTunes_BrokenFrames[substr($frame_name, 0, 3)])) { - return $ID3v22_iTunes_BrokenFrames[substr($frame_name, 0, 3)]; - } - } - } - return false; - } - + $frame_offset = 0; + @list($parsedFrame['element_id']) = explode("\x00", $parsedFrame['data'], 2); + $frame_offset += strlen($parsedFrame['element_id']."\x00"); + $ctoc_flags_raw = ord(substr($parsedFrame['data'], $frame_offset, 1)); + $frame_offset += 1; + $parsedFrame['entry_count'] = ord(substr($parsedFrame['data'], $frame_offset, 1)); + $frame_offset += 1; + + $terminator_position = null; + for ($i = 0; $i < $parsedFrame['entry_count']; $i++) { + $terminator_position = strpos($parsedFrame['data'], "\x00", $frame_offset); + $parsedFrame['child_element_ids'][$i] = substr($parsedFrame['data'], $frame_offset, $terminator_position - $frame_offset); + $frame_offset = $terminator_position + 1; + } + + $parsedFrame['ctoc_flags']['ordered'] = (bool) ($ctoc_flags_raw & 0x01); + $parsedFrame['ctoc_flags']['top_level'] = (bool) ($ctoc_flags_raw & 0x03); + + unset($ctoc_flags_raw, $terminator_position); + + if ($frame_offset < strlen($parsedFrame['data'])) { + $parsedFrame['subframes'] = []; + while ($frame_offset < strlen($parsedFrame['data'])) { + // + $subframe = []; + $subframe['name'] = substr($parsedFrame['data'], $frame_offset, 4); + $frame_offset += 4; + $subframe['size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + $frame_offset += 4; + $subframe['flags_raw'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); + $frame_offset += 2; + if ($subframe['size'] > (strlen($parsedFrame['data']) - $frame_offset)) { + $this->warning('CTOS subframe "'.$subframe['name'].'" at frame offset '.$frame_offset.' claims to be "'.$subframe['size'].'" bytes, which is more than the available data ('.(strlen($parsedFrame['data']) - $frame_offset).' bytes)'); + break; + } + $subframe_rawdata = substr($parsedFrame['data'], $frame_offset, $subframe['size']); + $frame_offset += $subframe['size']; + + $subframe['encodingid'] = ord(substr($subframe_rawdata, 0, 1)); + $subframe['text'] = substr($subframe_rawdata, 1); + $subframe['encoding'] = $this->TextEncodingNameLookup($subframe['encodingid']); + $encoding_converted_text = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe['text'])); + switch (substr($encoding_converted_text, 0, 2)) { + case "\xFF\xFE": + case "\xFE\xFF": + switch (strtoupper($info['id3v2']['encoding'])) { + case 'ISO-8859-1': + case 'UTF-8': + $encoding_converted_text = substr($encoding_converted_text, 2); + // remove unwanted byte-order-marks + break; + default: + // ignore + break; + } + break; + default: + // do not remove BOM + break; + } + + if (($subframe['name'] == 'TIT2') || ($subframe['name'] == 'TIT3')) { + if ($subframe['name'] == 'TIT2') { + $parsedFrame['toc_name'] = $encoding_converted_text; + } elseif ($subframe['name'] == 'TIT3') { + $parsedFrame['toc_description'] = $encoding_converted_text; + } + $parsedFrame['subframes'][] = $subframe; + } else { + $this->warning('ID3v2.CTOC subframe "'.$subframe['name'].'" not handled (only TIT2 and TIT3)'); + } + } + unset($subframe_rawdata, $subframe, $encoding_converted_text); + } + } + + return true; + } + + public function DeUnsynchronise($data) + { + return str_replace("\xFF\x00", "\xFF", $data); + } + + public function LookupExtendedHeaderRestrictionsTagSizeLimits($index) + { + static $LookupExtendedHeaderRestrictionsTagSizeLimits = [ + 0x00 => 'No more than 128 frames and 1 MB total tag size', + 0x01 => 'No more than 64 frames and 128 KB total tag size', + 0x02 => 'No more than 32 frames and 40 KB total tag size', + 0x03 => 'No more than 32 frames and 4 KB total tag size', + ]; + + return isset($LookupExtendedHeaderRestrictionsTagSizeLimits[$index]) ? $LookupExtendedHeaderRestrictionsTagSizeLimits[$index] : ''; + } + + public function LookupExtendedHeaderRestrictionsTextEncodings($index) + { + static $LookupExtendedHeaderRestrictionsTextEncodings = [ + 0x00 => 'No restrictions', + 0x01 => 'Strings are only encoded with ISO-8859-1 or UTF-8', + ]; + + return isset($LookupExtendedHeaderRestrictionsTextEncodings[$index]) ? $LookupExtendedHeaderRestrictionsTextEncodings[$index] : ''; + } + + public function LookupExtendedHeaderRestrictionsTextFieldSize($index) + { + static $LookupExtendedHeaderRestrictionsTextFieldSize = [ + 0x00 => 'No restrictions', + 0x01 => 'No string is longer than 1024 characters', + 0x02 => 'No string is longer than 128 characters', + 0x03 => 'No string is longer than 30 characters', + ]; + + return isset($LookupExtendedHeaderRestrictionsTextFieldSize[$index]) ? $LookupExtendedHeaderRestrictionsTextFieldSize[$index] : ''; + } + + public function LookupExtendedHeaderRestrictionsImageEncoding($index) + { + static $LookupExtendedHeaderRestrictionsImageEncoding = [ + 0x00 => 'No restrictions', + 0x01 => 'Images are encoded only with PNG or JPEG', + ]; + + return isset($LookupExtendedHeaderRestrictionsImageEncoding[$index]) ? $LookupExtendedHeaderRestrictionsImageEncoding[$index] : ''; + } + + public function LookupExtendedHeaderRestrictionsImageSizeSize($index) + { + static $LookupExtendedHeaderRestrictionsImageSizeSize = [ + 0x00 => 'No restrictions', + 0x01 => 'All images are 256x256 pixels or smaller', + 0x02 => 'All images are 64x64 pixels or smaller', + 0x03 => 'All images are exactly 64x64 pixels, unless required otherwise', + ]; + + return isset($LookupExtendedHeaderRestrictionsImageSizeSize[$index]) ? $LookupExtendedHeaderRestrictionsImageSizeSize[$index] : ''; + } + + public function LookupCurrencyUnits($currencyid) + { + $begin = __LINE__; + + /** This is not a comment! + + + AED Dirhams + AFA Afghanis + ALL Leke + AMD Drams + ANG Guilders + AOA Kwanza + ARS Pesos + ATS Schillings + AUD Dollars + AWG Guilders + AZM Manats + BAM Convertible Marka + BBD Dollars + BDT Taka + BEF Francs + BGL Leva + BHD Dinars + BIF Francs + BMD Dollars + BND Dollars + BOB Bolivianos + BRL Brazil Real + BSD Dollars + BTN Ngultrum + BWP Pulas + BYR Rubles + BZD Dollars + CAD Dollars + CDF Congolese Francs + CHF Francs + CLP Pesos + CNY Yuan Renminbi + COP Pesos + CRC Colones + CUP Pesos + CVE Escudos + CYP Pounds + CZK Koruny + DEM Deutsche Marks + DJF Francs + DKK Kroner + DOP Pesos + DZD Algeria Dinars + EEK Krooni + EGP Pounds + ERN Nakfa + ESP Pesetas + ETB Birr + EUR Euro + FIM Markkaa + FJD Dollars + FKP Pounds + FRF Francs + GBP Pounds + GEL Lari + GGP Pounds + GHC Cedis + GIP Pounds + GMD Dalasi + GNF Francs + GRD Drachmae + GTQ Quetzales + GYD Dollars + HKD Dollars + HNL Lempiras + HRK Kuna + HTG Gourdes + HUF Forints + IDR Rupiahs + IEP Pounds + ILS New Shekels + IMP Pounds + INR Rupees + IQD Dinars + IRR Rials + ISK Kronur + ITL Lire + JEP Pounds + JMD Dollars + JOD Dinars + JPY Yen + KES Shillings + KGS Soms + KHR Riels + KMF Francs + KPW Won + KWD Dinars + KYD Dollars + KZT Tenge + LAK Kips + LBP Pounds + LKR Rupees + LRD Dollars + LSL Maloti + LTL Litai + LUF Francs + LVL Lati + LYD Dinars + MAD Dirhams + MDL Lei + MGF Malagasy Francs + MKD Denars + MMK Kyats + MNT Tugriks + MOP Patacas + MRO Ouguiyas + MTL Liri + MUR Rupees + MVR Rufiyaa + MWK Kwachas + MXN Pesos + MYR Ringgits + MZM Meticais + NAD Dollars + NGN Nairas + NIO Gold Cordobas + NLG Guilders + NOK Krone + NPR Nepal Rupees + NZD Dollars + OMR Rials + PAB Balboa + PEN Nuevos Soles + PGK Kina + PHP Pesos + PKR Rupees + PLN Zlotych + PTE Escudos + PYG Guarani + QAR Rials + ROL Lei + RUR Rubles + RWF Rwanda Francs + SAR Riyals + SBD Dollars + SCR Rupees + SDD Dinars + SEK Kronor + SGD Dollars + SHP Pounds + SIT Tolars + SKK Koruny + SLL Leones + SOS Shillings + SPL Luigini + SRG Guilders + STD Dobras + SVC Colones + SYP Pounds + SZL Emalangeni + THB Baht + TJR Rubles + TMM Manats + TND Dinars + TOP Pa'anga + TRL Liras + TTD Dollars + TVD Tuvalu Dollars + TWD New Dollars + TZS Shillings + UAH Hryvnia + UGX Shillings + USD Dollars + UYU Pesos + UZS Sums + VAL Lire + VEB Bolivares + VND Dong + VUV Vatu + WST Tala + XAF Francs + XAG Ounces + XAU Ounces + XCD Dollars + XDR Special Drawing Rights + XPD Ounces + XPF Francs + XPT Ounces + YER Rials + YUM New Dinars + ZAR Rand + ZMK Kwacha + ZWD Zimbabwe Dollars + */ + + return getid3_lib::EmbeddedLookup($currencyid, $begin, __LINE__, __FILE__, 'id3v2-currency-units'); + } + + public function LookupCurrencyCountry($currencyid) + { + $begin = __LINE__; + + /** This is not a comment! + + AED United Arab Emirates + AFA Afghanistan + ALL Albania + AMD Armenia + ANG Netherlands Antilles + AOA Angola + ARS Argentina + ATS Austria + AUD Australia + AWG Aruba + AZM Azerbaijan + BAM Bosnia and Herzegovina + BBD Barbados + BDT Bangladesh + BEF Belgium + BGL Bulgaria + BHD Bahrain + BIF Burundi + BMD Bermuda + BND Brunei Darussalam + BOB Bolivia + BRL Brazil + BSD Bahamas + BTN Bhutan + BWP Botswana + BYR Belarus + BZD Belize + CAD Canada + CDF Congo/Kinshasa + CHF Switzerland + CLP Chile + CNY China + COP Colombia + CRC Costa Rica + CUP Cuba + CVE Cape Verde + CYP Cyprus + CZK Czech Republic + DEM Germany + DJF Djibouti + DKK Denmark + DOP Dominican Republic + DZD Algeria + EEK Estonia + EGP Egypt + ERN Eritrea + ESP Spain + ETB Ethiopia + EUR Euro Member Countries + FIM Finland + FJD Fiji + FKP Falkland Islands (Malvinas) + FRF France + GBP United Kingdom + GEL Georgia + GGP Guernsey + GHC Ghana + GIP Gibraltar + GMD Gambia + GNF Guinea + GRD Greece + GTQ Guatemala + GYD Guyana + HKD Hong Kong + HNL Honduras + HRK Croatia + HTG Haiti + HUF Hungary + IDR Indonesia + IEP Ireland (Eire) + ILS Israel + IMP Isle of Man + INR India + IQD Iraq + IRR Iran + ISK Iceland + ITL Italy + JEP Jersey + JMD Jamaica + JOD Jordan + JPY Japan + KES Kenya + KGS Kyrgyzstan + KHR Cambodia + KMF Comoros + KPW Korea + KWD Kuwait + KYD Cayman Islands + KZT Kazakstan + LAK Laos + LBP Lebanon + LKR Sri Lanka + LRD Liberia + LSL Lesotho + LTL Lithuania + LUF Luxembourg + LVL Latvia + LYD Libya + MAD Morocco + MDL Moldova + MGF Madagascar + MKD Macedonia + MMK Myanmar (Burma) + MNT Mongolia + MOP Macau + MRO Mauritania + MTL Malta + MUR Mauritius + MVR Maldives (Maldive Islands) + MWK Malawi + MXN Mexico + MYR Malaysia + MZM Mozambique + NAD Namibia + NGN Nigeria + NIO Nicaragua + NLG Netherlands (Holland) + NOK Norway + NPR Nepal + NZD New Zealand + OMR Oman + PAB Panama + PEN Peru + PGK Papua New Guinea + PHP Philippines + PKR Pakistan + PLN Poland + PTE Portugal + PYG Paraguay + QAR Qatar + ROL Romania + RUR Russia + RWF Rwanda + SAR Saudi Arabia + SBD Solomon Islands + SCR Seychelles + SDD Sudan + SEK Sweden + SGD Singapore + SHP Saint Helena + SIT Slovenia + SKK Slovakia + SLL Sierra Leone + SOS Somalia + SPL Seborga + SRG Suriname + STD São Tome and Principe + SVC El Salvador + SYP Syria + SZL Swaziland + THB Thailand + TJR Tajikistan + TMM Turkmenistan + TND Tunisia + TOP Tonga + TRL Turkey + TTD Trinidad and Tobago + TVD Tuvalu + TWD Taiwan + TZS Tanzania + UAH Ukraine + UGX Uganda + USD United States of America + UYU Uruguay + UZS Uzbekistan + VAL Vatican City + VEB Venezuela + VND Viet Nam + VUV Vanuatu + WST Samoa + XAF Communauté Financière Africaine + XAG Silver + XAU Gold + XCD East Caribbean + XDR International Monetary Fund + XPD Palladium + XPF Comptoirs Français du Pacifique + XPT Platinum + YER Yemen + YUM Yugoslavia + ZAR South Africa + ZMK Zambia + ZWD Zimbabwe + */ + + return getid3_lib::EmbeddedLookup($currencyid, $begin, __LINE__, __FILE__, 'id3v2-currency-country'); + } + + public static function LanguageLookup($languagecode, $casesensitive = false) + { + if (! $casesensitive) { + $languagecode = strtolower($languagecode); + } + + // http://www.id3.org/id3v2.4.0-structure.txt + // [4. ID3v2 frame overview] + // The three byte language field, present in several frames, is used to + // describe the language of the frame's content, according to ISO-639-2 + // [ISO-639-2]. The language should be represented in lower case. If the + // language is not known the string "XXX" should be used. + + // ISO 639-2 - http://www.id3.org/iso639-2.html + + $begin = __LINE__; + + /** This is not a comment! + + XXX unknown + xxx unknown + aar Afar + abk Abkhazian + ace Achinese + ach Acoli + ada Adangme + afa Afro-Asiatic (Other) + afh Afrihili + afr Afrikaans + aka Akan + akk Akkadian + alb Albanian + ale Aleut + alg Algonquian Languages + amh Amharic + ang English, Old (ca. 450-1100) + apa Apache Languages + ara Arabic + arc Aramaic + arm Armenian + arn Araucanian + arp Arapaho + art Artificial (Other) + arw Arawak + asm Assamese + ath Athapascan Languages + ava Avaric + ave Avestan + awa Awadhi + aym Aymara + aze Azerbaijani + bad Banda + bai Bamileke Languages + bak Bashkir + bal Baluchi + bam Bambara + ban Balinese + baq Basque + bas Basa + bat Baltic (Other) + bej Beja + bel Byelorussian + bem Bemba + ben Bengali + ber Berber (Other) + bho Bhojpuri + bih Bihari + bik Bikol + bin Bini + bis Bislama + bla Siksika + bnt Bantu (Other) + bod Tibetan + bra Braj + bre Breton + bua Buriat + bug Buginese + bul Bulgarian + bur Burmese + cad Caddo + cai Central American Indian (Other) + car Carib + cat Catalan + cau Caucasian (Other) + ceb Cebuano + cel Celtic (Other) + ces Czech + cha Chamorro + chb Chibcha + che Chechen + chg Chagatai + chi Chinese + chm Mari + chn Chinook jargon + cho Choctaw + chr Cherokee + chu Church Slavic + chv Chuvash + chy Cheyenne + cop Coptic + cor Cornish + cos Corsican + cpe Creoles and Pidgins, English-based (Other) + cpf Creoles and Pidgins, French-based (Other) + cpp Creoles and Pidgins, Portuguese-based (Other) + cre Cree + crp Creoles and Pidgins (Other) + cus Cushitic (Other) + cym Welsh + cze Czech + dak Dakota + dan Danish + del Delaware + deu German + din Dinka + div Divehi + doi Dogri + dra Dravidian (Other) + dua Duala + dum Dutch, Middle (ca. 1050-1350) + dut Dutch + dyu Dyula + dzo Dzongkha + efi Efik + egy Egyptian (Ancient) + eka Ekajuk + ell Greek, Modern (1453-) + elx Elamite + eng English + enm English, Middle (ca. 1100-1500) + epo Esperanto + esk Eskimo (Other) + esl Spanish + est Estonian + eus Basque + ewe Ewe + ewo Ewondo + fan Fang + fao Faroese + fas Persian + fat Fanti + fij Fijian + fin Finnish + fiu Finno-Ugrian (Other) + fon Fon + fra French + fre French + frm French, Middle (ca. 1400-1600) + fro French, Old (842- ca. 1400) + fry Frisian + ful Fulah + gaa Ga + gae Gaelic (Scots) + gai Irish + gay Gayo + gdh Gaelic (Scots) + gem Germanic (Other) + geo Georgian + ger German + gez Geez + gil Gilbertese + glg Gallegan + gmh German, Middle High (ca. 1050-1500) + goh German, Old High (ca. 750-1050) + gon Gondi + got Gothic + grb Grebo + grc Greek, Ancient (to 1453) + gre Greek, Modern (1453-) + grn Guarani + guj Gujarati + hai Haida + hau Hausa + haw Hawaiian + heb Hebrew + her Herero + hil Hiligaynon + him Himachali + hin Hindi + hmo Hiri Motu + hun Hungarian + hup Hupa + hye Armenian + iba Iban + ibo Igbo + ice Icelandic + ijo Ijo + iku Inuktitut + ilo Iloko + ina Interlingua (International Auxiliary language Association) + inc Indic (Other) + ind Indonesian + ine Indo-European (Other) + ine Interlingue + ipk Inupiak + ira Iranian (Other) + iri Irish + iro Iroquoian uages + isl Icelandic + ita Italian + jav Javanese + jaw Javanese + jpn Japanese + jpr Judeo-Persian + jrb Judeo-Arabic + kaa Kara-Kalpak + kab Kabyle + kac Kachin + kal Greenlandic + kam Kamba + kan Kannada + kar Karen + kas Kashmiri + kat Georgian + kau Kanuri + kaw Kawi + kaz Kazakh + kha Khasi + khi Khoisan (Other) + khm Khmer + kho Khotanese + kik Kikuyu + kin Kinyarwanda + kir Kirghiz + kok Konkani + kom Komi + kon Kongo + kor Korean + kpe Kpelle + kro Kru + kru Kurukh + kua Kuanyama + kum Kumyk + kur Kurdish + kus Kusaie + kut Kutenai + lad Ladino + lah Lahnda + lam Lamba + lao Lao + lat Latin + lav Latvian + lez Lezghian + lin Lingala + lit Lithuanian + lol Mongo + loz Lozi + ltz Letzeburgesch + lub Luba-Katanga + lug Ganda + lui Luiseno + lun Lunda + luo Luo (Kenya and Tanzania) + mac Macedonian + mad Madurese + mag Magahi + mah Marshall + mai Maithili + mak Macedonian + mak Makasar + mal Malayalam + man Mandingo + mao Maori + map Austronesian (Other) + mar Marathi + mas Masai + max Manx + may Malay + men Mende + mga Irish, Middle (900 - 1200) + mic Micmac + min Minangkabau + mis Miscellaneous (Other) + mkh Mon-Kmer (Other) + mlg Malagasy + mlt Maltese + mni Manipuri + mno Manobo Languages + moh Mohawk + mol Moldavian + mon Mongolian + mos Mossi + mri Maori + msa Malay + mul Multiple Languages + mun Munda Languages + mus Creek + mwr Marwari + mya Burmese + myn Mayan Languages + nah Aztec + nai North American Indian (Other) + nau Nauru + nav Navajo + nbl Ndebele, South + nde Ndebele, North + ndo Ndongo + nep Nepali + new Newari + nic Niger-Kordofanian (Other) + niu Niuean + nla Dutch + nno Norwegian (Nynorsk) + non Norse, Old + nor Norwegian + nso Sotho, Northern + nub Nubian Languages + nya Nyanja + nym Nyamwezi + nyn Nyankole + nyo Nyoro + nzi Nzima + oci Langue d'Oc (post 1500) + oji Ojibwa + ori Oriya + orm Oromo + osa Osage + oss Ossetic + ota Turkish, Ottoman (1500 - 1928) + oto Otomian Languages + paa Papuan-Australian (Other) + pag Pangasinan + pal Pahlavi + pam Pampanga + pan Panjabi + pap Papiamento + pau Palauan + peo Persian, Old (ca 600 - 400 B.C.) + per Persian + phn Phoenician + pli Pali + pol Polish + pon Ponape + por Portuguese + pra Prakrit uages + pro Provencal, Old (to 1500) + pus Pushto + que Quechua + raj Rajasthani + rar Rarotongan + roa Romance (Other) + roh Rhaeto-Romance + rom Romany + ron Romanian + rum Romanian + run Rundi + rus Russian + sad Sandawe + sag Sango + sah Yakut + sai South American Indian (Other) + sal Salishan Languages + sam Samaritan Aramaic + san Sanskrit + sco Scots + scr Serbo-Croatian + sel Selkup + sem Semitic (Other) + sga Irish, Old (to 900) + shn Shan + sid Sidamo + sin Singhalese + sio Siouan Languages + sit Sino-Tibetan (Other) + sla Slavic (Other) + slk Slovak + slo Slovak + slv Slovenian + smi Sami Languages + smo Samoan + sna Shona + snd Sindhi + sog Sogdian + som Somali + son Songhai + sot Sotho, Southern + spa Spanish + sqi Albanian + srd Sardinian + srr Serer + ssa Nilo-Saharan (Other) + ssw Siswant + ssw Swazi + suk Sukuma + sun Sudanese + sus Susu + sux Sumerian + sve Swedish + swa Swahili + swe Swedish + syr Syriac + tah Tahitian + tam Tamil + tat Tatar + tel Telugu + tem Timne + ter Tereno + tgk Tajik + tgl Tagalog + tha Thai + tib Tibetan + tig Tigre + tir Tigrinya + tiv Tivi + tli Tlingit + tmh Tamashek + tog Tonga (Nyasa) + ton Tonga (Tonga Islands) + tru Truk + tsi Tsimshian + tsn Tswana + tso Tsonga + tuk Turkmen + tum Tumbuka + tur Turkish + tut Altaic (Other) + twi Twi + tyv Tuvinian + uga Ugaritic + uig Uighur + ukr Ukrainian + umb Umbundu + und Undetermined + urd Urdu + uzb Uzbek + vai Vai + ven Venda + vie Vietnamese + vol Volapük + vot Votic + wak Wakashan Languages + wal Walamo + war Waray + was Washo + wel Welsh + wen Sorbian Languages + wol Wolof + xho Xhosa + yao Yao + yap Yap + yid Yiddish + yor Yoruba + zap Zapotec + zen Zenaga + zha Zhuang + zho Chinese + zul Zulu + zun Zuni + */ + + return getid3_lib::EmbeddedLookup($languagecode, $begin, __LINE__, __FILE__, 'id3v2-languagecode'); + } + + public static function ETCOEventLookup($index) + { + if (($index >= 0x17) && ($index <= 0xDF)) { + return 'reserved for future use'; + } + if (($index >= 0xE0) && ($index <= 0xEF)) { + return 'not predefined synch 0-F'; + } + if (($index >= 0xF0) && ($index <= 0xFC)) { + return 'reserved for future use'; + } + + static $EventLookup = [ + 0x00 => 'padding (has no meaning)', + 0x01 => 'end of initial silence', + 0x02 => 'intro start', + 0x03 => 'main part start', + 0x04 => 'outro start', + 0x05 => 'outro end', + 0x06 => 'verse start', + 0x07 => 'refrain start', + 0x08 => 'interlude start', + 0x09 => 'theme start', + 0x0A => 'variation start', + 0x0B => 'key change', + 0x0C => 'time change', + 0x0D => 'momentary unwanted noise (Snap, Crackle & Pop)', + 0x0E => 'sustained noise', + 0x0F => 'sustained noise end', + 0x10 => 'intro end', + 0x11 => 'main part end', + 0x12 => 'verse end', + 0x13 => 'refrain end', + 0x14 => 'theme end', + 0x15 => 'profanity', + 0x16 => 'profanity end', + 0xFD => 'audio end (start of silence)', + 0xFE => 'audio file ends', + 0xFF => 'one more byte of events follows', + ]; + + return isset($EventLookup[$index]) ? $EventLookup[$index] : ''; + } + + public static function SYTLContentTypeLookup($index) + { + static $SYTLContentTypeLookup = [ + 0x00 => 'other', + 0x01 => 'lyrics', + 0x02 => 'text transcription', + 0x03 => 'movement/part name', // (e.g. 'Adagio') + 0x04 => 'events', // (e.g. 'Don Quijote enters the stage') + 0x05 => 'chord', // (e.g. 'Bb F Fsus') + 0x06 => 'trivia/\'pop up\' information', + 0x07 => 'URLs to webpages', + 0x08 => 'URLs to images', + ]; + + return isset($SYTLContentTypeLookup[$index]) ? $SYTLContentTypeLookup[$index] : ''; + } + + public static function APICPictureTypeLookup($index, $returnarray = false) + { + static $APICPictureTypeLookup = [ + 0x00 => 'Other', + 0x01 => '32x32 pixels \'file icon\' (PNG only)', + 0x02 => 'Other file icon', + 0x03 => 'Cover (front)', + 0x04 => 'Cover (back)', + 0x05 => 'Leaflet page', + 0x06 => 'Media (e.g. label side of CD)', + 0x07 => 'Lead artist/lead performer/soloist', + 0x08 => 'Artist/performer', + 0x09 => 'Conductor', + 0x0A => 'Band/Orchestra', + 0x0B => 'Composer', + 0x0C => 'Lyricist/text writer', + 0x0D => 'Recording Location', + 0x0E => 'During recording', + 0x0F => 'During performance', + 0x10 => 'Movie/video screen capture', + 0x11 => 'A bright coloured fish', + 0x12 => 'Illustration', + 0x13 => 'Band/artist logotype', + 0x14 => 'Publisher/Studio logotype', + ]; + if ($returnarray) { + return $APICPictureTypeLookup; + } + + return isset($APICPictureTypeLookup[$index]) ? $APICPictureTypeLookup[$index] : ''; + } + + public static function COMRReceivedAsLookup($index) + { + static $COMRReceivedAsLookup = [ + 0x00 => 'Other', + 0x01 => 'Standard CD album with other songs', + 0x02 => 'Compressed audio on CD', + 0x03 => 'File over the Internet', + 0x04 => 'Stream over the Internet', + 0x05 => 'As note sheets', + 0x06 => 'As note sheets in a book with other sheets', + 0x07 => 'Music on other media', + 0x08 => 'Non-musical merchandise', + ]; + + return isset($COMRReceivedAsLookup[$index]) ? $COMRReceivedAsLookup[$index] : ''; + } + + public static function RVA2ChannelTypeLookup($index) + { + static $RVA2ChannelTypeLookup = [ + 0x00 => 'Other', + 0x01 => 'Master volume', + 0x02 => 'Front right', + 0x03 => 'Front left', + 0x04 => 'Back right', + 0x05 => 'Back left', + 0x06 => 'Front centre', + 0x07 => 'Back centre', + 0x08 => 'Subwoofer', + ]; + + return isset($RVA2ChannelTypeLookup[$index]) ? $RVA2ChannelTypeLookup[$index] : ''; + } + + public static function FrameNameLongLookup($framename) + { + $begin = __LINE__; + + /** This is not a comment! + + AENC Audio encryption + APIC Attached picture + ASPI Audio seek point index + BUF Recommended buffer size + CNT Play counter + COM Comments + COMM Comments + COMR Commercial frame + CRA Audio encryption + CRM Encrypted meta frame + ENCR Encryption method registration + EQU Equalisation + EQU2 Equalisation (2) + EQUA Equalisation + ETC Event timing codes + ETCO Event timing codes + GEO General encapsulated object + GEOB General encapsulated object + GRID Group identification registration + IPL Involved people list + IPLS Involved people list + LINK Linked information + LNK Linked information + MCDI Music CD identifier + MCI Music CD Identifier + MLL MPEG location lookup table + MLLT MPEG location lookup table + OWNE Ownership frame + PCNT Play counter + PIC Attached picture + POP Popularimeter + POPM Popularimeter + POSS Position synchronisation frame + PRIV Private frame + RBUF Recommended buffer size + REV Reverb + RVA Relative volume adjustment + RVA2 Relative volume adjustment (2) + RVAD Relative volume adjustment + RVRB Reverb + SEEK Seek frame + SIGN Signature frame + SLT Synchronised lyric/text + STC Synced tempo codes + SYLT Synchronised lyric/text + SYTC Synchronised tempo codes + TAL Album/Movie/Show title + TALB Album/Movie/Show title + TBP BPM (Beats Per Minute) + TBPM BPM (beats per minute) + TCM Composer + TCMP Part of a compilation + TCO Content type + TCOM Composer + TCON Content type + TCOP Copyright message + TCP Part of a compilation + TCR Copyright message + TDA Date + TDAT Date + TDEN Encoding time + TDLY Playlist delay + TDOR Original release time + TDRC Recording time + TDRL Release time + TDTG Tagging time + TDY Playlist delay + TEN Encoded by + TENC Encoded by + TEXT Lyricist/Text writer + TFLT File type + TFT File type + TIM Time + TIME Time + TIPL Involved people list + TIT1 Content group description + TIT2 Title/songname/content description + TIT3 Subtitle/Description refinement + TKE Initial key + TKEY Initial key + TLA Language(s) + TLAN Language(s) + TLE Length + TLEN Length + TMCL Musician credits list + TMED Media type + TMOO Mood + TMT Media type + TOA Original artist(s)/performer(s) + TOAL Original album/movie/show title + TOF Original filename + TOFN Original filename + TOL Original Lyricist(s)/text writer(s) + TOLY Original lyricist(s)/text writer(s) + TOPE Original artist(s)/performer(s) + TOR Original release year + TORY Original release year + TOT Original album/Movie/Show title + TOWN File owner/licensee + TP1 Lead artist(s)/Lead performer(s)/Soloist(s)/Performing group + TP2 Band/Orchestra/Accompaniment + TP3 Conductor/Performer refinement + TP4 Interpreted, remixed, or otherwise modified by + TPA Part of a set + TPB Publisher + TPE1 Lead performer(s)/Soloist(s) + TPE2 Band/orchestra/accompaniment + TPE3 Conductor/performer refinement + TPE4 Interpreted, remixed, or otherwise modified by + TPOS Part of a set + TPRO Produced notice + TPUB Publisher + TRC ISRC (International Standard Recording Code) + TRCK Track number/Position in set + TRD Recording dates + TRDA Recording dates + TRK Track number/Position in set + TRSN Internet radio station name + TRSO Internet radio station owner + TS2 Album-Artist sort order + TSA Album sort order + TSC Composer sort order + TSI Size + TSIZ Size + TSO2 Album-Artist sort order + TSOA Album sort order + TSOC Composer sort order + TSOP Performer sort order + TSOT Title sort order + TSP Performer sort order + TSRC ISRC (international standard recording code) + TSS Software/hardware and settings used for encoding + TSSE Software/Hardware and settings used for encoding + TSST Set subtitle + TST Title sort order + TT1 Content group description + TT2 Title/Songname/Content description + TT3 Subtitle/Description refinement + TXT Lyricist/text writer + TXX User defined text information frame + TXXX User defined text information frame + TYE Year + TYER Year + UFI Unique file identifier + UFID Unique file identifier + ULT Unsychronised lyric/text transcription + USER Terms of use + USLT Unsynchronised lyric/text transcription + WAF Official audio file webpage + WAR Official artist/performer webpage + WAS Official audio source webpage + WCM Commercial information + WCOM Commercial information + WCOP Copyright/Legal information + WCP Copyright/Legal information + WOAF Official audio file webpage + WOAR Official artist/performer webpage + WOAS Official audio source webpage + WORS Official Internet radio station homepage + WPAY Payment + WPB Publishers official webpage + WPUB Publishers official webpage + WXX User defined URL link frame + WXXX User defined URL link frame + TFEA Featured Artist + TSTU Recording Studio + rgad Replay Gain Adjustment + */ + + return getid3_lib::EmbeddedLookup($framename, $begin, __LINE__, __FILE__, 'id3v2-framename_long'); + + // Last three: + // from Helium2 [www.helium2.com] + // from http://privatewww.essex.ac.uk/~djmrob/replaygain/file_format_id3v2.html + } + + public static function FrameNameShortLookup($framename) + { + $begin = __LINE__; + + /** This is not a comment! + + AENC audio_encryption + APIC attached_picture + ASPI audio_seek_point_index + BUF recommended_buffer_size + CNT play_counter + COM comment + COMM comment + COMR commercial_frame + CRA audio_encryption + CRM encrypted_meta_frame + ENCR encryption_method_registration + EQU equalisation + EQU2 equalisation + EQUA equalisation + ETC event_timing_codes + ETCO event_timing_codes + GEO general_encapsulated_object + GEOB general_encapsulated_object + GRID group_identification_registration + IPL involved_people_list + IPLS involved_people_list + LINK linked_information + LNK linked_information + MCDI music_cd_identifier + MCI music_cd_identifier + MLL mpeg_location_lookup_table + MLLT mpeg_location_lookup_table + OWNE ownership_frame + PCNT play_counter + PIC attached_picture + POP popularimeter + POPM popularimeter + POSS position_synchronisation_frame + PRIV private_frame + RBUF recommended_buffer_size + REV reverb + RVA relative_volume_adjustment + RVA2 relative_volume_adjustment + RVAD relative_volume_adjustment + RVRB reverb + SEEK seek_frame + SIGN signature_frame + SLT synchronised_lyric + STC synced_tempo_codes + SYLT synchronised_lyric + SYTC synchronised_tempo_codes + TAL album + TALB album + TBP bpm + TBPM bpm + TCM composer + TCMP part_of_a_compilation + TCO genre + TCOM composer + TCON genre + TCOP copyright_message + TCP part_of_a_compilation + TCR copyright_message + TDA date + TDAT date + TDEN encoding_time + TDLY playlist_delay + TDOR original_release_time + TDRC recording_time + TDRL release_time + TDTG tagging_time + TDY playlist_delay + TEN encoded_by + TENC encoded_by + TEXT lyricist + TFLT file_type + TFT file_type + TIM time + TIME time + TIPL involved_people_list + TIT1 content_group_description + TIT2 title + TIT3 subtitle + TKE initial_key + TKEY initial_key + TLA language + TLAN language + TLE length + TLEN length + TMCL musician_credits_list + TMED media_type + TMOO mood + TMT media_type + TOA original_artist + TOAL original_album + TOF original_filename + TOFN original_filename + TOL original_lyricist + TOLY original_lyricist + TOPE original_artist + TOR original_year + TORY original_year + TOT original_album + TOWN file_owner + TP1 artist + TP2 band + TP3 conductor + TP4 remixer + TPA part_of_a_set + TPB publisher + TPE1 artist + TPE2 band + TPE3 conductor + TPE4 remixer + TPOS part_of_a_set + TPRO produced_notice + TPUB publisher + TRC isrc + TRCK track_number + TRD recording_dates + TRDA recording_dates + TRK track_number + TRSN internet_radio_station_name + TRSO internet_radio_station_owner + TS2 album_artist_sort_order + TSA album_sort_order + TSC composer_sort_order + TSI size + TSIZ size + TSO2 album_artist_sort_order + TSOA album_sort_order + TSOC composer_sort_order + TSOP performer_sort_order + TSOT title_sort_order + TSP performer_sort_order + TSRC isrc + TSS encoder_settings + TSSE encoder_settings + TSST set_subtitle + TST title_sort_order + TT1 content_group_description + TT2 title + TT3 subtitle + TXT lyricist + TXX text + TXXX text + TYE year + TYER year + UFI unique_file_identifier + UFID unique_file_identifier + ULT unsychronised_lyric + USER terms_of_use + USLT unsynchronised_lyric + WAF url_file + WAR url_artist + WAS url_source + WCM commercial_information + WCOM commercial_information + WCOP copyright + WCP copyright + WOAF url_file + WOAR url_artist + WOAS url_source + WORS url_station + WPAY url_payment + WPB url_publisher + WPUB url_publisher + WXX url_user + WXXX url_user + TFEA featured_artist + TSTU recording_studio + rgad replay_gain_adjustment + */ + + return getid3_lib::EmbeddedLookup($framename, $begin, __LINE__, __FILE__, 'id3v2-framename_short'); + } + + public static function TextEncodingTerminatorLookup($encoding) + { + // http://www.id3.org/id3v2.4.0-structure.txt + // Frames that allow different types of text encoding contains a text encoding description byte. Possible encodings: + static $TextEncodingTerminatorLookup = [ + 0 => "\x00", // $00 ISO-8859-1. Terminated with $00. + 1 => "\x00\x00", // $01 UTF-16 encoded Unicode with BOM. All strings in the same frame SHALL have the same byteorder. Terminated with $00 00. + 2 => "\x00\x00", // $02 UTF-16BE encoded Unicode without BOM. Terminated with $00 00. + 3 => "\x00", // $03 UTF-8 encoded Unicode. Terminated with $00. + 255 => "\x00\x00", + ]; + + return isset($TextEncodingTerminatorLookup[$encoding]) ? $TextEncodingTerminatorLookup[$encoding] : "\x00"; + } + + public static function TextEncodingNameLookup($encoding) + { + // http://www.id3.org/id3v2.4.0-structure.txt + // Frames that allow different types of text encoding contains a text encoding description byte. Possible encodings: + static $TextEncodingNameLookup = [ + 0 => 'ISO-8859-1', // $00 ISO-8859-1. Terminated with $00. + 1 => 'UTF-16', // $01 UTF-16 encoded Unicode with BOM. All strings in the same frame SHALL have the same byteorder. Terminated with $00 00. + 2 => 'UTF-16BE', // $02 UTF-16BE encoded Unicode without BOM. Terminated with $00 00. + 3 => 'UTF-8', // $03 UTF-8 encoded Unicode. Terminated with $00. + 255 => 'UTF-16BE', + ]; + + return isset($TextEncodingNameLookup[$encoding]) ? $TextEncodingNameLookup[$encoding] : 'ISO-8859-1'; + } + + public static function IsValidID3v2FrameName($framename, $id3v2majorversion) + { + switch ($id3v2majorversion) { + case 2: + return preg_match('#[A-Z][A-Z0-9]{2}#', $framename); + break; + + case 3: + case 4: + return preg_match('#[A-Z][A-Z0-9]{3}#', $framename); + break; + } + + return false; + } + + public static function IsANumber($numberstring, $allowdecimal = false, $allownegative = false) + { + for ($i = 0; $i < strlen($numberstring); $i++) { + if ((chr($numberstring[$i]) < chr('0')) || (chr($numberstring[$i]) > chr('9'))) { + if (($numberstring[$i] == '.') && $allowdecimal) { + // allowed + } elseif (($numberstring[$i] == '-') && $allownegative && ($i == 0)) { + // allowed + } else { + return false; + } + } + } + + return true; + } + + public static function IsValidDateStampString($datestamp) + { + if (strlen($datestamp) != 8) { + return false; + } + if (! self::IsANumber($datestamp, false)) { + return false; + } + $year = substr($datestamp, 0, 4); + $month = substr($datestamp, 4, 2); + $day = substr($datestamp, 6, 2); + if (($year == 0) || ($month == 0) || ($day == 0)) { + return false; + } + if ($month > 12) { + return false; + } + if ($day > 31) { + return false; + } + if (($day > 30) && (($month == 4) || ($month == 6) || ($month == 9) || ($month == 11))) { + return false; + } + if (($day > 29) && ($month == 2)) { + return false; + } + + return true; + } + + public static function ID3v2HeaderLength($majorversion) + { + return ($majorversion == 2) ? 6 : 10; + } + + public static function ID3v22iTunesBrokenFrameName($frame_name) + { + // iTunes (multiple versions) has been known to write ID3v2.3 style frames + // but use ID3v2.2 frame names, right-padded using either [space] or [null] + // to make them fit in the 4-byte frame name space of the ID3v2.3 frame. + // This function will detect and translate the corrupt frame name into ID3v2.3 standard. + static $ID3v22_iTunes_BrokenFrames = [ + 'BUF' => 'RBUF', // Recommended buffer size + 'CNT' => 'PCNT', // Play counter + 'COM' => 'COMM', // Comments + 'CRA' => 'AENC', // Audio encryption + 'EQU' => 'EQUA', // Equalisation + 'ETC' => 'ETCO', // Event timing codes + 'GEO' => 'GEOB', // General encapsulated object + 'IPL' => 'IPLS', // Involved people list + 'LNK' => 'LINK', // Linked information + 'MCI' => 'MCDI', // Music CD identifier + 'MLL' => 'MLLT', // MPEG location lookup table + 'PIC' => 'APIC', // Attached picture + 'POP' => 'POPM', // Popularimeter + 'REV' => 'RVRB', // Reverb + 'RVA' => 'RVAD', // Relative volume adjustment + 'SLT' => 'SYLT', // Synchronised lyric/text + 'STC' => 'SYTC', // Synchronised tempo codes + 'TAL' => 'TALB', // Album/Movie/Show title + 'TBP' => 'TBPM', // BPM (beats per minute) + 'TCM' => 'TCOM', // Composer + 'TCO' => 'TCON', // Content type + 'TCP' => 'TCMP', // Part of a compilation + 'TCR' => 'TCOP', // Copyright message + 'TDA' => 'TDAT', // Date + 'TDY' => 'TDLY', // Playlist delay + 'TEN' => 'TENC', // Encoded by + 'TFT' => 'TFLT', // File type + 'TIM' => 'TIME', // Time + 'TKE' => 'TKEY', // Initial key + 'TLA' => 'TLAN', // Language(s) + 'TLE' => 'TLEN', // Length + 'TMT' => 'TMED', // Media type + 'TOA' => 'TOPE', // Original artist(s)/performer(s) + 'TOF' => 'TOFN', // Original filename + 'TOL' => 'TOLY', // Original lyricist(s)/text writer(s) + 'TOR' => 'TORY', // Original release year + 'TOT' => 'TOAL', // Original album/movie/show title + 'TP1' => 'TPE1', // Lead performer(s)/Soloist(s) + 'TP2' => 'TPE2', // Band/orchestra/accompaniment + 'TP3' => 'TPE3', // Conductor/performer refinement + 'TP4' => 'TPE4', // Interpreted, remixed, or otherwise modified by + 'TPA' => 'TPOS', // Part of a set + 'TPB' => 'TPUB', // Publisher + 'TRC' => 'TSRC', // ISRC (international standard recording code) + 'TRD' => 'TRDA', // Recording dates + 'TRK' => 'TRCK', // Track number/Position in set + 'TS2' => 'TSO2', // Album-Artist sort order + 'TSA' => 'TSOA', // Album sort order + 'TSC' => 'TSOC', // Composer sort order + 'TSI' => 'TSIZ', // Size + 'TSP' => 'TSOP', // Performer sort order + 'TSS' => 'TSSE', // Software/Hardware and settings used for encoding + 'TST' => 'TSOT', // Title sort order + 'TT1' => 'TIT1', // Content group description + 'TT2' => 'TIT2', // Title/songname/content description + 'TT3' => 'TIT3', // Subtitle/Description refinement + 'TXT' => 'TEXT', // Lyricist/Text writer + 'TXX' => 'TXXX', // User defined text information frame + 'TYE' => 'TYER', // Year + 'UFI' => 'UFID', // Unique file identifier + 'ULT' => 'USLT', // Unsynchronised lyric/text transcription + 'WAF' => 'WOAF', // Official audio file webpage + 'WAR' => 'WOAR', // Official artist/performer webpage + 'WAS' => 'WOAS', // Official audio source webpage + 'WCM' => 'WCOM', // Commercial information + 'WCP' => 'WCOP', // Copyright/Legal information + 'WPB' => 'WPUB', // Publishers official webpage + 'WXX' => 'WXXX', // User defined URL link frame + ]; + if (strlen($frame_name) == 4) { + if ((substr($frame_name, 3, 1) == ' ') || (substr($frame_name, 3, 1) == "\x00")) { + if (isset($ID3v22_iTunes_BrokenFrames[substr($frame_name, 0, 3)])) { + return $ID3v22_iTunes_BrokenFrames[substr($frame_name, 0, 3)]; + } + } + } + + return false; + } } - diff --git a/app/Library/getid3/getid3/module.tag.lyrics3.php b/app/Library/getid3/getid3/module.tag.lyrics3.php index 1645396b..bf1ebf33 100644 --- a/app/Library/getid3/getid3/module.tag.lyrics3.php +++ b/app/Library/getid3/getid3/module.tag.lyrics3.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,285 +15,280 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_lyrics3 extends getid3_handler { + public function Analyze() + { + $info = &$this->getid3->info; - public function Analyze() { - $info = &$this->getid3->info; + // http://www.volweb.cz/str/tags.htm - // http://www.volweb.cz/str/tags.htm + if (! getid3_lib::intValueSupported($info['filesize'])) { + $this->warning('Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'); - if (!getid3_lib::intValueSupported($info['filesize'])) { - $this->warning('Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'); - return false; - } + return false; + } - $this->fseek((0 - 128 - 9 - 6), SEEK_END); // end - ID3v1 - "LYRICSEND" - [Lyrics3size] - $lyrics3_id3v1 = $this->fread(128 + 9 + 6); - $lyrics3lsz = substr($lyrics3_id3v1, 0, 6); // Lyrics3size - $lyrics3end = substr($lyrics3_id3v1, 6, 9); // LYRICSEND or LYRICS200 - $id3v1tag = substr($lyrics3_id3v1, 15, 128); // ID3v1 + $this->fseek((0 - 128 - 9 - 6), SEEK_END); // end - ID3v1 - "LYRICSEND" - [Lyrics3size] + $lyrics3_id3v1 = $this->fread(128 + 9 + 6); + $lyrics3lsz = substr($lyrics3_id3v1, 0, 6); // Lyrics3size + $lyrics3end = substr($lyrics3_id3v1, 6, 9); // LYRICSEND or LYRICS200 + $id3v1tag = substr($lyrics3_id3v1, 15, 128); // ID3v1 - if ($lyrics3end == 'LYRICSEND') { - // Lyrics3v1, ID3v1, no APE + if ($lyrics3end == 'LYRICSEND') { + // Lyrics3v1, ID3v1, no APE - $lyrics3size = 5100; - $lyrics3offset = $info['filesize'] - 128 - $lyrics3size; - $lyrics3version = 1; + $lyrics3size = 5100; + $lyrics3offset = $info['filesize'] - 128 - $lyrics3size; + $lyrics3version = 1; + } elseif ($lyrics3end == 'LYRICS200') { + // Lyrics3v2, ID3v1, no APE - } elseif ($lyrics3end == 'LYRICS200') { - // Lyrics3v2, ID3v1, no APE + // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200' + $lyrics3size = $lyrics3lsz + 6 + strlen('LYRICS200'); + $lyrics3offset = $info['filesize'] - 128 - $lyrics3size; + $lyrics3version = 2; + } elseif (substr(strrev($lyrics3_id3v1), 0, 9) == strrev('LYRICSEND')) { + // Lyrics3v1, no ID3v1, no APE - // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200' - $lyrics3size = $lyrics3lsz + 6 + strlen('LYRICS200'); - $lyrics3offset = $info['filesize'] - 128 - $lyrics3size; - $lyrics3version = 2; + $lyrics3size = 5100; + $lyrics3offset = $info['filesize'] - $lyrics3size; + $lyrics3version = 1; + $lyrics3offset = $info['filesize'] - $lyrics3size; + } elseif (substr(strrev($lyrics3_id3v1), 0, 9) == strrev('LYRICS200')) { - } elseif (substr(strrev($lyrics3_id3v1), 0, 9) == strrev('LYRICSEND')) { - // Lyrics3v1, no ID3v1, no APE + // Lyrics3v2, no ID3v1, no APE - $lyrics3size = 5100; - $lyrics3offset = $info['filesize'] - $lyrics3size; - $lyrics3version = 1; - $lyrics3offset = $info['filesize'] - $lyrics3size; + $lyrics3size = strrev(substr(strrev($lyrics3_id3v1), 9, 6)) + 6 + strlen('LYRICS200'); // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200' + $lyrics3offset = $info['filesize'] - $lyrics3size; + $lyrics3version = 2; + } else { + if (isset($info['ape']['tag_offset_start']) && ($info['ape']['tag_offset_start'] > 15)) { + $this->fseek($info['ape']['tag_offset_start'] - 15); + $lyrics3lsz = $this->fread(6); + $lyrics3end = $this->fread(9); - } elseif (substr(strrev($lyrics3_id3v1), 0, 9) == strrev('LYRICS200')) { + if ($lyrics3end == 'LYRICSEND') { + // Lyrics3v1, APE, maybe ID3v1 - // Lyrics3v2, no ID3v1, no APE + $lyrics3size = 5100; + $lyrics3offset = $info['ape']['tag_offset_start'] - $lyrics3size; + $info['avdataend'] = $lyrics3offset; + $lyrics3version = 1; + $this->warning('APE tag located after Lyrics3, will probably break Lyrics3 compatability'); + } elseif ($lyrics3end == 'LYRICS200') { + // Lyrics3v2, APE, maybe ID3v1 - $lyrics3size = strrev(substr(strrev($lyrics3_id3v1), 9, 6)) + 6 + strlen('LYRICS200'); // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200' - $lyrics3offset = $info['filesize'] - $lyrics3size; - $lyrics3version = 2; + $lyrics3size = $lyrics3lsz + 6 + strlen('LYRICS200'); // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200' + $lyrics3offset = $info['ape']['tag_offset_start'] - $lyrics3size; + $lyrics3version = 2; + $this->warning('APE tag located after Lyrics3, will probably break Lyrics3 compatability'); + } + } + } - } else { + if (isset($lyrics3offset)) { + $info['avdataend'] = $lyrics3offset; + $this->getLyrics3Data($lyrics3offset, $lyrics3version, $lyrics3size); - if (isset($info['ape']['tag_offset_start']) && ($info['ape']['tag_offset_start'] > 15)) { + if (! isset($info['ape'])) { + if (isset($info['lyrics3']['tag_offset_start'])) { + $GETID3_ERRORARRAY = &$info['warning']; + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.apetag.php', __FILE__, true); + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename); + $getid3_apetag = new getid3_apetag($getid3_temp); + $getid3_apetag->overrideendoffset = $info['lyrics3']['tag_offset_start']; + $getid3_apetag->Analyze(); + if (! empty($getid3_temp->info['ape'])) { + $info['ape'] = $getid3_temp->info['ape']; + } + if (! empty($getid3_temp->info['replay_gain'])) { + $info['replay_gain'] = $getid3_temp->info['replay_gain']; + } + unset($getid3_temp, $getid3_apetag); + } else { + $this->warning('Lyrics3 and APE tags appear to have become entangled (most likely due to updating the APE tags with a non-Lyrics3-aware tagger)'); + } + } + } - $this->fseek($info['ape']['tag_offset_start'] - 15); - $lyrics3lsz = $this->fread(6); - $lyrics3end = $this->fread(9); + return true; + } - if ($lyrics3end == 'LYRICSEND') { - // Lyrics3v1, APE, maybe ID3v1 + public function getLyrics3Data($endoffset, $version, $length) + { + // http://www.volweb.cz/str/tags.htm - $lyrics3size = 5100; - $lyrics3offset = $info['ape']['tag_offset_start'] - $lyrics3size; - $info['avdataend'] = $lyrics3offset; - $lyrics3version = 1; - $this->warning('APE tag located after Lyrics3, will probably break Lyrics3 compatability'); + $info = &$this->getid3->info; - } elseif ($lyrics3end == 'LYRICS200') { - // Lyrics3v2, APE, maybe ID3v1 + if (! getid3_lib::intValueSupported($endoffset)) { + $this->warning('Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'); - $lyrics3size = $lyrics3lsz + 6 + strlen('LYRICS200'); // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200' - $lyrics3offset = $info['ape']['tag_offset_start'] - $lyrics3size; - $lyrics3version = 2; - $this->warning('APE tag located after Lyrics3, will probably break Lyrics3 compatability'); + return false; + } - } + $this->fseek($endoffset); + if ($length <= 0) { + return false; + } + $rawdata = $this->fread($length); - } + $ParsedLyrics3['raw']['lyrics3version'] = $version; + $ParsedLyrics3['raw']['lyrics3tagsize'] = $length; + $ParsedLyrics3['tag_offset_start'] = $endoffset; + $ParsedLyrics3['tag_offset_end'] = $endoffset + $length - 1; - } + if (substr($rawdata, 0, 11) != 'LYRICSBEGIN') { + if (strpos($rawdata, 'LYRICSBEGIN') !== false) { + $this->warning('"LYRICSBEGIN" expected at '.$endoffset.' but actually found at '.($endoffset + strpos($rawdata, 'LYRICSBEGIN')).' - this is invalid for Lyrics3 v'.$version); + $info['avdataend'] = $endoffset + strpos($rawdata, 'LYRICSBEGIN'); + $rawdata = substr($rawdata, strpos($rawdata, 'LYRICSBEGIN')); + $length = strlen($rawdata); + $ParsedLyrics3['tag_offset_start'] = $info['avdataend']; + $ParsedLyrics3['raw']['lyrics3tagsize'] = $length; + } else { + $this->error('"LYRICSBEGIN" expected at '.$endoffset.' but found "'.substr($rawdata, 0, 11).'" instead'); - if (isset($lyrics3offset)) { - $info['avdataend'] = $lyrics3offset; - $this->getLyrics3Data($lyrics3offset, $lyrics3version, $lyrics3size); + return false; + } + } - if (!isset($info['ape'])) { - if (isset($info['lyrics3']['tag_offset_start'])) { - $GETID3_ERRORARRAY = &$info['warning']; - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.apetag.php', __FILE__, true); - $getid3_temp = new getID3(); - $getid3_temp->openfile($this->getid3->filename); - $getid3_apetag = new getid3_apetag($getid3_temp); - $getid3_apetag->overrideendoffset = $info['lyrics3']['tag_offset_start']; - $getid3_apetag->Analyze(); - if (!empty($getid3_temp->info['ape'])) { - $info['ape'] = $getid3_temp->info['ape']; - } - if (!empty($getid3_temp->info['replay_gain'])) { - $info['replay_gain'] = $getid3_temp->info['replay_gain']; - } - unset($getid3_temp, $getid3_apetag); - } else { - $this->warning('Lyrics3 and APE tags appear to have become entangled (most likely due to updating the APE tags with a non-Lyrics3-aware tagger)'); - } - } + switch ($version) { - } + case 1: + if (substr($rawdata, strlen($rawdata) - 9, 9) == 'LYRICSEND') { + $ParsedLyrics3['raw']['LYR'] = trim(substr($rawdata, 11, strlen($rawdata) - 11 - 9)); + $this->Lyrics3LyricsTimestampParse($ParsedLyrics3); + } else { + $this->error('"LYRICSEND" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead'); - return true; - } + return false; + } + break; - public function getLyrics3Data($endoffset, $version, $length) { - // http://www.volweb.cz/str/tags.htm + case 2: + if (substr($rawdata, strlen($rawdata) - 9, 9) == 'LYRICS200') { + $ParsedLyrics3['raw']['unparsed'] = substr($rawdata, 11, strlen($rawdata) - 11 - 9 - 6); // LYRICSBEGIN + LYRICS200 + LSZ + $rawdata = $ParsedLyrics3['raw']['unparsed']; + while (strlen($rawdata) > 0) { + $fieldname = substr($rawdata, 0, 3); + $fieldsize = (int) substr($rawdata, 3, 5); + $ParsedLyrics3['raw'][$fieldname] = substr($rawdata, 8, $fieldsize); + $rawdata = substr($rawdata, 3 + 5 + $fieldsize); + } - $info = &$this->getid3->info; + if (isset($ParsedLyrics3['raw']['IND'])) { + $i = 0; + $flagnames = ['lyrics', 'timestamps', 'inhibitrandom']; + foreach ($flagnames as $flagname) { + if (strlen($ParsedLyrics3['raw']['IND']) > $i++) { + $ParsedLyrics3['flags'][$flagname] = $this->IntString2Bool(substr($ParsedLyrics3['raw']['IND'], $i, 1 - 1)); + } + } + } - if (!getid3_lib::intValueSupported($endoffset)) { - $this->warning('Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'); - return false; - } + $fieldnametranslation = ['ETT'=>'title', 'EAR'=>'artist', 'EAL'=>'album', 'INF'=>'comment', 'AUT'=>'author']; + foreach ($fieldnametranslation as $key => $value) { + if (isset($ParsedLyrics3['raw'][$key])) { + $ParsedLyrics3['comments'][$value][] = trim($ParsedLyrics3['raw'][$key]); + } + } - $this->fseek($endoffset); - if ($length <= 0) { - return false; - } - $rawdata = $this->fread($length); + if (isset($ParsedLyrics3['raw']['IMG'])) { + $imagestrings = explode("\r\n", $ParsedLyrics3['raw']['IMG']); + foreach ($imagestrings as $key => $imagestring) { + if (strpos($imagestring, '||') !== false) { + $imagearray = explode('||', $imagestring); + $ParsedLyrics3['images'][$key]['filename'] = (isset($imagearray[0]) ? $imagearray[0] : ''); + $ParsedLyrics3['images'][$key]['description'] = (isset($imagearray[1]) ? $imagearray[1] : ''); + $ParsedLyrics3['images'][$key]['timestamp'] = $this->Lyrics3Timestamp2Seconds(isset($imagearray[2]) ? $imagearray[2] : ''); + } + } + } + if (isset($ParsedLyrics3['raw']['LYR'])) { + $this->Lyrics3LyricsTimestampParse($ParsedLyrics3); + } + } else { + $this->error('"LYRICS200" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead'); - $ParsedLyrics3['raw']['lyrics3version'] = $version; - $ParsedLyrics3['raw']['lyrics3tagsize'] = $length; - $ParsedLyrics3['tag_offset_start'] = $endoffset; - $ParsedLyrics3['tag_offset_end'] = $endoffset + $length - 1; + return false; + } + break; - if (substr($rawdata, 0, 11) != 'LYRICSBEGIN') { - if (strpos($rawdata, 'LYRICSBEGIN') !== false) { + default: + $this->error('Cannot process Lyrics3 version '.$version.' (only v1 and v2)'); - $this->warning('"LYRICSBEGIN" expected at '.$endoffset.' but actually found at '.($endoffset + strpos($rawdata, 'LYRICSBEGIN')).' - this is invalid for Lyrics3 v'.$version); - $info['avdataend'] = $endoffset + strpos($rawdata, 'LYRICSBEGIN'); - $rawdata = substr($rawdata, strpos($rawdata, 'LYRICSBEGIN')); - $length = strlen($rawdata); - $ParsedLyrics3['tag_offset_start'] = $info['avdataend']; - $ParsedLyrics3['raw']['lyrics3tagsize'] = $length; + return false; + break; + } - } else { + if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] <= $ParsedLyrics3['tag_offset_end'])) { + $this->warning('ID3v1 tag information ignored since it appears to be a false synch in Lyrics3 tag data'); + unset($info['id3v1']); + foreach ($info['warning'] as $key => $value) { + if ($value == 'Some ID3v1 fields do not use NULL characters for padding') { + unset($info['warning'][$key]); + sort($info['warning']); + break; + } + } + } - $this->error('"LYRICSBEGIN" expected at '.$endoffset.' but found "'.substr($rawdata, 0, 11).'" instead'); - return false; + $info['lyrics3'] = $ParsedLyrics3; - } + return true; + } - } + public function Lyrics3Timestamp2Seconds($rawtimestamp) + { + if (preg_match('#^\\[([0-9]{2}):([0-9]{2})\\]$#', $rawtimestamp, $regs)) { + return (int) (($regs[1] * 60) + $regs[2]); + } - switch ($version) { + return false; + } - case 1: - if (substr($rawdata, strlen($rawdata) - 9, 9) == 'LYRICSEND') { - $ParsedLyrics3['raw']['LYR'] = trim(substr($rawdata, 11, strlen($rawdata) - 11 - 9)); - $this->Lyrics3LyricsTimestampParse($ParsedLyrics3); - } else { - $this->error('"LYRICSEND" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead'); - return false; - } - break; + public function Lyrics3LyricsTimestampParse(&$Lyrics3data) + { + $lyricsarray = explode("\r\n", $Lyrics3data['raw']['LYR']); + foreach ($lyricsarray as $key => $lyricline) { + $regs = []; + unset($thislinetimestamps); + while (preg_match('#^(\\[[0-9]{2}:[0-9]{2}\\])#', $lyricline, $regs)) { + $thislinetimestamps[] = $this->Lyrics3Timestamp2Seconds($regs[0]); + $lyricline = str_replace($regs[0], '', $lyricline); + } + $notimestamplyricsarray[$key] = $lyricline; + if (isset($thislinetimestamps) && is_array($thislinetimestamps)) { + sort($thislinetimestamps); + foreach ($thislinetimestamps as $timestampkey => $timestamp) { + if (isset($Lyrics3data['synchedlyrics'][$timestamp])) { + // timestamps only have a 1-second resolution, it's possible that multiple lines + // could have the same timestamp, if so, append + $Lyrics3data['synchedlyrics'][$timestamp] .= "\r\n".$lyricline; + } else { + $Lyrics3data['synchedlyrics'][$timestamp] = $lyricline; + } + } + } + } + $Lyrics3data['unsynchedlyrics'] = implode("\r\n", $notimestamplyricsarray); + if (isset($Lyrics3data['synchedlyrics']) && is_array($Lyrics3data['synchedlyrics'])) { + ksort($Lyrics3data['synchedlyrics']); + } - case 2: - if (substr($rawdata, strlen($rawdata) - 9, 9) == 'LYRICS200') { - $ParsedLyrics3['raw']['unparsed'] = substr($rawdata, 11, strlen($rawdata) - 11 - 9 - 6); // LYRICSBEGIN + LYRICS200 + LSZ - $rawdata = $ParsedLyrics3['raw']['unparsed']; - while (strlen($rawdata) > 0) { - $fieldname = substr($rawdata, 0, 3); - $fieldsize = (int) substr($rawdata, 3, 5); - $ParsedLyrics3['raw'][$fieldname] = substr($rawdata, 8, $fieldsize); - $rawdata = substr($rawdata, 3 + 5 + $fieldsize); - } + return true; + } - if (isset($ParsedLyrics3['raw']['IND'])) { - $i = 0; - $flagnames = array('lyrics', 'timestamps', 'inhibitrandom'); - foreach ($flagnames as $flagname) { - if (strlen($ParsedLyrics3['raw']['IND']) > $i++) { - $ParsedLyrics3['flags'][$flagname] = $this->IntString2Bool(substr($ParsedLyrics3['raw']['IND'], $i, 1 - 1)); - } - } - } + public function IntString2Bool($char) + { + if ($char == '1') { + return true; + } elseif ($char == '0') { + return false; + } - $fieldnametranslation = array('ETT'=>'title', 'EAR'=>'artist', 'EAL'=>'album', 'INF'=>'comment', 'AUT'=>'author'); - foreach ($fieldnametranslation as $key => $value) { - if (isset($ParsedLyrics3['raw'][$key])) { - $ParsedLyrics3['comments'][$value][] = trim($ParsedLyrics3['raw'][$key]); - } - } - - if (isset($ParsedLyrics3['raw']['IMG'])) { - $imagestrings = explode("\r\n", $ParsedLyrics3['raw']['IMG']); - foreach ($imagestrings as $key => $imagestring) { - if (strpos($imagestring, '||') !== false) { - $imagearray = explode('||', $imagestring); - $ParsedLyrics3['images'][$key]['filename'] = (isset($imagearray[0]) ? $imagearray[0] : ''); - $ParsedLyrics3['images'][$key]['description'] = (isset($imagearray[1]) ? $imagearray[1] : ''); - $ParsedLyrics3['images'][$key]['timestamp'] = $this->Lyrics3Timestamp2Seconds(isset($imagearray[2]) ? $imagearray[2] : ''); - } - } - } - if (isset($ParsedLyrics3['raw']['LYR'])) { - $this->Lyrics3LyricsTimestampParse($ParsedLyrics3); - } - } else { - $this->error('"LYRICS200" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead'); - return false; - } - break; - - default: - $this->error('Cannot process Lyrics3 version '.$version.' (only v1 and v2)'); - return false; - break; - } - - - if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] <= $ParsedLyrics3['tag_offset_end'])) { - $this->warning('ID3v1 tag information ignored since it appears to be a false synch in Lyrics3 tag data'); - unset($info['id3v1']); - foreach ($info['warning'] as $key => $value) { - if ($value == 'Some ID3v1 fields do not use NULL characters for padding') { - unset($info['warning'][$key]); - sort($info['warning']); - break; - } - } - } - - $info['lyrics3'] = $ParsedLyrics3; - - return true; - } - - public function Lyrics3Timestamp2Seconds($rawtimestamp) { - if (preg_match('#^\\[([0-9]{2}):([0-9]{2})\\]$#', $rawtimestamp, $regs)) { - return (int) (($regs[1] * 60) + $regs[2]); - } - return false; - } - - public function Lyrics3LyricsTimestampParse(&$Lyrics3data) { - $lyricsarray = explode("\r\n", $Lyrics3data['raw']['LYR']); - foreach ($lyricsarray as $key => $lyricline) { - $regs = array(); - unset($thislinetimestamps); - while (preg_match('#^(\\[[0-9]{2}:[0-9]{2}\\])#', $lyricline, $regs)) { - $thislinetimestamps[] = $this->Lyrics3Timestamp2Seconds($regs[0]); - $lyricline = str_replace($regs[0], '', $lyricline); - } - $notimestamplyricsarray[$key] = $lyricline; - if (isset($thislinetimestamps) && is_array($thislinetimestamps)) { - sort($thislinetimestamps); - foreach ($thislinetimestamps as $timestampkey => $timestamp) { - if (isset($Lyrics3data['synchedlyrics'][$timestamp])) { - // timestamps only have a 1-second resolution, it's possible that multiple lines - // could have the same timestamp, if so, append - $Lyrics3data['synchedlyrics'][$timestamp] .= "\r\n".$lyricline; - } else { - $Lyrics3data['synchedlyrics'][$timestamp] = $lyricline; - } - } - } - } - $Lyrics3data['unsynchedlyrics'] = implode("\r\n", $notimestamplyricsarray); - if (isset($Lyrics3data['synchedlyrics']) && is_array($Lyrics3data['synchedlyrics'])) { - ksort($Lyrics3data['synchedlyrics']); - } - return true; - } - - public function IntString2Bool($char) { - if ($char == '1') { - return true; - } elseif ($char == '0') { - return false; - } - return null; - } + return null; + } } diff --git a/app/Library/getid3/getid3/module.tag.xmp.php b/app/Library/getid3/getid3/module.tag.xmp.php index 40dd8bd8..826e1edd 100644 --- a/app/Library/getid3/getid3/module.tag.xmp.php +++ b/app/Library/getid3/getid3/module.tag.xmp.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -33,736 +34,710 @@ *************************************************************************************************/ class Image_XMP { - /** - * @var string - * The name of the image file that contains the XMP fields to extract and modify. - * @see Image_XMP() - */ - public $_sFilename = null; + /** + * @var string + * The name of the image file that contains the XMP fields to extract and modify. + * @see Image_XMP() + */ + public $_sFilename = null; - /** - * @var array - * The XMP fields that were extracted from the image or updated by this class. - * @see getAllTags() - */ - public $_aXMP = array(); + /** + * @var array + * The XMP fields that were extracted from the image or updated by this class. + * @see getAllTags() + */ + public $_aXMP = []; - /** - * @var boolean - * True if an APP1 segment was found to contain XMP metadata. - * @see isValid() - */ - public $_bXMPParse = false; + /** + * @var bool + * True if an APP1 segment was found to contain XMP metadata. + * @see isValid() + */ + public $_bXMPParse = false; - /** - * Returns the status of XMP parsing during instantiation - * - * You'll normally want to call this method before trying to get XMP fields. - * - * @return boolean - * Returns true if an APP1 segment was found to contain XMP metadata. - */ - public function isValid() - { - return $this->_bXMPParse; - } + /** + * Returns the status of XMP parsing during instantiation. + * + * You'll normally want to call this method before trying to get XMP fields. + * + * @return bool + * Returns true if an APP1 segment was found to contain XMP metadata. + */ + public function isValid() + { + return $this->_bXMPParse; + } - /** - * Get a copy of all XMP tags extracted from the image - * - * @return array - An array of XMP fields as it extracted by the XMPparse() function - */ - public function getAllTags() - { - return $this->_aXMP; - } + /** + * Get a copy of all XMP tags extracted from the image. + * + * @return array - An array of XMP fields as it extracted by the XMPparse() function + */ + public function getAllTags() + { + return $this->_aXMP; + } - /** - * Reads all the JPEG header segments from an JPEG image file into an array - * - * @param string $filename - the filename of the JPEG file to read - * @return array $headerdata - Array of JPEG header segments - * @return boolean FALSE - if headers could not be read - */ - public function _get_jpeg_header_data($filename) - { - // prevent refresh from aborting file operations and hosing file - ignore_user_abort(true); + /** + * Reads all the JPEG header segments from an JPEG image file into an array. + * + * @param string $filename - the filename of the JPEG file to read + * @return array $headerdata - Array of JPEG header segments + * @return bool FALSE - if headers could not be read + */ + public function _get_jpeg_header_data($filename) + { + // prevent refresh from aborting file operations and hosing file + ignore_user_abort(true); - // Attempt to open the jpeg file - the at symbol supresses the error message about - // not being able to open files. The file_exists would have been used, but it - // does not work with files fetched over http or ftp. - if (is_readable($filename) && is_file($filename) && ($filehnd = fopen($filename, 'rb'))) { - // great - } else { - return false; - } + // Attempt to open the jpeg file - the at symbol supresses the error message about + // not being able to open files. The file_exists would have been used, but it + // does not work with files fetched over http or ftp. + if (is_readable($filename) && is_file($filename) && ($filehnd = fopen($filename, 'rb'))) { + // great + } else { + return false; + } - // Read the first two characters - $data = fread($filehnd, 2); + // Read the first two characters + $data = fread($filehnd, 2); - // Check that the first two characters are 0xFF 0xD8 (SOI - Start of image) - if ($data != "\xFF\xD8") - { - // No SOI (FF D8) at start of file - This probably isn't a JPEG file - close file and return; - echo '

    This probably is not a JPEG file

    '."\n"; - fclose($filehnd); - return false; - } + // Check that the first two characters are 0xFF 0xD8 (SOI - Start of image) + if ($data != "\xFF\xD8") { + // No SOI (FF D8) at start of file - This probably isn't a JPEG file - close file and return; + echo '

    This probably is not a JPEG file

    '."\n"; + fclose($filehnd); - // Read the third character - $data = fread($filehnd, 2); + return false; + } - // Check that the third character is 0xFF (Start of first segment header) - if ($data{0} != "\xFF") - { - // NO FF found - close file and return - JPEG is probably corrupted - fclose($filehnd); - return false; - } + // Read the third character + $data = fread($filehnd, 2); - // Flag that we havent yet hit the compressed image data - $hit_compressed_image_data = false; + // Check that the third character is 0xFF (Start of first segment header) + if ($data[0] != "\xFF") { + // NO FF found - close file and return - JPEG is probably corrupted + fclose($filehnd); - // Cycle through the file until, one of: 1) an EOI (End of image) marker is hit, - // 2) we have hit the compressed image data (no more headers are allowed after data) - // 3) or end of file is hit + return false; + } - while (($data{1} != "\xD9") && (!$hit_compressed_image_data) && (!feof($filehnd))) - { - // Found a segment to look at. - // Check that the segment marker is not a Restart marker - restart markers don't have size or data after them - if ((ord($data{1}) < 0xD0) || (ord($data{1}) > 0xD7)) - { - // Segment isn't a Restart marker - // Read the next two bytes (size) - $sizestr = fread($filehnd, 2); + // Flag that we havent yet hit the compressed image data + $hit_compressed_image_data = false; - // convert the size bytes to an integer - $decodedsize = unpack('nsize', $sizestr); + // Cycle through the file until, one of: 1) an EOI (End of image) marker is hit, + // 2) we have hit the compressed image data (no more headers are allowed after data) + // 3) or end of file is hit - // Save the start position of the data - $segdatastart = ftell($filehnd); + while (($data[1] != "\xD9") && (! $hit_compressed_image_data) && (! feof($filehnd))) { + // Found a segment to look at. + // Check that the segment marker is not a Restart marker - restart markers don't have size or data after them + if ((ord($data[1]) < 0xD0) || (ord($data[1]) > 0xD7)) { + // Segment isn't a Restart marker + // Read the next two bytes (size) + $sizestr = fread($filehnd, 2); - // Read the segment data with length indicated by the previously read size - $segdata = fread($filehnd, $decodedsize['size'] - 2); + // convert the size bytes to an integer + $decodedsize = unpack('nsize', $sizestr); - // Store the segment information in the output array - $headerdata[] = array( - 'SegType' => ord($data{1}), - 'SegName' => $GLOBALS['JPEG_Segment_Names'][ord($data{1})], - 'SegDataStart' => $segdatastart, - 'SegData' => $segdata, - ); - } + // Save the start position of the data + $segdatastart = ftell($filehnd); - // If this is a SOS (Start Of Scan) segment, then there is no more header data - the compressed image data follows - if ($data{1} == "\xDA") - { - // Flag that we have hit the compressed image data - exit loop as no more headers available. - $hit_compressed_image_data = true; - } - else - { - // Not an SOS - Read the next two bytes - should be the segment marker for the next segment - $data = fread($filehnd, 2); + // Read the segment data with length indicated by the previously read size + $segdata = fread($filehnd, $decodedsize['size'] - 2); - // Check that the first byte of the two is 0xFF as it should be for a marker - if ($data{0} != "\xFF") - { - // NO FF found - close file and return - JPEG is probably corrupted - fclose($filehnd); - return false; - } - } - } + // Store the segment information in the output array + $headerdata[] = [ + 'SegType' => ord($data[1]), + 'SegName' => $GLOBALS['JPEG_Segment_Names'][ord($data[1])], + 'SegDataStart' => $segdatastart, + 'SegData' => $segdata, + ]; + } - // Close File - fclose($filehnd); - // Alow the user to abort from now on - ignore_user_abort(false); + // If this is a SOS (Start Of Scan) segment, then there is no more header data - the compressed image data follows + if ($data[1] == "\xDA") { + // Flag that we have hit the compressed image data - exit loop as no more headers available. + $hit_compressed_image_data = true; + } else { + // Not an SOS - Read the next two bytes - should be the segment marker for the next segment + $data = fread($filehnd, 2); - // Return the header data retrieved - return $headerdata; - } + // Check that the first byte of the two is 0xFF as it should be for a marker + if ($data[0] != "\xFF") { + // NO FF found - close file and return - JPEG is probably corrupted + fclose($filehnd); + return false; + } + } + } - /** - * Retrieves XMP information from an APP1 JPEG segment and returns the raw XML text as a string. - * - * @param string $filename - the filename of the JPEG file to read - * @return string $xmp_data - the string of raw XML text - * @return boolean FALSE - if an APP 1 XMP segment could not be found, or if an error occured - */ - public function _get_XMP_text($filename) - { - //Get JPEG header data - $jpeg_header_data = $this->_get_jpeg_header_data($filename); + // Close File + fclose($filehnd); + // Alow the user to abort from now on + ignore_user_abort(false); - //Cycle through the header segments - for ($i = 0; $i < count($jpeg_header_data); $i++) - { - // If we find an APP1 header, - if (strcmp($jpeg_header_data[$i]['SegName'], 'APP1') == 0) - { - // And if it has the Adobe XMP/RDF label (http://ns.adobe.com/xap/1.0/\x00) , - if (strncmp($jpeg_header_data[$i]['SegData'], 'http://ns.adobe.com/xap/1.0/'."\x00", 29) == 0) - { - // Found a XMP/RDF block - // Return the XMP text - $xmp_data = substr($jpeg_header_data[$i]['SegData'], 29); + // Return the header data retrieved + return $headerdata; + } - return trim($xmp_data); // trim() should not be neccesary, but some files found in the wild with null-terminated block (known samples from Apple Aperture) causes problems elsewhere (see http://www.getid3.org/phpBB3/viewtopic.php?f=4&t=1153) - } - } - } - return false; - } + /** + * Retrieves XMP information from an APP1 JPEG segment and returns the raw XML text as a string. + * + * @param string $filename - the filename of the JPEG file to read + * @return string $xmp_data - the string of raw XML text + * @return bool FALSE - if an APP 1 XMP segment could not be found, or if an error occured + */ + public function _get_XMP_text($filename) + { + //Get JPEG header data + $jpeg_header_data = $this->_get_jpeg_header_data($filename); - /** - * Parses a string containing XMP data (XML), and returns an array - * which contains all the XMP (XML) information. - * - * @param string $xml_text - a string containing the XMP data (XML) to be parsed - * @return array $xmp_array - an array containing all xmp details retrieved. - * @return boolean FALSE - couldn't parse the XMP data - */ - public function read_XMP_array_from_text($xmltext) - { - // Check if there actually is any text to parse - if (trim($xmltext) == '') - { - return false; - } + //Cycle through the header segments + for ($i = 0; $i < count($jpeg_header_data); $i++) { + // If we find an APP1 header, + if (strcmp($jpeg_header_data[$i]['SegName'], 'APP1') == 0) { + // And if it has the Adobe XMP/RDF label (http://ns.adobe.com/xap/1.0/\x00) , + if (strncmp($jpeg_header_data[$i]['SegData'], 'http://ns.adobe.com/xap/1.0/'."\x00", 29) == 0) { + // Found a XMP/RDF block + // Return the XMP text + $xmp_data = substr($jpeg_header_data[$i]['SegData'], 29); - // Create an instance of a xml parser to parse the XML text - $xml_parser = xml_parser_create('UTF-8'); + return trim($xmp_data); // trim() should not be neccesary, but some files found in the wild with null-terminated block (known samples from Apple Aperture) causes problems elsewhere (see http://www.getid3.org/phpBB3/viewtopic.php?f=4&t=1153) + } + } + } - // Change: Fixed problem that caused the whitespace (especially newlines) to be destroyed when converting xml text to an xml array, as of revision 1.10 + return false; + } - // We would like to remove unneccessary white space, but this will also - // remove things like newlines ( ) in the XML values, so white space - // will have to be removed later - if (xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 0) == false) - { - // Error setting case folding - destroy the parser and return - xml_parser_free($xml_parser); - return false; - } + /** + * Parses a string containing XMP data (XML), and returns an array + * which contains all the XMP (XML) information. + * + * @param string $xml_text - a string containing the XMP data (XML) to be parsed + * @return array $xmp_array - an array containing all xmp details retrieved. + * @return bool FALSE - couldn't parse the XMP data + */ + public function read_XMP_array_from_text($xmltext) + { + // Check if there actually is any text to parse + if (trim($xmltext) == '') { + return false; + } - // to use XML code correctly we have to turn case folding - // (uppercasing) off. XML is case sensitive and upper - // casing is in reality XML standards violation - if (xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0) == false) - { - // Error setting case folding - destroy the parser and return - xml_parser_free($xml_parser); - return false; - } + // Create an instance of a xml parser to parse the XML text + $xml_parser = xml_parser_create('UTF-8'); - // Parse the XML text into a array structure - if (xml_parse_into_struct($xml_parser, $xmltext, $values, $tags) == 0) - { - // Error Parsing XML - destroy the parser and return - xml_parser_free($xml_parser); - return false; - } + // Change: Fixed problem that caused the whitespace (especially newlines) to be destroyed when converting xml text to an xml array, as of revision 1.10 - // Destroy the xml parser - xml_parser_free($xml_parser); + // We would like to remove unneccessary white space, but this will also + // remove things like newlines ( ) in the XML values, so white space + // will have to be removed later + if (xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 0) == false) { + // Error setting case folding - destroy the parser and return + xml_parser_free($xml_parser); - // Clear the output array - $xmp_array = array(); + return false; + } - // The XMP data has now been parsed into an array ... + // to use XML code correctly we have to turn case folding + // (uppercasing) off. XML is case sensitive and upper + // casing is in reality XML standards violation + if (xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0) == false) { + // Error setting case folding - destroy the parser and return + xml_parser_free($xml_parser); - // Cycle through each of the array elements - $current_property = ''; // current property being processed - $container_index = -1; // -1 = no container open, otherwise index of container content - foreach ($values as $xml_elem) - { - // Syntax and Class names - switch ($xml_elem['tag']) - { - case 'x:xmpmeta': - // only defined attribute is x:xmptk written by Adobe XMP Toolkit; value is the version of the toolkit - break; + return false; + } - case 'rdf:RDF': - // required element immediately within x:xmpmeta; no data here - break; + // Parse the XML text into a array structure + if (xml_parse_into_struct($xml_parser, $xmltext, $values, $tags) == 0) { + // Error Parsing XML - destroy the parser and return + xml_parser_free($xml_parser); - case 'rdf:Description': - switch ($xml_elem['type']) - { - case 'open': - case 'complete': - if (array_key_exists('attributes', $xml_elem)) - { - // rdf:Description may contain wanted attributes - foreach (array_keys($xml_elem['attributes']) as $key) - { - // Check whether we want this details from this attribute -// if (in_array($key, $GLOBALS['XMP_tag_captions'])) - if (true) - { - // Attribute wanted - $xmp_array[$key] = $xml_elem['attributes'][$key]; - } - } - } - case 'cdata': - case 'close': - break; - } + return false; + } - case 'rdf:ID': - case 'rdf:nodeID': - // Attributes are ignored - break; + // Destroy the xml parser + xml_parser_free($xml_parser); - case 'rdf:li': - // Property member - if ($xml_elem['type'] == 'complete') - { - if (array_key_exists('attributes', $xml_elem)) - { - // If Lang Alt (language alternatives) then ensure we take the default language - if (isset($xml_elem['attributes']['xml:lang']) && ($xml_elem['attributes']['xml:lang'] != 'x-default')) - { - break; - } - } - if ($current_property != '') - { - $xmp_array[$current_property][$container_index] = (isset($xml_elem['value']) ? $xml_elem['value'] : ''); - $container_index += 1; - } - //else unidentified attribute!! - } - break; + // Clear the output array + $xmp_array = []; - case 'rdf:Seq': - case 'rdf:Bag': - case 'rdf:Alt': - // Container found - switch ($xml_elem['type']) - { - case 'open': - $container_index = 0; - break; - case 'close': - $container_index = -1; - break; - case 'cdata': - break; - } - break; + // The XMP data has now been parsed into an array ... - default: - // Check whether we want the details from this attribute + // Cycle through each of the array elements + $current_property = ''; // current property being processed + $container_index = -1; // -1 = no container open, otherwise index of container content + foreach ($values as $xml_elem) { + // Syntax and Class names + switch ($xml_elem['tag']) { + case 'x:xmpmeta': + // only defined attribute is x:xmptk written by Adobe XMP Toolkit; value is the version of the toolkit + break; + + case 'rdf:RDF': + // required element immediately within x:xmpmeta; no data here + break; + + case 'rdf:Description': + switch ($xml_elem['type']) { + case 'open': + case 'complete': + if (array_key_exists('attributes', $xml_elem)) { + // rdf:Description may contain wanted attributes + foreach (array_keys($xml_elem['attributes']) as $key) { + // Check whether we want this details from this attribute + // if (in_array($key, $GLOBALS['XMP_tag_captions'])) + if (true) { + // Attribute wanted + $xmp_array[$key] = $xml_elem['attributes'][$key]; + } + } + } + case 'cdata': + case 'close': + break; + } + + case 'rdf:ID': + case 'rdf:nodeID': + // Attributes are ignored + break; + + case 'rdf:li': + // Property member + if ($xml_elem['type'] == 'complete') { + if (array_key_exists('attributes', $xml_elem)) { + // If Lang Alt (language alternatives) then ensure we take the default language + if (isset($xml_elem['attributes']['xml:lang']) && ($xml_elem['attributes']['xml:lang'] != 'x-default')) { + break; + } + } + if ($current_property != '') { + $xmp_array[$current_property][$container_index] = (isset($xml_elem['value']) ? $xml_elem['value'] : ''); + $container_index += 1; + } + //else unidentified attribute!! + } + break; + + case 'rdf:Seq': + case 'rdf:Bag': + case 'rdf:Alt': + // Container found + switch ($xml_elem['type']) { + case 'open': + $container_index = 0; + break; + case 'close': + $container_index = -1; + break; + case 'cdata': + break; + } + break; + + default: + // Check whether we want the details from this attribute // if (in_array($xml_elem['tag'], $GLOBALS['XMP_tag_captions'])) - if (true) - { - switch ($xml_elem['type']) - { - case 'open': - // open current element - $current_property = $xml_elem['tag']; - break; + if (true) { + switch ($xml_elem['type']) { + case 'open': + // open current element + $current_property = $xml_elem['tag']; + break; - case 'close': - // close current element - $current_property = ''; - break; + case 'close': + // close current element + $current_property = ''; + break; - case 'complete': - // store attribute value - $xmp_array[$xml_elem['tag']] = (isset($xml_elem['attributes']) ? $xml_elem['attributes'] : (isset($xml_elem['value']) ? $xml_elem['value'] : '')); - break; + case 'complete': + // store attribute value + $xmp_array[$xml_elem['tag']] = (isset($xml_elem['attributes']) ? $xml_elem['attributes'] : (isset($xml_elem['value']) ? $xml_elem['value'] : '')); + break; - case 'cdata': - // ignore - break; - } - } - break; - } + case 'cdata': + // ignore + break; + } + } + break; + } + } - } - return $xmp_array; - } + return $xmp_array; + } + /** + * Constructor. + * + * @param string - Name of the image file to access and extract XMP information from. + */ + public function __construct($sFilename) + { + $this->_sFilename = $sFilename; - /** - * Constructor - * - * @param string - Name of the image file to access and extract XMP information from. - */ - public function __construct($sFilename) - { - $this->_sFilename = $sFilename; - - if (is_file($this->_sFilename)) - { - // Get XMP data - $xmp_data = $this->_get_XMP_text($sFilename); - if ($xmp_data) - { - $this->_aXMP = $this->read_XMP_array_from_text($xmp_data); - $this->_bXMPParse = true; - } - } - } - + if (is_file($this->_sFilename)) { + // Get XMP data + $xmp_data = $this->_get_XMP_text($sFilename); + if ($xmp_data) { + $this->_aXMP = $this->read_XMP_array_from_text($xmp_data); + $this->_bXMPParse = true; + } + } + } } /** -* Global Variable: XMP_tag_captions -* -* The Property names of all known XMP fields. -* Note: this is a full list with unrequired properties commented out. -*/ + * Global Variable: XMP_tag_captions. + * + * The Property names of all known XMP fields. + * Note: this is a full list with unrequired properties commented out. + */ /* $GLOBALS['XMP_tag_captions'] = array( // IPTC Core - 'Iptc4xmpCore:CiAdrCity', - 'Iptc4xmpCore:CiAdrCtry', - 'Iptc4xmpCore:CiAdrExtadr', - 'Iptc4xmpCore:CiAdrPcode', - 'Iptc4xmpCore:CiAdrRegion', - 'Iptc4xmpCore:CiEmailWork', - 'Iptc4xmpCore:CiTelWork', - 'Iptc4xmpCore:CiUrlWork', - 'Iptc4xmpCore:CountryCode', - 'Iptc4xmpCore:CreatorContactInfo', - 'Iptc4xmpCore:IntellectualGenre', - 'Iptc4xmpCore:Location', - 'Iptc4xmpCore:Scene', - 'Iptc4xmpCore:SubjectCode', + 'Iptc4xmpCore:CiAdrCity', + 'Iptc4xmpCore:CiAdrCtry', + 'Iptc4xmpCore:CiAdrExtadr', + 'Iptc4xmpCore:CiAdrPcode', + 'Iptc4xmpCore:CiAdrRegion', + 'Iptc4xmpCore:CiEmailWork', + 'Iptc4xmpCore:CiTelWork', + 'Iptc4xmpCore:CiUrlWork', + 'Iptc4xmpCore:CountryCode', + 'Iptc4xmpCore:CreatorContactInfo', + 'Iptc4xmpCore:IntellectualGenre', + 'Iptc4xmpCore:Location', + 'Iptc4xmpCore:Scene', + 'Iptc4xmpCore:SubjectCode', // Dublin Core Schema - 'dc:contributor', - 'dc:coverage', - 'dc:creator', - 'dc:date', - 'dc:description', - 'dc:format', - 'dc:identifier', - 'dc:language', - 'dc:publisher', - 'dc:relation', - 'dc:rights', - 'dc:source', - 'dc:subject', - 'dc:title', - 'dc:type', + 'dc:contributor', + 'dc:coverage', + 'dc:creator', + 'dc:date', + 'dc:description', + 'dc:format', + 'dc:identifier', + 'dc:language', + 'dc:publisher', + 'dc:relation', + 'dc:rights', + 'dc:source', + 'dc:subject', + 'dc:title', + 'dc:type', // XMP Basic Schema - 'xmp:Advisory', - 'xmp:BaseURL', - 'xmp:CreateDate', - 'xmp:CreatorTool', - 'xmp:Identifier', - 'xmp:Label', - 'xmp:MetadataDate', - 'xmp:ModifyDate', - 'xmp:Nickname', - 'xmp:Rating', - 'xmp:Thumbnails', - 'xmpidq:Scheme', + 'xmp:Advisory', + 'xmp:BaseURL', + 'xmp:CreateDate', + 'xmp:CreatorTool', + 'xmp:Identifier', + 'xmp:Label', + 'xmp:MetadataDate', + 'xmp:ModifyDate', + 'xmp:Nickname', + 'xmp:Rating', + 'xmp:Thumbnails', + 'xmpidq:Scheme', // XMP Rights Management Schema - 'xmpRights:Certificate', - 'xmpRights:Marked', - 'xmpRights:Owner', - 'xmpRights:UsageTerms', - 'xmpRights:WebStatement', + 'xmpRights:Certificate', + 'xmpRights:Marked', + 'xmpRights:Owner', + 'xmpRights:UsageTerms', + 'xmpRights:WebStatement', // These are not in spec but Photoshop CS seems to use them - 'xap:Advisory', - 'xap:BaseURL', - 'xap:CreateDate', - 'xap:CreatorTool', - 'xap:Identifier', - 'xap:MetadataDate', - 'xap:ModifyDate', - 'xap:Nickname', - 'xap:Rating', - 'xap:Thumbnails', - 'xapidq:Scheme', - 'xapRights:Certificate', - 'xapRights:Copyright', - 'xapRights:Marked', - 'xapRights:Owner', - 'xapRights:UsageTerms', - 'xapRights:WebStatement', + 'xap:Advisory', + 'xap:BaseURL', + 'xap:CreateDate', + 'xap:CreatorTool', + 'xap:Identifier', + 'xap:MetadataDate', + 'xap:ModifyDate', + 'xap:Nickname', + 'xap:Rating', + 'xap:Thumbnails', + 'xapidq:Scheme', + 'xapRights:Certificate', + 'xapRights:Copyright', + 'xapRights:Marked', + 'xapRights:Owner', + 'xapRights:UsageTerms', + 'xapRights:WebStatement', // XMP Media Management Schema - 'xapMM:DerivedFrom', - 'xapMM:DocumentID', - 'xapMM:History', - 'xapMM:InstanceID', - 'xapMM:ManagedFrom', - 'xapMM:Manager', - 'xapMM:ManageTo', - 'xapMM:ManageUI', - 'xapMM:ManagerVariant', - 'xapMM:RenditionClass', - 'xapMM:RenditionParams', - 'xapMM:VersionID', - 'xapMM:Versions', - 'xapMM:LastURL', - 'xapMM:RenditionOf', - 'xapMM:SaveID', + 'xapMM:DerivedFrom', + 'xapMM:DocumentID', + 'xapMM:History', + 'xapMM:InstanceID', + 'xapMM:ManagedFrom', + 'xapMM:Manager', + 'xapMM:ManageTo', + 'xapMM:ManageUI', + 'xapMM:ManagerVariant', + 'xapMM:RenditionClass', + 'xapMM:RenditionParams', + 'xapMM:VersionID', + 'xapMM:Versions', + 'xapMM:LastURL', + 'xapMM:RenditionOf', + 'xapMM:SaveID', // XMP Basic Job Ticket Schema - 'xapBJ:JobRef', + 'xapBJ:JobRef', // XMP Paged-Text Schema - 'xmpTPg:MaxPageSize', - 'xmpTPg:NPages', - 'xmpTPg:Fonts', - 'xmpTPg:Colorants', - 'xmpTPg:PlateNames', + 'xmpTPg:MaxPageSize', + 'xmpTPg:NPages', + 'xmpTPg:Fonts', + 'xmpTPg:Colorants', + 'xmpTPg:PlateNames', // Adobe PDF Schema - 'pdf:Keywords', - 'pdf:PDFVersion', - 'pdf:Producer', + 'pdf:Keywords', + 'pdf:PDFVersion', + 'pdf:Producer', // Photoshop Schema - 'photoshop:AuthorsPosition', - 'photoshop:CaptionWriter', - 'photoshop:Category', - 'photoshop:City', - 'photoshop:Country', - 'photoshop:Credit', - 'photoshop:DateCreated', - 'photoshop:Headline', - 'photoshop:History', + 'photoshop:AuthorsPosition', + 'photoshop:CaptionWriter', + 'photoshop:Category', + 'photoshop:City', + 'photoshop:Country', + 'photoshop:Credit', + 'photoshop:DateCreated', + 'photoshop:Headline', + 'photoshop:History', // Not in XMP spec - 'photoshop:Instructions', - 'photoshop:Source', - 'photoshop:State', - 'photoshop:SupplementalCategories', - 'photoshop:TransmissionReference', - 'photoshop:Urgency', + 'photoshop:Instructions', + 'photoshop:Source', + 'photoshop:State', + 'photoshop:SupplementalCategories', + 'photoshop:TransmissionReference', + 'photoshop:Urgency', // EXIF Schemas - 'tiff:ImageWidth', - 'tiff:ImageLength', - 'tiff:BitsPerSample', - 'tiff:Compression', - 'tiff:PhotometricInterpretation', - 'tiff:Orientation', - 'tiff:SamplesPerPixel', - 'tiff:PlanarConfiguration', - 'tiff:YCbCrSubSampling', - 'tiff:YCbCrPositioning', - 'tiff:XResolution', - 'tiff:YResolution', - 'tiff:ResolutionUnit', - 'tiff:TransferFunction', - 'tiff:WhitePoint', - 'tiff:PrimaryChromaticities', - 'tiff:YCbCrCoefficients', - 'tiff:ReferenceBlackWhite', - 'tiff:DateTime', - 'tiff:ImageDescription', - 'tiff:Make', - 'tiff:Model', - 'tiff:Software', - 'tiff:Artist', - 'tiff:Copyright', - 'exif:ExifVersion', - 'exif:FlashpixVersion', - 'exif:ColorSpace', - 'exif:ComponentsConfiguration', - 'exif:CompressedBitsPerPixel', - 'exif:PixelXDimension', - 'exif:PixelYDimension', - 'exif:MakerNote', - 'exif:UserComment', - 'exif:RelatedSoundFile', - 'exif:DateTimeOriginal', - 'exif:DateTimeDigitized', - 'exif:ExposureTime', - 'exif:FNumber', - 'exif:ExposureProgram', - 'exif:SpectralSensitivity', - 'exif:ISOSpeedRatings', - 'exif:OECF', - 'exif:ShutterSpeedValue', - 'exif:ApertureValue', - 'exif:BrightnessValue', - 'exif:ExposureBiasValue', - 'exif:MaxApertureValue', - 'exif:SubjectDistance', - 'exif:MeteringMode', - 'exif:LightSource', - 'exif:Flash', - 'exif:FocalLength', - 'exif:SubjectArea', - 'exif:FlashEnergy', - 'exif:SpatialFrequencyResponse', - 'exif:FocalPlaneXResolution', - 'exif:FocalPlaneYResolution', - 'exif:FocalPlaneResolutionUnit', - 'exif:SubjectLocation', - 'exif:SensingMethod', - 'exif:FileSource', - 'exif:SceneType', - 'exif:CFAPattern', - 'exif:CustomRendered', - 'exif:ExposureMode', - 'exif:WhiteBalance', - 'exif:DigitalZoomRatio', - 'exif:FocalLengthIn35mmFilm', - 'exif:SceneCaptureType', - 'exif:GainControl', - 'exif:Contrast', - 'exif:Saturation', - 'exif:Sharpness', - 'exif:DeviceSettingDescription', - 'exif:SubjectDistanceRange', - 'exif:ImageUniqueID', - 'exif:GPSVersionID', - 'exif:GPSLatitude', - 'exif:GPSLongitude', - 'exif:GPSAltitudeRef', - 'exif:GPSAltitude', - 'exif:GPSTimeStamp', - 'exif:GPSSatellites', - 'exif:GPSStatus', - 'exif:GPSMeasureMode', - 'exif:GPSDOP', - 'exif:GPSSpeedRef', - 'exif:GPSSpeed', - 'exif:GPSTrackRef', - 'exif:GPSTrack', - 'exif:GPSImgDirectionRef', - 'exif:GPSImgDirection', - 'exif:GPSMapDatum', - 'exif:GPSDestLatitude', - 'exif:GPSDestLongitude', - 'exif:GPSDestBearingRef', - 'exif:GPSDestBearing', - 'exif:GPSDestDistanceRef', - 'exif:GPSDestDistance', - 'exif:GPSProcessingMethod', - 'exif:GPSAreaInformation', - 'exif:GPSDifferential', - 'stDim:w', - 'stDim:h', - 'stDim:unit', - 'xapGImg:height', - 'xapGImg:width', - 'xapGImg:format', - 'xapGImg:image', - 'stEvt:action', - 'stEvt:instanceID', - 'stEvt:parameters', - 'stEvt:softwareAgent', - 'stEvt:when', - 'stRef:instanceID', - 'stRef:documentID', - 'stRef:versionID', - 'stRef:renditionClass', - 'stRef:renditionParams', - 'stRef:manager', - 'stRef:managerVariant', - 'stRef:manageTo', - 'stRef:manageUI', - 'stVer:comments', - 'stVer:event', - 'stVer:modifyDate', - 'stVer:modifier', - 'stVer:version', - 'stJob:name', - 'stJob:id', - 'stJob:url', + 'tiff:ImageWidth', + 'tiff:ImageLength', + 'tiff:BitsPerSample', + 'tiff:Compression', + 'tiff:PhotometricInterpretation', + 'tiff:Orientation', + 'tiff:SamplesPerPixel', + 'tiff:PlanarConfiguration', + 'tiff:YCbCrSubSampling', + 'tiff:YCbCrPositioning', + 'tiff:XResolution', + 'tiff:YResolution', + 'tiff:ResolutionUnit', + 'tiff:TransferFunction', + 'tiff:WhitePoint', + 'tiff:PrimaryChromaticities', + 'tiff:YCbCrCoefficients', + 'tiff:ReferenceBlackWhite', + 'tiff:DateTime', + 'tiff:ImageDescription', + 'tiff:Make', + 'tiff:Model', + 'tiff:Software', + 'tiff:Artist', + 'tiff:Copyright', + 'exif:ExifVersion', + 'exif:FlashpixVersion', + 'exif:ColorSpace', + 'exif:ComponentsConfiguration', + 'exif:CompressedBitsPerPixel', + 'exif:PixelXDimension', + 'exif:PixelYDimension', + 'exif:MakerNote', + 'exif:UserComment', + 'exif:RelatedSoundFile', + 'exif:DateTimeOriginal', + 'exif:DateTimeDigitized', + 'exif:ExposureTime', + 'exif:FNumber', + 'exif:ExposureProgram', + 'exif:SpectralSensitivity', + 'exif:ISOSpeedRatings', + 'exif:OECF', + 'exif:ShutterSpeedValue', + 'exif:ApertureValue', + 'exif:BrightnessValue', + 'exif:ExposureBiasValue', + 'exif:MaxApertureValue', + 'exif:SubjectDistance', + 'exif:MeteringMode', + 'exif:LightSource', + 'exif:Flash', + 'exif:FocalLength', + 'exif:SubjectArea', + 'exif:FlashEnergy', + 'exif:SpatialFrequencyResponse', + 'exif:FocalPlaneXResolution', + 'exif:FocalPlaneYResolution', + 'exif:FocalPlaneResolutionUnit', + 'exif:SubjectLocation', + 'exif:SensingMethod', + 'exif:FileSource', + 'exif:SceneType', + 'exif:CFAPattern', + 'exif:CustomRendered', + 'exif:ExposureMode', + 'exif:WhiteBalance', + 'exif:DigitalZoomRatio', + 'exif:FocalLengthIn35mmFilm', + 'exif:SceneCaptureType', + 'exif:GainControl', + 'exif:Contrast', + 'exif:Saturation', + 'exif:Sharpness', + 'exif:DeviceSettingDescription', + 'exif:SubjectDistanceRange', + 'exif:ImageUniqueID', + 'exif:GPSVersionID', + 'exif:GPSLatitude', + 'exif:GPSLongitude', + 'exif:GPSAltitudeRef', + 'exif:GPSAltitude', + 'exif:GPSTimeStamp', + 'exif:GPSSatellites', + 'exif:GPSStatus', + 'exif:GPSMeasureMode', + 'exif:GPSDOP', + 'exif:GPSSpeedRef', + 'exif:GPSSpeed', + 'exif:GPSTrackRef', + 'exif:GPSTrack', + 'exif:GPSImgDirectionRef', + 'exif:GPSImgDirection', + 'exif:GPSMapDatum', + 'exif:GPSDestLatitude', + 'exif:GPSDestLongitude', + 'exif:GPSDestBearingRef', + 'exif:GPSDestBearing', + 'exif:GPSDestDistanceRef', + 'exif:GPSDestDistance', + 'exif:GPSProcessingMethod', + 'exif:GPSAreaInformation', + 'exif:GPSDifferential', + 'stDim:w', + 'stDim:h', + 'stDim:unit', + 'xapGImg:height', + 'xapGImg:width', + 'xapGImg:format', + 'xapGImg:image', + 'stEvt:action', + 'stEvt:instanceID', + 'stEvt:parameters', + 'stEvt:softwareAgent', + 'stEvt:when', + 'stRef:instanceID', + 'stRef:documentID', + 'stRef:versionID', + 'stRef:renditionClass', + 'stRef:renditionParams', + 'stRef:manager', + 'stRef:managerVariant', + 'stRef:manageTo', + 'stRef:manageUI', + 'stVer:comments', + 'stVer:event', + 'stVer:modifyDate', + 'stVer:modifier', + 'stVer:version', + 'stJob:name', + 'stJob:id', + 'stJob:url', // Exif Flash - 'exif:Fired', - 'exif:Return', - 'exif:Mode', - 'exif:Function', - 'exif:RedEyeMode', + 'exif:Fired', + 'exif:Return', + 'exif:Mode', + 'exif:Function', + 'exif:RedEyeMode', // Exif OECF/SFR - 'exif:Columns', - 'exif:Rows', - 'exif:Names', - 'exif:Values', + 'exif:Columns', + 'exif:Rows', + 'exif:Names', + 'exif:Values', // Exif CFAPattern - 'exif:Columns', - 'exif:Rows', - 'exif:Values', + 'exif:Columns', + 'exif:Rows', + 'exif:Values', // Exif DeviceSettings - 'exif:Columns', - 'exif:Rows', - 'exif:Settings', + 'exif:Columns', + 'exif:Rows', + 'exif:Settings', ); */ /** -* Global Variable: JPEG_Segment_Names -* -* The names of the JPEG segment markers, indexed by their marker number -*/ -$GLOBALS['JPEG_Segment_Names'] = array( - 0x01 => 'TEM', - 0x02 => 'RES', - 0xC0 => 'SOF0', - 0xC1 => 'SOF1', - 0xC2 => 'SOF2', - 0xC3 => 'SOF4', - 0xC4 => 'DHT', - 0xC5 => 'SOF5', - 0xC6 => 'SOF6', - 0xC7 => 'SOF7', - 0xC8 => 'JPG', - 0xC9 => 'SOF9', - 0xCA => 'SOF10', - 0xCB => 'SOF11', - 0xCC => 'DAC', - 0xCD => 'SOF13', - 0xCE => 'SOF14', - 0xCF => 'SOF15', - 0xD0 => 'RST0', - 0xD1 => 'RST1', - 0xD2 => 'RST2', - 0xD3 => 'RST3', - 0xD4 => 'RST4', - 0xD5 => 'RST5', - 0xD6 => 'RST6', - 0xD7 => 'RST7', - 0xD8 => 'SOI', - 0xD9 => 'EOI', - 0xDA => 'SOS', - 0xDB => 'DQT', - 0xDC => 'DNL', - 0xDD => 'DRI', - 0xDE => 'DHP', - 0xDF => 'EXP', - 0xE0 => 'APP0', - 0xE1 => 'APP1', - 0xE2 => 'APP2', - 0xE3 => 'APP3', - 0xE4 => 'APP4', - 0xE5 => 'APP5', - 0xE6 => 'APP6', - 0xE7 => 'APP7', - 0xE8 => 'APP8', - 0xE9 => 'APP9', - 0xEA => 'APP10', - 0xEB => 'APP11', - 0xEC => 'APP12', - 0xED => 'APP13', - 0xEE => 'APP14', - 0xEF => 'APP15', - 0xF0 => 'JPG0', - 0xF1 => 'JPG1', - 0xF2 => 'JPG2', - 0xF3 => 'JPG3', - 0xF4 => 'JPG4', - 0xF5 => 'JPG5', - 0xF6 => 'JPG6', - 0xF7 => 'JPG7', - 0xF8 => 'JPG8', - 0xF9 => 'JPG9', - 0xFA => 'JPG10', - 0xFB => 'JPG11', - 0xFC => 'JPG12', - 0xFD => 'JPG13', - 0xFE => 'COM', -); + * Global Variable: JPEG_Segment_Names. + * + * The names of the JPEG segment markers, indexed by their marker number + */ +$GLOBALS['JPEG_Segment_Names'] = [ + 0x01 => 'TEM', + 0x02 => 'RES', + 0xC0 => 'SOF0', + 0xC1 => 'SOF1', + 0xC2 => 'SOF2', + 0xC3 => 'SOF4', + 0xC4 => 'DHT', + 0xC5 => 'SOF5', + 0xC6 => 'SOF6', + 0xC7 => 'SOF7', + 0xC8 => 'JPG', + 0xC9 => 'SOF9', + 0xCA => 'SOF10', + 0xCB => 'SOF11', + 0xCC => 'DAC', + 0xCD => 'SOF13', + 0xCE => 'SOF14', + 0xCF => 'SOF15', + 0xD0 => 'RST0', + 0xD1 => 'RST1', + 0xD2 => 'RST2', + 0xD3 => 'RST3', + 0xD4 => 'RST4', + 0xD5 => 'RST5', + 0xD6 => 'RST6', + 0xD7 => 'RST7', + 0xD8 => 'SOI', + 0xD9 => 'EOI', + 0xDA => 'SOS', + 0xDB => 'DQT', + 0xDC => 'DNL', + 0xDD => 'DRI', + 0xDE => 'DHP', + 0xDF => 'EXP', + 0xE0 => 'APP0', + 0xE1 => 'APP1', + 0xE2 => 'APP2', + 0xE3 => 'APP3', + 0xE4 => 'APP4', + 0xE5 => 'APP5', + 0xE6 => 'APP6', + 0xE7 => 'APP7', + 0xE8 => 'APP8', + 0xE9 => 'APP9', + 0xEA => 'APP10', + 0xEB => 'APP11', + 0xEC => 'APP12', + 0xED => 'APP13', + 0xEE => 'APP14', + 0xEF => 'APP15', + 0xF0 => 'JPG0', + 0xF1 => 'JPG1', + 0xF2 => 'JPG2', + 0xF3 => 'JPG3', + 0xF4 => 'JPG4', + 0xF5 => 'JPG5', + 0xF6 => 'JPG6', + 0xF7 => 'JPG7', + 0xF8 => 'JPG8', + 0xF9 => 'JPG9', + 0xFA => 'JPG10', + 0xFB => 'JPG11', + 0xFC => 'JPG12', + 0xFD => 'JPG13', + 0xFE => 'COM', +]; diff --git a/app/Library/getid3/getid3/write.apetag.php b/app/Library/getid3/getid3/write.apetag.php index d6044b29..60036e97 100644 --- a/app/Library/getid3/getid3/write.apetag.php +++ b/app/Library/getid3/getid3/write.apetag.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,211 +15,216 @@ // /// ///////////////////////////////////////////////////////////////// - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.apetag.php', __FILE__, true); class getid3_write_apetag { + public $filename; + public $tag_data; + public $always_preserve_replaygain = true; // ReplayGain / MP3gain tags will be copied from old tag even if not passed in data + public $warnings = []; // any non-critical errors will be stored here + public $errors = []; // any critical errors will be stored here - public $filename; - public $tag_data; - public $always_preserve_replaygain = true; // ReplayGain / MP3gain tags will be copied from old tag even if not passed in data - public $warnings = array(); // any non-critical errors will be stored here - public $errors = array(); // any critical errors will be stored here + public function __construct() + { + return true; + } - public function __construct() { - return true; - } + public function WriteAPEtag() + { + // NOTE: All data passed to this function must be UTF-8 format - public function WriteAPEtag() { - // NOTE: All data passed to this function must be UTF-8 format + $getID3 = new getID3; + $ThisFileInfo = $getID3->analyze($this->filename); - $getID3 = new getID3; - $ThisFileInfo = $getID3->analyze($this->filename); + if (isset($ThisFileInfo['ape']['tag_offset_start']) && isset($ThisFileInfo['lyrics3']['tag_offset_end'])) { + if ($ThisFileInfo['ape']['tag_offset_start'] >= $ThisFileInfo['lyrics3']['tag_offset_end']) { + // Current APE tag between Lyrics3 and ID3v1/EOF + // This break Lyrics3 functionality + if (! $this->DeleteAPEtag()) { + return false; + } + $ThisFileInfo = $getID3->analyze($this->filename); + } + } - if (isset($ThisFileInfo['ape']['tag_offset_start']) && isset($ThisFileInfo['lyrics3']['tag_offset_end'])) { - if ($ThisFileInfo['ape']['tag_offset_start'] >= $ThisFileInfo['lyrics3']['tag_offset_end']) { - // Current APE tag between Lyrics3 and ID3v1/EOF - // This break Lyrics3 functionality - if (!$this->DeleteAPEtag()) { - return false; - } - $ThisFileInfo = $getID3->analyze($this->filename); - } - } + if ($this->always_preserve_replaygain) { + $ReplayGainTagsToPreserve = ['mp3gain_minmax', 'mp3gain_album_minmax', 'mp3gain_undo', 'replaygain_track_peak', 'replaygain_track_gain', 'replaygain_album_peak', 'replaygain_album_gain']; + foreach ($ReplayGainTagsToPreserve as $rg_key) { + if (isset($ThisFileInfo['ape']['items'][strtolower($rg_key)]['data'][0]) && ! isset($this->tag_data[strtoupper($rg_key)][0])) { + $this->tag_data[strtoupper($rg_key)][0] = $ThisFileInfo['ape']['items'][strtolower($rg_key)]['data'][0]; + } + } + } - if ($this->always_preserve_replaygain) { - $ReplayGainTagsToPreserve = array('mp3gain_minmax', 'mp3gain_album_minmax', 'mp3gain_undo', 'replaygain_track_peak', 'replaygain_track_gain', 'replaygain_album_peak', 'replaygain_album_gain'); - foreach ($ReplayGainTagsToPreserve as $rg_key) { - if (isset($ThisFileInfo['ape']['items'][strtolower($rg_key)]['data'][0]) && !isset($this->tag_data[strtoupper($rg_key)][0])) { - $this->tag_data[strtoupper($rg_key)][0] = $ThisFileInfo['ape']['items'][strtolower($rg_key)]['data'][0]; - } - } - } + if ($APEtag = $this->GenerateAPEtag()) { + if (is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'a+b'))) { + $oldignoreuserabort = ignore_user_abort(true); + flock($fp, LOCK_EX); - if ($APEtag = $this->GenerateAPEtag()) { - if (is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'a+b'))) { - $oldignoreuserabort = ignore_user_abort(true); - flock($fp, LOCK_EX); + $PostAPEdataOffset = $ThisFileInfo['avdataend']; + if (isset($ThisFileInfo['ape']['tag_offset_end'])) { + $PostAPEdataOffset = max($PostAPEdataOffset, $ThisFileInfo['ape']['tag_offset_end']); + } + if (isset($ThisFileInfo['lyrics3']['tag_offset_start'])) { + $PostAPEdataOffset = max($PostAPEdataOffset, $ThisFileInfo['lyrics3']['tag_offset_start']); + } + fseek($fp, $PostAPEdataOffset); + $PostAPEdata = ''; + if ($ThisFileInfo['filesize'] > $PostAPEdataOffset) { + $PostAPEdata = fread($fp, $ThisFileInfo['filesize'] - $PostAPEdataOffset); + } - $PostAPEdataOffset = $ThisFileInfo['avdataend']; - if (isset($ThisFileInfo['ape']['tag_offset_end'])) { - $PostAPEdataOffset = max($PostAPEdataOffset, $ThisFileInfo['ape']['tag_offset_end']); - } - if (isset($ThisFileInfo['lyrics3']['tag_offset_start'])) { - $PostAPEdataOffset = max($PostAPEdataOffset, $ThisFileInfo['lyrics3']['tag_offset_start']); - } - fseek($fp, $PostAPEdataOffset); - $PostAPEdata = ''; - if ($ThisFileInfo['filesize'] > $PostAPEdataOffset) { - $PostAPEdata = fread($fp, $ThisFileInfo['filesize'] - $PostAPEdataOffset); - } + fseek($fp, $PostAPEdataOffset); + if (isset($ThisFileInfo['ape']['tag_offset_start'])) { + fseek($fp, $ThisFileInfo['ape']['tag_offset_start']); + } + ftruncate($fp, ftell($fp)); + fwrite($fp, $APEtag, strlen($APEtag)); + if (! empty($PostAPEdata)) { + fwrite($fp, $PostAPEdata, strlen($PostAPEdata)); + } + flock($fp, LOCK_UN); + fclose($fp); + ignore_user_abort($oldignoreuserabort); - fseek($fp, $PostAPEdataOffset); - if (isset($ThisFileInfo['ape']['tag_offset_start'])) { - fseek($fp, $ThisFileInfo['ape']['tag_offset_start']); - } - ftruncate($fp, ftell($fp)); - fwrite($fp, $APEtag, strlen($APEtag)); - if (!empty($PostAPEdata)) { - fwrite($fp, $PostAPEdata, strlen($PostAPEdata)); - } - flock($fp, LOCK_UN); - fclose($fp); - ignore_user_abort($oldignoreuserabort); - return true; - } - } - return false; - } + return true; + } + } - public function DeleteAPEtag() { - $getID3 = new getID3; - $ThisFileInfo = $getID3->analyze($this->filename); - if (isset($ThisFileInfo['ape']['tag_offset_start']) && isset($ThisFileInfo['ape']['tag_offset_end'])) { - if (is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'a+b'))) { + return false; + } - flock($fp, LOCK_EX); - $oldignoreuserabort = ignore_user_abort(true); + public function DeleteAPEtag() + { + $getID3 = new getID3; + $ThisFileInfo = $getID3->analyze($this->filename); + if (isset($ThisFileInfo['ape']['tag_offset_start']) && isset($ThisFileInfo['ape']['tag_offset_end'])) { + if (is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'a+b'))) { + flock($fp, LOCK_EX); + $oldignoreuserabort = ignore_user_abort(true); - fseek($fp, $ThisFileInfo['ape']['tag_offset_end']); - $DataAfterAPE = ''; - if ($ThisFileInfo['filesize'] > $ThisFileInfo['ape']['tag_offset_end']) { - $DataAfterAPE = fread($fp, $ThisFileInfo['filesize'] - $ThisFileInfo['ape']['tag_offset_end']); - } + fseek($fp, $ThisFileInfo['ape']['tag_offset_end']); + $DataAfterAPE = ''; + if ($ThisFileInfo['filesize'] > $ThisFileInfo['ape']['tag_offset_end']) { + $DataAfterAPE = fread($fp, $ThisFileInfo['filesize'] - $ThisFileInfo['ape']['tag_offset_end']); + } - ftruncate($fp, $ThisFileInfo['ape']['tag_offset_start']); - fseek($fp, $ThisFileInfo['ape']['tag_offset_start']); + ftruncate($fp, $ThisFileInfo['ape']['tag_offset_start']); + fseek($fp, $ThisFileInfo['ape']['tag_offset_start']); - if (!empty($DataAfterAPE)) { - fwrite($fp, $DataAfterAPE, strlen($DataAfterAPE)); - } + if (! empty($DataAfterAPE)) { + fwrite($fp, $DataAfterAPE, strlen($DataAfterAPE)); + } - flock($fp, LOCK_UN); - fclose($fp); - ignore_user_abort($oldignoreuserabort); + flock($fp, LOCK_UN); + fclose($fp); + ignore_user_abort($oldignoreuserabort); - return true; - } - return false; - } - return true; - } + return true; + } + return false; + } - public function GenerateAPEtag() { - // NOTE: All data passed to this function must be UTF-8 format + return true; + } - $items = array(); - if (!is_array($this->tag_data)) { - return false; - } - foreach ($this->tag_data as $key => $arrayofvalues) { - if (!is_array($arrayofvalues)) { - return false; - } + public function GenerateAPEtag() + { + // NOTE: All data passed to this function must be UTF-8 format - $valuestring = ''; - foreach ($arrayofvalues as $value) { - $valuestring .= str_replace("\x00", '', $value)."\x00"; - } - $valuestring = rtrim($valuestring, "\x00"); + $items = []; + if (! is_array($this->tag_data)) { + return false; + } + foreach ($this->tag_data as $key => $arrayofvalues) { + if (! is_array($arrayofvalues)) { + return false; + } - // Length of the assigned value in bytes - $tagitem = getid3_lib::LittleEndian2String(strlen($valuestring), 4); + $valuestring = ''; + foreach ($arrayofvalues as $value) { + $valuestring .= str_replace("\x00", '', $value)."\x00"; + } + $valuestring = rtrim($valuestring, "\x00"); - //$tagitem .= $this->GenerateAPEtagFlags(true, true, false, 0, false); - $tagitem .= "\x00\x00\x00\x00"; + // Length of the assigned value in bytes + $tagitem = getid3_lib::LittleEndian2String(strlen($valuestring), 4); - $tagitem .= $this->CleanAPEtagItemKey($key)."\x00"; - $tagitem .= $valuestring; + //$tagitem .= $this->GenerateAPEtagFlags(true, true, false, 0, false); + $tagitem .= "\x00\x00\x00\x00"; - $items[] = $tagitem; + $tagitem .= $this->CleanAPEtagItemKey($key)."\x00"; + $tagitem .= $valuestring; - } + $items[] = $tagitem; + } - return $this->GenerateAPEtagHeaderFooter($items, true).implode('', $items).$this->GenerateAPEtagHeaderFooter($items, false); - } + return $this->GenerateAPEtagHeaderFooter($items, true).implode('', $items).$this->GenerateAPEtagHeaderFooter($items, false); + } - public function GenerateAPEtagHeaderFooter(&$items, $isheader=false) { - $tagdatalength = 0; - foreach ($items as $itemdata) { - $tagdatalength += strlen($itemdata); - } + public function GenerateAPEtagHeaderFooter(&$items, $isheader = false) + { + $tagdatalength = 0; + foreach ($items as $itemdata) { + $tagdatalength += strlen($itemdata); + } - $APEheader = 'APETAGEX'; - $APEheader .= getid3_lib::LittleEndian2String(2000, 4); - $APEheader .= getid3_lib::LittleEndian2String(32 + $tagdatalength, 4); - $APEheader .= getid3_lib::LittleEndian2String(count($items), 4); - $APEheader .= $this->GenerateAPEtagFlags(true, true, $isheader, 0, false); - $APEheader .= str_repeat("\x00", 8); + $APEheader = 'APETAGEX'; + $APEheader .= getid3_lib::LittleEndian2String(2000, 4); + $APEheader .= getid3_lib::LittleEndian2String(32 + $tagdatalength, 4); + $APEheader .= getid3_lib::LittleEndian2String(count($items), 4); + $APEheader .= $this->GenerateAPEtagFlags(true, true, $isheader, 0, false); + $APEheader .= str_repeat("\x00", 8); - return $APEheader; - } + return $APEheader; + } - public function GenerateAPEtagFlags($header=true, $footer=true, $isheader=false, $encodingid=0, $readonly=false) { - $APEtagFlags = array_fill(0, 4, 0); - if ($header) { - $APEtagFlags[0] |= 0x80; // Tag contains a header - } - if (!$footer) { - $APEtagFlags[0] |= 0x40; // Tag contains no footer - } - if ($isheader) { - $APEtagFlags[0] |= 0x20; // This is the header, not the footer - } + public function GenerateAPEtagFlags($header = true, $footer = true, $isheader = false, $encodingid = 0, $readonly = false) + { + $APEtagFlags = array_fill(0, 4, 0); + if ($header) { + $APEtagFlags[0] |= 0x80; // Tag contains a header + } + if (! $footer) { + $APEtagFlags[0] |= 0x40; // Tag contains no footer + } + if ($isheader) { + $APEtagFlags[0] |= 0x20; // This is the header, not the footer + } - // 0: Item contains text information coded in UTF-8 - // 1: Item contains binary information °) - // 2: Item is a locator of external stored information °°) - // 3: reserved - $APEtagFlags[3] |= ($encodingid << 1); + // 0: Item contains text information coded in UTF-8 + // 1: Item contains binary information °) + // 2: Item is a locator of external stored information °°) + // 3: reserved + $APEtagFlags[3] |= ($encodingid << 1); - if ($readonly) { - $APEtagFlags[3] |= 0x01; // Tag or Item is Read Only - } + if ($readonly) { + $APEtagFlags[3] |= 0x01; // Tag or Item is Read Only + } - return chr($APEtagFlags[3]).chr($APEtagFlags[2]).chr($APEtagFlags[1]).chr($APEtagFlags[0]); - } + return chr($APEtagFlags[3]).chr($APEtagFlags[2]).chr($APEtagFlags[1]).chr($APEtagFlags[0]); + } - public function CleanAPEtagItemKey($itemkey) { - $itemkey = preg_replace("#[^\x20-\x7E]#i", '', $itemkey); + public function CleanAPEtagItemKey($itemkey) + { + $itemkey = preg_replace("#[^\x20-\x7E]#i", '', $itemkey); - // http://www.personal.uni-jena.de/~pfk/mpp/sv8/apekey.html - switch (strtoupper($itemkey)) { - case 'EAN/UPC': - case 'ISBN': - case 'LC': - case 'ISRC': - $itemkey = strtoupper($itemkey); - break; + // http://www.personal.uni-jena.de/~pfk/mpp/sv8/apekey.html + switch (strtoupper($itemkey)) { + case 'EAN/UPC': + case 'ISBN': + case 'LC': + case 'ISRC': + $itemkey = strtoupper($itemkey); + break; - default: - $itemkey = ucwords($itemkey); - break; - } - return $itemkey; - - } + default: + $itemkey = ucwords($itemkey); + break; + } + return $itemkey; + } } diff --git a/app/Library/getid3/getid3/write.id3v1.php b/app/Library/getid3/getid3/write.id3v1.php index 4fa6a6c3..290c1e80 100644 --- a/app/Library/getid3/getid3/write.id3v1.php +++ b/app/Library/getid3/getid3/write.id3v1.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -18,120 +19,132 @@ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE_ class getid3_write_id3v1 { - public $filename; - public $filesize; - public $tag_data; - public $warnings = array(); // any non-critical errors will be stored here - public $errors = array(); // any critical errors will be stored here + public $filename; + public $filesize; + public $tag_data; + public $warnings = []; // any non-critical errors will be stored here + public $errors = []; // any critical errors will be stored here - public function __construct() { - return true; - } + public function __construct() + { + return true; + } - public function WriteID3v1() { - // File MUST be writeable - CHMOD(646) at least - if (!empty($this->filename) && is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename)) { - $this->setRealFileSize(); - if (($this->filesize <= 0) || !getid3_lib::intValueSupported($this->filesize)) { - $this->errors[] = 'Unable to WriteID3v1('.$this->filename.') because filesize ('.$this->filesize.') is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; - return false; - } - if ($fp_source = fopen($this->filename, 'r+b')) { - fseek($fp_source, -128, SEEK_END); - if (fread($fp_source, 3) == 'TAG') { - fseek($fp_source, -128, SEEK_END); // overwrite existing ID3v1 tag - } else { - fseek($fp_source, 0, SEEK_END); // append new ID3v1 tag - } - $this->tag_data['track'] = (isset($this->tag_data['track']) ? $this->tag_data['track'] : (isset($this->tag_data['track_number']) ? $this->tag_data['track_number'] : (isset($this->tag_data['tracknumber']) ? $this->tag_data['tracknumber'] : ''))); + public function WriteID3v1() + { + // File MUST be writeable - CHMOD(646) at least + if (! empty($this->filename) && is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename)) { + $this->setRealFileSize(); + if (($this->filesize <= 0) || ! getid3_lib::intValueSupported($this->filesize)) { + $this->errors[] = 'Unable to WriteID3v1('.$this->filename.') because filesize ('.$this->filesize.') is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; - $new_id3v1_tag_data = getid3_id3v1::GenerateID3v1Tag( - (isset($this->tag_data['title'] ) ? $this->tag_data['title'] : ''), - (isset($this->tag_data['artist'] ) ? $this->tag_data['artist'] : ''), - (isset($this->tag_data['album'] ) ? $this->tag_data['album'] : ''), - (isset($this->tag_data['year'] ) ? $this->tag_data['year'] : ''), - (isset($this->tag_data['genreid']) ? $this->tag_data['genreid'] : ''), - (isset($this->tag_data['comment']) ? $this->tag_data['comment'] : ''), - (isset($this->tag_data['track'] ) ? $this->tag_data['track'] : '')); - fwrite($fp_source, $new_id3v1_tag_data, 128); - fclose($fp_source); - return true; + return false; + } + if ($fp_source = fopen($this->filename, 'r+b')) { + fseek($fp_source, -128, SEEK_END); + if (fread($fp_source, 3) == 'TAG') { + fseek($fp_source, -128, SEEK_END); // overwrite existing ID3v1 tag + } else { + fseek($fp_source, 0, SEEK_END); // append new ID3v1 tag + } + $this->tag_data['track'] = (isset($this->tag_data['track']) ? $this->tag_data['track'] : (isset($this->tag_data['track_number']) ? $this->tag_data['track_number'] : (isset($this->tag_data['tracknumber']) ? $this->tag_data['tracknumber'] : ''))); - } else { - $this->errors[] = 'Could not fopen('.$this->filename.', "r+b")'; - return false; - } - } - $this->errors[] = 'File is not writeable: '.$this->filename; - return false; - } + $new_id3v1_tag_data = getid3_id3v1::GenerateID3v1Tag( + (isset($this->tag_data['title']) ? $this->tag_data['title'] : ''), + (isset($this->tag_data['artist']) ? $this->tag_data['artist'] : ''), + (isset($this->tag_data['album']) ? $this->tag_data['album'] : ''), + (isset($this->tag_data['year']) ? $this->tag_data['year'] : ''), + (isset($this->tag_data['genreid']) ? $this->tag_data['genreid'] : ''), + (isset($this->tag_data['comment']) ? $this->tag_data['comment'] : ''), + (isset($this->tag_data['track']) ? $this->tag_data['track'] : '')); + fwrite($fp_source, $new_id3v1_tag_data, 128); + fclose($fp_source); - public function FixID3v1Padding() { - // ID3v1 data is supposed to be padded with NULL characters, but some taggers incorrectly use spaces - // This function rewrites the ID3v1 tag with correct padding + return true; + } else { + $this->errors[] = 'Could not fopen('.$this->filename.', "r+b")'; - // Initialize getID3 engine - $getID3 = new getID3; - $getID3->option_tag_id3v2 = false; - $getID3->option_tag_apetag = false; - $getID3->option_tags_html = false; - $getID3->option_extra_info = false; - $getID3->option_tag_id3v1 = true; - $ThisFileInfo = $getID3->analyze($this->filename); - if (isset($ThisFileInfo['tags']['id3v1'])) { - foreach ($ThisFileInfo['tags']['id3v1'] as $key => $value) { - $id3v1data[$key] = implode(',', $value); - } - $this->tag_data = $id3v1data; - return $this->WriteID3v1(); - } - return false; - } + return false; + } + } + $this->errors[] = 'File is not writeable: '.$this->filename; - public function RemoveID3v1() { - // File MUST be writeable - CHMOD(646) at least - if (!empty($this->filename) && is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename)) { - $this->setRealFileSize(); - if (($this->filesize <= 0) || !getid3_lib::intValueSupported($this->filesize)) { - $this->errors[] = 'Unable to RemoveID3v1('.$this->filename.') because filesize ('.$this->filesize.') is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; - return false; - } - if ($fp_source = fopen($this->filename, 'r+b')) { + return false; + } - fseek($fp_source, -128, SEEK_END); - if (fread($fp_source, 3) == 'TAG') { - ftruncate($fp_source, $this->filesize - 128); - } else { - // no ID3v1 tag to begin with - do nothing - } - fclose($fp_source); - return true; + public function FixID3v1Padding() + { + // ID3v1 data is supposed to be padded with NULL characters, but some taggers incorrectly use spaces + // This function rewrites the ID3v1 tag with correct padding - } else { - $this->errors[] = 'Could not fopen('.$this->filename.', "r+b")'; - } - } else { - $this->errors[] = $this->filename.' is not writeable'; - } - return false; - } + // Initialize getID3 engine + $getID3 = new getID3; + $getID3->option_tag_id3v2 = false; + $getID3->option_tag_apetag = false; + $getID3->option_tags_html = false; + $getID3->option_extra_info = false; + $getID3->option_tag_id3v1 = true; + $ThisFileInfo = $getID3->analyze($this->filename); + if (isset($ThisFileInfo['tags']['id3v1'])) { + foreach ($ThisFileInfo['tags']['id3v1'] as $key => $value) { + $id3v1data[$key] = implode(',', $value); + } + $this->tag_data = $id3v1data; - public function setRealFileSize() { - if (PHP_INT_MAX > 2147483647) { - $this->filesize = filesize($this->filename); - return true; - } - // 32-bit PHP will not return correct values for filesize() if file is >=2GB - // but getID3->analyze() has workarounds to get actual filesize - $getID3 = new getID3; - $getID3->option_tag_id3v1 = false; - $getID3->option_tag_id3v2 = false; - $getID3->option_tag_apetag = false; - $getID3->option_tags_html = false; - $getID3->option_extra_info = false; - $ThisFileInfo = $getID3->analyze($this->filename); - $this->filesize = $ThisFileInfo['filesize']; - return true; - } + return $this->WriteID3v1(); + } + return false; + } + + public function RemoveID3v1() + { + // File MUST be writeable - CHMOD(646) at least + if (! empty($this->filename) && is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename)) { + $this->setRealFileSize(); + if (($this->filesize <= 0) || ! getid3_lib::intValueSupported($this->filesize)) { + $this->errors[] = 'Unable to RemoveID3v1('.$this->filename.') because filesize ('.$this->filesize.') is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; + + return false; + } + if ($fp_source = fopen($this->filename, 'r+b')) { + fseek($fp_source, -128, SEEK_END); + if (fread($fp_source, 3) == 'TAG') { + ftruncate($fp_source, $this->filesize - 128); + } else { + // no ID3v1 tag to begin with - do nothing + } + fclose($fp_source); + + return true; + } else { + $this->errors[] = 'Could not fopen('.$this->filename.', "r+b")'; + } + } else { + $this->errors[] = $this->filename.' is not writeable'; + } + + return false; + } + + public function setRealFileSize() + { + if (PHP_INT_MAX > 2147483647) { + $this->filesize = filesize($this->filename); + + return true; + } + // 32-bit PHP will not return correct values for filesize() if file is >=2GB + // but getID3->analyze() has workarounds to get actual filesize + $getID3 = new getID3; + $getID3->option_tag_id3v1 = false; + $getID3->option_tag_id3v2 = false; + $getID3->option_tag_apetag = false; + $getID3->option_tags_html = false; + $getID3->option_extra_info = false; + $ThisFileInfo = $getID3->analyze($this->filename); + $this->filesize = $ThisFileInfo['filesize']; + + return true; + } } diff --git a/app/Library/getid3/getid3/write.id3v2.php b/app/Library/getid3/getid3/write.id3v2.php index 17138db8..6f2e9188 100644 --- a/app/Library/getid3/getid3/write.id3v2.php +++ b/app/Library/getid3/getid3/write.id3v2.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -18,2092 +19,2122 @@ getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE_ class getid3_write_id3v2 { - public $filename; - public $tag_data; - public $fread_buffer_size = 32768; // read buffer size in bytes - public $paddedlength = 4096; // minimum length of ID3v2 tag in bytes - public $majorversion = 3; // ID3v2 major version (2, 3 (recommended), 4) - public $minorversion = 0; // ID3v2 minor version - always 0 - public $merge_existing_data = false; // if true, merge new data with existing tags; if false, delete old tag data and only write new tags - public $id3v2_default_encodingid = 0; // default text encoding (ISO-8859-1) if not explicitly passed - public $id3v2_use_unsynchronisation = false; // the specs say it should be TRUE, but most other ID3v2-aware programs are broken if unsynchronization is used, so by default don't use it. - public $warnings = array(); // any non-critical errors will be stored here - public $errors = array(); // any critical errors will be stored here - - public function __construct() { - return true; - } - - public function WriteID3v2() { - // File MUST be writeable - CHMOD(646) at least. It's best if the - // directory is also writeable, because that method is both faster and less susceptible to errors. - - if (!empty($this->filename) && (is_writeable($this->filename) || (!file_exists($this->filename) && is_writeable(dirname($this->filename))))) { - // Initialize getID3 engine - $getID3 = new getID3; - $OldThisFileInfo = $getID3->analyze($this->filename); - if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) { - $this->errors[] = 'Unable to write ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; - fclose($fp_source); - return false; - } - if ($this->merge_existing_data) { - // merge with existing data - if (!empty($OldThisFileInfo['id3v2'])) { - $this->tag_data = $this->array_join_merge($OldThisFileInfo['id3v2'], $this->tag_data); - } - } - $this->paddedlength = (isset($OldThisFileInfo['id3v2']['headerlength']) ? max($OldThisFileInfo['id3v2']['headerlength'], $this->paddedlength) : $this->paddedlength); - - if ($NewID3v2Tag = $this->GenerateID3v2Tag()) { - - if (file_exists($this->filename) && is_writeable($this->filename) && isset($OldThisFileInfo['id3v2']['headerlength']) && ($OldThisFileInfo['id3v2']['headerlength'] == strlen($NewID3v2Tag))) { - - // best and fastest method - insert-overwrite existing tag (padded to length of old tag if neccesary) - if (file_exists($this->filename)) { - - if (is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'r+b'))) { - rewind($fp); - fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag)); - fclose($fp); - } else { - $this->errors[] = 'Could not fopen("'.$this->filename.'", "r+b")'; - } - - } else { - - if (is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'wb'))) { - rewind($fp); - fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag)); - fclose($fp); - } else { - $this->errors[] = 'Could not fopen("'.$this->filename.'", "wb")'; - } - - } - - } else { - - if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) { - if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) { - if (is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) { - - fwrite($fp_temp, $NewID3v2Tag, strlen($NewID3v2Tag)); - - rewind($fp_source); - if (!empty($OldThisFileInfo['avdataoffset'])) { - fseek($fp_source, $OldThisFileInfo['avdataoffset']); - } - - while ($buffer = fread($fp_source, $this->fread_buffer_size)) { - fwrite($fp_temp, $buffer, strlen($buffer)); - } - - fclose($fp_temp); - fclose($fp_source); - copy($tempfilename, $this->filename); - unlink($tempfilename); - return true; - - } else { - $this->errors[] = 'Could not fopen("'.$tempfilename.'", "wb")'; - } - fclose($fp_source); - - } else { - $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")'; - } - } - return false; - - } - - } else { - - $this->errors[] = '$this->GenerateID3v2Tag() failed'; - - } - - if (!empty($this->errors)) { - return false; - } - return true; - } else { - $this->errors[] = 'WriteID3v2() failed: !is_writeable('.$this->filename.')'; - } - return false; - } - - public function RemoveID3v2() { - // File MUST be writeable - CHMOD(646) at least. It's best if the - // directory is also writeable, because that method is both faster and less susceptible to errors. - if (is_writeable(dirname($this->filename))) { - - // preferred method - only one copying operation, minimal chance of corrupting - // original file if script is interrupted, but required directory to be writeable - if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) { - - // Initialize getID3 engine - $getID3 = new getID3; - $OldThisFileInfo = $getID3->analyze($this->filename); - if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) { - $this->errors[] = 'Unable to remove ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; - fclose($fp_source); - return false; - } - rewind($fp_source); - if ($OldThisFileInfo['avdataoffset'] !== false) { - fseek($fp_source, $OldThisFileInfo['avdataoffset']); - } - if (is_writable($this->filename) && is_file($this->filename) && ($fp_temp = fopen($this->filename.'getid3tmp', 'w+b'))) { - while ($buffer = fread($fp_source, $this->fread_buffer_size)) { - fwrite($fp_temp, $buffer, strlen($buffer)); - } - fclose($fp_temp); - } else { - $this->errors[] = 'Could not fopen("'.$this->filename.'getid3tmp", "w+b")'; - } - fclose($fp_source); - } else { - $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")'; - } - if (file_exists($this->filename)) { - unlink($this->filename); - } - rename($this->filename.'getid3tmp', $this->filename); - - } elseif (is_writable($this->filename)) { - - // less desirable alternate method - double-copies the file, overwrites original file - // and could corrupt source file if the script is interrupted or an error occurs. - if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) { - - // Initialize getID3 engine - $getID3 = new getID3; - $OldThisFileInfo = $getID3->analyze($this->filename); - if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) { - $this->errors[] = 'Unable to remove ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; - fclose($fp_source); - return false; - } - rewind($fp_source); - if ($OldThisFileInfo['avdataoffset'] !== false) { - fseek($fp_source, $OldThisFileInfo['avdataoffset']); - } - if ($fp_temp = tmpfile()) { - while ($buffer = fread($fp_source, $this->fread_buffer_size)) { - fwrite($fp_temp, $buffer, strlen($buffer)); - } - fclose($fp_source); - if (is_writable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'wb'))) { - rewind($fp_temp); - while ($buffer = fread($fp_temp, $this->fread_buffer_size)) { - fwrite($fp_source, $buffer, strlen($buffer)); - } - fseek($fp_temp, -128, SEEK_END); - fclose($fp_source); - } else { - $this->errors[] = 'Could not fopen("'.$this->filename.'", "wb")'; - } - fclose($fp_temp); - } else { - $this->errors[] = 'Could not create tmpfile()'; - } - } else { - $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")'; - } - - } else { - - $this->errors[] = 'Directory and file both not writeable'; - - } - - if (!empty($this->errors)) { - return false; - } - return true; - } - - - public function GenerateID3v2TagFlags($flags) { - switch ($this->majorversion) { - case 4: - // %abcd0000 - $flag = (!empty($flags['unsynchronisation']) ? '1' : '0'); // a - Unsynchronisation - $flag .= (!empty($flags['extendedheader'] ) ? '1' : '0'); // b - Extended header - $flag .= (!empty($flags['experimental'] ) ? '1' : '0'); // c - Experimental indicator - $flag .= (!empty($flags['footer'] ) ? '1' : '0'); // d - Footer present - $flag .= '0000'; - break; - - case 3: - // %abc00000 - $flag = (!empty($flags['unsynchronisation']) ? '1' : '0'); // a - Unsynchronisation - $flag .= (!empty($flags['extendedheader'] ) ? '1' : '0'); // b - Extended header - $flag .= (!empty($flags['experimental'] ) ? '1' : '0'); // c - Experimental indicator - $flag .= '00000'; - break; - - case 2: - // %ab000000 - $flag = (!empty($flags['unsynchronisation']) ? '1' : '0'); // a - Unsynchronisation - $flag .= (!empty($flags['compression'] ) ? '1' : '0'); // b - Compression - $flag .= '000000'; - break; - - default: - return false; - break; - } - return chr(bindec($flag)); - } - - - public function GenerateID3v2FrameFlags($TagAlter=false, $FileAlter=false, $ReadOnly=false, $Compression=false, $Encryption=false, $GroupingIdentity=false, $Unsynchronisation=false, $DataLengthIndicator=false) { - switch ($this->majorversion) { - case 4: - // %0abc0000 %0h00kmnp - $flag1 = '0'; - $flag1 .= $TagAlter ? '1' : '0'; // a - Tag alter preservation (true == discard) - $flag1 .= $FileAlter ? '1' : '0'; // b - File alter preservation (true == discard) - $flag1 .= $ReadOnly ? '1' : '0'; // c - Read only (true == read only) - $flag1 .= '0000'; - - $flag2 = '0'; - $flag2 .= $GroupingIdentity ? '1' : '0'; // h - Grouping identity (true == contains group information) - $flag2 .= '00'; - $flag2 .= $Compression ? '1' : '0'; // k - Compression (true == compressed) - $flag2 .= $Encryption ? '1' : '0'; // m - Encryption (true == encrypted) - $flag2 .= $Unsynchronisation ? '1' : '0'; // n - Unsynchronisation (true == unsynchronised) - $flag2 .= $DataLengthIndicator ? '1' : '0'; // p - Data length indicator (true == data length indicator added) - break; - - case 3: - // %abc00000 %ijk00000 - $flag1 = $TagAlter ? '1' : '0'; // a - Tag alter preservation (true == discard) - $flag1 .= $FileAlter ? '1' : '0'; // b - File alter preservation (true == discard) - $flag1 .= $ReadOnly ? '1' : '0'; // c - Read only (true == read only) - $flag1 .= '00000'; - - $flag2 = $Compression ? '1' : '0'; // i - Compression (true == compressed) - $flag2 .= $Encryption ? '1' : '0'; // j - Encryption (true == encrypted) - $flag2 .= $GroupingIdentity ? '1' : '0'; // k - Grouping identity (true == contains group information) - $flag2 .= '00000'; - break; - - default: - return false; - break; - - } - return chr(bindec($flag1)).chr(bindec($flag2)); - } - - public function GenerateID3v2FrameData($frame_name, $source_data_array) { - if (!getid3_id3v2::IsValidID3v2FrameName($frame_name, $this->majorversion)) { - return false; - } - $framedata = ''; - - if (($this->majorversion < 3) || ($this->majorversion > 4)) { - - $this->errors[] = 'Only ID3v2.3 and ID3v2.4 are supported in GenerateID3v2FrameData()'; - - } else { // $this->majorversion 3 or 4 - - switch ($frame_name) { - case 'UFID': - // 4.1 UFID Unique file identifier - // Owner identifier $00 - // Identifier - if (strlen($source_data_array['data']) > 64) { - $this->errors[] = 'Identifier not allowed to be longer than 64 bytes in '.$frame_name.' (supplied data was '.strlen($source_data_array['data']).' bytes long)'; - } else { - $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00"; - $framedata .= substr($source_data_array['data'], 0, 64); // max 64 bytes - truncate anything longer - } - break; - - case 'TXXX': - // 4.2.2 TXXX User defined text information frame - // Text encoding $xx - // Description $00 (00) - // Value - $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); - if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) { - $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; - } else { - $framedata .= chr($source_data_array['encodingid']); - $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); - $framedata .= $source_data_array['data']; - } - break; - - case 'WXXX': - // 4.3.2 WXXX User defined URL link frame - // Text encoding $xx - // Description $00 (00) - // URL - $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); - if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) { - $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; - } elseif (!isset($source_data_array['data']) || !$this->IsValidURL($source_data_array['data'], false, false)) { - //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; - // probably should be an error, need to rewrite IsValidURL() to handle other encodings - $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; - } else { - $framedata .= chr($source_data_array['encodingid']); - $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); - $framedata .= $source_data_array['data']; - } - break; - - case 'IPLS': - // 4.4 IPLS Involved people list (ID3v2.3 only) - // Text encoding $xx - // People list strings - $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); - if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) { - $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; - } else { - $framedata .= chr($source_data_array['encodingid']); - $framedata .= $source_data_array['data']; - } - break; - - case 'MCDI': - // 4.4 MCDI Music CD identifier - // CD TOC - $framedata .= $source_data_array['data']; - break; - - case 'ETCO': - // 4.5 ETCO Event timing codes - // Time stamp format $xx - // Where time stamp format is: - // $01 (32-bit value) MPEG frames from beginning of file - // $02 (32-bit value) milliseconds from beginning of file - // Followed by a list of key events in the following format: - // Type of event $xx - // Time stamp $xx (xx ...) - // The 'Time stamp' is set to zero if directly at the beginning of the sound - // or after the previous event. All events MUST be sorted in chronological order. - if (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) { - $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')'; - } else { - $framedata .= chr($source_data_array['timestampformat']); - foreach ($source_data_array as $key => $val) { - if (!$this->ID3v2IsValidETCOevent($val['typeid'])) { - $this->errors[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')'; - } elseif (($key != 'timestampformat') && ($key != 'flags')) { - if (($val['timestamp'] > 0) && ($previousETCOtimestamp >= $val['timestamp'])) { - // The 'Time stamp' is set to zero if directly at the beginning of the sound - // or after the previous event. All events MUST be sorted in chronological order. - $this->errors[] = 'Out-of-order timestamp in '.$frame_name.' ('.$val['timestamp'].') for Event Type ('.$val['typeid'].')'; - } else { - $framedata .= chr($val['typeid']); - $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false); - } - } - } - } - break; - - case 'MLLT': - // 4.6 MLLT MPEG location lookup table - // MPEG frames between reference $xx xx - // Bytes between reference $xx xx xx - // Milliseconds between reference $xx xx xx - // Bits for bytes deviation $xx - // Bits for milliseconds dev. $xx - // Then for every reference the following data is included; - // Deviation in bytes %xxx.... - // Deviation in milliseconds %xxx.... - if (($source_data_array['framesbetweenreferences'] > 0) && ($source_data_array['framesbetweenreferences'] <= 65535)) { - $framedata .= getid3_lib::BigEndian2String($source_data_array['framesbetweenreferences'], 2, false); - } else { - $this->errors[] = 'Invalid MPEG Frames Between References in '.$frame_name.' ('.$source_data_array['framesbetweenreferences'].')'; - } - if (($source_data_array['bytesbetweenreferences'] > 0) && ($source_data_array['bytesbetweenreferences'] <= 16777215)) { - $framedata .= getid3_lib::BigEndian2String($source_data_array['bytesbetweenreferences'], 3, false); - } else { - $this->errors[] = 'Invalid bytes Between References in '.$frame_name.' ('.$source_data_array['bytesbetweenreferences'].')'; - } - if (($source_data_array['msbetweenreferences'] > 0) && ($source_data_array['msbetweenreferences'] <= 16777215)) { - $framedata .= getid3_lib::BigEndian2String($source_data_array['msbetweenreferences'], 3, false); - } else { - $this->errors[] = 'Invalid Milliseconds Between References in '.$frame_name.' ('.$source_data_array['msbetweenreferences'].')'; - } - if (!$this->IsWithinBitRange($source_data_array['bitsforbytesdeviation'], 8, false)) { - if (($source_data_array['bitsforbytesdeviation'] % 4) == 0) { - $framedata .= chr($source_data_array['bitsforbytesdeviation']); - } else { - $this->errors[] = 'Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.'; - } - } else { - $this->errors[] = 'Invalid Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].')'; - } - if (!$this->IsWithinBitRange($source_data_array['bitsformsdeviation'], 8, false)) { - if (($source_data_array['bitsformsdeviation'] % 4) == 0) { - $framedata .= chr($source_data_array['bitsformsdeviation']); - } else { - $this->errors[] = 'Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.'; - } - } else { - $this->errors[] = 'Invalid Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsformsdeviation'].')'; - } - foreach ($source_data_array as $key => $val) { - if (($key != 'framesbetweenreferences') && ($key != 'bytesbetweenreferences') && ($key != 'msbetweenreferences') && ($key != 'bitsforbytesdeviation') && ($key != 'bitsformsdeviation') && ($key != 'flags')) { - $unwrittenbitstream .= str_pad(getid3_lib::Dec2Bin($val['bytedeviation']), $source_data_array['bitsforbytesdeviation'], '0', STR_PAD_LEFT); - $unwrittenbitstream .= str_pad(getid3_lib::Dec2Bin($val['msdeviation']), $source_data_array['bitsformsdeviation'], '0', STR_PAD_LEFT); - } - } - for ($i = 0; $i < strlen($unwrittenbitstream); $i += 8) { - $highnibble = bindec(substr($unwrittenbitstream, $i, 4)) << 4; - $lownibble = bindec(substr($unwrittenbitstream, $i + 4, 4)); - $framedata .= chr($highnibble & $lownibble); - } - break; - - case 'SYTC': - // 4.7 SYTC Synchronised tempo codes - // Time stamp format $xx - // Tempo data - // Where time stamp format is: - // $01 (32-bit value) MPEG frames from beginning of file - // $02 (32-bit value) milliseconds from beginning of file - if (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) { - $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')'; - } else { - $framedata .= chr($source_data_array['timestampformat']); - foreach ($source_data_array as $key => $val) { - if (!$this->ID3v2IsValidETCOevent($val['typeid'])) { - $this->errors[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')'; - } elseif (($key != 'timestampformat') && ($key != 'flags')) { - if (($val['tempo'] < 0) || ($val['tempo'] > 510)) { - $this->errors[] = 'Invalid Tempo (max = 510) in '.$frame_name.' ('.$val['tempo'].') at timestamp ('.$val['timestamp'].')'; - } else { - if ($val['tempo'] > 255) { - $framedata .= chr(255); - $val['tempo'] -= 255; - } - $framedata .= chr($val['tempo']); - $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false); - } - } - } - } - break; - - case 'USLT': - // 4.8 USLT Unsynchronised lyric/text transcription - // Text encoding $xx - // Language $xx xx xx - // Content descriptor $00 (00) - // Lyrics/text - $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); - if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { - $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; - } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') { - $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')'; - } else { - $framedata .= chr($source_data_array['encodingid']); - $framedata .= strtolower($source_data_array['language']); - $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); - $framedata .= $source_data_array['data']; - } - break; - - case 'SYLT': - // 4.9 SYLT Synchronised lyric/text - // Text encoding $xx - // Language $xx xx xx - // Time stamp format $xx - // $01 (32-bit value) MPEG frames from beginning of file - // $02 (32-bit value) milliseconds from beginning of file - // Content type $xx - // Content descriptor $00 (00) - // Terminated text to be synced (typically a syllable) - // Sync identifier (terminator to above string) $00 (00) - // Time stamp $xx (xx ...) - $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); - if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { - $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; - } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') { - $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')'; - } elseif (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) { - $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')'; - } elseif (!$this->ID3v2IsValidSYLTtype($source_data_array['contenttypeid'])) { - $this->errors[] = 'Invalid Content Type byte in '.$frame_name.' ('.$source_data_array['contenttypeid'].')'; - } elseif (!is_array($source_data_array['data'])) { - $this->errors[] = 'Invalid Lyric/Timestamp data in '.$frame_name.' (must be an array)'; - } else { - $framedata .= chr($source_data_array['encodingid']); - $framedata .= strtolower($source_data_array['language']); - $framedata .= chr($source_data_array['timestampformat']); - $framedata .= chr($source_data_array['contenttypeid']); - $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); - ksort($source_data_array['data']); - foreach ($source_data_array['data'] as $key => $val) { - $framedata .= $val['data'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); - $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false); - } - } - break; - - case 'COMM': - // 4.10 COMM Comments - // Text encoding $xx - // Language $xx xx xx - // Short content descrip. $00 (00) - // The actual text - $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); - if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { - $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; - } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') { - $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')'; - } else { - $framedata .= chr($source_data_array['encodingid']); - $framedata .= strtolower($source_data_array['language']); - $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); - $framedata .= $source_data_array['data']; - } - break; - - case 'RVA2': - // 4.11 RVA2 Relative volume adjustment (2) (ID3v2.4+ only) - // Identification $00 - // The 'identification' string is used to identify the situation and/or - // device where this adjustment should apply. The following is then - // repeated for every channel: - // Type of channel $xx - // Volume adjustment $xx xx - // Bits representing peak $xx - // Peak volume $xx (xx ...) - $framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00"; - foreach ($source_data_array as $key => $val) { - if ($key != 'description') { - $framedata .= chr($val['channeltypeid']); - $framedata .= getid3_lib::BigEndian2String($val['volumeadjust'], 2, false, true); // signed 16-bit - if (!$this->IsWithinBitRange($source_data_array['bitspeakvolume'], 8, false)) { - $framedata .= chr($val['bitspeakvolume']); - if ($val['bitspeakvolume'] > 0) { - $framedata .= getid3_lib::BigEndian2String($val['peakvolume'], ceil($val['bitspeakvolume'] / 8), false, false); - } - } else { - $this->errors[] = 'Invalid Bits Representing Peak Volume in '.$frame_name.' ('.$val['bitspeakvolume'].') (range = 0 to 255)'; - } - } - } - break; - - case 'RVAD': - // 4.12 RVAD Relative volume adjustment (ID3v2.3 only) - // Increment/decrement %00fedcba - // Bits used for volume descr. $xx - // Relative volume change, right $xx xx (xx ...) // a - // Relative volume change, left $xx xx (xx ...) // b - // Peak volume right $xx xx (xx ...) - // Peak volume left $xx xx (xx ...) - // Relative volume change, right back $xx xx (xx ...) // c - // Relative volume change, left back $xx xx (xx ...) // d - // Peak volume right back $xx xx (xx ...) - // Peak volume left back $xx xx (xx ...) - // Relative volume change, center $xx xx (xx ...) // e - // Peak volume center $xx xx (xx ...) - // Relative volume change, bass $xx xx (xx ...) // f - // Peak volume bass $xx xx (xx ...) - if (!$this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) { - $this->errors[] = 'Invalid Bits For Volume Description byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)'; - } else { - $incdecflag .= '00'; - $incdecflag .= $source_data_array['incdec']['right'] ? '1' : '0'; // a - Relative volume change, right - $incdecflag .= $source_data_array['incdec']['left'] ? '1' : '0'; // b - Relative volume change, left - $incdecflag .= $source_data_array['incdec']['rightrear'] ? '1' : '0'; // c - Relative volume change, right back - $incdecflag .= $source_data_array['incdec']['leftrear'] ? '1' : '0'; // d - Relative volume change, left back - $incdecflag .= $source_data_array['incdec']['center'] ? '1' : '0'; // e - Relative volume change, center - $incdecflag .= $source_data_array['incdec']['bass'] ? '1' : '0'; // f - Relative volume change, bass - $framedata .= chr(bindec($incdecflag)); - $framedata .= chr($source_data_array['bitsvolume']); - $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['right'], ceil($source_data_array['bitsvolume'] / 8), false); - $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['left'], ceil($source_data_array['bitsvolume'] / 8), false); - $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['right'], ceil($source_data_array['bitsvolume'] / 8), false); - $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['left'], ceil($source_data_array['bitsvolume'] / 8), false); - if ($source_data_array['volumechange']['rightrear'] || $source_data_array['volumechange']['leftrear'] || - $source_data_array['peakvolume']['rightrear'] || $source_data_array['peakvolume']['leftrear'] || - $source_data_array['volumechange']['center'] || $source_data_array['peakvolume']['center'] || - $source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) { - $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['rightrear'], ceil($source_data_array['bitsvolume']/8), false); - $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['leftrear'], ceil($source_data_array['bitsvolume']/8), false); - $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['rightrear'], ceil($source_data_array['bitsvolume']/8), false); - $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['leftrear'], ceil($source_data_array['bitsvolume']/8), false); - } - if ($source_data_array['volumechange']['center'] || $source_data_array['peakvolume']['center'] || - $source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) { - $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['center'], ceil($source_data_array['bitsvolume']/8), false); - $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['center'], ceil($source_data_array['bitsvolume']/8), false); - } - if ($source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) { - $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['bass'], ceil($source_data_array['bitsvolume']/8), false); - $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['bass'], ceil($source_data_array['bitsvolume']/8), false); - } - } - break; - - case 'EQU2': - // 4.12 EQU2 Equalisation (2) (ID3v2.4+ only) - // Interpolation method $xx - // $00 Band - // $01 Linear - // Identification $00 - // The following is then repeated for every adjustment point - // Frequency $xx xx - // Volume adjustment $xx xx - if (($source_data_array['interpolationmethod'] < 0) || ($source_data_array['interpolationmethod'] > 1)) { - $this->errors[] = 'Invalid Interpolation Method byte in '.$frame_name.' ('.$source_data_array['interpolationmethod'].') (valid = 0 or 1)'; - } else { - $framedata .= chr($source_data_array['interpolationmethod']); - $framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00"; - foreach ($source_data_array['data'] as $key => $val) { - $framedata .= getid3_lib::BigEndian2String(intval(round($key * 2)), 2, false); - $framedata .= getid3_lib::BigEndian2String($val, 2, false, true); // signed 16-bit - } - } - break; - - case 'EQUA': - // 4.12 EQUA Equalisation (ID3v2.3 only) - // Adjustment bits $xx - // This is followed by 2 bytes + ('adjustment bits' rounded up to the - // nearest byte) for every equalisation band in the following format, - // giving a frequency range of 0 - 32767Hz: - // Increment/decrement %x (MSB of the Frequency) - // Frequency (lower 15 bits) - // Adjustment $xx (xx ...) - if (!$this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) { - $this->errors[] = 'Invalid Adjustment Bits byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)'; - } else { - $framedata .= chr($source_data_array['adjustmentbits']); - foreach ($source_data_array as $key => $val) { - if ($key != 'bitsvolume') { - if (($key > 32767) || ($key < 0)) { - $this->errors[] = 'Invalid Frequency in '.$frame_name.' ('.$key.') (range = 0 to 32767)'; - } else { - if ($val >= 0) { - // put MSB of frequency to 1 if increment, 0 if decrement - $key |= 0x8000; - } - $framedata .= getid3_lib::BigEndian2String($key, 2, false); - $framedata .= getid3_lib::BigEndian2String($val, ceil($source_data_array['adjustmentbits'] / 8), false); - } - } - } - } - break; - - case 'RVRB': - // 4.13 RVRB Reverb - // Reverb left (ms) $xx xx - // Reverb right (ms) $xx xx - // Reverb bounces, left $xx - // Reverb bounces, right $xx - // Reverb feedback, left to left $xx - // Reverb feedback, left to right $xx - // Reverb feedback, right to right $xx - // Reverb feedback, right to left $xx - // Premix left to right $xx - // Premix right to left $xx - if (!$this->IsWithinBitRange($source_data_array['left'], 16, false)) { - $this->errors[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['left'].') (range = 0 to 65535)'; - } elseif (!$this->IsWithinBitRange($source_data_array['right'], 16, false)) { - $this->errors[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['right'].') (range = 0 to 65535)'; - } elseif (!$this->IsWithinBitRange($source_data_array['bouncesL'], 8, false)) { - $this->errors[] = 'Invalid Reverb Bounces, Left in '.$frame_name.' ('.$source_data_array['bouncesL'].') (range = 0 to 255)'; - } elseif (!$this->IsWithinBitRange($source_data_array['bouncesR'], 8, false)) { - $this->errors[] = 'Invalid Reverb Bounces, Right in '.$frame_name.' ('.$source_data_array['bouncesR'].') (range = 0 to 255)'; - } elseif (!$this->IsWithinBitRange($source_data_array['feedbackLL'], 8, false)) { - $this->errors[] = 'Invalid Reverb Feedback, Left-To-Left in '.$frame_name.' ('.$source_data_array['feedbackLL'].') (range = 0 to 255)'; - } elseif (!$this->IsWithinBitRange($source_data_array['feedbackLR'], 8, false)) { - $this->errors[] = 'Invalid Reverb Feedback, Left-To-Right in '.$frame_name.' ('.$source_data_array['feedbackLR'].') (range = 0 to 255)'; - } elseif (!$this->IsWithinBitRange($source_data_array['feedbackRR'], 8, false)) { - $this->errors[] = 'Invalid Reverb Feedback, Right-To-Right in '.$frame_name.' ('.$source_data_array['feedbackRR'].') (range = 0 to 255)'; - } elseif (!$this->IsWithinBitRange($source_data_array['feedbackRL'], 8, false)) { - $this->errors[] = 'Invalid Reverb Feedback, Right-To-Left in '.$frame_name.' ('.$source_data_array['feedbackRL'].') (range = 0 to 255)'; - } elseif (!$this->IsWithinBitRange($source_data_array['premixLR'], 8, false)) { - $this->errors[] = 'Invalid Premix, Left-To-Right in '.$frame_name.' ('.$source_data_array['premixLR'].') (range = 0 to 255)'; - } elseif (!$this->IsWithinBitRange($source_data_array['premixRL'], 8, false)) { - $this->errors[] = 'Invalid Premix, Right-To-Left in '.$frame_name.' ('.$source_data_array['premixRL'].') (range = 0 to 255)'; - } else { - $framedata .= getid3_lib::BigEndian2String($source_data_array['left'], 2, false); - $framedata .= getid3_lib::BigEndian2String($source_data_array['right'], 2, false); - $framedata .= chr($source_data_array['bouncesL']); - $framedata .= chr($source_data_array['bouncesR']); - $framedata .= chr($source_data_array['feedbackLL']); - $framedata .= chr($source_data_array['feedbackLR']); - $framedata .= chr($source_data_array['feedbackRR']); - $framedata .= chr($source_data_array['feedbackRL']); - $framedata .= chr($source_data_array['premixLR']); - $framedata .= chr($source_data_array['premixRL']); - } - break; - - case 'APIC': - // 4.14 APIC Attached picture - // Text encoding $xx - // MIME type $00 - // Picture type $xx - // Description $00 (00) - // Picture data - $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); - if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { - $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; - } elseif (!$this->ID3v2IsValidAPICpicturetype($source_data_array['picturetypeid'])) { - $this->errors[] = 'Invalid Picture Type byte in '.$frame_name.' ('.$source_data_array['picturetypeid'].') for ID3v2.'.$this->majorversion; - } elseif (($this->majorversion >= 3) && (!$this->ID3v2IsValidAPICimageformat($source_data_array['mime']))) { - $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].') for ID3v2.'.$this->majorversion; - } elseif (($source_data_array['mime'] == '-->') && (!$this->IsValidURL($source_data_array['data'], false, false))) { - //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; - // probably should be an error, need to rewrite IsValidURL() to handle other encodings - $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; - } else { - $framedata .= chr($source_data_array['encodingid']); - $framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00"; - $framedata .= chr($source_data_array['picturetypeid']); - $framedata .= (!empty($source_data_array['description']) ? $source_data_array['description'] : '').getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); - $framedata .= $source_data_array['data']; - } - break; - - case 'GEOB': - // 4.15 GEOB General encapsulated object - // Text encoding $xx - // MIME type $00 - // Filename $00 (00) - // Content description $00 (00) - // Encapsulated object - $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); - if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { - $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; - } elseif (!$this->IsValidMIMEstring($source_data_array['mime'])) { - $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].')'; - } elseif (!$source_data_array['description']) { - $this->errors[] = 'Missing Description in '.$frame_name; - } else { - $framedata .= chr($source_data_array['encodingid']); - $framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00"; - $framedata .= $source_data_array['filename'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); - $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); - $framedata .= $source_data_array['data']; - } - break; - - case 'PCNT': - // 4.16 PCNT Play counter - // When the counter reaches all one's, one byte is inserted in - // front of the counter thus making the counter eight bits bigger - // Counter $xx xx xx xx (xx ...) - $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false); - break; - - case 'POPM': - // 4.17 POPM Popularimeter - // When the counter reaches all one's, one byte is inserted in - // front of the counter thus making the counter eight bits bigger - // Email to user $00 - // Rating $xx - // Counter $xx xx xx xx (xx ...) - if (!$this->IsWithinBitRange($source_data_array['rating'], 8, false)) { - $this->errors[] = 'Invalid Rating byte in '.$frame_name.' ('.$source_data_array['rating'].') (range = 0 to 255)'; - } elseif (!$this->IsValidEmail($source_data_array['email'])) { - $this->errors[] = 'Invalid Email in '.$frame_name.' ('.$source_data_array['email'].')'; - } else { - $framedata .= str_replace("\x00", '', $source_data_array['email'])."\x00"; - $framedata .= chr($source_data_array['rating']); - $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false); - } - break; - - case 'RBUF': - // 4.18 RBUF Recommended buffer size - // Buffer size $xx xx xx - // Embedded info flag %0000000x - // Offset to next tag $xx xx xx xx - if (!$this->IsWithinBitRange($source_data_array['buffersize'], 24, false)) { - $this->errors[] = 'Invalid Buffer Size in '.$frame_name; - } elseif (!$this->IsWithinBitRange($source_data_array['nexttagoffset'], 32, false)) { - $this->errors[] = 'Invalid Offset To Next Tag in '.$frame_name; - } else { - $framedata .= getid3_lib::BigEndian2String($source_data_array['buffersize'], 3, false); - $flag .= '0000000'; - $flag .= $source_data_array['flags']['embededinfo'] ? '1' : '0'; - $framedata .= chr(bindec($flag)); - $framedata .= getid3_lib::BigEndian2String($source_data_array['nexttagoffset'], 4, false); - } - break; - - case 'AENC': - // 4.19 AENC Audio encryption - // Owner identifier $00 - // Preview start $xx xx - // Preview length $xx xx - // Encryption info - if (!$this->IsWithinBitRange($source_data_array['previewstart'], 16, false)) { - $this->errors[] = 'Invalid Preview Start in '.$frame_name.' ('.$source_data_array['previewstart'].')'; - } elseif (!$this->IsWithinBitRange($source_data_array['previewlength'], 16, false)) { - $this->errors[] = 'Invalid Preview Length in '.$frame_name.' ('.$source_data_array['previewlength'].')'; - } else { - $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00"; - $framedata .= getid3_lib::BigEndian2String($source_data_array['previewstart'], 2, false); - $framedata .= getid3_lib::BigEndian2String($source_data_array['previewlength'], 2, false); - $framedata .= $source_data_array['encryptioninfo']; - } - break; - - case 'LINK': - // 4.20 LINK Linked information - // Frame identifier $xx xx xx xx - // URL $00 - // ID and additional data - if (!getid3_id3v2::IsValidID3v2FrameName($source_data_array['frameid'], $this->majorversion)) { - $this->errors[] = 'Invalid Frame Identifier in '.$frame_name.' ('.$source_data_array['frameid'].')'; - } elseif (!$this->IsValidURL($source_data_array['data'], true, false)) { - //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; - // probably should be an error, need to rewrite IsValidURL() to handle other encodings - $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; - } elseif ((($source_data_array['frameid'] == 'AENC') || ($source_data_array['frameid'] == 'APIC') || ($source_data_array['frameid'] == 'GEOB') || ($source_data_array['frameid'] == 'TXXX')) && ($source_data_array['additionaldata'] == '')) { - $this->errors[] = 'Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name; - } elseif (($source_data_array['frameid'] == 'USER') && (getid3_id3v2::LanguageLookup($source_data_array['additionaldata'], true) == '')) { - $this->errors[] = 'Language must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name; - } elseif (($source_data_array['frameid'] == 'PRIV') && ($source_data_array['additionaldata'] == '')) { - $this->errors[] = 'Owner Identifier must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name; - } elseif ((($source_data_array['frameid'] == 'COMM') || ($source_data_array['frameid'] == 'SYLT') || ($source_data_array['frameid'] == 'USLT')) && ((getid3_id3v2::LanguageLookup(substr($source_data_array['additionaldata'], 0, 3), true) == '') || (substr($source_data_array['additionaldata'], 3) == ''))) { - $this->errors[] = 'Language followed by Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name; - } else { - $framedata .= $source_data_array['frameid']; - $framedata .= str_replace("\x00", '', $source_data_array['data'])."\x00"; - switch ($source_data_array['frameid']) { - case 'COMM': - case 'SYLT': - case 'USLT': - case 'PRIV': - case 'USER': - case 'AENC': - case 'APIC': - case 'GEOB': - case 'TXXX': - $framedata .= $source_data_array['additionaldata']; - break; - case 'ASPI': - case 'ETCO': - case 'EQU2': - case 'MCID': - case 'MLLT': - case 'OWNE': - case 'RVA2': - case 'RVRB': - case 'SYTC': - case 'IPLS': - case 'RVAD': - case 'EQUA': - // no additional data required - break; - case 'RBUF': - if ($this->majorversion == 3) { - // no additional data required - } else { - $this->errors[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion.')'; - } - - default: - if ((substr($source_data_array['frameid'], 0, 1) == 'T') || (substr($source_data_array['frameid'], 0, 1) == 'W')) { - // no additional data required - } else { - $this->errors[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion.')'; - } - break; - } - } - break; - - case 'POSS': - // 4.21 POSS Position synchronisation frame (ID3v2.3+ only) - // Time stamp format $xx - // Position $xx (xx ...) - if (($source_data_array['timestampformat'] < 1) || ($source_data_array['timestampformat'] > 2)) { - $this->errors[] = 'Invalid Time Stamp Format in '.$frame_name.' ('.$source_data_array['timestampformat'].') (valid = 1 or 2)'; - } elseif (!$this->IsWithinBitRange($source_data_array['position'], 32, false)) { - $this->errors[] = 'Invalid Position in '.$frame_name.' ('.$source_data_array['position'].') (range = 0 to 4294967295)'; - } else { - $framedata .= chr($source_data_array['timestampformat']); - $framedata .= getid3_lib::BigEndian2String($source_data_array['position'], 4, false); - } - break; - - case 'USER': - // 4.22 USER Terms of use (ID3v2.3+ only) - // Text encoding $xx - // Language $xx xx xx - // The actual text - $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); - if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { - $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')'; - } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') { - $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')'; - } else { - $framedata .= chr($source_data_array['encodingid']); - $framedata .= strtolower($source_data_array['language']); - $framedata .= $source_data_array['data']; - } - break; - - case 'OWNE': - // 4.23 OWNE Ownership frame (ID3v2.3+ only) - // Text encoding $xx - // Price paid $00 - // Date of purch. - // Seller - $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); - if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { - $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')'; - } elseif (!$this->IsANumber($source_data_array['pricepaid']['value'], false)) { - $this->errors[] = 'Invalid Price Paid in '.$frame_name.' ('.$source_data_array['pricepaid']['value'].')'; - } elseif (!$this->IsValidDateStampString($source_data_array['purchasedate'])) { - $this->errors[] = 'Invalid Date Of Purchase in '.$frame_name.' ('.$source_data_array['purchasedate'].') (format = YYYYMMDD)'; - } else { - $framedata .= chr($source_data_array['encodingid']); - $framedata .= str_replace("\x00", '', $source_data_array['pricepaid']['value'])."\x00"; - $framedata .= $source_data_array['purchasedate']; - $framedata .= $source_data_array['seller']; - } - break; - - case 'COMR': - // 4.24 COMR Commercial frame (ID3v2.3+ only) - // Text encoding $xx - // Price string $00 - // Valid until - // Contact URL $00 - // Received as $xx - // Name of seller $00 (00) - // Description $00 (00) - // Picture MIME type $00 - // Seller logo - $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); - if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { - $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')'; - } elseif (!$this->IsValidDateStampString($source_data_array['pricevaliduntil'])) { - $this->errors[] = 'Invalid Valid Until date in '.$frame_name.' ('.$source_data_array['pricevaliduntil'].') (format = YYYYMMDD)'; - } elseif (!$this->IsValidURL($source_data_array['contacturl'], false, true)) { - $this->errors[] = 'Invalid Contact URL in '.$frame_name.' ('.$source_data_array['contacturl'].') (allowed schemes: http, https, ftp, mailto)'; - } elseif (!$this->ID3v2IsValidCOMRreceivedAs($source_data_array['receivedasid'])) { - $this->errors[] = 'Invalid Received As byte in '.$frame_name.' ('.$source_data_array['contacturl'].') (range = 0 to 8)'; - } elseif (!$this->IsValidMIMEstring($source_data_array['mime'])) { - $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].')'; - } else { - $framedata .= chr($source_data_array['encodingid']); - unset($pricestring); - foreach ($source_data_array['price'] as $key => $val) { - if ($this->ID3v2IsValidPriceString($key.$val['value'])) { - $pricestrings[] = $key.$val['value']; - } else { - $this->errors[] = 'Invalid Price String in '.$frame_name.' ('.$key.$val['value'].')'; - } - } - $framedata .= implode('/', $pricestrings); - $framedata .= $source_data_array['pricevaliduntil']; - $framedata .= str_replace("\x00", '', $source_data_array['contacturl'])."\x00"; - $framedata .= chr($source_data_array['receivedasid']); - $framedata .= $source_data_array['sellername'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); - $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); - $framedata .= $source_data_array['mime']."\x00"; - $framedata .= $source_data_array['logo']; - } - break; - - case 'ENCR': - // 4.25 ENCR Encryption method registration (ID3v2.3+ only) - // Owner identifier $00 - // Method symbol $xx - // Encryption data - if (!$this->IsWithinBitRange($source_data_array['methodsymbol'], 8, false)) { - $this->errors[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['methodsymbol'].') (range = 0 to 255)'; - } else { - $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00"; - $framedata .= ord($source_data_array['methodsymbol']); - $framedata .= $source_data_array['data']; - } - break; - - case 'GRID': - // 4.26 GRID Group identification registration (ID3v2.3+ only) - // Owner identifier $00 - // Group symbol $xx - // Group dependent data - if (!$this->IsWithinBitRange($source_data_array['groupsymbol'], 8, false)) { - $this->errors[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['groupsymbol'].') (range = 0 to 255)'; - } else { - $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00"; - $framedata .= ord($source_data_array['groupsymbol']); - $framedata .= $source_data_array['data']; - } - break; - - case 'PRIV': - // 4.27 PRIV Private frame (ID3v2.3+ only) - // Owner identifier $00 - // The private data - $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00"; - $framedata .= $source_data_array['data']; - break; - - case 'SIGN': - // 4.28 SIGN Signature frame (ID3v2.4+ only) - // Group symbol $xx - // Signature - if (!$this->IsWithinBitRange($source_data_array['groupsymbol'], 8, false)) { - $this->errors[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['groupsymbol'].') (range = 0 to 255)'; - } else { - $framedata .= ord($source_data_array['groupsymbol']); - $framedata .= $source_data_array['data']; - } - break; - - case 'SEEK': - // 4.29 SEEK Seek frame (ID3v2.4+ only) - // Minimum offset to next tag $xx xx xx xx - if (!$this->IsWithinBitRange($source_data_array['data'], 32, false)) { - $this->errors[] = 'Invalid Minimum Offset in '.$frame_name.' ('.$source_data_array['data'].') (range = 0 to 4294967295)'; - } else { - $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false); - } - break; - - case 'ASPI': - // 4.30 ASPI Audio seek point index (ID3v2.4+ only) - // Indexed data start (S) $xx xx xx xx - // Indexed data length (L) $xx xx xx xx - // Number of index points (N) $xx xx - // Bits per index point (b) $xx - // Then for every index point the following data is included: - // Fraction at index (Fi) $xx (xx) - if (!$this->IsWithinBitRange($source_data_array['datastart'], 32, false)) { - $this->errors[] = 'Invalid Indexed Data Start in '.$frame_name.' ('.$source_data_array['datastart'].') (range = 0 to 4294967295)'; - } elseif (!$this->IsWithinBitRange($source_data_array['datalength'], 32, false)) { - $this->errors[] = 'Invalid Indexed Data Length in '.$frame_name.' ('.$source_data_array['datalength'].') (range = 0 to 4294967295)'; - } elseif (!$this->IsWithinBitRange($source_data_array['indexpoints'], 16, false)) { - $this->errors[] = 'Invalid Number Of Index Points in '.$frame_name.' ('.$source_data_array['indexpoints'].') (range = 0 to 65535)'; - } elseif (!$this->IsWithinBitRange($source_data_array['bitsperpoint'], 8, false)) { - $this->errors[] = 'Invalid Bits Per Index Point in '.$frame_name.' ('.$source_data_array['bitsperpoint'].') (range = 0 to 255)'; - } elseif ($source_data_array['indexpoints'] != count($source_data_array['indexes'])) { - $this->errors[] = 'Number Of Index Points does not match actual supplied data in '.$frame_name; - } else { - $framedata .= getid3_lib::BigEndian2String($source_data_array['datastart'], 4, false); - $framedata .= getid3_lib::BigEndian2String($source_data_array['datalength'], 4, false); - $framedata .= getid3_lib::BigEndian2String($source_data_array['indexpoints'], 2, false); - $framedata .= getid3_lib::BigEndian2String($source_data_array['bitsperpoint'], 1, false); - foreach ($source_data_array['indexes'] as $key => $val) { - $framedata .= getid3_lib::BigEndian2String($val, ceil($source_data_array['bitsperpoint'] / 8), false); - } - } - break; - - case 'RGAD': - // RGAD Replay Gain Adjustment - // http://privatewww.essex.ac.uk/~djmrob/replaygain/ - // Peak Amplitude $xx $xx $xx $xx - // Radio Replay Gain Adjustment %aaabbbcd %dddddddd - // Audiophile Replay Gain Adjustment %aaabbbcd %dddddddd - // a - name code - // b - originator code - // c - sign bit - // d - replay gain adjustment - - if (($source_data_array['track_adjustment'] > 51) || ($source_data_array['track_adjustment'] < -51)) { - $this->errors[] = 'Invalid Track Adjustment in '.$frame_name.' ('.$source_data_array['track_adjustment'].') (range = -51.0 to +51.0)'; - } elseif (($source_data_array['album_adjustment'] > 51) || ($source_data_array['album_adjustment'] < -51)) { - $this->errors[] = 'Invalid Album Adjustment in '.$frame_name.' ('.$source_data_array['album_adjustment'].') (range = -51.0 to +51.0)'; - } elseif (!$this->ID3v2IsValidRGADname($source_data_array['raw']['track_name'])) { - $this->errors[] = 'Invalid Track Name Code in '.$frame_name.' ('.$source_data_array['raw']['track_name'].') (range = 0 to 2)'; - } elseif (!$this->ID3v2IsValidRGADname($source_data_array['raw']['album_name'])) { - $this->errors[] = 'Invalid Album Name Code in '.$frame_name.' ('.$source_data_array['raw']['album_name'].') (range = 0 to 2)'; - } elseif (!$this->ID3v2IsValidRGADoriginator($source_data_array['raw']['track_originator'])) { - $this->errors[] = 'Invalid Track Originator Code in '.$frame_name.' ('.$source_data_array['raw']['track_originator'].') (range = 0 to 3)'; - } elseif (!$this->ID3v2IsValidRGADoriginator($source_data_array['raw']['album_originator'])) { - $this->errors[] = 'Invalid Album Originator Code in '.$frame_name.' ('.$source_data_array['raw']['album_originator'].') (range = 0 to 3)'; - } else { - $framedata .= getid3_lib::Float2String($source_data_array['peakamplitude'], 32); - $framedata .= getid3_lib::RGADgainString($source_data_array['raw']['track_name'], $source_data_array['raw']['track_originator'], $source_data_array['track_adjustment']); - $framedata .= getid3_lib::RGADgainString($source_data_array['raw']['album_name'], $source_data_array['raw']['album_originator'], $source_data_array['album_adjustment']); - } - break; - - default: - if ((($this->majorversion == 2) && (strlen($frame_name) != 3)) || (($this->majorversion > 2) && (strlen($frame_name) != 4))) { - $this->errors[] = 'Invalid frame name "'.$frame_name.'" for ID3v2.'.$this->majorversion; - } elseif ($frame_name{0} == 'T') { - // 4.2. T??? Text information frames - // Text encoding $xx - // Information - $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); - if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { - $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; - } else { - $framedata .= chr($source_data_array['encodingid']); - $framedata .= $source_data_array['data']; - } - } elseif ($frame_name{0} == 'W') { - // 4.3. W??? URL link frames - // URL - if (!$this->IsValidURL($source_data_array['data'], false, false)) { - //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; - // probably should be an error, need to rewrite IsValidURL() to handle other encodings - $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; - } else { - $framedata .= $source_data_array['data']; - } - } else { - $this->errors[] = $frame_name.' not yet supported in $this->GenerateID3v2FrameData()'; - } - break; - } - } - if (!empty($this->errors)) { - return false; - } - return $framedata; - } - - public function ID3v2FrameIsAllowed($frame_name, $source_data_array) { - static $PreviousFrames = array(); - - if ($frame_name === null) { - // if the writing functions are called multiple times, the static array needs to be - // cleared - this can be done by calling $this->ID3v2FrameIsAllowed(null, '') - $PreviousFrames = array(); - return true; - } - if ($this->majorversion == 4) { - switch ($frame_name) { - case 'UFID': - case 'AENC': - case 'ENCR': - case 'GRID': - if (!isset($source_data_array['ownerid'])) { - $this->errors[] = '[ownerid] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['ownerid']; - } - break; - - case 'TXXX': - case 'WXXX': - case 'RVA2': - case 'EQU2': - case 'APIC': - case 'GEOB': - if (!isset($source_data_array['description'])) { - $this->errors[] = '[description] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['description']; - } - break; - - case 'USER': - if (!isset($source_data_array['language'])) { - $this->errors[] = '[language] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['language'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language ('.$source_data_array['language'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['language']; - } - break; - - case 'USLT': - case 'SYLT': - case 'COMM': - if (!isset($source_data_array['language'])) { - $this->errors[] = '[language] not specified for '.$frame_name; - } elseif (!isset($source_data_array['description'])) { - $this->errors[] = '[description] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description']; - } - break; - - case 'POPM': - if (!isset($source_data_array['email'])) { - $this->errors[] = '[email] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['email']; - } - break; - - case 'IPLS': - case 'MCDI': - case 'ETCO': - case 'MLLT': - case 'SYTC': - case 'RVRB': - case 'PCNT': - case 'RBUF': - case 'POSS': - case 'OWNE': - case 'SEEK': - case 'ASPI': - case 'RGAD': - if (in_array($frame_name, $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed'; - } else { - $PreviousFrames[] = $frame_name; - } - break; - - case 'LINK': - // this isn't implemented quite right (yet) - it should check the target frame data for compliance - // but right now it just allows one linked frame of each type, to be safe. - if (!isset($source_data_array['frameid'])) { - $this->errors[] = '[frameid] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')'; - } elseif (in_array($source_data_array['frameid'], $PreviousFrames)) { - // no links to singleton tags - $this->errors[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['frameid']; // only one linked tag of this type - $PreviousFrames[] = $source_data_array['frameid']; // no non-linked singleton tags of this type - } - break; - - case 'COMR': - // There may be more than one 'commercial frame' in a tag, but no two may be identical - // Checking isn't implemented at all (yet) - just assumes that it's OK. - break; - - case 'PRIV': - case 'SIGN': - if (!isset($source_data_array['ownerid'])) { - $this->errors[] = '[ownerid] not specified for '.$frame_name; - } elseif (!isset($source_data_array['data'])) { - $this->errors[] = '[data] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['ownerid'].$source_data_array['data'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID + Data ('.$source_data_array['ownerid'].' + '.$source_data_array['data'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['ownerid'].$source_data_array['data']; - } - break; - - default: - if (($frame_name{0} != 'T') && ($frame_name{0} != 'W')) { - $this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name; - } - break; - } - - } elseif ($this->majorversion == 3) { - - switch ($frame_name) { - case 'UFID': - case 'AENC': - case 'ENCR': - case 'GRID': - if (!isset($source_data_array['ownerid'])) { - $this->errors[] = '[ownerid] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['ownerid']; - } - break; - - case 'TXXX': - case 'WXXX': - case 'APIC': - case 'GEOB': - if (!isset($source_data_array['description'])) { - $this->errors[] = '[description] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['description']; - } - break; - - case 'USER': - if (!isset($source_data_array['language'])) { - $this->errors[] = '[language] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['language'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language ('.$source_data_array['language'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['language']; - } - break; - - case 'USLT': - case 'SYLT': - case 'COMM': - if (!isset($source_data_array['language'])) { - $this->errors[] = '[language] not specified for '.$frame_name; - } elseif (!isset($source_data_array['description'])) { - $this->errors[] = '[description] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description']; - } - break; - - case 'POPM': - if (!isset($source_data_array['email'])) { - $this->errors[] = '[email] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['email']; - } - break; - - case 'IPLS': - case 'MCDI': - case 'ETCO': - case 'MLLT': - case 'SYTC': - case 'RVAD': - case 'EQUA': - case 'RVRB': - case 'PCNT': - case 'RBUF': - case 'POSS': - case 'OWNE': - case 'RGAD': - if (in_array($frame_name, $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed'; - } else { - $PreviousFrames[] = $frame_name; - } - break; - - case 'LINK': - // this isn't implemented quite right (yet) - it should check the target frame data for compliance - // but right now it just allows one linked frame of each type, to be safe. - if (!isset($source_data_array['frameid'])) { - $this->errors[] = '[frameid] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')'; - } elseif (in_array($source_data_array['frameid'], $PreviousFrames)) { - // no links to singleton tags - $this->errors[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['frameid']; // only one linked tag of this type - $PreviousFrames[] = $source_data_array['frameid']; // no non-linked singleton tags of this type - } - break; - - case 'COMR': - // There may be more than one 'commercial frame' in a tag, but no two may be identical - // Checking isn't implemented at all (yet) - just assumes that it's OK. - break; - - case 'PRIV': - if (!isset($source_data_array['ownerid'])) { - $this->errors[] = '[ownerid] not specified for '.$frame_name; - } elseif (!isset($source_data_array['data'])) { - $this->errors[] = '[data] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['ownerid'].$source_data_array['data'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID + Data ('.$source_data_array['ownerid'].' + '.$source_data_array['data'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['ownerid'].$source_data_array['data']; - } - break; - - default: - if (($frame_name{0} != 'T') && ($frame_name{0} != 'W')) { - $this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name; - } - break; - } - - } elseif ($this->majorversion == 2) { - - switch ($frame_name) { - case 'UFI': - case 'CRM': - case 'CRA': - if (!isset($source_data_array['ownerid'])) { - $this->errors[] = '[ownerid] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['ownerid']; - } - break; - - case 'TXX': - case 'WXX': - case 'PIC': - case 'GEO': - if (!isset($source_data_array['description'])) { - $this->errors[] = '[description] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['description']; - } - break; - - case 'ULT': - case 'SLT': - case 'COM': - if (!isset($source_data_array['language'])) { - $this->errors[] = '[language] not specified for '.$frame_name; - } elseif (!isset($source_data_array['description'])) { - $this->errors[] = '[description] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description']; - } - break; - - case 'POP': - if (!isset($source_data_array['email'])) { - $this->errors[] = '[email] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['email']; - } - break; - - case 'IPL': - case 'MCI': - case 'ETC': - case 'MLL': - case 'STC': - case 'RVA': - case 'EQU': - case 'REV': - case 'CNT': - case 'BUF': - if (in_array($frame_name, $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed'; - } else { - $PreviousFrames[] = $frame_name; - } - break; - - case 'LNK': - // this isn't implemented quite right (yet) - it should check the target frame data for compliance - // but right now it just allows one linked frame of each type, to be safe. - if (!isset($source_data_array['frameid'])) { - $this->errors[] = '[frameid] not specified for '.$frame_name; - } elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) { - $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')'; - } elseif (in_array($source_data_array['frameid'], $PreviousFrames)) { - // no links to singleton tags - $this->errors[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')'; - } else { - $PreviousFrames[] = $frame_name.$source_data_array['frameid']; // only one linked tag of this type - $PreviousFrames[] = $source_data_array['frameid']; // no non-linked singleton tags of this type - } - break; - - default: - if (($frame_name{0} != 'T') && ($frame_name{0} != 'W')) { - $this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name; - } - break; - } - } - - if (!empty($this->errors)) { - return false; - } - return true; - } - - public function GenerateID3v2Tag($noerrorsonly=true) { - $this->ID3v2FrameIsAllowed(null, ''); // clear static array in case this isn't the first call to $this->GenerateID3v2Tag() - - $tagstring = ''; - if (is_array($this->tag_data)) { - foreach ($this->tag_data as $frame_name => $frame_rawinputdata) { - foreach ($frame_rawinputdata as $irrelevantindex => $source_data_array) { - if (getid3_id3v2::IsValidID3v2FrameName($frame_name, $this->majorversion)) { - unset($frame_length); - unset($frame_flags); - $frame_data = false; - if ($this->ID3v2FrameIsAllowed($frame_name, $source_data_array)) { - if(array_key_exists('description', $source_data_array) && array_key_exists('encodingid', $source_data_array) && array_key_exists('encoding', $this->tag_data)) { - $source_data_array['description'] = getid3_lib::iconv_fallback($this->tag_data['encoding'], $source_data_array['encoding'], $source_data_array['description']); - } - if ($frame_data = $this->GenerateID3v2FrameData($frame_name, $source_data_array)) { - $FrameUnsynchronisation = false; - if ($this->majorversion >= 4) { - // frame-level unsynchronisation - $unsynchdata = $frame_data; - if ($this->id3v2_use_unsynchronisation) { - $unsynchdata = $this->Unsynchronise($frame_data); - } - if (strlen($unsynchdata) != strlen($frame_data)) { - // unsynchronisation needed - $FrameUnsynchronisation = true; - $frame_data = $unsynchdata; - if (isset($TagUnsynchronisation) && $TagUnsynchronisation === false) { - // only set to true if ALL frames are unsynchronised - } else { - $TagUnsynchronisation = true; - } - } else { - if (isset($TagUnsynchronisation)) { - $TagUnsynchronisation = false; - } - } - unset($unsynchdata); - - $frame_length = getid3_lib::BigEndian2String(strlen($frame_data), 4, true); - } else { - $frame_length = getid3_lib::BigEndian2String(strlen($frame_data), 4, false); - } - $frame_flags = $this->GenerateID3v2FrameFlags($this->ID3v2FrameFlagsLookupTagAlter($frame_name), $this->ID3v2FrameFlagsLookupFileAlter($frame_name), false, false, false, false, $FrameUnsynchronisation, false); - } - } else { - $this->errors[] = 'Frame "'.$frame_name.'" is NOT allowed'; - } - if ($frame_data === false) { - $this->errors[] = '$this->GenerateID3v2FrameData() failed for "'.$frame_name.'"'; - if ($noerrorsonly) { - return false; - } else { - unset($frame_name); - } - } - } else { - // ignore any invalid frame names, including 'title', 'header', etc - $this->warnings[] = 'Ignoring invalid ID3v2 frame type: "'.$frame_name.'"'; - unset($frame_name); - unset($frame_length); - unset($frame_flags); - unset($frame_data); - } - if (isset($frame_name) && isset($frame_length) && isset($frame_flags) && isset($frame_data)) { - $tagstring .= $frame_name.$frame_length.$frame_flags.$frame_data; - } - } - } - - if (!isset($TagUnsynchronisation)) { - $TagUnsynchronisation = false; - } - if (($this->majorversion <= 3) && $this->id3v2_use_unsynchronisation) { - // tag-level unsynchronisation - $unsynchdata = $this->Unsynchronise($tagstring); - if (strlen($unsynchdata) != strlen($tagstring)) { - // unsynchronisation needed - $TagUnsynchronisation = true; - $tagstring = $unsynchdata; - } - } - - while ($this->paddedlength < (strlen($tagstring) + getid3_id3v2::ID3v2HeaderLength($this->majorversion))) { - $this->paddedlength += 1024; - } - - $footer = false; // ID3v2 footers not yet supported in getID3() - if (!$footer && ($this->paddedlength > (strlen($tagstring) + getid3_id3v2::ID3v2HeaderLength($this->majorversion)))) { - // pad up to $paddedlength bytes if unpadded tag is shorter than $paddedlength - // "Furthermore it MUST NOT have any padding when a tag footer is added to the tag." - if (($this->paddedlength - strlen($tagstring) - getid3_id3v2::ID3v2HeaderLength($this->majorversion)) > 0) { - $tagstring .= str_repeat("\x00", $this->paddedlength - strlen($tagstring) - getid3_id3v2::ID3v2HeaderLength($this->majorversion)); - } - } - if ($this->id3v2_use_unsynchronisation && (substr($tagstring, strlen($tagstring) - 1, 1) == "\xFF")) { - // special unsynchronisation case: - // if last byte == $FF then appended a $00 - $TagUnsynchronisation = true; - $tagstring .= "\x00"; - } - - $tagheader = 'ID3'; - $tagheader .= chr($this->majorversion); - $tagheader .= chr($this->minorversion); - $tagheader .= $this->GenerateID3v2TagFlags(array('unsynchronisation'=>$TagUnsynchronisation)); - $tagheader .= getid3_lib::BigEndian2String(strlen($tagstring), 4, true); - - return $tagheader.$tagstring; - } - $this->errors[] = 'tag_data is not an array in GenerateID3v2Tag()'; - return false; - } - - public function ID3v2IsValidPriceString($pricestring) { - if (getid3_id3v2::LanguageLookup(substr($pricestring, 0, 3), true) == '') { - return false; - } elseif (!$this->IsANumber(substr($pricestring, 3), true)) { - return false; - } - return true; - } - - public function ID3v2FrameFlagsLookupTagAlter($framename) { - // unfinished - switch ($framename) { - case 'RGAD': - $allow = true; - default: - $allow = false; - break; - } - return $allow; - } - - public function ID3v2FrameFlagsLookupFileAlter($framename) { - // unfinished - switch ($framename) { - case 'RGAD': - return false; - break; - - default: - return false; - break; - } - } - - public function ID3v2IsValidETCOevent($eventid) { - if (($eventid < 0) || ($eventid > 0xFF)) { - // outside range of 1 byte - return false; - } elseif (($eventid >= 0xF0) && ($eventid <= 0xFC)) { - // reserved for future use - return false; - } elseif (($eventid >= 0x17) && ($eventid <= 0xDF)) { - // reserved for future use - return false; - } elseif (($eventid >= 0x0E) && ($eventid <= 0x16) && ($this->majorversion == 2)) { - // not defined in ID3v2.2 - return false; - } elseif (($eventid >= 0x15) && ($eventid <= 0x16) && ($this->majorversion == 3)) { - // not defined in ID3v2.3 - return false; - } - return true; - } - - public function ID3v2IsValidSYLTtype($contenttype) { - if (($contenttype >= 0) && ($contenttype <= 8) && ($this->majorversion == 4)) { - return true; - } elseif (($contenttype >= 0) && ($contenttype <= 6) && ($this->majorversion == 3)) { - return true; - } - return false; - } - - public function ID3v2IsValidRVA2channeltype($channeltype) { - if (($channeltype >= 0) && ($channeltype <= 8) && ($this->majorversion == 4)) { - return true; - } - return false; - } - - public function ID3v2IsValidAPICpicturetype($picturetype) { - if (($picturetype >= 0) && ($picturetype <= 0x14) && ($this->majorversion >= 2) && ($this->majorversion <= 4)) { - return true; - } - return false; - } - - public function ID3v2IsValidAPICimageformat($imageformat) { - if ($imageformat == '-->') { - return true; - } elseif ($this->majorversion == 2) { - if ((strlen($imageformat) == 3) && ($imageformat == strtoupper($imageformat))) { - return true; - } - } elseif (($this->majorversion == 3) || ($this->majorversion == 4)) { - if ($this->IsValidMIMEstring($imageformat)) { - return true; - } - } - return false; - } - - public function ID3v2IsValidCOMRreceivedAs($receivedas) { - if (($this->majorversion >= 3) && ($receivedas >= 0) && ($receivedas <= 8)) { - return true; - } - return false; - } - - public static function ID3v2IsValidRGADname($RGADname) { - if (($RGADname >= 0) && ($RGADname <= 2)) { - return true; - } - return false; - } - - public static function ID3v2IsValidRGADoriginator($RGADoriginator) { - if (($RGADoriginator >= 0) && ($RGADoriginator <= 3)) { - return true; - } - return false; - } - - public function ID3v2IsValidTextEncoding($textencodingbyte) { - // 0 = ISO-8859-1 - // 1 = UTF-16 with BOM - // 2 = UTF-16BE without BOM - // 3 = UTF-8 - static $ID3v2IsValidTextEncoding_cache = array( - 2 => array(true, true), // ID3v2.2 - allow 0=ISO-8859-1, 1=UTF-16 - 3 => array(true, true), // ID3v2.3 - allow 0=ISO-8859-1, 1=UTF-16 - 4 => array(true, true, true, true), // ID3v2.4 - allow 0=ISO-8859-1, 1=UTF-16, 2=UTF-16BE, 3=UTF-8 - ); - return isset($ID3v2IsValidTextEncoding_cache[$this->majorversion][$textencodingbyte]); - } - - public static function Unsynchronise($data) { - // Whenever a false synchronisation is found within the tag, one zeroed - // byte is inserted after the first false synchronisation byte. The - // format of a correct sync that should be altered by ID3 encoders is as - // follows: - // %11111111 111xxxxx - // And should be replaced with: - // %11111111 00000000 111xxxxx - // This has the side effect that all $FF 00 combinations have to be - // altered, so they won't be affected by the decoding process. Therefore - // all the $FF 00 combinations have to be replaced with the $FF 00 00 - // combination during the unsynchronisation. - - $data = str_replace("\xFF\x00", "\xFF\x00\x00", $data); - $unsyncheddata = ''; - $datalength = strlen($data); - for ($i = 0; $i < $datalength; $i++) { - $thischar = $data{$i}; - $unsyncheddata .= $thischar; - if ($thischar == "\xFF") { - $nextchar = ord($data{$i + 1}); - if (($nextchar & 0xE0) == 0xE0) { - // previous byte = 11111111, this byte = 111????? - $unsyncheddata .= "\x00"; - } - } - } - return $unsyncheddata; - } - - public function is_hash($var) { - // written by dev-nullØchristophe*vg - // taken from http://www.php.net/manual/en/function.array-merge-recursive.php - if (is_array($var)) { - $keys = array_keys($var); - $all_num = true; - for ($i = 0; $i < count($keys); $i++) { - if (is_string($keys[$i])) { - return true; - } - } - } - return false; - } - - public function array_join_merge($arr1, $arr2) { - // written by dev-nullØchristophe*vg - // taken from http://www.php.net/manual/en/function.array-merge-recursive.php - if (is_array($arr1) && is_array($arr2)) { - // the same -> merge - $new_array = array(); - - if ($this->is_hash($arr1) && $this->is_hash($arr2)) { - // hashes -> merge based on keys - $keys = array_merge(array_keys($arr1), array_keys($arr2)); - foreach ($keys as $key) { - $new_array[$key] = $this->array_join_merge((isset($arr1[$key]) ? $arr1[$key] : ''), (isset($arr2[$key]) ? $arr2[$key] : '')); - } - } else { - // two real arrays -> merge - $new_array = array_reverse(array_unique(array_reverse(array_merge($arr1, $arr2)))); - } - return $new_array; - } else { - // not the same ... take new one if defined, else the old one stays - return $arr2 ? $arr2 : $arr1; - } - } - - public static function IsValidMIMEstring($mimestring) { - return preg_match('#^.+/.+$#', $mimestring); - } - - public static function IsWithinBitRange($number, $maxbits, $signed=false) { - if ($signed) { - if (($number > (0 - pow(2, $maxbits - 1))) && ($number <= pow(2, $maxbits - 1))) { - return true; - } - } else { - if (($number >= 0) && ($number <= pow(2, $maxbits))) { - return true; - } - } - return false; - } - - public static function IsValidEmail($email) { - if (function_exists('filter_var')) { - return filter_var($email, FILTER_VALIDATE_EMAIL); - } - // VERY crude email validation - return preg_match('#^[^ ]+@[a-z\\-\\.]+\\.[a-z]{2,}$#', $email); - } - - public static function IsValidURL($url, $allowUserPass=false) { - if ($url == '') { - return false; - } - if ($allowUserPass !== true) { - if (strstr($url, '@')) { - // in the format http://user:pass@example.com or http://user@example.com - // but could easily be somebody incorrectly entering an email address in place of a URL - return false; - } - } - // 2016-06-08: relax URL checking to avoid falsely rejecting valid URLs, leave URL validation to the user - // http://www.getid3.org/phpBB3/viewtopic.php?t=1926 - return true; - /* - if ($parts = $this->safe_parse_url($url)) { - if (($parts['scheme'] != 'http') && ($parts['scheme'] != 'https') && ($parts['scheme'] != 'ftp') && ($parts['scheme'] != 'gopher')) { - return false; - } elseif (!preg_match('#^[[:alnum:]]([-.]?[0-9a-z])*\\.[a-z]{2,3}$#i', $parts['host'], $regs) && !preg_match('#^[0-9]{1,3}(\\.[0-9]{1,3}){3}$#', $parts['host'])) { - return false; - } elseif (!preg_match('#^([[:alnum:]-]|[\\_])*$#i', $parts['user'], $regs)) { - return false; - } elseif (!preg_match('#^([[:alnum:]-]|[\\_])*$#i', $parts['pass'], $regs)) { - return false; - } elseif (!preg_match('#^[[:alnum:]/_\\.@~-]*$#i', $parts['path'], $regs)) { - return false; - } elseif (!empty($parts['query']) && !preg_match('#^[[:alnum:]?&=+:;_()%\\#/,\\.-]*$#i', $parts['query'], $regs)) { - return false; - } else { - return true; - } - } - return false; - */ - } - - public static function safe_parse_url($url) { - $parts = @parse_url($url); - $parts['scheme'] = (isset($parts['scheme']) ? $parts['scheme'] : ''); - $parts['host'] = (isset($parts['host']) ? $parts['host'] : ''); - $parts['user'] = (isset($parts['user']) ? $parts['user'] : ''); - $parts['pass'] = (isset($parts['pass']) ? $parts['pass'] : ''); - $parts['path'] = (isset($parts['path']) ? $parts['path'] : ''); - $parts['query'] = (isset($parts['query']) ? $parts['query'] : ''); - return $parts; - } - - public static function ID3v2ShortFrameNameLookup($majorversion, $long_description) { - $long_description = str_replace(' ', '_', strtolower(trim($long_description))); - static $ID3v2ShortFrameNameLookup = array(); - if (empty($ID3v2ShortFrameNameLookup)) { - - // The following are unique to ID3v2.2 - $ID3v2ShortFrameNameLookup[2]['recommended_buffer_size'] = 'BUF'; - $ID3v2ShortFrameNameLookup[2]['comment'] = 'COM'; - $ID3v2ShortFrameNameLookup[2]['audio_encryption'] = 'CRA'; - $ID3v2ShortFrameNameLookup[2]['encrypted_meta_frame'] = 'CRM'; - $ID3v2ShortFrameNameLookup[2]['equalisation'] = 'EQU'; - $ID3v2ShortFrameNameLookup[2]['event_timing_codes'] = 'ETC'; - $ID3v2ShortFrameNameLookup[2]['general_encapsulated_object'] = 'GEO'; - $ID3v2ShortFrameNameLookup[2]['involved_people_list'] = 'IPL'; - $ID3v2ShortFrameNameLookup[2]['linked_information'] = 'LNK'; - $ID3v2ShortFrameNameLookup[2]['music_cd_identifier'] = 'MCI'; - $ID3v2ShortFrameNameLookup[2]['mpeg_location_lookup_table'] = 'MLL'; - $ID3v2ShortFrameNameLookup[2]['attached_picture'] = 'PIC'; - $ID3v2ShortFrameNameLookup[2]['popularimeter'] = 'POP'; - $ID3v2ShortFrameNameLookup[2]['reverb'] = 'REV'; - $ID3v2ShortFrameNameLookup[2]['relative_volume_adjustment'] = 'RVA'; - $ID3v2ShortFrameNameLookup[2]['synchronised_lyric'] = 'SLT'; - $ID3v2ShortFrameNameLookup[2]['synchronised_tempo_codes'] = 'STC'; - $ID3v2ShortFrameNameLookup[2]['album'] = 'TAL'; - $ID3v2ShortFrameNameLookup[2]['beats_per_minute'] = 'TBP'; - $ID3v2ShortFrameNameLookup[2]['bpm'] = 'TBP'; - $ID3v2ShortFrameNameLookup[2]['composer'] = 'TCM'; - $ID3v2ShortFrameNameLookup[2]['genre'] = 'TCO'; - $ID3v2ShortFrameNameLookup[2]['part_of_a_compilation'] = 'TCP'; - $ID3v2ShortFrameNameLookup[2]['copyright_message'] = 'TCR'; - $ID3v2ShortFrameNameLookup[2]['date'] = 'TDA'; - $ID3v2ShortFrameNameLookup[2]['playlist_delay'] = 'TDY'; - $ID3v2ShortFrameNameLookup[2]['encoded_by'] = 'TEN'; - $ID3v2ShortFrameNameLookup[2]['file_type'] = 'TFT'; - $ID3v2ShortFrameNameLookup[2]['time'] = 'TIM'; - $ID3v2ShortFrameNameLookup[2]['initial_key'] = 'TKE'; - $ID3v2ShortFrameNameLookup[2]['language'] = 'TLA'; - $ID3v2ShortFrameNameLookup[2]['length'] = 'TLE'; - $ID3v2ShortFrameNameLookup[2]['media_type'] = 'TMT'; - $ID3v2ShortFrameNameLookup[2]['original_artist'] = 'TOA'; - $ID3v2ShortFrameNameLookup[2]['original_filename'] = 'TOF'; - $ID3v2ShortFrameNameLookup[2]['original_lyricist'] = 'TOL'; - $ID3v2ShortFrameNameLookup[2]['original_year'] = 'TOR'; - $ID3v2ShortFrameNameLookup[2]['original_album'] = 'TOT'; - $ID3v2ShortFrameNameLookup[2]['artist'] = 'TP1'; - $ID3v2ShortFrameNameLookup[2]['band'] = 'TP2'; - $ID3v2ShortFrameNameLookup[2]['conductor'] = 'TP3'; - $ID3v2ShortFrameNameLookup[2]['remixer'] = 'TP4'; - $ID3v2ShortFrameNameLookup[2]['part_of_a_set'] = 'TPA'; - $ID3v2ShortFrameNameLookup[2]['publisher'] = 'TPB'; - $ID3v2ShortFrameNameLookup[2]['isrc'] = 'TRC'; - $ID3v2ShortFrameNameLookup[2]['recording_dates'] = 'TRD'; - $ID3v2ShortFrameNameLookup[2]['tracknumber'] = 'TRK'; - $ID3v2ShortFrameNameLookup[2]['track_number'] = 'TRK'; - $ID3v2ShortFrameNameLookup[2]['album_artist_sort_order'] = 'TS2'; - $ID3v2ShortFrameNameLookup[2]['album_sort_order'] = 'TSA'; - $ID3v2ShortFrameNameLookup[2]['composer_sort_order'] = 'TSC'; - $ID3v2ShortFrameNameLookup[2]['size'] = 'TSI'; - $ID3v2ShortFrameNameLookup[2]['performer_sort_order'] = 'TSP'; - $ID3v2ShortFrameNameLookup[2]['encoder_settings'] = 'TSS'; - $ID3v2ShortFrameNameLookup[2]['title_sort_order'] = 'TST'; - $ID3v2ShortFrameNameLookup[2]['content_group_description'] = 'TT1'; - $ID3v2ShortFrameNameLookup[2]['title'] = 'TT2'; - $ID3v2ShortFrameNameLookup[2]['subtitle'] = 'TT3'; - $ID3v2ShortFrameNameLookup[2]['lyricist'] = 'TXT'; - $ID3v2ShortFrameNameLookup[2]['text'] = 'TXX'; - $ID3v2ShortFrameNameLookup[2]['year'] = 'TYE'; - $ID3v2ShortFrameNameLookup[2]['unique_file_identifier'] = 'UFI'; - $ID3v2ShortFrameNameLookup[2]['unsychronised_lyric'] = 'ULT'; - $ID3v2ShortFrameNameLookup[2]['url_file'] = 'WAF'; - $ID3v2ShortFrameNameLookup[2]['url_artist'] = 'WAR'; - $ID3v2ShortFrameNameLookup[2]['url_source'] = 'WAS'; - $ID3v2ShortFrameNameLookup[2]['commercial_information'] = 'WCM'; - $ID3v2ShortFrameNameLookup[2]['copyright'] = 'WCP'; - $ID3v2ShortFrameNameLookup[2]['url_publisher'] = 'WPB'; - $ID3v2ShortFrameNameLookup[2]['url_user'] = 'WXX'; - - // The following are common to ID3v2.3 and ID3v2.4 - $ID3v2ShortFrameNameLookup[3]['audio_encryption'] = 'AENC'; - $ID3v2ShortFrameNameLookup[3]['attached_picture'] = 'APIC'; - $ID3v2ShortFrameNameLookup[3]['picture'] = 'APIC'; - $ID3v2ShortFrameNameLookup[3]['comment'] = 'COMM'; - $ID3v2ShortFrameNameLookup[3]['commercial_frame'] = 'COMR'; - $ID3v2ShortFrameNameLookup[3]['encryption_method_registration'] = 'ENCR'; - $ID3v2ShortFrameNameLookup[3]['event_timing_codes'] = 'ETCO'; - $ID3v2ShortFrameNameLookup[3]['general_encapsulated_object'] = 'GEOB'; - $ID3v2ShortFrameNameLookup[3]['group_identification_registration'] = 'GRID'; - $ID3v2ShortFrameNameLookup[3]['linked_information'] = 'LINK'; - $ID3v2ShortFrameNameLookup[3]['music_cd_identifier'] = 'MCDI'; - $ID3v2ShortFrameNameLookup[3]['mpeg_location_lookup_table'] = 'MLLT'; - $ID3v2ShortFrameNameLookup[3]['ownership_frame'] = 'OWNE'; - $ID3v2ShortFrameNameLookup[3]['play_counter'] = 'PCNT'; - $ID3v2ShortFrameNameLookup[3]['popularimeter'] = 'POPM'; - $ID3v2ShortFrameNameLookup[3]['position_synchronisation_frame'] = 'POSS'; - $ID3v2ShortFrameNameLookup[3]['private_frame'] = 'PRIV'; - $ID3v2ShortFrameNameLookup[3]['recommended_buffer_size'] = 'RBUF'; - $ID3v2ShortFrameNameLookup[3]['replay_gain_adjustment'] = 'RGAD'; - $ID3v2ShortFrameNameLookup[3]['reverb'] = 'RVRB'; - $ID3v2ShortFrameNameLookup[3]['synchronised_lyric'] = 'SYLT'; - $ID3v2ShortFrameNameLookup[3]['synchronised_tempo_codes'] = 'SYTC'; - $ID3v2ShortFrameNameLookup[3]['album'] = 'TALB'; - $ID3v2ShortFrameNameLookup[3]['beats_per_minute'] = 'TBPM'; - $ID3v2ShortFrameNameLookup[3]['bpm'] = 'TBPM'; - $ID3v2ShortFrameNameLookup[3]['part_of_a_compilation'] = 'TCMP'; - $ID3v2ShortFrameNameLookup[3]['composer'] = 'TCOM'; - $ID3v2ShortFrameNameLookup[3]['genre'] = 'TCON'; - $ID3v2ShortFrameNameLookup[3]['copyright_message'] = 'TCOP'; - $ID3v2ShortFrameNameLookup[3]['playlist_delay'] = 'TDLY'; - $ID3v2ShortFrameNameLookup[3]['encoded_by'] = 'TENC'; - $ID3v2ShortFrameNameLookup[3]['lyricist'] = 'TEXT'; - $ID3v2ShortFrameNameLookup[3]['file_type'] = 'TFLT'; - $ID3v2ShortFrameNameLookup[3]['content_group_description'] = 'TIT1'; - $ID3v2ShortFrameNameLookup[3]['title'] = 'TIT2'; - $ID3v2ShortFrameNameLookup[3]['subtitle'] = 'TIT3'; - $ID3v2ShortFrameNameLookup[3]['initial_key'] = 'TKEY'; - $ID3v2ShortFrameNameLookup[3]['language'] = 'TLAN'; - $ID3v2ShortFrameNameLookup[3]['length'] = 'TLEN'; - $ID3v2ShortFrameNameLookup[3]['media_type'] = 'TMED'; - $ID3v2ShortFrameNameLookup[3]['original_album'] = 'TOAL'; - $ID3v2ShortFrameNameLookup[3]['original_filename'] = 'TOFN'; - $ID3v2ShortFrameNameLookup[3]['original_lyricist'] = 'TOLY'; - $ID3v2ShortFrameNameLookup[3]['original_artist'] = 'TOPE'; - $ID3v2ShortFrameNameLookup[3]['file_owner'] = 'TOWN'; - $ID3v2ShortFrameNameLookup[3]['artist'] = 'TPE1'; - $ID3v2ShortFrameNameLookup[3]['band'] = 'TPE2'; - $ID3v2ShortFrameNameLookup[3]['conductor'] = 'TPE3'; - $ID3v2ShortFrameNameLookup[3]['remixer'] = 'TPE4'; - $ID3v2ShortFrameNameLookup[3]['part_of_a_set'] = 'TPOS'; - $ID3v2ShortFrameNameLookup[3]['publisher'] = 'TPUB'; - $ID3v2ShortFrameNameLookup[3]['tracknumber'] = 'TRCK'; - $ID3v2ShortFrameNameLookup[3]['track_number'] = 'TRCK'; - $ID3v2ShortFrameNameLookup[3]['internet_radio_station_name'] = 'TRSN'; - $ID3v2ShortFrameNameLookup[3]['internet_radio_station_owner'] = 'TRSO'; - $ID3v2ShortFrameNameLookup[3]['album_artist_sort_order'] = 'TSO2'; - $ID3v2ShortFrameNameLookup[3]['album_sort_order'] = 'TSOA'; - $ID3v2ShortFrameNameLookup[3]['composer_sort_order'] = 'TSOC'; - $ID3v2ShortFrameNameLookup[3]['performer_sort_order'] = 'TSOP'; - $ID3v2ShortFrameNameLookup[3]['title_sort_order'] = 'TSOT'; - $ID3v2ShortFrameNameLookup[3]['isrc'] = 'TSRC'; - $ID3v2ShortFrameNameLookup[3]['encoder_settings'] = 'TSSE'; - $ID3v2ShortFrameNameLookup[3]['text'] = 'TXXX'; - $ID3v2ShortFrameNameLookup[3]['unique_file_identifier'] = 'UFID'; - $ID3v2ShortFrameNameLookup[3]['terms_of_use'] = 'USER'; - $ID3v2ShortFrameNameLookup[3]['unsychronised_lyric'] = 'USLT'; - $ID3v2ShortFrameNameLookup[3]['commercial_information'] = 'WCOM'; - $ID3v2ShortFrameNameLookup[3]['copyright'] = 'WCOP'; - $ID3v2ShortFrameNameLookup[3]['url_file'] = 'WOAF'; - $ID3v2ShortFrameNameLookup[3]['url_artist'] = 'WOAR'; - $ID3v2ShortFrameNameLookup[3]['url_source'] = 'WOAS'; - $ID3v2ShortFrameNameLookup[3]['url_station'] = 'WORS'; - $ID3v2ShortFrameNameLookup[3]['url_payment'] = 'WPAY'; - $ID3v2ShortFrameNameLookup[3]['url_publisher'] = 'WPUB'; - $ID3v2ShortFrameNameLookup[3]['url_user'] = 'WXXX'; - - // The above are common to ID3v2.3 and ID3v2.4 - // so copy them to ID3v2.4 before adding specifics for 2.3 and 2.4 - $ID3v2ShortFrameNameLookup[4] = $ID3v2ShortFrameNameLookup[3]; - - // The following are unique to ID3v2.3 - $ID3v2ShortFrameNameLookup[3]['equalisation'] = 'EQUA'; - $ID3v2ShortFrameNameLookup[3]['involved_people_list'] = 'IPLS'; - $ID3v2ShortFrameNameLookup[3]['relative_volume_adjustment'] = 'RVAD'; - $ID3v2ShortFrameNameLookup[3]['date'] = 'TDAT'; - $ID3v2ShortFrameNameLookup[3]['time'] = 'TIME'; - $ID3v2ShortFrameNameLookup[3]['original_year'] = 'TORY'; - $ID3v2ShortFrameNameLookup[3]['recording_dates'] = 'TRDA'; - $ID3v2ShortFrameNameLookup[3]['size'] = 'TSIZ'; - $ID3v2ShortFrameNameLookup[3]['year'] = 'TYER'; - - - // The following are unique to ID3v2.4 - $ID3v2ShortFrameNameLookup[4]['audio_seek_point_index'] = 'ASPI'; - $ID3v2ShortFrameNameLookup[4]['equalisation'] = 'EQU2'; - $ID3v2ShortFrameNameLookup[4]['relative_volume_adjustment'] = 'RVA2'; - $ID3v2ShortFrameNameLookup[4]['seek_frame'] = 'SEEK'; - $ID3v2ShortFrameNameLookup[4]['signature_frame'] = 'SIGN'; - $ID3v2ShortFrameNameLookup[4]['encoding_time'] = 'TDEN'; - $ID3v2ShortFrameNameLookup[4]['original_release_time'] = 'TDOR'; - $ID3v2ShortFrameNameLookup[4]['recording_time'] = 'TDRC'; - $ID3v2ShortFrameNameLookup[4]['release_time'] = 'TDRL'; - $ID3v2ShortFrameNameLookup[4]['tagging_time'] = 'TDTG'; - $ID3v2ShortFrameNameLookup[4]['involved_people_list'] = 'TIPL'; - $ID3v2ShortFrameNameLookup[4]['musician_credits_list'] = 'TMCL'; - $ID3v2ShortFrameNameLookup[4]['mood'] = 'TMOO'; - $ID3v2ShortFrameNameLookup[4]['produced_notice'] = 'TPRO'; - $ID3v2ShortFrameNameLookup[4]['album_sort_order'] = 'TSOA'; - $ID3v2ShortFrameNameLookup[4]['performer_sort_order'] = 'TSOP'; - $ID3v2ShortFrameNameLookup[4]['title_sort_order'] = 'TSOT'; - $ID3v2ShortFrameNameLookup[4]['set_subtitle'] = 'TSST'; - } - return (isset($ID3v2ShortFrameNameLookup[$majorversion][strtolower($long_description)]) ? $ID3v2ShortFrameNameLookup[$majorversion][strtolower($long_description)] : ''); - - } - + public $filename; + public $tag_data; + public $fread_buffer_size = 32768; // read buffer size in bytes + public $paddedlength = 4096; // minimum length of ID3v2 tag in bytes + public $majorversion = 3; // ID3v2 major version (2, 3 (recommended), 4) + public $minorversion = 0; // ID3v2 minor version - always 0 + public $merge_existing_data = false; // if true, merge new data with existing tags; if false, delete old tag data and only write new tags + public $id3v2_default_encodingid = 0; // default text encoding (ISO-8859-1) if not explicitly passed + public $id3v2_use_unsynchronisation = false; // the specs say it should be TRUE, but most other ID3v2-aware programs are broken if unsynchronization is used, so by default don't use it. + public $warnings = []; // any non-critical errors will be stored here + public $errors = []; // any critical errors will be stored here + + public function __construct() + { + return true; + } + + public function WriteID3v2() + { + // File MUST be writeable - CHMOD(646) at least. It's best if the + // directory is also writeable, because that method is both faster and less susceptible to errors. + + if (! empty($this->filename) && (is_writable($this->filename) || (! file_exists($this->filename) && is_writable(dirname($this->filename))))) { + // Initialize getID3 engine + $getID3 = new getID3; + $OldThisFileInfo = $getID3->analyze($this->filename); + if (! getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) { + $this->errors[] = 'Unable to write ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; + fclose($fp_source); + + return false; + } + if ($this->merge_existing_data) { + // merge with existing data + if (! empty($OldThisFileInfo['id3v2'])) { + $this->tag_data = $this->array_join_merge($OldThisFileInfo['id3v2'], $this->tag_data); + } + } + $this->paddedlength = (isset($OldThisFileInfo['id3v2']['headerlength']) ? max($OldThisFileInfo['id3v2']['headerlength'], $this->paddedlength) : $this->paddedlength); + + if ($NewID3v2Tag = $this->GenerateID3v2Tag()) { + if (file_exists($this->filename) && is_writable($this->filename) && isset($OldThisFileInfo['id3v2']['headerlength']) && ($OldThisFileInfo['id3v2']['headerlength'] == strlen($NewID3v2Tag))) { + + // best and fastest method - insert-overwrite existing tag (padded to length of old tag if neccesary) + if (file_exists($this->filename)) { + if (is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'r+b'))) { + rewind($fp); + fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag)); + fclose($fp); + } else { + $this->errors[] = 'Could not fopen("'.$this->filename.'", "r+b")'; + } + } else { + if (is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'wb'))) { + rewind($fp); + fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag)); + fclose($fp); + } else { + $this->errors[] = 'Could not fopen("'.$this->filename.'", "wb")'; + } + } + } else { + if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) { + if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) { + if (is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) { + fwrite($fp_temp, $NewID3v2Tag, strlen($NewID3v2Tag)); + + rewind($fp_source); + if (! empty($OldThisFileInfo['avdataoffset'])) { + fseek($fp_source, $OldThisFileInfo['avdataoffset']); + } + + while ($buffer = fread($fp_source, $this->fread_buffer_size)) { + fwrite($fp_temp, $buffer, strlen($buffer)); + } + + fclose($fp_temp); + fclose($fp_source); + copy($tempfilename, $this->filename); + unlink($tempfilename); + + return true; + } else { + $this->errors[] = 'Could not fopen("'.$tempfilename.'", "wb")'; + } + fclose($fp_source); + } else { + $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")'; + } + } + + return false; + } + } else { + $this->errors[] = '$this->GenerateID3v2Tag() failed'; + } + + if (! empty($this->errors)) { + return false; + } + + return true; + } else { + $this->errors[] = 'WriteID3v2() failed: !is_writeable('.$this->filename.')'; + } + + return false; + } + + public function RemoveID3v2() + { + // File MUST be writeable - CHMOD(646) at least. It's best if the + // directory is also writeable, because that method is both faster and less susceptible to errors. + if (is_writable(dirname($this->filename))) { + + // preferred method - only one copying operation, minimal chance of corrupting + // original file if script is interrupted, but required directory to be writeable + if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) { + + // Initialize getID3 engine + $getID3 = new getID3; + $OldThisFileInfo = $getID3->analyze($this->filename); + if (! getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) { + $this->errors[] = 'Unable to remove ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; + fclose($fp_source); + + return false; + } + rewind($fp_source); + if ($OldThisFileInfo['avdataoffset'] !== false) { + fseek($fp_source, $OldThisFileInfo['avdataoffset']); + } + if (is_writable($this->filename) && is_file($this->filename) && ($fp_temp = fopen($this->filename.'getid3tmp', 'w+b'))) { + while ($buffer = fread($fp_source, $this->fread_buffer_size)) { + fwrite($fp_temp, $buffer, strlen($buffer)); + } + fclose($fp_temp); + } else { + $this->errors[] = 'Could not fopen("'.$this->filename.'getid3tmp", "w+b")'; + } + fclose($fp_source); + } else { + $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")'; + } + if (file_exists($this->filename)) { + unlink($this->filename); + } + rename($this->filename.'getid3tmp', $this->filename); + } elseif (is_writable($this->filename)) { + + // less desirable alternate method - double-copies the file, overwrites original file + // and could corrupt source file if the script is interrupted or an error occurs. + if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) { + + // Initialize getID3 engine + $getID3 = new getID3; + $OldThisFileInfo = $getID3->analyze($this->filename); + if (! getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) { + $this->errors[] = 'Unable to remove ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; + fclose($fp_source); + + return false; + } + rewind($fp_source); + if ($OldThisFileInfo['avdataoffset'] !== false) { + fseek($fp_source, $OldThisFileInfo['avdataoffset']); + } + if ($fp_temp = tmpfile()) { + while ($buffer = fread($fp_source, $this->fread_buffer_size)) { + fwrite($fp_temp, $buffer, strlen($buffer)); + } + fclose($fp_source); + if (is_writable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'wb'))) { + rewind($fp_temp); + while ($buffer = fread($fp_temp, $this->fread_buffer_size)) { + fwrite($fp_source, $buffer, strlen($buffer)); + } + fseek($fp_temp, -128, SEEK_END); + fclose($fp_source); + } else { + $this->errors[] = 'Could not fopen("'.$this->filename.'", "wb")'; + } + fclose($fp_temp); + } else { + $this->errors[] = 'Could not create tmpfile()'; + } + } else { + $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")'; + } + } else { + $this->errors[] = 'Directory and file both not writeable'; + } + + if (! empty($this->errors)) { + return false; + } + + return true; + } + + public function GenerateID3v2TagFlags($flags) + { + switch ($this->majorversion) { + case 4: + // %abcd0000 + $flag = (! empty($flags['unsynchronisation']) ? '1' : '0'); // a - Unsynchronisation + $flag .= (! empty($flags['extendedheader']) ? '1' : '0'); // b - Extended header + $flag .= (! empty($flags['experimental']) ? '1' : '0'); // c - Experimental indicator + $flag .= (! empty($flags['footer']) ? '1' : '0'); // d - Footer present + $flag .= '0000'; + break; + + case 3: + // %abc00000 + $flag = (! empty($flags['unsynchronisation']) ? '1' : '0'); // a - Unsynchronisation + $flag .= (! empty($flags['extendedheader']) ? '1' : '0'); // b - Extended header + $flag .= (! empty($flags['experimental']) ? '1' : '0'); // c - Experimental indicator + $flag .= '00000'; + break; + + case 2: + // %ab000000 + $flag = (! empty($flags['unsynchronisation']) ? '1' : '0'); // a - Unsynchronisation + $flag .= (! empty($flags['compression']) ? '1' : '0'); // b - Compression + $flag .= '000000'; + break; + + default: + return false; + break; + } + + return chr(bindec($flag)); + } + + public function GenerateID3v2FrameFlags($TagAlter = false, $FileAlter = false, $ReadOnly = false, $Compression = false, $Encryption = false, $GroupingIdentity = false, $Unsynchronisation = false, $DataLengthIndicator = false) + { + switch ($this->majorversion) { + case 4: + // %0abc0000 %0h00kmnp + $flag1 = '0'; + $flag1 .= $TagAlter ? '1' : '0'; // a - Tag alter preservation (true == discard) + $flag1 .= $FileAlter ? '1' : '0'; // b - File alter preservation (true == discard) + $flag1 .= $ReadOnly ? '1' : '0'; // c - Read only (true == read only) + $flag1 .= '0000'; + + $flag2 = '0'; + $flag2 .= $GroupingIdentity ? '1' : '0'; // h - Grouping identity (true == contains group information) + $flag2 .= '00'; + $flag2 .= $Compression ? '1' : '0'; // k - Compression (true == compressed) + $flag2 .= $Encryption ? '1' : '0'; // m - Encryption (true == encrypted) + $flag2 .= $Unsynchronisation ? '1' : '0'; // n - Unsynchronisation (true == unsynchronised) + $flag2 .= $DataLengthIndicator ? '1' : '0'; // p - Data length indicator (true == data length indicator added) + break; + + case 3: + // %abc00000 %ijk00000 + $flag1 = $TagAlter ? '1' : '0'; // a - Tag alter preservation (true == discard) + $flag1 .= $FileAlter ? '1' : '0'; // b - File alter preservation (true == discard) + $flag1 .= $ReadOnly ? '1' : '0'; // c - Read only (true == read only) + $flag1 .= '00000'; + + $flag2 = $Compression ? '1' : '0'; // i - Compression (true == compressed) + $flag2 .= $Encryption ? '1' : '0'; // j - Encryption (true == encrypted) + $flag2 .= $GroupingIdentity ? '1' : '0'; // k - Grouping identity (true == contains group information) + $flag2 .= '00000'; + break; + + default: + return false; + break; + + } + + return chr(bindec($flag1)).chr(bindec($flag2)); + } + + public function GenerateID3v2FrameData($frame_name, $source_data_array) + { + if (! getid3_id3v2::IsValidID3v2FrameName($frame_name, $this->majorversion)) { + return false; + } + $framedata = ''; + + if (($this->majorversion < 3) || ($this->majorversion > 4)) { + $this->errors[] = 'Only ID3v2.3 and ID3v2.4 are supported in GenerateID3v2FrameData()'; + } else { // $this->majorversion 3 or 4 + + switch ($frame_name) { + case 'UFID': + // 4.1 UFID Unique file identifier + // Owner identifier $00 + // Identifier + if (strlen($source_data_array['data']) > 64) { + $this->errors[] = 'Identifier not allowed to be longer than 64 bytes in '.$frame_name.' (supplied data was '.strlen($source_data_array['data']).' bytes long)'; + } else { + $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00"; + $framedata .= substr($source_data_array['data'], 0, 64); // max 64 bytes - truncate anything longer + } + break; + + case 'TXXX': + // 4.2.2 TXXX User defined text information frame + // Text encoding $xx + // Description $00 (00) + // Value + $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); + if (! $this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) { + $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; + } else { + $framedata .= chr($source_data_array['encodingid']); + $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); + $framedata .= $source_data_array['data']; + } + break; + + case 'WXXX': + // 4.3.2 WXXX User defined URL link frame + // Text encoding $xx + // Description $00 (00) + // URL + $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); + if (! $this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) { + $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; + } elseif (! isset($source_data_array['data']) || ! $this->IsValidURL($source_data_array['data'], false, false)) { + //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; + // probably should be an error, need to rewrite IsValidURL() to handle other encodings + $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; + } else { + $framedata .= chr($source_data_array['encodingid']); + $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); + $framedata .= $source_data_array['data']; + } + break; + + case 'IPLS': + // 4.4 IPLS Involved people list (ID3v2.3 only) + // Text encoding $xx + // People list strings + $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); + if (! $this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) { + $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; + } else { + $framedata .= chr($source_data_array['encodingid']); + $framedata .= $source_data_array['data']; + } + break; + + case 'MCDI': + // 4.4 MCDI Music CD identifier + // CD TOC + $framedata .= $source_data_array['data']; + break; + + case 'ETCO': + // 4.5 ETCO Event timing codes + // Time stamp format $xx + // Where time stamp format is: + // $01 (32-bit value) MPEG frames from beginning of file + // $02 (32-bit value) milliseconds from beginning of file + // Followed by a list of key events in the following format: + // Type of event $xx + // Time stamp $xx (xx ...) + // The 'Time stamp' is set to zero if directly at the beginning of the sound + // or after the previous event. All events MUST be sorted in chronological order. + if (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) { + $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')'; + } else { + $framedata .= chr($source_data_array['timestampformat']); + foreach ($source_data_array as $key => $val) { + if (! $this->ID3v2IsValidETCOevent($val['typeid'])) { + $this->errors[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')'; + } elseif (($key != 'timestampformat') && ($key != 'flags')) { + if (($val['timestamp'] > 0) && ($previousETCOtimestamp >= $val['timestamp'])) { + // The 'Time stamp' is set to zero if directly at the beginning of the sound + // or after the previous event. All events MUST be sorted in chronological order. + $this->errors[] = 'Out-of-order timestamp in '.$frame_name.' ('.$val['timestamp'].') for Event Type ('.$val['typeid'].')'; + } else { + $framedata .= chr($val['typeid']); + $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false); + } + } + } + } + break; + + case 'MLLT': + // 4.6 MLLT MPEG location lookup table + // MPEG frames between reference $xx xx + // Bytes between reference $xx xx xx + // Milliseconds between reference $xx xx xx + // Bits for bytes deviation $xx + // Bits for milliseconds dev. $xx + // Then for every reference the following data is included; + // Deviation in bytes %xxx.... + // Deviation in milliseconds %xxx.... + if (($source_data_array['framesbetweenreferences'] > 0) && ($source_data_array['framesbetweenreferences'] <= 65535)) { + $framedata .= getid3_lib::BigEndian2String($source_data_array['framesbetweenreferences'], 2, false); + } else { + $this->errors[] = 'Invalid MPEG Frames Between References in '.$frame_name.' ('.$source_data_array['framesbetweenreferences'].')'; + } + if (($source_data_array['bytesbetweenreferences'] > 0) && ($source_data_array['bytesbetweenreferences'] <= 16777215)) { + $framedata .= getid3_lib::BigEndian2String($source_data_array['bytesbetweenreferences'], 3, false); + } else { + $this->errors[] = 'Invalid bytes Between References in '.$frame_name.' ('.$source_data_array['bytesbetweenreferences'].')'; + } + if (($source_data_array['msbetweenreferences'] > 0) && ($source_data_array['msbetweenreferences'] <= 16777215)) { + $framedata .= getid3_lib::BigEndian2String($source_data_array['msbetweenreferences'], 3, false); + } else { + $this->errors[] = 'Invalid Milliseconds Between References in '.$frame_name.' ('.$source_data_array['msbetweenreferences'].')'; + } + if (! $this->IsWithinBitRange($source_data_array['bitsforbytesdeviation'], 8, false)) { + if (($source_data_array['bitsforbytesdeviation'] % 4) == 0) { + $framedata .= chr($source_data_array['bitsforbytesdeviation']); + } else { + $this->errors[] = 'Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.'; + } + } else { + $this->errors[] = 'Invalid Bits For Bytes Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].')'; + } + if (! $this->IsWithinBitRange($source_data_array['bitsformsdeviation'], 8, false)) { + if (($source_data_array['bitsformsdeviation'] % 4) == 0) { + $framedata .= chr($source_data_array['bitsformsdeviation']); + } else { + $this->errors[] = 'Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsforbytesdeviation'].') must be a multiple of 4.'; + } + } else { + $this->errors[] = 'Invalid Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsformsdeviation'].')'; + } + foreach ($source_data_array as $key => $val) { + if (($key != 'framesbetweenreferences') && ($key != 'bytesbetweenreferences') && ($key != 'msbetweenreferences') && ($key != 'bitsforbytesdeviation') && ($key != 'bitsformsdeviation') && ($key != 'flags')) { + $unwrittenbitstream .= str_pad(getid3_lib::Dec2Bin($val['bytedeviation']), $source_data_array['bitsforbytesdeviation'], '0', STR_PAD_LEFT); + $unwrittenbitstream .= str_pad(getid3_lib::Dec2Bin($val['msdeviation']), $source_data_array['bitsformsdeviation'], '0', STR_PAD_LEFT); + } + } + for ($i = 0; $i < strlen($unwrittenbitstream); $i += 8) { + $highnibble = bindec(substr($unwrittenbitstream, $i, 4)) << 4; + $lownibble = bindec(substr($unwrittenbitstream, $i + 4, 4)); + $framedata .= chr($highnibble & $lownibble); + } + break; + + case 'SYTC': + // 4.7 SYTC Synchronised tempo codes + // Time stamp format $xx + // Tempo data + // Where time stamp format is: + // $01 (32-bit value) MPEG frames from beginning of file + // $02 (32-bit value) milliseconds from beginning of file + if (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) { + $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')'; + } else { + $framedata .= chr($source_data_array['timestampformat']); + foreach ($source_data_array as $key => $val) { + if (! $this->ID3v2IsValidETCOevent($val['typeid'])) { + $this->errors[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')'; + } elseif (($key != 'timestampformat') && ($key != 'flags')) { + if (($val['tempo'] < 0) || ($val['tempo'] > 510)) { + $this->errors[] = 'Invalid Tempo (max = 510) in '.$frame_name.' ('.$val['tempo'].') at timestamp ('.$val['timestamp'].')'; + } else { + if ($val['tempo'] > 255) { + $framedata .= chr(255); + $val['tempo'] -= 255; + } + $framedata .= chr($val['tempo']); + $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false); + } + } + } + } + break; + + case 'USLT': + // 4.8 USLT Unsynchronised lyric/text transcription + // Text encoding $xx + // Language $xx xx xx + // Content descriptor $00 (00) + // Lyrics/text + $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); + if (! $this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { + $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; + } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') { + $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')'; + } else { + $framedata .= chr($source_data_array['encodingid']); + $framedata .= strtolower($source_data_array['language']); + $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); + $framedata .= $source_data_array['data']; + } + break; + + case 'SYLT': + // 4.9 SYLT Synchronised lyric/text + // Text encoding $xx + // Language $xx xx xx + // Time stamp format $xx + // $01 (32-bit value) MPEG frames from beginning of file + // $02 (32-bit value) milliseconds from beginning of file + // Content type $xx + // Content descriptor $00 (00) + // Terminated text to be synced (typically a syllable) + // Sync identifier (terminator to above string) $00 (00) + // Time stamp $xx (xx ...) + $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); + if (! $this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { + $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; + } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') { + $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')'; + } elseif (($source_data_array['timestampformat'] > 2) || ($source_data_array['timestampformat'] < 1)) { + $this->errors[] = 'Invalid Time Stamp Format byte in '.$frame_name.' ('.$source_data_array['timestampformat'].')'; + } elseif (! $this->ID3v2IsValidSYLTtype($source_data_array['contenttypeid'])) { + $this->errors[] = 'Invalid Content Type byte in '.$frame_name.' ('.$source_data_array['contenttypeid'].')'; + } elseif (! is_array($source_data_array['data'])) { + $this->errors[] = 'Invalid Lyric/Timestamp data in '.$frame_name.' (must be an array)'; + } else { + $framedata .= chr($source_data_array['encodingid']); + $framedata .= strtolower($source_data_array['language']); + $framedata .= chr($source_data_array['timestampformat']); + $framedata .= chr($source_data_array['contenttypeid']); + $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); + ksort($source_data_array['data']); + foreach ($source_data_array['data'] as $key => $val) { + $framedata .= $val['data'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); + $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false); + } + } + break; + + case 'COMM': + // 4.10 COMM Comments + // Text encoding $xx + // Language $xx xx xx + // Short content descrip. $00 (00) + // The actual text + $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); + if (! $this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { + $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; + } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') { + $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')'; + } else { + $framedata .= chr($source_data_array['encodingid']); + $framedata .= strtolower($source_data_array['language']); + $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); + $framedata .= $source_data_array['data']; + } + break; + + case 'RVA2': + // 4.11 RVA2 Relative volume adjustment (2) (ID3v2.4+ only) + // Identification $00 + // The 'identification' string is used to identify the situation and/or + // device where this adjustment should apply. The following is then + // repeated for every channel: + // Type of channel $xx + // Volume adjustment $xx xx + // Bits representing peak $xx + // Peak volume $xx (xx ...) + $framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00"; + foreach ($source_data_array as $key => $val) { + if ($key != 'description') { + $framedata .= chr($val['channeltypeid']); + $framedata .= getid3_lib::BigEndian2String($val['volumeadjust'], 2, false, true); // signed 16-bit + if (! $this->IsWithinBitRange($source_data_array['bitspeakvolume'], 8, false)) { + $framedata .= chr($val['bitspeakvolume']); + if ($val['bitspeakvolume'] > 0) { + $framedata .= getid3_lib::BigEndian2String($val['peakvolume'], ceil($val['bitspeakvolume'] / 8), false, false); + } + } else { + $this->errors[] = 'Invalid Bits Representing Peak Volume in '.$frame_name.' ('.$val['bitspeakvolume'].') (range = 0 to 255)'; + } + } + } + break; + + case 'RVAD': + // 4.12 RVAD Relative volume adjustment (ID3v2.3 only) + // Increment/decrement %00fedcba + // Bits used for volume descr. $xx + // Relative volume change, right $xx xx (xx ...) // a + // Relative volume change, left $xx xx (xx ...) // b + // Peak volume right $xx xx (xx ...) + // Peak volume left $xx xx (xx ...) + // Relative volume change, right back $xx xx (xx ...) // c + // Relative volume change, left back $xx xx (xx ...) // d + // Peak volume right back $xx xx (xx ...) + // Peak volume left back $xx xx (xx ...) + // Relative volume change, center $xx xx (xx ...) // e + // Peak volume center $xx xx (xx ...) + // Relative volume change, bass $xx xx (xx ...) // f + // Peak volume bass $xx xx (xx ...) + if (! $this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) { + $this->errors[] = 'Invalid Bits For Volume Description byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)'; + } else { + $incdecflag .= '00'; + $incdecflag .= $source_data_array['incdec']['right'] ? '1' : '0'; // a - Relative volume change, right + $incdecflag .= $source_data_array['incdec']['left'] ? '1' : '0'; // b - Relative volume change, left + $incdecflag .= $source_data_array['incdec']['rightrear'] ? '1' : '0'; // c - Relative volume change, right back + $incdecflag .= $source_data_array['incdec']['leftrear'] ? '1' : '0'; // d - Relative volume change, left back + $incdecflag .= $source_data_array['incdec']['center'] ? '1' : '0'; // e - Relative volume change, center + $incdecflag .= $source_data_array['incdec']['bass'] ? '1' : '0'; // f - Relative volume change, bass + $framedata .= chr(bindec($incdecflag)); + $framedata .= chr($source_data_array['bitsvolume']); + $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['right'], ceil($source_data_array['bitsvolume'] / 8), false); + $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['left'], ceil($source_data_array['bitsvolume'] / 8), false); + $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['right'], ceil($source_data_array['bitsvolume'] / 8), false); + $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['left'], ceil($source_data_array['bitsvolume'] / 8), false); + if ($source_data_array['volumechange']['rightrear'] || $source_data_array['volumechange']['leftrear'] || + $source_data_array['peakvolume']['rightrear'] || $source_data_array['peakvolume']['leftrear'] || + $source_data_array['volumechange']['center'] || $source_data_array['peakvolume']['center'] || + $source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) { + $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['rightrear'], ceil($source_data_array['bitsvolume'] / 8), false); + $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['leftrear'], ceil($source_data_array['bitsvolume'] / 8), false); + $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['rightrear'], ceil($source_data_array['bitsvolume'] / 8), false); + $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['leftrear'], ceil($source_data_array['bitsvolume'] / 8), false); + } + if ($source_data_array['volumechange']['center'] || $source_data_array['peakvolume']['center'] || + $source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) { + $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['center'], ceil($source_data_array['bitsvolume'] / 8), false); + $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['center'], ceil($source_data_array['bitsvolume'] / 8), false); + } + if ($source_data_array['volumechange']['bass'] || $source_data_array['peakvolume']['bass']) { + $framedata .= getid3_lib::BigEndian2String($source_data_array['volumechange']['bass'], ceil($source_data_array['bitsvolume'] / 8), false); + $framedata .= getid3_lib::BigEndian2String($source_data_array['peakvolume']['bass'], ceil($source_data_array['bitsvolume'] / 8), false); + } + } + break; + + case 'EQU2': + // 4.12 EQU2 Equalisation (2) (ID3v2.4+ only) + // Interpolation method $xx + // $00 Band + // $01 Linear + // Identification $00 + // The following is then repeated for every adjustment point + // Frequency $xx xx + // Volume adjustment $xx xx + if (($source_data_array['interpolationmethod'] < 0) || ($source_data_array['interpolationmethod'] > 1)) { + $this->errors[] = 'Invalid Interpolation Method byte in '.$frame_name.' ('.$source_data_array['interpolationmethod'].') (valid = 0 or 1)'; + } else { + $framedata .= chr($source_data_array['interpolationmethod']); + $framedata .= str_replace("\x00", '', $source_data_array['description'])."\x00"; + foreach ($source_data_array['data'] as $key => $val) { + $framedata .= getid3_lib::BigEndian2String(intval(round($key * 2)), 2, false); + $framedata .= getid3_lib::BigEndian2String($val, 2, false, true); // signed 16-bit + } + } + break; + + case 'EQUA': + // 4.12 EQUA Equalisation (ID3v2.3 only) + // Adjustment bits $xx + // This is followed by 2 bytes + ('adjustment bits' rounded up to the + // nearest byte) for every equalisation band in the following format, + // giving a frequency range of 0 - 32767Hz: + // Increment/decrement %x (MSB of the Frequency) + // Frequency (lower 15 bits) + // Adjustment $xx (xx ...) + if (! $this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) { + $this->errors[] = 'Invalid Adjustment Bits byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)'; + } else { + $framedata .= chr($source_data_array['adjustmentbits']); + foreach ($source_data_array as $key => $val) { + if ($key != 'bitsvolume') { + if (($key > 32767) || ($key < 0)) { + $this->errors[] = 'Invalid Frequency in '.$frame_name.' ('.$key.') (range = 0 to 32767)'; + } else { + if ($val >= 0) { + // put MSB of frequency to 1 if increment, 0 if decrement + $key |= 0x8000; + } + $framedata .= getid3_lib::BigEndian2String($key, 2, false); + $framedata .= getid3_lib::BigEndian2String($val, ceil($source_data_array['adjustmentbits'] / 8), false); + } + } + } + } + break; + + case 'RVRB': + // 4.13 RVRB Reverb + // Reverb left (ms) $xx xx + // Reverb right (ms) $xx xx + // Reverb bounces, left $xx + // Reverb bounces, right $xx + // Reverb feedback, left to left $xx + // Reverb feedback, left to right $xx + // Reverb feedback, right to right $xx + // Reverb feedback, right to left $xx + // Premix left to right $xx + // Premix right to left $xx + if (! $this->IsWithinBitRange($source_data_array['left'], 16, false)) { + $this->errors[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['left'].') (range = 0 to 65535)'; + } elseif (! $this->IsWithinBitRange($source_data_array['right'], 16, false)) { + $this->errors[] = 'Invalid Reverb Left in '.$frame_name.' ('.$source_data_array['right'].') (range = 0 to 65535)'; + } elseif (! $this->IsWithinBitRange($source_data_array['bouncesL'], 8, false)) { + $this->errors[] = 'Invalid Reverb Bounces, Left in '.$frame_name.' ('.$source_data_array['bouncesL'].') (range = 0 to 255)'; + } elseif (! $this->IsWithinBitRange($source_data_array['bouncesR'], 8, false)) { + $this->errors[] = 'Invalid Reverb Bounces, Right in '.$frame_name.' ('.$source_data_array['bouncesR'].') (range = 0 to 255)'; + } elseif (! $this->IsWithinBitRange($source_data_array['feedbackLL'], 8, false)) { + $this->errors[] = 'Invalid Reverb Feedback, Left-To-Left in '.$frame_name.' ('.$source_data_array['feedbackLL'].') (range = 0 to 255)'; + } elseif (! $this->IsWithinBitRange($source_data_array['feedbackLR'], 8, false)) { + $this->errors[] = 'Invalid Reverb Feedback, Left-To-Right in '.$frame_name.' ('.$source_data_array['feedbackLR'].') (range = 0 to 255)'; + } elseif (! $this->IsWithinBitRange($source_data_array['feedbackRR'], 8, false)) { + $this->errors[] = 'Invalid Reverb Feedback, Right-To-Right in '.$frame_name.' ('.$source_data_array['feedbackRR'].') (range = 0 to 255)'; + } elseif (! $this->IsWithinBitRange($source_data_array['feedbackRL'], 8, false)) { + $this->errors[] = 'Invalid Reverb Feedback, Right-To-Left in '.$frame_name.' ('.$source_data_array['feedbackRL'].') (range = 0 to 255)'; + } elseif (! $this->IsWithinBitRange($source_data_array['premixLR'], 8, false)) { + $this->errors[] = 'Invalid Premix, Left-To-Right in '.$frame_name.' ('.$source_data_array['premixLR'].') (range = 0 to 255)'; + } elseif (! $this->IsWithinBitRange($source_data_array['premixRL'], 8, false)) { + $this->errors[] = 'Invalid Premix, Right-To-Left in '.$frame_name.' ('.$source_data_array['premixRL'].') (range = 0 to 255)'; + } else { + $framedata .= getid3_lib::BigEndian2String($source_data_array['left'], 2, false); + $framedata .= getid3_lib::BigEndian2String($source_data_array['right'], 2, false); + $framedata .= chr($source_data_array['bouncesL']); + $framedata .= chr($source_data_array['bouncesR']); + $framedata .= chr($source_data_array['feedbackLL']); + $framedata .= chr($source_data_array['feedbackLR']); + $framedata .= chr($source_data_array['feedbackRR']); + $framedata .= chr($source_data_array['feedbackRL']); + $framedata .= chr($source_data_array['premixLR']); + $framedata .= chr($source_data_array['premixRL']); + } + break; + + case 'APIC': + // 4.14 APIC Attached picture + // Text encoding $xx + // MIME type $00 + // Picture type $xx + // Description $00 (00) + // Picture data + $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); + if (! $this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { + $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; + } elseif (! $this->ID3v2IsValidAPICpicturetype($source_data_array['picturetypeid'])) { + $this->errors[] = 'Invalid Picture Type byte in '.$frame_name.' ('.$source_data_array['picturetypeid'].') for ID3v2.'.$this->majorversion; + } elseif (($this->majorversion >= 3) && (! $this->ID3v2IsValidAPICimageformat($source_data_array['mime']))) { + $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].') for ID3v2.'.$this->majorversion; + } elseif (($source_data_array['mime'] == '-->') && (! $this->IsValidURL($source_data_array['data'], false, false))) { + //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; + // probably should be an error, need to rewrite IsValidURL() to handle other encodings + $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; + } else { + $framedata .= chr($source_data_array['encodingid']); + $framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00"; + $framedata .= chr($source_data_array['picturetypeid']); + $framedata .= (! empty($source_data_array['description']) ? $source_data_array['description'] : '').getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); + $framedata .= $source_data_array['data']; + } + break; + + case 'GEOB': + // 4.15 GEOB General encapsulated object + // Text encoding $xx + // MIME type $00 + // Filename $00 (00) + // Content description $00 (00) + // Encapsulated object + $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); + if (! $this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { + $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; + } elseif (! $this->IsValidMIMEstring($source_data_array['mime'])) { + $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].')'; + } elseif (! $source_data_array['description']) { + $this->errors[] = 'Missing Description in '.$frame_name; + } else { + $framedata .= chr($source_data_array['encodingid']); + $framedata .= str_replace("\x00", '', $source_data_array['mime'])."\x00"; + $framedata .= $source_data_array['filename'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); + $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); + $framedata .= $source_data_array['data']; + } + break; + + case 'PCNT': + // 4.16 PCNT Play counter + // When the counter reaches all one's, one byte is inserted in + // front of the counter thus making the counter eight bits bigger + // Counter $xx xx xx xx (xx ...) + $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false); + break; + + case 'POPM': + // 4.17 POPM Popularimeter + // When the counter reaches all one's, one byte is inserted in + // front of the counter thus making the counter eight bits bigger + // Email to user $00 + // Rating $xx + // Counter $xx xx xx xx (xx ...) + if (! $this->IsWithinBitRange($source_data_array['rating'], 8, false)) { + $this->errors[] = 'Invalid Rating byte in '.$frame_name.' ('.$source_data_array['rating'].') (range = 0 to 255)'; + } elseif (! $this->IsValidEmail($source_data_array['email'])) { + $this->errors[] = 'Invalid Email in '.$frame_name.' ('.$source_data_array['email'].')'; + } else { + $framedata .= str_replace("\x00", '', $source_data_array['email'])."\x00"; + $framedata .= chr($source_data_array['rating']); + $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false); + } + break; + + case 'RBUF': + // 4.18 RBUF Recommended buffer size + // Buffer size $xx xx xx + // Embedded info flag %0000000x + // Offset to next tag $xx xx xx xx + if (! $this->IsWithinBitRange($source_data_array['buffersize'], 24, false)) { + $this->errors[] = 'Invalid Buffer Size in '.$frame_name; + } elseif (! $this->IsWithinBitRange($source_data_array['nexttagoffset'], 32, false)) { + $this->errors[] = 'Invalid Offset To Next Tag in '.$frame_name; + } else { + $framedata .= getid3_lib::BigEndian2String($source_data_array['buffersize'], 3, false); + $flag .= '0000000'; + $flag .= $source_data_array['flags']['embededinfo'] ? '1' : '0'; + $framedata .= chr(bindec($flag)); + $framedata .= getid3_lib::BigEndian2String($source_data_array['nexttagoffset'], 4, false); + } + break; + + case 'AENC': + // 4.19 AENC Audio encryption + // Owner identifier $00 + // Preview start $xx xx + // Preview length $xx xx + // Encryption info + if (! $this->IsWithinBitRange($source_data_array['previewstart'], 16, false)) { + $this->errors[] = 'Invalid Preview Start in '.$frame_name.' ('.$source_data_array['previewstart'].')'; + } elseif (! $this->IsWithinBitRange($source_data_array['previewlength'], 16, false)) { + $this->errors[] = 'Invalid Preview Length in '.$frame_name.' ('.$source_data_array['previewlength'].')'; + } else { + $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00"; + $framedata .= getid3_lib::BigEndian2String($source_data_array['previewstart'], 2, false); + $framedata .= getid3_lib::BigEndian2String($source_data_array['previewlength'], 2, false); + $framedata .= $source_data_array['encryptioninfo']; + } + break; + + case 'LINK': + // 4.20 LINK Linked information + // Frame identifier $xx xx xx xx + // URL $00 + // ID and additional data + if (! getid3_id3v2::IsValidID3v2FrameName($source_data_array['frameid'], $this->majorversion)) { + $this->errors[] = 'Invalid Frame Identifier in '.$frame_name.' ('.$source_data_array['frameid'].')'; + } elseif (! $this->IsValidURL($source_data_array['data'], true, false)) { + //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; + // probably should be an error, need to rewrite IsValidURL() to handle other encodings + $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; + } elseif ((($source_data_array['frameid'] == 'AENC') || ($source_data_array['frameid'] == 'APIC') || ($source_data_array['frameid'] == 'GEOB') || ($source_data_array['frameid'] == 'TXXX')) && ($source_data_array['additionaldata'] == '')) { + $this->errors[] = 'Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name; + } elseif (($source_data_array['frameid'] == 'USER') && (getid3_id3v2::LanguageLookup($source_data_array['additionaldata'], true) == '')) { + $this->errors[] = 'Language must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name; + } elseif (($source_data_array['frameid'] == 'PRIV') && ($source_data_array['additionaldata'] == '')) { + $this->errors[] = 'Owner Identifier must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name; + } elseif ((($source_data_array['frameid'] == 'COMM') || ($source_data_array['frameid'] == 'SYLT') || ($source_data_array['frameid'] == 'USLT')) && ((getid3_id3v2::LanguageLookup(substr($source_data_array['additionaldata'], 0, 3), true) == '') || (substr($source_data_array['additionaldata'], 3) == ''))) { + $this->errors[] = 'Language followed by Content Descriptor must be specified as additional data for Frame Identifier of '.$source_data_array['frameid'].' in '.$frame_name; + } else { + $framedata .= $source_data_array['frameid']; + $framedata .= str_replace("\x00", '', $source_data_array['data'])."\x00"; + switch ($source_data_array['frameid']) { + case 'COMM': + case 'SYLT': + case 'USLT': + case 'PRIV': + case 'USER': + case 'AENC': + case 'APIC': + case 'GEOB': + case 'TXXX': + $framedata .= $source_data_array['additionaldata']; + break; + case 'ASPI': + case 'ETCO': + case 'EQU2': + case 'MCID': + case 'MLLT': + case 'OWNE': + case 'RVA2': + case 'RVRB': + case 'SYTC': + case 'IPLS': + case 'RVAD': + case 'EQUA': + // no additional data required + break; + case 'RBUF': + if ($this->majorversion == 3) { + // no additional data required + } else { + $this->errors[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion.')'; + } + + default: + if ((substr($source_data_array['frameid'], 0, 1) == 'T') || (substr($source_data_array['frameid'], 0, 1) == 'W')) { + // no additional data required + } else { + $this->errors[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion.')'; + } + break; + } + } + break; + + case 'POSS': + // 4.21 POSS Position synchronisation frame (ID3v2.3+ only) + // Time stamp format $xx + // Position $xx (xx ...) + if (($source_data_array['timestampformat'] < 1) || ($source_data_array['timestampformat'] > 2)) { + $this->errors[] = 'Invalid Time Stamp Format in '.$frame_name.' ('.$source_data_array['timestampformat'].') (valid = 1 or 2)'; + } elseif (! $this->IsWithinBitRange($source_data_array['position'], 32, false)) { + $this->errors[] = 'Invalid Position in '.$frame_name.' ('.$source_data_array['position'].') (range = 0 to 4294967295)'; + } else { + $framedata .= chr($source_data_array['timestampformat']); + $framedata .= getid3_lib::BigEndian2String($source_data_array['position'], 4, false); + } + break; + + case 'USER': + // 4.22 USER Terms of use (ID3v2.3+ only) + // Text encoding $xx + // Language $xx xx xx + // The actual text + $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); + if (! $this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { + $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')'; + } elseif (getid3_id3v2::LanguageLookup($source_data_array['language'], true) == '') { + $this->errors[] = 'Invalid Language in '.$frame_name.' ('.$source_data_array['language'].')'; + } else { + $framedata .= chr($source_data_array['encodingid']); + $framedata .= strtolower($source_data_array['language']); + $framedata .= $source_data_array['data']; + } + break; + + case 'OWNE': + // 4.23 OWNE Ownership frame (ID3v2.3+ only) + // Text encoding $xx + // Price paid $00 + // Date of purch. + // Seller + $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); + if (! $this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { + $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')'; + } elseif (! $this->IsANumber($source_data_array['pricepaid']['value'], false)) { + $this->errors[] = 'Invalid Price Paid in '.$frame_name.' ('.$source_data_array['pricepaid']['value'].')'; + } elseif (! $this->IsValidDateStampString($source_data_array['purchasedate'])) { + $this->errors[] = 'Invalid Date Of Purchase in '.$frame_name.' ('.$source_data_array['purchasedate'].') (format = YYYYMMDD)'; + } else { + $framedata .= chr($source_data_array['encodingid']); + $framedata .= str_replace("\x00", '', $source_data_array['pricepaid']['value'])."\x00"; + $framedata .= $source_data_array['purchasedate']; + $framedata .= $source_data_array['seller']; + } + break; + + case 'COMR': + // 4.24 COMR Commercial frame (ID3v2.3+ only) + // Text encoding $xx + // Price string $00 + // Valid until + // Contact URL $00 + // Received as $xx + // Name of seller $00 (00) + // Description $00 (00) + // Picture MIME type $00 + // Seller logo + $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); + if (! $this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { + $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')'; + } elseif (! $this->IsValidDateStampString($source_data_array['pricevaliduntil'])) { + $this->errors[] = 'Invalid Valid Until date in '.$frame_name.' ('.$source_data_array['pricevaliduntil'].') (format = YYYYMMDD)'; + } elseif (! $this->IsValidURL($source_data_array['contacturl'], false, true)) { + $this->errors[] = 'Invalid Contact URL in '.$frame_name.' ('.$source_data_array['contacturl'].') (allowed schemes: http, https, ftp, mailto)'; + } elseif (! $this->ID3v2IsValidCOMRreceivedAs($source_data_array['receivedasid'])) { + $this->errors[] = 'Invalid Received As byte in '.$frame_name.' ('.$source_data_array['contacturl'].') (range = 0 to 8)'; + } elseif (! $this->IsValidMIMEstring($source_data_array['mime'])) { + $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].')'; + } else { + $framedata .= chr($source_data_array['encodingid']); + unset($pricestring); + foreach ($source_data_array['price'] as $key => $val) { + if ($this->ID3v2IsValidPriceString($key.$val['value'])) { + $pricestrings[] = $key.$val['value']; + } else { + $this->errors[] = 'Invalid Price String in '.$frame_name.' ('.$key.$val['value'].')'; + } + } + $framedata .= implode('/', $pricestrings); + $framedata .= $source_data_array['pricevaliduntil']; + $framedata .= str_replace("\x00", '', $source_data_array['contacturl'])."\x00"; + $framedata .= chr($source_data_array['receivedasid']); + $framedata .= $source_data_array['sellername'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); + $framedata .= $source_data_array['description'].getid3_id3v2::TextEncodingTerminatorLookup($source_data_array['encodingid']); + $framedata .= $source_data_array['mime']."\x00"; + $framedata .= $source_data_array['logo']; + } + break; + + case 'ENCR': + // 4.25 ENCR Encryption method registration (ID3v2.3+ only) + // Owner identifier $00 + // Method symbol $xx + // Encryption data + if (! $this->IsWithinBitRange($source_data_array['methodsymbol'], 8, false)) { + $this->errors[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['methodsymbol'].') (range = 0 to 255)'; + } else { + $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00"; + $framedata .= ord($source_data_array['methodsymbol']); + $framedata .= $source_data_array['data']; + } + break; + + case 'GRID': + // 4.26 GRID Group identification registration (ID3v2.3+ only) + // Owner identifier $00 + // Group symbol $xx + // Group dependent data + if (! $this->IsWithinBitRange($source_data_array['groupsymbol'], 8, false)) { + $this->errors[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['groupsymbol'].') (range = 0 to 255)'; + } else { + $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00"; + $framedata .= ord($source_data_array['groupsymbol']); + $framedata .= $source_data_array['data']; + } + break; + + case 'PRIV': + // 4.27 PRIV Private frame (ID3v2.3+ only) + // Owner identifier $00 + // The private data + $framedata .= str_replace("\x00", '', $source_data_array['ownerid'])."\x00"; + $framedata .= $source_data_array['data']; + break; + + case 'SIGN': + // 4.28 SIGN Signature frame (ID3v2.4+ only) + // Group symbol $xx + // Signature + if (! $this->IsWithinBitRange($source_data_array['groupsymbol'], 8, false)) { + $this->errors[] = 'Invalid Group Symbol in '.$frame_name.' ('.$source_data_array['groupsymbol'].') (range = 0 to 255)'; + } else { + $framedata .= ord($source_data_array['groupsymbol']); + $framedata .= $source_data_array['data']; + } + break; + + case 'SEEK': + // 4.29 SEEK Seek frame (ID3v2.4+ only) + // Minimum offset to next tag $xx xx xx xx + if (! $this->IsWithinBitRange($source_data_array['data'], 32, false)) { + $this->errors[] = 'Invalid Minimum Offset in '.$frame_name.' ('.$source_data_array['data'].') (range = 0 to 4294967295)'; + } else { + $framedata .= getid3_lib::BigEndian2String($source_data_array['data'], 4, false); + } + break; + + case 'ASPI': + // 4.30 ASPI Audio seek point index (ID3v2.4+ only) + // Indexed data start (S) $xx xx xx xx + // Indexed data length (L) $xx xx xx xx + // Number of index points (N) $xx xx + // Bits per index point (b) $xx + // Then for every index point the following data is included: + // Fraction at index (Fi) $xx (xx) + if (! $this->IsWithinBitRange($source_data_array['datastart'], 32, false)) { + $this->errors[] = 'Invalid Indexed Data Start in '.$frame_name.' ('.$source_data_array['datastart'].') (range = 0 to 4294967295)'; + } elseif (! $this->IsWithinBitRange($source_data_array['datalength'], 32, false)) { + $this->errors[] = 'Invalid Indexed Data Length in '.$frame_name.' ('.$source_data_array['datalength'].') (range = 0 to 4294967295)'; + } elseif (! $this->IsWithinBitRange($source_data_array['indexpoints'], 16, false)) { + $this->errors[] = 'Invalid Number Of Index Points in '.$frame_name.' ('.$source_data_array['indexpoints'].') (range = 0 to 65535)'; + } elseif (! $this->IsWithinBitRange($source_data_array['bitsperpoint'], 8, false)) { + $this->errors[] = 'Invalid Bits Per Index Point in '.$frame_name.' ('.$source_data_array['bitsperpoint'].') (range = 0 to 255)'; + } elseif ($source_data_array['indexpoints'] != count($source_data_array['indexes'])) { + $this->errors[] = 'Number Of Index Points does not match actual supplied data in '.$frame_name; + } else { + $framedata .= getid3_lib::BigEndian2String($source_data_array['datastart'], 4, false); + $framedata .= getid3_lib::BigEndian2String($source_data_array['datalength'], 4, false); + $framedata .= getid3_lib::BigEndian2String($source_data_array['indexpoints'], 2, false); + $framedata .= getid3_lib::BigEndian2String($source_data_array['bitsperpoint'], 1, false); + foreach ($source_data_array['indexes'] as $key => $val) { + $framedata .= getid3_lib::BigEndian2String($val, ceil($source_data_array['bitsperpoint'] / 8), false); + } + } + break; + + case 'RGAD': + // RGAD Replay Gain Adjustment + // http://privatewww.essex.ac.uk/~djmrob/replaygain/ + // Peak Amplitude $xx $xx $xx $xx + // Radio Replay Gain Adjustment %aaabbbcd %dddddddd + // Audiophile Replay Gain Adjustment %aaabbbcd %dddddddd + // a - name code + // b - originator code + // c - sign bit + // d - replay gain adjustment + + if (($source_data_array['track_adjustment'] > 51) || ($source_data_array['track_adjustment'] < -51)) { + $this->errors[] = 'Invalid Track Adjustment in '.$frame_name.' ('.$source_data_array['track_adjustment'].') (range = -51.0 to +51.0)'; + } elseif (($source_data_array['album_adjustment'] > 51) || ($source_data_array['album_adjustment'] < -51)) { + $this->errors[] = 'Invalid Album Adjustment in '.$frame_name.' ('.$source_data_array['album_adjustment'].') (range = -51.0 to +51.0)'; + } elseif (! $this->ID3v2IsValidRGADname($source_data_array['raw']['track_name'])) { + $this->errors[] = 'Invalid Track Name Code in '.$frame_name.' ('.$source_data_array['raw']['track_name'].') (range = 0 to 2)'; + } elseif (! $this->ID3v2IsValidRGADname($source_data_array['raw']['album_name'])) { + $this->errors[] = 'Invalid Album Name Code in '.$frame_name.' ('.$source_data_array['raw']['album_name'].') (range = 0 to 2)'; + } elseif (! $this->ID3v2IsValidRGADoriginator($source_data_array['raw']['track_originator'])) { + $this->errors[] = 'Invalid Track Originator Code in '.$frame_name.' ('.$source_data_array['raw']['track_originator'].') (range = 0 to 3)'; + } elseif (! $this->ID3v2IsValidRGADoriginator($source_data_array['raw']['album_originator'])) { + $this->errors[] = 'Invalid Album Originator Code in '.$frame_name.' ('.$source_data_array['raw']['album_originator'].') (range = 0 to 3)'; + } else { + $framedata .= getid3_lib::Float2String($source_data_array['peakamplitude'], 32); + $framedata .= getid3_lib::RGADgainString($source_data_array['raw']['track_name'], $source_data_array['raw']['track_originator'], $source_data_array['track_adjustment']); + $framedata .= getid3_lib::RGADgainString($source_data_array['raw']['album_name'], $source_data_array['raw']['album_originator'], $source_data_array['album_adjustment']); + } + break; + + default: + if ((($this->majorversion == 2) && (strlen($frame_name) != 3)) || (($this->majorversion > 2) && (strlen($frame_name) != 4))) { + $this->errors[] = 'Invalid frame name "'.$frame_name.'" for ID3v2.'.$this->majorversion; + } elseif ($frame_name[0] == 'T') { + // 4.2. T??? Text information frames + // Text encoding $xx + // Information + $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); + if (! $this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { + $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; + } else { + $framedata .= chr($source_data_array['encodingid']); + $framedata .= $source_data_array['data']; + } + } elseif ($frame_name[0] == 'W') { + // 4.3. W??? URL link frames + // URL + if (! $this->IsValidURL($source_data_array['data'], false, false)) { + //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; + // probably should be an error, need to rewrite IsValidURL() to handle other encodings + $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; + } else { + $framedata .= $source_data_array['data']; + } + } else { + $this->errors[] = $frame_name.' not yet supported in $this->GenerateID3v2FrameData()'; + } + break; + } + } + if (! empty($this->errors)) { + return false; + } + + return $framedata; + } + + public function ID3v2FrameIsAllowed($frame_name, $source_data_array) + { + static $PreviousFrames = []; + + if ($frame_name === null) { + // if the writing functions are called multiple times, the static array needs to be + // cleared - this can be done by calling $this->ID3v2FrameIsAllowed(null, '') + $PreviousFrames = []; + + return true; + } + if ($this->majorversion == 4) { + switch ($frame_name) { + case 'UFID': + case 'AENC': + case 'ENCR': + case 'GRID': + if (! isset($source_data_array['ownerid'])) { + $this->errors[] = '[ownerid] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['ownerid']; + } + break; + + case 'TXXX': + case 'WXXX': + case 'RVA2': + case 'EQU2': + case 'APIC': + case 'GEOB': + if (! isset($source_data_array['description'])) { + $this->errors[] = '[description] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['description']; + } + break; + + case 'USER': + if (! isset($source_data_array['language'])) { + $this->errors[] = '[language] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['language'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language ('.$source_data_array['language'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['language']; + } + break; + + case 'USLT': + case 'SYLT': + case 'COMM': + if (! isset($source_data_array['language'])) { + $this->errors[] = '[language] not specified for '.$frame_name; + } elseif (! isset($source_data_array['description'])) { + $this->errors[] = '[description] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description']; + } + break; + + case 'POPM': + if (! isset($source_data_array['email'])) { + $this->errors[] = '[email] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['email']; + } + break; + + case 'IPLS': + case 'MCDI': + case 'ETCO': + case 'MLLT': + case 'SYTC': + case 'RVRB': + case 'PCNT': + case 'RBUF': + case 'POSS': + case 'OWNE': + case 'SEEK': + case 'ASPI': + case 'RGAD': + if (in_array($frame_name, $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed'; + } else { + $PreviousFrames[] = $frame_name; + } + break; + + case 'LINK': + // this isn't implemented quite right (yet) - it should check the target frame data for compliance + // but right now it just allows one linked frame of each type, to be safe. + if (! isset($source_data_array['frameid'])) { + $this->errors[] = '[frameid] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')'; + } elseif (in_array($source_data_array['frameid'], $PreviousFrames)) { + // no links to singleton tags + $this->errors[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['frameid']; // only one linked tag of this type + $PreviousFrames[] = $source_data_array['frameid']; // no non-linked singleton tags of this type + } + break; + + case 'COMR': + // There may be more than one 'commercial frame' in a tag, but no two may be identical + // Checking isn't implemented at all (yet) - just assumes that it's OK. + break; + + case 'PRIV': + case 'SIGN': + if (! isset($source_data_array['ownerid'])) { + $this->errors[] = '[ownerid] not specified for '.$frame_name; + } elseif (! isset($source_data_array['data'])) { + $this->errors[] = '[data] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['ownerid'].$source_data_array['data'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID + Data ('.$source_data_array['ownerid'].' + '.$source_data_array['data'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['ownerid'].$source_data_array['data']; + } + break; + + default: + if (($frame_name[0] != 'T') && ($frame_name[0] != 'W')) { + $this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name; + } + break; + } + } elseif ($this->majorversion == 3) { + switch ($frame_name) { + case 'UFID': + case 'AENC': + case 'ENCR': + case 'GRID': + if (! isset($source_data_array['ownerid'])) { + $this->errors[] = '[ownerid] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['ownerid']; + } + break; + + case 'TXXX': + case 'WXXX': + case 'APIC': + case 'GEOB': + if (! isset($source_data_array['description'])) { + $this->errors[] = '[description] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['description']; + } + break; + + case 'USER': + if (! isset($source_data_array['language'])) { + $this->errors[] = '[language] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['language'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language ('.$source_data_array['language'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['language']; + } + break; + + case 'USLT': + case 'SYLT': + case 'COMM': + if (! isset($source_data_array['language'])) { + $this->errors[] = '[language] not specified for '.$frame_name; + } elseif (! isset($source_data_array['description'])) { + $this->errors[] = '[description] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description']; + } + break; + + case 'POPM': + if (! isset($source_data_array['email'])) { + $this->errors[] = '[email] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['email']; + } + break; + + case 'IPLS': + case 'MCDI': + case 'ETCO': + case 'MLLT': + case 'SYTC': + case 'RVAD': + case 'EQUA': + case 'RVRB': + case 'PCNT': + case 'RBUF': + case 'POSS': + case 'OWNE': + case 'RGAD': + if (in_array($frame_name, $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed'; + } else { + $PreviousFrames[] = $frame_name; + } + break; + + case 'LINK': + // this isn't implemented quite right (yet) - it should check the target frame data for compliance + // but right now it just allows one linked frame of each type, to be safe. + if (! isset($source_data_array['frameid'])) { + $this->errors[] = '[frameid] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')'; + } elseif (in_array($source_data_array['frameid'], $PreviousFrames)) { + // no links to singleton tags + $this->errors[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['frameid']; // only one linked tag of this type + $PreviousFrames[] = $source_data_array['frameid']; // no non-linked singleton tags of this type + } + break; + + case 'COMR': + // There may be more than one 'commercial frame' in a tag, but no two may be identical + // Checking isn't implemented at all (yet) - just assumes that it's OK. + break; + + case 'PRIV': + if (! isset($source_data_array['ownerid'])) { + $this->errors[] = '[ownerid] not specified for '.$frame_name; + } elseif (! isset($source_data_array['data'])) { + $this->errors[] = '[data] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['ownerid'].$source_data_array['data'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID + Data ('.$source_data_array['ownerid'].' + '.$source_data_array['data'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['ownerid'].$source_data_array['data']; + } + break; + + default: + if (($frame_name[0] != 'T') && ($frame_name[0] != 'W')) { + $this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name; + } + break; + } + } elseif ($this->majorversion == 2) { + switch ($frame_name) { + case 'UFI': + case 'CRM': + case 'CRA': + if (! isset($source_data_array['ownerid'])) { + $this->errors[] = '[ownerid] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['ownerid'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same OwnerID ('.$source_data_array['ownerid'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['ownerid']; + } + break; + + case 'TXX': + case 'WXX': + case 'PIC': + case 'GEO': + if (! isset($source_data_array['description'])) { + $this->errors[] = '[description] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['description'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Description ('.$source_data_array['description'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['description']; + } + break; + + case 'ULT': + case 'SLT': + case 'COM': + if (! isset($source_data_array['language'])) { + $this->errors[] = '[language] not specified for '.$frame_name; + } elseif (! isset($source_data_array['description'])) { + $this->errors[] = '[description] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['language'].$source_data_array['description'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Language + Description ('.$source_data_array['language'].' + '.$source_data_array['description'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['language'].$source_data_array['description']; + } + break; + + case 'POP': + if (! isset($source_data_array['email'])) { + $this->errors[] = '[email] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['email'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same Email ('.$source_data_array['email'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['email']; + } + break; + + case 'IPL': + case 'MCI': + case 'ETC': + case 'MLL': + case 'STC': + case 'RVA': + case 'EQU': + case 'REV': + case 'CNT': + case 'BUF': + if (in_array($frame_name, $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed'; + } else { + $PreviousFrames[] = $frame_name; + } + break; + + case 'LNK': + // this isn't implemented quite right (yet) - it should check the target frame data for compliance + // but right now it just allows one linked frame of each type, to be safe. + if (! isset($source_data_array['frameid'])) { + $this->errors[] = '[frameid] not specified for '.$frame_name; + } elseif (in_array($frame_name.$source_data_array['frameid'], $PreviousFrames)) { + $this->errors[] = 'Only one '.$frame_name.' tag allowed with the same FrameID ('.$source_data_array['frameid'].')'; + } elseif (in_array($source_data_array['frameid'], $PreviousFrames)) { + // no links to singleton tags + $this->errors[] = 'Cannot specify a '.$frame_name.' tag to a singleton tag that already exists ('.$source_data_array['frameid'].')'; + } else { + $PreviousFrames[] = $frame_name.$source_data_array['frameid']; // only one linked tag of this type + $PreviousFrames[] = $source_data_array['frameid']; // no non-linked singleton tags of this type + } + break; + + default: + if (($frame_name[0] != 'T') && ($frame_name[0] != 'W')) { + $this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name; + } + break; + } + } + + if (! empty($this->errors)) { + return false; + } + + return true; + } + + public function GenerateID3v2Tag($noerrorsonly = true) + { + $this->ID3v2FrameIsAllowed(null, ''); // clear static array in case this isn't the first call to $this->GenerateID3v2Tag() + + $tagstring = ''; + if (is_array($this->tag_data)) { + foreach ($this->tag_data as $frame_name => $frame_rawinputdata) { + foreach ($frame_rawinputdata as $irrelevantindex => $source_data_array) { + if (getid3_id3v2::IsValidID3v2FrameName($frame_name, $this->majorversion)) { + unset($frame_length); + unset($frame_flags); + $frame_data = false; + if ($this->ID3v2FrameIsAllowed($frame_name, $source_data_array)) { + if (array_key_exists('description', $source_data_array) && array_key_exists('encodingid', $source_data_array) && array_key_exists('encoding', $this->tag_data)) { + $source_data_array['description'] = getid3_lib::iconv_fallback($this->tag_data['encoding'], $source_data_array['encoding'], $source_data_array['description']); + } + if ($frame_data = $this->GenerateID3v2FrameData($frame_name, $source_data_array)) { + $FrameUnsynchronisation = false; + if ($this->majorversion >= 4) { + // frame-level unsynchronisation + $unsynchdata = $frame_data; + if ($this->id3v2_use_unsynchronisation) { + $unsynchdata = $this->Unsynchronise($frame_data); + } + if (strlen($unsynchdata) != strlen($frame_data)) { + // unsynchronisation needed + $FrameUnsynchronisation = true; + $frame_data = $unsynchdata; + if (isset($TagUnsynchronisation) && $TagUnsynchronisation === false) { + // only set to true if ALL frames are unsynchronised + } else { + $TagUnsynchronisation = true; + } + } else { + if (isset($TagUnsynchronisation)) { + $TagUnsynchronisation = false; + } + } + unset($unsynchdata); + + $frame_length = getid3_lib::BigEndian2String(strlen($frame_data), 4, true); + } else { + $frame_length = getid3_lib::BigEndian2String(strlen($frame_data), 4, false); + } + $frame_flags = $this->GenerateID3v2FrameFlags($this->ID3v2FrameFlagsLookupTagAlter($frame_name), $this->ID3v2FrameFlagsLookupFileAlter($frame_name), false, false, false, false, $FrameUnsynchronisation, false); + } + } else { + $this->errors[] = 'Frame "'.$frame_name.'" is NOT allowed'; + } + if ($frame_data === false) { + $this->errors[] = '$this->GenerateID3v2FrameData() failed for "'.$frame_name.'"'; + if ($noerrorsonly) { + return false; + } else { + unset($frame_name); + } + } + } else { + // ignore any invalid frame names, including 'title', 'header', etc + $this->warnings[] = 'Ignoring invalid ID3v2 frame type: "'.$frame_name.'"'; + unset($frame_name); + unset($frame_length); + unset($frame_flags); + unset($frame_data); + } + if (isset($frame_name) && isset($frame_length) && isset($frame_flags) && isset($frame_data)) { + $tagstring .= $frame_name.$frame_length.$frame_flags.$frame_data; + } + } + } + + if (! isset($TagUnsynchronisation)) { + $TagUnsynchronisation = false; + } + if (($this->majorversion <= 3) && $this->id3v2_use_unsynchronisation) { + // tag-level unsynchronisation + $unsynchdata = $this->Unsynchronise($tagstring); + if (strlen($unsynchdata) != strlen($tagstring)) { + // unsynchronisation needed + $TagUnsynchronisation = true; + $tagstring = $unsynchdata; + } + } + + while ($this->paddedlength < (strlen($tagstring) + getid3_id3v2::ID3v2HeaderLength($this->majorversion))) { + $this->paddedlength += 1024; + } + + $footer = false; // ID3v2 footers not yet supported in getID3() + if (! $footer && ($this->paddedlength > (strlen($tagstring) + getid3_id3v2::ID3v2HeaderLength($this->majorversion)))) { + // pad up to $paddedlength bytes if unpadded tag is shorter than $paddedlength + // "Furthermore it MUST NOT have any padding when a tag footer is added to the tag." + if (($this->paddedlength - strlen($tagstring) - getid3_id3v2::ID3v2HeaderLength($this->majorversion)) > 0) { + $tagstring .= str_repeat("\x00", $this->paddedlength - strlen($tagstring) - getid3_id3v2::ID3v2HeaderLength($this->majorversion)); + } + } + if ($this->id3v2_use_unsynchronisation && (substr($tagstring, strlen($tagstring) - 1, 1) == "\xFF")) { + // special unsynchronisation case: + // if last byte == $FF then appended a $00 + $TagUnsynchronisation = true; + $tagstring .= "\x00"; + } + + $tagheader = 'ID3'; + $tagheader .= chr($this->majorversion); + $tagheader .= chr($this->minorversion); + $tagheader .= $this->GenerateID3v2TagFlags(['unsynchronisation'=>$TagUnsynchronisation]); + $tagheader .= getid3_lib::BigEndian2String(strlen($tagstring), 4, true); + + return $tagheader.$tagstring; + } + $this->errors[] = 'tag_data is not an array in GenerateID3v2Tag()'; + + return false; + } + + public function ID3v2IsValidPriceString($pricestring) + { + if (getid3_id3v2::LanguageLookup(substr($pricestring, 0, 3), true) == '') { + return false; + } elseif (! $this->IsANumber(substr($pricestring, 3), true)) { + return false; + } + + return true; + } + + public function ID3v2FrameFlagsLookupTagAlter($framename) + { + // unfinished + switch ($framename) { + case 'RGAD': + $allow = true; + default: + $allow = false; + break; + } + + return $allow; + } + + public function ID3v2FrameFlagsLookupFileAlter($framename) + { + // unfinished + switch ($framename) { + case 'RGAD': + return false; + break; + + default: + return false; + break; + } + } + + public function ID3v2IsValidETCOevent($eventid) + { + if (($eventid < 0) || ($eventid > 0xFF)) { + // outside range of 1 byte + return false; + } elseif (($eventid >= 0xF0) && ($eventid <= 0xFC)) { + // reserved for future use + return false; + } elseif (($eventid >= 0x17) && ($eventid <= 0xDF)) { + // reserved for future use + return false; + } elseif (($eventid >= 0x0E) && ($eventid <= 0x16) && ($this->majorversion == 2)) { + // not defined in ID3v2.2 + return false; + } elseif (($eventid >= 0x15) && ($eventid <= 0x16) && ($this->majorversion == 3)) { + // not defined in ID3v2.3 + return false; + } + + return true; + } + + public function ID3v2IsValidSYLTtype($contenttype) + { + if (($contenttype >= 0) && ($contenttype <= 8) && ($this->majorversion == 4)) { + return true; + } elseif (($contenttype >= 0) && ($contenttype <= 6) && ($this->majorversion == 3)) { + return true; + } + + return false; + } + + public function ID3v2IsValidRVA2channeltype($channeltype) + { + if (($channeltype >= 0) && ($channeltype <= 8) && ($this->majorversion == 4)) { + return true; + } + + return false; + } + + public function ID3v2IsValidAPICpicturetype($picturetype) + { + if (($picturetype >= 0) && ($picturetype <= 0x14) && ($this->majorversion >= 2) && ($this->majorversion <= 4)) { + return true; + } + + return false; + } + + public function ID3v2IsValidAPICimageformat($imageformat) + { + if ($imageformat == '-->') { + return true; + } elseif ($this->majorversion == 2) { + if ((strlen($imageformat) == 3) && ($imageformat == strtoupper($imageformat))) { + return true; + } + } elseif (($this->majorversion == 3) || ($this->majorversion == 4)) { + if ($this->IsValidMIMEstring($imageformat)) { + return true; + } + } + + return false; + } + + public function ID3v2IsValidCOMRreceivedAs($receivedas) + { + if (($this->majorversion >= 3) && ($receivedas >= 0) && ($receivedas <= 8)) { + return true; + } + + return false; + } + + public static function ID3v2IsValidRGADname($RGADname) + { + if (($RGADname >= 0) && ($RGADname <= 2)) { + return true; + } + + return false; + } + + public static function ID3v2IsValidRGADoriginator($RGADoriginator) + { + if (($RGADoriginator >= 0) && ($RGADoriginator <= 3)) { + return true; + } + + return false; + } + + public function ID3v2IsValidTextEncoding($textencodingbyte) + { + // 0 = ISO-8859-1 + // 1 = UTF-16 with BOM + // 2 = UTF-16BE without BOM + // 3 = UTF-8 + static $ID3v2IsValidTextEncoding_cache = [ + 2 => [true, true], // ID3v2.2 - allow 0=ISO-8859-1, 1=UTF-16 + 3 => [true, true], // ID3v2.3 - allow 0=ISO-8859-1, 1=UTF-16 + 4 => [true, true, true, true], // ID3v2.4 - allow 0=ISO-8859-1, 1=UTF-16, 2=UTF-16BE, 3=UTF-8 + ]; + + return isset($ID3v2IsValidTextEncoding_cache[$this->majorversion][$textencodingbyte]); + } + + public static function Unsynchronise($data) + { + // Whenever a false synchronisation is found within the tag, one zeroed + // byte is inserted after the first false synchronisation byte. The + // format of a correct sync that should be altered by ID3 encoders is as + // follows: + // %11111111 111xxxxx + // And should be replaced with: + // %11111111 00000000 111xxxxx + // This has the side effect that all $FF 00 combinations have to be + // altered, so they won't be affected by the decoding process. Therefore + // all the $FF 00 combinations have to be replaced with the $FF 00 00 + // combination during the unsynchronisation. + + $data = str_replace("\xFF\x00", "\xFF\x00\x00", $data); + $unsyncheddata = ''; + $datalength = strlen($data); + for ($i = 0; $i < $datalength; $i++) { + $thischar = $data[$i]; + $unsyncheddata .= $thischar; + if ($thischar == "\xFF") { + $nextchar = ord($data[$i + 1]); + if (($nextchar & 0xE0) == 0xE0) { + // previous byte = 11111111, this byte = 111????? + $unsyncheddata .= "\x00"; + } + } + } + + return $unsyncheddata; + } + + public function is_hash($var) + { + // written by dev-nullØchristophe*vg + // taken from http://www.php.net/manual/en/function.array-merge-recursive.php + if (is_array($var)) { + $keys = array_keys($var); + $all_num = true; + for ($i = 0; $i < count($keys); $i++) { + if (is_string($keys[$i])) { + return true; + } + } + } + + return false; + } + + public function array_join_merge($arr1, $arr2) + { + // written by dev-nullØchristophe*vg + // taken from http://www.php.net/manual/en/function.array-merge-recursive.php + if (is_array($arr1) && is_array($arr2)) { + // the same -> merge + $new_array = []; + + if ($this->is_hash($arr1) && $this->is_hash($arr2)) { + // hashes -> merge based on keys + $keys = array_merge(array_keys($arr1), array_keys($arr2)); + foreach ($keys as $key) { + $new_array[$key] = $this->array_join_merge((isset($arr1[$key]) ? $arr1[$key] : ''), (isset($arr2[$key]) ? $arr2[$key] : '')); + } + } else { + // two real arrays -> merge + $new_array = array_reverse(array_unique(array_reverse(array_merge($arr1, $arr2)))); + } + + return $new_array; + } else { + // not the same ... take new one if defined, else the old one stays + return $arr2 ? $arr2 : $arr1; + } + } + + public static function IsValidMIMEstring($mimestring) + { + return preg_match('#^.+/.+$#', $mimestring); + } + + public static function IsWithinBitRange($number, $maxbits, $signed = false) + { + if ($signed) { + if (($number > (0 - pow(2, $maxbits - 1))) && ($number <= pow(2, $maxbits - 1))) { + return true; + } + } else { + if (($number >= 0) && ($number <= pow(2, $maxbits))) { + return true; + } + } + + return false; + } + + public static function IsValidEmail($email) + { + if (function_exists('filter_var')) { + return filter_var($email, FILTER_VALIDATE_EMAIL); + } + // VERY crude email validation + return preg_match('#^[^ ]+@[a-z\\-\\.]+\\.[a-z]{2,}$#', $email); + } + + public static function IsValidURL($url, $allowUserPass = false) + { + if ($url == '') { + return false; + } + if ($allowUserPass !== true) { + if (strstr($url, '@')) { + // in the format http://user:pass@example.com or http://user@example.com + // but could easily be somebody incorrectly entering an email address in place of a URL + return false; + } + } + // 2016-06-08: relax URL checking to avoid falsely rejecting valid URLs, leave URL validation to the user + // http://www.getid3.org/phpBB3/viewtopic.php?t=1926 + return true; + /* + if ($parts = $this->safe_parse_url($url)) { + if (($parts['scheme'] != 'http') && ($parts['scheme'] != 'https') && ($parts['scheme'] != 'ftp') && ($parts['scheme'] != 'gopher')) { + return false; + } elseif (!preg_match('#^[[:alnum:]]([-.]?[0-9a-z])*\\.[a-z]{2,3}$#i', $parts['host'], $regs) && !preg_match('#^[0-9]{1,3}(\\.[0-9]{1,3}){3}$#', $parts['host'])) { + return false; + } elseif (!preg_match('#^([[:alnum:]-]|[\\_])*$#i', $parts['user'], $regs)) { + return false; + } elseif (!preg_match('#^([[:alnum:]-]|[\\_])*$#i', $parts['pass'], $regs)) { + return false; + } elseif (!preg_match('#^[[:alnum:]/_\\.@~-]*$#i', $parts['path'], $regs)) { + return false; + } elseif (!empty($parts['query']) && !preg_match('#^[[:alnum:]?&=+:;_()%\\#/,\\.-]*$#i', $parts['query'], $regs)) { + return false; + } else { + return true; + } + } + return false; + */ + } + + public static function safe_parse_url($url) + { + $parts = @parse_url($url); + $parts['scheme'] = (isset($parts['scheme']) ? $parts['scheme'] : ''); + $parts['host'] = (isset($parts['host']) ? $parts['host'] : ''); + $parts['user'] = (isset($parts['user']) ? $parts['user'] : ''); + $parts['pass'] = (isset($parts['pass']) ? $parts['pass'] : ''); + $parts['path'] = (isset($parts['path']) ? $parts['path'] : ''); + $parts['query'] = (isset($parts['query']) ? $parts['query'] : ''); + + return $parts; + } + + public static function ID3v2ShortFrameNameLookup($majorversion, $long_description) + { + $long_description = str_replace(' ', '_', strtolower(trim($long_description))); + static $ID3v2ShortFrameNameLookup = []; + if (empty($ID3v2ShortFrameNameLookup)) { + + // The following are unique to ID3v2.2 + $ID3v2ShortFrameNameLookup[2]['recommended_buffer_size'] = 'BUF'; + $ID3v2ShortFrameNameLookup[2]['comment'] = 'COM'; + $ID3v2ShortFrameNameLookup[2]['audio_encryption'] = 'CRA'; + $ID3v2ShortFrameNameLookup[2]['encrypted_meta_frame'] = 'CRM'; + $ID3v2ShortFrameNameLookup[2]['equalisation'] = 'EQU'; + $ID3v2ShortFrameNameLookup[2]['event_timing_codes'] = 'ETC'; + $ID3v2ShortFrameNameLookup[2]['general_encapsulated_object'] = 'GEO'; + $ID3v2ShortFrameNameLookup[2]['involved_people_list'] = 'IPL'; + $ID3v2ShortFrameNameLookup[2]['linked_information'] = 'LNK'; + $ID3v2ShortFrameNameLookup[2]['music_cd_identifier'] = 'MCI'; + $ID3v2ShortFrameNameLookup[2]['mpeg_location_lookup_table'] = 'MLL'; + $ID3v2ShortFrameNameLookup[2]['attached_picture'] = 'PIC'; + $ID3v2ShortFrameNameLookup[2]['popularimeter'] = 'POP'; + $ID3v2ShortFrameNameLookup[2]['reverb'] = 'REV'; + $ID3v2ShortFrameNameLookup[2]['relative_volume_adjustment'] = 'RVA'; + $ID3v2ShortFrameNameLookup[2]['synchronised_lyric'] = 'SLT'; + $ID3v2ShortFrameNameLookup[2]['synchronised_tempo_codes'] = 'STC'; + $ID3v2ShortFrameNameLookup[2]['album'] = 'TAL'; + $ID3v2ShortFrameNameLookup[2]['beats_per_minute'] = 'TBP'; + $ID3v2ShortFrameNameLookup[2]['bpm'] = 'TBP'; + $ID3v2ShortFrameNameLookup[2]['composer'] = 'TCM'; + $ID3v2ShortFrameNameLookup[2]['genre'] = 'TCO'; + $ID3v2ShortFrameNameLookup[2]['part_of_a_compilation'] = 'TCP'; + $ID3v2ShortFrameNameLookup[2]['copyright_message'] = 'TCR'; + $ID3v2ShortFrameNameLookup[2]['date'] = 'TDA'; + $ID3v2ShortFrameNameLookup[2]['playlist_delay'] = 'TDY'; + $ID3v2ShortFrameNameLookup[2]['encoded_by'] = 'TEN'; + $ID3v2ShortFrameNameLookup[2]['file_type'] = 'TFT'; + $ID3v2ShortFrameNameLookup[2]['time'] = 'TIM'; + $ID3v2ShortFrameNameLookup[2]['initial_key'] = 'TKE'; + $ID3v2ShortFrameNameLookup[2]['language'] = 'TLA'; + $ID3v2ShortFrameNameLookup[2]['length'] = 'TLE'; + $ID3v2ShortFrameNameLookup[2]['media_type'] = 'TMT'; + $ID3v2ShortFrameNameLookup[2]['original_artist'] = 'TOA'; + $ID3v2ShortFrameNameLookup[2]['original_filename'] = 'TOF'; + $ID3v2ShortFrameNameLookup[2]['original_lyricist'] = 'TOL'; + $ID3v2ShortFrameNameLookup[2]['original_year'] = 'TOR'; + $ID3v2ShortFrameNameLookup[2]['original_album'] = 'TOT'; + $ID3v2ShortFrameNameLookup[2]['artist'] = 'TP1'; + $ID3v2ShortFrameNameLookup[2]['band'] = 'TP2'; + $ID3v2ShortFrameNameLookup[2]['conductor'] = 'TP3'; + $ID3v2ShortFrameNameLookup[2]['remixer'] = 'TP4'; + $ID3v2ShortFrameNameLookup[2]['part_of_a_set'] = 'TPA'; + $ID3v2ShortFrameNameLookup[2]['publisher'] = 'TPB'; + $ID3v2ShortFrameNameLookup[2]['isrc'] = 'TRC'; + $ID3v2ShortFrameNameLookup[2]['recording_dates'] = 'TRD'; + $ID3v2ShortFrameNameLookup[2]['tracknumber'] = 'TRK'; + $ID3v2ShortFrameNameLookup[2]['track_number'] = 'TRK'; + $ID3v2ShortFrameNameLookup[2]['album_artist_sort_order'] = 'TS2'; + $ID3v2ShortFrameNameLookup[2]['album_sort_order'] = 'TSA'; + $ID3v2ShortFrameNameLookup[2]['composer_sort_order'] = 'TSC'; + $ID3v2ShortFrameNameLookup[2]['size'] = 'TSI'; + $ID3v2ShortFrameNameLookup[2]['performer_sort_order'] = 'TSP'; + $ID3v2ShortFrameNameLookup[2]['encoder_settings'] = 'TSS'; + $ID3v2ShortFrameNameLookup[2]['title_sort_order'] = 'TST'; + $ID3v2ShortFrameNameLookup[2]['content_group_description'] = 'TT1'; + $ID3v2ShortFrameNameLookup[2]['title'] = 'TT2'; + $ID3v2ShortFrameNameLookup[2]['subtitle'] = 'TT3'; + $ID3v2ShortFrameNameLookup[2]['lyricist'] = 'TXT'; + $ID3v2ShortFrameNameLookup[2]['text'] = 'TXX'; + $ID3v2ShortFrameNameLookup[2]['year'] = 'TYE'; + $ID3v2ShortFrameNameLookup[2]['unique_file_identifier'] = 'UFI'; + $ID3v2ShortFrameNameLookup[2]['unsychronised_lyric'] = 'ULT'; + $ID3v2ShortFrameNameLookup[2]['url_file'] = 'WAF'; + $ID3v2ShortFrameNameLookup[2]['url_artist'] = 'WAR'; + $ID3v2ShortFrameNameLookup[2]['url_source'] = 'WAS'; + $ID3v2ShortFrameNameLookup[2]['commercial_information'] = 'WCM'; + $ID3v2ShortFrameNameLookup[2]['copyright'] = 'WCP'; + $ID3v2ShortFrameNameLookup[2]['url_publisher'] = 'WPB'; + $ID3v2ShortFrameNameLookup[2]['url_user'] = 'WXX'; + + // The following are common to ID3v2.3 and ID3v2.4 + $ID3v2ShortFrameNameLookup[3]['audio_encryption'] = 'AENC'; + $ID3v2ShortFrameNameLookup[3]['attached_picture'] = 'APIC'; + $ID3v2ShortFrameNameLookup[3]['picture'] = 'APIC'; + $ID3v2ShortFrameNameLookup[3]['comment'] = 'COMM'; + $ID3v2ShortFrameNameLookup[3]['commercial_frame'] = 'COMR'; + $ID3v2ShortFrameNameLookup[3]['encryption_method_registration'] = 'ENCR'; + $ID3v2ShortFrameNameLookup[3]['event_timing_codes'] = 'ETCO'; + $ID3v2ShortFrameNameLookup[3]['general_encapsulated_object'] = 'GEOB'; + $ID3v2ShortFrameNameLookup[3]['group_identification_registration'] = 'GRID'; + $ID3v2ShortFrameNameLookup[3]['linked_information'] = 'LINK'; + $ID3v2ShortFrameNameLookup[3]['music_cd_identifier'] = 'MCDI'; + $ID3v2ShortFrameNameLookup[3]['mpeg_location_lookup_table'] = 'MLLT'; + $ID3v2ShortFrameNameLookup[3]['ownership_frame'] = 'OWNE'; + $ID3v2ShortFrameNameLookup[3]['play_counter'] = 'PCNT'; + $ID3v2ShortFrameNameLookup[3]['popularimeter'] = 'POPM'; + $ID3v2ShortFrameNameLookup[3]['position_synchronisation_frame'] = 'POSS'; + $ID3v2ShortFrameNameLookup[3]['private_frame'] = 'PRIV'; + $ID3v2ShortFrameNameLookup[3]['recommended_buffer_size'] = 'RBUF'; + $ID3v2ShortFrameNameLookup[3]['replay_gain_adjustment'] = 'RGAD'; + $ID3v2ShortFrameNameLookup[3]['reverb'] = 'RVRB'; + $ID3v2ShortFrameNameLookup[3]['synchronised_lyric'] = 'SYLT'; + $ID3v2ShortFrameNameLookup[3]['synchronised_tempo_codes'] = 'SYTC'; + $ID3v2ShortFrameNameLookup[3]['album'] = 'TALB'; + $ID3v2ShortFrameNameLookup[3]['beats_per_minute'] = 'TBPM'; + $ID3v2ShortFrameNameLookup[3]['bpm'] = 'TBPM'; + $ID3v2ShortFrameNameLookup[3]['part_of_a_compilation'] = 'TCMP'; + $ID3v2ShortFrameNameLookup[3]['composer'] = 'TCOM'; + $ID3v2ShortFrameNameLookup[3]['genre'] = 'TCON'; + $ID3v2ShortFrameNameLookup[3]['copyright_message'] = 'TCOP'; + $ID3v2ShortFrameNameLookup[3]['playlist_delay'] = 'TDLY'; + $ID3v2ShortFrameNameLookup[3]['encoded_by'] = 'TENC'; + $ID3v2ShortFrameNameLookup[3]['lyricist'] = 'TEXT'; + $ID3v2ShortFrameNameLookup[3]['file_type'] = 'TFLT'; + $ID3v2ShortFrameNameLookup[3]['content_group_description'] = 'TIT1'; + $ID3v2ShortFrameNameLookup[3]['title'] = 'TIT2'; + $ID3v2ShortFrameNameLookup[3]['subtitle'] = 'TIT3'; + $ID3v2ShortFrameNameLookup[3]['initial_key'] = 'TKEY'; + $ID3v2ShortFrameNameLookup[3]['language'] = 'TLAN'; + $ID3v2ShortFrameNameLookup[3]['length'] = 'TLEN'; + $ID3v2ShortFrameNameLookup[3]['media_type'] = 'TMED'; + $ID3v2ShortFrameNameLookup[3]['original_album'] = 'TOAL'; + $ID3v2ShortFrameNameLookup[3]['original_filename'] = 'TOFN'; + $ID3v2ShortFrameNameLookup[3]['original_lyricist'] = 'TOLY'; + $ID3v2ShortFrameNameLookup[3]['original_artist'] = 'TOPE'; + $ID3v2ShortFrameNameLookup[3]['file_owner'] = 'TOWN'; + $ID3v2ShortFrameNameLookup[3]['artist'] = 'TPE1'; + $ID3v2ShortFrameNameLookup[3]['band'] = 'TPE2'; + $ID3v2ShortFrameNameLookup[3]['conductor'] = 'TPE3'; + $ID3v2ShortFrameNameLookup[3]['remixer'] = 'TPE4'; + $ID3v2ShortFrameNameLookup[3]['part_of_a_set'] = 'TPOS'; + $ID3v2ShortFrameNameLookup[3]['publisher'] = 'TPUB'; + $ID3v2ShortFrameNameLookup[3]['tracknumber'] = 'TRCK'; + $ID3v2ShortFrameNameLookup[3]['track_number'] = 'TRCK'; + $ID3v2ShortFrameNameLookup[3]['internet_radio_station_name'] = 'TRSN'; + $ID3v2ShortFrameNameLookup[3]['internet_radio_station_owner'] = 'TRSO'; + $ID3v2ShortFrameNameLookup[3]['album_artist_sort_order'] = 'TSO2'; + $ID3v2ShortFrameNameLookup[3]['album_sort_order'] = 'TSOA'; + $ID3v2ShortFrameNameLookup[3]['composer_sort_order'] = 'TSOC'; + $ID3v2ShortFrameNameLookup[3]['performer_sort_order'] = 'TSOP'; + $ID3v2ShortFrameNameLookup[3]['title_sort_order'] = 'TSOT'; + $ID3v2ShortFrameNameLookup[3]['isrc'] = 'TSRC'; + $ID3v2ShortFrameNameLookup[3]['encoder_settings'] = 'TSSE'; + $ID3v2ShortFrameNameLookup[3]['text'] = 'TXXX'; + $ID3v2ShortFrameNameLookup[3]['unique_file_identifier'] = 'UFID'; + $ID3v2ShortFrameNameLookup[3]['terms_of_use'] = 'USER'; + $ID3v2ShortFrameNameLookup[3]['unsychronised_lyric'] = 'USLT'; + $ID3v2ShortFrameNameLookup[3]['commercial_information'] = 'WCOM'; + $ID3v2ShortFrameNameLookup[3]['copyright'] = 'WCOP'; + $ID3v2ShortFrameNameLookup[3]['url_file'] = 'WOAF'; + $ID3v2ShortFrameNameLookup[3]['url_artist'] = 'WOAR'; + $ID3v2ShortFrameNameLookup[3]['url_source'] = 'WOAS'; + $ID3v2ShortFrameNameLookup[3]['url_station'] = 'WORS'; + $ID3v2ShortFrameNameLookup[3]['url_payment'] = 'WPAY'; + $ID3v2ShortFrameNameLookup[3]['url_publisher'] = 'WPUB'; + $ID3v2ShortFrameNameLookup[3]['url_user'] = 'WXXX'; + + // The above are common to ID3v2.3 and ID3v2.4 + // so copy them to ID3v2.4 before adding specifics for 2.3 and 2.4 + $ID3v2ShortFrameNameLookup[4] = $ID3v2ShortFrameNameLookup[3]; + + // The following are unique to ID3v2.3 + $ID3v2ShortFrameNameLookup[3]['equalisation'] = 'EQUA'; + $ID3v2ShortFrameNameLookup[3]['involved_people_list'] = 'IPLS'; + $ID3v2ShortFrameNameLookup[3]['relative_volume_adjustment'] = 'RVAD'; + $ID3v2ShortFrameNameLookup[3]['date'] = 'TDAT'; + $ID3v2ShortFrameNameLookup[3]['time'] = 'TIME'; + $ID3v2ShortFrameNameLookup[3]['original_year'] = 'TORY'; + $ID3v2ShortFrameNameLookup[3]['recording_dates'] = 'TRDA'; + $ID3v2ShortFrameNameLookup[3]['size'] = 'TSIZ'; + $ID3v2ShortFrameNameLookup[3]['year'] = 'TYER'; + + // The following are unique to ID3v2.4 + $ID3v2ShortFrameNameLookup[4]['audio_seek_point_index'] = 'ASPI'; + $ID3v2ShortFrameNameLookup[4]['equalisation'] = 'EQU2'; + $ID3v2ShortFrameNameLookup[4]['relative_volume_adjustment'] = 'RVA2'; + $ID3v2ShortFrameNameLookup[4]['seek_frame'] = 'SEEK'; + $ID3v2ShortFrameNameLookup[4]['signature_frame'] = 'SIGN'; + $ID3v2ShortFrameNameLookup[4]['encoding_time'] = 'TDEN'; + $ID3v2ShortFrameNameLookup[4]['original_release_time'] = 'TDOR'; + $ID3v2ShortFrameNameLookup[4]['recording_time'] = 'TDRC'; + $ID3v2ShortFrameNameLookup[4]['release_time'] = 'TDRL'; + $ID3v2ShortFrameNameLookup[4]['tagging_time'] = 'TDTG'; + $ID3v2ShortFrameNameLookup[4]['involved_people_list'] = 'TIPL'; + $ID3v2ShortFrameNameLookup[4]['musician_credits_list'] = 'TMCL'; + $ID3v2ShortFrameNameLookup[4]['mood'] = 'TMOO'; + $ID3v2ShortFrameNameLookup[4]['produced_notice'] = 'TPRO'; + $ID3v2ShortFrameNameLookup[4]['album_sort_order'] = 'TSOA'; + $ID3v2ShortFrameNameLookup[4]['performer_sort_order'] = 'TSOP'; + $ID3v2ShortFrameNameLookup[4]['title_sort_order'] = 'TSOT'; + $ID3v2ShortFrameNameLookup[4]['set_subtitle'] = 'TSST'; + } + + return isset($ID3v2ShortFrameNameLookup[$majorversion][strtolower($long_description)]) ? $ID3v2ShortFrameNameLookup[$majorversion][strtolower($long_description)] : ''; + } } - diff --git a/app/Library/getid3/getid3/write.lyrics3.php b/app/Library/getid3/getid3/write.lyrics3.php index 12275f49..cc316084 100644 --- a/app/Library/getid3/getid3/write.lyrics3.php +++ b/app/Library/getid3/getid3/write.lyrics3.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,59 +15,61 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_write_lyrics3 { - public $filename; - public $tag_data; - //public $lyrics3_version = 2; // 1 or 2 - public $warnings = array(); // any non-critical errors will be stored here - public $errors = array(); // any critical errors will be stored here + public $filename; + public $tag_data; + //public $lyrics3_version = 2; // 1 or 2 + public $warnings = []; // any non-critical errors will be stored here + public $errors = []; // any critical errors will be stored here - public function __construct() { - return true; - } + public function __construct() + { + return true; + } - public function WriteLyrics3() { - $this->errors[] = 'WriteLyrics3() not yet functional - cannot write Lyrics3'; - return false; - } - public function DeleteLyrics3() { - // Initialize getID3 engine - $getID3 = new getID3; - $ThisFileInfo = $getID3->analyze($this->filename); - if (isset($ThisFileInfo['lyrics3']['tag_offset_start']) && isset($ThisFileInfo['lyrics3']['tag_offset_end'])) { - if (is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'a+b'))) { + public function WriteLyrics3() + { + $this->errors[] = 'WriteLyrics3() not yet functional - cannot write Lyrics3'; - flock($fp, LOCK_EX); - $oldignoreuserabort = ignore_user_abort(true); + return false; + } - fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_end']); - $DataAfterLyrics3 = ''; - if ($ThisFileInfo['filesize'] > $ThisFileInfo['lyrics3']['tag_offset_end']) { - $DataAfterLyrics3 = fread($fp, $ThisFileInfo['filesize'] - $ThisFileInfo['lyrics3']['tag_offset_end']); - } + public function DeleteLyrics3() + { + // Initialize getID3 engine + $getID3 = new getID3; + $ThisFileInfo = $getID3->analyze($this->filename); + if (isset($ThisFileInfo['lyrics3']['tag_offset_start']) && isset($ThisFileInfo['lyrics3']['tag_offset_end'])) { + if (is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'a+b'))) { + flock($fp, LOCK_EX); + $oldignoreuserabort = ignore_user_abort(true); - ftruncate($fp, $ThisFileInfo['lyrics3']['tag_offset_start']); + fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_end']); + $DataAfterLyrics3 = ''; + if ($ThisFileInfo['filesize'] > $ThisFileInfo['lyrics3']['tag_offset_end']) { + $DataAfterLyrics3 = fread($fp, $ThisFileInfo['filesize'] - $ThisFileInfo['lyrics3']['tag_offset_end']); + } - if (!empty($DataAfterLyrics3)) { - fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_start']); - fwrite($fp, $DataAfterLyrics3, strlen($DataAfterLyrics3)); - } + ftruncate($fp, $ThisFileInfo['lyrics3']['tag_offset_start']); - flock($fp, LOCK_UN); - fclose($fp); - ignore_user_abort($oldignoreuserabort); + if (! empty($DataAfterLyrics3)) { + fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_start']); + fwrite($fp, $DataAfterLyrics3, strlen($DataAfterLyrics3)); + } - return true; + flock($fp, LOCK_UN); + fclose($fp); + ignore_user_abort($oldignoreuserabort); - } else { - $this->errors[] = 'Cannot fopen('.$this->filename.', "a+b")'; - return false; - } - } - // no Lyrics3 present - return true; - } + return true; + } else { + $this->errors[] = 'Cannot fopen('.$this->filename.', "a+b")'; + return false; + } + } + // no Lyrics3 present + return true; + } } diff --git a/app/Library/getid3/getid3/write.metaflac.php b/app/Library/getid3/getid3/write.metaflac.php index 186e2c17..068fe59a 100644 --- a/app/Library/getid3/getid3/write.metaflac.php +++ b/app/Library/getid3/getid3/write.metaflac.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,149 +15,142 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_write_metaflac { + public $filename; + public $tag_data; + public $warnings = []; // any non-critical errors will be stored here + public $errors = []; // any critical errors will be stored here - public $filename; - public $tag_data; - public $warnings = array(); // any non-critical errors will be stored here - public $errors = array(); // any critical errors will be stored here + public function __construct() + { + return true; + } - public function __construct() { - return true; - } + public function WriteMetaFLAC() + { + if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { + $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call metaflac, tags not written'; - public function WriteMetaFLAC() { + return false; + } - if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { - $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call metaflac, tags not written'; - return false; - } + // Create file with new comments + $tempcommentsfilename = tempnam(GETID3_TEMP_DIR, 'getID3'); + if (is_writable($tempcommentsfilename) && is_file($tempcommentsfilename) && ($fpcomments = fopen($tempcommentsfilename, 'wb'))) { + foreach ($this->tag_data as $key => $value) { + foreach ($value as $commentdata) { + fwrite($fpcomments, $this->CleanmetaflacName($key).'='.$commentdata."\n"); + } + } + fclose($fpcomments); + } else { + $this->errors[] = 'failed to open temporary tags file, tags not written - fopen("'.$tempcommentsfilename.'", "wb")'; - // Create file with new comments - $tempcommentsfilename = tempnam(GETID3_TEMP_DIR, 'getID3'); - if (is_writable($tempcommentsfilename) && is_file($tempcommentsfilename) && ($fpcomments = fopen($tempcommentsfilename, 'wb'))) { - foreach ($this->tag_data as $key => $value) { - foreach ($value as $commentdata) { - fwrite($fpcomments, $this->CleanmetaflacName($key).'='.$commentdata."\n"); - } - } - fclose($fpcomments); + return false; + } - } else { - $this->errors[] = 'failed to open temporary tags file, tags not written - fopen("'.$tempcommentsfilename.'", "wb")'; - return false; - } + $oldignoreuserabort = ignore_user_abort(true); + if (GETID3_OS_ISWINDOWS) { + if (file_exists(GETID3_HELPERAPPSDIR.'metaflac.exe')) { + //$commandline = '"'.GETID3_HELPERAPPSDIR.'metaflac.exe" --no-utf8-convert --remove-all-tags --import-tags-from="'.$tempcommentsfilename.'" "'.str_replace('/', '\\', $this->filename).'"'; + // metaflac works fine if you copy-paste the above commandline into a command prompt, + // but refuses to work with `backtick` if there are "doublequotes" present around BOTH + // the metaflac pathname and the target filename. For whatever reason...?? + // The solution is simply ensure that the metaflac pathname has no spaces, + // and therefore does not need to be quoted - $oldignoreuserabort = ignore_user_abort(true); - if (GETID3_OS_ISWINDOWS) { + // On top of that, if error messages are not always captured properly under Windows + // To at least see if there was a problem, compare file modification timestamps before and after writing + clearstatcache(); + $timestampbeforewriting = filemtime($this->filename); - if (file_exists(GETID3_HELPERAPPSDIR.'metaflac.exe')) { - //$commandline = '"'.GETID3_HELPERAPPSDIR.'metaflac.exe" --no-utf8-convert --remove-all-tags --import-tags-from="'.$tempcommentsfilename.'" "'.str_replace('/', '\\', $this->filename).'"'; - // metaflac works fine if you copy-paste the above commandline into a command prompt, - // but refuses to work with `backtick` if there are "doublequotes" present around BOTH - // the metaflac pathname and the target filename. For whatever reason...?? - // The solution is simply ensure that the metaflac pathname has no spaces, - // and therefore does not need to be quoted + $commandline = GETID3_HELPERAPPSDIR.'metaflac.exe --no-utf8-convert --remove-all-tags --import-tags-from='.escapeshellarg($tempcommentsfilename).' '.escapeshellarg($this->filename).' 2>&1'; + $metaflacError = `$commandline`; - // On top of that, if error messages are not always captured properly under Windows - // To at least see if there was a problem, compare file modification timestamps before and after writing - clearstatcache(); - $timestampbeforewriting = filemtime($this->filename); + if (empty($metaflacError)) { + clearstatcache(); + if ($timestampbeforewriting == filemtime($this->filename)) { + $metaflacError = 'File modification timestamp has not changed - it looks like the tags were not written'; + } + } + } else { + $metaflacError = 'metaflac.exe not found in '.GETID3_HELPERAPPSDIR; + } + } else { - $commandline = GETID3_HELPERAPPSDIR.'metaflac.exe --no-utf8-convert --remove-all-tags --import-tags-from='.escapeshellarg($tempcommentsfilename).' '.escapeshellarg($this->filename).' 2>&1'; - $metaflacError = `$commandline`; + // It's simpler on *nix + $commandline = 'metaflac --no-utf8-convert --remove-all-tags --import-tags-from='.escapeshellarg($tempcommentsfilename).' '.escapeshellarg($this->filename).' 2>&1'; + $metaflacError = `$commandline`; + } - if (empty($metaflacError)) { - clearstatcache(); - if ($timestampbeforewriting == filemtime($this->filename)) { - $metaflacError = 'File modification timestamp has not changed - it looks like the tags were not written'; - } - } - } else { - $metaflacError = 'metaflac.exe not found in '.GETID3_HELPERAPPSDIR; - } + // Remove temporary comments file + unlink($tempcommentsfilename); + ignore_user_abort($oldignoreuserabort); - } else { + if (! empty($metaflacError)) { + $this->errors[] = 'System call to metaflac failed with this message returned: '."\n\n".$metaflacError; - // It's simpler on *nix - $commandline = 'metaflac --no-utf8-convert --remove-all-tags --import-tags-from='.escapeshellarg($tempcommentsfilename).' '.escapeshellarg($this->filename).' 2>&1'; - $metaflacError = `$commandline`; + return false; + } - } + return true; + } - // Remove temporary comments file - unlink($tempcommentsfilename); - ignore_user_abort($oldignoreuserabort); + public function DeleteMetaFLAC() + { + if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { + $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call metaflac, tags not deleted'; - if (!empty($metaflacError)) { + return false; + } - $this->errors[] = 'System call to metaflac failed with this message returned: '."\n\n".$metaflacError; - return false; + $oldignoreuserabort = ignore_user_abort(true); + if (GETID3_OS_ISWINDOWS) { + if (file_exists(GETID3_HELPERAPPSDIR.'metaflac.exe')) { + // To at least see if there was a problem, compare file modification timestamps before and after writing + clearstatcache(); + $timestampbeforewriting = filemtime($this->filename); - } + $commandline = GETID3_HELPERAPPSDIR.'metaflac.exe --remove-all-tags "'.$this->filename.'" 2>&1'; + $metaflacError = `$commandline`; - return true; - } + if (empty($metaflacError)) { + clearstatcache(); + if ($timestampbeforewriting == filemtime($this->filename)) { + $metaflacError = 'File modification timestamp has not changed - it looks like the tags were not deleted'; + } + } + } else { + $metaflacError = 'metaflac.exe not found in '.GETID3_HELPERAPPSDIR; + } + } else { + // It's simpler on *nix + $commandline = 'metaflac --remove-all-tags "'.$this->filename.'" 2>&1'; + $metaflacError = `$commandline`; + } - public function DeleteMetaFLAC() { + ignore_user_abort($oldignoreuserabort); - if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { - $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call metaflac, tags not deleted'; - return false; - } + if (! empty($metaflacError)) { + $this->errors[] = 'System call to metaflac failed with this message returned: '."\n\n".$metaflacError; - $oldignoreuserabort = ignore_user_abort(true); - if (GETID3_OS_ISWINDOWS) { + return false; + } - if (file_exists(GETID3_HELPERAPPSDIR.'metaflac.exe')) { - // To at least see if there was a problem, compare file modification timestamps before and after writing - clearstatcache(); - $timestampbeforewriting = filemtime($this->filename); + return true; + } - $commandline = GETID3_HELPERAPPSDIR.'metaflac.exe --remove-all-tags "'.$this->filename.'" 2>&1'; - $metaflacError = `$commandline`; - - if (empty($metaflacError)) { - clearstatcache(); - if ($timestampbeforewriting == filemtime($this->filename)) { - $metaflacError = 'File modification timestamp has not changed - it looks like the tags were not deleted'; - } - } - } else { - $metaflacError = 'metaflac.exe not found in '.GETID3_HELPERAPPSDIR; - } - - } else { - - // It's simpler on *nix - $commandline = 'metaflac --remove-all-tags "'.$this->filename.'" 2>&1'; - $metaflacError = `$commandline`; - - } - - ignore_user_abort($oldignoreuserabort); - - if (!empty($metaflacError)) { - $this->errors[] = 'System call to metaflac failed with this message returned: '."\n\n".$metaflacError; - return false; - } - return true; - } - - - public function CleanmetaflacName($originalcommentname) { - // A case-insensitive field name that may consist of ASCII 0x20 through 0x7D, 0x3D ('=') excluded. - // ASCII 0x41 through 0x5A inclusive (A-Z) is to be considered equivalent to ASCII 0x61 through - // 0x7A inclusive (a-z). - - // replace invalid chars with a space, return uppercase text - // Thanks Chris Bolt for improving this function - // note: *reg_replace() replaces nulls with empty string (not space) - return strtoupper(preg_replace('#[^ -<>-}]#', ' ', str_replace("\x00", ' ', $originalcommentname))); - - } + public function CleanmetaflacName($originalcommentname) + { + // A case-insensitive field name that may consist of ASCII 0x20 through 0x7D, 0x3D ('=') excluded. + // ASCII 0x41 through 0x5A inclusive (A-Z) is to be considered equivalent to ASCII 0x61 through + // 0x7A inclusive (a-z). + // replace invalid chars with a space, return uppercase text + // Thanks Chris Bolt for improving this function + // note: *reg_replace() replaces nulls with empty string (not space) + return strtoupper(preg_replace('#[^ -<>-}]#', ' ', str_replace("\x00", ' ', $originalcommentname))); + } } diff --git a/app/Library/getid3/getid3/write.php b/app/Library/getid3/getid3/write.php index d4416549..9ef9eeac 100644 --- a/app/Library/getid3/getid3/write.php +++ b/app/Library/getid3/getid3/write.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -20,14 +21,13 @@ // /// ///////////////////////////////////////////////////////////////// -if (!defined('GETID3_INCLUDEPATH')) { - throw new Exception('getid3.php MUST be included before calling getid3_writetags'); +if (! defined('GETID3_INCLUDEPATH')) { + throw new Exception('getid3.php MUST be included before calling getid3_writetags'); } -if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) { - throw new Exception('write.php depends on getid3.lib.php, which is missing.'); +if (! include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) { + throw new Exception('write.php depends on getid3.lib.php, which is missing.'); } - // NOTES: // // You should pass data here with standard field names as follows: @@ -44,610 +44,631 @@ if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) { // The APEv2 Tag Items Keys definition says "TRACK" is correct but foobar2000 uses "TRACKNUMBER" instead // Pass data here as "TRACKNUMBER" for compatability with all formats - -class getid3_writetags +class write { - // public - public $filename; // absolute filename of file to write tags to - public $tagformats = array(); // array of tag formats to write ('id3v1', 'id3v2.2', 'id2v2.3', 'id3v2.4', 'ape', 'vorbiscomment', 'metaflac', 'real') - public $tag_data = array(array()); // 2-dimensional array of tag data (ex: $data['ARTIST'][0] = 'Elvis') - public $tag_encoding = 'ISO-8859-1'; // text encoding used for tag data ('ISO-8859-1', 'UTF-8', 'UTF-16', 'UTF-16LE', 'UTF-16BE', ) - public $overwrite_tags = true; // if true will erase existing tag data and write only passed data; if false will merge passed data with existing tag data - public $remove_other_tags = false; // if true will erase remove all existing tags and only write those passed in $tagformats; if false will ignore any tags not mentioned in $tagformats - - public $id3v2_tag_language = 'eng'; // ISO-639-2 3-character language code needed for some ID3v2 frames (http://www.id3.org/iso639-2.html) - public $id3v2_paddedlength = 4096; // minimum length of ID3v2 tags (will be padded to this length if tag data is shorter) - - public $warnings = array(); // any non-critical errors will be stored here - public $errors = array(); // any critical errors will be stored here - - // private - private $ThisFileInfo; // analysis of file before writing - - public function __construct() { - return true; - } - - - public function WriteTags() { - - if (empty($this->filename)) { - $this->errors[] = 'filename is undefined in getid3_writetags'; - return false; - } elseif (!file_exists($this->filename)) { - $this->errors[] = 'filename set to non-existant file "'.$this->filename.'" in getid3_writetags'; - return false; - } - - if (!is_array($this->tagformats)) { - $this->errors[] = 'tagformats must be an array in getid3_writetags'; - return false; - } - - $TagFormatsToRemove = array(); - if (filesize($this->filename) == 0) { - - // empty file special case - allow any tag format, don't check existing format - // could be useful if you want to generate tag data for a non-existant file - $this->ThisFileInfo = array('fileformat'=>''); - $AllowedTagFormats = array('id3v1', 'id3v2.2', 'id3v2.3', 'id3v2.4', 'ape', 'lyrics3'); - - } else { - - $getID3 = new getID3; - $getID3->encoding = $this->tag_encoding; - $this->ThisFileInfo = $getID3->analyze($this->filename); - - // check for what file types are allowed on this fileformat - switch (isset($this->ThisFileInfo['fileformat']) ? $this->ThisFileInfo['fileformat'] : '') { - case 'mp3': - case 'mp2': - case 'mp1': - case 'riff': // maybe not officially, but people do it anyway - $AllowedTagFormats = array('id3v1', 'id3v2.2', 'id3v2.3', 'id3v2.4', 'ape', 'lyrics3'); - break; - - case 'mpc': - $AllowedTagFormats = array('ape'); - break; - - case 'flac': - $AllowedTagFormats = array('metaflac'); - break; - - case 'real': - $AllowedTagFormats = array('real'); - break; - - case 'ogg': - switch (isset($this->ThisFileInfo['audio']['dataformat']) ? $this->ThisFileInfo['audio']['dataformat'] : '') { - case 'flac': - //$AllowedTagFormats = array('metaflac'); - $this->errors[] = 'metaflac is not (yet) compatible with OggFLAC files'; - return false; - break; - case 'vorbis': - $AllowedTagFormats = array('vorbiscomment'); - break; - default: - $this->errors[] = 'metaflac is not (yet) compatible with Ogg files other than OggVorbis'; - return false; - break; - } - break; - - default: - $AllowedTagFormats = array(); - break; - } - foreach ($this->tagformats as $requested_tag_format) { - if (!in_array($requested_tag_format, $AllowedTagFormats)) { - $errormessage = 'Tag format "'.$requested_tag_format.'" is not allowed on "'.(isset($this->ThisFileInfo['fileformat']) ? $this->ThisFileInfo['fileformat'] : ''); - $errormessage .= (isset($this->ThisFileInfo['audio']['dataformat']) ? '.'.$this->ThisFileInfo['audio']['dataformat'] : ''); - $errormessage .= '" files'; - $this->errors[] = $errormessage; - return false; - } - } - - // List of other tag formats, removed if requested - if ($this->remove_other_tags) { - foreach ($AllowedTagFormats as $AllowedTagFormat) { - switch ($AllowedTagFormat) { - case 'id3v2.2': - case 'id3v2.3': - case 'id3v2.4': - if (!in_array('id3v2', $TagFormatsToRemove) && !in_array('id3v2.2', $this->tagformats) && !in_array('id3v2.3', $this->tagformats) && !in_array('id3v2.4', $this->tagformats)) { - $TagFormatsToRemove[] = 'id3v2'; - } - break; - - default: - if (!in_array($AllowedTagFormat, $this->tagformats)) { - $TagFormatsToRemove[] = $AllowedTagFormat; - } - break; - } - } - } - } - - $WritingFilesToInclude = array_merge($this->tagformats, $TagFormatsToRemove); - - // Check for required include files and include them - foreach ($WritingFilesToInclude as $tagformat) { - switch ($tagformat) { - case 'ape': - $GETID3_ERRORARRAY = &$this->errors; - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.apetag.php', __FILE__, true); - break; - - case 'id3v1': - case 'lyrics3': - case 'vorbiscomment': - case 'metaflac': - case 'real': - $GETID3_ERRORARRAY = &$this->errors; - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.'.$tagformat.'.php', __FILE__, true); - break; - - case 'id3v2.2': - case 'id3v2.3': - case 'id3v2.4': - case 'id3v2': - $GETID3_ERRORARRAY = &$this->errors; - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.id3v2.php', __FILE__, true); - break; - - default: - $this->errors[] = 'unknown tag format "'.$tagformat.'" in $tagformats in WriteTags()'; - return false; - break; - } - - } - - // Validation of supplied data - if (!is_array($this->tag_data)) { - $this->errors[] = '$this->tag_data is not an array in WriteTags()'; - return false; - } - // convert supplied data array keys to upper case, if they're not already - foreach ($this->tag_data as $tag_key => $tag_array) { - if (strtoupper($tag_key) !== $tag_key) { - $this->tag_data[strtoupper($tag_key)] = $this->tag_data[$tag_key]; - unset($this->tag_data[$tag_key]); - } - } - // convert source data array keys to upper case, if they're not already - if (!empty($this->ThisFileInfo['tags'])) { - foreach ($this->ThisFileInfo['tags'] as $tag_format => $tag_data_array) { - foreach ($tag_data_array as $tag_key => $tag_array) { - if (strtoupper($tag_key) !== $tag_key) { - $this->ThisFileInfo['tags'][$tag_format][strtoupper($tag_key)] = $this->ThisFileInfo['tags'][$tag_format][$tag_key]; - unset($this->ThisFileInfo['tags'][$tag_format][$tag_key]); - } - } - } - } - - // Convert "TRACK" to "TRACKNUMBER" (if needed) for compatability with all formats - if (isset($this->tag_data['TRACK']) && !isset($this->tag_data['TRACKNUMBER'])) { - $this->tag_data['TRACKNUMBER'] = $this->tag_data['TRACK']; - unset($this->tag_data['TRACK']); - } - - // Remove all other tag formats, if requested - if ($this->remove_other_tags) { - $this->DeleteTags($TagFormatsToRemove); - } - - // Write data for each tag format - foreach ($this->tagformats as $tagformat) { - $success = false; // overridden if tag writing is successful - switch ($tagformat) { - case 'ape': - $ape_writer = new getid3_write_apetag; - if (($ape_writer->tag_data = $this->FormatDataForAPE()) !== false) { - $ape_writer->filename = $this->filename; - if (($success = $ape_writer->WriteAPEtag()) === false) { - $this->errors[] = 'WriteAPEtag() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $ape_writer->errors)))).'
    '; - } - } else { - $this->errors[] = 'FormatDataForAPE() failed'; - } - break; - - case 'id3v1': - $id3v1_writer = new getid3_write_id3v1; - if (($id3v1_writer->tag_data = $this->FormatDataForID3v1()) !== false) { - $id3v1_writer->filename = $this->filename; - if (($success = $id3v1_writer->WriteID3v1()) === false) { - $this->errors[] = 'WriteID3v1() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $id3v1_writer->errors)))).'
    '; - } - } else { - $this->errors[] = 'FormatDataForID3v1() failed'; - } - break; - - case 'id3v2.2': - case 'id3v2.3': - case 'id3v2.4': - $id3v2_writer = new getid3_write_id3v2; - $id3v2_writer->majorversion = intval(substr($tagformat, -1)); - $id3v2_writer->paddedlength = $this->id3v2_paddedlength; - if (($id3v2_writer->tag_data = $this->FormatDataForID3v2($id3v2_writer->majorversion)) !== false) { - $id3v2_writer->filename = $this->filename; - if (($success = $id3v2_writer->WriteID3v2()) === false) { - $this->errors[] = 'WriteID3v2() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $id3v2_writer->errors)))).'
    '; - } - } else { - $this->errors[] = 'FormatDataForID3v2() failed'; - } - break; - - case 'vorbiscomment': - $vorbiscomment_writer = new getid3_write_vorbiscomment; - if (($vorbiscomment_writer->tag_data = $this->FormatDataForVorbisComment()) !== false) { - $vorbiscomment_writer->filename = $this->filename; - if (($success = $vorbiscomment_writer->WriteVorbisComment()) === false) { - $this->errors[] = 'WriteVorbisComment() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $vorbiscomment_writer->errors)))).'
    '; - } - } else { - $this->errors[] = 'FormatDataForVorbisComment() failed'; - } - break; - - case 'metaflac': - $metaflac_writer = new getid3_write_metaflac; - if (($metaflac_writer->tag_data = $this->FormatDataForMetaFLAC()) !== false) { - $metaflac_writer->filename = $this->filename; - if (($success = $metaflac_writer->WriteMetaFLAC()) === false) { - $this->errors[] = 'WriteMetaFLAC() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $metaflac_writer->errors)))).'
    '; - } - } else { - $this->errors[] = 'FormatDataForMetaFLAC() failed'; - } - break; - - case 'real': - $real_writer = new getid3_write_real; - if (($real_writer->tag_data = $this->FormatDataForReal()) !== false) { - $real_writer->filename = $this->filename; - if (($success = $real_writer->WriteReal()) === false) { - $this->errors[] = 'WriteReal() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $real_writer->errors)))).'
    '; - } - } else { - $this->errors[] = 'FormatDataForReal() failed'; - } - break; - - default: - $this->errors[] = 'Invalid tag format to write: "'.$tagformat.'"'; - return false; - break; - } - if (!$success) { - return false; - } - } - return true; - - } - - - public function DeleteTags($TagFormatsToDelete) { - foreach ($TagFormatsToDelete as $DeleteTagFormat) { - $success = false; // overridden if tag deletion is successful - switch ($DeleteTagFormat) { - case 'id3v1': - $id3v1_writer = new getid3_write_id3v1; - $id3v1_writer->filename = $this->filename; - if (($success = $id3v1_writer->RemoveID3v1()) === false) { - $this->errors[] = 'RemoveID3v1() failed with message(s):
    • '.trim(implode('
    • ', $id3v1_writer->errors)).'
    '; - } - break; - - case 'id3v2': - $id3v2_writer = new getid3_write_id3v2; - $id3v2_writer->filename = $this->filename; - if (($success = $id3v2_writer->RemoveID3v2()) === false) { - $this->errors[] = 'RemoveID3v2() failed with message(s):
    • '.trim(implode('
    • ', $id3v2_writer->errors)).'
    '; - } - break; - - case 'ape': - $ape_writer = new getid3_write_apetag; - $ape_writer->filename = $this->filename; - if (($success = $ape_writer->DeleteAPEtag()) === false) { - $this->errors[] = 'DeleteAPEtag() failed with message(s):
    • '.trim(implode('
    • ', $ape_writer->errors)).'
    '; - } - break; - - case 'vorbiscomment': - $vorbiscomment_writer = new getid3_write_vorbiscomment; - $vorbiscomment_writer->filename = $this->filename; - if (($success = $vorbiscomment_writer->DeleteVorbisComment()) === false) { - $this->errors[] = 'DeleteVorbisComment() failed with message(s):
    • '.trim(implode('
    • ', $vorbiscomment_writer->errors)).'
    '; - } - break; - - case 'metaflac': - $metaflac_writer = new getid3_write_metaflac; - $metaflac_writer->filename = $this->filename; - if (($success = $metaflac_writer->DeleteMetaFLAC()) === false) { - $this->errors[] = 'DeleteMetaFLAC() failed with message(s):
    • '.trim(implode('
    • ', $metaflac_writer->errors)).'
    '; - } - break; - - case 'lyrics3': - $lyrics3_writer = new getid3_write_lyrics3; - $lyrics3_writer->filename = $this->filename; - if (($success = $lyrics3_writer->DeleteLyrics3()) === false) { - $this->errors[] = 'DeleteLyrics3() failed with message(s):
    • '.trim(implode('
    • ', $lyrics3_writer->errors)).'
    '; - } - break; - - case 'real': - $real_writer = new getid3_write_real; - $real_writer->filename = $this->filename; - if (($success = $real_writer->RemoveReal()) === false) { - $this->errors[] = 'RemoveReal() failed with message(s):
    • '.trim(implode('
    • ', $real_writer->errors)).'
    '; - } - break; - - default: - $this->errors[] = 'Invalid tag format to delete: "'.$tagformat.'"'; - return false; - break; - } - if (!$success) { - return false; - } - } - return true; - } - - - public function MergeExistingTagData($TagFormat, &$tag_data) { - // Merge supplied data with existing data, if requested - if ($this->overwrite_tags) { - // do nothing - ignore previous data - } else { -throw new Exception('$this->overwrite_tags=false is known to be buggy in this version of getID3. Will be fixed in the near future, check www.getid3.org for a newer version.'); - if (!isset($this->ThisFileInfo['tags'][$TagFormat])) { - return false; - } - $tag_data = array_merge_recursive($tag_data, $this->ThisFileInfo['tags'][$TagFormat]); - } - return true; - } - - public function FormatDataForAPE() { - $ape_tag_data = array(); - foreach ($this->tag_data as $tag_key => $valuearray) { - switch ($tag_key) { - case 'ATTACHED_PICTURE': - // ATTACHED_PICTURE is ID3v2 only - ignore - $this->warnings[] = '$data['.$tag_key.'] is assumed to be ID3v2 APIC data - NOT written to APE tag'; - break; - - default: - foreach ($valuearray as $key => $value) { - if (is_string($value) || is_numeric($value)) { - $ape_tag_data[$tag_key][$key] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value); - } else { - $this->warnings[] = '$data['.$tag_key.']['.$key.'] is not a string value - all of $data['.$tag_key.'] NOT written to APE tag'; - unset($ape_tag_data[$tag_key]); - break; - } - } - break; - } - } - $this->MergeExistingTagData('ape', $ape_tag_data); - return $ape_tag_data; - } - - - public function FormatDataForID3v1() { - $tag_data_id3v1['genreid'] = 255; - if (!empty($this->tag_data['GENRE'])) { - foreach ($this->tag_data['GENRE'] as $key => $value) { - if (getid3_id3v1::LookupGenreID($value) !== false) { - $tag_data_id3v1['genreid'] = getid3_id3v1::LookupGenreID($value); - break; - } - } - } - $tag_data_id3v1['title'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['TITLE'] ) ? $this->tag_data['TITLE'] : array()))); - $tag_data_id3v1['artist'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['ARTIST'] ) ? $this->tag_data['ARTIST'] : array()))); - $tag_data_id3v1['album'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['ALBUM'] ) ? $this->tag_data['ALBUM'] : array()))); - $tag_data_id3v1['year'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['YEAR'] ) ? $this->tag_data['YEAR'] : array()))); - $tag_data_id3v1['comment'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['COMMENT'] ) ? $this->tag_data['COMMENT'] : array()))); - $tag_data_id3v1['track'] = intval(getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['TRACKNUMBER']) ? $this->tag_data['TRACKNUMBER'] : array())))); - if ($tag_data_id3v1['track'] <= 0) { - $tag_data_id3v1['track'] = ''; - } - - $this->MergeExistingTagData('id3v1', $tag_data_id3v1); - return $tag_data_id3v1; - } - - public function FormatDataForID3v2($id3v2_majorversion) { - $tag_data_id3v2 = array(); - - $ID3v2_text_encoding_lookup[2] = array('ISO-8859-1'=>0, 'UTF-16'=>1); - $ID3v2_text_encoding_lookup[3] = array('ISO-8859-1'=>0, 'UTF-16'=>1); - $ID3v2_text_encoding_lookup[4] = array('ISO-8859-1'=>0, 'UTF-16'=>1, 'UTF-16BE'=>2, 'UTF-8'=>3); - foreach ($this->tag_data as $tag_key => $valuearray) { - $ID3v2_framename = getid3_write_id3v2::ID3v2ShortFrameNameLookup($id3v2_majorversion, $tag_key); - switch ($ID3v2_framename) { - case 'APIC': - foreach ($valuearray as $key => $apic_data_array) { - if (isset($apic_data_array['data']) && - isset($apic_data_array['picturetypeid']) && - isset($apic_data_array['description']) && - isset($apic_data_array['mime'])) { - $tag_data_id3v2['APIC'][] = $apic_data_array; - } else { - $this->errors[] = 'ID3v2 APIC data is not properly structured'; - return false; - } - } - break; - - case 'POPM': - if (isset($valuearray['email']) && - isset($valuearray['rating']) && - isset($valuearray['data'])) { - $tag_data_id3v2['POPM'][] = $valuearray; - } else { - $this->errors[] = 'ID3v2 POPM data is not properly structured'; - return false; - } - break; - - case 'GRID': - if ( - isset($valuearray['groupsymbol']) && - isset($valuearray['ownerid']) && - isset($valuearray['data']) - ) { - $tag_data_id3v2['GRID'][] = $valuearray; - } else { - $this->errors[] = 'ID3v2 GRID data is not properly structured'; - return false; - } - break; - - case 'UFID': - if (isset($valuearray['ownerid']) && - isset($valuearray['data'])) { - $tag_data_id3v2['UFID'][] = $valuearray; - } else { - $this->errors[] = 'ID3v2 UFID data is not properly structured'; - return false; - } - break; - - case 'TXXX': - foreach ($valuearray as $key => $txxx_data_array) { - if (isset($txxx_data_array['description']) && isset($txxx_data_array['data'])) { - $tag_data_id3v2['TXXX'][] = $txxx_data_array; - } else { - $this->errors[] = 'ID3v2 TXXX data is not properly structured'; - return false; - } - } - break; - - case '': - $this->errors[] = 'ID3v2: Skipping "'.$tag_key.'" because cannot match it to a known ID3v2 frame type'; - // some other data type, don't know how to handle it, ignore it - break; - - default: - // most other (text) frames can be copied over as-is - foreach ($valuearray as $key => $value) { - if (isset($ID3v2_text_encoding_lookup[$id3v2_majorversion][$this->tag_encoding])) { - // source encoding is valid in ID3v2 - use it with no conversion - $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = $ID3v2_text_encoding_lookup[$id3v2_majorversion][$this->tag_encoding]; - $tag_data_id3v2[$ID3v2_framename][$key]['data'] = $value; - } else { - // source encoding is NOT valid in ID3v2 - convert it to an ID3v2-valid encoding first - if ($id3v2_majorversion < 4) { - // convert data from other encoding to UTF-16 (with BOM) - // note: some software, notably Windows Media Player and iTunes are broken and treat files tagged with UTF-16BE (with BOM) as corrupt - // therefore we force data to UTF-16LE and manually prepend the BOM - $ID3v2_tag_data_converted = false; - if (!$ID3v2_tag_data_converted && ($this->tag_encoding == 'ISO-8859-1')) { - // great, leave data as-is for minimum compatability problems - $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 0; - $tag_data_id3v2[$ID3v2_framename][$key]['data'] = $value; - $ID3v2_tag_data_converted = true; - } - if (!$ID3v2_tag_data_converted && ($this->tag_encoding == 'UTF-8')) { - do { - // if UTF-8 string does not include any characters above chr(127) then it is identical to ISO-8859-1 - for ($i = 0; $i < strlen($value); $i++) { - if (ord($value{$i}) > 127) { - break 2; - } - } - $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 0; - $tag_data_id3v2[$ID3v2_framename][$key]['data'] = $value; - $ID3v2_tag_data_converted = true; - } while (false); - } - if (!$ID3v2_tag_data_converted) { - $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 1; - //$tag_data_id3v2[$ID3v2_framename][$key]['data'] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-16', $value); // output is UTF-16LE+BOM or UTF-16BE+BOM depending on system architecture - $tag_data_id3v2[$ID3v2_framename][$key]['data'] = "\xFF\xFE".getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-16LE', $value); // force LittleEndian order version of UTF-16 - $ID3v2_tag_data_converted = true; - } - - } else { - // convert data from other encoding to UTF-8 - $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 3; - $tag_data_id3v2[$ID3v2_framename][$key]['data'] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value); - } - } - - // These values are not needed for all frame types, but if they're not used no matter - $tag_data_id3v2[$ID3v2_framename][$key]['description'] = ''; - $tag_data_id3v2[$ID3v2_framename][$key]['language'] = $this->id3v2_tag_language; - } - break; - } - } - $this->MergeExistingTagData('id3v2', $tag_data_id3v2); - return $tag_data_id3v2; - } - - public function FormatDataForVorbisComment() { - $tag_data_vorbiscomment = $this->tag_data; - - // check for multi-line comment values - split out to multiple comments if neccesary - // and convert data to UTF-8 strings - foreach ($tag_data_vorbiscomment as $tag_key => $valuearray) { - foreach ($valuearray as $key => $value) { - str_replace("\r", "\n", $value); - if (strstr($value, "\n")) { - unset($tag_data_vorbiscomment[$tag_key][$key]); - $multilineexploded = explode("\n", $value); - foreach ($multilineexploded as $newcomment) { - if (strlen(trim($newcomment)) > 0) { - $tag_data_vorbiscomment[$tag_key][] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $newcomment); - } - } - } elseif (is_string($value) || is_numeric($value)) { - $tag_data_vorbiscomment[$tag_key][$key] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value); - } else { - $this->warnings[] = '$data['.$tag_key.']['.$key.'] is not a string value - all of $data['.$tag_key.'] NOT written to VorbisComment tag'; - unset($tag_data_vorbiscomment[$tag_key]); - break; - } - } - } - $this->MergeExistingTagData('vorbiscomment', $tag_data_vorbiscomment); - return $tag_data_vorbiscomment; - } - - public function FormatDataForMetaFLAC() { - // FLAC & OggFLAC use VorbisComments same as OggVorbis - // but require metaflac to do the writing rather than vorbiscomment - return $this->FormatDataForVorbisComment(); - } - - public function FormatDataForReal() { - $tag_data_real['title'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['TITLE'] ) ? $this->tag_data['TITLE'] : array()))); - $tag_data_real['artist'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['ARTIST'] ) ? $this->tag_data['ARTIST'] : array()))); - $tag_data_real['copyright'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['COPYRIGHT']) ? $this->tag_data['COPYRIGHT'] : array()))); - $tag_data_real['comment'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['COMMENT'] ) ? $this->tag_data['COMMENT'] : array()))); - - $this->MergeExistingTagData('real', $tag_data_real); - return $tag_data_real; - } - + // public + public $filename; // absolute filename of file to write tags to + public $tagformats = []; // array of tag formats to write ('id3v1', 'id3v2.2', 'id2v2.3', 'id3v2.4', 'ape', 'vorbiscomment', 'metaflac', 'real') + public $tag_data = [[]]; // 2-dimensional array of tag data (ex: $data['ARTIST'][0] = 'Elvis') + public $tag_encoding = 'ISO-8859-1'; // text encoding used for tag data ('ISO-8859-1', 'UTF-8', 'UTF-16', 'UTF-16LE', 'UTF-16BE', ) + public $overwrite_tags = true; // if true will erase existing tag data and write only passed data; if false will merge passed data with existing tag data + public $remove_other_tags = false; // if true will erase remove all existing tags and only write those passed in $tagformats; if false will ignore any tags not mentioned in $tagformats + + public $id3v2_tag_language = 'eng'; // ISO-639-2 3-character language code needed for some ID3v2 frames (http://www.id3.org/iso639-2.html) + public $id3v2_paddedlength = 4096; // minimum length of ID3v2 tags (will be padded to this length if tag data is shorter) + + public $warnings = []; // any non-critical errors will be stored here + public $errors = []; // any critical errors will be stored here + + // private + private $ThisFileInfo; // analysis of file before writing + + public function __construct() + { + return true; + } + + public function WriteTags() + { + if (empty($this->filename)) { + $this->errors[] = 'filename is undefined in getid3_writetags'; + + return false; + } elseif (! file_exists($this->filename)) { + $this->errors[] = 'filename set to non-existant file "'.$this->filename.'" in getid3_writetags'; + + return false; + } + + if (! is_array($this->tagformats)) { + $this->errors[] = 'tagformats must be an array in getid3_writetags'; + + return false; + } + + $TagFormatsToRemove = []; + if (filesize($this->filename) == 0) { + + // empty file special case - allow any tag format, don't check existing format + // could be useful if you want to generate tag data for a non-existant file + $this->ThisFileInfo = ['fileformat'=>'']; + $AllowedTagFormats = ['id3v1', 'id3v2.2', 'id3v2.3', 'id3v2.4', 'ape', 'lyrics3']; + } else { + $getID3 = new getID3; + $getID3->encoding = $this->tag_encoding; + $this->ThisFileInfo = $getID3->analyze($this->filename); + + // check for what file types are allowed on this fileformat + switch (isset($this->ThisFileInfo['fileformat']) ? $this->ThisFileInfo['fileformat'] : '') { + case 'mp3': + case 'mp2': + case 'mp1': + case 'riff': // maybe not officially, but people do it anyway + $AllowedTagFormats = ['id3v1', 'id3v2.2', 'id3v2.3', 'id3v2.4', 'ape', 'lyrics3']; + break; + + case 'mpc': + $AllowedTagFormats = ['ape']; + break; + + case 'flac': + $AllowedTagFormats = ['metaflac']; + break; + + case 'real': + $AllowedTagFormats = ['real']; + break; + + case 'ogg': + switch (isset($this->ThisFileInfo['audio']['dataformat']) ? $this->ThisFileInfo['audio']['dataformat'] : '') { + case 'flac': + //$AllowedTagFormats = array('metaflac'); + $this->errors[] = 'metaflac is not (yet) compatible with OggFLAC files'; + + return false; + break; + case 'vorbis': + $AllowedTagFormats = ['vorbiscomment']; + break; + default: + $this->errors[] = 'metaflac is not (yet) compatible with Ogg files other than OggVorbis'; + + return false; + break; + } + break; + + default: + $AllowedTagFormats = []; + break; + } + foreach ($this->tagformats as $requested_tag_format) { + if (! in_array($requested_tag_format, $AllowedTagFormats)) { + $errormessage = 'Tag format "'.$requested_tag_format.'" is not allowed on "'.(isset($this->ThisFileInfo['fileformat']) ? $this->ThisFileInfo['fileformat'] : ''); + $errormessage .= (isset($this->ThisFileInfo['audio']['dataformat']) ? '.'.$this->ThisFileInfo['audio']['dataformat'] : ''); + $errormessage .= '" files'; + $this->errors[] = $errormessage; + + return false; + } + } + + // List of other tag formats, removed if requested + if ($this->remove_other_tags) { + foreach ($AllowedTagFormats as $AllowedTagFormat) { + switch ($AllowedTagFormat) { + case 'id3v2.2': + case 'id3v2.3': + case 'id3v2.4': + if (! in_array('id3v2', $TagFormatsToRemove) && ! in_array('id3v2.2', $this->tagformats) && ! in_array('id3v2.3', $this->tagformats) && ! in_array('id3v2.4', $this->tagformats)) { + $TagFormatsToRemove[] = 'id3v2'; + } + break; + + default: + if (! in_array($AllowedTagFormat, $this->tagformats)) { + $TagFormatsToRemove[] = $AllowedTagFormat; + } + break; + } + } + } + } + + $WritingFilesToInclude = array_merge($this->tagformats, $TagFormatsToRemove); + + // Check for required include files and include them + foreach ($WritingFilesToInclude as $tagformat) { + switch ($tagformat) { + case 'ape': + $GETID3_ERRORARRAY = &$this->errors; + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.apetag.php', __FILE__, true); + break; + + case 'id3v1': + case 'lyrics3': + case 'vorbiscomment': + case 'metaflac': + case 'real': + $GETID3_ERRORARRAY = &$this->errors; + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.'.$tagformat.'.php', __FILE__, true); + break; + + case 'id3v2.2': + case 'id3v2.3': + case 'id3v2.4': + case 'id3v2': + $GETID3_ERRORARRAY = &$this->errors; + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.id3v2.php', __FILE__, true); + break; + + default: + $this->errors[] = 'unknown tag format "'.$tagformat.'" in $tagformats in WriteTags()'; + + return false; + break; + } + } + + // Validation of supplied data + if (! is_array($this->tag_data)) { + $this->errors[] = '$this->tag_data is not an array in WriteTags()'; + + return false; + } + // convert supplied data array keys to upper case, if they're not already + foreach ($this->tag_data as $tag_key => $tag_array) { + if (strtoupper($tag_key) !== $tag_key) { + $this->tag_data[strtoupper($tag_key)] = $this->tag_data[$tag_key]; + unset($this->tag_data[$tag_key]); + } + } + // convert source data array keys to upper case, if they're not already + if (! empty($this->ThisFileInfo['tags'])) { + foreach ($this->ThisFileInfo['tags'] as $tag_format => $tag_data_array) { + foreach ($tag_data_array as $tag_key => $tag_array) { + if (strtoupper($tag_key) !== $tag_key) { + $this->ThisFileInfo['tags'][$tag_format][strtoupper($tag_key)] = $this->ThisFileInfo['tags'][$tag_format][$tag_key]; + unset($this->ThisFileInfo['tags'][$tag_format][$tag_key]); + } + } + } + } + + // Convert "TRACK" to "TRACKNUMBER" (if needed) for compatability with all formats + if (isset($this->tag_data['TRACK']) && ! isset($this->tag_data['TRACKNUMBER'])) { + $this->tag_data['TRACKNUMBER'] = $this->tag_data['TRACK']; + unset($this->tag_data['TRACK']); + } + + // Remove all other tag formats, if requested + if ($this->remove_other_tags) { + $this->DeleteTags($TagFormatsToRemove); + } + + // Write data for each tag format + foreach ($this->tagformats as $tagformat) { + $success = false; // overridden if tag writing is successful + switch ($tagformat) { + case 'ape': + $ape_writer = new getid3_write_apetag; + if (($ape_writer->tag_data = $this->FormatDataForAPE()) !== false) { + $ape_writer->filename = $this->filename; + if (($success = $ape_writer->WriteAPEtag()) === false) { + $this->errors[] = 'WriteAPEtag() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $ape_writer->errors)))).'
    '; + } + } else { + $this->errors[] = 'FormatDataForAPE() failed'; + } + break; + + case 'id3v1': + $id3v1_writer = new getid3_write_id3v1; + if (($id3v1_writer->tag_data = $this->FormatDataForID3v1()) !== false) { + $id3v1_writer->filename = $this->filename; + if (($success = $id3v1_writer->WriteID3v1()) === false) { + $this->errors[] = 'WriteID3v1() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $id3v1_writer->errors)))).'
    '; + } + } else { + $this->errors[] = 'FormatDataForID3v1() failed'; + } + break; + + case 'id3v2.2': + case 'id3v2.3': + case 'id3v2.4': + $id3v2_writer = new getid3_write_id3v2; + $id3v2_writer->majorversion = intval(substr($tagformat, -1)); + $id3v2_writer->paddedlength = $this->id3v2_paddedlength; + if (($id3v2_writer->tag_data = $this->FormatDataForID3v2($id3v2_writer->majorversion)) !== false) { + $id3v2_writer->filename = $this->filename; + if (($success = $id3v2_writer->WriteID3v2()) === false) { + $this->errors[] = 'WriteID3v2() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $id3v2_writer->errors)))).'
    '; + } + } else { + $this->errors[] = 'FormatDataForID3v2() failed'; + } + break; + + case 'vorbiscomment': + $vorbiscomment_writer = new getid3_write_vorbiscomment; + if (($vorbiscomment_writer->tag_data = $this->FormatDataForVorbisComment()) !== false) { + $vorbiscomment_writer->filename = $this->filename; + if (($success = $vorbiscomment_writer->WriteVorbisComment()) === false) { + $this->errors[] = 'WriteVorbisComment() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $vorbiscomment_writer->errors)))).'
    '; + } + } else { + $this->errors[] = 'FormatDataForVorbisComment() failed'; + } + break; + + case 'metaflac': + $metaflac_writer = new getid3_write_metaflac; + if (($metaflac_writer->tag_data = $this->FormatDataForMetaFLAC()) !== false) { + $metaflac_writer->filename = $this->filename; + if (($success = $metaflac_writer->WriteMetaFLAC()) === false) { + $this->errors[] = 'WriteMetaFLAC() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $metaflac_writer->errors)))).'
    '; + } + } else { + $this->errors[] = 'FormatDataForMetaFLAC() failed'; + } + break; + + case 'real': + $real_writer = new getid3_write_real; + if (($real_writer->tag_data = $this->FormatDataForReal()) !== false) { + $real_writer->filename = $this->filename; + if (($success = $real_writer->WriteReal()) === false) { + $this->errors[] = 'WriteReal() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $real_writer->errors)))).'
    '; + } + } else { + $this->errors[] = 'FormatDataForReal() failed'; + } + break; + + default: + $this->errors[] = 'Invalid tag format to write: "'.$tagformat.'"'; + + return false; + break; + } + if (! $success) { + return false; + } + } + + return true; + } + + public function DeleteTags($TagFormatsToDelete) + { + foreach ($TagFormatsToDelete as $DeleteTagFormat) { + $success = false; // overridden if tag deletion is successful + switch ($DeleteTagFormat) { + case 'id3v1': + $id3v1_writer = new getid3_write_id3v1; + $id3v1_writer->filename = $this->filename; + if (($success = $id3v1_writer->RemoveID3v1()) === false) { + $this->errors[] = 'RemoveID3v1() failed with message(s):
    • '.trim(implode('
    • ', $id3v1_writer->errors)).'
    '; + } + break; + + case 'id3v2': + $id3v2_writer = new getid3_write_id3v2; + $id3v2_writer->filename = $this->filename; + if (($success = $id3v2_writer->RemoveID3v2()) === false) { + $this->errors[] = 'RemoveID3v2() failed with message(s):
    • '.trim(implode('
    • ', $id3v2_writer->errors)).'
    '; + } + break; + + case 'ape': + $ape_writer = new getid3_write_apetag; + $ape_writer->filename = $this->filename; + if (($success = $ape_writer->DeleteAPEtag()) === false) { + $this->errors[] = 'DeleteAPEtag() failed with message(s):
    • '.trim(implode('
    • ', $ape_writer->errors)).'
    '; + } + break; + + case 'vorbiscomment': + $vorbiscomment_writer = new getid3_write_vorbiscomment; + $vorbiscomment_writer->filename = $this->filename; + if (($success = $vorbiscomment_writer->DeleteVorbisComment()) === false) { + $this->errors[] = 'DeleteVorbisComment() failed with message(s):
    • '.trim(implode('
    • ', $vorbiscomment_writer->errors)).'
    '; + } + break; + + case 'metaflac': + $metaflac_writer = new getid3_write_metaflac; + $metaflac_writer->filename = $this->filename; + if (($success = $metaflac_writer->DeleteMetaFLAC()) === false) { + $this->errors[] = 'DeleteMetaFLAC() failed with message(s):
    • '.trim(implode('
    • ', $metaflac_writer->errors)).'
    '; + } + break; + + case 'lyrics3': + $lyrics3_writer = new getid3_write_lyrics3; + $lyrics3_writer->filename = $this->filename; + if (($success = $lyrics3_writer->DeleteLyrics3()) === false) { + $this->errors[] = 'DeleteLyrics3() failed with message(s):
    • '.trim(implode('
    • ', $lyrics3_writer->errors)).'
    '; + } + break; + + case 'real': + $real_writer = new getid3_write_real; + $real_writer->filename = $this->filename; + if (($success = $real_writer->RemoveReal()) === false) { + $this->errors[] = 'RemoveReal() failed with message(s):
    • '.trim(implode('
    • ', $real_writer->errors)).'
    '; + } + break; + + default: + $this->errors[] = 'Invalid tag format to delete: "'.$tagformat.'"'; + + return false; + break; + } + if (! $success) { + return false; + } + } + + return true; + } + + public function MergeExistingTagData($TagFormat, &$tag_data) + { + // Merge supplied data with existing data, if requested + if ($this->overwrite_tags) { + // do nothing - ignore previous data + } else { + throw new Exception('$this->overwrite_tags=false is known to be buggy in this version of getID3. Will be fixed in the near future, check www.getid3.org for a newer version.'); + if (! isset($this->ThisFileInfo['tags'][$TagFormat])) { + return false; + } + $tag_data = array_merge_recursive($tag_data, $this->ThisFileInfo['tags'][$TagFormat]); + } + + return true; + } + + public function FormatDataForAPE() + { + $ape_tag_data = []; + foreach ($this->tag_data as $tag_key => $valuearray) { + switch ($tag_key) { + case 'ATTACHED_PICTURE': + // ATTACHED_PICTURE is ID3v2 only - ignore + $this->warnings[] = '$data['.$tag_key.'] is assumed to be ID3v2 APIC data - NOT written to APE tag'; + break; + + default: + foreach ($valuearray as $key => $value) { + if (is_string($value) || is_numeric($value)) { + $ape_tag_data[$tag_key][$key] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value); + } else { + $this->warnings[] = '$data['.$tag_key.']['.$key.'] is not a string value - all of $data['.$tag_key.'] NOT written to APE tag'; + unset($ape_tag_data[$tag_key]); + break; + } + } + break; + } + } + $this->MergeExistingTagData('ape', $ape_tag_data); + + return $ape_tag_data; + } + + public function FormatDataForID3v1() + { + $tag_data_id3v1['genreid'] = 255; + if (! empty($this->tag_data['GENRE'])) { + foreach ($this->tag_data['GENRE'] as $key => $value) { + if (getid3_id3v1::LookupGenreID($value) !== false) { + $tag_data_id3v1['genreid'] = getid3_id3v1::LookupGenreID($value); + break; + } + } + } + $tag_data_id3v1['title'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['TITLE']) ? $this->tag_data['TITLE'] : []))); + $tag_data_id3v1['artist'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['ARTIST']) ? $this->tag_data['ARTIST'] : []))); + $tag_data_id3v1['album'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['ALBUM']) ? $this->tag_data['ALBUM'] : []))); + $tag_data_id3v1['year'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['YEAR']) ? $this->tag_data['YEAR'] : []))); + $tag_data_id3v1['comment'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['COMMENT']) ? $this->tag_data['COMMENT'] : []))); + $tag_data_id3v1['track'] = intval(getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['TRACKNUMBER']) ? $this->tag_data['TRACKNUMBER'] : [])))); + if ($tag_data_id3v1['track'] <= 0) { + $tag_data_id3v1['track'] = ''; + } + + $this->MergeExistingTagData('id3v1', $tag_data_id3v1); + + return $tag_data_id3v1; + } + + public function FormatDataForID3v2($id3v2_majorversion) + { + $tag_data_id3v2 = []; + + $ID3v2_text_encoding_lookup[2] = ['ISO-8859-1'=>0, 'UTF-16'=>1]; + $ID3v2_text_encoding_lookup[3] = ['ISO-8859-1'=>0, 'UTF-16'=>1]; + $ID3v2_text_encoding_lookup[4] = ['ISO-8859-1'=>0, 'UTF-16'=>1, 'UTF-16BE'=>2, 'UTF-8'=>3]; + foreach ($this->tag_data as $tag_key => $valuearray) { + $ID3v2_framename = getid3_write_id3v2::ID3v2ShortFrameNameLookup($id3v2_majorversion, $tag_key); + switch ($ID3v2_framename) { + case 'APIC': + foreach ($valuearray as $key => $apic_data_array) { + if (isset($apic_data_array['data']) && + isset($apic_data_array['picturetypeid']) && + isset($apic_data_array['description']) && + isset($apic_data_array['mime'])) { + $tag_data_id3v2['APIC'][] = $apic_data_array; + } else { + $this->errors[] = 'ID3v2 APIC data is not properly structured'; + + return false; + } + } + break; + + case 'POPM': + if (isset($valuearray['email']) && + isset($valuearray['rating']) && + isset($valuearray['data'])) { + $tag_data_id3v2['POPM'][] = $valuearray; + } else { + $this->errors[] = 'ID3v2 POPM data is not properly structured'; + + return false; + } + break; + + case 'GRID': + if ( + isset($valuearray['groupsymbol']) && + isset($valuearray['ownerid']) && + isset($valuearray['data']) + ) { + $tag_data_id3v2['GRID'][] = $valuearray; + } else { + $this->errors[] = 'ID3v2 GRID data is not properly structured'; + + return false; + } + break; + + case 'UFID': + if (isset($valuearray['ownerid']) && + isset($valuearray['data'])) { + $tag_data_id3v2['UFID'][] = $valuearray; + } else { + $this->errors[] = 'ID3v2 UFID data is not properly structured'; + + return false; + } + break; + + case 'TXXX': + foreach ($valuearray as $key => $txxx_data_array) { + if (isset($txxx_data_array['description']) && isset($txxx_data_array['data'])) { + $tag_data_id3v2['TXXX'][] = $txxx_data_array; + } else { + $this->errors[] = 'ID3v2 TXXX data is not properly structured'; + + return false; + } + } + break; + + case '': + $this->errors[] = 'ID3v2: Skipping "'.$tag_key.'" because cannot match it to a known ID3v2 frame type'; + // some other data type, don't know how to handle it, ignore it + break; + + default: + // most other (text) frames can be copied over as-is + foreach ($valuearray as $key => $value) { + if (isset($ID3v2_text_encoding_lookup[$id3v2_majorversion][$this->tag_encoding])) { + // source encoding is valid in ID3v2 - use it with no conversion + $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = $ID3v2_text_encoding_lookup[$id3v2_majorversion][$this->tag_encoding]; + $tag_data_id3v2[$ID3v2_framename][$key]['data'] = $value; + } else { + // source encoding is NOT valid in ID3v2 - convert it to an ID3v2-valid encoding first + if ($id3v2_majorversion < 4) { + // convert data from other encoding to UTF-16 (with BOM) + // note: some software, notably Windows Media Player and iTunes are broken and treat files tagged with UTF-16BE (with BOM) as corrupt + // therefore we force data to UTF-16LE and manually prepend the BOM + $ID3v2_tag_data_converted = false; + if (! $ID3v2_tag_data_converted && ($this->tag_encoding == 'ISO-8859-1')) { + // great, leave data as-is for minimum compatability problems + $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 0; + $tag_data_id3v2[$ID3v2_framename][$key]['data'] = $value; + $ID3v2_tag_data_converted = true; + } + if (! $ID3v2_tag_data_converted && ($this->tag_encoding == 'UTF-8')) { + do { + // if UTF-8 string does not include any characters above chr(127) then it is identical to ISO-8859-1 + for ($i = 0; $i < strlen($value); $i++) { + if (ord($value[$i]) > 127) { + break 2; + } + } + $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 0; + $tag_data_id3v2[$ID3v2_framename][$key]['data'] = $value; + $ID3v2_tag_data_converted = true; + } while (false); + } + if (! $ID3v2_tag_data_converted) { + $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 1; + //$tag_data_id3v2[$ID3v2_framename][$key]['data'] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-16', $value); // output is UTF-16LE+BOM or UTF-16BE+BOM depending on system architecture + $tag_data_id3v2[$ID3v2_framename][$key]['data'] = "\xFF\xFE".getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-16LE', $value); // force LittleEndian order version of UTF-16 + $ID3v2_tag_data_converted = true; + } + } else { + // convert data from other encoding to UTF-8 + $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 3; + $tag_data_id3v2[$ID3v2_framename][$key]['data'] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value); + } + } + + // These values are not needed for all frame types, but if they're not used no matter + $tag_data_id3v2[$ID3v2_framename][$key]['description'] = ''; + $tag_data_id3v2[$ID3v2_framename][$key]['language'] = $this->id3v2_tag_language; + } + break; + } + } + $this->MergeExistingTagData('id3v2', $tag_data_id3v2); + + return $tag_data_id3v2; + } + + public function FormatDataForVorbisComment() + { + $tag_data_vorbiscomment = $this->tag_data; + + // check for multi-line comment values - split out to multiple comments if neccesary + // and convert data to UTF-8 strings + foreach ($tag_data_vorbiscomment as $tag_key => $valuearray) { + foreach ($valuearray as $key => $value) { + str_replace("\r", "\n", $value); + if (strstr($value, "\n")) { + unset($tag_data_vorbiscomment[$tag_key][$key]); + $multilineexploded = explode("\n", $value); + foreach ($multilineexploded as $newcomment) { + if (strlen(trim($newcomment)) > 0) { + $tag_data_vorbiscomment[$tag_key][] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $newcomment); + } + } + } elseif (is_string($value) || is_numeric($value)) { + $tag_data_vorbiscomment[$tag_key][$key] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value); + } else { + $this->warnings[] = '$data['.$tag_key.']['.$key.'] is not a string value - all of $data['.$tag_key.'] NOT written to VorbisComment tag'; + unset($tag_data_vorbiscomment[$tag_key]); + break; + } + } + } + $this->MergeExistingTagData('vorbiscomment', $tag_data_vorbiscomment); + + return $tag_data_vorbiscomment; + } + + public function FormatDataForMetaFLAC() + { + // FLAC & OggFLAC use VorbisComments same as OggVorbis + // but require metaflac to do the writing rather than vorbiscomment + return $this->FormatDataForVorbisComment(); + } + + public function FormatDataForReal() + { + $tag_data_real['title'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['TITLE']) ? $this->tag_data['TITLE'] : []))); + $tag_data_real['artist'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['ARTIST']) ? $this->tag_data['ARTIST'] : []))); + $tag_data_real['copyright'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['COPYRIGHT']) ? $this->tag_data['COPYRIGHT'] : []))); + $tag_data_real['comment'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['COMMENT']) ? $this->tag_data['COMMENT'] : []))); + + $this->MergeExistingTagData('real', $tag_data_real); + + return $tag_data_real; + } } diff --git a/app/Library/getid3/getid3/write.real.php b/app/Library/getid3/getid3/write.real.php index fd67c859..0af44607 100644 --- a/app/Library/getid3/getid3/write.real.php +++ b/app/Library/getid3/getid3/write.real.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -16,259 +17,272 @@ class getid3_write_real { - public $filename; - public $tag_data = array(); - public $fread_buffer_size = 32768; // read buffer size in bytes - public $warnings = array(); // any non-critical errors will be stored here - public $errors = array(); // any critical errors will be stored here - public $paddedlength = 512; // minimum length of CONT tag in bytes + public $filename; + public $tag_data = []; + public $fread_buffer_size = 32768; // read buffer size in bytes + public $warnings = []; // any non-critical errors will be stored here + public $errors = []; // any critical errors will be stored here + public $paddedlength = 512; // minimum length of CONT tag in bytes - public function __construct() { - return true; - } + public function __construct() + { + return true; + } - public function WriteReal() { - // File MUST be writeable - CHMOD(646) at least - if (is_writeable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'r+b'))) { + public function WriteReal() + { + // File MUST be writeable - CHMOD(646) at least + if (is_writable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'r+b'))) { - // Initialize getID3 engine - $getID3 = new getID3; - $OldThisFileInfo = $getID3->analyze($this->filename); - if (empty($OldThisFileInfo['real']['chunks']) && !empty($OldThisFileInfo['real']['old_ra_header'])) { - $this->errors[] = 'Cannot write Real tags on old-style file format'; - fclose($fp_source); - return false; - } + // Initialize getID3 engine + $getID3 = new getID3; + $OldThisFileInfo = $getID3->analyze($this->filename); + if (empty($OldThisFileInfo['real']['chunks']) && ! empty($OldThisFileInfo['real']['old_ra_header'])) { + $this->errors[] = 'Cannot write Real tags on old-style file format'; + fclose($fp_source); - if (empty($OldThisFileInfo['real']['chunks'])) { - $this->errors[] = 'Cannot write Real tags because cannot find DATA chunk in file'; - fclose($fp_source); - return false; - } - foreach ($OldThisFileInfo['real']['chunks'] as $chunknumber => $chunkarray) { - $oldChunkInfo[$chunkarray['name']] = $chunkarray; - } - if (!empty($oldChunkInfo['CONT']['length'])) { - $this->paddedlength = max($oldChunkInfo['CONT']['length'], $this->paddedlength); - } + return false; + } - $new_CONT_tag_data = $this->GenerateCONTchunk(); - $new_PROP_tag_data = $this->GeneratePROPchunk($OldThisFileInfo['real']['chunks'], $new_CONT_tag_data); - $new__RMF_tag_data = $this->GenerateRMFchunk($OldThisFileInfo['real']['chunks']); + if (empty($OldThisFileInfo['real']['chunks'])) { + $this->errors[] = 'Cannot write Real tags because cannot find DATA chunk in file'; + fclose($fp_source); - if (isset($oldChunkInfo['.RMF']['length']) && ($oldChunkInfo['.RMF']['length'] == strlen($new__RMF_tag_data))) { - fseek($fp_source, $oldChunkInfo['.RMF']['offset']); - fwrite($fp_source, $new__RMF_tag_data); - } else { - $this->errors[] = 'new .RMF tag ('.strlen($new__RMF_tag_data).' bytes) different length than old .RMF tag ('.$oldChunkInfo['.RMF']['length'].' bytes)'; - fclose($fp_source); - return false; - } + return false; + } + foreach ($OldThisFileInfo['real']['chunks'] as $chunknumber => $chunkarray) { + $oldChunkInfo[$chunkarray['name']] = $chunkarray; + } + if (! empty($oldChunkInfo['CONT']['length'])) { + $this->paddedlength = max($oldChunkInfo['CONT']['length'], $this->paddedlength); + } - if (isset($oldChunkInfo['PROP']['length']) && ($oldChunkInfo['PROP']['length'] == strlen($new_PROP_tag_data))) { - fseek($fp_source, $oldChunkInfo['PROP']['offset']); - fwrite($fp_source, $new_PROP_tag_data); - } else { - $this->errors[] = 'new PROP tag ('.strlen($new_PROP_tag_data).' bytes) different length than old PROP tag ('.$oldChunkInfo['PROP']['length'].' bytes)'; - fclose($fp_source); - return false; - } + $new_CONT_tag_data = $this->GenerateCONTchunk(); + $new_PROP_tag_data = $this->GeneratePROPchunk($OldThisFileInfo['real']['chunks'], $new_CONT_tag_data); + $new__RMF_tag_data = $this->GenerateRMFchunk($OldThisFileInfo['real']['chunks']); - if (isset($oldChunkInfo['CONT']['length']) && ($oldChunkInfo['CONT']['length'] == strlen($new_CONT_tag_data))) { + if (isset($oldChunkInfo['.RMF']['length']) && ($oldChunkInfo['.RMF']['length'] == strlen($new__RMF_tag_data))) { + fseek($fp_source, $oldChunkInfo['.RMF']['offset']); + fwrite($fp_source, $new__RMF_tag_data); + } else { + $this->errors[] = 'new .RMF tag ('.strlen($new__RMF_tag_data).' bytes) different length than old .RMF tag ('.$oldChunkInfo['.RMF']['length'].' bytes)'; + fclose($fp_source); - // new data length is same as old data length - just overwrite - fseek($fp_source, $oldChunkInfo['CONT']['offset']); - fwrite($fp_source, $new_CONT_tag_data); - fclose($fp_source); - return true; + return false; + } - } else { + if (isset($oldChunkInfo['PROP']['length']) && ($oldChunkInfo['PROP']['length'] == strlen($new_PROP_tag_data))) { + fseek($fp_source, $oldChunkInfo['PROP']['offset']); + fwrite($fp_source, $new_PROP_tag_data); + } else { + $this->errors[] = 'new PROP tag ('.strlen($new_PROP_tag_data).' bytes) different length than old PROP tag ('.$oldChunkInfo['PROP']['length'].' bytes)'; + fclose($fp_source); - if (empty($oldChunkInfo['CONT'])) { - // no existing CONT chunk - $BeforeOffset = $oldChunkInfo['DATA']['offset']; - $AfterOffset = $oldChunkInfo['DATA']['offset']; - } else { - // new data is longer than old data - $BeforeOffset = $oldChunkInfo['CONT']['offset']; - $AfterOffset = $oldChunkInfo['CONT']['offset'] + $oldChunkInfo['CONT']['length']; - } - if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) { - if (is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) { + return false; + } - rewind($fp_source); - fwrite($fp_temp, fread($fp_source, $BeforeOffset)); - fwrite($fp_temp, $new_CONT_tag_data); - fseek($fp_source, $AfterOffset); - while ($buffer = fread($fp_source, $this->fread_buffer_size)) { - fwrite($fp_temp, $buffer, strlen($buffer)); - } - fclose($fp_temp); + if (isset($oldChunkInfo['CONT']['length']) && ($oldChunkInfo['CONT']['length'] == strlen($new_CONT_tag_data))) { - if (copy($tempfilename, $this->filename)) { - unlink($tempfilename); - fclose($fp_source); - return true; - } - unlink($tempfilename); - $this->errors[] = 'FAILED: copy('.$tempfilename.', '.$this->filename.')'; + // new data length is same as old data length - just overwrite + fseek($fp_source, $oldChunkInfo['CONT']['offset']); + fwrite($fp_source, $new_CONT_tag_data); + fclose($fp_source); - } else { - $this->errors[] = 'Could not fopen("'.$tempfilename.'", "wb")'; - } - } - fclose($fp_source); - return false; + return true; + } else { + if (empty($oldChunkInfo['CONT'])) { + // no existing CONT chunk + $BeforeOffset = $oldChunkInfo['DATA']['offset']; + $AfterOffset = $oldChunkInfo['DATA']['offset']; + } else { + // new data is longer than old data + $BeforeOffset = $oldChunkInfo['CONT']['offset']; + $AfterOffset = $oldChunkInfo['CONT']['offset'] + $oldChunkInfo['CONT']['length']; + } + if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) { + if (is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) { + rewind($fp_source); + fwrite($fp_temp, fread($fp_source, $BeforeOffset)); + fwrite($fp_temp, $new_CONT_tag_data); + fseek($fp_source, $AfterOffset); + while ($buffer = fread($fp_source, $this->fread_buffer_size)) { + fwrite($fp_temp, $buffer, strlen($buffer)); + } + fclose($fp_temp); - } + if (copy($tempfilename, $this->filename)) { + unlink($tempfilename); + fclose($fp_source); - } - $this->errors[] = 'Could not fopen("'.$this->filename.'", "r+b")'; - return false; - } + return true; + } + unlink($tempfilename); + $this->errors[] = 'FAILED: copy('.$tempfilename.', '.$this->filename.')'; + } else { + $this->errors[] = 'Could not fopen("'.$tempfilename.'", "wb")'; + } + } + fclose($fp_source); - public function GenerateRMFchunk(&$chunks) { - $oldCONTexists = false; - foreach ($chunks as $key => $chunk) { - $chunkNameKeys[$chunk['name']] = $key; - if ($chunk['name'] == 'CONT') { - $oldCONTexists = true; - } - } - $newHeadersCount = $chunks[$chunkNameKeys['.RMF']]['headers_count'] + ($oldCONTexists ? 0 : 1); + return false; + } + } + $this->errors[] = 'Could not fopen("'.$this->filename.'", "r+b")'; - $RMFchunk = "\x00\x00"; // object version - $RMFchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['.RMF']]['file_version'], 4); - $RMFchunk .= getid3_lib::BigEndian2String($newHeadersCount, 4); + return false; + } - $RMFchunk = '.RMF'.getid3_lib::BigEndian2String(strlen($RMFchunk) + 8, 4).$RMFchunk; // .RMF chunk identifier + chunk length - return $RMFchunk; - } + public function GenerateRMFchunk(&$chunks) + { + $oldCONTexists = false; + foreach ($chunks as $key => $chunk) { + $chunkNameKeys[$chunk['name']] = $key; + if ($chunk['name'] == 'CONT') { + $oldCONTexists = true; + } + } + $newHeadersCount = $chunks[$chunkNameKeys['.RMF']]['headers_count'] + ($oldCONTexists ? 0 : 1); - public function GeneratePROPchunk(&$chunks, &$new_CONT_tag_data) { - $old_CONT_length = 0; - $old_DATA_offset = 0; - $old_INDX_offset = 0; - foreach ($chunks as $key => $chunk) { - $chunkNameKeys[$chunk['name']] = $key; - if ($chunk['name'] == 'CONT') { - $old_CONT_length = $chunk['length']; - } elseif ($chunk['name'] == 'DATA') { - if (!$old_DATA_offset) { - $old_DATA_offset = $chunk['offset']; - } - } elseif ($chunk['name'] == 'INDX') { - if (!$old_INDX_offset) { - $old_INDX_offset = $chunk['offset']; - } - } - } - $CONTdelta = strlen($new_CONT_tag_data) - $old_CONT_length; + $RMFchunk = "\x00\x00"; // object version + $RMFchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['.RMF']]['file_version'], 4); + $RMFchunk .= getid3_lib::BigEndian2String($newHeadersCount, 4); - $PROPchunk = "\x00\x00"; // object version - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['max_bit_rate'], 4); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['avg_bit_rate'], 4); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['max_packet_size'], 4); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['avg_packet_size'], 4); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['num_packets'], 4); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['duration'], 4); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['preroll'], 4); - $PROPchunk .= getid3_lib::BigEndian2String(max(0, $old_INDX_offset + $CONTdelta), 4); - $PROPchunk .= getid3_lib::BigEndian2String(max(0, $old_DATA_offset + $CONTdelta), 4); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['num_streams'], 2); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['flags_raw'], 2); + $RMFchunk = '.RMF'.getid3_lib::BigEndian2String(strlen($RMFchunk) + 8, 4).$RMFchunk; // .RMF chunk identifier + chunk length - $PROPchunk = 'PROP'.getid3_lib::BigEndian2String(strlen($PROPchunk) + 8, 4).$PROPchunk; // PROP chunk identifier + chunk length - return $PROPchunk; - } + return $RMFchunk; + } - public function GenerateCONTchunk() { - foreach ($this->tag_data as $key => $value) { - // limit each value to 0xFFFF bytes - $this->tag_data[$key] = substr($value, 0, 65535); - } + public function GeneratePROPchunk(&$chunks, &$new_CONT_tag_data) + { + $old_CONT_length = 0; + $old_DATA_offset = 0; + $old_INDX_offset = 0; + foreach ($chunks as $key => $chunk) { + $chunkNameKeys[$chunk['name']] = $key; + if ($chunk['name'] == 'CONT') { + $old_CONT_length = $chunk['length']; + } elseif ($chunk['name'] == 'DATA') { + if (! $old_DATA_offset) { + $old_DATA_offset = $chunk['offset']; + } + } elseif ($chunk['name'] == 'INDX') { + if (! $old_INDX_offset) { + $old_INDX_offset = $chunk['offset']; + } + } + } + $CONTdelta = strlen($new_CONT_tag_data) - $old_CONT_length; - $CONTchunk = "\x00\x00"; // object version + $PROPchunk = "\x00\x00"; // object version + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['max_bit_rate'], 4); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['avg_bit_rate'], 4); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['max_packet_size'], 4); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['avg_packet_size'], 4); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['num_packets'], 4); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['duration'], 4); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['preroll'], 4); + $PROPchunk .= getid3_lib::BigEndian2String(max(0, $old_INDX_offset + $CONTdelta), 4); + $PROPchunk .= getid3_lib::BigEndian2String(max(0, $old_DATA_offset + $CONTdelta), 4); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['num_streams'], 2); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['flags_raw'], 2); - $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['title']) ? strlen($this->tag_data['title']) : 0), 2); - $CONTchunk .= (!empty($this->tag_data['title']) ? strlen($this->tag_data['title']) : ''); + $PROPchunk = 'PROP'.getid3_lib::BigEndian2String(strlen($PROPchunk) + 8, 4).$PROPchunk; // PROP chunk identifier + chunk length - $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['artist']) ? strlen($this->tag_data['artist']) : 0), 2); - $CONTchunk .= (!empty($this->tag_data['artist']) ? strlen($this->tag_data['artist']) : ''); + return $PROPchunk; + } - $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['copyright']) ? strlen($this->tag_data['copyright']) : 0), 2); - $CONTchunk .= (!empty($this->tag_data['copyright']) ? strlen($this->tag_data['copyright']) : ''); + public function GenerateCONTchunk() + { + foreach ($this->tag_data as $key => $value) { + // limit each value to 0xFFFF bytes + $this->tag_data[$key] = substr($value, 0, 65535); + } - $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['comment']) ? strlen($this->tag_data['comment']) : 0), 2); - $CONTchunk .= (!empty($this->tag_data['comment']) ? strlen($this->tag_data['comment']) : ''); + $CONTchunk = "\x00\x00"; // object version - if ($this->paddedlength > (strlen($CONTchunk) + 8)) { - $CONTchunk .= str_repeat("\x00", $this->paddedlength - strlen($CONTchunk) - 8); - } + $CONTchunk .= getid3_lib::BigEndian2String((! empty($this->tag_data['title']) ? strlen($this->tag_data['title']) : 0), 2); + $CONTchunk .= (! empty($this->tag_data['title']) ? strlen($this->tag_data['title']) : ''); - $CONTchunk = 'CONT'.getid3_lib::BigEndian2String(strlen($CONTchunk) + 8, 4).$CONTchunk; // CONT chunk identifier + chunk length + $CONTchunk .= getid3_lib::BigEndian2String((! empty($this->tag_data['artist']) ? strlen($this->tag_data['artist']) : 0), 2); + $CONTchunk .= (! empty($this->tag_data['artist']) ? strlen($this->tag_data['artist']) : ''); - return $CONTchunk; - } + $CONTchunk .= getid3_lib::BigEndian2String((! empty($this->tag_data['copyright']) ? strlen($this->tag_data['copyright']) : 0), 2); + $CONTchunk .= (! empty($this->tag_data['copyright']) ? strlen($this->tag_data['copyright']) : ''); - public function RemoveReal() { - // File MUST be writeable - CHMOD(646) at least - if (is_writeable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'r+b'))) { + $CONTchunk .= getid3_lib::BigEndian2String((! empty($this->tag_data['comment']) ? strlen($this->tag_data['comment']) : 0), 2); + $CONTchunk .= (! empty($this->tag_data['comment']) ? strlen($this->tag_data['comment']) : ''); - // Initialize getID3 engine - $getID3 = new getID3; - $OldThisFileInfo = $getID3->analyze($this->filename); - if (empty($OldThisFileInfo['real']['chunks']) && !empty($OldThisFileInfo['real']['old_ra_header'])) { - $this->errors[] = 'Cannot remove Real tags from old-style file format'; - fclose($fp_source); - return false; - } + if ($this->paddedlength > (strlen($CONTchunk) + 8)) { + $CONTchunk .= str_repeat("\x00", $this->paddedlength - strlen($CONTchunk) - 8); + } - if (empty($OldThisFileInfo['real']['chunks'])) { - $this->errors[] = 'Cannot remove Real tags because cannot find DATA chunk in file'; - fclose($fp_source); - return false; - } - foreach ($OldThisFileInfo['real']['chunks'] as $chunknumber => $chunkarray) { - $oldChunkInfo[$chunkarray['name']] = $chunkarray; - } + $CONTchunk = 'CONT'.getid3_lib::BigEndian2String(strlen($CONTchunk) + 8, 4).$CONTchunk; // CONT chunk identifier + chunk length - if (empty($oldChunkInfo['CONT'])) { - // no existing CONT chunk - fclose($fp_source); - return true; - } + return $CONTchunk; + } - $BeforeOffset = $oldChunkInfo['CONT']['offset']; - $AfterOffset = $oldChunkInfo['CONT']['offset'] + $oldChunkInfo['CONT']['length']; - if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) { - if (is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) { + public function RemoveReal() + { + // File MUST be writeable - CHMOD(646) at least + if (is_writable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'r+b'))) { - rewind($fp_source); - fwrite($fp_temp, fread($fp_source, $BeforeOffset)); - fseek($fp_source, $AfterOffset); - while ($buffer = fread($fp_source, $this->fread_buffer_size)) { - fwrite($fp_temp, $buffer, strlen($buffer)); - } - fclose($fp_temp); + // Initialize getID3 engine + $getID3 = new getID3; + $OldThisFileInfo = $getID3->analyze($this->filename); + if (empty($OldThisFileInfo['real']['chunks']) && ! empty($OldThisFileInfo['real']['old_ra_header'])) { + $this->errors[] = 'Cannot remove Real tags from old-style file format'; + fclose($fp_source); - if (copy($tempfilename, $this->filename)) { - unlink($tempfilename); - fclose($fp_source); - return true; - } - unlink($tempfilename); - $this->errors[] = 'FAILED: copy('.$tempfilename.', '.$this->filename.')'; + return false; + } - } else { - $this->errors[] = 'Could not fopen("'.$tempfilename.'", "wb")'; - } - } - fclose($fp_source); - return false; - } - $this->errors[] = 'Could not fopen("'.$this->filename.'", "r+b")'; - return false; - } + if (empty($OldThisFileInfo['real']['chunks'])) { + $this->errors[] = 'Cannot remove Real tags because cannot find DATA chunk in file'; + fclose($fp_source); + return false; + } + foreach ($OldThisFileInfo['real']['chunks'] as $chunknumber => $chunkarray) { + $oldChunkInfo[$chunkarray['name']] = $chunkarray; + } + + if (empty($oldChunkInfo['CONT'])) { + // no existing CONT chunk + fclose($fp_source); + + return true; + } + + $BeforeOffset = $oldChunkInfo['CONT']['offset']; + $AfterOffset = $oldChunkInfo['CONT']['offset'] + $oldChunkInfo['CONT']['length']; + if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) { + if (is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) { + rewind($fp_source); + fwrite($fp_temp, fread($fp_source, $BeforeOffset)); + fseek($fp_source, $AfterOffset); + while ($buffer = fread($fp_source, $this->fread_buffer_size)) { + fwrite($fp_temp, $buffer, strlen($buffer)); + } + fclose($fp_temp); + + if (copy($tempfilename, $this->filename)) { + unlink($tempfilename); + fclose($fp_source); + + return true; + } + unlink($tempfilename); + $this->errors[] = 'FAILED: copy('.$tempfilename.', '.$this->filename.')'; + } else { + $this->errors[] = 'Could not fopen("'.$tempfilename.'", "wb")'; + } + } + fclose($fp_source); + + return false; + } + $this->errors[] = 'Could not fopen("'.$this->filename.'", "r+b")'; + + return false; + } } diff --git a/app/Library/getid3/getid3/write.vorbiscomment.php b/app/Library/getid3/getid3/write.vorbiscomment.php index 971f91fe..51eb002f 100644 --- a/app/Library/getid3/getid3/write.vorbiscomment.php +++ b/app/Library/getid3/getid3/write.vorbiscomment.php @@ -1,4 +1,5 @@ // // available at http://getid3.sourceforge.net // @@ -14,107 +15,102 @@ // /// ///////////////////////////////////////////////////////////////// - class getid3_write_vorbiscomment { + public $filename; + public $tag_data; + public $warnings = []; // any non-critical errors will be stored here + public $errors = []; // any critical errors will be stored here - public $filename; - public $tag_data; - public $warnings = array(); // any non-critical errors will be stored here - public $errors = array(); // any critical errors will be stored here + public function __construct() + { + return true; + } - public function __construct() { - return true; - } + public function WriteVorbisComment() + { + if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { + $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call vorbiscomment, tags not written'; - public function WriteVorbisComment() { + return false; + } - if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { - $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call vorbiscomment, tags not written'; - return false; - } + // Create file with new comments + $tempcommentsfilename = tempnam(GETID3_TEMP_DIR, 'getID3'); + if (is_writable($tempcommentsfilename) && is_file($tempcommentsfilename) && ($fpcomments = fopen($tempcommentsfilename, 'wb'))) { + foreach ($this->tag_data as $key => $value) { + foreach ($value as $commentdata) { + fwrite($fpcomments, $this->CleanVorbisCommentName($key).'='.$commentdata."\n"); + } + } + fclose($fpcomments); + } else { + $this->errors[] = 'failed to open temporary tags file "'.$tempcommentsfilename.'", tags not written'; - // Create file with new comments - $tempcommentsfilename = tempnam(GETID3_TEMP_DIR, 'getID3'); - if (is_writable($tempcommentsfilename) && is_file($tempcommentsfilename) && ($fpcomments = fopen($tempcommentsfilename, 'wb'))) { + return false; + } - foreach ($this->tag_data as $key => $value) { - foreach ($value as $commentdata) { - fwrite($fpcomments, $this->CleanVorbisCommentName($key).'='.$commentdata."\n"); - } - } - fclose($fpcomments); + $oldignoreuserabort = ignore_user_abort(true); + if (GETID3_OS_ISWINDOWS) { + if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) { + //$commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w --raw -c "'.$tempcommentsfilename.'" "'.str_replace('/', '\\', $this->filename).'"'; + // vorbiscomment works fine if you copy-paste the above commandline into a command prompt, + // but refuses to work with `backtick` if there are "doublequotes" present around BOTH + // the metaflac pathname and the target filename. For whatever reason...?? + // The solution is simply ensure that the metaflac pathname has no spaces, + // and therefore does not need to be quoted - } else { - $this->errors[] = 'failed to open temporary tags file "'.$tempcommentsfilename.'", tags not written'; - return false; - } + // On top of that, if error messages are not always captured properly under Windows + // To at least see if there was a problem, compare file modification timestamps before and after writing + clearstatcache(); + $timestampbeforewriting = filemtime($this->filename); - $oldignoreuserabort = ignore_user_abort(true); - if (GETID3_OS_ISWINDOWS) { + $commandline = GETID3_HELPERAPPSDIR.'vorbiscomment.exe -w --raw -c "'.$tempcommentsfilename.'" "'.$this->filename.'" 2>&1'; + $VorbiscommentError = `$commandline`; - if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) { - //$commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w --raw -c "'.$tempcommentsfilename.'" "'.str_replace('/', '\\', $this->filename).'"'; - // vorbiscomment works fine if you copy-paste the above commandline into a command prompt, - // but refuses to work with `backtick` if there are "doublequotes" present around BOTH - // the metaflac pathname and the target filename. For whatever reason...?? - // The solution is simply ensure that the metaflac pathname has no spaces, - // and therefore does not need to be quoted + if (empty($VorbiscommentError)) { + clearstatcache(); + if ($timestampbeforewriting == filemtime($this->filename)) { + $VorbiscommentError = 'File modification timestamp has not changed - it looks like the tags were not written'; + } + } + } else { + $VorbiscommentError = 'vorbiscomment.exe not found in '.GETID3_HELPERAPPSDIR; + } + } else { + $commandline = 'vorbiscomment -w --raw -c "'.$tempcommentsfilename.'" "'.$this->filename.'" 2>&1'; + $VorbiscommentError = `$commandline`; + } - // On top of that, if error messages are not always captured properly under Windows - // To at least see if there was a problem, compare file modification timestamps before and after writing - clearstatcache(); - $timestampbeforewriting = filemtime($this->filename); + // Remove temporary comments file + unlink($tempcommentsfilename); + ignore_user_abort($oldignoreuserabort); - $commandline = GETID3_HELPERAPPSDIR.'vorbiscomment.exe -w --raw -c "'.$tempcommentsfilename.'" "'.$this->filename.'" 2>&1'; - $VorbiscommentError = `$commandline`; + if (! empty($VorbiscommentError)) { + $this->errors[] = 'system call to vorbiscomment failed with message: '."\n\n".$VorbiscommentError; - if (empty($VorbiscommentError)) { - clearstatcache(); - if ($timestampbeforewriting == filemtime($this->filename)) { - $VorbiscommentError = 'File modification timestamp has not changed - it looks like the tags were not written'; - } - } - } else { - $VorbiscommentError = 'vorbiscomment.exe not found in '.GETID3_HELPERAPPSDIR; - } + return false; + } - } else { + return true; + } - $commandline = 'vorbiscomment -w --raw -c "'.$tempcommentsfilename.'" "'.$this->filename.'" 2>&1'; - $VorbiscommentError = `$commandline`; + public function DeleteVorbisComment() + { + $this->tag_data = [[]]; - } + return $this->WriteVorbisComment(); + } - // Remove temporary comments file - unlink($tempcommentsfilename); - ignore_user_abort($oldignoreuserabort); - - if (!empty($VorbiscommentError)) { - - $this->errors[] = 'system call to vorbiscomment failed with message: '."\n\n".$VorbiscommentError; - return false; - - } - - return true; - } - - public function DeleteVorbisComment() { - $this->tag_data = array(array()); - return $this->WriteVorbisComment(); - } - - public function CleanVorbisCommentName($originalcommentname) { - // A case-insensitive field name that may consist of ASCII 0x20 through 0x7D, 0x3D ('=') excluded. - // ASCII 0x41 through 0x5A inclusive (A-Z) is to be considered equivalent to ASCII 0x61 through - // 0x7A inclusive (a-z). - - // replace invalid chars with a space, return uppercase text - // Thanks Chris Bolt for improving this function - // note: *reg_replace() replaces nulls with empty string (not space) - return strtoupper(preg_replace('#[^ -<>-}]#', ' ', str_replace("\x00", ' ', $originalcommentname))); - - } + public function CleanVorbisCommentName($originalcommentname) + { + // A case-insensitive field name that may consist of ASCII 0x20 through 0x7D, 0x3D ('=') excluded. + // ASCII 0x41 through 0x5A inclusive (A-Z) is to be considered equivalent to ASCII 0x61 through + // 0x7A inclusive (a-z). + // replace invalid chars with a space, return uppercase text + // Thanks Chris Bolt for improving this function + // note: *reg_replace() replaces nulls with empty string (not space) + return strtoupper(preg_replace('#[^ -<>-}]#', ' ', str_replace("\x00", ' ', $originalcommentname))); + } } diff --git a/app/Mail/BaseNotification.php b/app/Mail/BaseNotification.php index f999266e..591b8650 100644 --- a/app/Mail/BaseNotification.php +++ b/app/Mail/BaseNotification.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,14 +20,15 @@ namespace App\Mail; +use App\Models\Activity; +use App\Models\Email; use Carbon\Carbon; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; -use App\Models\Activity; -use App\Models\Email; -abstract class BaseNotification extends Mailable { +abstract class BaseNotification extends Mailable +{ use Queueable, SerializesModels; /** @var Email */ @@ -47,7 +48,8 @@ abstract class BaseNotification extends Mailable { * * @param Email $email */ - public function __construct(Email $email) { + public function __construct(Email $email) + { $this->emailRecord = $email; $this->notificationRecord = $email->notification; $this->activityRecord = $email->notification->activity; @@ -62,7 +64,8 @@ abstract class BaseNotification extends Mailable { * @param Email $email * @return BaseNotification */ - static public function factory(Activity $activity, Email $email): BaseNotification { + public static function factory(Activity $activity, Email $email): self + { switch ($activity->activity_type) { case Activity::TYPE_NEWS: break; @@ -96,7 +99,8 @@ abstract class BaseNotification extends Mailable { * * @return string */ - protected function generateUnsubscribeUrl() { + protected function generateUnsubscribeUrl() + { return route('email:unsubscribe', ['subscriptionKey' => $this->emailRecord->getSubscription()->id]); } @@ -105,7 +109,8 @@ abstract class BaseNotification extends Mailable { * * @return string */ - protected function generateNotificationUrl() { + protected function generateNotificationUrl() + { return route('email:click', ['emailKey' => $this->emailRecord->id]); } @@ -121,7 +126,8 @@ abstract class BaseNotification extends Mailable { * @param array $extraVariables * @return $this */ - protected function renderEmail(string $templateName, string $subject, array $extraVariables) { + protected function renderEmail(string $templateName, string $subject, array $extraVariables) + { return $this ->subject($subject) ->view("emails.html.notifications.{$templateName}") diff --git a/app/Mail/ContentFavourited.php b/app/Mail/ContentFavourited.php index fd04e57c..004cc849 100644 --- a/app/Mail/ContentFavourited.php +++ b/app/Mail/ContentFavourited.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -23,7 +23,7 @@ namespace App\Mail; class ContentFavourited extends BaseNotification { /** - * @inheritdoc + * {@inheritdoc} */ public function build() { diff --git a/app/Mail/NewComment.php b/app/Mail/NewComment.php index 80acc135..fcfdb65a 100644 --- a/app/Mail/NewComment.php +++ b/app/Mail/NewComment.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,11 +20,10 @@ namespace App\Mail; - class NewComment extends BaseNotification { /** - * @inheritdoc + * {@inheritdoc} */ public function build() { @@ -49,6 +48,5 @@ class NewComment extends BaseNotification 'comment' => $this->activityRecord->resource->content, ]); } - } } diff --git a/app/Mail/NewFollower.php b/app/Mail/NewFollower.php index 4f8d0932..8c69a9d5 100644 --- a/app/Mail/NewFollower.php +++ b/app/Mail/NewFollower.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -23,7 +23,7 @@ namespace App\Mail; class NewFollower extends BaseNotification { /** - * @inheritdoc + * {@inheritdoc} */ public function build() { diff --git a/app/Mail/NewPlaylist.php b/app/Mail/NewPlaylist.php index 7ffa181b..cd31250a 100644 --- a/app/Mail/NewPlaylist.php +++ b/app/Mail/NewPlaylist.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -23,7 +23,7 @@ namespace App\Mail; class NewPlaylist extends BaseNotification { /** - * @inheritdoc + * {@inheritdoc} */ public function build() { diff --git a/app/Mail/NewTrack.php b/app/Mail/NewTrack.php index b83946d9..33c145d2 100644 --- a/app/Mail/NewTrack.php +++ b/app/Mail/NewTrack.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -23,7 +23,7 @@ namespace App\Mail; class NewTrack extends BaseNotification { /** - * @inheritdoc + * {@inheritdoc} */ public function build() { @@ -36,7 +36,7 @@ class NewTrack extends BaseNotification [ 'creatorName' => $creatorName, 'trackTitle' => $trackTitle, - 'genreTitle' => $this->activityRecord->resource->genre->name + 'genreTitle' => $this->activityRecord->resource->genre->name, ]); } } diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 8f22302d..f4eae1af 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -24,14 +24,14 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; /** - * App\Models\Activity + * App\Models\Activity. * - * @property integer $id + * @property int $id * @property \Carbon\Carbon $created_at - * @property integer $user_id - * @property boolean $activity_type - * @property boolean $resource_type - * @property integer $resource_id + * @property int $user_id + * @property bool $activity_type + * @property bool $resource_type + * @property int $resource_id * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Notification[] $notifications * @property-read \App\Models\User $initiatingUser * @property-read \App\Models\Activity $resource @@ -88,12 +88,12 @@ class Activity extends Model * Activity types to subscribe new users to email notifications for. */ const DEFAULT_EMAIL_TYPES = [ - Activity::TYPE_PUBLISHED_TRACK, - Activity::TYPE_PUBLISHED_ALBUM, - Activity::TYPE_PUBLISHED_PLAYLIST, - Activity::TYPE_NEW_FOLLOWER, - Activity::TYPE_NEW_COMMENT, - Activity::TYPE_CONTENT_FAVOURITED, + self::TYPE_PUBLISHED_TRACK, + self::TYPE_PUBLISHED_ALBUM, + self::TYPE_PUBLISHED_PLAYLIST, + self::TYPE_NEW_FOLLOWER, + self::TYPE_NEW_COMMENT, + self::TYPE_CONTENT_FAVOURITED, ]; /** @@ -122,7 +122,7 @@ class Activity extends Model { return $this->hasMany(Notification::class, 'activity_id', 'id'); } - + public function notificationRecipients() { return $this->hasManyThrough(User::class, Notification::class, 'activity_id', 'user_id', 'id'); @@ -141,7 +141,7 @@ class Activity extends Model return $this->resource->url; } } - + public function getResourceTypeAttribute($value) { switch ($value) { @@ -159,7 +159,7 @@ class Activity extends Model case static::TARGET_COMMENT: return Comment::class; - + default: // Null must be returned here for Eloquent's eager-loading // of the polymorphic relation to work. @@ -220,21 +220,20 @@ class Activity extends Model public function getTitleFromActivityType() { - switch ($this->activity_type) { case static::TYPE_PUBLISHED_TRACK: - return "Pony.fm - New track"; + return 'Pony.fm - New track'; case static::TYPE_PUBLISHED_PLAYLIST: - return "Pony.fm - New playlist"; + return 'Pony.fm - New playlist'; case static::TYPE_NEW_FOLLOWER: - return "Pony.fm - New follower"; + return 'Pony.fm - New follower'; case static::TYPE_NEW_COMMENT: - return "Pony.fm - New comment"; + return 'Pony.fm - New comment'; case static::TYPE_CONTENT_FAVOURITED: - return "Pony.fm - Favourited"; + return 'Pony.fm - Favourited'; default: - return "Pony.fm - Unknown"; + return 'Pony.fm - Unknown'; } } @@ -247,7 +246,7 @@ class Activity extends Model */ public function getResourceTypeString():string { - switch($this->activity_type) { + switch ($this->activity_type) { case static::TYPE_NEW_COMMENT: return $this->resource->resource->getResourceType(); case static::TYPE_CONTENT_FAVOURITED: @@ -259,7 +258,8 @@ class Activity extends Model /** * @return bool */ - public function isProfileComment():bool { + public function isProfileComment():bool + { return static::TYPE_NEW_COMMENT === $this->activity_type && User::class === $this->resource->getResourceClass(); } @@ -277,7 +277,6 @@ class Activity extends Model case static::TYPE_NEWS: // not implemented yet throw new \InvalidArgumentException('This type of activity has not been implemented yet!'); - case static::TYPE_PUBLISHED_TRACK: return "{$this->resource->user->display_name} published a new track, {$this->resource->title}!"; @@ -295,7 +294,7 @@ class Activity extends Model } else { return "{$this->initiatingUser->display_name} left a comment on your {$this->getResourceTypeString()}, \"{$this->resource->resource->title}\"!"; } - + case static::TYPE_CONTENT_FAVOURITED: return "{$this->initiatingUser->display_name} favourited your {$this->getResourceTypeString()}, \"{$this->resource->title}\"!"; diff --git a/app/Models/Album.php b/app/Models/Album.php index e8603f24..aa083367 100644 --- a/app/Models/Album.php +++ b/app/Models/Album.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,39 +20,39 @@ namespace App\Models; -use DB; -use Exception; -use Helpers; -use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\HasMany; -use Illuminate\Database\Eloquent\Relations\MorphMany; -use Illuminate\Database\Eloquent\SoftDeletes; -use Auth; -use Gate; -use Cache; use App\Contracts\Commentable; use App\Contracts\Favouritable; use App\Contracts\Searchable; use App\Exceptions\TrackFileNotFoundException; use App\Traits\IndexedInElasticsearchTrait; -use App\Traits\TrackCollection; use App\Traits\SlugTrait; +use App\Traits\TrackCollection; +use Auth; +use Cache; +use DB; +use Exception; +use Gate; +use Helpers; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\MorphMany; +use Illuminate\Database\Eloquent\SoftDeletes; use Venturecraft\Revisionable\RevisionableTrait; /** - * App\Models\Album + * App\Models\Album. * - * @property integer $id - * @property integer $user_id + * @property int $id + * @property int $user_id * @property string $title * @property string $slug * @property string $description - * @property integer $cover_id - * @property integer $track_count - * @property integer $view_count - * @property integer $download_count - * @property integer $favourite_count - * @property integer $comment_count + * @property int $cover_id + * @property int $track_count + * @property int $view_count + * @property int $download_count + * @property int $favourite_count + * @property int $comment_count * @property \Carbon\Carbon $created_at * @property string $updated_at * @property \Carbon\Carbon $deleted_at @@ -118,7 +118,7 @@ class Album extends Model implements Searchable, Commentable, Favouritable $query->with([ 'users' => function ($query) { $query->whereUserId(Auth::user()->id); - } + }, ]); } @@ -155,6 +155,7 @@ class Album extends Model implements Searchable, Commentable, Favouritable public function trackFiles() { $trackIds = $this->tracks->pluck('id'); + return TrackFile::join('tracks', 'tracks.current_version', '=', 'track_files.version')->whereIn('track_id', $trackIds); } @@ -168,7 +169,7 @@ class Album extends Model implements Searchable, Commentable, Favouritable return $this->morphMany(Activity::class, 'resource'); } - public static function mapPublicAlbumShow(Album $album) + public static function mapPublicAlbumShow(self $album) { $tracks = []; foreach ($album->tracks as $track) { @@ -177,7 +178,7 @@ class Album extends Model implements Searchable, Commentable, Favouritable $formats = []; foreach (Track::$Formats as $name => $format) { - if (in_array($name, Track::$LosslessFormats) && !$album->hasLosslessTracksOnly() && !$album->hasLosslessTracks()) { + if (in_array($name, Track::$LosslessFormats) && ! $album->hasLosslessTracksOnly() && ! $album->hasLosslessTracks()) { continue; } @@ -187,10 +188,10 @@ class Album extends Model implements Searchable, Commentable, Favouritable 'url' => $album->getDownloadUrl($name), 'size' => Helpers::formatBytes($album->getFilesize($name)), 'isCacheable' => (in_array($name, Track::$CacheableFormats) ? true : false), - 'isMixedLosslessness' => (in_array($name, Track::$LosslessFormats) && !$album->hasLosslessTracksOnly() && $album->hasLosslessTracks()) + 'isMixedLosslessness' => (in_array($name, Track::$LosslessFormats) && ! $album->hasLosslessTracksOnly() && $album->hasLosslessTracks()), ]; } - + $comments = []; foreach ($album->comments as $comment) { $comments[] = Comment::mapPublic($comment); @@ -213,20 +214,20 @@ class Album extends Model implements Searchable, Commentable, Favouritable $data['share'] = [ 'url' => action('AlbumsController@getShortlink', ['id' => $album->id]), 'tumblrUrl' => 'http://www.tumblr.com/share/link?url='.urlencode($album->url).'&name='.urlencode($album->title).'&description='.urlencode($album->description), - 'twitterUrl' => 'https://platform.twitter.com/widgets/tweet_button.html?text='.$album->title.' by '.$album->user->display_name.' on Pony.fm' + 'twitterUrl' => 'https://platform.twitter.com/widgets/tweet_button.html?text='.$album->title.' by '.$album->user->display_name.' on Pony.fm', ]; return $data; } - public static function mapPublicAlbumSummary(Album $album) + public static function mapPublicAlbumSummary(self $album) { $userData = [ 'stats' => [ 'views' => 0, - 'downloads' => 0 + 'downloads' => 0, ], - 'is_favourited' => false + 'is_favourited' => false, ]; if (Auth::check() && $album->users->count()) { @@ -236,7 +237,7 @@ class Album extends Model implements Searchable, Commentable, Favouritable 'views' => (int) $userRow->view_count, 'downloads' => (int) $userRow->download_count, ], - 'is_favourited' => (bool) $userRow->is_favourited + 'is_favourited' => (bool) $userRow->is_favourited, ]; } @@ -250,12 +251,12 @@ class Album extends Model implements Searchable, Commentable, Favouritable 'views' => (int) $album->view_count, 'downloads' => (int) $album->download_count, 'comments' => (int) $album->comment_count, - 'favourites' => (int) $album->favourite_count + 'favourites' => (int) $album->favourite_count, ], 'covers' => [ 'small' => $album->getCoverUrl(Image::SMALL), 'normal' => $album->getCoverUrl(Image::NORMAL), - 'original' => $album->getCoverUrl(Image::ORIGINAL) + 'original' => $album->getCoverUrl(Image::ORIGINAL), ], 'url' => $album->url, 'user' => [ @@ -267,8 +268,8 @@ class Album extends Model implements Searchable, Commentable, Favouritable 'user_data' => $userData, 'permissions' => [ 'delete' => Gate::allows('delete', $album), - 'edit' => Gate::allows('edit', $album) - ] + 'edit' => Gate::allows('edit', $album), + ], ]; } @@ -289,7 +290,7 @@ class Album extends Model implements Searchable, Commentable, Favouritable public function getCoverUrl($type = Image::NORMAL) { - if (!$this->hasCover()) { + if (! $this->hasCover()) { return $this->user->getAvatarUrl($type); } @@ -310,7 +311,7 @@ class Album extends Model implements Searchable, Commentable, Favouritable public function getFilenameFor($format) { - if (!isset(Track::$Formats[$format])) { + if (! isset(Track::$Formats[$format])) { throw new Exception("$format is not a valid format!"); } @@ -326,7 +327,6 @@ class Album extends Model implements Searchable, Commentable, Favouritable foreach ($tracks as $track) { /** @var $track Track */ - $track->track_number = $index; $index++; $track->updateTags(); @@ -369,7 +369,7 @@ class Album extends Model implements Searchable, Commentable, Favouritable } foreach ($trackIds as $trackId) { - if (!strlen(trim($trackId))) { + if (! strlen(trim($trackId))) { continue; } @@ -391,7 +391,6 @@ class Album extends Model implements Searchable, Commentable, Favouritable foreach ($tracksToRemove as $track) { /** @var $track Track */ - $track->album_id = null; $track->track_number = null; $track->updateTags(); @@ -400,7 +399,6 @@ class Album extends Model implements Searchable, Commentable, Favouritable foreach ($albumsToFix as $album) { /** @var $album Album */ - $album->updateTrackNumbers(); } @@ -427,6 +425,7 @@ class Album extends Model implements Searchable, Commentable, Favouritable public function save(array $options = []) { $this->recountTracks(); + return parent::save($options); } @@ -459,11 +458,11 @@ class Album extends Model implements Searchable, Commentable, Favouritable } /** - * @inheritdoc + * {@inheritdoc} */ public function shouldBeIndexed():bool { - return $this->track_count > 0 && !$this->trashed(); + return $this->track_count > 0 && ! $this->trashed(); } /** diff --git a/app/Models/AlexaSession.php b/app/Models/AlexaSession.php index 521e7ef8..07774dfc 100644 --- a/app/Models/AlexaSession.php +++ b/app/Models/AlexaSession.php @@ -5,7 +5,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; /** - * App\Models\AlexaSession + * App\Models\AlexaSession. * * @property string $id * @property string $payload @@ -24,7 +24,7 @@ class AlexaSession extends Model protected $table = 'alexa_session'; protected $casts = [ - 'payload' => 'array' + 'payload' => 'array', ]; public function put($key, $value) diff --git a/app/Models/Announcement.php b/app/Models/Announcement.php index 5e5790f0..1ea9bebe 100644 --- a/app/Models/Announcement.php +++ b/app/Models/Announcement.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Logic + * Copyright (C) 2016 Logic. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -23,12 +23,12 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; /** - * App\Models\Announcement + * App\Models\Announcement. * - * @property integer $id + * @property int $id * @property string $title * @property string $text_content - * @property integer $announcement_type_id + * @property int $announcement_type_id * @property mixed $links * @property mixed $tracks * @property string $css_class @@ -47,12 +47,13 @@ use Illuminate\Database\Eloquent\Model; * @method static \Illuminate\Database\Query\Builder|\App\Models\Announcement whereEndTime($value) * @mixin \Eloquent */ -class Announcement extends Model { +class Announcement extends Model +{ protected $table = 'announcements'; protected $casts = [ 'links' => 'array', - 'tracks' => 'array' + 'tracks' => 'array', ]; const TYPE_GENERIC = 1; diff --git a/app/Models/Comment.php b/app/Models/Comment.php index 1d842482..0a1706ea 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,26 +20,26 @@ namespace App\Models; +use App\Contracts\Commentable; use DB; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\SoftDeletes; -use App\Contracts\Commentable; /** - * App\Models\Comment + * App\Models\Comment. * - * @property integer $id - * @property integer $user_id + * @property int $id + * @property int $user_id * @property string $ip_address * @property string $content * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at * @property \Carbon\Carbon $deleted_at - * @property integer $profile_id - * @property integer $track_id - * @property integer $album_id - * @property integer $playlist_id + * @property int $profile_id + * @property int $track_id + * @property int $album_id + * @property int $playlist_id * @property-read \App\Models\User $user * @property-read \App\Models\Track $track * @property-read \App\Models\Album $album @@ -123,8 +123,8 @@ class Comment extends Model 'normal' => $comment->user->getAvatarUrl(Image::NORMAL), 'thumbnail' => $comment->user->getAvatarUrl(Image::THUMBNAIL), 'small' => $comment->user->getAvatarUrl(Image::SMALL), - ] - ] + ], + ], ]; } @@ -157,7 +157,8 @@ class Comment extends Model * * @return string */ - public function getResourceClass():string { + public function getResourceClass():string + { return get_class($this->resource); } diff --git a/app/Models/Email.php b/app/Models/Email.php index 2814de45..782dcbc5 100644 --- a/app/Models/Email.php +++ b/app/Models/Email.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -21,14 +21,14 @@ namespace App\Models; use Alsofronie\Uuid\UuidModelTrait; -use Illuminate\Database\Eloquent\Model; use App\Models\Notification; +use Illuminate\Database\Eloquent\Model; /** - * App\Models\Email + * App\Models\Email. * * @property string $id - * @property integer $notification_id + * @property int $notification_id * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at * @property-read \App\Models\Notification $notification @@ -45,23 +45,28 @@ class Email extends Model // Non-sequential UUID's are desirable for this model. protected $uuidVersion = 4; - public function notification() { + public function notification() + { return $this->belongsTo(Notification::class, 'notification_id', 'id', 'notifications'); } - public function emailClicks() { + public function emailClicks() + { return $this->hasMany(EmailClick::class, 'email_id', 'id'); } - public function getActivity():Activity { + public function getActivity():Activity + { return $this->notification->activity; } - public function getUser():User { + public function getUser():User + { return $this->notification->recipient; } - public function getSubscription():EmailSubscription { + public function getSubscription():EmailSubscription + { return $this ->getUser() ->emailSubscriptions() diff --git a/app/Models/EmailClick.php b/app/Models/EmailClick.php index 6d0b442e..9568f33a 100644 --- a/app/Models/EmailClick.php +++ b/app/Models/EmailClick.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -24,7 +24,7 @@ use Alsofronie\Uuid\UuidModelTrait; use Illuminate\Database\Eloquent\Model; /** - * App\Models\EmailClick + * App\Models\EmailClick. * * @property string $id * @property string $email_id @@ -45,7 +45,8 @@ class EmailClick extends Model protected $fillable = ['ip_address']; - public function email() { + public function email() + { return $this->belongsTo(Email::class, 'email_id', 'id', 'emails'); } } diff --git a/app/Models/EmailSubscription.php b/app/Models/EmailSubscription.php index 4d013383..1f2d2c7a 100644 --- a/app/Models/EmailSubscription.php +++ b/app/Models/EmailSubscription.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -21,16 +21,16 @@ namespace App\Models; use Alsofronie\Uuid\UuidModelTrait; +use App\Models\User; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; -use App\Models\User; /** - * App\EmailSubscription + * App\EmailSubscription. * * @property string $id - * @property integer $user_id - * @property integer $activity_type + * @property int $user_id + * @property int $activity_type * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at * @property string $deleted_at @@ -56,7 +56,8 @@ class EmailSubscription extends Model protected $fillable = ['activity_type']; - public function user() { + public function user() + { return $this->belongsTo(User::class, 'user_id', 'id', 'users'); } } diff --git a/app/Models/Favourite.php b/app/Models/Favourite.php index 0c2500e1..33df34d8 100644 --- a/app/Models/Favourite.php +++ b/app/Models/Favourite.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -23,13 +23,13 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; /** - * App\Models\Favourite + * App\Models\Favourite. * - * @property integer $id - * @property integer $user_id - * @property integer $track_id - * @property integer $album_id - * @property integer $playlist_id + * @property int $id + * @property int $user_id + * @property int $track_id + * @property int $album_id + * @property int $playlist_id * @property string $created_at * @property-read \App\Models\User $user * @property-read \App\Models\Track $track @@ -79,7 +79,7 @@ class Favourite extends Model /** * Return the resource associated with this favourite. * - * @return Resource|NULL + * @return resource|null */ public function getResourceAttribute() { diff --git a/app/Models/Follower.php b/app/Models/Follower.php index a0a07238..70e7f364 100644 --- a/app/Models/Follower.php +++ b/app/Models/Follower.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -24,12 +24,12 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; /** - * App\Models\Follower + * App\Models\Follower. * - * @property integer $id - * @property integer $user_id - * @property integer $artist_id - * @property integer $playlist_id + * @property int $id + * @property int $user_id + * @property int $artist_id + * @property int $playlist_id * @property string $created_at * @property-read \App\Models\User $follower * @property-read \App\Models\User $artist @@ -46,7 +46,6 @@ class Follower extends Model public $timestamps = false; - public function follower():BelongsTo { return $this->belongsTo(User::class, 'user_id'); diff --git a/app/Models/Genre.php b/app/Models/Genre.php index d652c46d..c1548b79 100644 --- a/app/Models/Genre.php +++ b/app/Models/Genre.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,17 +20,17 @@ namespace App\Models; +use App\Traits\SlugTrait; use DB; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\SoftDeletes; -use App\Traits\SlugTrait; -use Illuminate\Database\Eloquent\Model; use Venturecraft\Revisionable\RevisionableTrait; /** - * App\Models\Genre + * App\Models\Genre. * - * @property integer $id + * @property int $id * @property string $name * @property string $slug * @property string $deleted_at @@ -92,7 +92,7 @@ class Genre extends Model */ public function getTrackCountAttribute() { - if (!$this->relationLoaded('trackCountRelation')) { + if (! $this->relationLoaded('trackCountRelation')) { $this->load('trackCountRelation'); } diff --git a/app/Models/Image.php b/app/Models/Image.php index a9cf158a..0e85dda4 100644 --- a/app/Models/Image.php +++ b/app/Models/Image.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,9 +20,9 @@ namespace App\Models; +use Config; use External; use Illuminate\Database\Eloquent\Model; -use Config; use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; @@ -30,15 +30,15 @@ use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\File\UploadedFile; /** - * App\Models\Image + * App\Models\Image. * - * @property integer $id + * @property int $id * @property string $filename * @property string $mime * @property string $extension - * @property integer $size + * @property int $size * @property string $hash - * @property integer $uploaded_by + * @property int $uploaded_by * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at * @method static \Illuminate\Database\Query\Builder|\App\Models\Image whereId($value) @@ -63,7 +63,7 @@ class Image extends Model self::NORMAL => ['id' => self::NORMAL, 'name' => 'normal', 'width' => 350, 'height' => 350, 'geometry' => '350'], self::ORIGINAL => ['id' => self::ORIGINAL, 'name' => 'original', 'width' => null, 'height' => null, 'geometry' => null], self::SMALL => ['id' => self::SMALL, 'name' => 'small', 'width' => 100, 'height' => 100, 'geometry' => '100x100^'], - self::THUMBNAIL => ['id' => self::THUMBNAIL, 'name' => 'thumbnail', 'width' => 50, 'height' => 50, 'geometry' => '50x50^'] + self::THUMBNAIL => ['id' => self::THUMBNAIL, 'name' => 'thumbnail', 'width' => 50, 'height' => 50, 'geometry' => '50x50^'], ]; const MIME_JPEG = 'image/jpeg'; @@ -96,7 +96,7 @@ class Image extends Model } $hash = md5_file($file->getPathname()); - $image = Image::whereHash($hash)->whereUploadedBy($userId)->first(); + $image = self::whereHash($hash)->whereUploadedBy($userId)->first(); if ($image) { if ($forceReupload) { @@ -105,7 +105,7 @@ class Image extends Model return $image; } } else { - $image = new Image(); + $image = new self(); } try { @@ -136,12 +136,13 @@ class Image extends Model * @param string $path The path to save the processed image file * @param array $coverType The type to process the image to */ - private static function processFile(File $image, string $path, $coverType) { - if ($coverType['id'] === self::ORIGINAL && $image->getMimeType() === self::MIME_JPEG ){ - if($image->getPathname() === $path) { + private static function processFile(File $image, string $path, $coverType) + { + if ($coverType['id'] === self::ORIGINAL && $image->getMimeType() === self::MIME_JPEG) { + if ($image->getPathname() === $path) { Log::warning("Attempted to copy an original file $path to itself."); } else { - $command = 'cp "' . $image->getPathname() . '" ' . $path; + $command = 'cp "'.$image->getPathname().'" '.$path; } } else { // ImageMagick options reference: http://www.imagemagick.org/script/command-line-options.php @@ -197,26 +198,26 @@ class Image extends Model $destination = $this->getDirectory(); umask(0); - if (!is_dir($destination)) { + if (! is_dir($destination)) { mkdir($destination, 0777, true); } } /** - * Deletes any generated files if they exist + * Deletes any generated files if they exist. * @param bool $includeOriginal Set to true if the original image should be deleted as well. */ - public function clearExisting(bool $includeOriginal = false) { + public function clearExisting(bool $includeOriginal = false) + { $files = scandir($this->getDirectory()); $filePrefix = $this->id.'_'; - $originalName = $filePrefix.Image::$ImageTypes[Image::ORIGINAL]['name']; + $originalName = $filePrefix.self::$ImageTypes[self::ORIGINAL]['name']; - $files = array_filter($files, function($file) use ($originalName, $includeOriginal, $filePrefix) { - if (Str::startsWith($file,$originalName) && !$includeOriginal) { + $files = array_filter($files, function ($file) use ($originalName, $includeOriginal, $filePrefix) { + if (Str::startsWith($file, $originalName) && ! $includeOriginal) { return false; - } - else { - return (Str::startsWith($file, $filePrefix)); + } else { + return Str::startsWith($file, $filePrefix); } }); @@ -230,12 +231,13 @@ class Image extends Model * * @throws FileNotFoundException If the original file cannot be found. */ - public function buildCovers() { + public function buildCovers() + { $originalFile = new File($this->getFile(self::ORIGINAL)); foreach (self::$ImageTypes as $imageType) { //Ignore original imagetype - if($imageType['id'] === self::ORIGINAL) { + if ($imageType['id'] === self::ORIGINAL) { continue; } diff --git a/app/Models/License.php b/app/Models/License.php index 8a213f9a..8ac97b15 100644 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -23,14 +23,14 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; /** - * App\Models\License + * App\Models\License. * - * @property integer $id + * @property int $id * @property string $title * @property string $description - * @property boolean $affiliate_distribution - * @property boolean $open_distribution - * @property boolean $remix + * @property bool $affiliate_distribution + * @property bool $open_distribution + * @property bool $remix * @method static \Illuminate\Database\Query\Builder|\App\Models\License whereId($value) * @method static \Illuminate\Database\Query\Builder|\App\Models\License whereTitle($value) * @method static \Illuminate\Database\Query\Builder|\App\Models\License whereDescription($value) diff --git a/app/Models/Notification.php b/app/Models/Notification.php index f514203d..24b950ff 100644 --- a/app/Models/Notification.php +++ b/app/Models/Notification.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -24,12 +24,12 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; /** - * App\Models\Notification + * App\Models\Notification. * - * @property integer $id - * @property integer $activity_id - * @property integer $user_id - * @property boolean $is_read + * @property int $id + * @property int $activity_id + * @property int $user_id + * @property bool $is_read * @property-read \App\Models\Activity $activity * @property-read \App\Models\Email $email * @property-read \App\Models\User $recipient @@ -55,7 +55,7 @@ class Notification extends Model { return $this->belongsTo(Activity::class, 'activity_id', 'id'); } - + public function recipient() { return $this->belongsTo(User::class, 'user_id', 'id'); @@ -101,7 +101,7 @@ class Notification extends Model 'thumbnail_url' => $this->activity->thumbnail_url, 'text' => $this->activity->text, 'url' => $this->activity->url, - 'is_read' => $this->is_read + 'is_read' => $this->is_read, ]; } } diff --git a/app/Models/PinnedPlaylist.php b/app/Models/PinnedPlaylist.php index 1e5d8ea5..00a6f316 100644 --- a/app/Models/PinnedPlaylist.php +++ b/app/Models/PinnedPlaylist.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -23,11 +23,11 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; /** - * App\Models\PinnedPlaylist + * App\Models\PinnedPlaylist. * - * @property integer $id - * @property integer $user_id - * @property integer $playlist_id + * @property int $id + * @property int $user_id + * @property int $playlist_id * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at * @property-read \App\Models\User $user diff --git a/app/Models/Playlist.php b/app/Models/Playlist.php index bf2cb48c..cdee9ef4 100644 --- a/app/Models/Playlist.php +++ b/app/Models/Playlist.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,6 +20,15 @@ namespace App\Models; +use App\Contracts\Commentable; +use App\Contracts\Favouritable; +use App\Contracts\Searchable; +use App\Exceptions\TrackFileNotFoundException; +use App\Traits\IndexedInElasticsearchTrait; +use App\Traits\SlugTrait; +use App\Traits\TrackCollection; +use Auth; +use Cache; use DB; use Helpers; use Illuminate\Database\Eloquent\Model; @@ -27,32 +36,23 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Bus\DispatchesJobs; -use Auth; -use Cache; -use App\Contracts\Commentable; -use App\Contracts\Favouritable; -use App\Contracts\Searchable; -use App\Exceptions\TrackFileNotFoundException; -use App\Traits\IndexedInElasticsearchTrait; -use App\Traits\TrackCollection; -use App\Traits\SlugTrait; use Venturecraft\Revisionable\RevisionableTrait; /** - * App\Models\Playlist + * App\Models\Playlist. * - * @property integer $id - * @property integer $user_id + * @property int $id + * @property int $user_id * @property string $title * @property string $slug * @property string $description - * @property boolean $is_public - * @property integer $track_count - * @property integer $view_count - * @property integer $download_count - * @property integer $favourite_count - * @property integer $follow_count - * @property integer $comment_count + * @property bool $is_public + * @property int $track_count + * @property int $view_count + * @property int $download_count + * @property int $favourite_count + * @property int $follow_count + * @property int $comment_count * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at * @property \Carbon\Carbon $deleted_at @@ -134,25 +134,24 @@ class Playlist extends Model implements Searchable, Commentable, Favouritable $query->with([ 'users' => function ($query) { $query->whereUserId(Auth::user()->id); - } + }, ]); } return $query; } - public static function mapPublicPlaylistShow(Playlist $playlist) + public static function mapPublicPlaylistShow(self $playlist) { $tracks = []; foreach ($playlist->tracks as $track) { /** @var $track Track */ - $tracks[] = Track::mapPublicTrackSummary($track); } $formats = []; foreach (Track::$Formats as $name => $format) { - if (in_array($name, Track::$LosslessFormats) && !$playlist->hasLosslessTracksOnly() && !$playlist->hasLosslessTracks()) { + if (in_array($name, Track::$LosslessFormats) && ! $playlist->hasLosslessTracksOnly() && ! $playlist->hasLosslessTracks()) { continue; } @@ -162,7 +161,7 @@ class Playlist extends Model implements Searchable, Commentable, Favouritable 'url' => $playlist->getDownloadUrl($name), 'size' => Helpers::formatBytes($playlist->getFilesize($name)), 'isCacheable' => (in_array($name, Track::$CacheableFormats) ? true : false), - 'isMixedLosslessness' => (in_array($name, Track::$LosslessFormats) && !$playlist->hasLosslessTracksOnly() && $playlist->hasLosslessTracks()) + 'isMixedLosslessness' => (in_array($name, Track::$LosslessFormats) && ! $playlist->hasLosslessTracksOnly() && $playlist->hasLosslessTracks()), ]; } @@ -178,20 +177,20 @@ class Playlist extends Model implements Searchable, Commentable, Favouritable $data['share'] = [ 'url' => action('PlaylistsController@getShortlink', ['id' => $playlist->id]), 'tumblrUrl' => 'http://www.tumblr.com/share/link?url='.urlencode($playlist->url).'&name='.urlencode($playlist->title).'&description='.urlencode($playlist->description), - 'twitterUrl' => 'https://platform.twitter.com/widgets/tweet_button.html?text='.$playlist->title.' by '.$playlist->user->display_name.' on Pony.fm' + 'twitterUrl' => 'https://platform.twitter.com/widgets/tweet_button.html?text='.$playlist->title.' by '.$playlist->user->display_name.' on Pony.fm', ]; return $data; } - public static function mapPublicPlaylistSummary(Playlist $playlist) + public static function mapPublicPlaylistSummary(self $playlist) { $userData = [ 'stats' => [ 'views' => 0, - 'downloads' => 0 + 'downloads' => 0, ], - 'is_favourited' => false + 'is_favourited' => false, ]; if (Auth::check() && $playlist->users->count()) { @@ -201,7 +200,7 @@ class Playlist extends Model implements Searchable, Commentable, Favouritable 'views' => (int) $userRow->view_count, 'downloads' => (int) $userRow->download_count, ], - 'is_favourited' => (bool) $userRow->is_favourited + 'is_favourited' => (bool) $userRow->is_favourited, ]; } @@ -216,12 +215,12 @@ class Playlist extends Model implements Searchable, Commentable, Favouritable 'views' => (int) $playlist->view_count, 'downloads' => (int) $playlist->download_count, 'comments' => (int) $playlist->comment_count, - 'favourites' => (int) $playlist->favourite_count + 'favourites' => (int) $playlist->favourite_count, ], 'covers' => [ 'small' => $playlist->getCoverUrl(Image::SMALL), 'normal' => $playlist->getCoverUrl(Image::NORMAL), - 'original' => $playlist->getCoverUrl(Image::ORIGINAL) + 'original' => $playlist->getCoverUrl(Image::ORIGINAL), ], 'url' => $playlist->url, 'user' => [ @@ -232,8 +231,8 @@ class Playlist extends Model implements Searchable, Commentable, Favouritable 'user_data' => $userData, 'permissions' => [ 'delete' => Auth::check() && Auth::user()->id == $playlist->user_id, - 'edit' => Auth::check() && Auth::user()->id == $playlist->user_id - ] + 'edit' => Auth::check() && Auth::user()->id == $playlist->user_id, + ], ]; } @@ -259,6 +258,7 @@ class Playlist extends Model implements Searchable, Commentable, Favouritable public function trackFiles() { $trackIds = $this->tracks->pluck('id'); + return TrackFile::join('tracks', 'tracks.current_version', '=', 'track_files.version')->whereIn('track_id', $trackIds); } @@ -364,17 +364,17 @@ class Playlist extends Model implements Searchable, Commentable, Favouritable } /** - * @inheritdoc + * {@inheritdoc} */ public function shouldBeIndexed():bool { return $this->is_public && $this->track_count > 0 && - !$this->trashed(); + ! $this->trashed(); } /** - * @inheritdoc + * {@inheritdoc} */ public function getResourceType():string { diff --git a/app/Models/ResourceLogItem.php b/app/Models/ResourceLogItem.php index b4ab9793..40f16e49 100644 --- a/app/Models/ResourceLogItem.php +++ b/app/Models/ResourceLogItem.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,23 +20,23 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; -use Carbon\Carbon; use Auth; +use Carbon\Carbon; use DB; +use Illuminate\Database\Eloquent\Model; use Request; /** - * App\Models\ResourceLogItem + * App\Models\ResourceLogItem. * - * @property integer $id - * @property integer $user_id - * @property integer $log_type + * @property int $id + * @property int $user_id + * @property int $log_type * @property string $ip_address - * @property integer $track_format_id - * @property integer $track_id - * @property integer $album_id - * @property integer $playlist_id + * @property int $track_format_id + * @property int $track_id + * @property int $album_id + * @property int $playlist_id * @property \Carbon\Carbon $created_at * @method static \Illuminate\Database\Query\Builder|\App\Models\ResourceLogItem whereId($value) * @method static \Illuminate\Database\Query\Builder|\App\Models\ResourceLogItem whereUserId($value) @@ -63,7 +63,7 @@ class ResourceLogItem extends Model { $resourceIdColumn = $resourceType.'_id'; - $logItem = new ResourceLogItem(); + $logItem = new self(); $logItem->{$resourceIdColumn} = $resourceId; $logItem->created_at = Carbon::now(); $logItem->log_type = $logType; @@ -96,31 +96,29 @@ class ResourceLogItem extends Model // for the same resource at the same time, the cached values will still be correct with this method. DB::table($resourceTable)->whereId($resourceId)->update([ - $countColumn => - DB::raw('(SELECT + $countColumn => DB::raw('(SELECT COUNT(id) FROM resource_log_items - WHERE ' . + WHERE '. $resourceIdColumn.' = '.$resourceId.' AND - log_type = ' . $logType.')') + log_type = '.$logType.')'), ]); if (Auth::check()) { $resourceUserId = ResourceUser::getId(Auth::user()->id, $resourceType, $resourceId); DB::table('resource_users')->whereId($resourceUserId)->update([ - $countColumn => - DB::raw('(SELECT + $countColumn => DB::raw('(SELECT COUNT(id) FROM resource_log_items WHERE - user_id = ' . Auth::user()->id.' - AND ' . + user_id = '.Auth::user()->id.' + AND '. $resourceIdColumn.' = '.$resourceId.' AND - log_type = ' . $logType.')') + log_type = '.$logType.')'), ]); } } diff --git a/app/Models/ResourceUser.php b/app/Models/ResourceUser.php index 35969a90..68614c27 100644 --- a/app/Models/ResourceUser.php +++ b/app/Models/ResourceUser.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -23,20 +23,20 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; /** - * App\Models\ResourceUser + * App\Models\ResourceUser. * - * @property integer $id - * @property integer $user_id - * @property integer $track_id - * @property integer $album_id - * @property integer $playlist_id - * @property integer $artist_id - * @property boolean $is_followed - * @property boolean $is_favourited - * @property boolean $is_pinned - * @property integer $view_count - * @property integer $play_count - * @property integer $download_count + * @property int $id + * @property int $user_id + * @property int $track_id + * @property int $album_id + * @property int $playlist_id + * @property int $artist_id + * @property bool $is_followed + * @property bool $is_favourited + * @property bool $is_pinned + * @property int $view_count + * @property int $play_count + * @property int $download_count * @method static \Illuminate\Database\Query\Builder|\App\Models\ResourceUser whereId($value) * @method static \Illuminate\Database\Query\Builder|\App\Models\ResourceUser whereUserId($value) * @method static \Illuminate\Database\Query\Builder|\App\Models\ResourceUser whereTrackId($value) @@ -64,7 +64,7 @@ class ResourceUser extends Model return $existing; } - $item = new ResourceUser(); + $item = new self(); $item->{$resourceIdColumn} = $resourceId; $item->user_id = $userId; diff --git a/app/Models/Role.php b/app/Models/Role.php index be53de49..6f208f13 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -23,9 +23,9 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; /** - * App\Models\Role + * App\Models\Role. * - * @property integer $id + * @property int $id * @property string $name * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\User[] $users * @method static \Illuminate\Database\Query\Builder|\App\Models\Role whereId($value) diff --git a/app/Models/ShowSong.php b/app/Models/ShowSong.php index f6389412..b277347e 100644 --- a/app/Models/ShowSong.php +++ b/app/Models/ShowSong.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -24,9 +24,9 @@ use DB; use Illuminate\Database\Eloquent\Model; /** - * App\Models\ShowSong + * App\Models\ShowSong. * - * @property integer $id + * @property int $id * @property string $title * @property string $lyrics * @property string $slug diff --git a/app/Models/Subscription.php b/app/Models/Subscription.php index 0c623366..7d4b4f18 100644 --- a/app/Models/Subscription.php +++ b/app/Models/Subscription.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Logic + * Copyright (C) 2016 Logic. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -23,10 +23,10 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; /** - * App\Models\Subscription + * App\Models\Subscription. * - * @property integer $id - * @property integer $user_id + * @property int $id + * @property int $user_id * @property string $endpoint * @property string $p256dh * @property string $auth @@ -51,7 +51,7 @@ class Subscription extends Model 'user_id' => 'integer', 'endpoint' => 'string', 'p256dh' => 'string', - 'auth' => 'string' + 'auth' => 'string', ]; public function user() diff --git a/app/Models/Track.php b/app/Models/Track.php index 285e71b7..5fe14b57 100644 --- a/app/Models/Track.php +++ b/app/Models/Track.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015-2017 Feld0 + * Copyright (C) 2015-2017 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,13 +20,6 @@ namespace App\Models; -use Auth; -use Cache; -use Config; -use DB; -use Gate; -use Illuminate\Database\Eloquent\Relations\HasMany; -use Illuminate\Database\Eloquent\Relations\MorphMany; use App\Contracts\Commentable; use App\Contracts\Favouritable; use App\Contracts\Searchable; @@ -34,48 +27,55 @@ use App\Exceptions\TrackFileNotFoundException; use App\Models\ResourceLogItem; use App\Traits\IndexedInElasticsearchTrait; use App\Traits\SlugTrait; +use Auth; +use Cache; +use Config; +use DB; use Exception; use External; +use Gate; use getid3_writetags; use Helpers; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Str; use Log; use Venturecraft\Revisionable\RevisionableTrait; /** - * App\Models\Track + * App\Models\Track. * - * @property integer $id - * @property integer $user_id - * @property integer $license_id - * @property integer $genre_id - * @property integer $track_type_id + * @property int $id + * @property int $user_id + * @property int $license_id + * @property int $genre_id + * @property int $track_type_id * @property string $title * @property string $slug * @property string $description * @property string $lyrics - * @property boolean $is_vocal - * @property boolean $is_explicit - * @property integer $cover_id - * @property boolean $is_downloadable + * @property bool $is_vocal + * @property bool $is_explicit + * @property int $cover_id + * @property bool $is_downloadable * @property float $duration - * @property integer $play_count - * @property integer $view_count - * @property integer $download_count - * @property integer $favourite_count - * @property integer $comment_count + * @property int $play_count + * @property int $view_count + * @property int $download_count + * @property int $favourite_count + * @property int $comment_count * @property \Carbon\Carbon $created_at * @property string $updated_at * @property \Carbon\Carbon $deleted_at * @property \Carbon\Carbon $published_at * @property \Carbon\Carbon $released_at - * @property integer $album_id - * @property integer $track_number - * @property boolean $is_latest + * @property int $album_id + * @property int $track_number + * @property bool $is_latest * @property string $hash - * @property boolean $is_listed + * @property bool $is_listed * @property string $source * @property string $original_tags * @property string $metadata @@ -184,7 +184,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable const STATUS_ERROR = 2; /** - * All the information about how to encode files into Pony.fm's various formats + * All the information about how to encode files into Pony.fm's various formats. * * @var array */ @@ -196,7 +196,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable 'tag_format' => 'metaflac', 'tag_method' => 'updateTagsWithGetId3', 'mime_type' => 'audio/flac', - 'command' => 'ffmpeg 2>&1 -y -i {$source} -map 0:a -map_metadata -1 -codec:a flac -aq 8 -f flac {$target}' + 'command' => 'ffmpeg 2>&1 -y -i {$source} -map 0:a -map_metadata -1 -codec:a flac -aq 8 -f flac {$target}', ], 'MP3' => [ 'index' => 1, @@ -205,7 +205,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable 'tag_format' => 'id3v2.3', 'tag_method' => 'updateTagsWithGetId3', 'mime_type' => 'audio/mpeg', - 'command' => 'ffmpeg 2>&1 -y -i {$source} -map 0:a -map_metadata -1 -codec:a libmp3lame -ab 320k -f mp3 {$target}' + 'command' => 'ffmpeg 2>&1 -y -i {$source} -map 0:a -map_metadata -1 -codec:a libmp3lame -ab 320k -f mp3 {$target}', ], 'OGG Vorbis' => [ 'index' => 2, @@ -214,7 +214,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable 'tag_format' => 'vorbiscomment', 'tag_method' => 'updateTagsWithGetId3', 'mime_type' => 'audio/ogg', - 'command' => 'ffmpeg 2>&1 -y -i {$source} -map 0:a -map_metadata -1 -codec:a libvorbis -aq 7 -f ogg {$target}' + 'command' => 'ffmpeg 2>&1 -y -i {$source} -map 0:a -map_metadata -1 -codec:a libvorbis -aq 7 -f ogg {$target}', ], 'AAC' => [ 'index' => 3, @@ -223,7 +223,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable 'tag_format' => 'AtomicParsley', 'tag_method' => 'updateTagsWithAtomicParsley', 'mime_type' => 'audio/mp4', - 'command' => 'ffmpeg 2>&1 -y -i {$source} -map 0:a -map_metadata -1 -codec:a libfaac -ab 256k -f mp4 {$target}' + 'command' => 'ffmpeg 2>&1 -y -i {$source} -map 0:a -map_metadata -1 -codec:a libfaac -ab 256k -f mp4 {$target}', ], 'ALAC' => [ 'index' => 4, @@ -232,7 +232,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable 'tag_format' => 'AtomicParsley', 'tag_method' => 'updateTagsWithAtomicParsley', 'mime_type' => 'audio/mp4', - 'command' => 'ffmpeg 2>&1 -y -i {$source} -map 0:a -map_metadata -1 -codec:a alac {$target}' + 'command' => 'ffmpeg 2>&1 -y -i {$source} -map 0:a -map_metadata -1 -codec:a alac {$target}', ], ]; @@ -250,7 +250,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable public static $CacheableFormats = [ 'OGG Vorbis', 'ALAC', - 'AAC' + 'AAC', ]; /** @@ -264,7 +264,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable */ public static $LosslessFormats = [ 'FLAC', - 'ALAC' + 'ALAC', ]; /** @@ -311,7 +311,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable $query->with([ 'users' => function ($query) { $query->whereUserId(Auth::user()->id); - } + }, ]); } } @@ -343,7 +343,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable */ public function scopeExplicitFilter($query) { - if (!Auth::check() || !Auth::user()->can_see_explicit_content) { + if (! Auth::check() || ! Auth::user()->can_see_explicit_content) { $query->whereIsExplicit(false); } } @@ -358,7 +358,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable $query->with([ 'comments' => function ($query) { $query->with('user'); - } + }, ]); } @@ -376,7 +376,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable * The (messy) query used to generate the list of popular tracks on PFM's * homepage. * - * @param integer $count the number of tracks to return + * @param int $count the number of tracks to return * @param bool $allowExplicit whether to include explicit tracks in the results * @param int $skip currently unused as of 2017-09-22 * @return array @@ -443,7 +443,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable foreach ($countQuery as $track) { $results[] = [ 'id' => $track->track_id, - 'weight' => $track->weight + 'weight' => $track->weight, ]; } @@ -459,11 +459,11 @@ class Track extends Model implements Searchable, Commentable, Favouritable $trackWeights[$track['id']] = $track['weight']; } - if (!count($trackIds)) { + if (! count($trackIds)) { return []; } - $tracks = Track::summary() + $tracks = self::summary() ->userDetails() ->explicitFilter() ->published() @@ -472,12 +472,12 @@ class Track extends Model implements Searchable, Commentable, Favouritable $processed = []; foreach ($tracks->get() as $track) { - $trackModel = Track::mapPublicTrackSummary($track); + $trackModel = self::mapPublicTrackSummary($track); $trackModel['weight'] = $trackWeights[$track->id]; $processed[] = $trackModel; } - usort($processed, function($a, $b) { + usort($processed, function ($a, $b) { return $a['weight'] <=> $b['weight']; }); @@ -493,7 +493,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable * @param Track $track * @return array */ - public static function mapPublicTrackShow(Track $track) + public static function mapPublicTrackShow(self $track) { $returnValue = self::mapPublicTrackSummary($track); $returnValue['description'] = $track->description; @@ -506,7 +506,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable } $returnValue['comments'] = $comments; - + $formats = []; foreach ($track->trackFiles as $trackFile) { @@ -515,7 +515,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable 'extension' => $trackFile->extension, 'url' => $trackFile->url, 'size' => $trackFile->size, - 'isCacheable' => (bool) $trackFile->is_cacheable + 'isCacheable' => (bool) $trackFile->is_cacheable, ]; } @@ -523,7 +523,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable 'url' => action('TracksController@getShortlink', ['id' => $track->id]), 'html' => '', 'bbcode' => '[url='.$track->url.'][img]'.$track->getCoverUrl().'[/img][/url]', - 'twitterUrl' => 'https://platform.twitter.com/widgets/tweet_button.html?text='.$track->title.' by '.$track->user->display_name.' on Pony.fm' + 'twitterUrl' => 'https://platform.twitter.com/widgets/tweet_button.html?text='.$track->title.' by '.$track->user->display_name.' on Pony.fm', ]; $returnValue['share']['tumblrUrl'] = 'http://www.tumblr.com/share/video?embed='.urlencode($returnValue['share']['html']).'&caption='.urlencode($track->title); @@ -540,15 +540,15 @@ class Track extends Model implements Searchable, Commentable, Favouritable * @param Track $track * @return array */ - public static function mapPublicTrackSummary(Track $track) + public static function mapPublicTrackSummary(self $track) { $userData = [ 'stats' => [ 'views' => 0, 'plays' => 0, - 'downloads' => 0 + 'downloads' => 0, ], - 'is_favourited' => false + 'is_favourited' => false, ]; if (Auth::check() && $track->users->count()) { @@ -559,7 +559,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable 'plays' => (int) $userRow->play_count, 'downloads' => $userRow->download_count, ], - 'is_favourited' => (bool) $userRow->is_favourited + 'is_favourited' => (bool) $userRow->is_favourited, ]; } @@ -569,14 +569,14 @@ class Track extends Model implements Searchable, Commentable, Favouritable 'user' => [ 'id' => (int) $track->user->id, 'name' => $track->user->display_name, - 'url' => $track->user->url + 'url' => $track->user->url, ], 'stats' => [ 'views' => (int) $track->view_count, 'plays' => (int) $track->play_count, 'downloads' => (int) $track->download_count, 'comments' => (int) $track->comment_count, - 'favourites' => (int) $track->favourite_count + 'favourites' => (int) $track->favourite_count, ], 'url' => $track->url, 'slug' => $track->slug, @@ -599,18 +599,18 @@ class Track extends Model implements Searchable, Commentable, Favouritable 'thumbnail' => $track->getCoverUrl(Image::THUMBNAIL), 'small' => $track->getCoverUrl(Image::SMALL), 'normal' => $track->getCoverUrl(Image::NORMAL), - 'original' => $track->getCoverUrl(Image::ORIGINAL) + 'original' => $track->getCoverUrl(Image::ORIGINAL), ], 'streams' => [ 'mp3' => $track->getStreamUrl('MP3'), - 'aac' => (!Config::get('app.debug') || is_file($track->getFileFor('AAC'))) ? $track->getStreamUrl('AAC') : null, - 'ogg' => (Config::get('app.debug') || is_file($track->getFileFor('OGG Vorbis'))) ? $track->getStreamUrl('OGG Vorbis') : null + 'aac' => (! Config::get('app.debug') || is_file($track->getFileFor('AAC'))) ? $track->getStreamUrl('AAC') : null, + 'ogg' => (Config::get('app.debug') || is_file($track->getFileFor('OGG Vorbis'))) ? $track->getStreamUrl('OGG Vorbis') : null, ], 'user_data' => $userData, 'permissions' => [ 'delete' => Gate::allows('delete', $track), - 'edit' => Gate::allows('edit', $track) - ] + 'edit' => Gate::allows('edit', $track), + ], ]; if ($track->album_id != null) { @@ -630,7 +630,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable * @param Track $track * @return array */ - public static function mapPrivateTrackShow(Track $track) + public static function mapPrivateTrackShow(self $track) { $showSongs = []; foreach ($track->showSongs as $showSong) { @@ -646,7 +646,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable $returnValue['released_at'] = $track->released_at ? $track->released_at->toDateString() : null; $returnValue['lyrics'] = $track->lyrics; $returnValue['description'] = $track->description; - $returnValue['is_downloadable'] = !$track->isPublished() ? true : (bool) $track->is_downloadable; + $returnValue['is_downloadable'] = ! $track->isPublished() ? true : (bool) $track->is_downloadable; $returnValue['license_id'] = $track->license_id != null ? $track->license_id : 3; $returnValue['username'] = User::whereId($track->user_id)->first()->username; @@ -667,7 +667,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable * @param Track $track * @return array */ - public static function mapPrivateTrackSummary(Track $track) + public static function mapPrivateTrackSummary(self $track) { return [ 'id' => $track->id, @@ -684,7 +684,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable 'genre_id' => $track->genre_id, 'track_type_id' => $track->track_type_id, 'cover_url' => $track->getCoverUrl(Image::SMALL), - 'is_listed' => !!$track->is_listed + 'is_listed' => (bool) $track->is_listed, ]; } @@ -740,7 +740,6 @@ class Track extends Model implements Searchable, Commentable, Favouritable return $this->hasMany(TrackFile::class)->where('version', $this->current_version); } - public function trackFilesForAllVersions() { return $this->hasMany(TrackFile::class); @@ -860,7 +859,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable $destination = $this->getDirectory(); umask(0); - if (!is_dir($destination)) { + if (! is_dir($destination)) { mkdir($destination, 0777, true); } } @@ -919,7 +918,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable */ public function getCoverUrl($type = Image::NORMAL) { - if (!$this->hasCover()) { + if (! $this->hasCover()) { if ($this->album_id != null) { return $this->album->getCoverUrl($type); } @@ -945,7 +944,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable return action('TracksController@getStream', [ 'id' => $this->id, - 'extension' => self::$Formats[$format]['extension'] + 'extension' => self::$Formats[$format]['extension'], ] + ($apiClientId !== null ? ['api_client_id' => $apiClientId] : []) ); } @@ -978,7 +977,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable */ public function getFilenameFor(string $format) : string { - if (!isset(self::$Formats[$format])) { + if (! isset(self::$Formats[$format])) { throw new Exception("$format is not a valid format!"); } @@ -997,7 +996,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable */ public function getDownloadFilenameFor(string $format) : string { - if (!isset(self::$Formats[$format])) { + if (! isset(self::$Formats[$format])) { throw new Exception("$format is not a valid format!"); } @@ -1015,7 +1014,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable */ public function getFileFor(string $format) : string { - if (!isset(self::$Formats[$format])) { + if (! isset(self::$Formats[$format])) { throw new Exception("$format is not a valid format!"); } @@ -1046,7 +1045,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable */ public function getUrlFor(string $format) : string { - if (!isset(self::$Formats[$format])) { + if (! isset(self::$Formats[$format])) { throw new Exception("$format is not a valid format!"); } @@ -1055,7 +1054,6 @@ class Track extends Model implements Searchable, Commentable, Favouritable return action('TracksController@getDownload', ['id' => $this->id, 'extension' => $format['extension']]); } - /** * @return int one of the Track::STATUS_* values, indicating whether this track is currently being processed */ @@ -1067,7 +1065,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable } elseif ($carry !== static::STATUS_ERROR && in_array($trackFile->status, [TrackFile::STATUS_PROCESSING, TrackFile::STATUS_PROCESSING_PENDING])) { return static::STATUS_PROCESSING; - } elseif (!in_array($carry, [static::STATUS_ERROR, static::STATUS_PROCESSING, TrackFile::STATUS_PROCESSING_PENDING]) && + } elseif (! in_array($carry, [static::STATUS_ERROR, static::STATUS_PROCESSING, TrackFile::STATUS_PROCESSING_PENDING]) && (int) $trackFile->status === TrackFile::STATUS_NOT_BEING_PROCESSED ) { return static::STATUS_COMPLETE; @@ -1152,7 +1150,6 @@ class Track extends Model implements Searchable, Commentable, Favouritable External::execute($command); } - /** * Writes a TrackFile's tags using getId3(). This is useful for MP3, FLAC, * and OGG Vorbis files. This function is called from updateTagsForTrackFile. @@ -1162,8 +1159,8 @@ class Track extends Model implements Searchable, Commentable, Favouritable */ private function updateTagsWithGetId3(string $format) { - require_once(app_path().'/Library/getid3/getid3/getid3.php'); - require_once(app_path().'/Library/getid3/getid3/write.php'); + require_once app_path().'/Library/getid3/getid3/getid3.php'; + require_once app_path().'/Library/getid3/getid3/write.php'; $tagWriter = new getid3_writetags; $tagWriter->overwrite_tags = true; @@ -1182,7 +1179,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable // 'url_artist' => [$this->user->url], // 'url_source' => [$this->url], // 'url_file' => [$this->url], - 'url_publisher' => ['https://pony.fm/'] + 'url_publisher' => ['https://pony.fm/'], ]; if ($this->album_id !== null) { @@ -1195,7 +1192,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable 'data' => file_get_contents($this->cover->getFile(Image::ORIGINAL)), 'picturetypeid' => 2, 'description' => 'cover', - 'mime' => $this->cover->mime + 'mime' => $this->cover->mime, ]; } @@ -1203,7 +1200,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable $tagWriter->tagformats = [self::$Formats[$format]['tag_format']]; if ($tagWriter->WriteTags()) { - if (!empty($tagWriter->warnings)) { + if (! empty($tagWriter->warnings)) { Log::warning('Track #'.$this->id.': There were some warnings:
    '.implode( '

    ', $tagWriter->warnings @@ -1234,17 +1231,17 @@ class Track extends Model implements Searchable, Commentable, Favouritable } /** - * @inheritdoc + * {@inheritdoc} */ public function shouldBeIndexed():bool { return $this->is_listed && $this->published_at !== null && - !$this->trashed(); + ! $this->trashed(); } /** - * @inheritdoc + * {@inheritdoc} */ public function toElasticsearch():array { @@ -1254,7 +1251,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable 'published_at' => $this->published_at ? $this->published_at->toIso8601String() : null, 'genre' => $this->genre->name, 'track_type' => $this->trackType->title, - 'show_songs' => $this->showSongs->pluck('title') + 'show_songs' => $this->showSongs->pluck('title'), ]; } diff --git a/app/Models/TrackFile.php b/app/Models/TrackFile.php index ecddb6e8..17a91196 100644 --- a/app/Models/TrackFile.php +++ b/app/Models/TrackFile.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,31 +20,31 @@ namespace App\Models; +use App; use Config; +use File; use Helpers; use Illuminate\Database\Eloquent\Model; -use App; -use File; /** - * App\Models\TrackFile + * App\Models\TrackFile. * - * @property integer $id - * @property integer $track_id - * @property boolean $is_master + * @property int $id + * @property int $track_id + * @property bool $is_master * @property string $format * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at - * @property boolean $is_cacheable - * @property boolean $status + * @property bool $is_cacheable + * @property bool $status * @property \Carbon\Carbon $expires_at - * @property integer $filesize + * @property int $filesize * @property-read \App\Models\Track $track * @property-read mixed $extension * @property-read mixed $url * @property-read mixed $size * @property-read mixed $is_expired - * @property integer $version + * @property int $version * @method static \Illuminate\Database\Query\Builder|\App\Models\TrackFile whereId($value) * @method static \Illuminate\Database\Query\Builder|\App\Models\TrackFile whereTrackId($value) * @method static \Illuminate\Database\Query\Builder|\App\Models\TrackFile whereIsMaster($value) @@ -95,7 +95,7 @@ class TrackFile extends Model public static function findOrFailByExtension($trackId, $extension) { $track = Track::find($trackId); - if (!$track) { + if (! $track) { App::abort(404); } @@ -219,6 +219,6 @@ class TrackFile extends Model public function isLossy() : bool { - return !in_array($this->format, Track::$LosslessFormats); + return ! in_array($this->format, Track::$LosslessFormats); } } diff --git a/app/Models/TrackType.php b/app/Models/TrackType.php index d0cd53e5..0240f260 100644 --- a/app/Models/TrackType.php +++ b/app/Models/TrackType.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -23,9 +23,9 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; /** - * App\Models\TrackType + * App\Models\TrackType. * - * @property integer $id + * @property int $id * @property string $title * @property string $editor_title * @method static \Illuminate\Database\Query\Builder|\App\Models\TrackType whereId($value) diff --git a/app/Models/User.php b/app/Models/User.php index bbc4310b..8a195748 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,6 +20,10 @@ namespace App\Models; +use App\Contracts\Commentable; +use App\Contracts\Searchable; +use App\Traits\IndexedInElasticsearchTrait; +use Auth; use Carbon\Carbon; use DB; use Gravatar; @@ -31,35 +35,31 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Foundation\Auth\Access\Authorizable; -use Auth; use Illuminate\Support\Str; use League\OAuth2\Client\Token\AccessToken; -use App\Contracts\Commentable; -use App\Contracts\Searchable; -use App\Traits\IndexedInElasticsearchTrait; use Validator; use Venturecraft\Revisionable\RevisionableTrait; /** - * App\Models\User + * App\Models\User. * - * @property integer $id + * @property int $id * @property string $display_name * @property string $username - * @property boolean $sync_names + * @property bool $sync_names * @property string $email * @property string $gravatar * @property string $slug - * @property boolean $uses_gravatar - * @property boolean $can_see_explicit_content + * @property bool $uses_gravatar + * @property bool $can_see_explicit_content * @property string $bio - * @property integer $track_count - * @property integer $comment_count + * @property int $track_count + * @property int $comment_count * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at - * @property integer $avatar_id + * @property int $avatar_id * @property string $remember_token - * @property boolean $is_archived + * @property bool $is_archived * @property \Carbon\Carbon $disabled_at * @property-read \App\Models\Image $avatar * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ResourceUser[] $users @@ -118,7 +118,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon 'comment_count' => 'integer', 'avatar_id' => 'integer', 'is_archived' => 'boolean', - 'redirect_to' => 'integer' + 'redirect_to' => 'integer', ]; protected $dates = ['created_at', 'updated_at', 'disabled_at']; protected $hidden = ['disabled_at', 'remember_token']; @@ -129,7 +129,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon $query->with([ 'users' => function ($query) { $query->whereUserId(Auth::user()->id); - } + }, ]); } @@ -143,7 +143,8 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon * @param int $activityType one of the TYPE_* constants in the Activity class * @return mixed */ - public function scopeWithEmailSubscriptionFor($query, int $activityType) { + public function scopeWithEmailSubscriptionFor($query, int $activityType) + { return $query->whereHas('emailSubscriptions', function ($query) use ($activityType) { $query->where('activity_type', $activityType); }); @@ -156,7 +157,8 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon * @param int $poniverseId * @return mixed */ - public function scopeWherePoniverseId($query, int $poniverseId) { + public function scopeWherePoniverseId($query, int $poniverseId) + { return $query ->whereLinkedToPoniverse($query) ->where('oauth2_tokens.external_user_id', '=', $poniverseId); @@ -168,7 +170,8 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon * @param $query * @return mixed */ - public function scopeWhereLinkedToPoniverse($query) { + public function scopeWhereLinkedToPoniverse($query) + { return $query ->join('oauth2_tokens', 'users.id', '=', 'oauth2_tokens.user_id') ->select('users.*', 'oauth2_tokens.external_user_id'); @@ -179,7 +182,8 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon * * @return AccessToken|null */ - public function getAccessToken() { + public function getAccessToken() + { $accessTokenRecord = DB::table('oauth2_tokens')->where('user_id', '=', $this->id)->first(); if ($accessTokenRecord === null) { @@ -199,7 +203,8 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon * * @param AccessToken $accessToken */ - public function setAccessToken(AccessToken $accessToken) { + public function setAccessToken(AccessToken $accessToken) + { DB::table('oauth2_tokens') ->where('user_id', '=', $this->id) ->update([ @@ -267,7 +272,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon if (null !== $user) { return $user; } else { - $user = new User; + $user = new self; $user->username = $username; $user->display_name = $displayName; @@ -292,10 +297,10 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon { return $this->hasMany(ResourceUser::class, 'artist_id'); } - + public function followers() { - return $this->belongsToMany(User::class, 'followers', 'artist_id', 'user_id'); + return $this->belongsToMany(self::class, 'followers', 'artist_id', 'user_id'); } public function roles() @@ -312,7 +317,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon { return $this->hasMany(Track::class, 'user_id'); } - + public function notifications() { return $this->hasMany(Notification::class, 'user_id'); @@ -370,17 +375,17 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon public function getAvatarUrl($type = Image::NORMAL) { - if (!$this->uses_gravatar && $this->avatar !== null) { + if (! $this->uses_gravatar && $this->avatar !== null) { return $this->avatar->getUrl($type); } - if ($this->email == "redacted@example.net") { - return Gravatar::getUrl($this->id."", Image::$ImageTypes[$type]['width'], "identicon"); + if ($this->email == 'redacted@example.net') { + return Gravatar::getUrl($this->id.'', Image::$ImageTypes[$type]['width'], 'identicon'); } $email = $this->gravatar; - if (!strlen($email)) { + if (! strlen($email)) { $email = $this->email; } @@ -389,17 +394,17 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon public function getAvatarUrlLocal($type = Image::NORMAL) { - if (!$this->uses_gravatar && $this->avatar !== null) { + if (! $this->uses_gravatar && $this->avatar !== null) { return $this->avatar->getFile($type); } - if ($this->email == "redacted@example.net") { - return Gravatar::getUrl($this->id."", Image::$ImageTypes[$type]['width'], "identicon"); + if ($this->email == 'redacted@example.net') { + return Gravatar::getUrl($this->id.'', Image::$ImageTypes[$type]['width'], 'identicon'); } $email = $this->gravatar; - if (!strlen($email)) { + if (! strlen($email)) { $email = $this->email; } @@ -439,16 +444,16 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon */ public function getRememberTokenName() { - return "remember_token"; + return 'remember_token'; } - public function getUserAttribute():User + public function getUserAttribute():self { return $this; } /** - * @inheritdoc + * {@inheritdoc} */ public function getResourceType():string { @@ -477,7 +482,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon return false; } - public static function mapPublicUserSummary(User $user) + public static function mapPublicUserSummary(self $user) { return [ 'id' => $user->id, @@ -487,9 +492,9 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon 'is_archived' => $user->is_archived, 'avatars' => [ 'small' => $user->getAvatarUrl(Image::SMALL), - 'normal' => $user->getAvatarUrl(Image::NORMAL) + 'normal' => $user->getAvatarUrl(Image::NORMAL), ], - 'created_at' => $user->created_at + 'created_at' => $user->created_at, ]; } @@ -499,7 +504,8 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon * * @return array */ - private function emailSubscriptionsJoined() { + private function emailSubscriptionsJoined() + { return DB::select(' SELECT "subscriptions".*, "activity_types".* FROM (SELECT * FROM "email_subscriptions" @@ -516,17 +522,18 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon * * @return array */ - public function getNotificationSettings() { + public function getNotificationSettings() + { $settings = []; $emailSubscriptions = $this->emailSubscriptionsJoined(); - foreach($emailSubscriptions as $subscription) { + foreach ($emailSubscriptions as $subscription) { // TODO: remove this check when news and album notifications are implemented - if (!in_array($subscription->activity_type, [Activity::TYPE_NEWS, Activity::TYPE_PUBLISHED_ALBUM])) { + if (! in_array($subscription->activity_type, [Activity::TYPE_NEWS, Activity::TYPE_PUBLISHED_ALBUM])) { $settings[] = [ 'description' => $subscription->description, 'activity_type' => $subscription->activity_type, - 'receive_emails' => $subscription->id !== NULL + 'receive_emails' => $subscription->id !== null, ]; } } @@ -550,7 +557,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon } /** - * @inheritdoc + * {@inheritdoc} */ public function shouldBeIndexed():bool { diff --git a/app/PlaylistDownloader.php b/app/PlaylistDownloader.php index ae1e11f5..0aecad0c 100644 --- a/app/PlaylistDownloader.php +++ b/app/PlaylistDownloader.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -46,8 +46,8 @@ class PlaylistDownloader public function download(User $user) { // Check whether the format is lossless yet not all master files are lossless - $isLosslessFormatWithLossyTracks = in_array($this->_format, Track::$LosslessFormats) - && !$this->_playlist->hasLosslessTracksOnly() + $isLosslessFormatWithLossyTracks = in_array($this->_format, Track::$LosslessFormats) + && ! $this->_playlist->hasLosslessTracksOnly() && $this->_playlist->hasLosslessTracks(); $zip = new ZipStream($this->_playlist->user->display_name.' - '.$this->_playlist->title.'.zip'); @@ -72,19 +72,19 @@ class PlaylistDownloader $m3u = ''; $index = 1; foreach ($this->_playlist->tracks as $track) { - if (!$track->is_downloadable && !$user->hasRole('admin')) { + if (! $track->is_downloadable && ! $user->hasRole('admin')) { continue; } if ($isLosslessFormatWithLossyTracks && $track->isMasterLossy()) { $masterFormatName = $track->getMasterFormatName(); - $trackTarget = $track->downloadDirectory . '/' . $track->getDownloadFilenameFor($masterFormatName); + $trackTarget = $track->downloadDirectory.'/'.$track->getDownloadFilenameFor($masterFormatName); $zip->addLargeFile($track->getFileFor($masterFormatName), $trackTarget); } else { - $trackTarget = $track->downloadDirectory . '/' . $track->getDownloadFilenameFor($this->_format); + $trackTarget = $track->downloadDirectory.'/'.$track->getDownloadFilenameFor($this->_format); $zip->addLargeFile($track->getFileFor($this->_format), $trackTarget); } - + $notes .= $index.'. '.$track->title."\r\n". $track->description."\r\n". diff --git a/app/Policies/AlbumPolicy.php b/app/Policies/AlbumPolicy.php index 2f43a8da..2b91ce3a 100644 --- a/app/Policies/AlbumPolicy.php +++ b/app/Policies/AlbumPolicy.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Policies/GenrePolicy.php b/app/Policies/GenrePolicy.php index 06cc0756..0e0a764f 100644 --- a/app/Policies/GenrePolicy.php +++ b/app/Policies/GenrePolicy.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Policies/TrackPolicy.php b/app/Policies/TrackPolicy.php index 0d44b428..bf37d5be 100644 --- a/app/Policies/TrackPolicy.php +++ b/app/Policies/TrackPolicy.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Policies/UserPolicy.php b/app/Policies/UserPolicy.php index 3d9e1ba8..1f59f1a6 100644 --- a/app/Policies/UserPolicy.php +++ b/app/Policies/UserPolicy.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 8c96ebd6..8882dca9 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 2ce3378c..6517847e 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,19 +20,19 @@ namespace App\Providers; -use Gate; -use Illuminate\Contracts\Auth\Access\Gate as GateContract; -use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use App\Models\Album; use App\Models\Genre; +use App\Models\ShowSong; +use App\Models\Track; +use App\Models\User; use App\Policies\AlbumPolicy; use App\Policies\GenrePolicy; use App\Policies\ShowSongPolicy; use App\Policies\TrackPolicy; -use App\Models\Track; -use App\Models\User; -use App\Models\ShowSong; use App\Policies\UserPolicy; +use Gate; +use Illuminate\Contracts\Auth\Access\Gate as GateContract; +use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; class AuthServiceProvider extends ServiceProvider { @@ -46,7 +46,7 @@ class AuthServiceProvider extends ServiceProvider Track::class => TrackPolicy::class, Album::class => AlbumPolicy::class, User::class => UserPolicy::class, - ShowSong::class => ShowSongPolicy::class + ShowSong::class => ShowSongPolicy::class, ]; /** diff --git a/app/Providers/BroadcastServiceProvider.php b/app/Providers/BroadcastServiceProvider.php index ee67f771..aadec50c 100755 --- a/app/Providers/BroadcastServiceProvider.php +++ b/app/Providers/BroadcastServiceProvider.php @@ -2,8 +2,8 @@ namespace App\Providers; -use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Broadcast; +use Illuminate\Support\ServiceProvider; class BroadcastServiceProvider extends ServiceProvider { diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index b60ab919..c01ea420 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/app/Providers/NotificationServiceProvider.php b/app/Providers/NotificationServiceProvider.php index c1f03f9b..706a0b97 100644 --- a/app/Providers/NotificationServiceProvider.php +++ b/app/Providers/NotificationServiceProvider.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,9 +20,9 @@ namespace App\Providers; +use App\Library\Notifications\NotificationManager; use Illuminate\Foundation\Application; use Illuminate\Support\ServiceProvider; -use App\Library\Notifications\NotificationManager; class NotificationServiceProvider extends ServiceProvider { diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 0954a2cd..ebd44394 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,10 +20,10 @@ namespace App\Providers; -use Illuminate\Routing\Router; -use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; -use Illuminate\Support\Facades\Route; use App\Models\User; +use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; +use Illuminate\Routing\Router; +use Illuminate\Support\Facades\Route; class RouteServiceProvider extends ServiceProvider { @@ -60,7 +60,7 @@ class RouteServiceProvider extends ServiceProvider { Route::group([ 'middleware' => 'web', - 'namespace' => $this->namespace + 'namespace' => $this->namespace, ], function ($router) { require base_path('routes/web.php'); }); diff --git a/app/Traits/IndexedInElasticsearchTrait.php b/app/Traits/IndexedInElasticsearchTrait.php index b5ceb833..def34c28 100644 --- a/app/Traits/IndexedInElasticsearchTrait.php +++ b/app/Traits/IndexedInElasticsearchTrait.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,20 +20,18 @@ namespace App\Traits; +use App\Contracts\Searchable; +use App\Jobs\UpdateSearchIndexForEntity; use Config; use Elasticsearch; use Elasticsearch\Common\Exceptions\Missing404Exception; use Illuminate\Foundation\Bus\DispatchesJobs; -use App\Contracts\Searchable; -use App\Jobs\UpdateSearchIndexForEntity; /** - * Class IndexedInElasticsearch + * Class IndexedInElasticsearch. * * Classes using this trait must declare the `$elasticsearchType` property and * implement the `Searchable` interface. - * - * @package App\Traits */ trait IndexedInElasticsearchTrait { @@ -41,9 +39,9 @@ trait IndexedInElasticsearchTrait // These two functions are from the Searchable interface. They're included // here, without being implemented, to assist IDE's when editing this trait. - public abstract function toElasticsearch():array; - public abstract function shouldBeIndexed():bool; + abstract public function toElasticsearch():array; + abstract public function shouldBeIndexed():bool; // Laravel automatically runs this method based on the trait's name. #magic public static function bootIndexedInElasticsearchTrait() diff --git a/app/Traits/SlugTrait.php b/app/Traits/SlugTrait.php index 4682ffa9..4767fdc3 100644 --- a/app/Traits/SlugTrait.php +++ b/app/Traits/SlugTrait.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -30,11 +30,13 @@ trait SlugTrait $this->attributes['title'] = $value; } - private static function makeNonemptySlug($title) { + private static function makeNonemptySlug($title) + { $slug = Str::slug($title); if ($slug === '') { $slug = '-'; } + return $slug; } } diff --git a/app/Traits/TrackCollection.php b/app/Traits/TrackCollection.php index 7dcad760..b6376ee1 100644 --- a/app/Traits/TrackCollection.php +++ b/app/Traits/TrackCollection.php @@ -3,7 +3,7 @@ /** * Pony.fm - A community for pony fan music. * Copyright (C) 2015 Feld0 - * Copyright (C) 2015 Kelvin Zhang + * Copyright (C) 2015 Kelvin Zhang. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -21,21 +21,17 @@ namespace App\Traits; +use App\Jobs\EncodeTrackFile; +use App\Models\Track; +use App\Models\TrackFile; use File; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Facades\Cache; -use App\Jobs\EncodeTrackFile; -use App\Models\Track; -use App\Models\TrackFile; /** - * Class TrackCollection - * @package App\Traits - * - * Contains common logic between albums and playlists. They share some functionality - * because they're both a form of downloadable track collection. + * Class TrackCollection. */ trait TrackCollection { @@ -54,7 +50,6 @@ trait TrackCollection */ abstract public function trackFiles(); - /** * Returns the number of tracks that are available in the given format. * @@ -66,7 +61,6 @@ trait TrackCollection return $this->downloadableTrackFiles($format)->count(); } - /** * Returns the number of currently-available track files (master files + * currently cached files) for this collection in the given format. @@ -81,7 +75,6 @@ trait TrackCollection foreach ($trackFiles as $trackFile) { /** @var TrackFile $trackFile */ - if ($trackFile->is_master || ($trackFile->expires_at != null && File::exists($trackFile->getFile())) ) { @@ -92,7 +85,6 @@ trait TrackCollection return $availableCount; } - /** * Kicks off the encoding of any cacheable files in this collection that * do not currently exist. @@ -105,13 +97,12 @@ trait TrackCollection foreach ($trackFiles as $trackFile) { /** @var TrackFile $trackFile */ - if (!File::exists($trackFile->getFile()) && $trackFile->status == TrackFile::STATUS_NOT_BEING_PROCESSED) { + if (! File::exists($trackFile->getFile()) && $trackFile->status == TrackFile::STATUS_NOT_BEING_PROCESSED) { $this->dispatch(new EncodeTrackFile($trackFile, true)); } } } - /** * Returns an Eloquent collection of downloadable TrackFiles for this {@link TrackCollection}. * A {@link TrackFile} is considered downloadable if its associated {@link Track} is. @@ -124,7 +115,7 @@ trait TrackCollection return $this->trackFiles()->with([ 'track' => function ($query) { $query->where('is_downloadable', true); - } + }, ])->where('format', $format)->get(); } @@ -138,11 +129,12 @@ trait TrackCollection { $hasLosslessTracks = false; foreach ($this->tracks as $track) { - if (!$track->isMasterLossy()) { + if (! $track->isMasterLossy()) { $hasLosslessTracks = true; break; } } + return $hasLosslessTracks; } @@ -161,6 +153,7 @@ trait TrackCollection break; } } + return $hasLosslessTracksOnly; } @@ -173,7 +166,7 @@ trait TrackCollection public function getFilesize($format) : int { $tracks = $this->tracks; - if (!count($tracks)) { + if (! count($tracks)) { return 0; } @@ -181,15 +174,15 @@ trait TrackCollection $size = 0; // Check whether the format is lossless yet not all master files are lossless - $isLosslessFormatWithLossyTracks = in_array($format, Track::$LosslessFormats) - && !$this->hasLosslessTracksOnly() + $isLosslessFormatWithLossyTracks = in_array($format, Track::$LosslessFormats) + && ! $this->hasLosslessTracksOnly() && $this->hasLosslessTracks(); - + foreach ($tracks as $track) { /** @var $track Track */ // Ensure that only downloadable tracks are added onto the file size - if (!$track->is_downloadable) { + if (! $track->is_downloadable) { continue; } diff --git a/config/app.php b/config/app.php index 4f9232cd..fbfa27f8 100644 --- a/config/app.php +++ b/config/app.php @@ -14,10 +14,8 @@ return [ 'name' => env('APP_NAME', 'My Application'), - 'env' => env('APP_ENV', 'production'), - /* |-------------------------------------------------------------------------- | Application Debug Mode diff --git a/config/cors.php b/config/cors.php index 6016f1f8..0c7e0467 100644 --- a/config/cors.php +++ b/config/cors.php @@ -1,4 +1,5 @@ 'file', // redis, file, pdo, custom 'path' => storage_path('debugbar'), // For file driver 'connection' => null, // Leave null for default connection (Redis/PDO) - 'provider' => '' // Instance of StorageInterface for custom driver + 'provider' => '', // Instance of StorageInterface for custom driver ], /* @@ -143,19 +143,19 @@ return [ 'hints' => true, // Show hints for common mistakes ], 'mail' => [ - 'full_log' => false + 'full_log' => false, ], 'views' => [ 'data' => false, //Note: Can slow down the application, because the data can be quite large.. ], 'route' => [ - 'label' => true // show complete route on bar + 'label' => true, // show complete route on bar ], 'logs' => [ - 'file' => null + 'file' => null, ], 'cache' => [ - 'values' => true // collect cache values + 'values' => true, // collect cache values ], ], diff --git a/config/elasticsearch.php b/config/elasticsearch.php index 7bf412d6..15ac62a6 100644 --- a/config/elasticsearch.php +++ b/config/elasticsearch.php @@ -10,19 +10,17 @@ return [ * as your default connection when building an client. Of course you may * use create several clients at once, each with different configurations. */ - 'defaultConnection' => 'default', /** * These are the connection parameters used when building a client. */ - 'connections' => [ 'default' => [ /** - * Hosts + * Hosts. * * This is an array of hosts that the client will connect to. It can be a * single host name, or an array if you are running a cluster of Elasticsearch @@ -35,11 +33,10 @@ return [ * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_host_configuration */ - 'hosts' => explode(',', env('ELASTICSEARCH_HOSTS', 'localhost:9200')), /** - * SSL + * SSL. * * If your Elasticsearch instance uses an out-dated or self-signed SSL * certificate, you will need to pass in the certificate bundle. This can @@ -53,11 +50,10 @@ return [ * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_security.html#_ssl_encryption_2 */ - 'sslVerification' => null, /** - * Logging + * Logging. * * Logging is handled by passing in an instance of Monolog\Logger (which * coincidentally is what Laravel's default logger is). @@ -73,7 +69,6 @@ return [ * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#enabling_logger */ - 'logging' => false, // If you have an existing instance of Monolog you can use it here. @@ -84,7 +79,7 @@ return [ 'logLevel' => Monolog\Logger::INFO, /** - * Retries + * Retries. * * By default, the client will retry n times, where n = number of nodes in * your cluster. If you would like to disable retries, or change the number, @@ -92,7 +87,6 @@ return [ * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_set_retries */ - 'retries' => null, /** @@ -103,66 +97,59 @@ return [ */ /** - * Sniff On Start + * Sniff On Start. * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html */ - 'sniffOnStart' => false, /** - * HTTP Handler + * HTTP Handler. * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_configure_the_http_handler * @see http://ringphp.readthedocs.org/en/latest/client_handlers.html */ - 'httpHandler' => null, /** - * Connection Pool + * Connection Pool. * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_setting_the_connection_pool * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_connection_pool.html */ - 'connectionPool' => null, /** - * Connection Selector + * Connection Selector. * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_setting_the_connection_selector * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_selectors.html */ - 'connectionSelector' => null, /** - * Serializer + * Serializer. * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_setting_the_serializer * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_serializers.html */ - 'serializer' => null, /** - * Connection Factory + * Connection Factory. * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_setting_a_custom_connectionfactory */ - 'connectionFactory' => null, /** - * Endpoint + * Endpoint. * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_set_the_endpoint_closure */ - 'endpoint' => null, - ] - ] + ], + ], ]; diff --git a/config/ide-helper.php b/config/ide-helper.php index 58afd5fb..a799cda6 100644 --- a/config/ide-helper.php +++ b/config/ide-helper.php @@ -44,7 +44,6 @@ return [ 'app/Models', ], - /* |-------------------------------------------------------------------------- | Extra classes @@ -69,9 +68,9 @@ return [ 'critical' => 'Monolog\Logger::addCritical', 'alert' => 'Monolog\Logger::addAlert', 'emergency' => 'Monolog\Logger::addEmergency', - ] + ], ], - + /* |-------------------------------------------------------------------------- | Interface implementations @@ -81,7 +80,7 @@ return [ | are detected by the helpers, others can be listed below. | */ - + 'interfaces' => [ ], diff --git a/config/poniverse.php b/config/poniverse.php index bf043b13..fe715e62 100644 --- a/config/poniverse.php +++ b/config/poniverse.php @@ -1,4 +1,5 @@ env('PONI_CLIENT_ID'), 'secret' => env('PONI_CLIENT_SECRET'), diff --git a/config/ponyfm.php b/config/ponyfm.php index b27cd037..564a0068 100644 --- a/config/ponyfm.php +++ b/config/ponyfm.php @@ -115,9 +115,9 @@ return [ | be desirable for future site functionality. | */ - + 'user_slug_minimum_length' => 3, - + /* |-------------------------------------------------------------------------- | Indexing queue name diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 94e413bc..c6da6be3 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015-2017 Feld0 + * Copyright (C) 2015-2017 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -31,7 +31,7 @@ use App\Models\User; -$factory->define(App\Models\User::class, function (\Faker\Generator $faker) { +$factory->define(App\Models\User::class, function (Faker\Generator $faker) { return [ 'username' => $faker->userName, 'display_name' => $faker->userName, @@ -45,7 +45,7 @@ $factory->define(App\Models\User::class, function (\Faker\Generator $faker) { ]; }); -$factory->define(\App\Models\Track::class, function(\Faker\Generator $faker) { +$factory->define(\App\Models\Track::class, function (Faker\Generator $faker) { $user = factory(User::class)->create(); return [ @@ -62,11 +62,11 @@ $factory->define(\App\Models\Track::class, function(\Faker\Generator $faker) { 'is_downloadable' => true, 'is_listed' => true, 'metadata' => '{"this":{"is":["very","random","metadata"]}}', - 'duration' => $faker->randomFloat(null, 30, 600) + 'duration' => $faker->randomFloat(null, 30, 600), ]; }); -$factory->define(\App\Models\Genre::class, function(\Faker\Generator $faker) { +$factory->define(\App\Models\Genre::class, function (Faker\Generator $faker) { return [ 'name' => $faker->word, 'slug' => $faker->slug, @@ -74,23 +74,22 @@ $factory->define(\App\Models\Genre::class, function(\Faker\Generator $faker) { }); /** - * - * @property integer $id - * @property integer $user_id + * @property int $id + * @property int $user_id * @property string $title * @property string $slug * @property string $description - * @property integer $cover_id - * @property integer $track_count - * @property integer $view_count - * @property integer $download_count - * @property integer $favourite_count - * @property integer $comment_count + * @property int $cover_id + * @property int $track_count + * @property int $view_count + * @property int $download_count + * @property int $favourite_count + * @property int $comment_count * @property \Carbon\Carbon $created_at * @property string $updated_at * @property \Carbon\Carbon $deleted_at */ -$factory->define(\App\Models\Album::class, function(\Faker\Generator $faker) { +$factory->define(\App\Models\Album::class, function (Faker\Generator $faker) { return [ 'title' => $faker->sentence(5), 'slug' => $faker->slug, diff --git a/database/legacy_migrations/2013_06_07_003952_create_users_table.php b/database/legacy_migrations/2013_06_07_003952_create_users_table.php index 3b1a5a94..01e2223c 100644 --- a/database/legacy_migrations/2013_06_07_003952_create_users_table.php +++ b/database/legacy_migrations/2013_06_07_003952_create_users_table.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/database/legacy_migrations/2013_06_27_015259_create_tracks_table.php b/database/legacy_migrations/2013_06_27_015259_create_tracks_table.php index bb9402dd..a8a19743 100644 --- a/database/legacy_migrations/2013_06_27_015259_create_tracks_table.php +++ b/database/legacy_migrations/2013_06_27_015259_create_tracks_table.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -80,13 +80,12 @@ class CreateTracksTable extends Migration $table->foreign('track_type_id')->references('id')->on('track_types')->on_update('cascade'); }); - DB::table('licenses')->insert([ 'title' => 'Personal', 'description' => 'Only you and Pony.fm are allowed to distribute and broadcast the track.', 'affiliate_distribution' => 0, 'open_distribution' => 0, - 'remix' => 0 + 'remix' => 0, ]); DB::table('licenses')->insert([ @@ -94,7 +93,7 @@ class CreateTracksTable extends Migration 'description' => 'You, Pony.fm, and its affiliates may distribute and broadcast the track.', 'affiliate_distribution' => 1, 'open_distribution' => 0, - 'remix' => 0 + 'remix' => 0, ]); DB::table('licenses')->insert([ @@ -102,7 +101,7 @@ class CreateTracksTable extends Migration 'description' => 'Anyone is permitted to broadcast and distribute the song in its original form, with attribution to you.', 'affiliate_distribution' => 1, 'open_distribution' => 1, - 'remix' => 0 + 'remix' => 0, ]); DB::table('licenses')->insert([ @@ -110,32 +109,32 @@ class CreateTracksTable extends Migration 'description' => 'Anyone is permitted to broadcast and distribute the song in any form, or create derivative works based on it for any purpose, with attribution to you.', 'affiliate_distribution' => 1, 'open_distribution' => 1, - 'remix' => 1 + 'remix' => 1, ]); DB::table('track_types')->insert([ 'title' => 'Original Song', - 'editor_title' => 'an original song' + 'editor_title' => 'an original song', ]); DB::table('track_types')->insert([ 'title' => 'Official Song Remix', - 'editor_title' => 'a remix of an official song' + 'editor_title' => 'a remix of an official song', ]); DB::table('track_types')->insert([ 'title' => 'Fan Song Remix', - 'editor_title' => 'a remix of a fan song' + 'editor_title' => 'a remix of a fan song', ]); DB::table('track_types')->insert([ 'title' => 'Ponified Song', - 'editor_title' => 'a non-pony song, turned pony' + 'editor_title' => 'a non-pony song, turned pony', ]); DB::table('track_types')->insert([ 'title' => 'Official Show Audio Remix', - 'editor_title' => 'a remix of official show audio' + 'editor_title' => 'a remix of official show audio', ]); } diff --git a/database/legacy_migrations/2013_07_26_230827_create_images_table.php b/database/legacy_migrations/2013_07_26_230827_create_images_table.php index e320befe..bf97f8a5 100644 --- a/database/legacy_migrations/2013_07_26_230827_create_images_table.php +++ b/database/legacy_migrations/2013_07_26_230827_create_images_table.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/database/legacy_migrations/2013_07_28_034328_create_songs_table.php b/database/legacy_migrations/2013_07_28_034328_create_songs_table.php index a7ddd00d..4a3bd7c9 100644 --- a/database/legacy_migrations/2013_07_28_034328_create_songs_table.php +++ b/database/legacy_migrations/2013_07_28_034328_create_songs_table.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -42,7 +42,7 @@ class CreateSongsTable extends Migration DB::table('show_songs')->insert([ 'id' => 1, - 'title' => "Equestria Girls", + 'title' => 'Equestria Girls', 'lyrics' => "[Pinkie Pie] Ooh! This is my jam! @@ -117,11 +117,11 @@ Aoaoah oh, aoaoaoh! Break it down, DJ Pon-3 These are the ponies I love the most I wish you could all be Equestria girls", - 'slug' => "equestria-girls", + 'slug' => 'equestria-girls', ]); DB::table('show_songs')->insert([ 'id' => 2, - 'title' => "My Little Pony Theme Song", + 'title' => 'My Little Pony Theme Song', 'lyrics' => "[Backup singer] My Little Pony, My Little Pony Ahh, ahh, ahh, ahhh….. @@ -152,11 +152,11 @@ It's an easy feat And magic makes it all complete You have my little ponies Do you know you're all my very best friends?", - 'slug' => "my-little-pony-theme-song", + 'slug' => 'my-little-pony-theme-song', ]); DB::table('show_songs')->insert([ 'id' => 3, - 'title' => "Laughter Song", + 'title' => 'Laughter Song', 'lyrics' => "[Pinkie Pie] When I was a little filly and the sun was going down... @@ -196,7 +196,7 @@ Snortle at the spooky And tell that big dumb scary face to take a hike and leave you alone and if he thinks he can scare you then he's got another thing coming and the very idea of such a thing just makes you wanna... hahahaha... heh... Laaaaaaauuugh!", - 'slug' => "laughter-song", + 'slug' => 'laughter-song', ]); DB::table('show_songs')->insert([ 'id' => 4, @@ -217,11 +217,11 @@ Oh the Grand Galloping Gala is the best place for me 'Cause it's the most galarrific superly-terrific gala ever In the whole galaxy Wheee!", - 'slug' => "pinkies-gala-fantasy-song", + 'slug' => 'pinkies-gala-fantasy-song', ]); DB::table('show_songs')->insert([ 'id' => 5, - 'title' => "The Ticket Song", + 'title' => 'The Ticket Song', 'lyrics' => "[Pinkie Pie] Twilight is my bestest friend Whoopie, whoopie! @@ -242,21 +242,21 @@ Twilight Sparkle: Pinkie! She'll give her extra ticket to the gala to me! Twilight Sparkle: PIIINKIIIE!!", - 'slug' => "the-ticket-song", + 'slug' => 'the-ticket-song', ]); DB::table('show_songs')->insert([ 'id' => 6, - 'title' => "Junior Speedsters Chant", + 'title' => 'Junior Speedsters Chant', 'lyrics' => "[Rainbow Dash/Gilda] Junior Speedsters are our lives, Sky-bound soars and daring dives Junior Speedsters, it's our quest, To some day be the very best!", - 'slug' => "junior-speedsters-chant", + 'slug' => 'junior-speedsters-chant', ]); DB::table('show_songs')->insert([ 'id' => 7, - 'title' => "Hop Skip and Jump song", + 'title' => 'Hop Skip and Jump song', 'lyrics' => "[Pinkie Pie] It's not very far Just move your little rump @@ -272,11 +272,11 @@ A hop, skip and jump, A hop, skip and jump, A hop skip and jump, A hop skip and jump!", - 'slug' => "hop-skip-and-jump-song", + 'slug' => 'hop-skip-and-jump-song', ]); DB::table('show_songs')->insert([ 'id' => 8, - 'title' => "Evil Enchantress song", + 'title' => 'Evil Enchantress song', 'lyrics' => "[Pinkie Pie/Flutterguy] She's an evil enchantress She does evil dances @@ -287,11 +287,11 @@ She'll mix up an evil brew Then she'll gobble you up In a big tasty stew Soooo.... Watch out!", - 'slug' => "evil-enchantress-song", + 'slug' => 'evil-enchantress-song', ]); DB::table('show_songs')->insert([ 'id' => 9, - 'title' => "Winter Wrap Up", + 'title' => 'Winter Wrap Up', 'lyrics' => "[Rainbow Dash] Three months of winter coolness And awesome holidays @@ -427,11 +427,11 @@ Winter Wrap Up! Winter Wrap Up! 'Cause tomorrow spring is here 'Cause tomorrow spring is here 'Cause tomorrow spring is here!", - 'slug' => "winter-wrap-up", + 'slug' => 'winter-wrap-up', ]); DB::table('show_songs')->insert([ 'id' => 10, - 'title' => "Cupcake Song", + 'title' => 'Cupcake Song', 'lyrics' => "[Pinkie Pie] All you have to do is take a cup of flour! Add it to the mix! @@ -446,11 +446,11 @@ And you never get your fill of... Cupcakes! So sweet and tasty! Cupcakes! Don't be too hasty! Cupcakes! Cupcakes, cupcakes, CUPCAKES!", - 'slug' => "cupcake-song", + 'slug' => 'cupcake-song', ]); DB::table('show_songs')->insert([ 'id' => 11, - 'title' => "Art of the Dress", + 'title' => 'Art of the Dress', 'lyrics' => "[Rarity] Thread by thread, stitching it together Twilight's dress, cutting out the pattern snip by snip @@ -487,11 +487,11 @@ Croup, dock, haunch, shoulders, hip Thread by thread, primmed and pressed Yard by yard, never stressed And that's the art of the dress!", - 'slug' => "art-of-the-dress", + 'slug' => 'art-of-the-dress', ]); DB::table('show_songs')->insert([ 'id' => 12, - 'title' => "Hush Now Lullaby", + 'title' => 'Hush Now Lullaby', 'lyrics' => "[Fluttershy] Hush now, quiet now It's time to lay your sleepy head @@ -522,11 +522,11 @@ Said hush now! Quiet now! It's time to go to BED! OW!", - 'slug' => "hush-now-lullaby", + 'slug' => 'hush-now-lullaby', ]); DB::table('show_songs')->insert([ 'id' => 13, - 'title' => "Cutie Mark Crusaders Song", + 'title' => 'Cutie Mark Crusaders Song', 'lyrics' => "[Scootaloo] Look, here, are three little ponies Ready to sing for this crowd @@ -576,11 +576,11 @@ We are the Cutie Mark Crusaders On a quest to find out who we are And we will never stop the journey Not until we have our cutie marks!", - 'slug' => "cutie-mark-crusaders-song", + 'slug' => 'cutie-mark-crusaders-song', ]); DB::table('show_songs')->insert([ 'id' => 14, - 'title' => "You Got to Share, You Got to Care", + 'title' => 'You Got to Share, You Got to Care', 'lyrics' => "[Pinkie Pie] We may be divided But of you all, I beg @@ -614,11 +614,11 @@ You gotta care It's the right thing to do And there'll always be a way Thro-o-o-o-ugh!", - 'slug' => "you-got-to-share-you-got-to-care", + 'slug' => 'you-got-to-share-you-got-to-care', ]); DB::table('show_songs')->insert([ 'id' => 15, - 'title' => "So Many Wonders", + 'title' => 'So Many Wonders', 'lyrics' => "[Fluttershy] What is this place filled with so many wonders? @@ -638,7 +638,7 @@ If I knew the ground had so much up its sleeve I'd have come here sooner, and never leave Yes, I love everythiiiiiiiiiiiing!", - 'slug' => "so-many-wonders", + 'slug' => 'so-many-wonders', ]); DB::table('show_songs')->insert([ 'id' => 16, @@ -668,11 +668,11 @@ It won't be the same without you So we hope that you say yes So, please, oh please R.S.V.P And come, and be our guest!", - 'slug' => "pinkie-pies-singing-telegram", + 'slug' => 'pinkie-pies-singing-telegram', ]); DB::table('show_songs')->insert([ 'id' => 17, - 'title' => "At the Gala", + 'title' => 'At the Gala', 'lyrics' => "Twilight Sparkle: I can't believe we're finally here. With all that we've imagined, the reality of this night is sure to make this... The Best Night Ever! At the Gala @@ -783,7 +783,7 @@ Twilight Sparkle: To talk! Into the Gala, into the Gala! And we'll have the best night ever! At the Gala!", - 'slug' => "at-the-gala", + 'slug' => 'at-the-gala', ]); DB::table('show_songs')->insert([ 'id' => 18, @@ -800,11 +800,11 @@ I'm at the Grand Galloping GalaaaaaaaaaaAAAAAAAAAAAA! [pause] It's all I ever... dreamed?", - 'slug' => "im-at-the-grand-galloping-gala", + 'slug' => 'im-at-the-grand-galloping-gala', ]); DB::table('show_songs')->insert([ 'id' => 19, - 'title' => "Pony Pokey", + 'title' => 'Pony Pokey', 'lyrics' => "[Pinkie] You reach your right hoof in You reach your right hoof out @@ -850,11 +850,11 @@ You do the Pony Pokey And that's what it's all about Yeah!", - 'slug' => "pony-pokey", + 'slug' => 'pony-pokey', ]); DB::table('show_songs')->insert([ 'id' => 20, - 'title' => "Find A Pet Song", + 'title' => 'Find A Pet Song', 'lyrics' => "[Fluttershy] Now, Rainbow, my dear, I cannot express my delight It's abundantly clear @@ -989,11 +989,11 @@ May the games Begin Rainbow Dash: And may the best pet win!", - 'slug' => "find-a-pet-song", + 'slug' => 'find-a-pet-song', ]); DB::table('show_songs')->insert([ 'id' => 21, - 'title' => "Becoming Popular (The Pony Everypony Should Know)", + 'title' => 'Becoming Popular (The Pony Everypony Should Know)', 'lyrics' => "[Rarity] I'll be the toast of the town, the girl on the go I'm the type of pony everypony, everypony should know @@ -1018,11 +1018,11 @@ I'm the type of pony everypony, everypony should know Because I'm the type of pony Yes, I'm the type of pony Yes, I'm the type of pony everypony should know", - 'slug' => "becoming-popular-the-pony-everypony-should-know", + 'slug' => 'becoming-popular-the-pony-everypony-should-know', ]); DB::table('show_songs')->insert([ 'id' => 22, - 'title' => "The Heart Carol", + 'title' => 'The Heart Carol', 'lyrics' => "[Choir] The fire of friendship lives in our hearts As long as it burns we cannot drift apart @@ -1030,31 +1030,31 @@ Though quarrels arise, their numbers are few Laughter and singing will see us through (will see us through) We are a circle of pony friends A circle of friends we'll be to the very end", - 'slug' => "the-heart-carol", + 'slug' => 'the-heart-carol', ]); DB::table('show_songs')->insert([ 'id' => 23, - 'title' => "Happy Monthiversary", + 'title' => 'Happy Monthiversary', 'lyrics' => "[Pinkie Pie] Happy monthiversary to you and you today [very quickly] I can't believe you're already a month old time sure flies doesn't it well it seems like only yesterday you were born. But now you're a month old today, hey!", - 'slug' => "happy-monthiversary", + 'slug' => 'happy-monthiversary', ]); DB::table('show_songs')->insert([ 'id' => 24, - 'title' => "Piggy Dance", - 'lyrics' => "[Pinkie Pie] + 'title' => 'Piggy Dance', + 'lyrics' => '[Pinkie Pie] First you jiggle your tail! Oink oink oink! Then you wriggle your snout! Oink oink oink! Then you wiggle your rump! Oink oink oink! Then shout it out! Oink oink oink! -[repeat verse two more times]", - 'slug' => "piggy-dance", +[repeat verse two more times]', + 'slug' => 'piggy-dance', ]); DB::table('show_songs')->insert([ 'id' => 25, - 'title' => "The Flim Flam Brothers", + 'title' => 'The Flim Flam Brothers', 'lyrics' => "[Flim] Well, lookie what we got here, brother of mine, it's the same in every town Ponies with thirsty throats, dry tongues, and not a drop of cider to be found @@ -1215,11 +1215,11 @@ Traveling salesponies nonpareil [Flim and Flam] Yeah!", - 'slug' => "the-flim-flam-brothers", + 'slug' => 'the-flim-flam-brothers', ]); DB::table('show_songs')->insert([ 'id' => 26, - 'title' => "The Perfect Stallion", + 'title' => 'The Perfect Stallion', 'lyrics' => "[Sweetie Belle] Cheerilee is sweet and kind. She's the best teacher we could hope for. @@ -1298,11 +1298,11 @@ We did it girls. We've found the one. Who will send our teacher's heart aflutter. Apple Bloom: Wait a minute. Let me get this straight. Are you talking about my brother?", - 'slug' => "the-perfect-stallion", + 'slug' => 'the-perfect-stallion', ]); DB::table('show_songs')->insert([ 'id' => 27, - 'title' => "Smile Song", + 'title' => 'Smile Song', 'lyrics' => "[Pinkie Pie] My name is Pinkie Pie (Hello!) And I am here to say (How ya doin'?) @@ -1374,21 +1374,21 @@ Smile, smile, smile, smile, smile! [Pinkie Pie] Come on and smile Come on and smile!", - 'slug' => "smile-song", + 'slug' => 'smile-song', ]); DB::table('show_songs')->insert([ 'id' => 28, - 'title' => "Cranky Doodle Donkey", + 'title' => 'Cranky Doodle Donkey', 'lyrics' => "[Pinkie Pie] You're a Cranky Doodle Donkey guy. A Cranky Doodle Donkey. I never met you but you're my new friend and I'm your best friend Pinkie Pie!", - 'slug' => "cranky-doodle-donkey", + 'slug' => 'cranky-doodle-donkey', ]); DB::table('show_songs')->insert([ 'id' => 29, - 'title' => "Welcome Song", - 'lyrics' => "[Pinkie Pie] + 'title' => 'Welcome Song', + 'lyrics' => '[Pinkie Pie] Welcome welcome welcome A fine welcome to you Welcome welcome welcome @@ -1398,12 +1398,12 @@ I say hip hip hurray Welcome welcome welcome To Ponyville today -Pinkie Pie: Wait for it!", - 'slug' => "welcome-song", +Pinkie Pie: Wait for it!', + 'slug' => 'welcome-song', ]); DB::table('show_songs')->insert([ 'id' => 30, - 'title' => "Cranky Doodle Joy", + 'title' => 'Cranky Doodle Joy', 'lyrics' => "[Pinkie Pie] He had a Cranky Doodle sweetheart She's his cranky doodle joy @@ -1412,11 +1412,11 @@ I helped the Cranky Doodle boy! Cranky Doodle Donkey and Matilda: Pinkie! Pinkie Pie: Whoops, privacy. Sorry.", - 'slug' => "cranky-doodle-joy", + 'slug' => 'cranky-doodle-joy', ]); DB::table('show_songs')->insert([ 'id' => 31, - 'title' => "Big Brother Best Friend Forever (B.B.B.F.F.)", + 'title' => 'Big Brother Best Friend Forever (B.B.B.F.F.)', 'lyrics' => "[Twilight Sparkle] When I was just a filly, I found it rather silly To see how many other ponies I could meet @@ -1444,11 +1444,11 @@ I hoped that he would stay My big brother best friend Forever... Forever...", - 'slug' => "big-brother-best-friend-forever-bbbff", + 'slug' => 'big-brother-best-friend-forever-bbbff', ]); DB::table('show_songs')->insert([ 'id' => 32, - 'title' => "This Day Aria", + 'title' => 'This Day Aria', 'lyrics' => "[Queen Chrysalis] This day is going to be perfect The kind of day of which I've dreamed since I was small @@ -1495,11 +1495,11 @@ He'll end up marrying a fake Shining Armor will be [Queen Chrysalis]: ...mine, all mine. [evil laugh]", - 'slug' => "this-day-aria", + 'slug' => 'this-day-aria', ]); DB::table('show_songs')->insert([ 'id' => 33, - 'title' => "Love Is In Bloom", + 'title' => 'Love Is In Bloom', 'lyrics' => "[Twilight Sparkle] Love is in bloom A beautiful bride, a handsome groom, @@ -1522,11 +1522,11 @@ A beautiful bride, a handsome groom I said love is in bloom You're starting a life and making room For us, (For us... For us...Aah...)", - 'slug' => "love-is-in-bloom", + 'slug' => 'love-is-in-bloom', ]); DB::table('show_songs')->insert([ 'id' => 34, - 'title' => "The Failure Song", + 'title' => 'The Failure Song', 'lyrics' => "[Twilight Sparkle] I was prepared to do my best Thought I could handle any test @@ -1574,12 +1574,12 @@ No I wasn't [Twilight Sparkle and Spike] Prepared... for this!", - 'slug' => "the-failure-song", + 'slug' => 'the-failure-song', ]); DB::table('show_songs')->insert([ 'id' => 35, - 'title' => "The Ballad of the Crystal Empire", - 'lyrics' => "[Twilight Sparkle] + 'title' => 'The Ballad of the Crystal Empire', + 'lyrics' => '[Twilight Sparkle] Princess Cadence needs our help Her magic will not last forever I think we can do it @@ -1616,13 +1616,13 @@ Can you learn it in a day? [Twilight Sparkle, Rainbow Dash, Pinkie Pie, Applejack, Rarity, Fluttershy and Spike] Oh, we have to get this right Yes we have to make them see -We can save the Crystal Ponies... with their history!", - 'slug' => "the-ballad-of-the-crystal-empire", +We can save the Crystal Ponies... with their history!', + 'slug' => 'the-ballad-of-the-crystal-empire', ]); DB::table('show_songs')->insert([ 'id' => 36, - 'title' => "The Success Song", - 'lyrics' => "[Rarity] + 'title' => 'The Success Song', + 'lyrics' => '[Rarity] You were prepared to do your best Had what it takes to pass the test All those doubts you can dismiss @@ -1663,12 +1663,12 @@ Turns out I was Turns out you were [Spike, Applejack, Rainbow Dash, Rarity, Pinkie Pie, Fluttershy, and Twilight Sparkle] -Prepared... for this!", - 'slug' => "the-success-song", +Prepared... for this!', + 'slug' => 'the-success-song', ]); DB::table('show_songs')->insert([ 'id' => 37, - 'title' => "Babs Seed", + 'title' => 'Babs Seed', 'lyrics' => "[Cutie Mark Crusaders] Yeah, yeah, yeah Yeah, yeah, yeah @@ -1728,11 +1728,11 @@ Babs Seed, Babs Seed- [Scootaloo] She's just a bad, bad seed", - 'slug' => "babs-seed", + 'slug' => 'babs-seed', ]); DB::table('show_songs')->insert([ 'id' => 38, - 'title' => "Raise This Barn", + 'title' => 'Raise This Barn', 'lyrics' => "[Applejack] Yee-hoo! @@ -1823,11 +1823,11 @@ All we need to strive to be Is part of the Apple family Apple Bloom: Yeah!", - 'slug' => "raise-this-barn", + 'slug' => 'raise-this-barn', ]); DB::table('show_songs')->insert([ 'id' => 39, - 'title' => "Morning in Ponyville", + 'title' => 'Morning in Ponyville', 'lyrics' => "[Twilight Sparkle] Morning in Ponyville shimmers Morning in Ponyville shines @@ -1848,11 +1848,11 @@ Morning in Ponyville shimmers Morning in Ponyville shines And I know for absolute certain That everything is certainly...", - 'slug' => "morning-in-ponyville", + 'slug' => 'morning-in-ponyville', ]); DB::table('show_songs')->insert([ 'id' => 40, - 'title' => "What My Cutie Mark Is Telling Me", + 'title' => 'What My Cutie Mark Is Telling Me', 'lyrics' => "[Rainbow Dash] These animals don't listen, no, not one little bit They run around out of control and throw their hissy fits @@ -1900,7 +1900,7 @@ It's what my cutie mark [All] Yes, it's what my cutie mark is telling me!", - 'slug' => "what-my-cutie-mark-is-telling-me", + 'slug' => 'what-my-cutie-mark-is-telling-me', ]); DB::table('show_songs')->insert([ 'id' => 41, @@ -1919,11 +1919,11 @@ I don't know what to do I fear I won't get through to you Oh why, oh why", - 'slug' => "ive-got-to-find-a-way", + 'slug' => 'ive-got-to-find-a-way', ]); DB::table('show_songs')->insert([ 'id' => 42, - 'title' => "A True, True Friend", + 'title' => 'A True, True Friend', 'lyrics' => "[Twilight Sparkle] A true, true friend helps a friend in need @@ -2002,7 +2002,7 @@ A true, true friend helps a friend in need To see the light (to see the light) That shines (that shines) From a true, true friend!", - 'slug' => "a-true-true-friend", + 'slug' => 'a-true-true-friend', ]); DB::table('show_songs')->insert([ 'id' => 43, @@ -2021,12 +2021,12 @@ To go where you will go To see what you will see To find what you will be For it's time for you to fulfill your destiny", - 'slug' => "celestias-ballad", + 'slug' => 'celestias-ballad', ]); DB::table('show_songs')->insert([ 'id' => 44, - 'title' => "Behold, Princess Twilight Sparkle", - 'lyrics' => "[Choir] + 'title' => 'Behold, Princess Twilight Sparkle', + 'lyrics' => '[Choir] Thou Princess Twilight cometh Behold, behold A Princess here before us @@ -2036,13 +2036,13 @@ Behold, behold (behold, behold) The Princess Twilight cometh Behold, behold (behold, behold) The Princess is -The Princess is here", - 'slug' => "behold-princess-twilight-sparkle", +The Princess is here', + 'slug' => 'behold-princess-twilight-sparkle', ]); DB::table('show_songs')->insert([ 'id' => 45, - 'title' => "Life in Equestria", - 'lyrics' => "[Twilight Sparkle] + 'title' => 'Life in Equestria', + 'lyrics' => '[Twilight Sparkle] Life in Equestria shimmers Life in Equestria shines And I know for absolute certain @@ -2053,8 +2053,8 @@ Yes, everything Yes, everything is certainly fine It’s fine -Twilight Sparkle: Yes! Everything’s going to be just fine!", - 'slug' => "life-in-equestria", +Twilight Sparkle: Yes! Everything’s going to be just fine!', + 'slug' => 'life-in-equestria', ]); } diff --git a/database/legacy_migrations/2013_07_28_060804_create_albums.php b/database/legacy_migrations/2013_07_28_060804_create_albums.php index f6ee3174..dc0c65fc 100644 --- a/database/legacy_migrations/2013_07_28_060804_create_albums.php +++ b/database/legacy_migrations/2013_07_28_060804_create_albums.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/database/legacy_migrations/2013_07_28_135136_create_playlists.php b/database/legacy_migrations/2013_07_28_135136_create_playlists.php index a73b32f7..5985ce30 100644 --- a/database/legacy_migrations/2013_07_28_135136_create_playlists.php +++ b/database/legacy_migrations/2013_07_28_135136_create_playlists.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -84,5 +84,4 @@ class CreatePlaylists extends Migration Schema::drop('playlists'); } - } diff --git a/database/legacy_migrations/2013_08_01_051337_create_comments.php b/database/legacy_migrations/2013_08_01_051337_create_comments.php index fe236af2..98054e4c 100644 --- a/database/legacy_migrations/2013_08_01_051337_create_comments.php +++ b/database/legacy_migrations/2013_08_01_051337_create_comments.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/database/legacy_migrations/2013_08_18_041928_create_user_tables.php b/database/legacy_migrations/2013_08_18_041928_create_user_tables.php index d0a2c8e5..35c056a1 100644 --- a/database/legacy_migrations/2013_08_18_041928_create_user_tables.php +++ b/database/legacy_migrations/2013_08_18_041928_create_user_tables.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -43,9 +43,9 @@ class CreateUserTables extends Migration $table->foreign('artist_id')->references('id')->on('users')->on_delete('cascade'); $table->foreign('user_id')->references('id')->on('users')->on_delete('cascade'); - $table->foreign('track_id')->references('id')->on('tracks')->on_delete('cascade');; - $table->foreign('album_id')->references('id')->on('albums')->on_delete('cascade');; - $table->foreign('playlist_id')->references('id')->on('playlists')->on_delete('cascade');; + $table->foreign('track_id')->references('id')->on('tracks')->on_delete('cascade'); + $table->foreign('album_id')->references('id')->on('albums')->on_delete('cascade'); + $table->foreign('playlist_id')->references('id')->on('playlists')->on_delete('cascade'); $table->unique(['user_id', 'track_id', 'album_id', 'playlist_id', 'artist_id'], 'resource_unique'); }); diff --git a/database/legacy_migrations/2013_08_18_045248_create_favourites.php b/database/legacy_migrations/2013_08_18_045248_create_favourites.php index a9e15b54..5ad7fd4b 100644 --- a/database/legacy_migrations/2013_08_18_045248_create_favourites.php +++ b/database/legacy_migrations/2013_08_18_045248_create_favourites.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/database/legacy_migrations/2013_08_29_025516_create_followers.php b/database/legacy_migrations/2013_08_29_025516_create_followers.php index 188c9ceb..011c8b7a 100644 --- a/database/legacy_migrations/2013_08_29_025516_create_followers.php +++ b/database/legacy_migrations/2013_08_29_025516_create_followers.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/database/legacy_migrations/2013_09_01_025031_oauth.php b/database/legacy_migrations/2013_09_01_025031_oauth.php index 780ac208..67c595c5 100644 --- a/database/legacy_migrations/2013_09_01_025031_oauth.php +++ b/database/legacy_migrations/2013_09_01_025031_oauth.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/database/legacy_migrations/2013_09_01_232520_create_news_table.php b/database/legacy_migrations/2013_09_01_232520_create_news_table.php index 63e15ba9..e36e70b9 100644 --- a/database/legacy_migrations/2013_09_01_232520_create_news_table.php +++ b/database/legacy_migrations/2013_09_01_232520_create_news_table.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -38,5 +38,4 @@ class CreateNewsTable extends Migration { Schema::drop('news'); } - } diff --git a/database/legacy_migrations/2013_09_10_014644_create_latest_column.php b/database/legacy_migrations/2013_09_10_014644_create_latest_column.php index c41fbdce..1c28534c 100644 --- a/database/legacy_migrations/2013_09_10_014644_create_latest_column.php +++ b/database/legacy_migrations/2013_09_10_014644_create_latest_column.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/database/legacy_migrations/2013_09_23_031316_create_track_hashes.php b/database/legacy_migrations/2013_09_23_031316_create_track_hashes.php index 8c0a42e8..c4bea74d 100644 --- a/database/legacy_migrations/2013_09_23_031316_create_track_hashes.php +++ b/database/legacy_migrations/2013_09_23_031316_create_track_hashes.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -37,7 +37,6 @@ class CreateTrackHashes extends Migration Schema::table('tracks', function ($table) { $table->string('hash', 32)->notNullable()->change(); }); - } public function down() diff --git a/database/legacy_migrations/2013_09_24_055911_track_is_listed.php b/database/legacy_migrations/2013_09_24_055911_track_is_listed.php index 215295d7..0c71c725 100644 --- a/database/legacy_migrations/2013_09_24_055911_track_is_listed.php +++ b/database/legacy_migrations/2013_09_24_055911_track_is_listed.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/database/legacy_migrations/2014_05_28_071738_update_track_hash.php b/database/legacy_migrations/2014_05_28_071738_update_track_hash.php index c099a1f5..1bd05b6c 100644 --- a/database/legacy_migrations/2014_05_28_071738_update_track_hash.php +++ b/database/legacy_migrations/2014_05_28_071738_update_track_hash.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/database/legacy_migrations/2015_04_30_064436_add_remember_me_field.php b/database/legacy_migrations/2015_04_30_064436_add_remember_me_field.php index 781b83bc..c76cb8b7 100644 --- a/database/legacy_migrations/2015_04_30_064436_add_remember_me_field.php +++ b/database/legacy_migrations/2015_04_30_064436_add_remember_me_field.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/database/legacy_migrations/2015_05_20_155236_add_archived_profile_field.php b/database/legacy_migrations/2015_05_20_155236_add_archived_profile_field.php index f8ca8a93..e9d7e646 100644 --- a/database/legacy_migrations/2015_05_20_155236_add_archived_profile_field.php +++ b/database/legacy_migrations/2015_05_20_155236_add_archived_profile_field.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -22,7 +22,6 @@ use Illuminate\Database\Migrations\Migration; class AddArchivedProfileField extends Migration { - /** * Run the migrations. * @@ -46,5 +45,4 @@ class AddArchivedProfileField extends Migration $table->dropColumn('is_archived'); }); } - } diff --git a/database/legacy_migrations/2015_05_25_011121_create_track_files_table.php b/database/legacy_migrations/2015_05_25_011121_create_track_files_table.php index 3a91f689..cacdb98b 100644 --- a/database/legacy_migrations/2015_05_25_011121_create_track_files_table.php +++ b/database/legacy_migrations/2015_05_25_011121_create_track_files_table.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -21,10 +21,8 @@ use App\Models\Track; use Illuminate\Database\Migrations\Migration; - class CreateTrackFilesTable extends Migration { - /** * Run the migrations. * @@ -52,7 +50,7 @@ class CreateTrackFilesTable extends Migration 'is_master' => $name === 'FLAC' ? true : false, 'format' => $name, 'created_at' => $track->created_at, - 'updated_at' => Carbon\Carbon::now() + 'updated_at' => Carbon\Carbon::now(), ] ); } @@ -69,5 +67,4 @@ class CreateTrackFilesTable extends Migration { Schema::drop('track_files'); } - } diff --git a/database/legacy_migrations/2015_09_04_160648_make_email_nullable.php b/database/legacy_migrations/2015_09_04_160648_make_email_nullable.php index de26b8fc..8c9538ab 100644 --- a/database/legacy_migrations/2015_09_04_160648_make_email_nullable.php +++ b/database/legacy_migrations/2015_09_04_160648_make_email_nullable.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class MakeEmailNullable extends Migration { @@ -30,7 +30,7 @@ class MakeEmailNullable extends Migration */ public function up() { - Schema::table('users', function(Blueprint $table){ + Schema::table('users', function (Blueprint $table) { $table->string('email', 150)->nullable()->change(); }); } diff --git a/database/legacy_migrations/2015_09_05_113647_add_new_indices.php b/database/legacy_migrations/2015_09_05_113647_add_new_indices.php index 47fe7a11..9d3a7790 100644 --- a/database/legacy_migrations/2015_09_05_113647_add_new_indices.php +++ b/database/legacy_migrations/2015_09_05_113647_add_new_indices.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class AddNewIndices extends Migration { diff --git a/database/legacy_migrations/2015_09_05_143300_create_mlpma_table.php b/database/legacy_migrations/2015_09_05_143300_create_mlpma_table.php index 57539549..74b26c59 100644 --- a/database/legacy_migrations/2015_09_05_143300_create_mlpma_table.php +++ b/database/legacy_migrations/2015_09_05_143300_create_mlpma_table.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class CreateMlpmaTable extends Migration { @@ -30,7 +30,7 @@ class CreateMlpmaTable extends Migration */ public function up() { - Schema::create('mlpma_tracks', function(\Illuminate\Database\Schema\Blueprint $table) { + Schema::create('mlpma_tracks', function (Blueprint $table) { $table->increments('id'); $table->integer('track_id')->unsigned()->index(); $table->string('path')->index(); diff --git a/database/legacy_migrations/2015_09_12_225021_create_session_table.php b/database/legacy_migrations/2015_09_12_225021_create_session_table.php index 2a336a57..b44ded7f 100644 --- a/database/legacy_migrations/2015_09_12_225021_create_session_table.php +++ b/database/legacy_migrations/2015_09_12_225021_create_session_table.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class CreateSessionTable extends Migration { diff --git a/database/legacy_migrations/2015_09_29_035228_AddAlphabeticalIndices.php b/database/legacy_migrations/2015_09_29_035228_AddAlphabeticalIndices.php index 5e293b5c..f7471df1 100644 --- a/database/legacy_migrations/2015_09_29_035228_AddAlphabeticalIndices.php +++ b/database/legacy_migrations/2015_09_29_035228_AddAlphabeticalIndices.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class AddAlphabeticalIndices extends Migration { diff --git a/database/legacy_migrations/2015_10_26_192855_update_track_files_with_cache.php b/database/legacy_migrations/2015_10_26_192855_update_track_files_with_cache.php index e848db6f..2d72cfcf 100644 --- a/database/legacy_migrations/2015_10_26_192855_update_track_files_with_cache.php +++ b/database/legacy_migrations/2015_10_26_192855_update_track_files_with_cache.php @@ -3,7 +3,7 @@ /** * Pony.fm - A community for pony fan music. * Copyright (C) 2015 Feld0 - * Copyright (C) 2015 Kelvin Zhang + * Copyright (C) 2015 Kelvin Zhang. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -19,8 +19,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class UpdateTrackFilesWithCache extends Migration { diff --git a/database/legacy_migrations/2015_10_26_231224_AddTrackSourceColumn.php b/database/legacy_migrations/2015_10_26_231224_AddTrackSourceColumn.php index 094057fd..c4a0cdc5 100644 --- a/database/legacy_migrations/2015_10_26_231224_AddTrackSourceColumn.php +++ b/database/legacy_migrations/2015_10_26_231224_AddTrackSourceColumn.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class AddTrackSourceColumn extends Migration { @@ -30,7 +30,7 @@ class AddTrackSourceColumn extends Migration */ public function up() { - Schema::table('tracks', function(Blueprint $table){ + Schema::table('tracks', function (Blueprint $table) { $table->string('source', 40)->default('direct_upload'); }); @@ -49,7 +49,7 @@ class AddTrackSourceColumn extends Migration */ public function down() { - Schema::table('tracks', function(Blueprint $table){ + Schema::table('tracks', function (Blueprint $table) { $table->dropColumn('source'); }); } diff --git a/database/legacy_migrations/2015_10_28_162655_AddTrackFilesForDeletedTracks.php b/database/legacy_migrations/2015_10_28_162655_AddTrackFilesForDeletedTracks.php index de2aacb6..7c09bc5f 100644 --- a/database/legacy_migrations/2015_10_28_162655_AddTrackFilesForDeletedTracks.php +++ b/database/legacy_migrations/2015_10_28_162655_AddTrackFilesForDeletedTracks.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,9 +18,9 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Migrations\Migration; use App\Models\Track; +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class AddTrackFilesForDeletedTracks extends Migration { @@ -48,7 +48,7 @@ class AddTrackFilesForDeletedTracks extends Migration 'is_master' => $name === 'FLAC' ? true : false, 'format' => $name, 'created_at' => $track->created_at, - 'updated_at' => Carbon\Carbon::now() + 'updated_at' => Carbon\Carbon::now(), ] ); } diff --git a/database/legacy_migrations/2015_10_29_153827_update_track_files_with_filesize.php b/database/legacy_migrations/2015_10_29_153827_update_track_files_with_filesize.php index 6fd18847..1e629077 100644 --- a/database/legacy_migrations/2015_10_29_153827_update_track_files_with_filesize.php +++ b/database/legacy_migrations/2015_10_29_153827_update_track_files_with_filesize.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Kelvin Zhang + * Copyright (C) 2015 Kelvin Zhang. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by diff --git a/database/legacy_migrations/2015_11_05_004145_AddUnclassifiedTrackType.php b/database/legacy_migrations/2015_11_05_004145_AddUnclassifiedTrackType.php index b8adf4c1..1c5ae232 100644 --- a/database/legacy_migrations/2015_11_05_004145_AddUnclassifiedTrackType.php +++ b/database/legacy_migrations/2015_11_05_004145_AddUnclassifiedTrackType.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class AddUnclassifiedTrackType extends Migration { @@ -33,7 +33,7 @@ class AddUnclassifiedTrackType extends Migration DB::table('track_types')->insert([ 'id' => 6, 'title' => 'Unclassified', - 'editor_title' => 'an unclassified track' + 'editor_title' => 'an unclassified track', ]); } diff --git a/database/legacy_migrations/2015_11_21_020332_RenameUsernameAndIndexIsArchived.php b/database/legacy_migrations/2015_11_21_020332_RenameUsernameAndIndexIsArchived.php index fd8deca0..1006186a 100644 --- a/database/legacy_migrations/2015_11_21_020332_RenameUsernameAndIndexIsArchived.php +++ b/database/legacy_migrations/2015_11_21_020332_RenameUsernameAndIndexIsArchived.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class RenameUsernameAndIndexIsArchived extends Migration { @@ -30,7 +30,7 @@ class RenameUsernameAndIndexIsArchived extends Migration */ public function up() { - Schema::table('users', function(Blueprint $table) { + Schema::table('users', function (Blueprint $table) { $table->renameColumn('mlpforums_name', 'username'); $table->index('is_archived'); }); @@ -43,7 +43,7 @@ class RenameUsernameAndIndexIsArchived extends Migration */ public function down() { - Schema::table('users', function(Blueprint $table) { + Schema::table('users', function (Blueprint $table) { $table->renameColumn('username', 'mlpforums_name'); $table->dropIndex('users_is_archived_index'); }); diff --git a/database/legacy_migrations/2015_11_24_025733_create_revisions_table.php b/database/legacy_migrations/2015_11_24_025733_create_revisions_table.php index 338129ab..b51d66a2 100644 --- a/database/legacy_migrations/2015_11_24_025733_create_revisions_table.php +++ b/database/legacy_migrations/2015_11_24_025733_create_revisions_table.php @@ -1,7 +1,7 @@ . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class AddDeletedAtColumnToGenres extends Migration { @@ -30,7 +30,7 @@ class AddDeletedAtColumnToGenres extends Migration */ public function up() { - Schema::table('genres', function(Blueprint $table) { + Schema::table('genres', function (Blueprint $table) { $table->softDeletes()->index(); }); } @@ -42,7 +42,7 @@ class AddDeletedAtColumnToGenres extends Migration */ public function down() { - Schema::table('genres', function(Blueprint $table) { + Schema::table('genres', function (Blueprint $table) { $table->dropSoftDeletes(); }); } diff --git a/database/legacy_migrations/2015_12_05_235108_create_failed_jobs_table.php b/database/legacy_migrations/2015_12_05_235108_create_failed_jobs_table.php index c1ba41b4..16db8524 100644 --- a/database/legacy_migrations/2015_12_05_235108_create_failed_jobs_table.php +++ b/database/legacy_migrations/2015_12_05_235108_create_failed_jobs_table.php @@ -1,7 +1,7 @@ . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class ConvertTrackFileInProgressToStatus extends Migration { @@ -31,7 +31,7 @@ class ConvertTrackFileInProgressToStatus extends Migration public function up() { // - Schema::table('track_files', function(Blueprint $table) { + Schema::table('track_files', function (Blueprint $table) { $table->renameColumn('is_in_progress', 'status'); }); } diff --git a/database/legacy_migrations/2015_12_24_151903_add_sensible_defaults.php b/database/legacy_migrations/2015_12_24_151903_add_sensible_defaults.php index 3c01e6d9..cda97f83 100644 --- a/database/legacy_migrations/2015_12_24_151903_add_sensible_defaults.php +++ b/database/legacy_migrations/2015_12_24_151903_add_sensible_defaults.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class AddSensibleDefaults extends Migration { @@ -30,7 +30,7 @@ class AddSensibleDefaults extends Migration */ public function up() { - Schema::table('tracks', function(Blueprint $table){ + Schema::table('tracks', function (Blueprint $table) { $table->boolean('is_listed')->default(true)->change(); $table->boolean('is_explicit')->default(false)->change(); $table->boolean('is_vocal')->default(false)->change(); @@ -43,7 +43,7 @@ class AddSensibleDefaults extends Migration $table->unsignedInteger('comment_count')->default(0)->change(); }); - Schema::table('users', function(Blueprint $table){ + Schema::table('users', function (Blueprint $table) { $table->boolean('can_see_explicit_content')->default(false)->change(); $table->text('bio')->default('')->change(); $table->unsignedInteger('track_count')->default(0)->change(); diff --git a/database/legacy_migrations/2015_12_25_154727_add_more_defaults.php b/database/legacy_migrations/2015_12_25_154727_add_more_defaults.php index 5fe875a8..16b822d3 100644 --- a/database/legacy_migrations/2015_12_25_154727_add_more_defaults.php +++ b/database/legacy_migrations/2015_12_25_154727_add_more_defaults.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class AddMoreDefaults extends Migration { @@ -31,7 +31,6 @@ class AddMoreDefaults extends Migration public function up() { Schema::table('albums', function (Blueprint $table) { - $table->text('description')->default('')->change(); $table->unsignedInteger('view_count')->default(0)->change(); $table->unsignedInteger('download_count')->default(0)->change(); diff --git a/database/legacy_migrations/2015_12_25_155223_add_metadata_columns.php b/database/legacy_migrations/2015_12_25_155223_add_metadata_columns.php index a2f826af..1edc0067 100644 --- a/database/legacy_migrations/2015_12_25_155223_add_metadata_columns.php +++ b/database/legacy_migrations/2015_12_25_155223_add_metadata_columns.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class AddMetadataColumns extends Migration { @@ -30,7 +30,7 @@ class AddMetadataColumns extends Migration */ public function up() { - Schema::table('tracks', function(Blueprint $table) { + Schema::table('tracks', function (Blueprint $table) { $table->longText('metadata')->nullable(); $table->longText('original_tags')->nullable(); }); @@ -43,7 +43,7 @@ class AddMetadataColumns extends Migration */ public function down() { - Schema::table('tracks', function(Blueprint $table) { + Schema::table('tracks', function (Blueprint $table) { $table->dropColumn(['original_tags', 'metadata']); }); } diff --git a/database/legacy_migrations/2015_12_29_152005_add_account_disabled_column.php b/database/legacy_migrations/2015_12_29_152005_add_account_disabled_column.php index e7a46b91..ac519636 100644 --- a/database/legacy_migrations/2015_12_29_152005_add_account_disabled_column.php +++ b/database/legacy_migrations/2015_12_29_152005_add_account_disabled_column.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class AddAccountDisabledColumn extends Migration { @@ -30,7 +30,7 @@ class AddAccountDisabledColumn extends Migration */ public function up() { - Schema::table('users', function(Blueprint $table){ + Schema::table('users', function (Blueprint $table) { $table->dateTime('disabled_at')->nullable()->index(); }); } @@ -42,7 +42,7 @@ class AddAccountDisabledColumn extends Migration */ public function down() { - Schema::table('users', function(Blueprint $table){ + Schema::table('users', function (Blueprint $table) { $table->dropColumn('disabled_at'); }); } diff --git a/database/legacy_migrations/2016_01_01_001340_update_model_namespaces_in_revisions.php b/database/legacy_migrations/2016_01_01_001340_update_model_namespaces_in_revisions.php index b10a3d00..cac5cd10 100644 --- a/database/legacy_migrations/2016_01_01_001340_update_model_namespaces_in_revisions.php +++ b/database/legacy_migrations/2016_01_01_001340_update_model_namespaces_in_revisions.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class UpdateModelNamespacesInRevisions extends Migration { diff --git a/database/legacy_migrations/2016_01_06_123513_add_genre_timestamps.php b/database/legacy_migrations/2016_01_06_123513_add_genre_timestamps.php index d9570079..fa3eb717 100644 --- a/database/legacy_migrations/2016_01_06_123513_add_genre_timestamps.php +++ b/database/legacy_migrations/2016_01_06_123513_add_genre_timestamps.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class AddGenreTimestamps extends Migration { @@ -30,7 +30,7 @@ class AddGenreTimestamps extends Migration */ public function up() { - Schema::table('genres', function(Blueprint $table) { + Schema::table('genres', function (Blueprint $table) { $table->nullableTimestamps(); }); } @@ -42,7 +42,7 @@ class AddGenreTimestamps extends Migration */ public function down() { - Schema::table('genres', function(Blueprint $table) { + Schema::table('genres', function (Blueprint $table) { $table->dropTimestamps(); }); } diff --git a/database/legacy_migrations/2016_01_14_021607_setup_elasticsearch.php b/database/legacy_migrations/2016_01_14_021607_setup_elasticsearch.php index e1372e0e..7e306de7 100644 --- a/database/legacy_migrations/2016_01_14_021607_setup_elasticsearch.php +++ b/database/legacy_migrations/2016_01_14_021607_setup_elasticsearch.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -56,7 +56,7 @@ class SetupElasticsearch extends Migration // Note that all Elasticsearch fields can technically be used as arrays. // See: https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html 'show_songs' => ['type' => 'string'], - ] + ], ], 'album' => [ @@ -69,8 +69,8 @@ class SetupElasticsearch extends Migration // This field is intended to be used as an array. // Note that all Elasticsearch fields can technically be used as arrays. // See: https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html - 'tracks' => ['type' => 'string', 'analyzer' => 'english'] - ] + 'tracks' => ['type' => 'string', 'analyzer' => 'english'], + ], ], 'playlist' => [ @@ -83,8 +83,8 @@ class SetupElasticsearch extends Migration // This field is intended to be used as an array. // Note that all Elasticsearch fields can technically be used as arrays. // See: https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html - 'tracks' => ['type' => 'string', 'analyzer' => 'english'] - ] + 'tracks' => ['type' => 'string', 'analyzer' => 'english'], + ], ], 'user' => [ @@ -97,11 +97,11 @@ class SetupElasticsearch extends Migration // This field is intended to be used as an array. // Note that all Elasticsearch fields can technically be used as arrays. // See: https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html - 'tracks' => ['type' => 'string', 'analyzer' => 'english'] - ] + 'tracks' => ['type' => 'string', 'analyzer' => 'english'], + ], ], - ] - ] + ], + ], ]); Artisan::call('rebuild:search'); diff --git a/database/legacy_migrations/2016_01_23_062640_EnforceUniqueTracksInPlaylists.php b/database/legacy_migrations/2016_01_23_062640_EnforceUniqueTracksInPlaylists.php index 0d035586..d00223bb 100644 --- a/database/legacy_migrations/2016_01_23_062640_EnforceUniqueTracksInPlaylists.php +++ b/database/legacy_migrations/2016_01_23_062640_EnforceUniqueTracksInPlaylists.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,9 +18,9 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Migrations\Migration; use App\Models\Playlist; +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class EnforceUniqueTracksInPlaylists extends Migration { @@ -31,7 +31,7 @@ class EnforceUniqueTracksInPlaylists extends Migration */ public function up() { - DB::transaction(function(){ + DB::transaction(function () { $playlistIds = DB::table('playlists')->pluck('id'); foreach ($playlistIds as $playlistId) { @@ -41,7 +41,7 @@ class EnforceUniqueTracksInPlaylists extends Migration // duplicate track except for the first one. $ids = DB::select( DB::raw( -<<pluck('id'); DB::table('playlist_track') @@ -70,7 +69,7 @@ EOF $playlist = Playlist::with('tracks')->withTrashed()->find($playlistId); $position = 1; - foreach($playlist->tracks as $track) { + foreach ($playlist->tracks as $track) { $track->pivot->position = $position; $track->pivot->save(); $position++; @@ -78,7 +77,7 @@ EOF } }); - Schema::table('playlist_track', function(Blueprint $table) { + Schema::table('playlist_track', function (Blueprint $table) { $table->unique(['playlist_id', 'track_id']); }); diff --git a/database/legacy_migrations/2016_04_06_152844_create_notifications_tables.php b/database/legacy_migrations/2016_04_06_152844_create_notifications_tables.php index 285551b1..40cbc17e 100644 --- a/database/legacy_migrations/2016_04_06_152844_create_notifications_tables.php +++ b/database/legacy_migrations/2016_04_06_152844_create_notifications_tables.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class CreateNotificationsTables extends Migration { @@ -30,7 +30,7 @@ class CreateNotificationsTables extends Migration */ public function up() { - Schema::create('activities', function(Blueprint $table){ + Schema::create('activities', function (Blueprint $table) { $table->bigIncrements('id'); $table->dateTime('created_at')->index(); $table->unsignedInteger('user_id'); // initiator of the action @@ -39,13 +39,13 @@ class CreateNotificationsTables extends Migration $table->unsignedInteger('resource_id'); // ID of the entity this activity is about }); - Schema::create('notifications', function(Blueprint $table){ + Schema::create('notifications', function (Blueprint $table) { // Notifications are a pivot table between activities and users. $table->bigIncrements('id'); $table->unsignedBigInteger('activity_id')->index(); $table->unsignedInteger('user_id')->index(); // recipient of the notification $table->boolean('is_read')->default(false)->index(); - + $table->foreign('activity_id')->references('id')->on('activities')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users'); }); diff --git a/database/legacy_migrations/2016_06_05_193032_enforce_unique_slugs.php b/database/legacy_migrations/2016_06_05_193032_enforce_unique_slugs.php index 9fad962e..e7dfc8b2 100644 --- a/database/legacy_migrations/2016_06_05_193032_enforce_unique_slugs.php +++ b/database/legacy_migrations/2016_06_05_193032_enforce_unique_slugs.php @@ -1,7 +1,7 @@ where('id', $user->id) ->update([ 'slug' => $newSlug, - 'updated_at' => $now + 'updated_at' => $now, ]); $counter++; @@ -75,7 +75,7 @@ class EnforceUniqueSlugs extends Migration }); } - Schema::table('users', function(Blueprint $table) { + Schema::table('users', function (Blueprint $table) { $table->unique('slug'); }); } diff --git a/database/legacy_migrations/2016_06_05_221208_add_timestamps_to_show_songs.php b/database/legacy_migrations/2016_06_05_221208_add_timestamps_to_show_songs.php index 17a58bba..92b13a42 100644 --- a/database/legacy_migrations/2016_06_05_221208_add_timestamps_to_show_songs.php +++ b/database/legacy_migrations/2016_06_05_221208_add_timestamps_to_show_songs.php @@ -1,7 +1,7 @@ . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class FixCacheTable extends Migration { diff --git a/database/legacy_migrations/2016_06_15_080045_fix_cache_table_2.php b/database/legacy_migrations/2016_06_15_080045_fix_cache_table_2.php index acdbe799..317ffb41 100644 --- a/database/legacy_migrations/2016_06_15_080045_fix_cache_table_2.php +++ b/database/legacy_migrations/2016_06_15_080045_fix_cache_table_2.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class FixCacheTable2 extends Migration { diff --git a/database/migrations/2016_06_26_225535_create_activities_table.php b/database/migrations/2016_06_26_225535_create_activities_table.php index 3fb6943c..94ab2396 100644 --- a/database/migrations/2016_06_26_225535_create_activities_table.php +++ b/database/migrations/2016_06_26_225535_create_activities_table.php @@ -3,35 +3,32 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateActivitiesTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('activities', function(Blueprint $table) - { - $table->bigInteger('id', true)->unsigned(); - $table->dateTime('created_at')->index(); - $table->integer('user_id')->unsigned(); - $table->unsignedTinyInteger('activity_type'); - $table->unsignedTinyInteger('resource_type'); - $table->integer('resource_id')->unsigned(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('activities'); - } +class CreateActivitiesTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('activities', function (Blueprint $table) { + $table->bigInteger('id', true)->unsigned(); + $table->dateTime('created_at')->index(); + $table->integer('user_id')->unsigned(); + $table->unsignedTinyInteger('activity_type'); + $table->unsignedTinyInteger('resource_type'); + $table->integer('resource_id')->unsigned(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('activities'); + } } diff --git a/database/migrations/2016_06_26_225535_create_albums_table.php b/database/migrations/2016_06_26_225535_create_albums_table.php index 1a62ad78..4354ea43 100644 --- a/database/migrations/2016_06_26_225535_create_albums_table.php +++ b/database/migrations/2016_06_26_225535_create_albums_table.php @@ -3,42 +3,39 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateAlbumsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('albums', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('user_id')->unsigned()->index('albums_user_id_foreign'); - $table->string('title')->index(); - $table->string('slug')->index(); - $table->text('description', 65535); - $table->integer('cover_id')->unsigned()->nullable()->index('albums_cover_id_foreign'); - $table->integer('track_count')->unsigned()->default(0); - $table->integer('view_count')->unsigned()->default(0); - $table->integer('download_count')->unsigned()->default(0); - $table->integer('favourite_count')->unsigned()->default(0); - $table->integer('comment_count')->unsigned()->default(0); - $table->timestamps(); - $table->softDeletes()->index(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('albums'); - } +class CreateAlbumsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('albums', function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->unsigned()->index('albums_user_id_foreign'); + $table->string('title')->index(); + $table->string('slug')->index(); + $table->text('description', 65535); + $table->integer('cover_id')->unsigned()->nullable()->index('albums_cover_id_foreign'); + $table->integer('track_count')->unsigned()->default(0); + $table->integer('view_count')->unsigned()->default(0); + $table->integer('download_count')->unsigned()->default(0); + $table->integer('favourite_count')->unsigned()->default(0); + $table->integer('comment_count')->unsigned()->default(0); + $table->timestamps(); + $table->softDeletes()->index(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('albums'); + } } diff --git a/database/migrations/2016_06_26_225535_create_cache_table.php b/database/migrations/2016_06_26_225535_create_cache_table.php index af8bb77f..d9bd6af0 100644 --- a/database/migrations/2016_06_26_225535_create_cache_table.php +++ b/database/migrations/2016_06_26_225535_create_cache_table.php @@ -3,32 +3,29 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateCacheTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('cache', function(Blueprint $table) - { - $table->string('key')->index(); - $table->text('value', 65535); - $table->integer('expiration')->unsigned()->index(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('cache'); - } +class CreateCacheTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('cache', function (Blueprint $table) { + $table->string('key')->index(); + $table->text('value', 65535); + $table->integer('expiration')->unsigned()->index(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('cache'); + } } diff --git a/database/migrations/2016_06_26_225535_create_comments_table.php b/database/migrations/2016_06_26_225535_create_comments_table.php index cc93f9ca..7c7bbc7f 100644 --- a/database/migrations/2016_06_26_225535_create_comments_table.php +++ b/database/migrations/2016_06_26_225535_create_comments_table.php @@ -3,39 +3,36 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateCommentsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('comments', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('user_id')->unsigned()->index('comments_user_id_foreign'); - $table->string('ip_address', 46)->nullable(); - $table->text('content', 65535); - $table->timestamps(); - $table->softDeletes()->index(); - $table->integer('profile_id')->unsigned()->nullable()->index(); - $table->integer('track_id')->unsigned()->nullable()->index(); - $table->integer('album_id')->unsigned()->nullable()->index(); - $table->integer('playlist_id')->unsigned()->nullable()->index(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('comments'); - } +class CreateCommentsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('comments', function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->unsigned()->index('comments_user_id_foreign'); + $table->string('ip_address', 46)->nullable(); + $table->text('content', 65535); + $table->timestamps(); + $table->softDeletes()->index(); + $table->integer('profile_id')->unsigned()->nullable()->index(); + $table->integer('track_id')->unsigned()->nullable()->index(); + $table->integer('album_id')->unsigned()->nullable()->index(); + $table->integer('playlist_id')->unsigned()->nullable()->index(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('comments'); + } } diff --git a/database/migrations/2016_06_26_225535_create_failed_jobs_table_2.php b/database/migrations/2016_06_26_225535_create_failed_jobs_table_2.php index cf73737d..098a39f8 100644 --- a/database/migrations/2016_06_26_225535_create_failed_jobs_table_2.php +++ b/database/migrations/2016_06_26_225535_create_failed_jobs_table_2.php @@ -4,38 +4,35 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; /** - * Class CreateFailedJobsTable2 + * Class CreateFailedJobsTable2. * * This is the PostgreSQL version of CreateFailedJobsTable. */ -class CreateFailedJobsTable2 extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('failed_jobs', function(Blueprint $table) - { - $table->increments('id'); - $table->text('connection', 65535); - $table->text('queue', 65535); - $table->text('payload'); - $table->dateTime('failed_at')->default('now()'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('failed_jobs'); - } +class CreateFailedJobsTable2 extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('failed_jobs', function (Blueprint $table) { + $table->increments('id'); + $table->text('connection', 65535); + $table->text('queue', 65535); + $table->text('payload'); + $table->dateTime('failed_at')->default('now()'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('failed_jobs'); + } } diff --git a/database/migrations/2016_06_26_225535_create_favourites_table.php b/database/migrations/2016_06_26_225535_create_favourites_table.php index 7adadee3..7fd2c839 100644 --- a/database/migrations/2016_06_26_225535_create_favourites_table.php +++ b/database/migrations/2016_06_26_225535_create_favourites_table.php @@ -3,35 +3,32 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateFavouritesTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('favourites', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('user_id')->unsigned()->index(); - $table->integer('track_id')->unsigned()->nullable()->index(); - $table->integer('album_id')->unsigned()->nullable()->index(); - $table->integer('playlist_id')->unsigned()->nullable()->index(); - $table->dateTime('created_at')->default('now()')->nullable(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('favourites'); - } +class CreateFavouritesTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('favourites', function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->unsigned()->index(); + $table->integer('track_id')->unsigned()->nullable()->index(); + $table->integer('album_id')->unsigned()->nullable()->index(); + $table->integer('playlist_id')->unsigned()->nullable()->index(); + $table->dateTime('created_at')->default('now()')->nullable(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('favourites'); + } } diff --git a/database/migrations/2016_06_26_225535_create_followers_table.php b/database/migrations/2016_06_26_225535_create_followers_table.php index 48596cff..6e5b40d3 100644 --- a/database/migrations/2016_06_26_225535_create_followers_table.php +++ b/database/migrations/2016_06_26_225535_create_followers_table.php @@ -3,34 +3,31 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateFollowersTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('followers', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('user_id')->unsigned()->index(); - $table->integer('artist_id')->unsigned()->nullable()->index(); - $table->integer('playlist_id')->unsigned()->nullable()->index(); - $table->dateTime('created_at')->default('now()')->nullable(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('followers'); - } +class CreateFollowersTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('followers', function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->unsigned()->index(); + $table->integer('artist_id')->unsigned()->nullable()->index(); + $table->integer('playlist_id')->unsigned()->nullable()->index(); + $table->dateTime('created_at')->default('now()')->nullable(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('followers'); + } } diff --git a/database/migrations/2016_06_26_225535_create_genres_table.php b/database/migrations/2016_06_26_225535_create_genres_table.php index dcf2da07..fe5fabe2 100644 --- a/database/migrations/2016_06_26_225535_create_genres_table.php +++ b/database/migrations/2016_06_26_225535_create_genres_table.php @@ -3,34 +3,31 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateGenresTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('genres', function(Blueprint $table) - { - $table->increments('id'); - $table->string('name')->unique(); - $table->string('slug', 200)->index(); - $table->softDeletes()->index(); - $table->nullableTimestamps(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('genres'); - } +class CreateGenresTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('genres', function (Blueprint $table) { + $table->increments('id'); + $table->string('name')->unique(); + $table->string('slug', 200)->index(); + $table->softDeletes()->index(); + $table->nullableTimestamps(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('genres'); + } } diff --git a/database/migrations/2016_06_26_225535_create_images_table_2.php b/database/migrations/2016_06_26_225535_create_images_table_2.php index 692177e1..b559a08a 100644 --- a/database/migrations/2016_06_26_225535_create_images_table_2.php +++ b/database/migrations/2016_06_26_225535_create_images_table_2.php @@ -4,41 +4,38 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; /** - * Class CreateImagesTable2 + * Class CreateImagesTable2. * * This is the PostgreSQL version of CreateImagesTable. */ -class CreateImagesTable2 extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('images', function(Blueprint $table) - { - $table->increments('id'); - $table->string('filename', 256); - $table->string('mime', 100); - $table->string('extension', 32); - $table->unsignedInteger('size'); - $table->string('hash', 32)->index(); - $table->unsignedInteger('uploaded_by')->index(); - $table->timestamps(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('images'); - } +class CreateImagesTable2 extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('images', function (Blueprint $table) { + $table->increments('id'); + $table->string('filename', 256); + $table->string('mime', 100); + $table->string('extension', 32); + $table->unsignedInteger('size'); + $table->string('hash', 32)->index(); + $table->unsignedInteger('uploaded_by')->index(); + $table->timestamps(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('images'); + } } diff --git a/database/migrations/2016_06_26_225535_create_licenses_table.php b/database/migrations/2016_06_26_225535_create_licenses_table.php index f929562b..533cb3c4 100644 --- a/database/migrations/2016_06_26_225535_create_licenses_table.php +++ b/database/migrations/2016_06_26_225535_create_licenses_table.php @@ -3,8 +3,8 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateLicensesTable extends Migration { - +class CreateLicensesTable extends Migration +{ /** * Run the migrations. * @@ -12,8 +12,7 @@ class CreateLicensesTable extends Migration { */ public function up() { - Schema::create('licenses', function(Blueprint $table) - { + Schema::create('licenses', function (Blueprint $table) { $table->increments('id'); $table->string('title', 100); $table->text('description', 65535); @@ -28,7 +27,7 @@ class CreateLicensesTable extends Migration { 'description' => 'Only you and Pony.fm are allowed to distribute and broadcast the track.', 'affiliate_distribution' => 0, 'open_distribution' => 0, - 'remix' => 0 + 'remix' => 0, ]); DB::table('licenses')->insert([ @@ -37,7 +36,7 @@ class CreateLicensesTable extends Migration { 'description' => 'You, Pony.fm, and its affiliates may distribute and broadcast the track.', 'affiliate_distribution' => 1, 'open_distribution' => 0, - 'remix' => 0 + 'remix' => 0, ]); DB::table('licenses')->insert([ @@ -46,7 +45,7 @@ class CreateLicensesTable extends Migration { 'description' => 'Anyone is permitted to broadcast and distribute the song in its original form, with attribution to you.', 'affiliate_distribution' => 1, 'open_distribution' => 1, - 'remix' => 0 + 'remix' => 0, ]); DB::table('licenses')->insert([ @@ -55,11 +54,10 @@ class CreateLicensesTable extends Migration { 'description' => 'Anyone is permitted to broadcast and distribute the song in any form, or create derivative works based on it for any purpose, with attribution to you.', 'affiliate_distribution' => 1, 'open_distribution' => 1, - 'remix' => 1 + 'remix' => 1, ]); } - /** * Reverse the migrations. * @@ -69,5 +67,4 @@ class CreateLicensesTable extends Migration { { Schema::drop('licenses'); } - } diff --git a/database/migrations/2016_06_26_225535_create_mlpma_tracks_table.php b/database/migrations/2016_06_26_225535_create_mlpma_tracks_table.php index cd638e78..10b8aaa8 100644 --- a/database/migrations/2016_06_26_225535_create_mlpma_tracks_table.php +++ b/database/migrations/2016_06_26_225535_create_mlpma_tracks_table.php @@ -3,37 +3,34 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateMlpmaTracksTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('mlpma_tracks', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('track_id')->unsigned()->index(); - $table->string('path')->index(); - $table->string('filename')->index(); - $table->string('extension')->index(); - $table->dateTime('imported_at'); - $table->text('parsed_tags'); - $table->text('raw_tags'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('mlpma_tracks'); - } +class CreateMlpmaTracksTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('mlpma_tracks', function (Blueprint $table) { + $table->increments('id'); + $table->integer('track_id')->unsigned()->index(); + $table->string('path')->index(); + $table->string('filename')->index(); + $table->string('extension')->index(); + $table->dateTime('imported_at'); + $table->text('parsed_tags'); + $table->text('raw_tags'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('mlpma_tracks'); + } } diff --git a/database/migrations/2016_06_26_225535_create_news_table_2.php b/database/migrations/2016_06_26_225535_create_news_table_2.php index c0e5c874..21027659 100644 --- a/database/migrations/2016_06_26_225535_create_news_table_2.php +++ b/database/migrations/2016_06_26_225535_create_news_table_2.php @@ -4,37 +4,34 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; /** - * Class CreateNewsTable2 + * Class CreateNewsTable2. * * This is the PostgreSQL version of CreateNewsTable. */ -class CreateNewsTable2 extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('news', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('user_id')->unsigned()->index(); - $table->string('post_hash', 32)->index(); - $table->timestamps(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('news'); - } +class CreateNewsTable2 extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('news', function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->unsigned()->index(); + $table->string('post_hash', 32)->index(); + $table->timestamps(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('news'); + } } diff --git a/database/migrations/2016_06_26_225535_create_notifications_table.php b/database/migrations/2016_06_26_225535_create_notifications_table.php index 93f0c384..5e0601b9 100644 --- a/database/migrations/2016_06_26_225535_create_notifications_table.php +++ b/database/migrations/2016_06_26_225535_create_notifications_table.php @@ -3,33 +3,30 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateNotificationsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('notifications', function(Blueprint $table) - { - $table->bigInteger('id', true)->unsigned(); - $table->bigInteger('activity_id')->unsigned()->index(); - $table->integer('user_id')->unsigned()->index(); - $table->boolean('is_read')->default(false)->index(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('notifications'); - } +class CreateNotificationsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('notifications', function (Blueprint $table) { + $table->bigInteger('id', true)->unsigned(); + $table->bigInteger('activity_id')->unsigned()->index(); + $table->integer('user_id')->unsigned()->index(); + $table->boolean('is_read')->default(false)->index(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('notifications'); + } } diff --git a/database/migrations/2016_06_26_225535_create_oauth2_tokens_table.php b/database/migrations/2016_06_26_225535_create_oauth2_tokens_table.php index 1e4dc91c..149149ac 100644 --- a/database/migrations/2016_06_26_225535_create_oauth2_tokens_table.php +++ b/database/migrations/2016_06_26_225535_create_oauth2_tokens_table.php @@ -3,37 +3,34 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateOauth2TokensTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('oauth2_tokens', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('user_id')->unsigned(); - $table->integer('external_user_id')->unsigned(); - $table->text('access_token', 65535); - $table->dateTime('expires')->default('now()'); - $table->text('refresh_token', 65535); - $table->string('type'); - $table->string('service'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('oauth2_tokens'); - } +class CreateOauth2TokensTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('oauth2_tokens', function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->unsigned(); + $table->integer('external_user_id')->unsigned(); + $table->text('access_token', 65535); + $table->dateTime('expires')->default('now()'); + $table->text('refresh_token', 65535); + $table->string('type'); + $table->string('service'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('oauth2_tokens'); + } } diff --git a/database/migrations/2016_06_26_225535_create_pinned_playlists_table.php b/database/migrations/2016_06_26_225535_create_pinned_playlists_table.php index 14beeddf..a534b76e 100644 --- a/database/migrations/2016_06_26_225535_create_pinned_playlists_table.php +++ b/database/migrations/2016_06_26_225535_create_pinned_playlists_table.php @@ -3,33 +3,30 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreatePinnedPlaylistsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('pinned_playlists', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('user_id')->unsigned()->index(); - $table->integer('playlist_id')->unsigned()->index(); - $table->timestamps(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('pinned_playlists'); - } +class CreatePinnedPlaylistsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('pinned_playlists', function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->unsigned()->index(); + $table->integer('playlist_id')->unsigned()->index(); + $table->timestamps(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('pinned_playlists'); + } } diff --git a/database/migrations/2016_06_26_225535_create_playlist_track_table.php b/database/migrations/2016_06_26_225535_create_playlist_track_table.php index ba4e8274..4adadf33 100644 --- a/database/migrations/2016_06_26_225535_create_playlist_track_table.php +++ b/database/migrations/2016_06_26_225535_create_playlist_track_table.php @@ -3,35 +3,32 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreatePlaylistTrackTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('playlist_track', function(Blueprint $table) - { - $table->increments('id'); - $table->timestamps(); - $table->integer('playlist_id')->unsigned()->index(); - $table->integer('track_id')->unsigned()->index(); - $table->integer('position')->unsigned(); - $table->unique(['playlist_id','track_id']); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('playlist_track'); - } +class CreatePlaylistTrackTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('playlist_track', function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->integer('playlist_id')->unsigned()->index(); + $table->integer('track_id')->unsigned()->index(); + $table->integer('position')->unsigned(); + $table->unique(['playlist_id', 'track_id']); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('playlist_track'); + } } diff --git a/database/migrations/2016_06_26_225535_create_playlists_table.php b/database/migrations/2016_06_26_225535_create_playlists_table.php index 4f3382a7..f2547108 100644 --- a/database/migrations/2016_06_26_225535_create_playlists_table.php +++ b/database/migrations/2016_06_26_225535_create_playlists_table.php @@ -3,43 +3,40 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreatePlaylistsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('playlists', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('user_id')->unsigned()->index(); - $table->string('title')->index(); - $table->string('slug'); - $table->text('description', 65535); - $table->boolean('is_public')->index(); - $table->integer('track_count')->unsigned()->default(0)->index(); - $table->integer('view_count')->unsigned()->default(0); - $table->integer('download_count')->unsigned()->default(0); - $table->integer('favourite_count')->unsigned()->default(0); - $table->integer('follow_count')->unsigned()->default(0); - $table->integer('comment_count')->unsigned()->default(0); - $table->timestamps(); - $table->date('deleted_at')->nullable()->index(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('playlists'); - } +class CreatePlaylistsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('playlists', function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->unsigned()->index(); + $table->string('title')->index(); + $table->string('slug'); + $table->text('description', 65535); + $table->boolean('is_public')->index(); + $table->integer('track_count')->unsigned()->default(0)->index(); + $table->integer('view_count')->unsigned()->default(0); + $table->integer('download_count')->unsigned()->default(0); + $table->integer('favourite_count')->unsigned()->default(0); + $table->integer('follow_count')->unsigned()->default(0); + $table->integer('comment_count')->unsigned()->default(0); + $table->timestamps(); + $table->date('deleted_at')->nullable()->index(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('playlists'); + } } diff --git a/database/migrations/2016_06_26_225535_create_resource_log_items_table.php b/database/migrations/2016_06_26_225535_create_resource_log_items_table.php index 5b905d61..94dc16d8 100644 --- a/database/migrations/2016_06_26_225535_create_resource_log_items_table.php +++ b/database/migrations/2016_06_26_225535_create_resource_log_items_table.php @@ -3,38 +3,35 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateResourceLogItemsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('resource_log_items', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('user_id')->unsigned()->nullable()->index(); - $table->tinyInteger('log_type')->unsigned(); - $table->string('ip_address', 46)->index(); - $table->tinyInteger('track_format_id')->unsigned()->nullable(); - $table->integer('track_id')->unsigned()->nullable()->index(); - $table->integer('album_id')->unsigned()->nullable()->index(); - $table->integer('playlist_id')->unsigned()->nullable()->index(); - $table->dateTime('created_at')->default('now()'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('resource_log_items'); - } +class CreateResourceLogItemsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('resource_log_items', function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->unsigned()->nullable()->index(); + $table->tinyInteger('log_type')->unsigned(); + $table->string('ip_address', 46)->index(); + $table->tinyInteger('track_format_id')->unsigned()->nullable(); + $table->integer('track_id')->unsigned()->nullable()->index(); + $table->integer('album_id')->unsigned()->nullable()->index(); + $table->integer('playlist_id')->unsigned()->nullable()->index(); + $table->dateTime('created_at')->default('now()'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('resource_log_items'); + } } diff --git a/database/migrations/2016_06_26_225535_create_resource_users_table.php b/database/migrations/2016_06_26_225535_create_resource_users_table.php index 45328280..e7e42b11 100644 --- a/database/migrations/2016_06_26_225535_create_resource_users_table.php +++ b/database/migrations/2016_06_26_225535_create_resource_users_table.php @@ -3,42 +3,39 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateResourceUsersTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('resource_users', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('user_id')->unsigned()->index(); - $table->integer('track_id')->unsigned()->nullable()->index(); - $table->integer('album_id')->unsigned()->nullable()->index(); - $table->integer('playlist_id')->unsigned()->nullable()->index(); - $table->integer('artist_id')->unsigned()->nullable()->index(); - $table->boolean('is_followed')->default(false); - $table->boolean('is_favourited')->default(false); - $table->boolean('is_pinned')->default(false); - $table->unsignedInteger('view_count')->default(0); - $table->unsignedInteger('play_count')->default(0); - $table->unsignedInteger('download_count')->default(0); - $table->unique(['user_id','track_id','album_id','playlist_id','artist_id'], 'resource_unique'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('resource_users'); - } +class CreateResourceUsersTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('resource_users', function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->unsigned()->index(); + $table->integer('track_id')->unsigned()->nullable()->index(); + $table->integer('album_id')->unsigned()->nullable()->index(); + $table->integer('playlist_id')->unsigned()->nullable()->index(); + $table->integer('artist_id')->unsigned()->nullable()->index(); + $table->boolean('is_followed')->default(false); + $table->boolean('is_favourited')->default(false); + $table->boolean('is_pinned')->default(false); + $table->unsignedInteger('view_count')->default(0); + $table->unsignedInteger('play_count')->default(0); + $table->unsignedInteger('download_count')->default(0); + $table->unique(['user_id', 'track_id', 'album_id', 'playlist_id', 'artist_id'], 'resource_unique'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('resource_users'); + } } diff --git a/database/migrations/2016_06_26_225535_create_revisions_table_2.php b/database/migrations/2016_06_26_225535_create_revisions_table_2.php index cf4d7249..65257a4e 100644 --- a/database/migrations/2016_06_26_225535_create_revisions_table_2.php +++ b/database/migrations/2016_06_26_225535_create_revisions_table_2.php @@ -3,44 +3,40 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; - /** - * Class CreateRevisionsTable2 + * Class CreateRevisionsTable2. * * This is the PostgreSQL version of CreateRevisionsTable. */ -class CreateRevisionsTable2 extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('revisions', function(Blueprint $table) - { - $table->increments('id'); - $table->string('revisionable_type'); - $table->integer('revisionable_id'); - $table->unsignedInteger('user_id')->nullable(); - $table->string('key'); - $table->text('old_value', 65535)->nullable(); - $table->text('new_value', 65535)->nullable(); - $table->timestamps(); - $table->index(['revisionable_id','revisionable_type']); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('revisions'); - } +class CreateRevisionsTable2 extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('revisions', function (Blueprint $table) { + $table->increments('id'); + $table->string('revisionable_type'); + $table->integer('revisionable_id'); + $table->unsignedInteger('user_id')->nullable(); + $table->string('key'); + $table->text('old_value', 65535)->nullable(); + $table->text('new_value', 65535)->nullable(); + $table->timestamps(); + $table->index(['revisionable_id', 'revisionable_type']); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('revisions'); + } } diff --git a/database/migrations/2016_06_26_225535_create_role_user_table.php b/database/migrations/2016_06_26_225535_create_role_user_table.php index 96db8517..0b5af8a5 100644 --- a/database/migrations/2016_06_26_225535_create_role_user_table.php +++ b/database/migrations/2016_06_26_225535_create_role_user_table.php @@ -3,33 +3,30 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateRoleUserTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('role_user', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('user_id')->unsigned()->index(); - $table->integer('role_id')->unsigned()->index(); - $table->timestamps(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('role_user'); - } +class CreateRoleUserTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('role_user', function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->unsigned()->index(); + $table->integer('role_id')->unsigned()->index(); + $table->timestamps(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('role_user'); + } } diff --git a/database/migrations/2016_06_26_225535_create_roles_table.php b/database/migrations/2016_06_26_225535_create_roles_table.php index 38fa2000..729f4b7a 100644 --- a/database/migrations/2016_06_26_225535_create_roles_table.php +++ b/database/migrations/2016_06_26_225535_create_roles_table.php @@ -3,8 +3,8 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateRolesTable extends Migration { - +class CreateRolesTable extends Migration +{ /** * Run the migrations. * @@ -12,8 +12,7 @@ class CreateRolesTable extends Migration { */ public function up() { - Schema::create('roles', function(Blueprint $table) - { + Schema::create('roles', function (Blueprint $table) { $table->increments('id'); $table->string('name'); }); diff --git a/database/migrations/2016_06_26_225535_create_sessions_table.php b/database/migrations/2016_06_26_225535_create_sessions_table.php index f341e8d0..ca33a4a5 100644 --- a/database/migrations/2016_06_26_225535_create_sessions_table.php +++ b/database/migrations/2016_06_26_225535_create_sessions_table.php @@ -3,32 +3,29 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateSessionsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('sessions', function(Blueprint $table) - { - $table->string('id')->unique(); - $table->text('payload'); - $table->integer('last_activity'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('sessions'); - } +class CreateSessionsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('sessions', function (Blueprint $table) { + $table->string('id')->unique(); + $table->text('payload'); + $table->integer('last_activity'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('sessions'); + } } diff --git a/database/migrations/2016_06_26_225535_create_show_song_track_table.php b/database/migrations/2016_06_26_225535_create_show_song_track_table.php index f4cc9fb4..1275880d 100644 --- a/database/migrations/2016_06_26_225535_create_show_song_track_table.php +++ b/database/migrations/2016_06_26_225535_create_show_song_track_table.php @@ -3,32 +3,29 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateShowSongTrackTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('show_song_track', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('track_id')->unsigned()->index('show_song_track_track_id_foreign'); - $table->integer('show_song_id')->unsigned()->index('show_song_track_show_song_id_foreign'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('show_song_track'); - } +class CreateShowSongTrackTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('show_song_track', function (Blueprint $table) { + $table->increments('id'); + $table->integer('track_id')->unsigned()->index('show_song_track_track_id_foreign'); + $table->integer('show_song_id')->unsigned()->index('show_song_track_show_song_id_foreign'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('show_song_track'); + } } diff --git a/database/migrations/2016_06_26_225535_create_show_songs_table.php b/database/migrations/2016_06_26_225535_create_show_songs_table.php index a4937c64..5cc69bcb 100644 --- a/database/migrations/2016_06_26_225535_create_show_songs_table.php +++ b/database/migrations/2016_06_26_225535_create_show_songs_table.php @@ -3,35 +3,32 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateShowSongsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('show_songs', function(Blueprint $table) - { - $table->increments('id'); - $table->string('title', 100)->index('show_songs_title_fulltext'); - $table->text('lyrics', 65535); - $table->string('slug', 200); - $table->timestamps(); - $table->timestamp('deleted_at')->default(DB::raw('CURRENT_TIMESTAMP')); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('show_songs'); - } +class CreateShowSongsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('show_songs', function (Blueprint $table) { + $table->increments('id'); + $table->string('title', 100)->index('show_songs_title_fulltext'); + $table->text('lyrics', 65535); + $table->string('slug', 200); + $table->timestamps(); + $table->timestamp('deleted_at')->default(DB::raw('CURRENT_TIMESTAMP')); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('show_songs'); + } } diff --git a/database/migrations/2016_06_26_225535_create_subscriptions_table.php b/database/migrations/2016_06_26_225535_create_subscriptions_table.php index b34de79d..1070ba24 100644 --- a/database/migrations/2016_06_26_225535_create_subscriptions_table.php +++ b/database/migrations/2016_06_26_225535_create_subscriptions_table.php @@ -3,35 +3,32 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateSubscriptionsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('subscriptions', function(Blueprint $table) - { - $table->bigInteger('id', true)->unsigned(); - $table->integer('user_id')->unsigned()->index(); - $table->string('endpoint'); - $table->string('p256dh'); - $table->string('auth'); - $table->nullableTimestamps(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('subscriptions'); - } +class CreateSubscriptionsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('subscriptions', function (Blueprint $table) { + $table->bigInteger('id', true)->unsigned(); + $table->integer('user_id')->unsigned()->index(); + $table->string('endpoint'); + $table->string('p256dh'); + $table->string('auth'); + $table->nullableTimestamps(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('subscriptions'); + } } diff --git a/database/migrations/2016_06_26_225535_create_track_files_table_2.php b/database/migrations/2016_06_26_225535_create_track_files_table_2.php index 4556108d..b0535390 100644 --- a/database/migrations/2016_06_26_225535_create_track_files_table_2.php +++ b/database/migrations/2016_06_26_225535_create_track_files_table_2.php @@ -4,42 +4,39 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; /** - * Class CreateTrackFilesTable2 + * Class CreateTrackFilesTable2. * * This is the PostgreSQL version of CreateTrackFilesTable. */ -class CreateTrackFilesTable2 extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('track_files', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('track_id')->unsigned()->index('track_files_track_id_foreign'); - $table->boolean('is_master')->default(false)->index(); - $table->string('format')->index(); - $table->timestamps(); - $table->boolean('is_cacheable')->default(false)->index(); - $table->unsignedTinyInteger('status')->default(false); - $table->dateTime('expires_at')->nullable()->index(); - $table->integer('filesize')->unsigned()->nullable(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('track_files'); - } +class CreateTrackFilesTable2 extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('track_files', function (Blueprint $table) { + $table->increments('id'); + $table->integer('track_id')->unsigned()->index('track_files_track_id_foreign'); + $table->boolean('is_master')->default(false)->index(); + $table->string('format')->index(); + $table->timestamps(); + $table->boolean('is_cacheable')->default(false)->index(); + $table->unsignedTinyInteger('status')->default(false); + $table->dateTime('expires_at')->nullable()->index(); + $table->integer('filesize')->unsigned()->nullable(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('track_files'); + } } diff --git a/database/migrations/2016_06_26_225535_create_track_types_table.php b/database/migrations/2016_06_26_225535_create_track_types_table.php index 28adcb0e..d3b12a03 100644 --- a/database/migrations/2016_06_26_225535_create_track_types_table.php +++ b/database/migrations/2016_06_26_225535_create_track_types_table.php @@ -3,68 +3,65 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateTrackTypesTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('track_types', function(Blueprint $table) - { - $table->increments('id'); - $table->string('title'); - $table->string('editor_title'); - }); +class CreateTrackTypesTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('track_types', function (Blueprint $table) { + $table->increments('id'); + $table->string('title'); + $table->string('editor_title'); + }); DB::table('track_types')->insert([ 'id' => 1, 'title' => 'Original Song', - 'editor_title' => 'an original song' + 'editor_title' => 'an original song', ]); DB::table('track_types')->insert([ 'id' => 2, 'title' => 'Official Song Remix', - 'editor_title' => 'a remix of an official song' + 'editor_title' => 'a remix of an official song', ]); DB::table('track_types')->insert([ 'id' => 3, 'title' => 'Fan Song Remix', - 'editor_title' => 'a remix of a fan song' + 'editor_title' => 'a remix of a fan song', ]); DB::table('track_types')->insert([ 'id' => 4, 'title' => 'Ponified Song', - 'editor_title' => 'a non-pony song, turned pony' + 'editor_title' => 'a non-pony song, turned pony', ]); DB::table('track_types')->insert([ 'id' => 5, 'title' => 'Official Show Audio Remix', - 'editor_title' => 'a remix of official show audio' + 'editor_title' => 'a remix of official show audio', ]); DB::table('track_types')->insert([ 'id' => 6, 'title' => 'Unclassified', - 'editor_title' => 'an unclassified track' + 'editor_title' => 'an unclassified track', ]); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('track_types'); - } + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('track_types'); + } } diff --git a/database/migrations/2016_06_26_225535_create_tracks_table_2.php b/database/migrations/2016_06_26_225535_create_tracks_table_2.php index 3872884f..bfa4cb6b 100644 --- a/database/migrations/2016_06_26_225535_create_tracks_table_2.php +++ b/database/migrations/2016_06_26_225535_create_tracks_table_2.php @@ -4,64 +4,61 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; /** - * Class CreateTracksTable2 - * + * Class CreateTracksTable2. + * * This is the PostgreSQL version of CreateTracksTable. */ -class CreateTracksTable2 extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('tracks', function(Blueprint $table) - { - $table->increments('id'); - $table->integer('user_id')->unsigned()->index('tracks_user_id_foreign'); - $table->integer('license_id')->unsigned()->nullable()->index('tracks_license_id_foreign'); - $table->integer('genre_id')->unsigned()->nullable()->index(); - $table->integer('track_type_id')->unsigned()->nullable()->index('tracks_track_type_id_foreign'); - $table->string('title', 100)->index(); - $table->string('slug', 200)->index(); - $table->text('description', 65535)->nullable(); - $table->text('lyrics', 65535)->nullable(); - $table->boolean('is_vocal')->default(0); - $table->boolean('is_explicit')->default(0); - $table->integer('cover_id')->unsigned()->nullable()->index('tracks_cover_id_foreign'); - $table->boolean('is_downloadable')->default(0); - $table->float('duration')->unsigned(); - $table->integer('play_count')->unsigned()->default(0); - $table->integer('view_count')->unsigned()->default(0); - $table->integer('download_count')->unsigned()->default(0); - $table->integer('favourite_count')->unsigned()->default(0); - $table->integer('comment_count')->unsigned()->default(0); - $table->timestamps(); - $table->softDeletes()->index(); - $table->dateTime('published_at')->nullable()->index(); - $table->dateTime('released_at')->nullable(); - $table->integer('album_id')->unsigned()->nullable()->index('tracks_album_id_foreign'); - $table->integer('track_number')->unsigned()->nullable(); - $table->boolean('is_latest')->default(0); - $table->string('hash', 32)->nullable(); - $table->boolean('is_listed')->default(1); - $table->string('source', 40)->default('direct_upload'); - $table->jsonb('metadata')->nullable(); - $table->jsonb('original_tags')->nullable(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('tracks'); - } +class CreateTracksTable2 extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('tracks', function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->unsigned()->index('tracks_user_id_foreign'); + $table->integer('license_id')->unsigned()->nullable()->index('tracks_license_id_foreign'); + $table->integer('genre_id')->unsigned()->nullable()->index(); + $table->integer('track_type_id')->unsigned()->nullable()->index('tracks_track_type_id_foreign'); + $table->string('title', 100)->index(); + $table->string('slug', 200)->index(); + $table->text('description', 65535)->nullable(); + $table->text('lyrics', 65535)->nullable(); + $table->boolean('is_vocal')->default(0); + $table->boolean('is_explicit')->default(0); + $table->integer('cover_id')->unsigned()->nullable()->index('tracks_cover_id_foreign'); + $table->boolean('is_downloadable')->default(0); + $table->float('duration')->unsigned(); + $table->integer('play_count')->unsigned()->default(0); + $table->integer('view_count')->unsigned()->default(0); + $table->integer('download_count')->unsigned()->default(0); + $table->integer('favourite_count')->unsigned()->default(0); + $table->integer('comment_count')->unsigned()->default(0); + $table->timestamps(); + $table->softDeletes()->index(); + $table->dateTime('published_at')->nullable()->index(); + $table->dateTime('released_at')->nullable(); + $table->integer('album_id')->unsigned()->nullable()->index('tracks_album_id_foreign'); + $table->integer('track_number')->unsigned()->nullable(); + $table->boolean('is_latest')->default(0); + $table->string('hash', 32)->nullable(); + $table->boolean('is_listed')->default(1); + $table->string('source', 40)->default('direct_upload'); + $table->jsonb('metadata')->nullable(); + $table->jsonb('original_tags')->nullable(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('tracks'); + } } diff --git a/database/migrations/2016_06_26_225535_create_users_table_2.php b/database/migrations/2016_06_26_225535_create_users_table_2.php index 6508e040..01c15eeb 100644 --- a/database/migrations/2016_06_26_225535_create_users_table_2.php +++ b/database/migrations/2016_06_26_225535_create_users_table_2.php @@ -4,50 +4,47 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; /** - * Class CreateUsersTable2 + * Class CreateUsersTable2. * * This is the PostgreSQL version of CreateUsersTable. */ -class CreateUsersTable2 extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('users', function(Blueprint $table) - { - $table->increments('id'); - $table->string('display_name')->index(); - $table->string('username')->nullable(); - $table->boolean('sync_names')->default(true); - $table->string('email', 150)->nullable(); - $table->string('gravatar')->nullable(); - $table->string('slug')->unique(); - $table->boolean('uses_gravatar')->default(true); - $table->boolean('can_see_explicit_content')->default(false); - $table->text('bio', 65535)->default(''); - $table->integer('track_count')->unsigned()->default(0)->index(); - $table->integer('comment_count')->unsigned()->default(0); - $table->timestamps(); - $table->integer('avatar_id')->unsigned()->nullable()->index('users_avatar_id_foreign'); - $table->string('remember_token', 100)->nullable(); - $table->boolean('is_archived')->default(false)->index(); - $table->dateTime('disabled_at')->nullable()->index(); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('users'); - } +class CreateUsersTable2 extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('users', function (Blueprint $table) { + $table->increments('id'); + $table->string('display_name')->index(); + $table->string('username')->nullable(); + $table->boolean('sync_names')->default(true); + $table->string('email', 150)->nullable(); + $table->string('gravatar')->nullable(); + $table->string('slug')->unique(); + $table->boolean('uses_gravatar')->default(true); + $table->boolean('can_see_explicit_content')->default(false); + $table->text('bio', 65535)->default(''); + $table->integer('track_count')->unsigned()->default(0)->index(); + $table->integer('comment_count')->unsigned()->default(0); + $table->timestamps(); + $table->integer('avatar_id')->unsigned()->nullable()->index('users_avatar_id_foreign'); + $table->string('remember_token', 100)->nullable(); + $table->boolean('is_archived')->default(false)->index(); + $table->dateTime('disabled_at')->nullable()->index(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('users'); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_albums_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_albums_table.php index add196b6..03735a70 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_albums_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_albums_table.php @@ -3,35 +3,31 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToAlbumsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('albums', function(Blueprint $table) - { - $table->foreign('cover_id')->references('id')->on('images')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('albums', function(Blueprint $table) - { - $table->dropForeign('albums_cover_id_foreign'); - $table->dropForeign('albums_user_id_foreign'); - }); - } +class AddForeignKeysToAlbumsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('albums', function (Blueprint $table) { + $table->foreign('cover_id')->references('id')->on('images')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('albums', function (Blueprint $table) { + $table->dropForeign('albums_cover_id_foreign'); + $table->dropForeign('albums_user_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_comments_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_comments_table.php index c53d84b1..41e775a9 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_comments_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_comments_table.php @@ -3,41 +3,37 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToCommentsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('comments', function(Blueprint $table) - { - $table->foreign('album_id')->references('id')->on('albums')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('playlist_id')->references('id')->on('playlists')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('profile_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('comments', function(Blueprint $table) - { - $table->dropForeign('comments_album_id_foreign'); - $table->dropForeign('comments_playlist_id_foreign'); - $table->dropForeign('comments_profile_id_foreign'); - $table->dropForeign('comments_track_id_foreign'); - $table->dropForeign('comments_user_id_foreign'); - }); - } +class AddForeignKeysToCommentsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('comments', function (Blueprint $table) { + $table->foreign('album_id')->references('id')->on('albums')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('playlist_id')->references('id')->on('playlists')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('profile_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('comments', function (Blueprint $table) { + $table->dropForeign('comments_album_id_foreign'); + $table->dropForeign('comments_playlist_id_foreign'); + $table->dropForeign('comments_profile_id_foreign'); + $table->dropForeign('comments_track_id_foreign'); + $table->dropForeign('comments_user_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_favourites_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_favourites_table.php index e6372454..07d262ac 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_favourites_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_favourites_table.php @@ -3,39 +3,35 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToFavouritesTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('favourites', function(Blueprint $table) - { - $table->foreign('album_id')->references('id')->on('albums')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('playlist_id')->references('id')->on('playlists')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('favourites', function(Blueprint $table) - { - $table->dropForeign('favourites_album_id_foreign'); - $table->dropForeign('favourites_playlist_id_foreign'); - $table->dropForeign('favourites_track_id_foreign'); - $table->dropForeign('favourites_user_id_foreign'); - }); - } +class AddForeignKeysToFavouritesTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('favourites', function (Blueprint $table) { + $table->foreign('album_id')->references('id')->on('albums')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('playlist_id')->references('id')->on('playlists')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('favourites', function (Blueprint $table) { + $table->dropForeign('favourites_album_id_foreign'); + $table->dropForeign('favourites_playlist_id_foreign'); + $table->dropForeign('favourites_track_id_foreign'); + $table->dropForeign('favourites_user_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_followers_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_followers_table.php index f18e0447..e7e8612f 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_followers_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_followers_table.php @@ -3,37 +3,33 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToFollowersTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('followers', function(Blueprint $table) - { - $table->foreign('artist_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('playlist_id')->references('id')->on('playlists')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('followers', function(Blueprint $table) - { - $table->dropForeign('followers_artist_id_foreign'); - $table->dropForeign('followers_playlist_id_foreign'); - $table->dropForeign('followers_user_id_foreign'); - }); - } +class AddForeignKeysToFollowersTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('followers', function (Blueprint $table) { + $table->foreign('artist_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('playlist_id')->references('id')->on('playlists')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('followers', function (Blueprint $table) { + $table->dropForeign('followers_artist_id_foreign'); + $table->dropForeign('followers_playlist_id_foreign'); + $table->dropForeign('followers_user_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_images_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_images_table.php index 382d079e..6941115f 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_images_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_images_table.php @@ -3,33 +3,29 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToImagesTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('images', function(Blueprint $table) - { - $table->foreign('uploaded_by')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('images', function(Blueprint $table) - { - $table->dropForeign('images_uploaded_by_foreign'); - }); - } +class AddForeignKeysToImagesTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('images', function (Blueprint $table) { + $table->foreign('uploaded_by')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('images', function (Blueprint $table) { + $table->dropForeign('images_uploaded_by_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_mlpma_tracks_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_mlpma_tracks_table.php index f684544e..d470726a 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_mlpma_tracks_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_mlpma_tracks_table.php @@ -3,33 +3,29 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToMlpmaTracksTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('mlpma_tracks', function(Blueprint $table) - { - $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('mlpma_tracks', function(Blueprint $table) - { - $table->dropForeign('mlpma_tracks_track_id_foreign'); - }); - } +class AddForeignKeysToMlpmaTracksTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('mlpma_tracks', function (Blueprint $table) { + $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('mlpma_tracks', function (Blueprint $table) { + $table->dropForeign('mlpma_tracks_track_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_news_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_news_table.php index 47c4becc..82fa5911 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_news_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_news_table.php @@ -3,33 +3,29 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToNewsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('news', function(Blueprint $table) - { - $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('CASCADE'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('news', function(Blueprint $table) - { - $table->dropForeign('news_user_id_foreign'); - }); - } +class AddForeignKeysToNewsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('news', function (Blueprint $table) { + $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('CASCADE'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('news', function (Blueprint $table) { + $table->dropForeign('news_user_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_notifications_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_notifications_table.php index 752fb671..98cf4ff6 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_notifications_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_notifications_table.php @@ -3,35 +3,31 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToNotificationsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('notifications', function(Blueprint $table) - { - $table->foreign('activity_id')->references('id')->on('activities')->onUpdate('RESTRICT')->onDelete('CASCADE'); - $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('notifications', function(Blueprint $table) - { - $table->dropForeign('notifications_activity_id_foreign'); - $table->dropForeign('notifications_user_id_foreign'); - }); - } +class AddForeignKeysToNotificationsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('notifications', function (Blueprint $table) { + $table->foreign('activity_id')->references('id')->on('activities')->onUpdate('RESTRICT')->onDelete('CASCADE'); + $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('notifications', function (Blueprint $table) { + $table->dropForeign('notifications_activity_id_foreign'); + $table->dropForeign('notifications_user_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_pinned_playlists_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_pinned_playlists_table.php index bc007b11..c049da71 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_pinned_playlists_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_pinned_playlists_table.php @@ -3,35 +3,31 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToPinnedPlaylistsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('pinned_playlists', function(Blueprint $table) - { - $table->foreign('playlist_id')->references('id')->on('playlists')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('pinned_playlists', function(Blueprint $table) - { - $table->dropForeign('pinned_playlists_playlist_id_foreign'); - $table->dropForeign('pinned_playlists_user_id_foreign'); - }); - } +class AddForeignKeysToPinnedPlaylistsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('pinned_playlists', function (Blueprint $table) { + $table->foreign('playlist_id')->references('id')->on('playlists')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('pinned_playlists', function (Blueprint $table) { + $table->dropForeign('pinned_playlists_playlist_id_foreign'); + $table->dropForeign('pinned_playlists_user_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_playlist_track_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_playlist_track_table.php index 0f1b08a5..25b9b556 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_playlist_track_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_playlist_track_table.php @@ -3,35 +3,31 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToPlaylistTrackTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('playlist_track', function(Blueprint $table) - { - $table->foreign('playlist_id')->references('id')->on('playlists')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('playlist_track', function(Blueprint $table) - { - $table->dropForeign('playlist_track_playlist_id_foreign'); - $table->dropForeign('playlist_track_track_id_foreign'); - }); - } +class AddForeignKeysToPlaylistTrackTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('playlist_track', function (Blueprint $table) { + $table->foreign('playlist_id')->references('id')->on('playlists')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('playlist_track', function (Blueprint $table) { + $table->dropForeign('playlist_track_playlist_id_foreign'); + $table->dropForeign('playlist_track_track_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_playlists_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_playlists_table.php index f28f06f3..6e3d81c5 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_playlists_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_playlists_table.php @@ -3,33 +3,29 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToPlaylistsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('playlists', function(Blueprint $table) - { - $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('playlists', function(Blueprint $table) - { - $table->dropForeign('playlists_user_id_foreign'); - }); - } +class AddForeignKeysToPlaylistsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('playlists', function (Blueprint $table) { + $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('playlists', function (Blueprint $table) { + $table->dropForeign('playlists_user_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_resource_log_items_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_resource_log_items_table.php index 8c05d9c8..5d555bad 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_resource_log_items_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_resource_log_items_table.php @@ -3,39 +3,35 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToResourceLogItemsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('resource_log_items', function(Blueprint $table) - { - $table->foreign('album_id')->references('id')->on('albums')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('playlist_id')->references('id')->on('playlists')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('resource_log_items', function(Blueprint $table) - { - $table->dropForeign('resource_log_items_album_id_foreign'); - $table->dropForeign('resource_log_items_playlist_id_foreign'); - $table->dropForeign('resource_log_items_track_id_foreign'); - $table->dropForeign('resource_log_items_user_id_foreign'); - }); - } +class AddForeignKeysToResourceLogItemsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('resource_log_items', function (Blueprint $table) { + $table->foreign('album_id')->references('id')->on('albums')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('playlist_id')->references('id')->on('playlists')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('resource_log_items', function (Blueprint $table) { + $table->dropForeign('resource_log_items_album_id_foreign'); + $table->dropForeign('resource_log_items_playlist_id_foreign'); + $table->dropForeign('resource_log_items_track_id_foreign'); + $table->dropForeign('resource_log_items_user_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_resource_users_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_resource_users_table.php index be4d39fb..bee61a69 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_resource_users_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_resource_users_table.php @@ -3,41 +3,37 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToResourceUsersTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('resource_users', function(Blueprint $table) - { - $table->foreign('album_id')->references('id')->on('albums')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('artist_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('playlist_id')->references('id')->on('playlists')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('resource_users', function(Blueprint $table) - { - $table->dropForeign('resource_users_album_id_foreign'); - $table->dropForeign('resource_users_artist_id_foreign'); - $table->dropForeign('resource_users_playlist_id_foreign'); - $table->dropForeign('resource_users_track_id_foreign'); - $table->dropForeign('resource_users_user_id_foreign'); - }); - } +class AddForeignKeysToResourceUsersTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('resource_users', function (Blueprint $table) { + $table->foreign('album_id')->references('id')->on('albums')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('artist_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('playlist_id')->references('id')->on('playlists')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('resource_users', function (Blueprint $table) { + $table->dropForeign('resource_users_album_id_foreign'); + $table->dropForeign('resource_users_artist_id_foreign'); + $table->dropForeign('resource_users_playlist_id_foreign'); + $table->dropForeign('resource_users_track_id_foreign'); + $table->dropForeign('resource_users_user_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_role_user_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_role_user_table.php index 21bff8bd..e0568e60 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_role_user_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_role_user_table.php @@ -3,35 +3,31 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToRoleUserTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('role_user', function(Blueprint $table) - { - $table->foreign('role_id')->references('id')->on('roles')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('role_user', function(Blueprint $table) - { - $table->dropForeign('role_user_role_id_foreign'); - $table->dropForeign('role_user_user_id_foreign'); - }); - } +class AddForeignKeysToRoleUserTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('role_user', function (Blueprint $table) { + $table->foreign('role_id')->references('id')->on('roles')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('role_user', function (Blueprint $table) { + $table->dropForeign('role_user_role_id_foreign'); + $table->dropForeign('role_user_user_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_show_song_track_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_show_song_track_table.php index 0d1c42cc..dc09a7b3 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_show_song_track_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_show_song_track_table.php @@ -3,35 +3,31 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToShowSongTrackTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('show_song_track', function(Blueprint $table) - { - $table->foreign('show_song_id')->references('id')->on('show_songs')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('show_song_track', function(Blueprint $table) - { - $table->dropForeign('show_song_track_show_song_id_foreign'); - $table->dropForeign('show_song_track_track_id_foreign'); - }); - } +class AddForeignKeysToShowSongTrackTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('show_song_track', function (Blueprint $table) { + $table->foreign('show_song_id')->references('id')->on('show_songs')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('show_song_track', function (Blueprint $table) { + $table->dropForeign('show_song_track_show_song_id_foreign'); + $table->dropForeign('show_song_track_track_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_subscriptions_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_subscriptions_table.php index aeddd668..0c9916aa 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_subscriptions_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_subscriptions_table.php @@ -3,33 +3,29 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToSubscriptionsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('subscriptions', function(Blueprint $table) - { - $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('subscriptions', function(Blueprint $table) - { - $table->dropForeign('subscriptions_user_id_foreign'); - }); - } +class AddForeignKeysToSubscriptionsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('subscriptions', function (Blueprint $table) { + $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('subscriptions', function (Blueprint $table) { + $table->dropForeign('subscriptions_user_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_track_files_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_track_files_table.php index 84992aec..16184617 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_track_files_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_track_files_table.php @@ -3,33 +3,29 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToTrackFilesTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('track_files', function(Blueprint $table) - { - $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('track_files', function(Blueprint $table) - { - $table->dropForeign('track_files_track_id_foreign'); - }); - } +class AddForeignKeysToTrackFilesTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('track_files', function (Blueprint $table) { + $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('track_files', function (Blueprint $table) { + $table->dropForeign('track_files_track_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_tracks_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_tracks_table.php index 71119fda..b507695b 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_tracks_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_tracks_table.php @@ -3,43 +3,39 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToTracksTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('tracks', function(Blueprint $table) - { - $table->foreign('album_id')->references('id')->on('albums')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('cover_id')->references('id')->on('images')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('genre_id')->references('id')->on('genres')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('license_id')->references('id')->on('licenses')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('track_type_id')->references('id')->on('track_types')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('tracks', function(Blueprint $table) - { - $table->dropForeign('tracks_album_id_foreign'); - $table->dropForeign('tracks_cover_id_foreign'); - $table->dropForeign('tracks_genre_id_foreign'); - $table->dropForeign('tracks_license_id_foreign'); - $table->dropForeign('tracks_track_type_id_foreign'); - $table->dropForeign('tracks_user_id_foreign'); - }); - } +class AddForeignKeysToTracksTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('tracks', function (Blueprint $table) { + $table->foreign('album_id')->references('id')->on('albums')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('cover_id')->references('id')->on('images')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('genre_id')->references('id')->on('genres')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('license_id')->references('id')->on('licenses')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('track_type_id')->references('id')->on('track_types')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('user_id')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('tracks', function (Blueprint $table) { + $table->dropForeign('tracks_album_id_foreign'); + $table->dropForeign('tracks_cover_id_foreign'); + $table->dropForeign('tracks_genre_id_foreign'); + $table->dropForeign('tracks_license_id_foreign'); + $table->dropForeign('tracks_track_type_id_foreign'); + $table->dropForeign('tracks_user_id_foreign'); + }); + } } diff --git a/database/migrations/2016_06_26_225537_add_foreign_keys_to_users_table.php b/database/migrations/2016_06_26_225537_add_foreign_keys_to_users_table.php index a0ba5675..8f832856 100644 --- a/database/migrations/2016_06_26_225537_add_foreign_keys_to_users_table.php +++ b/database/migrations/2016_06_26_225537_add_foreign_keys_to_users_table.php @@ -3,33 +3,29 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class AddForeignKeysToUsersTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('users', function(Blueprint $table) - { - $table->foreign('avatar_id')->references('id')->on('images')->onUpdate('RESTRICT')->onDelete('RESTRICT'); - }); - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('users', function(Blueprint $table) - { - $table->dropForeign('users_avatar_id_foreign'); - }); - } +class AddForeignKeysToUsersTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('users', function (Blueprint $table) { + $table->foreign('avatar_id')->references('id')->on('images')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropForeign('users_avatar_id_foreign'); + }); + } } diff --git a/database/migrations/2016_07_10_000354_add_deleted_at_column_to_activities.php b/database/migrations/2016_07_10_000354_add_deleted_at_column_to_activities.php index 47f157c5..5a031a2b 100644 --- a/database/migrations/2016_07_10_000354_add_deleted_at_column_to_activities.php +++ b/database/migrations/2016_07_10_000354_add_deleted_at_column_to_activities.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class AddDeletedAtColumnToActivities extends Migration { @@ -30,7 +30,7 @@ class AddDeletedAtColumnToActivities extends Migration */ public function up() { - if (!Schema::hasColumn('activities', 'deleted_at')) { + if (! Schema::hasColumn('activities', 'deleted_at')) { Schema::table('activities', function (Blueprint $table) { $table->softDeletes()->index(); }); diff --git a/database/migrations/2016_07_14_154357_MysqlToPostgres.php b/database/migrations/2016_07_14_154357_MysqlToPostgres.php index 8fa0f251..c5ea3bdd 100644 --- a/database/migrations/2016_07_14_154357_MysqlToPostgres.php +++ b/database/migrations/2016_07_14_154357_MysqlToPostgres.php @@ -1,7 +1,7 @@ execCallback($line); } } } - private function execCallback($line) { - $this->console->writeln("[PGLOADER] " . $line); + private function execCallback($line) + { + $this->console->writeln('[PGLOADER] '.$line); } /** diff --git a/database/migrations/2016_08_07_185426_add_version_column_to_track_files_table.php b/database/migrations/2016_08_07_185426_add_version_column_to_track_files_table.php index f9e3e2c2..477b9a35 100644 --- a/database/migrations/2016_08_07_185426_add_version_column_to_track_files_table.php +++ b/database/migrations/2016_08_07_185426_add_version_column_to_track_files_table.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Kelvin Zhang + * Copyright (C) 2016 Kelvin Zhang. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; class AddVersionColumnToTrackFilesTable extends Migration { diff --git a/database/migrations/2016_08_15_103625_add_version_column_to_tracks_table.php b/database/migrations/2016_08_15_103625_add_version_column_to_tracks_table.php index 09292981..d48fc4b1 100644 --- a/database/migrations/2016_08_15_103625_add_version_column_to_tracks_table.php +++ b/database/migrations/2016_08_15_103625_add_version_column_to_tracks_table.php @@ -1,7 +1,7 @@ integer('user_id')->nullable(); $table->string('ip_address', 45)->nullable(); $table->text('user_agent')->nullable(); @@ -26,7 +26,7 @@ class UpdateSessionsTableForLaravel52 extends Migration */ public function down() { - Schema::table('sessions', function(Blueprint $table) { + Schema::table('sessions', function (Blueprint $table) { $table->dropColumn(['user_id', 'ip_address', 'user_agent']); }); } diff --git a/database/migrations/2016_09_30_202330_create_alexa_session.php b/database/migrations/2016_09_30_202330_create_alexa_session.php index 9db31910..c91c28de 100644 --- a/database/migrations/2016_09_30_202330_create_alexa_session.php +++ b/database/migrations/2016_09_30_202330_create_alexa_session.php @@ -1,8 +1,8 @@ string('id')->unique(); $table->text('payload'); $table->timestamps(); diff --git a/database/migrations/2016_11_10_220126_create_announcements_table.php b/database/migrations/2016_11_10_220126_create_announcements_table.php index 310b513b..e91ede3e 100644 --- a/database/migrations/2016_11_10_220126_create_announcements_table.php +++ b/database/migrations/2016_11_10_220126_create_announcements_table.php @@ -1,8 +1,8 @@ json('tracks')->nullable(); $table->string('css_class')->nullable(); $table->string('template_file')->nullable(); - $table->dateTime("start_time")->nullable(); - $table->dateTime("end_time")->nullable(); + $table->dateTime('start_time')->nullable(); + $table->dateTime('end_time')->nullable(); }); } diff --git a/database/migrations/2016_11_15_014829_create_email_notification_tables.php b/database/migrations/2016_11_15_014829_create_email_notification_tables.php index 263d8197..2612c54a 100644 --- a/database/migrations/2016_11_15_014829_create_email_notification_tables.php +++ b/database/migrations/2016_11_15_014829_create_email_notification_tables.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,9 +18,9 @@ * along with this program. If not, see . */ -use Illuminate\Support\Facades\Schema; -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; class CreateEmailNotificationTables extends Migration { @@ -31,7 +31,7 @@ class CreateEmailNotificationTables extends Migration */ public function up() { - DB::transaction(function(){ + DB::transaction(function () { // This table is used to enforce referential data integrity // for the polymorphic "activity" table. Schema::create('activity_types', function (Blueprint $table) { @@ -53,7 +53,6 @@ class CreateEmailNotificationTables extends Migration $table->foreign('activity_type')->references('activity_type')->on('activity_types'); }); - Schema::create('email_subscriptions', function (Blueprint $table) { $table->uuid('id')->primary(); $table->unsignedInteger('user_id'); @@ -92,7 +91,7 @@ class CreateEmailNotificationTables extends Migration */ public function down() { - DB::transaction(function() { + DB::transaction(function () { Schema::drop('email_clicks'); Schema::drop('emails'); Schema::drop('email_subscriptions'); diff --git a/database/migrations/2016_12_10_120107_create_failed_jobs_table_3.php b/database/migrations/2016_12_10_120107_create_failed_jobs_table_3.php index e0be195b..daeb1d1a 100644 --- a/database/migrations/2016_12_10_120107_create_failed_jobs_table_3.php +++ b/database/migrations/2016_12_10_120107_create_failed_jobs_table_3.php @@ -1,8 +1,8 @@ . */ -use Illuminate\Support\Facades\Schema; -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; class UpdateActivityDescriptions extends Migration { diff --git a/database/migrations/2016_12_30_193250_EnableEmailNotifications.php b/database/migrations/2016_12_30_193250_EnableEmailNotifications.php index 0ff298a0..51b35786 100644 --- a/database/migrations/2016_12_30_193250_EnableEmailNotifications.php +++ b/database/migrations/2016_12_30_193250_EnableEmailNotifications.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2016 Feld0 + * Copyright (C) 2016 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,30 +18,31 @@ * along with this program. If not, see . */ - -use Illuminate\Support\Facades\Schema; -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Migrations\Migration; use App\Models\User; +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; -class EnableEmailNotifications extends Migration { +class EnableEmailNotifications extends Migration +{ /** * Run the migrations. * * @return void */ - public function up() { + public function up() + { DB::table('email_subscriptions')->delete(); User::whereNull('disabled_at') ->where('is_archived', false) ->chunk(100, function ($users) { - /** @var User $user */ - foreach ($users as $user) { - $now = \Carbon\Carbon::now(); - $userId = $user->id; + /** @var User $user */ + foreach ($users as $user) { + $now = \Carbon\Carbon::now(); + $userId = $user->id; - DB::table('email_subscriptions') + DB::table('email_subscriptions') ->insert([ [ 'id' => \Webpatser\Uuid\Uuid::generate(4), @@ -84,11 +85,10 @@ class EnableEmailNotifications extends Migration { 'activity_type' => 7, 'created_at' => $now, 'updated_at' => $now, - ] + ], ]); - } - - }); + } + }); } /** @@ -96,7 +96,8 @@ class EnableEmailNotifications extends Migration { * * @return void */ - public function down() { + public function down() + { DB::table('email_subscriptions')->delete(); } } diff --git a/database/migrations/2017_02_08_233324_create_ponify_tracks.php b/database/migrations/2017_02_08_233324_create_ponify_tracks.php index 30424b05..c55f446e 100644 --- a/database/migrations/2017_02_08_233324_create_ponify_tracks.php +++ b/database/migrations/2017_02_08_233324_create_ponify_tracks.php @@ -1,8 +1,8 @@ increments('id'); $table->integer('track_id')->unsigned()->index(); $table->string('path')->index(); @@ -25,8 +24,7 @@ class CreatePonifyTracks extends Migration $table->text('raw_tags'); }); - Schema::table('ponify_tracks', function(Blueprint $table) - { + Schema::table('ponify_tracks', function (Blueprint $table) { $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); }); } @@ -38,8 +36,7 @@ class CreatePonifyTracks extends Migration */ public function down() { - Schema::table('ponify_tracks', function(Blueprint $table) - { + Schema::table('ponify_tracks', function (Blueprint $table) { $table->dropForeign('ponify_tracks_track_id_foreign'); }); diff --git a/database/migrations/2017_09_20_200156_AddRedirectToUsers.php b/database/migrations/2017_09_20_200156_AddRedirectToUsers.php index 09e4248e..68fe69c5 100644 --- a/database/migrations/2017_09_20_200156_AddRedirectToUsers.php +++ b/database/migrations/2017_09_20_200156_AddRedirectToUsers.php @@ -1,8 +1,8 @@ foreign('redirect_to')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + $table->foreign('redirect_to')->references('id')->on('users')->onUpdate('RESTRICT')->onDelete('RESTRICT'); }); } @@ -26,7 +26,7 @@ class AddForeignKeyToRedirect extends Migration public function down() { Schema::table('users', function (Blueprint $table) { - $table->dropForeign('users_redirect_to_foreign'); + $table->dropForeign('users_redirect_to_foreign'); }); } } diff --git a/database/migrations/2017_09_22_082723_CreateEQBeatsTracks.php b/database/migrations/2017_09_22_082723_CreateEQBeatsTracks.php index 81815184..eacc68d1 100644 --- a/database/migrations/2017_09_22_082723_CreateEQBeatsTracks.php +++ b/database/migrations/2017_09_22_082723_CreateEQBeatsTracks.php @@ -1,8 +1,8 @@ increments('id'); $table->integer('track_id')->unsigned()->index(); $table->string('path')->index(); @@ -25,8 +24,7 @@ class CreateEQBeatsTracks extends Migration $table->text('raw_tags'); }); - Schema::table('eqbeats_tracks', function(Blueprint $table) - { + Schema::table('eqbeats_tracks', function (Blueprint $table) { $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); }); } @@ -38,8 +36,7 @@ class CreateEQBeatsTracks extends Migration */ public function down() { - Schema::table('eqbeats_tracks', function(Blueprint $table) - { + Schema::table('eqbeats_tracks', function (Blueprint $table) { $table->dropForeign('eqbeats_tracks_track_id_foreign'); }); diff --git a/database/migrations/2017_12_03_091509_Laravel55Upgrade.php b/database/migrations/2017_12_03_091509_Laravel55Upgrade.php index e6d5977b..a53da742 100644 --- a/database/migrations/2017_12_03_091509_Laravel55Upgrade.php +++ b/database/migrations/2017_12_03_091509_Laravel55Upgrade.php @@ -1,8 +1,8 @@ . */ -use Illuminate\Database\Seeder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder { diff --git a/database/seeds/GenreTableSeeder.php b/database/seeds/GenreTableSeeder.php index 25b0e15e..2ce46904 100644 --- a/database/seeds/GenreTableSeeder.php +++ b/database/seeds/GenreTableSeeder.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,8 +20,8 @@ use Illuminate\Database\Seeder; -class GenreTableSeeder extends Seeder { - +class GenreTableSeeder extends Seeder +{ public function run() { // This table only needs to be filled once. @@ -30,155 +30,154 @@ class GenreTableSeeder extends Seeder { [ [ 'name' => 'Acoustic', - 'slug' => 'acoustic' + 'slug' => 'acoustic', ], [ 'name' => 'Adult Contemporary', - 'slug' => 'adult-contemporary' + 'slug' => 'adult-contemporary', ], [ 'name' => 'Ambient', - 'slug' => 'ambient' + 'slug' => 'ambient', ], [ 'name' => 'Chiptune', - 'slug' => 'chiptune' + 'slug' => 'chiptune', ], [ 'name' => 'Country', - 'slug' => 'country' + 'slug' => 'country', ], [ 'name' => 'Darkwave', - 'slug' => 'darkwave' + 'slug' => 'darkwave', ], [ 'name' => 'Disco / Funk', - 'slug' => 'disco-funk' + 'slug' => 'disco-funk', ], [ 'name' => 'Downtempo', - 'slug' => 'downtempo' + 'slug' => 'downtempo', ], [ 'name' => 'Drum & Bass', - 'slug' => 'drum-bass' + 'slug' => 'drum-bass', ], [ 'name' => 'Dubstep', - 'slug' => 'dubstep' + 'slug' => 'dubstep', ], [ 'name' => 'EDM', - 'slug' => 'edm' + 'slug' => 'edm', ], [ 'name' => 'Electro', - 'slug' => 'electro' + 'slug' => 'electro', ], [ 'name' => 'Eurobeat', - 'slug' => 'eurobeat' + 'slug' => 'eurobeat', ], [ 'name' => 'Experimental', - 'slug' => 'experimental' + 'slug' => 'experimental', ], [ 'name' => 'Hardcore', - 'slug' => 'hardcore' + 'slug' => 'hardcore', ], [ 'name' => 'Hardstyle', - 'slug' => 'hardstyle' + 'slug' => 'hardstyle', ], [ 'name' => 'Hip-Hop', - 'slug' => 'hip-hop' + 'slug' => 'hip-hop', ], [ 'name' => 'House', - 'slug' => 'house' + 'slug' => 'house', ], [ 'name' => 'IDM', - 'slug' => 'idm' + 'slug' => 'idm', ], [ 'name' => 'Jazz', - 'slug' => 'jazz' + 'slug' => 'jazz', ], [ 'name' => 'Mashup', - 'slug' => 'mashup' + 'slug' => 'mashup', ], [ 'name' => 'Metal', - 'slug' => 'metal' + 'slug' => 'metal', ], [ 'name' => 'Orchestral', - 'slug' => 'orchestral' + 'slug' => 'orchestral', ], [ 'name' => 'Other', - 'slug' => 'other' + 'slug' => 'other', ], [ 'name' => 'Pop', - 'slug' => 'pop' + 'slug' => 'pop', ], [ 'name' => 'Progressive', - 'slug' => 'progressive' + 'slug' => 'progressive', ], [ 'name' => 'Rock', - 'slug' => 'rock' + 'slug' => 'rock', ], [ 'name' => 'Ska / Punk', - 'slug' => 'ska-punk' + 'slug' => 'ska-punk', ], [ 'name' => 'Synthpop', - 'slug' => 'synthpop' + 'slug' => 'synthpop', ], [ 'name' => 'Trance', - 'slug' => 'trance' - ] + 'slug' => 'trance', + ], ]); - } + } } - } diff --git a/database/seeds/ShowSongTableSeeder.php b/database/seeds/ShowSongTableSeeder.php index 8d54fd24..0fd6476f 100644 --- a/database/seeds/ShowSongTableSeeder.php +++ b/database/seeds/ShowSongTableSeeder.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -26,8 +26,7 @@ class ShowSongTableSeeder extends Seeder [ 'title' => 'My Little Pony Theme Song', 'slug' => 'my-little-pony-theme-song', - 'lyrics' => - "[Backup singer] + 'lyrics' => "[Backup singer] My Little Pony, My Little Pony Ahh, ahh, ahh, ahhh... @@ -56,14 +55,13 @@ Sharing kindness It's an easy feat And magic makes it all complete You have my little ponies -Do you know you're all my very best friends?" +Do you know you're all my very best friends?", ], [ 'title' => 'Laughter Song (Giggle at the Ghostly)', 'slug' => 'laughter-song', - 'lyrics' => - "[Pinkie Pie] + 'lyrics' => "[Pinkie Pie] When I was a little filly and the sun was going down... Twilight Sparkle: Tell me she's not... @@ -101,14 +99,13 @@ Snortle at the spooky And tell that big dumb scary face to take a hike and leave you alone and if he thinks he can scare you then he's got another thing coming and the very idea of such a thing just makes you wanna... hahahaha... heh... -Laaaaaaauuugh!" +Laaaaaaauuugh!", ], [ 'title' => 'Winter Wrap-Up', 'slug' => 'winter-wrap-up', - 'lyrics' => - "[Rainbow Dash] + 'lyrics' => "[Rainbow Dash] Three months of winter coolness And awesome holidays @@ -242,13 +239,12 @@ Winter Wrap Up! Winter Wrap Up! [Twilight Sparkle] 'Cause tomorrow spring is here 'Cause tomorrow spring is here -'Cause tomorrow spring is here!" +'Cause tomorrow spring is here!", ], [ 'title' => 'EQG - Helping Twilight Win The Crown', 'slug' => 'helping-twilight-win-the-crown', - 'lyrics' => - "[Pinkie Pie, Rainbow Dash, Applejack, Fluttershy, Rarity] + 'lyrics' => "[Pinkie Pie, Rainbow Dash, Applejack, Fluttershy, Rarity] Hey! Hey! Everybody! We've got something to say. We may seem as different, @@ -340,8 +336,8 @@ Gonna come around. Jump up, make a sound. Hey! Stomp your hooves, turn around. Canterlot Wondercolts -Help her win the crown..." - ] +Help her win the crown...", + ], ]; /** @@ -357,9 +353,10 @@ Help her win the crown..." // sourced from http://mlp.wikia.com/wiki/Songs if (DB::table('show_songs')->count() === 0) { $now = \Carbon\Carbon::now(); - $showSongs = array_map(function(array $item) use ($now) { + $showSongs = array_map(function (array $item) use ($now) { $item['created_at'] = $now; $item['updated_at'] = $now; + return $item; }, $this->showSongs); DB::table('show_songs')->insert($showSongs); diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 433f900c..0e68ac60 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -13,7 +13,6 @@ return [ | */ - 'accepted' => 'The :attribute must be accepted.', 'active_url' => 'The :attribute is not a valid URL.', 'after' => 'The :attribute must be a date after :date.', @@ -98,14 +97,14 @@ return [ ], ], - "audio" => "The :attribute must be an audio file.", - "audio_channels" => "The :attribute contains an invalid number of channels.", - "audio_format" => "The :attribute does not contain audio in a valid format.", - "required_when" => "The :attribute field cannot be left blank.", - "sample_rate" => "The :attribute has an invalid sample rate.", - "min_width" => "The :attribute is not wide enough.", - "min_height" => "The :attribute is not tall enough.", - "textarea_length" => "The :attribute must be less than 250 characters long.", // @TODO: Figure out how to retrieve the parameter from the validation rule + 'audio' => 'The :attribute must be an audio file.', + 'audio_channels' => 'The :attribute contains an invalid number of channels.', + 'audio_format' => 'The :attribute does not contain audio in a valid format.', + 'required_when' => 'The :attribute field cannot be left blank.', + 'sample_rate' => 'The :attribute has an invalid sample rate.', + 'min_width' => 'The :attribute is not wide enough.', + 'min_height' => 'The :attribute is not tall enough.', + 'textarea_length' => 'The :attribute must be less than 250 characters long.', // @TODO: Figure out how to retrieve the parameter from the validation rule 'is_not_reserved_slug' => 'This :attribute is reserved. Please pick another one.', /* diff --git a/routes/web.php b/routes/web.php index 455db971..34b8003d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,7 +2,7 @@ /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015-2017 Feld0 + * Copyright (C) 2015-2017 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -78,28 +78,25 @@ Route::get('p{id}/dl.{extension}', 'PlaylistsController@getDownload'); Route::get('notifications', 'AccountController@getNotifications'); - -Route::group(['prefix' => 'notifications/email'], function() { +Route::group(['prefix' => 'notifications/email'], function () { Route::get('/unsubscribe/{subscriptionKey}', 'NotificationsController@getEmailUnsubscribe')->name('email:unsubscribe'); Route::get('/unsubscribed', 'NotificationsController@getEmailUnsubscribePage')->name('email:confirm-unsubscribed'); Route::get('/click/{emailKey}', 'NotificationsController@getEmailClick')->name('email:click'); }); - Route::get('oembed', 'TracksController@getOembed'); Route::group(['prefix' => 'api/v1', 'middleware' => 'json-exceptions'], function () { - Route::get( '/tracks/radio-details/{hash}', 'Api\V1\TracksController@getTrackRadioDetails'); + Route::get('/tracks/radio-details/{hash}', 'Api\V1\TracksController@getTrackRadioDetails'); Route::post('/tracks/radio-details/{hash}', 'Api\V1\TracksController@getTrackRadioDetails'); - Route::get( '/tracks/{id}', 'Api\V1\TracksController@getTrackDetails')->where('id', '\d+'); + Route::get('/tracks/{id}', 'Api\V1\TracksController@getTrackDetails')->where('id', '\d+'); Route::group(['middleware' => 'auth.oauth:ponyfm:tracks:upload'], function () { Route::post('tracks', 'Api\V1\TracksController@postUploadTrack'); - Route::get( '/tracks/{id}/upload-status', 'Api\V1\TracksController@getUploadStatus'); + Route::get('/tracks/{id}/upload-status', 'Api\V1\TracksController@getUploadStatus'); }); }); - Route::group(['prefix' => 'api/web', 'middleware' => 'cors'], function () { Route::post('/alexa', 'Api\Web\AlexaController@handle'); @@ -219,7 +216,6 @@ Route::group(['prefix' => 'api/web', 'middleware' => 'cors'], function () { Route::post('/auth/logout', 'Api\Web\AuthController@postLogout'); }); - Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'can:access-admin-area']], function () { Route::get('/genres', 'AdminController@getGenres'); Route::get('/tracks', 'AdminController@getTracks'); @@ -233,13 +229,11 @@ Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'can:access-admin-ar Route::get('u{id}', 'ArtistsController@getShortlink')->where('id', '\d+'); Route::get('users/{id}-{slug}', 'ArtistsController@getShortlink')->where('id', '\d+'); - Route::group(['prefix' => '{slug}'], function () { Route::get('/', 'ArtistsController@getProfile'); Route::get('/content', 'ArtistsController@getContent'); Route::get('/favourites', 'ArtistsController@getFavourites'); - Route::group(['prefix' => 'account', 'middleware' => 'auth'], function () { Route::get('/tracks', 'ContentController@getTracks'); Route::get('/tracks/edit/{id}', 'ContentController@getTracks'); @@ -258,5 +252,5 @@ Route::get('/', 'HomeController@getIndex'); Route::group(['domain' => 'api.pony.fm'], function () { Route::get('tracks/latest', ['uses' => 'Api\Mobile\TracksController@latest']); - Route::get('tracks/popular', [ 'uses' => 'Api\Mobile\TracksController@popular']); + Route::get('tracks/popular', ['uses' => 'Api\Mobile\TracksController@popular']); }); diff --git a/tests/ApiAuthTest.php b/tests/ApiAuthTest.php index 1d2430b8..e5f09530 100644 --- a/tests/ApiAuthTest.php +++ b/tests/ApiAuthTest.php @@ -4,7 +4,7 @@ namespace Tests; /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,9 +20,9 @@ namespace Tests; * along with this program. If not, see . */ +use App\Models\User; use Illuminate\Foundation\Testing\DatabaseMigrations; use Poniverse\Lib\AccessToken; -use App\Models\User; class ApiAuthTest extends TestCase { diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 28359057..698534f2 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -4,7 +4,7 @@ namespace Tests; /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015-2017 Feld0 + * Copyright (C) 2015-2017 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -20,13 +20,13 @@ namespace Tests; * along with this program. If not, see . */ -use Carbon\Carbon; -use Illuminate\Foundation\Testing\WithoutMiddleware; -use Illuminate\Foundation\Testing\DatabaseMigrations; use App\Models\Album; use App\Models\Genre; use App\Models\Track; use App\Models\User; +use Carbon\Carbon; +use Illuminate\Foundation\Testing\DatabaseMigrations; +use Illuminate\Foundation\Testing\WithoutMiddleware; class ApiTest extends TestCase { @@ -41,9 +41,9 @@ class ApiTest extends TestCase ->post('/api/v1/tracks', []) ->seeJsonEquals([ 'errors' => [ - 'track' => ['You must upload an audio file!'] + 'track' => ['You must upload an audio file!'], ], - 'message' => 'Validation failed' + 'message' => 'Validation failed', ]); $this->assertResponseStatus(400); } @@ -51,14 +51,14 @@ class ApiTest extends TestCase public function testUploadWithFileWithoutAutoPublish() { $this->callUploadWithParameters([ - 'auto_publish' => false + 'auto_publish' => false, ]); $this->seeJsonEquals([ 'message' => "This track has been accepted for processing! Poll the status_url to know when it's ready to publish. It will be published at the track_url.", - 'id' => "1", - 'status_url' => "http://ponyfm-testing.poni/api/v1/tracks/1/upload-status", - 'track_url' => "http://ponyfm-testing.poni/tracks/1-ponyfm-test-file", + 'id' => '1', + 'status_url' => 'http://ponyfm-testing.poni/api/v1/tracks/1/upload-status', + 'track_url' => 'http://ponyfm-testing.poni/tracks/1-ponyfm-test-file', ]); } @@ -67,10 +67,10 @@ class ApiTest extends TestCase $this->callUploadWithParameters([]); $this->seeJsonEquals([ - 'message' => "This track has been accepted for processing! Poll the status_url to know when it has been published. It will be published at the track_url.", - 'id' => "1", - 'status_url' => "http://ponyfm-testing.poni/api/v1/tracks/1/upload-status", - 'track_url' => "http://ponyfm-testing.poni/tracks/1-ponyfm-test-file", + 'message' => 'This track has been accepted for processing! Poll the status_url to know when it has been published. It will be published at the track_url.', + 'id' => '1', + 'status_url' => 'http://ponyfm-testing.poni/api/v1/tracks/1/upload-status', + 'track_url' => 'http://ponyfm-testing.poni/tracks/1-ponyfm-test-file', ]); $this->visit('/tracks/1-ponyfm-test'); @@ -98,29 +98,29 @@ class ApiTest extends TestCase 'is_explicit' => true, 'is_downloadable' => false, 'is_listed' => false, - 'metadata' => $track->metadata + 'metadata' => $track->metadata, ], [ - 'cover' => $this->getTestFileForUpload('ponyfm-transparent-cover-art.png') + 'cover' => $this->getTestFileForUpload('ponyfm-transparent-cover-art.png'), ]); $this->seeInDatabase('genres', [ - 'name' => $genre->name + 'name' => $genre->name, ]); $this->seeInDatabase('albums', [ - 'title' => $album->title + 'title' => $album->title, ]); $this->seeInDatabase('images', [ 'id' => 1, - 'uploaded_by' => $this->user->id + 'uploaded_by' => $this->user->id, ]); $this->seeInDatabase('tracks', [ 'title' => $track->title, 'user_id' => $this->user->id, 'track_type_id' => $track->track_type_id, - 'released_at' => "2015-01-01 01:01:01", + 'released_at' => '2015-01-01 01:01:01', 'description' => $track->description, 'lyrics' => $track->lyrics, 'is_vocal' => true, @@ -128,7 +128,7 @@ class ApiTest extends TestCase 'is_downloadable' => false, 'is_listed' => false, 'cover_id' => 1, - 'metadata' => $track->metadata + 'metadata' => $track->metadata, ]); } @@ -145,7 +145,6 @@ class ApiTest extends TestCase $track->published_at = Carbon::now(); $track->save(); - $response = $this ->withSession(['api_client_id' => 'ponyponyponyponypony']) ->get("/api/v1/tracks/{$track->id}"); @@ -158,9 +157,9 @@ class ApiTest extends TestCase 'streams' => [ 'mp3' => [ 'url' => $track->getStreamUrl('MP3', 'ponyponyponyponypony'), - 'mime_type' => Track::$Formats['MP3']['mime_type'] - ] - ] + 'mime_type' => Track::$Formats['MP3']['mime_type'], + ], + ], ]); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 9b355920..0a33c2e8 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,14 +2,14 @@ namespace Tests; -use Illuminate\Contracts\Console\Kernel; -use Storage; -use Laravel\BrowserKitTesting\TestCase as BaseTestCase; use App\Models\User; +use Illuminate\Contracts\Console\Kernel; +use Laravel\BrowserKitTesting\TestCase as BaseTestCase; +use Storage; /** * Pony.fm - A community for pony fan music. - * Copyright (C) 2015 Feld0 + * Copyright (C) 2015 Feld0. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -24,7 +24,6 @@ use App\Models\User; * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - class TestCase extends BaseTestCase { /** @@ -62,7 +61,7 @@ class TestCase extends BaseTestCase public function getTestFiles() { // Ensure we have the Pony.fm test files - if (!static::$initializedFiles) { + if (! static::$initializedFiles) { Storage::disk('local')->makeDirectory('test-files'); $storage = Storage::disk('testing'); @@ -71,11 +70,11 @@ class TestCase extends BaseTestCase // timestamp. $files = [ 'ponyfm-test.flac' => 1450965707, - 'ponyfm-transparent-cover-art.png' => 1451211579 + 'ponyfm-transparent-cover-art.png' => 1451211579, ]; foreach ($files as $filename => $lastModifiedTimestamp) { - if (!$storage->has($filename) || + if (! $storage->has($filename) || $storage->lastModified($filename) < $lastModifiedTimestamp ) { echo "Downloading test file: ${filename}...".PHP_EOL; @@ -96,7 +95,7 @@ class TestCase extends BaseTestCase // Delete any unnecessary test files foreach ($storage->allFiles() as $filename) { - if (!isset($files[$filename])) { + if (! isset($files[$filename])) { $storage->delete($filename); } } @@ -113,7 +112,7 @@ class TestCase extends BaseTestCase /** * Returns an object for testing file uploads using the given test file. - * In a test, to "attach" a file to the `track` field, call the following: + * In a test, to "attach" a file to the `track` field, call the following:. * * $this->call('POST', '/api/v1/tracks', [], [], ['track' => $file]); * // then, deal with the response @@ -141,7 +140,7 @@ class TestCase extends BaseTestCase { $this->expectsJobs([ \App\Jobs\EncodeTrackFile::class, - \App\Jobs\UpdateSearchIndexForEntity::class + \App\Jobs\UpdateSearchIndexForEntity::class, ]); $this->user = factory(User::class)->create();