Example #1
0
def web_channel_data(channelid, load_video=None):
    channel_data = ws_request('/ws/-/channels/%s/' % channelid, size=40)
    selected_video = None
    if load_video:
        for instance in channel_data['videos']['items']:
            if instance['id'] == load_video:
                selected_video = instance
        # Not in the first 40 - try fetching separately:
        if not selected_video:
            try:
                video_data = ws_request(
                    '/ws/-/channels/%s/videos/%s/' % (channelid, load_video))
            except NotFound:
                pass
            else:
                if 'error' not in video_data:
                    selected_video = video_data
    channel_data['canonical_url'] = url_for(
        'channel', slug=slugify(channel_data['title']) or '-', channelid=channelid)
    if selected_video:
        channel_data['canonical_url'] += '?video=' + selected_video['id']
    return dict(channel_data=channel_data, selected_video=selected_video, api_urls=json.dumps(ws_request('/ws/')))
Example #2
0
 def process_redirect(self, increment_click_count=True):
     """Construct redirect url for link and record the click."""
     channel = Channel.query.with_entities(Channel.id, Channel.title)
     if self.object_type == 'video_instance':
         channel = channel.filter(
             (VideoInstance.channel == Channel.id) &
             (VideoInstance.id == self.object_id))
         params = dict(video=self.object_id)
     else:
         channel = channel.filter_by(id=self.object_id)
         params = dict()
     # TODO: Do something more friendly than throw a 404?
     channelid, title = channel.first_or_404()
     url = url_for('channel', slug=slugify(title) or '-', channelid=channelid)
     if params:
         # TODO: add utm tracking params for google analytics
         url += '?' + urlencode(params)
     if increment_click_count:
         ShareLink.increment_click_count(self.id)
     return {'url': url,
             'channel': channelid,
             'video': params.get('video', None),
             'user': self.user}