class UOLMais(MediaAPI):
    __NAME__ = MediaHost.HOST_UOLMAIS

    SUCCESS_CODES = (10, )
    PROCESSING_CODES = (0, 1, 2, 3, 6, 11, 12, 13, 30, 31, 32, 33)
    REMOVED_CODES = (
        20,
        21,
        22,
    )
    ERROR_CODES = (
        60,
        70,
        71,
        72,
        73,
        74,
    )

    def __init__(self, mediahost):
        super(UOLMais, self).__init__(mediahost)
        from uolmais_lib import UOLMaisLib
        self._lib = UOLMaisLib()

    def authenticate(self):
        try:
            username = settings.UOLMAIS_USERNAME
        except AttributeError:
            raise Exception(_(u'Settings UOLMAIS_USERNAME is not set'))

        try:
            password = settings.UOLMAIS_PASSWORD
        except AttributeError:
            raise Exception(_(u'Settings UOLMAIS_PASSWORD is not set'))

        self._lib.authenticate(username, password)

    def upload(self, type, media_path, title, description, tags):
        tags = tags or []
        tags += DEFAULT_TAGS

        self.authenticate()

        pub_date = timezone.now()
        if settings.USE_TZ:
            local_timezone = pytz.timezone(settings.TIME_ZONE)
            pub_date = timezone.localtime(pub_date, local_timezone)

        with open(media_path, 'rb') as f:
            media_args = {
                'f': f,
                'pub_date': pub_date,
                'title': title,
                'description': description,
                'tags': u','.join(tags),
                'visibility': self._lib.VISIBILITY_ANYONE,
                'comments': self._lib.COMMENTS_NONE,
                'is_hot': False
            }

            if type == u'video':
                media_id = self._lib.upload_video(**media_args)
            elif type == u'audio':
                media_id = self._lib.upload_audio(**media_args)

        return self.get_info(media_id)

    def get_info(self, media_id):
        self.authenticate()
        result = super(UOLMais, self).get_info(media_id)
        result['id'] = media_id

        info = self._lib.get_private_info(media_id)
        public_info = self._lib.get_public_info(media_id)

        # Public information are available only when file are fully processed
        if public_info and public_info.get('duration'):
            duration = public_info['duration'].split(':')

            if len(duration) == 3:
                hours, minutes, seconds = duration
            else:
                minutes, seconds = duration
                minutes = int(minutes)
                hours = 0
                if minutes >= 60:
                    hours, minutes = divmod(minutes, 60)
            result['duration'] = time(int(hours), int(minutes), int(seconds))

        if info['status'] in self.SUCCESS_CODES:
            # Embed for audio
            if info['mediaType'] == u'P':
                embed = render_to_string(
                    'multimedias/uolmais/audio_embed.html',
                    {'media_id': media_id})
            else:
                embed = info['embedCode']

            result.update({
                u'title': info['title'],
                u'description': info['description'],
                u'thumbnail': info['thumbLarge'],
                u'tags': info['tags'],
                u'embed': embed,
                u'url': info['url'],
                u'status': u'ok',
                u'status_msg': info['status_description']
            })
        elif info['status'] in self.PROCESSING_CODES:
            result.update({
                u'status': u'processing',
                u'status_msg': info['status_description']
            })
        elif info['status'] in self.REMOVED_CODES:
            result.update({
                u'status': u'deleted',
                u'status_msg': info['status_description']
            })
        else:
            result.update({
                u'status': u'error',
                u'status_msg': info['status_description']
            })

        return result
 def __init__(self, mediahost):
     super(UOLMais, self).__init__(mediahost)
     from uolmais_lib import UOLMaisLib
     self._lib = UOLMaisLib()
