Skip to content

Commit

Permalink
Add: Now you can add playlists using link
Browse files Browse the repository at this point in the history
  • Loading branch information
gokadzev committed Sep 29, 2024
1 parent 98ec794 commit a9d4eb7
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 31 deletions.
51 changes: 40 additions & 11 deletions lib/API/musify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,48 @@ Future<List<dynamic>> getUserPlaylists() async {
return playlistsByUser;
}

Future<String> addUserPlaylist(String playlistId, BuildContext context) async {
if (playlistId.startsWith('http://') || playlistId.startsWith('https://')) {
return '${context.l10n!.notYTlist}!';
} else {
try {
await _yt.playlists.get(playlistId);
userPlaylists.add(playlistId);
addOrUpdateData('user', 'playlists', userPlaylists);
return '${context.l10n!.addedSuccess}!';
} catch (e) {
return '${context.l10n!.error}!';
bool youtubeValidate(String url) {
final regExp = RegExp(
r'^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/.*(list=([a-zA-Z0-9_-]+)).*$',
);
return regExp.hasMatch(url);
}

String? youtubePlaylistParser(String url) {
if (!youtubeValidate(url)) {
return null;
}

final regExp = RegExp(r'[&?]list=([a-zA-Z0-9_-]+)');
final match = regExp.firstMatch(url);

return match?.group(1);
}

Future<String> addUserPlaylist(String input, BuildContext context) async {
String? playlistId = input;

if (input.startsWith('http://') || input.startsWith('https://')) {
playlistId = youtubePlaylistParser(input);

if (playlistId == null) {
return '${context.l10n!.notYTlist}!';
}
}

try {
await _yt.playlists.get(playlistId);

if (userPlaylists.contains(playlistId)) {
return '${context.l10n!.playlistAlreadyExists}!';
}

userPlaylists.add(playlistId);
addOrUpdateData('user', 'playlists', userPlaylists);
return '${context.l10n!.addedSuccess}!';
} catch (e) {
return '${context.l10n!.error}: $e';
}
}

String createCustomPlaylist(
Expand Down
3 changes: 2 additions & 1 deletion lib/localization/app_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "Original algorithm for recommendations",
"others": "آخرون",
"playlist": "قائمة تشغيل",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "تم تحديث القائمة بنجاح",
"playlists": "قوائم التشغيل",
"preferences": "Preferences",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "Use pure black",
"useSquigglySlider": "Use squiggly slider",
"userPlaylists": "قوائم تشغيل المستخدم",
"youtubePlaylistID": "معرف قائمة تشغيل YouTube"
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
3 changes: 2 additions & 1 deletion lib/localization/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "Originaler Algorithmus für Vorschläge",
"others": "Andere",
"playlist": "Playlist",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "Playlist erfolgreich aktualisiert",
"playlists": "Playlists",
"preferences": "Einstellungen",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "Use pure black",
"useSquigglySlider": "Use squiggly slider",
"userPlaylists": "Benutzer-Playlists",
"youtubePlaylistID": "YouTube-Playlist-ID"
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
3 changes: 2 additions & 1 deletion lib/localization/app_el.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "Πρωτότυπος αλγόριθμος για συστάσεις",
"others": "Άλλα",
"playlist": "Λίστα αναπαραγωγής",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "Η λίστα αναπαραγωγής ενημερώθηκε επιτυχώς",
"playlists": "Λίστες αναπαραγωγής",
"preferences": "Preferences",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "Use pure black",
"useSquigglySlider": "Use squiggly slider",
"userPlaylists": "Λίστες αναπαραγωγής χρήστη",
"youtubePlaylistID": "ID Λίστας Αναπαραγωγής YouTube"
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
3 changes: 2 additions & 1 deletion lib/localization/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "Original algorithm for recommendations",
"others": "Others",
"playlist": "Playlist",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "Playlist updated successfully",
"playlists": "Playlists",
"preferences": "Preferences",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "Use pure black",
"useSquigglySlider": "Use squiggly slider",
"userPlaylists": "User playlists",
"youtubePlaylistID": "YouTube playlist ID"
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
3 changes: 2 additions & 1 deletion lib/localization/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "Original algorithm for recommendations",
"others": "Otros",
"playlist": "Lista de reproducción",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "Lista de reproducción actualizada exitosamente",
"playlists": "Listas de reproducción",
"preferences": "Preferences",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "Use pure black",
"useSquigglySlider": "Use squiggly slider",
"userPlaylists": "Listas de reproducción del usuario",
"youtubePlaylistID": "ID de lista de reproducción de YouTube"
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
3 changes: 2 additions & 1 deletion lib/localization/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "Original algorithm for recommendations",
"others": "Autres",
"playlist": "Liste de lecture",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "Mise à jour de la liste de lecture réussie",
"playlists": "Listes de lectures",
"preferences": "Preferences",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "Use pure black",
"useSquigglySlider": "Use squiggly slider",
"userPlaylists": "Listes de lectures des utilisateurs",
"youtubePlaylistID": "ID de playlist YouTube"
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
3 changes: 2 additions & 1 deletion lib/localization/app_id.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "Algoritma asli untuk rekomendasi",
"others": "Lainnya",
"playlist": "Playlist",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "Playlist berhasil diperbarui",
"playlists": "Playlist",
"preferences": "Preferensi",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "Gunakan hitam murni",
"useSquigglySlider": "Gunakan slider bergelombang",
"userPlaylists": "Playlist pengguna",
"youtubePlaylistID": "ID playlist YouTube"
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
3 changes: 2 additions & 1 deletion lib/localization/app_it.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "Algoritmo originale per le raccomandazioni",
"others": "Altri",
"playlist": "Playlist",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "Playlist aggiornata con successo",
"playlists": "Playlist",
"preferences": "Preferenze",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "Use pure black",
"useSquigglySlider": "Use squiggly slider",
"userPlaylists": "Playlist utente",
"youtubePlaylistID": "ID playlist YouTube"
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
5 changes: 3 additions & 2 deletions lib/localization/app_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "おすすめに独自アルゴリズムを使用",
"others": "ほか",
"playlist": "再生リスト",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "再生リストを更新しました",
"playlists": "再生リスト",
"preferences": "設定",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "ピュアブラックを使用",
"useSquigglySlider": "くねくねしたスライダーを使用",
"userPlaylists": "再生リスト",
"youtubePlaylistID": "YouTube の再生リストの ID"
}
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
3 changes: 2 additions & 1 deletion lib/localization/app_ka.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "ორიგინალი ალგორითმი რეკომენდაციებისთვის",
"others": "სხვა",
"playlist": "ჩასართავი სია",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "ჩასართავი სია განახლდა წარმატებით",
"playlists": "ჩასართავი სიები",
"preferences": "უპირატესობები",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "გამოიყენე სუფთა შავი",
"useSquigglySlider": "გამოიყენე ტალღოვანი სლაიდერი",
"userPlaylists": "მომხმარებლის ჩასართავი სიები",
"youtubePlaylistID": "YouTube ჩასართავი სიის აიდი"
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
5 changes: 3 additions & 2 deletions lib/localization/app_ko.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "추천을 위한 오리지널 알고리즘",
"others": "기타",
"playlist": "재생목록",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "재생목록이 성공적으로 업데이트되었음",
"playlists": "재생목록",
"preferences": "환경 설정",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "순수 검정색 사용",
"useSquigglySlider": "굴곡 슬라이더 사용",
"userPlaylists": "사용자 재생목록",
"youtubePlaylistID": "유튜브 재생목록 ID"
}
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
3 changes: 2 additions & 1 deletion lib/localization/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "Oryginalny algorytm rekomendacji",
"others": "Inne",
"playlist": "Playlista",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "Playlista zaktualizowana pomyślnie",
"playlists": "Playlisty",
"preferences": "Preferencje",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "Use pure black",
"useSquigglySlider": "Use squiggly slider",
"userPlaylists": "Playlisty użytkownika",
"youtubePlaylistID": "ID playlisty YouTube"
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
5 changes: 3 additions & 2 deletions lib/localization/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "Algoritmo original para recomendações",
"others": "Outros",
"playlist": "Playlist",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "Playlist atualizada com sucesso",
"playlists": "Playlists",
"preferences": "Configurações",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "Usar preto puro",
"useSquigglySlider": "Usar controle deslizante ondulado",
"userPlaylists": "Suas playlists",
"youtubePlaylistID": "ID da playlist do YouTube"
}
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
3 changes: 2 additions & 1 deletion lib/localization/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "Оригинальный алгоритм рекомендаций",
"others": "Ещё",
"playlist": "Плейлист",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "Плейлист успешно обновлён",
"playlists": "Плейлисты",
"preferences": "Настройки",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "Ночная тема",
"useSquigglySlider": "Волнистая полоса прокрутки",
"userPlaylists": "Ваши плейлисты",
"youtubePlaylistID": "ID плейлиста Youtube"
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
3 changes: 2 additions & 1 deletion lib/localization/app_tr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "Orjinal önerilenler algoritması",
"others": "Diğerleri",
"playlist": "Çalma Listesi",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "Çalma Listesi Başarıyla Güncellendi",
"playlists": "Çalma Listeleri",
"preferences": "Tercihler",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "Use pure black",
"useSquigglySlider": "Use squiggly slider",
"userPlaylists": "Kullanıcı Çalma Listeleri",
"youtubePlaylistID": "YouTube Çalma Listesi Kimliği"
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
3 changes: 2 additions & 1 deletion lib/localization/app_uk.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"originalRecommendations": "Original algorithm for recommendations",
"others": "Інше",
"playlist": "Плейлист",
"playlistAlreadyExists": "Playlist already exists",
"playlistUpdated": "Список відтворення успішно оновлено",
"playlists": "Плейлисти",
"preferences": "Preferences",
Expand Down Expand Up @@ -86,5 +87,5 @@
"usePureBlack": "Use pure black",
"useSquigglySlider": "Use squiggly slider",
"userPlaylists": "Плейлисти користувача",
"youtubePlaylistID": "Ідентифікатор плейлиста YouTube"
"youtubePlaylistLinkOrId": "YouTube playlist link or ID "
}
3 changes: 2 additions & 1 deletion lib/screens/user_added_playlists_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class _UserPlaylistsPageState extends State<UserPlaylistsPage> {
if (isYouTubeMode)
TextField(
decoration: InputDecoration(
labelText: context.l10n!.youtubePlaylistID,
labelText:
context.l10n!.youtubePlaylistLinkOrId,
),
onChanged: (value) {
id = value;
Expand Down

1 comment on commit a9d4eb7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@muhammadbahaa2001, @Yoshlix, @CrisBalGreece, @Anto1337, @daviddprtma, @motzarello, @maboroshin, @gokadzev, @DDinghoya, @Pazdikan, @GeovaneDev, @S0nter, @kyskerem, @DanielProg39
The following translations have been updated:

  • 'app_ar.arb'
  • 'app_de.arb'
  • 'app_el.arb'
  • 'app_fr.arb'
  • 'app_id.arb'
  • 'app_it.arb'
  • 'app_ja.arb'
  • 'app_ka.arb'
  • 'app_ko.arb'
  • 'app_pl.arb'
  • 'app_pt.arb'
  • 'app_ru.arb'
  • 'app_tr.arb'
  • 'app_uk.arb'

Please sign in to comment.