public class

YouTubeQuery

extends Query
java.lang.Object
   ↳ com.google.gdata.client.Query
     ↳ com.google.gdata.client.youtube.YouTubeQuery

Class Overview

A helper class that helps building queries for the YouTube feeds. Not all feeds implement all parameters defined on this class. See the documentation to get the list of parameters each feed supports.

Summary

Nested Classes
enum YouTubeQuery.OrderBy Standard values for the orderby parameter. 
enum YouTubeQuery.SafeSearch Standard values for the safeSearch parameter. 
enum YouTubeQuery.Time Standard values for the time parameter. 
enum YouTubeQuery.Uploader Standard values for the uploader parameter. 
Constants
String FORMAT
String LANGUAGE_RESTRICT
String LOCATION
String LOCATION_RADIUS
String ORDERBY
String RACY
String RACY_EXCLUDE
String RACY_INCLUDE
String RESTRICTION
String SAFE_SEARCH
String TIME
String UPLOADER
String VQ
[Expand]
Inherited Constants
From class com.google.gdata.client.Query
Fields
private static final Pattern COUNTRY_CODE_PATTERN
private static final Pattern IP_V4_PATTERN
private static final Pattern LOCATION_RADIUS_PATTERN
private static final Pattern RELEVANCE_LANGUAGE_PATTERN Prefix for specifying relevance by language.
[Expand]
Inherited Fields
From class com.google.gdata.client.Query
Public Constructors
YouTubeQuery(URL feedUrl)
Constructs a new YouTubeQuery object that targets a feed.
Public Methods
String getCountryRestriction()
Retrieves the country restriction set on the current query, if any.
Set<Integer> getFormats()
Gets the value of the format parameter.
boolean getIncludeRacy()
This method is deprecated. Please use getSafeSearch() instead.
String getIpRestriction()
Retrieves the IP restriction set on the current query, if any.
String getLanguageRestrict()
Gets the value of the lr parameter.
GeoRssWhere getLocation()
Returns the value of the location parameter.
String getLocationRadius()
Sets the value of the location-radius parameter.
String getOrderByRelevanceForLanguage()
Gets the language for which relevance ordering is optimized.
YouTubeQuery.OrderBy getOrderby()
Gets the value of the orderby parameter.
YouTubeQuery.SafeSearch getSafeSearch()
Gets the value of the safeSearch parameter.
YouTubeQuery.Time getTime()
Gets the value of the time parameter.
YouTubeQuery.Uploader getUploader()
Gets the value of the uploader parameter.
String getVideoQuery()
This method is deprecated. Please use getFullTextQuery() instead.
boolean hasRestrictLocation()
Returns true if the query only wants results that have latitude and longitude information.
void setCountryRestriction(String countryCode)
Sets the restriction parameter to a country code.
void setFormats(Set<Integer> formats)
Sets the value of the format parameter.
void setFormats(int... formats)
Sets the value of the format parameter.
void setIncludeRacy(Boolean includeRacy)
This method is deprecated. Please use #setSafeSearch(String) instead.
void setIpRestriction(String ip)
Sets the restriction parameter to an IP v4 address.
void setLanguageRestrict(String languageCode)
Sets the value of the lr parameter.
void setLocation(GeoRssWhere where)
Sets the value of the location parameter.
void setLocationRadius(String locationRadius)
Sets the value of the location-radius parameter.
void setOrderBy(YouTubeQuery.OrderBy orderBy)
Sets the value of the orderby parameter.
void setOrderByRelevanceForLanguage(String languageCode)
Sets order by relevance with results optimized for a specific language.
void setRestrictLocation(boolean isRestrictLocation)
Set/unset the location restrict.
void setSafeSearch(YouTubeQuery.SafeSearch safeSearch)
Sets the value of the safeSearch parameter.
void setTime(YouTubeQuery.Time time)
Sets the value of the time parameter.
void setUploader(YouTubeQuery.Uploader uploader)
Sets the value of the uploader parameter.
void setVideoQuery(String query)
This method is deprecated. Please use Query#setFullTextQuery() instead.
[Expand]
Inherited Methods
From class com.google.gdata.client.Query
From class java.lang.Object

