1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-03 09:49:30 +02:00

it technically logs in and streams.. but thats it, complete rewrite almost everything broken

This commit is contained in:
Karl 'vollmerk' Vollmer 2007-04-23 07:31:05 +00:00
parent 8b27d66add
commit a31560aec4
199 changed files with 30445 additions and 33070 deletions

View file

@ -20,7 +20,7 @@
*/ */
require ('../lib/init.php'); require '../lib/init.php';
$action = scrub_in($_REQUEST['action']); $action = scrub_in($_REQUEST['action']);
@ -29,12 +29,12 @@ if (!$GLOBALS['user']->has_access(100)) {
exit(); exit();
} }
require_once Config::get('prefix') . '/templates/header.inc.php';
show_template('header'); ?> ?>
<div id="admin-tools"> <div id="admin-tools">
<?php require (conf('prefix') . '/templates/show_admin_tools.inc.php'); ?> <?php require Config::get('prefix') . '/templates/show_admin_tools.inc.php'; ?>
</div> </div>
<div id="admin-info"> <div id="admin-info">
<?php require (conf('prefix') . '/templates/show_admin_info.inc.php'); ?> <?php require Config::get('prefix') . '/templates/show_admin_info.inc.php'; ?>
</div> </div>
<?php show_footer(); ?> <?php show_footer(); ?>

View file

@ -1,539 +1,499 @@
##<?php exit(); ?>## ;#<?php exit(); ?>##
#################### ;###################
# General Config # ; General Config #
#################### ;###################
# This value is used to detect quickly ; This value is used to detect quickly
# if this config file is up to date ; if this config file is up to date
# this is compared against a value hardcoded ; this is compared against a value hardcoded
# into the init script ; into the init script
config_version = 2 config_version = 2
#################### ;###################
# Path Vars # ; Path Vars #
#################### ;###################
# The path to your ampache install ; The path to your ampache install
# Do not put a trailing / on this path ; Do not put a trailing / on this path
# For example if your site is located at http://localhost ; For example if your site is located at http://localhost
# than you do not need to enter anything for the web_path ; than you do not need to enter anything for the web_path
# if it is located at http://localhost/music you need to ; if it is located at http://localhost/music you need to
# set web_path to /music ; set web_path to /music
# DEFAULT: "" ; DEFAULT: ""
#web_path = "" ;web_path = ""
############################### ;##############################
# Session and Login Variables # ; Session and Login Variables #
############################### ;##############################
# Hostname of your Database ; Hostname of your Database
# DEFAULT: localhost ; DEFAULT: localhost
local_host = localhost database_hostname = localhost
# Name of your ampache database ; Name of your ampache database
# DEFAULT: ampache ; DEFAULT: ampache
local_db = ampache database_name = ampache
# Username for your ampache database ; Username for your ampache database
# DEFAULT: "" ; DEFAULT: ""
local_username = username database_username = username
# Password for your ampache database, this can not be blank ; Password for your ampache database, this can not be blank
# this is a 'forced' security precaution, the default value ; this is a 'forced' security precaution, the default value
# will not work ; will not work
# DEFAULT: "" ; DEFAULT: ""
local_pass = password database_password = password
# Length that a session will last, the default is very restrictive ; Length that a session will last, the default is very restrictive
# at 15min ; at 15min
# DEFAULT: 900 ; DEFAULT: 900
local_length = 900 session_length = 900
# This length defines how long a 'remember me' session and cookie will ; This length defines how long a 'remember me' session and cookie will
# last, the default is 900, same as length. It is up to the administrator ; last, the default is 900, same as length. It is up to the administrator
# of the box to increase this, for reference 86400 = 1 day ; of the box to increase this, for reference 86400 = 1 day
# 604800 = 1 week and 2419200 = 1 month ; 604800 = 1 week and 2419200 = 1 month
# DEAFULT: 900 ; DEAFULT: 900
remember_length = 900 remember_length = 900
# Name of the Session/Cookie that will sent to the browser ; Name of the Session/Cookie that will sent to the browser
# default should be fine ; default should be fine
# DEFAULT: ampache ; DEFAULT: ampache
sess_name = ampache session_name = ampache
# Lifetime of the Cookie, 0 == Forever (until browser close) , otherwise in terms of seconds ; Lifetime of the Cookie, 0 == Forever (until browser close) , otherwise in terms of seconds
# DEFAULT: 0 ; DEFAULT: 0
sess_cookielife = 0 session_cookielife = 0
# Is the cookie a "secure" cookie? ; Is the cookie a "secure" cookie?
# DEFAULT: 0 ; DEFAULT: 0
sess_cookiesecure = 0 session_cookiesecure = 0
# Auth Methods ; Auth Methods
# This defines which auth methods vauth will attempt ; This defines which auth methods vauth will attempt
# to use and in which order, if auto_create isn't enabled ; to use and in which order, if auto_create isn't enabled
# The user must exist locally as well ; The user must exist locally as well
# DEFAULT: mysql ; DEFAULT: mysql
# VALUES: mysql,ldap,http ; VALUES: mysql,ldap,http
#auth_methods = "ldap"
auth_methods = "mysql" auth_methods = "mysql"
###################### ;#####################
# Program Settings # ; Program Settings #
###################### ;#####################
# File Pattern ; File Pattern
# This defines which file types Ampache will attempt to catalog ; This defines which file types Ampache will attempt to catalog
# You can specify any file extension you want in here seperating them ; You can specify any file extension you want in here seperating them
# with a | ; with a |
# DEFAULT: mp3|mpc|m4p|m4a|mp4|aac|ogg|rm|wma|asf|flac|spx|ra|ape|shn|wv ; DEFAULT: mp3|mpc|m4p|m4a|mp4|aac|ogg|rm|wma|asf|flac|spx|ra|ape|shn|wv
catalog_file_pattern = "mp3|mpc|m4p|m4a|mp4|aac|ogg|rm|wma|asf|flac|spx|ra|ape|shn|wv" catalog_file_pattern = "mp3|mpc|m4p|m4a|mp4|aac|ogg|rm|wma|asf|flac|spx|ra|ape|shn|wv"
# Use Access List ; Use Access List
# Toggle this on if you want ampache to pay attention to the access list ; Toggle this on if you want ampache to pay attention to the access list
# and only allow streaming/downloading/xml-rpc from known hosts by default ; and only allow streaming/downloading/xml-rpc from known hosts by default
# xml-rpc will not working without this on. ; xml-rpc will not working without this on.
# DEFAULT: false ; DEFAULT: false
#access_control = "false" ;access_control = "false"
# Require Session ; Require Session
# If this is set to true ampache will make sure that the URL passed when ; If this is set to true ampache will make sure that the URL passed when
# attempting to retrieve a song contains a valid Session ID This prevents ; attempting to retrieve a song contains a valid Session ID This prevents
# others from guessing URL's ; others from guessing URL's
# DEFAULT: true ; DEFAULT: true
require_session = "true" require_session = "true"
# Downsample Remote ; Downsample Remote
# If this is set to true and access control is on any users who are not ; If this is set to true and access control is on any users who are not
# coming from a defined localnet will be automatically downsampled ; coming from a defined localnet will be automatically downsampled
# regardless of their preferences ; regardless of their preferences
# DEFAULT: false ; DEFAULT: false
#downsample_remote = "false" ;downsample_remote = "false"
# Track User IPs ; Track User IPs
# If this is enabled Ampache will log the IP of every completed login ; If this is enabled Ampache will log the IP of every completed login
# it will store user,ip,time at one row per login. The results are ; it will store user,ip,time at one row per login. The results are
# displayed in Admin --> Users ; displayed in Admin --> Users
# DEFAULT: false ; DEFAULT: false
#track_user_ip = "false" ;track_user_ip = "false"
# User IP Cardinality ; User IP Cardinality
# This defines how many days worth of IP history Ampache will track ; This defines how many days worth of IP history Ampache will track
# As it is one row per login on high volume sites you will want to ; As it is one row per login on high volume sites you will want to
# clear it every now and then. ; clear it every now and then.
# DEFAULT: 42 days ; DEFAULT: 42 days
#user_ip_cardinality = "42" ;user_ip_cardinality = "42"
# Use XML-RPC ; Use XML-RPC
# Allow XML-RPC connections, if you don't want _any_ possibility of your ; Allow XML-RPC connections, if you don't want _any_ possibility of your
# catalog being streamed from another location comment this out ; catalog being streamed from another location comment this out
# DEFAULT: false ; DEFAULT: false
#xml_rpc = "false" ;xml_rpc = "false"
# This setting allows/disallows using zlib to zip up an entire ; This setting allows/disallows using zlib to zip up an entire
# playlist/album for download. Even if this is turned on you will ; playlist/album for download. Even if this is turned on you will
# still need to enabled downloading for the specific user you ; still need to enabled downloading for the specific user you
# want to be able to use this function ; want to be able to use this function
# DEFAULT: false ; DEFAULT: false
#allow_zip_download = "false" ;allow_zip_download = "false"
# This setting throttles a persons downloading to the specified ; This setting throttles a persons downloading to the specified
# bytes per second. This is not a 100% guaranteed function, and ; bytes per second. This is not a 100% guaranteed function, and
# you should really use a server based rate limiter if you want ; you should really use a server based rate limiter if you want
# to do this correctly. ; to do this correctly.
# DEFAULT: off ; DEFAULT: off
# VALUES: any whole number (in bytes per second) ; VALUES: any whole number (in bytes per second)
#throttle_download = 10 ;throttle_download = 10
# This determines the tag order for all cataloged ; This determines the tag order for all cataloged
# music. If none of the listed tags are found then ; music. If none of the listed tags are found then
# ampache will default to the first tag format ; ampache will default to the first tag format
# that was found. ; that was found.
# POSSIBLE VALUES: id3v1 id3v2 file vorbiscomment ; POSSIBLE VALUES: id3v1 id3v2 file vorbiscomment
# quicktime ape asf ; quicktime ape asf
# DEFAULT: id3v2,id3v1 vorbiscomment quicktime ape ; DEFAULT: id3v2,id3v1 vorbiscomment quicktime ape
# asf ; asf
tag_order = id3v2 tag_order = "id3v2,id3v1,vorbiscomment,quicktime,ape,asf"
tag_order = id3v1
tag_order = vorbiscomment
tag_order = quicktime
tag_order = ape
tag_order = asf
#tag_order = file
# Un comment if don't want ampache to follow symlinks ; Un comment if don't want ampache to follow symlinks
# DEFAULT: false ; DEFAULT: false
#no_symlinks = "false" ;no_symlinks = "false"
# Use auth? ; Use auth?
# If this is set to "Yes" ampache will require a valid ; If this is set to "Yes" ampache will require a valid
# Username and password. If this is set to false then ampache ; Username and password. If this is set to false then ampache
# will not ask you for a username and password. false is only ; will not ask you for a username and password. false is only
# recommended for internal only instances ; recommended for internal only instances
# DEFAULT true ; DEFAULT true
use_auth = "yes" use_auth = "yes"
# 5 Star Ratings ; 5 Star Ratings
# This allows ratings for almost any object in ampache ; This allows ratings for almost any object in ampache
# POSSIBLE VALUES: false true ; POSSIBLE VALUES: false true
# DEFAULT: true ; DEFAULT: true
ratings = "true" ratings = "true"
# This options will turn on/off Demo Mode ; This options will turn on/off Demo Mode
# If Demo mode is on you can not play songs or update your catalog ; If Demo mode is on you can not play songs or update your catalog
# in other words.. leave this commented out ; in other words.. leave this commented out
# DEFAULT: false ; DEFAULT: false
#demo_mode = "false" ;demo_mode = "false"
# Memory Limit ; Memory Limit
# This defines the "Min" memory limit for PHP if your php.ini ; This defines the "Min" memory limit for PHP if your php.ini
# has a lower value set Ampache will set it up to this. If you ; has a lower value set Ampache will set it up to this. If you
# set it below 16MB getid3() will not work! ; set it below 16MB getid3() will not work!
# DEFAULT: 24 ; DEFAULT: 24
#memory_limit = 24 ;memory_limit = 24
# Album Art Preferred Filename ; Album Art Preferred Filename
# Specify a filename to look for if you always give the same filename ; Specify a filename to look for if you always give the same filename
# i.e. "folder.jpg" Ampache currently only supports jpg/gif and png ; i.e. "folder.jpg" Ampache currently only supports jpg/gif and png
# Especially useful if you have a front and a back image in a folder ; Especially useful if you have a front and a back image in a folder
# comment out if ampache should search for any jpg,gif or png ; comment out if ampache should search for any jpg,gif or png
# DEFAULT: folder.jpg ; DEFAULT: folder.jpg
#album_art_preferred_filename = "folder.jpg" ;album_art_preferred_filename = "folder.jpg"
# Resize Images * Requires PHP-GD * ; Resize Images * Requires PHP-GD *
# Set this to true if you want Ampache to resize the Album ; Set this to true if you want Ampache to resize the Album
# art on the fly, this increases load time and CPU usage ; art on the fly, this increases load time and CPU usage
# and also requires the PHP-GD library. This is very useful ; and also requires the PHP-GD library. This is very useful
# If you have high-quality album art and a small upload cap ; If you have high-quality album art and a small upload cap
# DEFAULT: false ; DEFAULT: false
#resize_images = "false" ;resize_images = "false"
# Album Art Gather Order ; Album Art Gather Order
# Simply arrange the following in the order you would like ; Simply arrange the following in the order you would like
# ampache to search if you want to disable one of the search ; ampache to search if you want to disable one of the search
# method simply comment it out valid values are ; method simply comment it out valid values are
# POSSIBLE VALUES: db id3 folder amazon ; POSSIBLE VALUES: db id3 folder amazon
# DEFAULT: db,id3,folder,amazon ; DEFAULT: db,id3,folder,amazon
album_art_order = "db" album_art_order = "db,id3,folder,amazon"
album_art_order = "id3"
album_art_order = "folder"
album_art_order = "amazon"
# Album Art ; Album Art
# Set this to true if you want album art displayed on pages besides the ; Set this to true if you want album art displayed on pages besides the
# Single Album view, if you have a slow machine, or limited bandwidth ; Single Album view, if you have a slow machine, or limited bandwidth
# turning this off can vastly improve performance ; turning this off can vastly improve performance
# DEFAULT: true ; DEFAULT: true
show_album_art = "true" show_album_art = "true"
# Amazon Developer Key ; Amazon Developer Key
# This is needed in order to actually use the amazon album art ; This is needed in order to actually use the amazon album art
# DEFAULT: false ; DEFAULT: false
#amazon_developer_key = "" ;amazon_developer_key = ""
# Amazon base urls ; Amazon base urls
# An array of Amazon sites to search. ; An array of Amazon sites to search.
# NOTE: This will search each of these sites in turn so don't expect it ; NOTE: This will search each of these sites in turn so don't expect it
# to be lightening fast! ; to be lightening fast!
# It is strongly recommended that only one of these is selected at any ; It is strongly recommended that only one of these is selected at any
# one time ; one time
# Default: Just the US (.com) ; POSSIBLE VALUES:
; http://webservices.amazon.com
; http://webservices.amazon.co.uk
; http://webservices.amazon.de
; http://webservices.amazon.co.jp
; http://webservices.amazon.fr
; http://webservices.amazon.ca
; Default: http://webservices.amazon.com
amazon_base_urls = "http://webservices.amazon.com" amazon_base_urls = "http://webservices.amazon.com"
#amazon_base_urls = "http://webservices.amazon.co.uk"
#amazon_base_urls = "http://webservices.amazon.de"
#amazon_base_urls = "http://webservices.amazon.co.jp"
#amazon_base_urls = "http://webservices.amazon.fr"
#amazon_base_urls = "http://webservices.amazon.ca"
# max_amazon_results_pages ; max_amazon_results_pages
# The maximum number of results pages to pull from EACH amazon site ; The maximum number of results pages to pull from EACH amazon site
# NOTE: The art search pages through the results returned by your search ; NOTE: The art search pages through the results returned by your search
# up to this number of pages. As with the base_urls above, this is going ; up to this number of pages. As with the base_urls above, this is going
# to take more time, the more pages you ask it to process. ; to take more time, the more pages you ask it to process.
# Of course a good search will return only a few matches anyway. ; Of course a good search will return only a few matches anyway.
# It is strongly recommended that you do _not_ change this value ; It is strongly recommended that you do _not_ change this value
# DEFAULT: 1 page (10 items) ; DEFAULT: 1 page (10 items)
max_amazon_results_pages = 1 max_amazon_results_pages = 1
# Debug ; Debug
# If this is enabled Ampache will get really chatty ; If this is enabled Ampache will get really chatty
# warning this can crash browser during catalog builds due to ; warning this can crash browser during catalog builds due to
# the amount of text that is dumped out this will also cause ; the amount of text that is dumped out this will also cause
# ampache to write to the log file ; ampache to write to the log file
# DEFAULT: false ; DEFAULT: false
#debug = "false" ;debug = "false"
# Debug Level ; Debug Level
# This should always be set in conjunction with the ; This should always be set in conjunction with the
# debug option, it defines how prolific you want the ; debug option, it defines how prolific you want the
# debugging in ampache to be. values are 1-5. ; debugging in ampache to be. values are 1-5.
# 1 == Errors only ; 1 == Errors only
# 2 == Error + Failures (login attempts etc.) ; 2 == Error + Failures (login attempts etc.)
# 3 == ?? ; 3 == ??
# 4 == ?? (Profit!) ; 4 == ?? (Profit!)
# 5 == Information (cataloging progress etc.) ; 5 == Information (cataloging progress etc.)
# DEFAULT: 5 ; DEFAULT: 5
debug_level = 5 debug_level = 5
# Path to Log File ; Path to Log File
# This defines where you want ampache to log events to ; This defines where you want ampache to log events to
# this will only happen if debug is turned on. Do not ; this will only happen if debug is turned on. Do not
# include trailing slash. You will need to make sure that ; include trailing slash. You will need to make sure that
# your HTTP server has write access to the specified directory ; your HTTP server has write access to the specified directory
# DEFAULT: NULL ; DEFAULT: NULL
#log_path = "/var/log/ampache" ;log_path = "/var/log/ampache"
# Charset of generated HTML pages ; Charset of generated HTML pages
# Default of UTF-8 should work for most people ; Default of UTF-8 should work for most people
# DEFAULT: UTF-8 ; DEFAULT: UTF-8
site_charset = UTF-8 site_charset = UTF-8
# Locale Charset ; Locale Charset
# In some cases this has to be different ; In some cases this has to be different
# in order for XHTML and other things to work ; in order for XHTML and other things to work
# This is disabled by default, enabled only ; This is disabled by default, enabled only
# if needed. It's specifically needed for Russian ; if needed. It's specifically needed for Russian
# so that is the default ; so that is the default
# DEFAULT: cp1251 ; DEFAULT: cp1251
#lc_charset = cp1251 ;lc_charset = cp1251
# Refresh Limit ; Refresh Limit
# This defines the default refresh limit in seconds for ; This defines the default refresh limit in seconds for
# pages with dynamic content, such as now playing ; pages with dynamic content, such as now playing
# DEFAULT: 60 ; DEFAULT: 60
# Possible Values: Int > 5 ; Possible Values: Int > 5
refresh_limit = "60" refresh_limit = "60"
########################################################## ;#########################################################
# LDAP login info (optional) # ; LDAP login info (optional) #
########################################################## ;#########################################################
# This setting will silently create an ampache account ; This setting will silently create an ampache account
# for anyone who can login using ldap (or any other login ; for anyone who can login using ldap (or any other login
# extension) ; extension)
# DEFAULT: false ; DEFAULT: false
#auto_create = "false" ;auto_create = "false"
# LDAP filter string to use ; LDAP filter string to use
# For OpenLDAP use "uid" ; For OpenLDAP use "uid"
# For Microsoft Active Directory (MAD) use "sAMAccountName" ; For Microsoft Active Directory (MAD) use "sAMAccountName"
# DEFAULT: null ; DEFAULT: null
# ldap_filter = "uid" ; ldap_filter = "sAMAccountName"
# ldap_filter = "sAMAccountName"
# LDAP objectclass it's required so if you don't know use * ; LDAP objectclass it's required so if you don't know use *
# OpanLDAP objectclass = "*" ; OpanLDAP objectclass = "*"
# MAD objectclass = "organizationalPerson" ; MAD objectclass = "organizationalPerson"
# DEFAULT null ; DEFAULT null
#ldap_objectclass = "*" ;ldap_objectclass = "organizationalPerson"
#ldap_objectclass = "organizationalPerson"
# if this is the case, fill these in here: ; if this is the case, fill these in here:
# DEFAULT: null ; DEFAULT: null
#ldap_username = "" ;ldap_username = ""
#ldap_password = "" ;ldap_password = ""
# NOT YET IMPLEMENTED!! ; NOT YET IMPLEMENTED!!
# This option checks to see if the specified user is in ; This option checks to see if the specified user is in
# a specific ldap group, allowing you to give access based ; a specific ldap group, allowing you to give access based
# on group membership ; on group membership
# DEFAULT: null ; DEFAULT: null
#ldap_require_group = "cn=yourgroup,ou=yourorg,dc=yoursubdomain,dc=yourdomain,dc=yourtld" ;ldap_require_group = "cn=yourgroup,ou=yourorg,dc=yoursubdomain,dc=yourdomain,dc=yourtld"
# This is the search dn used to find your user, uid=username is added on to ; This is the search dn used to find your user, uid=username is added on to
# This string ; This string
# DEFAULT: null ; DEFAULT: null
#ldap_search_dn = "ou=People,dc=yoursubdomain,dc=yourdomain,dc=yourtld" ;ldap_search_dn = "ou=People,dc=yoursubdomain,dc=yourdomain,dc=yourtld"
# This is the address of your ldap server ; This is the address of your ldap server
# DEFAULT: null ; DEFAULT: null
#ldap_url = "" ;ldap_url = ""
# Specify where in your ldap db the following fields are stored: ; Specify where in your ldap db the following fields are stored:
# (comment out if you don't have them) ; (comment out if you don't have them)
# OpenLDAP: ldap_name_field = "cn" ; OpenLDAP: ldap_name_field = "cn"
# MAD ldap_name_field = "displayname" ; MAD ldap_name_field = "displayname"
# DEFAULT: [none] ; DEFAULT: [none]
#ldap_email_field = "mail" ;ldap_email_field = "mail"
#ldap_name_field = "cn" ;ldap_name_field = "cn"
########################################################## ;#########################################################
# Public Registration settings, defaults to disabled # ; Public Registration settings, defaults to disabled #
########################################################## ;#########################################################
# This setting turns on/off public registration. It is ; This setting turns on/off public registration. It is
# recommended you leave this off, as it will allow anyone to ; recommended you leave this off, as it will allow anyone to
# sign up for an account on your server. ; sign up for an account on your server.
# REMEMBER: don't forget to set the mail from address further down in the config. ; REMEMBER: don't forget to set the mail from address further down in the config.
# DEFAULT: false ; DEFAULT: false
#allow_public_registration = "false" ;allow_public_registration = "false"
# Require Captcha Text on Image confirmation ; Require Captcha Text on Image confirmation
# Turning this on requires the user to correctly ; Turning this on requires the user to correctly
# type in the letters in the image created by Captcha ; type in the letters in the image created by Captcha
# Default is off because its very hard to detect if it failed ; Default is off because its very hard to detect if it failed
# to draw, or they failed to enter it. ; to draw, or they failed to enter it.
# DEFAULT: false ; DEFAULT: false
#captcha_public_reg = "false" ;captcha_public_reg = "false"
# This setting defines the mail domain your in. ; This setting defines the mail domain your in.
# It tries to deliver a test mail before the user can register and uses ; It tries to deliver a test mail before the user can register and uses
# the from address info@"domain.tld". No mail is send from this address it's ; the from address info@"domain.tld". No mail is send from this address it's
# only used to test the existence of a mailbox before accepting user registration. ; only used to test the existence of a mailbox before accepting user registration.
# DEFAULT: domain.tld ; DEFAULT: domain.tld
#mail_domain = "domain.tld" ;mail_domain = "domain.tld"
# This setting will be used as mail from address. ; This setting will be used as mail from address.
# It will also be used to notify if a registration occurred. ; It will also be used to notify if a registration occurred.
# You need to change this when you activate public_registration. ; You need to change this when you activate public_registration.
#mail_from = "info@domain.tld" ;mail_from = "info@domain.tld"
# This setting turns on/off admin notify off registration. ; This setting turns on/off admin notify off registration.
# DEFAULT: false ; DEFAULT: false
#admin_notify_reg = "false" ;admin_notify_reg = "false"
# This setting will allow all registrants to be auto-approved ; This setting will allow all registrants to be auto-approved
# as a user. By default, they will be added as a guest and ; as a user. By default, they will be added as a guest and
# must be "promoted" by the admin. ; must be "promoted" by the admin.
# POSSIBLE VALUES: guest, user, admin ; POSSIBLE VALUES: guest, user, admin
# DEFAULT: guest ; DEFAULT: guest
#auto_user = "guest" ;auto_user = "guest"
# This will display the user agreement when registering ; This will display the user agreement when registering
# For agreement text, edit templates/user_agreement.php ; For agreement text, edit templates/user_agreement.php
# User will need to accept the agreement before they can register ; User will need to accept the agreement before they can register
# DEFAULT: false ; DEFAULT: false
#user_agreement = "false" ;user_agreement = "false"
######################################################### ;########################################################
# These options control the dynamic down-sampling based # ; These options control the dynamic down-sampling based #
# on current usage # ; on current usage #
# *Note* Down-sampling must be enabled and working # ; *Note* Down-sampling must be enabled and working #
######################################################### ;########################################################
# Attempt to optimize bandwidth by dynamically down-sampling ; Attempt to optimize bandwidth by dynamically down-sampling
# all connections from users to fit within a maximum bandwidth. ; all connections from users to fit within a maximum bandwidth.
# The benefit is that it won't downsample more than it needs to. As it only ; The benefit is that it won't downsample more than it needs to. As it only
# adjusts the sample rate at the beginning of a song, it may take a few ; adjusts the sample rate at the beginning of a song, it may take a few
# minutes to reset all connections to a lower rate. This won't never go higher ; minutes to reset all connections to a lower rate. This won't never go higher
# than a user's sample rate and only applies to users who are set to ; than a user's sample rate and only applies to users who are set to
# the Downsample playback method ; the Downsample playback method
# DEFAULT: 576 ; DEFAULT: 576
#max_bit_rate = 576 ;max_bit_rate = 576
# If min_bit_rate is set then new streams will be denied if it would ; If min_bit_rate is set then new streams will be denied if it would
# cause all streams to be down-sampled below this rate. ; cause all streams to be down-sampled below this rate.
# DEFAULT: 48 ; DEFAULT: 48
#min_bit_rate = 48 ;min_bit_rate = 48
####################################################### ;######################################################
# These options control how searching works # ; These options control how searching works #
####################################################### ;######################################################
# choices are: artist,album,song_title,song_genre,song_year,song_bitrate,song_min_bitrate,song_filename ; choices are: artist,album,song_title,song_genre,song_year,song_bitrate,song_min_bitrate,song_filename
# DEFAULT: song_title ; DEFAULT: song_title
search_field = song_title search_field = song_title
# choices are: exact,fuzzy ; choices are: exact,fuzzy
# DEFAULT: fuzzy ; DEFAULT: fuzzy
search_type = fuzzy search_type = fuzzy
####################################################### ;######################################################
# This option controls what Ampache sends for the Stream name. This ; These are commands used to transcode non-streaming
# is most valuable when then 'Type of Playback' is set to downsample. ; formats to the target file type for streaming. Any
# because lame seems to strip id3 tags. if you want the Ampache default ; file types defined here will automatically be transcoded
# just leave this option commented out. ; using the stream_cmd_??? regardless of personal preferences
# ; This can be useful in re-encoding file types that don't stream
# the format supports the following options: ; very well, or if the player doesn't support some file types.
# ; This is also the string used when 'downsampling' is selected
# %A = album name ;
# %a = artist name ; REQUIRED variables
# %C = catalog path ; transcode_TYPE = true/false ## True if you want to force transcode
# %c = id3 comment ; transcode_TYPE_target = TARGET_FILE_TYPE
# %g = genre ; transcode_cmd_TYPE = TRANSCODE_COMMAND
# %T = track number ; %FILE% = filename
# %t = song title ; %OFFSET% = offset
# %y = year ; %SAMPLE% = sample rate
# %basename = current filename (just the actual filename) ; %EOF% = end of file in min.sec
# %catalog = catalog name
# %filename = current filename (full path)
# %type = song type (mp3, ogg, ...)
#
# DEFAULT: %a - %A - %t
#stream_name_format = %a - %A - %t
####################################################### ; List of filetypes to transcode
# These options control the down-sampling feature
# this requires you to install some applications such
# as lame that can re-encode the mp3 for you.
# we recommend mp3splt and lame
# %FILE% = filename
# %OFFSET% = offset
# %SAMPLE% = sample rate
# %EOF% = end of file in min.sec
# DEFAULT: mp3splt -qnf %FILE% %OFFSET% %EOF% -o - | lame --mp3input -q 3 -b %SAMPLE% -S - -
downsample_cmd = mp3splt -qnf %FILE% %OFFSET% %EOF% -o - | lame --mp3input -q 3 -b %SAMPLE% -S - -
#######################################################
# These are commands used to transcode non-streaming
# formats to the target file type for streaming. Any
# file types defined here will automatically be transcoded
# using the stream_cmd_??? regardless of personal preferences
# This can be useful in re-encoding file types that don't stream
# very well, or if the player doesn't support some file types.
# REQUIRED variables
# transcode_TYPE = true
# transcode_TYPE_target = TARGET_FILE_TYPE
# stream_cmd_TYPE = TRANSCODE_COMMAND
# List of filetypes to transcode
transcode_m4a = true transcode_m4a = true
transcode_m4a_target = mp3 transcode_m4a_target = mp3
transcode_flac = true ;transcode_flac = true
transcode_flac_target = mp3 transcode_flac_target = mp3
#transcode_mpc = false ;transcode_mp3 = false
#transcode_mpc_target = mp3 transcode_mp3_target = mp3
# These are the commands that will be run to transcode the file ; These are the commands that will be run to transcode the file
stream_cmd_flac = flac -dc %FILE% | lame -r -b 128 -S - - trascode_cmd_flac = flac -dc %FILE% | lame -r -b 128 -S - -
stream_cmd_m4a = faad -f 2 -w %FILE% | lame -r -b 128 -S - - trascode_cmd_m4a = faad -f 2 -w %FILE% | lame -r -b 128 -S - -
#stream_cmd_mpc = transcode_cmd_mp3 = mp3splt -qnf %FILE% %OFFSET% %EOF% -o - | lame --mp3input -q 3 -b %SAMPLE% -S - -
####################################################### ;######################################################
# these options allow you to configure your rss-feed ; these options allow you to configure your rss-feed
# layout. rss exists of two parts, main and song ; layout. rss exists of two parts, main and song
# main is the information about the feed ; main is the information about the feed
# song is the information in the feed. can be multiple ; song is the information in the feed. can be multiple
# items. ; items.
# ;
# use_rss = false (values true | false) ; use_rss = false (values true | false)
# ;
#DEFAULT: use_rss = false ;DEFAULT: use_rss = false
#use_rss = false ;use_rss = false
# ;
# ;
# rss_main_title = the title for your feed. ; rss_main_title = the title for your feed.
# DEFAULT: Ampache for the love of Music ; DEFAULT: Ampache for the love of Music
rss_main_title = Ampache for the love of Music rss_main_title = Ampache for the love of Music
# rss_main_description = the description for your feed ; rss_main_description = the description for your feed
# DEFAULT: Rss feed for Ampache so you can monitor who is listening to what ; DEFAULT: Rss feed for Ampache so you can monitor who is listening to what
rss_main_description = Rss feed for Ampache so you can monitor who is listening to what rss_main_description = Rss feed for Ampache so you can monitor who is listening to what
# rss_main_copyright = here you can enter copyright information if you wish ; rss_main_copyright = here you can enter copyright information if you wish
# DEFAULT: copyright (c) Speedy B for Ampache ; DEFAULT: copyright (c) Speedy B for Ampache
rss_main_copyright = copyright (c) Speedy B for Ampache rss_main_copyright = copyright (c) Speedy B for Ampache
# rss_song_description = The description of the song. ; rss_song_description = The description of the song.
# It has to start with <![CDATA[ ; It has to start with <![CDATA[
# and end with ]]>. this is because xml wont parse if strange ; and end with ]]>. this is because xml wont parse if strange
# characters are used in the id3-tag ; characters are used in the id3-tag
# usable items: ; usable items:
# $song->f_title ; $song->f_title
# $song->f_album ; $song->f_album
# $user->fullname ; $user->fullname
# $artist ; $artist
# $album ; $album
# DEFAULT: <![CDATA[$song->f_title @ $album played by $user->fullname]]> ; DEFAULT: <![CDATA[$song->f_title @ $album played by $user->fullname]]>
# FIXME it's hardcoded in lib/rss.lib.php now ; FIXME it's hardcoded in lib/rss.lib.php now
#rss_song_description = <![CDATA[$song->f_title @ $album played by $user->fullname]]> ;rss_song_description = <![CDATA[$song->f_title @ $album played by $user->fullname]]>
###################################################### ;#####################################################

View file

@ -4,6 +4,11 @@
-------------------------------------------------------------------------- --------------------------------------------------------------------------
v.3.4-Alpha1 v.3.4-Alpha1
- Fixed an issue with the random album selection that was causing
a full table scan, which could lead to poor performance
with large databases
- Start of Complete rewrite, config file format changed, requires
manual re-creation of /config/ampache.cfg.php
- Added some minor sorting to the browse by song - Added some minor sorting to the browse by song
- Added ability to search year range (Thx Tom Kiehne) - Added ability to search year range (Thx Tom Kiehne)
- Updated French and German translations - Updated French and German translations

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
Copyright (c) 2001 - 2006 Ampache.org Copyright (c) 2001 - 2007 Ampache.org
All rights reserved. All rights reserved.
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
@ -70,29 +70,30 @@ switch ($_REQUEST['type']) {
$album = new Album($_REQUEST['id']); $album = new Album($_REQUEST['id']);
// Attempt to pull art from the database // Attempt to pull art from the database
$r = $album->get_art(); $art = $album->get_art();
if (isset($r['art'])) { if (!$art['art_mime']) {
$art = $r['art'];
$mime = $r['art_mime'];
}
else {
header('Content-type: image/gif'); header('Content-type: image/gif');
readfile(conf('prefix') . conf('theme_path') . "/images/blankalbum.gif"); readfile(Config::get('prefix') . Config::get('theme_path') . '/images/blankalbum.gif');
break; break;
} // else no image } // else no image
// Print the album art // Print the album art
$data = explode("/",$mime); $data = explode("/",$art['art_mime']);
$extension = $data['1']; $extension = $data['1'];
// if (empty($_REQUEST['thumb'])) {
$art_data = $art['art'];
// }
//else {
// $art_data = img_resize($art,$size,$extension,$_REQUEST['id']);
//}
// Send the headers and output the image
header("Content-type: $mime"); header("Content-type: $mime");
header("Content-Disposition: filename=" . $album->name . "." . $extension); header("Content-Disposition: filename=" . $album->name . "." . $extension);
if (empty($_REQUEST['thumb'])) { echo $art_data;
echo $art;
}
elseif (!img_resize($art,$size,$extension)) {
echo $art;
}
break; break;
} // end switch type } // end switch type

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

BIN
images/ampache.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

View file

@ -24,8 +24,8 @@
@discussion Do most of the dirty work of displaying the mp3 catalog @discussion Do most of the dirty work of displaying the mp3 catalog
*/ */
require_once('lib/init.php'); require_once 'lib/init.php';
show_template('header'); require_once Config::get('prefix') . '/templates/header.inc.php';
$action = scrub_in($_REQUEST['action']); $action = scrub_in($_REQUEST['action']);
@ -34,14 +34,14 @@ $action = scrub_in($_REQUEST['action']);
* refresh_javascript include. Must be greater then 5, I'm not * refresh_javascript include. Must be greater then 5, I'm not
* going to let them break their servers * going to let them break their servers
*/ */
if (conf('refresh_limit') > 5) { if (Config::get('refresh_limit') > 5) {
$ajax_url = conf('ajax_url') . '?action=reloadnp' . conf('ajax_info'); $ajax_url = Config::get('ajax_url') . '?action=reloadnp' . Config::get('ajax_info');
/* Can't have the &amp; stuff in the Javascript */ /* Can't have the &amp; stuff in the Javascript */
$ajax_url = str_replace("&amp;","&",$ajax_url); $ajax_url = str_replace("&amp;","&",$ajax_url);
require_once(conf('prefix') . '/templates/javascript_refresh.inc.php'); require_once Config::get('prefix') . '/templates/javascript_refresh.inc.php';
} }
require_once(conf('prefix') . '/templates/show_index.inc.php'); require_once Config::get('prefix') . '/templates/show_index.inc.php';
show_footer(); show_footer();

View file

@ -68,15 +68,21 @@ function get_random_albums($count='') {
if (!$count) { $count = 5; } if (!$count) { $count = 5; }
$count = sql_escape($count); $count = Dba::escape($count);
$sql = "SELECT id FROM album WHERE art IS NOT NULL ORDER BY RAND() LIMIT $count"; // We avoid a table scan by using the id index and then using a rand to pick a row #
$db_results = mysql_query($sql,dbh()); $sql = "SELECT `id` FROM `album` WHERE `art` IS NOT NULL";
$db_results = Dba::query($sql);
$results = array(); while ($r = Dba::fetch_assoc($db_results)) {
$albums[] = $r['id'];
}
while ($r = mysql_fetch_assoc($db_results)) { $total = count($albums);
$results[] = $r['id'];
for ($i=0; $i <= $count; $i++) {
$record = rand(0,$total);
$results[] = $albums[$record];
} }
return $results; return $results;

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
Copyright (c) 2001 - 2006 Ampache.org Copyright (c) 2001 - 2007 Ampache.org
All Rights Reserved All Rights Reserved
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
@ -145,11 +145,13 @@ class Access {
} // delete } // delete
/*! /**
@function check * check
@discussion check to see if they have rights * This takes a type, ip, user, level and key
*/ * and then returns true or false if they have access to this
function check($type,$ip,$user,$level,$key='') { * the IP is passed as a dotted quad
*/
public static function check($type,$ip,$user,$level,$key='') {
// They aren't using access control // They aren't using access control
// lets just keep on trucking // lets just keep on trucking

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
Copyright (c) 2001 - 2006 Ampache.org Copyright (c) 2001 - 2007 Ampache.org
All Rights Reserved All Rights Reserved
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
@ -73,7 +73,7 @@ class Album {
@discussion get's the vars for $this out of the database @discussion get's the vars for $this out of the database
@param $this->id Taken from the object @param $this->id Taken from the object
*/ */
function _get_info() { private function _get_info() {
$this->id = intval($this->id); $this->id = intval($this->id);
@ -81,10 +81,9 @@ class Album {
$sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,album.prefix,album.year,album.name AS album_name,COUNT(song.id) AS song_count," . $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,album.prefix,album.year,album.name AS album_name,COUNT(song.id) AS song_count," .
"artist.name AS artist_name,artist.id AS art_id,artist.prefix AS artist_prefix,album.art AS has_art ". "artist.name AS artist_name,artist.id AS art_id,artist.prefix AS artist_prefix,album.art AS has_art ".
"FROM song,artist,album WHERE album.id='$this->id' AND song.album=album.id AND song.artist=artist.id GROUP BY song.album"; "FROM song,artist,album WHERE album.id='$this->id' AND song.album=album.id AND song.artist=artist.id GROUP BY song.album";
$db_results = Dba::query($sql);
$db_results = mysql_query($sql, dbh()); $results = Dba::fetch_assoc($db_results);
$results = mysql_fetch_assoc($db_results);
// If there is art then set it to 1, if not set it to 0, we don't want to cary // If there is art then set it to 1, if not set it to 0, we don't want to cary
// around the full blob with every object because it can be pretty big // around the full blob with every object because it can be pretty big
@ -147,10 +146,10 @@ class Album {
*/ */
function format() { function format() {
$web_path = conf('web_path'); $web_path = Config::get('web_path');
/* Truncate the string if it's to long */ /* Truncate the string if it's to long */
$name = scrub_out(truncate_with_ellipse($this->name,conf('ellipse_threshold_album'))); $name = scrub_out(truncate_with_ellipse($this->name,Config::get('ellipse_threshold_album')));
$artist = scrub_out($this->artist); $artist = scrub_out($this->artist);
$this->f_name = "<a href=\"$web_path/albums.php?action=show&amp;album=" . $this->id . "\" title=\"" . scrub_out($this->name) . "\">" . $name . "</a>"; $this->f_name = "<a href=\"$web_path/albums.php?action=show&amp;album=" . $this->id . "\" title=\"" . scrub_out($this->name) . "\">" . $name . "</a>";
$this->f_link = "<a href=\"$web_path/albums.php?action=show&amp;album=" . scrub_out($this->id) . "\" title=\"" . scrub_out($this->name) . "\">" . $name . "</a>"; $this->f_link = "<a href=\"$web_path/albums.php?action=show&amp;album=" . scrub_out($this->id) . "\" title=\"" . scrub_out($this->name) . "\">" . $name . "</a>";
@ -182,12 +181,20 @@ class Album {
/** /**
* get_art * get_art
* This function only pulls art from the database, nothing else * This function only pulls art from the database, if thumb is passed
* It should not be called when trying to find new art * it trys to pull the resized art instead, if resized art is found then
* it returns an additional resized=true in the array
*/ */
function get_art() { function get_art() {
return $this->get_db_art(); // Attempt to get the resized art first
$art = $this->get_resized_db_art();
if (!is_array($art)) {
$art = $this->get_db_art();
}
return $art;
} // get_art } // get_art
@ -371,15 +378,37 @@ class Album {
} // get_folder_art() } // get_folder_art()
/** /**
* get_db_art() * get_resized_db_art
* This looks to see if we have a resized thumbnail that we can load rather then taking
* the fullsized and resizing that
*/
public function get_resized_db_art() {
$id = Dba::escape($this->id);
$sql = "SELECT `thumb` AS `art`,`thumb_mime` AS `art_mime` FROM `album` WHERE `id`='$id'";
$db_results = Dba::query($sql);
$results = Dba::fetch_assoc($db_results);
if (strlen($results['art_mime'])) {
$results['resized'] = true;
}
else { return false; }
return $results;
} // get_resized_db_art
/**
* get_db_art
* returns the album art from the db along with the mime type * returns the album art from the db along with the mime type
*/ */
function get_db_art() { public function get_db_art() {
$sql = "SELECT art,art_mime FROM album WHERE id='$this->id' AND art_mime IS NOT NULL"; $sql = "SELECT `art`,`art_mime` FROM `album` WHERE `id`='$this->id'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$results = mysql_fetch_assoc($db_results); $results = Dba::fetch_assoc($db_results);
if (!$results['art']) { return array(); } if (!$results['art']) { return array(); }
@ -585,6 +614,22 @@ class Album {
} // insert_art } // insert_art
/**
* save_resized_art
* This takes data from a gd resize operation and saves
* it back into the database as a thumbnail
*/
public static function save_resized_art($data,$mime,$album) {
$data = Dba::escape($data);
$mime = Dba::escape($mime);
$album = Dba::escape($album);
$sql = "UPDATE `album` SET `thumb`='$data',`thumb_mime`='$mime' " .
"WHERE `album`.`id`='$album'";
$db_results = Dba::query($sql);
} // save_resized_art
} //end of album class } //end of album class

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
Copyright (c) 2001 - 2006 Ampache.org Copyright (c) 2001 - 2007 Ampache.org
All rights reserved. All rights reserved.
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
@ -31,10 +31,10 @@ class Artist {
var $albums; var $albums;
var $prefix; var $prefix;
/*! /**
@function Artist * Artist
@discussion Artist class, for modifing a artist * Artist class, for modifing a artist
@param $artist_id The ID of the artist * Takes the ID of the artist and pulls the info from the db
*/ */
function Artist($artist_id = 0) { function Artist($artist_id = 0) {
@ -46,32 +46,30 @@ class Artist {
/* Get the information from the db */ /* Get the information from the db */
$info = $this->_get_info(); $info = $this->_get_info();
if (count($info)) {
/* Assign Vars */ foreach ($info as $key=>$value) {
$this->name = $info['name']; $this->$key = $value;
$this->prefix = $info['prefix']; } // foreach info
} // if info
return true; return true;
} //constructor } //constructor
/*! /**
@function _get_info * _get_info
@discussion get's the vars for $this out of the database * get's the vars for $this out of the database taken from the object
@param $this->id Taken from the object
*/ */
function _get_info() { private function _get_info() {
/* Grab the basic information from the catalog and return it */ /* Grab the basic information from the catalog and return it */
$sql = "SELECT * FROM artist WHERE id='" . sql_escape($this->id) . "'"; $sql = "SELECT * FROM artist WHERE id='" . Dba::escape($this->id) . "'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$results = mysql_fetch_assoc($db_results); $results = Dba::fetch_assoc($db_results);
return $results; return $results;
} //get_info } // _get_info
/*! /*!
@function get_albums @function get_albums
@ -161,9 +159,9 @@ class Artist {
$albums = 0; $albums = 0;
$sql = "SELECT COUNT(song.id) FROM song WHERE song.artist='$this->id' GROUP BY song.album"; $sql = "SELECT COUNT(song.id) FROM song WHERE song.artist='$this->id' GROUP BY song.album";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
while ($r = mysql_fetch_array($db_results)) { while ($r = Dba::fetch_row($db_results)) {
$songs += $r[0]; $songs += $r[0];
$albums++; $albums++;
} }
@ -193,7 +191,7 @@ class Artist {
$this->full_name = scrub_out(trim($this->prefix . " " . $this->name)); $this->full_name = scrub_out(trim($this->prefix . " " . $this->name));
//FIXME: This should be f_link //FIXME: This should be f_link
$this->link = "<a href=\"" . conf('web_path') . "/artists.php?action=show&amp;artist=" . $this->id . "\" title=\"" . $this->full_name . "\">" . $name . "</a>"; $this->f_link = "<a href=\"" . Config::get('web_path') . "/artists.php?action=show&amp;artist=" . $this->id . "\" title=\"" . $this->full_name . "\">" . $name . "</a>";
// Get the counts // Get the counts
$this->get_count(); $this->get_count();

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
Copyright (c) 2001 - 2006 Ampache.org Copyright (c) 2001 - 2007 Ampache.org
All Rights Reserved All Rights Reserved
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
@ -27,22 +27,22 @@
*/ */
class Catalog { class Catalog {
var $name; public $name;
var $last_update; public $last_update;
var $last_add; public $last_add;
var $key; public $key;
var $rename_pattern; public $rename_pattern;
var $sort_pattern; public $sort_pattern;
var $catalog_type; public $catalog_type;
/* This is a private var that's used during catalog builds */ /* This is a private var that's used during catalog builds */
var $_playlists = array(); private $_playlists = array();
var $_art_albums = array(); private $_art_albums = array();
// Used in functions // Used in functions
var $albums = array(); public $albums = array();
var $artists = array(); public $artists = array();
var $genres = array(); public $genres = array();
/** /**
* Catalog * Catalog
@ -52,57 +52,47 @@ class Catalog {
*/ */
function Catalog($catalog_id = 0) { function Catalog($catalog_id = 0) {
/* If we have passed an id then do something */ if (!$catalog_id) { return false; }
if ($catalog_id) {
/* Assign id for use in get_info() */
$this->id = intval($catalog_id);
/* Get the information from the db */ /* Assign id for use in get_info() */
$info = $this->get_info(); $this->id = intval($catalog_id);
/* Assign Vars */ /* Get the information from the db */
$this->path = $info->path; $info = $this->_get_info();
$this->name = $info->name;
$this->last_update = $info->last_update; foreach ($info as $key=>$value) {
$this->last_add = $info->last_add; $this->$key = $value;
$this->key = $info->key; }
$this->rename_pattern = $info->rename_pattern;
$this->sort_pattern = $info->sort_pattern;
$this->catalog_type = $info->catalog_type;
} //catalog_id
} //constructor } //constructor
/**
/*! * _get_info
@function get_info * get's the vars for $this out of the database requires an id
@discussion get's the vars for $this out of the database */
@param $this->id Taken from the object private function _get_info() {
*/
function get_info() {
/* Grab the basic information from the catalog and return it */ /* Grab the basic information from the catalog and return it */
$sql = "SELECT * FROM catalog WHERE id='$this->id'"; $sql = "SELECT * FROM `catalog` WHERE `id`='$this->id'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$results = mysql_fetch_object($db_results); $results = Dba::fetch_assoc($db_results);
return $results; return $results;
} //get_info } // _get_info
/**
* get_catalogs
*Pull all the current catalogs
*/
public static function get_catalogs() {
/*! $sql = "SELECT `id` FROM `catalog`";
@function get_catalogs $db_results = Dba::query($sql);
@discussion Pull all the current catalogs
*/
function get_catalogs() {
$sql = "SELECT id FROM catalog"; while ($r = Dba::fetch_assoc($db_results)) {
$db_results = mysql_query($sql, dbh()); $results[] = new Catalog($r['id']);
while ($r = mysql_fetch_object($db_results)) {
$results[] = new Catalog($r->id);
} }
return $results; return $results;
@ -115,10 +105,10 @@ class Catalog {
*/ */
function get_catalog_ids() { function get_catalog_ids() {
$sql = "SELECT id FROM catalog"; $sql = "SELECT `id` FROM `catalog`";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::qery($sql);
while ($r = mysql_fetch_assoc($db_results)) { while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r['id']; $results[] = $r['id'];
} }
@ -126,46 +116,89 @@ class Catalog {
} // get_catalog_ids } // get_catalog_ids
/*! /**
@function get_catalog_stats * get_stats
@discussion Pulls information about number of songs etc for a specifc catalog, or all catalogs * This returns an hash with the #'s for the different
calls many other internal functions, returns an object containing results * objects that are assoicated with this catalog. This is used
@param $catalog_id If set tells us to pull from a single catalog, rather than all catalogs * to build the stats box, it also calculates time
*/ */
function get_catalog_stats($catalog_id=0) { public static function get_stats($catalog_id=0) {
$results->songs = $this->count_songs($catalog_id); $results = self::count_songs($catalog_id);
$results->albums = $this->count_albums($catalog_id); $results = array_merge(self::count_users($catalog_id),$results);
$results->artists = $this->count_artists($catalog_id);
$results->size = $this->get_song_size($catalog_id);
$results->time = $this->get_song_time($catalog_id);
} // get_catalog_stats
/*!
@function get_song_time
@discussion Get the total amount of time (song wise) in all or specific catalog
@param $catalog_id If set tells ut to pick a specific catalog
*/
function get_song_time($catalog_id=0) {
$sql = "SELECT SUM(song.time) FROM song";
if ($catalog_id) {
$sql .= " WHERE catalog='$catalog_id'";
}
$db_results = mysql_query($sql, dbh());
$results = mysql_fetch_field($db_results);
/* Do some conversion to get Hours Min Sec */
// $results->songs = $this->count_songs($catalog_id);
// $results->albums = $this->count_albums($catalog_id);
// $results->artists = $this->count_artists($catalog_id);
// $results->size = $this->get_song_size($catalog_id);
// $results->time = $this->get_song_time($catalog_id);
return $results; return $results;
} // get_song_time } // get_stats
/**
* count_songs
* This returns the current # of songs, albums, artists, genres
* in this catalog
*/
public static function count_songs($catalog_id='') {
if ($catalog_id) { $catalog_search = "WHERE `catalog`='" . Dba::escape($catalog_id) . "'"; }
$sql = "SELECT `id`,`album`,`artist`,`genre`,`file`,`size`,`time` FROM `song` $catalog_search";
$db_results = Dba::query($sql);
while ($data = Dba::fetch_assoc($db_results)) {
$albums[$data['album']] = true;
$artists[$data['artist']] = true;
$genres[$data['genre']] = true;
$dir = basename($data['file']);
$folders[$dir] = true;
$size += $data['size'];
$time += $data['time'];
$songs++;
}
$results['songs'] = $songs;
$results['albums'] = count($albums);
$results['artists'] = count($artists);
$results['genres'] = count($genres);
$results['folders'] = count($folders);
$results['size'] = $size;
$results['time'] = $time;
return $results;
} // count_songs
/**
* count_users
* This returns the total number of users in the ampache instance
*/
public static function count_users($catalog_id='') {
// Count total users
$sql = "SELECT COUNT(id) FROM `user`";
$db_results = Dba::query($sql);
$data = Dba::fetch_row($db_results);
$results['users'] = $data['0'];
// Get the connected users
$time = time();
$last_seen_time = $time - 1200;
$sql = "SELECT count(DISTINCT s.username) FROM session AS s " .
"INNER JOIN user AS u ON s.username = u.username " .
"WHERE s.expire > " . $time . " " .
"AND u.last_seen > " . $last_seen_time;
$db_results = Dba::query($sql);
$data = Dba::fetch_row($db_results);
$results['connected'] = $data['0'];
return $results;
} // count_users
/*! /*!
@function get_song_size @function get_song_size
@ -233,25 +266,6 @@ class Catalog {
} // count_albums } // count_albums
/*!
@function count_songs
@discussion Count the number of songs in all catalogs, or a specific one
@param $catalog_id If set tells us to pick a specific catalog
*/
function count_songs($catalog_id=0) {
$sql = "SELECT count(*) FROM song";
if ($catalog_id) {
$sql .= " WHERE catalog='$catalog_id'";
}
$db_results = mysql_query($sql, dbh());
$results = mysql_fetch_field($db_results);
return $results;
} // count_songs
/*! /*!
@function add_file @function add_file
@discussion adds a single file @discussion adds a single file
@ -585,16 +599,16 @@ class Catalog {
* Gets an array of the disabled songs for all catalogs * Gets an array of the disabled songs for all catalogs
* and returns full song objects with them * and returns full song objects with them
*/ */
function get_disabled($count=0) { public static function get_disabled($count=0) {
$results = array(); $results = array();
if ($count) { $limit_clause = " LIMIT $count"; } if ($count) { $limit_clause = " LIMIT $count"; }
$sql = "SELECT id FROM song WHERE enabled='0' $limit_clause"; $sql = "SELECT id FROM song WHERE enabled='0' $limit_clause";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
while ($r = mysql_fetch_array($db_results)) { while ($r = Dba::fetch_assoc($db_results)) {
$results[] = new Song($r['id']); $results[] = new Song($r['id']);
} }
@ -602,7 +616,6 @@ class Catalog {
} // get_disabled } // get_disabled
/*! /*!
@function get_files @function get_files
@discussion Get's an array of .mp3s and returns the filenames @discussion Get's an array of .mp3s and returns the filenames

View file

@ -21,6 +21,15 @@
/* Make sure they aren't directly accessing it */ /* Make sure they aren't directly accessing it */
if (INIT_LOADED != '1') { exit; } if (INIT_LOADED != '1') { exit; }
/**
* Dba
* This is the database abstraction class
* It duplicates the functionality of mysql_???
* with a few exceptions, the row and assoc will always
* return an array, simplifying checking on the far end
* it will also auto-connect as needed, and has a default
* database simplifying queries in most cases.
*/
class Dba { class Dba {
private static $_default_db; private static $_default_db;
@ -66,6 +75,7 @@ class Dba {
/** /**
* fetch_assoc * fetch_assoc
* This emulates the mysql_fetch_assoc and takes a resource result * This emulates the mysql_fetch_assoc and takes a resource result
* we force it to always return an array, albit an empty one
*/ */
public static function fetch_assoc($resource) { public static function fetch_assoc($resource) {
@ -80,6 +90,7 @@ class Dba {
/** /**
* fetch_row * fetch_row
* This emulates the mysql_fetch_row and takes a resource result * This emulates the mysql_fetch_row and takes a resource result
* we force it to always return an array, albit an empty one
*/ */
public static function fetch_row($resource) { public static function fetch_row($resource) {
@ -91,6 +102,21 @@ class Dba {
} // fetch_row } // fetch_row
/**
* num_rows
* This emulates the mysql_num_rows function which is really
* just a count of rows returned by our select statement, this
* doesn't work for updates or inserts
*/
public static function num_rows($resource) {
$result = mysql_num_rows($resource);
if (!$result) { return '0'; }
return $result;
} // num_rows
/** /**
* _connect * _connect
* This connects to the database, used by the DBH function * This connects to the database, used by the DBH function
@ -98,10 +124,10 @@ class Dba {
private static function _connect($db_name) { private static function _connect($db_name) {
if (self::$_default_db == $db_name) { if (self::$_default_db == $db_name) {
$username = Config::get('mysql_username'); $username = Config::get('database_username');
$hostname = Config::get('mysql_hostname'); $hostname = Config::get('database_hostname');
$password = Config::get('mysql_password'); $password = Config::get('database_password');
$database = Config::get('mysql_database'); $database = Config::get('database_name');
} }
else { else {
// Do this later // Do this later
@ -125,13 +151,16 @@ class Dba {
if (!$database) { $database = self::$_default_db; } if (!$database) { $database = self::$_default_db; }
if (!is_resource(self::$config->get($database))) { // Assign the Handle name that we are going to store
$handle = 'dbh_' . $database;
if (!is_resource(Config::get($handle))) {
$dbh = self::_connect($database); $dbh = self::_connect($database);
self::$config->set($database,$dbh,1); Config::set($handle,$dbh,1);
return $dbh; return $dbh;
} }
else { else {
return self::$config->get($database); return Config::get($handle);
} }
@ -154,10 +183,9 @@ class Dba {
* This is the auto init function it sets up the config class * This is the auto init function it sets up the config class
* and also sets the default database * and also sets the default database
*/ */
public static function auto_init() { public static function _auto_init() {
self::$_default_db = Config::get('mysql_database'); self::$_default_db = Config::get('database_name');
self::$config = new Config();
return true; return true;

View file

@ -1,92 +1,80 @@
<?php <?php
/* /**
* Error class
Copyright (c) 2001 - 2006 Ampache.org * This is the baic error class, its better now that we can use php5
All rights reserved. * hello static functions and variables
*/
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*!
@header Error handler requires error_results() function
*/
class Error { class Error {
//Basic Componets public static $state = false; // set to one when an error occurs
var $error_state=0; public static $errors = array(); // Errors array key'd array with errors that have occured
/* Generated values */ /**
var $errors = array(); * __constructor
* This does nothing... amazing isn't it!
*/
private function __construct() {
/*! // Rien a faire
@function error
@discussion this is the constructor for the error class
*/
function Error() {
return true; } // __construct
} //constructor /**
* add
* This is a public static function it adds a new error message to the array
* It can optionally clobber rather then adding to the error message
*/
public static function add($name,$message,$clobber=0) {
/*! // Make sure its set first
@function add_error if (!isset(Error::$errors[$name])) {
@discussion adds an error to the static array stored in Error::$errors[$name] = $message;
error_results() Error::$state = 1;
*/
function add_error($name,$description) {
$array = array($name=>$description);
error_results($array,1);
$this->error_state = 1;
return true;
} // add_error
/*!
@function has_error
@discussion returns true if the name given has an error,
false if it doesn't
*/
function has_error($name) {
$results = error_results($name);
if (!empty($results)) {
return true; return true;
} }
return false; // They want us to clobber it
if ($clobber) {
} // has_error Error::$state = 1;
Error::$errors[$name] = $message;
/*! return true;
@function print_error
@discussion prints out the error for a name if it exists
*/
function print_error($name) {
if ($this->has_error($name)) {
echo "<div class=\"fatalerror\">" . error_results($name) . "</div>\n";
} }
} // print_error // They want us to append the error, add a BR\n and then the message
else {
Error::$state = 1;
Error::$errors[$name] .= "<br />\n" . $message;
return true;
}
} //end error class
?> } // add
/**
* get
* This returns an error by name
*/
public static function get($name) {
if (!isset(Error::$errors[$name])) { return ''; }
return Error::$errors[$name];
} // get
/**
* display
* This prints the error out with a standard Error class span
* Ben Goska: Renamed from print to display, print is reserved
*/
public static function display($name) {
// Be smart about this, if no error don't print
if (!isset(Error::$errors[$name])) { return ''; }
echo '<span class="error">' . Error::$errors[$name] . '</span>';
} // display
} // Error

View file

@ -70,14 +70,14 @@ class Flag {
* _get_info * _get_info
* Private function for getting the information for this object from the database * Private function for getting the information for this object from the database
*/ */
function _get_info() { private function _get_info() {
$id = sql_escape($this->id); $id = Dba::escape($this->id);
$sql = "SELECT * FROM flagged WHERE id='$id'"; $sql = "SELECT * FROM `flagged` WHERE `id`='$id'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$results = mysql_fetch_assoc($db_results); $results = Dba::fetch_assoc($db_results);
return $results; return $results;
@ -88,16 +88,16 @@ class Flag {
* This returns the id's of the most recently flagged songs, it takes an int * This returns the id's of the most recently flagged songs, it takes an int
* as an argument which is the count of the object you want to return * as an argument which is the count of the object you want to return
*/ */
function get_recent($count=0) { public static function get_recent($count=0) {
if ($count) { $limit = " LIMIT " . intval($count); } if ($count) { $limit = " LIMIT " . intval($count); }
$results = array(); $results = array();
$sql = "SELECT id FROM flagged ORDER BY date " . $limit; $sql = "SELECT id FROM flagged ORDER BY date " . $limit;
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
while ($r = mysql_fetch_assoc($db_results)) { while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r['id']; $results[] = $r['id'];
} }

View file

@ -57,39 +57,19 @@ class Song {
*/ */
function Song($song_id = 0) { function Song($song_id = 0) {
/* If we have passed an id then do something */ if (!$song_id) { return false; }
if ($song_id) {
/* Assign id for use in get_info() */ /* Assign id for use in get_info() */
$this->id = intval($song_id); $this->id = intval($song_id);
/* Get the information from the db */ /* Get the information from the db */
if ($info = $this->_get_info()) { if ($info = $this->_get_info()) {
/* Assign Vars */
$this->file = $info->file;
$this->album = $info->album;
$this->artist = $info->artist;
$this->title = $info->title;
$this->comment = $info->comment;
$this->year = $info->year;
$this->bitrate = $info->bitrate;
$this->rate = $info->rate;
$this->mode = $info->mode;
$this->size = $info->size;
$this->time = $info->time;
$this->track = $info->track;
$this->genre = $info->genre;
$this->addition_time = $info->addition_time;
$this->catalog = $info->catalog;
$this->played = $info->played;
$this->update_time = $info->update_time;
$this->enabled = $info->enabled;
foreach ($info as $key=>$value) {
$this->$key = $value;
}
// Format the Type of the song // Format the Type of the song
$this->format_type(); $this->format_type();
}
} }
} //constructor } //constructor
@ -100,16 +80,16 @@ class Song {
@discussion get's the vars for $this out of the database @discussion get's the vars for $this out of the database
@param $this->id Taken from the object @param $this->id Taken from the object
*/ */
function _get_info() { private function _get_info() {
/* Grab the basic information from the catalog and return it */ /* Grab the basic information from the catalog and return it */
$sql = "SELECT song.id,file,catalog,album,year,artist,". $sql = "SELECT song.id,file,catalog,album,year,artist,".
"title,bitrate,rate,mode,size,time,track,genre,played,song.enabled,update_time,". "title,bitrate,rate,mode,size,time,track,genre,played,song.enabled,update_time,".
"addition_time FROM song WHERE song.id = '$this->id'"; "addition_time FROM `song` WHERE `song`.`id` = '$this->id'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$results = mysql_fetch_object($db_results); $results = Dba::fetch_assoc($db_results);
return $results; return $results;
@ -229,10 +209,10 @@ class Song {
if (!$album_id) { $album_id = $this->album; } if (!$album_id) { $album_id = $this->album; }
$sql = "SELECT name,prefix FROM album WHERE id='" . sql_escape($album_id) . "'"; $sql = "SELECT `name`,`prefix` FROM `album` WHERE `id`='" . Dba::escape($album_id) . "'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$results = mysql_fetch_assoc($db_results); $results = Dba::fetch_assoc($db_results);
if ($results['prefix']) { if ($results['prefix']) {
return $results['prefix'] . " " .$results['name']; return $results['prefix'] . " " .$results['name'];
@ -251,10 +231,10 @@ class Song {
if (!$artist_id) { $artist_id = $this->artist; } if (!$artist_id) { $artist_id = $this->artist; }
$sql = "SELECT name,prefix FROM artist WHERE id='" . sql_escape($artist_id) . "'"; $sql = "SELECT name,prefix FROM artist WHERE id='" . Dba::escape($artist_id) . "'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$results = mysql_fetch_assoc($db_results); $results = Dba::fetch_assoc($db_results);
if ($results['prefix']) { if ($results['prefix']) {
return $results['prefix'] . " " . $results['name']; return $results['prefix'] . " " . $results['name'];
@ -274,10 +254,10 @@ class Song {
if (!$genre_id) { $genre_id = $this->genre; } if (!$genre_id) { $genre_id = $this->genre; }
$sql = "SELECT name FROM genre WHERE id='" . sql_escape($genre_id) . "'"; $sql = "SELECT name FROM genre WHERE id='" . Dba::escape($genre_id) . "'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$results = mysql_fetch_assoc($db_results); $results = Dba::fetch_assoc($db_results);
return $results['name']; return $results['name'];
@ -681,19 +661,19 @@ class Song {
// Format the album name // Format the album name
$this->f_album_full = $this->get_album_name(); $this->f_album_full = $this->get_album_name();
$this->f_album = truncate_with_ellipse($this->f_album_full,conf('ellipse_threshold_album')); $this->f_album = truncate_with_ellipse($this->f_album_full,Config::get('ellipse_threshold_album'));
// Format the artist name // Format the artist name
$this->f_artist_full = $this->get_artist_name(); $this->f_artist_full = $this->get_artist_name();
$this->f_artist = truncate_with_ellipse($this->f_artist_full,conf('ellipse_threshold_artist')); $this->f_artist = truncate_with_ellipse($this->f_artist_full,Config::get('ellipse_threshold_artist'));
// Format the title // Format the title
$this->f_title = truncate_with_ellipse($this->title,conf('ellipse_threshold_title')); $this->f_title = truncate_with_ellipse($this->title,Config::get('ellipse_threshold_title'));
// Create Links for the different objects // Create Links for the different objects
$this->f_link = "<a href=\"" . conf('web_path') . "/song.php?action=single_song&amp;song_id=" . $this->id . "\">$this->f_title</a>"; $this->f_link = "<a href=\"" . Config::get('web_path') . "/stream.php?action=single_song&amp;song_id=" . $this->id . "\">$this->f_title</a>";
$this->f_album_link = "<a href=\"" . conf('web_path') . "/albums.php?action=show&amp;album=" . $this->album . "\">$this->f_album</a>"; $this->f_album_link = "<a href=\"" . Config::get('web_path') . "/albums.php?action=show&amp;album=" . $this->album . "\">$this->f_album</a>";
$this->f_artist_link = "<a href=\"" . conf('web_path') . "/artists.php?action=show&amp;artist=" . $this->artist . "\">$this->f_artist</a>"; $this->f_artist_link = "<a href=\"" . Config::get('web_path') . "/artists.php?action=show&amp;artist=" . $this->artist . "\">$this->f_artist</a>";
// Format the Bitrate // Format the Bitrate
$this->f_bitrate = intval($this->bitrate/1000) . "-" . strtoupper($this->mode); $this->f_bitrate = intval($this->bitrate/1000) . "-" . strtoupper($this->mode);
@ -802,7 +782,7 @@ class Song {
$user_id = scrub_out($GLOBALS['user']->id); $user_id = scrub_out($GLOBALS['user']->id);
$song_id = $this->id; $song_id = $this->id;
if (conf('require_session')) { if (Config::get('require_session')) {
if ($session_id) { if ($session_id) {
$session_string = "&sid=" . $session_id; $session_string = "&sid=" . $session_id;
} }
@ -823,10 +803,10 @@ class Song {
$this->format(); $this->format();
$song_name = rawurlencode($this->f_artist_full . " - " . $this->title . "." . $type); $song_name = rawurlencode($this->f_artist_full . " - " . $this->title . "." . $type);
$web_path = conf('web_path'); $web_path = Config::get('web_path');
if (conf('force_http_play') OR !empty($force_http)) { if (Config::get('force_http_play') OR !empty($force_http)) {
$port = conf('http_port'); $port = Config::get('http_port');
if (preg_match("/:\d+/",$web_path)) { if (preg_match("/:\d+/",$web_path)) {
$web_path = str_replace("https://", "http://",$web_path); $web_path = str_replace("https://", "http://",$web_path);
$web_path = preg_replace("/:\d+/",":$port",$web_path); $web_path = preg_replace("/:\d+/",":$port",$web_path);
@ -854,9 +834,9 @@ class Song {
$conf_var = 'transcode_' . $this->type; $conf_var = 'transcode_' . $this->type;
$conf_type = 'transcode_' . $this->type . '_target'; $conf_type = 'transcode_' . $this->type . '_target';
if (conf($conf_var)) { if (Config::get($conf_var)) {
$this->_transcode = true; $this->_transcode = true;
$this->format_type(conf($conf_type)); $this->format_type(Config::get($conf_type));
debug_event('auto_transcode','Transcoding to ' . $this->type,'5'); debug_event('auto_transcode','Transcoding to ' . $this->type,'5');
return false; return false;
} }

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
Copyright (c) 2001 - 2006 Ampache.org Copyright (c) 2001 - 2007 Ampache.org
All rights reserved. All rights reserved.
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
@ -77,7 +77,7 @@ class Stats {
/* If they don't pass one, then use the preference */ /* If they don't pass one, then use the preference */
if (!$threshold) { if (!$threshold) {
$threshold = conf('stats_threshold'); $threshold = Config::get('stats_threshold');
} }
$count = intval($count); $count = intval($count);
@ -88,11 +88,11 @@ class Stats {
$sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" . $sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" .
" WHERE object_type='$type' AND date >= '$date'" . " WHERE object_type='$type' AND date >= '$date'" .
" GROUP BY object_id ORDER BY `count` DESC LIMIT $count"; " GROUP BY object_id ORDER BY `count` DESC LIMIT $count";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$results = array(); $results = array();
while ($r = mysql_fetch_assoc($db_results)) { while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r; $results[] = $r;
} }
@ -105,29 +105,30 @@ class Stats {
* This gets all stats for atype based on user with thresholds and all * This gets all stats for atype based on user with thresholds and all
* If full is passed, doesn't limit based on date * If full is passed, doesn't limit based on date
*/ */
function get_user($count,$type,$user,$full='') { public static function get_user($count,$type,$user,$full='') {
$count = intval($count); $count = intval($count);
$type = $this->validate_type($type); $type = self::validate_type($type);
$user = sql_escape($user); $user = Dba::escape($user);
/* If full then don't limit on date */ /* If full then don't limit on date */
if ($full) { if ($full) {
$date = '0'; $date = '0';
} }
else { else {
$date = time() - (86400*conf('stats_threshold')); $date = time() - (86400*Config::get('stats_threshold'));
} }
/* Select Objects based on user */ /* Select Objects based on user */
//FIXME:: Requires table can, look at improving
$sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" . $sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" .
" WHERE object_type='$type' AND date >= '$date' AND user = '$user'" . " WHERE object_type='$type' AND date >= '$date' AND user = '$user'" .
" GROUP BY object_id ORDER BY `count` DESC LIMIT $count"; " GROUP BY object_id ORDER BY `count` DESC LIMIT $count";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$results = array(); $results = array();
while ($r = mysql_fetch_assoc($db_results)) { while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r; $results[] = $r;
} }
@ -140,7 +141,7 @@ class Stats {
* This function takes a type and returns only those * This function takes a type and returns only those
* which are allowed, ensures good data gets put into the db * which are allowed, ensures good data gets put into the db
*/ */
function validate_type($type) { public static function validate_type($type) {
switch ($type) { switch ($type) {
case 'artist': case 'artist':
@ -160,5 +161,31 @@ class Stats {
} // validate_type } // validate_type
/**
* get_newest
* This returns an array of the newest artists/albums/whatever
* in this ampache instance
*/
public static function get_newest($type,$limit='') {
if (!$limit) { $limit = Config::get('popular_threshold'); }
$type = self::validate_type($type);
$object_name = ucfirst($type);
$sql = "SELECT DISTINCT($type) FROM `song` ORDER BY `addition_time` DESC " .
"LIMIT $limit";
$db_results = Dba::query($sql);
while ($r = Dba::fetch_row($db_results)) {
$object = new $object_name($r['0']);
$object->format();
$items[] = $object;
} // end while results
return $items;
} // get_newest
} //Stats class } //Stats class
?> ?>

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
Copyright (c) 2001 - 2006 Ampache.org Copyright (c) 2001 - 2007 Ampache.org
All rights reserved. All rights reserved.
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
@ -43,16 +43,16 @@ class Stream {
$this->type = $type; $this->type = $type;
$this->songs = $song_ids; $this->songs = $song_ids;
$this->web_path = conf('web_path'); $this->web_path = Config::get('web_path');
if (conf('force_http_play')) { if (Config::get('force_http_play')) {
$port = conf('http_port'); $port = Config::get('http_port');
$this->web_path = preg_replace("/https/", "http",$this->web_path); $this->web_path = preg_replace("/https/", "http",$this->web_path);
$this->web_path = preg_replace("/:\d+/",":$port",$this->web_path); $this->web_path = preg_replace("/:\d+/",":$port",$this->web_path);
} }
$this->sess = session_id(); $this->sess = session_id();
$this->user_id = $_SESSION['userdata']['username']; $this->user_id = $GLOBALS['user']->id;
} //constructor } //constructor
@ -120,24 +120,25 @@ class Stream {
} // simple_m3u } // simple_m3u
/*! /**
@function create_m3u * create_m3u
@discussion creates an m3u file * creates an m3u file, this includes the EXTINFO and as such can be
*/ * large with very long playlsits
function create_m3u() { */
public function create_m3u() {
// Send the client an m3u playlist // Send the client an m3u playlist
header("Cache-control: public"); header("Cache-control: public");
header("Content-Disposition: filename=playlist.m3u"); header("Content-Disposition: filename=playlist.m3u");
header("Content-Type: audio/x-mpegurl;"); header("Content-Type: audio/x-mpegurl;");
echo "#EXTM3U\n"; echo "#EXTM3U\n";
foreach($this->songs as $song_id) { foreach($this->songs as $song_id) {
$song = new Song($song_id); $song = new Song($song_id);
$song->format_song(); $song->format();
if ($song->type == ".flac") { $song->type = ".ogg"; }
$song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type; $song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type;
echo "#EXTINF:$song->time," . $song->f_artist_full . " - " . $song->title . "\n"; echo "#EXTINF:$song->time," . $song->f_artist_full . " - " . $song->title . "\n";
$sess = $_COOKIE[conf('sess_name')]; $sess = $_COOKIE[Config::get('sess_name')];
if($GLOBALS['user']->prefs['play_type'] == 'downsample') { if($GLOBALS['user']->prefs['play_type'] == 'downsample') {
$ds = $GLOBALS['user']->prefs['sample_rate']; $ds = $GLOBALS['user']->prefs['sample_rate'];
} }

View file

@ -37,9 +37,9 @@
class Update { class Update {
var $key; public $key;
var $value; public $value;
var $versions; // array containing version information public static $versions; // array containing version information
/*! /*!
@function Update @function Update
@ -77,16 +77,16 @@ class Update {
because we may not have the update_info table we have to check because we may not have the update_info table we have to check
for it's existance first. for it's existance first.
*/ */
function get_version() { public static function get_version() {
/* Make sure that update_info exits */ /* Make sure that update_info exits */
$sql = "SHOW TABLES LIKE 'update_info'"; $sql = "SHOW TABLES LIKE 'update_info'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
if (!is_resource(dbh())) { header("Location: test.php"); } if (!is_resource(Dba::dbh())) { header("Location: test.php"); }
// If no table // If no table
if (!mysql_num_rows($db_results)) { if (!Dba::num_rows($db_results)) {
$version = '310000'; $version = '310000';
@ -95,9 +95,9 @@ class Update {
else { else {
// If we've found the update_info table, let's get the version from it // If we've found the update_info table, let's get the version from it
$sql = "SELECT * FROM update_info WHERE `key`='db_version'"; $sql = "SELECT * FROM update_info WHERE `key`='db_version'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$results = mysql_fetch_object($db_results); $results = Dba::fetch_assoc($db_results);
$version = $results->value; $version = $results['value'];
} }
return $version; return $version;
@ -117,24 +117,24 @@ class Update {
} // format_version } // format_version
/*! /**
@function need_update * need_update
@discussion checks to see if we need to update * checks to see if we need to update
maintain at all * maintain at all
*/ */
function need_update() { public static function need_update() {
$current_version = $this->get_version(); $current_version = self::get_version();
if (!is_array($this->versions)) { if (!is_array(self::$versions)) {
$this->versions = $this->populate_version(); self::$versions = self::populate_version();
} }
/* /*
Go through the versions we have and see if Go through the versions we have and see if
we need to apply any updates we need to apply any updates
*/ */
foreach ($this->versions as $update) { foreach (self::$versions as $update) {
if ($update['version'] > $current_version) { if ($update['version'] > $current_version) {
return true; return true;
} }
@ -175,7 +175,7 @@ class Update {
@discussion just sets an array the current differences @discussion just sets an array the current differences
that require an update that require an update
*/ */
function populate_version() { public static function populate_version() {
/* Define the array */ /* Define the array */
$version = array(); $version = array();

View file

@ -54,16 +54,11 @@ class User {
$info = $this->_get_info(); $info = $this->_get_info();
if (!count($info)) { return false; } if (!count($info)) { return false; }
foreach ($info as $key=>$value) {
$this->$key = $value;
}
$this->uid = $info->id; $this->uid = $info->id;
$this->username = $info->username;
$this->fullname = $info->fullname;
$this->access = $info->access;
$this->disabled = $info->disabled;
$this->email = $info->email;
$this->last_seen = $info->last_seen;
$this->create_date = $info->create_date;
$this->validation = $info->validation;
$this->set_preferences(); $this->set_preferences();
// Make sure the Full name is always filled // Make sure the Full name is always filled
@ -77,16 +72,35 @@ class User {
*/ */
function _get_info() { function _get_info() {
$id = sql_escape($this->id); $id = Dba::escape($this->id);
$sql = "SELECT * FROM `user` WHERE `id`='" . $id . "'"; $sql = "SELECT * FROM `user` WHERE `id`='" . $id . "'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
return mysql_fetch_object($db_results); return Dba::fetch_assoc($db_results);
} // _get_info } // _get_info
/**
* get_from_username
* This returns a built user from a username. This is a
* static function so it doesn't require an instance
*/
public static function get_from_username($username) {
$username = Dba::escape($username);
$sql = "SELECT `id` FROM `user` WHERE `username`='$username'";
$db_results = Dba::query($sql);
$results = Dba::fetch_assoc($db_results);
$user = new User($results['id']);
return $user;
} // get_from_username
/** /**
* get_preferences * get_preferences
* This is a little more complicate now that we've got many types of preferences * This is a little more complicate now that we've got many types of preferences
@ -140,10 +154,11 @@ class User {
$sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='$this->id' " . $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='$this->id' " .
"AND user_preference.preference=preferences.id AND preferences.type != 'system'"; "AND user_preference.preference=preferences.id AND preferences.type != 'system'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
while ($r = mysql_fetch_object($db_results)) { while ($r = Dba::fetch_assoc($db_results)) {
$this->prefs[$r->name] = $r->value; $key = $r['name'];
$this->prefs[$key] = $r['value'];
} }
} // get_preferences } // get_preferences
@ -153,10 +168,9 @@ class User {
*/ */
function get_favorites($type) { function get_favorites($type) {
$web_path = conf('web_path'); $web_path = Config::get('web_path');
$stats = new Stats(); $results = Stats::get_user(Config::get('popular_threshold'),$type,$this->id,1);
$results = $stats->get_user(conf('popular_threshold'),$type,$this->uid,1);
$items = array(); $items = array();
@ -165,7 +179,7 @@ class User {
if ($type == 'song') { if ($type == 'song') {
$data = new Song($r['object_id']); $data = new Song($r['object_id']);
$data->count = $r['count']; $data->count = $r['count'];
$data->format_song(); $data->format();
$data->f_name = $data->f_link; $data->f_name = $data->f_link;
$items[] = $data; $items[] = $data;
} }
@ -173,23 +187,23 @@ class User {
elseif ($type == 'album') { elseif ($type == 'album') {
$data = new Album($r['object_id']); $data = new Album($r['object_id']);
$data->count = $r['count']; $data->count = $r['count'];
$data->format_album(); $data->format();
$items[] = $data; $items[] = $data;
} }
/* If its an artist */ /* If its an artist */
elseif ($type == 'artist') { elseif ($type == 'artist') {
$data = new Artist($r['object_id']); $data = new Artist($r['object_id']);
$data->count = $r['count']; $data->count = $r['count'];
$data->format_artist(); $data->format();
$data->f_name = $data->link; $data->f_name = $data->f_link;
$items[] = $data; $items[] = $data;
} }
/* If it's a genre */ /* If it's a genre */
elseif ($type == 'genre') { elseif ($type == 'genre') {
$data = new Genre($r['object_id']); $data = new Genre($r['object_id']);
$data->count = $r['count']; $data->count = $r['count'];
$data->format_genre(); $data->format();
$data->f_name = $data->link; $data->f_name = $data->f_link;
$items[] = $data; $items[] = $data;
} }
@ -208,24 +222,24 @@ class User {
/* First pull all of your ratings of this type */ /* First pull all of your ratings of this type */
$sql = "SELECT object_id,user_rating FROM ratings " . $sql = "SELECT object_id,user_rating FROM ratings " .
"WHERE object_type='" . sql_escape($type) . "' AND user='" . sql_escape($this->id) . "'"; "WHERE object_type='" . Dba::escape($type) . "' AND user='" . Dba::escape($this->id) . "'";
$db_results = mysql_query($sql,dbh()); $db_results = Dba::query($sql);
// Incase they only have one user // Incase they only have one user
$users = array(); $users = array();
while ($r = mysql_fetch_assoc($db_results)) { while ($r = Dba::fetch_assoc($db_results)) {
/* Store the fact that you rated this */ /* Store the fact that you rated this */
$key = $r['object_id']; $key = $r['object_id'];
$ratings[$key] = true; $ratings[$key] = true;
/* Build a key'd array of users with this same rating */ /* Build a key'd array of users with this same rating */
$sql = "SELECT user FROM ratings WHERE object_type='" . sql_escape($type) . "' " . $sql = "SELECT user FROM ratings WHERE object_type='" . Dba::escape($type) . "' " .
"AND user !='" . sql_escape($this->id) . "' AND object_id='" . sql_escape($r['object_id']) . "' " . "AND user !='" . Dba::escape($this->id) . "' AND object_id='" . Dba::escape($r['object_id']) . "' " .
"AND user_rating ='" . sql_escape($r['user_rating']) . "'"; "AND user_rating ='" . Dba::escape($r['user_rating']) . "'";
$user_results = mysql_query($sql,dbh()); $user_results = Dba::query($sql);
while ($user_info = mysql_fetch_assoc($user_results)) { while ($user_info = Dba::fetch_assoc($user_results)) {
$key = $user_info['user']; $key = $user_info['user'];
$users[$key]++; $users[$key]++;
} }
@ -243,11 +257,11 @@ class User {
/* Find everything they've rated at 4+ */ /* Find everything they've rated at 4+ */
$sql = "SELECT object_id,user_rating FROM ratings " . $sql = "SELECT object_id,user_rating FROM ratings " .
"WHERE user='" . sql_escape($user_id) . "' AND user_rating >='4' AND " . "WHERE user='" . Dba::escape($user_id) . "' AND user_rating >='4' AND " .
"object_type = '" . sql_escape($type) . "' ORDER BY user_rating DESC"; "object_type = '" . Dba::escape($type) . "' ORDER BY user_rating DESC";
$db_results = mysql_query($sql,dbh()); $db_results = Dba::query($sql);
while ($r = mysql_fetch_assoc($db_results)) { while ($r = Dba::fetch_assoc($db_results)) {
$key = $r['object_id']; $key = $r['object_id'];
if (isset($ratings[$key])) { continue; } if (isset($ratings[$key])) { continue; }
@ -290,7 +304,7 @@ class User {
*/ */
function has_access($needed_level) { function has_access($needed_level) {
if (!conf('use_auth') || conf('demo_mode')) { return true; } if (!Config::get('use_auth') || Config::get('demo_mode')) { return true; }
if ($this->access >= $needed_level) { return true; } if ($this->access >= $needed_level) { return true; }
@ -474,7 +488,7 @@ class User {
function update_last_seen() { function update_last_seen() {
$sql = "UPDATE user SET last_seen='" . time() . "' WHERE `id`='$this->id'"; $sql = "UPDATE user SET last_seen='" . time() . "' WHERE `id`='$this->id'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
} // update_last_seen } // update_last_seen
@ -664,7 +678,7 @@ class User {
} }
$item = "[$data->count] - $data->f_name"; $item = "[$data->count] - $data->f_name";
$results[]->link = $item; $results[]->f_link = $item;
} // end foreach items } // end foreach items
return $results; return $results;

View file

@ -21,52 +21,29 @@
*/ */
/* /**
@header Debug Library * Debug Library
This library is loaded when somehow our mojo has * This library is loaded when somehow our mojo has
been lost, it contains functions for checking sql * been lost, it contains functions for checking sql
connections, web paths etc.. * connections, web paths etc..
*/ */
/*!
@function read_config_file
@discussion checks to see if the config
file is readable, overkill I know..
@param level 0 is readable, 1 detailed info
*/
function read_config_file($file,$level=0) {
$fp = @fopen($file, 'r');
if (!$level) {
return is_resource($fp);
}
} // read_config_file
/*! /*!
@function check_database @function check_database
@discussion checks the local mysql db @discussion checks the local mysql db
and make sure life is good and make sure life is good
*/ */
function check_database($host,$username,$pass,$level=0) { function check_database($host,$username,$pass,$database) {
$dbh = @mysql_connect($host, $username, $pass); $dbh = @mysql_connect($host, $username, $pass);
if (!is_resource($dbh)) { if (!is_resource($dbh)) {
$error['error_state'] = true; return false;
$error['mysql_error'] = mysql_errno() . ": " . mysql_error() . "\n";
} }
if (!$host || !$username || !$pass) { if (!$host || !$username || !$pass) {
$error['error_state'] = true; return false;
$error['mysql_error'] .= "<br />HOST:$host<br />User:$username<br />Pass:$pass<br />";
} }
if ($error['error_state']) { return false; }
return $dbh; return $dbh;
} // check_database } // check_database
@ -101,13 +78,10 @@ function check_database_inserted($dbh,$db_name) {
*/ */
function check_php_ver($level=0) { function check_php_ver($level=0) {
if (strcmp('4.1.2',phpversion()) > 0) { if (strcmp('5.0.0',phpversion()) > 0) {
$error['error_state'] = true; return false;
$error['php_ver'] = phpversion();
} }
if ($error['error_state']) { return false; }
return true; return true;
} // check_php_ver } // check_php_ver
@ -119,12 +93,9 @@ function check_php_ver($level=0) {
function check_php_mysql() { function check_php_mysql() {
if (!function_exists('mysql_query')) { if (!function_exists('mysql_query')) {
$error['error_state'] = true; return false;
$error['php_mysql'] = false;
} }
if ($error['error_state']) { return false; }
return true; return true;
} // check_php_mysql } // check_php_mysql
@ -137,12 +108,9 @@ function check_php_mysql() {
function check_php_session() { function check_php_session() {
if (!function_exists('session_set_save_handler')) { if (!function_exists('session_set_save_handler')) {
$error['error_state'] = true; return false;
$error['php_session'] = false;
} }
if ($error['error_state']) { return false; }
return true; return true;
} // check_php_session } // check_php_session
@ -154,12 +122,9 @@ function check_php_session() {
function check_php_iconv() { function check_php_iconv() {
if (!function_exists('iconv')) { if (!function_exists('iconv')) {
$error['error_state'] = true; return false;
$error['php_iconv'] = false;
} }
if ($error['error_state']) { return false; }
return true; return true;
} // check_php_iconv } // check_php_iconv
@ -172,12 +137,9 @@ function check_php_iconv() {
function check_php_pcre() { function check_php_pcre() {
if (!function_exists('preg_match')) { if (!function_exists('preg_match')) {
$error['error_state'] = true; return false;
$error['php_pcre'] = false;
} }
if ($error['error_state']) { return false; }
return true; return true;
} // check_php_pcre } // check_php_pcre
@ -188,34 +150,33 @@ function check_php_pcre() {
least set the needed variables least set the needed variables
*/ */
function check_config_values($conf) { function check_config_values($conf) {
$error = new Error();
if (!$conf['local_host']) { if (!$conf['database_hostname']) {
return false; return false;
} }
if (!$conf['local_db']) { if (!$conf['database_name']) {
return false; return false;
} }
if (!$conf['local_username']) { if (!$conf['database_username']) {
return false; return false;
} }
if (!$conf['local_pass']) { if (!$conf['database_password']) {
return false; return false;
} }
if (!$conf['local_length']) { if (!$conf['session_length']) {
return false; return false;
} }
if (!$conf['sess_name']) { if (!$conf['session_name']) {
return false; return false;
} }
if (!isset($conf['sess_cookielife'])) { if (!isset($conf['session_cookielife'])) {
return false; return false;
} }
if (!isset($conf['sess_cookiesecure'])) { if (!isset($conf['session_cookiesecure'])) {
return false; return false;
} }
if (isset($conf['debug'])) { if (isset($conf['debug'])) {
if (!isset($conf['log_path'])) { if (!isset($conf['log_path'])) {
$error->add_error('log_path',_("You defined the option \"debug = on\" but didn't define a log path for the log to be stored"));
return false; return false;
} }
} }
@ -224,117 +185,6 @@ function check_config_values($conf) {
} // check_config_values } // check_config_values
/*!
@function debug_read_config
@discussion this is the same as the read config function
except it will pull config values with a # before them
(basicly adding a #config="value" check) and not
ever dieing on a config file error
*/
function debug_read_config($config_file,$debug) {
$fp = @fopen($config_file,'r');
if(!is_resource($fp)) return false;
$file_data = fread($fp,filesize($config_file));
fclose($fp);
// explode the var by \n's
$data = explode("\n",$file_data);
if($debug) echo "<pre>";
$count = 0;
if (!count($data)) {
debug_event('debug_read_config','Error Unable to Read config file','1');
return false;
}
$results = array();
foreach($data as $value) {
$count++;
$value = trim($value);
if (preg_match("/^#?([\w\d]+)\s+=\s+[\"]{1}(.*?)[\"]{1}$/",$value,$matches)
|| preg_match("/^#?([\w\d]+)\s+=\s+[\']{1}(.*?)[\']{1}$/", $value, $matches)
|| preg_match("/^#?([\w\d]+)\s+=\s+[\'\"]{0}(.*)[\'\"]{0}$/",$value,$matches)) {
if (is_array($results[$matches[1]]) && isset($matches[2]) ) {
if($debug) echo "Adding value <strong>$matches[2]</strong> to existing key <strong>$matches[1]</strong>\n";
array_push($results[$matches[1]], $matches[2]);
}
elseif (isset($results[$matches[1]]) && isset($matches[2]) ) {
if($debug) echo "Adding value <strong>$matches[2]</strong> to existing key $matches[1]</strong>\n";
$results[$matches[1]] = array($results[$matches[1]],$matches[2]);
}
elseif ($matches[2] !== "") {
if($debug) echo "Adding value <strong>$matches[2]</strong> for key <strong>$matches[1]</strong>\n";
$results[$matches[1]] = $matches[2];
}
// if there is something there and it's not a comment
elseif ($value{0} !== "#" AND strlen(trim($value)) > 0 AND !$test AND strlen($matches[2]) > 0) {
echo "Error Invalid Config Entry --> Line:$count"; return false;
} // elseif it's not a comment and there is something there
else {
if($debug) echo "Key <strong>$matches[1]</strong> defined, but no value set\n";
}
} // end else
} // foreach
if (isset($config_name) && isset(${$config_name}) && count(${$config_name})) {
$results[$config_name] = ${$config_name};
}
if($debug) echo "</pre>";
return $results;
} // debug_read_config
/*!
@function debug_compare_configs
@discussion this takes two config files, and then compares
the results and returns an array of the values
that are missing from the first one passed
*/
function debug_compare_configs($config,$dist_config) {
/* Get the results from the two difference configs including #'d values */
$results = debug_read_config($config,0);
$dist_results = debug_read_config($dist_config,0);
$missing = array();
foreach ($dist_results as $key=>$value) {
if (!isset($results[$key])) {
/* If it's an array we need to split it out */
if (is_array($value)) {
foreach ($value as $element) {
$missing[$key][] = $element;
}
}
else {
$missing[$key] = $value;
} // end else not array
} // if it's not set
} // end foreach conf
return $missing;
} // debug_compare_configs
/** /**
* check_putenv * check_putenv
* This checks to see if we can manually set the * This checks to see if we can manually set the

View file

@ -1,342 +0,0 @@
<?php
/*
Copyright (c) 2001 - 2006 Ampache.org
All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
//
//
function add_to_edit_queue($flags=0)
{
$oldflags = 0;
if(empty($flags)) $flags = 0;
if($_SESSION['edit_queue'])
{
$oldflags = $_SESSION['edit_queue'];
if(!is_array($oldflags)) $oldflags = array($oldflags);
}
if(!is_array($flags))
{
if($flags !== 0) $flags = array($flags);
}
if(is_array($flags))
{
if(is_array($oldflags)) $new_array = array_merge($flags, $oldflags);
else $new_array = $flags;
}
elseif (is_array($oldflags)) $new_array = $oldflags;
if(count($new_array))
{
$_SESSION['edit_queue'] = $new_array;
return count($new_array);
}
else
{
unset($_SESSION['edit_queue']);
return 0;
}
}
function show_edit_flagged($flag=0)
{
if(empty($flag)||$flag === 0)
{
$flag = array_pop($_SESSION['edit_queue']);
}
$flaginfo = get_flag($flag);
if($flaginfo['type'] === 'badid3')
{
show_edit_badid3($flaginfo['song'],$flag);
}
else
{
echo "I don't know how to edit already edited songs yet: $flag.<br />";
}
}
function show_edit_badid3($songid,$flagid)
{
$song = get_song_info($songid);
require(conf('prefix')."/templates/song_edit.inc");
}
function get_flag($id)
{
if(!is_array($id)) $id = array($id);
$results = array();
$newid = array_pop($id);
$sql = "SELECT flagged.id,user.username,type,song,date,comment" .
" FROM flagged,user WHERE flagged.user = user.username AND (flagged.song = '$newid'";
foreach($id as $num)
{
$sql .= " OR flagged.song = '$num'";
}
$sql .= ")";
$result = mysql_query($sql, dbh());
while ($row = mysql_fetch_array($result))
{
$results[] = $row;
}
if(count($results) == 1) return $results[0];
else return $results;
}
function get_flagged_songs($user = 0)
{
$sql = "SELECT flagged.id,user.username,type,song,date,comment" .
" FROM flagged,user WHERE flagged.user = user.username AND flagged.type <> 'notify' AND flagged.type <> 'done'";
// If the user is not an admin, they can only see songs they've flagged
if($user)
{
if($_SESSION['userdata']['access'] === 'admin')
{
$sql .= " AND user.username = '$user'";
}
else
{
$sql .= " AND user.username = '".$_SESSION['userdata']['username']."'";
}
}
$sql .= " ORDER BY date";
$result = mysql_query($sql, dbh());
$arr = array();
while ($flag = mysql_fetch_array($result))
{
$arr[] = $flag;
}
return $arr;
}
function accept_new_tags($flags)
{
if(!is_array($flags)) $flags = array($flags);
foreach($flags as $flag)
{
copy_updated_tag($flag);
}
set_flag_value($flags, 'setid3');
}
function reject_new_tags($flags)
{
if(!is_array($flags)) $flags = array($flags);
$oldflags = $flags;
$flag = array_pop($flags);
$sql = "DELETE FROM flagged_songs WHERE song = '$flag'";
foreach($flags as $flag)
{
$sql .= " OR song = '$flag'";
}
$result = mysql_query($sql, dbh());
$user = $_SESSION['userdata']['username'];
set_flag_value($oldflags, 'notify', "Tag changes rejected by $user");
}
function set_flag_value($flags, $val, $comment = '')
{
if(!is_array($flags)) $flags = array($flags);
$user = $_SESSION['userdata']['id'];
/* $flagid = array_pop($flags);*/
$dbh = dbh();
foreach($flags as $flagid)
{
$sql = "REPLACE INTO flagged (type,song,comment,user,date)".
" VALUES ('$val','$flagid','$comment','$user','".time()."')";
$result = mysql_query($sql, $dbh);
}
return $result;
}
function copy_updated_tag($flag)
{
$flagdata = get_flag($flag);
$sql = "SELECT * FROM flagged_song WHERE song = '".$flagdata['song']."'";
$result = mysql_query($sql, dbh());
$newtag = mysql_fetch_array($result);
if($newtag['new_artist'])
{
$newtag['artist'] = insert_artist($newtag['new_artist']);
}
if($newtag['new_album'])
{
$newtag['album'] = insert_album($newtag['new_album']);
}
$sql = "UPDATE song SET ".
"title = '".$newtag['title']."',".
"artist = '".$newtag['artist']."',".
"album = '".$newtag['album']."',".
"track = '".$newtag['track']."',".
"genre = '".$newtag['genre']."',".
"year = '".$newtag['year']."' ".
"WHERE song.id = '".$newtag['song']."'";
$result = mysql_query($sql, dbh());
if($result)
{
$sql2 = "DELETE FROM flagged_song WHERE song='".$flagdata['song']."'";
$result2 = mysql_query($sql2, dbh());
}
return ($result && $result2);
}
function update_flags($songs)
{
$accepted = array();
$rejected = array();
$newflags = array();
foreach($songs as $song)
{
$accept = scrub_in($_REQUEST[$song.'_accept']);
if($accept === 'accept') $accepted[] = $song;
elseif ($accept === 'reject') $rejected[] = $song;
else
{
$newflag = scrub_in($_REQUEST[$song.'_newflag']);
$newflags[$song] = $newflag;
}
}
if(count($accepted))
{
accept_new_tags($accepted);
}
if(count($rejected))
{
reject_new_tags($rejected);
}
if(count($newflags))
{
foreach($newflags as $flag=>$type)
{
set_flag_value($flag, $type);
}
}
}
function update_song_info($song)
{
$user = $_SESSION['userdata'];
$title = scrub_in($_REQUEST['title']);
$track = scrub_in($_REQUEST['track']);
$genre = scrub_in($_REQUEST['genre']);
$year = scrub_in($_REQUEST['year']);
if(isset($_REQUEST['update_id3']))
$update_id3 = 1;
if(isset($_REQUEST['new_artist']) && $_REQUEST['new_artist'] !== '')
{
$create_artist = 1;
$artist = scrub_in($_REQUEST['new_artist']);
}
else
$artist = scrub_in($_REQUEST['artist']);
if(isset($_REQUEST['new_album']) && $_REQUEST['new_album'] !== '')
{
$create_album = 1;
$album = scrub_in($_REQUEST['new_album']);
}
else
$album = scrub_in($_REQUEST['album']);
if(is_array($_REQUEST['genre'])) {
$genre = $genre[0];
}
if($user['access'] == 'admin')
// Update the file directly
{
if($create_artist)
{
$artist = insert_artist($artist);
}
if($create_album)
{
$album = insert_album($album);
}
// Escape data (prevent " or ' snafu's)
$title = sql_escape($title);
$artist = sql_escape($artist);
$album = sql_escape($album);
$genre = sql_escape($genre);
$year = sql_escape($year);
$sql = "UPDATE song SET" .
" title = '$title'," .
" track = '$track'," .
" genre = '$genre'," .
" year = '$year'," .
" artist = '$artist',".
" album = '$album'," .
" update_time = '".time()."'" .
" WHERE id = '$song' LIMIT 1";
$result = mysql_query($sql, dbh() );
if($result && $update_id3 )
{
//Add to flagged table so we can fix the id3 tags
$date = time();
$sql = "REPLACE INTO flagged SET " .
" type = 'setid3', song = '$song', date = '$date', user = '".$user['id']."'";
$result = mysql_query($sql, dbh());
}
}
else
// Stick in the flagged_songs table to be updated by an admin
{
if($create_artist) $artist_field = 'new_artist';
else $artist_field = 'artist';
if($create_album) $album_field = 'new_album';
else $album_field = 'album';
$sql = "INSERT INTO flagged_song(song,title,track,genre,year,$artist_field,$album_field,update_time) " .
"VALUES ('$song','$title','$track','$genre','$year','$artist','$album','".time()."')";
$result = mysql_query($sql, dbh() );
if($result && $update_id3 )
{
//Add to flagged table so we can fix the id3 tags
$date = time();
$sql = "REPLACE INTO flagged SET " .
" type = 'newid3', song = '$song', date = '$date', user = '".$user['id']."'";
$result = mysql_query($sql, dbh());
}
echo "Thanks for helping to keep the catalog up to date. Someone will review your changes, and you will be notified on the main page when they're approved.";
}
}

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
Copyright (c) 2001 - 2006 Ampache.org Copyright (c) 2001 - 2007 Ampache.org
All rights reserved. All rights reserved.
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
@ -27,29 +27,6 @@
that doesn't have a home elsewhere that doesn't have a home elsewhere
*/ */
/*!
@function sql_escape
@discussion this takes a sql statement
and properly escapes it before a query is run
against it.
*/
function sql_escape($sql,$dbh=0) {
if (!is_resource($dbh)) {
$dbh = dbh();
}
if (function_exists('mysql_real_escape_string')) {
$sql = mysql_real_escape_string($sql,$dbh);
}
else {
$sql = mysql_escape_string($sql);
}
return $sql;
} // sql_escape
/*! /*!
@function ip2int @function ip2int
@discussion turns a dotted quad ip into an @discussion turns a dotted quad ip into an
@ -74,89 +51,6 @@ function int2ip($i) {
return "$d[0].$d[1].$d[2].$d[3]"; return "$d[0].$d[1].$d[2].$d[3]";
} // int2ip } // int2ip
/*!
@function show_template
@discussion show a template from the /templates directory, automaticly appends .inc
to the passed filename
@param $template Name of Template
*/
function show_template($template) {
global $user;
/* Check for a 'Theme' template */
if (is_readable(conf('prefix') . conf('theme_path') . "/templates/$template".".inc")) {
require (conf('prefix') . conf('theme_path') . "/templates/$template".".inc");
}
else {
require (conf('prefix') . "/templates/$template".".inc");
}
} // show_template
/*!
@function read_config
@discussion reads the config file for ampache
*/
function read_config($config_file, $debug=0, $test=0) {
$fp = @fopen($config_file,'r');
if(!is_resource($fp)) return false;
$file_data = fread($fp,filesize($config_file));
fclose($fp);
// explode the var by \n's
$data = explode("\n",$file_data);
if($debug) echo "<pre>";
$count = 0;
foreach($data as $value) {
$count++;
$value = trim($value);
if (substr($value,0,1) == '#') { continue; }
if (preg_match("/^([\w\d]+)\s+=\s+[\"]{1}(.*?)[\"]{1}$/",$value,$matches)
|| preg_match("/^([\w\d]+)\s+=\s+[\']{1}(.*?)[\']{1}$/", $value, $matches)
|| preg_match("/^([\w\d]+)\s+=\s+[\'\"]{0}(.*)[\'\"]{0}$/",$value,$matches)) {
if (is_array($results[$matches[1]]) && isset($matches[2]) ) {
if($debug) echo "Adding value <strong>$matches[2]</strong> to existing key <strong>$matches[1]</strong>\n";
array_push($results[$matches[1]], $matches[2]);
}
elseif (isset($results[$matches[1]]) && isset($matches[2]) ) {
if($debug) echo "Adding value <strong>$matches[2]</strong> to existing key $matches[1]</strong>\n";
$results[$matches[1]] = array($results[$matches[1]],$matches[2]);
}
elseif ($matches[2] !== "") {
if($debug) echo "Adding value <strong>$matches[2]</strong> for key <strong>$matches[1]</strong>\n";
$results[$matches[1]] = $matches[2];
}
// if there is something there and it's not a comment
elseif ($value{0} !== "#" AND strlen(trim($value)) > 0 AND !$test AND strlen($matches[2]) > 0) {
echo "Error Invalid Config Entry --> Line:$count"; return false;
} // elseif it's not a comment and there is something there
else {
if($debug) echo "Key <strong>$matches[1]</strong> defined, but no value set\n";
}
} // end else
} // foreach
if ($debug) { echo "</pre>\n"; }
return $results;
} // read_config
/* /*
* Conf function by Robert Hopson * Conf function by Robert Hopson
* call it with a $parm name to retrieve * call it with a $parm name to retrieve
@ -164,7 +58,7 @@ function read_config($config_file, $debug=0, $test=0) {
* to reset a var pass the array plus * to reset a var pass the array plus
* Clobber! replaces global $conf; * Clobber! replaces global $conf;
*/ */
function conf($param,$clobber=0) /*function conf($param,$clobber=0)
{ {
static $params = array(); static $params = array();
@ -215,37 +109,7 @@ function error_results($param,$clobber=0)
else return; else return;
} }
} //error_results } //error_results
/**
* dbh
* Alias for the vauth_dbh function
*/
function dbh() {
return vauth_dbh();
} // dbh
/*!
@function fix_preferences
@discussion cleans up the preferences
*/ */
function fix_preferences($results) {
foreach ($results as $key=>$data) {
if (strcasecmp($data, "yes") == "0") { $data = 1; }
if (strcasecmp($data,"true") == "0") { $data = 1; }
if (strcasecmp($data,"enabled") == "0") { $data = 1; }
if (strcasecmp($data,"disabled") == "0") { $data = 0; }
if (strcasecmp($data,"false") == "0") { $data = 0; }
if (strcasecmp($data,"no") == "0") { $data = 0; }
$results[$key] = $data;
}
return $results;
} // fix_preferences
/** /**
* session_exists * session_exists
@ -259,10 +123,10 @@ function session_exists($sid,$xml_rpc=0) {
$found = true; $found = true;
$sql = "SELECT * FROM session WHERE id = '$sid'"; $sql = "SELECT * FROM `session` WHERE `id` = '$sid'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
if (!mysql_num_rows($db_results)) { if (!Dba::num_rows($db_results)) {
$found = false; $found = false;
} }
@ -306,12 +170,12 @@ function session_exists($sid,$xml_rpc=0) {
*/ */
function extend_session($sid) { function extend_session($sid) {
$new_time = time() + conf('local_length'); $new_time = time() + Config::get('local_length');
if ($_COOKIE['amp_longsess'] == '1') { $new_time = time() + 86400*364; } if ($_COOKIE['amp_longsess'] == '1') { $new_time = time() + 86400*364; }
$sql = "UPDATE session SET expire='$new_time' WHERE id='$sid'"; $sql = "UPDATE `session` SET `expire`='$new_time' WHERE `id`='$sid'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
} // extend_session } // extend_session
@ -601,8 +465,8 @@ function cleanup_and_exit($playing_id) {
function get_global_popular($type) { function get_global_popular($type) {
$stats = new Stats(); $stats = new Stats();
$count = conf('popular_threshold'); $count = Config::get('popular_threshold');
$web_path = conf('web_path'); $web_path = Config::get('web_path');
/* Pull the top */ /* Pull the top */
$results = $stats->get_top($count,$type); $results = $stats->get_top($count,$type);
@ -652,43 +516,6 @@ function get_global_popular($type) {
} // get_global_popular } // get_global_popular
/**
* gen_newest
* Get a list of newest $type (which can then be handed to show_info_box
* @package Web Interface
* @catagory Get
* @todo Add Genre
*/
function get_newest ($type = 'artist',$limit='') {
$dbh = dbh();
if (!$limit) { $limit = conf('popular_threshold'); }
$sql = "SELECT DISTINCT $type FROM song ORDER BY addition_time " .
"DESC LIMIT " . conf('popular_threshold');
$db_result = mysql_query($sql, $dbh);
$items = array();
while ($r = mysql_fetch_array($db_result)) {
if ( $type == 'artist' ) {
$artist = new Artist($r[0]);
$artist->format_artist();
$items[] = $artist;
}
elseif ( $type == 'album' ) {
$album = new Album($r[0]);
$album->format();
$album->link = $album->f_link;
$items[] = $album;
}
}
return $items;
} // get_newest
/** /**
* show_info_box * show_info_box
* This shows the basic box that popular and newest stuff goes into * This shows the basic box that popular and newest stuff goes into
@ -698,9 +525,9 @@ function get_newest ($type = 'artist',$limit='') {
*/ */
function show_info_box ($title, $type, $items) { function show_info_box ($title, $type, $items) {
$web_path = conf('web_path'); $web_path = Config::get('web_path');
$popular_threshold = conf('popular_threshold'); $popular_threshold = Config::get('popular_threshold');
require (conf('prefix') . '/templates/show_box.inc.php'); require Config::get('prefix') . '/templates/show_box.inc.php';
} // show_info_box } // show_info_box
@ -784,7 +611,7 @@ function scrub_out($str) {
$str = stripslashes($str); $str = stripslashes($str);
} }
$str = htmlentities($str,ENT_QUOTES,conf('site_charset')); $str = htmlentities($str,ENT_QUOTES,Config::get('site_charset'));
return $str; return $str;
@ -890,7 +717,7 @@ function logout() {
vauth_logout(session_id()); vauth_logout(session_id());
/* Redirect them to the login page */ /* Redirect them to the login page */
header ('Location: ' . conf('web_path') . '/login.php'); header ('Location: ' . Config::get('web_path') . '/login.php');
return true; return true;
@ -976,10 +803,12 @@ function invert_boolean($value) {
*/ */
function get_user_from_username($username) { function get_user_from_username($username) {
$sql = "SELECT `id` FROM `user` WHERE `username`='" . sql_escape($username) . "'"; $username = Dba::escape($username);
$db_results = mysql_query($sql, dbh());
$results = mysql_fetch_assoc($db_results); $sql = "SELECT `id` FROM `user` WHERE `username`='$username'";
$db_results = Dba::query($sql);
$results = Dba::fetch_assoc($db_results);
$user = new User($results['id']); $user = new User($results['id']);
@ -1037,5 +866,30 @@ function unhtmlentities ($string) {
} // unhtmlentities } // unhtmlentities
/**
* __autoload
* This function automatically loads any missing
* classes as they are called so that we don't have to have
* a million include statements, and load more then we need
*/
function __autoload($class) {
// Lowercase the class
$class = strtolower($class);
$file = Config::get('prefix') . "/lib/class/$class.class.php";
// See if it exists
if (is_readable($file)) {
require_once $file;
if (is_callable($class . '::_auto_init')) {
call_user_func(array($class, '_auto_init'));
}
}
// Else log this as a fatal error
else {
debug_event('__autoload', "'$class' not found!",'1');
}
} // __autoload
?> ?>

View file

@ -27,22 +27,22 @@
function load_gettext() { function load_gettext() {
/* If we have gettext */ /* If we have gettext */
if (function_exists('bindtextdomain')) { if (function_exists('bindtextdomain')) {
$lang = conf('lang'); $lang = Config::get('lang');
putenv("LANG=" . $lang); putenv("LANG=" . $lang);
putenv("LANGUAGE=" . $lang); putenv("LANGUAGE=" . $lang);
/* Try lang, lang + charset and lang + utf-8 */ /* Try lang, lang + charset and lang + utf-8 */
setlocale(LC_ALL, setlocale(LC_ALL,
$lang, $lang,
$lang . '.'. conf('site_charset'), $lang . '.'. Config::get('site_charset'),
$lang . '.UTF-8', $lang . '.UTF-8',
$lang . '.utf-8', $lang . '.utf-8',
$lang . '.' . conf('lc_charset')); $lang . '.' . Config::get('lc_charset'));
/* Bind the Text Domain */ /* Bind the Text Domain */
bindtextdomain('messages', conf('prefix') . "/locale/"); bindtextdomain('messages', Config::get('prefix') . "/locale/");
textdomain('messages'); textdomain('messages');
if (function_exists('bind_textdomain_codeset')) { if (function_exists('bind_textdomain_codeset')) {
bind_textdomain_codeset('messages',conf('site_charset')); bind_textdomain_codeset('messages',Config::get('site_charset'));
} // if we can codeset the textdomain } // if we can codeset the textdomain
} // If bindtext domain exists } // If bindtext domain exists

View file

@ -31,7 +31,8 @@ error_reporting(E_ALL ^ E_NOTICE);
$ampache_path = dirname(__FILE__); $ampache_path = dirname(__FILE__);
$prefix = realpath($ampache_path . "/../"); $prefix = realpath($ampache_path . "/../");
$configfile = "$prefix/config/ampache.cfg.php"; $configfile = "$prefix/config/ampache.cfg.php";
require_once($prefix . "/lib/general.lib.php"); require_once $prefix . '/lib/general.lib.php';
require_once $prefix . '/lib/class/config.class.php';
/* /*
Check to see if this is Http or https Check to see if this is Http or https
@ -55,11 +56,10 @@ if (!file_exists($configfile)) {
exit(); exit();
} }
/* // Use the built in PHP function, supress errors here so we can handle it properly
Try to read the config file, if it fails give them $results = @parse_ini_file($configfile);
an explanation
*/ if (!count($results)) {
if (!$results = read_config($configfile,0)) {
$path = preg_replace("/(.*)\/(\w+\.php)$/","\${1}", $_SERVER['PHP_SELF']); $path = preg_replace("/(.*)\/(\w+\.php)$/","\${1}", $_SERVER['PHP_SELF']);
$link = $http_type . $_SERVER['HTTP_HOST'] . $path . "/test.php"; $link = $http_type . $_SERVER['HTTP_HOST'] . $path . "/test.php";
header ("Location: $link"); header ("Location: $link");
@ -67,7 +67,7 @@ if (!$results = read_config($configfile,0)) {
} }
/** This is the version.... fluf nothing more... **/ /** This is the version.... fluf nothing more... **/
$results['version'] = '3.4-Alpha1 (Build 001)'; $results['version'] = '3.4-Alpha1 (Build 002)';
$results['int_config_version'] = '2'; $results['int_config_version'] = '2';
$results['raw_web_path'] = $results['web_path']; $results['raw_web_path'] = $results['web_path'];
@ -87,96 +87,67 @@ if (!$results['raw_web_path']) {
if (!$_SERVER['SERVER_NAME']) { if (!$_SERVER['SERVER_NAME']) {
$_SERVER['SERVER_NAME'] = ''; $_SERVER['SERVER_NAME'] = '';
} }
if (!isset($results['auth_methods'])) {
$results['auth_methods'] = array('mysql');
}
if (!is_array($results['auth_methods'])) {
$results['auth_methods'] = array($results['auth_methods']);
}
if (!$results['user_ip_cardinality']) { if (!$results['user_ip_cardinality']) {
$results['user_ip_cardinality'] = 42; $results['user_ip_cardinality'] = 42;
} }
if (!$results['local_length']) { if (!$results['local_length']) {
$results['local_length'] = '9000'; $results['local_length'] = '900';
} }
/* Variables needed for vauth Module */ /* Variables needed for vauth Module */
$results['cookie_path'] = $results['raw_web_path']; $results['cookie_path'] = $results['raw_web_path'];
$results['cookie_domain'] = $_SERVER['SERVER_NAME']; $results['cookie_domain'] = $_SERVER['SERVER_NAME'];
$results['cookie_life'] = $results['sess_cookielife']; $results['cookie_life'] = $results['session_cookielife'];
$results['session_name'] = $results['sess_name']; $results['cookie_secure'] = $results['session_cookiesecure'];
$results['cookie_secure'] = $results['sess_cookiesecure']; $results['mysql_password'] = $results['database_password'];
$results['session_length'] = $results['local_length']; $results['mysql_username'] = $results['database_username'];
$results['mysql_password'] = $results['local_pass']; $results['mysql_hostname'] = $results['database_hostname'];
$results['mysql_username'] = $results['local_username']; $results['mysql_db'] = $results['database_name'];
$results['mysql_hostname'] = $results['local_host'];
$results['mysql_db'] = $results['local_db']; // Define that we've loaded the INIT file
define('INIT_LOADED','1');
// Vauth Requires
require_once $prefix . '/modules/vauth/init.php';
// Library and module includes we can't do with the autoloader
require_once $prefix . '/lib/album.lib.php';
require_once $prefix . '/lib/artist.lib.php';
require_once $prefix . '/lib/song.php';
require_once $prefix . '/lib/search.php';
require_once $prefix . '/lib/preferences.php';
require_once $prefix . '/lib/rss.php';
require_once $prefix . '/lib/log.lib.php';
require_once $prefix . '/lib/localplay.lib.php';
require_once $prefix . '/lib/ui.lib.php';
require_once $prefix . '/lib/gettext.php';
require_once $prefix . '/lib/batch.lib.php';
require_once $prefix . '/lib/themes.php';
require_once $prefix . '/lib/stream.lib.php';
require_once $prefix . '/lib/playlist.lib.php';
require_once $prefix . '/lib/democratic.lib.php';
require_once $prefix . '/lib/xmlrpc.php';
require_once $prefix . '/modules/xmlrpc/xmlrpc.inc';
require_once $prefix . '/modules/catalog.php';
require_once $prefix . '/modules/getid3/getid3.php';
require_once $prefix . '/modules/infotools/Snoopy.class.php';
require_once $prefix . '/modules/infotools/AmazonSearchEngine.class.php';
//require_once $prefix . '/modules/infotools/jamendoSearch.class.php';
/* Temp Fixes */ /* Temp Fixes */
$results = fix_preferences($results); $results = fix_preferences($results);
// Setup Static Arrays // Setup Static Arrays
conf($results); Config::set_by_array($results,1);
// Vauth Requires
require_once(conf('prefix') . '/modules/vauth/init.php');
// Librarys
require_once(conf('prefix') . '/lib/album.lib.php');
require_once(conf('prefix') . '/lib/artist.lib.php');
require_once(conf('prefix') . '/lib/song.php');
require_once(conf('prefix') . '/lib/search.php');
require_once(conf('prefix') . '/lib/preferences.php');
require_once(conf('prefix') . '/lib/rss.php');
require_once(conf('prefix') . '/lib/log.lib.php');
require_once(conf('prefix') . '/lib/localplay.lib.php');
require_once(conf('prefix') . '/lib/ui.lib.php');
require_once(conf('prefix') . '/lib/gettext.php');
require_once(conf('prefix') . '/lib/batch.lib.php');
require_once(conf('prefix') . '/lib/themes.php');
require_once(conf('prefix') . '/lib/stream.lib.php');
require_once(conf('prefix') . '/lib/playlist.lib.php');
require_once(conf('prefix') . '/lib/democratic.lib.php');
require_once(conf('prefix') . '/modules/catalog.php');
require_once(conf('prefix') . "/modules/id3/getid3/getid3.php");
require_once(conf('prefix') . '/modules/id3/vainfo.class.php');
require_once(conf('prefix') . '/modules/infotools/Snoopy.class.php');
require_once(conf('prefix') . '/modules/infotools/AmazonSearchEngine.class.php');
//require_once(conf('prefix') . '/modules/infotools/jamendoSearch.class.php');
require_once(conf('prefix') . '/lib/xmlrpc.php');
require_once(conf('prefix') . '/modules/xmlrpc/xmlrpc.inc');
// Modules (These are conditionaly included depending upon config values) // Modules (These are conditionaly included depending upon config values)
if (conf('ratings')) { if (Config::get('ratings')) {
require_once(conf('prefix') . '/lib/class/rating.class.php'); require_once $prefix . '/lib/class/rating.class.php';
require_once(conf('prefix') . '/lib/rating.lib.php'); require_once $prefix . '/lib/rating.lib.php';
} }
// Classes
require_once(conf('prefix') . '/lib/class/localplay.class.php');
require_once(conf('prefix') . '/lib/class/plugin.class.php');
require_once(conf('prefix') . '/lib/class/stats.class.php');
require_once(conf('prefix') . '/lib/class/catalog.class.php');
require_once(conf('prefix') . '/lib/class/stream.class.php');
require_once(conf('prefix') . '/lib/class/playlist.class.php');
require_once(conf('prefix') . '/lib/class/tmp_playlist.class.php');
require_once(conf('prefix') . '/lib/class/song.class.php');
require_once(conf('prefix') . '/lib/class/view.class.php');
require_once(conf('prefix') . '/lib/class/update.class.php');
require_once(conf('prefix') . '/lib/class/user.class.php');
require_once(conf('prefix') . '/lib/class/album.class.php');
require_once(conf('prefix') . '/lib/class/artist.class.php');
require_once(conf('prefix') . '/lib/class/access.class.php');
require_once(conf('prefix') . '/lib/class/error.class.php');
require_once(conf('prefix') . '/lib/class/genre.class.php');
require_once(conf('prefix') . '/lib/class/flag.class.php');
require_once(conf('prefix') . '/lib/class/audioscrobbler.class.php');
/* Set a new Error Handler */ /* Set a new Error Handler */
$old_error_handler = set_error_handler("ampache_error_handler"); $old_error_handler = set_error_handler('ampache_error_handler');
/* Initilize the Vauth Library */ /* Initilize the Vauth Library */
vauth_init($results); vauth_init($results);
@ -192,35 +163,8 @@ if ($results['memory_limit'] < 24) {
} }
set_memory_limit($results['memory_limit']); set_memory_limit($results['memory_limit']);
// Check Session GC mojo, increase if need be
$gc_probability = @ini_get('session.gc_probability');
$gc_divisor = @ini_get('session.gc_divisor');
if (!$gc_divisor) {
$gc_divisor = '100';
}
if (!$gc_probability) {
$gc_probability = '1';
}
// Force GC on 1:5 page loads
if (($gc_divisor / $gc_probability) > 5) {
$new_gc_probability = $gc_divisor * .2;
ini_set('session.gc_probability',$new_gc_probability);
}
/* Seed the random number */
srand((double) microtime() * 1000003);
/**** END Set PHP Vars ****/ /**** END Set PHP Vars ****/
/* Check to see if they've tried to set no_session via get/post */
if (isset($_POST['no_session']) || isset($_GET['no_session'])) {
/* just incase of register globals */
unset($no_session);
debug_event('no_session','No Session passed as get/post','1');
}
/* We have to check for HTTP Auth */ /* We have to check for HTTP Auth */
if (in_array("http",$results['auth_methods'])) { if (in_array("http",$results['auth_methods'])) {
@ -237,24 +181,22 @@ if (in_array("http",$results['auth_methods'])) {
} // end if http auth } // end if http auth
// If we don't want a session // If we want a session
if (NO_SESSION != '1' AND conf('use_auth')) { if (NO_SESSION != '1' AND Config::get('use_auth')) {
/* Verify Their session */ /* Verify Their session */
if (!vauth_check_session()) { logout(); exit; } if (!vauth_check_session()) { logout(); exit; }
/* Create the new user */ /* Create the new user */
$user = get_user_from_username($_SESSION['userdata']['username']); $GLOBALS['user'] = User::get_from_username($_SESSION['userdata']['username']);
/* If they user ID doesn't exist deny them */ /* If they user ID doesn't exist deny them */
if (!$user->uid AND !conf('demo_mode')) { logout(); exit; } if (!$GLOBALS['user']->id AND !Config::get('demo_mode')) { logout(); exit; }
/* Load preferences and theme */ /* Load preferences and theme */
init_preferences();
set_theme(); set_theme();
$user->set_preferences(); $GLOBALS['user']->update_last_seen();
$user->update_last_seen();
} }
elseif (!conf('use_auth')) { elseif (!Config::get('use_auth')) {
$auth['success'] = 1; $auth['success'] = 1;
$auth['username'] = '-1'; $auth['username'] = '-1';
$auth['fullname'] = "Ampache User"; $auth['fullname'] = "Ampache User";
@ -262,37 +204,38 @@ elseif (!conf('use_auth')) {
$auth['access'] = "admin"; $auth['access'] = "admin";
$auth['offset_limit'] = 50; $auth['offset_limit'] = 50;
if (!vauth_check_session()) { vauth_session_create($auth); } if (!vauth_check_session()) { vauth_session_create($auth); }
$user = new User(-1); $GLOBALS['user'] = new User(-1);
$user->fullname = 'Ampache User'; $GLOBALS['user']->fullname = 'Ampache User';
$user->offset_limit = $auth['offset_limit']; $GLOBALS['user']->offset_limit = $auth['offset_limit'];
$user->username = '-1'; $GLOBALS['user']->username = '-1';
$user->access = $auth['access']; $GLOBALS['user']->access = $auth['access'];
$_SESSION['userdata']['username'] = $auth['username']; $_SESSION['userdata']['username'] = $auth['username'];
$user->set_preferences();
init_preferences();
set_theme(); set_theme();
} }
// If Auth, but no session is set
else { else {
if (isset($_REQUEST['sessid'])) { if (isset($_REQUEST['sessid'])) {
$sess_results = vauth_get_session($_REQUEST['sessid']); $sess_results = vauth_get_session($_REQUEST['sessid']);
session_id(scrub_in($_REQUEST['sessid'])); session_id(scrub_in($_REQUEST['sessid']));
session_start(); session_start();
} }
$user = get_user_from_username($sess_results['username']); $GLOBALS['user'] = User::get_from_username($sess_results['username']);
init_preferences();
} }
// Load the Preferences from the database
init_preferences();
/* Add in some variables for ajax done here because we need the user */ /* Add in some variables for ajax done here because we need the user */
$ajax_info['ajax_url'] = $results['web_path'] . '/server/ajax.server.php'; $ajax_info['ajax_url'] = $results['web_path'] . '/server/ajax.server.php';
$ajax_info['ajax_info'] = '&amp;user_id=' . $user->id . '&amp;sessid=' . session_id(); $ajax_info['ajax_info'] = '&amp;user_id=' . $GLOBALS['user']->id;
conf($ajax_info); Config::set_by_array($ajax_info);
unset($ajax_info); unset($ajax_info);
// Load gettext mojo // Load gettext mojo
load_gettext(); load_gettext();
/* Set CHARSET */ /* Set CHARSET */
header ("Content-Type: text/html; charset=" . conf('site_charset')); header ("Content-Type: text/html; charset=" . Config::get('site_charset'));
/* Clean up a bit */ /* Clean up a bit */
unset($array); unset($array);
@ -301,19 +244,14 @@ unset($results);
/* Setup the flip class */ /* Setup the flip class */
flip_class(array('odd','even')); flip_class(array('odd','even'));
/* Setup the Error Class */
$error = new Error();
/* Set the Theme */ /* Set the Theme */
$theme = get_theme(conf('theme_name')); $theme = get_theme(Config::get('theme_name'));
/* Check to see if we need to perform an update */
if (! preg_match('/update\.php/', $_SERVER['PHP_SELF'])) { if (! preg_match('/update\.php/', $_SERVER['PHP_SELF'])) {
$update = new Update(); if (Update::need_update()) {
if ($update->need_update()) { header("Location: " . Config::get('web_path') . "/update.php");
header("Location: " . conf('web_path') . "/update.php");
exit(); exit();
} }
} }
unset($update);
?> ?>

View file

@ -33,7 +33,7 @@ function log_event($username='Unknown',$event_name,$event_description,$log_name=
/* must have some name */ /* must have some name */
if (!strlen($log_name)) { $log_name = 'ampache'; } if (!strlen($log_name)) { $log_name = 'ampache'; }
$log_filename = conf('log_path') . "/$log_name." . date("Ymd",$log_time) . ".log"; $log_filename = Config::get('log_path') . "/$log_name." . date("Ymd",$log_time) . ".log";
$log_line = date("Y-m-d H:i:s",$log_time) . " { $username } ( $event_name ) - $event_description \n"; $log_line = date("Y-m-d H:i:s",$log_time) . " { $username } ( $event_name ) - $event_description \n";
$log_write = error_log($log_line, 3, $log_filename); $log_write = error_log($log_line, 3, $log_filename);
@ -109,7 +109,7 @@ function ampache_error_handler($errno, $errstr, $errfile, $errline) {
*/ */
function debug_event($type,$message,$level,$file='',$username='') { function debug_event($type,$message,$level,$file='',$username='') {
if (!conf('debug') || $level > conf('debug_level')) { if (!Config::get('debug') || $level > Config::get('debug_level')) {
return false; return false;
} }

View file

@ -175,29 +175,27 @@ function update_preference($username,$name,$pref_id,$value) {
} // update_preference } // update_preference
/*! /**
@function has_preference_access * has_preference_access
@discussion makes sure that the user has sufficient * makes sure that the user has sufficient
rights to actually set this preference, handle * rights to actually set this preference, handle
as allow all, deny X * as allow all, deny X
//FIXME: */
// This is no longer needed, we just need to check against preferences.level
*/
function has_preference_access($name) { function has_preference_access($name) {
/* If it's a demo they don't get jack */ /* If it's a demo they don't get jack */
if (conf('demo_mode')) { if (Config::get('demo_mode')) {
return false; return false;
} }
$name = sql_escape($name); $name = Dba::escape($name);
/* Check Against the Database Row */ /* Check Against the Database Row */
$sql = "SELECT level FROM preferences " . $sql = "SELECT `level` FROM `preferences` " .
"WHERE name='$name'"; "WHERE `name`='$name'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$data = mysql_fetch_assoc($db_results); $data = Dba::fetch_assoc($db_results);
$level = $data['level']; $level = $data['level'];
@ -207,7 +205,7 @@ function has_preference_access($name) {
return false; return false;
} // has_preference_access } //has_preference_access
/*! /*!
@ -423,28 +421,27 @@ function insert_preference($name,$description,$default,$level,$type,$catagory) {
*/ */
function init_preferences() { function init_preferences() {
/* Get Global Preferences */ /* Get Global Preferences */
$sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='-1' " . $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='-1' " .
" AND user_preference.preference = preferences.id AND preferences.catagory='system'"; " AND user_preference.preference = preferences.id AND preferences.catagory='system'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
while ($r = mysql_fetch_assoc($db_results)) { while ($r = Dba::fetch_assoc($db_results)) {
$name = $r['name']; $name = $r['name'];
$results[$name] = $r['value']; $results[$name] = $r['value'];
} // end while sys prefs } // end while sys prefs
/* Now we need to allow the user to override some stuff that's been set by the above */ /* Now we need to allow the user to override some stuff that's been set by the above */
$user_id = '-1'; $user_id = '-1';
if ($GLOBALS['user']->username) { if ($GLOBALS['user']->id) {
$user_id = sql_escape($GLOBALS['user']->id); $user_id = Dba::escape($GLOBALS['user']->id);
} }
$sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='$user_id' " . $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='$user_id' " .
" AND user_preference.preference = preferences.id AND preferences.catagory != 'system'"; " AND user_preference.preference = preferences.id AND preferences.catagory != 'system'";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
while ($r = mysql_fetch_assoc($db_results)) { while ($r = Dba::fetch_assoc($db_results)) {
$name = $r['name']; $name = $r['name'];
$results[$name] = $r['value']; $results[$name] = $r['value'];
} // end while } // end while
@ -454,9 +451,7 @@ function init_preferences() {
$results['theme_path'] = '/themes/' . $results['theme_name']; $results['theme_path'] = '/themes/' . $results['theme_name'];
} }
conf($results,1); Config::set_by_array($results,1);
return true;
} // init_preferences } // init_preferences
@ -529,4 +524,25 @@ function fix_all_users_prefs() {
} // fix_all_users_prefs } // fix_all_users_prefs
/**
* fix_preferences
* This takes the preferences, explodes what needs to
* become an array and boolean everythings
*/
function fix_preferences($results) {
$results['auth_methods'] = explode(",",$results['auth_methods']);
$results['tag_order'] = explode(",",$results['tag_order']);
$results['album_art_order'] = explode(",",$results['album_art_order']);
$results['amazon_base_urls'] = explode(",",$results['amazon_base_urls']);
foreach ($results as $key=>$data) {
if (strcasecmp($data,"true") == "0") { $results[$key] = 1; }
if (strcasecmp($data,"false") == "0") { $results[$key] = 0; }
}
return $results;
} // fix_preferences
?> ?>

View file

@ -88,12 +88,12 @@ function get_recently_played() {
"FROM object_count " . "FROM object_count " .
"WHERE object_type='song' " . "WHERE object_type='song' " .
"ORDER by object_count.date DESC " . "ORDER by object_count.date DESC " .
"LIMIT " . conf('popular_threshold'); "LIMIT " . Config::get('popular_threshold');
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$results = array(); $results = array();
while ($r = mysql_fetch_assoc($db_results)) { while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r; $results[] = $r;
} }
@ -101,16 +101,6 @@ function get_recently_played() {
} // get_recently_played } // get_recently_played
/*!
@function format_song
@discussion takes a song array and makes it html friendly
*/
function format_song($song) {
return $song;
} // format_song
/** /**
* get_popular_songs * get_popular_songs
* This returns the current popular songs * This returns the current popular songs

View file

@ -58,13 +58,13 @@ function gc_now_playing() {
$time = time(); $time = time();
$expire = $time - 3200; // 86400 seconds = 1 day $expire = $time - 3200; // 86400 seconds = 1 day
$session_id = sql_escape($_REQUEST['sid']); $session_id = Dba::escape($_REQUEST['sid']);
if (strlen($session_id)) { if (strlen($session_id)) {
$session_sql = " OR session = '$session_id'"; $session_sql = " OR session = '$session_id'";
} }
$sql = "DELETE FROM now_playing WHERE start_time < $expire" . $session_sql; $sql = "DELETE FROM now_playing WHERE start_time < $expire" . $session_sql;
$db_result = mysql_query($sql, dbh()); $db_result = Dba::query($sql);
} // gc_now_playing } // gc_now_playing
@ -101,9 +101,9 @@ function insert_now_playing($song_id,$uid,$song_length) {
$sql = "INSERT INTO now_playing (`song_id`, `user`, `start_time`,`session`)" . $sql = "INSERT INTO now_playing (`song_id`, `user`, `start_time`,`session`)" .
" VALUES ('$song_id', '$uid', '$expire','$session_id')"; " VALUES ('$song_id', '$uid', '$expire','$session_id')";
$db_result = mysql_query($sql, dbh()); $db_result = Dba::query($sql);
$insert_id = mysql_insert_id(dbh()); $insert_id = Dba::insert_id();
return $insert_id; return $insert_id;

View file

@ -68,8 +68,8 @@ function get_theme($name) {
if (strlen($name) < 1) { return false; } if (strlen($name) < 1) { return false; }
$config_file = conf('prefix') . "/themes/" . $name . "/theme.cfg.php"; $config_file = Config::get('prefix') . "/themes/" . $name . "/theme.cfg.php";
$results = read_config($config_file); $results = parse_ini_file($config_file);
$results['path'] = $name; $results['path'] = $name;
return $results; return $results;
@ -116,9 +116,9 @@ function set_theme_colors($theme_name,$user_id) {
*/ */
function set_theme() { function set_theme() {
if (strlen(conf('theme_name')) > 0) { if (strlen(Config::get('theme_name')) > 0) {
$theme_path = "/themes/" . conf('theme_name'); $theme_path = "/themes/" . Config::get('theme_name');
conf(array('theme_path'=>$theme_path),1); Config::set(array('theme_path'=>$theme_path),1);
} }
} // set_theme } // set_theme

View file

@ -76,10 +76,8 @@ function flip_class($array=0) {
*/ */
function clear_now_playing() { function clear_now_playing() {
$sql = "TRUNCATE TABLE now_playing"; $sql = "TRUNCATE TABLE `now_playing`";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
return true;
} // clear_now_playing } // clear_now_playing
@ -89,11 +87,11 @@ function clear_now_playing() {
* if it isn't it defines it as a simple return * if it isn't it defines it as a simple return
*/ */
if (!function_exists('_')) { if (!function_exists('_')) {
function _($string) { function _($string) {
return $string; return $string;
} // _ } // _
} // if _ isn't defined } // if _ isn't defined
/** /**
@ -223,9 +221,9 @@ function truncate_with_ellipsis($text, $max=27) {
/* Make sure the functions exist before doing the iconv mojo */ /* Make sure the functions exist before doing the iconv mojo */
if (function_exists('iconv') && function_exists('iconv_substr') && function_exists('iconv_strlen')) { if (function_exists('iconv') && function_exists('iconv_substr') && function_exists('iconv_strlen')) {
if (iconv_strlen($text, conf('site_charset')) > $max) { if (iconv_strlen($text, Config::get('site_charset')) > $max) {
$text = iconv_substr($text, 0, $max-3, conf('site_charset')); $text = iconv_substr($text, 0, $max-3, Config::get('site_charset'));
$text .= iconv("ISO-8859-1", conf('site_charset'), "..."); $text .= iconv("ISO-8859-1", Config::get('site_charset'), "...");
} }
} }
@ -247,7 +245,7 @@ function truncate_with_ellipsis($text, $max=27) {
*/ */
function show_footer() { function show_footer() {
require_once(conf('prefix') . '/templates/footer.inc'); require_once Config::get('prefix') . '/templates/footer.inc';
} // show_footer } // show_footer
@ -257,10 +255,9 @@ function show_footer() {
*/ */
function show_now_playing() { function show_now_playing() {
$dbh = dbh(); $web_path = Config::get('web_path');
$web_path = conf('web_path');
$results = get_now_playing(); $results = get_now_playing();
require (conf('prefix') . "/templates/show_now_playing.inc"); require Config::get('prefix') . '/templates/show_now_playing.inc';
} // show_now_playing } // show_now_playing
@ -296,15 +293,15 @@ function show_play_selected() {
*/ */
function get_now_playing($filter='') { function get_now_playing($filter='') {
$sql = "SELECT song_id,user FROM now_playing ORDER BY id DESC"; $sql = "SELECT `song_id`,`user` FROM `now_playing` ORDER BY `id` DESC";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$results = array(); $results = array();
/* While we've got stuff playing */ /* While we've got stuff playing */
while ($r = mysql_fetch_assoc($db_results)) { while ($r = Dba::fetch_assoc($db_results)) {
$song = new Song($r['song_id']); $song = new Song($r['song_id']);
$song->format_song(); $song->format();
$np_user = new User($r['user']); $np_user = new User($r['user']);
$results[] = array('song'=>$song,'user'=>$np_user); $results[] = array('song'=>$song,'user'=>$np_user);
} // end while } // end while
@ -468,7 +465,7 @@ function show_all_popular() {
$songs = get_global_popular('song'); $songs = get_global_popular('song');
$genres = get_global_popular('genre'); $genres = get_global_popular('genre');
require_once(conf('prefix') . '/templates/show_all_popular.inc.php'); require_once Config::get('prefix') . '/templates/show_all_popular.inc.php';
} // show_all_popular } // show_all_popular
@ -480,12 +477,12 @@ function show_all_popular() {
* @catagory Display * @catagory Display
* @author Karl Vollmer * @author Karl Vollmer
*/ */
function show_all_recent() { function show_all_recent($limit='') {
$artists = get_newest('artist'); $artists = Stats::get_newest('artist',$limit);
$albums = get_newest('album'); $albums = Stats::get_newest('album',$limit);
require_once(conf('prefix') . '/templates/show_all_recent.inc.php'); require_once Config::get('prefix') . '/templates/show_all_recent.inc.php';
} // show_all_recent } // show_all_recent
@ -497,47 +494,24 @@ function show_all_recent() {
*/ */
function show_local_catalog_info() { function show_local_catalog_info() {
$dbh = dbh();
/* Before we display anything make sure that they have a catalog */ /* Before we display anything make sure that they have a catalog */
$query = "SELECT * FROM catalog"; $query = "SELECT * FROM catalog";
$db_results = mysql_query($query, $dbh); $db_results = Dba::query($query);
if (!mysql_num_rows($db_results)) {
// Make sure we have something to display
if (!Dba::num_rows($db_results)) {
show_box_top(); show_box_top();
$items[] = "<span align=\"center\" class=\"error\">" . _('No Catalogs Found!') . "</span><br />"; $items[] = "<span align=\"center\" class=\"error\">" . _('No Catalogs Found!') . "</span><br />";
$items[] = "<a href=\"" . conf('web_path') . "/admin/catalog.php?action=show_add_catalog\">" ._('Add a Catalog') . "</a>"; $items[] = "<a href=\"" . Config::get('web_path') . "/admin/catalog.php?action=show_add_catalog\">" ._('Add a Catalog') . "</a>";
show_info_box('','catalog',$items); show_info_box('','catalog',$items);
show_box_bottom(); show_box_bottom();
return false; return false;
} }
$query = "SELECT count(*) AS songs, SUM(size) AS size, SUM(time) as time FROM song"; $results = Catalog::get_stats();
$db_result = mysql_query($query, $dbh);
$songs = mysql_fetch_assoc($db_result);
$query = "SELECT count(*) FROM album"; $hours = floor($results['time']/3600);
$db_result = mysql_query($query, $dbh); $size = $results['size']/1048576;
$albums = mysql_fetch_row($db_result);
$query = "SELECT count(*) FROM artist";
$db_result = mysql_query($query, $dbh);
$artists = mysql_fetch_row($db_result);
$sql = "SELECT count(*) FROM user";
$db_result = mysql_query($sql, $dbh);
$users = mysql_fetch_row($db_result);
$time = time();
$last_seen_time = $time - 1200;
$sql = "SELECT count(DISTINCT s.username) FROM session AS s " .
"INNER JOIN user AS u ON s.username = u.username " .
"WHERE s.expire > " . $time . " " .
"AND u.last_seen > " . $last_seen_time;
$db_result = mysql_query($sql, $dbh);
$connected_users = mysql_fetch_row($db_result);
$hours = floor($songs['time']/3600);
$size = $songs['size']/1048576;
$days = floor($hours/24); $days = floor($hours/24);
$hours = $hours%24; $hours = $hours%24;
@ -556,22 +530,29 @@ function show_local_catalog_info() {
$size_unit = "MB"; $size_unit = "MB";
} }
require(conf('prefix') . "/templates/show_local_catalog_info.inc.php"); require Config::get('prefix') . '/templates/show_local_catalog_info.inc.php';
} // show_local_catalog_info } // show_local_catalog_info
/*! /**
@function img_resize * img_resize
@discussion this automaticly resizes the image for thumbnail viewing * this automaticly resizes the image for thumbnail viewing
only works on gif/jpg/png this function also checks to make * only works on gif/jpg/png this function also checks to make
sure php-gd is enabled * sure php-gd is enabled
*/ */
function img_resize($image,$size,$type){ function img_resize($image,$size,$type,$album_id) {
/* Make sure they even want us to resize it */ /* Make sure they even want us to resize it */
if (!conf('resize_images')) { if (!Config::get('resize_images')) {
return false; return $image['art'];
} }
// Already resized
if ($image['resized']) {
debug_event('using_resized','using resized image for Album:' . $album_id,'2');
return $image['art'];
}
$image = $image['art'];
if (!function_exists('gd_info')) { return false; } if (!function_exists('gd_info')) { return false; }
@ -604,6 +585,8 @@ function img_resize($image,$size,$type){
return false; return false;
} }
ob_start();
// determine image type and send it to the client // determine image type and send it to the client
switch ($type) { switch ($type) {
case 'jpg': case 'jpg':
@ -618,6 +601,21 @@ function img_resize($image,$size,$type){
break; break;
} }
// Grab this image data and save it into the thumbnail
$data = ob_get_contents();
ob_end_clean();
// If our image create failed don't save it, just return
if (!$data) {
debug_event('IMG_RESIZE','Failed to resize Art from Album:' . $album_id,'3');
return $image;
}
// Save what we've got
Album::save_resized_art($data,'image/' . $type,$album_id);
return $data;
} // img_resize } // img_resize
/** /**
@ -692,14 +690,14 @@ function show_artist_pulldown ($artist_id,$select_name='artist') {
*/ */
function show_catalog_pulldown ($name='catalog',$style) { function show_catalog_pulldown ($name='catalog',$style) {
$sql = "SELECT id,name FROM catalog ORDER BY name"; $sql = "SELECT `id`,`name` FROM `catalog` ORDER BY `name`";
$db_result = mysql_query($sql, dbh()); $db_result = Dba::query($sql);
echo "\n<select name=\"" . $name . "\" style=\"" . $style . "\">\n"; echo "\n<select name=\"" . $name . "\" style=\"" . $style . "\">\n";
echo "<option value=\"-1\">All</option>\n"; echo "<option value=\"-1\">" . _('All') . "</option>\n";
while ($r = mysql_fetch_assoc($db_result)) { while ($r = Dba::fetch_assoc($db_result)) {
$catalog_name = scrub_out($r['name']); $catalog_name = scrub_out($r['name']);
if ( $catalog == $r['id'] ) { if ( $catalog == $r['id'] ) {
@ -722,7 +720,7 @@ function show_catalog_pulldown ($name='catalog',$style) {
*/ */
function show_submenu($items) { function show_submenu($items) {
require (conf('prefix') . '/templates/subnavbar.inc.php'); require Config::get('prefix') . '/templates/subnavbar.inc.php';
} // show_submenu } // show_submenu
@ -750,7 +748,7 @@ function get_location() {
} }
/* Sanatize the $_SERVER['PHP_SELF'] variable */ /* Sanatize the $_SERVER['PHP_SELF'] variable */
$source = str_replace(conf('raw_web_path'),"",$source); $source = str_replace(Config::get('raw_web_path'),"",$source);
$location['page'] = preg_replace("/^\/(.+\.php)\/?.*/","$1",$source); $location['page'] = preg_replace("/^\/(.+\.php)\/?.*/","$1",$source);
switch ($location['page']) { switch ($location['page']) {
@ -850,12 +848,11 @@ function show_preference_box($preferences) {
* the currently selected and then the size * the currently selected and then the size
* *
*/ */
function show_genre_pulldown ($name,$selected='',$size=1,$width=0,$style='') { function show_genre_pulldown ($name,$selected='',$size=1,$width=0,$style='') {
/* Get them genre hippies */ /* Get them genre hippies */
$sql = "SELECT genre.id,genre.name FROM genre ORDER BY genre.name"; $sql = "SELECT genre.id,genre.name FROM genre ORDER BY genre.name";
$db_result = mysql_query($sql, dbh()); $db_result = Dba::query($sql);
if ($size > 0) { if ($size > 0) {
$multiple_txt = "multiple=\"multiple\" size=\"$size\""; $multiple_txt = "multiple=\"multiple\" size=\"$size\"";
@ -867,7 +864,7 @@ function show_genre_pulldown ($name,$selected='',$size=1,$width=0,$style='') {
echo "<select name=\"" . $name . "[]\" $multiple_txt $style_txt>\n"; echo "<select name=\"" . $name . "[]\" $multiple_txt $style_txt>\n";
echo "\t<option value=\"-1\">" . _("All") . "</option>\n"; echo "\t<option value=\"-1\">" . _("All") . "</option>\n";
while ($r = mysql_fetch_assoc($db_result)) { while ($r = Dba::fetch_assoc($db_result)) {
if ($width > 0) { if ($width > 0) {
$r['name'] = truncate_with_ellipsis($r['name'],$width); $r['name'] = truncate_with_ellipsis($r['name'],$width);
@ -1183,7 +1180,7 @@ function show_user_select($name,$selected='',$style='') {
*/ */
function show_box_top($title='') { function show_box_top($title='') {
require (conf('prefix') . '/templates/show_box_top.inc.php'); require Config::get('prefix') . '/templates/show_box_top.inc.php';
} // show_box_top } // show_box_top
@ -1194,7 +1191,7 @@ function show_box_top($title='') {
*/ */
function show_box_bottom() { function show_box_bottom() {
require (conf('prefix') . '/templates/show_box_bottom.inc.php'); require Config::get('prefix') . '/templates/show_box_bottom.inc.php';
} // show_box_bottom } // show_box_bottom
@ -1224,21 +1221,21 @@ function get_user_icon($name,$hover_name='') {
$icon_name = 'icon_' . $name . '.png'; $icon_name = 'icon_' . $name . '.png';
/* Build the image url */ /* Build the image url */
if (file_exists(conf('prefix') . '/themes/' . $GLOBALS['theme']['path'] . '/images/' . $icon_name)) { if (file_exists(Config::get('prefix') . '/themes/' . Config::get('theme_path') . '/images/' . $icon_name)) {
$img_url = conf('web_path') . conf('theme_path') . '/images/' . $icon_name; $img_url = Config::get('web_path') . Config::get('theme_path') . '/images/' . $icon_name;
} }
else { else {
$img_url = conf('web_path') . '/images/' . $icon_name; $img_url = Config::get('web_path') . '/images/' . $icon_name;
} }
/* If Hover, then build its url */ /* If Hover, then build its url */
if (!empty($hover_name)) { if (!empty($hover_name)) {
$hover_icon = 'icon_' . $hover_name . '.png'; $hover_icon = 'icon_' . $hover_name . '.png';
if (file_exists(conf('prefix') . '/themes/' . $GLOBALS['theme']['path'] . '/images/' . $icon_name)) { if (file_exists(Config::get('prefix') . '/themes/' . Config::get('theme_path') . '/images/' . $icon_name)) {
$hov_url = conf('web_path') . conf('theme_path') . '/images/' . $hover_icon; $hov_url = Config::get('web_path') . Config::get('theme_path') . '/images/' . $hover_icon;
} }
else { else {
$hov_url = conf('web_path') . '/images/' . $hover_icon; $hov_url = Config::get('web_path') . '/images/' . $hover_icon;
} }
$hov_txt = "onMouseOver=\"this.src='$hov_url'; return true;\" onMouseOut=\"this.src='$img_url'; return true;\""; $hov_txt = "onMouseOver=\"this.src='$hov_url'; return true;\" onMouseOut=\"this.src='$img_url'; return true;\"";

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
Copyright (c) 2001 - 2006 Ampache.org Copyright (c) 2001 - 2007 Ampache.org
All Rights Reserved All Rights Reserved
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
@ -20,14 +20,8 @@
*/ */
/*
Login our friendly users
*/
define('NO_SESSION','1'); define('NO_SESSION','1');
require_once('lib/init.php'); require_once 'lib/init.php';
/* We have to create a cookie here because IIS /* We have to create a cookie here because IIS
* can't handle Cookie + Redirect * can't handle Cookie + Redirect
@ -40,9 +34,8 @@ init_preferences();
* even want them to be able to get to the login * even want them to be able to get to the login
* page if they aren't in the ACL * page if they aren't in the ACL
*/ */
if (conf('access_control')) { if (Config::get('access_control')) {
$access = new Access(0); if (!Access::check('interface',$_SERVER['REMOTE_ADDR'],'','5')) {
if (!$access->check('interface',$_SERVER['REMOTE_ADDR'],'','5')) {
debug_event('access_denied','Access Denied:' . $_SERVER['REMOTE_ADDR'] . ' is not in the Interface Access list','3'); debug_event('access_denied','Access Denied:' . $_SERVER['REMOTE_ADDR'] . ' is not in the Interface Access list','3');
access_denied(); access_denied();
} }
@ -63,7 +56,7 @@ if ($_POST['username'] && $_POST['password']) {
} }
/* If we are in demo mode let's force auth success */ /* If we are in demo mode let's force auth success */
if (conf('demo_mode')) { if (Config::get('demo_mode')) {
$auth['success'] = 1; $auth['success'] = 1;
$auth['info']['username'] = "Admin- DEMO"; $auth['info']['username'] = "Admin- DEMO";
$auth['info']['fullname'] = "Administrative User"; $auth['info']['fullname'] = "Administrative User";
@ -73,7 +66,7 @@ if ($_POST['username'] && $_POST['password']) {
$username = scrub_in($_POST['username']); $username = scrub_in($_POST['username']);
$password = scrub_in($_POST['password']); $password = scrub_in($_POST['password']);
$auth = authenticate($username, $password); $auth = authenticate($username, $password);
$user = get_user_from_username($username); $user = User::get_from_username($username);
if ($user->disabled == '1') { if ($user->disabled == '1') {
$auth['success'] = false; $auth['success'] = false;
@ -82,8 +75,8 @@ if ($_POST['username'] && $_POST['password']) {
elseif (!$user->username AND $auth['success']) { elseif (!$user->username AND $auth['success']) {
/* This is run if we want to auto_create users who don't exist (usefull for non mysql auth) */ /* This is run if we want to auto_create users who don't exist (usefull for non mysql auth) */
if (conf('auto_create')) { if (Config::get('auto_create')) {
if (!$access = conf('auto_user')) { $access = '5'; } if (!$access = Config::get('auto_user')) { $access = '5'; }
$name = $auth['name']; $name = $auth['name'];
$email = $auth['email']; $email = $auth['email'];
@ -123,8 +116,8 @@ if ($auth['success']) {
// //
// Record the IP of this person! // Record the IP of this person!
// //
if (conf('track_user_ip')) { if (Config::get('track_user_ip')) {
$user = get_user_from_username($username); $user = User::get_from_username($username);
$user->insert_ip_history(); $user->insert_ip_history();
unset($user); unset($user);
} }
@ -132,7 +125,7 @@ if ($auth['success']) {
/* Make sure they are actually trying to get to this site and don't try to redirect them back into /* Make sure they are actually trying to get to this site and don't try to redirect them back into
* an admin section * an admin section
**/ **/
if (substr($_POST['referrer'],0,strlen(conf('web_path'))) == conf('web_path') AND if (substr($_POST['referrer'],0,strlen(Config::get('web_path'))) == Config::get('web_path') AND
!strstr($_POST['referrer'],"install.php") AND !strstr($_POST['referrer'],"install.php") AND
!strstr($_POST['referrer'],"login.php") AND !strstr($_POST['referrer'],"login.php") AND
!strstr($_POST['referrer'],"update.php") AND !strstr($_POST['referrer'],"update.php") AND
@ -142,39 +135,20 @@ if ($auth['success']) {
header("Location: " . $_POST['referrer']); header("Location: " . $_POST['referrer']);
exit(); exit();
} // if we've got a referrer } // if we've got a referrer
header("Location: " . conf('web_path') . "/index.php"); header("Location: " . Config::get('web_path') . "/index.php");
exit(); exit();
} // auth success } // auth success
/* If auth failed then setup the error */ /* If auth failed then setup the error */
else { else {
$GLOBALS['error']->add_error('general',$auth['error']); Error::add('general',$auth['error']);
} }
$htmllang = str_replace("_","-",conf('lang')); require Config::get('prefix') . '/templates/show_login_form.inc';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $htmllang; ?>" lang="<?php echo $htmllang; ?>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo conf('site_charset'); ?>" />
<link rel="shortcut icon" href="<?php echo conf('web_path'); ?>/favicon.ico" />
<link rel="stylesheet" href="templates/print.css" type="text/css" media="print" />
<link rel="stylesheet" href="templates/handheld.css" type="text/css" media="handheld" />
<link rel="stylesheet" href="<?php echo conf('web_path'); ?><?php echo conf('theme_path'); ?>/templates/default.css" type="text/css" media="screen" />
<title> <?php echo conf('site_title'); ?> </title>
<script type="text/javascript" language="javascript">
function focus(){ document.login.username.focus(); }
</script>
</head>
<body bgcolor="#D3D3D3" onload="focus();"> if (@is_readable(Config::get('prefix') . '/config/motd.php')) {
<?php
require(conf('prefix') . "/templates/show_login_form.inc");
if (@is_readable(conf('prefix') . '/config/motd.php')) {
echo "<div align=\"center\">\n"; echo "<div align=\"center\">\n";
show_box_top(_('Message of the Day')); show_box_top(_('Message of the Day'));
include conf('prefix') . '/config/motd.php'; include Config::get('prefix') . '/config/motd.php';
show_box_bottom(); show_box_bottom();
echo "</div>\n"; echo "</div>\n";
} }

View file

@ -0,0 +1,491 @@
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | Changelog |
// +----------------------------------------------------------------------+
//
// $Id: changelog.txt,v 1.47 2007/02/12 10:00:15 ah Exp $
» denotes a major feature addition/change
¤ denotes a change in the returned structure
! denotes a cry for help from developers
* Bugfix: denotes a fixed bug
getID3() 2.x Version History
============================
2.0.0b4: [2007-01-12] Allan Hansen
GENERAL
» Major update to readme.txt
» Added new section sample apps
» Added well-written sample application "morg".
See sample_apps/morg/screen_shots for more
¤ option_tags_process now generates root key 'comments' with merged
values from 'tags'.
¤ Removed option_tags_html. HTML entities is a thing of the past.
Use UTF-8 encoded pages instead. Saves bandwidth and is much easier.
* Bugfix: PHP_NOTICE issue in BigEndian2Float().
» Tag writing support: ID3v1
» Tag writing support: APEtag
» Tag writing support: FLAC
» Tag writing support: Ogg Vorbis
» Tag writing support: Lyrics3
» SVG file detection (no parsing)
» PAR2 file detection (no parsing)
» Got rid of windowed and option_helperapps_dir. Helper apps must be
somewhere in the path, e.g. c:\windows\system32 or /usr/bin
ASF MODULE:
* Bugfix: Wrong mime type (video/x-ms-wma instead of video/x-ms-wmv)
for certain FourCCs.
* Bugfix: Padding offset bug.
DATA_HASH MODULE:
¤ copy md5_data_source to md5_data if option set to true
DTS MODULE:
» New module (module.audio.dts.php)
FLV MODULE:
* Bugfix: DivByZero on zero length FLV files.
* Bugfix: PHP_NOTICE one some files.
ID3v1 MODULE:
¤ Removed: Padding check.
ID3v2 MODULE:
* Bugfix: PHP_NOTICE issues with broken ID3v2 tag/garbage.
* Bugfix: UTF-8/16 encoded frames terminated by \x00.
* Bugfix: ID3v2 LINK frames iconv error.
* Bugfix: Padding length calculated incorrectly.
* Bugfix: ID3v2.3 extended headers non-conformance.
LYRICS3 MODULE
* Bugfix: Minor issues with lyrics3 (avoid PHP_NOTICE).
PNG MODULE:
* Bugfix: Module broken in regards to gIFg and gIFx chunks.
MIDI MODULE
* Bugfix: Minor issues with midi module (avoid PHP_NOTICE).
MP3 MODULE:
* Bugfix: Removed whitespace after ?>
* Bugfix: Some CBR MP3 files detected as VBR with plenty of warnings.
* Bugfix: PHP_NOTICE issues.
MPC MODULE:
¤ Mime type returned: audio/x-musepack
QUICKTIME MODULE:
* Bugfix: TYPO in variable, resulting in unknown errors.
* Bugfix: Incorrect frame rate returned.
REAL MODULE:
* Bugfix: fread() zero bytes issue.
RIFF MODULE:
* Bugfix: Wave files being detected as MP3.
¤ Zero sized chunk invokes warning instead of error.
SHORTEN MODULE:
* Bugfix: Not working for wav files with fmt chunks <> 16 bytes.
XIPH MODULE:
» replaygain_reference_loudness from FLAC 1.1.3 moved from comments
to ['replay_gain']['reference_volume'].
» Supporting FLAC 1.1.3 PICTURE block.
¤ FLAC: Removed some ['raw'] keys.
2.0.0b3: [2006-06-25] Allan Hansen
AAC_ADTS MODULE
* Bugfix: Static bitrate cache wrong result when parsing several files
ASF MODULE
* Bugfix: Do not return NULL video bitrate for ASF v3.
* Bugfix: ['codec'] key warning in module.audio-video.asf.php from 1.7.6,
* Bugfix: audio & video bitrates sometimes wrong in ASF files from 1.7.6,
¤ ASF lyrics now returned under [comments][lyrics] from 1.7.5,
BMP MODULE
* Bugfix: Undocumented bugfix between 1.7.3 and 1.7.6,
DATA_HASH MODULE
* Bugfix: Filenames not escaped with escapeshellarg() under UNIX.
* Bugfix: UNIX: head and tail called with -cNNN instead of "-c NNN".
FLV MODULE
» No longer reads entire file into memory.
ID3v1 MODULE
¤ Put back id3v1 padding check, since it exists in 1.7.6.
ID3v2 MODULE
* Bugfix: PHP notices on bad ID3v2 frames from 1.7.6.
* Bugfix: 'url_source' typo in module.tag.id3v2.php from 1.7.3.
¤ ID3v2 "TDRC" frame now used as "year" in comments if TYER
unavailable (TYER is deprecated in ID3v2.4)
¤ Bugfix: gmmktime() instead of mktime().
ISO MODULE
¤ Using gmmktime() instead of mktime().
GZIP MODULE
! Module is a memory hog. Reads entire file into memory. It also
gzdeflates() it to memory. Will use lots of memory on huge files.
Please someone rewrite it to work with filepointers and seeking.
» info['gzip']['files'] removed. Contains redundant information only.
» Replaced ['tar'] key with ['parsed_content']. Module can now parse
anything that getID3() can parse - not just tar files.
JPEG MODULE
* Bugfix: Error when php exif support enabled.
LYRICS MODULE
¤ Comments are no longer trimmed.
QUICKTIME MODULE
* Bugfix: incorrect dimensions from disabled Quicktime tracks from 1.7.6,
¤ Added ['quicktime']['hinting'] key (boolean) from 1.7.4,
* Bugfix: Quicktime 'mvhd' matrix values were wrong from 1.7.3,
MIDI MODULE
* Bugfix: Fixed bug that reported wrong playing time on some files.
MP3 MODULE
» Module fully working.
» Memory caches are reset when scanning new file. Might make analyse
slightly slower, but will save lots of memory.
» Removed unrecommended bruteforce code.
* Bugfix: Encoder options should now return proper "--alt-preset n" /
"--alt-preset cbr n" when scanning more files.
* Bugfix: added LAME preset guessing for presets 410,420,440,490
(thanks adminØlogbud*com)
RIFF MODULE
¤ No longer returns zero bits_per_sample for multiple formats.
* Bugfix: Missing 'lossless' key in RIFF-WAV from 1.7.4.
¤ Using gmmktime() instead of mktime().
SHORTEN MODULE
* Bugfix: Filenames not escaped with escapeshellarg() under UNIX.
TAR MODULE
» Module rewritten to work with filepointer only. Makes parsing a lot
faster (will fseek() past data). Also saves a lot of memory, expecially
with large files.
» Added warning for non ASCII filenames, which breaks specification.
» info['tar']['files'] removed. Contains redundant information only. Also
causes problems for non ASCII tar files, as filenames are used as keys
in PHP arrays.
XIPH MODULE
* Bugfix: Error message when padding in FLAC files were used up.
ZIP MODULE
¤ Using gmmktime() instead of mktime().
ICONV_REPLACEMENT MODULE
* Bugfix: Major UTF-8 to UTF-16/ISO-8859-1 conversion bug (empty string
returned) when iconv() not available - from 1.7.4.
* Bugfix: Other major bugfixes that broke the module.
demo.joinmp3.php
Demo removed - out of getID3()'s scope.
PDF files can now be detected, but not parsed/analyzed.
MSOffice files can now be detected, but not parsed/analyzed.
2.0.0b2: [2004-11-01] Allan Hansen
GENERAL
* Bugfixes: Analyzed 3,000 files and compared result with 1.7.2 - several
minor bugs were fixed. Output of 2.0.0 should match 1.7.2 reasonable well.
* Bugfix: fail_id3 and fail_ape code never executed.
Wavpack4 support
Quicktime/MP3-in-MP4, Apple Lossless support
» New encoding_id3v2 option/hack for broken ID3v2 tags
¤ Tags are no longer trim()ed.
¤ Some ['bits_per_sample'] == 0 removed
» New option_analyze - disable to detect format only.
» New option_accurate_results - disable to greatly speed up parsing of
AAC/ADTS, headerless MP3/MP2 VBR, midi (later), possible more in future.
Warnings issued when disabled and accuracy affected!
AAC/ADTS
» Memory caches destroyed after analyze() to free up memory.
LA MODULE
* Bugfix: RIFF tags now parsed properly
OPTIMFROG MODULE
* Bugfix: RIFF tags now parsed properly
WAVPACK MODULE
* Bugfix: RIFF trailer now parsed properly
QUICKTIME MODULE
¤ option_extra_info determines whether atom_data is returned
¤ Removed $ParseAllPossibleAtoms option. We should only return useful data.
zlib support in PHP optional reqirement
* Bugfix: New iTunes crashes PHP - temp fix - no tags on those files.
RIFF MODULE
* Bugfix: Wavpack3 extra fields now parsed properly.
¤ RIFF tags in Litewave files now parsed properly
BONK MODULE
* Bugfix: ['bonk']['ID3']['valid'] now returns bool instead of object
NSV MODULE
* Bugfix: PCM part ignored
APETAG MODULE
* Bugfix: APEtag 1.0 broken
ASF MODULE
¤ Embedded ID3v2 tags processes again - supported by Windows Media Player.
DEMOS
» demo.browse.php scans directories faster with inaccurate results.
» demo.browse.php now uses javascript alert to show longer warnings etc
instead of tool tips.
» demo.browse.php now shows embedded covers just like the 1.7.x demo.
» demo.browse.dhtml.php - DHTML version of the browser. Has progressive
display in MSIE - but quite slow when scanning LOTS of files.
» New demo.mime_only.php for returning mime type only.
» Search example in demo.mysql.php
2.0.0b1: [2004-08-23] Allan Hansen
» Major memory savings. 1.7.1 use 25% more memory under PHP 5.0.0 than
PHP 4.3.7. 2.0.0b1 memory usage is comparable to 1.7.1 under PHP 4.3.7.
See Memory.xls for details (will not be included in 2.0.0 final).
Loading all modules requires 4,277 kb of memory (4,171 with iconv()
support in PHP. Some of the modules require more memory while scanning,
as they cache the results - MP3 and AAC/ADTS in particular.
» New internal testing method. Output of 2.0.0 matches that of 1.7.1
exactly - except those places where we deliberately changed something.
If something is changed it is because we did not have a test file
to show it.
» New extras directory.
This contains multiple usefull code snips that really does not
belong to the main getID3() codebase - i.e. stuff that the user most
likely can/will do differently.
» Deleted getid3_lib.php
- Some common functions moved to getid3.php - getid3_lib declared
there.
- Replaygain function moved to getid3.php - new class
geti3_replaygain.
- iconv() replacement function moved to new lib module.
- md5/sha1 data hash function moved to new lib module.
- Some function moved to the files that use them.
- CopyTagsToComments() moved to extras dir.
- EmbeddedLookup() gone - PHP5 use way more memory that way.
» magic_quotes_runtime must be disabled before running getID3().
If you use them, use set_magic_quotes_runtime(0) and
set_magic_quotes_runtime(1) around your getID3() block.
Older versions turned them on and off automatically. This would
require a lot extra code, since they needed being restored before
every first level throw.
* Bugfix: Fixed multiple bugs in the caching extentions .
Optimized most modules using new getid3_ReadSequence()
Checked all(most) code using error_reporting (E_STRICT | E_ALL)
¤ Removed all dead modules: EXE, RAR, Bink, Matroska, MOD*.
¤ Kept magic bytes - getid3 will detect them and do nothing and return
warning instead of error.
¤ Disabled quicktime and mpeg modules as they depend on mp3-
Reformatted and updated dependencies.txt
GETID3 MAIN
¤ getid3 option_tags_html now defaults to false.
¤ getid3 option_max_2gb_check now defaults to false.
¤ New getid3 option_tags_images defaults to false. Scan tags for binary
image data - ID3v2 and vorbiscomments only. Possible apetag later.
JPEG MODULE
¤ Renamed module from jpg to jpeg.
¤ Changed mime type to correct image/jpeg.
¤ Added optional exif depency to depencies.txt for jpeg files.
PNG MODULE
¤ Made png zlib dependecy optional.
BMP MODULE
» Removed unused and unneeded PlotBMP() in bmp module.
Removed extract_palette and extract_data code
- This does not belong in getid3. We should analyze files, not process
them. If the user wants to display bmp files to the browser she can
convert them with ImageMagick or something similar. She will
probably have it installed already to resize user uploaded images.
PCD MODULE
» Removed $ExtractData from pcd module - same reason as BMP.
SWF MODULE
¤ Added zlib dependecy REQUIRED for swf.
ID3v1 MODULE
¤ Removed id3v1 padding check - who cares?
- also removed in lyrics3 - if needed - it needs to be done differently
- no access to warnings and no sorting!
ID3v2 MODULE
¤ Made id3v2 zlib dependecy optional.
¤ id3v2 - images - changed 'image_mime' to actual mime type.
AAC MODULE(s)
» Split aac module in two - aac_adif and aac_adts.
This saves memory if user only have files of one type (very likely).
Replaced getid3_lib::Bin2Dec() with bindec() in aac modules - speed.
AC3 MODULE
Added ac3 optional dependency to dependencies.txt.
¤ Changed riff module dependency on mp3 to optional.
Changed wawpack references in riff module to wavpack3.
* Bugfix: RIFFparseWavPackHeader() needs 28 bytes, not 22.
ASF MODULE
» Removed id3v1 dependency
» Removed id3v2 dependency
¤ ASF genres are no longer case adjustet to match standard ID3v1 ones.
¤ Embedded ID3v2 tags no longer processes. Not part of the ASF spec.
¤ Changed warning at line 71 to error.
» Removed a lot of unneeded conversions between Bytestring and GUID
» Changed the constants from bytestring to GUID
* Bugfix: Fixed incorrect warning messages on
{4B1ACBE3-100B-11D0-A39B-00A0C90348F6}
{4CFEDB20-75F6-11CF-9C0F-00A0C90349CB}
¤ Removed objectid, fileid, reserved_1_id and reserved where 'same'_guid
exists.
MP3 MODULE
¤ MARKED MP3 MODULE BROKEN
Removed echoerrors debugcode in mp3 module.
Removed bruteforce code in mp3 module - never executed in 1.7.
Removed $scan_as_cbr - not used.
MPC MODULE(s)
» Split mpc module in two - SV7 in "mpc" and SV4-6 in mpc_old.
This saves memory if user only have files of one type (very likely).
OGG, FLAC MODULES
» Merged interdependant modules ogg and flac into new module xiph.
¤ Updated FLACapplicationIDLookup() with 2 new entries.
REAL MODULE
¤ Removed 'unknown' keys.
SHORTEN MODULE
» Improved UNIX shorten binary detection. Scanning `which shorten`,
/usr/bin, /usr/local/bin and checking is_executable()
ISO MODULE
¤ Removed unused_ indexes in iso modules - they are afterall not used.
DEMOS
» Created new index.php in demos/ explaining what the different demos
does.
» Rewrote demo.browse.php completely.
- Using public domain HTML abstraction library by Allan Hansen.
- Removed security breach - able to browse any parent directory .
- A $root_path must be set before browsing.
- Screen width option.
- Compressed filename column using title=.
- Removed filesize column - not really that interesting.
- Removed md5data column.
- Removed total at the bottom - the user can probably figure out
how to implement this himself.
- Added Audio column: sample_rate/bits_per_sample/channels columns.
- Added scan_time columns - how long it took getid3 to process the
file.
- Compressed artist, title and warning column using tool_tips.
- Removed delete feature - possible security risk.
- Repeating file header every 20 rows.
- Added audio format/video format to format column.
- Listing supported php modules in footer.
- New colour scheme.
» Rewrote demo.mysql.php completely.
- Using multiple tables instead of just one. No string is stored
twice. Searching tags should be a lot faster for large databases.
- Multiple artists, titles, genres, etc per file supported.
- Using public domain HTML abstraction library by Allan Hansen.
- Using public domain MySQL abstraction library by Allan Hansen.
- Scanning limited to $audio_path - security.
- Included sample data that can be imported and browsed.
» Rewrote demo.basic.php
» Removed demo.simple.php - basic should be enough
» Removed demo.joinmp3.php - this advanced demo should go in the extras
module IF/WHEN the mp3 module is running again.
¤ Updated demo.audioinfo.class - minor changes.
MISC CODING SPECIFIC
Partial new coding style - some is easily changed with Replace In Files
- New file header - PEAR compatible
- Indentation with four spaces instead of tab - PEAR compatible
- array() changed to as array () - as suggested by PEAR standard
- All(most) function names in MixedCase
- Variables in $my_variable lowercase/underscores
- (bool) $var changed to (bool)$var
- A few "} else {" changed to "else {" to make room for easier
readable comments
Removed all DivByZero checks. The plan was to catch them, but php
errors and warnings are not exceptions... Something needs to be
done here.

View file

@ -0,0 +1,79 @@
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | Dependencies |
// +----------------------------------------------------------------------+
//
// $Id: dependencies.txt,v 1.9 2006/11/16 22:39:59 ah Exp $
READER MODULES:
asf riff module required
bonk id3v2 module optional
id3v2 id3v1 module required
zlib php support optional
gzip zlib php support optional
jpeg exif php support optional
la riff module required
lpac riff module required
lyrics3 apetag module optional
mpeg mp3 module required
optimfrog riff module required
png zlib php support optional
quicktime mp3 module required
zlib php support optional
riff mp3 module optional
ac3 module optional
dts module optional
mpeg module optional
shn shorten binary (shorten.exe on windows) required
swf zlib php support required
wavpack riff module required
xiph vorbiscomment binary (vorbiscomment.exe on windows) for md5/sha1 data hashes on ogg vorbis files.
WRITER MODULES:
apetag apetag (reader) module required
id3v1 (reader) module required
lyrics3 (reader) module required
id3v1 id3v1(reader) module required
lyrics3 lyrics3 (reader) module required
id3v1 (reader) module required
flac metaflac binary
vorbis vorbiscomment binary

View file

@ -0,0 +1,27 @@
getID3() Commercial License
===========================
getID3() is licensed under the "GNU Public License" (GPL) and/or the
"getID3() Commercial License" (gCL). This document describes the gCL.
---------------------------------------------------------------------
The license is non-exclusively granted to a single person or company,
per payment of the license fee, for the lifetime of that person or
company. The license is non-transferrable.
The gCL grants the licensee the right to use getID3() in commercial
closed-source projects. Modifications may be made to getID3() with no
obligation to release the modified source code. getID3() (or pieces
thereof) may be included in any number of projects authored (in whole
or in part) by the licensee.
The licensee may use any version of getID3(), past, present or future,
as is most convenient. This license does not entitle the licensee to
receive any technical support, updates or bugfixes, except as such are
made publicly available to all getID3() users.
The licensee may not sub-license getID3() itself, meaning that any
commercially released product containing all or parts of getID3() must
have added functionality beyond what is available in getID3();
getID3() itself may not be re-licensed by the licensee.

View file

@ -0,0 +1,537 @@
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | Dependencies |
// +----------------------------------------------------------------------+
//
// $Id: readme.txt,v 1.6 2006/12/03 19:46:04 ah Exp $
This code is released under the GNU GPL:
http://www.gnu.org/copyleft/gpl.html
+---------------------------------------------+
| If you do use this code somewhere, send me |
| an email and tell me how/where you used it. |
| |
| If you want to donate, there is a link on |
| http://www.getid3.org for PayPal donations. |
+---------------------------------------------+
Quick Start
===========================================================================
Q: How can I check that getID3() works on my server/files?
A: Unzip getID3() to a directory, then access /demos/demo.browse.php
Sourceforge Notification
===========================================================================
It's highly recommended that you sign up for notification from
Sourceforge for when new versions are released. Please visit:
http://sourceforge.net/project/showfiles.php?group_id=55859
and click the little "monitor package" icon/link. If you're
previously signed up for the mailing list, be aware that it has
been discontinued, only the automated Sourceforge notification
will be used from now on.
What does getID3() do?
===========================================================================
Reads & parses (to varying degrees):
¤ tags:
* APE (v1 and v2)
* ID3v1 (& ID3v1.1)
* ID3v2 (v2.4, v2.3, v2.2)
* Lyrics3 (v1 & v2)
¤ audio-lossy:
* MP3/MP2/MP1
* MPC / Musepack
* Ogg (Vorbis, OggFLAC, Speex)
* RealAudio
* Speex
* VQF
¤ audio-lossless:
* AIFF
* AU
* Bonk
* CD-audio (*.cda)
* FLAC
* LA (Lossless Audio)
* LPAC
* MIDI
* Monkey's Audio
* OptimFROG
* RKAU
* VOC
* WAV (RIFF)
* WavPack
¤ audio-video:
* ASF: ASF, Windows Media Audio (WMA), Windows Media Video (WMV)
* AVI (RIFF)
* Flash
* MPEG-1 / MPEG-2
* NSV (Nullsoft Streaming Video)
* Quicktime
* RealVideo
¤ still image:
* BMP
* GIF
* JPEG
* PNG
¤ data:
* ISO-9660 CD-ROM image (directory structure)
* SZIP (limited support)
* ZIP (directory structure)
Writes:
* ID3v1 (& ID3v1.1)
* ID3v2 (v2.3 & v2.4)
* VorbisComment on OggVorbis
* VorbisComment on FLAC (not OggFLAC)
* APE v2
* Lyrics3 (delete only)
Requirements
===========================================================================
* PHP 4.2.0 (or higher) for getID3() 1.7.8 (and up).
* PHP 5.0.0 (or higher) for getID3() 2.0.0 (and up).
* at least 4MB memory for PHP. 8MB is highly recommended.
12MB is required with all modules loaded.
Usage
===========================================================================
See /demos/demo.basic.php for a very basic use of getID3() with no
fancy output, just scanning one file.
See structure.txt for the returned data structure.
*> For an example of a complete directory-browsing, <*
*> file-scanning implementation of getID3(), please run <*
*> /demos/demo.browse.php <*
See /demos/demo.mysql.php for a sample recursive scanning code that
scans every file in a given directory, and all sub-directories, stores
the results in a database and allows various analysis / maintenance
operations
To analyze remote files over HTTP or FTP you need to copy the file
locally first before running getID3(). Your code would look something
like this:
// Copy remote file locally to scan with getID3()
$remotefilename = 'http://www.example.com/filename.mp3';
if ($fp_remote = fopen($remotefilename, 'rb')) {
$localtempfilename = tempnam('/tmp', 'getID3');
if ($fp_local = fopen($localtempfilename, 'wb')) {
while ($buffer = fread($fp_remote, 8192)) {
fwrite($fp_local, $buffer);
}
fclose($fp_local);
// Initialize getID3 engine
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($filename);
// Delete temporary file
unlink($localtempfilename);
}
fclose($fp_remote);
}
See /demos/demo.write.php for how to write tags.
What does the returned data structure look like?
===========================================================================
See structure.txt
It is recommended that you look at the output of
/demos/demo.browse.php scanning the file(s) you're interested in to
confirm what data is actually returned for any particular filetype in
general, and your files in particular, as the actual data returned
may vary considerably depending on what information is available in
the file itself.
Notes
===========================================================================
getID3() 1.7:
If the format parser encounters a critical problem, it will return
something in $fileinfo['error'], describing the encountered error. If
a less critical error or notice is generated it will appear in
$fileinfo['warning']. Both keys may contain more than one warning or
error. If something is returned in ['error'] then the file was not
correctly parsed and returned data may or may not be correct and/or
complete. If something is returned in ['warning'] (and not ['error'])
then the data that is returned is OK - usually getID3() is reporting
errors in the file that have been worked around due to known bugs in
other programs. Some warnings may indicate that the data that is
returned is OK but that some data could not be extracted due to
errors in the file.
getID3() 2.0:
See above except errors are thrown (so you will only get one error).
Disclaimer
===========================================================================
getID3() has been tested on many systems, on many types of files,
under many operating systems, and is generally believe to be stable
and safe. That being said, there is still the chance there is an
undiscovered and/or unfixed bug that may potentially corrupt your
file, especially within the writing functions. By using getID3() you
agree that it's not my fault if any of your files are corrupted.
In fact, I'm not liable for anything :)
License
===========================================================================
GNU General Public License - see license.txt
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA.
FAQ:
Q: Can I use getID3() in my program? Do I need a commercial license?
A: You're generally free to use getID3 however you see fit. The only
case in which you would require a commercial license is if you're
selling your closed-source program that integrates getID3. If you
sell your program including a copy of getID3, that's fine as long
as you include a copy of the sourcecode when you sell it. Or you
can distribute your code without getID3 and say "download it from
getid3.sourceforge.net"
Future Plans
===========================================================================
* Writing support for Real
* Better support for MP4 container format
* Support for Matroska (www.matroska.org)
http://corecodec.com/modules.php?op=modload&name=PNphpBB2&file=viewtopic&t=227
* Scan for appended ID3v2 tag at end of file per ID3v2.4 specs (Section 5.0)
* Support for JPEG-2000 (http://www.morgan-multimedia.com/jpeg2000_overview.htm)
* Support for MOD (mod/stm/s3m/it/xm/mtm/ult/669)
* Support for ACE (thanks Vince)
* Support for Ogg other than Vorbis, Speex and OggFlac (ie. Ogg+Xvid)
* Ability to create Xing/LAME VBR header for VBR MP3s that are missing VBR header
* Ability to "clean" ID3v2 padding (replace invalid padding with valid padding)
* Warn if MP3s change version mid-stream (in full-scan mode)
* check for corrupt/broken mid-file MP3 streams in histogram scan
* Support for lossless-compression formats
(http://www.firstpr.com.au/audiocomp/lossless/#Links)
(http://compression.ca/act-sound.html)
(http://web.inter.nl.net/users/hvdh/lossless/lossless.htm)
* Support for RIFF-INFO chunks
* http://lotto.st-andrews.ac.uk/~njh/tag_interchange.html
(thanks Nick Humfrey <njhØsurgeradio*co*uk>)
* http://abcavi.narod.ru/sof/abcavi/infotags.htm
(thanks Kibi)
* Better support for Bink video
* http://www.hr/josip/DSP/AudioFile2.html
* http://www.pcisys.net/~melanson/codecs/
* Detect mp3PRO
* Support for PSD
* Support for JPC
* Support for JP2
* Support for JPX
* Support for JB2
* Support for IFF
* Support for ICO
* Support for ANI
* Support for EXE (comments, author, etc) (thanks p*quaedackersØplanet*nl)
* Support for DVD-IFO (region, subtitles, aspect ratio, etc)
(thanks p*quaedackersØplanet*nl)
* More complete support for SWF - parsing encapsulated MP3 and/or JPEG content
(thanks n8n8Øyahoo*com)
* Support for a2b
* Optional scan-through-frames for AVI verification
(thanks rockcohenØmassive-interactive*nl)
* Support for TTF (thanks infoØbutterflyx*com)
* Support for DSS (http://www.getid3.org/phpBB2/viewtopic.php?t=171)
* Support for SMAF (http://smaf-yamaha.com/what/demo.html)
http://www.getid3.org/phpBB2/viewtopic.php?t=182
* Support for AMR (http://www.getid3.org/phpBB2/viewtopic.php?t=195)
* Support for 3gpp (http://www.getid3.org/phpBB2/viewtopic.php?t=195)
* Support for ID4 (http://www.wackysoft.cjb.net grizlyY2KØhotmail*com)
* Parse XML data returned in Ogg comments
* Parse XML data from Quicktime SMIL metafiles (klausrathØmac*com)
* ID3v2 genre string creator function
* More complete parsing of JPG
* Support for all old-style ASF packets
* ASF/WMA/WMV tag writing
* Parse declared T??? ID3v2 text information frames, where appropriate
(thanks Christian Fritz for the idea)
* Recognize encoder:
http://www.guerillasoft.com/EncSpot2/index.html
http://ff123.net/identify.html
http://www.hydrogenaudio.org/?act=ST&f=16&t=9414
http://www.hydrogenaudio.org/?showtopic=11785
* Support for other OS/2 bitmap structures: Bitmap Array('BA'),
Color Icon('CI'), Color Pointer('CP'), Icon('IC'), Pointer ('PT')
http://netghost.narod.ru/gff/graphics/summary/os2bmp.htm
* Support for WavPack RAW mode
* ASF/WMA/WMV data packet parsing
* ID3v2FrameFlagsLookupTagAlter()
* ID3v2FrameFlagsLookupFileAlter()
* obey ID3v2 tag alter/preserve/discard rules
* http://www.geocities.com/SiliconValley/Sector/9654/Softdoc/Illyrium/Aolyr.htm
* proper checking for LINK/LNK frame validity in ID3v2 writing
* proper checking for ASPI-TLEN frame validity in ID3v2 writing
* proper checking for COMR frame validity in ID3v2 writing
* http://www.geocities.co.jp/SiliconValley-Oakland/3664/index.html
* decode GEOB ID3v2 structure as encoded by RealJukebox,
decode NCON ID3v2 structure as encoded by MusicMatch
(probably won't happen - the formats are proprietary)
Known Bugs/Issues in getID3() that may be fixed eventually
===========================================================================
* Cannot determine bitrate for MPEG video with VBR video data
(need documentation)
* Interlace/progressive cannot be determined for MPEG video
(need documentation)
* MIDI playtime is sometimes inaccurate
* AAC-RAW mode files cannot be identified
* WavPack-RAW mode files cannot be identified
* mp4 files report lots of "Unknown QuickTime atom type"
(need documentation)
* Encrypted ASF/WMA/WMV files warn about "unhandled GUID
ASF_Content_Encryption_Object"
* Bitrate split between audio and video cannot be calculated for
NSV, only the total bitrate. (need documentation)
* All Ogg formats (Vorbis, OggFLAC, Speex) are affected by the
problem of large VorbisComments spanning multiple Ogg pages, but
but only OggVorbis files can be processed with vorbiscomment.
* The version of "head" supplied with Mac OS 10.2.8 (maybe other
versions too) does only understands a single option (-n) and
therefore fails. getID3 ignores this and returns wrong md5_data.
Known Bugs/Issues in getID3() that cannot be fixed
--------------------------------------------------
* Files larger than 2GB (of any format) cannot be parsed by
getID3() due to limitations in the PHP filesystem functions
Known Bugs/Issues in other programs
-----------------------------------
* Winamp (up to v2.80 at least) does not support ID3v2.4 tags,
only ID3v2.3
see: http://forums.winamp.com/showthread.php?postid=387524
* Some versions of Helium2 (www.helium2.com) do not write
ID3v2.4-compliant Frame Sizes, even though the tag is marked
as ID3v2.4) (detected by getID3())
* MP3ext V3.3.17 places a non-compliant padding string at the end
of the ID3v2 header. This is supposedly fixed in v3.4b21 but
only if you manually add a registry key. This fix is not yet
confirmed. (detected by getID3())
* CDex v1.40 (fixed by v1.50b7) writes non-compliant Ogg comment
strings, supposed to be in the format "NAME=value" but actually
written just "value" (detected by getID3())
* Oggenc 0.9-rc3 flags the encoded file as ABR whether it's
actually ABR or VBR.
* iTunes (versions "X v2.0.3", "v3.0.1" are known-guilty, probably
other versions are too) writes ID3v2.3 comment tags using a
frame name 'COM ' which is not valid for ID3v2.3+ (it's an
ID3v2.2-style frame name) (detected by getID3())
* MP2enc does not encode mono CBR MP2 files properly (half speed
sound and double playtime)
* MP2enc does not encode mono VBR MP2 files properly (actually
encoded as stereo)
* tooLAME does not encode mono VBR MP2 files properly (actually
encoded as stereo)
* AACenc encodes files in VBR mode (actually ABR) even if CBR is
specified
* AAC/ADIF - bitrate_mode = cbr for vbr files
* LAME 3.90-3.92 prepends one frame of null data (space for the
LAME/VBR header, but it never gets written) when encoding in CBR
mode with the DLL
* Ahead Nero encodes TwinVQF with a DSIZ value (which is supposed
to be the filesize in bytes) of "0" for TwinVQF v1.0 and "1" for
TwinVQF v2.0 (detected by getID3())
* Ahead Nero encodes TwinVQF files 1 second shorter than they
should be
* AAC-ADTS files are always actually encoded VBR, even if CBR mode
is specified (the CBR-mode switches on the encoder enable ABR
mode, not CBR as such, but it's not possible to tell the
difference between such ABR files and true VBR)
* STREAMINFO.audio_signature in OggFLAC is always null. "The reason
it's like that is because there is no seeking support in
libOggFLAC yet, so it has no way to go back and write the
computed sum after encoding. Seeking support in Ogg FLAC is the
#1 item for the next release." - Josh Coalson (FLAC developer)
NOTE: getID3() will calculate md5_data in a method similar to
other file formats, but that value cannot be compared to the
md5_data value from FLAC data in a FLAC file format.
* STREAMINFO.audio_signature is not calculated in FLAC v0.3.0 &
v0.4.0 - getID3() will calculate md5_data in a method similar to
other file formats, but that value cannot be compared to the
md5_data value from FLAC v0.5.0+
* RioPort (various versions including 2.0 and 3.11) tags ID3v2 with
a WCOM frame that has no data portion
* Earlier versions of Coolplayer adds illegal ID3 tags to Ogg Vorbis
files, thus making them corrupt.
* Meracl ID3 Tag Writer v1.3.4 (and older) incorrectly truncates the
last byte of data from an MP3 file when appending a new ID3v1 tag.
(detected by getID3())
* Lossless-Audio files encoded with and without the -noseek switch
do actually differ internally and therefore cannot match md5_data
* iTunes has been known to append a new ID3v1 tag on the end of an
existing ID3v1 tag when ID3v2 tag is also present
(detected by getID3())
Reference material:
===========================================================================
[www.id3.org material now mirrored at http://id3lib.sourceforge.net/id3/]
* http://www.id3.org/id3v2.4.0-structure.txt
* http://www.id3.org/id3v2.4.0-frames.txt
* http://www.id3.org/id3v2.4.0-changes.txt
* http://www.id3.org/id3v2.3.0.txt
* http://www.id3.org/id3v2-00.txt
* http://www.id3.org/mp3frame.html
* http://minnie.tuhs.org/pipermail/mp3encoder/2001-January/001800.html <mathewhendry@hotmail.com>
* http://www.dv.co.yu/mpgscript/mpeghdr.htm
* http://www.mp3-tech.org/programmer/frame_header.html
* http://users.belgacom.net/gc247244/extra/tag.html
* http://gabriel.mp3-tech.org/mp3infotag.html
* http://www.id3.org/iso4217.html
* http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-1.TXT
* http://www.xiph.org/ogg/vorbis/doc/framing.html
* http://www.xiph.org/ogg/vorbis/doc/v-comment.html
* http://leknor.com/code/php/class.ogg.php.txt
* http://www.id3.org/iso639-2.html
* http://www.id3.org/lyrics3.html
* http://www.id3.org/lyrics3200.html
* http://www.psc.edu/general/software/packages/ieee/ieee.html
* http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html
* http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
* http://www.jmcgowan.com/avi.html
* http://www.wotsit.org/
* http://www.herdsoft.com/ti/davincie/davp3xo2.htm
* http://www.mathdogs.com/vorbis-illuminated/bitstream-appendix.html
* "Standard MIDI File Format" by Dustin Caldwell (from www.wotsit.org)
* http://midistudio.com/Help/GMSpecs_Patches.htm
* http://www.xiph.org/archives/vorbis/200109/0459.html
* http://www.replaygain.org/
* http://www.lossless-audio.com/
* http://download.microsoft.com/download/winmediatech40/Doc/1.0/WIN98MeXP/EN-US/ASF_Specification_v.1.0.exe
* http://mediaxw.sourceforge.net/files/doc/Active%20Streaming%20Format%20(ASF)%201.0%20Specification.pdf
* http://www.uni-jena.de/~pfk/mpp/sv8/
* http://jfaul.de/atl/
* http://www.uni-jena.de/~pfk/mpp/
* http://www.libpng.org/pub/png/spec/png-1.2-pdg.html
* http://www.real.com/devzone/library/creating/rmsdk/doc/rmff.htm
* http://www.fastgraph.com/help/bmp_os2_header_format.html
* http://netghost.narod.ru/gff/graphics/summary/os2bmp.htm
* http://flac.sourceforge.net/format.html
* http://www.research.att.com/projects/mpegaudio/mpeg2.html
* http://www.audiocoding.com/wiki/index.php?page=AAC
* http://libmpeg.org/mpeg4/doc/w2203tfs.pdf
* http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt
* http://developer.apple.com/techpubs/quicktime/qtdevdocs/RM/frameset.htm
* http://www.nullsoft.com/nsv/
* http://www.wotsit.org/download.asp?f=iso9660
* http://sandbox.mc.edu/~bennet/cs110/tc/tctod.html
* http://www.cdroller.com/htm/readdata.html
* http://www.speex.org/manual/node10.html
* http://www.harmony-central.com/Computer/Programming/aiff-file-format.doc
* http://www.faqs.org/rfcs/rfc2361.html
* http://ghido.shelter.ro/
* http://www.ebu.ch/tech_t3285.pdf
* http://www.sr.se/utveckling/tu/bwf
* http://ftp.aessc.org/pub/aes46-2002.pdf
* http://cartchunk.org:8080/
* http://www.broadcastpapers.com/radio/cartchunk01.htm
* http://www.hr/josip/DSP/AudioFile2.html
* http://home.attbi.com/~chris.bagwell/AudioFormats-11.html
* http://www.pure-mac.com/extkey.html
* http://cesnet.dl.sourceforge.net/sourceforge/bonkenc/bonk-binary-format-0.9.txt
* http://www.headbands.com/gspot/
* http://www.openswf.org/spec/SWFfileformat.html
* http://j-faul.virtualave.net/
* http://www.btinternet.com/~AnthonyJ/Atari/programming/avr_format.html
* http://cui.unige.ch/OSG/info/AudioFormats/ap11.html
* http://sswf.sourceforge.net/SWFalexref.html
* http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt
* http://www-lehre.informatik.uni-osnabrueck.de/~fbstark/diplom/docs/swf/Flash_Uncovered.htm
* http://developer.apple.com/quicktime/icefloe/dispatch012.html
* http://www.csdn.net/Dev/Format/graphics/PCD.htm
* http://tta.iszf.irk.ru/
* http://www.atsc.org/standards/a_52a.pdf
* http://www.alanwood.net/unicode/
* http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html
* http://www.its.msstate.edu/net/real/reports/config/tags.stats
* http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt
* http://brennan.young.net/Comp/LiveStage/things.html
* http://www.multiweb.cz/twoinches/MP3inside.htm
* http://www.geocities.co.jp/SiliconValley-Oakland/3664/alittle.html#GenreExtended
* http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/
* http://www.unicode.org/unicode/faq/utf_bom.html
* http://tta.corecodec.org/?menu=format
* http://www.scvi.net/nsvformat.htm
* http://pda.etsi.org/pda/queryform.asp

View file

@ -0,0 +1,59 @@
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | List of binary files required under Windows for some features and/or |
// | file formats. |
// +----------------------------------------------------------------------+
//
// $Id: readme.windows.txt,v 1.1 2006/12/03 21:12:11 ah Exp $
Windows users may want to download the latest version of the
"getID3()-WindowsSupport" package and extract it to c:\windows\system32
or another directory in the system path.
The package is required for these features:
* Shorten support.
* md5_data/sha1_data of Ogg Vorbis files
The package will also greatly speed up calculation of md5_data for other
files.
Included files:
=====================================================
Taken from http://www.cygwin.com/
* cygwin1.dll
Taken from http://unxutils.sourceforge.net/
* head.exe
* md5sum.exe
* tail.exe
Taken from http://ebible.org/mpj/software.htm
* sha1sum.exe
Taken from http://www.vorbis.com/download.psp
* vorbiscomment.exe
Taken from http://flac.sourceforge.net/download.html
* metaflac.exe
Taken from http://www.etree.org/shncom.html
* shorten.exe

View file

@ -1,17 +1,31 @@
///////////////////////////////////////////////////////////////// // +----------------------------------------------------------------------+
/// getID3() by James Heinrich <info@getid3.org> // // | PHP version 5 |
// available at http://getid3.sourceforge.net // // +----------------------------------------------------------------------+
// or http://www.getid3.org // // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
///////////////////////////////////////////////////////////////// // +----------------------------------------------------------------------+
// // // | This source file is subject to version 2 of the GPL license, |
// changelog.txt - part of getID3() // // | that is bundled with this package in the file license.txt and is |
// See readme.txt for more details // // | available through the world-wide-web at the following url: |
// /// // | http://www.gnu.org/copyleft/gpl.html |
///////////////////////////////////////////////////////////////// // +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | Dependencies |
// +----------------------------------------------------------------------+
//
// $Id: structure.txt,v 1.3 2006/11/02 10:47:59 ah Exp $
What does the returned data structure look like? What does the returned data structure look like?
================================================ ================================================
Hint: If you take a look at the nicely-formatted output of
/demos/demo.browse.php you can generally see where the data you want
is returned.
Note that what is described below is only a rough guide to what data Note that what is described below is only a rough guide to what data
is actually returned by getID3(), since the actual data returned is actually returned by getID3(), since the actual data returned
depends entirely on what data is in your file, what type of file it depends entirely on what data is in your file, what type of file it

View file

@ -0,0 +1,217 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | extension.cache.mysql.php |
// | MySQL Cache Extension. |
// | dependencies: getid3. |
// +----------------------------------------------------------------------+
//
// $Id: extension.cache.dbm.php,v 1.2 2006/11/02 10:47:59 ah Exp $
/**
* 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.dbm.php in /demo/)
*
* Normal getID3 usage (example):
*
* require_once 'getid3/getid3.php';
* $getid3 = new getid3;
* $getid3->encoding = 'UTF-8';
* try {
* $info1 = $getid3->Analyse('file1.flac');
* $info2 = $getid3->Analyse('file2.wv');
* ....
*
* getID3_cached usage:
*
* require_once 'getid3/getid3.php';
* require_once 'getid3/getid3/extension.cache.mysql.php';
* $getid3 = new getid3_cached_mysql('localhost', 'database', 'username', 'password');
* $getid3->encoding = 'UTF-8';
* try {
* $info1 = $getid3->analyse('file1.flac');
* $info2 = $getid3->analyse('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 function __construct($cache_type, $dbm_filename, $lock_filename) {
// Check for dba extension
if (!extension_loaded('dba')) {
throw new getid3_exception('PHP is not compiled with dba support, required to use DBM style cache.');
}
if (!in_array($cache_type, dba_handlers())) {
throw new getid3_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)) {
die('failed to create lock file: ' . $lock_filename);
}
}
// Open lock file for writing
if (!is_writeable($lock_filename)) {
die('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);
// Create dbm-file if needed
if (!file_exists($dbm_filename)) {
if (!touch($dbm_filename)) {
die('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) {
// Failed - create new dbm file
$this->dba = dba_open($dbm_filename, 'n', $cache_type);
if (!$this->dba) {
die('failed to create dbm file: ' . $dbm_filename);
}
// 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;
// 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();
}
parent::__construct();
}
public function __destruct() {
// Close dbm file
@dba_close($this->dba);
// Release exclusive lock
@flock($this->lock, LOCK_UN);
// Close lock file
@fclose($this->lock);
}
public function clear_cache() {
// Close dbm file
dba_close($this->dba);
// Create new dbm file
$this->dba = dba_open($this->dbm_filename, 'n', $this->cache_type);
if (!$this->dba) {
die('failed to clear cache/recreate dbm file: ' . $this->dbm_filename);
}
// Insert getID3 version number
dba_insert(getid3::VERSION, getid3::VERSION, $this->dba);
// Reregister shutdown function
register_shutdown_function(array($this, '__destruct'));
}
// 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;
}
}
?>

View file

@ -0,0 +1,177 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | extension.cache.mysql.php |
// | MySQL Cache Extension. |
// | dependencies: getid3. |
// +----------------------------------------------------------------------+
//
// $Id: extension.cache.mysql.php,v 1.2 2006/11/02 10:47:59 ah Exp $
/**
* 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';
* try {
* $info1 = $getid3->Analyse('file1.flac');
* $info2 = $getid3->Analyse('file2.wv');
* ....
*
* getID3_cached usage:
*
* require_once 'getid3/getid3.php';
* require_once 'getid3/getid3/extension.cache.mysql.php';
* $getid3 = new getid3_cached_mysql('localhost', 'database', 'username', 'password');
* $getid3->encoding = 'UTF-8';
* try {
* $info1 = $getid3->analyse('file1.flac');
* $info2 = $getid3->analyse('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 $cursor;
private $connection;
public function __construct($host, $database, $username, $password) {
// Check for mysql support
if (!function_exists('mysql_pconnect')) {
throw new getid3_exception('PHP not compiled with mysql support.');
}
// Connect to database
$this->connection = @mysql_pconnect($host, $username, $password);
if (!$this->connection) {
throw new getid3_exception('mysql_pconnect() failed - check permissions and spelling.');
}
// Select database
if (!@mysql_select_db($database, $this->connection)) {
throw new getid3_exception('Cannot use database '.$database);
}
// Create cache table if not exists
$this->create_table();
// Check version number and clear cache if changed
$this->cursor = mysql_query("SELECT `value` FROM `getid3_cache` WHERE (`filename` = '".getid3::VERSION."') AND (`filesize` = '-1') AND (`filetime` = '-1') AND (`analyzetime` = '-1')", $this->connection);
list($version) = @mysql_fetch_array($this->cursor);
if ($version != getid3::VERSION) {
$this->clear_cache();
}
parent::__construct();
}
public function clear_cache() {
$this->cursor = mysql_query("DELETE FROM `getid3_cache`", $this->connection);
$this->cursor = mysql_query("INSERT INTO `getid3_cache` VALUES ('".getid3::VERSION."', -1, -1, -1, '".getid3::VERSION."')", $this->connection);
}
public function Analyze($filename) {
if (file_exists($filename)) {
// Short-hands
$filetime = filemtime($filename);
$filesize = filesize($filename);
$filenam2 = mysql_escape_string($filename);
// Loopup file
$this->cursor = mysql_query("SELECT `value` FROM `getid3_cache` WHERE (`filename`='".$filenam2."') AND (`filesize`='".$filesize."') AND (`filetime`='".$filetime."')", $this->connection);
list($result) = @mysql_fetch_array($this->cursor);
// Hit
if ($result) {
return unserialize($result);
}
}
// Miss
$result = parent::Analyze($filename);
// Save result
if (file_exists($filename)) {
$res2 = mysql_escape_string(serialize($result));
$this->cursor = mysql_query("INSERT INTO `getid3_cache` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES ('".$filenam2."', '".$filesize."', '".$filetime."', '".time()."', '".$res2."')", $this->connection);
}
return $result;
}
// (re)create sql table
private function create_table($drop = false) {
$this->cursor = mysql_query("CREATE TABLE IF NOT EXISTS `getid3_cache` (
`filename` 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',
`value` TEXT NOT NULL,
PRIMARY KEY (`filename`,`filesize`,`filetime`)) TYPE=MyISAM", $this->connection);
echo mysql_error($this->connection);
}
}
?>

1598
modules/getid3/getid3.php Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,296 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.archive.gzip.php |
// | module for analyzing GZIP files |
// | dependencies: PHP compiled with zlib support (optional) |
// +----------------------------------------------------------------------+
// | Module originally written by Mike Mozolin <teddybearØmail*ru> |
// +----------------------------------------------------------------------+
//
// $Id: module.archive.gzip.php,v 1.4 2006/12/04 16:00:35 ah Exp $
class getid3_gzip extends getid3_handler
{
// public: Optional file list - disable for speed.
public $option_gzip_parse_contents = true; // decode gzipped files, if possible, and parse recursively (.tar.gz for example)
// Reads the gzip-file
function Analyze() {
$info = &$this->getid3->info;
$info['fileformat'] = 'gzip';
$start_length = 10;
$unpack_header = 'a1id1/a1id2/a1cmethod/a1flags/a4mtime/a1xflags/a1os';
//+---+---+---+---+---+---+---+---+---+---+
//|ID1|ID2|CM |FLG| MTIME |XFL|OS |
//+---+---+---+---+---+---+---+---+---+---+
@fseek($this->getid3->fp, 0);
$buffer = @fread($this->getid3->fp, $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];
$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;
}
}
$fpointer = 0;
$idx = 0;
for ($i = 0; $i < $num_members; $i++) {
if (strlen($arr_members[$i]) == 0) {
continue;
}
$info_gzip_member_header_idx = &$info['gzip']['member_header'][++$idx];
$buff = "\x1F\x8B\x08".$arr_members[$i];
$attr = unpack($unpack_header, substr($buff, 0, $start_length));
$info_gzip_member_header_idx['filemtime'] = getid3_lib::LittleEndian2Int($attr['mtime']);
$info_gzip_member_header_idx['raw']['id1'] = ord($attr['cmethod']);
$info_gzip_member_header_idx['raw']['id2'] = ord($attr['cmethod']);
$info_gzip_member_header_idx['raw']['cmethod'] = ord($attr['cmethod']);
$info_gzip_member_header_idx['raw']['os'] = ord($attr['os']);
$info_gzip_member_header_idx['raw']['xflags'] = ord($attr['xflags']);
$info_gzip_member_header_idx['raw']['flags'] = ord($attr['flags']);
$info_gzip_member_header_idx['flags']['crc16'] = (bool) ($info_gzip_member_header_idx['raw']['flags'] & 0x02);
$info_gzip_member_header_idx['flags']['extra'] = (bool) ($info_gzip_member_header_idx['raw']['flags'] & 0x04);
$info_gzip_member_header_idx['flags']['filename'] = (bool) ($info_gzip_member_header_idx['raw']['flags'] & 0x08);
$info_gzip_member_header_idx['flags']['comment'] = (bool) ($info_gzip_member_header_idx['raw']['flags'] & 0x10);
$info_gzip_member_header_idx['compression'] = $this->get_xflag_type($info_gzip_member_header_idx['raw']['xflags']);
$info_gzip_member_header_idx['os'] = $this->get_os_type($info_gzip_member_header_idx['raw']['os']);
if (!$info_gzip_member_header_idx['os']) {
$info['error'][] = 'Read error on gzip file';
return false;
}
$fpointer = 10;
$arr_xsubfield = array ();
// bit 2 - FLG.FEXTRA
//+---+---+=================================+
//| XLEN |...XLEN bytes of "extra field"...|
//+---+---+=================================+
if ($info_gzip_member_header_idx['flags']['extra']) {
$w_xlen = substr($buff, $fpointer, 2);
$xlen = getid3_lib::LittleEndian2Int($w_xlen);
$fpointer += 2;
$info_gzip_member_header_idx['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
$info_gzip_member_header_idx['filename'] = eregi_replace('.gz$', '', @$info['filename']);
if ($info_gzip_member_header_idx['flags']['filename']) {
while (true) {
if (ord($buff[$fpointer]) == 0) {
$fpointer++;
break;
}
$info_gzip_member_header_idx['filename'] .= $buff[$fpointer];
$fpointer++;
}
}
// bit 4 - FLG.FCOMMENT
//+===================================+
//|...file comment, zero-terminated...|
//+===================================+
if ($info_gzip_member_header_idx['flags']['comment']) {
while (true) {
if (ord($buff[$fpointer]) == 0) {
$fpointer++;
break;
}
$info_gzip_member_header_idx['comment'] .= $buff[$fpointer];
$fpointer++;
}
}
// bit 1 - FLG.FHCRC
//+---+---+
//| CRC16 |
//+---+---+
if ($info_gzip_member_header_idx['flags']['crc16']) {
$w_crc = substr($buff, $fpointer, 2);
$info_gzip_member_header_idx['crc16'] = getid3_lib::LittleEndian2Int($w_crc);
$fpointer += 2;
}
// bit 0 - FLG.FTEXT
//if ($info_gzip_member_header_idx['raw']['flags'] & 0x01) {
// Ignored...
//}
// bits 5, 6, 7 - reserved
$info_gzip_member_header_idx['crc32'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 8, 4));
$info_gzip_member_header_idx['filesize'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 4));
if ($this->option_gzip_parse_contents) {
// Try to inflate GZip
if (!function_exists('gzinflate')) {
$this->getid3->warning('PHP does not have zlib support - contents not parsed.');
return true;
}
$csize = 0;
$inflated = '';
$chkcrc32 = '';
$cdata = substr($buff, $fpointer);
$cdata = substr($cdata, 0, strlen($cdata) - 8);
$csize = strlen($cdata);
$inflated = gzinflate($cdata);
// Calculate CRC32 for inflated content
$info_gzip_member_header_idx['crc32_valid'] = (bool) (sprintf('%u', crc32($inflated)) == $info_gzip_member_header_idx['crc32']);
//// Analyse contents
// write content to temp file
if (($temp_file_name = tempnam('*', 'getID3')) === false) {
throw new getid3_exception('Unable to create temporary file.');
}
if ($tmp = fopen($temp_file_name, 'wb')) {
fwrite($tmp, $inflated);
fclose($tmp);
// clone getid3 - we want same settings
$clone = clone $this->getid3;
unset($clone->info);
try {
$clone->Analyze($temp_file_name);
$info_gzip_member_header_idx['parsed_content'] = $clone->info;
}
catch (getid3_exception $e) {
// unable to parse contents
}
unlink($temp_file_name);
}
// Unknown/unhandled format
else {
}
}
}
return true;
}
// Converts the OS type
public static 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 @$os_type[$key];
}
// Converts the eXtra FLags
public static function get_xflag_type($key) {
static $xflag_type = array (
'0' => 'unknown',
'2' => 'maximum compression',
'4' => 'fastest algorithm'
);
return @$xflag_type[$key];
}
}
?>

View file

@ -0,0 +1,105 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.archive.szip.php |
// | module for analyzing SZIP compressed files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.archive.szip.php,v 1.2 2006/11/02 10:48:00 ah Exp $
class getid3_szip extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$szip_rkau = fread($getid3->fp, 6);
// Magic bytes: 'SZ'."\x0A\x04"
$getid3->info['fileformat'] = 'szip';
$getid3->info['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($szip_rkau, 4, 1));
$getid3->info['szip']['minor_version'] = getid3_lib::BigEndian2Int(substr($szip_rkau, 5, 1));
while (!feof($getid3->fp)) {
$next_block_id = fread($getid3->fp, 2);
switch ($next_block_id) {
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.
fseek($getid3->fp, 4, SEEK_CUR);
break;
case 'BH':
$bh_header_bytes = getid3_lib::BigEndian2Int(fread($getid3->fp, 3));
$bh_header_data = fread($getid3->fp, $bh_header_bytes);
$bh_header_offset = 0;
while (strpos($bh_header_data, "\x00", $bh_header_offset) > 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)
$bh_data_array['filename'] = substr($bh_header_data, $bh_header_offset, strcspn($bh_header_data, "\x00"));
$bh_header_offset += (strlen($bh_data_array['filename']) + 1);
$bh_data_array['owner'] = substr($bh_header_data, $bh_header_offset, strcspn($bh_header_data, "\x00"));
$bh_header_offset += (strlen($bh_data_array['owner']) + 1);
$bh_data_array['group'] = substr($bh_header_data, $bh_header_offset, strcspn($bh_header_data, "\x00"));
$bh_header_offset += (strlen($bh_data_array['group']) + 1);
$bh_data_array['filelength'] = getid3_lib::BigEndian2Int(substr($bh_header_data, $bh_header_offset, 3));
$bh_header_offset += 3;
$bh_data_array['access_flags'] = getid3_lib::BigEndian2Int(substr($bh_header_data, $bh_header_offset, 2));
$bh_header_offset += 2;
$bh_data_array['creation_time'] = getid3_lib::BigEndian2Int(substr($bh_header_data, $bh_header_offset, 4));
$bh_header_offset += 4;
$bh_data_array['modification_time'] = getid3_lib::BigEndian2Int(substr($bh_header_data, $bh_header_offset, 4));
$bh_header_offset += 4;
$bh_data_array['access_time'] = getid3_lib::BigEndian2Int(substr($bh_header_data, $bh_header_offset, 4));
$bh_header_offset += 4;
$getid3->info['szip']['BH'][] = $bh_data_array;
}
break;
default:
break 2;
}
}
return true;
}
}
?>

View file

@ -0,0 +1,231 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.archive.tar.php |
// | module for analyzing TAR files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
// | Module originally written by Mike Mozolin <teddybearØmail*ru> |
// +----------------------------------------------------------------------+
//
// $Id: module.archive.tar.php,v 1.2 2006/11/02 10:48:00 ah Exp $
class getid3_tar extends getid3_handler
{
function Analyze() {
$info = &$this->getid3->info;
$info['fileformat'] = 'tar';
$fp = $this->getid3->fp;
fseek($fp, 0);
$unpack_header = 'a100fname/a8mode/a8uid/a8gid/a12size/a12mtime/a8chksum/a1typflag/a100lnkname/a6magic/a2ver/a32uname/a32gname/a8devmaj/a8devmin/a155/prefix';
$null_512k = str_repeat("\0", 512); // end-of-file marker
$already_warned = false;
while (!feof($fp)) {
$buffer = fread($fp, 512);
// check the block
$checksum = 0;
for ($i = 0; $i < 148; $i++) {
$checksum += ord(substr($buffer, $i, 1));
}
for ($i = 148; $i < 156; $i++) {
$checksum += ord(' ');
}
for ($i = 156; $i < 512; $i++) {
$checksum += ord(substr($buffer, $i, 1));
}
$attr = unpack($unpack_header, $buffer);
$name = trim(@$attr['fname']);
$mode = octdec(trim(@$attr['mode']));
$uid = octdec(trim(@$attr['uid']));
$gid = octdec(trim(@$attr['gid']));
$size = octdec(trim(@$attr['size']));
$mtime = octdec(trim(@$attr['mtime']));
$chksum = octdec(trim(@$attr['chksum']));
$typflag = trim(@$attr['typflag']);
$lnkname = trim(@$attr['lnkname']);
$magic = trim(@$attr['magic']);
$ver = trim(@$attr['ver']);
$uname = trim(@$attr['uname']);
$gname = trim(@$attr['gname']);
$devmaj = octdec(trim(@$attr['devmaj']));
$devmin = octdec(trim(@$attr['devmin']));
$prefix = trim(@$attr['prefix']);
// EOF Found
if (($checksum == 256) && ($chksum == 0)) {
break;
}
// Check if filename if 7bit as spec requires
if (!$already_warned) {
for ($i = 0; $i < strlen($name); $i++) {
if ($name{$i} < chr(32) || $name{$i} > chr(127)) {
$this->getid3->warning('Some filenames contains extended characters, which breaks the tar specifation. This is not uncommon, but you will have to handle the character encoding for filenames yourself.');
$already_warned = true;
break;
}
}
}
if ($prefix) {
$name = $prefix.'/'.$name;
}
if ((preg_match('#/$#', $name)) && !$name) {
$typeflag = 5;
}
// If it's the end of the tar-file...
if ($buffer == $null_512k) {
break;
}
// Protect against tar-files with garbage at the end
if ($name == '') {
break;
}
$info['tar']['file_details'][$name] = array (
'name' => $name,
'mode_raw' => $mode,
'mode' => getid3_tar::display_perms($mode),
'uid' => $uid,
'gid' => $gid,
'size' => $size,
'mtime' => $mtime,
'chksum' => $chksum,
'typeflag' => getid3_tar::get_flag_type($typflag),
'linkname' => $lnkname,
'magic' => $magic,
'version' => $ver,
'uname' => $uname,
'gname' => $gname,
'devmajor' => $devmaj,
'devminor' => $devmin
);
// Skip the next chunk
fseek($fp, $size, SEEK_CUR);
// Throw away padding
if ($size % 512) {
fseek($fp, 512 - $diff, SEEK_CUR);
}
}
return true;
}
// Parses the file mode to file permissions
public static 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' : '-');
// 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;
}
// Converts the file type
public static 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 @$flag_types[$typflag];
}
}
?>

View file

@ -0,0 +1,510 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.archive.zip.php |
// | Module for analyzing pkZip files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.archive.zip.php,v 1.4 2006/11/02 10:48:00 ah Exp $
class getid3_zip extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->info['zip'] = array ();
$info_zip = &$getid3->info['zip'];
$getid3->info['fileformat'] = 'zip';
$info_zip['encoding'] = 'ISO-8859-1';
$info_zip['files'] = array ();
$info_zip['compressed_size'] = $info_zip['uncompressed_size'] = $info_zip['entries_count'] = 0;
$eocd_search_data = '';
$eocd_search_counter = 0;
while ($eocd_search_counter++ < 512) {
fseek($getid3->fp, -128 * $eocd_search_counter, SEEK_END);
$eocd_search_data = fread($getid3->fp, 128).$eocd_search_data;
if (strstr($eocd_search_data, 'PK'."\x05\x06")) {
$eocd_position = strpos($eocd_search_data, 'PK'."\x05\x06");
fseek($getid3->fp, (-128 * $eocd_search_counter) + $eocd_position, SEEK_END);
$info_zip['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory();
fseek($getid3->fp, $info_zip['end_central_directory']['directory_offset'], SEEK_SET);
$info_zip['entries_count'] = 0;
while ($central_directoryentry = $this->ZIPparseCentralDirectory($getid3->fp)) {
$info_zip['central_directory'][] = $central_directoryentry;
$info_zip['entries_count']++;
$info_zip['compressed_size'] += $central_directoryentry['compressed_size'];
$info_zip['uncompressed_size'] += $central_directoryentry['uncompressed_size'];
if ($central_directoryentry['uncompressed_size'] > 0) {
$info_zip['files'] = getid3_zip::array_merge_clobber($info_zip['files'], getid3_zip::CreateDeepArray($central_directoryentry['filename'], '/', $central_directoryentry['uncompressed_size']));
}
}
if ($info_zip['entries_count'] == 0) {
throw new getid3_exception('No Central Directory entries found (truncated file?)');
}
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';
}
return true;
}
}
if ($this->getZIPentriesFilepointer()) {
// 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'] > ($getid3->info['filesize'] - 46 - 22)) {
throw new getid3_exception('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 ('.($getid3->info['filesize'] - 46 - 22).' bytes)');
}
throw new getid3_exception('Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete');
}
//throw new getid3_exception('Cannot find End Of Central Directory (truncated file?)');
}
private function getZIPHeaderFilepointerTopDown() {
// shortcut
$getid3 = $this->getid3;
$getid3->info['fileformat'] = 'zip';
$getid3->info['zip'] = array ();
$info_zip['compressed_size'] = $info_zip['uncompressed_size'] = $info_zip['entries_count'] = 0;
rewind($getid3->fp);
while ($fileentry = $this->ZIPparseLocalFileHeader()) {
$info_zip['entries'][] = $fileentry;
$info_zip['entries_count']++;
}
if ($info_zip['entries_count'] == 0) {
throw new getid3_exception('No Local File Header entries found');
}
$info_zip['entries_count'] = 0;
while ($central_directoryentry = $this->ZIPparseCentralDirectory($getid3->fp)) {
$info_zip['central_directory'][] = $central_directoryentry;
$info_zip['entries_count']++;
$info_zip['compressed_size'] += $central_directoryentry['compressed_size'];
$info_zip['uncompressed_size'] += $central_directoryentry['uncompressed_size'];
}
if ($info_zip['entries_count'] == 0) {
throw new getid3_exception('No Central Directory entries found (truncated file?)');
}
if ($eocd = $this->ZIPparseEndOfCentralDirectory()) {
$info_zip['end_central_directory'] = $eocd;
} else {
throw new getid3_exception('No End Of Central Directory entry found (truncated file?)');
}
if (!@$info_zip['end_central_directory']['comment']) {
$info_zip['comments']['comment'][] = $info_zip['end_central_directory']['comment'];
}
return true;
}
private function getZIPentriesFilepointer() {
// shortcut
$getid3 = $this->getid3;
$getid3->info['zip'] = array ();
$info_zip['compressed_size'] = $info_zip['uncompressed_size'] = $info_zip['entries_count'] = 0;
rewind($getid3->fp);
while ($fileentry = $this->ZIPparseLocalFileHeader($getid3->fp)) {
$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) {
throw new getid3_exception('No Local File Header entries found');
}
return true;
}
private function ZIPparseLocalFileHeader() {
// shortcut
$getid3 = $this->getid3;
$local_file_header['offset'] = ftell($getid3->fp);
$zip_local_file_header = fread($getid3->fp, 30);
$local_file_header['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($zip_local_file_header, 0, 4));
// Invalid Local File Header Signature
if ($local_file_header['raw']['signature'] != 0x04034B50) {
fseek($getid3->fp, $local_file_header['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
return false;
}
getid3_lib::ReadSequence('LittleEndian2Int', $local_file_header['raw'], $zip_local_file_header, 4,
array (
'extract_version' => 2,
'general_flags' => 2,
'compression_method' => 2,
'last_mod_file_time' => 2,
'last_mod_file_date' => 2,
'crc_32' => 2,
'compressed_size' => 2,
'uncompressed_size' => 2,
'filename_length' => 2,
'extra_field_length' => 2
)
);
$local_file_header['extract_version'] = sprintf('%1.1f', $local_file_header['raw']['extract_version'] / 10);
$local_file_header['host_os'] = $this->ZIPversionOSLookup(($local_file_header['raw']['extract_version'] & 0xFF00) >> 8);
$local_file_header['compression_method'] = $this->ZIPcompressionMethodLookup($local_file_header['raw']['compression_method']);
$local_file_header['compressed_size'] = $local_file_header['raw']['compressed_size'];
$local_file_header['uncompressed_size'] = $local_file_header['raw']['uncompressed_size'];
$local_file_header['flags'] = $this->ZIPparseGeneralPurposeFlags($local_file_header['raw']['general_flags'], $local_file_header['raw']['compression_method']);
$local_file_header['last_modified_timestamp'] = $this->DOStime2UNIXtime($local_file_header['raw']['last_mod_file_date'], $local_file_header['raw']['last_mod_file_time']);
$filename_extra_field_length = $local_file_header['raw']['filename_length'] + $local_file_header['raw']['extra_field_length'];
if ($filename_extra_field_length > 0) {
$zip_local_file_header .= fread($getid3->fp, $filename_extra_field_length);
if ($local_file_header['raw']['filename_length'] > 0) {
$local_file_header['filename'] = substr($zip_local_file_header, 30, $local_file_header['raw']['filename_length']);
}
if ($local_file_header['raw']['extra_field_length'] > 0) {
$local_file_header['raw']['extra_field_data'] = substr($zip_local_file_header, 30 + $local_file_header['raw']['filename_length'], $local_file_header['raw']['extra_field_length']);
}
}
$local_file_header['data_offset'] = ftell($getid3->fp);
fseek($getid3->fp, $local_file_header['raw']['compressed_size'], SEEK_CUR);
if ($local_file_header['flags']['data_descriptor_used']) {
$data_descriptor = fread($getid3->fp, 12);
getid3_lib::ReadSequence('LittleEndian2Int', $local_file_header['data_descriptor'], $data_descriptor, 0,
array (
'crc_32' => 4,
'compressed_size' => 4,
'uncompressed_size' => 4
)
);
}
return $local_file_header;
}
private function ZIPparseCentralDirectory() {
// shortcut
$getid3 = $this->getid3;
$central_directory['offset'] = ftell($getid3->fp);
$zip_central_directory = fread($getid3->fp, 46);
$central_directory['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($zip_central_directory, 0, 4));
// invalid Central Directory Signature
if ($central_directory['raw']['signature'] != 0x02014B50) {
fseek($getid3->fp, $central_directory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
return false;
}
getid3_lib::ReadSequence('LittleEndian2Int', $central_directory['raw'], $zip_central_directory, 4,
array (
'create_version' => 2,
'extract_version' => 2,
'general_flags' => 2,
'compression_method' => 2,
'last_mod_file_time' => 2,
'last_mod_file_date' => 2,
'crc_32' => 4,
'compressed_size' => 4,
'uncompressed_size' => 4,
'filename_length' => 2,
'extra_field_length' => 2,
'file_comment_length' => 2,
'disk_number_start' => 2,
'internal_file_attrib' => 2,
'external_file_attrib' => 4,
'local_header_offset' => 4
)
);
$central_directory['entry_offset'] = $central_directory['raw']['local_header_offset'];
$central_directory['create_version'] = sprintf('%1.1f', $central_directory['raw']['create_version'] / 10);
$central_directory['extract_version'] = sprintf('%1.1f', $central_directory['raw']['extract_version'] / 10);
$central_directory['host_os'] = $this->ZIPversionOSLookup(($central_directory['raw']['extract_version'] & 0xFF00) >> 8);
$central_directory['compression_method'] = $this->ZIPcompressionMethodLookup($central_directory['raw']['compression_method']);
$central_directory['compressed_size'] = $central_directory['raw']['compressed_size'];
$central_directory['uncompressed_size'] = $central_directory['raw']['uncompressed_size'];
$central_directory['flags'] = $this->ZIPparseGeneralPurposeFlags($central_directory['raw']['general_flags'], $central_directory['raw']['compression_method']);
$central_directory['last_modified_timestamp'] = $this->DOStime2UNIXtime($central_directory['raw']['last_mod_file_date'], $central_directory['raw']['last_mod_file_time']);
$filename_extra_field_comment_length = $central_directory['raw']['filename_length'] + $central_directory['raw']['extra_field_length'] + $central_directory['raw']['file_comment_length'];
if ($filename_extra_field_comment_length > 0) {
$filename_extra_field_comment = fread($getid3->fp, $filename_extra_field_comment_length);
if ($central_directory['raw']['filename_length'] > 0) {
$central_directory['filename']= substr($filename_extra_field_comment, 0, $central_directory['raw']['filename_length']);
}
if ($central_directory['raw']['extra_field_length'] > 0) {
$central_directory['raw']['extra_field_data'] = substr($filename_extra_field_comment, $central_directory['raw']['filename_length'], $central_directory['raw']['extra_field_length']);
}
if ($central_directory['raw']['file_comment_length'] > 0) {
$central_directory['file_comment'] = substr($filename_extra_field_comment, $central_directory['raw']['filename_length'] + $central_directory['raw']['extra_field_length'], $central_directory['raw']['file_comment_length']);
}
}
return $central_directory;
}
private function ZIPparseEndOfCentralDirectory() {
// shortcut
$getid3 = $this->getid3;
$end_of_central_directory['offset'] = ftell($getid3->fp);
$zip_end_of_central_directory = fread($getid3->fp, 22);
$end_of_central_directory['signature'] = getid3_lib::LittleEndian2Int(substr($zip_end_of_central_directory, 0, 4));
// invalid End Of Central Directory Signature
if ($end_of_central_directory['signature'] != 0x06054B50) {
fseek($getid3->fp, $end_of_central_directory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
return false;
}
getid3_lib::ReadSequence('LittleEndian2Int', $end_of_central_directory, $zip_end_of_central_directory, 4,
array (
'disk_number_current' => 2,
'disk_number_start_directory' => 2,
'directory_entries_this_disk' => 2,
'directory_entries_total' => 2,
'directory_size' => 4,
'directory_offset' => 4,
'comment_length' => 2
)
);
if ($end_of_central_directory['comment_length'] > 0) {
$end_of_central_directory['comment'] = fread($getid3->fp, $end_of_central_directory['comment_length']);
}
return $end_of_central_directory;
}
public static function ZIPparseGeneralPurposeFlags($flag_bytes, $compression_method) {
$parsed_flags['encrypted'] = (bool)($flag_bytes & 0x0001);
switch ($compression_method) {
case 6:
$parsed_flags['dictionary_size'] = (($flag_bytes & 0x0002) ? 8192 : 4096);
$parsed_flags['shannon_fano_trees'] = (($flag_bytes & 0x0004) ? 3 : 2);
break;
case 8:
case 9:
switch (($flag_bytes & 0x0006) >> 1) {
case 0:
$parsed_flags['compression_speed'] = 'normal';
break;
case 1:
$parsed_flags['compression_speed'] = 'maximum';
break;
case 2:
$parsed_flags['compression_speed'] = 'fast';
break;
case 3:
$parsed_flags['compression_speed'] = 'superfast';
break;
}
break;
}
$parsed_flags['data_descriptor_used'] = (bool)($flag_bytes & 0x0008);
return $parsed_flags;
}
public static function ZIPversionOSLookup($index) {
static $lookup = 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'
);
return (isset($lookup[$index]) ? $lookup[$index] : '[unknown]');
}
public static function ZIPcompressionMethodLookup($index) {
static $lookup = 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 => 'PKWARE Date Compression Library Imploding'
);
return (isset($lookup[$index]) ? $lookup[$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);
*/
return gmmktime(($DOStime & 0xF800) >> 11, ($DOStime & 0x07E0) >> 5, ($DOStime & 0x001F) * 2, ($DOSdate & 0x01E0) >> 5, $DOSdate & 0x001F, (($DOSdate & 0xFE00) >> 9) + 1980);
}
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] = getid3_zip::array_merge_clobber($newarray[$key], $val);
} else {
$newarray[$key] = $val;
}
}
return $newarray;
}
public static function CreateDeepArray($array_path, $separator, $value) {
// assigns $value to a nested array path:
// $foo = getid3_lib::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 ($array_path{0} == $separator) {
$array_path = substr($array_path, 1);
}
if (($pos = strpos($array_path, $separator)) !== false) {
return array (substr($array_path, 0, $pos) => getid3_zip::CreateDeepArray(substr($array_path, $pos + 1), $separator, $value));
}
return array ($array_path => $value);
}
}
?>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,574 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.archive.gzip.php |
// | module for analyzing GZIP files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
// | FLV module by Seth Kaufman <sethØwhirl-i.gig*com> |
// | |
// | * version 0.1 (26 June 2005) |
// | |
// | minor modifications by James Heinrich <infoØgetid3*org> |
// | * version 0.1.1 (15 July 2005) |
// | |
// | Support for On2 VP6 codec and meta information by |
// | Steve Webster <steve.websterØfeaturecreep*com> |
// | * version 0.2 (22 February 2006) |
// | |
// | Modified to not read entire file into memory |
// | by James Heinrich <infoØgetid3*org> |
// | * version 0.3 (15 June 2006) |
// | |
// | Modifications by Allan Hansen <ahØartemis*dk> |
// | Adapted module for PHP5 and getID3 2.0.0. |
// +----------------------------------------------------------------------+
//
// $Id: module.audio-video.flv.php,v 1.7 2006/11/10 11:20:12 ah Exp $
class getid3_flv extends getid3_handler
{
const TAG_AUDIO = 8;
const TAG_VIDEO = 9;
const TAG_META = 18;
const VIDEO_H263 = 2;
const VIDEO_SCREEN = 3;
const VIDEO_VP6 = 4;
public function Analyze()
{
$info = &$this->getid3->info;
$info['flv'] = array ();
$info_flv = &$info['flv'];
fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
$flv_data_length = $info['avdataend'] - $info['avdataoffset'];
$flv_header = fread($this->getid3->fp, 5);
$info['fileformat'] = 'flv';
$info_flv['header']['signature'] = substr($flv_header, 0, 3);
$info_flv['header']['version'] = getid3_lib::BigEndian2Int(substr($flv_header, 3, 1));
$type_flags = getid3_lib::BigEndian2Int(substr($flv_header, 4, 1));
$info_flv['header']['hasAudio'] = (bool) ($type_flags & 0x04);
$info_flv['header']['hasVideo'] = (bool) ($type_flags & 0x01);
$frame_size_data_length = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 4));
$flv_header_frame_length = 9;
if ($frame_size_data_length > $flv_header_frame_length) {
fseek($this->getid3->fp, $frame_size_data_length - $flv_header_frame_length, SEEK_CUR);
}
$duration = 0;
while ((ftell($this->getid3->fp) + 1) < $info['avdataend']) {
$this_tag_header = fread($this->getid3->fp, 16);
$previous_tag_length = getid3_lib::BigEndian2Int(substr($this_tag_header, 0, 4));
$tag_type = getid3_lib::BigEndian2Int(substr($this_tag_header, 4, 1));
$data_length = getid3_lib::BigEndian2Int(substr($this_tag_header, 5, 3));
$timestamp = getid3_lib::BigEndian2Int(substr($this_tag_header, 8, 3));
$last_header_byte = getid3_lib::BigEndian2Int(substr($this_tag_header, 15, 1));
$next_offset = ftell($this->getid3->fp) - 1 + $data_length;
switch ($tag_type) {
case getid3_flv::TAG_AUDIO:
if (!isset($info_flv['audio']['audioFormat'])) {
$info_flv['audio']['audioFormat'] = $last_header_byte & 0x07;
$info_flv['audio']['audioRate'] = ($last_header_byte & 0x30) / 0x10;
$info_flv['audio']['audioSampleSize'] = ($last_header_byte & 0x40) / 0x40;
$info_flv['audio']['audioType'] = ($last_header_byte & 0x80) / 0x80;
}
break;
case getid3_flv::TAG_VIDEO:
if (!isset($info_flv['video']['videoCodec'])) {
$info_flv['video']['videoCodec'] = $last_header_byte & 0x07;
$flv_video_header = fread($this->getid3->fp, 11);
if ($info_flv['video']['videoCodec'] != getid3_flv::VIDEO_VP6) {
$picture_size_type = (getid3_lib::BigEndian2Int(substr($flv_video_header, 3, 2))) >> 7;
$picture_size_type = $picture_size_type & 0x0007;
$info_flv['header']['videoSizeType'] = $picture_size_type;
switch ($picture_size_type) {
case 0:
$picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 5, 2));
$picture_size_enc <<= 1;
$info['video']['resolution_x'] = ($picture_size_enc & 0xFF00) >> 8;
$picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 6, 2));
$picture_size_enc <<= 1;
$info['video']['resolution_y'] = ($picture_size_enc & 0xFF00) >> 8;
break;
case 1:
$picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 5, 4));
$picture_size_enc <<= 1;
$info['video']['resolution_x'] = ($picture_size_enc & 0xFFFF0000) >> 16;
$picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 7, 4));
$picture_size_enc <<= 1;
$info['video']['resolution_y'] = ($picture_size_enc & 0xFFFF0000) >> 16;
break;
case 2:
$info['video']['resolution_x'] = 352;
$info['video']['resolution_y'] = 288;
break;
case 3:
$info['video']['resolution_x'] = 176;
$info['video']['resolution_y'] = 144;
break;
case 4:
$info['video']['resolution_x'] = 128;
$info['video']['resolution_y'] = 96;
break;
case 5:
$info['video']['resolution_x'] = 320;
$info['video']['resolution_y'] = 240;
break;
case 6:
$info['video']['resolution_x'] = 160;
$info['video']['resolution_y'] = 120;
break;
default:
$info['video']['resolution_x'] = 0;
$info['video']['resolution_y'] = 0;
break;
}
}
}
break;
// Meta tag
case getid3_flv::TAG_META:
fseek($this->getid3->fp, -1, SEEK_CUR);
$reader = new AMFReader(new AMFStream(fread($this->getid3->fp, $data_length)));
$event_name = $reader->readData();
$info['meta'][$event_name] = $reader->readData();
unset($reader);
$info['video']['frame_rate'] = @$info['meta']['onMetaData']['framerate'];
$info['video']['resolution_x'] = @$info['meta']['onMetaData']['width'];
$info['video']['resolution_y'] = @$info['meta']['onMetaData']['height'];
break;
default:
// noop
break;
}
if ($timestamp > $duration) {
$duration = $timestamp;
}
fseek($this->getid3->fp, $next_offset, SEEK_SET);
}
if ($info['playtime_seconds'] = $duration / 1000) {
$info['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds'];
}
if ($info_flv['header']['hasAudio']) {
$info['audio']['codec'] = $this->FLVaudioFormat($info_flv['audio']['audioFormat']);
$info['audio']['sample_rate'] = $this->FLVaudioRate($info_flv['audio']['audioRate']);
$info['audio']['bits_per_sample'] = $this->FLVaudioBitDepth($info_flv['audio']['audioSampleSize']);
$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 (@$info_flv['header']['hasVideo']) {
$info['video']['codec'] = $this->FLVvideoCodec($info_flv['video']['videoCodec']);
$info['video']['dataformat'] = 'flv';
$info['video']['lossless'] = false;
}
return true;
}
public static function FLVaudioFormat($id) {
static $lookup = array(
0 => 'uncompressed',
1 => 'ADPCM',
2 => 'mp3',
5 => 'Nellymoser 8kHz mono',
6 => 'Nellymoser',
);
return (@$lookup[$id] ? @$lookup[$id] : false);
}
public static function FLVaudioRate($id) {
static $lookup = array(
0 => 5500,
1 => 11025,
2 => 22050,
3 => 44100,
);
return (@$lookup[$id] ? @$lookup[$id] : false);
}
public static function FLVaudioBitDepth($id) {
static $lookup = array(
0 => 8,
1 => 16,
);
return (@$lookup[$id] ? @$lookup[$id] : false);
}
public static function FLVvideoCodec($id) {
static $lookup = array(
getid3_flv::VIDEO_H263 => 'Sorenson H.263',
getid3_flv::VIDEO_SCREEN => 'Screen video',
getid3_flv::VIDEO_VP6 => 'On2 VP6',
);
return (@$lookup[$id] ? @$lookup[$id] : false);
}
}
class AMFStream
{
public $bytes;
public $pos;
public function AMFStream($bytes) {
$this->bytes = $bytes;
$this->pos = 0;
}
public function readByte() {
return getid3_lib::BigEndian2Int(substr($this->bytes, $this->pos++, 1));
}
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 readDouble() {
return getid3_lib::BigEndian2Float($this->read(8));
}
public function readUTF() {
$length = $this->readInt();
return $this->read($length);
}
public function readLongUTF() {
$length = $this->readLong();
return $this->read($length);
}
public function read($length) {
$val = substr($this->bytes, $this->pos, $length);
$this->pos += $length;
return $val;
}
public function peekByte() {
$pos = $this->pos;
$val = $this->readByte();
$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;
public function __construct($stream) {
$this->stream = $stream;
}
public function readData() {
$value = null;
$type = $this->stream->readByte();
switch($type) {
// Double
case 0:
$value = $this->readDouble();
break;
// Boolean
case 1:
$value = $this->readBoolean();
break;
// String
case 2:
$value = $this->readString();
break;
// Object
case 3:
$value = $this->readObject();
break;
// null
case 6:
return null;
break;
// Mixed array
case 8:
$value = $this->readMixedArray();
break;
// Array
case 10:
$value = $this->readArray();
break;
// Date
case 11:
$value = $this->readDate();
break;
// Long string
case 13:
$value = $this->readLongString();
break;
// XML (handled as string)
case 15:
$value = $this->readXML();
break;
// Typed object (handled as object)
case 16:
$value = $this->readTypedObject();
break;
// Long string
default:
$value = '(unknown or unsupported data type)';
break;
}
return $value;
}
public function readDouble() {
return $this->stream->readDouble();
}
public function readBoolean() {
return $this->stream->readByte() == 1;
}
public function readString() {
return $this->stream->readUTF();
}
public function readObject() {
// Get highest numerical index - ignored
$highestIndex = $this->stream->readLong();
$data = array();
while ($key = $this->stream->readUTF()) {
// Mixed array record ends with empty string (0x00 0x00) and 0x09
if (($key == '') && ($this->stream->peekByte() == 0x09)) {
// Consume byte
$this->stream->readByte();
break;
}
$data[$key] = $this->readData();
}
return $data;
}
public function readMixedArray() {
// Get highest numerical index - ignored
$highestIndex = $this->stream->readLong();
$data = array();
while ($key = $this->stream->readUTF()) {
// Mixed array record ends with empty string (0x00 0x00) and 0x09
if (($key == '') && ($this->stream->peekByte() == 0x09)) {
// Consume byte
$this->stream->readByte();
break;
}
if (is_numeric($key)) {
$key = (float) $key;
}
$data[$key] = $this->readData();
}
return $data;
}
public function readArray() {
$length = $this->stream->readLong();
$data = array();
for ($i = 0; $i < count($length); $i++) {
$data[] = $this->readData();
}
return $data;
}
public function readDate() {
$timestamp = $this->stream->readDouble();
$timezone = $this->stream->readInt();
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();
}
}
?>

View file

@ -0,0 +1,324 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio-video.mpeg.php |
// | Module for analyzing MPEG files |
// | dependencies: module.audio.mp3.php |
// +----------------------------------------------------------------------+
//
// $Id: module.audio-video.mpeg.php,v 1.3 2006/11/02 10:48:00 ah Exp $
class getid3_mpeg extends getid3_handler
{
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() {
$getid3 = $this->getid3;
$getid3->info['mpeg']['video']['raw'] = array ();
$info_mpeg_video = &$getid3->info['mpeg']['video'];
$info_mpeg_video_raw = &$info_mpeg_video['raw'];
$getid3->info['video'] = array ();
$info_video = &$getid3->info['video'];
$getid3->include_module('audio.mp3');
if ($getid3->info['avdataend'] <= $getid3->info['avdataoffset']) {
throw new getid3_exception('"avdataend" ('.$getid3->info['avdataend'].') is unexpectedly less-than-or-equal-to "avdataoffset" ('.$getid3->info['avdataoffset'].')');
}
$getid3->info['fileformat'] = 'mpeg';
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$mpeg_stream_data = fread($getid3->fp, min(100000, $getid3->info['avdataend'] - $getid3->info['avdataoffset']));
$mpeg_stream_data_length = strlen($mpeg_stream_data);
$video_chunk_offset = 0;
while (substr($mpeg_stream_data, $video_chunk_offset++, 4) !== getid3_mpeg::VIDEO_SEQUENCE_HEADER) {
if ($video_chunk_offset >= $mpeg_stream_data_length) {
throw new getid3_exception('Could not find start of video block in the first 100,000 bytes (or before end of file) - this might not be an MPEG-video file?');
}
}
// Start code 32 bits
// horizontal frame size 12 bits
// vertical frame size 12 bits
// pixel aspect ratio 4 bits
// frame rate 4 bits
// bitrate 18 bits
// marker bit 1 bit
// VBV buffer size 10 bits
// constrained parameter flag 1 bit
// intra quant. matrix flag 1 bit
// intra quant. matrix values 512 bits (present if matrix flag == 1)
// non-intra quant. matrix flag 1 bit
// non-intra quant. matrix values 512 bits (present if matrix flag == 1)
$info_video['dataformat'] = 'mpeg';
$video_chunk_offset += (strlen(getid3_mpeg::VIDEO_SEQUENCE_HEADER) - 1);
$frame_size_dword = getid3_lib::BigEndian2Int(substr($mpeg_stream_data, $video_chunk_offset, 3));
$video_chunk_offset += 3;
$aspect_ratio_frame_rate_dword = getid3_lib::BigEndian2Int(substr($mpeg_stream_data, $video_chunk_offset, 1));
$video_chunk_offset += 1;
$assorted_information = getid3_lib::BigEndian2Bin(substr($mpeg_stream_data, $video_chunk_offset, 4));
$video_chunk_offset += 4;
$info_mpeg_video_raw['framesize_horizontal'] = ($frame_size_dword & 0xFFF000) >> 12; // 12 bits for horizontal frame size
$info_mpeg_video_raw['framesize_vertical'] = ($frame_size_dword & 0x000FFF); // 12 bits for vertical frame size
$info_mpeg_video_raw['pixel_aspect_ratio'] = ($aspect_ratio_frame_rate_dword & 0xF0) >> 4;
$info_mpeg_video_raw['frame_rate'] = ($aspect_ratio_frame_rate_dword & 0x0F);
$info_mpeg_video['framesize_horizontal'] = $info_mpeg_video_raw['framesize_horizontal'];
$info_mpeg_video['framesize_vertical'] = $info_mpeg_video_raw['framesize_vertical'];
$info_mpeg_video['pixel_aspect_ratio'] = $this->MPEGvideoAspectRatioLookup($info_mpeg_video_raw['pixel_aspect_ratio']);
$info_mpeg_video['pixel_aspect_ratio_text'] = $this->MPEGvideoAspectRatioTextLookup($info_mpeg_video_raw['pixel_aspect_ratio']);
$info_mpeg_video['frame_rate'] = $this->MPEGvideoFramerateLookup($info_mpeg_video_raw['frame_rate']);
$info_mpeg_video_raw['bitrate'] = bindec(substr($assorted_information, 0, 18));
$info_mpeg_video_raw['marker_bit'] = (bool)bindec($assorted_information{18});
$info_mpeg_video_raw['vbv_buffer_size'] = bindec(substr($assorted_information, 19, 10));
$info_mpeg_video_raw['constrained_param_flag'] = (bool)bindec($assorted_information{29});
$info_mpeg_video_raw['intra_quant_flag'] = (bool)bindec($assorted_information{30});
if ($info_mpeg_video_raw['intra_quant_flag']) {
// read 512 bits
$info_mpeg_video_raw['intra_quant'] = getid3_lib::BigEndian2Bin(substr($mpeg_stream_data, $video_chunk_offset, 64));
$video_chunk_offset += 64;
$info_mpeg_video_raw['non_intra_quant_flag'] = (bool)bindec($info_mpeg_video_raw['intra_quant']{511});
$info_mpeg_video_raw['intra_quant'] = bindec($assorted_information{31}).substr(getid3_lib::BigEndian2Bin(substr($mpeg_stream_data, $video_chunk_offset, 64)), 0, 511);
if ($info_mpeg_video_raw['non_intra_quant_flag']) {
$info_mpeg_video_raw['non_intra_quant'] = substr($mpeg_stream_data, $video_chunk_offset, 64);
$video_chunk_offset += 64;
}
} else {
$info_mpeg_video_raw['non_intra_quant_flag'] = (bool)bindec($assorted_information{31});
if ($info_mpeg_video_raw['non_intra_quant_flag']) {
$info_mpeg_video_raw['non_intra_quant'] = substr($mpeg_stream_data, $video_chunk_offset, 64);
$video_chunk_offset += 64;
}
}
if ($info_mpeg_video_raw['bitrate'] == 0x3FFFF) { // 18 set bits
$getid3->warning('This version of getID3() 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['framesize_horizontal'];
$info_video['resolution_y'] = $info_mpeg_video['framesize_vertical'];
$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;
//0x000001B3 begins the sequence_header of every MPEG video stream.
//But in MPEG-2, this header must immediately be followed by an
//extension_start_code (0x000001B5) with a sequence_extension ID (1).
//(This extension contains all the additional MPEG-2 stuff.)
//MPEG-1 doesn't have this extension, so that's a sure way to tell the
//difference between MPEG-1 and MPEG-2 video streams.
$info_video['codec'] = substr($mpeg_stream_data, $video_chunk_offset, 4) == getid3_mpeg::VIDEO_EXTENSION_START ? 'MPEG-2' : 'MPEG-1';
$audio_chunk_offset = 0;
while (true) {
while (substr($mpeg_stream_data, $audio_chunk_offset++, 4) !== getid3_mpeg::AUDIO_START) {
if ($audio_chunk_offset >= $mpeg_stream_data_length) {
break 2;
}
}
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
// make copy of info
$dummy = $getid3->info;
// clone getid3 - better safe than sorry
$clone = clone $this->getid3;
// check
$mp3 = new getid3_mp3($clone);
if ($mp3->decodeMPEGaudioHeader($getid3->fp, ($audio_chunk_offset + 3) + 8 + $i, $dummy, false)) {
$getid3->info = $dummy;
$getid3->info['audio']['bitrate_mode'] = 'cbr';
$getid3->info['audio']['lossless'] = false;
break 2;
}
// destroy copy
unset($dummy);
}
}
// Temporary hack to account for interleaving overhead:
if (!empty($info_video['bitrate']) && !empty($getid3->info['audio']['bitrate'])) {
$getid3->info['playtime_seconds'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / ($info_video['bitrate'] + $getid3->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 patter
// Use interpolated lookup tables to approximately guess how much is overhead, because
// playtime is calculated as filesize / total-bitrate
$getid3->info['playtime_seconds'] *= $this->MPEGsystemNonOverheadPercentage($info_video['bitrate'], $getid3->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;
//}
//$getid3->info['playtime_seconds'] *= $multiplier;
//$getid3->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) {
$getid3->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.');
}
}
return true;
}
public static function MPEGsystemNonOverheadPercentage($video_bitrate, $audio_bitrate) {
$overhead_percentage = 0;
$audio_bitrate = max(min($audio_bitrate / 1000, 384), 32); // limit to range of 32kbps - 384kbps (should be only legal bitrates, but maybe VBR?)
$video_bitrate = max(min($video_bitrate / 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)
static $overhead_multiplier_by_bitrate = array (
32 => array (0, 0.9676287944368530, 0.9802276264360310, 0.9844916183244460, 0.9852821845179940),
48 => array (0, 0.9779100089209830, 0.9787770035359320, 0.9846738664076130, 0.9852683013799960),
56 => array (0, 0.9731249855367600, 0.9776624308938040, 0.9832606361852130, 0.9843922606633340),
64 => array (0, 0.9755642683275760, 0.9795256705493390, 0.9836573009193170, 0.9851122539404470),
96 => array (0, 0.9788025247497290, 0.9798553314148700, 0.9822956869792560, 0.9834815119124690),
128 => array (0, 0.9816940050925480, 0.9821675936072120, 0.9829756927470870, 0.9839763420152050),
160 => array (0, 0.9825894094561180, 0.9820913399073960, 0.9823907143253970, 0.9832821783651570),
192 => array (0, 0.9832038474336260, 0.9825731694317960, 0.9821028622712400, 0.9828262076447620),
224 => array (0, 0.9836516298538770, 0.9824718601823890, 0.9818302180625380, 0.9823735101626480),
256 => array (0, 0.9845863022094920, 0.9837229411967540, 0.9824521662210830, 0.9828645172100790),
320 => array (0, 0.9849565280263180, 0.9837683142805110, 0.9822885275960400, 0.9824424382727190),
384 => array (0, 0.9856094774357600, 0.9844573394432720, 0.9825970399837330, 0.9824673808303890)
);
$bitrate_to_use_min = $bitrate_to_use_max = $previous_bitrate = 32;
foreach ($overhead_multiplier_by_bitrate as $key => $value) {
if ($audio_bitrate >= $previous_bitrate) {
$bitrate_to_use_min = $previous_bitrate;
}
if ($audio_bitrate < $key) {
$bitrate_to_use_max = $key;
break;
}
$previous_bitrate = $key;
}
$factor_a = ($bitrate_to_use_max - $audio_bitrate) / ($bitrate_to_use_max - $bitrate_to_use_min);
$video_bitrate_log10 = log10($video_bitrate);
$video_factor_min1 = $overhead_multiplier_by_bitrate[$bitrate_to_use_min][floor($video_bitrate_log10)];
$video_factor_min2 = $overhead_multiplier_by_bitrate[$bitrate_to_use_max][floor($video_bitrate_log10)];
$video_factor_max1 = $overhead_multiplier_by_bitrate[$bitrate_to_use_min][ceil($video_bitrate_log10)];
$video_factor_max2 = $overhead_multiplier_by_bitrate[$bitrate_to_use_max][ceil($video_bitrate_log10)];
$factor_v = $video_bitrate_log10 - floor($video_bitrate_log10);
$overhead_percentage = $video_factor_min1 * $factor_a * $factor_v;
$overhead_percentage += $video_factor_min2 * (1 - $factor_a) * $factor_v;
$overhead_percentage += $video_factor_max1 * $factor_a * (1 - $factor_v);
$overhead_percentage += $video_factor_max2 * (1 - $factor_a) * (1 - $factor_v);
return $overhead_percentage;
}
public static function MPEGvideoFramerateLookup($raw_frame_rate) {
$lookup = array (0, 23.976, 24, 25, 29.97, 30, 50, 59.94, 60);
return (float)(isset($lookup[$raw_frame_rate]) ? $lookup[$raw_frame_rate] : 0);
}
public static function MPEGvideoAspectRatioLookup($raw_aspect_ratio) {
$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 (float)(isset($lookup[$raw_aspect_ratio]) ? $lookup[$raw_aspect_ratio] : 0);
}
public static function MPEGvideoAspectRatioTextLookup($raw_aspect_ratio) {
$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[$raw_aspect_ratio]) ? $lookup[$raw_aspect_ratio] : '');
}
}
?>

View file

@ -0,0 +1,210 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio-video.nsv.php |
// | module for analyzing Nullsoft NSV files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio-video.nsv.php,v 1.3 2006/11/02 10:48:00 ah Exp $
class getid3_nsv extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->info['fileformat'] = 'nsv';
$getid3->info['audio']['dataformat'] = 'nsv';
$getid3->info['video']['dataformat'] = 'nsv';
$getid3->info['audio']['lossless'] = false;
$getid3->info['video']['lossless'] = false;
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$nsv_header = fread($getid3->fp, 4);
switch ($nsv_header) {
case 'NSVs':
$this->getNSVsHeader();
break;
case 'NSVf':
if ($this->getNSVfHeader()) {
$this->getNSVsHeader($getid3->info['nsv']['NSVf']['header_length']);
}
break;
default:
throw new getid3_exception('Expecting "NSVs" or "NSVf" at offset '.$getid3->info['avdataoffset'].', found "'.$nsv_header.'"');
break;
}
if (!isset($getid3->info['nsv']['NSVf'])) {
$getid3->warning('NSVf header not present - cannot calculate playtime or bitrate');
}
return true;
}
private function getNSVsHeader($file_offset = 0) {
$getid3 = $this->getid3;
fseek($getid3->fp, $file_offset, SEEK_SET);
$nsvs_header = fread($getid3->fp, 28);
$getid3->info['nsv']['NSVs'] = array ();
$info_nsv_NSVs = &$getid3->info['nsv']['NSVs'];
$info_nsv_NSVs['identifier'] = substr($nsvs_header, 0, 4);
if ($info_nsv_NSVs['identifier'] != 'NSVs') {
throw new getid3_exception('expected "NSVs" at offset ('.$file_offset.'), found "'.$info_nsv_NSVs['identifier'].'" instead');
}
$info_nsv_NSVs['offset'] = $file_offset;
getid3_lib::ReadSequence('LittleEndian2Int', $info_nsv_NSVs, $nsvs_header, 4,
array (
'video_codec' => -4, // string
'audio_codec' => -4, // string
'resolution_x' => 2,
'resolution_y' => 2,
'framerate_index' => 1,
)
);
if ($info_nsv_NSVs['audio_codec'] == 'PCM ') {
getid3_lib::ReadSequence('LittleEndian2Int', $info_nsv_NSVs, $nsvs_header, 24,
array (
'bits_channel' => 1,
'channels' => 1,
'sample_rate' => 2
)
);
$getid3->info['audio']['sample_rate'] = $info_nsv_NSVs['sample_rate'];
}
$getid3->info['video']['resolution_x'] = $info_nsv_NSVs['resolution_x'];
$getid3->info['video']['resolution_y'] = $info_nsv_NSVs['resolution_y'];
$info_nsv_NSVs['frame_rate'] = getid3_nsv::NSVframerateLookup($info_nsv_NSVs['framerate_index']);
$getid3->info['video']['frame_rate'] = $info_nsv_NSVs['frame_rate'];
$getid3->info['video']['bits_per_sample'] = 24;
$getid3->info['video']['pixel_aspect_ratio'] = (float)1;
return true;
}
private function getNSVfHeader($file_offset = 0, $get_toc_offsets=false) {
$getid3 = $this->getid3;
fseek($getid3->fp, $file_offset, SEEK_SET);
$nsvf_header = fread($getid3->fp, 28);
$getid3->info['nsv']['NSVf'] = array ();
$info_nsv_NSVf = &$getid3->info['nsv']['NSVf'];
$info_nsv_NSVf['identifier'] = substr($nsvf_header, 0, 4);
if ($info_nsv_NSVf['identifier'] != 'NSVf') {
throw new getid3_exception('expected "NSVf" at offset ('.$file_offset.'), found "'.$info_nsv_NSVf['identifier'].'" instead');
}
$getid3->info['nsv']['NSVs']['offset'] = $file_offset;
getid3_lib::ReadSequence('LittleEndian2Int', $info_nsv_NSVf, $nsvf_header, 4,
array (
'header_length' => 4,
'file_size' => 4,
'playtime_ms' => 4,
'meta_size' => 4,
'TOC_entries_1' => 4,
'TOC_entries_2' => 4
)
);
if ($info_nsv_NSVf['playtime_ms'] == 0) {
throw new getid3_exception('Corrupt NSV file: NSVf.playtime_ms == zero');
}
if ($info_nsv_NSVf['file_size'] > $getid3->info['avdataend']) {
$getid3->warning('truncated file - NSVf header indicates '.$info_nsv_NSVf['file_size'].' bytes, file actually '.$getid3->info['avdataend'].' bytes');
}
$nsvf_header .= fread($getid3->fp, $info_nsv_NSVf['meta_size'] + (4 * $info_nsv_NSVf['TOC_entries_1']) + (4 * $info_nsv_NSVf['TOC_entries_2']));
$nsvf_headerlength = strlen($nsvf_header);
$info_nsv_NSVf['metadata'] = substr($nsvf_header, 28, $info_nsv_NSVf['meta_size']);
$offset = 28 + $info_nsv_NSVf['meta_size'];
if ($get_toc_offsets) {
$toc_counter = 0;
while ($toc_counter < $info_nsv_NSVf['TOC_entries_1']) {
if ($toc_counter < $info_nsv_NSVf['TOC_entries_1']) {
$info_nsv_NSVf['TOC_1'][$toc_counter] = getid3_lib::LittleEndian2Int(substr($nsvf_header, $offset, 4));
$offset += 4;
$toc_counter++;
}
}
}
if (trim($info_nsv_NSVf['metadata']) != '') {
$info_nsv_NSVf['metadata'] = str_replace('`', "\x01", $info_nsv_NSVf['metadata']);
$comment_pair_array = explode("\x01".' ', $info_nsv_NSVf['metadata']);
foreach ($comment_pair_array as $comment_pair) {
if (strstr($comment_pair, '='."\x01")) {
list($key, $value) = explode('='."\x01", $comment_pair, 2);
$getid3->info['nsv']['comments'][strtolower($key)][] = trim(str_replace("\x01", '', $value));
}
}
}
$getid3->info['playtime_seconds'] = $info_nsv_NSVf['playtime_ms'] / 1000;
$getid3->info['bitrate'] = ($info_nsv_NSVf['file_size'] * 8) / $getid3->info['playtime_seconds'];
return true;
}
public static function NSVframerateLookup($frame_rate_index) {
if ($frame_rate_index <= 127) {
return (float)$frame_rate_index;
}
static $lookup = array (
129 => 29.970,
131 => 23.976,
133 => 14.985,
197 => 59.940,
199 => 47.952
);
return (isset($lookup[$frame_rate_index]) ? $lookup[$frame_rate_index] : false);
}
}
?>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,591 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio-video.real.php |
// | Module for analyzing Real Audio/Video files |
// | dependencies: module.audio-video.riff.php |
// +----------------------------------------------------------------------+
//
// $Id: module.audio-video.real.php,v 1.4 2006/11/02 10:48:00 ah Exp $
class getid3_real extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->include_module('audio-video.riff');
$getid3->info['fileformat'] = 'real';
$getid3->info['bitrate'] = 0;
$getid3->info['playtime_seconds'] = 0;
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$chunk_counter = 0;
while (ftell($getid3->fp) < $getid3->info['avdataend']) {
$chunk_data = fread($getid3->fp, 8);
$chunk_name = substr($chunk_data, 0, 4);
$chunk_size = getid3_lib::BigEndian2Int(substr($chunk_data, 4, 4));
if ($chunk_name == '.ra'."\xFD") {
$chunk_data .= fread($getid3->fp, $chunk_size - 8);
if ($this->ParseOldRAheader(substr($chunk_data, 0, 128), $getid3->info['real']['old_ra_header'])) {
$getid3->info['audio']['dataformat'] = 'real';
$getid3->info['audio']['lossless'] = false;
$getid3->info['audio']['sample_rate'] = $getid3->info['real']['old_ra_header']['sample_rate'];
$getid3->info['audio']['bits_per_sample'] = $getid3->info['real']['old_ra_header']['bits_per_sample'];
$getid3->info['audio']['channels'] = $getid3->info['real']['old_ra_header']['channels'];
$getid3->info['playtime_seconds'] = 60 * ($getid3->info['real']['old_ra_header']['audio_bytes'] / $getid3->info['real']['old_ra_header']['bytes_per_minute']);
$getid3->info['audio']['bitrate'] = 8 * ($getid3->info['real']['old_ra_header']['audio_bytes'] / $getid3->info['playtime_seconds']);
$getid3->info['audio']['codec'] = $this->RealAudioCodecFourCClookup($getid3->info['real']['old_ra_header']['fourcc'], $getid3->info['audio']['bitrate']);
foreach ($getid3->info['real']['old_ra_header']['comments'] as $key => $value_array) {
if (strlen(trim($value_array[0])) > 0) {
$getid3->info['real']['comments'][$key][] = trim($value_array[0]);
}
}
return true;
}
throw new getid3_exception('There was a problem parsing this RealAudio file. Please submit it for analysis to http://www.getid3.org/upload/ or info@getid3.org');
}
$getid3->info['real']['chunks'][$chunk_counter] = array ();
$info_real_chunks_current_chunk = &$getid3->info['real']['chunks'][$chunk_counter];
$info_real_chunks_current_chunk['name'] = $chunk_name;
$info_real_chunks_current_chunk['offset'] = ftell($getid3->fp) - 8;
$info_real_chunks_current_chunk['length'] = $chunk_size;
if (($info_real_chunks_current_chunk['offset'] + $info_real_chunks_current_chunk['length']) > $getid3->info['avdataend']) {
$getid3->warning('Chunk "'.$info_real_chunks_current_chunk['name'].'" at offset '.$info_real_chunks_current_chunk['offset'].' claims to be '.$info_real_chunks_current_chunk['length'].' bytes long, which is beyond end of file');
return false;
}
if ($chunk_size > (getid3::FREAD_BUFFER_SIZE + 8)) {
$chunk_data .= fread($getid3->fp, getid3::FREAD_BUFFER_SIZE - 8);
fseek($getid3->fp, $info_real_chunks_current_chunk['offset'] + $chunk_size, SEEK_SET);
} elseif(($chunk_size - 8) > 0) {
$chunk_data .= fread($getid3->fp, $chunk_size - 8);
}
$offset = 8;
switch ($chunk_name) {
case '.RMF': // RealMedia File Header
$info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
$offset += 2;
switch ($info_real_chunks_current_chunk['object_version']) {
case 0:
$info_real_chunks_current_chunk['file_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4));
$offset += 4;
$info_real_chunks_current_chunk['headers_count'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4));
$offset += 4;
break;
default:
//$getid3->warning('Expected .RMF-object_version to be "0", actual value is "'.$info_real_chunks_current_chunk['object_version'].'" (should not be a problem)';
break;
}
break;
case 'PROP': // Properties Header
$info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
$offset += 2;
if ($info_real_chunks_current_chunk['object_version'] == 0) {
getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset,
array (
'max_bit_rate' => 4,
'avg_bit_rate' => 4,
'max_packet_size' => 4,
'avg_packet_size' => 4,
'num_packets' => 4,
'duration' => 4,
'preroll' => 4,
'index_offset' => 4,
'data_offset' => 4,
'num_streams' => 2,
'flags_raw' => 2
)
);
$offset += 40;
$getid3->info['playtime_seconds'] = $info_real_chunks_current_chunk['duration'] / 1000;
if ($info_real_chunks_current_chunk['duration'] > 0) {
$getid3->info['bitrate'] += $info_real_chunks_current_chunk['avg_bit_rate'];
}
$info_real_chunks_current_chunk['flags']['save_enabled'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0001);
$info_real_chunks_current_chunk['flags']['perfect_play'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0002);
$info_real_chunks_current_chunk['flags']['live_broadcast'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0004);
}
break;
case 'MDPR': // Media Properties Header
$info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
$offset += 2;
if ($info_real_chunks_current_chunk['object_version'] == 0) {
getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset,
array (
'stream_number' => 2,
'max_bit_rate' => 4,
'avg_bit_rate' => 4,
'max_packet_size' => 4,
'avg_packet_size' => 4,
'start_time' => 4,
'preroll' => 4,
'duration' => 4,
'stream_name_size' => 1
)
);
$offset += 31;
$info_real_chunks_current_chunk['stream_name'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['stream_name_size']);
$offset += $info_real_chunks_current_chunk['stream_name_size'];
$info_real_chunks_current_chunk['mime_type_size'] = getid3_lib::BigEndian2Int($chunk_data{$offset++});
$info_real_chunks_current_chunk['mime_type'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['mime_type_size']);
$offset += $info_real_chunks_current_chunk['mime_type_size'];
$info_real_chunks_current_chunk['type_specific_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4));
$offset += 4;
$info_real_chunks_current_chunk['type_specific_data'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['type_specific_len']);
$offset += $info_real_chunks_current_chunk['type_specific_len'];
$info_real_chunks_current_chunk_typespecificdata = &$info_real_chunks_current_chunk['type_specific_data'];
switch ($info_real_chunks_current_chunk['mime_type']) {
case 'video/x-pn-realvideo':
case 'video/x-pn-multirate-realvideo':
// http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html
$info_real_chunks_current_chunk['video_info'] = array ();
$info_real_chunks_current_chunk_video_info = &$info_real_chunks_current_chunk['video_info'];
getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk_video_info, $info_real_chunks_current_chunk_typespecificdata, 0,
array (
'dwSize' => 4,
'fourcc1' => -4,
'fourcc2' => -4,
'width' => 2,
'height' => 2,
'bits_per_sample' => 2,
'IGNORE-unknown1' => 2,
'IGNORE-unknown2' => 2,
'frames_per_second' => 2,
'IGNORE-unknown3' => 2,
'IGNORE-unknown4' => 2,
'IGNORE-unknown5' => 2,
'IGNORE-unknown6' => 2,
'IGNORE-unknown7' => 2,
'IGNORE-unknown8' => 2,
'IGNORE-unknown9' => 2
)
);
$info_real_chunks_current_chunk_video_info['codec'] = getid3_riff::RIFFfourccLookup($info_real_chunks_current_chunk_video_info['fourcc2']);
$getid3->info['video']['resolution_x'] = $info_real_chunks_current_chunk_video_info['width'];
$getid3->info['video']['resolution_y'] = $info_real_chunks_current_chunk_video_info['height'];
$getid3->info['video']['frame_rate'] = (float)$info_real_chunks_current_chunk_video_info['frames_per_second'];
$getid3->info['video']['codec'] = $info_real_chunks_current_chunk_video_info['codec'];
$getid3->info['video']['bits_per_sample'] = $info_real_chunks_current_chunk_video_info['bits_per_sample'];
break;
case 'audio/x-pn-realaudio':
case 'audio/x-pn-multirate-realaudio':
$this->ParseOldRAheader($info_real_chunks_current_chunk_typespecificdata, $info_real_chunks_current_chunk['parsed_audio_data']);
$getid3->info['audio']['sample_rate'] = $info_real_chunks_current_chunk['parsed_audio_data']['sample_rate'];
$getid3->info['audio']['bits_per_sample'] = $info_real_chunks_current_chunk['parsed_audio_data']['bits_per_sample'];
$getid3->info['audio']['channels'] = $info_real_chunks_current_chunk['parsed_audio_data']['channels'];
if (!empty($getid3->info['audio']['dataformat'])) {
foreach ($getid3->info['audio'] as $key => $value) {
if ($key != 'streams') {
$getid3->info['audio']['streams'][$info_real_chunks_current_chunk['stream_number']][$key] = $value;
}
}
}
break;
case 'logical-fileinfo':
$info_real_chunks_current_chunk['logical_fileinfo']['logical_fileinfo_length'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 0, 4));
// $info_real_chunks_current_chunk['logical_fileinfo']['IGNORE-unknown1'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 4, 4));
$info_real_chunks_current_chunk['logical_fileinfo']['num_tags'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 8, 4));
// $info_real_chunks_current_chunk['logical_fileinfo']['IGNORE-unknown2'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 12, 4));
break;
}
if (empty($getid3->info['playtime_seconds'])) {
$getid3->info['playtime_seconds'] = max($getid3->info['playtime_seconds'], ($info_real_chunks_current_chunk['duration'] + $info_real_chunks_current_chunk['start_time']) / 1000);
}
if ($info_real_chunks_current_chunk['duration'] > 0) {
switch ($info_real_chunks_current_chunk['mime_type']) {
case 'audio/x-pn-realaudio':
case 'audio/x-pn-multirate-realaudio':
$getid3->info['audio']['bitrate'] = (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate'];
$getid3->info['audio']['codec'] = $this->RealAudioCodecFourCClookup($info_real_chunks_current_chunk['parsed_audio_data']['fourcc'], $getid3->info['audio']['bitrate']);
$getid3->info['audio']['dataformat'] = 'real';
$getid3->info['audio']['lossless'] = false;
break;
case 'video/x-pn-realvideo':
case 'video/x-pn-multirate-realvideo':
$getid3->info['video']['bitrate'] = (isset($getid3->info['video']['bitrate']) ? $getid3->info['video']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate'];
$getid3->info['video']['bitrate_mode'] = 'cbr';
$getid3->info['video']['dataformat'] = 'real';
$getid3->info['video']['lossless'] = false;
$getid3->info['video']['pixel_aspect_ratio'] = (float)1;
break;
case 'audio/x-ralf-mpeg4-generic':
$getid3->info['audio']['bitrate'] = (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate'];
$getid3->info['audio']['codec'] = 'RealAudio Lossless';
$getid3->info['audio']['dataformat'] = 'real';
$getid3->info['audio']['lossless'] = true;
break;
}
$getid3->info['bitrate'] = (isset($getid3->info['video']['bitrate']) ? $getid3->info['video']['bitrate'] : 0) + (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0);
}
}
break;
case 'CONT': // Content Description Header (text comments)
$info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
$offset += 2;
if ($info_real_chunks_current_chunk['object_version'] == 0) {
$info_real_chunks_current_chunk['title_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
$offset += 2;
$info_real_chunks_current_chunk['title'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['title_len']);
$offset += $info_real_chunks_current_chunk['title_len'];
$info_real_chunks_current_chunk['artist_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
$offset += 2;
$info_real_chunks_current_chunk['artist'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['artist_len']);
$offset += $info_real_chunks_current_chunk['artist_len'];
$info_real_chunks_current_chunk['copyright_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
$offset += 2;
$info_real_chunks_current_chunk['copyright'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['copyright_len']);
$offset += $info_real_chunks_current_chunk['copyright_len'];
$info_real_chunks_current_chunk['comment_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
$offset += 2;
$info_real_chunks_current_chunk['comment'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['comment_len']);
$offset += $info_real_chunks_current_chunk['comment_len'];
foreach (array ('title'=>'title', 'artist'=>'artist', 'copyright'=>'copyright', 'comment'=>'comment') as $key => $val) {
if ($info_real_chunks_current_chunk[$key]) {
$getid3->info['real']['comments'][$val][] = trim($info_real_chunks_current_chunk[$key]);
}
}
}
break;
case 'DATA': // Data Chunk Header
// do nothing
break;
case 'INDX': // Index Section Header
$info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2));
$offset += 2;
if ($info_real_chunks_current_chunk['object_version'] == 0) {
getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset,
array (
'num_indices' => 4,
'stream_number' => 2,
'next_index_header' => 4
)
);
$offset += 10;
if ($info_real_chunks_current_chunk['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)
fseek($getid3->fp, $info_real_chunks_current_chunk['next_index_header'], SEEK_SET);
}
}
break;
default:
$getid3->warning('Unhandled RealMedia chunk "'.$chunk_name.'" at offset '.$info_real_chunks_current_chunk['offset']);
break;
}
$chunk_counter++;
}
if (!empty($getid3->info['audio']['streams'])) {
$getid3->info['audio']['bitrate'] = 0;
foreach ($getid3->info['audio']['streams'] as $key => $value_array) {
$getid3->info['audio']['bitrate'] += $value_array['bitrate'];
}
}
return true;
}
public static function ParseOldRAheader($old_ra_header_data, &$parsed_array) {
// http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html
$parsed_array = array ();
$parsed_array['magic'] = substr($old_ra_header_data, 0, 4);
if ($parsed_array['magic'] != '.ra'."\xFD") {
return false;
}
$parsed_array['version1'] = getid3_lib::BigEndian2Int(substr($old_ra_header_data, 4, 2));
if ($parsed_array['version1'] < 3) {
return false;
}
if ($parsed_array['version1'] == 3) {
$parsed_array['fourcc1'] = '.ra3';
$parsed_array['bits_per_sample'] = 16; // hard-coded for old versions?
$parsed_array['sample_rate'] = 8000; // hard-coded for old versions?
getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 6,
array (
'header_size' => 2,
'channels' => 2, // always 1 (?)
'IGNORE-unknown1' => 2,
'IGNORE-unknown2' => 2,
'IGNORE-unknown3' => 2,
'bytes_per_minute' => 2,
'audio_bytes' => 4,
)
);
$parsed_array['comments_raw'] = substr($old_ra_header_data, 22, $parsed_array['header_size'] - 22 + 1); // not including null terminator
$comment_offset = 0;
foreach (array ('title', 'artist', 'copyright') as $name) {
$comment_length = getid3_lib::BigEndian2Int($parsed_array['comments_raw']{$comment_offset++});
$parsed_array['comments'][$name][]= substr($parsed_array['comments_raw'], $comment_offset, $comment_length);
$comment_offset += $comment_length;
}
$comment_offset++; // final null terminator (?)
$comment_offset++; // fourcc length (?) should be 4
$parsed_array['fourcc'] = substr($old_ra_header_data, 23 + $comment_offset, 4);
} elseif ($parsed_array['version1'] <= 5) {
getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 6,
array (
'IGNORE-unknown1' => 2,
'fourcc1' => -4,
'file_size' => 4,
'version2' => 2,
'header_size' => 4,
'codec_flavor_id' => 2,
'coded_frame_size' => 4,
'audio_bytes' => 4,
'bytes_per_minute' => 4,
'IGNORE-unknown5' => 4,
'sub_packet_h' => 2,
'frame_size' => 2,
'sub_packet_size' => 2,
'IGNORE-unknown6' => 2
)
);
switch ($parsed_array['version1']) {
case 4:
getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 48,
array (
'sample_rate' => 2,
'IGNORE-unknown8' => 2,
'bits_per_sample' => 2,
'channels' => 2,
'length_fourcc2' => 1,
'fourcc2' => -4,
'length_fourcc3' => 1,
'fourcc3' => -4,
'IGNORE-unknown9' => 1,
'IGNORE-unknown10' => 2,
)
);
$parsed_array['comments_raw'] = substr($old_ra_header_data, 69, $parsed_array['header_size'] - 69 + 16);
$comment_offset = 0;
foreach (array ('title', 'artist', 'copyright') as $name) {
$comment_length = getid3_lib::BigEndian2Int($parsed_array['comments_raw']{$comment_offset++});
$parsed_array['comments'][$name][]= substr($parsed_array['comments_raw'], $comment_offset, $comment_length);
$comment_offset += $comment_length;
}
break;
case 5:
getid3_lib::ReadSequence('BigEndian2Int', $parsed_array, $old_ra_header_data, 48,
array (
'sample_rate' => 4,
'sample_rate2' => 4,
'bits_per_sample' => 4,
'channels' => 2,
'genr' => -4,
'fourcc3' => -4,
)
);
$parsed_array['comments'] = array ();
break;
}
$parsed_array['fourcc'] = $parsed_array['fourcc3'];
}
foreach ($parsed_array['comments'] as $key => $value) {
if ($parsed_array['comments'][$key][0] === false) {
$parsed_array['comments'][$key][0] = '';
}
}
return true;
}
public static function RealAudioCodecFourCClookup($fourcc, $bitrate) {
// http://www.its.msstate.edu/net/real/reports/config/tags.stats
// http://www.freelists.org/archives/matroska-devel/06-2003/fullthread18.html
static $lookup;
if (empty($lookup)) {
$lookup['14_4'][8000] = 'RealAudio v2 (14.4kbps)';
$lookup['14.4'][8000] = 'RealAudio v2 (14.4kbps)';
$lookup['lpcJ'][8000] = 'RealAudio v2 (14.4kbps)';
$lookup['28_8'][15200] = 'RealAudio v2 (28.8kbps)';
$lookup['28.8'][15200] = 'RealAudio v2 (28.8kbps)';
$lookup['sipr'][4933] = 'RealAudio v4 (5kbps Voice)';
$lookup['sipr'][6444] = 'RealAudio v4 (6.5kbps Voice)';
$lookup['sipr'][8444] = 'RealAudio v4 (8.5kbps Voice)';
$lookup['sipr'][16000] = 'RealAudio v4 (16kbps Wideband)';
$lookup['dnet'][8000] = 'RealAudio v3 (8kbps Music)';
$lookup['dnet'][16000] = 'RealAudio v3 (16kbps Music Low Response)';
$lookup['dnet'][15963] = 'RealAudio v3 (16kbps Music Mid/High Response)';
$lookup['dnet'][20000] = 'RealAudio v3 (20kbps Music Stereo)';
$lookup['dnet'][32000] = 'RealAudio v3 (32kbps Music Mono)';
$lookup['dnet'][31951] = 'RealAudio v3 (32kbps Music Stereo)';
$lookup['dnet'][39965] = 'RealAudio v3 (40kbps Music Mono)';
$lookup['dnet'][40000] = 'RealAudio v3 (40kbps Music Stereo)';
$lookup['dnet'][79947] = 'RealAudio v3 (80kbps Music Mono)';
$lookup['dnet'][80000] = 'RealAudio v3 (80kbps Music Stereo)';
$lookup['dnet'][0] = 'RealAudio v3';
$lookup['sipr'][0] = 'RealAudio v4';
$lookup['cook'][0] = 'RealAudio G2';
$lookup['atrc'][0] = 'RealAudio 8';
}
$round_bitrate = intval(round($bitrate));
if (isset($lookup[$fourcc][$round_bitrate])) {
return $lookup[$fourcc][$round_bitrate];
}
if (isset($lookup[$fourcc][0])) {
return $lookup[$fourcc][0];
}
return $fourcc;
}
}
?>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,154 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio-video.swf.php |
// | module for analyzing Macromedia Shockwave Flash files. |
// | dependencies: zlib support in PHP |
// +----------------------------------------------------------------------+
//
// $Id: module.audio-video.swf.php,v 1.2 2006/11/02 10:48:00 ah Exp $
class getid3_swf extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->info['fileformat'] = 'swf';
$getid3->info['video']['dataformat'] = 'swf';
// http://www.openswf.org/spec/SWFfileformat.html
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$swf_file_data = fread($getid3->fp, $getid3->info['avdataend'] - $getid3->info['avdataoffset']); // 8 + 2 + 2 + max(9) bytes NOT including Frame_Size RECT data
$getid3->info['swf']['header']['signature'] = substr($swf_file_data, 0, 3);
switch ($getid3->info['swf']['header']['signature']) {
case 'FWS':
$getid3->info['swf']['header']['compressed'] = false;
break;
case 'CWS':
$getid3->info['swf']['header']['compressed'] = true;
break;
default:
throw new getid3_exception('Expecting "FWS" or "CWS" at offset '.$getid3->info['avdataoffset'].', found "'.$getid3->info['swf']['header']['signature'].'"');
}
$getid3->info['swf']['header']['version'] = getid3_lib::LittleEndian2Int($swf_file_data{3});
$getid3->info['swf']['header']['length'] = getid3_lib::LittleEndian2Int(substr($swf_file_data, 4, 4));
if (!function_exists('gzuncompress')) {
throw new getid3_exception('getid3_swf requires --zlib support in PHP.');
}
if ($getid3->info['swf']['header']['compressed']) {
if ($uncompressed_file_data = @gzuncompress(substr($swf_file_data, 8))) {
$swf_file_data = substr($swf_file_data, 0, 8).$uncompressed_file_data;
} else {
throw new getid3_exception('Error decompressing compressed SWF data');
}
}
$frame_size_bits_per_value = (ord(substr($swf_file_data, 8, 1)) & 0xF8) >> 3;
$frame_size_data_length = ceil((5 + (4 * $frame_size_bits_per_value)) / 8);
$frame_size_data_string = str_pad(decbin(ord($swf_file_data[8]) & 0x07), 3, '0', STR_PAD_LEFT);
for ($i = 1; $i < $frame_size_data_length; $i++) {
$frame_size_data_string .= str_pad(decbin(ord(substr($swf_file_data, 8 + $i, 1))), 8, '0', STR_PAD_LEFT);
}
list($x1, $x2, $y1, $y2) = explode("\n", wordwrap($frame_size_data_string, $frame_size_bits_per_value, "\n", 1));
$getid3->info['swf']['header']['frame_width'] = bindec($x2);
$getid3->info['swf']['header']['frame_height'] = bindec($y2);
// 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.
// Byte at (8 + $frame_size_data_length) is always zero and ignored
$getid3->info['swf']['header']['frame_rate'] = getid3_lib::LittleEndian2Int($swf_file_data[9 + $frame_size_data_length]);
$getid3->info['swf']['header']['frame_count'] = getid3_lib::LittleEndian2Int(substr($swf_file_data, 10 + $frame_size_data_length, 2));
$getid3->info['video']['frame_rate'] = $getid3->info['swf']['header']['frame_rate'];
$getid3->info['video']['resolution_x'] = intval(round($getid3->info['swf']['header']['frame_width'] / 20));
$getid3->info['video']['resolution_y'] = intval(round($getid3->info['swf']['header']['frame_height'] / 20));
$getid3->info['video']['pixel_aspect_ratio'] = (float)1;
if (($getid3->info['swf']['header']['frame_count'] > 0) && ($getid3->info['swf']['header']['frame_rate'] > 0)) {
$getid3->info['playtime_seconds'] = $getid3->info['swf']['header']['frame_count'] / $getid3->info['swf']['header']['frame_rate'];
}
// SWF tags
$current_offset = 12 + $frame_size_data_length;
$swf_data_length = strlen($swf_file_data);
while ($current_offset < $swf_data_length) {
$tag_ID_tag_length = getid3_lib::LittleEndian2Int(substr($swf_file_data, $current_offset, 2));
$tag_ID = ($tag_ID_tag_length & 0xFFFC) >> 6;
$tag_length = ($tag_ID_tag_length & 0x003F);
$current_offset += 2;
if ($tag_length == 0x3F) {
$tag_length = getid3_lib::LittleEndian2Int(substr($swf_file_data, $current_offset, 4));
$current_offset += 4;
}
unset($tag_data);
$tag_data['offset'] = $current_offset;
$tag_data['size'] = $tag_length;
$tag_data['id'] = $tag_ID;
$tag_data['data'] = substr($swf_file_data, $current_offset, $tag_length);
switch ($tag_ID) {
case 0: // end of movie
break 2;
case 9: // Set background color
$getid3->info['swf']['bgcolor'] = strtoupper(str_pad(dechex(getid3_lib::BigEndian2Int($tag_data['data'])), 6, '0', STR_PAD_LEFT));
break;
default:
/*
if ($ReturnAllTagData) {
$getid3->info['swf']['tags'][] = $tag_data;
}
*/
break;
}
$current_offset += $tag_length;
}
return true;
}
}
?>

View file

@ -0,0 +1,311 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.aac_adif.php |
// | Module for analyzing AAC files with ADIF header. |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.aac_adif.php,v 1.3 2006/11/02 10:48:00 ah Exp $
class getid3_aac_adif extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
// 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()
// }
// }
$getid3->info['fileformat'] = 'aac';
$getid3->info['audio']['dataformat'] = 'aac';
$getid3->info['audio']['lossless'] = false;
$getid3->info['aac']['header'] = array () ;
$info_aac = &$getid3->info['aac'];
$info_aac_header = & $info_aac['header'];
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$aac_header_bitstream = getid3_lib::BigEndian2Bin(fread($getid3->fp, 1024));
$info_aac['header_type'] = 'ADIF';
$info_aac_header['mpeg_version'] = 4;
$bit_offset = 32;
$info_aac_header['copyright'] = $aac_header_bitstream{$bit_offset++} == '1';
if ($info_aac_header['copyright']) {
$info_aac_header['copyright_id'] = getid3_aac_adif::Bin2String(substr($aac_header_bitstream, $bit_offset, 72));
$bit_offset += 72;
}
$info_aac_header['original_copy'] = $aac_header_bitstream{$bit_offset++} == '1';
$info_aac_header['home'] = $aac_header_bitstream{$bit_offset++} == '1';
$info_aac_header['is_vbr'] = $aac_header_bitstream{$bit_offset++} == '1';
if ($info_aac_header['is_vbr']) {
$getid3->info['audio']['bitrate_mode'] = 'vbr';
$info_aac_header['bitrate_max'] = bindec(substr($aac_header_bitstream, $bit_offset, 23));
$bit_offset += 23;
}
else {
$getid3->info['audio']['bitrate_mode'] = 'cbr';
$info_aac_header['bitrate'] = bindec(substr($aac_header_bitstream, $bit_offset, 23));
$bit_offset += 23;
$getid3->info['audio']['bitrate'] = $info_aac_header['bitrate'];
}
$info_aac_header['num_program_configs'] = 1 + bindec(substr($aac_header_bitstream, $bit_offset, 4));
$bit_offset += 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
// }
$info_aac['program_configs'][$i] = array ();
$info_aac_program_configs_i = &$info_aac['program_configs'][$i];
if (!$info_aac_header['is_vbr']) {
$info_aac_program_configs_i['buffer_fullness'] = bindec(substr($aac_header_bitstream, $bit_offset, 20));
$bit_offset += 20;
}
$info_aac_program_configs_i['element_instance_tag'] = bindec(substr($aac_header_bitstream, $bit_offset, 4));
$info_aac_program_configs_i['object_type'] = bindec(substr($aac_header_bitstream, $bit_offset + 4, 2));
$info_aac_program_configs_i['sampling_frequency_index'] = bindec(substr($aac_header_bitstream, $bit_offset + 6, 4));
$info_aac_program_configs_i['num_front_channel_elements'] = bindec(substr($aac_header_bitstream, $bit_offset + 10, 4));
$info_aac_program_configs_i['num_side_channel_elements'] = bindec(substr($aac_header_bitstream, $bit_offset + 14, 4));
$info_aac_program_configs_i['num_back_channel_elements'] = bindec(substr($aac_header_bitstream, $bit_offset + 18, 4));
$info_aac_program_configs_i['num_lfe_channel_elements'] = bindec(substr($aac_header_bitstream, $bit_offset + 22, 2));
$info_aac_program_configs_i['num_assoc_data_elements'] = bindec(substr($aac_header_bitstream, $bit_offset + 24, 3));
$info_aac_program_configs_i['num_valid_cc_elements'] = bindec(substr($aac_header_bitstream, $bit_offset + 27, 4));
$bit_offset += 31;
$info_aac_program_configs_i['mono_mixdown_present'] = $aac_header_bitstream{$bit_offset++} == 1;
if ($info_aac_program_configs_i['mono_mixdown_present']) {
$info_aac_program_configs_i['mono_mixdown_element_number'] = bindec(substr($aac_header_bitstream, $bit_offset, 4));
$bit_offset += 4;
}
$info_aac_program_configs_i['stereo_mixdown_present'] = $aac_header_bitstream{$bit_offset++} == 1;
if ($info_aac_program_configs_i['stereo_mixdown_present']) {
$info_aac_program_configs_i['stereo_mixdown_element_number'] = bindec(substr($aac_header_bitstream, $bit_offset, 4));
$bit_offset += 4;
}
$info_aac_program_configs_i['matrix_mixdown_idx_present'] = $aac_header_bitstream{$bit_offset++} == 1;
if ($info_aac_program_configs_i['matrix_mixdown_idx_present']) {
$info_aac_program_configs_i['matrix_mixdown_idx'] = bindec(substr($aac_header_bitstream, $bit_offset, 2));
$bit_offset += 2;
$info_aac_program_configs_i['pseudo_surround_enable'] = $aac_header_bitstream{$bit_offset++} == 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] = $aac_header_bitstream{$bit_offset++} == 1;
$info_aac_program_configs_i['front_element_tag_select'][$j] = bindec(substr($aac_header_bitstream, $bit_offset, 4));
$bit_offset += 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] = $aac_header_bitstream{$bit_offset++} == 1;
$info_aac_program_configs_i['side_element_tag_select'][$j] = bindec(substr($aac_header_bitstream, $bit_offset, 4));
$bit_offset += 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] = $aac_header_bitstream{$bit_offset++} == 1;
$info_aac_program_configs_i['back_element_tag_select'][$j] = bindec(substr($aac_header_bitstream, $bit_offset, 4));
$bit_offset += 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] = bindec(substr($aac_header_bitstream, $bit_offset, 4));
$bit_offset += 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] = bindec(substr($aac_header_bitstream, $bit_offset, 4));
$bit_offset += 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] = $aac_header_bitstream{$bit_offset++} == 1;
$info_aac_program_configs_i['valid_cc_element_tag_select'][$j] = bindec(substr($aac_header_bitstream, $bit_offset, 4));
$bit_offset += 4;
}
$bit_offset = ceil($bit_offset / 8) * 8;
$info_aac_program_configs_i['comment_field_bytes'] = bindec(substr($aac_header_bitstream, $bit_offset, 8));
$bit_offset += 8;
$info_aac_program_configs_i['comment_field'] = getid3_aac_adif::Bin2String(substr($aac_header_bitstream, $bit_offset, 8 * $info_aac_program_configs_i['comment_field_bytes']));
$bit_offset += 8 * $info_aac_program_configs_i['comment_field_bytes'];
$info_aac_header['profile_text'] = getid3_aac_adif::AACprofileLookup($info_aac_program_configs_i['object_type'], $info_aac_header['mpeg_version']);
$info_aac_program_configs_i['sampling_frequency'] = $getid3->info['audio']['sample_rate'] = getid3_aac_adif::AACsampleRateLookup($info_aac_program_configs_i['sampling_frequency_index']);
$getid3->info['audio']['channels'] = getid3_aac_adif::AACchannelCountCalculate($info_aac_program_configs_i);
if ($info_aac_program_configs_i['comment_field']) {
$info_aac['comments'][] = $info_aac_program_configs_i['comment_field'];
}
}
$getid3->info['playtime_seconds'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['audio']['bitrate'];
$getid3->info['audio']['encoder_options'] = $info_aac['header_type'].' '.$info_aac_header['profile_text'];
return true;
}
public static function Bin2String($bin_string) {
// return 'hi' for input of '0110100001101001'
$string = '';
$bin_string_reversed = strrev($bin_string);
for ($i = 0; $i < strlen($bin_string_reversed); $i += 8) {
$string = chr(bindec(strrev(substr($bin_string_reversed, $i, 8)))).$string;
}
return $string;
}
public static function AACsampleRateLookup($samplerate_id) {
static $lookup = array (
0 => 96000,
1 => 88200,
2 => 64000,
3 => 48000,
4 => 44100,
5 => 32000,
6 => 24000,
7 => 22050,
8 => 16000,
9 => 12000,
10 => 11025,
11 => 8000,
12 => 0,
13 => 0,
14 => 0,
15 => 0
);
return (isset($lookup[$samplerate_id]) ? $lookup[$samplerate_id] : 'invalid');
}
public static function AACprofileLookup($profile_id, $mpeg_version) {
static $lookup = array (
2 => array (
0 => 'Main profile',
1 => 'Low Complexity profile (LC)',
2 => 'Scalable Sample Rate profile (SSR)',
3 => '(reserved)'
),
4 => array (
0 => 'AAC_MAIN',
1 => 'AAC_LC',
2 => 'AAC_SSR',
3 => 'AAC_LTP'
)
);
return (isset($lookup[$mpeg_version][$profile_id]) ? $lookup[$mpeg_version][$profile_id] : 'invalid');
}
public static function AACchannelCountCalculate($program_configs) {
$channels = 0;
foreach (array ('front', 'side', 'back') as $placement) {
for ($i = 0; $i < $program_configs['num_'.$placement.'_channel_elements']; $i++) {
// Each element is channel pair (CPE = Channel Pair Element)
$channels += 1 + ($program_configs[$placement.'_element_is_cpe'][$i] ? 1 : 0);
}
}
return $channels + $program_configs['num_lfe_channel_elements'];
}
}
?>

View file

@ -0,0 +1,282 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.aac_adts.php |
// | Module for analyzing AAC files with ADTS header. |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.aac_adts.php,v 1.4 2006/11/02 10:48:01 ah Exp $
class getid3_aac_adts extends getid3_handler
{
public $option_max_frames_to_scan = 1000000;
public $option_return_extended_info = false;
private $decbin_cache;
private $bitrate_cache;
public function __construct(getID3 $getid3) {
parent::__construct($getid3);
// Populate bindec_cache
for ($i = 0; $i < 256; $i++) {
$this->decbin_cache[chr($i)] = str_pad(decbin($i), 8, '0', STR_PAD_LEFT);
}
// Init cache
$this->bitrate_cache = array ();
// Fast scanning?
if (!$getid3->option_accurate_results) {
$this->option_max_frames_to_scan = 200;
$getid3->warning('option_accurate_results set to false - bitrate and playing time are not accurate.');
}
}
public function Analyze() {
$getid3 = $this->getid3;
// based loosely on code from AACfile by Jurgen Faul <jfaulØgmx.de>
// http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html
// http://faac.sourceforge.net/wiki/index.php?page=ADTS
// * ADTS Fixed Header: these don't change from frame to frame
// syncword 12 always: '111111111111'
// ID 1 0: MPEG-4, 1: MPEG-2
// layer 2 always: '00'
// protection_absent 1
// profile 2
// sampling_frequency_index 4
// private_bit 1
// channel_configuration 3
// original/copy 1
// home 1
// emphasis 2 only if ID == 0 (ie MPEG-4)
// * 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
$getid3->info['aac']['header'] = array () ;
$info_aac = &$getid3->info['aac'];
$info_aac_header = & $info_aac['header'];
$byte_offset = $frame_number = 0;
while (true) {
// Breaks out when end-of-file encountered, or invalid data found,
// or MaxFramesToScan frames have been scanned
fseek($getid3->fp, $byte_offset, SEEK_SET);
// First get substring
$sub_string = fread($getid3->fp, 10);
$sub_string_length = strlen($sub_string);
if ($sub_string_length != 10) {
throw new getid3_exception('Failed to read 10 bytes at offset '.(ftell($getid3->fp) - $sub_string_length).' (only read '.$sub_string_length.' bytes)');
}
// Initialise $aac_header_bitstream
$aac_header_bitstream = '';
// Loop thru substring chars
for ($i = 0; $i < 10; $i++) {
$aac_header_bitstream .= $this->decbin_cache[$sub_string[$i]];
}
$sync_test = bindec(substr($aac_header_bitstream, 0, 12));
$bit_offset = 12;
if ($sync_test != 0x0FFF) {
throw new getid3_exception('Synch pattern (0x0FFF) not found at offset '.(ftell($getid3->fp) - 10).' (found 0x0'.strtoupper(dechex($sync_test)).' instead)');
}
// Only gather info once - this takes time to do 1000 times!
if ($frame_number > 0) {
// MPEG-4: 20, // MPEG-2: 18
$bit_offset += $aac_header_bitstream[$bit_offset] ? 18 : 20;
}
// Gather info for first frame only - this takes time to do 1000 times!
else {
$info_aac['header_type'] = 'ADTS';
$info_aac_header['synch'] = $sync_test;
$getid3->info['fileformat'] = 'aac';
$getid3->info['audio']['dataformat'] = 'aac';
$info_aac_header['mpeg_version'] = $aac_header_bitstream{$bit_offset++} == '0' ? 4 : 2;
$info_aac_header['layer'] = bindec(substr($aac_header_bitstream, $bit_offset, 2));
$bit_offset += 2;
if ($info_aac_header['layer'] != 0) {
throw new getid3_exception('Layer error - expected 0x00, found 0x'.dechex($info_aac_header['layer']).' instead');
}
$info_aac_header['crc_present'] = $aac_header_bitstream{$bit_offset++} == '0' ? true : false;
$info_aac_header['profile_id'] = bindec(substr($aac_header_bitstream, $bit_offset, 2));
$bit_offset += 2;
$info_aac_header['profile_text'] = getid3_aac_adts::AACprofileLookup($info_aac_header['profile_id'], $info_aac_header['mpeg_version']);
$info_aac_header['sample_frequency_index'] = bindec(substr($aac_header_bitstream, $bit_offset, 4));
$bit_offset += 4;
$info_aac_header['sample_frequency'] = getid3_aac_adts::AACsampleRateLookup($info_aac_header['sample_frequency_index']);
$getid3->info['audio']['sample_rate'] = $info_aac_header['sample_frequency'];
$info_aac_header['private'] = $aac_header_bitstream{$bit_offset++} == 1;
$info_aac_header['channel_configuration'] = $getid3->info['audio']['channels'] = bindec(substr($aac_header_bitstream, $bit_offset, 3));
$bit_offset += 3;
$info_aac_header['original'] = $aac_header_bitstream{$bit_offset++} == 1;
$info_aac_header['home'] = $aac_header_bitstream{$bit_offset++} == 1;
if ($info_aac_header['mpeg_version'] == 4) {
$info_aac_header['emphasis'] = bindec(substr($aac_header_bitstream, $bit_offset, 2));
$bit_offset += 2;
}
if ($this->option_return_extended_info) {
$info_aac[$frame_number]['copyright_id_bit'] = $aac_header_bitstream{$bit_offset++} == 1;
$info_aac[$frame_number]['copyright_id_start'] = $aac_header_bitstream{$bit_offset++} == 1;
} else {
$bit_offset += 2;
}
}
$frame_length = bindec(substr($aac_header_bitstream, $bit_offset, 13));
if (!isset($this->bitrate_cache[$frame_length])) {
$this->bitrate_cache[$frame_length] = ($info_aac_header['sample_frequency'] / 1024) * $frame_length * 8;
}
@$info_aac['bitrate_distribution'][$this->bitrate_cache[$frame_length]]++;
$info_aac[$frame_number]['aac_frame_length'] = $frame_length;
$bit_offset += 13;
$info_aac[$frame_number]['adts_buffer_fullness'] = bindec(substr($aac_header_bitstream, $bit_offset, 11));
$bit_offset += 11;
$getid3->info['audio']['bitrate_mode'] = ($info_aac[$frame_number]['adts_buffer_fullness'] == 0x07FF) ? 'vbr' : 'cbr';
$info_aac[$frame_number]['num_raw_data_blocks'] = bindec(substr($aac_header_bitstream, $bit_offset, 2));
$bit_offset += 2;
if ($info_aac_header['crc_present']) {
$bit_offset += 16;
}
if (!$this->option_return_extended_info) {
unset($info_aac[$frame_number]);
}
$byte_offset += $frame_length;
if ((++$frame_number < $this->option_max_frames_to_scan) && (($byte_offset + 10) < $getid3->info['avdataend'])) {
// keep scanning
} else {
$info_aac['frames'] = $frame_number;
$getid3->info['playtime_seconds'] = ($getid3->info['avdataend'] / $byte_offset) * (($frame_number * 1024) / $info_aac_header['sample_frequency']); // (1 / % of file scanned) * (samples / (samples/sec)) = seconds
$getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
ksort($info_aac['bitrate_distribution']);
$getid3->info['audio']['encoder_options'] = $info_aac['header_type'].' '.$info_aac_header['profile_text'];
return true;
}
}
}
public static function AACsampleRateLookup($samplerate_id) {
static $lookup = array (
0 => 96000,
1 => 88200,
2 => 64000,
3 => 48000,
4 => 44100,
5 => 32000,
6 => 24000,
7 => 22050,
8 => 16000,
9 => 12000,
10 => 11025,
11 => 8000,
12 => 0,
13 => 0,
14 => 0,
15 => 0
);
return (isset($lookup[$samplerate_id]) ? $lookup[$samplerate_id] : 'invalid');
}
public static function AACprofileLookup($profile_id, $mpeg_version) {
static $lookup = array (
2 => array (
0 => 'Main profile',
1 => 'Low Complexity profile (LC)',
2 => 'Scalable Sample Rate profile (SSR)',
3 => '(reserved)'
),
4 => array (
0 => 'AAC_MAIN',
1 => 'AAC_LC',
2 => 'AAC_SSR',
3 => 'AAC_LTP'
)
);
return (isset($lookup[$mpeg_version][$profile_id]) ? $lookup[$mpeg_version][$profile_id] : 'invalid');
}
}
?>

View file

@ -0,0 +1,500 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.ac3.php |
// | Module for analyzing AC-3 (aka Dolby Digital) audio files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.ac3.php,v 1.3 2006/11/02 10:48:01 ah Exp $
class getid3_ac3 extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
// http://www.atsc.org/standards/a_52a.pdf
$getid3->info['fileformat'] = 'ac3';
$getid3->info['audio']['dataformat'] = 'ac3';
$getid3->info['audio']['bitrate_mode'] = 'cbr';
$getid3->info['audio']['lossless'] = false;
$getid3->info['ac3']['raw']['bsi'] = array ();
$info_ac3 = &$getid3->info['ac3'];
$info_ac3_raw = &$info_ac3['raw'];
$info_ac3_raw_bsi = &$info_ac3_raw['bsi'];
// 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
$this->fseek($getid3->info['avdataoffset'], SEEK_SET);
$ac3_header['syncinfo'] = $this->fread(5);
$info_ac3_raw['synchinfo']['synchword'] = substr($ac3_header['syncinfo'], 0, 2);
if ($info_ac3_raw['synchinfo']['synchword'] != "\x0B\x77") {
throw new getid3_exception('Expecting "\x0B\x77" at offset '.$getid3->info['avdataoffset'].', found \x'.strtoupper(dechex($ac3_header['syncinfo']{0})).'\x'.strtoupper(dechex($ac3_header['syncinfo']{1})).' instead');
}
// syncinfo() {
// syncword 16
// crc1 16
// fscod 2
// frmsizecod 6
// } /* end of syncinfo */
$info_ac3_raw['synchinfo']['crc1'] = getid3_lib::LittleEndian2Int(substr($ac3_header['syncinfo'], 2, 2));
$ac3_synchinfo_fscod_frmsizecod = getid3_lib::LittleEndian2Int(substr($ac3_header['syncinfo'], 4, 1));
$info_ac3_raw['synchinfo']['fscod'] = ($ac3_synchinfo_fscod_frmsizecod & 0xC0) >> 6;
$info_ac3_raw['synchinfo']['frmsizecod'] = ($ac3_synchinfo_fscod_frmsizecod & 0x3F);
$info_ac3['sample_rate'] = getid3_ac3::AC3sampleRateCodeLookup($info_ac3_raw['synchinfo']['fscod']);
if ($info_ac3_raw['synchinfo']['fscod'] <= 3) {
$getid3->info['audio']['sample_rate'] = $info_ac3['sample_rate'];
}
$info_ac3['frame_length'] = getid3_ac3::AC3frameSizeLookup($info_ac3_raw['synchinfo']['frmsizecod'], $info_ac3_raw['synchinfo']['fscod']);
$info_ac3['bitrate'] = getid3_ac3::AC3bitrateLookup($info_ac3_raw['synchinfo']['frmsizecod']);
$getid3->info['audio']['bitrate'] = $info_ac3['bitrate'];
$ac3_header['bsi'] = getid3_lib::BigEndian2Bin($this->fread(15));
$info_ac3_raw_bsi['bsid'] = bindec(substr($ac3_header['bsi'], 0, 5));
if ($info_ac3_raw_bsi['bsid'] > 8) {
// Decoders which can decode version 8 will thus be able to decode version numbers less than 8.
// If this standard is extended by the addition of additional elements or features, a value of bsid greater than 8 will be used.
// Decoders built to this version of the standard will not be able to decode versions with bsid greater than 8.
throw new getid3_exception('Bit stream identification is version '.$info_ac3_raw_bsi['bsid'].', but getID3() only understands up to version 8');
}
$info_ac3_raw_bsi['bsmod'] = bindec(substr($ac3_header['bsi'], 5, 3));
$info_ac3_raw_bsi['acmod'] = bindec(substr($ac3_header['bsi'], 8, 3));
$info_ac3['service_type'] = getid3_ac3::AC3serviceTypeLookup($info_ac3_raw_bsi['bsmod'], $info_ac3_raw_bsi['acmod']);
$ac3_coding_mode = getid3_ac3::AC3audioCodingModeLookup($info_ac3_raw_bsi['acmod']);
foreach($ac3_coding_mode as $key => $value) {
$info_ac3[$key] = $value;
}
switch ($info_ac3_raw_bsi['acmod']) {
case 0:
case 1:
$getid3->info['audio']['channelmode'] = 'mono';
break;
case 3:
case 4:
$getid3->info['audio']['channelmode'] = 'stereo';
break;
default:
$getid3->info['audio']['channelmode'] = 'surround';
break;
}
$getid3->info['audio']['channels'] = $info_ac3['num_channels'];
$offset = 11;
if ($info_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.
$info_ac3_raw_bsi['cmixlev'] = bindec(substr($ac3_header['bsi'], $offset, 2));
$info_ac3['center_mix_level'] = getid3_ac3::AC3centerMixLevelLookup($info_ac3_raw_bsi['cmixlev']);
$offset += 2;
}
if ($info_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.
$info_ac3_raw_bsi['surmixlev'] = bindec(substr($ac3_header['bsi'], $offset, 2));
$info_ac3['surround_mix_level'] = getid3_ac3::AC3surroundMixLevelLookup($info_ac3_raw_bsi['surmixlev']);
$offset += 2;
}
if ($info_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.
$info_ac3_raw_bsi['dsurmod'] = bindec(substr($ac3_header['bsi'], $offset, 2));
$info_ac3['dolby_surround_mode'] = getid3_ac3::AC3dolbySurroundModeLookup($info_ac3_raw_bsi['dsurmod']);
$offset += 2;
}
$info_ac3_raw_bsi['lfeon'] = $ac3_header['bsi']{$offset++} == '1';
$info_ac3['lfe_enabled'] = $info_ac3_raw_bsi['lfeon'];
if ($info_ac3_raw_bsi['lfeon']) {
$getid3->info['audio']['channels'] .= '.1';
}
$info_ac3['channels_enabled'] = getid3_ac3::AC3channelsEnabledLookup($info_ac3_raw_bsi['acmod'], $info_ac3_raw_bsi['lfeon']);
// This indicates how far the average dialogue level is below digital 100 percent. Valid values are 131.
// 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.
$info_ac3_raw_bsi['dialnorm'] = bindec(substr($ac3_header['bsi'], $offset, 5));
$offset += 5;
$info_ac3['dialogue_normalization'] = '-'.$info_ac3_raw_bsi['dialnorm'].'dB';
$info_ac3_raw_bsi['compre_flag'] = $ac3_header['bsi']{$offset++} == '1';
if ($info_ac3_raw_bsi['compre_flag']) {
$info_ac3_raw_bsi['compr'] = bindec(substr($ac3_header['bsi'], $offset, 8));
$offset += 8;
$info_ac3['heavy_compression'] = getid3_ac3::AC3heavyCompression($info_ac3_raw_bsi['compr']);
}
$info_ac3_raw_bsi['langcode_flag'] = $ac3_header['bsi']{$offset++} == '1';
if ($info_ac3_raw_bsi['langcode_flag']) {
$info_ac3_raw_bsi['langcod'] = bindec(substr($ac3_header['bsi'], $offset, 8));
$offset += 8;
}
$info_ac3_raw_bsi['audprodie'] = $ac3_header['bsi']{$offset++} == '1';
if ($info_ac3_raw_bsi['audprodie']) {
$info_ac3_raw_bsi['mixlevel'] = bindec(substr($ac3_header['bsi'], $offset, 5));
$offset += 5;
$info_ac3_raw_bsi['roomtyp'] = bindec(substr($ac3_header['bsi'], $offset, 2));
$offset += 2;
$info_ac3['mixing_level'] = (80 + $info_ac3_raw_bsi['mixlevel']).'dB';
$info_ac3['room_type'] = getid3_ac3::AC3roomTypeLookup($info_ac3_raw_bsi['roomtyp']);
}
if ($info_ac3_raw_bsi['acmod'] == 0x00) {
// If acmod is 0, then two completely independent program channels (dual mono)
// are encoded into the bit stream, and are referenced as Ch1, Ch2. In this case,
// a number of additional items are present in BSI or audblk to fully describe Ch2.
// This indicates how far the average dialogue level is below digital 100 percent. Valid values are 131.
// 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.
$info_ac3_raw_bsi['dialnorm2'] = bindec(substr($ac3_header['bsi'], $offset, 5));
$offset += 5;
$info_ac3['dialogue_normalization2'] = '-'.$info_ac3_raw_bsi['dialnorm2'].'dB';
$info_ac3_raw_bsi['compre_flag2'] = $ac3_header['bsi']{$offset++} == '1';
if ($info_ac3_raw_bsi['compre_flag2']) {
$info_ac3_raw_bsi['compr2'] = bindec(substr($ac3_header['bsi'], $offset, 8));
$offset += 8;
$info_ac3['heavy_compression2'] = getid3_ac3::AC3heavyCompression($info_ac3_raw_bsi['compr2']);
}
$info_ac3_raw_bsi['langcode_flag2'] = $ac3_header['bsi']{$offset++} == '1';
if ($info_ac3_raw_bsi['langcode_flag2']) {
$info_ac3_raw_bsi['langcod2'] = bindec(substr($ac3_header['bsi'], $offset, 8));
$offset += 8;
}
$info_ac3_raw_bsi['audprodie2'] = $ac3_header['bsi']{$offset++} == '1';
if ($info_ac3_raw_bsi['audprodie2']) {
$info_ac3_raw_bsi['mixlevel2'] = bindec(substr($ac3_header['bsi'], $offset, 5));
$offset += 5;
$info_ac3_raw_bsi['roomtyp2'] = bindec(substr($ac3_header['bsi'], $offset, 2));
$offset += 2;
$info_ac3['mixing_level2'] = (80 + $info_ac3_raw_bsi['mixlevel2']).'dB';
$info_ac3['room_type2'] = getid3_ac3::AC3roomTypeLookup($info_ac3_raw_bsi['roomtyp2']);
}
}
$info_ac3_raw_bsi['copyright'] = $ac3_header['bsi']{$offset++} == '1';
$info_ac3_raw_bsi['original'] = $ac3_header['bsi']{$offset++} == '1';
$info_ac3_raw_bsi['timecode1_flag'] = $ac3_header['bsi']{$offset++} == '1';
if ($info_ac3_raw_bsi['timecode1_flag']) {
$info_ac3_raw_bsi['timecode1'] = bindec(substr($ac3_header['bsi'], $offset, 14));
$offset += 14;
}
$info_ac3_raw_bsi['timecode2_flag'] = $ac3_header['bsi']{$offset++} == '1';
if ($info_ac3_raw_bsi['timecode2_flag']) {
$info_ac3_raw_bsi['timecode2'] = bindec(substr($ac3_header['bsi'], $offset, 14));
$offset += 14;
}
$info_ac3_raw_bsi['addbsi_flag'] = $ac3_header['bsi']{$offset++} == '1';
if ($info_ac3_raw_bsi['addbsi_flag']) {
$info_ac3_raw_bsi['addbsi_length'] = bindec(substr($ac3_header['bsi'], $offset, 6));
$offset += 6;
$ac3_header['bsi'] .= getid3_lib::BigEndian2Bin($this->fread($info_ac3_raw_bsi['addbsi_length']));
$info_ac3_raw_bsi['addbsi_data'] = substr($ac3_header['bsi'], 119, $info_ac3_raw_bsi['addbsi_length'] * 8);
}
return true;
}
public static function AC3sampleRateCodeLookup($fscod) {
static $lookup = 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($lookup[$fscod]) ? $lookup[$fscod] : false);
}
public static function AC3serviceTypeLookup($bsmod, $acmod) {
static $lookup = array (
0 => 'main audio service: complete main (CM)',
1 => 'main audio service: music and effects (ME)',
2 => 'associated service: visually impaired (VI)',
3 => 'associated service: hearing impaired (HI)',
4 => 'associated service: dialogue (D)',
5 => 'associated service: commentary (C)',
6 => 'associated service: emergency (E)',
7 => 'main audio service: karaoke'
);
if ($bsmod == 7 && $acmod == 1) {
return 'associated service: voice over (VO)';
}
return (isset($lookup[$bsmod]) ? $lookup[$bsmod] : false);
}
public static function AC3audioCodingModeLookup($acmod) {
// array (channel configuration, # channels (not incl LFE), channel order)
static $lookup = 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($lookup[$acmod]) ? $lookup[$acmod] : false);
}
public static function AC3centerMixLevelLookup($cmixlev) {
static $lookup;
if (!@$lookup) {
$lookup = 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($lookup[$cmixlev]) ? $lookup[$cmixlev] : false);
}
public static function AC3surroundMixLevelLookup($surmixlev) {
static $lookup;
if (!@$lookup) {
$lookup = array (
0 => pow(2, -3.0 / 6),
1 => pow(2, -6.0 / 6),
2 => 0,
3 => 'reserved'
);
}
return (isset($lookup[$surmixlev]) ? $lookup[$surmixlev] : false);
}
public static function AC3dolbySurroundModeLookup($dsurmod) {
static $lookup = array (
0 => 'not indicated',
1 => 'Not Dolby Surround encoded',
2 => 'Dolby Surround encoded',
3 => 'reserved'
);
return (isset($lookup[$dsurmod]) ? $lookup[$dsurmod] : false);
}
public static function AC3channelsEnabledLookup($acmod, $lfeon) {
return array (
'ch1' => $acmod == 0,
'ch2' => $acmod == 0,
'left' => $acmod > 1,
'right' => $acmod > 1,
'center' => (bool)($acmod & 0x01),
'surround_mono' => $acmod == 4 || $acmod == 5,
'surround_left' => $acmod == 6 || $acmod == 7,
'surround_right' => $acmod == 6 || $acmod == 7,
'lfe' => $lfeon
);
}
public static function AC3heavyCompression($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.
// 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
$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) * (20 * log10(2));
// 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.
$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 AC3roomTypeLookup($roomtyp) {
static $lookup = array (
0 => 'not indicated',
1 => 'large room, X curve monitor',
2 => 'small room, flat monitor',
3 => 'reserved'
);
return (isset($lookup[$roomtyp]) ? $lookup[$roomtyp] : false);
}
public static function AC3frameSizeLookup($frmsizecod, $fscod) {
$padding = (bool)($frmsizecod % 2);
$frame_size_id = floor($frmsizecod / 2);
static $lookup = array (
0 => array (128, 138, 192),
1 => array (40, 160, 174, 240),
2 => array (48, 192, 208, 288),
3 => array (56, 224, 242, 336),
4 => array (64, 256, 278, 384),
5 => array (80, 320, 348, 480),
6 => array (96, 384, 416, 576),
7 => array (112, 448, 486, 672),
8 => array (128, 512, 556, 768),
9 => array (160, 640, 696, 960),
10 => array (192, 768, 834, 1152),
11 => array (224, 896, 974, 1344),
12 => array (256, 1024, 1114, 1536),
13 => array (320, 1280, 1392, 1920),
14 => array (384, 1536, 1670, 2304),
15 => array (448, 1792, 1950, 2688),
16 => array (512, 2048, 2228, 3072),
17 => array (576, 2304, 2506, 3456),
18 => array (640, 2560, 2786, 3840)
);
if (($fscod == 1) && $padding) {
// frame lengths are padded by 1 word (16 bits) at 44100
$lookup[$frmsizecod] += 2;
}
return (isset($lookup[$frame_size_id][$fscod]) ? $lookup[$frame_size_id][$fscod] : false);
}
public static function AC3bitrateLookup($frmsizecod) {
static $lookup = 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
);
$frame_size_id = floor($frmsizecod / 2);
return (isset($lookup[$frame_size_id]) ? $lookup[$frame_size_id] : false);
}
}
?>

View file

@ -0,0 +1,184 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.au.php |
// | module for analyzing AU files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.au.php,v 1.2 2006/11/02 10:48:01 ah Exp $
class getid3_au extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$au_header = fread($getid3->fp, 8);
// Magic bytes: .snd
$getid3->info['au'] = array ();
$info_au = &$getid3->info['au'];
$getid3->info['fileformat'] = 'au';
$getid3->info['audio']['dataformat'] = 'au';
$getid3->info['audio']['bitrate_mode'] = 'cbr';
$info_au['encoding'] = 'ISO-8859-1';
$info_au['header_length'] = getid3_lib::BigEndian2Int(substr($au_header, 4, 4));
$au_header .= fread($getid3->fp, $info_au['header_length'] - 8);
$getid3->info['avdataoffset'] += $info_au['header_length'];
getid3_lib::ReadSequence('BigEndian2Int', $info_au, $au_header, 8,
array (
'data_size' => 4,
'data_format_id'=> 4,
'sample_rate' => 4,
'channels' => 4
)
);
$info_au['comments']['comment'][] = trim(substr($au_header, 24));
$info_au['data_format'] = getid3_au::AUdataFormatNameLookup($info_au['data_format_id']);
$info_au['used_bits_per_sample'] = getid3_au::AUdataFormatUsedBitsPerSampleLookup($info_au['data_format_id']);
if ($info_au['bits_per_sample'] = getid3_au::AUdataFormatBitsPerSampleLookup($info_au['data_format_id'])) {
$getid3->info['audio']['bits_per_sample'] = $info_au['bits_per_sample'];
} else {
unset($info_au['bits_per_sample']);
}
$getid3->info['audio']['sample_rate'] = $info_au['sample_rate'];
$getid3->info['audio']['channels'] = $info_au['channels'];
if (($getid3->info['avdataoffset'] + $info_au['data_size']) > $getid3->info['avdataend']) {
$getid3->warning('Possible truncated file - expecting "'.$info_au['data_size'].'" bytes of audio data, only found '.($getid3->info['avdataend'] - $getid3->info['avdataoffset']).' bytes"');
}
$getid3->info['playtime_seconds'] = $info_au['data_size'] / ($info_au['sample_rate'] * $info_au['channels'] * ($info_au['used_bits_per_sample'] / 8));
$getid3->info['audio']['bitrate'] = ($info_au['data_size'] * 8) / $getid3->info['playtime_seconds'];
return true;
}
public static function AUdataFormatNameLookup($id) {
static $lookup = 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',
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($lookup[$id]) ? $lookup[$id] : false);
}
public static function AUdataFormatBitsPerSampleLookup($id) {
static $lookup = array (
1 => 8,
2 => 8,
3 => 16,
4 => 24,
5 => 32,
6 => 32,
7 => 64,
11 => 8,
12 => 16,
13 => 24,
14 => 32,
18 => 16,
19 => 16,
20 => 16,
23 => 16,
25 => 16,
26 => 16,
27 => 8
);
return (isset($lookup[$id]) ? $lookup[$id] : false);
}
public static function AUdataFormatUsedBitsPerSampleLookup($id) {
static $lookup = array (
1 => 8,
2 => 8,
3 => 16,
4 => 24,
5 => 32,
6 => 32,
7 => 64,
11 => 8,
12 => 16,
13 => 24,
14 => 32,
18 => 16,
19 => 16,
20 => 16,
23 => 4,
25 => 3,
26 => 5,
27 => 8,
);
return (isset($lookup[$id]) ? $lookup[$id] : false);
}
}
?>

View file

@ -0,0 +1,135 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.avr.php |
// | Module for analyzing AVR audio files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.avr.php,v 1.2 2006/11/02 10:48:01 ah Exp $
class getid3_avr extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
// 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
// Magic bytes: '2BIT'
$getid3->info['avr'] = array ();
$info_avr = &$getid3->info['avr'];
$getid3->info['fileformat'] = 'avr';
$info_avr['raw']['magic'] = '2BIT';
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$avr_header = fread($getid3->fp, 128);
$getid3->info['avdataoffset'] += 128;
$info_avr['sample_name'] = rtrim(substr($avr_header, 4, 8));
$info_avr['raw']['mono'] = getid3_lib::BigEndian2Int(substr($avr_header, 12, 2));
$info_avr['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($avr_header, 14, 2));
$info_avr['raw']['signed'] = getid3_lib::BigEndian2Int(substr($avr_header, 16, 2));
$info_avr['raw']['loop'] = getid3_lib::BigEndian2Int(substr($avr_header, 18, 2));
$info_avr['raw']['midi'] = getid3_lib::BigEndian2Int(substr($avr_header, 20, 2));
$info_avr['raw']['replay_freq'] = getid3_lib::BigEndian2Int(substr($avr_header, 22, 1));
$info_avr['sample_rate'] = getid3_lib::BigEndian2Int(substr($avr_header, 23, 3));
$info_avr['sample_length'] = getid3_lib::BigEndian2Int(substr($avr_header, 26, 4));
$info_avr['loop_start'] = getid3_lib::BigEndian2Int(substr($avr_header, 30, 4));
$info_avr['loop_end'] = getid3_lib::BigEndian2Int(substr($avr_header, 34, 4));
$info_avr['midi_split'] = getid3_lib::BigEndian2Int(substr($avr_header, 38, 2));
$info_avr['sample_compression'] = getid3_lib::BigEndian2Int(substr($avr_header, 40, 2));
$info_avr['reserved'] = getid3_lib::BigEndian2Int(substr($avr_header, 42, 2));
$info_avr['sample_name_extra'] = rtrim(substr($avr_header, 44, 20));
$info_avr['comment'] = rtrim(substr($avr_header, 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['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);
}
if (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) != ($info_avr['sample_length'] * (($info_avr['bits_per_sample'] == 8) ? 1 : 2))) {
$getid3->warning('Probable truncated file: expecting '.($info_avr['sample_length'] * (($info_avr['bits_per_sample'] == 8) ? 1 : 2)).' bytes of audio data, found '.($getid3->info['avdataend'] - $getid3->info['avdataoffset']));
}
$getid3->info['audio']['dataformat'] = 'avr';
$getid3->info['audio']['lossless'] = true;
$getid3->info['audio']['bitrate_mode'] = 'cbr';
$getid3->info['audio']['bits_per_sample'] = $info_avr['bits_per_sample'];
$getid3->info['audio']['sample_rate'] = $info_avr['sample_rate'];
$getid3->info['audio']['channels'] = ($info_avr['flags']['stereo'] ? 2 : 1);
$getid3->info['playtime_seconds'] = ($info_avr['sample_length'] / $getid3->info['audio']['channels']) / $info_avr['sample_rate'];
$getid3->info['audio']['bitrate'] = ($info_avr['sample_length'] * (($info_avr['bits_per_sample'] == 8) ? 8 : 16)) / $getid3->info['playtime_seconds'];
return true;
}
}
?>

View file

@ -0,0 +1,235 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.bonk.php |
// | Module for analyzing BONK audio files |
// | dependencies: module.tag.id3v2.php (optional) |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.bonk.php,v 1.3 2006/11/02 10:48:01 ah Exp $
class getid3_bonk extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->info['bonk'] = array ();
$info_bonk = &$getid3->info['bonk'];
$info_bonk['dataoffset'] = $getid3->info['avdataoffset'];
$info_bonk['dataend'] = $getid3->info['avdataend'];
// Scan-from-end method, for v0.6 and higher
fseek($getid3->fp, $info_bonk['dataend'] - 8, SEEK_SET);
$possible_bonk_tag = fread($getid3->fp, 8);
while (getid3_bonk::BonkIsValidTagName(substr($possible_bonk_tag, 4, 4), true)) {
$bonk_tag_size = getid3_lib::LittleEndian2Int(substr($possible_bonk_tag, 0, 4));
fseek($getid3->fp, 0 - $bonk_tag_size, SEEK_CUR);
$bonk_tag_offset = ftell($getid3->fp);
$tag_header_test = fread($getid3->fp, 5);
if (($tag_header_test{0} != "\x00") || (substr($possible_bonk_tag, 4, 4) != strtolower(substr($possible_bonk_tag, 4, 4)))) {
throw new getid3_exception('Expecting "Ø'.strtoupper(substr($possible_bonk_tag, 4, 4)).'" at offset '.$bonk_tag_offset.', found "'.$tag_header_test.'"');
}
$bonk_tag_name = substr($tag_header_test, 1, 4);
$info_bonk[$bonk_tag_name]['size'] = $bonk_tag_size;
$info_bonk[$bonk_tag_name]['offset'] = $bonk_tag_offset;
$this->HandleBonkTags($bonk_tag_name);
$next_tag_end_offset = $bonk_tag_offset - 8;
if ($next_tag_end_offset < $info_bonk['dataoffset']) {
if (empty($getid3->info['audio']['encoder'])) {
$getid3->info['audio']['encoder'] = 'Extended BONK v0.9+';
}
return true;
}
fseek($getid3->fp, $next_tag_end_offset, SEEK_SET);
$possible_bonk_tag = fread($getid3->fp, 8);
}
// Seek-from-beginning method for v0.4 and v0.5
if (empty($info_bonk['BONK'])) {
fseek($getid3->fp, $info_bonk['dataoffset'], SEEK_SET);
do {
$tag_header_test = fread($getid3->fp, 5);
switch ($tag_header_test) {
case "\x00".'BONK':
if (empty($getid3->info['audio']['encoder'])) {
$getid3->info['audio']['encoder'] = 'BONK v0.4';
}
break;
case "\x00".'INFO':
$getid3->info['audio']['encoder'] = 'Extended BONK v0.5';
break;
default:
break 2;
}
$bonk_tag_name = substr($tag_header_test, 1, 4);
$info_bonk[$bonk_tag_name]['size'] = $info_bonk['dataend'] - $info_bonk['dataoffset'];
$info_bonk[$bonk_tag_name]['offset'] = $info_bonk['dataoffset'];
$this->HandleBonkTags($bonk_tag_name);
} while (true);
}
// Parse META block for v0.6 - v0.8
if (!@$info_bonk['INFO'] && isset($info_bonk['META']['tags']['info'])) {
fseek($getid3->fp, $info_bonk['META']['tags']['info'], SEEK_SET);
$tag_header_test = fread($getid3->fp, 5);
if ($tag_header_test == "\x00".'INFO') {
$getid3->info['audio']['encoder'] = 'Extended BONK v0.6 - v0.8';
$bonk_tag_name = substr($tag_header_test, 1, 4);
$info_bonk[$bonk_tag_name]['size'] = $info_bonk['dataend'] - $info_bonk['dataoffset'];
$info_bonk[$bonk_tag_name]['offset'] = $info_bonk['dataoffset'];
$this->HandleBonkTags($bonk_tag_name);
}
}
if (empty($getid3->info['audio']['encoder'])) {
$getid3->info['audio']['encoder'] = 'Extended BONK v0.9+';
}
if (empty($info_bonk['BONK'])) {
unset($getid3->info['bonk']);
}
return true;
}
private function HandleBonkTags(&$bonk_tag_name) {
// Shortcut to getid3 pointer
$getid3 = $this->getid3;
$info_audio = &$getid3->info['audio'];
switch ($bonk_tag_name) {
case 'BONK':
// shortcut
$info_bonk_BONK = &$getid3->info['bonk']['BONK'];
$bonk_data = "\x00".'BONK'.fread($getid3->fp, 17);
getid3_lib::ReadSequence('LittleEndian2Int', $info_bonk_BONK, $bonk_data, 5,
array (
'version' => 1,
'number_samples' => 4,
'sample_rate' => 4,
'channels' => 1,
'lossless' => 1,
'joint_stereo' => 1,
'number_taps' => 2,
'downsampling_ratio' => 1,
'samples_per_packet' => 2
)
);
$info_bonk_BONK['lossless'] = (bool)$info_bonk_BONK['lossless'];
$info_bonk_BONK['joint_stereo'] = (bool)$info_bonk_BONK['joint_stereo'];
$getid3->info['avdataoffset'] = $info_bonk_BONK['offset'] + 5 + 17;
$getid3->info['avdataend'] = $info_bonk_BONK['offset'] + $info_bonk_BONK['size'];
$getid3->info['fileformat'] = 'bonk';
$info_audio['dataformat'] = 'bonk';
$info_audio['bitrate_mode'] = 'vbr'; // assumed
$info_audio['channels'] = $info_bonk_BONK['channels'];
$info_audio['sample_rate'] = $info_bonk_BONK['sample_rate'];
$info_audio['channelmode'] = $info_bonk_BONK['joint_stereo'] ? 'joint stereo' : 'stereo';
$info_audio['lossless'] = $info_bonk_BONK['lossless'];
$info_audio['codec'] = 'bonk';
$getid3->info['playtime_seconds'] = $info_bonk_BONK['number_samples'] / ($info_bonk_BONK['sample_rate'] * $info_bonk_BONK['channels']);
if ($getid3->info['playtime_seconds'] > 0) {
$info_audio['bitrate'] = (($getid3->info['bonk']['dataend'] - $getid3->info['bonk']['dataoffset']) * 8) / $getid3->info['playtime_seconds'];
}
break;
case 'INFO':
// shortcut
$info_bonk_INFO = &$getid3->info['bonk']['INFO'];
$info_bonk_INFO['version'] = getid3_lib::LittleEndian2Int(fread($getid3->fp, 1));
$info_bonk_INFO['entries_count'] = 0;
$next_info_data_pair = fread($getid3->fp, 5);
if (!getid3_bonk::BonkIsValidTagName(substr($next_info_data_pair, 1, 4))) {
while (!feof($getid3->fp)) {
$next_info_data_pair = fread($getid3->fp, 5);
if (getid3_bonk::BonkIsValidTagName(substr($next_info_data_pair, 1, 4))) {
fseek($getid3->fp, -5, SEEK_CUR);
break;
}
$info_bonk_INFO['entries_count']++;
}
}
break;
case 'META':
$bonk_data = "\x00".'META'.fread($getid3->fp, $getid3->info['bonk']['META']['size'] - 5);
$getid3->info['bonk']['META']['version'] = getid3_lib::LittleEndian2Int(substr($bonk_data, 5, 1));
$meta_tag_entries = floor(((strlen($bonk_data) - 8) - 6) / 8); // BonkData - xxxxmeta - ØMETA
$offset = 6;
for ($i = 0; $i < $meta_tag_entries; $i++) {
$meta_entry_tag_name = substr($bonk_data, $offset, 4);
$offset += 4;
$meta_entry_tag_offset = getid3_lib::LittleEndian2Int(substr($bonk_data, $offset, 4));
$offset += 4;
$getid3->info['bonk']['META']['tags'][$meta_entry_tag_name] = $meta_entry_tag_offset;
}
break;
case ' ID3':
$info_audio['encoder'] = 'Extended BONK v0.9+';
// ID3v2 checking is optional
if (class_exists('getid3_id3v2')) {
$id3v2 = new getid3_id3v2($getid3);
$id3v2->option_starting_offset = $getid3->info['bonk'][' ID3']['offset'] + 2;
$getid3->info['bonk'][' ID3']['valid'] = $id3v2->Analyze();
}
break;
default:
$getid3->warning('Unexpected Bonk tag "'.$bonk_tag_name.'" at offset '.$getid3->info['bonk'][$bonk_tag_name]['offset']);
break;
}
}
public static function BonkIsValidTagName($possible_bonk_tag, $ignore_case=false) {
$ignore_case = $ignore_case ? 'i' : '';
return preg_match('/^(BONK|INFO| ID3|META)$/'.$ignore_case, $possible_bonk_tag);
}
}
?>

View file

@ -0,0 +1,254 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.dts.php |
// | Module for analyzing DTS audio files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.dts.php,v 1.2 2006/11/16 13:14:26 ah Exp $
// Specs taken from "DTS Coherent Acoustics;Core and Extensions, ETSI TS 102 114 V1.2.1 (2002-12)"
// (http://pda.etsi.org/pda/queryform.asp)
// With thanks to Gambit <macteam@users.sourceforge.net> http://mac.sourceforge.net/atl/
class getid3_dts extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->info['dts'] = array ();
$info_dts = &$getid3->info['dts'];
$getid3->info['fileformat'] = 'dts';
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$header = fread($getid3->fp, 16);
$fhBS = getid3_lib::BigEndian2Bin(substr($header, 4, 12));
$bs_offset = 0;
$info_dts['raw']['frame_type'] = bindec(substr($fhBS, $bs_offset, 1)); $bs_offset += 1;
$info_dts['raw']['deficit_samples'] = bindec(substr($fhBS, $bs_offset, 5)); $bs_offset += 5;
$info_dts['flags']['crc_present'] = (bool) bindec(substr($fhBS, $bs_offset, 1)); $bs_offset += 1;
$info_dts['raw']['pcm_sample_blocks'] = bindec(substr($fhBS, $bs_offset, 7)); $bs_offset += 7;
$info_dts['raw']['frame_byte_size'] = bindec(substr($fhBS, $bs_offset, 14)); $bs_offset += 14;
$info_dts['raw']['channel_arrangement'] = bindec(substr($fhBS, $bs_offset, 6)); $bs_offset += 6;
$info_dts['raw']['sample_frequency'] = bindec(substr($fhBS, $bs_offset, 4)); $bs_offset += 4;
$info_dts['raw']['bitrate'] = bindec(substr($fhBS, $bs_offset, 5)); $bs_offset += 5;
$info_dts['flags']['embedded_downmix'] = (bool) bindec(substr($fhBS, $bs_offset, 1)); $bs_offset += 1;
$info_dts['flags']['dynamicrange'] = (bool) bindec(substr($fhBS, $bs_offset, 1)); $bs_offset += 1;
$info_dts['flags']['timestamp'] = (bool) bindec(substr($fhBS, $bs_offset, 1)); $bs_offset += 1;
$info_dts['flags']['auxdata'] = (bool) bindec(substr($fhBS, $bs_offset, 1)); $bs_offset += 1;
$info_dts['flags']['hdcd'] = (bool) bindec(substr($fhBS, $bs_offset, 1)); $bs_offset += 1;
$info_dts['raw']['extension_audio'] = bindec(substr($fhBS, $bs_offset, 3)); $bs_offset += 3;
$info_dts['flags']['extended_coding'] = (bool) bindec(substr($fhBS, $bs_offset, 1)); $bs_offset += 1;
$info_dts['flags']['audio_sync_insertion'] = (bool) bindec(substr($fhBS, $bs_offset, 1)); $bs_offset += 1;
$info_dts['raw']['lfe_effects'] = bindec(substr($fhBS, $bs_offset, 2)); $bs_offset += 2;
$info_dts['flags']['predictor_history'] = (bool) bindec(substr($fhBS, $bs_offset, 1)); $bs_offset += 1;
if ($info_dts['flags']['crc_present']) {
$info_dts['raw']['crc16'] = bindec(substr($fhBS, $bs_offset, 16)); $bs_offset += 16;
}
$info_dts['flags']['mri_perfect_reconst'] = (bool) bindec(substr($fhBS, $bs_offset, 1)); $bs_offset += 1;
$info_dts['raw']['encoder_soft_version'] = bindec(substr($fhBS, $bs_offset, 4)); $bs_offset += 4;
$info_dts['raw']['copy_history'] = bindec(substr($fhBS, $bs_offset, 2)); $bs_offset += 2;
$info_dts['raw']['bits_per_sample'] = bindec(substr($fhBS, $bs_offset, 2)); $bs_offset += 2;
$info_dts['flags']['surround_es'] = (bool) bindec(substr($fhBS, $bs_offset, 1)); $bs_offset += 1;
$info_dts['flags']['front_sum_diff'] = (bool) bindec(substr($fhBS, $bs_offset, 1)); $bs_offset += 1;
$info_dts['flags']['surround_sum_diff'] = (bool) bindec(substr($fhBS, $bs_offset, 1)); $bs_offset += 1;
$info_dts['raw']['dialog_normalization'] = bindec(substr($fhBS, $bs_offset, 4)); $bs_offset += 4;
$info_dts['bitrate'] = $this->DTSbitrateLookup($info_dts['raw']['bitrate']);
$info_dts['bits_per_sample'] = $this->DTSbitPerSampleLookup($info_dts['raw']['bits_per_sample']);
$info_dts['sample_rate'] = $this->DTSsampleRateLookup($info_dts['raw']['sample_frequency']);
$info_dts['dialog_normalization'] = $this->DTSdialogNormalization($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'] = $this->DTSnumChannelsLookup($info_dts['raw']['channel_arrangement']);
$info_dts['channel_arrangement'] = $this->DTSchannelArrangementLookup($info_dts['raw']['channel_arrangement']);
$getid3->info['audio']['dataformat'] = 'dts';
$getid3->info['audio']['lossless'] = $info_dts['flags']['lossless'];
$getid3->info['audio']['bitrate_mode'] = $info_dts['bitrate_mode'];
$getid3->info['audio']['bits_per_sample'] = $info_dts['bits_per_sample'];
$getid3->info['audio']['sample_rate'] = $info_dts['sample_rate'];
$getid3->info['audio']['channels'] = $info_dts['channels'];
$getid3->info['audio']['bitrate'] = $info_dts['bitrate'];
$getid3->info['playtime_seconds'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) / ($info_dts['bitrate'] / 8);
return true;
}
public static function DTSbitrateLookup($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 @$lookup[$index];
}
public static function DTSsampleRateLookup($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 @$lookup[$index];
}
public static function DTSbitPerSampleLookup($index) {
static $lookup = array (
0 => 16,
1 => 20,
2 => 24,
3 => 24,
);
return @$lookup[$index];
}
public static function DTSnumChannelsLookup($index) {
switch ($index) {
case 0:
return 1;
case 1:
case 2:
case 3:
case 4:
return 2;
case 5:
case 6:
return 3;
case 7:
case 8:
return 4;
case 9:
return 5;
case 10:
case 11:
case 12:
return 6;
case 13:
return 7;
case 14:
case 15:
return 8;
}
return false;
}
public static function DTSchannelArrangementLookup($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 (@$lookup[$index] ? @$lookup[$index] : 'user-defined');
}
public static function DTSdialogNormalization($index, $version) {
switch ($version) {
case 7:
return 0 - $index;
case 6:
return 0 - 16 - $index;
}
return false;
}
}
?>

View file

@ -0,0 +1,196 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.la.php |
// | Module for analyzing LA udio files |
// | dependencies: module.audio-video.riff.php |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.la.php,v 1.2 2006/11/02 10:48:01 ah Exp $
class getid3_la extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->include_module('audio-video.riff');
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$raw_data = fread($getid3->fp, getid3::FREAD_BUFFER_SIZE);
$getid3->info['fileformat'] = 'la';
$getid3->info['audio']['dataformat'] = 'la';
$getid3->info['audio']['lossless'] = true;
$getid3->info['la']['version_major'] = (int)$raw_data{2};
$getid3->info['la']['version_minor'] = (int)$raw_data{3};
$getid3->info['la']['version'] = (float)$getid3->info['la']['version_major'] + ($getid3->info['la']['version_minor'] / 10);
$getid3->info['la']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($raw_data, 4, 4));
$wave_chunk = substr($raw_data, 8, 4);
if ($wave_chunk !== 'WAVE') {
throw new getid3_exception('Expected "WAVE" ('.getid3_lib::PrintHexBytes('WAVE').') at offset 8, found "'.$wave_chunk.'" ('.getid3_lib::PrintHexBytes($wave_chunk).') instead.');
}
$offset = 12;
$getid3->info['la']['fmt_size'] = 24;
if ($getid3->info['la']['version'] >= 0.3) {
$getid3->info['la']['fmt_size'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4));
$getid3->info['la']['header_size'] = 49 + $getid3->info['la']['fmt_size'] - 24;
$offset += 4;
} else {
// version 0.2 didn't support additional data blocks
$getid3->info['la']['header_size'] = 41;
}
$fmt_chunk = substr($raw_data, $offset, 4);
if ($fmt_chunk !== 'fmt ') {
throw new getid3_exception('Expected "fmt " ('.getid3_lib::PrintHexBytes('fmt ').') at offset '.$offset.', found "'.$fmt_chunk.'" ('.getid3_lib::PrintHexBytes($fmt_chunk).') instead.');
}
$offset += 4;
$fmt_size = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4));
$offset += 4;
$getid3->info['la']['raw']['format'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 2));
$offset += 2;
getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['la'], $raw_data, $offset,
array (
'channels' => 2,
'sample_rate' => 4,
'bytes_per_second' => 4,
'bytes_per_sample' => 2,
'bits_per_sample' => 2,
'samples' => 4
)
);
$offset += 18;
$getid3->info['la']['raw']['flags'] = getid3_lib::LittleEndian2Int($raw_data{$offset++});
$getid3->info['la']['flags']['seekable'] = (bool)($getid3->info['la']['raw']['flags'] & 0x01);
if ($getid3->info['la']['version'] >= 0.4) {
$getid3->info['la']['flags']['high_compression'] = (bool)($getid3->info['la']['raw']['flags'] & 0x02);
}
$getid3->info['la']['original_crc'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4));
$offset += 4;
// 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 ($getid3->info['la']['version'] >= 0.4) {
$getid3->info['la']['blocksize'] = 61440;
$getid3->info['la']['seekevery'] = 19;
} else {
$getid3->info['la']['blocksize'] = 73728;
$getid3->info['la']['seekevery'] = 16;
}
$getid3->info['la']['seekpoint_count'] = 0;
if ($getid3->info['la']['flags']['seekable']) {
$getid3->info['la']['seekpoint_count'] = floor($getid3->info['la']['samples'] / ($getid3->info['la']['blocksize'] * $getid3->info['la']['seekevery']));
for ($i = 0; $i < $getid3->info['la']['seekpoint_count']; $i++) {
$getid3->info['la']['seekpoints'][] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4));
$offset += 4;
}
}
if ($getid3->info['la']['version'] >= 0.3) {
// 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.
$getid3->info['la']['footerstart'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4));
$offset += 4;
if ($getid3->info['la']['footerstart'] > $getid3->info['filesize']) {
$getid3->warning('FooterStart value points to offset '.$getid3->info['la']['footerstart'].' which is beyond end-of-file ('.$getid3->info['filesize'].')');
$getid3->info['la']['footerstart'] = $getid3->info['filesize'];
}
} else {
// La v0.2 didn't have FooterStart value
$getid3->info['la']['footerstart'] = $getid3->info['avdataend'];
}
if ($getid3->info['la']['footerstart'] < $getid3->info['avdataend']) {
// Create riff header
$riff_data = 'WAVE';
if ($getid3->info['la']['version'] == 0.2) {
$riff_data .= substr($raw_data, 12, 24);
} else {
$riff_data .= substr($raw_data, 16, 24);
}
if ($getid3->info['la']['footerstart'] < $getid3->info['avdataend']) {
fseek($getid3->fp, $getid3->info['la']['footerstart'], SEEK_SET);
$riff_data .= fread($getid3->fp, $getid3->info['avdataend'] - $getid3->info['la']['footerstart']);
}
$riff_data = 'RIFF'.getid3_lib::LittleEndian2String(strlen($riff_data), 4, false).$riff_data;
// Clone getid3 - messing with offsets - better safe than sorry
$clone = clone $getid3;
// Analyze clone by string
$riff = new getid3_riff($clone);
$riff->AnalyzeString($riff_data);
// Import from clone and destroy
$getid3->info['riff'] = $clone->info['riff'];
$getid3->warnings($clone->warnings());
unset($clone);
}
// $getid3->info['avdataoffset'] should be zero to begin with, but just in case it's not, include the addition anyway
$getid3->info['avdataend'] = $getid3->info['avdataoffset'] + $getid3->info['la']['footerstart'];
$getid3->info['avdataoffset'] = $getid3->info['avdataoffset'] + $offset;
$getid3->info['la']['compression_ratio'] = (float)(($getid3->info['avdataend'] - $getid3->info['avdataoffset']) / $getid3->info['la']['uncompressed_size']);
$getid3->info['playtime_seconds'] = (float)($getid3->info['la']['samples'] / $getid3->info['la']['sample_rate']) / $getid3->info['la']['channels'];
$getid3->info['audio']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 / $getid3->info['playtime_seconds'];
$getid3->info['audio']['bits_per_sample'] = $getid3->info['la']['bits_per_sample'];
$getid3->info['audio']['channels'] = $getid3->info['la']['channels'];
$getid3->info['audio']['sample_rate'] = (int)$getid3->info['la']['sample_rate'];
$getid3->info['audio']['encoder'] = 'LA v'.$getid3->info['la']['version'];
return true;
}
}
?>

View file

@ -0,0 +1,148 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.lpac.php |
// | Module for analyzing LPAC Audio files |
// | dependencies: module.audio-video.riff.php |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.lpac.php,v 1.2 2006/11/02 10:48:01 ah Exp $
class getid3_lpac extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->include_module('audio-video.riff');
// Magic bytes - 'LPAC'
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$lpac_header = fread($getid3->fp, 14);
$getid3->info['avdataoffset'] += 14;
$getid3->info['lpac'] = array ();
$info_lpac = &$getid3->info['lpac'];
$getid3->info['fileformat'] = 'lpac';
$getid3->info['audio']['dataformat'] = 'lpac';
$getid3->info['audio']['lossless'] = true;
$getid3->info['audio']['bitrate_mode'] = 'vbr';
$info_lpac['file_version'] = getid3_lib::BigEndian2Int($lpac_header{4});
$flags['audio_type'] = getid3_lib::BigEndian2Int($lpac_header{5});
$info_lpac['total_samples'] = getid3_lib::BigEndian2Int(substr($lpac_header, 6, 4));
$flags['parameters'] = getid3_lib::BigEndian2Int(substr($lpac_header, 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);
if ($info_lpac['flags']['24_bit'] && $info_lpac['flags']['16_bit']) {
$getid3->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);
if ($info_lpac['flags']['fast_compress'] && ($info_lpac['max_prediction_order'] != 3)) {
$getid3->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']) {
$getid3->warning('adaptive_quantization expected to be false in LPAC file stucture v6, actually true');
}
if ($info_lpac['quantization'] != 20) {
$getid3->warning('Quantization expected to be 20 in LPAC file stucture v6, actually '.$info_lpac['flags']['Q']);
}
break;
default:
//$getid3->warning('This version of getID3() only supports LPAC file format version 6, this file is version '.$info_lpac['file_version'].' - please report to info@getid3.org');
break;
}
// Clone getid3 - messing with something - better safe than sorry
$clone = clone $getid3;
// Analyze clone by fp
$riff = new getid3_riff($clone);
$riff->Analyze();
// Import from clone and destroy
$getid3->info['avdataoffset'] = $clone->info['avdataoffset'];
$getid3->info['riff'] = $clone->info['riff'];
//$info_lpac['comments']['comment'] = $clone->info['comments'];
$getid3->info['audio']['sample_rate'] = $clone->info['audio']['sample_rate'];
$getid3->warnings($clone->warnings());
unset($clone);
$getid3->info['audio']['channels'] = ($info_lpac['flags']['stereo'] ? 2 : 1);
if ($info_lpac['flags']['24_bit']) {
$getid3->info['audio']['bits_per_sample'] = $getid3->info['riff']['audio'][0]['bits_per_sample'];
} elseif ($info_lpac['flags']['16_bit']) {
$getid3->info['audio']['bits_per_sample'] = 16;
} else {
$getid3->info['audio']['bits_per_sample'] = 8;
}
if ($info_lpac['flags']['fast_compress']) {
// fast
$getid3->info['audio']['encoder_options'] = '-1';
} else {
switch ($info_lpac['max_prediction_order']) {
case 20: // simple
$getid3->info['audio']['encoder_options'] = '-2';
break;
case 30: // medium
$getid3->info['audio']['encoder_options'] = '-3';
break;
case 40: // high
$getid3->info['audio']['encoder_options'] = '-4';
break;
case 60: // extrahigh
$getid3->info['audio']['encoder_options'] = '-5';
break;
}
}
$getid3->info['playtime_seconds'] = $info_lpac['total_samples'] / $getid3->info['audio']['sample_rate'];
$getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
return true;
}
}
?>

View file

@ -0,0 +1,552 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.midi.php |
// | Module for analyzing midi audio files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.midi.php,v 1.5 2006/11/02 10:48:01 ah Exp $
class getid3_midi extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->info['midi']['raw'] = array ();
$info_midi = &$getid3->info['midi'];
$info_midi_raw = &$info_midi['raw'];
$getid3->info['fileformat'] = 'midi';
$getid3->info['audio']['dataformat'] = 'midi';
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$midi_data = fread($getid3->fp, getid3::FREAD_BUFFER_SIZE);
// Magic bytes: 'MThd'
getid3_lib::ReadSequence('BigEndian2Int', $info_midi_raw, $midi_data, 4,
array (
'headersize' => 4,
'fileformat' => 2,
'tracks' => 2,
'ticksperqnote' => 2
)
);
$offset = 14;
for ($i = 0; $i < $info_midi_raw['tracks']; $i++) {
if ((strlen($midi_data) - $offset) < 8) {
$midi_data .= fread($getid3->fp, getid3::FREAD_BUFFER_SIZE);
}
$track_id = substr($midi_data, $offset, 4);
$offset += 4;
if ($track_id != 'MTrk') {
throw new getid3_exception('Expecting "MTrk" at '.$offset.', found '.$track_id.' instead');
}
$track_size = getid3_lib::BigEndian2Int(substr($midi_data, $offset, 4));
$offset += 4;
$track_data_array[$i] = substr($midi_data, $offset, $track_size);
$offset += $track_size;
}
if (!isset($track_data_array) || !is_array($track_data_array)) {
throw new getid3_exception('Cannot find MIDI track information');
}
$info_midi['totalticks'] = 0;
$getid3->info['playtime_seconds'] = 0;
$current_ms_per_beat = 500000; // 120 beats per minute; 60,000,000 microseconds per minute -> 500,000 microseconds per beat
$current_beats_per_min = 120; // 120 beats per minute; 60,000,000 microseconds per minute -> 500,000 microseconds per beat
$ms_per_quarter_note_after = array ();
foreach ($track_data_array as $track_number => $track_data) {
$events_offset = $last_issued_midi_command = $last_issued_midi_channel = $cumulative_delta_time = $ticks_at_current_bpm = 0;
while ($events_offset < strlen($track_data)) {
$event_id = 0;
if (isset($midi_events[$track_number]) && is_array($midi_events[$track_number])) {
$event_id = count($midi_events[$track_number]);
}
$delta_time = 0;
for ($i = 0; $i < 4; $i++) {
$delta_time_byte = ord($track_data{$events_offset++});
$delta_time = ($delta_time << 7) + ($delta_time_byte & 0x7F);
if ($delta_time_byte & 0x80) {
// another byte follows
} else {
break;
}
}
$cumulative_delta_time += $delta_time;
$ticks_at_current_bpm += $delta_time;
$midi_events[$track_number][$event_id]['deltatime'] = $delta_time;
$midi_event_channel = ord($track_data{$events_offset++});
// OK, normal event - MIDI command has MSB set
if ($midi_event_channel & 0x80) {
$last_issued_midi_command = $midi_event_channel >> 4;
$last_issued_midi_channel = $midi_event_channel & 0x0F;
}
// Running event - assume last command
else {
$events_offset--;
}
$midi_events[$track_number][$event_id]['eventid'] = $last_issued_midi_command;
$midi_events[$track_number][$event_id]['channel'] = $last_issued_midi_channel;
switch ($midi_events[$track_number][$event_id]['eventid']) {
case 0x8: // Note off (key is released)
case 0x9: // Note on (key is pressed)
case 0xA: // Key after-touch
//$notenumber = ord($track_data{$events_offset++});
//$velocity = ord($track_data{$events_offset++});
$events_offset += 2;
break;
case 0xB: // Control Change
//$controllernum = ord($track_data{$events_offset++});
//$newvalue = ord($track_data{$events_offset++});
$events_offset += 2;
break;
case 0xC: // Program (patch) change
$new_program_num = ord($track_data{$events_offset++});
$info_midi_raw['track'][$track_number]['instrumentid'] = $new_program_num;
$info_midi_raw['track'][$track_number]['instrument'] = $track_number == 10 ? getid3_midi::GeneralMIDIpercussionLookup($new_program_num) : getid3_midi::GeneralMIDIinstrumentLookup($new_program_num);
break;
case 0xD: // Channel after-touch
//$channelnumber = ord($track_data{$events_offset++});
break;
case 0xE: // Pitch wheel change (2000H is normal or no change)
//$changeLSB = ord($track_data{$events_offset++});
//$changeMSB = ord($track_data{$events_offset++});
//$pitchwheelchange = (($changeMSB & 0x7F) << 7) & ($changeLSB & 0x7F);
$events_offset += 2;
break;
case 0xF:
if ($midi_events[$track_number][$event_id]['channel'] == 0xF) {
$meta_event_command = ord($track_data{$events_offset++});
$meta_event_length = ord($track_data{$events_offset++});
$meta_event_data = substr($track_data, $events_offset, $meta_event_length);
$events_offset += $meta_event_length;
switch ($meta_event_command) {
case 0x00: // Set track sequence number
//$track_sequence_number = getid3_lib::BigEndian2Int(substr($meta_event_data, 0, $meta_event_length));
//$info_midi_raw['events'][$track_number][$event_id]['seqno'] = $track_sequence_number;
break;
case 0x01: // Text: generic
$text_generic = substr($meta_event_data, 0, $meta_event_length);
//$info_midi_raw['events'][$track_number][$event_id]['text'] = $text_generic;
$info_midi['comments']['comment'][] = $text_generic;
break;
case 0x02: // Text: copyright
$text_copyright = substr($meta_event_data, 0, $meta_event_length);
//$info_midi_raw['events'][$track_number][$event_id]['copyright'] = $text_copyright;
$info_midi['comments']['copyright'][] = $text_copyright;
break;
case 0x03: // Text: track name
$text_trackname = substr($meta_event_data, 0, $meta_event_length);
$info_midi_raw['track'][$track_number]['name'] = $text_trackname;
break;
case 0x04: // Text: track instrument name
//$text_instrument = substr($meta_event_data, 0, $meta_event_length);
//$info_midi_raw['events'][$track_number][$event_id]['instrument'] = $text_instrument;
break;
case 0x05: // Text: lyrics
$text_lyrics = substr($meta_event_data, 0, $meta_event_length);
//$info_midi_raw['events'][$track_number][$event_id]['lyrics'] = $text_lyrics;
if (!isset($info_midi['lyrics'])) {
$info_midi['lyrics'] = '';
}
$info_midi['lyrics'] .= $text_lyrics . "\n";
break;
case 0x06: // Text: marker
//$text_marker = substr($meta_event_data, 0, $meta_event_length);
//$info_midi_raw['events'][$track_number][$event_id]['marker'] = $text_marker;
break;
case 0x07: // Text: cue point
//$text_cuepoint = substr($meta_event_data, 0, $meta_event_length);
//$info_midi_raw['events'][$track_number][$event_id]['cuepoint'] = $text_cuepoint;
break;
case 0x2F: // End Of Track
//$info_midi_raw['events'][$track_number][$event_id]['EOT'] = $cumulative_delta_time;
break;
case 0x51: // Tempo: microseconds / quarter note
$current_ms_per_beat = getid3_lib::BigEndian2Int(substr($meta_event_data, 0, $meta_event_length));
$info_midi_raw['events'][$track_number][$cumulative_delta_time]['us_qnote'] = $current_ms_per_beat;
$current_beats_per_min = (1000000 / $current_ms_per_beat) * 60;
$ms_per_quarter_note_after[$cumulative_delta_time] = $current_ms_per_beat;
$ticks_at_current_bpm = 0;
break;
case 0x58: // Time signature
$timesig_numerator = getid3_lib::BigEndian2Int($meta_event_data[0]);
$timesig_denominator = pow(2, getid3_lib::BigEndian2Int($meta_event_data[1])); // $02 -> x/4, $03 -> x/8, etc
//$timesig_32inqnote = getid3_lib::BigEndian2Int($meta_event_data[2]); // number of 32nd notes to the quarter note
//$info_midi_raw['events'][$track_number][$event_id]['timesig_32inqnote'] = $timesig_32inqnote;
//$info_midi_raw['events'][$track_number][$event_id]['timesig_numerator'] = $timesig_numerator;
//$info_midi_raw['events'][$track_number][$event_id]['timesig_denominator'] = $timesig_denominator;
//$info_midi_raw['events'][$track_number][$event_id]['timesig_text'] = $timesig_numerator.'/'.$timesig_denominator;
$info_midi['timesignature'][] = $timesig_numerator.'/'.$timesig_denominator;
break;
case 0x59: // Keysignature
$keysig_sharpsflats = getid3_lib::BigEndian2Int($meta_event_data{0});
if ($keysig_sharpsflats & 0x80) {
// (-7 -> 7 flats, 0 ->key of C, 7 -> 7 sharps)
$keysig_sharpsflats -= 256;
}
$keysig_majorminor = getid3_lib::BigEndian2Int($meta_event_data{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#');
//$info_midi_raw['events'][$track_number][$event_id]['keysig_sharps'] = (($keysig_sharpsflats > 0) ? abs($keysig_sharpsflats) : 0);
//$info_midi_raw['events'][$track_number][$event_id]['keysig_flats'] = (($keysig_sharpsflats < 0) ? abs($keysig_sharpsflats) : 0);
//$info_midi_raw['events'][$track_number][$event_id]['keysig_minor'] = (bool)$keysig_majorminor;
//$info_midi_raw['events'][$track_number][$event_id]['keysig_text'] = $keysigs[$keysig_sharpsflats].' '.($info_midi_raw['events'][$track_number][$event_id]['keysig_minor'] ? 'minor' : 'major');
// $keysigs[$keysig_sharpsflats] gets an int key (correct) - $keysigs["$keysig_sharpsflats"] gets a string key (incorrect)
$info_midi['keysignature'][] = $keysigs[$keysig_sharpsflats].' '.((bool)$keysig_majorminor ? 'minor' : 'major');
break;
case 0x7F: // Sequencer specific information
$custom_data = substr($meta_event_data, 0, $meta_event_length);
break;
default:
$getid3->warning('Unhandled META Event Command: '.$meta_event_command);
}
}
break;
default:
$getid3->warning('Unhandled MIDI Event ID: '.$midi_events[$track_number][$event_id]['eventid']);
}
}
if (($track_number > 0) || (count($track_data_array) == 1)) {
$info_midi['totalticks'] = max($info_midi['totalticks'], $cumulative_delta_time);
}
}
$previous_tick_offset = null;
ksort($ms_per_quarter_note_after);
foreach ($ms_per_quarter_note_after as $tick_offset => $ms_per_beat) {
if (is_null($previous_tick_offset)) {
$prev_ms_per_beat = $ms_per_beat;
$previous_tick_offset = $tick_offset;
continue;
}
if ($info_midi['totalticks'] > $tick_offset) {
$getid3->info['playtime_seconds'] += (($tick_offset - $previous_tick_offset) / $info_midi_raw['ticksperqnote']) * ($prev_ms_per_beat / 1000000);
$prev_ms_per_beat = $ms_per_beat;
$previous_tick_offset = $tick_offset;
}
}
if ($info_midi['totalticks'] > $previous_tick_offset) {
$getid3->info['playtime_seconds'] += (($info_midi['totalticks'] - $previous_tick_offset) / $info_midi_raw['ticksperqnote']) * ($ms_per_beat / 1000000);
}
if (@$getid3->info['playtime_seconds'] > 0) {
$getid3->info['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
}
if (!empty($info_midi['lyrics'])) {
$info_midi['comments']['lyrics'][] = $info_midi['lyrics'];
}
return true;
}
public static function GeneralMIDIinstrumentLookup($instrument_id) {
static $lookup = array (
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 @$lookup[$instrument_id];
}
public static function GeneralMIDIpercussionLookup($instrument_id) {
static $lookup = array (
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 @$lookup[$instrument_id];
}
}
?>

View file

@ -0,0 +1,216 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.monkey.php |
// | Module for analyzing Monkey's Audio files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.monkey.php,v 1.2 2006/11/02 10:48:01 ah Exp $
class getid3_monkey extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
// based loosely on code from TMonkey by Jurgen Faul <jfaulØgmx*de>
// http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html
$getid3->info['fileformat'] = 'mac';
$getid3->info['audio']['dataformat'] = 'mac';
$getid3->info['audio']['bitrate_mode'] = 'vbr';
$getid3->info['audio']['lossless'] = true;
$getid3->info['monkeys_audio']['raw'] = array ();
$info_monkeys_audio = &$getid3->info['monkeys_audio'];
$info_monkeys_audio_raw = &$info_monkeys_audio['raw'];
// Read file header
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$mac_header_data = fread($getid3->fp, 74);
$info_monkeys_audio_raw['magic'] = 'MAC '; // Magic bytes
// Read MAC version
$info_monkeys_audio_raw['nVersion'] = getid3_lib::LittleEndian2Int(substr($mac_header_data, 4, 2)); // appears to be uint32 in 3.98+
// Parse MAC Header < v3980
if ($info_monkeys_audio_raw['nVersion'] < 3980) {
getid3_lib::ReadSequence("LittleEndian2Int", $info_monkeys_audio_raw, $mac_header_data, 6,
array (
'nCompressionLevel' => 2,
'nFormatFlags' => 2,
'nChannels' => 2,
'nSampleRate' => 4,
'nHeaderDataBytes' => 4,
'nWAVTerminatingBytes' => 4,
'nTotalFrames' => 4,
'nFinalFrameSamples' => 4,
'nPeakLevel' => 4,
'IGNORE-1' => 2,
'nSeekElements' => 2
)
);
}
// Parse MAC Header >= v3980
else {
getid3_lib::ReadSequence("LittleEndian2Int", $info_monkeys_audio_raw, $mac_header_data, 8,
array (
// APE_DESCRIPTOR
'nDescriptorBytes' => 4,
'nHeaderBytes' => 4,
'nSeekTableBytes' => 4,
'nHeaderDataBytes' => 4,
'nAPEFrameDataBytes' => 4,
'nAPEFrameDataBytesHigh'=> 4,
'nTerminatingDataBytes' => 4,
// MD5 - string
'cFileMD5' => -16,
// APE_HEADER
'nCompressionLevel' => 2,
'nFormatFlags' => 2,
'nBlocksPerFrame' => 4,
'nFinalFrameBlocks' => 4,
'nTotalFrames' => 4,
'nBitsPerSample' => 2,
'nChannels' => 2,
'nSampleRate' => 4
)
);
}
// Process data
$info_monkeys_audio['flags']['8-bit'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0001);
$info_monkeys_audio['flags']['crc-32'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0002);
$info_monkeys_audio['flags']['peak_level'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0004);
$info_monkeys_audio['flags']['24-bit'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0008);
$info_monkeys_audio['flags']['seek_elements'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0010);
$info_monkeys_audio['flags']['no_wav_header'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0020);
$info_monkeys_audio['version'] = $info_monkeys_audio_raw['nVersion'] / 1000;
$info_monkeys_audio['compression'] = getid3_monkey::MonkeyCompressionLevelNameLookup($info_monkeys_audio_raw['nCompressionLevel']);
$info_monkeys_audio['bits_per_sample'] = ($info_monkeys_audio['flags']['24-bit'] ? 24 : ($info_monkeys_audio['flags']['8-bit'] ? 8 : 16));
$info_monkeys_audio['channels'] = $info_monkeys_audio_raw['nChannels'];
$getid3->info['audio']['channels'] = $info_monkeys_audio['channels'];
$info_monkeys_audio['sample_rate'] = $info_monkeys_audio_raw['nSampleRate'];
$getid3->info['audio']['sample_rate'] = $info_monkeys_audio['sample_rate'];
if ($info_monkeys_audio['flags']['peak_level']) {
$info_monkeys_audio['peak_level'] = $info_monkeys_audio_raw['nPeakLevel'];
$info_monkeys_audio['peak_ratio'] = $info_monkeys_audio['peak_level'] / pow(2, $info_monkeys_audio['bits_per_sample'] - 1);
}
// MAC >= v3980
if ($info_monkeys_audio_raw['nVersion'] >= 3980) {
$info_monkeys_audio['samples'] = (($info_monkeys_audio_raw['nTotalFrames'] - 1) * $info_monkeys_audio_raw['nBlocksPerFrame']) + $info_monkeys_audio_raw['nFinalFrameBlocks'];
}
// MAC < v3980
else {
$info_monkeys_audio['samples_per_frame'] = getid3_monkey::MonkeySamplesPerFrame($info_monkeys_audio_raw['nVersion'], $info_monkeys_audio_raw['nCompressionLevel']);
$info_monkeys_audio['samples'] = (($info_monkeys_audio_raw['nTotalFrames'] - 1) * $info_monkeys_audio['samples_per_frame']) + $info_monkeys_audio_raw['nFinalFrameSamples'];
}
$info_monkeys_audio['playtime'] = $info_monkeys_audio['samples'] / $info_monkeys_audio['sample_rate'];
$getid3->info['playtime_seconds'] = $info_monkeys_audio['playtime'];
$info_monkeys_audio['compressed_size'] = $getid3->info['avdataend'] - $getid3->info['avdataoffset'];
$info_monkeys_audio['uncompressed_size'] = $info_monkeys_audio['samples'] * $info_monkeys_audio['channels'] * ($info_monkeys_audio['bits_per_sample'] / 8);
$info_monkeys_audio['compression_ratio'] = $info_monkeys_audio['compressed_size'] / ($info_monkeys_audio['uncompressed_size'] + $info_monkeys_audio_raw['nHeaderDataBytes']);
$info_monkeys_audio['bitrate'] = (($info_monkeys_audio['samples'] * $info_monkeys_audio['channels'] * $info_monkeys_audio['bits_per_sample']) / $info_monkeys_audio['playtime']) * $info_monkeys_audio['compression_ratio'];
$getid3->info['audio']['bitrate'] = $info_monkeys_audio['bitrate'];
$getid3->info['audio']['bits_per_sample'] = $info_monkeys_audio['bits_per_sample'];
$getid3->info['audio']['encoder'] = 'MAC v'.number_format($info_monkeys_audio['version'], 2);
$getid3->info['audio']['encoder_options'] = ucfirst($info_monkeys_audio['compression']).' compression';
// MAC >= v3980 - get avdataoffsets from MAC header
if ($info_monkeys_audio_raw['nVersion'] >= 3980) {
$getid3->info['avdataoffset'] += $info_monkeys_audio_raw['nDescriptorBytes'] + $info_monkeys_audio_raw['nHeaderBytes'] + $info_monkeys_audio_raw['nSeekTableBytes'] + $info_monkeys_audio_raw['nHeaderDataBytes'];
$getid3->info['avdataend'] -= $info_monkeys_audio_raw['nTerminatingDataBytes'];
}
// MAC < v3980 Add size of MAC header to avdataoffset
else {
$getid3->info['avdataoffset'] += 8;
}
// Convert md5sum to 32 byte string
if (@$info_monkeys_audio_raw['cFileMD5']) {
if ($info_monkeys_audio_raw['cFileMD5'] !== str_repeat("\x00", 16)) {
$getid3->info['md5_data_source'] = '';
$md5 = $info_monkeys_audio_raw['cFileMD5'];
for ($i = 0; $i < strlen($md5); $i++) {
$getid3->info['md5_data_source'] .= str_pad(dechex(ord($md5{$i})), 2, '00', STR_PAD_LEFT);
}
if (!preg_match('/^[0-9a-f]{32}$/', $getid3->info['md5_data_source'])) {
unset($getid3->info['md5_data_source']);
}
}
}
return true;
}
public static function MonkeyCompressionLevelNameLookup($compression_level) {
static $lookup = array (
0 => 'unknown',
1000 => 'fast',
2000 => 'normal',
3000 => 'high',
4000 => 'extra-high',
5000 => 'insane'
);
return (isset($lookup[$compression_level]) ? $lookup[$compression_level] : 'invalid');
}
public static function MonkeySamplesPerFrame($version_id, $compression_level) {
if ($version_id >= 3950) {
return 73728 * 4;
}
if (($version_id >= 3900) || (($version_id >= 3800) && ($compression_level == 4000))) {
return 73728;
}
return 9216;
}
}
?>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,211 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.mpc.php |
// | Module for analyzing Musepack/MPEG+ Audio files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.mpc.php,v 1.3 2006/11/02 10:48:01 ah Exp $
class getid3_mpc extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
// http://www.uni-jena.de/~pfk/mpp/sv8/header.html
$getid3->info['fileformat'] = 'mpc';
$getid3->info['audio']['dataformat'] = 'mpc';
$getid3->info['audio']['bitrate_mode'] = 'vbr';
$getid3->info['audio']['channels'] = 2; // the format appears to be hardcoded for stereo only
$getid3->info['audio']['lossless'] = false;
$getid3->info['mpc']['header'] = array ();
$info_mpc_header = &$getid3->info['mpc']['header'];
$info_mpc_header['size'] = 28;
$info_mpc_header['raw']['preamble'] = 'MP+'; // Magic bytes
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$mpc_header_data = fread($getid3->fp, 28);
$stream_version_byte = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 3, 1));
$info_mpc_header['stream_major_version'] = ($stream_version_byte & 0x0F);
$info_mpc_header['stream_minor_version'] = ($stream_version_byte & 0xF0) >> 4;
if ($info_mpc_header['stream_major_version'] != 7) {
throw new getid3_exception('Only Musepack SV7 supported');
}
$info_mpc_header['frame_count'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 4, 4));
$info_mpc_header['raw']['title_peak'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 12, 2));
$info_mpc_header['raw']['title_gain'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 14, 2), true);
$info_mpc_header['raw']['album_peak'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 16, 2));
$info_mpc_header['raw']['album_gain'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 18, 2), true);
$info_mpc_header['raw']['not_sure_what'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 24, 3));
$info_mpc_header['raw']['encoder_version'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 27, 1));
$flags_dword1 = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 8, 4));
$flags_dword2 = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 20, 4));
$info_mpc_header['intensity_stereo'] = (bool)(($flags_dword1 & 0x80000000) >> 31);
$info_mpc_header['mid_side_stereo'] = (bool)(($flags_dword1 & 0x40000000) >> 30);
$info_mpc_header['max_subband'] = ($flags_dword1 & 0x3F000000) >> 24;
$info_mpc_header['raw']['profile'] = ($flags_dword1 & 0x00F00000) >> 20;
$info_mpc_header['begin_loud'] = (bool)(($flags_dword1 & 0x00080000) >> 19);
$info_mpc_header['end_loud'] = (bool)(($flags_dword1 & 0x00040000) >> 18);
$info_mpc_header['raw']['sample_rate'] = ($flags_dword1 & 0x00030000) >> 16;
$info_mpc_header['max_level'] = ($flags_dword1 & 0x0000FFFF);
$info_mpc_header['true_gapless'] = (bool)(($flags_dword2 & 0x80000000) >> 31);
$info_mpc_header['last_frame_length'] = ($flags_dword2 & 0x7FF00000) >> 20;
$info_mpc_header['profile'] = getid3_mpc::MPCprofileNameLookup($info_mpc_header['raw']['profile']);
$info_mpc_header['sample_rate'] = getid3_mpc::MPCfrequencyLookup($info_mpc_header['raw']['sample_rate']);
$getid3->info['audio']['sample_rate'] = $info_mpc_header['sample_rate'];
$info_mpc_header['samples'] = ((($info_mpc_header['frame_count'] - 1) * 1152) + $info_mpc_header['last_frame_length']) * $getid3->info['audio']['channels'];
$getid3->info['playtime_seconds'] = ($info_mpc_header['samples'] / $getid3->info['audio']['channels']) / $getid3->info['audio']['sample_rate'];
$getid3->info['avdataoffset'] += $info_mpc_header['size'];
$getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
$info_mpc_header['title_peak'] = $info_mpc_header['raw']['title_peak'];
$info_mpc_header['title_peak_db'] = getid3_mpc::MPCpeakDBLookup($info_mpc_header['title_peak']);
if ($info_mpc_header['raw']['title_gain'] < 0) {
$info_mpc_header['title_gain_db'] = (float)(32768 + $info_mpc_header['raw']['title_gain']) / -100;
}
else {
$info_mpc_header['title_gain_db'] = (float)$info_mpc_header['raw']['title_gain'] / 100;
}
$info_mpc_header['album_peak'] = $info_mpc_header['raw']['album_peak'];
$info_mpc_header['album_peak_db'] = getid3_mpc::MPCpeakDBLookup($info_mpc_header['album_peak']);
if ($info_mpc_header['raw']['album_gain'] < 0) {
$info_mpc_header['album_gain_db'] = (float)(32768 + $info_mpc_header['raw']['album_gain']) / -100;
}
else {
$info_mpc_header['album_gain_db'] = (float)$info_mpc_header['raw']['album_gain'] / 100;;
}
$info_mpc_header['encoder_version'] = getid3_mpc::MPCencoderVersionLookup($info_mpc_header['raw']['encoder_version']);
$getid3->info['replay_gain']['track']['adjustment'] = $info_mpc_header['title_gain_db'];
$getid3->info['replay_gain']['album']['adjustment'] = $info_mpc_header['album_gain_db'];
if ($info_mpc_header['title_peak'] > 0) {
$getid3->info['replay_gain']['track']['peak'] = $info_mpc_header['title_peak'];
}
elseif (round($info_mpc_header['max_level'] * 1.18) > 0) {
$getid3->info['replay_gain']['track']['peak'] = (int)(round($info_mpc_header['max_level'] * 1.18)); // why? I don't know - see mppdec.c
}
if ($info_mpc_header['album_peak'] > 0) {
$getid3->info['replay_gain']['album']['peak'] = $info_mpc_header['album_peak'];
}
$getid3->info['audio']['encoder'] = $info_mpc_header['encoder_version'];
$getid3->info['audio']['encoder_options'] = $info_mpc_header['profile'];
return true;
}
public static function MPCprofileNameLookup($profileid) {
static $lookup = 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($lookup[$profileid]) ? $lookup[$profileid] : 'invalid');
}
public static function MPCfrequencyLookup($frequencyid) {
static $lookup = array (
0 => 44100,
1 => 48000,
2 => 37800,
3 => 32000
);
return (isset($lookup[$frequencyid]) ? $lookup[$frequencyid] : 'invalid');
}
public static function MPCpeakDBLookup($int_value) {
if ($int_value > 0) {
return ((log10($int_value) / log10(2)) - 15) * 6;
}
return false;
}
public static function MPCencoderVersionLookup($encoder_version) {
//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 ($encoder_version == 0) {
// very old version, not known exactly which
return 'Buschmann v1.7.0-v1.7.9 or Klemm v0.90-v1.05';
}
if (($encoder_version % 10) == 0) {
// release version
return number_format($encoder_version / 100, 2);
} elseif (($encoder_version % 2) == 0) {
// beta version
return number_format($encoder_version / 100, 2).' beta';
}
// alpha version
return number_format($encoder_version / 100, 2).' alpha';
}
}
?>

View file

@ -0,0 +1,107 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.mpc_old.php |
// | Module for analyzing Musepack/MPEG+ Audio files - SV4-SV6 |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.mpc_old.php,v 1.2 2006/11/02 10:48:01 ah Exp $
class getid3_mpc_old extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
// http://www.uni-jena.de/~pfk/mpp/sv8/header.html
$getid3->info['mpc']['header'] = array ();
$info_mpc_header = &$getid3->info['mpc']['header'];
$getid3->info['fileformat'] = 'mpc';
$getid3->info['audio']['dataformat'] = 'mpc';
$getid3->info['audio']['bitrate_mode'] = 'vbr';
$getid3->info['audio']['channels'] = 2; // the format appears to be hardcoded for stereo only
$getid3->info['audio']['lossless'] = false;
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$info_mpc_header['size'] = 8;
$getid3->info['avdataoffset'] += $info_mpc_header['size'];
$mpc_header_data = fread($getid3->fp, $info_mpc_header['size']);
// Most of this code adapted from Jurgen Faul's MPEGplus source code - thanks Jurgen! :)
$header_dword[0] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 0, 4));
$header_dword[1] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 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
$info_mpc_header['target_bitrate'] = (($header_dword[0] & 0xFF800000) >> 23);
$info_mpc_header['intensity_stereo'] = (bool)(($header_dword[0] & 0x00400000) >> 22);
$info_mpc_header['mid-side_stereo'] = (bool)(($header_dword[0] & 0x00200000) >> 21);
$info_mpc_header['stream_major_version'] = ($header_dword[0] & 0x001FF800) >> 11;
$info_mpc_header['stream_minor_version'] = 0;
$info_mpc_header['max_band'] = ($header_dword[0] & 0x000007C0) >> 6; // related to lowpass frequency, not sure how it translates exactly
$info_mpc_header['block_size'] = ($header_dword[0] & 0x0000003F);
switch ($info_mpc_header['stream_major_version']) {
case 4:
$info_mpc_header['frame_count'] = ($header_dword[1] >> 16);
break;
case 5:
case 6:
$info_mpc_header['frame_count'] = $header_dword[1];
break;
default:
throw new getid3_exception('Expecting 4, 5 or 6 in version field, found '.$info_mpc_header['stream_major_version'].' instead');
}
if (($info_mpc_header['stream_major_version'] > 4) && ($info_mpc_header['block_size'] != 1)) {
$getid3->warning('Block size expected to be 1, actual value found: '.$info_mpc_header['block_size']);
}
$info_mpc_header['sample_rate'] = $getid3->info['audio']['sample_rate'] = 44100; // AB: used by all files up to SV7
$info_mpc_header['samples'] = $info_mpc_header['frame_count'] * 1152 * $getid3->info['audio']['channels'];
$getid3->info['audio']['bitrate_mode'] = $info_mpc_header['target_bitrate'] == 0 ? 'vbr' : 'cbr';
$getid3->info['mpc']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 * 44100 / $info_mpc_header['frame_count'] / 1152;
$getid3->info['audio']['bitrate'] = $getid3->info['mpc']['bitrate'];
$getid3->info['audio']['encoder'] = 'SV'.$info_mpc_header['stream_major_version'];
return true;
}
}
?>

View file

@ -0,0 +1,468 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.optimfrog.php |
// | Module for analyzing OptimFROG Audio files |
// | dependencies: module.audio-video.riff.php |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.optimfrog.php,v 1.3 2006/11/02 10:48:01 ah Exp $
class getid3_optimfrog extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->include_module('audio-video.riff');
$getid3->info['audio']['dataformat'] = 'ofr';
$getid3->info['audio']['bitrate_mode'] = 'vbr';
$getid3->info['audio']['lossless'] = true;
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$ofr_header = fread($getid3->fp, 8);
if (substr($ofr_header, 0, 5) == '*RIFF') {
return $this->ParseOptimFROGheader42($getid3->fp, $getid3->info);
} elseif (substr($ofr_header, 0, 3) == 'OFR') {
return $this->ParseOptimFROGheader45($getid3->fp, $getid3->info);
}
throw new getid3_exception('Expecting "*RIFF" or "OFR " at offset '.$getid3->info['avdataoffset'].', found "'.$ofr_header.'"');
}
private function ParseOptimFROGheader42() {
$getid3 = $this->getid3;
// for fileformat of v4.21 and older
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$ofr_header_data = fread($getid3->fp, 45);
$getid3->info['avdataoffset'] = 45;
$ofr_encoder_version_raw = getid3_lib::LittleEndian2Int(substr($ofr_header_data, 0, 1));
$ofr_encoder_version_major = floor($ofr_encoder_version_raw / 10);
$ofr_encoder_version_minor = $ofr_encoder_version_raw - ($ofr_encoder_version_major * 10);
$riff_data = substr($ofr_header_data, 1, 44);
$origna_riff_header_size = getid3_lib::LittleEndian2Int(substr($riff_data, 4, 4)) + 8;
$origna_riff_data_size = getid3_lib::LittleEndian2Int(substr($riff_data, 40, 4)) + 44;
if ($origna_riff_header_size > $origna_riff_data_size) {
$getid3->info['avdataend'] -= ($origna_riff_header_size - $origna_riff_data_size);
fseek($getid3->fp, $getid3->info['avdataend'], SEEK_SET);
$riff_data .= fread($getid3->fp, $origna_riff_header_size - $origna_riff_data_size);
}
// 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
$riff_data = substr($riff_data, 0, 36).substr($riff_data, 44).substr($riff_data, 36, 8);
// Save audio info key
$saved_info_audio = $getid3->info['audio'];
// Instantiate riff module and analyze string
$riff = new getid3_riff($getid3);
$riff->AnalyzeString($riff_data);
// Restore info key
$getid3->info['audio'] = $saved_info_audio;
$getid3->info['audio']['encoder'] = 'OptimFROG '.$ofr_encoder_version_major.'.'.$ofr_encoder_version_minor;
$getid3->info['audio']['channels'] = $getid3->info['riff']['audio'][0]['channels'];
$getid3->info['audio']['sample_rate'] = $getid3->info['riff']['audio'][0]['sample_rate'];
$getid3->info['audio']['bits_per_sample'] = $getid3->info['riff']['audio'][0]['bits_per_sample'];
$getid3->info['playtime_seconds'] = $origna_riff_data_size / ($getid3->info['audio']['channels'] * $getid3->info['audio']['sample_rate'] * ($getid3->info['audio']['bits_per_sample'] / 8));
$getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
$getid3->info['fileformat'] = 'ofr';
return true;
}
private function ParseOptimFROGheader45() {
$getid3 = $this->getid3;
// for fileformat of v4.50a and higher
$riff_data = '';
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
while (!feof($getid3->fp) && (ftell($getid3->fp) < $getid3->info['avdataend'])) {
$block_offset = ftell($getid3->fp);
$block_data = fread($getid3->fp, 8);
$offset = 8;
$block_name = substr($block_data, 0, 4);
$block_size = getid3_lib::LittleEndian2Int(substr($block_data, 4, 4));
if ($block_name == 'OFRX') {
$block_name = 'OFR ';
}
if (!isset($getid3->info['ofr'][$block_name])) {
$getid3->info['ofr'][$block_name] = array ();
}
$info_ofr_this_block = &$getid3->info['ofr'][$block_name];
switch ($block_name) {
case 'OFR ':
// shortcut
$info_ofr_this_block['offset'] = $block_offset;
$info_ofr_this_block['size'] = $block_size;
$getid3->info['audio']['encoder'] = 'OptimFROG 4.50 alpha';
switch ($block_size) {
case 12:
case 15:
// good
break;
default:
$getid3->warning('"'.$block_name.'" contains more data than expected (expected 12 or 15 bytes, found '.$block_size.' bytes)');
break;
}
$block_data .= fread($getid3->fp, $block_size);
$info_ofr_this_block['total_samples'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 6));
$offset += 6;
$info_ofr_this_block['raw']['sample_type'] = getid3_lib::LittleEndian2Int($block_data{$offset++});
$info_ofr_this_block['sample_type'] = $this->OptimFROGsampleTypeLookup($info_ofr_this_block['raw']['sample_type']);
$info_ofr_this_block['channel_config'] = getid3_lib::LittleEndian2Int($block_data{$offset++});
$info_ofr_this_block['channels'] = $info_ofr_this_block['channel_config'];
$info_ofr_this_block['sample_rate'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 4));
$offset += 4;
if ($block_size > 12) {
// OFR 4.504b or higher
$info_ofr_this_block['channels'] = $this->OptimFROGchannelConfigNumChannelsLookup($info_ofr_this_block['channel_config']);
$info_ofr_this_block['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 2));
$info_ofr_this_block['encoder'] = $this->OptimFROGencoderNameLookup($info_ofr_this_block['raw']['encoder_id']);
$offset += 2;
$info_ofr_this_block['raw']['compression'] = getid3_lib::LittleEndian2Int($block_data{$offset++});
$info_ofr_this_block['compression'] = $this->OptimFROGcompressionLookup($info_ofr_this_block['raw']['compression']);
$info_ofr_this_block['speedup'] = $this->OptimFROGspeedupLookup($info_ofr_this_block['raw']['compression']);
$getid3->info['audio']['encoder'] = 'OptimFROG '.$info_ofr_this_block['encoder'];
$getid3->info['audio']['encoder_options'] = '--mode '.$info_ofr_this_block['compression'];
if ((($info_ofr_this_block['raw']['encoder_id'] & 0xF0) >> 4) == 7) { // v4.507
if (preg_match('/\.ofs$/i', $getid3->filename)) {
// 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.
$getid3->info['audio']['dataformat'] = 'ofs';
$getid3->info['audio']['lossless'] = true;
}
}
}
$getid3->info['audio']['channels'] = $info_ofr_this_block['channels'];
$getid3->info['audio']['sample_rate'] = $info_ofr_this_block['sample_rate'];
$getid3->info['audio']['bits_per_sample'] = $this->OptimFROGbitsPerSampleTypeLookup($info_ofr_this_block['raw']['sample_type']);
break;
case 'COMP':
// unlike other block types, there CAN be multiple COMP blocks
$comp_data['offset'] = $block_offset;
$comp_data['size'] = $block_size;
if ($getid3->info['avdataoffset'] == 0) {
$getid3->info['avdataoffset'] = $block_offset;
}
// Only interested in first 14 bytes (only first 12 needed for v4.50 alpha), not actual audio data
$block_data .= fread($getid3->fp, 14);
fseek($getid3->fp, $block_size - 14, SEEK_CUR);
$comp_data['crc_32'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 4));
$offset += 4;
$comp_data['sample_count'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 4));
$offset += 4;
$comp_data['raw']['sample_type'] = getid3_lib::LittleEndian2Int($block_data{$offset++});
$comp_data['sample_type'] = $this->OptimFROGsampleTypeLookup($comp_data['raw']['sample_type']);
$comp_data['raw']['channel_configuration'] = getid3_lib::LittleEndian2Int($block_data{$offset++});
$comp_data['channel_configuration'] = $this->OptimFROGchannelConfigurationLookup($comp_data['raw']['channel_configuration']);
$comp_data['raw']['algorithm_id'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 2));
$offset += 2;
if ($getid3->info['ofr']['OFR ']['size'] > 12) {
// OFR 4.504b or higher
$comp_data['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($block_data, $offset, 2));
$comp_data['encoder'] = $this->OptimFROGencoderNameLookup($comp_data['raw']['encoder_id']);
$offset += 2;
}
if ($comp_data['crc_32'] == 0x454E4F4E) {
// ASCII value of 'NONE' - placeholder value in v4.50a
$comp_data['crc_32'] = false;
}
$info_ofr_this_block[] = $comp_data;
break;
case 'HEAD':
$info_ofr_this_block['offset'] = $block_offset;
$info_ofr_this_block['size'] = $block_size;
$riff_data .= fread($getid3->fp, $block_size);
break;
case 'TAIL':
$info_ofr_this_block['offset'] = $block_offset;
$info_ofr_this_block['size'] = $block_size;
if ($block_size > 0) {
$riff_data .= fread($getid3->fp, $block_size);
}
break;
case 'RECV':
// block contains no useful meta data - simply note and skip
$info_ofr_this_block['offset'] = $block_offset;
$info_ofr_this_block['size'] = $block_size;
fseek($getid3->fp, $block_size, SEEK_CUR);
break;
case 'APET':
// APEtag v2
$info_ofr_this_block['offset'] = $block_offset;
$info_ofr_this_block['size'] = $block_size;
$getid3->warning('APEtag processing inside OptimFROG not supported in this version ('.GETID3_VERSION.') of getID3()');
fseek($getid3->fp, $block_size, SEEK_CUR);
break;
case 'MD5 ':
// APEtag v2
$info_ofr_this_block['offset'] = $block_offset;
$info_ofr_this_block['size'] = $block_size;
if ($block_size == 16) {
$info_ofr_this_block['md5_binary'] = fread($getid3->fp, $block_size);
$info_ofr_this_block['md5_string'] = getid3_lib::PrintHexBytes($info_ofr_this_block['md5_binary'], true, false, false);
$getid3->info['md5_data_source'] = $info_ofr_this_block['md5_string'];
} else {
$getid3->warning('Expecting block size of 16 in "MD5 " chunk, found '.$block_size.' instead');
fseek($getid3->fp, $block_size, SEEK_CUR);
}
break;
default:
$info_ofr_this_block['offset'] = $block_offset;
$info_ofr_this_block['size'] = $block_size;
$getid3->warning('Unhandled OptimFROG block type "'.$block_name.'" at offset '.$info_ofr_this_block['offset']);
fseek($getid3->fp, $block_size, SEEK_CUR);
break;
}
}
if (isset($getid3->info['ofr']['TAIL']['offset'])) {
$getid3->info['avdataend'] = $getid3->info['ofr']['TAIL']['offset'];
}
$getid3->info['playtime_seconds'] = (float)$getid3->info['ofr']['OFR ']['total_samples'] / ($getid3->info['audio']['channels'] * $getid3->info['audio']['sample_rate']);
$getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->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
$riff_data = substr($riff_data, 0, 36).substr($riff_data, 44).substr($riff_data, 36, 8);
// Save audio info key
$saved_info_audio = $getid3->info['audio'];
// Instantiate riff module and analyze string
$riff = new getid3_riff($getid3);
$riff->AnalyzeString($riff_data);
// Restore info key
$getid3->info['audio'] = $saved_info_audio;
$getid3->info['fileformat'] = 'ofr';
return true;
}
public static function OptimFROGsampleTypeLookup($sample_type) {
static $lookup = 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 @$lookup[$sample_type];
}
public static function OptimFROGbitsPerSampleTypeLookup($sample_type) {
static $lookup = array (
0 => 8,
1 => 8,
2 => 16,
3 => 16,
4 => 24,
5 => 24,
6 => 32,
7 => 32,
8 => 32,
9 => 32,
10 => 32
);
return @$lookup[$sample_type];
}
public static function OptimFROGchannelConfigurationLookup($channel_configuration) {
static $lookup = array (
0 => 'mono',
1 => 'stereo'
);
return @$lookup[$channel_configuration];
}
public static function OptimFROGchannelConfigNumChannelsLookup($channel_configuration) {
static $lookup = array (
0 => 1,
1 => 2
);
return @$lookup[$channel_configuration];
}
public static function OptimFROGencoderNameLookup($encoder_id) {
// version = (encoderID >> 4) + 4500
// system = encoderID & 0xF
$encoder_version = number_format(((($encoder_id & 0xF0) >> 4) + 4500) / 1000, 3);
$encoder_system_id = ($encoder_id & 0x0F);
static $lookup = array (
0x00 => 'Windows console',
0x01 => 'Linux console',
0x0F => 'unknown'
);
return $encoder_version.' ('.(isset($lookup[$encoder_system_id]) ? $lookup[$encoder_system_id] : 'undefined encoder type (0x'.dechex($encoder_system_id).')').')';
}
public static function OptimFROGcompressionLookup($compression_id) {
// mode = compression >> 3
// speedup = compression & 0x07
$compression_mode_id = ($compression_id & 0xF8) >> 3;
//$compression_speed_up_id = ($compression_id & 0x07);
static $lookup = 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($lookup[$compression_mode_id]) ? $lookup[$compression_mode_id] : 'undefined mode (0x'.str_pad(dechex($compression_mode_id), 2, '0', STR_PAD_LEFT).')');
}
public static function OptimFROGspeedupLookup($compression_id) {
// mode = compression >> 3
// speedup = compression & 0x07
//$compression_mode_id = ($compression_id & 0xF8) >> 3;
$compression_speed_up_id = ($compression_id & 0x07);
static $lookup = array (
0x00 => '1x',
0x01 => '2x',
0x02 => '4x'
);
return (isset($lookup[$compression_speed_up_id]) ? $lookup[$compression_speed_up_id] : 'undefined mode (0x'.dechex($compression_speed_up_id));
}
}
?>

View file

@ -0,0 +1,101 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.rkau.php |
// | Module for analyzing RKAU Audio files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.rkau.php,v 1.2 2006/11/02 10:48:01 ah Exp $
class getid3_rkau extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$rkau_header = fread($getid3->fp, 20);
// Magic bytes 'RKA'
$getid3->info['fileformat'] = 'rkau';
$getid3->info['audio']['dataformat'] = 'rkau';
$getid3->info['audio']['bitrate_mode'] = 'vbr';
// Shortcut
$getid3->info['rkau'] = array ();
$info_rkau = &$getid3->info['rkau'];
$info_rkau['raw']['version'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 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)) {
throw new getid3_exception('This version of getID3() can only parse RKAU files v1.06 and 1.07 (this file is v'.$info_rkau['version'].')');
}
getid3_lib::ReadSequence('LittleEndian2Int', $info_rkau, $rkau_header, 4,
array (
'source_bytes' => 4,
'sample_rate' => 4,
'channels' => 1,
'bits_per_sample' => 1
)
);
$info_rkau['raw']['quality'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 14, 1));
$quality = $info_rkau['raw']['quality'] & 0x0F;
$info_rkau['lossless'] = (($quality == 0) ? true : false);
$info_rkau['compression_level'] = (($info_rkau['raw']['quality'] & 0xF0) >> 4) + 1;
if (!$info_rkau['lossless']) {
$info_rkau['quality_setting'] = $quality;
}
$info_rkau['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 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);
if ($info_rkau['flags']['streaming']) {
$getid3->info['avdataoffset'] += 20;
$info_rkau['compressed_bytes'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 16, 4));
}
else {
$getid3->info['avdataoffset'] += 16;
$info_rkau['compressed_bytes'] = $getid3->info['avdataend'] - $getid3->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(?)
$getid3->info['audio']['lossless'] = $info_rkau['lossless'];
$getid3->info['audio']['channels'] = $info_rkau['channels'];
$getid3->info['audio']['bits_per_sample'] = $info_rkau['bits_per_sample'];
$getid3->info['audio']['sample_rate'] = $info_rkau['sample_rate'];
$getid3->info['playtime_seconds'] = $info_rkau['source_bytes'] / ($info_rkau['sample_rate'] * $info_rkau['channels'] * ($info_rkau['bits_per_sample'] / 8));
$getid3->info['audio']['bitrate'] = ($info_rkau['compressed_bytes'] * 8) / $getid3->info['playtime_seconds'];
return true;
}
}
?>

View file

@ -0,0 +1,121 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.shorten.php |
// | Module for analyzing Shorten Audio files |
// | dependencies: module.audio-video.riff.php |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.shorten.php,v 1.5 2006/12/03 19:28:18 ah Exp $
class getid3_shorten extends getid3_handler
{
public function __construct(getID3 $getid3) {
parent::__construct($getid3);
if ((bool)ini_get('safe_mode')) {
throw new getid3_exception('PHP running in Safe Mode - backtick operator not available, cannot analyze Shorten files.');
}
if (!`head --version`) {
throw new getid3_exception('head[.exe] binary not found in path. UNIX: typically /usr/bin. Windows: typically c:\windows\system32.');
}
if (!`shorten -l`) {
throw new getid3_exception('shorten[.exe] binary not found in path. UNIX: typically /usr/bin. Windows: typically c:\windows\system32.');
}
}
public function Analyze() {
$getid3 = $this->getid3;
$getid3->include_module('audio-video.riff');
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$shn_header = fread($getid3->fp, 8);
// Magic bytes: "ajkg"
$getid3->info['fileformat'] = 'shn';
$getid3->info['audio']['dataformat'] = 'shn';
$getid3->info['audio']['lossless'] = true;
$getid3->info['audio']['bitrate_mode'] = 'vbr';
$getid3->info['shn']['version'] = getid3_lib::LittleEndian2Int($shn_header{4});
fseek($getid3->fp, $getid3->info['avdataend'] - 12, SEEK_SET);
$seek_table_signature_test = fread($getid3->fp, 12);
$getid3->info['shn']['seektable']['present'] = (bool)(substr($seek_table_signature_test, 4, 8) == 'SHNAMPSK');
if ($getid3->info['shn']['seektable']['present']) {
$getid3->info['shn']['seektable']['length'] = getid3_lib::LittleEndian2Int(substr($seek_table_signature_test, 0, 4));
$getid3->info['shn']['seektable']['offset'] = $getid3->info['avdataend'] - $getid3->info['shn']['seektable']['length'];
fseek($getid3->fp, $getid3->info['shn']['seektable']['offset'], SEEK_SET);
$seek_table_magic = fread($getid3->fp, 4);
if ($seek_table_magic != 'SEEK') {
throw new getid3_exception('Expecting "SEEK" at offset '.$getid3->info['shn']['seektable']['offset'].', found "'.$seek_table_magic.'"');
}
$seek_table_data = fread($getid3->fp, $getid3->info['shn']['seektable']['length'] - 16);
$getid3->info['shn']['seektable']['entry_count'] = floor(strlen($seek_table_data) / 80);
}
$commandline = 'shorten -x '.escapeshellarg(realpath($getid3->filename)).' - | head -c 64';
$output = `$commandline`;
if (@$output && substr($output, 12, 4) == 'fmt ') {
$fmt_size = getid3_lib::LittleEndian2Int(substr($output, 16, 4));
$decoded_wav_format_ex = getid3_riff::RIFFparseWAVEFORMATex(substr($output, 20, $fmt_size));
$getid3->info['audio']['channels'] = $decoded_wav_format_ex['channels'];
$getid3->info['audio']['bits_per_sample'] = $decoded_wav_format_ex['bits_per_sample'];
$getid3->info['audio']['sample_rate'] = $decoded_wav_format_ex['sample_rate'];
if (substr($output, 20 + $fmt_size, 4) == 'data') {
$getid3->info['playtime_seconds'] = getid3_lib::LittleEndian2Int(substr($output, 20 + 4 + $fmt_size, 4)) / $decoded_wav_format_ex['raw']['nAvgBytesPerSec'];
} else {
throw new getid3_exception('shorten failed to decode DATA chunk to expected location, cannot determine playtime');
}
$getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) / $getid3->info['playtime_seconds']) * 8;
} else {
throw new getid3_exception('shorten failed to decode file to WAV for parsing');
return false;
}
return true;
}
}
?>

View file

@ -0,0 +1,125 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.tta.php |
// | Module for analyzing TTA Audio files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.tta.php,v 1.2 2006/11/02 10:48:01 ah Exp $
class getid3_tta extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->info['fileformat'] = 'tta';
$getid3->info['audio']['dataformat'] = 'tta';
$getid3->info['audio']['lossless'] = true;
$getid3->info['audio']['bitrate_mode'] = 'vbr';
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$tta_header = fread($getid3->fp, 26);
$getid3->info['tta']['magic'] = 'TTA'; // Magic bytes
switch ($tta_header{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."
$getid3->info['tta']['major_version'] = 1;
$getid3->info['avdataoffset'] += 16;
getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4,
array (
'channels' => 2,
'bits_per_sample' => 2,
'sample_rate' => 4,
'samples_per_channel' => 4
)
);
$getid3->info['tta']['compression_level'] = ord($tta_header{3});
$getid3->info['audio']['encoder_options'] = '-e'.$getid3->info['tta']['compression_level'];
$getid3->info['playtime_seconds'] = $getid3->info['tta']['samples_per_channel'] / $getid3->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."
$getid3->info['tta']['major_version'] = 2;
$getid3->info['avdataoffset'] += 20;
getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4,
array (
'compression_level' => 2,
'audio_format' => 2,
'channels' => 2,
'bits_per_sample' => 2,
'sample_rate' => 4,
'data_length' => 4
)
);
$getid3->info['audio']['encoder_options'] = '-e'.$getid3->info['tta']['compression_level'];
$getid3->info['playtime_seconds'] = $getid3->info['tta']['data_length'] / $getid3->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."
$getid3->info['tta']['major_version'] = 3;
$getid3->info['avdataoffset'] += 26;
getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4,
array (
'audio_format' => 2,
'channels' => 2,
'bits_per_sample'=> 2,
'sample_rate' => 4,
'data_length' => 4,
'crc32_footer' => -4, // string
'seek_point' => 4
)
);
$getid3->info['playtime_seconds'] = $getid3->info['tta']['data_length'] / $getid3->info['tta']['sample_rate'];
break;
default:
throw new getid3_exception('This version of getID3() only knows how to handle TTA v1, v2 and v3 - it may not work correctly with this file which appears to be TTA v'.$tta_header{3});
return false;
break;
}
$getid3->info['audio']['encoder'] = 'TTA v'.$getid3->info['tta']['major_version'];
$getid3->info['audio']['bits_per_sample'] = $getid3->info['tta']['bits_per_sample'];
$getid3->info['audio']['sample_rate'] = $getid3->info['tta']['sample_rate'];
$getid3->info['audio']['channels'] = $getid3->info['tta']['channels'];
$getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
return true;
}
}
?>

View file

@ -0,0 +1,240 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.voc.php |
// | Module for analyzing Creative VOC Audio files. |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.voc.php,v 1.3 2006/11/02 10:48:02 ah Exp $
class getid3_voc extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$original_av_data_offset = $getid3->info['avdataoffset'];
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$voc_header= fread($getid3->fp, 26);
// Magic bytes: 'Creative Voice File'
$info_audio = &$getid3->info['audio'];
$getid3->info['voc'] = array ();
$info_voc = &$getid3->info['voc'];
$getid3->info['fileformat'] = 'voc';
$info_audio['dataformat'] = 'voc';
$info_audio['bitrate_mode'] = 'cbr';
$info_audio['lossless'] = true;
$info_audio['channels'] = 1; // might be overriden below
$info_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)
getid3_lib::ReadSequence('LittleEndian2Int', $info_voc['header'], $voc_header, 20,
array (
'datablock_offset' => 2,
'minor_version' => 1,
'major_version' => 1
)
);
do {
$block_offset = ftell($getid3->fp);
$block_data = fread($getid3->fp, 4);
$block_type = ord($block_data{0});
$block_size = getid3_lib::LittleEndian2Int(substr($block_data, 1, 3));
$this_block = array ();
@$info_voc['blocktypes'][$block_type]++;
switch ($block_type) {
case 0: // Terminator
// do nothing, we'll break out of the loop down below
break;
case 1: // Sound data
$block_data .= fread($getid3->fp, 2);
if ($getid3->info['avdataoffset'] <= $original_av_data_offset) {
$getid3->info['avdataoffset'] = ftell($getid3->fp);
}
fseek($getid3->fp, $block_size - 2, SEEK_CUR);
getid3_lib::ReadSequence('LittleEndian2Int', $this_block, $block_data, 4,
array (
'sample_rate_id' => 1,
'compression_type' => 1
)
);
$this_block['compression_name'] = getid3_voc::VOCcompressionTypeLookup($this_block['compression_type']);
if ($this_block['compression_type'] <= 3) {
$info_voc['compressed_bits_per_sample'] = (int)(str_replace('-bit', '', $this_block['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($info_audio['sample_rate'])) {
// SR byte = 256 - (1000000 / sample_rate)
$info_audio['sample_rate'] = (int)floor((1000000 / (256 - $this_block['sample_rate_id'])) / $info_audio['channels']);
}
break;
case 2: // Sound continue
case 3: // Silence
case 4: // Marker
case 6: // Repeat
case 7: // End repeat
// nothing useful, just skip
fseek($getid3->fp, $block_size, SEEK_CUR);
break;
case 8: // Extended
$block_data .= fread($getid3->fp, 4);
//00-01 Time Constant:
// Mono: 65536 - (256000000 / sample_rate)
// Stereo: 65536 - (256000000 / (sample_rate * 2))
getid3_lib::ReadSequence('LittleEndian2Int', $this_block, $block_data, 4,
array (
'time_constant' => 2,
'pack_method' => 1,
'stereo' => 1
)
);
$this_block['stereo'] = (bool)$this_block['stereo'];
$info_audio['channels'] = ($this_block['stereo'] ? 2 : 1);
$info_audio['sample_rate'] = (int)floor((256000000 / (65536 - $this_block['time_constant'])) / $info_audio['channels']);
break;
case 9: // data block that supersedes blocks 1 and 8. Used for stereo, 16 bit
$block_data .= fread($getid3->fp, 12);
if ($getid3->info['avdataoffset'] <= $original_av_data_offset) {
$getid3->info['avdataoffset'] = ftell($getid3->fp);
}
fseek($getid3->fp, $block_size - 12, SEEK_CUR);
getid3_lib::ReadSequence('LittleEndian2Int', $this_block, $block_data, 4,
array (
'sample_rate' => 4,
'bits_per_sample' => 1,
'channels' => 1,
'wFormat' => 2
)
);
$this_block['compression_name'] = getid3_voc::VOCwFormatLookup($this_block['wFormat']);
if (getid3_voc::VOCwFormatActualBitsPerSampleLookup($this_block['wFormat'])) {
$info_voc['compressed_bits_per_sample'] = getid3_voc::VOCwFormatActualBitsPerSampleLookup($this_block['wFormat']);
}
$info_audio['sample_rate'] = $this_block['sample_rate'];
$info_audio['bits_per_sample'] = $this_block['bits_per_sample'];
$info_audio['channels'] = $this_block['channels'];
break;
default:
$getid3->warning('Unhandled block type "'.$block_type.'" at offset '.$block_offset);
fseek($getid3->fp, $block_size, SEEK_CUR);
break;
}
if (!empty($this_block)) {
$this_block['block_offset'] = $block_offset;
$this_block['block_size'] = $block_size;
$this_block['block_type_id'] = $block_type;
$info_voc['blocks'][] = $this_block;
}
} while (!feof($getid3->fp) && ($block_type != 0));
// Terminator block doesn't have size field, so seek back 3 spaces
fseek($getid3->fp, -3, SEEK_CUR);
ksort($info_voc['blocktypes']);
if (!empty($info_voc['compressed_bits_per_sample'])) {
$getid3->info['playtime_seconds'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / ($info_voc['compressed_bits_per_sample'] * $info_audio['channels'] * $info_audio['sample_rate']);
$info_audio['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
}
return true;
}
public static function VOCcompressionTypeLookup($index) {
static $lookup = array (
0 => '8-bit',
1 => '4-bit',
2 => '2.6-bit',
3 => '2-bit'
);
return (isset($lookup[$index]) ? $lookup[$index] : 'Multi DAC ('.($index - 3).') channels');
}
public static function VOCwFormatLookup($index) {
static $lookup = 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($lookup[$index]) ? $lookup[$index] : false);
}
public static function VOCwFormatActualBitsPerSampleLookup($index) {
static $lookup = array (
0x0000 => 8,
0x0001 => 4,
0x0002 => 3,
0x0003 => 2,
0x0004 => 16,
0x0006 => 8,
0x0007 => 8,
0x2000 => 4
);
return (isset($lookup[$index]) ? $lookup[$index] : false);
}
}
?>

View file

@ -0,0 +1,164 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.vqf.php |
// | Module for analyzing VQF Audio files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.vqf.php,v 1.3 2006/11/16 23:16:31 ah Exp $
class getid3_vqf extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
// based loosely on code from TTwinVQ by Jurgen Faul <jfaulØgmx*de>
// http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html
$getid3->info['fileformat'] = 'vqf';
$getid3->info['audio']['dataformat'] = 'vqf';
$getid3->info['audio']['bitrate_mode'] = 'cbr';
$getid3->info['audio']['lossless'] = false;
// Shortcuts
$getid3->info['vqf']['raw'] = array ();
$info_vqf = &$getid3->info['vqf'];
$info_vqf_raw = &$info_vqf['raw'];
// Get header
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$vqf_header_data = fread($getid3->fp, 16);
$info_vqf_raw['header_tag'] = 'TWIN'; // Magic bytes
$info_vqf_raw['version'] = substr($vqf_header_data, 4, 8);
$info_vqf_raw['size'] = getid3_lib::BigEndian2Int(substr($vqf_header_data, 12, 4));
while (ftell($getid3->fp) < $getid3->info['avdataend']) {
$chunk_base_offset = ftell($getid3->fp);
$chunk_data = fread($getid3->fp, 8);
$chunk_name = substr($chunk_data, 0, 4);
if ($chunk_name == 'DATA') {
$getid3->info['avdataoffset'] = $chunk_base_offset;
break;
}
$chunk_size = getid3_lib::BigEndian2Int(substr($chunk_data, 4, 4));
if ($chunk_size > ($getid3->info['avdataend'] - ftell($getid3->fp))) {
throw new getid3_exception('Invalid chunk size ('.$chunk_size.') for chunk "'.$chunk_name.'" at offset 8.');
}
if ($chunk_size > 0) {
$chunk_data .= fread($getid3->fp, $chunk_size);
}
switch ($chunk_name) {
case 'COMM':
$info_vqf['COMM'] = array ();
getid3_lib::ReadSequence('BigEndian2Int', $info_vqf['COMM'], $chunk_data, 8,
array (
'channel_mode' => 4,
'bitrate' => 4,
'sample_rate' => 4,
'security_level' => 4
)
);
$getid3->info['audio']['channels'] = $info_vqf['COMM']['channel_mode'] + 1;
$getid3->info['audio']['sample_rate'] = getid3_vqf::VQFchannelFrequencyLookup($info_vqf['COMM']['sample_rate']);
$getid3->info['audio']['bitrate'] = $info_vqf['COMM']['bitrate'] * 1000;
$getid3->info['audio']['encoder_options'] = 'CBR' . ceil($getid3->info['audio']['bitrate']/1000);
if ($getid3->info['audio']['bitrate'] == 0) {
throw new getid3_exception('Corrupt VQF file: bitrate_audio == zero');
}
break;
case 'NAME':
case 'AUTH':
case '(c) ':
case 'FILE':
case 'COMT':
case 'ALBM':
$info_vqf['comments'][getid3_vqf::VQFcommentNiceNameLookup($chunk_name)][] = trim(substr($chunk_data, 8));
break;
case 'DSIZ':
$info_vqf['DSIZ'] = getid3_lib::BigEndian2Int(substr($chunk_data, 8, 4));
break;
default:
$getid3->warning('Unhandled chunk type "'.$chunk_name.'" at offset 8');
break;
}
}
$getid3->info['playtime_seconds'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['audio']['bitrate'];
if (isset($info_vqf['DSIZ']) && (($info_vqf['DSIZ'] != ($getid3->info['avdataend'] - $getid3->info['avdataoffset'] - strlen('DATA'))))) {
switch ($info_vqf['DSIZ']) {
case 0:
case 1:
$getid3->warning('Invalid DSIZ value "'.$info_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'.($info_vqf['DSIZ'] + 1).'.0');
$getid3->info['audio']['encoder'] = 'Ahead Nero';
break;
default:
$getid3->warning('Probable corrupted file - should be '.$info_vqf['DSIZ'].' bytes, actually '.($getid3->info['avdataend'] - $getid3->info['avdataoffset'] - strlen('DATA')));
break;
}
}
return true;
}
public static function VQFchannelFrequencyLookup($frequencyid) {
static $lookup = array (
11 => 11025,
22 => 22050,
44 => 44100
);
return (isset($lookup[$frequencyid]) ? $lookup[$frequencyid] : $frequencyid * 1000);
}
public static function VQFcommentNiceNameLookup($shortname) {
static $lookup = array (
'NAME' => 'title',
'AUTH' => 'artist',
'(c) ' => 'copyright',
'FILE' => 'filename',
'COMT' => 'comment',
'ALBM' => 'album'
);
return (isset($lookup[$shortname]) ? $lookup[$shortname] : $shortname);
}
}
?>

View file

@ -0,0 +1,399 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.wavpack.php |
// | module for analyzing WavPack v4.0+ Audio files |
// | dependencies: audio-video.riff |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.wavpack.php,v 1.2 2006/11/02 10:48:02 ah Exp $
class getid3_wavpack extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->include_module('audio-video.riff');
$getid3->info['wavpack'] = array ();
$info_wavpack = &$getid3->info['wavpack'];
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
while (true) {
$wavpack_header = fread($getid3->fp, 32);
if (ftell($getid3->fp) >= $getid3->info['avdataend']) {
break;
} elseif (feof($getid3->fp)) {
break;
} elseif (
(@$info_wavpack_blockheader['total_samples'] > 0) &&
(@$info_wavpack_blockheader['block_samples'] > 0) &&
(!isset($info_wavpack['riff_trailer_size']) || ($info_wavpack['riff_trailer_size'] <= 0)) &&
((@$info_wavpack['config_flags']['md5_checksum'] === false) || !empty($getid3->info['md5_data_source']))) {
break;
}
$block_header_offset = ftell($getid3->fp) - 32;
$block_header_magic = substr($wavpack_header, 0, 4);
$block_header_size = getid3_lib::LittleEndian2Int(substr($wavpack_header, 4, 4));
if ($block_header_magic != 'wvpk') {
throw new getid3_exception('Expecting "wvpk" at offset '.$block_header_offset.', found "'.$block_header_magic.'"');
}
if ((@$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.
$getid3->info['audio']['dataformat'] = 'wavpack';
$getid3->info['fileformat'] = 'wavpack';
$getid3->info['audio']['lossless'] = true;
$getid3->info['audio']['bitrate_mode'] = 'vbr';
$info_wavpack['blockheader']['offset'] = $block_header_offset;
$info_wavpack['blockheader']['magic'] = $block_header_magic;
$info_wavpack['blockheader']['size'] = $block_header_size;
$info_wavpack_blockheader = &$info_wavpack['blockheader'];
if ($info_wavpack_blockheader['size'] >= 0x100000) {
throw new getid3_exception('Expecting WavPack block size less than "0x100000", found "'.$info_wavpack_blockheader['size'].'" at offset '.$info_wavpack_blockheader['offset']);
}
$info_wavpack_blockheader['minor_version'] = ord($wavpack_header{8});
$info_wavpack_blockheader['major_version'] = ord($wavpack_header{9});
if (($info_wavpack_blockheader['major_version'] != 4) ||
(($info_wavpack_blockheader['minor_version'] < 4) &&
($info_wavpack_blockheader['minor_version'] > 16))) {
throw new getid3_exception('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']);
}
$info_wavpack_blockheader['track_number'] = ord($wavpack_header{10}); // unused
$info_wavpack_blockheader['index_number'] = ord($wavpack_header{11}); // unused
getid3_lib::ReadSequence('LittleEndian2Int', $info_wavpack_blockheader, $wavpack_header, 12,
array (
'total_samples' => 4,
'block_index' => 4,
'block_samples' => 4,
'flags_raw' => 4,
'crc' => 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);
$getid3->info['audio']['lossless'] = !$info_wavpack_blockheader['flags']['hybrid'];
}
while (!feof($getid3->fp) && (ftell($getid3->fp) < ($block_header_offset + $block_header_size + 8))) {
$metablock = array('offset'=>ftell($getid3->fp));
$metablockheader = fread($getid3->fp, 2);
if (feof($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);
$metablock['padded_data'] = (bool) ($metablock['id'] & 0x40);
$metablock['large_block'] = (bool) ($metablock['id'] & 0x80);
if ($metablock['large_block']) {
$metablockheader .= fread($getid3->fp, 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'] = fread($getid3->fp, $metablock['size']);
if ($metablock['padded_data']) {
// padded to the nearest even byte
$metablock['size']--;
$metablock['data'] = substr($metablock['data'], 0, -1);
}
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
fseek($getid3->fp, $metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size'], SEEK_SET);
break;
default:
$getid3->warning('Unexpected metablock type "0x'.str_pad(dechex($metablock['function_id']), 2, '0', STR_PAD_LEFT).'" at offset '.$metablock['offset']);
fseek($getid3->fp, $metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size'], SEEK_SET);
break;
}
switch ($metablock['function_id']) {
case 0x21: // ID_RIFF_HEADER
$original_wav_filesize = getid3_lib::LittleEndian2Int(substr($metablock['data'], 4, 4));
// Clone getid3
$clone = clone $getid3;
// Analyze clone by string
$riff = new getid3_riff($clone);
$riff->AnalyzeString($metablock['data']);
// Import from clone and destroy
$metablock['riff'] = $clone->info['riff'];
$getid3->warnings($clone->warnings());
unset($clone);
// Save RIFF header - we may need it later for RIFF footer parsing
$this->riff_header = $metablock['data'];
$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'];
$getid3->info['audio']['sample_rate'] = $metablock['riff']['raw']['fmt ']['nSamplesPerSec'];
$getid3->info['playtime_seconds'] = $info_wavpack_blockheader['total_samples'] / $getid3->info['audio']['sample_rate'];
// Safe RIFF header in case there's a RIFF footer later
$metablock_riff_header = $metablock['data'];
break;
case 0x22: // ID_RIFF_TRAILER
$metablock_riff_footer = $metablock_riff_header.$metablock['data'];
$start_offset = $metablock['offset'] + ($metablock['large_block'] ? 4 : 2);
$ftell_old = ftell($getid3->fp);
// Clone getid3
$clone = clone $getid3;
// Call public method that really should be private
$riff = new getid3_riff($clone);
$metablock['riff'] = $riff->ParseRIFF($start_offset, $start_offset + $metablock['size']);
unset($clone);
fseek($getid3->fp, $ftell_old, SEEK_SET);
if (!empty($metablock['riff']['INFO'])) {
getid3_riff::RIFFCommentsParse($metablock['riff']['INFO'], $metablock['comments']);
$getid3->info['tags']['riff'] = $metablock['comments'];
}
break;
case 0x23: // ID_REPLAY_GAIN
$getid3->warning('WavPack "Replay Gain" contents not yet handled by getID3() in metablock at offset '.$metablock['offset']);
break;
case 0x24: // ID_CUESHEET
$getid3->warning('WavPack "Cuesheet" contents not yet handled by getID3() in metablock at offset '.$metablock['offset']);
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 %
$info_wavpack['config_flags'] = $metablock['flags'];
$getid3->info['audio']['encoder_options'] = trim(
($info_wavpack_blockheader['flags']['hybrid'] ? ' -b???' : '') .
($metablock['flags']['adobe_mode'] ? ' -a' : '') .
($metablock['flags']['optimize_wvc'] ? ' -cc' : '') .
($metablock['flags']['create_exe'] ? ' -e' : '') .
($metablock['flags']['fast_flag'] ? ' -f' : '') .
($metablock['flags']['joint_override'] ? ' -j?' : '') .
($metablock['flags']['high_flag'] ? ' -h' : '') .
($metablock['flags']['md5_checksum'] ? ' -m' : '') .
($metablock['flags']['calc_noise'] ? ' -n' : '') .
($metablock['flags']['shape_override'] ? ' -s?' : '') .
($metablock['flags']['extra_mode'] ? ' -x?' : '')
);
if (!$getid3->info['audio']['encoder_options']) {
unset($getid3->info['audio']['encoder_options']);
}
break;
case 0x26: // ID_MD5_CHECKSUM
if (strlen($metablock['data']) == 16) {
$getid3->info['md5_data_source'] = strtolower(getid3_lib::PrintHexBytes($metablock['data'], true, false, false));
} else {
$getid3->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;
}
}
}
$getid3->info['audio']['encoder'] = 'WavPack v'.$info_wavpack_blockheader['major_version'].'.'.str_pad($info_wavpack_blockheader['minor_version'], 2, '0', STR_PAD_LEFT);
$getid3->info['audio']['bits_per_sample'] = $info_wavpack_blockheader['flags']['bytes_per_sample'] * 8;
$getid3->info['audio']['channels'] = ($info_wavpack_blockheader['flags']['mono'] ? 1 : 2);
if (@$getid3->info['playtime_seconds']) {
$getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
} else {
$getid3->info['audio']['dataformat'] = 'wvc';
}
return true;
}
public static function WavPackMetablockNameLookup($id) {
static $lookup = 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 (@$lookup[$id]);
}
}
?>

View file

@ -0,0 +1,952 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.xiph.php |
// | Module for analyzing Xiph.org audio file formats: |
// | Ogg Vorbis, FLAC, OggFLAC and Speex - not Ogg Theora |
// | dependencies: module.lib.image_size.php (optional) |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.xiph.php,v 1.5 2006/12/03 21:12:43 ah Exp $
class getid3_xiph extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
if ($getid3->option_tags_images) {
$getid3->include_module('lib.image_size');
}
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$magic = fread($getid3->fp, 4);
if ($magic == 'OggS') {
return $this->ParseOgg();
}
if ($magic == 'fLaC') {
return $this->ParseFLAC();
}
}
private function ParseOgg() {
$getid3 = $this->getid3;
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$getid3->info['audio'] = $getid3->info['ogg'] = array ();
$info_ogg = &$getid3->info['ogg'];
$info_audio = &$getid3->info['audio'];
$getid3->info['fileformat'] = 'ogg';
//// Page 1 - Stream Header
$ogg_page_info = $this->ParseOggPageHeader();
$info_ogg['pageheader'][$ogg_page_info['page_seqno']] = $ogg_page_info;
if (ftell($getid3->fp) >= getid3::FREAD_BUFFER_SIZE) {
throw new getid3_exception('Could not find start of Ogg page in the first '.getid3::FREAD_BUFFER_SIZE.' bytes (this might not be an Ogg file?)');
}
$file_data = fread($getid3->fp, $ogg_page_info['page_length']);
$file_data_offset = 0;
// OggFLAC
if (substr($file_data, 0, 4) == 'fLaC') {
$info_audio['dataformat'] = 'flac';
$info_audio['bitrate_mode'] = 'vbr';
$info_audio['lossless'] = true;
}
// Ogg Vorbis
elseif (substr($file_data, 1, 6) == 'vorbis') {
$info_audio['dataformat'] = 'vorbis';
$info_audio['lossless'] = false;
$info_ogg['pageheader'][$ogg_page_info['page_seqno']]['packet_type'] = getid3_lib::LittleEndian2Int($file_data[0]);
$info_ogg['pageheader'][$ogg_page_info['page_seqno']]['stream_type'] = substr($file_data, 1, 6); // hard-coded to 'vorbis'
getid3_lib::ReadSequence('LittleEndian2Int', $info_ogg, $file_data, 7,
array (
'bitstreamversion' => 4,
'numberofchannels' => 1,
'samplerate' => 4,
'bitrate_max' => 4,
'bitrate_nominal' => 4,
'bitrate_min' => 4
)
);
$n28 = getid3_lib::LittleEndian2Int($file_data{28});
$info_ogg['blocksize_small'] = pow(2, $n28 & 0x0F);
$info_ogg['blocksize_large'] = pow(2, ($n28 & 0xF0) >> 4);
$info_ogg['stop_bit'] = $n28;
$info_audio['channels'] = $info_ogg['numberofchannels'];
$info_audio['sample_rate'] = $info_ogg['samplerate'];
$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';
}
}
// Speex
elseif (substr($file_data, 0, 8) == 'Speex ') {
// http://www.speex.org/manual/node10.html
$info_audio['dataformat'] = 'speex';
$getid3->info['mime_type'] = 'audio/speex';
$info_audio['bitrate_mode'] = 'abr';
$info_audio['lossless'] = false;
getid3_lib::ReadSequence('LittleEndian2Int', $info_ogg['pageheader'][$ogg_page_info['page_seqno']], $file_data, 0,
array (
'speex_string' => -8, // hard-coded to 'Speex '
'speex_version' => -20, // string
'speex_version_id' => 4,
'header_size' => 4,
'rate' => 4,
'mode' => 4,
'mode_bitstream_version' => 4,
'nb_channels' => 4,
'bitrate' => 4,
'framesize' => 4,
'vbr' => 4,
'frames_per_packet' => 4,
'extra_headers' => 4,
'reserved1' => 4,
'reserved2' => 4
)
);
$getid3->info['speex']['speex_version'] = trim($info_ogg['pageheader'][$ogg_page_info['page_seqno']]['speex_version']);
$getid3->info['speex']['sample_rate'] = $info_ogg['pageheader'][$ogg_page_info['page_seqno']]['rate'];
$getid3->info['speex']['channels'] = $info_ogg['pageheader'][$ogg_page_info['page_seqno']]['nb_channels'];
$getid3->info['speex']['vbr'] = (bool)$info_ogg['pageheader'][$ogg_page_info['page_seqno']]['vbr'];
$getid3->info['speex']['band_type'] = getid3_xiph::SpeexBandModeLookup($info_ogg['pageheader'][$ogg_page_info['page_seqno']]['mode']);
$info_audio['sample_rate'] = $getid3->info['speex']['sample_rate'];
$info_audio['channels'] = $getid3->info['speex']['channels'];
if ($getid3->info['speex']['vbr']) {
$info_audio['bitrate_mode'] = 'vbr';
}
}
// Unsupported Ogg file
else {
throw new getid3_exception('Expecting either "Speex " or "vorbis" identifier strings, found neither');
}
//// Page 2 - Comment Header
$ogg_page_info = $this->ParseOggPageHeader();
$info_ogg['pageheader'][$ogg_page_info['page_seqno']] = $ogg_page_info;
switch ($info_audio['dataformat']) {
case 'vorbis':
$file_data = fread($getid3->fp, $info_ogg['pageheader'][$ogg_page_info['page_seqno']]['page_length']);
$info_ogg['pageheader'][$ogg_page_info['page_seqno']]['packet_type'] = getid3_lib::LittleEndian2Int(substr($file_data, 0, 1));
$info_ogg['pageheader'][$ogg_page_info['page_seqno']]['stream_type'] = substr($file_data, 1, 6); // hard-coded to 'vorbis'
$this->ParseVorbisCommentsFilepointer();
break;
case 'flac':
if (!$this->FLACparseMETAdata()) {
throw new getid3_exception('Failed to parse FLAC headers');
}
break;
case 'speex':
fseek($getid3->fp, $info_ogg['pageheader'][$ogg_page_info['page_seqno']]['page_length'], SEEK_CUR);
$this->ParseVorbisCommentsFilepointer();
break;
}
//// Last Page - Number of Samples
fseek($getid3->fp, max($getid3->info['avdataend'] - getid3::FREAD_BUFFER_SIZE, 0), SEEK_SET);
$last_chunk_of_ogg = strrev(fread($getid3->fp, getid3::FREAD_BUFFER_SIZE));
if ($last_OggS_postion = strpos($last_chunk_of_ogg, 'SggO')) {
fseek($getid3->fp, $getid3->info['avdataend'] - ($last_OggS_postion + strlen('SggO')), SEEK_SET);
$getid3->info['avdataend'] = ftell($getid3->fp);
$info_ogg['pageheader']['eos'] = $this->ParseOggPageHeader();
$info_ogg['samples'] = $info_ogg['pageheader']['eos']['pcm_abs_position'];
$info_ogg['bitrate_average'] = (($getid3->info['avdataend'] - $getid3->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($getid3->info['playtime_seconds'])) {
$getid3->info['playtime_seconds'] = (float)((($getid3->info['avdataend'] - $getid3->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 '.getid3_xiph::GetQualityFromNominalBitrate($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;
}
private function ParseOggPageHeader() {
$getid3 = $this->getid3;
// http://xiph.org/ogg/vorbis/doc/framing.html
$ogg_header['page_start_offset'] = ftell($getid3->fp); // where we started from in the file
$file_data = fread($getid3->fp, getid3::FREAD_BUFFER_SIZE);
$file_data_offset = 0;
while ((substr($file_data, $file_data_offset++, 4) != 'OggS')) {
if ((ftell($getid3->fp) - $ogg_header['page_start_offset']) >= getid3::FREAD_BUFFER_SIZE) {
// should be found before here
return false;
}
if ((($file_data_offset + 28) > strlen($file_data)) || (strlen($file_data) < 28)) {
if (feof($getid3->fp) || (($file_data .= fread($getid3->fp, getid3::FREAD_BUFFER_SIZE)) === false)) {
// get some more data, unless eof, in which case fail
return false;
}
}
}
$file_data_offset += 3; // page, delimited by 'OggS'
getid3_lib::ReadSequence('LittleEndian2Int', $ogg_header, $file_data, $file_data_offset,
array (
'stream_structver' => 1,
'flags_raw' => 1,
'pcm_abs_position' => 8,
'stream_serialno' => 4,
'page_seqno' => 4,
'page_checksum' => 4,
'page_segments' => 1
)
);
$file_data_offset += 23;
$ogg_header['flags']['fresh'] = (bool)($ogg_header['flags_raw'] & 0x01); // fresh packet
$ogg_header['flags']['bos'] = (bool)($ogg_header['flags_raw'] & 0x02); // first page of logical bitstream (bos)
$ogg_header['flags']['eos'] = (bool)($ogg_header['flags_raw'] & 0x04); // last page of logical bitstream (eos)
$ogg_header['page_length'] = 0;
for ($i = 0; $i < $ogg_header['page_segments']; $i++) {
$ogg_header['segment_table'][$i] = getid3_lib::LittleEndian2Int($file_data{$file_data_offset++});
$ogg_header['page_length'] += $ogg_header['segment_table'][$i];
}
$ogg_header['header_end_offset'] = $ogg_header['page_start_offset'] + $file_data_offset;
$ogg_header['page_end_offset'] = $ogg_header['header_end_offset'] + $ogg_header['page_length'];
fseek($getid3->fp, $ogg_header['header_end_offset'], SEEK_SET);
return $ogg_header;
}
private function ParseVorbisCommentsFilepointer() {
$getid3 = $this->getid3;
$original_offset = ftell($getid3->fp);
$comment_start_offset = $original_offset;
$comment_data_offset = 0;
$vorbis_comment_page = 1;
switch ($getid3->info['audio']['dataformat']) {
case 'vorbis':
$comment_start_offset = $getid3->info['ogg']['pageheader'][$vorbis_comment_page]['page_start_offset']; // Second Ogg page, after header block
fseek($getid3->fp, $comment_start_offset, SEEK_SET);
$comment_data_offset = 27 + $getid3->info['ogg']['pageheader'][$vorbis_comment_page]['page_segments'];
$comment_data = fread($getid3->fp, getid3_xiph::OggPageSegmentLength($getid3->info['ogg']['pageheader'][$vorbis_comment_page], 1) + $comment_data_offset);
$comment_data_offset += (strlen('vorbis') + 1);
break;
case 'flac':
fseek($getid3->fp, $getid3->info['flac']['VORBIS_COMMENT']['raw']['offset'] + 4, SEEK_SET);
$comment_data = fread($getid3->fp, $getid3->info['flac']['VORBIS_COMMENT']['raw']['block_length']);
break;
case 'speex':
$comment_start_offset = $getid3->info['ogg']['pageheader'][$vorbis_comment_page]['page_start_offset']; // Second Ogg page, after header block
fseek($getid3->fp, $comment_start_offset, SEEK_SET);
$comment_data_offset = 27 + $getid3->info['ogg']['pageheader'][$vorbis_comment_page]['page_segments'];
$comment_data = fread($getid3->fp, getid3_xiph::OggPageSegmentLength($getid3->info['ogg']['pageheader'][$vorbis_comment_page], 1) + $comment_data_offset);
break;
default:
return false;
}
$vendor_size = getid3_lib::LittleEndian2Int(substr($comment_data, $comment_data_offset, 4));
$comment_data_offset += 4;
$getid3->info['ogg']['vendor'] = substr($comment_data, $comment_data_offset, $vendor_size);
$comment_data_offset += $vendor_size;
$comments_count = getid3_lib::LittleEndian2Int(substr($comment_data, $comment_data_offset, 4));
$comment_data_offset += 4;
$getid3->info['avdataoffset'] = $comment_start_offset + $comment_data_offset;
for ($i = 0; $i < $comments_count; $i++) {
$getid3->info['ogg']['comments_raw'][$i]['dataoffset'] = $comment_start_offset + $comment_data_offset;
if (ftell($getid3->fp) < ($getid3->info['ogg']['comments_raw'][$i]['dataoffset'] + 4)) {
$vorbis_comment_page++;
$ogg_page_info = $this->ParseOggPageHeader();
$getid3->info['ogg']['pageheader'][$ogg_page_info['page_seqno']] = $ogg_page_info;
// First, save what we haven't read yet
$as_yet_unused_data = substr($comment_data, $comment_data_offset);
// Then take that data off the end
$comment_data = substr($comment_data, 0, $comment_data_offset);
// Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct
$comment_data .= str_repeat("\x00", 27 + $getid3->info['ogg']['pageheader'][$ogg_page_info['page_seqno']]['page_segments']);
$comment_data_offset += (27 + $getid3->info['ogg']['pageheader'][$ogg_page_info['page_seqno']]['page_segments']);
// Finally, stick the unused data back on the end
$comment_data .= $as_yet_unused_data;
$comment_data .= fread($getid3->fp, getid3_xiph::OggPageSegmentLength($getid3->info['ogg']['pageheader'][$vorbis_comment_page], 1));
}
$getid3->info['ogg']['comments_raw'][$i]['size'] = getid3_lib::LittleEndian2Int(substr($comment_data, $comment_data_offset, 4));
// replace avdataoffset with position just after the last vorbiscomment
$getid3->info['avdataoffset'] = $getid3->info['ogg']['comments_raw'][$i]['dataoffset'] + $getid3->info['ogg']['comments_raw'][$i]['size'] + 4;
$comment_data_offset += 4;
while ((strlen($comment_data) - $comment_data_offset) < $getid3->info['ogg']['comments_raw'][$i]['size']) {
if (($getid3->info['ogg']['comments_raw'][$i]['size'] > $getid3->info['avdataend']) || ($getid3->info['ogg']['comments_raw'][$i]['size'] < 0)) {
throw new getid3_exception('Invalid Ogg comment size (comment #'.$i.', claims to be '.number_format($getid3->info['ogg']['comments_raw'][$i]['size']).' bytes) - aborting reading comments');
}
$vorbis_comment_page++;
$ogg_page_info = $this->ParseOggPageHeader();
$getid3->info['ogg']['pageheader'][$ogg_page_info['page_seqno']] = $ogg_page_info;
// First, save what we haven't read yet
$as_yet_unused_data = substr($comment_data, $comment_data_offset);
// Then take that data off the end
$comment_data = substr($comment_data, 0, $comment_data_offset);
// Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct
$comment_data .= str_repeat("\x00", 27 + $getid3->info['ogg']['pageheader'][$ogg_page_info['page_seqno']]['page_segments']);
$comment_data_offset += (27 + $getid3->info['ogg']['pageheader'][$ogg_page_info['page_seqno']]['page_segments']);
// Finally, stick the unused data back on the end
$comment_data .= $as_yet_unused_data;
//$comment_data .= fread($getid3->fp, $getid3->info['ogg']['pageheader'][$ogg_page_info['page_seqno']]['page_length']);
$comment_data .= fread($getid3->fp, getid3_xiph::OggPageSegmentLength($getid3->info['ogg']['pageheader'][$vorbis_comment_page], 1));
//$filebaseoffset += $ogg_page_info['header_end_offset'] - $ogg_page_info['page_start_offset'];
}
$comment_string = substr($comment_data, $comment_data_offset, $getid3->info['ogg']['comments_raw'][$i]['size']);
$comment_data_offset += $getid3->info['ogg']['comments_raw'][$i]['size'];
if (!$comment_string) {
// no comment?
$getid3->warning('Blank Ogg comment ['.$i.']');
} elseif (strstr($comment_string, '=')) {
$comment_exploded = explode('=', $comment_string, 2);
$getid3->info['ogg']['comments_raw'][$i]['key'] = strtoupper($comment_exploded[0]);
$getid3->info['ogg']['comments_raw'][$i]['value'] = @$comment_exploded[1];
$getid3->info['ogg']['comments_raw'][$i]['data'] = base64_decode($getid3->info['ogg']['comments_raw'][$i]['value']);
$getid3->info['ogg']['comments'][strtolower($getid3->info['ogg']['comments_raw'][$i]['key'])][] = $getid3->info['ogg']['comments_raw'][$i]['value'];
if ($getid3->option_tags_images) {
$image_chunk_check = getid3_lib_image_size::get($getid3->info['ogg']['comments_raw'][$i]['data']);
$getid3->info['ogg']['comments_raw'][$i]['image_mime'] = image_type_to_mime_type($image_chunk_check[2]);
}
if (!@$getid3->info['ogg']['comments_raw'][$i]['image_mime'] || ($getid3->info['ogg']['comments_raw'][$i]['image_mime'] == 'application/octet-stream')) {
unset($getid3->info['ogg']['comments_raw'][$i]['image_mime']);
unset($getid3->info['ogg']['comments_raw'][$i]['data']);
}
} else {
$getid3->warning('[known problem with CDex >= v1.40, < v1.50b7] Invalid Ogg comment name/value pair ['.$i.']: '.$comment_string);
}
}
// Replay Gain Adjustment
// http://privatewww.essex.ac.uk/~djmrob/replaygain/
if (isset($getid3->info['ogg']['comments']) && is_array($getid3->info['ogg']['comments'])) {
foreach ($getid3->info['ogg']['comments'] as $index => $commentvalue) {
switch ($index) {
case 'rg_audiophile':
case 'replaygain_album_gain':
$getid3->info['replay_gain']['album']['adjustment'] = (float)$commentvalue[0];
unset($getid3->info['ogg']['comments'][$index]);
break;
case 'rg_radio':
case 'replaygain_track_gain':
$getid3->info['replay_gain']['track']['adjustment'] = (float)$commentvalue[0];
unset($getid3->info['ogg']['comments'][$index]);
break;
case 'replaygain_album_peak':
$getid3->info['replay_gain']['album']['peak'] = (float)$commentvalue[0];
unset($getid3->info['ogg']['comments'][$index]);
break;
case 'rg_peak':
case 'replaygain_track_peak':
$getid3->info['replay_gain']['track']['peak'] = (float)$commentvalue[0];
unset($getid3->info['ogg']['comments'][$index]);
break;
case 'replaygain_reference_loudness':
$getid3->info['replay_gain']['reference_volume'] = (float)$commentvalue[0];
unset($getid3->info['ogg']['comments'][$index]);
break;
}
}
}
fseek($getid3->fp, $original_offset, SEEK_SET);
return true;
}
private function ParseFLAC() {
$getid3 = $this->getid3;
// http://flac.sourceforge.net/format.html
$getid3->info['fileformat'] = 'flac';
$getid3->info['audio']['dataformat'] = 'flac';
$getid3->info['audio']['bitrate_mode'] = 'vbr';
$getid3->info['audio']['lossless'] = true;
return $this->FLACparseMETAdata();
}
private function FLACparseMETAdata() {
$getid3 = $this->getid3;
do {
$meta_data_block_offset = ftell($getid3->fp);
$meta_data_block_header = fread($getid3->fp, 4);
$meta_data_last_block_flag = (bool)(getid3_lib::BigEndian2Int($meta_data_block_header[0]) & 0x80);
$meta_data_block_type = getid3_lib::BigEndian2Int($meta_data_block_header[0]) & 0x7F;
$meta_data_block_length = getid3_lib::BigEndian2Int(substr($meta_data_block_header, 1, 3));
$meta_data_block_type_text = getid3_xiph::FLACmetaBlockTypeLookup($meta_data_block_type);
if ($meta_data_block_length < 0) {
throw new getid3_exception('corrupt or invalid METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$meta_data_block_type.') at offset '.$meta_data_block_offset);
}
$getid3->info['flac'][$meta_data_block_type_text]['raw'] = array (
'offset' => $meta_data_block_offset,
'last_meta_block' => $meta_data_last_block_flag,
'block_type' => $meta_data_block_type,
'block_type_text' => $meta_data_block_type_text,
'block_length' => $meta_data_block_length,
'block_data' => @fread($getid3->fp, $meta_data_block_length)
);
$getid3->info['avdataoffset'] = ftell($getid3->fp);
switch ($meta_data_block_type_text) {
case 'STREAMINFO':
if (!$this->FLACparseSTREAMINFO($getid3->info['flac'][$meta_data_block_type_text]['raw']['block_data'])) {
return false;
}
break;
case 'PADDING':
// ignore
break;
case 'APPLICATION':
if (!$this->FLACparseAPPLICATION($getid3->info['flac'][$meta_data_block_type_text]['raw']['block_data'])) {
return false;
}
break;
case 'SEEKTABLE':
if (!$this->FLACparseSEEKTABLE($getid3->info['flac'][$meta_data_block_type_text]['raw']['block_data'])) {
return false;
}
break;
case 'VORBIS_COMMENT':
$old_offset = ftell($getid3->fp);
fseek($getid3->fp, 0 - $meta_data_block_length, SEEK_CUR);
$this->ParseVorbisCommentsFilepointer($getid3->fp, $getid3->info);
fseek($getid3->fp, $old_offset, SEEK_SET);
break;
case 'CUESHEET':
if (!$this->FLACparseCUESHEET($getid3->info['flac'][$meta_data_block_type_text]['raw']['block_data'])) {
return false;
}
break;
case 'PICTURE':
if (!$this->FLACparsePICTURE($getid3->info['flac'][$meta_data_block_type_text]['raw']['block_data'])) {
return false;
}
break;
default:
$getid3->warning('Unhandled METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$meta_data_block_type.') at offset '.$meta_data_block_offset);
}
} while ($meta_data_last_block_flag === false);
if (isset($getid3->info['flac']['STREAMINFO'])) {
$getid3->info['flac']['compressed_audio_bytes'] = $getid3->info['avdataend'] - $getid3->info['avdataoffset'];
$getid3->info['flac']['uncompressed_audio_bytes'] = $getid3->info['flac']['STREAMINFO']['samples_stream'] * $getid3->info['flac']['STREAMINFO']['channels'] * ($getid3->info['flac']['STREAMINFO']['bits_per_sample'] / 8);
$getid3->info['flac']['compression_ratio'] = $getid3->info['flac']['compressed_audio_bytes'] / $getid3->info['flac']['uncompressed_audio_bytes'];
}
// set md5_data_source - built into flac 0.5+
if (isset($getid3->info['flac']['STREAMINFO']['audio_signature'])) {
if ($getid3->info['flac']['STREAMINFO']['audio_signature'] === str_repeat("\x00", 16)) {
$getid3->warning('FLAC STREAMINFO.audio_signature is null (known issue with libOggFLAC)');
} else {
$getid3->info['md5_data_source'] = '';
$md5 = $getid3->info['flac']['STREAMINFO']['audio_signature'];
for ($i = 0; $i < strlen($md5); $i++) {
$getid3->info['md5_data_source'] .= str_pad(dechex(ord($md5{$i})), 2, '00', STR_PAD_LEFT);
}
if (!preg_match('/^[0-9a-f]{32}$/', $getid3->info['md5_data_source'])) {
unset($getid3->info['md5_data_source']);
}
}
}
$getid3->info['audio']['bits_per_sample'] = $getid3->info['flac']['STREAMINFO']['bits_per_sample'];
if ($getid3->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
$getid3->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 (!empty($getid3->info['ogg']['vendor'])) {
$getid3->info['audio']['encoder'] = $getid3->info['ogg']['vendor'];
}
return true;
}
private function FLACparseSTREAMINFO($meta_data_block_data) {
$getid3 = $this->getid3;
getid3_lib::ReadSequence('BigEndian2Int', $getid3->info['flac']['STREAMINFO'], $meta_data_block_data, 0,
array (
'min_block_size' => 2,
'max_block_size' => 2,
'min_frame_size' => 3,
'max_frame_size' => 3
)
);
$sample_rate_channels_sample_bits_stream_samples = getid3_lib::BigEndian2Bin(substr($meta_data_block_data, 10, 8));
$getid3->info['flac']['STREAMINFO']['sample_rate'] = bindec(substr($sample_rate_channels_sample_bits_stream_samples, 0, 20));
$getid3->info['flac']['STREAMINFO']['channels'] = bindec(substr($sample_rate_channels_sample_bits_stream_samples, 20, 3)) + 1;
$getid3->info['flac']['STREAMINFO']['bits_per_sample'] = bindec(substr($sample_rate_channels_sample_bits_stream_samples, 23, 5)) + 1;
$getid3->info['flac']['STREAMINFO']['samples_stream'] = bindec(substr($sample_rate_channels_sample_bits_stream_samples, 28, 36)); // bindec() returns float in case of int overrun
$getid3->info['flac']['STREAMINFO']['audio_signature'] = substr($meta_data_block_data, 18, 16);
if (!empty($getid3->info['flac']['STREAMINFO']['sample_rate'])) {
$getid3->info['audio']['bitrate_mode'] = 'vbr';
$getid3->info['audio']['sample_rate'] = $getid3->info['flac']['STREAMINFO']['sample_rate'];
$getid3->info['audio']['channels'] = $getid3->info['flac']['STREAMINFO']['channels'];
$getid3->info['audio']['bits_per_sample'] = $getid3->info['flac']['STREAMINFO']['bits_per_sample'];
$getid3->info['playtime_seconds'] = $getid3->info['flac']['STREAMINFO']['samples_stream'] / $getid3->info['flac']['STREAMINFO']['sample_rate'];
$getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
} else {
throw new getid3_exception('Corrupt METAdata block: STREAMINFO');
}
unset($getid3->info['flac']['STREAMINFO']['raw']);
return true;
}
private function FLACparseAPPLICATION($meta_data_block_data) {
$getid3 = $this->getid3;
$application_id = getid3_lib::BigEndian2Int(substr($meta_data_block_data, 0, 4));
$getid3->info['flac']['APPLICATION'][$application_id]['name'] = getid3_xiph::FLACapplicationIDLookup($application_id);
$getid3->info['flac']['APPLICATION'][$application_id]['data'] = substr($meta_data_block_data, 4);
unset($getid3->info['flac']['APPLICATION']['raw']);
return true;
}
private function FLACparseSEEKTABLE($meta_data_block_data) {
$getid3 = $this->getid3;
$offset = 0;
$meta_data_block_length = strlen($meta_data_block_data);
while ($offset < $meta_data_block_length) {
$sample_number_string = substr($meta_data_block_data, $offset, 8);
$offset += 8;
if ($sample_number_string == "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF") {
// placeholder point
@$getid3->info['flac']['SEEKTABLE']['placeholders']++;
$offset += 10;
} else {
$sample_number = getid3_lib::BigEndian2Int($sample_number_string);
$getid3->info['flac']['SEEKTABLE'][$sample_number]['offset'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 8));
$offset += 8;
$getid3->info['flac']['SEEKTABLE'][$sample_number]['samples'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 2));
$offset += 2;
}
}
unset($getid3->info['flac']['SEEKTABLE']['raw']);
return true;
}
private function FLACparseCUESHEET($meta_data_block_data) {
$getid3 = $this->getid3;
$getid3->info['flac']['CUESHEET']['media_catalog_number'] = trim(substr($meta_data_block_data, 0, 128), "\0");
$getid3->info['flac']['CUESHEET']['lead_in_samples'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, 128, 8));
$getid3->info['flac']['CUESHEET']['flags']['is_cd'] = (bool)(getid3_lib::BigEndian2Int($meta_data_block_data[136]) & 0x80);
$getid3->info['flac']['CUESHEET']['number_tracks'] = getid3_lib::BigEndian2Int($meta_data_block_data[395]);
$offset = 396;
for ($track = 0; $track < $getid3->info['flac']['CUESHEET']['number_tracks']; $track++) {
$track_sample_offset = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 8));
$offset += 8;
$track_number = getid3_lib::BigEndian2Int($meta_data_block_data{$offset++});
$getid3->info['flac']['CUESHEET']['tracks'][$track_number]['sample_offset'] = $track_sample_offset;
$getid3->info['flac']['CUESHEET']['tracks'][$track_number]['isrc'] = substr($meta_data_block_data, $offset, 12);
$offset += 12;
$track_flags_raw = getid3_lib::BigEndian2Int($meta_data_block_data{$offset++});
$getid3->info['flac']['CUESHEET']['tracks'][$track_number]['flags']['is_audio'] = (bool)($track_flags_raw & 0x80);
$getid3->info['flac']['CUESHEET']['tracks'][$track_number]['flags']['pre_emphasis'] = (bool)($track_flags_raw & 0x40);
$offset += 13; // reserved
$getid3->info['flac']['CUESHEET']['tracks'][$track_number]['index_points'] = getid3_lib::BigEndian2Int($meta_data_block_data{$offset++});
for ($index = 0; $index < $getid3->info['flac']['CUESHEET']['tracks'][$track_number]['index_points']; $index++) {
$index_sample_offset = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 8));
$offset += 8;
$index_number = getid3_lib::BigEndian2Int($meta_data_block_data{$offset++});
$getid3->info['flac']['CUESHEET']['tracks'][$track_number]['indexes'][$index_number] = $index_sample_offset;
$offset += 3; // reserved
}
}
unset($getid3->info['flac']['CUESHEET']['raw']);
return true;
}
private function FLACparsePICTURE($meta_data_block_data) {
$getid3 = $this->getid3;
$picture = &$getid3->info['flac']['PICTURE'][sizeof($getid3->info['flac']['PICTURE']) - 1];
$offset = 0;
$picture['type'] = $this->FLACpictureTypeLookup(getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)));
$offset += 4;
$length = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4));
$offset += 4;
$picture['mime_type'] = substr($meta_data_block_data, $offset, $length);
$offset += $length;
$length = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4));
$offset += 4;
$picture['description'] = substr($meta_data_block_data, $offset, $length);
$offset += $length;
$picture['width'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4));
$offset += 4;
$picture['height'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4));
$offset += 4;
$picture['color_depth'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4));
$offset += 4;
$picture['colors_indexed'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4));
$offset += 4;
$length = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4));
$offset += 4;
$picture['image_data'] = substr($meta_data_block_data, $offset, $length);
$offset += $length;
unset($getid3->info['flac']['PICTURE']['raw']);
return true;
}
public static function SpeexBandModeLookup($mode) {
static $lookup = array (
0 => 'narrow',
1 => 'wide',
2 => 'ultra-wide'
);
return (isset($lookup[$mode]) ? $lookup[$mode] : null);
}
public static function OggPageSegmentLength($ogg_info_array, $segment_number=1) {
for ($i = 0; $i < $segment_number; $i++) {
$segment_length = 0;
foreach ($ogg_info_array['segment_table'] as $key => $value) {
$segment_length += $value;
if ($value < 255) {
break;
}
}
}
return $segment_length;
}
public static function GetQualityFromNominalBitrate($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 round($qval, 1); // 5 or 4.9
}
public static function FLACmetaBlockTypeLookup($block_type) {
static $lookup = array (
0 => 'STREAMINFO',
1 => 'PADDING',
2 => 'APPLICATION',
3 => 'SEEKTABLE',
4 => 'VORBIS_COMMENT',
5 => 'CUESHEET',
6 => 'PICTURE'
);
return (isset($lookup[$block_type]) ? $lookup[$block_type] : 'reserved');
}
public static function FLACapplicationIDLookup($application_id) {
// http://flac.sourceforge.net/id.html
static $lookup = array (
0x46746F6C => 'flac-tools', // 'Ftol'
0x46746F6C => 'Sound Font FLAC', // 'SFFL'
0x7065656D => 'Parseable Embedded Extensible Metadata (specification)', // 'peem'
0x786D6364 => 'xmcd'
);
return (isset($lookup[$application_id]) ? $lookup[$application_id] : 'reserved');
}
public static function FLACpictureTypeLookup($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');
}
}
?>

View file

@ -0,0 +1,319 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.graphic.bmp.php |
// | Module for analyzing BMP graphic files. |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.graphic.bmp.php,v 1.4 2006/11/02 10:48:02 ah Exp $
class getid3_bmp extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
// 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;
// shortcuts
$getid3->info['bmp']['header']['raw'] = array ();
$info_bmp = &$getid3->info['bmp'];
$info_bmp_header = &$info_bmp['header'];
$info_bmp_header_raw = &$info_bmp_header['raw'];
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$bmp_header = fread($getid3->fp, 14 + 40);
// Magic bytes
$info_bmp_header_raw['identifier'] = 'BM';
getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 2,
array (
'filesize' => 4,
'reserved1' => 2,
'reserved2' => 2,
'data_offset' => 4,
'header_size' => 4
)
);
// Check if the hardcoded-to-1 "planes" is at offset 22 or 26
$planes22 = getid3_lib::LittleEndian2Int(substr($bmp_header, 22, 2));
$planes26 = getid3_lib::LittleEndian2Int(substr($bmp_header, 26, 2));
if (($planes22 == 1) && ($planes26 != 1)) {
$info_bmp['type_os'] = 'OS/2';
$info_bmp['type_version'] = 1;
}
elseif (($planes26 == 1) && ($planes22 != 1)) {
$info_bmp['type_os'] = 'Windows';
$info_bmp['type_version'] = 1;
}
elseif ($info_bmp_header_raw['header_size'] == 12) {
$info_bmp['type_os'] = 'OS/2';
$info_bmp['type_version'] = 1;
}
elseif ($info_bmp_header_raw['header_size'] == 40) {
$info_bmp['type_os'] = 'Windows';
$info_bmp['type_version'] = 1;
}
elseif ($info_bmp_header_raw['header_size'] == 84) {
$info_bmp['type_os'] = 'Windows';
$info_bmp['type_version'] = 4;
}
elseif ($info_bmp_header_raw['header_size'] == 100) {
$info_bmp['type_os'] = 'Windows';
$info_bmp['type_version'] = 5;
}
else {
throw new getid3_exception('Unknown BMP subtype (or not a BMP file)');
}
$getid3->info['fileformat'] = 'bmp';
$getid3->info['video']['dataformat'] = 'bmp';
$getid3->info['video']['lossless'] = true;
$getid3->info['video']['pixel_aspect_ratio'] = (float)1;
if ($info_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 */
getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 18,
array (
'width' => 2,
'height' => 2,
'planes' => 2,
'bits_per_pixel' => 2
)
);
$getid3->info['video']['resolution_x'] = $info_bmp_header_raw['width'];
$getid3->info['video']['resolution_y'] = $info_bmp_header_raw['height'];
$getid3->info['video']['codec'] = 'BI_RGB '.$info_bmp_header_raw['bits_per_pixel'].'-bit';
$getid3->info['video']['bits_per_sample'] = $info_bmp_header_raw['bits_per_pixel'];
if ($info_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 */
getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 26,
array (
'compression' => 4,
'bmp_data_size' => 4,
'resolution_h' => 4,
'resolution_v' => 4,
'colors_used' => 4,
'colors_important' => 4,
'resolution_units' => 2,
'reserved1' => 2,
'recording' => 2,
'rendering' => 2,
'size1' => 4,
'size2' => 4,
'color_encoding' => 4,
'identifier' => 4
)
);
$info_bmp_header['compression'] = getid3_bmp::BMPcompressionOS2Lookup($info_bmp_header_raw['compression']);
$getid3->info['video']['codec'] = $info_bmp_header['compression'].' '.$info_bmp_header_raw['bits_per_pixel'].'-bit';
}
return true;
}
if ($info_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;
getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 18,
array (
'width' => -4, //signed
'height' => -4, //signed
'planes' => 2,
'bits_per_pixel' => 2,
'compression' => 4,
'bmp_data_size' => 4,
'resolution_h' => -4, //signed
'resolution_v' => -4, //signed
'colors_used' => 4,
'colors_important' => 4
)
);
foreach (array ('width', 'height', 'resolution_h', 'resolution_v') as $key) {
$info_bmp_header_raw[$key] = getid3_lib::LittleEndian2Int($info_bmp_header_raw[$key], true);
}
$info_bmp_header['compression'] = getid3_bmp::BMPcompressionWindowsLookup($info_bmp_header_raw['compression']);
$getid3->info['video']['resolution_x'] = $info_bmp_header_raw['width'];
$getid3->info['video']['resolution_y'] = $info_bmp_header_raw['height'];
$getid3->info['video']['codec'] = $info_bmp_header['compression'].' '.$info_bmp_header_raw['bits_per_pixel'].'-bit';
$getid3->info['video']['bits_per_sample'] = $info_bmp_header_raw['bits_per_pixel'];
// should only be v4+, but BMPs with type_version==1 and BI_BITFIELDS compression have been seen
if (($info_bmp['type_version'] >= 4) || ($info_bmp_header_raw['compression'] == 3)) {
$bmp_header .= fread($getid3->fp, 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;
getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 54,
array (
'red_mask' => 4,
'green_mask' => 4,
'blue_mask' => 4,
'alpha_mask' => 4,
'cs_type' => 4,
'ciexyz_red' => -4, //string
'ciexyz_green' => -4, //string
'ciexyz_blue' => -4, //string
'gamma_red' => 4,
'gamma_green' => 4,
'gamma_blue' => 4
)
);
$info_bmp_header['ciexyz_red'] = getid3_bmp::FixedPoint2_30(strrev($info_bmp_header_raw['ciexyz_red']));
$info_bmp_header['ciexyz_green'] = getid3_bmp::FixedPoint2_30(strrev($info_bmp_header_raw['ciexyz_green']));
$info_bmp_header['ciexyz_blue'] = getid3_bmp::FixedPoint2_30(strrev($info_bmp_header_raw['ciexyz_blue']));
if ($info_bmp['type_version'] >= 5) {
$bmp_header .= fread($getid3->fp, 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;
getid3_lib::ReadSequence('LittleEndian2Int', $info_bmp_header_raw, $bmp_header, 98,
array (
'intent' => 4,
'profile_data_offset' => 4,
'profile_data_size' => 4,
'reserved3' => 4
)
);
}
}
return true;
}
throw new getid3_exception('Unknown BMP format in header.');
}
public static function BMPcompressionWindowsLookup($compression_id) {
static $lookup = array (
0 => 'BI_RGB',
1 => 'BI_RLE8',
2 => 'BI_RLE4',
3 => 'BI_BITFIELDS',
4 => 'BI_JPEG',
5 => 'BI_PNG'
);
return (isset($lookup[$compression_id]) ? $lookup[$compression_id] : 'invalid');
}
public static function BMPcompressionOS2Lookup($compression_id) {
static $lookup = array (
0 => 'BI_RGB',
1 => 'BI_RLE8',
2 => 'BI_RLE4',
3 => 'Huffman 1D',
4 => 'BI_RLE24',
);
return (isset($lookup[$compression_id]) ? $lookup[$compression_id] : 'invalid');
}
public static function FixedPoint2_30($raw_data) {
$binary_string = getid3_lib::BigEndian2Bin($raw_data);
return bindec(substr($binary_string, 0, 2)) + (float)(bindec(substr($binary_string, 2, 30)) / 1073741824); // pow(2, 30) = 1073741824
}
}
?>

View file

@ -0,0 +1,92 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.graphic.gif.php |
// | Module for analyzing CompuServe GIF graphic files. |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.graphic.gif.php,v 1.2 2006/11/02 10:48:02 ah Exp $
class getid3_gif extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->info['fileformat'] = 'gif';
$getid3->info['video']['dataformat'] = 'gif';
$getid3->info['video']['lossless'] = true;
$getid3->info['video']['pixel_aspect_ratio'] = (float)1;
$getid3->info['gif']['header'] = array ();
$info_gif_header = &$getid3->info['gif']['header'];
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$gif_header = fread($getid3->fp, 13);
// Magic bytes
$info_gif_header['raw']['identifier'] = 'GIF';
getid3_lib::ReadSequence('LittleEndian2Int', $info_gif_header['raw'], $gif_header, 3,
array (
'version' => -3, // string
'width' => 2,
'height' => 2,
'flags' => 1,
'bg_color_index' => 1,
'aspect_ratio' => 1
)
);
$getid3->info['video']['resolution_x'] = $info_gif_header['raw']['width'];
$getid3->info['video']['resolution_y'] = $info_gif_header['raw']['height'];
$getid3->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);
$getid3->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;
}
return true;
}
}
?>

View file

@ -0,0 +1,62 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.graphic.jpeg.php |
// | Module for analyzing JPEG graphic files. |
// | dependencies: exif support in PHP (optional) |
// +----------------------------------------------------------------------+
//
// $Id: module.graphic.jpeg.php,v 1.4 2006/11/02 10:48:02 ah Exp $
class getid3_jpeg extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->info['fileformat'] = 'jpg';
$getid3->info['video']['dataformat'] = 'jpg';
$getid3->info['video']['lossless'] = false;
$getid3->info['video']['bits_per_sample'] = 24;
$getid3->info['video']['pixel_aspect_ratio'] = (float)1;
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
list($getid3->info['video']['resolution_x'], $getid3->info['video']['resolution_y'], $type) = getimagesize($getid3->filename);
if ($type != 2) {
throw new getid3_exception('File detected as JPEG, but is currupt.');
}
if (function_exists('exif_read_data')) {
$getid3->info['jpg']['exif'] = exif_read_data($getid3->filename, '', true, false);
} else {
$getid3->warning('EXIF parsing only available when compiled with --enable-exif (or php_exif.dll enabled for Windows).');
}
return true;
}
}
?>

View file

@ -0,0 +1,56 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.graphic.pcd.php |
// | Module for analyzing PhotoCD (PCD) Image files. |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.graphic.pcd.php,v 1.2 2006/11/02 10:48:02 ah Exp $
class getid3_pcd extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->info['fileformat'] = 'pcd';
$getid3->info['video']['dataformat'] = 'pcd';
$getid3->info['video']['lossless'] = false;
fseek($getid3->fp, $getid3->info['avdataoffset'] + 72, SEEK_SET);
$pcd_flags = fread($getid3->fp, 1);
$pcd_is_vertical = ((ord($pcd_flags) & 0x01) ? true : false);
if ($pcd_is_vertical) {
$getid3->info['video']['resolution_x'] = 3072;
$getid3->info['video']['resolution_y'] = 2048;
} else {
$getid3->info['video']['resolution_x'] = 2048;
$getid3->info['video']['resolution_y'] = 3072;
}
}
}
?>

View file

@ -0,0 +1,556 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.graphic.png.php |
// | Module for analyzing PNG graphic files. |
// | dependencies: zlib support in PHP (optional) |
// +----------------------------------------------------------------------+
//
// $Id: module.graphic.png.php,v 1.4 2006/11/02 10:48:02 ah Exp $
class getid3_png extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->info['png'] = array ();
$info_png = &$getid3->info['png'];
$getid3->info['fileformat'] = 'png';
$getid3->info['video']['dataformat'] = 'png';
$getid3->info['video']['lossless'] = false;
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$png_filedata = fread($getid3->fp, getid3::FREAD_BUFFER_SIZE);
// Magic bytes "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"
$offset = 8;
while (((ftell($getid3->fp) - (strlen($png_filedata) - $offset)) < $getid3->info['filesize'])) {
$chunk['data_length'] = getid3_lib::BigEndian2Int(substr($png_filedata, $offset, 4));
$offset += 4;
while (((strlen($png_filedata) - $offset) < ($chunk['data_length'] + 4)) && (ftell($getid3->fp) < $getid3->info['filesize'])) {
$png_filedata .= fread($getid3->fp, getid3::FREAD_BUFFER_SIZE);
}
$chunk['type_text'] = substr($png_filedata, $offset, 4);
$chunk['type_raw'] = getid3_lib::BigEndian2Int($chunk['type_text']);
$offset += 4;
$chunk['data'] = substr($png_filedata, $offset, $chunk['data_length']);
$offset += $chunk['data_length'];
$chunk['crc'] = getid3_lib::BigEndian2Int(substr($png_filedata, $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
$info_png[$chunk['type_text']] = array ();
$info_png_chunk_type_text = &$info_png[$chunk['type_text']];
switch ($chunk['type_text']) {
case 'IHDR': // Image Header
$info_png_chunk_type_text['header'] = $chunk;
$info_png_chunk_type_text['width'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4));
$info_png_chunk_type_text['height'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4));
getid3_lib::ReadSequence('BigEndian2Int', $info_png_chunk_type_text['raw'], $chunk['data'], 8,
array (
'bit_depth' => 1,
'color_type' => 1,
'compression_method' => 1,
'filter_method' => 1,
'interlace_method' => 1
)
);
$info_png_chunk_type_text['compression_method_text'] = getid3_png::PNGcompressionMethodLookup($info_png_chunk_type_text['raw']['compression_method']);
$info_png_chunk_type_text['color_type']['palette'] = (bool)($info_png_chunk_type_text['raw']['color_type'] & 0x01);
$info_png_chunk_type_text['color_type']['true_color'] = (bool)($info_png_chunk_type_text['raw']['color_type'] & 0x02);
$info_png_chunk_type_text['color_type']['alpha'] = (bool)($info_png_chunk_type_text['raw']['color_type'] & 0x04);
$getid3->info['video']['resolution_x'] = $info_png_chunk_type_text['width'];
$getid3->info['video']['resolution_y'] = $info_png_chunk_type_text['height'];
$getid3->info['video']['bits_per_sample'] = getid3_png::IHDRcalculateBitsPerSample($info_png_chunk_type_text['raw']['color_type'], $info_png_chunk_type_text['raw']['bit_depth']);
break;
case 'PLTE': // Palette
$info_png_chunk_type_text['header'] = $chunk;
$palette_offset = 0;
for ($i = 0; $i <= 255; $i++) {
$red = @getid3_lib::BigEndian2Int($chunk['data']{$palette_offset++});
$green = @getid3_lib::BigEndian2Int($chunk['data']{$palette_offset++});
$blue = @getid3_lib::BigEndian2Int($chunk['data']{$palette_offset++});
$info_png_chunk_type_text[$i] = (($red << 16) | ($green << 8) | ($blue));
}
break;
case 'tRNS': // Transparency
$info_png_chunk_type_text['header'] = $chunk;
switch ($info_png['IHDR']['raw']['color_type']) {
case 0:
$info_png_chunk_type_text['transparent_color_gray'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 2));
break;
case 2:
$info_png_chunk_type_text['transparent_color_red'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 2));
$info_png_chunk_type_text['transparent_color_green'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2, 2));
$info_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++) {
$info_png_chunk_type_text['palette_opacity'][$i] = getid3_lib::BigEndian2Int($chunk['data'][$i]);
}
break;
case 4:
case 6:
throw new getid3_exception('Invalid color_type in tRNS chunk: '.$info_png['IHDR']['raw']['color_type']);
default:
$getid3->warning('Unhandled color_type in tRNS chunk: '.$info_png['IHDR']['raw']['color_type']);
break;
}
break;
case 'gAMA': // Image Gamma
$info_png_chunk_type_text['header'] = $chunk;
$info_png_chunk_type_text['gamma'] = getid3_lib::BigEndian2Int($chunk['data']) / 100000;
break;
case 'cHRM': // Primary Chromaticities
$info_png_chunk_type_text['header'] = $chunk;
$info_png_chunk_type_text['white_x'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4)) / 100000;
$info_png_chunk_type_text['white_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4)) / 100000;
$info_png_chunk_type_text['red_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 8, 4)) / 100000;
$info_png_chunk_type_text['red_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 12, 4)) / 100000;
$info_png_chunk_type_text['green_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 16, 4)) / 100000;
$info_png_chunk_type_text['green_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 20, 4)) / 100000;
$info_png_chunk_type_text['blue_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 24, 4)) / 100000;
$info_png_chunk_type_text['blue_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 28, 4)) / 100000;
break;
case 'sRGB': // Standard RGB Color Space
$info_png_chunk_type_text['header'] = $chunk;
$info_png_chunk_type_text['reindering_intent'] = getid3_lib::BigEndian2Int($chunk['data']);
$info_png_chunk_type_text['reindering_intent_text'] = getid3_png::PNGsRGBintentLookup($info_png_chunk_type_text['reindering_intent']);
break;
case 'iCCP': // Embedded ICC Profile
$info_png_chunk_type_text['header'] = $chunk;
list($profilename, $compressiondata) = explode("\x00", $chunk['data'], 2);
$info_png_chunk_type_text['profile_name'] = $profilename;
$info_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int($compressiondata[0]);
$info_png_chunk_type_text['compression_profile'] = substr($compressiondata, 1);
$info_png_chunk_type_text['compression_method_text'] = getid3_png::PNGcompressionMethodLookup($info_png_chunk_type_text['compression_method']);
break;
case 'tEXt': // Textual Data
$info_png_chunk_type_text['header'] = $chunk;
list($keyword, $text) = explode("\x00", $chunk['data'], 2);
$info_png_chunk_type_text['keyword'] = $keyword;
$info_png_chunk_type_text['text'] = $text;
$info_png['comments'][$info_png_chunk_type_text['keyword']][] = $info_png_chunk_type_text['text'];
break;
case 'zTXt': // Compressed Textual Data
$info_png_chunk_type_text['header'] = $chunk;
list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2);
$info_png_chunk_type_text['keyword'] = $keyword;
$info_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int(substr($otherdata, 0, 1));
$info_png_chunk_type_text['compressed_text'] = substr($otherdata, 1);
$info_png_chunk_type_text['compression_method_text'] = getid3_png::PNGcompressionMethodLookup($info_png_chunk_type_text['compression_method']);
if ($info_png_chunk_type_text['compression_method'] != 0) {
// unknown compression method
break;
}
if (function_exists('gzuncompress')) {
$info_png_chunk_type_text['text'] = gzuncompress($info_png_chunk_type_text['compressed_text']);
}
else {
if (!@$this->zlib_warning) {
$getid3->warning('PHP does not have --with-zlib support - cannot gzuncompress()');
}
$this->zlib_warning = true;
}
if (isset($info_png_chunk_type_text['text'])) {
$info_png['comments'][$info_png_chunk_type_text['keyword']][] = $info_png_chunk_type_text['text'];
}
break;
case 'iTXt': // International Textual Data
$info_png_chunk_type_text['header'] = $chunk;
list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2);
$info_png_chunk_type_text['keyword'] = $keyword;
$info_png_chunk_type_text['compression'] = (bool)getid3_lib::BigEndian2Int(substr($otherdata, 0, 1));
$info_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int($otherdata[1]);
$info_png_chunk_type_text['compression_method_text'] = getid3_png::PNGcompressionMethodLookup($info_png_chunk_type_text['compression_method']);
list($languagetag, $translatedkeyword, $text) = explode("\x00", substr($otherdata, 2), 3);
$info_png_chunk_type_text['language_tag'] = $languagetag;
$info_png_chunk_type_text['translated_keyword'] = $translatedkeyword;
if ($info_png_chunk_type_text['compression']) {
switch ($info_png_chunk_type_text['compression_method']) {
case 0:
if (function_exists('gzuncompress')) {
$info_png_chunk_type_text['text'] = gzuncompress($text);
}
else {
if (!@$this->zlib_warning) {
$getid3->warning('PHP does not have --with-zlib support - cannot gzuncompress()');
}
$this->zlib_warning = true;
}
break;
default:
// unknown compression method
break;
}
} else {
$info_png_chunk_type_text['text'] = $text;
}
if (isset($info_png_chunk_type_text['text'])) {
$info_png['comments'][$info_png_chunk_type_text['keyword']][] = $info_png_chunk_type_text['text'];
}
break;
case 'bKGD': // Background Color
$info_png_chunk_type_text['header'] = $chunk;
switch ($info_png['IHDR']['raw']['color_type']) {
case 0:
case 4:
$info_png_chunk_type_text['background_gray'] = getid3_lib::BigEndian2Int($chunk['data']);
break;
case 2:
case 6:
$info_png_chunk_type_text['background_red'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0 * $info_png['IHDR']['raw']['bit_depth'], $info_png['IHDR']['raw']['bit_depth']));
$info_png_chunk_type_text['background_green'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 1 * $info_png['IHDR']['raw']['bit_depth'], $info_png['IHDR']['raw']['bit_depth']));
$info_png_chunk_type_text['background_blue'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 2 * $info_png['IHDR']['raw']['bit_depth'], $info_png['IHDR']['raw']['bit_depth']));
break;
case 3:
$info_png_chunk_type_text['background_index'] = getid3_lib::BigEndian2Int($chunk['data']);
break;
default:
break;
}
break;
case 'pHYs': // Physical Pixel Dimensions
$info_png_chunk_type_text['header'] = $chunk;
$info_png_chunk_type_text['pixels_per_unit_x'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4));
$info_png_chunk_type_text['pixels_per_unit_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4));
$info_png_chunk_type_text['unit_specifier'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 8, 1));
$info_png_chunk_type_text['unit'] = getid3_png::PNGpHYsUnitLookup($info_png_chunk_type_text['unit_specifier']);
break;
case 'sBIT': // Significant Bits
$info_png_chunk_type_text['header'] = $chunk;
switch ($info_png['IHDR']['raw']['color_type']) {
case 0:
$info_png_chunk_type_text['significant_bits_gray'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1));
break;
case 2:
case 3:
$info_png_chunk_type_text['significant_bits_red'] = getid3_lib::BigEndian2Int($chunk['data'][0]);
$info_png_chunk_type_text['significant_bits_green'] = getid3_lib::BigEndian2Int($chunk['data'][1]);
$info_png_chunk_type_text['significant_bits_blue'] = getid3_lib::BigEndian2Int($chunk['data'][2]);
break;
case 4:
$info_png_chunk_type_text['significant_bits_gray'] = getid3_lib::BigEndian2Int($chunk['data'][0]);
$info_png_chunk_type_text['significant_bits_alpha'] = getid3_lib::BigEndian2Int($chunk['data'][1]);
break;
case 6:
$info_png_chunk_type_text['significant_bits_red'] = getid3_lib::BigEndian2Int($chunk['data'][0]);
$info_png_chunk_type_text['significant_bits_green'] = getid3_lib::BigEndian2Int($chunk['data'][1]);
$info_png_chunk_type_text['significant_bits_blue'] = getid3_lib::BigEndian2Int($chunk['data'][2]);
$info_png_chunk_type_text['significant_bits_alpha'] = getid3_lib::BigEndian2Int($chunk['data'][3]);
break;
default:
break;
}
break;
case 'sPLT': // Suggested Palette
$info_png_chunk_type_text['header'] = $chunk;
list($palettename, $otherdata) = explode("\x00", $chunk['data'], 2);
$info_png_chunk_type_text['palette_name'] = $palettename;
$info_png_chunk_type_text['sample_depth_bits'] = getid3_lib::BigEndian2Int($otherdata[0]);
$info_png_chunk_type_text['sample_depth_bytes'] = $info_png_chunk_type_text['sample_depth_bits'] / 8;
$s_plt_offset = 1;
$paletteCounter = 0;
while ($s_plt_offset < strlen($otherdata)) {
$info_png_chunk_type_text['red'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes']));
$s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes'];
$info_png_chunk_type_text['green'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes']));
$s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes'];
$info_png_chunk_type_text['blue'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes']));
$s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes'];
$info_png_chunk_type_text['alpha'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, $info_png_chunk_type_text['sample_depth_bytes']));
$s_plt_offset += $info_png_chunk_type_text['sample_depth_bytes'];
$info_png_chunk_type_text['frequency'][$paletteCounter] = getid3_lib::BigEndian2Int(substr($otherdata, $s_plt_offset, 2));
$s_plt_offset += 2;
$paletteCounter++;
}
break;
case 'hIST': // Palette Histogram
$info_png_chunk_type_text['header'] = $chunk;
$h_ist_counter = 0;
while ($h_ist_counter < strlen($chunk['data'])) {
$info_png_chunk_type_text[$h_ist_counter] = getid3_lib::BigEndian2Int(substr($chunk['data'], $h_ist_counter / 2, 2));
$h_ist_counter += 2;
}
break;
case 'tIME': // Image Last-Modification Time
$info_png_chunk_type_text['header'] = $chunk;
$info_png_chunk_type_text['year'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 2));
$info_png_chunk_type_text['month'] = getid3_lib::BigEndian2Int($chunk['data']{2});
$info_png_chunk_type_text['day'] = getid3_lib::BigEndian2Int($chunk['data']{3});
$info_png_chunk_type_text['hour'] = getid3_lib::BigEndian2Int($chunk['data']{4});
$info_png_chunk_type_text['minute'] = getid3_lib::BigEndian2Int($chunk['data']{5});
$info_png_chunk_type_text['second'] = getid3_lib::BigEndian2Int($chunk['data']{6});
$info_png_chunk_type_text['unix'] = gmmktime($info_png_chunk_type_text['hour'], $info_png_chunk_type_text['minute'], $info_png_chunk_type_text['second'], $info_png_chunk_type_text['month'], $info_png_chunk_type_text['day'], $info_png_chunk_type_text['year']);
break;
case 'oFFs': // Image Offset
$info_png_chunk_type_text['header'] = $chunk;
$info_png_chunk_type_text['position_x'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4), false, true);
$info_png_chunk_type_text['position_y'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4), false, true);
$info_png_chunk_type_text['unit_specifier'] = getid3_lib::BigEndian2Int($chunk['data'][8]);
$info_png_chunk_type_text['unit'] = getid3_png::PNGoFFsUnitLookup($info_png_chunk_type_text['unit_specifier']);
break;
case 'pCAL': // Calibration Of Pixel Values
$info_png_chunk_type_text['header'] = $chunk;
list($calibrationname, $otherdata) = explode("\x00", $chunk['data'], 2);
$info_png_chunk_type_text['calibration_name'] = $calibrationname;
$info_png_chunk_type_text['original_zero'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4), false, true);
$info_png_chunk_type_text['original_max'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4), false, true);
$info_png_chunk_type_text['equation_type'] = getid3_lib::BigEndian2Int($chunk['data'][8]);
$info_png_chunk_type_text['equation_type_text'] = getid3_png::PNGpCALequationTypeLookup($info_png_chunk_type_text['equation_type']);
$info_png_chunk_type_text['parameter_count'] = getid3_lib::BigEndian2Int($chunk['data'][9]);
$info_png_chunk_type_text['parameters'] = explode("\x00", substr($chunk['data'], 10));
break;
case 'sCAL': // Physical Scale Of Image Subject
$info_png_chunk_type_text['header'] = $chunk;
$info_png_chunk_type_text['unit_specifier'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 1));
$info_png_chunk_type_text['unit'] = getid3_png::PNGsCALUnitLookup($info_png_chunk_type_text['unit_specifier']);
list($info_png_chunk_type_text['pixel_width'], $info_png_chunk_type_text['pixel_height']) = explode("\x00", substr($chunk['data'], 1));
break;
case 'gIFg': // GIF Graphic Control Extension
$gIFg_counter = 0;
if (isset($info_png_chunk_type_text) && is_array($info_png_chunk_type_text)) {
$gIFg_counter = count($info_png_chunk_type_text);
}
$info_png_chunk_type_text[$gIFg_counter]['header'] = $chunk;
$info_png_chunk_type_text[$gIFg_counter]['disposal_method'] = getid3_lib::BigEndian2Int($chunk['data'][0]);
$info_png_chunk_type_text[$gIFg_counter]['user_input_flag'] = getid3_lib::BigEndian2Int($chunk['data'][1]);
$info_png_chunk_type_text[$gIFg_counter]['delay_time'] = getid3_lib::BigEndian2Int($chunk['data'][2]);
break;
case 'gIFx': // GIF Application Extension
$gIFx_counter = 0;
if (isset($info_png_chunk_type_text) && is_array($info_png_chunk_type_text)) {
$gIFx_counter = count($info_png_chunk_type_text);
}
$info_png_chunk_type_text[$gIFx_counter]['header'] = $chunk;
$info_png_chunk_type_text[$gIFx_counter]['application_identifier'] = substr($chunk['data'], 0, 8);
$info_png_chunk_type_text[$gIFx_counter]['authentication_code'] = substr($chunk['data'], 8, 3);
$info_png_chunk_type_text[$gIFx_counter]['application_data'] = substr($chunk['data'], 11);
break;
case 'IDAT': // Image Data
$idat_information_field_index = 0;
if (isset($info_png['IDAT']) && is_array($info_png['IDAT'])) {
$idat_information_field_index = count($info_png['IDAT']);
}
unset($chunk['data']);
$info_png_chunk_type_text[$idat_information_field_index]['header'] = $chunk;
break;
case 'IEND': // Image Trailer
$info_png_chunk_type_text['header'] = $chunk;
break;
default:
$info_png_chunk_type_text['header'] = $chunk;
$getid3->warning('Unhandled chunk type: '.$chunk['type_text']);
break;
}
}
return true;
}
public static function PNGsRGBintentLookup($sRGB) {
static $lookup = array (
0 => 'Perceptual',
1 => 'Relative colorimetric',
2 => 'Saturation',
3 => 'Absolute colorimetric'
);
return (isset($lookup[$sRGB]) ? $lookup[$sRGB] : 'invalid');
}
public static function PNGcompressionMethodLookup($compression_method) {
return ($compression_method == 0 ? 'deflate/inflate' : 'invalid');
}
public static function PNGpHYsUnitLookup($unit_id) {
static $lookup = array (
0 => 'unknown',
1 => 'meter'
);
return (isset($lookup[$unit_id]) ? $lookup[$unit_id] : 'invalid');
}
public static function PNGoFFsUnitLookup($unit_id) {
static $lookup = array (
0 => 'pixel',
1 => 'micrometer'
);
return (isset($lookup[$unit_id]) ? $lookup[$unit_id] : 'invalid');
}
public static function PNGpCALequationTypeLookup($equation_type) {
static $lookup = array (
0 => 'Linear mapping',
1 => 'Base-e exponential mapping',
2 => 'Arbitrary-base exponential mapping',
3 => 'Hyperbolic mapping'
);
return (isset($lookup[$equation_type]) ? $lookup[$equation_type] : 'invalid');
}
public static function PNGsCALUnitLookup($unit_id) {
static $lookup = array (
0 => 'meter',
1 => 'radian'
);
return (isset($lookup[$unit_id]) ? $lookup[$unit_id] : 'invalid');
}
public static function IHDRcalculateBitsPerSample($color_type, $bit_depth) {
switch ($color_type) {
case 0: // Each pixel is a grayscale sample.
return $bit_depth;
case 2: // Each pixel is an R,G,B triple
return 3 * $bit_depth;
case 3: // Each pixel is a palette index; a PLTE chunk must appear.
return $bit_depth;
case 4: // Each pixel is a grayscale sample, followed by an alpha sample.
return 2 * $bit_depth;
case 6: // Each pixel is an R,G,B triple, followed by an alpha sample.
return 4 * $bit_depth;
}
return false;
}
}
?>

View file

@ -0,0 +1,215 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.graphic.tiff.php |
// | Module for analyzing TIFF graphic files. |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.graphic.tiff.php,v 1.2 2006/11/02 10:48:02 ah Exp $
class getid3_tiff extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$tiff_header = fread($getid3->fp, 4);
$getid3->info['tiff']['byte_order'] = substr($tiff_header, 0, 2) == 'II' ? 'Intel' : 'Motorola';
$endian2int = substr($tiff_header, 0, 2) == 'II' ? 'LittleEndian2Int' : 'BigEndian2Int';
$getid3->info['fileformat'] = 'tiff';
$getid3->info['video']['dataformat'] = 'tiff';
$getid3->info['video']['lossless'] = true;
$getid3->info['tiff']['ifd'] = array ();
$current_ifd = array ();
$field_type_byte_length = array (1=>1, 2=>1, 3=>2, 4=>4, 5=>8);
$next_ifd_offset = getid3_lib::$endian2int(fread($getid3->fp, 4));
while ($next_ifd_offset > 0) {
$current_ifd['offset'] = $next_ifd_offset;
fseek($getid3->fp, $getid3->info['avdataoffset'] + $next_ifd_offset, SEEK_SET);
$current_ifd['fieldcount'] = getid3_lib::$endian2int(fread($getid3->fp, 2));
for ($i = 0; $i < $current_ifd['fieldcount']; $i++) {
// shortcut
$current_ifd['fields'][$i] = array ();
$current_ifd_fields_i = &$current_ifd['fields'][$i];
$current_ifd_fields_i['raw']['tag'] = getid3_lib::$endian2int(fread($getid3->fp, 2));
$current_ifd_fields_i['raw']['type'] = getid3_lib::$endian2int(fread($getid3->fp, 2));
$current_ifd_fields_i['raw']['length'] = getid3_lib::$endian2int(fread($getid3->fp, 4));
$current_ifd_fields_i['raw']['offset'] = fread($getid3->fp, 4);
switch ($current_ifd_fields_i['raw']['type']) {
case 1: // BYTE An 8-bit unsigned integer.
if ($current_ifd_fields_i['raw']['length'] <= 4) {
$current_ifd_fields_i['value'] = getid3_lib::$endian2int(substr($current_ifd_fields_i['raw']['offset'], 0, 1));
} else {
$current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']);
}
break;
case 2: // ASCII 8-bit bytes that store ASCII codes; the last byte must be null.
if ($current_ifd_fields_i['raw']['length'] <= 4) {
$current_ifd_fields_i['value'] = substr($current_ifd_fields_i['raw']['offset'], 3);
} else {
$current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']);
}
break;
case 3: // SHORT A 16-bit (2-byte) unsigned integer.
if ($current_ifd_fields_i['raw']['length'] <= 2) {
$current_ifd_fields_i['value'] = getid3_lib::$endian2int(substr($current_ifd_fields_i['raw']['offset'], 0, 2));
} else {
$current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']);
}
break;
case 4: // LONG A 32-bit (4-byte) unsigned integer.
if ($current_ifd_fields_i['raw']['length'] <= 1) {
$current_ifd_fields_i['value'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']);
} else {
$current_ifd_fields_i['offset'] = getid3_lib::$endian2int($current_ifd_fields_i['raw']['offset']);
}
break;
case 5: // RATIONAL Two LONG_s: the first represents the numerator of a fraction, the second the denominator.
break;
}
}
$getid3->info['tiff']['ifd'][] = $current_ifd;
$current_ifd = array ();
$next_ifd_offset = getid3_lib::$endian2int(fread($getid3->fp, 4));
}
foreach ($getid3->info['tiff']['ifd'] as $ifd_id => $ifd_array) {
foreach ($ifd_array['fields'] as $key => $field_array) {
switch ($field_array['raw']['tag']) {
case 256: // ImageWidth
case 257: // ImageLength
case 258: // BitsPerSample
case 259: // Compression
if (!isset($field_array['value'])) {
fseek($getid3->fp, $field_array['offset'], SEEK_SET);
$getid3->info['tiff']['ifd'][$ifd_id]['fields'][$key]['raw']['data'] = fread($getid3->fp, $field_array['raw']['length'] * $field_type_byte_length[$field_array['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($field_array['value'])) {
$getid3->info['tiff']['ifd'][$ifd_id]['fields'][$key]['raw']['data'] = $field_array['value'];
} else {
fseek($getid3->fp, $field_array['offset'], SEEK_SET);
$getid3->info['tiff']['ifd'][$ifd_id]['fields'][$key]['raw']['data'] = fread($getid3->fp, $field_array['raw']['length'] * $field_type_byte_length[$field_array['raw']['type']]);
}
break;
}
switch ($field_array['raw']['tag']) {
case 256: // ImageWidth
$getid3->info['video']['resolution_x'] = $field_array['value'];
break;
case 257: // ImageLength
$getid3->info['video']['resolution_y'] = $field_array['value'];
break;
case 258: // BitsPerSample
if (isset($field_array['value'])) {
$getid3->info['video']['bits_per_sample'] = $field_array['value'];
} else {
$getid3->info['video']['bits_per_sample'] = 0;
for ($i = 0; $i < $field_array['raw']['length']; $i++) {
$getid3->info['video']['bits_per_sample'] += getid3_lib::$endian2int(substr($getid3->info['tiff']['ifd'][$ifd_id]['fields'][$key]['raw']['data'], $i * $field_type_byte_length[$field_array['raw']['type']], $field_type_byte_length[$field_array['raw']['type']]));
}
}
break;
case 259: // Compression
$getid3->info['video']['codec'] = getid3_tiff::TIFFcompressionMethod($field_array['value']);
break;
case 270: // ImageDescription
case 271: // Make
case 272: // Model
case 305: // Software
case 306: // DateTime
case 315: // Artist
case 316: // HostComputer
@$getid3->info['tiff']['comments'][getid3_tiff::TIFFcommentName($field_array['raw']['tag'])][] = $getid3->info['tiff']['ifd'][$ifd_id]['fields'][$key]['raw']['data'];
break;
default:
break;
}
}
}
return true;
}
public static function TIFFcompressionMethod($id) {
static $lookup = array (
1 => 'Uncompressed',
2 => 'Huffman',
3 => 'Fax - CCITT 3',
5 => 'LZW',
32773 => 'PackBits',
);
return (isset($lookup[$id]) ? $lookup[$id] : 'unknown/invalid ('.$id.')');
}
public static function TIFFcommentName($id) {
static $lookup = array (
270 => 'imagedescription',
271 => 'make',
272 => 'model',
305 => 'software',
306 => 'datetime',
315 => 'artist',
316 => 'hostcomputer',
);
return (isset($lookup[$id]) ? $lookup[$id] : 'unknown/invalid ('.$id.')');
}
}
?>

View file

@ -0,0 +1,196 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.lib.data-hash.php |
// | getID3() library file. |
// | dependencies: NONE. |
// +----------------------------------------------------------------------+
//
// $Id: module.lib.data_hash.php,v 1.5 2006/12/03 19:28:18 ah Exp $
class getid3_lib_data_hash
{
private $getid3;
// constructer - calculate md5/sha1 data
public function __construct(getID3 $getid3, $algorithm) {
$this->getid3 = $getid3;
// Check algorithm
if (!preg_match('/^(md5|sha1)$/', $algorithm)) {
throw new getid3_exception('Unsupported algorithm, "'.$algorithm.'", in GetHashdata()');
}
//// Handle ogg vorbis files
if ((@$getid3->info['fileformat'] == 'ogg') && (@$getid3->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 ((bool)ini_get('safe_mode')) {
throw new getid3_exception('PHP running in Safe Mode - cannot make system call to vorbiscomment[.exe] needed for '.$algorithm.'_data.');
}
if (!preg_match('/^Vorbiscomment /', `vorbiscomment --version 2>&1`)) {
throw new getid3_exception('vorbiscomment[.exe] binary not found in path. UNIX: typically /usr/bin. Windows: typically c:\windows\system32.');
}
// Prevent user from aborting script
$old_abort = ignore_user_abort(true);
// Create empty file
$empty = tempnam('*', 'getID3');
touch($empty);
// Use vorbiscomment to make temp file without comments
$temp = tempnam('*', 'getID3');
$command_line = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg(realpath($getid3->filename)).' '.escapeshellarg($temp).' 2>&1';
// Error from vorbiscomment
if ($vorbis_comment_error = `$command_line`) {
throw new getid3_exception('System call to vorbiscomment[.exe] failed.');
}
// Get hash of newly created file
$hash_function = $algorithm . '_file';
$getid3->info[$algorithm.'_data'] = $hash_function($temp);
// Clean up
unlink($empty);
unlink($temp);
// Reset abort setting
ignore_user_abort($old_abort);
// Return success
return true;
}
//// Handle other file formats
// Get hash from part of file
if (@$getid3->info['avdataoffset'] || (@$getid3->info['avdataend'] && @$getid3->info['avdataend'] < $getid3->info['filesize'])) {
if ((bool)ini_get('safe_mode')) {
$getid3->warning('PHP running in Safe Mode - backtick operator not available, using slower non-system-call '.$algorithm.' algorithm.');
$hash_function = 'hash_file_partial_safe_mode';
}
else {
$hash_function = 'hash_file_partial';
}
$getid3->info[$algorithm.'_data'] = $this->$hash_function($getid3->filename, $getid3->info['avdataoffset'], $getid3->info['avdataend'], $algorithm);
}
// Get hash from whole file - use built-in md5_file() and sha1_file()
else {
$hash_function = $algorithm . '_file';
$getid3->info[$algorithm.'_data'] = $hash_function($getid3->filename);
}
}
// Return md5/sha1sum for a file from starting position to absolute end position
// Using windows system call
private function hash_file_partial($file, $offset, $end, $algorithm) {
// 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' && strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
return $this->hash_file_partial_safe_mode($file, $offset, $end, $algorithm);
}
// Check for presence of binaries and revert to safe mode if not found
if (!`head --version`) {
return $this->hash_file_partial_safe_mode($file, $offset, $end, $algorithm);
}
if (!`tail --version`) {
return $this->hash_file_partial_safe_mode($file, $offset, $end, $algorithm);
}
if (!`${algorithm}sum --version`) {
return $this->hash_file_partial_safe_mode($file, $offset, $end, $algorithm);
}
$size = $end - $offset;
$command_line = 'head -c'.$end.' '.escapeshellarg(realpath($file)).' | tail -c'.$size.' | '.$algorithm.'sum';
return substr(`$command_line`, 0, $algorithm == 'md5' ? 32 : 40);
}
// Return md5/sha1sum for a file from starting position to absolute end position
// Using slow safe_mode temp file
private function hash_file_partial_safe_mode($file, $offset, $end, $algorithm) {
// Attempt to create a temporary file in the system temp directory - invalid dirname should force to system temp dir
if (($data_filename = tempnam('*', 'getID3')) === false) {
throw new getid3_exception('Unable to create temporary file.');
}
// Init
$result = false;
// Copy parts of file
if ($fp = @fopen($file, 'rb')) {
if ($fp_data = @fopen($data_filename, 'wb')) {
fseek($fp, $offset, SEEK_SET);
$bytes_left_to_write = $end - $offset;
while (($bytes_left_to_write > 0) && ($buffer = fread($fp, getid3::FREAD_BUFFER_SIZE))) {
$bytes_written = fwrite($fp_data, $buffer, $bytes_left_to_write);
$bytes_left_to_write -= $bytes_written;
}
fclose($fp_data);
$hash_function = $algorithm . '_file';
$result = $hash_function($data_filename);
}
fclose($fp);
}
unlink($data_filename);
return $result;
}
}
?>

View file

@ -0,0 +1,415 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.lib.iconv_replacement.php |
// | getID3() library file. |
// | dependencies: NONE, required by getid3.php if no iconv() present. |
// +----------------------------------------------------------------------+
//
// $Id: module.lib.iconv_replacement.php,v 1.4 2006/11/02 10:48:02 ah Exp $
class getid3_iconv_replacement
{
public static function iconv($in_charset, $out_charset, $string) {
if ($in_charset == $out_charset) {
return $string;
}
static $supported_charsets = array (
'ISO-8859-1' => 'iso88591',
'UTF-8' => 'utf8',
'UTF-16BE' => 'utf16be',
'UTF-16LE' => 'utf16le',
'UTF-16' => 'utf16'
);
// Convert
$function_name = 'iconv_' . @$supported_charsets[$in_charset] . '_' . @$supported_charsets[$out_charset];
if (is_callable(array('getid3_iconv_replacement', $function_name))) {
return getid3_iconv_replacement::$function_name($string);
}
// Invalid charset used
if (!@$supported_charsets[$in_charset]) {
throw new getid3_exception('PHP does not have iconv() support - cannot use ' . $in_charset . ' charset.');
}
if (!@$supported_charsets[$out_charset]) {
throw new getid3_exception('PHP does not have iconv() support - cannot use ' . $out_charset . ' charset.');
}
}
public static function iconv_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_iso88591_utf8($string, $bom=false) {
if (function_exists('utf8_encode')) {
return utf8_encode($string);
}
// utf8_encode() unavailable, use getID3()'s iconv() 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 .= getid3_iconv_replacement::iconv_int_utf8($charval);
}
return $newcharstring;
}
// ISO-8859-1 => UTF-16BE
public static function iconv_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_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-16
public static function iconv_iso88591_utf16($string) {
return getid3_lib::iconv_iso88591_utf16le($string, true);
}
// UTF-8 => ISO-8859-1
public static function iconv_utf8_iso88591($string) {
if (function_exists('utf8_decode')) {
return utf8_decode($string);
}
// utf8_decode() unavailable, use getID3()'s iconv() 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_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) ? getid3_lib::BigEndian2String($charval, 2) : "\x00".'?');
}
}
return $newcharstring;
}
// UTF-8 => UTF-16LE
public static function iconv_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) ? getid3_lib::LittleEndian2String($charval, 2) : '?'."\x00");
}
}
return $newcharstring;
}
// UTF-8 => UTF-16
public static function iconv_utf8_utf16($string) {
return getid3_lib::iconv_utf8_utf16le($string, true);
}
// UTF-16BE => ISO-8859-1
public static function iconv_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 = getid3_lib::BigEndian2Int(substr($string, $i, 2));
$newcharstring .= (($charval < 256) ? chr($charval) : '?');
}
return $newcharstring;
}
// UTF-16BE => UTF-8
public static function iconv_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 = getid3_lib::BigEndian2Int(substr($string, $i, 2));
$newcharstring .= getid3_iconv_replacement::iconv_int_utf8($charval);
}
return $newcharstring;
}
// UTF-16BE => UTF-16LE
public static function iconv_utf16be_utf16le($string) {
return getid3_iconv_replacement::iconv_utf8_utf16le(getid3_iconv_replacement::iconv_utf16be_utf8($string));
}
// UTF-16BE => UTF-16
public static function iconv_utf16be_utf16($string) {
return getid3_iconv_replacement::iconv_utf8_utf16(getid3_iconv_replacement::iconv_utf16be_utf8($string));
}
// UTF-16LE => ISO-8859-1
public static function iconv_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 = getid3_lib::LittleEndian2Int(substr($string, $i, 2));
$newcharstring .= (($charval < 256) ? chr($charval) : '?');
}
return $newcharstring;
}
// UTF-16LE => UTF-8
public static function iconv_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 = getid3_lib::LittleEndian2Int(substr($string, $i, 2));
$newcharstring .= getid3_iconv_replacement::iconv_int_utf8($charval);
}
return $newcharstring;
}
// UTF-16LE => UTF-16BE
public static function iconv_utf16le_utf16be($string) {
return getid3_iconv_replacement::iconv_utf8_utf16be(getid3_iconv_replacement::iconv_utf16le_utf8($string));
}
// UTF-16LE => UTF-16
public static function iconv_utf16le_utf16($string) {
return getid3_iconv_replacement::iconv_utf8_utf16(getid3_iconv_replacement::iconv_utf16le_utf8($string));
}
// UTF-16 => ISO-8859-1
public static function iconv_utf16_iso88591($string) {
$bom = substr($string, 0, 2);
if ($bom == "\xFE\xFF") {
return getid3_lib::iconv_utf16be_iso88591(substr($string, 2));
} elseif ($bom == "\xFF\xFE") {
return getid3_lib::iconv_utf16le_iso88591(substr($string, 2));
}
return $string;
}
// UTF-16 => UTF-8
public static function iconv_utf16_utf8($string) {
$bom = substr($string, 0, 2);
if ($bom == "\xFE\xFF") {
return getid3_iconv_replacement::iconv_utf16be_utf8(substr($string, 2));
} elseif ($bom == "\xFF\xFE") {
return getid3_iconv_replacement::iconv_utf16le_utf8(substr($string, 2));
}
return $string;
}
// UTF-16 => UTF-16BE
public static function iconv_utf16_utf16be($string) {
return getid3_iconv_replacement::iconv_utf8_utf16be(getid3_iconv_replacement::iconv_utf16_utf8($string));
}
// UTF-16 => UTF-16LE
public static function iconv_utf16_utf16le($string) {
return getid3_iconv_replacement::iconv_utf8_utf16le(getid3_iconv_replacement::iconv_utf16_utf8($string));
}
}
?>

View file

@ -0,0 +1,126 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.lib.data-hash.php |
// | getID3() library file. |
// | dependencies: NONE. |
// +----------------------------------------------------------------------+
//
// $Id: module.lib.image_size.php,v 1.2 2006/11/02 10:48:02 ah Exp $
class getid3_lib_image_size
{
const GIF_SIG = "\x47\x49\x46"; // 'GIF'
const PNG_SIG = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
const JPG_SIG = "\xFF\xD8\xFF";
const JPG_SOS = "\xDA"; // Start Of Scan - image data start
const JPG_SOF0 = "\xC0"; // Start Of Frame N
const JPG_SOF1 = "\xC1"; // N indicates which compression process
const JPG_SOF2 = "\xC2"; // Only SOF0-SOF2 are now in common use
const JPG_SOF3 = "\xC3"; // NB: codes C4 and CC are *not* SOF markers
const JPG_SOF5 = "\xC5";
const JPG_SOF6 = "\xC6";
const JPG_SOF7 = "\xC7";
const JPG_SOF9 = "\xC9";
const JPG_SOF10 = "\xCA";
const JPG_SOF11 = "\xCB"; // NB: codes C4 and CC are *not* SOF markers
const JPG_SOF13 = "\xCD";
const JPG_SOF14 = "\xCE";
const JPG_SOF15 = "\xCF";
const JPG_EOI = "\xD9"; // End Of Image (end of datastream)
static public function get($img_data) {
$height = $width = $type = '';
if ((substr($img_data, 0, 3) == getid3_lib_image_size::GIF_SIG) && (strlen($img_data) > 10)) {
$dim = unpack('v2dim', substr($img_data, 6, 4));
$width = $dim['dim1'];
$height = $dim['dim2'];
$type = 1;
} elseif ((substr($img_data, 0, 8) == getid3_lib_image_size::PNG_SIG) && (strlen($img_data) > 24)) {
$dim = unpack('N2dim', substr($img_data, 16, 8));
$width = $dim['dim1'];
$height = $dim['dim2'];
$type = 3;
} elseif ((substr($img_data, 0, 3) == getid3_lib_image_size::JPG_SIG) && (strlen($img_data) > 4)) {
///////////////// JPG CHUNK SCAN ////////////////////
$img_pos = $type = 2;
$buffer = strlen($img_data) - 2;
while ($img_pos < strlen($img_data)) {
// synchronize to the marker 0xFF
$img_pos = strpos($img_data, 0xFF, $img_pos) + 1;
$marker = $img_data[$img_pos];
do {
$marker = ord($img_data[$img_pos++]);
} while ($marker == 255);
// find dimensions of block
switch (chr($marker)) {
// Grab width/height from SOF segment (these are acceptable chunk types)
case getid3_lib_image_size::JPG_SOF0:
case getid3_lib_image_size::JPG_SOF1:
case getid3_lib_image_size::JPG_SOF2:
case getid3_lib_image_size::JPG_SOF3:
case getid3_lib_image_size::JPG_SOF5:
case getid3_lib_image_size::JPG_SOF6:
case getid3_lib_image_size::JPG_SOF7:
case getid3_lib_image_size::JPG_SOF9:
case getid3_lib_image_size::JPG_SOF10:
case getid3_lib_image_size::JPG_SOF11:
case getid3_lib_image_size::JPG_SOF13:
case getid3_lib_image_size::JPG_SOF14:
case getid3_lib_image_size::JPG_SOF15:
$dim = unpack('n2dim', substr($img_data, $img_pos + 3, 4));
$height = $dim['dim1'];
$width = $dim['dim2'];
break 2; // found it so exit
case getid3_lib_image_size::JPG_EOI:
case getid3_lib_image_size::JPG_SOS:
return false;
default: // We're not interested in other markers
$skiplen = (ord($img_data[$img_pos++]) << 8) + ord($img_data[$img_pos++]) - 2;
// if the skip is more than what we've read in, read more
$buffer -= $skiplen;
if ($buffer < 512) { // if the buffer of data is too low, read more file.
return false;
}
$img_pos += $skiplen;
break;
}
}
}
return array ($width, $height, $type);
} // end function
}
?>

View file

@ -0,0 +1,450 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.misc.iso.php |
// | Module for analyzing ISO files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.misc.iso.php,v 1.3 2006/11/02 10:48:02 ah Exp $
class getid3_iso extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->info['fileformat'] = 'iso';
for ($i = 16; $i <= 19; $i++) {
fseek($getid3->fp, 2048 * $i, SEEK_SET);
$iso_header = fread($getid3->fp, 2048);
if (substr($iso_header, 1, 5) == 'CD001') {
switch (ord($iso_header{0})) {
case 1:
$getid3->info['iso']['primary_volume_descriptor']['offset'] = 2048 * $i;
$this->ParsePrimaryVolumeDescriptor($iso_header);
break;
case 2:
$getid3->info['iso']['supplementary_volume_descriptor']['offset'] = 2048 * $i;
$this->ParseSupplementaryVolumeDescriptor($iso_header);
break;
default:
// skip
break;
}
}
}
$this->ParsePathTable();
$getid3->info['iso']['files'] = array ();
foreach ($getid3->info['iso']['path_table']['directories'] as $directory_num => $directory_data) {
$getid3->info['iso']['directories'][$directory_num] = $this->ParseDirectoryRecord($directory_data);
}
return true;
}
private function ParsePrimaryVolumeDescriptor(&$iso_header) {
$getid3 = $this->getid3;
// 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
$getid3->info['iso']['primary_volume_descriptor']['raw'] = array ();
$info_iso_primaryVD = &$getid3->info['iso']['primary_volume_descriptor'];
$info_iso_primaryVD_raw = &$info_iso_primaryVD['raw'];
$info_iso_primaryVD_raw['volume_descriptor_type'] = getid3_lib::LittleEndian2Int(substr($iso_header, 0, 1));
$info_iso_primaryVD_raw['standard_identifier'] = substr($iso_header, 1, 5);
if ($info_iso_primaryVD_raw['standard_identifier'] != 'CD001') {
throw new getid3_exception('Expected "CD001" at offset ('.($info_iso_primaryVD['offset'] + 1).'), found "'.$info_iso_primaryVD_raw['standard_identifier'].'" instead');
}
getid3_lib::ReadSequence('LittleEndian2Int', $info_iso_primaryVD_raw, $iso_header, 6,
array (
'volume_descriptor_version' => 1,
'IGNORE-unused_1' => 1,
'system_identifier' => -32, // string
'volume_identifier' => -32, // string
'IGNORE-unused_2' => 8,
'volume_space_size' => 4,
'IGNORE-1' => 4,
'IGNORE-unused_3' => 32,
'volume_set_size' => 2,
'IGNORE-2' => 2,
'volume_sequence_number' => 2,
'IGNORE-3' => 2,
'logical_block_size' => 2,
'IGNORE-4' => 2,
'path_table_size' => 4,
'IGNORE-5' => 4,
'path_table_l_location' => 2,
'IGNORE-6' => 2,
'path_table_l_opt_location' => 2,
'IGNORE-7' => 2,
'path_table_m_location' => 2,
'IGNORE-8' => 2,
'path_table_m_opt_location' => 2,
'IGNORE-9' => 2,
'root_directory_record' => -34, // string
'volume_set_identifier' => -128, // string
'publisher_identifier' => -128, // string
'data_preparer_identifier' => -128, // string
'application_identifier' => -128, // string
'copyright_file_identifier' => -37, // string
'abstract_file_identifier' => -37, // string
'bibliographic_file_identifier' => -37, // string
'volume_creation_date_time' => -17, // string
'volume_modification_date_time' => -17, // string
'volume_expiration_date_time' => -17, // string
'volume_effective_date_time' => -17, // string
'file_structure_version' => 1,
'IGNORE-unused_4' => 1,
'application_data' => -512 // string
)
);
$info_iso_primaryVD['system_identifier'] = trim($info_iso_primaryVD_raw['system_identifier']);
$info_iso_primaryVD['volume_identifier'] = trim($info_iso_primaryVD_raw['volume_identifier']);
$info_iso_primaryVD['volume_set_identifier'] = trim($info_iso_primaryVD_raw['volume_set_identifier']);
$info_iso_primaryVD['publisher_identifier'] = trim($info_iso_primaryVD_raw['publisher_identifier']);
$info_iso_primaryVD['data_preparer_identifier'] = trim($info_iso_primaryVD_raw['data_preparer_identifier']);
$info_iso_primaryVD['application_identifier'] = trim($info_iso_primaryVD_raw['application_identifier']);
$info_iso_primaryVD['copyright_file_identifier'] = trim($info_iso_primaryVD_raw['copyright_file_identifier']);
$info_iso_primaryVD['abstract_file_identifier'] = trim($info_iso_primaryVD_raw['abstract_file_identifier']);
$info_iso_primaryVD['bibliographic_file_identifier'] = trim($info_iso_primaryVD_raw['bibliographic_file_identifier']);
$info_iso_primaryVD['volume_creation_date_time'] = getid3_iso::ISOtimeText2UNIXtime($info_iso_primaryVD_raw['volume_creation_date_time']);
$info_iso_primaryVD['volume_modification_date_time'] = getid3_iso::ISOtimeText2UNIXtime($info_iso_primaryVD_raw['volume_modification_date_time']);
$info_iso_primaryVD['volume_expiration_date_time'] = getid3_iso::ISOtimeText2UNIXtime($info_iso_primaryVD_raw['volume_expiration_date_time']);
$info_iso_primaryVD['volume_effective_date_time'] = getid3_iso::ISOtimeText2UNIXtime($info_iso_primaryVD_raw['volume_effective_date_time']);
if (($info_iso_primaryVD_raw['volume_space_size'] * 2048) > $getid3->info['filesize']) {
throw new getid3_exception('Volume Space Size ('.($info_iso_primaryVD_raw['volume_space_size'] * 2048).' bytes) is larger than the file size ('.$getid3->info['filesize'].' bytes) (truncated file?)');
}
return true;
}
private function ParseSupplementaryVolumeDescriptor(&$iso_header) {
$getid3 = $this->getid3;
// ISO integer values are stored Both-Endian format!!
// ie 12345 == 0x3039 is stored as $39 $30 $30 $39 in a 4-byte field
$getid3->info['iso']['supplementary_volume_descriptor']['raw'] = array ();
$info_iso_supplementaryVD = &$getid3->info['iso']['supplementary_volume_descriptor'];
$info_iso_supplementaryVD_raw = &$info_iso_supplementaryVD['raw'];
$info_iso_supplementaryVD_raw['volume_descriptor_type'] = getid3_lib::LittleEndian2Int(substr($iso_header, 0, 1));
$info_iso_supplementaryVD_raw['standard_identifier'] = substr($iso_header, 1, 5);
if ($info_iso_supplementaryVD_raw['standard_identifier'] != 'CD001') {
throw new getid3_exception('Expected "CD001" at offset ('.($info_iso_supplementaryVD['offset'] + 1).'), found "'.$info_iso_supplementaryVD_raw['standard_identifier'].'" instead');
}
getid3_lib::ReadSequence('LittleEndian2Int', $info_iso_supplementaryVD_raw, $iso_header, 6,
array (
'volume_descriptor_version' => 1,
'IGNORE-unused_1' => -1,
'system_identifier' => -32,
'volume_identifier' => -32,
'IGNORE-unused_2' => -8,
'volume_space_size' => 4,
'IGNORE-1' => 4,
'IGNORE-unused_3' => -32,
'volume_set_size' => 2,
'IGNORE-2' => 2,
'volume_sequence_number' => 2,
'IGNORE-3' => 2,
'logical_block_size' => 2,
'IGNORE-4' => 2,
'path_table_size' => 4,
'IGNORE-5' => 4,
'path_table_l_location' => 2,
'IGNORE-6' => 2,
'path_table_l_opt_location' => 2,
'IGNORE-7' => 2,
'path_table_m_location' => 2,
'IGNORE-8' => 2,
'path_table_m_opt_location' => 2,
'IGNORE-9' => 2,
'root_directory_record' => -34,
'volume_set_identifier' => -128,
'publisher_identifier' => -128,
'data_preparer_identifier' => -128,
'application_identifier' => -128,
'copyright_file_identifier' => -37,
'abstract_file_identifier' => -37,
'bibliographic_file_identifier' => -37,
'volume_creation_date_time' => -17,
'volume_modification_date_time' => -17,
'volume_expiration_date_time' => -17,
'volume_effective_date_time' => -17,
'file_structure_version' => 1,
'IGNORE-unused_4' => 1,
'application_data' => -512
)
);
$info_iso_supplementaryVD['system_identifier'] = trim($info_iso_supplementaryVD_raw['system_identifier']);
$info_iso_supplementaryVD['volume_identifier'] = trim($info_iso_supplementaryVD_raw['volume_identifier']);
$info_iso_supplementaryVD['volume_set_identifier'] = trim($info_iso_supplementaryVD_raw['volume_set_identifier']);
$info_iso_supplementaryVD['publisher_identifier'] = trim($info_iso_supplementaryVD_raw['publisher_identifier']);
$info_iso_supplementaryVD['data_preparer_identifier'] = trim($info_iso_supplementaryVD_raw['data_preparer_identifier']);
$info_iso_supplementaryVD['application_identifier'] = trim($info_iso_supplementaryVD_raw['application_identifier']);
$info_iso_supplementaryVD['copyright_file_identifier'] = trim($info_iso_supplementaryVD_raw['copyright_file_identifier']);
$info_iso_supplementaryVD['abstract_file_identifier'] = trim($info_iso_supplementaryVD_raw['abstract_file_identifier']);
$info_iso_supplementaryVD['bibliographic_file_identifier'] = trim($info_iso_supplementaryVD_raw['bibliographic_file_identifier']);
$info_iso_supplementaryVD['volume_creation_date_time'] = getid3_iso::ISOtimeText2UNIXtime($info_iso_supplementaryVD_raw['volume_creation_date_time']);
$info_iso_supplementaryVD['volume_modification_date_time'] = getid3_iso::ISOtimeText2UNIXtime($info_iso_supplementaryVD_raw['volume_modification_date_time']);
$info_iso_supplementaryVD['volume_expiration_date_time'] = getid3_iso::ISOtimeText2UNIXtime($info_iso_supplementaryVD_raw['volume_expiration_date_time']);
$info_iso_supplementaryVD['volume_effective_date_time'] = getid3_iso::ISOtimeText2UNIXtime($info_iso_supplementaryVD_raw['volume_effective_date_time']);
if (($info_iso_supplementaryVD_raw['volume_space_size'] * $info_iso_supplementaryVD_raw['logical_block_size']) > $getid3->info['filesize']) {
throw new getid3_exception('Volume Space Size ('.($info_iso_supplementaryVD_raw['volume_space_size'] * $info_iso_supplementaryVD_raw['logical_block_size']).' bytes) is larger than the file size ('.$getid3->info['filesize'].' bytes) (truncated file?)');
}
return true;
}
private function ParsePathTable() {
$getid3 = $this->getid3;
if (!isset($getid3->info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location']) && !isset($getid3->info['iso']['primary_volume_descriptor']['raw']['path_table_l_location'])) {
return false;
}
if (isset($getid3->info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location'])) {
$path_table_location = $getid3->info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location'];
$path_table_size = $getid3->info['iso']['supplementary_volume_descriptor']['raw']['path_table_size'];
$text_encoding = 'UTF-16BE'; // Big-Endian Unicode
}
else {
$path_table_location = $getid3->info['iso']['primary_volume_descriptor']['raw']['path_table_l_location'];
$path_table_size = $getid3->info['iso']['primary_volume_descriptor']['raw']['path_table_size'];
$text_encoding = 'ISO-8859-1'; // Latin-1
}
if (($path_table_location * 2048) > $getid3->info['filesize']) {
throw new getid3_exception('Path Table Location specifies an offset ('.($path_table_location * 2048).') beyond the end-of-file ('.$getid3->info['filesize'].')');
}
$getid3->info['iso']['path_table']['offset'] = $path_table_location * 2048;
fseek($getid3->fp, $getid3->info['iso']['path_table']['offset'], SEEK_SET);
$getid3->info['iso']['path_table']['raw'] = fread($getid3->fp, $path_table_size);
$offset = 0;
$pathcounter = 1;
while ($offset < $path_table_size) {
$getid3->info['iso']['path_table']['directories'][$pathcounter] = array ();
$info_iso_pathtable_directories_current = &$getid3->info['iso']['path_table']['directories'][$pathcounter];
getid3_lib::ReadSequence('LittleEndian2Int', $info_iso_pathtable_directories_current, $getid3->info['iso']['path_table']['raw'], $offset,
array (
'length' => 1,
'extended_length' => 1,
'location_logical' => 4,
'parent_directory' => 2,
)
);
$info_iso_pathtable_directories_current['name'] = substr($getid3->info['iso']['path_table']['raw'], $offset+8, $info_iso_pathtable_directories_current['length']);
$offset += 8 + $info_iso_pathtable_directories_current['length'] + ($info_iso_pathtable_directories_current['length'] % 2);
$info_iso_pathtable_directories_current['name_ascii'] = $getid3->iconv($text_encoding, $getid3->encoding, $info_iso_pathtable_directories_current['name'], true);
$info_iso_pathtable_directories_current['location_bytes'] = $info_iso_pathtable_directories_current['location_logical'] * 2048;
if ($pathcounter == 1) {
$info_iso_pathtable_directories_current['full_path'] = '/';
}
else {
$info_iso_pathtable_directories_current['full_path'] = $getid3->info['iso']['path_table']['directories'][$info_iso_pathtable_directories_current['parent_directory']]['full_path'].$info_iso_pathtable_directories_current['name_ascii'].'/';
}
$full_path_array[] = $info_iso_pathtable_directories_current['full_path'];
$pathcounter++;
}
return true;
}
private function ParseDirectoryRecord($directory_data) {
$getid3 = $this->getid3;
$text_encoding = isset($getid3->info['iso']['supplementary_volume_descriptor']) ? 'UTF-16BE' : 'ISO-8859-1';
fseek($getid3->fp, $directory_data['location_bytes'], SEEK_SET);
$directory_record_data = fread($getid3->fp, 1);
while (ord($directory_record_data{0}) > 33) {
$directory_record_data .= fread($getid3->fp, ord($directory_record_data{0}) - 1);
$this_directory_record = array ();
$this_directory_record['raw'] = array ();
$this_directory_record_raw = &$this_directory_record['raw'];
getid3_lib::ReadSequence('LittleEndian2Int', $this_directory_record_raw, $directory_record_data, 0,
array (
'length' => 1,
'extended_attribute_length' => 1,
'offset_logical' => 4,
'IGNORE-1' => 4,
'filesize' => 4,
'IGNORE-2' => 4,
'recording_date_time' => -7,
'file_flags' => 1,
'file_unit_size' => 1,
'interleave_gap_size' => 1,
'volume_sequence_number' => 2,
'IGNORE-3' => 2,
'file_identifier_length' => 1,
)
);
$this_directory_record_raw['file_identifier'] = substr($directory_record_data, 33, $this_directory_record_raw['file_identifier_length']);
$this_directory_record['file_identifier_ascii'] = $getid3->iconv($text_encoding, $getid3->encoding, $this_directory_record_raw['file_identifier'], true);
$this_directory_record['filesize'] = $this_directory_record_raw['filesize'];
$this_directory_record['offset_bytes'] = $this_directory_record_raw['offset_logical'] * 2048;
$this_directory_record['file_flags']['hidden'] = (bool)($this_directory_record_raw['file_flags'] & 0x01);
$this_directory_record['file_flags']['directory'] = (bool)($this_directory_record_raw['file_flags'] & 0x02);
$this_directory_record['file_flags']['associated'] = (bool)($this_directory_record_raw['file_flags'] & 0x04);
$this_directory_record['file_flags']['extended'] = (bool)($this_directory_record_raw['file_flags'] & 0x08);
$this_directory_record['file_flags']['permissions'] = (bool)($this_directory_record_raw['file_flags'] & 0x10);
$this_directory_record['file_flags']['multiple'] = (bool)($this_directory_record_raw['file_flags'] & 0x80);
$this_directory_record['recording_timestamp'] = getid3_iso::ISOtime2UNIXtime($this_directory_record_raw['recording_date_time']);
if ($this_directory_record['file_flags']['directory']) {
$this_directory_record['filename'] = $directory_data['full_path'];
}
else {
$this_directory_record['filename'] = $directory_data['full_path'].getid3_iso::ISOstripFilenameVersion($this_directory_record['file_identifier_ascii']);
$getid3->info['iso']['files'] = getid3_iso::array_merge_clobber($getid3->info['iso']['files'], getid3_iso::CreateDeepArray($this_directory_record['filename'], '/', $this_directory_record['filesize']));
}
$directory_record[] = $this_directory_record;
$directory_record_data = fread($getid3->fp, 1);
}
return $directory_record;
}
public static function ISOstripFilenameVersion($iso_filename) {
// convert 'filename.ext;1' to 'filename.ext'
if (!strstr($iso_filename, ';')) {
return $iso_filename;
}
return substr($iso_filename, 0, strpos($iso_filename, ';'));
}
public static function ISOtimeText2UNIXtime($iso_time) {
if (!(int)substr($iso_time, 0, 4)) {
return false;
}
return gmmktime((int)substr($iso_time, 8, 2), (int)substr($iso_time, 10, 2), (int)substr($iso_time, 12, 2), (int)substr($iso_time, 4, 2), (int)substr($iso_time, 6, 2), (int)substr($iso_time, 0, 4));
}
public static function ISOtime2UNIXtime($iso_time) {
// 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)
return gmmktime(ord($iso_time[3]), ord($iso_time[4]), ord($iso_time[5]), ord($iso_time[1]), ord($iso_time[2]), ord($iso_time[0]) + 1900);
}
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] = getid3_iso::array_merge_clobber($newarray[$key], $val);
} else {
$newarray[$key] = $val;
}
}
return $newarray;
}
public static function CreateDeepArray($array_path, $separator, $value) {
// assigns $value to a nested array path:
// $foo = getid3_lib::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 ($array_path{0} == $separator) {
$array_path = substr($array_path, 1);
}
if (($pos = strpos($array_path, $separator)) !== false) {
return array (substr($array_path, 0, $pos) => getid3_iso::CreateDeepArray(substr($array_path, $pos + 1), $separator, $value));
}
return array ($array_path => $value);
}
}
?>

View file

@ -0,0 +1,312 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.tag.apetag.php |
// | module for analyzing APE tags |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.tag.apetag.php,v 1.5 2006/11/16 14:05:21 ah Exp $
class getid3_apetag extends getid3_handler
{
/*
ID3v1_TAG_SIZE = 128;
APETAG_HEADER_SIZE = 32;
LYRICS3_TAG_SIZE = 10;
*/
public $option_override_end_offset = 0;
public function Analyze() {
$getid3 = $this->getid3;
if ($this->option_override_end_offset == 0) {
fseek($getid3->fp, 0 - 170, SEEK_END); // 170 = ID3v1_TAG_SIZE + APETAG_HEADER_SIZE + LYRICS3_TAG_SIZE
$apetag_footer_id3v1 = fread($getid3->fp, 170); // 170 = ID3v1_TAG_SIZE + APETAG_HEADER_SIZE + LYRICS3_TAG_SIZE
// APE tag found before ID3v1
if (substr($apetag_footer_id3v1, strlen($apetag_footer_id3v1) - 160, 8) == 'APETAGEX') { // 160 = ID3v1_TAG_SIZE + APETAG_HEADER_SIZE
$getid3->info['ape']['tag_offset_end'] = filesize($getid3->filename) - 128; // 128 = ID3v1_TAG_SIZE
}
// APE tag found, no ID3v1
elseif (substr($apetag_footer_id3v1, strlen($apetag_footer_id3v1) - 32, 8) == 'APETAGEX') { // 32 = APETAG_HEADER_SIZE
$getid3->info['ape']['tag_offset_end'] = filesize($getid3->filename);
}
}
else {
fseek($getid3->fp, $this->option_override_end_offset - 32, SEEK_SET); // 32 = APETAG_HEADER_SIZE
if (fread($getid3->fp, 8) == 'APETAGEX') {
$getid3->info['ape']['tag_offset_end'] = $this->option_override_end_offset;
}
}
// APE tag not found
if (!@$getid3->info['ape']['tag_offset_end']) {
return false;
}
// Shortcut
$info_ape = &$getid3->info['ape'];
// Read and parse footer
fseek($getid3->fp, $info_ape['tag_offset_end'] - 32, SEEK_SET); // 32 = APETAG_HEADER_SIZE
$apetag_footer_data = fread($getid3->fp, 32);
if (!($this->ParseAPEHeaderFooter($apetag_footer_data, $info_ape['footer']))) {
throw new getid3_exception('Error parsing APE footer at offset '.$info_ape['tag_offset_end']);
}
if (isset($info_ape['footer']['flags']['header']) && $info_ape['footer']['flags']['header']) {
fseek($getid3->fp, $info_ape['tag_offset_end'] - $info_ape['footer']['raw']['tagsize'] - 32, SEEK_SET);
$info_ape['tag_offset_start'] = ftell($getid3->fp);
$apetag_data = fread($getid3->fp, $info_ape['footer']['raw']['tagsize'] + 32);
}
else {
$info_ape['tag_offset_start'] = $info_ape['tag_offset_end'] - $info_ape['footer']['raw']['tagsize'];
fseek($getid3->fp, $info_ape['tag_offset_start'], SEEK_SET);
$apetag_data = fread($getid3->fp, $info_ape['footer']['raw']['tagsize']);
}
$getid3->info['avdataend'] = $info_ape['tag_offset_start'];
if (isset($getid3->info['id3v1']['tag_offset_start']) && ($getid3->info['id3v1']['tag_offset_start'] < $info_ape['tag_offset_end'])) {
$getid3->warning('ID3v1 tag information ignored since it appears to be a false synch in APEtag data');
unset($getid3->info['id3v1']);
}
$offset = 0;
if (isset($info_ape['footer']['flags']['header']) && $info_ape['footer']['flags']['header']) {
if (!$this->ParseAPEHeaderFooter(substr($apetag_data, 0, 32), $info_ape['header'])) {
throw new getid3_exception('Error parsing APE header at offset '.$info_ape['tag_offset_start']);
}
$offset = 32;
}
// Shortcut
$getid3->info['replay_gain'] = array ();
$info_replaygain = &$getid3->info['replay_gain'];
for ($i = 0; $i < $info_ape['footer']['raw']['tag_items']; $i++) {
$value_size = getid3_lib::LittleEndian2Int(substr($apetag_data, $offset, 4));
$item_flags = getid3_lib::LittleEndian2Int(substr($apetag_data, $offset + 4, 4));
$offset += 8;
if (strstr(substr($apetag_data, $offset), "\x00") === false) {
throw new getid3_exception('Cannot find null-byte (0x00) seperator between ItemKey #'.$i.' and value. ItemKey starts ' . $offset . ' bytes into the APE tag, at file offset '.($info_ape['tag_offset_start'] + $offset));
}
$item_key_length = strpos($apetag_data, "\x00", $offset) - $offset;
$item_key = strtolower(substr($apetag_data, $offset, $item_key_length));
// Shortcut
$info_ape['items'][$item_key] = array ();
$info_ape_items_current = &$info_ape['items'][$item_key];
$offset += $item_key_length + 1; // skip 0x00 terminator
$info_ape_items_current['data'] = substr($apetag_data, $offset, $value_size);
$offset += $value_size;
$info_ape_items_current['flags'] = $this->ParseAPEtagFlags($item_flags);
switch ($info_ape_items_current['flags']['item_contents_raw']) {
case 0: // UTF-8
case 3: // Locator (URL, filename, etc), UTF-8 encoded
$info_ape_items_current['data'] = explode("\x00", trim($info_ape_items_current['data']));
break;
default: // binary data
break;
}
switch (strtolower($item_key)) {
case 'replaygain_track_gain':
$info_replaygain['track']['adjustment'] = (float)str_replace(',', '.', $info_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
$info_replaygain['track']['originator'] = 'unspecified';
break;
case 'replaygain_track_peak':
$info_replaygain['track']['peak'] = (float)str_replace(',', '.', $info_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
$info_replaygain['track']['originator'] = 'unspecified';
if ($info_replaygain['track']['peak'] <= 0) {
$getid3->warning('ReplayGain Track peak from APEtag appears invalid: '.$info_replaygain['track']['peak'].' (original value = "'.$info_ape_items_current['data'][0].'")');
}
break;
case 'replaygain_album_gain':
$info_replaygain['album']['adjustment'] = (float)str_replace(',', '.', $info_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
$info_replaygain['album']['originator'] = 'unspecified';
break;
case 'replaygain_album_peak':
$info_replaygain['album']['peak'] = (float)str_replace(',', '.', $info_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
$info_replaygain['album']['originator'] = 'unspecified';
if ($info_replaygain['album']['peak'] <= 0) {
$getid3->warning('ReplayGain Album peak from APEtag appears invalid: '.$info_replaygain['album']['peak'].' (original value = "'.$info_ape_items_current['data'][0].'")');
}
break;
case 'mp3gain_undo':
list($mp3gain_undo_left, $mp3gain_undo_right, $mp3gain_undo_wrap) = explode(',', $info_ape_items_current['data'][0]);
$info_replaygain['mp3gain']['undo_left'] = intval($mp3gain_undo_left);
$info_replaygain['mp3gain']['undo_right'] = intval($mp3gain_undo_right);
$info_replaygain['mp3gain']['undo_wrap'] = (($mp3gain_undo_wrap == 'Y') ? true : false);
break;
case 'mp3gain_minmax':
list($mp3gain_globalgain_min, $mp3gain_globalgain_max) = explode(',', $info_ape_items_current['data'][0]);
$info_replaygain['mp3gain']['globalgain_track_min'] = intval($mp3gain_globalgain_min);
$info_replaygain['mp3gain']['globalgain_track_max'] = intval($mp3gain_globalgain_max);
break;
case 'mp3gain_album_minmax':
list($mp3gain_globalgain_album_min, $mp3gain_globalgain_album_max) = explode(',', $info_ape_items_current['data'][0]);
$info_replaygain['mp3gain']['globalgain_album_min'] = intval($mp3gain_globalgain_album_min);
$info_replaygain['mp3gain']['globalgain_album_max'] = intval($mp3gain_globalgain_album_max);
break;
case 'tracknumber':
foreach ($info_ape_items_current['data'] as $comment) {
$info_ape['comments']['track'][] = $comment;
}
break;
default:
foreach ($info_ape_items_current['data'] as $comment) {
$info_ape['comments'][strtolower($item_key)][] = $comment;
}
break;
}
}
if (empty($info_replaygain)) {
unset($getid3->info['replay_gain']);
}
return true;
}
protected function ParseAPEheaderFooter($data, &$target) {
// http://www.uni-jena.de/~pfk/mpp/sv8/apeheader.html
if (substr($data, 0, 8) != 'APETAGEX') {
return false;
}
// shortcut
$target['raw'] = array ();
$target_raw = &$target['raw'];
$target_raw['footer_tag'] = 'APETAGEX';
getid3_lib::ReadSequence("LittleEndian2Int", $target_raw, $data, 8,
array (
'version' => 4,
'tagsize' => 4,
'tag_items' => 4,
'global_flags' => 4
)
);
$target_raw['reserved'] = substr($data, 24, 8);
$target['tag_version'] = $target_raw['version'] / 1000;
if ($target['tag_version'] >= 2) {
$target['flags'] = $this->ParseAPEtagFlags($target_raw['global_flags']);
}
return true;
}
protected function ParseAPEtagFlags($raw_flag_int) {
// "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://www.uni-jena.de/~pfk/mpp/sv8/apetagflags.html
$target['header'] = (bool) ($raw_flag_int & 0x80000000);
$target['footer'] = (bool) ($raw_flag_int & 0x40000000);
$target['this_is_header'] = (bool) ($raw_flag_int & 0x20000000);
$target['item_contents_raw'] = ($raw_flag_int & 0x00000006) >> 1;
$target['read_only'] = (bool) ($raw_flag_int & 0x00000001);
$target['item_contents'] = getid3_apetag::APEcontentTypeFlagLookup($target['item_contents_raw']);
return $target;
}
public static function APEcontentTypeFlagLookup($content_type_id) {
static $lookup = array (
0 => 'utf-8',
1 => 'binary',
2 => 'external',
3 => 'reserved'
);
return (isset($lookup[$content_type_id]) ? $lookup[$content_type_id] : 'invalid');
}
public static function APEtagItemIsUTF8Lookup($item_key) {
static $lookup = 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($item_key), $lookup);
}
}
?>

View file

@ -0,0 +1,324 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.tag.id3v1.php |
// | module for analyzing ID3v1 tags |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.tag.id3v1.php,v 1.6 2006/11/16 16:19:52 ah Exp $
class getid3_id3v1 extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
fseek($getid3->fp, -256, SEEK_END);
$pre_id3v1 = fread($getid3->fp, 128);
$id3v1_tag = fread($getid3->fp, 128);
if (substr($id3v1_tag, 0, 3) == 'TAG') {
$getid3->info['avdataend'] -= 128;
// Shortcut
$getid3->info['id3v1'] = array ();
$info_id3v1 = &$getid3->info['id3v1'];
$info_id3v1['title'] = getid3_id3v1::cutfield(substr($id3v1_tag, 3, 30));
$info_id3v1['artist'] = getid3_id3v1::cutfield(substr($id3v1_tag, 33, 30));
$info_id3v1['album'] = getid3_id3v1::cutfield(substr($id3v1_tag, 63, 30));
$info_id3v1['year'] = getid3_id3v1::cutfield(substr($id3v1_tag, 93, 4));
$info_id3v1['comment'] = substr($id3v1_tag, 97, 30); // can't remove nulls yet, track detection depends on them
$info_id3v1['genreid'] = ord(substr($id3v1_tag, 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 (($id3v1_tag{125} === "\x00") && ($id3v1_tag{126} !== "\x00")) {
$info_id3v1['track'] = ord(substr($info_id3v1['comment'], 29, 1));
$info_id3v1['comment'] = substr($info_id3v1['comment'], 0, 28);
}
$info_id3v1['comment'] = getid3_id3v1::cutfield($info_id3v1['comment']);
$info_id3v1['genre'] = getid3_id3v1::LookupGenreName($info_id3v1['genreid']);
if (!empty($info_id3v1['genre'])) {
unset($info_id3v1['genreid']);
}
if (empty($info_id3v1['genre']) || (@$info_id3v1['genre'] == 'Unknown')) {
unset($info_id3v1['genre']);
}
foreach ($info_id3v1 as $key => $value) {
$key != 'comments' and $info_id3v1['comments'][$key][0] = $value;
}
$info_id3v1['tag_offset_end'] = filesize($getid3->filename);
$info_id3v1['tag_offset_start'] = $info_id3v1['tag_offset_end'] - 128;
}
if (substr($pre_id3v1, 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($pre_id3v1, 96, 8) == 'APETAGEX') {
// an APE tag footer was found before the last ID3v1, assume false "TAG" synch
} elseif (substr($pre_id3v1, 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
$getid3->warning('Duplicate ID3v1 tag detected - this has been known to happen with iTunes.');
$getid3->info['avdataend'] -= 128;
}
}
return true;
}
public static function cutfield($str) {
return trim(substr($str, 0, strcspn($str, "\x00")));
}
public static function ArrayOfGenres($allow_SCMPX_extended=false) {
static $lookup = 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 => 'Trash Metal',
145 => 'Anime',
146 => 'JPop',
147 => 'Synthpop',
255 => 'Unknown',
'CR' => 'Cover',
'RX' => 'Remix'
);
static $lookupSCMPX = array ();
if ($allow_SCMPX_extended && empty($lookupSCMPX)) {
$lookupSCMPX = $lookup;
// 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"
$lookupSCMPX[240] = 'Sacred';
$lookupSCMPX[241] = 'Northern Europe';
$lookupSCMPX[242] = 'Irish & Scottish';
$lookupSCMPX[243] = 'Scotland';
$lookupSCMPX[244] = 'Ethnic Europe';
$lookupSCMPX[245] = 'Enka';
$lookupSCMPX[246] = 'Children\'s Song';
$lookupSCMPX[247] = 'Japanese Sky';
$lookupSCMPX[248] = 'Japanese Heavy Rock';
$lookupSCMPX[249] = 'Japanese Doom Rock';
$lookupSCMPX[250] = 'Japanese J-POP';
$lookupSCMPX[251] = 'Japanese Seiyu';
$lookupSCMPX[252] = 'Japanese Ambient Techno';
$lookupSCMPX[253] = 'Japanese Moemoe';
$lookupSCMPX[254] = 'Japanese Tokusatsu';
//$lookupSCMPX[255] = 'Japanese Anime';
}
return ($allow_SCMPX_extended ? $lookupSCMPX : $lookup);
}
public static function LookupGenreName($genre_id, $allow_SCMPX_extended=true) {
switch ($genre_id) {
case 'RX':
case 'CR':
break;
default:
$genre_id = intval($genre_id); // to handle 3 or '3' or '03'
break;
}
$lookup = getid3_id3v1::ArrayOfGenres($allow_SCMPX_extended);
return (isset($lookup[$genre_id]) ? $lookup[$genre_id] : false);
}
public static function LookupGenreID($genre, $allow_SCMPX_extended=false) {
$lookup = getid3_id3v1::ArrayOfGenres($allow_SCMPX_extended);
$lower_case_no_space_search_term = strtolower(str_replace(' ', '', $genre));
foreach ($lookup as $key => $value) {
foreach ($lookup as $key => $value) {
if (strtolower(str_replace(' ', '', $value)) == $lower_case_no_space_search_term) {
return $key;
}
}
return false;
}
return (isset($lookup[$genre_id]) ? $lookup[$genre_id] : false);
}
}
?>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,270 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | module.tag.lyrics3.php |
// | module for analyzing Lyrics3 tags |
// | dependencies: module.tag.apetag.php (optional) |
// +----------------------------------------------------------------------+
//
// $Id: module.tag.lyrics3.php,v 1.5 2006/11/16 22:04:23 ah Exp $
class getid3_lyrics3 extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
fseek($getid3->fp, (0 - 128 - 9 - 6), SEEK_END); // end - ID3v1 - LYRICSEND - [Lyrics3size]
$lyrics3_id3v1 = fread($getid3->fp, 128 + 9 + 6);
$lyrics3_lsz = substr($lyrics3_id3v1, 0, 6); // Lyrics3size
$lyrics3_end = substr($lyrics3_id3v1, 6, 9); // LYRICSEND or LYRICS200
$id3v1_tag = substr($lyrics3_id3v1, 15, 128); // ID3v1
// Lyrics3v1, ID3v1, no APE
if ($lyrics3_end == 'LYRICSEND') {
$lyrics3_size = 5100;
$lyrics3_offset = filesize($getid3->filename) - 128 - $lyrics3_size;
$lyrics3_version = 1;
}
// Lyrics3v2, ID3v1, no APE
elseif ($lyrics3_end == 'LYRICS200') {
// LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200'
$lyrics3_size = $lyrics3_lsz + 6 + strlen('LYRICS200');
$lyrics3_offset = filesize($getid3->filename) - 128 - $lyrics3_size;
$lyrics3_version = 2;
}
// Lyrics3v1, no ID3v1, no APE
elseif (substr(strrev($lyrics3_id3v1), 0, 9) == 'DNESCIRYL') { // strrev('LYRICSEND') = 'DNESCIRYL'
$lyrics3_size = 5100;
$lyrics3_offset = filesize($getid3->filename) - $lyrics3_size;
$lyrics3_version = 1;
$lyrics3_offset = filesize($getid3->filename) - $lyrics3_size;
}
// Lyrics3v2, no ID3v1, no APE
elseif (substr(strrev($lyrics3_id3v1), 0, 9) == '002SCIRYL') { // strrev('LYRICS200') = '002SCIRYL'
$lyrics3_size = strrev(substr(strrev($lyrics3_id3v1), 9, 6)) + 15; // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200' // 15 = 6 + strlen('LYRICS200')
$lyrics3_offset = filesize($getid3->filename) - $lyrics3_size;
$lyrics3_version = 2;
}
elseif (isset($getid3->info['ape']['tag_offset_start']) && ($getid3->info['ape']['tag_offset_start'] > 15)) {
fseek($getid3->fp, $getid3->info['ape']['tag_offset_start'] - 15, SEEK_SET);
$lyrics3_lsz = fread($getid3->fp, 6);
$lyrics3_end = fread($getid3->fp, 9);
// Lyrics3v1, APE, maybe ID3v1
if ($lyrics3_end == 'LYRICSEND') {
$lyrics3_size = 5100;
$lyrics3_offset = $getid3->info['ape']['tag_offset_start'] - $lyrics3_size;
$getid3->info['avdataend'] = $lyrics3_offset;
$lyrics3_version = 1;
$getid3->warning('APE tag located after Lyrics3, will probably break Lyrics3 compatability');
}
// Lyrics3v2, APE, maybe ID3v1
elseif ($lyrics3_end == 'LYRICS200') {
$lyrics3_size = $lyrics3_lsz + 15; // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200'
$lyrics3_offset = $getid3->info['ape']['tag_offset_start'] - $lyrics3_size;
$lyrics3_version = 2;
$getid3->warning('APE tag located after Lyrics3, will probably break Lyrics3 compatability');
}
}
//// GetLyrics3Data()
if (isset($lyrics3_offset)) {
$getid3->info['avdataend'] = $lyrics3_offset;
if ($lyrics3_size <= 0) {
return false;
}
fseek($getid3->fp, $lyrics3_offset, SEEK_SET);
$raw_data = fread($getid3->fp, $lyrics3_size);
if (substr($raw_data, 0, 11) != 'LYRICSBEGIN') {
if (strpos($raw_data, 'LYRICSBEGIN') !== false) {
$getid3->warning('"LYRICSBEGIN" expected at '.$lyrics3_offset.' but actually found at '.($lyrics3_offset + strpos($raw_data, 'LYRICSBEGIN')).' - this is invalid for Lyrics3 v'.$lyrics3_version);
$getid3->info['avdataend'] = $lyrics3_offset + strpos($raw_data, 'LYRICSBEGIN');
$parsed_lyrics3['tag_offset_start'] = $getid3->info['avdataend'];
$raw_data = substr($raw_data, strpos($raw_data, 'LYRICSBEGIN'));
$lyrics3_size = strlen($raw_data);
}
else {
throw new getid3_exception('"LYRICSBEGIN" expected at '.$lyrics3_offset.' but found "'.substr($raw_data, 0, 11).'" instead.');
}
}
$parsed_lyrics3['raw']['lyrics3version'] = $lyrics3_version;
$parsed_lyrics3['raw']['lyrics3tagsize'] = $lyrics3_size;
$parsed_lyrics3['tag_offset_start'] = $lyrics3_offset;
$parsed_lyrics3['tag_offset_end'] = $lyrics3_offset + $lyrics3_size;
switch ($lyrics3_version) {
case 1:
if (substr($raw_data, strlen($raw_data) - 9, 9) == 'LYRICSEND') {
$parsed_lyrics3['raw']['LYR'] = trim(substr($raw_data, 11, strlen($raw_data) - 11 - 9));
getid3_lyrics3::Lyrics3LyricsTimestampParse($parsed_lyrics3);
}
else {
throw new getid3_exception('"LYRICSEND" expected at '.(ftell($getid3->fp) - 11 + $lyrics3_size - 9).' but found "'.substr($raw_data, strlen($raw_data) - 9, 9).'" instead.');
}
break;
case 2:
if (substr($raw_data, strlen($raw_data) - 9, 9) == 'LYRICS200') {
$parsed_lyrics3['raw']['unparsed'] = substr($raw_data, 11, strlen($raw_data) - 11 - 9 - 6); // LYRICSBEGIN + LYRICS200 + LSZ
$raw_data = $parsed_lyrics3['raw']['unparsed'];
while (strlen($raw_data) > 0) {
$fieldname = substr($raw_data, 0, 3);
$fieldsize = (int)substr($raw_data, 3, 5);
$parsed_lyrics3['raw'][$fieldname] = substr($raw_data, 8, $fieldsize);
$raw_data = substr($raw_data, 3 + 5 + $fieldsize);
}
if (isset($parsed_lyrics3['raw']['IND'])) {
$i = 0;
foreach (array ('lyrics', 'timestamps', 'inhibitrandom') as $flagname) {
if (strlen($parsed_lyrics3['raw']['IND']) > ++$i) {
$parsed_lyrics3['flags'][$flagname] = getid3_lyrics3::IntString2Bool(substr($parsed_lyrics3['raw']['IND'], $i, 1));
}
}
}
foreach (array ('ETT'=>'title', 'EAR'=>'artist', 'EAL'=>'album', 'INF'=>'comment', 'AUT'=>'author') as $key => $value) {
if (isset($parsed_lyrics3['raw'][$key])) {
$parsed_lyrics3['comments'][$value][] = trim($parsed_lyrics3['raw'][$key]);
}
}
if (isset($parsed_lyrics3['raw']['IMG'])) {
foreach (explode("\r\n", $parsed_lyrics3['raw']['IMG']) as $key => $image_string) {
if (strpos($image_string, '||') !== false) {
$imagearray = explode('||', $image_string);
$parsed_lyrics3['images'][$key]['filename'] = @$imagearray[0];
$parsed_lyrics3['images'][$key]['description'] = @$imagearray[1];
$parsed_lyrics3['images'][$key]['timestamp'] = getid3_lyrics3::Lyrics3Timestamp2Seconds(@$imagearray[2]);
}
}
}
if (isset($parsed_lyrics3['raw']['LYR'])) {
getid3_lyrics3::Lyrics3LyricsTimestampParse($parsed_lyrics3);
}
}
else {
throw new getid3_exception('"LYRICS200" expected at '.(ftell($getid3->fp) - 11 + $lyrics3_size - 9).' but found "'.substr($raw_data, strlen($raw_data) - 9, 9).'" instead.');
}
break;
default:
throw new getid3_exception('Cannot process Lyrics3 version '.$lyrics3_version.' (only v1 and v2)');
}
if (isset($getid3->info['id3v1']['tag_offset_start']) && ($getid3->info['id3v1']['tag_offset_start'] < $parsed_lyrics3['tag_offset_end'])) {
$getid3->warning('ID3v1 tag information ignored since it appears to be a false synch in Lyrics3 tag data');
unset($getid3->info['id3v1']);
}
$getid3->info['lyrics3'] = $parsed_lyrics3;
// Check for APE tag after lyrics3
if (!@$getid3->info['ape'] && $getid3->option_tag_apetag && class_exists('getid3_apetag')) {
$apetag = new getid3_apetag($getid3);
$apetag->option_override_end_offset = $getid3->info['lyrics3']['tag_offset_start'];
$apetag->Analyze();
}
}
return true;
}
public static function Lyrics3Timestamp2Seconds($rawtimestamp) {
if (ereg('^\\[([0-9]{2}):([0-9]{2})\\]$', $rawtimestamp, $regs)) {
return (int)(($regs[1] * 60) + $regs[2]);
}
return false;
}
public static function Lyrics3LyricsTimestampParse(&$lyrics3_data) {
$lyrics_array = explode("\r\n", $lyrics3_data['raw']['LYR']);
foreach ($lyrics_array as $key => $lyric_line) {
while (ereg('^(\\[[0-9]{2}:[0-9]{2}\\])', $lyric_line, $regs)) {
$this_line_timestamps[] = getid3_lyrics3::Lyrics3Timestamp2Seconds($regs[0]);
$lyric_line = str_replace($regs[0], '', $lyric_line);
}
$no_timestamp_lyrics_array[$key] = $lyric_line;
if (@is_array($this_line_timestamps)) {
sort($this_line_timestamps);
foreach ($this_line_timestamps as $timestampkey => $timestamp) {
if (isset($lyrics3_data['synchedlyrics'][$timestamp])) {
// timestamps only have a 1-second resolution, it's possible that multiple lines
// could have the same timestamp, if so, append
$lyrics3_data['synchedlyrics'][$timestamp] .= "\r\n".$lyric_line;
} else {
$lyrics3_data['synchedlyrics'][$timestamp] = $lyric_line;
}
}
}
unset($this_line_timestamps);
$regs = array ();
}
$lyrics3_data['unsynchedlyrics'] = implode("\r\n", $no_timestamp_lyrics_array);
if (isset($lyrics3_data['synchedlyrics']) && is_array($lyrics3_data['synchedlyrics'])) {
ksort($lyrics3_data['synchedlyrics']);
}
return true;
}
public static function IntString2Bool($char) {
return $char == '1' ? true : ($char == '0' ? false : null);
}
}
?>

View file

@ -0,0 +1,264 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | write.apetag.php |
// | writing module for ape tags |
// | dependencies: module.tag.apetag.php |
// | dependencies: module.tag.id3v1.php |
// | dependencies: module.tag.lyrics3.php |
// +----------------------------------------------------------------------+
//
// $Id: write.apetag.php,v 1.9 2006/11/20 16:13:31 ah Exp $
class getid3_write_apetag extends getid3_handler_write
{
public $comments;
public function read() {
$engine = new getid3;
$engine->filename = $this->filename;
$engine->fp = fopen($this->filename, 'rb');
$engine->include_module('tag.apetag');
$tag = new getid3_apetag($engine);
$tag->Analyze();
if (!isset($engine->info['ape']['comments'])) {
return;
}
$this->comments = $engine->info['ape']['comments'];
// convert single element arrays to string
foreach ($this->comments as $key => $value) {
if (sizeof($value) == 1) {
$this->comments[$key] = $value[0];
}
}
return true;
}
public function write() {
// remove existing apetag
$this->remove();
$engine = new getid3;
$engine->filename = $this->filename;
$engine->fp = fopen($this->filename, 'rb');
$engine->include_module('tag.id3v1');
$engine->include_module('tag.lyrics3');
$tag = new getid3_id3v1($engine);
$tag->Analyze();
$tag = new getid3_lyrics3($engine);
$tag->Analyze();
$apetag = $this->generate_tag();
if (!$fp = @fopen($this->filename, 'a+b')) {
throw new getid3_exception('Could not open a+b: ' . $this->filename);
}
// init: audio ends at eof
$post_audio_offset = filesize($this->filename);
// lyrics3 tag present
if (@$engine->info['lyrics3']['tag_offset_start']) {
// audio ends before lyrics3 tag
$post_audio_offset = @$engine->info['lyrics3']['tag_offset_start'];
}
// id3v1 tag present
elseif (@$engine->info['id3v1']['tag_offset_start']) {
// audio ends before id3v1 tag
$post_audio_offset = $engine->info['id3v1']['tag_offset_start'];
}
// seek to end of audio data
fseek($fp, $post_audio_offset, SEEK_SET);
// save data after audio data
$post_audio_data = '';
if (filesize($this->filename) > $post_audio_offset) {
$post_audio_data = fread($fp, filesize($this->filename) - $post_audio_offset);
}
// truncate file before start of new apetag
fseek($fp, $post_audio_offset, SEEK_SET);
ftruncate($fp, ftell($fp));
// write new apetag
fwrite($fp, $apetag, strlen($apetag));
// rewrite data after audio
if (!empty($post_audio_data)) {
fwrite($fp, $post_audio_data, strlen($post_audio_data));
}
fclose($fp);
clearstatcache();
return true;
}
public function remove() {
$engine = new getid3;
$engine->filename = $this->filename;
$engine->fp = fopen($this->filename, 'rb');
$engine->include_module('tag.apetag');
$tag = new getid3_apetag($engine);
$tag->Analyze();
if (isset($engine->info['ape']['tag_offset_start']) && isset($engine->info['ape']['tag_offset_end'])) {
if (!$fp = @fopen($this->filename, 'a+b')) {
throw new getid3_exception('Could not open a+b: ' . $this->filename);
}
// get data after apetag
if (filesize($this->filename) > $engine->info['ape']['tag_offset_end']) {
fseek($fp, $engine->info['ape']['tag_offset_end'], SEEK_SET);
$data_after_ape = fread($fp, filesize($this->filename) - $engine->info['ape']['tag_offset_end']);
}
// truncate file before start of apetag
ftruncate($fp, $engine->info['ape']['tag_offset_start']);
// rewrite data after apetag
if (isset($data_after_ape)) {
fseek($fp, $engine->info['ape']['tag_offset_start'], SEEK_SET);
fwrite($fp, $data_after_ape, strlen($data_after_ape));
}
fclose($fp);
clearstatcache();
}
// success when removing non-existant tag
return true;
}
protected function generate_tag() {
// NOTE: All data passed to this function must be UTF-8 format
$items = array();
if (!is_array($this->comments)) {
throw new getid3_exception('Cannot write empty tag, use remove() instead.');
}
foreach ($this->comments as $key => $values) {
// http://www.personal.uni-jena.de/~pfk/mpp/sv8/apekey.html
// A case-insensitive vobiscomment field name that may consist of ASCII 0x20 through 0x7E.
// ASCII 0x41 through 0x5A inclusive (A-Z) is to be considered equivalent to ASCII 0x61 through 0x7A inclusive (a-z).
if (preg_match("/[^\x20-\x7E]/", $key)) {
throw new getid3_exception('Field name "' . $key . '" contains invalid character(s).');
}
$key = strtolower($key);
// convert single value comment to array
if (!is_array($values)) {
$values = array ($values);
}
$value_array = array ();
foreach ($values as $value) {
$value_array[] = str_replace("\x00", '', $value);
}
$value_string = implode("\x00", $value_array);
// length of the assigned value in bytes
$tag_item = getid3_lib::LittleEndian2String(strlen($value_string), 4);
$tag_item .= "\x00\x00\x00\x00" . $key . "\x00" . $value_string;
$items[] = $tag_item;
}
return $this->generate_header_footer($items, true) . implode('', $items) . $this->generate_header_footer($items, false);
}
protected function generate_header_footer(&$items, $is_header=false) {
$comments_length = 0;
foreach ($items as $item_data) {
$comments_length += strlen($item_data);
}
$header = 'APETAGEX';
$header .= getid3_lib::LittleEndian2String(2000, 4);
$header .= getid3_lib::LittleEndian2String(32 + $comments_length, 4);
$header .= getid3_lib::LittleEndian2String(count($items), 4);
$header .= $this->generate_flags(true, true, $is_header, 0, false);
$header .= str_repeat("\x00", 8);
return $header;
}
protected function generate_flags($header=true, $footer=true, $is_header=false, $encoding_id=0, $read_only=false) {
$flags = array_fill(0, 4, 0);
// Tag contains a header
if ($header) {
$flags[0] |= 0x80;
}
// Tag contains no footer
if (!$footer) {
$flags[0] |= 0x40;
}
// This is the header, not the footer
if ($is_header) {
$flags[0] |= 0x20;
}
// 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
$flags[3] |= ($encoding_id << 1);
// Tag or Item is Read Only
if ($read_only) {
$flags[3] |= 0x01;
}
return chr($flags[3]).chr($flags[2]).chr($flags[1]).chr($flags[0]);
}
}
?>

View file

@ -0,0 +1,155 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | write.flac.php |
// | writing module for flac tags |
// | dependencies: metaflac binary. |
// +----------------------------------------------------------------------+
//
// $Id: write.flac.php,v 1.9 2006/12/03 20:02:25 ah Exp $
class getid3_write_flac extends getid3_handler_write
{
public $comments = array ();
public function __construct($filename) {
if (ini_get('safe_mode')) {
throw new getid3_exception('PHP running in Safe Mode (backtick operator not available). Cannot call metaflac binary.');
}
static $initialized;
if (!$initialized) {
// check existance and version of metaflac
if (!ereg('^metaflac ([0-9]+\.[0-9]+\.[0-9]+)', `metaflac --version`, $r)) {
throw new getid3_exception('Fatal: metaflac binary not available.');
}
if (strnatcmp($r[1], '1.1.1') == -1) {
throw new getid3_exception('Fatal: metaflac version 1.1.1 or newer is required, available version: ' . $r[1] . '.');
}
$initialized = true;
}
parent::__construct($filename);
}
public function read() {
// read info with metaflac
if (!$info = trim(`metaflac --no-utf8-convert --export-tags-to=- "$this->filename"`)) {
return;
}
// process info
foreach (explode("\n", $info) as $line) {
$pos = strpos($line, '=');
$key = strtolower(substr($line, 0, $pos));
$value = substr($line, $pos+1);
$this->comments[$key][] = $value;
}
// convert single element arrays to string
foreach ($this->comments as $key => $value) {
if (sizeof($value) == 1) {
$this->comments[$key] = $value[0];
}
}
return true;
}
public function write() {
// create temp file with new comments
$temp_filename = tempnam('*', 'getID3');
if (!$fp = @fopen($temp_filename, 'wb')) {
throw new getid3_exception('Could not write temporary file.');
}
fwrite($fp, $this->generate_tag());
fclose($fp);
// write comments
$this->save_permissions();
if ($error = `metaflac --no-utf8-convert --remove-all-tags --import-tags-from="$temp_filename" "$this->filename" 2>&1`) {
throw new getid3_exception('Fatal: metaflac returned error: ' . $error);
}
$this->restore_permissions();
// success
@unlink($temp_filename);
return true;
}
protected function generate_tag() {
if (!$this->comments) {
throw new getid3_exception('Cannot write empty tag, use remove() instead.');
}
$result = '';
foreach ($this->comments as $key => $values) {
// A case-insensitive FLAC 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).
if (preg_match("/[^\x20-\x7D]|\x3D/", $key)) {
throw new getid3_exception('Field name "' . $key . '" contains invalid character(s).');
}
$key = strtolower($key);
if (!is_array($values)) {
$values = array ($values);
}
foreach ($values as $value) {
if (strstr($value, "\n") || strstr($value, "\r")) {
throw new getid3_exception('Multi-line comments not supported (value contains \n or \r)');
}
$result .= $key . '=' . $value . "\n";
}
}
return $result;
}
public function remove() {
$this->save_permissions();
if ($error = `metaflac --remove-all-tags "$this->filename" 2>&1`) {
throw new getid3_exception('Fatal: metaflac returned error: ' . $error);
}
$this->restore_permissions();
// success when removing non-existant tag
return true;
}
}
?>

View file

@ -0,0 +1,156 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | write.id3v1.php |
// | writing module for id3v1 tags |
// | dependencies: module.tag.id3v1.php. |
// +----------------------------------------------------------------------+
//
// $Id: write.id3v1.php,v 1.15 2006/11/20 16:09:33 ah Exp $
class getid3_write_id3v1 extends getid3_handler_write
{
public $title;
public $artist;
public $album;
public $year;
public $genre_id;
public $genre;
public $comment;
public $track;
public function read() {
$engine = new getid3;
$engine->filename = $this->filename;
$engine->fp = fopen($this->filename, 'rb');
$engine->include_module('tag.id3v1');
$tag = new getid3_id3v1($engine);
$tag->Analyze();
if (!isset($engine->info['id3v1'])) {
return;
}
$this->title = $engine->info['id3v1']['title'];
$this->artist = $engine->info['id3v1']['artist'];
$this->album = $engine->info['id3v1']['album'];
$this->year = $engine->info['id3v1']['year'];
$this->genre_id = $engine->info['id3v1']['genre_id'];
$this->genre = $engine->info['id3v1']['genre'];
$this->comment = $engine->info['id3v1']['comment'];
$this->track = $engine->info['id3v1']['track'];
return true;
}
public function write() {
if (!$fp = @fopen($this->filename, 'r+b')) {
throw new getid3_exception('Could not open r+b: ' . $this->filename);
}
// seek to end minus 128 bytes
fseek($fp, -128, SEEK_END);
// overwrite existing ID3v1 tag
if (fread($fp, 3) == 'TAG') {
fseek($fp, -128, SEEK_END);
}
// append new ID3v1 tag
else {
fseek($fp, 0, SEEK_END);
}
fwrite($fp, $this->generate_tag(), 128);
fclose($fp);
clearstatcache();
return true;
}
protected function generate_tag() {
$result = 'TAG';
$result .= str_pad(trim(substr($this->title, 0, 30)), 30, "\x00", STR_PAD_RIGHT);
$result .= str_pad(trim(substr($this->artist, 0, 30)), 30, "\x00", STR_PAD_RIGHT);
$result .= str_pad(trim(substr($this->album, 0, 30)), 30, "\x00", STR_PAD_RIGHT);
$result .= str_pad(trim(substr($this->year, 0, 4)), 4, "\x00", STR_PAD_LEFT);
if (!empty($this->track) && ($this->track > 0) && ($this->track <= 255)) {
$result .= str_pad(trim(substr($this->comment, 0, 28)), 28, "\x00", STR_PAD_RIGHT);
$result .= "\x00";
$result .= chr($this->track);
}
else {
$result .= str_pad(trim(substr($comment, 0, 30)), 30, "\x00", STR_PAD_RIGHT);
}
// both genre and genre_id set
if ($this->genre && $this->genre_id) {
if ($this->genre != getid3_id3v1::LookupGenreName($this->genre_id)) {
throw new getid3_exception('Genre and genre_id does not match. Unset one and the other will be determined automatically.');
}
}
// only genre set
elseif ($this->genre) {
$this->genre_id = getid3_id3v1::LookupGenreID($this->genre);
}
// only genre_id set
else {
if ($this->genre_id < 0 || $this->genre_id > 147) {
$this->genre_id = 255; // 'unknown' genre
}
$this->genre = getid3_id3v1::LookupGenreName($this->genre_id);
}
$result .= chr(intval($this->genre_id));
return $result;
}
public function remove() {
if (!$fp = @fopen($this->filename, 'r+b')) {
throw new getid3_exception('Could not open r+b: ' . $filename);
}
fseek($fp, -128, SEEK_END);
if (fread($fp, 3) == 'TAG') {
ftruncate($fp, filesize($this->filename) - 128);
fclose($fp);
clearstatcache();
}
// success when removing non-existant tag
return true;
}
}
?>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,209 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | write.lyrics3.php |
// | writing module for lyrics3 2.00 tags |
// | dependencies: module.tag.lyrics3.php. |
// | dependencies: module.tag.id3v1.php |
// +----------------------------------------------------------------------+
//
// $Id: write.lyrics3.php,v 1.5 2006/11/20 16:13:39 ah Exp $
class getid3_write_lyrics3 extends getid3_handler_write
{
public $synched;
public $random_inhibited;
public $lyrics;
public $comment;
public $author;
public $title;
public $artist;
public $album;
public $images;
public function read() {
$engine = new getid3;
$engine->filename = $this->filename;
$engine->fp = fopen($this->filename, 'rb');
$engine->include_module('tag.lyrics3');
$tag = new getid3_lyrics3($engine);
$tag->Analyze();
if (!isset($engine->info['lyrics3']['tag_offset_start'])) {
return;
}
$this->lyrics = @$engine->info['lyrics3']['raw']['LYR'];
$this->comment = @$engine->info['lyrics3']['raw']['INF'];
$this->author = @$engine->info['lyrics3']['raw']['AUT'];
$this->title = @$engine->info['lyrics3']['raw']['ETT'];
$this->artist = @$engine->info['lyrics3']['raw']['EAR'];
$this->album = @$engine->info['lyrics3']['raw']['EAL'];
$this->images = @$engine->info['lyrics3']['raw']['IMG'];
return true;
}
public function write() {
// remove existing apetag
$this->remove();
$engine = new getid3;
$engine->filename = $this->filename;
$engine->fp = fopen($this->filename, 'rb');
$engine->include_module('tag.id3v1');
$tag = new getid3_id3v1($engine);
$tag->Analyze();
$apetag = $this->generate_tag();
if (!$fp = @fopen($this->filename, 'a+b')) {
throw new getid3_exception('Could not open a+b: ' . $this->filename);
}
// init: audio ends at eof
$post_audio_offset = filesize($this->filename);
// id3v1 tag present
if (@$engine->info['id3v1']['tag_offset_start']) {
// audio ends before id3v1 tag
$post_audio_offset = $engine->info['id3v1']['tag_offset_start'];
}
// seek to end of audio data
fseek($fp, $post_audio_offset, SEEK_SET);
// save data after audio data
$post_audio_data = '';
if (filesize($this->filename) > $post_audio_offset) {
$post_audio_data = fread($fp, filesize($this->filename) - $post_audio_offset);
}
// truncate file before start of new apetag
fseek($fp, $post_audio_offset, SEEK_SET);
ftruncate($fp, ftell($fp));
// write new apetag
fwrite($fp, $apetag, strlen($apetag));
// rewrite data after audio
if (!empty($post_audio_data)) {
fwrite($fp, $post_audio_data, strlen($post_audio_data));
}
fclose($fp);
clearstatcache();
return true;
}
protected function generate_tag() {
// define fields
static $fields = array (
'lyrics' => 'LYR',
'comment' => 'INF',
'author' => 'AUT',
'title' => 'ETT',
'artist' => 'EAR',
'album' => 'EAL',
'images' => 'IMG'
);
// loop thru fields and add to frames
$frames = '';
foreach ($fields as $field => $frame_name) {
// field set?
if ($this->$field) {
$frames .= $frame_name . str_pad(strlen($this->$field), 5, '0', STR_PAD_LEFT) . $this->$field;
}
}
if (!$frames) {
throw new getid3_exception('Cannot write empty tag, use remove() instead.');
}
// header
$result = 'LYRICSBEGIN';
// indicator frame
$result .= 'IND00003' . ($this->lyrics ? '1' : '0') . ($this->synched ? '1' : '0') . ($this->random_inibited ? '1' : '0');
// other frames
$result .= $frames;
// footer
$result .= str_pad(strlen($result), 6, '0', STR_PAD_LEFT);
$result .= 'LYRICS200';
return $result;
}
public function remove() {
$engine = new getid3;
$engine->filename = $this->filename;
$engine->fp = fopen($this->filename, 'rb');
$engine->include_module('tag.lyrics3');
$tag = new getid3_lyrics3($engine);
$tag->Analyze();
if (isset($engine->info['lyrics3']['tag_offset_start']) && isset($engine->info['lyrics3']['tag_offset_end'])) {
if (!$fp = @fopen($this->filename, 'a+b')) {
throw new getid3_exception('Could not open a+b: ' . $this->filename);
}
// get data after tag
fseek($fp, $engine->info['lyrics3']['tag_offset_end'], SEEK_SET);
$data_after_lyrics3 = '';
if (filesize($this->filename) > $engine->info['lyrics3']['tag_offset_end']) {
$data_after_lyrics3 = fread($fp, filesize($this->filename) - $engine->info['lyrics3']['tag_offset_end']);
}
// truncate file before start of tag and seek to end
ftruncate($fp, $engine->info['lyrics3']['tag_offset_start']);
// rewrite data after tag
if (!empty($data_after_lyrics3)) {
fseek($fp, $engine->info['lyrics3']['tag_offset_start'], SEEK_SET);
fwrite($fp, $data_after_lyrics3, strlen($data_after_lyrics3));
}
fclose($fp);
clearstatcache();
}
// success when removing non-existant tag
return true;
}
}
?>

View file

@ -0,0 +1,166 @@
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org> |
// | Allan Hansen <ahØartemis*dk> |
// +----------------------------------------------------------------------+
// | write.vorbis.php |
// | writing module for vorbis tags |
// | dependencies: vorbiscomment binary. |
// +----------------------------------------------------------------------+
//
// $Id: write.vorbis.php,v 1.6 2006/12/03 20:02:25 ah Exp $
class getid3_write_vorbis extends getid3_handler_write
{
public $comments = array ();
public function __construct($filename) {
if (ini_get('safe_mode')) {
throw new getid3_exception('PHP running in Safe Mode (backtick operator not available). Cannot call vorbiscomment binary.');
}
static $initialized;
if (!$initialized) {
// check existance and version of vorbiscomment
if (!ereg('^Vorbiscomment ([0-9]+\.[0-9]+\.[0-9]+)', `vorbiscomment --version 2>&1`, $r)) {
throw new getid3_exception('Fatal: vorbiscomment binary not available.');
}
if (strnatcmp($r[1], '1.0.0') == -1) {
throw new getid3_exception('Fatal: vorbiscomment version 1.0.0 or newer is required, available version: ' . $r[1] . '.');
}
$initialized = true;
}
parent::__construct($filename);
}
public function read() {
// read info with vorbiscomment
if (!$info = trim(`vorbiscomment -l "$this->filename"`)) {
return;
}
// process info
foreach (explode("\n", $info) as $line) {
$pos = strpos($line, '=');
$key = strtolower(substr($line, 0, $pos));
$value = substr($line, $pos+1);
$this->comments[$key][] = $value;
}
// convert single element arrays to string
foreach ($this->comments as $key => $value) {
if (sizeof($value) == 1) {
$this->comments[$key] = $value[0];
}
}
return true;
}
public function write() {
// create temp file with new comments
$temp_filename = tempnam('*', 'getID3');
if (!$fp = @fopen($temp_filename, 'wb')) {
throw new getid3_exception('Could not write temporary file.');
}
fwrite($fp, $this->generate_tag());
fclose($fp);
// write comments
$this->save_permissions();
if ($error = `vorbiscomment -w --raw -c "$temp_filename" "$this->filename" 2>&1`) {
throw new getid3_exception('Fatal: vorbiscomment returned error: ' . $error);
}
$this->restore_permissions();
// success
@unlink($temp_filename);
return true;
}
protected function generate_tag() {
if (!$this->comments) {
throw new getid3_exception('Cannot write empty tag, use remove() instead.');
}
$result = '';
foreach ($this->comments as $key => $values) {
// A case-insensitive vobiscomment 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).
if (preg_match("/[^\x20-\x7D]|\x3D/", $key)) {
throw new getid3_exception('Field name "' . $key . '" contains invalid character(s).');
}
$key = strtolower($key);
if (!is_array($values)) {
$values = array ($values);
}
foreach ($values as $value) {
if (strstr($value, "\n") || strstr($value, "\r")) {
throw new getid3_exception('Multi-line comments not supported (value contains \n or \r)');
}
$result .= $key . '=' . $value . "\n";
}
}
return $result;
}
public function remove() {
// create temp file with new comments
$temp_filename = tempnam('*', 'getID3');
if (!$fp = @fopen($temp_filename, 'wb')) {
throw new getid3_exception('Could not write temporary file.');
}
fwrite($fp, '');
fclose($fp);
// write comments
$this->save_permissions();
if ($error = `vorbiscomment -w --raw -c "$temp_filename" "$this->filename" 2>&1`) {
throw new getid3_exception('Fatal: vorbiscomment returned error: ' . $error);
}
$this->restore_permissions();
// success when removing non-existant tag
@unlink($temp_filename);
return true;
}
}
?>

File diff suppressed because it is too large Load diff

View file

@ -1,24 +0,0 @@
/////////////////////////////////////////////////////////////////
/// getID3() by James Heinrich <info@getid3.org> //
// available at http://getid3.sourceforge.net //
// or http://www.getid3.org //
/////////////////////////////////////////////////////////////////
// //
// dependencies.txt - part of getID3() //
// See readme.txt for more details //
// ///
/////////////////////////////////////////////////////////////////
lyrics3 depends on apetag (optional)
ogg depends on flac
id3v2 depends on id3v1
apetag depends on id3v1 (optional, writing only)
bonk depends on id3v2 (optional)
riff depends on mp3
mpeg depends on mp3
quicktime depends on mp3
flac depends on ogg
optimfrog depends on riff
la depends on riff
lpac depends on riff
asf depends on riff, id3v1 (optional)

View file

@ -1,222 +0,0 @@
<?php
/////////////////////////////////////////////////////////////////
/// getID3() by James Heinrich <info@getid3.org> //
// available at http://getid3.sourceforge.net //
// or http://www.getid3.org //
/////////////////////////////////////////////////////////////////
// //
// extension.cache.dbm.php - part of getID3() //
// Please see readme.txt for more information //
// ///
/////////////////////////////////////////////////////////////////
// //
// This extension written by Allan Hansen <ahØartemis*dk> //
// ///
/////////////////////////////////////////////////////////////////
/**
* 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
function getID3_cached_dbm($cache_type, $dbm_filename, $lock_filename) {
// Check for dba extension
if (!extension_loaded('dba')) {
die('PHP is not compiled with dba support, required to use DBM style cache.');
}
// Check for specific dba driver
if (function_exists('dba_handlers')) { // PHP 4.3.0+
if (!in_array('db3', dba_handlers())) {
die('PHP is not compiled --with '.$cache_type.' support, required to use DBM style cache.');
}
}
else { // PHP <= 4.2.3
ob_start(); // nasty, buy the only way to check...
phpinfo();
$contents = ob_get_contents();
ob_end_clean();
if (!strstr($contents, $cache_type)) {
die('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)) {
die('failed to create lock file: ' . $lock_filename);
}
}
// Open lock file for writing
if (!is_writeable($lock_filename)) {
die('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);
// Create dbm-file if needed
if (!file_exists($dbm_filename)) {
if (!touch($dbm_filename)) {
die('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) {
// Failed - create new dbm file
$this->dba = dba_open($dbm_filename, 'n', $cache_type);
if (!$this->dba) {
die('failed to create dbm file: ' . $dbm_filename);
}
// 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;
// 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();
}
parent::getID3();
}
// public: destuctor
function __destruct() {
// Close dbm file
@dba_close($this->dba);
// Release exclusive lock
@flock($this->lock, LOCK_UN);
// Close lock file
@fclose($this->lock);
}
// public: clear cache
function clear_cache() {
// Close dbm file
dba_close($this->dba);
// Create new dbm file
$this->dba = dba_open($this->dbm_filename, 'n', $this->cache_type);
if (!$this->dba) {
die('failed to clear cache/recreate dbm file: ' . $this->dbm_filename);
}
// Insert getID3 version number
dba_insert(GETID3_VERSION, GETID3_VERSION, $this->dba);
// Reregister shutdown function
register_shutdown_function(array($this, '__destruct'));
}
// public: analyze file
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;
}
}
?>

Some files were not shown because too many files have changed in this diff Show more