home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- __license__ = 'GPL v3'
- __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
- __docformat__ = 'restructuredtext en'
- from uuid import uuid4
- from calibre.constants import __appname__, __version__
- from calibre import strftime, prepare_string_for_xml as xml
- SONY_METADATA = u'<?xml version="1.0" encoding="utf-8"?>\n<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n\t\t xmlns:dcterms="http://purl.org/dc/terms/"\n\t\t xmlns:dc="http://purl.org/dc/elements/1.1/"\n\t\t xmlns:prs="http://xmlns.sony.net/e-book/prs/">\n\t<rdf:Description rdf:about="">\n\t\t<dc:title>{title}</dc:title>\n\t\t<dc:publisher>{publisher}</dc:publisher>\n\t\t<dcterms:alternative>{short_title}</dcterms:alternative>\n\t\t<dcterms:issued>{issue_date}</dcterms:issued>\n\t\t<dc:language>{language}</dc:language>\n\t\t<dcterms:conformsTo rdf:resource="http://xmlns.sony.net/e-book/prs/periodicals/1.0/newspaper/1.0"/>\n\t\t<dcterms:type rdf:resource="http://xmlns.sony.net/e-book/prs/datatype/newspaper"/>\n\t\t<dcterms:type rdf:resource="http://xmlns.sony.net/e-book/prs/datatype/periodical"/>\n\t</rdf:Description>\n</rdf:RDF>\n'
- SONY_ATOM = u'<?xml version="1.0" encoding="utf-8" ?>\n<feed xmlns="http://www.w3.org/2005/Atom"\n xmlns:dc="http://purl.org/dc/elements/1.1/"\n xmlns:dcterms="http://purl.org/dc/terms/"\n xmlns:prs="http://xmlns.sony.net/e-book/prs/"\n xmlns:media="http://video.search.yahoo.com/mrss"\n xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\n\n<title>{short_title}</title>\n<updated>{updated}</updated>\n<id>{id}</id>\n{entries}\n</feed>\n'
- SONY_ATOM_SECTION = u'<entry rdf:ID="{title}">\n <title>{title}</title>\n <link href="{href}"/>\n <id>{id}</id>\n <updated>{updated}</updated>\n <summary>{desc}</summary>\n <category term="{short_title}/{title}"\n scheme="http://xmlns.sony.net/e-book/terms/" label="{title}"/>\n <dc:type xsi:type="prs:datatype">newspaper/section</dc:type>\n <dcterms:isReferencedBy rdf:resource=""/>\n</entry>\n'
- SONY_ATOM_ENTRY = u'<entry>\n <title>{title}</title>\n <author><name>{author}</name></author>\n <link href="{href}"/>\n <id>{id}</id>\n <updated>{updated}</updated>\n <summary>{desc}</summary>\n <category term="{short_title}/{section_title}"\n scheme="http://xmlns.sony.net/e-book/terms/" label="{section_title}"/>\n <dcterms:extent xsi:type="prs:word-count">{word_count}</dcterms:extent>\n <dc:type xsi:type="prs:datatype">newspaper/article</dc:type>\n <dcterms:isReferencedBy rdf:resource="#{section_title}"/>\n</entry>\n'
-
- def sony_metadata(oeb):
- m = oeb.metadata
- title = short_title = unicode(m.title[0])
- publisher = __appname__ + ' ' + __version__
-
- try:
- pt = unicode(oeb.metadata.publication_type[0])
- short_title = u':'.join(pt.split(':')[2:])
- except:
- pass
-
-
- try:
- date = unicode(m.date[0]).split('T')[0]
- except:
- date = strftime('%Y-%m-%d')
-
-
- try:
- language = unicode(m.language[0]).replace('_', '-')
- except:
- language = 'en'
-
- short_title = xml(short_title, True)
- metadata = SONY_METADATA.format(title = xml(title), short_title = short_title, publisher = xml(publisher), issue_date = xml(date), language = xml(language))
- updated = strftime('%Y-%m-%dT%H:%M:%SZ')
-
- def cal_id(x):
- for k, v in x.attrib.items():
- if k.endswith('scheme') and v == 'uuid':
- return True
-
-
-
- try:
- base_id = unicode(list(filter(cal_id, m.identifier))[0])
- except:
- base_id = str(uuid4())
-
- entries = []
- seen_titles = set([])
- for i, section in enumerate(oeb.toc):
- if not section.href:
- continue
-
- secid = 'section%d' % i
- sectitle = section.title
- if not sectitle:
- sectitle = _('Unknown')
-
- d = 1
- bsectitle = sectitle
- while sectitle in seen_titles:
- sectitle = bsectitle + ' ' + str(d)
- d += 1
- seen_titles.add(sectitle)
- sectitle = xml(sectitle, True)
- secdesc = section.description
- if not secdesc:
- secdesc = ''
-
- secdesc = xml(secdesc)
- entries.append(SONY_ATOM_SECTION.format(title = sectitle, href = section.href, id = xml(base_id) + '/' + secid, short_title = short_title, desc = secdesc, updated = updated))
- for j, article in enumerate(section):
- if not article.href:
- continue
-
- atitle = article.title
- btitle = atitle
- d = 1
- while atitle in seen_titles:
- atitle = btitle + ' ' + str(d)
- d += 1
- auth = None if article.author else ''
- desc = section.description
- if not desc:
- desc = ''
-
- aid = 'article%d' % j
- entries.append(SONY_ATOM_ENTRY.format(title = xml(atitle), author = xml(auth), updated = updated, desc = desc, short_title = short_title, section_title = sectitle, href = article.href, word_count = str(1), id = xml(base_id) + '/' + secid + '/' + aid))
-
-
- atom = SONY_ATOM.format(short_title = short_title, entries = '\n\n'.join(entries), updated = updated, id = xml(base_id)).encode('utf-8')
- return (metadata, atom)
-
-