From 06069b71e26bb9400d97398cc8af82b6f29cf9c4 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 17 Jan 2012 16:09:45 +0530 Subject: [PATCH] match places/events in any case, update url-list in torrent to match current url --- pandora/annotation/models.py | 1 - pandora/annotation/tasks.py | 4 ++-- pandora/item/models.py | 8 ++++++++ pandora/item/views.py | 16 +++++++++------- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index 97422e28d..1af88dedb 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -29,7 +29,6 @@ def get_matches(obj, model, layer_type): if name in othername: super_matches.append(othername) - exact = [l['id'] for l in filter(lambda l: l['type'] == layer_type, settings.CONFIG['layers'])] if exact: q = Q(value__iexact=obj.name) diff --git a/pandora/annotation/tasks.py b/pandora/annotation/tasks.py index 8a58d29c1..891ee44f4 100644 --- a/pandora/annotation/tasks.py +++ b/pandora/annotation/tasks.py @@ -15,7 +15,7 @@ def update_matching_events(id): for i in ids: e = Event.objects.get(pk=i) for name in [e.name] + list(e.alternativeNames): - if name in annotation.value: + if name.lower() in annotation.value.lower(): e.update_matches() break @@ -29,6 +29,6 @@ def update_matching_places(id): for i in ids: e = Place.objects.get(pk=i) for name in [e.name] + list(e.alternativeNames): - if name in annotation.value: + if name.lower() in annotation.value.lower(): e.update_matches() break diff --git a/pandora/item/models.py b/pandora/item/models.py index 616800287..4d7332d8c 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -901,6 +901,14 @@ class Item(models.Model): self.update_timeline() 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): streams = self.streams() if streams.count() == 0: diff --git a/pandora/item/views.py b/pandora/item/views.py index 780c95ae9..95e0a4657 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -723,8 +723,8 @@ def torrent(request, id, filename=None): if not item.torrent: raise Http404 if not filename or filename.endswith('.torrent'): - response = HttpFileResponse(item.torrent.path, - content_type='application/x-bittorrent') + response = HttpResponse(item.get_torrent(request), + content_type='application/x-bittorrent') filename = "%s.torrent" % item.get('title') response['Content-Disposition'] = 'attachment; filename="%s"' % filename.encode('utf-8') return response @@ -906,18 +906,20 @@ def atom_xml(request): el.text = u"1:1" 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 + #for s in item.streams().filter(resolution=max(settings.CONFIG['video']['resolutions'])): for s in item.streams().filter(source=None): el = ET.SubElement(entry, "link") el.attrib['rel'] = 'enclosure' el.attrib['type'] = 'video/%s' % s.format el.attrib['href'] = '%s/%sp.%s' % (page_link, s.resolution, s.format) 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") thumbheight = 96