1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
##
# Copyright (C) 2015 Jessica T. (Tsyesika) <xray7224@googlemail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##
import logging
from pypump.models import (PumpObject, Likeable, Shareable, Commentable,
Deleteable, Uploadable, Mapper)
_log = logging.getLogger(__name__)
class MediaObject(PumpObject, Likeable, Shareable, Commentable, Deleteable, Uploadable):
object_type = 'dummy'
_ignore_attr = ["summary"]
_mapping = {
"stream": "stream",
"license": "license",
"embed_code": "embedCode",
}
def __init__(self, display_name=None, content=None, license=None, **kwargs):
super(MediaObject, self).__init__(**kwargs)
self.display_name = display_name
self.content = content
self.license = license
def __repr__(self):
return "<{type} by {webfinger}>".format(
type=self.object_type.capitalize(),
webfinger=getattr(self.author, 'webfinger', 'unknown')
)
def __unicode__(self):
return u"{type} by {webfinger}".format(
type=self.object_type,
webfinger=getattr(self.author, 'webfinger', 'unknown')
)
def _get_fileurl(self, data):
if data.get("pump_io", {}).get("proxyURL"):
return data["pump_io"]["proxyURL"]
else:
return data["url"]
def unserialize(self, data):
if "stream" in data:
stream = data["stream"]
self.stream = StreamContainer(
url=self._get_fileurl(stream)
)
Mapper(pypump=self._pump).parse_map(self, data=data)
self._add_links(data)
return self
class StreamContainer(object):
""" Container that holds information about a stream.
:param url: URL to the file on the pump.io server.
"""
def __init__(self, url):
self.url = url
def __repr__(self):
return "<Stream: {url}>".format(url=self.url)
class Video(MediaObject):
""" This object represents a pump.io **video** object,
video objects are used to post video content with optional text (or html) messages
to the pump.io network.
:param content: (optional) Video text content.
:param display_name: (optional) Video title.
Example:
>>> myogv = pump.Video(display_name='Happy Caturday!')
>>> myogv.from_file('/path/to/kitteh.ogv')
"""
object_type = 'video'
class Audio(MediaObject):
""" This object represents a pump.io **audio** object,
audio objects are used to post audio content with optional text (or html) messages
to the pump.io network.
:param content: (optional) Audio text content.
:param display_name: (optional) Audio title.
Example:
>>> myogg = pump.Audio(display_name='Happy Caturday!')
>>> myogg.from_file('/path/to/kitteh.ogg')
"""
object_type = 'audio'
class ImageContainer(object):
""" Container that holds information about an image.
:param url: URL to image file on the pump.io server.
:param width: Width of the image.
:param height: Height of the image.
"""
def __init__(self, url, width, height):
self.url = url
self.width = width
self.height = height
def __repr__(self):
return "<Image {width}x{height}>".format(
width=self.width,
height=self.height
)
class Image(MediaObject):
""" This object represents a pump.io **image**,
images are used to post image content with optional text (or html) messages
to the pump.io network.
:param content: (optional) Image text content.
:param display_name: (optional) Image title.
Example:
>>> myimage = pump.Image(display_name='Happy Caturday!')
>>> myimage.from_file('/path/to/kitteh.png')
"""
object_type = 'image'
_ignore_attr = ["summary", "image"]
_mapping = {
"thumbnail": "image",
"original": "fullImage",
"license": "license",
}
def unserialize(self, data):
if "image" in data:
thumbnail = data["image"]
self.thumbnail = ImageContainer(
url=self._get_fileurl(thumbnail),
height=thumbnail.get("height"),
width=thumbnail.get("width")
)
if "fullImage" in data:
full_image = data["fullImage"]
self.original = ImageContainer(
url=self._get_fileurl(full_image),
height=full_image.get("height"),
width=full_image.get("width")
)
else:
self.original = self.thumbnail
Mapper(pypump=self._pump).parse_map(self, data=data)
self._add_links(data)
return self
|