Exemple #1
0
    def get_video_data(self, item):
        if item.get('published_parsed'):
            best_date = struct_time_to_datetime(item['published_parsed'])
        elif item.get('updated_parsed'):
            best_date = struct_time_to_datetime(item['updated_parsed'])
        else:
            best_date = None

        link = item.get('link')
        if 'links' in item:
            for possible_link in item.links:
                if possible_link.get('rel') == 'via':
                    # original URL
                    link = possible_link['href']
                    break
        if ('content' in item and item['content'] and
            item['content'][0]['value']): # Atom
            description = item['content'][0]['value']
        else:
            description = item.get('summary', '')

        files = [VideoFile(url=enclosure.get('url'),
                           mime_type=enclosure.get('type'),
                           length=(enclosure.get('filesize') or
                                   enclosure.get('length')))
                 for enclosure in get_accepted_enclosures(item)]

        embed_code = None
        if 'media_player' in item:
            player = item['media_player']
            if player.get('content'):
                embed_code = convert_entities(player['content'])
            elif 'url' in player:
                files.append(VideoFile(
                                     url=player['url'],
                                     mime_type=player.get('type')))
        if not files:
            files = None
        if 'media_license' in item:
            license = item['media_license']['href']
        else:
            license = item.get('license')
        return {
            'link': link,
            'title': convert_entities(item.get('title', '')),
            'description': description,
            'thumbnail_url': get_entry_thumbnail_url(item),
            'files': files,
            'publish_datetime': best_date,
            'guid': item.get('id'),
            'embed_code': embed_code,
            'tags': [tag['term'] for tag in item['tags']
                     if tag['scheme'] is None] if 'tags' in item else None,
            'license': license
        }
Exemple #2
0
    def parse_feed_entry(self, entry):
        enclosure = get_first_accepted_enclosure(entry)
        if "published_parsed" in entry:
            best_date = struct_time_to_datetime(entry["published_parsed"])
        elif "updated_parsed" in entry:
            best_date = struct_time_to_datetime(entry["updated_parsed"])
        else:
            best_date = None

        link = entry.get("link")
        if "links" in entry:
            for possible_link in entry.links:
                if possible_link.get("rel") == "via":
                    # original URL
                    link = possible_link["href"]
                    break
        if "content" in entry and entry["content"] and entry["content"][0]["value"]:  # Atom
            description = entry["content"][0]["value"]
        else:
            description = entry.get("summary", "")

        embed_code = None
        if "media_player" in entry:
            player = entry["media_player"]
            if player.get("content"):
                embed_code = convert_entities(player["content"])
            elif "url" in player:
                embed_code = make_embed_code(player["url"], "")
        if "media_license" in entry:
            license = entry["media_license"]["href"]
        else:
            license = entry.get("license")
        return {
            "link": link,
            "title": convert_entities(entry["title"]),
            "description": description,
            "thumbnail_url": get_entry_thumbnail_url(entry),
            "file_url": enclosure.get("url") if enclosure else None,
            "file_url_mimetype": enclosure.get("type") if enclosure else None,
            "file_url_length": ((enclosure.get("filesize") or enclosure.get("length")) if enclosure else None),
            "publish_datetime": best_date,
            "guid": entry.get("id"),
            "embed_code": embed_code,
            "tags": [tag["term"] for tag in entry["tags"] if tag["scheme"] is None] if "tags" in entry else None,
            "license": license,
        }
Exemple #3
0
    def parse_feed_entry(self, entry):
        enclosure = get_first_accepted_enclosure(entry)
        if 'published_parsed' in entry:
            best_date = struct_time_to_datetime(entry['published_parsed'])
        elif 'updated_parsed' in entry:
            best_date = struct_time_to_datetime(entry['updated_parsed'])
        else:
            best_date = None

        link = entry.get('link')
        if 'links' in entry:
            for possible_link in entry.links:
                if possible_link.get('rel') == 'via':
                    # original URL
                    link = possible_link['href']
                    break
        if ('content' in entry and entry['content'] and
            entry['content'][0]['value']): # Atom
            description = entry['content'][0]['value']
        else:
            description = entry['summary'] or ''

        embed_code = None
        if 'media_player' in entry:
            player = entry['media_player']
            if player.get('content'):
                embed_code = convert_entities(player['content'])
            elif 'url' in player:
                embed_code = make_embed_code(player['url'], '')

        return {
            'link': link,
            'title': convert_entities(entry['title']),
            'description': description,
            'thumbnail_url': get_entry_thumbnail_url(entry),
            'file_url': enclosure.get('url') if enclosure else None,
            'file_url_mimetype': enclosure.get('type') if enclosure else None,
            'file_url_length': ((enclosure.get('filesize') or
                                enclosure.get('length'))
                                if enclosure else None),
            'publish_datetime': best_date,
            'guid': entry.get('id'),
            'embed_code': embed_code,
            'tags': [tag['term'] for tag in entry['tags']
                     if tag['scheme'] is None] if 'tags' in entry else None
            }
Exemple #4
0
    def get_video_data(self, item):
        if item.get('published_parsed'):
            best_date = struct_time_to_datetime(item['published_parsed'])
        elif item.get('updated_parsed'):
            best_date = struct_time_to_datetime(item['updated_parsed'])
        else:
            best_date = None

        link = item.get('link')
        if 'links' in item:
            for possible_link in item.links:
                if possible_link.get('rel') == 'via':
                    # original URL
                    link = possible_link['href']
                    break
        if ('content' in item and item['content']
                and item['content'][0]['value']):  # Atom
            description = item['content'][0]['value']
        else:
            description = item.get('summary', '')

        files = [
            VideoFile(url=enclosure.get('url'),
                      mime_type=enclosure.get('type'),
                      length=(enclosure.get('filesize')
                              or enclosure.get('length')))
            for enclosure in get_accepted_enclosures(item)
        ]

        embed_code = None
        if 'media_player' in item:
            player = item['media_player']
            if player.get('content'):
                embed_code = convert_entities(player['content'])
            elif 'url' in player:
                files.append(
                    VideoFile(url=player['url'], mime_type=player.get('type')))
        if not files:
            files = None
        if 'media_license' in item:
            license = item['media_license']['href']
        else:
            license = item.get('license')
        return {
            'link':
            link,
            'title':
            convert_entities(item.get('title', '')),
            'description':
            description,
            'thumbnail_url':
            get_entry_thumbnail_url(item),
            'files':
            files,
            'publish_datetime':
            best_date,
            'guid':
            item.get('id'),
            'embed_code':
            embed_code,
            'tags':
            [tag['term'] for tag in item['tags']
             if tag['scheme'] is None] if 'tags' in item else None,
            'license':
            license
        }