Skip to content

Commit 949fc58

Browse files
authored
Merge pull request #4689 from jamesachamp/4672/refactor/update-download-endpoint
Update zipview_url with new endpoint
2 parents 72acc4c + 81c7e7d commit 949fc58

File tree

1 file changed

+1
-28
lines changed

1 file changed

+1
-28
lines changed

openlibrary/coverstore/code.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import json
66
import logging
77
import os
8-
import time
98

109
import memcache
1110
import requests
@@ -164,36 +163,10 @@ def trim_microsecond(date):
164163
return datetime.datetime(*date.timetuple()[:6])
165164

166165

167-
@web.memoize
168-
def get_memcache():
169-
servers = config.get("memcache_servers")
170-
return memcache.Client(servers)
171-
172-
def _locate_item(item):
173-
"""Locates the archive.org item in the cluster and returns the server and directory.
174-
"""
175-
print(time.asctime(), "_locate_item", item, file=web.debug)
176-
d = requests.get("https://archive.org/metadata/" + item).json()
177-
return d['server'], d['dir']
178-
179-
def locate_item(item):
180-
mc = get_memcache()
181-
if not mc:
182-
return _locate_item(item)
183-
else:
184-
x = mc.get(item)
185-
if not x:
186-
x = _locate_item(item)
187-
print(time.asctime(), "mc.set", item, x, file=web.debug)
188-
mc.set(item, x, time=600) # cache it for 10 minutes
189-
return x
190-
191166
def zipview_url(item, zipfile, filename):
192-
server, dir = locate_item(item)
193-
194167
# http or https
195168
protocol = web.ctx.protocol
196-
return "%(protocol)s://%(server)s/zipview.php?zip=%(dir)s/%(zipfile)s&file=%(filename)s" % locals()
169+
return "%(protocol)s://archive.org/download/%(item)s/%(zipfile)s/%(filename)s" % locals()
197170

198171
# Number of images stored in one archive.org item
199172
IMAGES_PER_ITEM = 10000

0 commit comments

Comments
 (0)