This module provides the main API for accessing the urlresolver features.
For most cases you probably want to use urlresolver.resolve() or urlresolver.choose_source().
See also
Given a list of HostedMediaFile representing web pages that are thought to be associated with media content this function checks which are playable and if there are more than one it pops up a dialog box displaying the choices.
Example:
sources = [HostedMediaFile(url='http://youtu.be/VIDEOID', title='Youtube [verified] (20 views)'),
HostedMediaFile(url='http://putlocker.com/file/VIDEOID', title='Putlocker (3 views)')]
source = urlresolver.choose_source(sources)
if source:
stream_url = source.resolve()
addon.resolve_url(stream_url)
else:
addon.resolve_url(False)
Opens the settings dialog for urlresolver and its plugins.
This can be called from your addon to provide access to global urlresolver settings. Each resolver plugin is also capable of exposing settings.
Note
All changes made to these setting by the user are global and will affect any addon that uses urlresolver and its plugins.
Takes a list of HostedMediaFile`s representing web pages that are thought to be associated with media content. If no resolver plugins exist to resolve a :class:`HostedMediaFile to a link to a media file it is removed from the list.
Resolve a web page to a media stream.
It is usually as simple as:
import urlresolver
media_url = urlresolver.resolve(web_url)
where web_url is the address of a web page which is associated with a media file and media_url is the direct URL to the media.
Behind the scenes, urlresolver will check each of the available resolver plugins to see if they accept the web_url in priority order (lowest priotity number first). When it finds a plugin willing to resolve the URL, it passes the web_url to the plugin and returns the direct URL to the media file, or False if it was not possible to resolve.
See also
This class represents a piece of media (file or stream) that is hosted somewhere on the internet. It may be instantiated with EITHER the url to the web page associated with the media file, OR the host name and a unique media_id used by the host to point to the media.
For example:
HostedMediaFile(url='http://youtube.com/watch?v=ABC123XYZ')
represents the same piece of media as:
HostedMediaFile(host='youtube.com', media_id='ABC123XYZ')
title is a free text field useful for display purposes such as in choose_source().
Note
If there is no resolver plugin to handle the arguments passed, the resulting object will evaluate to False. Otherwise it will evaluate to True. This is a handy way of checking whether a resolver exists:
hmf = HostedMediaFile('http://youtube.com/watch?v=ABC123XYZ')
if hmf:
print 'yay! we can resolve this one'
else:
print 'sorry :( no resolvers available to handle this one.')
Warning
If you pass url you must not pass host or media_id. You must pass either url or host AND media_id.
url (str): a URL to a web page that represents a piece of media.
host (str): the host of the media to be represented.
media_id (str): the unique ID given to the media by the host.
Returns the host of this HostedMediaFile.
Returns the media_id of this HostedMediaFile.
Returns the URL of this HostedMediaFile.
Resolves this HostedMediaFile to a media URL.
Example:
stream_url = HostedMediaFile(host='youtube.com', media_id='ABC123XYZ').resolve()
Note
This method currently uses just the highest priority resolver to attempt to resolve to a media URL and if that fails it will return False. In future perhaps we should be more clever and check to make sure that there are no more resolvers capable of attempting to resolve the URL first.
Returns True if the HostedMediaFile can be resolved.
Note
The following are exactly equivalent:
if HostedMediaFile('http://youtube.com/watch?v=ABC123XYZ').valid_url():
print 'resolvable!'
if HostedMediaFile('http://youtube.com/watch?v=ABC123XYZ'):
print 'resolvable!'