Пример #1
0
def get_videos_group(per_page=20, page=1, group_id='science'):
    """
    Gets videos for a given group
    :arg string channel id: Vimeo group id to get the videos
    :returns: A list of Videos.
    :rtype: list
    """
    try:
        v = vimeo.Client(key=config.CONSUMER_KEY,
                         secret=config.CONSUMER_SECRET)
        results = v.get('vimeo.groups.getVideos',
                        group_id=group_id,
                        per_page=per_page,
                        page=page)
        results = json.loads(results)
        videos = results['videos']['video']
        oembeds = []
        for v in videos:
            req = 'http://vimeo.com/%s' % v['id']
            url = 'http://vimeo.com/api/oembed.json?url=%s' % req
            payload = {'maxwidth': 512}
            res = requests.get(url, params=payload)
            if res.status_code == 200:
                oembeds.append(json.loads(res.text)['html'])
        # print oembeds
        return oembeds
    except:
        raise
        raise Exception(
            "config.py file not found, please copy config.py.template \
                        to config.py and fill in the OAuth parameters")
Пример #2
0
def cli(per_page, page, by_tags, by_channel, by_group, by_category, by_user,
        tagged, by_album):
    try:
        action = None
        filename = None
        query = dict(page=page, per_page=per_page)
        v = vimeo.Client(key=config.CONSUMER_KEY,
                         secret=config.CONSUMER_SECRET)
        if by_tags:
            click.secho("Getting videos from tags: %s" % by_tags, fg="yellow")
            action = 'vimeo.videos.getByTag'
            query['tag'] = by_tags
            filename = 'video_tasks_from_tags.json'
        elif by_channel:
            click.secho("Getting videos from channel: %s" % by_channel,
                        fg="yellow")
            action = 'vimeo.channels.getVideos'
            query['channel_id'] = by_channel
            filename = 'video_tasks_from_channel.json'
        elif by_group:
            click.secho("Getting videos from group: %s" % by_group,
                        fg="yellow")
            action = 'vimeo.groups.getVideos'
            query['group_id'] = by_group
            filename = 'video_tasks_from_group.json'
        elif by_category:
            click.secho("Getting videos from category: %s" % by_category,
                        fg="yellow")
            action = 'vimeo.categories.getRelatedVideos'
            query['category'] = by_category
            filename = 'video_tasks_from_category.json'
        elif by_user and tagged:
            click.secho("Getting videos tagged: %s from user: %s" %
                        (tagged, by_user))
            action = 'vimeo.videos.search'
            query['user_id'] = by_user
            query['query'] = tagged
            filename = 'video_tasks_from_user_tagged.json'
        elif by_album:
            click.secho("Getting videos from album: %s " % by_album)
            action = 'vimeo.albums.getVideos'
            query['album_id'] = by_album
            filename = 'video_tasks_from_album.json'
        else:
            raise click.UsageError(
                "Please use --help to see the available options")
        results = v.get(action, **query)
        write_results_to_json_file(results, filename)
        click.secho("Done!", fg="green")
    except:
        raise
        raise Exception(
            "config.py file not found, please copy config.py.template \
                        to config.py and fill in the OAuth parameters")
Пример #3
0
import math

parser = argparse.ArgumentParser()
parser.add_argument("media_dir", help="where the video files are stored")
parser.add_argument("input", help="schedule CSV to be parsed into JSON")
parser.add_argument("output", help="output JSON filename")
args = parser.parse_args()
INPUT_FILENAME = args.input
OUTPUT_FILENAME = args.output
#MEDIA_DIR = "../../media"
MEDIA_DIR = args.media_dir
YOUTUBE_API_KEY = "AIzaSyBNiJ9LRO4Kz2QvP7XelKByB6ZW0klj9Q8"

v = vimeo.Client(
    token="f56711a29d92ea38a30be43e3be8b026",
    key="b107e780eab4aa51e5db252cefc939481fc4491c",
    secret=
    "Ba3eQoaQz3FNsoaFKUsLkMGWM/4yILJkBHTwA8PN059qpcLOXF5T+sqgEYbYSfhH5lovEVg5bSULejchnGFMguoq2rIU6aMdynySsgmkRkLm5DtM+pOtC15LB45X0tAv"
)


def get_video_length(path):
    path = re.escape(path)
    cmd = 'ffprobe -i ' + path + ' -show_entries format=duration -v quiet -of csv="p=0"'
    result = subprocess.Popen(cmd,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT,
                              shell=True)
    output = result.communicate()
    return float(output[0]) * 1000

Пример #4
0
def get_results_page(request):
    """api de busquedas de paginas"""
    try:
        by_search = request.REQUEST['search']
    except KeyError:
        by_search = None
    
    try:
        by_search_you = request.REQUEST['search_you']
    except KeyError:
        by_search_you = None

    try:
        by_search_vi = request.REQUEST['search_vi']
    except KeyError:
        by_search_vi = None

    try:
        by_search_soundcl = request.REQUEST['search_soundcl']
    except KeyError:
        by_search_soundcl = None
        
    try:
        number_page = int(request.REQUEST['page'])
    except KeyError:
        number_page = 1
    
    try:
        limit = request.REQUEST['limit']
    except KeyError:
        limit = 2
    
    def check(foo):
        if foo:
            return foo.url
        else:
            return None

    def bar(foo):
        """obtener colecciones"""
        s = []
        for i in foo:
            s.append({
                'name': i.name,
                'visits': i.get_visits(),
                'body': i.body,
                'video': i.video,
                'id': i.id,
                'foto': i.foto,
                'path': i.path,
                'like': i.get_number_likes(),
                'nolike': i.get_number_nolikes(),
                'type': "current",
            })
        
        return s
    
    def set_filter(ejec, value):
        try:
            rj_type_search = "&search=" + request.REQUEST['search']
        except KeyError:
            rj_type_search = ""
        
        try:
            rj_type_search_you = "&search_you=" + request.REQUEST['search']
        except KeyError:
            rj_type_search_you = "&search_you=electro house trance"

        if ejec:
            if value:
                return "/process/api/pages/?page=" + str(number_page + 1) + "&limit="  + str(limit) + rj_type_search
            else:
                #return "/process/api/pages/?limit=8&start_index=1" + rj_type_search_you
                return None
        else:
            if value:
                return "/process/api/pages/?page=" + str(number_page - 1) + "&limit="  + str(limit)  + rj_type_search
            else:
                #return "/process/api/pages/?limit=8&start_index=1" + rj_type_search_you
                return None

    if by_search:
        m = by_search.split()
        list2d = []
        list2d.append(Page.objects.filter(name__icontains=by_search))
        for i in m:
            if i.__len__() > 2:
                list2d.append(Page.objects.filter(name__icontains=i))
        
        
        matches = [item for sublist in list2d for item in sublist]
        seen_titles = set()
        new_list = []
        for obj in matches:
            if obj.id not in seen_titles:
                new_list.append(obj)
                seen_titles.add(obj.id)
        
        p = Paginator(new_list, limit)
        
        page = p.page(number_page)
        
        send = bar(page.object_list)


    elif by_search_you:
        #searchs relations
        try:
            start_index = request.REQUEST['start_index']
        except KeyError:
            start_index = 1
        send = []
        uri = "http://gdata.youtube.com/feeds/api/videos?q=" + by_search_you + "&start-index=" + str(start_index) + "&max-results=" + str(limit) + "&v=2"
        videos = GetAndPrintUserUploads(uri)
        for i in videos.entry:
            send.append({
                'name': i.media.title.text,
                'visits': "0",
                'body': "cero",
                'video': i.media.player.url ,
                'id': "cero",
                'foto': i.media.thumbnail[3].url,
                'path': "cero",
                'like': "0",
                'nolike': "0",
                'type': "youtube",
                'urlplayer': i.media.player.url,
                
            })

        meta = {
            "next": "/process/api/pages/?limit=8&start_index=" + str(int(start_index) + 10) + "&search_you=" + by_search_you,
            "total_count": "0",
            'next_you': videos.link[4].href,
        }
    elif by_search_vi:
        send = []
        client = vimeo.Client(key='6a01aee5ad59757f7bc8138a5f7ec762ae86d414', secret='758e18407bd68f114cb72ef3bbdcace9c909ec5c', callback='http://fleet2001.herokuapp.com')
        videos = client.get('vimeo.videos.search', query=by_search_vi, page=number_page, per_page=limit)
        videos = videos.encode('ascii','ignore')
        videos = simplejson.loads(videos)
        for i in videos['videos']['video']:
            send.append({
                'name': i['title'],
                'visits': "0",
                'body': "cero",
                'video': i['id'] ,
                'id': "cero",
                'foto': i['thumbnails']['thumbnail'][0]['_content'],
                'path': "cero",
                'like': i['number_of_likes'],
                'nolike': "0",
                'type': "vimeo",            
            })
            
        meta = {
            "next": "/process/api/pages/?limit=8&page="+ str(number_page + 1) +"&search_vi=" + by_search_vi,
            "total_count": "0",
        }
    elif by_search_soundcl:
        try:
            start_index = request.REQUEST['start_index']
        except KeyError:
            start_index = 1
        send = []
        client = soundcloud.Client(client_id='f7e19128ac2ebf5679f6310167a1fcd2',
                                   client_secret='f24e173f7cc5d925171650b9436add7c',
                                   redirect_uri='http://fleet2001.herokuapp.com')
        tracks = client.get('/tracks', q=by_search_soundcl, license='cc-by-sa', limit=limit, offset=start_index)
        for i in tracks:
            obk = i.__dict__['obj']
            send.append({
                'name': obk['title'],
                'visits': "0",
                'body': "cero",
                'video': obk['uri'],
                'id': "cero",
                'foto': obk['artwork_url'],
                'path': "cero",
                'like': "0",
                'nolike': "0",
                'type': "soundcloud",            
            })
        meta = {
            "next": "/process/api/pages/?limit=8&start_index="+ str(int(start_index) + 8) +"&search_soundcl=" + by_search_soundcl,
            "total_count": "0",
        }
    else:
        matches = Page.objects.all()
        p = Paginator(matches, limit)
        
        page = p.page(number_page)
        send = bar(page.object_list)

    
    try:
        meta = meta
    except UnboundLocalError:
        meta = {
            "next": set_filter(True, page.has_next()),
            "previous": set_filter(False, page.has_previous()),
            "total_count": p.count,
            "pages": p.num_pages,
            "limit": int(limit),
        }
    
    send = simplejson.dumps({"meta": meta, "objects": send})
    
    return HttpResponse(send, "text/json")