Example #1
0
	def get_image_xml(self):
		if self.is_image():
			return myxml.em(u'image', {
				'original': myxml.uri(os.path.basename(self.name)),
				'medium': myxml.uri(os.path.basename(self.img_medium)),
				})
		return u''
Example #2
0
	def makeXML(self):
		artist, album = self.find_meta()
		contents = u'' # u'<?xml version="1.0"?>\n<album name=%s artist=%s>' % (escape(album), escape(artist))
		for w, m in [(u'tracks', File.get_track_xml), (u'images', File.get_image_xml), (u'files', File.get_file_xml)]:
			contents += myxml.em(w, content=u''.join([m(file) for file in self.files]), empty=False)

		xml = u'<?xml version="1.0"?>\n'
		xml += myxml.em(u'album', {
			'artist': artist,
			'name': album,
			'owner': self.owner,
		}, contents)

		filename = os.path.join(self.tmpdir, 'album.xml')
		open(filename, 'w').write(xml.encode('utf-8'))
		self.files.append(File(filename))
Example #3
0
	def get_file_xml(self):
		if not self.is_audio() and not self.is_image():
			name = os.path.basename(self.name)
			size = os.path.getsize(self.name)
			return myxml.em('file', {
				'name': name,
				'uri': myxml.uri(name),
				'type': self.type[0],
				'size': os.path.getsize(self.name),
			})
		return u''
Example #4
0
	def get_track_xml(self):
		if self.is_audio():
			try:
				tracknumber = int(self.tag('tracknumber').split('/')[0])
			except:
				tracknumber = None
			return myxml.em(u'track', {
				'artist': self.tag('artist'),
				'title': self.tag('title'),
				'number': tracknumber,
				'duration': self.duration,
				'mp3-link': myxml.uri(os.path.basename(self.mp3_online)),
				'ogg-link': myxml.uri(os.path.basename(self.ogg_online)),
			})
		return u''
Example #5
0
    def sendRSS(self, items, title=None, link="", description=None):
        base = self.getBaseURL()
        content = u""

        if not title:
            title = u"Новости сайта " + self.getHost()
        if not description:
            description = title

        content += xml.em(u"title", content=title)
        content += xml.em(u"link", content=base + link)
        content += xml.em(u"description", content=xml.cdata(description))
        content += xml.em(u"atom:link", {"href": self.request.url, "rel": "self", "type": "application/rss+xml"})
        content += xml.em(u"language", content=u"ru")

        for item in items:
            entry = xml.em(u"title", content=xml.cdata(item["title"]))
            entry += xml.em(u"link", content=base + item["link"])
            if "description" not in item.keys():
                item["description"] = item["title"]
            entry += xml.em(u"description", content=xml.cdata(item["description"]))
            entry += xml.em(u"guid", {"isPermaLink": "true"}, content=base + item["link"])
            if "author" in item:
                entry += xml.em(u"author", content=item["author"])
            if "_" in item.keys():
                entry += item["_"]
            content += xml.em(u"item", content=entry)
        self.response.headers["Content-Type"] = "text/xml; charset=utf-8"
        self.response.out.write(
            xml.em(
                u"rss",
                {"version": "2.0", "xmlns:atom": "http://www.w3.org/2005/Atom"},
                xml.em(u"channel", content=content),
            )
        )