示例#1
0
文件: views.py 项目: kmshi/miroguide
    def __init__(self, url, name=None, description=None,
                 date=None, thumbnail_url=None):
        self.url = url
        self.name = name
        self.description = description
        self.date = date
        self.thumbnail_url = thumbnail_url

        self.fake = True

        self.mime_type = filetypes.guessMimeType(self.url)
示例#2
0
    def __init__(self,
                 url,
                 name=None,
                 description=None,
                 date=None,
                 thumbnail_url=None):
        self.url = url
        self.name = name
        self.description = description
        self.date = date
        self.thumbnail_url = thumbnail_url

        self.fake = True

        self.mime_type = filetypes.guessMimeType(self.url)
示例#3
0
文件: models.py 项目: kmshi/miroguide
 def from_feedparser_entry(entry):
     # XXX Added some hacks to get a decent item out of YouTube after they
     # stopped having enclosures (2008-1-21).
     enclosure = feedutil.get_first_video_enclosure(entry)
     if enclosure is None:
         if 'link' not in entry:
             raise exceptions.FeedparserEntryError(
                 "No video enclosure and ngo link")
         if entry['link'].find('youtube.com') == -1:
             if not filetypes.isAllowedFilename(entry['link']):
                 raise exceptions.EntryMissingDataError('Link is invalid')
     rv = Item()
     try:
         rv.name = feedutil.to_utf8(entry['title'])
         if enclosure is not None:
             rv.url = feedutil.to_utf8(enclosure['href'])
             # split off the front if there's additional data in the
             # MIME type
             if 'type' in enclosure:
                 rv.mime_type = feedutil.to_utf8(enclosure['type']
                                                 ).split(';', 1)[0]
             else:
                 rv.mime_type = 'video/unknown'
         elif entry['link'].find('youtube.com') != -1:
             rv.url = entry['link']
             rv.mime_type = 'video/x-flv'
         else:
             rv.url = entry['link']
             rv.mime_type = filetypes.guessMimeType(rv.url)
         if enclosure is not None and 'text' in enclosure:
             rv.description = feedutil.to_utf8(enclosure['text'])
         elif 'description' in entry:
             rv.description = feedutil.to_utf8(entry['description'])
         elif 'media_description' in entry:
             rv.description = feedutil.to_utf8(entry['media_description'])
         elif entry.get('link', '').find('youtube.com') != -1:
             match = re.search(r'<div><span>(.*?)</span></div>',
                               rv.description, re.S)
             if match:
                 rv.description = feedutil.to_utf8(
                     saxutils.unescape(match.group(1)))
         rv.description # this will raise an AttributeError if it wasn't set
     except (AttributeError, KeyError), e:
         raise exceptions.EntryMissingDataError(e.args[0])
示例#4
0
文件: models.py 项目: kmshi/miroguide
 def from_feedparser_entry(entry):
     # XXX Added some hacks to get a decent item out of YouTube after they
     # stopped having enclosures (2008-1-21).
     enclosure = feedutil.get_first_video_enclosure(entry)
     if enclosure is None:
         if 'link' not in entry:
             raise exceptions.FeedparserEntryError(
                 "No video enclosure and ngo link")
         if entry['link'].find('youtube.com') == -1:
             if not filetypes.isAllowedFilename(entry['link']):
                 raise exceptions.EntryMissingDataError('Link is invalid')
     rv = Item()
     try:
         rv.name = feedutil.to_utf8(entry['title'])
         if enclosure is not None:
             rv.url = feedutil.to_utf8(enclosure['href'])
             # split off the front if there's additional data in the
             # MIME type
             if 'type' in enclosure:
                 rv.mime_type = feedutil.to_utf8(enclosure['type']).split(
                     ';', 1)[0]
             else:
                 rv.mime_type = 'video/unknown'
         elif entry['link'].find('youtube.com') != -1:
             rv.url = entry['link']
             rv.mime_type = 'video/x-flv'
         else:
             rv.url = entry['link']
             rv.mime_type = filetypes.guessMimeType(rv.url)
         if enclosure is not None and 'text' in enclosure:
             rv.description = feedutil.to_utf8(enclosure['text'])
         elif 'description' in entry:
             rv.description = feedutil.to_utf8(entry['description'])
         elif 'media_description' in entry:
             rv.description = feedutil.to_utf8(entry['media_description'])
         elif entry.get('link', '').find('youtube.com') != -1:
             match = re.search(r'<div><span>(.*?)</span></div>',
                               rv.description, re.S)
             if match:
                 rv.description = feedutil.to_utf8(
                     saxutils.unescape(match.group(1)))
         rv.description  # this will raise an AttributeError if it wasn't set
     except (AttributeError, KeyError), e:
         raise exceptions.EntryMissingDataError(e.args[0])