GithubHelp home page GithubHelp logo

ocelma / python-itunes Goto Github PK

View Code? Open in Web Editor NEW
157.0 10.0 64.0 41 KB

A simple python wrapper to access iTunes Store API http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html

Python 100.00%

python-itunes's Introduction

Python iTunes

A simple python wrapper to access iTunes Store API http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html

Installation

Pypi package available at http://pypi.python.org/pypi/python-itunes/1.0

$ easy_install python-itunes

Or download the code from https://github.com/ocelma/python-itunes/archives/master and then

$ python setup.py install

Note

If you're using python version <= 2.5 you'll need to install simplejson. E.g:

$ easy_install simplejson

Examples

import itunes

# Search band U2
artist = itunes.search_artist('u2')[0]
for album in artist.get_albums():
    for track in album.get_tracks():
        print album.get_name(), album.get_url(), track.get_name(), track.get_duration(), track.get_preview_url()

# Search U2 videos
videos = itunes.search(query='u2', media='musicVideo')
for video in videos:
    print video.get_name(), video.get_preview_url(), video.get_artwork()

# Search Volta album by Björk
album = itunes.search_album('Volta Björk')[0]

# Global Search 'Beatles'
items = itunes.search(query='beatles')
for item in items: 
    print '[' + item.type + ']', item.get_artist(), item.get_name(), item.get_url(), item.get_release_date()

# Search 'Angry Birds' game
item = itunes.search(query='angry birds', media='software')[0]
item.get_version()
item.get_price()
item.get_url()
item.get_seller_url()
item.get_screenshots()
item.get_languages()
item.get_avg_rating()
item.get_num_ratings()

Lookup

import itunes

# Lookup Achtung Baby album by U2
U2_ACHTUNGBABY_ID = 475390461
album = itunes.lookup(U2_ACHTUNGBABY_ID)

print album.get_url()
print album.get_artwork()

artist = album.get_artist()
tracks = album.get_tracks()

# Lookup song One from Achtung Baby album by U2
U2_ONE_ID = 475391315
track = itunes.lookup(U2_ONE_ID)

artist = track.get_artist()
album = track.get_album()

Caching JSON results

import itunes

if not itunes.is_caching_enabled():
    itunes.enable_caching('/tmp/itunes_cache') #If no param given it creates a folder in /tmp

#From now on all JSON results are cached here:
print itunes.__cache_dir

Tests

$ nosetests tests

python-itunes's People

Contributors

afit avatar caxap avatar ocelma avatar quentinhayot avatar robottwo avatar sampsyo avatar vietanh85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-itunes's Issues

tolerate missing 'collectionPrice'

Python 2.7.13 (default, Dec 18 2016, 07:03:39)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import itunes
>>> itunes.search_artist('health')[0].get_albums()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.12-x86_64/egg/itunes/__init__.py", line 334, in get_albums
  File "build/bdist.macosx-10.12-x86_64/egg/itunes/__init__.py", line 174, in get
  File "build/bdist.macosx-10.12-x86_64/egg/itunes/__init__.py", line 377, in _set
KeyError: 'collectionPrice'
>>>

Seems similar to #12, not sure if it's related.

Getting song previews?

Hi, this is not an issues as much as a question about the capabilities of this wrapper api.

I want to get JSON results from the iTunes search api, which includes the previewURL for a certain song. (i want to only search for songs).

