vendor/azuracast/php-api-client/src/Dto/MediaFileDto.php line 550

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace AzuraCast\Api\Dto;
  4. use JsonSerializable;
  5. class MediaFileDto implements JsonSerializable
  6. {
  7. /**
  8. * @var int
  9. */
  10. protected $id;
  11. /**
  12. * @var string
  13. */
  14. protected $songId;
  15. /**
  16. * @var string
  17. */
  18. protected $title;
  19. /**
  20. * @var string
  21. */
  22. protected $artist;
  23. /**
  24. * @var string
  25. */
  26. protected $album;
  27. /**
  28. * @var string
  29. */
  30. protected $lyrics;
  31. /**
  32. * @var string
  33. */
  34. protected $isrc;
  35. /**
  36. * @var int
  37. */
  38. protected $length;
  39. /**
  40. * @var string
  41. */
  42. protected $lengthText;
  43. /**
  44. * @var string
  45. */
  46. protected $path;
  47. /**
  48. * @var int
  49. */
  50. protected $mtime;
  51. /**
  52. * @var float
  53. */
  54. protected $fadeOverlap;
  55. /**
  56. * @var float
  57. */
  58. protected $fadeIn;
  59. /**
  60. * @var float
  61. */
  62. protected $fadeOut;
  63. /**
  64. * @var float
  65. */
  66. protected $cueIn;
  67. /**
  68. * @var float
  69. */
  70. protected $cueOut;
  71. /**
  72. * @var MediaFilePlaylistDto[]
  73. */
  74. protected $playlists;
  75. /**
  76. * @var string
  77. */
  78. protected $uniqueId;
  79. /**
  80. * @var MediaFileCustomFieldDto[]
  81. */
  82. protected $customFields;
  83. /**
  84. * @param int $id
  85. * @param string $songId
  86. * @param string $title
  87. * @param string $artist
  88. * @param string $album
  89. * @param string $lyrics
  90. * @param string $isrc
  91. * @param int $length
  92. * @param string $lengthText
  93. * @param string $path
  94. * @param int $mtime
  95. * @param float $fadeOverlap
  96. * @param float $fadeIn
  97. * @param float $fadeOut
  98. * @param float $cueIn
  99. * @param float $cueOut
  100. * @param MediaFilePlaylistDto[] $playlists
  101. * @param string $uniqueId
  102. * @param MediaFileCustomFieldDto[] $customFields
  103. */
  104. public function __construct(
  105. int $id,
  106. string $songId,
  107. string $title,
  108. string $artist,
  109. string $album,
  110. string $lyrics,
  111. string $isrc,
  112. $length,
  113. string $lengthText,
  114. string $path,
  115. int $mtime,
  116. float $fadeOverlap,
  117. float $fadeIn,
  118. float $fadeOut,
  119. float $cueIn,
  120. float $cueOut,
  121. array $playlists,
  122. string $uniqueId,
  123. array $customFields
  124. ) {
  125. $this->setId($id)
  126. ->setSongId($songId)
  127. ->setTitle($title)
  128. ->setArtist($artist)
  129. ->setAlbum($album)
  130. ->setLyrics($lyrics)
  131. ->setIsrc($isrc)
  132. ->setLength($length)
  133. ->setLengthText($lengthText)
  134. ->setPath($path)
  135. ->setMtime($mtime)
  136. ->setFadeOverlap($fadeOverlap)
  137. ->setFadeIn($fadeIn)
  138. ->setFadeOut($fadeOut)
  139. ->setCueIn($cueIn)
  140. ->setCueOut($cueOut)
  141. ->setPlaylists($playlists)
  142. ->setUniqueId($uniqueId)
  143. ->setCustomFields($customFields);
  144. }
  145. /**
  146. * @return int
  147. */
  148. public function getId(): int
  149. {
  150. return $this->id;
  151. }
  152. /**
  153. * @param int $id
  154. *
  155. * @return MediaFileDto
  156. */
  157. public function setId(int $id): MediaFileDto
  158. {
  159. $this->id = $id;
  160. return $this;
  161. }
  162. /**
  163. * @return string
  164. */
  165. public function getSongId(): string
  166. {
  167. return $this->songId;
  168. }
  169. /**
  170. * @param string $songId
  171. *
  172. * @return MediaFileDto
  173. */
  174. public function setSongId(string $songId): MediaFileDto
  175. {
  176. $this->songId = $songId;
  177. return $this;
  178. }
  179. /**
  180. * @return string
  181. */
  182. public function getTitle(): string
  183. {
  184. return $this->title;
  185. }
  186. /**
  187. * @param string $title
  188. *
  189. * @return MediaFileDto
  190. */
  191. public function setTitle(string $title): MediaFileDto
  192. {
  193. $this->title = $title;
  194. return $this;
  195. }
  196. /**
  197. * @return string
  198. */
  199. public function getArtist(): string
  200. {
  201. return $this->artist;
  202. }
  203. /**
  204. * @param string $artist
  205. *
  206. * @return MediaFileDto
  207. */
  208. public function setArtist(string $artist): MediaFileDto
  209. {
  210. $this->artist = $artist;
  211. return $this;
  212. }
  213. /**
  214. * @return string
  215. */
  216. public function getAlbum(): string
  217. {
  218. return $this->album;
  219. }
  220. /**
  221. * @param string $album
  222. *
  223. * @return MediaFileDto
  224. */
  225. public function setAlbum(string $album): MediaFileDto
  226. {
  227. $this->album = $album;
  228. return $this;
  229. }
  230. /**
  231. * @return string
  232. */
  233. public function getLyrics(): string
  234. {
  235. return $this->lyrics;
  236. }
  237. /**
  238. * @param string $lyrics
  239. *
  240. * @return MediaFileDto
  241. */
  242. public function setLyrics(string $lyrics): MediaFileDto
  243. {
  244. $this->lyrics = $lyrics;
  245. return $this;
  246. }
  247. /**
  248. * @return string
  249. */
  250. public function getIsrc(): string
  251. {
  252. return $this->isrc;
  253. }
  254. /**
  255. * @param string $isrc
  256. *
  257. * @return MediaFileDto
  258. */
  259. public function setIsrc(string $isrc): MediaFileDto
  260. {
  261. $this->isrc = $isrc;
  262. return $this;
  263. }
  264. /**
  265. * @return int
  266. */
  267. public function getLength(): int
  268. {
  269. return $this->length;
  270. }
  271. /**
  272. * @param int|float $length
  273. *
  274. * @return MediaFileDto
  275. */
  276. public function setLength($length): MediaFileDto
  277. {
  278. $this->length = (int) $length;
  279. return $this;
  280. }
  281. /**
  282. * @return string
  283. */
  284. public function getLengthText(): string
  285. {
  286. return $this->lengthText;
  287. }
  288. /**
  289. * @param string $lengthText
  290. *
  291. * @return MediaFileDto
  292. */
  293. public function setLengthText(string $lengthText): MediaFileDto
  294. {
  295. $this->lengthText = $lengthText;
  296. return $this;
  297. }
  298. /**
  299. * @return string
  300. */
  301. public function getPath(): string
  302. {
  303. return $this->path;
  304. }
  305. /**
  306. * @param string $path
  307. *
  308. * @return MediaFileDto
  309. */
  310. public function setPath(string $path): MediaFileDto
  311. {
  312. $this->path = $path;
  313. return $this;
  314. }
  315. /**
  316. * @return int
  317. */
  318. public function getMtime(): int
  319. {
  320. return $this->mtime;
  321. }
  322. /**
  323. * @param int $mtime
  324. *
  325. * @return MediaFileDto
  326. */
  327. public function setMtime(int $mtime): MediaFileDto
  328. {
  329. $this->mtime = $mtime;
  330. return $this;
  331. }
  332. /**
  333. * @return float
  334. */
  335. public function getFadeOverlap(): float
  336. {
  337. return $this->fadeOverlap;
  338. }
  339. /**
  340. * @param float $fadeOverlap
  341. *
  342. * @return MediaFileDto
  343. */
  344. public function setFadeOverlap(float $fadeOverlap): MediaFileDto
  345. {
  346. $this->fadeOverlap = $fadeOverlap;
  347. return $this;
  348. }
  349. /**
  350. * @return float
  351. */
  352. public function getFadeIn(): float
  353. {
  354. return $this->fadeIn;
  355. }
  356. /**
  357. * @param float $fadeIn
  358. * @return MediaFileDto
  359. */
  360. public function setFadeIn(float $fadeIn): MediaFileDto
  361. {
  362. $this->fadeIn = $fadeIn;
  363. return $this;
  364. }
  365. /**
  366. * @return float
  367. */
  368. public function getFadeOut(): float
  369. {
  370. return $this->fadeOut;
  371. }
  372. /**
  373. * @param float $fadeOut
  374. *
  375. * @return MediaFileDto
  376. */
  377. public function setFadeOut(float $fadeOut): MediaFileDto
  378. {
  379. $this->fadeOut = $fadeOut;
  380. return $this;
  381. }
  382. /**
  383. * @return float
  384. */
  385. public function getCueIn(): float
  386. {
  387. return $this->cueIn;
  388. }
  389. /**
  390. * @param float $cueIn
  391. *
  392. * @return MediaFileDto
  393. */
  394. public function setCueIn(float $cueIn): MediaFileDto
  395. {
  396. $this->cueIn = $cueIn;
  397. return $this;
  398. }
  399. /**
  400. * @return float
  401. */
  402. public function getCueOut(): float
  403. {
  404. return $this->cueOut;
  405. }
  406. /**
  407. * @param float $cueOut
  408. *
  409. * @return MediaFileDto
  410. */
  411. public function setCueOut(float $cueOut): MediaFileDto
  412. {
  413. $this->cueOut = $cueOut;
  414. return $this;
  415. }
  416. /**
  417. * @return MediaFilePlaylistDto[]
  418. */
  419. public function getPlaylists(): array
  420. {
  421. return $this->playlists;
  422. }
  423. /**
  424. * @param MediaFilePlaylistDto[] $playlists
  425. *
  426. * @return MediaFileDto
  427. */
  428. public function setPlaylists(array $playlists): MediaFileDto
  429. {
  430. $this->playlists = $playlists;
  431. return $this;
  432. }
  433. /**
  434. * @return string
  435. */
  436. public function getUniqueId(): string
  437. {
  438. return $this->uniqueId;
  439. }
  440. /**
  441. * @param string $uniqueId
  442. *
  443. * @return MediaFileDto
  444. */
  445. public function setUniqueId(string $uniqueId): MediaFileDto
  446. {
  447. $this->uniqueId = $uniqueId;
  448. return $this;
  449. }
  450. /**
  451. * @return MediaFileCustomFieldDto[]
  452. */
  453. public function getCustomFields(): array
  454. {
  455. return $this->customFields;
  456. }
  457. /**
  458. * @param MediaFileCustomFieldDto[] $customFields
  459. *
  460. * @return MediaFileDto
  461. */
  462. public function setCustomFields(array $customFields): MediaFileDto
  463. {
  464. $this->customFields = $customFields;
  465. return $this;
  466. }
  467. /**
  468. * @return mixed
  469. */
  470. public function jsonSerialize()
  471. {
  472. return [
  473. 'id' => $this->getId(),
  474. 'song_id' => $this->getSongId(),
  475. 'title' => $this->getTitle(),
  476. 'artist' => $this->getArtist(),
  477. 'album' => $this->getAlbum(),
  478. 'lyrics' => $this->getLyrics(),
  479. 'isrc' => $this->getIsrc(),
  480. 'length' => $this->getLength(),
  481. 'length_text' => $this->getLengthText(),
  482. 'path' => $this->getPath(),
  483. 'mtime' => $this->getMtime(),
  484. 'fade_overlap' => $this->getFadeOverlap(),
  485. 'fade_in' => $this->getFadeIn(),
  486. 'fade_out' => $this->getFadeOut(),
  487. 'cue_in' => $this->getCueIn(),
  488. 'cue_out' => $this->getCueOut(),
  489. 'playlists' => $this->getPlaylists(),
  490. 'unique_id' => $this->getUniqueId(),
  491. 'custom_fields' => $this->getCustomFields()
  492. ];
  493. }
  494. /**
  495. * @param array $mediaFileData
  496. *
  497. * @return self
  498. */
  499. public static function fromArray(array $mediaFileData): self
  500. {
  501. $playlists = [];
  502. foreach ($mediaFileData['playlists'] as $playlistData) {
  503. $playlists[] = MediaFilePlaylistDto::fromArray($playlistData);
  504. }
  505. $customFields = [];
  506. foreach ($mediaFileData['custom_fields'] as $id => $value) {
  507. $customFields[] = new MediaFileCustomFieldDto((int)$id, $value);
  508. }
  509. return new MediaFileDto(
  510. $mediaFileData['id'],
  511. $mediaFileData['song_id'] ?? "0",
  512. $mediaFileData['title'] ?? '',
  513. $mediaFileData['artist'] ?? '',
  514. $mediaFileData['album'] ?? '',
  515. $mediaFileData['lyrics'] ?? '',
  516. $mediaFileData['isrc'] ?? '',
  517. $mediaFileData['length'] ?? 0,
  518. $mediaFileData['length_text'] ?? '',
  519. $mediaFileData['path'],
  520. $mediaFileData['mtime'],
  521. $mediaFileData['fade_overlap'] ?? 0.0,
  522. $mediaFileData['fade_in'] ?? 0.0,
  523. $mediaFileData['fade_out'] ?? 0.0,
  524. $mediaFileData['cue_in'] ?? 0.0,
  525. $mediaFileData['cue_out'] ?? 0.0,
  526. $playlists,
  527. $mediaFileData['unique_id'],
  528. $customFields
  529. );
  530. }
  531. }