class UOLMais(MediaAPI):
    __NAME__ = MediaHost.HOST_UOLMAIS

    SUCCESS_CODES = (10,)
    PROCESSING_CODES = (0, 1, 2, 3, 6, 11, 12, 13, 30, 31, 32, 33)
    REMOVED_CODES = (20, 21, 22)
    ERROR_CODES = (60, 70, 71, 72, 73, 74)

    def __init__(self, mediahost):
        super(UOLMais, self).__init__(mediahost)
        from uolmais_lib import UOLMaisLib

        self._lib = UOLMaisLib()

    def authenticate(self):
        try:
            username = settings.UOLMAIS_USERNAME
        except AttributeError:
            raise Exception(_(u"Settings UOLMAIS_USERNAME is not set"))

        try:
            password = settings.UOLMAIS_PASSWORD
        except AttributeError:
            raise Exception(_(u"Settings UOLMAIS_PASSWORD is not set"))

        self._lib.authenticate(username, password)

    def upload(self, type, media_path, title, description, tags):
        tags = tags or []
        tags += DEFAULT_TAGS

        self.authenticate()

        pub_date = timezone.now()
        if settings.USE_TZ:
            local_timezone = pytz.timezone(settings.TIME_ZONE)
            pub_date = timezone.localtime(pub_date, local_timezone)

        with open(media_path, "rb") as f:
            media_args = {
                "f": f,
                "pub_date": pub_date,
                "title": title,
                "description": description,
                "tags": u",".join(tags),
                "visibility": self._lib.VISIBILITY_ANYONE,
                "comments": self._lib.COMMENTS_NONE,
                "is_hot": False,
            }

            if type == u"video":
                media_id = self._lib.upload_video(**media_args)
            elif type == u"audio":
                media_id = self._lib.upload_audio(**media_args)

        return self.get_info(media_id)

    def get_info(self, media_id):
        self.authenticate()
        result = super(UOLMais, self).get_info(media_id)
        result["id"] = media_id

        info = self._lib.get_private_info(media_id)
        public_info = self._lib.get_public_info(media_id)

        # Public information are available only when file are fully processed
        if public_info and public_info.get("duration"):
            duration = public_info["duration"].split(":")

            if len(duration) == 3:
                hours, minutes, seconds = duration
            else:
                minutes, seconds = duration
                minutes = int(minutes)
                hours = 0
                if minutes >= 60:
                    hours, minutes = divmod(minutes, 60)
            result["duration"] = time(int(hours), int(minutes), int(seconds))

        if info["status"] in self.SUCCESS_CODES:
            # Embed for audio
            if info["mediaType"] == u"P":
                embed = render_to_string("multimedias/uolmais/audio_embed.html", {"media_id": media_id})
            else:
                embed = info["embedCode"]

            result.update(
                {
                    u"title": info["title"],
                    u"description": info["description"],
                    u"thumbnail": info["thumbLarge"],
                    u"tags": info["tags"],
                    u"embed": embed,
                    u"url": info["url"],
                    u"status": u"ok",
                    u"status_msg": info["status_description"],
                }
            )
        elif info["status"] in self.PROCESSING_CODES:
            result.update({u"status": u"processing", u"status_msg": info["status_description"]})
        elif info["status"] in self.REMOVED_CODES:
            result.update({u"status": u"deleted", u"status_msg": info["status_description"]})
        else:
            result.update({u"status": u"error", u"status_msg": info["status_description"]})

        return result
    def __init__(self, mediahost):
        super(UOLMais, self).__init__(mediahost)
        from uolmais_lib import UOLMaisLib

        self._lib = UOLMaisLib()
Exemple #5
0
 def __init__(self):
     super(UOLMais, self).__init__()
     self._lib = UOLMaisLib()
