-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapple.py
38 lines (32 loc) · 954 Bytes
/
apple.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
import requests
import json
from movie import movie
class Apple(object):
"""
Apple iTunes API
"""
def __init__ (self):
self.base_url = 'https://itunes.apple.com/search?'
def get_movie_by_title(self, title, filter=None):
'''
'''
country = 'US'
media = 'movie'
entity = 'movie'
limit = 1
payload = {'term': title,
'country': country,
'media': media,
'entity': entity,
'limit': limit
}
r = requests.get(self.base_url, params=payload)
results = json.loads(r.text.strip())
results = results.get('results')[0]
m = {}
if results.get('trackName') == title:
m = movie(str(results.get('trackName')), 'iTunes')
m.stream = True
m.price_stream = results.get('trackPrice')
return m