Esempio n. 1
0
def search_youtube_by_keyword(keyword=None, popular=False, max_results=10,
                              start_index=1, parent_control=False):
    url = 'http://gdata.youtube.com/feeds/api/videos'
    params = {
        'v': 2,
        'vq': keyword,
        'racy': 'exclude',
        'orderby': 'relevance',
        'alt': 'json',
        'max-results': max_results,
        'start-index': start_index
    }
    if popular:
        params['orderby'] = 'viewCount'

    if parent_control is True:
        params['safeSearch'] = 'strict'

    success, error, data = requests_get_json(url, params=params)

    if not success:
        logger.error('Searching YouTube by keyword failed: ' + error)
        return None
    if 'feed' in data and 'entry' in data['feed']:
        global last_search_count
        last_search_count = data['feed']['openSearch$totalResults']['$t']

        return data['feed']['entry']
Esempio n. 2
0
def search_youtube_by_keyword(keyword=None,
                              popular=False,
                              max_results=10,
                              start_index=1,
                              parent_control=False):
    url = 'http://gdata.youtube.com/feeds/api/videos'
    params = {
        'v': 2,
        'vq': keyword,
        'racy': 'exclude',
        'orderby': 'relevance',
        'alt': 'json',
        'max-results': max_results,
        'start-index': start_index
    }
    if popular:
        params['orderby'] = 'viewCount'

    if parent_control is True:
        params['safeSearch'] = 'strict'

    success, error, data = requests_get_json(url, params=params)

    if not success:
        logger.error('Searching YouTube by keyword failed: ' + error)
        return None
    if 'feed' in data and 'entry' in data['feed']:
        global last_search_count
        last_search_count = data['feed']['openSearch$totalResults']['$t']

        return data['feed']['entry']
Esempio n. 3
0
def search_youtube_by_user(username, parent_control=False):
    url = 'http://gdata.youtube.com/feeds/api/users/{}/uploads'.format(
        username)
    params = {'v': 2, 'alt': 'json', 'orderby': 'viewCount', 'max-results': 10}

    if parent_control is True:
        params['safeSearch'] = 'strict'

    success, error, data = requests_get_json(url, params=params)
    if not success:
        logger.error('Searching YouTube by keyword failed: ' + error)
        return None
    if 'feed' in data and 'entry' in data['feed']:
        global last_search_count
        last_search_count = data['feed']['openSearch$totalResults']['$t']

        return data['feed']['entry']
Esempio n. 4
0
def search_youtube_by_user(username, parent_control=False):
    url = 'http://gdata.youtube.com/feeds/api/users/{}/uploads'.format(username)
    params = {
        'v': 2,
        'alt': 'json',
        'orderby': 'viewCount',
        'max-results': 10
    }

    if parent_control is True:
        params['safeSearch'] = 'strict'

    success, error, data = requests_get_json(url, params=params)
    if not success:
        logger.error('Searching YouTube by keyword failed: ' + error)
        return None
    if 'feed' in data and 'entry' in data['feed']:
        global last_search_count
        last_search_count = data['feed']['openSearch$totalResults']['$t']

        return data['feed']['entry']