[PHP] iTunes API

Gestart doorJenner19 reacties48 weergaven

20 berichten · pagina 1 van 2

Jenner

Lid · Topicstarter

Berichten
1.544
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo,

Ik heb even snel een scriptje in elkaar gezet voor mijn nieuwe website. Je kunt hiermee data ophalen vanaf iTunes.

Demo

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]//Set default config[/COLOR]
iTunes[COLOR= #007700]::[/COLOR]config[COLOR= #007700]([/COLOR][COLOR= #DD0000]media[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]music[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #FF8000]//Search for Maroon 5 in the Dutch iTunes store[/COLOR]
[COLOR= #0000BB]$results[/COLOR] [COLOR= #007700]=[/COLOR] iTunes[COLOR= #007700]:[/COLOR]SMILEYYYYYYYYYYYBEGIN[COLOR= #007700]:[/COLOR]search[COLOR= #007700]([/COLOR][COLOR= #DD0000]Maroon 5[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR]
    [COLOR= #DD0000]country[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]NL[/COLOR]
[COLOR= #007700]))->[/COLOR]results[COLOR= #007700];[/COLOR]

[COLOR= #FF8000]//Get all the albums from artist id 439823[/COLOR]
[COLOR= #0000BB]$artist[/COLOR] [COLOR= #007700]=[/COLOR] iTunes[COLOR= #007700]::[/COLOR]lookup[COLOR= #007700]([/COLOR][COLOR= #0000BB]439823[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]id[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR]
    [COLOR= #DD0000]entity[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]album[/COLOR]
[COLOR= #007700]));[/COLOR]
?>


Github: https://github.com/ijanerik/PHP-iTunes-API (Hier vind je ook de updates)

Source
Spoiler tonen
Class

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]/**
 * iTunes class
 *
 * Search for the config and the returned results to {@url http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html}
 */[/COLOR]
[URL="http://www.php.net/class"]class[/URL] iTunes
[COLOR= #007700]{[/COLOR]
    const API_LOOKUP [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]http://itunes.apple.com/lookup?[/COLOR][COLOR= #007700];[/COLOR]
    const API_SEARCH [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]http://itunes.apple.com/search?[/COLOR][COLOR= #007700];[/COLOR]
    
    [COLOR= #FF8000]/**
     * The lookup config
     * 
     * (default value: array())
     * 
     * @var array
     * @access protected
     * @static
     */[/COLOR]
    [URL="http://www.php.net/protected"]protected[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #0000BB]$_lookup_config[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]
    
    [COLOR= #FF8000]/**
     * The search config
     * 
     * (default value: array())
     * 
     * @var array
     * @access protected
     * @static
     */[/COLOR]
    [URL="http://www.php.net/protected"]protected[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #0000BB]$_search_config[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]

    [COLOR= #FF8000]/**
     * Set a new config
     *
     * FORUMCODE0
     * 
     * @access public
     * @static
     * @param array|string $index (default: array())
     * @param string $value (default: null)
     * @param string $type (default: search)
     * @return void
     */[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] config[COLOR= #007700]([/COLOR][COLOR= #0000BB]$index[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700](),[/COLOR] [COLOR= #0000BB]$value[/COLOR] [COLOR= #007700]=[/COLOR] null[COLOR= #007700],[/COLOR] [COLOR= #0000BB]$type[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]search[/COLOR][COLOR= #007700])
    {[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/is_array"]is_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$index[/COLOR][COLOR= #007700]))
        {[/COLOR]
            [COLOR= #0000BB]$index[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$index[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]$value[/COLOR][COLOR= #007700]);
        }[/COLOR]
        [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/is_array"]is_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$index[/COLOR][COLOR= #007700]) &&[/COLOR] [COLOR= #0000BB]$value[/COLOR] [COLOR= #007700]!==[/COLOR] null[COLOR= #007700])
        {[/COLOR]
            [COLOR= #0000BB]$type[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$value[/COLOR][COLOR= #007700];
        }[/COLOR]
        
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$type[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]lookup[/COLOR][COLOR= #007700])
        {[/COLOR]
            self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$_lookup_config[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array_merge"]array_merge[/URL][COLOR= #007700]([/COLOR]self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$_lookup_config[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$index[/COLOR][COLOR= #007700]);
        }[/COLOR]
        [URL="http://www.php.net/else"]else[/URL]
        [COLOR= #007700]{[/COLOR]
            self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$_search_config[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array_merge"]array_merge[/URL][COLOR= #007700]([/COLOR]self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$_search_config[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$index[/COLOR][COLOR= #007700]);
        }
        
        
        
    }[/COLOR]

    [COLOR= #FF8000]/**
     * Search inside iTunes
     * 
     * @access public
     * @static
     * @param mixed $term
     * @param mixed $by (default: null)
     * @param array $config (default: array())
     * @return array
     */[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] search[COLOR= #007700]([/COLOR][COLOR= #0000BB]$term[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$by[/COLOR] [COLOR= #007700]=[/COLOR] null[COLOR= #007700],[/COLOR] [URL="http://www.php.net/array"]array[/URL] [COLOR= #0000BB]$config[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]())
    {[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/is_array"]is_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$by[/COLOR][COLOR= #007700]))
        {[/COLOR]
            [COLOR= #0000BB]$config[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$by[/COLOR][COLOR= #007700];
        }[/COLOR]
        [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$by[/COLOR] [COLOR= #007700]!==[/COLOR] null[COLOR= #007700])
        {[/COLOR]
            [COLOR= #0000BB]$config[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]attribute[/COLOR][COLOR= #007700]] =[/COLOR] [COLOR= #0000BB]$by[/COLOR][COLOR= #007700];
        }[/COLOR]
    
        [COLOR= #0000BB]$config[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]term[/COLOR][COLOR= #007700]] =[/COLOR] [COLOR= #0000BB]$term[/COLOR][COLOR= #007700];[/COLOR]
        [COLOR= #0000BB]$content[/COLOR] [COLOR= #007700]=[/COLOR] self[COLOR= #007700]::[/COLOR]_get_content[COLOR= #007700]([/COLOR][COLOR= #0000BB]$config[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]search[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$content[/COLOR][COLOR= #007700];
    }[/COLOR]
    
    [COLOR= #FF8000]/**
     * Look for artists or other objects inside iTunes
     * 
     * @access public
     * @static
     * @param string $term
     * @param string|array $by (default: id)
     * @param array $config (default: array())
     * @return array
     */[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] lookup[COLOR= #007700]([/COLOR][COLOR= #0000BB]$term[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$by[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]id[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/array"]array[/URL] [COLOR= #0000BB]$config[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]())
    {[/COLOR]
        [COLOR= #0000BB]$config[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$by[/COLOR][COLOR= #007700]] =[/COLOR] [COLOR= #0000BB]$term[/COLOR][COLOR= #007700];[/COLOR]
        [COLOR= #0000BB]$content[/COLOR] [COLOR= #007700]=[/COLOR] self[COLOR= #007700]::[/COLOR]_get_content[COLOR= #007700]([/COLOR][COLOR= #0000BB]$config[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]lookup[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$content[/COLOR][COLOR= #007700];
    }[/COLOR]
    
    [COLOR= #FF8000]/**
     * Get the content from the iTunes servers
     * 
     * @access protected
     * @static
     * @param array $config
     * @param string $type (default: search)
     * @return array
     */[/COLOR]
    [URL="http://www.php.net/protected"]protected[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] _get_content[COLOR= #007700]([/COLOR][COLOR= #0000BB]$config[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$type[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]search[/COLOR][COLOR= #007700])
    {[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$type[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]lookup[/COLOR][COLOR= #007700])
        {[/COLOR]
            [COLOR= #0000BB]$url[/COLOR] [COLOR= #007700]=[/COLOR] self[COLOR= #007700]::[/COLOR]API_LOOKUP[COLOR= #007700];
        }[/COLOR]
        [URL="http://www.php.net/else"]else[/URL]
        [COLOR= #007700]{[/COLOR]
            [COLOR= #0000BB]$url[/COLOR] [COLOR= #007700]=[/COLOR] self[COLOR= #007700]::[/COLOR]API_SEARCH[COLOR= #007700];
        }[/COLOR]
        
        [COLOR= #0000BB]$url[/COLOR] [COLOR= #007700].=[/COLOR] http_build_query[COLOR= #007700]([/COLOR][COLOR= #0000BB]$config[/COLOR][COLOR= #007700]);[/COLOR]
        
        [COLOR= #0000BB]$content[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/file_get_contents"]file_get_contents[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$url[/COLOR][COLOR= #007700]);[/COLOR]
        [COLOR= #0000BB]$array[/COLOR] [COLOR= #007700]=[/COLOR] json_decode[COLOR= #007700]([/COLOR][COLOR= #0000BB]$content[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$array[/COLOR][COLOR= #007700];
    }

}[/COLOR]
?>
0
Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Best wel cool, ik hoop dat jee nog meer apis maakt biggrin
0
Jvdw

Lid

Berichten
4.321
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Nice hopelijk maak je nog eentje voor de appsore ook
0
Jenner

Lid · Topicstarter

Berichten
1.544
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jvdw schreef:
Nice hopelijk maak je nog eentje voor de appsore ook
Ow, misschien moet ik dat er wat duidelijk bij zetten, maar als je de uitleg van de link leest dan zie je dat je alle content van iTunes kunt ophalen en daar valt de Appstore ook onder wink
Shahiem schreef:
Best wel cool, ik hoop dat jee nog meer apis maakt biggrin
Ik ben bezig wink Misschien binnenkort eentje voor de Envato API. Heb je anders nog andere ideeën voor APIs?
0
Jvdw

Lid

Berichten
4.321
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jenner schreef:
Eerdere citaten tonen
Jvdw schreef:
Nice hopelijk maak je nog eentje voor de appsore ook
Ow, misschien moet ik dat er wat duidelijk bij zetten, maar als je de uitleg van de link leest dan zie je dat je alle content van iTunes kunt ophalen en daar valt de Appstore ook onder wink
Eerdere citaten tonen
Shahiem schreef:
Best wel cool, ik hoop dat jee nog meer apis maakt biggrin
Ik ben bezig wink Misschien binnenkort eentje voor de Envato API. Heb je anders nog andere ideeën voor APIs?
Ooh oke, nice nicethumbsup
0
Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jenner schreef:
Eerdere citaten tonen
Jvdw schreef:
Nice hopelijk maak je nog eentje voor de appsore ook
Ow, misschien moet ik dat er wat duidelijk bij zetten, maar als je de uitleg van de link leest dan zie je dat je alle content van iTunes kunt ophalen en daar valt de Appstore ook onder wink
Eerdere citaten tonen
Shahiem schreef:
Best wel cool, ik hoop dat jee nog meer apis maakt biggrin
Ik ben bezig wink Misschien binnenkort eentje voor de Envato API. Heb je anders nog andere ideeën voor APIs?
Misschien een RTL XL/uitzending gemist api, waarmee ik data er vanaf kan halen. OF een uitgebreide youtube api (Niet die van youtube zelf, maar een eigen)
0
Jenner

Lid · Topicstarter

Berichten
1.544
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Joeey schreef:
Ik krijg er deze error mee; http://trollface.be/apis/itunes/
Bug fixed wink Oja en dat is een fake ID. Op de iTunes API vind je wel geldige wink
0
Berichten
3.074
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jenner schreef:
Eerdere citaten tonen
Joeey schreef:
Ik krijg er deze error mee; http://trollface.be/library/apis/itunes/
Bug fixed wink Oja en dat is een fake ID. Op de iTunes API vind je wel geldige wink
Dat zag ik al aan de errors, ze konden het ID niet vinden.
0
Jenner

Lid · Topicstarter

Berichten
1.544
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Shahiem schreef:
Eerdere citaten tonen
Jenner schreef:
Eerdere citaten tonen
Jvdw schreef:
Nice hopelijk maak je nog eentje voor de appsore ook
Ow, misschien moet ik dat er wat duidelijk bij zetten, maar als je de uitleg van de link leest dan zie je dat je alle content van iTunes kunt ophalen en daar valt de Appstore ook onder wink
Eerdere citaten tonen
Shahiem schreef:
Best wel cool, ik hoop dat jee nog meer apis maakt biggrin
Ik ben bezig wink Misschien binnenkort eentje voor de Envato API. Heb je anders nog andere ideeën voor APIs?
Misschien een RTL XL/uitzending gemist api, waarmee ik data er vanaf kan halen. OF een uitgebreide youtube api (Niet die van youtube zelf, maar een eigen)
Op dit moment bestaat er geen RTL XL API dus daar ga ik me niet mee bezig houden, maar van de NOS is wel wat. smile http://open.nos.nl/ Misschien kan ik daar wat mee doen. Een Youtube API vind ik onnodig, want daar zijn er al tientallen van en ik kan je verzekeren dat er zeker goede bijzitten smile
0
Berichten
3.074
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jenner schreef:
Eerdere citaten tonen
Shahiem schreef:
Eerdere citaten tonen
Jenner schreef:
Eerdere citaten tonen
Jvdw schreef:
Nice hopelijk maak je nog eentje voor de appsore ook
Ow, misschien moet ik dat er wat duidelijk bij zetten, maar als je de uitleg van de link leest dan zie je dat je alle content van iTunes kunt ophalen en daar valt de Appstore ook onder wink
Eerdere citaten tonen
Shahiem schreef:
Best wel cool, ik hoop dat jee nog meer apis maakt biggrin
Ik ben bezig wink Misschien binnenkort eentje voor de Envato API. Heb je anders nog andere ideeën voor APIs?
Misschien een RTL XL/uitzending gemist api, waarmee ik data er vanaf kan halen. OF een uitgebreide youtube api (Niet die van youtube zelf, maar een eigen)
Op dit moment bestaat er geen RTL XL API dus daar ga ik me niet mee bezig houden, maar van de NOS is wel wat. smile http://open.nos.nl/ Misschien kan ik daar wat mee doen. Een Youtube API vind ik onnodig, want daar zijn er al tientallen van en ik kan je verzekeren dat er zeker goede bijzitten smile
Je kan misschien een API voor een van je eigen websites maken, mocht je die hebben?
0
Jvdw

Lid

Berichten
4.321
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Maybe niet voor jou, maar habbo apis hebben ook succes
0
Jenner

Lid · Topicstarter

Berichten
1.544
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jvdw schreef:
Maybe niet voor jou, maar habbo apis hebben ook succes
Ik zeg: "Schiet die mensen van Habbo af". Ghehe, nee. Ik ben al een poosje over Habbo heen gegroeid en ik moet er het nut in zien voor mezelf. Envato, NOS en iTunes doe ik zelf wat mee en met Habbo (helaas voor jullie) niet.

toevoeging op 22 juli 2012, 22:04:49:
Ik heb een Github link toegevoegd. Daar worden nu verdere alle updates gedaan.
https://github.com/ijanerik/PHP-iTunes-API
0
Berichten
2.517
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
misschien een hyves api? waar je bepaalde gegevens van hyves kan halen ? zoals het nieuws ofzo
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Propje schreef:
misschien een hyves api? waar je bepaalde gegevens van hyves kan halen ? zoals het nieuws ofzo
Is er al? Maar wel beperkt...
Verder rust er auteursrecht op het nieuws...
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren