Beispiel #1
0
def search_v2(query, order=None, start=0, size=10, region=None, client_address=None):
    params = {
        'q': query,
        'orderby': order,
        'start-index': start + 1,
        'max-results': size,
        'region': region,
        'restriction': client_address,
        'safeSearch': app.config.get('YOUTUBE_SAFESEARCH'),
    }
    if app.config.get('YOUTUBE_SEARCH_PARTNER_ONLY'):
        params['uploader'] = 'partner'
    data = _youtube_feed('videos', '', params)['feed']
    total = data['openSearch$totalResults']['$t']
    videos = [_get_video_data(e, id) for e in data.get('entry', [])]
    return Videolist(total, [v for v in videos if not v.restricted])
Beispiel #2
0
def search_v3(query, order=None, start=0, size=10, region=None, client_address=None):
    # new http instance required for thread-safety
    if not hasattr(_youtube_search_http, 'value'):
        _youtube_search_http.value = httplib2.Http()
    data = _youtube_search.list(
        q=query,
        type='video',
        part='snippet',
        order='date' if order == 'published' else order,
        pageToken=None,     # start number doesn't map to page token easily :-(
        maxResults=size,
        regionCode=region,
        userIp=client_address,
        safeSearch=app.config.get('YOUTUBE_SAFESEARCH'),
        videoEmbeddable='true',
    ).execute(http=_youtube_search_http.value)
    total = data['pageInfo']['totalResults']
    videos = [_get_video_data_v3(i) for i in data.get('items', [])]
    return Videolist(total, videos)