Exemple #6
0
class UOLMais(MediaAPI):

    def __init__(self):
        super(UOLMais, self).__init__()
        self._lib = UOLMaisLib()

    def authenticate(self):
        try:
            username = settings.UOLMAIS_USERNAME
        except AttributeError:
            raise Exception(_('Settings UOLMAIS_USERNAME is not set'))

        try:
            password = settings.UOLMAIS_PASSWORD
        except AttributeError:
            raise Exception(_('Settings UOLMAIS_PASSWORD is not set'))

        self._lib.authenticate(username, password)

    def video_upload(self, *args, **kwargs):
        return self.upload('video', *args, **kwargs)

    def audio_upload(self, *args, **kwargs):
        return self.upload('audio', *args, **kwargs)

    def upload(self, type, media_path, title, description, tags):
        tags = tags or []
        tags.append('virgula')

        self.authenticate()

        saopaulo_tz = pytz.timezone('America/Sao_Paulo')
        media_args = {
            'f': open(media_path, 'rb'),
            'pub_date': timezone.localtime(timezone.now(), saopaulo_tz),
            'title': title,
            'description': description,
            'tags': u','.join(tags),
            'visibility': UOLMaisLib.VISIBILITY_ANYONE,
            'comments': UOLMaisLib.COMMENTS_NONE,
            'is_hot': False
        }

        if type == 'video':
            media_id = self._lib.upload_video(**media_args)
        elif type == 'audio':
            media_id = self._lib.upload_audio(**media_args)

        return self.get_info(media_id)

    def get_info(self, media_id):
        result = super(UOLMais, self).get_info(media_id)
        result['id'] = media_id

        info = self._lib.get_by_id(media_id)

        if info:
            tags = u','.join([tag['description'] for tag in info['tags']])
            # Embed for audio
            if info['mediaType'] == 'P':
                embed = render_to_string('multimedias/uolmais/audio_embed.html',
                                         {'media_id': media_id})
            else:
                embed = info['embedCode']

            result.update({
                u'title': info['title'],
                u'description': info['description'],
                u'thumbnail': info['thumbLarge'],
                u'tags': tags,
                u'embed': embed,
                u'url': info['url'],
                u'status': 'ok',
            })
        else:
            result['status'] = 'error'

        return result
Exemple #7
0
class UOLMais(MediaAPI):
    __NAME__ = MediaHost.HOST_UOLMAIS

    SUCCESS_CODES = (10, )
    PROCESSING_CODES = (0, 1, 2, 3, 6, 11, 12, 13, 30, 31, 32, 33)
    REMOVED_CODES = (20, 21, 22, )
    ERROR_CODES = (60, 70, 71, 72, 73, 74, )

    def __init__(self, mediahost):
        super(UOLMais, self).__init__(mediahost)
        from uolmais_lib import UOLMaisLib
        self._lib = UOLMaisLib()

    def authenticate(self):
        try:
            username = settings.UOLMAIS_USERNAME
        except AttributeError:
            raise Exception(_(u'Settings UOLMAIS_USERNAME is not set'))

        try:
            password = settings.UOLMAIS_PASSWORD
        except AttributeError:
            raise Exception(_(u'Settings UOLMAIS_PASSWORD is not set'))

        self._lib.authenticate(username, password)

    def upload(self, type, media_path, title, description, tags):
        tags = tags or []
        tags += DEFAULT_TAGS

        self.authenticate()

        pub_date = timezone.now()
        if settings.USE_TZ:
            local_timezone = pytz.timezone(settings.TIME_ZONE)
            pub_date = timezone.localtime(pub_date, local_timezone)

        with open(media_path, 'rb') as f:
            media_args = {
                'f': f,
                'pub_date': pub_date,
                'title': title,
                'description': description,
                'tags': u','.join(tags),
                'visibility': self._lib.VISIBILITY_ANYONE,
                'comments': self._lib.COMMENTS_NONE,
                'is_hot': False
            }

            if type == u'video':
                media_id = self._lib.upload_video(**media_args)
            elif type == u'audio':
                media_id = self._lib.upload_audio(**media_args)

        return self.get_info(media_id)

    def get_info(self, media_id):
        self.authenticate()
        result = super(UOLMais, self).get_info(media_id)
        result['id'] = media_id

        info = self._lib.get_private_info(media_id)
        public_info = self._lib.get_public_info(media_id)

        # Public information are available only when file are fully processed
        if public_info and public_info.get('duration'):
            duration = public_info['duration'].split(':')

            if len(duration) == 3:
                hours, minutes, seconds = duration
            else:
                minutes, seconds = duration
                minutes = int(minutes)
                hours = 0
                if minutes >= 60:
                     hours, minutes = divmod(minutes, 60)
            result['duration'] = time(int(hours), int(minutes), int(seconds))

        if info['status'] in self.SUCCESS_CODES:
            # Embed for audio
            if info['mediaType'] == u'P':
                embed = render_to_string(
                    'multimedias/uolmais/audio_embed.html',
                    {'media_id': media_id}
                )
            else:
                embed = info['embedCode']

            result.update({
                u'title': info['title'],
                u'description': info['description'],
                u'thumbnail': info['thumbLarge'],
                u'tags': info['tags'],
                u'embed': embed,
                u'url': info['url'],
                u'status': u'ok',
                u'status_msg': info['status_description']
            })
        elif info['status'] in self.PROCESSING_CODES:
            result.update({
                u'status': u'processing',
                u'status_msg': info['status_description']
            })
        elif info['status'] in self.REMOVED_CODES:
            result.update({
                u'status': u'deleted',
                u'status_msg': info['status_description']
            })
        else:
            result.update({
                u'status': u'error',
                u'status_msg': info['status_description']
            })

        return result
