-
Notifications
You must be signed in to change notification settings - Fork 0
/
subpotato.py
69 lines (55 loc) · 2.02 KB
/
subpotato.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
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
#subpotato.py
import simplejson as json
import urllib2
import feedparser
import os.path as path
defaultUrl="https://couchpotato/"
#get this from defaultUrl/docs
defaultKey=
defaultFeed="http://http://rss.imdb.com/user/ur#######/watchlist"
listFilename=path.expanduser("~/subpotato/filestocopy.txt")
pathPrefix="/mnt/samba/Videos/Movies"
def processFileList(filesToCopy) :
#open the list file, read it in
#print filesToCopy
with open(listFilename) as f:
d = {}
lines = f.read().split('\n')
#print lines
f.close()
#add unique filenames to the list
for files in filesToCopy:
if files not in lines:
lines.append(files)
#rewrite the file with all unique filenames
with open(listFilename, 'w') as outputFile:
for line in lines:
outputFile.write("%s\n" % line)
def subpotato(URL_BASE, API_KEY, FEED_URL) :
feedDict = feedparser.parse(FEED_URL)["entries"]
#Make the set of movie names and imdb numbers
movies = []
feedLength = len(feedDict)
for j in range(feedLength):
imdbID=feedDict[j]['link'][26:35]
#print imdbID
#print feedDict[j]['title']
movies.append({'title' : feedDict[j]['title'], 'id' : imdbID})
#get the set of movie names available from couchpotato
releases= []
for movie in movies:
url=URL_BASE+"/api/"+API_KEY+"/"+"movie.get?id="+movie['id']
json_string = urllib2.urlopen(url).read()
the_data=json.loads(json_string)
releases.append(the_data["movie"]["releases"])
#get filenames to be synced
filesList = []
for release in releases:
for x in release :
for filename in x["files"] :
filesList.append( filename["path"][len(pathPrefix):] )
#process the list of files
processFileList(filesList)
if __name__ == "__main__" :
subpotato(defaultURL, defaultKey, defaultFeed)
#TBD: actually copy the files, rsync or something.