match places/events in any case, update url-list in torrent to match current url

This commit is contained in:
j 2012-01-17 16:09:45 +05:30
parent 7140d4c3f5
commit 06069b71e2
4 changed files with 19 additions and 10 deletions

View file

@ -29,7 +29,6 @@ def get_matches(obj, model, layer_type):
if name in othername: if name in othername:
super_matches.append(othername) super_matches.append(othername)
exact = [l['id'] for l in filter(lambda l: l['type'] == layer_type, settings.CONFIG['layers'])] exact = [l['id'] for l in filter(lambda l: l['type'] == layer_type, settings.CONFIG['layers'])]
if exact: if exact:
q = Q(value__iexact=obj.name) q = Q(value__iexact=obj.name)

View file

@ -15,7 +15,7 @@ def update_matching_events(id):
for i in ids: for i in ids:
e = Event.objects.get(pk=i) e = Event.objects.get(pk=i)
for name in [e.name] + list(e.alternativeNames): for name in [e.name] + list(e.alternativeNames):
if name in annotation.value: if name.lower() in annotation.value.lower():
e.update_matches() e.update_matches()
break break
@ -29,6 +29,6 @@ def update_matching_places(id):
for i in ids: for i in ids:
e = Place.objects.get(pk=i) e = Place.objects.get(pk=i)
for name in [e.name] + list(e.alternativeNames): for name in [e.name] + list(e.alternativeNames):
if name in annotation.value: if name.lower() in annotation.value.lower():
e.update_matches() e.update_matches()
break break

View file

@ -901,6 +901,14 @@ class Item(models.Model):
self.update_timeline() self.update_timeline()
break break
def get_torrent(self, request):
if self.torrent:
self.torrent.seek(0)
data = ox.torrent.bdecode(self.torrent.read())
url = request.build_absolute_uri("%s/torrent/"%self.get_absolute_url())
data['url-list'] = ['%s%s' % (url, u.split('torrent/')[1]) for u in data['url-list']]
return ox.torrent.bencode(data)
def make_torrent(self): def make_torrent(self):
streams = self.streams() streams = self.streams()
if streams.count() == 0: if streams.count() == 0:

View file

@ -723,7 +723,7 @@ def torrent(request, id, filename=None):
if not item.torrent: if not item.torrent:
raise Http404 raise Http404
if not filename or filename.endswith('.torrent'): if not filename or filename.endswith('.torrent'):
response = HttpFileResponse(item.torrent.path, response = HttpResponse(item.get_torrent(request),
content_type='application/x-bittorrent') content_type='application/x-bittorrent')
filename = "%s.torrent" % item.get('title') filename = "%s.torrent" % item.get('title')
response['Content-Disposition'] = 'attachment; filename="%s"' % filename.encode('utf-8') response['Content-Disposition'] = 'attachment; filename="%s"' % filename.encode('utf-8')
@ -906,18 +906,20 @@ def atom_xml(request):
el.text = u"1:1" el.text = u"1:1"
if settings.CONFIG['video'].get('download'): if settings.CONFIG['video'].get('download'):
if item.torrent:
el = ET.SubElement(entry, "link")
el.attrib['rel'] = 'enclosure'
el.attrib['type'] = 'application/x-bittorrent'
el.attrib['href'] = '%s/torrent/' % page_link
el.attrib['length'] = '%s' % ox.getTorrentSize(item.torrent.path)
#FIXME: loop over streams #FIXME: loop over streams
#for s in item.streams().filter(resolution=max(settings.CONFIG['video']['resolutions'])):
for s in item.streams().filter(source=None): for s in item.streams().filter(source=None):
el = ET.SubElement(entry, "link") el = ET.SubElement(entry, "link")
el.attrib['rel'] = 'enclosure' el.attrib['rel'] = 'enclosure'
el.attrib['type'] = 'video/%s' % s.format el.attrib['type'] = 'video/%s' % s.format
el.attrib['href'] = '%s/%sp.%s' % (page_link, s.resolution, s.format) el.attrib['href'] = '%s/%sp.%s' % (page_link, s.resolution, s.format)
el.attrib['length'] = '%s'%s.video.size el.attrib['length'] = '%s'%s.video.size
el = ET.SubElement(entry, "link")
el.attrib['rel'] = 'enclosure'
el.attrib['type'] = 'application/x-bittorrent'
el.attrib['href'] = '%s/torrent/' % page_link
#el.attrib['length'] = unicode(item.size)
el = ET.SubElement(entry, "media:thumbnail") el = ET.SubElement(entry, "media:thumbnail")
thumbheight = 96 thumbheight = 96