Constants

private static final String FORMAT

Constant Value: "format"

private static final String LANGUAGE_RESTRICT

Constant Value: "lr"

private static final String LOCATION

Constant Value: "location"

private static final String LOCATION_RADIUS

Constant Value: "location-radius"

private static final String ORDERBY

Constant Value: "orderby"

private static final String RACY

Constant Value: "racy"

private static final String RACY_EXCLUDE

Constant Value: "exclude"

private static final String RACY_INCLUDE

Constant Value: "include"

private static final String RESTRICTION

Constant Value: "restriction"

private static final String SAFE_SEARCH

Constant Value: "safeSearch"

private static final String TIME

Constant Value: "time"

private static final String UPLOADER

Constant Value: "uploader"

private static final String VQ

Constant Value: "vq"

Fields

private static final Pattern COUNTRY_CODE_PATTERN

private static final Pattern IP_V4_PATTERN

private static final Pattern LOCATION_RADIUS_PATTERN

private static final Pattern RELEVANCE_LANGUAGE_PATTERN

Prefix for specifying relevance by language.

Public Constructors

public YouTubeQuery (URL feedUrl)

Constructs a new YouTubeQuery object that targets a feed. The initial state of the query contains no parameters, meaning all entries in the feed would be returned if the query was executed immediately after construction.

Parameters
feedUrl The URL of the feed against which queries will be executed.

Public Methods

public String getCountryRestriction ()

Retrieves the country restriction set on the current query, if any.

Returns
  • the current country restriction as a two letter ISO 3166 country code, or null if no country restriction is set.

public Set<Integer> getFormats ()

Gets the value of the format parameter.

Returns
  • all defined formats, might be empty but not null
Throws
NumberFormatException if the current value is invalid.

public boolean getIncludeRacy ()

This method is deprecated.
Please use getSafeSearch() instead.

Gets the value of the racy parameter.

Returns
  • true if the racy=include parameter is present

public String getIpRestriction ()

Retrieves the IP restriction set on the current query, if any.

Returns
  • the current IP v4 restriction or null if no IP restriction is set.

public String getLanguageRestrict ()

Gets the value of the lr parameter.

Returns
  • value of the lr parameter; a language code

public GeoRssWhere getLocation ()

Returns the value of the location parameter.

Returns
  • A GeoRssWhere element describing the center of where to search.

public String getLocationRadius ()

Sets the value of the location-radius parameter. Format is "100km". Valid units of measurement are "ft", "mi", "m", and "km".

Returns
  • The current search radius.

public String getOrderByRelevanceForLanguage ()

Gets the language for which relevance ordering is optimized.

Returns
Throws
IllegalStateException if ordering is not set to relevance

public YouTubeQuery.OrderBy getOrderby ()

Gets the value of the orderby parameter.

Returns
  • value of the orderby parameter.
Throws
IllegalStateException if a time value was found in the query that cannot be transformed into YouTubeQuery.OrderBy

public YouTubeQuery.SafeSearch getSafeSearch ()

Gets the value of the safeSearch parameter.

Returns
  • value of the safeSearch parameter.
Throws
IllegalStateException if a value was found in the query that cannot be transformed into YouTubeQuery.SafeSearch

public YouTubeQuery.Time getTime ()

Gets the value of the time parameter.

Returns
  • value of the time parameter
Throws
IllegalStateException if a time value was found in the query that cannot be transformed into YouTubeQuery.Time

public YouTubeQuery.Uploader getUploader ()

Gets the value of the uploader parameter.

Returns
  • value of the uploader parameter.
Throws
IllegalStateException if a value was found in the query that cannot be transformed into YouTubeQuery.Uploader

public String getVideoQuery ()

This method is deprecated.
Please use getFullTextQuery() instead.

