Class Utils
java.lang.Object
org.schabi.newpipe.extractor.utils.Utils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidCheck if the url matches the pattern.static voidCheck if the url matches the pattern.static StringdecodeUrlUtf8(String url) Decodes a URL using the UTF-8 character set.static StringencodeUrlUtf8(String string) Encodes a string to URL format using the UTF-8 character set.static StringIf the provided url is a Google search redirect, then the actual url is extracted from theurl=query value and returned, otherwise the original url is returned.static StringgetBaseUrl(String url) static StringgetQueryValue(URL url, String parameterName) Get the value of a URL-query by name.static StringgetStringResultFromRegexArray(String input, String[] regexes) Find the result of an array of string regular expressions inside an input on the first group (0).static StringgetStringResultFromRegexArray(String input, String[] regexes, int group) Find the result of an array of string regular expressions inside an input on a specific group.static StringgetStringResultFromRegexArray(String input, Pattern[] regexes) Find the result of an array ofPatterns inside an input on the first group (0).static StringgetStringResultFromRegexArray(String input, Pattern[] regexes, int group) Find the result of an array ofPatterns inside an input on a specific group.static booleanstatic booleanstatic booleanisNullOrEmpty(String str) static booleanisNullOrEmpty(Collection<?> collection) Checks if a collection is null or empty.static <K,V> boolean isNullOrEmpty(Map<K, V> map) Checks if amapis null or empty.static Stringjoin(String delimiter, String mapJoin, Map<? extends CharSequence, ? extends CharSequence> elements) static longmixedNumberWordToLong(String numberWord) Convert a mixed number word to a long.static StringnonEmptyAndNullJoin(CharSequence delimiter, String... elements) Concatenate all non-null, non-empty and strings which are not equal to"null".static Stringstatic StringremoveNonDigitCharacters(String toRemove) Remove all non-digit characters from a string.static Stringstatic Stringstatic URLstringToURL(String url) Convert a string to aURL object.
-
Field Details
-
HTTP
- See Also:
-
HTTPS
- See Also:
-
-
Method Details
-
encodeUrlUtf8
Encodes a string to URL format using the UTF-8 character set.- Parameters:
string- The string to be encoded.- Returns:
- The encoded URL.
-
decodeUrlUtf8
Decodes a URL using the UTF-8 character set.- Parameters:
url- The URL to be decoded.- Returns:
- The decoded URL.
-
removeNonDigitCharacters
Remove all non-digit characters from a string.Examples:
- 1 234 567 views -> 1234567
- $31,133.124 -> 31133124
- Parameters:
toRemove- string to remove non-digit chars- Returns:
- a string that contains only digits
-
mixedNumberWordToLong
public static long mixedNumberWordToLong(String numberWord) throws NumberFormatException, ParsingException Convert a mixed number word to a long.Examples:
- 123 -> 123
- 1.23K -> 1230
- 1.23M -> 1230000
- Parameters:
numberWord- string to be converted to a long- Returns:
- a long
- Throws:
NumberFormatExceptionParsingException
-
checkUrl
Check if the url matches the pattern.- Parameters:
pattern- the pattern that will be used to check the urlurl- the url to be tested- Throws:
ParsingException
-
checkUrl
Check if the url matches the pattern.- Parameters:
pattern- the pattern that will be used to check the urlurl- the url to be tested- Throws:
ParsingException
-
replaceHttpWithHttps
-
getQueryValue
Get the value of a URL-query by name.If an url-query is give multiple times, only the value of the first query is returned.
- Parameters:
url- the url to be usedparameterName- the pattern that will be used to check the url- Returns:
- a string that contains the value of the query parameter or
nullif nothing was found
-
stringToURL
Convert a string to aURL object.Defaults to HTTP if no protocol is given.
- Parameters:
url- the string to be converted to a URL-Object- Returns:
- a
URL objectcontaining the url - Throws:
MalformedURLException
-
isHTTP
-
removeMAndWWWFromUrl
-
removeUTF8BOM
-
getBaseUrl
- Throws:
ParsingException
-
followGoogleRedirectIfNeeded
If the provided url is a Google search redirect, then the actual url is extracted from theurl=query value and returned, otherwise the original url is returned.- Parameters:
url- the url which can possibly be a Google search redirect- Returns:
- an url with no Google search redirects
-
isNullOrEmpty
-
isNullOrEmpty
Checks if a collection is null or empty.This method can be also used for
JsonArrays.- Parameters:
collection- the collection on which check if it's null or empty- Returns:
- whether the collection is null or empty
-
isNullOrEmpty
Checks if amapis null or empty.This method can be also used for
JsonObjects. -
isBlank
-
join
@Nonnull public static String join(String delimiter, String mapJoin, @Nonnull Map<? extends CharSequence, ? extends CharSequence> elements) -
nonEmptyAndNullJoin
Concatenate all non-null, non-empty and strings which are not equal to"null". -
getStringResultFromRegexArray
@Nonnull public static String getStringResultFromRegexArray(@Nonnull String input, @Nonnull String[] regexes) throws Parser.RegexException Find the result of an array of string regular expressions inside an input on the first group (0).- Parameters:
input- the input on which using the regular expressionsregexes- the string array of regular expressions- Returns:
- the result
- Throws:
Parser.RegexException- if none of the patterns match the input
-
getStringResultFromRegexArray
@Nonnull public static String getStringResultFromRegexArray(@Nonnull String input, @Nonnull Pattern[] regexes) throws Parser.RegexException Find the result of an array ofPatterns inside an input on the first group (0).- Parameters:
input- the input on which using the regular expressionsregexes- thePatternarray- Returns:
- the result
- Throws:
Parser.RegexException- if none of the patterns match the input
-
getStringResultFromRegexArray
@Nonnull public static String getStringResultFromRegexArray(@Nonnull String input, @Nonnull String[] regexes, int group) throws Parser.RegexException Find the result of an array of string regular expressions inside an input on a specific group.- Parameters:
input- the input on which using the regular expressionsregexes- the string array of regular expressionsgroup- the group to match- Returns:
- the result
- Throws:
Parser.RegexException- if none of the patterns match the input, or at least in the specified group
-
getStringResultFromRegexArray
@Nonnull public static String getStringResultFromRegexArray(@Nonnull String input, @Nonnull Pattern[] regexes, int group) throws Parser.RegexException Find the result of an array ofPatterns inside an input on a specific group.- Parameters:
input- the input on which using the regular expressionsregexes- thePatternarraygroup- the group to match- Returns:
- the result
- Throws:
Parser.RegexException- if none of the patterns match the input, or at least in the specified group
-