// SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue
// SPDX-License-Identifier: BSD-3-Clause
* Handles everything related to enclosures (including Media RSS and iTunes RSS)
* Used by {@see \SimplePie\Item::get_enclosure()} and {@see \SimplePie\Item::get_enclosures()}
* This class can be overloaded with {@see \SimplePie\SimplePie::set_enclosure_class()}
* @see get_restrictions()
* @see get_sampling_rate()
* Constructor, used to input the data
* For documentation on all the parameters, see the corresponding
* properties and their accessors
* @uses idn_to_ascii If available, this will convert an IDN
* @param null $javascript
* @param Caption[]|null $captions
* @param Category[]|null $categories
* @param Credit[]|null $credits
* @param string[]|null $hashes
* @param string[]|null $keywords
* @param Rating[]|null $ratings
* @param Restriction[]|null $restrictions
* @param string[]|null $thumbnails
public function __construct(
?array $categories = null,
?Copyright $copyright = null,
?string $description = null,
?string $expression = null,
?string $framerate = null,
?array $restrictions = null,
?string $samplingrate = null,
?array $thumbnails = null,
$this->bitrate = $bitrate;
$this->captions = $captions;
$this->categories = $categories;
$this->channels = $channels;
$this->copyright = $copyright;
$this->credits = $credits;
$this->description = $description;
$this->duration = $duration;
$this->expression = $expression;
$this->framerate = $framerate;
$this->keywords = $keywords;
$this->ratings = $ratings;
$this->restrictions = $restrictions;
$this->samplingrate = $samplingrate;
$this->thumbnails = $thumbnails;
if (function_exists('idn_to_ascii')) {
$parsed = \SimplePie\Misc::parse_url($link ?? '');
if ($parsed['authority'] !== '' && !ctype_print($parsed['authority'])) {
$authority = (string) \idn_to_ascii($parsed['authority'], \IDNA_NONTRANSITIONAL_TO_ASCII, \INTL_IDNA_VARIANT_UTS46);
$this->link = \SimplePie\Misc::compress_parse_url($parsed['scheme'], $authority, $parsed['path'], $parsed['query'], $parsed['fragment']);
$this->handler = $this->get_handler(); // Needs to load last
public function __toString()
// There is no $this->data here
return md5(serialize($this));
public function get_bitrate()
if ($this->bitrate !== null) {
* @return \SimplePie\Caption|null
public function get_caption(int $key = 0)
$captions = $this->get_captions();
if (isset($captions[$key])) {
public function get_captions()
if ($this->captions !== null) {
* @return \SimplePie\Category|null
public function get_category(int $key = 0)
$categories = $this->get_categories();
if (isset($categories[$key])) {
return $categories[$key];
* @return \SimplePie\Category[]|null
public function get_categories()
if ($this->categories !== null) {
return $this->categories;
* Get the number of audio channels
public function get_channels()
if ($this->channels !== null) {
* Get the copyright information
* @return \SimplePie\Copyright|null
public function get_copyright()
if ($this->copyright !== null) {
* @return \SimplePie\Credit|null
public function get_credit(int $key = 0)
$credits = $this->get_credits();
if (isset($credits[$key])) {
public function get_credits()
if ($this->credits !== null) {
* Get the description of the enclosure
public function get_description()
if ($this->description !== null) {
return $this->description;
* Get the duration of the enclosure
* @param bool $convert Convert seconds into hh:mm:ss
* @return string|int|null 'hh:mm:ss' string if `$convert` was specified, otherwise integer (or null if none found)
public function get_duration(bool $convert = false)
if ($this->duration !== null) {
$time = \SimplePie\Misc::time_hms($this->duration);
* @return string Probably one of 'sample', 'full', 'nonstop', 'clip'. Defaults to 'full'
public function get_expression()
if ($this->expression !== null) {
return $this->expression;
public function get_extension()
if ($this->link !== null) {
$url = \SimplePie\Misc::parse_url($this->link);
if ($url['path'] !== '') {
return pathinfo($url['path'], PATHINFO_EXTENSION);
* Get the framerate (in frames-per-second)
public function get_framerate()
if ($this->framerate !== null) {
* Get the preferred handler
* @return string|null One of 'flash', 'fmedia', 'quicktime', 'wmedia', 'mp3'
public function get_handler()
return $this->get_real_type(true);
* @link http://www.rssboard.org/media-rss#media-hash
* @return string|null Hash as per `media:hash`, prefixed with "$algo:"