forked from N3MIS15/trakt_xbmc_sync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrakt_unwatch_series.py
More file actions
70 lines (53 loc) · 2.09 KB
/
Copy pathtrakt_unwatch_series.py
File metadata and controls
70 lines (53 loc) · 2.09 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
###################### SETTINGS ######################
trakt_username = ''
trakt_password = ''
trakt_apikey = ''
# Array of show slugs to set to unwatched
unwatch_shows = ['how-i-met-your-mother', 'fringe']
#################### END SETTINGS ####################
try:
import json
except ImportError:
import simplejson as json
import urllib2, base64, hashlib, copy
def trakt_api(url, params={}):
'''Connects to trakt.tv api'''
username = trakt_username
password = hashlib.sha1(trakt_password).hexdigest()
params = json.JSONEncoder().encode(params)
request = urllib2.Request(url, params)
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
response = urllib2.urlopen(request).read()
response = json.JSONDecoder().decode(response)
return response
def unwatch_show(show_name):
print '\nGetting TV shows from trakt'
# Episodes Collection
url = 'http://api.trakt.tv/show/summary.json/%s/%s/extended' % (trakt_apikey, show_name)
try:
show = trakt_api(url)
show['episodes'] = []
except Exception as e:
quit(e)
print '\nFound %s' % (show['title'])
for season in show['seasons']:
for episode in season['episodes']:
ep = { 'season': episode['season'], 'episode': episode['episode'], 'title': episode['title'] }
show['episodes'].append(ep)
url = 'http://api.trakt.tv/show/episode/unseen/%s' % (trakt_apikey)
params = {}
params['username'] = trakt_username
params['password'] = hashlib.sha1(trakt_password).hexdigest()
params['tvdb_id'] = show['tvdb_id']
params['title'] = show['title']
params['year'] = show['year']
params['episodes'] = []
for ep in show['episodes']:
print '%s-%sx%s-%s' % (show_name, ep['season'], ep['episode'], ep['title'])
params['episodes'].append({'season': ep['season'], 'episode': ep['episode']})
trakt_api(url, params)
if __name__ == '__main__':
for show in unwatch_shows:
unwatch_show(show)