### Get Relevant Resolvers
Source: https://context7.com/gujal00/resolveurl/llms.txt
This example shows how to retrieve a list of available resolver plugins that match specific criteria using `relevant_resolvers()`. You can filter by domain, and include or exclude universal, disabled, or popup resolvers. The function can also order resolvers by priority.
```python
import resolveurl
# Get all enabled resolvers for a specific domain
youtube_resolvers = resolveurl.relevant_resolvers(domain='youtube.com')
print(f"YouTube resolvers: {youtube_resolvers}")
# Get all resolvers including disabled and universal
all_resolvers = resolveurl.relevant_resolvers(
include_universal=True,
include_disabled=True,
include_popups=True,
order_matters=True # Sort by priority
)
for resolver in all_resolvers:
print(f"{resolver.name}: domains={resolver.domains}, priority={resolver.priority}")
```
--------------------------------
### Select Video Source with choose_source()
Source: https://context7.com/gujal00/resolveurl/llms.txt
This example shows how to use the `choose_source()` function to filter and select a video source from a list of potential sources. It handles cases with multiple valid sources by presenting a user dialog, or auto-selecting if only one source is valid. It requires the `resolveurl` and `HostedMediaFile` classes.
```python
import resolveurl
from resolveurl import HostedMediaFile
# Create list of potential sources from scraping
sources = [
HostedMediaFile(url='https://youtube.com/watch?v=ABC123', title='YouTube [HD] (1000 views)'),
HostedMediaFile(url='https://vimeo.com/123456', title='Vimeo [1080p]')
HostedMediaFile(url='https://unknown-host.com/video', title='Unknown Host'),
]
# choose_source filters invalid sources and shows dialog if multiple valid
source = resolveurl.choose_source(sources)
if source:
stream_url = source.resolve()
print(f"Selected source resolved to: {stream_url}")
else:
print("No valid source selected or dialog cancelled")
```
--------------------------------
### Open ResolveURL Settings Dialog
Source: https://context7.com/gujal00/resolveurl/llms.txt
This example shows how to open the ResolveURL settings dialog using the `display_settings()` function. This dialog allows users to configure various aspects of the library, including resolver priorities, host enablement, and authentication for debrid services.
```python
import resolveurl
# Open settings dialog from your addon
resolveurl.display_settings()
# This opens a Kodi settings dialog with:
# - General settings (auto-pick, caching, universal resolvers)
# - Per-resolver settings (priority, enabled/disabled)
# - Debrid service authentication (Real-Debrid, AllDebrid, etc.)
```
--------------------------------
### Quick URL Resolution with resolveurl.resolve() in Python
Source: https://context7.com/gujal00/resolveurl/llms.txt
Illustrates the simplified `resolve()` function for one-liner URL resolution. This function internally creates a `HostedMediaFile` object and calls its `resolve` method, providing a convenient way to get stream URLs.
```python
import resolveurl
# Simple one-liner resolution
url = 'https://vimeo.com/123456789'
stream_url = resolveurl.resolve(url)
if stream_url:
# Use stream_url for playback
print(f"Stream URL: {stream_url}")
else:
print("Failed to resolve URL")
# With subtitles support
stream_url = resolveurl.resolve(url, subs=True)
```
--------------------------------
### Include ResolveURL Dependency in addon.xml
Source: https://github.com/gujal00/resolveurl/blob/master/README.md
XML snippet for your addon's `addon.xml` file to declare `script.module.resolveurl` as a dependency. This ensures the ResolveURL script is available and at least version 5.1.0 is installed.
```xml
```
--------------------------------
### Network Utilities for HTTP Requests
Source: https://context7.com/gujal00/resolveurl/llms.txt
Provides essential network utilities for making HTTP requests, including GET, POST, and HEAD methods. It allows for setting custom headers, handling responses, and extracting information like content length from headers.
```python
from resolveurl import common
# Create network instance
net = common.Net()
# GET request
response = net.http_GET(
'https://api.example.com/video/123',
headers={'User-Agent': common.RAND_UA}
)
html = response.content
cookies = response.get_cookies()
# POST request
data = {'action': 'get_video', 'id': '123'}
response = net.http_POST(
'https://api.example.com/action',
form_data=data,
headers={'User-Agent': common.RAND_UA}
)
# HEAD request (useful for checking file info without downloading)
response = net.http_HEAD('https://cdn.example.com/video.mp4')
headers = response.get_headers(as_dict=True)
content_length = headers.get('Content-Length')
```
--------------------------------
### Create Custom Resolver Plugin
Source: https://context7.com/gujal00/resolveurl/llms.txt
Demonstrates how to create a custom resolver plugin by extending the `ResolveUrl` base class. It includes defining supported domains, URL patterns, and methods for fetching media URLs, handling network requests, and defining custom settings.
```python
from resolveurl.resolver import ResolveUrl, ResolverError
from resolveurl.lib import helpers
from resolveurl import common
class MyCustomResolver(ResolveUrl):
name = 'MyHost'
domains = ['myhost.com', 'myhost.net']
pattern = r'(?://|\.)(myhost\.(?:com|net))/(?:embed/|video/)?([A-Za-z0-9]+)'
def get_media_url(self, host, media_id):
"""Resolve the video URL"""
web_url = self.get_url(host, media_id)
# Fetch the page
headers = {'User-Agent': common.RAND_UA}
html = self.net.http_GET(web_url, headers=headers).content
# Extract video sources
sources = helpers.scrape_sources(html)
if sources:
return helpers.pick_source(sources) + helpers.append_headers(headers)
raise ResolverError('Could not find video source')
def get_url(self, host, media_id):
"""Build URL from host and media_id"""
return f'https://{host}/embed/{media_id}'
@classmethod
def get_settings_xml(cls):
"""Define custom settings for this resolver"""
xml = super(cls, cls).get_settings_xml()
xml.append(f'')
return xml
```
--------------------------------
### Resolve URL with HostedMediaFile Class in Python
Source: https://context7.com/gujal00/resolveurl/llms.txt
Demonstrates the basic usage of the HostedMediaFile class to resolve a YouTube URL into a direct media stream. It shows how to instantiate the class with a URL or host/media_id and how to check for resolvable URLs.
```python
import resolveurl
# Basic URL resolution
url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
hmf = resolveurl.HostedMediaFile(url=url)
# Check if URL is resolvable (evaluates to True/False)
if hmf:
# Resolve to direct media URL
stream_url = hmf.resolve()
print(f"Resolved URL: {stream_url}")
# Output: plugin://plugin.video.youtube/play/?video_id=dQw4w9WgXcQ
else:
print("No resolver available for this URL")
# Alternative: using host and media_id
hmf = resolveurl.HostedMediaFile(host='youtube.com', media_id='dQw4w9WgXcQ')
stream_url = hmf.resolve()
```
--------------------------------
### Resolve XXX Content using ResolveURL in Python
Source: https://github.com/gujal00/resolveurl/blob/master/README.md
Python code demonstrating how to use ResolveURL to resolve URLs, including those handled by the XXX extension. After setting up the plugin paths, you can use `HostedMediaFile` as usual.
```python
hmf = resolveurl.HostedMediaFile(url)
if hmf:
resolved = hmf.resolve()
```
--------------------------------
### Add External Plugin Directories
Source: https://context7.com/gujal00/resolveurl/llms.txt
This snippet demonstrates how to load additional resolver plugins from external directories using `add_plugin_dirs()`. This is particularly useful for integrating extensions like `resolveurl.xxx` for adult content. It checks if the path exists using `xbmcvfs` before adding it.
```python
import resolveurl
import xbmcvfs
# Add path to external plugins
xxx_plugins_path = 'special://home/addons/script.module.resolveurl.xxx/resources/plugins/'
if xbmcvfs.exists(xxx_plugins_path):
translated_path = xbmcvfs.translatePath(xxx_plugins_path)
resolveurl.add_plugin_dirs(translated_path)
# Now resolve URLs - will include xxx resolvers
url = 'https://some-adult-host.com/video/123'
hmf = resolveurl.HostedMediaFile(url=url)
if hmf:
stream_url = hmf.resolve()
```
--------------------------------
### Basic ResolveURL Usage in Python
Source: https://github.com/gujal00/resolveurl/blob/master/README.md
Python code demonstrating how to import the ResolveURL module and use the `HostedMediaFile` class to resolve a given URL. It checks if the URL is valid and then attempts to resolve it.
```python
import resolveurl
hmf = resolveurl.HostedMediaFile(url)
if hmf:
resolved = hmf.resolve()
```
--------------------------------
### Magnet/Torrent Support via Debrid Services in Python
Source: https://context7.com/gujal00/resolveurl/llms.txt
Illustrates how universal resolvers, such as those for Real-Debrid, can handle magnet links and torrents. The `return_all=True` parameter can be used to retrieve a list of all video files within a torrent.
```python
import resolveurl
# Example for magnet link resolution (actual implementation depends on debrid service)
# magnet_link = 'magnet:?xt=urn:btih:...'
# hmf = resolveurl.HostedMediaFile(url=magnet_link, return_all=True)
# if hmf:
# files = hmf.resolve()
# # 'files' will be a list of dictionaries, each representing a file in the torrent
# for file_info in files:
# print(f"File: {file_info['filename']}, URL: {file_info['url']}")
```
--------------------------------
### Include ResolveURL and XXX Extension in addon.xml
Source: https://github.com/gujal00/resolveurl/blob/master/README.md
XML snippet for `addon.xml` to include both `script.module.resolveurl` and its adult resolver extension `script.module.resolveurl.xxx` as dependencies.
```xml
```
--------------------------------
### ResolveURL for Magnet Links with All Files in Python
Source: https://github.com/gujal00/resolveurl/blob/master/README.md
Python code demonstrating how to use ResolveURL to extract all files from a magnet link. The `return_all=True` argument is used, and the result is a list of dictionaries, each representing a file with its link.
```python
import resolveurl
hmf = resolveurl.HostedMediaFile(magnet, return_all=True)
if hmf:
allfiles = hmf.resolve()
# returns list of dictionaries
# pick the file you want to play with whatever logic
stream_url = allfiles[item].get('link')
if resolveurl.HostedMediaFile(stream_url):
stream_url = resolveurl.resolve(stream_url)
```
--------------------------------
### Add XXX Plugin Directories for ResolveURL in Python
Source: https://github.com/gujal00/resolveurl/blob/master/README.md
Python code to set up ResolveURL to recognize plugins from the `script.module.resolveurl.xxx` addon. It checks for the existence of the plugins directory and adds it to ResolveURL's search path.
```python
import resolveurl
import xbmcvfs
xxx_plugins_path = 'special://home/addons/script.module.resolveurl.xxx/resources/plugins/'
if xbmcvfs.exists(xxx_plugins_path):
resolveurl.add_plugin_dirs(xbmcvfs.translatePath(xxx_plugins_path))
```
--------------------------------
### Resolve and Play Video URL using ResolveURL in Python
Source: https://context7.com/gujal00/resolveurl/llms.txt
This Python snippet demonstrates how to use the ResolveURL library to resolve a video URL and prepare it for playback in Kodi. It handles cases where no resolver is found or if the resolution fails, providing user notifications for errors. It requires the `resolveurl` and `xbmc` modules.
```python
import xbmcgui
import xbmcplugin
import resolveurl
import sys
def play_video(url):
"""Resolve and play a video URL"""
# Check if URL is resolvable
hmf = resolveurl.HostedMediaFile(url=url, subs=True)
if not hmf:
xbmcgui.Dialog().notification(
'ResolveURL',
'No resolver found for this URL',
xbmcgui.NOTIFICATION_ERROR
)
return False
try:
# Resolve the URL
result = hmf.resolve()
if isinstance(result, dict):
stream_url = result.get('url')
subtitles = result.get('subs', {})
else:
stream_url = result
subtitles = {}
if not stream_url:
raise Exception('Resolution returned empty URL')
# Create playable item
li = xbmcgui.ListItem(path=stream_url)
# Add subtitles if available
if subtitles:
sub_urls = list(subtitles.values())
li.setSubtitles(sub_urls)
# Set resolved URL for playback
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, li)
return True
except Exception as e:
xbmcgui.Dialog().notification(
'ResolveURL Error',
str(e),
xbmcgui.NOTIFICATION_ERROR
)
return False
# In your addon
# addon.xml requires:
#
```
--------------------------------
### ResolveURL with Subtitle Fetching in Python
Source: https://github.com/gujal00/resolveurl/blob/master/README.md
Python code demonstrating how to use ResolveURL to not only resolve the media stream but also to fetch available subtitles. The `subs=True` argument is used, and subtitles are returned as a dictionary.
```python
import resolveurl
hmf = resolveurl.HostedMediaFile(url, subs=True)
if hmf:
resp = hmf.resolve()
resolved = resp.get('url')
# subs are returned as a dict with keys as lang and values as urls
subs = resp.get('subs')
```
--------------------------------
### Resolve Magnet Links and Hosted Media Files
Source: https://context7.com/gujal00/resolveurl/llms.txt
This snippet demonstrates how to resolve magnet links using ResolveURL. It shows how to create a HostedMediaFile object from a magnet link, retrieve all available files, select a file, and resolve its final stream URL. It handles cases where multiple files are present in the magnet link.
```python
import resolveurl
magnet = 'magnet:?xt=urn:btih:abc123...'
hmf = resolveurl.HostedMediaFile(url=magnet, return_all=True)
if hmf:
all_files = hmf.resolve()
# Returns list of dictionaries with file info
# [{'name': 'Movie.mkv', 'link': 'https://...'}, ...]
for idx, file in enumerate(all_files):
print(f"{idx}: {file.get('name')}")
# Pick desired file and resolve its link
selected = all_files[0] # or use dialog for user selection
stream_link = selected.get('link')
# Resolve the selected file's link
if resolveurl.HostedMediaFile(stream_link):
final_url = resolveurl.resolve(stream_link)
print(f"Final stream URL: {final_url}")
```
--------------------------------
### Helper Functions for Scraping Video Sources
Source: https://context7.com/gujal00/resolveurl/llms.txt
This snippet introduces the `helpers` module within `resolveurl.lib`, which provides utility functions for scraping video sources from HTML pages. These helpers are commonly used when developing custom resolver plugins for ResolveURL.
```python
from resolveurl.lib import helpers
from resolveurl import common
```
--------------------------------
### Unpack Obfuscated JavaScript
Source: https://context7.com/gujal00/resolveurl/llms.txt
Handles various JavaScript obfuscation techniques commonly found on video hosting sites. It can detect and unpack standard packed JavaScript, as well as specific formats like JuicyCodes.
```python
from resolveurl.lib import helpers, jsunpack
html_with_packed = """
"""
# Extract and unpack packed JavaScript
unpacked = helpers.get_packed_data(html_with_packed)
print(f"Unpacked JS: {unpacked}")
# Check if content is packed
if jsunpack.detect(html_with_packed):
unpacked = jsunpack.unpack(html_with_packed)
# Handle JuicyCodes obfuscation
juiced_html = """"""
decoded = helpers.get_juiced_data(juiced_html)
```
--------------------------------
### Scrape Supported URLs from HTML
Source: https://context7.com/gujal00/resolveurl/llms.txt
This snippet demonstrates how to use `scrape_supported()` to extract resolvable video links from HTML content. It can optionally use a custom regular expression or perform host-only validation for faster scraping. The function returns a list of supported URLs found within the provided HTML.
```python
import resolveurl
html_content = """
YouTube
Vimeo
Other
Dailymotion
"""
# Get all supported links from HTML
supported_links = resolveurl.scrape_supported(html_content)
print(f"Found {len(supported_links)} supported links:")
for link in supported_links:
print(f" {link}")
# Output will only include YouTube, Vimeo, Dailymotion URLs
# With custom regex pattern
custom_regex = r'''data-src\s*=\s*['"]([^'"]+)'''
links = resolveurl.scrape_supported(html_content, regex=custom_regex)
# Host-only validation (faster, doesn't validate full URL format)
links = resolveurl.scrape_supported(html_content, host_only=True)
```
--------------------------------
### ResolveURL with Referer URL in Python
Source: https://github.com/gujal00/resolveurl/blob/master/README.md
Python code showing how to pass a referer URL when resolving an embed URL using ResolveURL. The embed URL and referer URL are joined with `$$`.
```python
# You can pass referer url along with the embed url by joining them with `$$` when required as shown below
url: _embed_url_`$$`_referer_url_
```
--------------------------------
### Add Repository Information for ResolveURL
Source: https://github.com/gujal00/resolveurl/blob/master/README.md
XML snippet to include in your repository configuration to fetch the latest updates for ResolveURL. It specifies the URLs for the addons.xml file, its checksum, and the directory for zip archives.
```xml
https://raw.githubusercontent.com/Gujal00/smrzips/master/addons.xml
https://raw.githubusercontent.com/Gujal00/smrzips/master/addons.xml.md5
https://raw.githubusercontent.com/Gujal00/smrzips/master/zips/
```
--------------------------------
### Scrape Video Sources from HTML
Source: https://context7.com/gujal00/resolveurl/llms.txt
Extracts video source URLs from embedded HTML, supporting different quality labels. It can also automatically select the highest quality source or allow user selection. Finally, it appends necessary headers to the selected URL for playback.
```python
html = """
"
# Generic source scraping
sources = helpers.scrape_sources(html, result_blacklist=['.srt', '.vtt'])
print(f"Found sources: {sources}")
# Output: [('1080p', 'https://cdn.example.com/video_1080p.mp4'), ...]
# Let user pick or auto-select highest quality
selected_url = helpers.pick_source(sources, auto_pick=False)
print(f"Selected: {selected_url}")
# Append headers to URL for Kodi playback
headers = {'User-Agent': common.RAND_UA, 'Referer': 'https://example.com/'}
final_url = selected_url + helpers.append_headers(headers)
# Output: https://cdn.example.com/video_1080p.mp4|User-Agent=Mozilla...&Referer=https%3A...
```
--------------------------------
### ResolveURL with Content Type in Python
Source: https://github.com/gujal00/resolveurl/blob/master/README.md
Python code showing how to retrieve the MIME type of the resolved stream using ResolveURL. The `content_type=True` argument is passed to `HostedMediaFile`, and the MIME type is available in the response.
```python
import resolveurl
hmf = resolveurl.HostedMediaFile(url, content_type=True)
if hmf:
resp = hmf.resolve()
resolved = resp.get('url')
mimetype = resp.get('content-type')
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.