Exemple #8
0
 def __init__(self):
     super(UOLMais, self).__init__()
     from uolmais_lib import UOLMaisLib
     self._lib = UOLMaisLib()
Exemple #9
0
class UOLMais(MediaAPI):

    SUCCESS_CODES = (10, )
    PROCESSING_CODES = (0, 1, 2, 3, 6, 11, 12, 13, 30, 31, 32, 33)
    REMOVED_CODES = (20, 21, 22, )
    ERROR_CODES = (60, 70, 71, 72, 73, 74, )

    def __init__(self):
        super(UOLMais, self).__init__()
        from uolmais_lib import UOLMaisLib
        self._lib = UOLMaisLib()

    def authenticate(self):
        try:
            username = settings.UOLMAIS_USERNAME
        except AttributeError:
            raise Exception(_(u'Settings UOLMAIS_USERNAME is not set'))

        try:
            password = settings.UOLMAIS_PASSWORD
        except AttributeError:
            raise Exception(_(u'Settings UOLMAIS_PASSWORD is not set'))

        self._lib.authenticate(username, password)

    def video_upload(self, *args, **kwargs):
        return self.upload('video', *args, **kwargs)

    def audio_upload(self, *args, **kwargs):
        return self.upload('audio', *args, **kwargs)

    def upload(self, type, media_path, title, description, tags):
        tags = tags or []
        tags += DEFAULT_TAGS

        self.authenticate()

        saopaulo_tz = pytz.timezone('America/Sao_Paulo')
        with open(media_path, 'rb') as f:
            media_args = {
                'f': f,
                'pub_date': timezone.localtime(timezone.now(), saopaulo_tz),
                'title': title,
                'description': description,
                'tags': u','.join(tags),
                'visibility': self._lib.VISIBILITY_ANYONE,
                'comments': self._lib.COMMENTS_NONE,
                'is_hot': False
            }

            if type == u'video':
                media_id = self._lib.upload_video(**media_args)
            elif type == u'audio':
                media_id = self._lib.upload_audio(**media_args)

        return self.get_info(media_id)

    def get_info(self, media_id):
        self.authenticate()
        result = super(UOLMais, self).get_info(media_id)
        result['id'] = media_id

        info = self._lib.get_private_info(media_id)

        if info['status'] in self.SUCCESS_CODES:
            # Embed for audio
            if info['mediaType'] == u'P':
                embed = render_to_string(
                    'multimedias/uolmais/audio_embed.html',
                    {'media_id': media_id}
                )
            else:
                embed = info['embedCode']

            result.update({
                u'title': info['title'],
                u'description': info['description'],
                u'thumbnail': info['thumbLarge'],
                u'tags': info['tags'],
                u'embed': embed,
                u'url': info['url'],
                u'status': u'ok',
                u'status_msg': info['status_description']
            })
        elif info['status'] in self.PROCESSING_CODES:
            result.update({
                u'status': u'processing',
                u'status_msg': info['status_description']
            })
        elif info['status'] in self.REMOVED_CODES:
            result.update({
                u'status': u'deleted',
                u'status_msg': info['status_description']
            })
        else:
            result.update({
                u'status': u'error',
                u'status_msg': info['status_description']
            })

        return result