From 6310873c4826591789d17164463a42dfbd7f5669 Mon Sep 17 00:00:00 2001
From: Schneelocke <75278644+Schneelocke@users.noreply.github.com>
Date: Thu, 7 Jan 2021 22:07:40 +0100
Subject: [PATCH] Spotify url conversion (http to mopidy format) (#1203)
* Added spotify url conversion
* Improved and translated error message
---
htdocs/inc.processCheckCardEditRegister.php | 16 ++++++++++++++++
htdocs/lang/lang-de-DE.php | 1 +
htdocs/lang/lang-en-UK.php | 1 +
htdocs/lang/lang-nl-NL.php | 1 +
4 files changed, 19 insertions(+)
diff --git a/htdocs/inc.processCheckCardEditRegister.php b/htdocs/inc.processCheckCardEditRegister.php
index 7d96dcf53..5ae713aee 100755
--- a/htdocs/inc.processCheckCardEditRegister.php
+++ b/htdocs/inc.processCheckCardEditRegister.php
@@ -171,6 +171,22 @@ function fillRfidArrAvailWithUsed($rfidAvailArr, $rfidUsedArr=array()) {
$post['audiofolderNew'] = $link = str_replace(array('http://','https://','/','=','-','.', 'www','?','&'), '', $post['streamURL']);
}
+ //wrong spotify url, convert to mopidy format
+ if((isset($post['streamURL']) && $post['streamType'] == "spotify") && (strpos($post['streamURL'], "https://open.spotify.com/") !== false)){
+ $patterns = array();
+ $patterns[0] = '/https\:\/\/open.spotify.com/';
+ $patterns[1] = '/\/(playlist|album|track|artist)\//';
+ $patterns[2] = '/(\w+)\?(.*)/';
+ $replacements = array();
+ $replacements[0] = 'spotify:';
+ $replacements[1] = '$1:';
+ $replacements[2] = '$1';
+ $newSpotifyURL = preg_replace($patterns, $replacements, $post['streamURL']);
+ $messageError .= $lang['cardRegisterErrorConvertSpotifyURL']." (error 007)
".$post['streamURL']." ➔ ".$newSpotifyURL;
+ $post['streamURL'] = $newSpotifyURL;
+ }
+
+
/*
* any errors?
*/
diff --git a/htdocs/lang/lang-de-DE.php b/htdocs/lang/lang-de-DE.php
index 386214cc4..f1992aa9f 100755
--- a/htdocs/lang/lang-de-DE.php
+++ b/htdocs/lang/lang-de-DE.php
@@ -124,6 +124,7 @@
$lang['cardRegisterErrorExistingAndNew'] = "
Das ist zu viel! Wähle entweder einen bestehenden Ordner aus oder erstelle einen neuen.
"; $lang['cardRegisterErrorExistingFolder'] = "Ein Ordner mit dem gleichen Namen existiert bereits! Wähle einen anderen.
"; $lang['cardRegisterErrorSuggestFolder'] = "Ein Ordnername für den Stream muss erstellt werden. Unten im Formular steht ein Vorschlag."; +$lang['cardRegisterErrorConvertSpotifyURL'] = "Falsche Spotify URL, konvertiert in korrektes Format"; $lang['cardRegisterStream2Card'] = "Stream ist mit der Karten-ID verknüpft."; $lang['cardRegisterFolder2Card'] = "Audio-Ordner ist nun mit der Karten-ID verknüpft."; $lang['cardRegisterDownloadingYT'] = "YouTube Audio wird heruntergeladen. Dies kann einige Minuten dauern. Du kannst die Logdatei \"youtube-dl.log\" im Ordner \"shared\" ansehen.
"; diff --git a/htdocs/lang/lang-en-UK.php b/htdocs/lang/lang-en-UK.php index ee208e498..e670c4174 100755 --- a/htdocs/lang/lang-en-UK.php +++ b/htdocs/lang/lang-en-UK.php @@ -125,6 +125,7 @@ $lang['cardRegisterErrorExistingAndNew'] = "This is too much! Either choose an existing folder or create a new one.
"; $lang['cardRegisterErrorExistingFolder'] = "A folder named with the same name already exists! Chose a different one.
"; $lang['cardRegisterErrorSuggestFolder'] = "A folder name for the stream needs to be created. Below in the form I made a suggestion."; +$lang['cardRegisterErrorConvertSpotifyURL'] = "Wrong spotify url, converted to the correct format"; $lang['cardRegisterStream2Card'] = "Stream is linked to Card ID."; $lang['cardRegisterFolder2Card'] = "Audio folder is now linked to Card."; $lang['cardRegisterDownloadingYT'] = "YouTube audio is downloading. This may take a couple of minutes. You may check the logfile \"youtube-dl.log\" in the shared folder.
"; diff --git a/htdocs/lang/lang-nl-NL.php b/htdocs/lang/lang-nl-NL.php index 6f27f51e3..1fb654509 100755 --- a/htdocs/lang/lang-nl-NL.php +++ b/htdocs/lang/lang-nl-NL.php @@ -109,6 +109,7 @@ $lang['cardRegisterErrorExistingAndNew'] = "Dit is te veel! Kies een bestaande map of maak een nieuwe map aan.
"; $lang['cardRegisterErrorExistingFolder'] = "Er bestaat al een map met dezelfde naam! Kies een andere.
"; $lang['cardRegisterErrorSuggestFolder'] = "Er moet een mapnaam voor de stream worden gemaakt. Hieronder in het formulier heb ik een suggestie gedaan."; +$lang['cardRegisterErrorConvertSpotifyURL'] = "Verkeerde spotify url, geconverteerd naar het juiste formaat"; $lang['cardRegisterStream2Card'] = "Stream is gekoppeld aan kaart-ID."; $lang['cardRegisterFolder2Card'] = "De audiomap is nu gekoppeld aan kaart-ID"; $lang['cardRegisterDownloadingYT'] = "YouTube-audio wordt gedownload. Dit kan een paar minuten duren. U kunt het logbestand 'youtube-dl.log' in de gedeelde map controleren.
";