Esempio n. 1
0
def media_inspector(request):

    video_info = {}
    video_metadata = None
    ffprobe_exists = True

    if which('ffprobe') == None:
        ffprobe_exists = False
    # TODO: use this flag in view to add instructions to install ffprobe

    form = ImageForm(request.POST, request.FILES)
    if form.is_valid():
        file = request.FILES['file']
        
        # save to file
        image = Image(file = file)
        image.save()

        # metadata of file        
        #video_metadata = get_metadata(image.file.path) 
        #print video_metadata

        # ffprobe
        if ffprobe_exists:
            video_info = ffprobe(image.file.path)
            print json.dumps(video_info, indent=4)
            
            # Add warning checks
            if video_info.get('streams', None):
                for stream in video_info['streams']:
                    if stream.get('codec_type', None) == "audio":
                        stream['channel_layout_warning'] = (stream.get('channel_layout', None) in ["mono","stereo"])

    context = {'request': request, 'form': form, 'video_info': video_info, 'video_info_pretty': json.dumps(video_info), 'video_metadata': video_metadata, 'ffprobe_exists': ffprobe_exists }
    return render_to_response('media_inspector.html', context, context_instance=RequestContext(request))
Esempio n. 2
0
def profile(request):
    
    examples = {}
    examples["twurl"] = "Coming soon..."
    examples["python"] = """

import twitter

api = twitter.Api(
    base_url='https://api.twitter.com/1.1',
    consumer_key='YOUR_CONSUMER_KEY',
    consumer_secret='YOUR_CONSUMER_SECRET',
    access_token_key='YOUR_ACCESS_KEY',
    access_token_secret='YOUR_ACCESS_SECRET')
    
api.UpdateImage("/path/to/file")

"""
    
    api = get_twitter(request.user)
    response = None
        
    form = ImageForm(request.POST, request.FILES)
    if form.is_valid():
        file = request.FILES['file']
        
        # save to file
        image = Image(file = file)
        image.save()
        
        response = api.UpdateImage(image.file.path)
        
    context = {'request': request, 'examples': examples, 'form': form, 'response': response}
    return render_to_response('profile.html', context, context_instance=RequestContext(request))
Esempio n. 3
0
def profile(request):
    
    examples = {}
    examples["twurl"] = "Coming soon..."
    examples["python"] = """

import twitter

api = twitter.Api(
    base_url='https://api.twitter.com/1.1',
    consumer_key='YOUR_CONSUMER_KEY',
    consumer_secret='YOUR_CONSUMER_SECRET',
    access_token_key='YOUR_ACCESS_KEY',
    access_token_secret='YOUR_ACCESS_SECRET')
    
api.UpdateImage("/path/to/file")

"""
    
    api = get_twitter(request.user)
    response = None
        
    form = ImageForm(request.POST, request.FILES)
    if form.is_valid():
        file = request.FILES['file']
        
        # save to file
        image = Image(file = file)
        image.save()
        
        response = api.UpdateImage(image.file.path)
        
    context = {'request': request, 'examples': examples, 'form': form, 'response': response}
    return render_to_response('profile.html', context, context_instance=RequestContext(request))
Esempio n. 4
0
def media_inspector(request):

    video_info = {}
    video_metadata = None
    ffprobe_exists = True

    if which('ffprobe') == None:
        ffprobe_exists = False
    # TODO: use this flag in view to add instructions to install ffprobe

    form = ImageForm(request.POST, request.FILES)
    if form.is_valid():
        file = request.FILES['file']
        
        # save to file
        image = Image(file = file)
        image.save()

        # metadata of file        
        #video_metadata = get_metadata(image.file.path) 
        #print video_metadata

        # ffprobe
        if ffprobe_exists:
            video_info = ffprobe(image.file.path)
            print json.dumps(video_info, indent=4)
            
            # Add warning checks
            if video_info.get('streams', None):
                for stream in video_info['streams']:
                    if stream.get('codec_type', None) == "audio":
                        stream['channel_layout_warning'] = (stream.get('channel_layout', None) in ["mono","stereo"])

    context = {'request': request, 'form': form, 'video_info': video_info, 'video_info_pretty': json.dumps(video_info), 'video_metadata': video_metadata, 'ffprobe_exists': ffprobe_exists }
    return render_to_response('media_inspector.html', context, context_instance=RequestContext(request))
def media(request, type, template):
    
    log = Log()

    api = get_twitter(request.user)
    response = {}
    metadata = None
        
    status = request.POST.get("status", None)
    media_type = request.POST.get("media_type", None)
    media_category = request.POST.get("media_category", None)
    upload_url = '%s/media/upload.json' % api.upload_url

    form = ImageForm(request.POST, request.FILES)
    if form.is_valid():
        file = request.FILES['file']
        
        # save to file
        image = Image(file=file)
        image.save()

        # metadata of file        
        metadata = get_metadata(image.file.path) 
        
        media_id = None
        
        if type == "video":
            result = media_upload_chunked(api, upload_url, image, media_type, media_category, log=log)
            response["media"] = result.get("upload", None)
            media_id = result.get("media_id", None)
            
        else:
            result = media_upload(api, upload_url, image, media_type, log=log)
            response["media"] = result.get("upload", None)
            media_id = result.get("media_id", None)
        
        # this is wrong, based on photo vs. video
        if media_id:
            data = {'status': status, 'media_ids': [media_id]}
            url = '%s/statuses/update.json' % api.base_url
            log.append("%s request: %s" % (url, data))
            json_data = api._RequestUrl(url, 'POST', data=data)
            json_data = json_data.content
            log.append("%s response: %s" % (url, json_data))

            data = None        
            if not 'error' in json_data and not 'errors' in json_data:
                data = api._ParseAndCheckTwitter(json_data)

            response['tweet'] = data
            
        response["log"] = log.out()
            
    context = {'request': request, 'form': form, 'response': response, 'metadata': metadata}
    return render_to_response(template, context, context_instance=RequestContext(request))
def profile(request):
    
    api = get_twitter(request.user)
    response = None
        
    form = ImageForm(request.POST, request.FILES)
    if form.is_valid():
        file = request.FILES['file']
        
        # save to file
        image = Image(file=file)
        image.save()
        
        response = api.UpdateImage(image.file.path)
        
    context = {'request': request, 'form': form, 'response': response}
    return render_to_response('profile.html', context, context_instance=RequestContext(request))
Esempio n. 7
0
def home(request):
    
    status = request.REQUEST.get("status", None)
    screen_name = request.REQUEST.get("screen_name", None)
    if not screen_name:
        screen_name = request.user.username
    
    api = get_twitter(request.user)
    if status:
        api.PostUpdates(status)
        
    form = ImageForm(request.POST, request.FILES)
    print "valid: %s (%s)" % (form.is_valid(), form.errors)
    if form.is_valid():
        file = request.FILES['file']
        
        # save to file
        image = Image(file = file)
        image.save()
        
        api.UpdateImage(image.file.path)
        
    statuses = []  
    max_id = None   
    while True:
        
        # get latest page
        new_statuses = api.GetUserTimeline(screen_name=screen_name, count=200, max_id=max_id)

        # out of statuses: done
        if len(new_statuses) == 0:
            break

        max_id = min([s.id for s in new_statuses]) - 1
        statuses = statuses + new_statuses
        
        # reached max: done
        if len(statuses) >= 3200:
            break

    context = {"request": request, 'statuses': statuses, 'form': form}
    return render_to_response('home.html', context, context_instance=RequestContext(request))