Here is an example output from iTunes that I want to get:
SRC: [https://affiliate.itunes.apple.com/resources/documentation/itunes-store-web-service-search-api/]

{"wrapperType":"track",
 "kind":"song",
 "artistId":909253,
 "collectionId":120954021,
 "trackId":120954025,
 "artistName":"Jack Johnson",
 "collectionName":"Sing-a-Longs and Lullabies for the Film Curious George",
 "trackName":"Upside Down",
 "collectionCensoredName":"Sing-a-Longs and Lullabies for the Film Curious George",
 "trackCensoredName":"Upside Down",
 "artistViewUrl":"https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewArtist?id=909253",
 "collectionViewUrl":"https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=120954025&id=120954021&s=143441",
 "trackViewUrl":"https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=120954025&id=120954021&s=143441",
 "previewUrl":"http://a1099.itunes.apple.com/r10/Music/f9/54/43/mzi.gqvqlvcq.aac.p.m4p",
 "artworkUrl60":"http://a1.itunes.apple.com/r10/Music/3b/6a/33/mzi.qzdqwsel.60x60-50.jpg",
 "artworkUrl100":"http://a1.itunes.apple.com/r10/Music/3b/6a/33/mzi.qzdqwsel.100x100-75.jpg",
 "collectionPrice":10.99,
 "trackPrice":0.99,
 "collectionExplicitness":"notExplicit",
 "trackExplicitness":"notExplicit",
 "discCount":1,
 "discNumber":1,
 "trackCount":14,
 "trackNumber":1,
 "trackTimeMillis":210743,
 "country":"USA",
 "currency":"USD",
 "primaryGenreName":"Rock"}

Any ideas? Thanks in advance

Use json or require dep simplejson

First of all, thank you for this package - it's excellent.

Since python-itunes requires simplejson - I think setup.py should require it:


setup(
    name = "python-itunes",
    ...
    packages=['itunes'],
    install_requires = ['simplejson']
)

Alternatively, you could change from simplejson to json, which is available as a standard module as of python 2.6 and only require simplejson if python-itunes is installed in a version `< 2.6'.

Thank you.

Cannot install from pip

pip install of python-itunes always fails for me with the message:

Downloading/unpacking python-itunes
  Could not find any downloads that satisfy the requirement python-itunes
No distributions at all found for python-itunes

I'm wondering if something is wrong with the package on PyPI? Below is some more detailed information from the pip log.

Downloading/unpacking python-itunes

  Getting page http://pypi.python.org/simple/python-itunes
  URLs to search for versions for python-itunes:
  * http://pypi.python.org/simple/python-itunes/
  Getting page https://github.com/ocelma/python-itunes
  Analyzing links from page http://pypi.python.org/simple/python-itunes/
    Skipping link http://pypi.python.org/packages/source/p/python-itunes/python-itunes.tar.gz#md5=6690e8a261d3486b90763e3281842c1b (from http://pypi.python.org/simple/python-it\
unes/); wrong project name (not python-itunes)
    Skipping link https://github.com/ocelma/python-itunes (from http://pypi.python.org/simple/python-itunes/); not a file
    Skipping link http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html (from http://pypi.python.org/simple/python-itunes/); u\
nknown archive format: .html
  Analyzing links from page https://github.com/ocelma/python-itunes
    Skipping link https://github.com/opensearch.xml (from https://github.com/ocelma/python-itunes); unknown archive format: .xml
    Skipping link https://github.com/fluidicon.png (from https://github.com/ocelma/python-itunes); unknown archive format: .png
...

Unbound local variable

After a could of requests i got a "unbound local variable: Variable id is referenced before assignment" exception for "lookup" method.

By the way, thanks for sharing this library on git :)

Tolerate missing "collectionPrice" JSON key

The library seems to require a collectionPrice key in search responses, which may not be present:

>>> import itunes
>>> itunes.search_album('bar')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "itunes/__init__.py", line 605, in search_album
    limit=limit, offset=offset, order=order, country=store).get()
  File "itunes/__init__.py", line 181, in get
    item._set(json)
  File "itunes/__init__.py", line 398, in _set
    self.price = round(json['collectionPrice'] or 0, 4)
KeyError: 'collectionPrice'

A simple solution would be to check for they's presence and emit a null value if it's missing.

Pip cannot find python-itunes package

This issue is slightly different than #7 .

easy_install works, but when I run pip install python-itunes, I also get the error "No distributions at all found for python-itunes".

But in the log, I saw this:

Downloading/unpacking python-itunes
Getting page http://pypi.python.org/simple/python-itunes
URLs to search for versions for python-itunes:
* http://pypi.python.org/simple/python-itunes/
Getting page http://pypi.python.org/simple/python-itunes/
Analyzing links from page https://pypi.python.org/simple/python-itunes/
  Skipping link https://pypi.python.org/packages/source/p/python-itunes/python-itunes.tar.gz#md5=6690e8a261d3486b90763e3281842c1b (from https://pypi.python.org/simple/python-itunes/); wrong project name (not python-itunes)
  Skipping link http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html (from https://pypi.python.org/simple/python-itunes/); unknown archive format: .html

Could not find any downloads that satisfy the requirement python-itunes

Note that in line 7 it's skipping the tar.gz package link with the message "wrong project name (not python-itunes)". I think that if you remove the "#md5=..." after the file name, it will work.

If fact, this works:

pip install https://pypi.python.org/packages/source/p/python-itunes/python-itunes.tar.gz

Thanks for the package!

Check for None as a value of 'other' when doing __eq__ or __ne__

I have a loop on a search where I need to check to see if I found a match, it not the Artist/Album, etc object can be set to None if not found. When comparing these objects to None the eq and ne methods blow up with:
AttributeError: 'NoneType' object has no attribute 'id'

Please find the attached patch that resolves this issue.
none-patch.txt

Change lang

Thanks for your lib.

One good feature would be to be able to change the lang ;)

pyitunes.ServiceException: Error:

Is there any limit to number of search queries (items = itunes.search(query=song_name)) made with itunes api as i am getting this error after processing for songs greater than 47 in a row.
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "itunes/__init__.py", line 677, in search offset=offset, order=order, country=store).get() File "itunes/__init__.py", line 149, in get self._json_results = self._request(cacheable=is_caching_enabled()) File "itunes/__init__.py", line 140, in _request return _Request(method_name, params).execute(cacheable) File "itunes/__init__.py", line 96, in execute raise self._get_error(e.fp.read()) pyitunes.ServiceException: Error:
Once i get this error, it throws back same unexpectedly on any other further made query.
What is the real issue behind this and how to avoid this (if possible) ?

lyrics

i wanna get the lyrics of the song from the api how ca i get it please help

AttributeError: 'str' object has no attribute 'get_id'

Hi,

I'm trying to store the Song ID and I get the error
songid = track.get_id()
AttributeError: 'str' object has no attribute 'get_id'
I also get this on the Duration
track_duration = track.get_duration()
Any help would be greatly appriciated

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.