Gets the value of the vq parameter.

Returns
  • current query string

public boolean hasRestrictLocation ()

Returns true if the query only wants results that have latitude and longitude information.

Returns
  • true if the query is restricted by location, false otherwise.

public void setCountryRestriction (String countryCode)

Sets the restriction parameter to a country code.

This parameter restricts the returned results to content available for clients in the specified country.

Only one of the setCountryRestriction(String) or setIpRestriction(String) should be used, using both will only take into consideration the last used.

Parameters
countryCode A two letter ISO-3166 country code, may be null to mean no restriction at all.
Throws
IllegalArgumentException if the given country code is not a well formated two letter country code.

public void setFormats (Set<Integer> formats)

Sets the value of the format parameter. See the documentation for a description of the different formats that are be available.

Parameters
formats Integer id of all the formats you are interested in. Videos will be returned if and only if they have downloadable content for at least one of these formats. null or an empty set removes the parameter

public void setFormats (int... formats)

Sets the value of the format parameter. See the documentation for a description of the different formats that are be available.

Parameters
formats Integer id of all the formats you are interested in. Videos will be returned if and only if they have downloadable content for at least one of these formats. No formats removes the parameter.

public void setIncludeRacy (Boolean includeRacy)

This method is deprecated.
Please use #setSafeSearch(String) instead.

Sets the value of the racy parameter.

Parameters
includeRacy true to include racy content, false to exclude it, null to remove the parameter

public void setIpRestriction (String ip)

Sets the restriction parameter to an IP v4 address.

This parameter restricts the returned results to content available for clients in the country that the provided IP address belongs to.

Only one of the setCountryRestriction(String) or setIpRestriction(String) should be used, using both will only take into consideration the last used.

Parameters
ip A v4 IP address and may be null to mean no restriction at all.
Throws
IllegalArgumentException if the given address is not a well formated IP v4 address.

public void setLanguageRestrict (String languageCode)

Sets the value of the lr parameter. This parameters restricts the videos that are returned to videos with its title, description and tags mostly in the specified language. It might be different from the language of the video itself.

Parameters
languageCode ISO 639-1 2-letter language code. zh-Hans for simplified chinese, zh-Hant for traditional chinese.

public void setLocation (GeoRssWhere where)

Sets the value of the location parameter.

Parameters
where A GeoRssWhere element describing the center of where to search.

public void setLocationRadius (String locationRadius)

Sets the value of the location-radius parameter. Format is "100km". Valid units of measurement are "ft", "mi", "m", and "km".

Parameters
locationRadius The requested search radius.

public void setOrderBy (YouTubeQuery.OrderBy orderBy)

Sets the value of the orderby parameter.

Parameters
orderBy Value of the orderby parameter, null to remove the parameter

public void setOrderByRelevanceForLanguage (String languageCode)

Sets order by relevance with results optimized for a specific language.

Parameters
languageCode null or ISO 639-1 2-letter language code. zh-Hans for simplified chinese, zh-Hant for traditional chinese.

public void setRestrictLocation (boolean isRestrictLocation)

Set/unset the location restrict.

Parameters
isRestrictLocation true if only videos that have latitude and longitude information are to be returned, false otherwise.

public void setSafeSearch (YouTubeQuery.SafeSearch safeSearch)

Sets the value of the safeSearch parameter.

Parameters
safeSearch Value of safeSearch parameter, null to remove the parameter

public void setTime (YouTubeQuery.Time time)

Sets the value of the time parameter.

Parameters
time Time value, null to remove the parameter

public void setUploader (YouTubeQuery.Uploader uploader)

Sets the value of the uploader parameter.

Parameters
uploader Value of the uploader parameter, null to remove the parameter

public void setVideoQuery (String query)

This method is deprecated.
Please use Query#setFullTextQuery() instead.

Sets the value of the vq parameter. The vq parameter is exactly equivalent to the q parameter.

Parameters
query Query string, null to remove the parameter