From 8c60b4e393cee25825808df2d07182657ed25eb1 Mon Sep 17 00:00:00 2001 From: tsufeki Date: Sat, 27 Jul 2013 15:52:48 +0200 Subject: [PATCH] Remote URLs support. --- doc/templates.md | 3 +- qygmy/browser.py | 12 +- qygmy/dialogs.py | 11 ++ qygmy/formatter.py | 5 +- qygmy/lists.py | 9 + qygmy/qygmy.py | 14 +- qygmy/translations/qygmy_pl.ts | 309 +++++++++++++++++++-------------- qygmy/ui/browser.ui | 17 +- qygmy/ui/main.ui | 31 +++- 9 files changed, 261 insertions(+), 150 deletions(-) diff --git a/doc/templates.md b/doc/templates.md index d95ec45..a531c19 100644 --- a/doc/templates.md +++ b/doc/templates.md @@ -47,8 +47,9 @@ Exactly one of those is set to `1`. - `%length%`: length of the song in seconds (see `$time()`). - `%track%`, `%totaltracks%`, `%disc%`, `%totaldiscs%` - `%lastmodified%`: last modification date. +- `%name%`: defined e.g. in HTTP streams. - All tags recognized by MPD: `%title%`, `%artist%`, `%album%`, `%date%`, - `%comment%`, `%composer%`, `%performer%`, etc. + `%comment%`, `%composer%`, `%performer%` etc. Functions diff --git a/qygmy/browser.py b/qygmy/browser.py index 643b70b..7191806 100644 --- a/qygmy/browser.py +++ b/qygmy/browser.py @@ -2,6 +2,7 @@ from PySide.QtCore import * from PySide.QtGui import * +from .dialogs import input_url from .ui.browser import Ui_browser @@ -75,13 +76,15 @@ def contextMenuEvent(self, e): self.ui.remove.setVisible(self.current_view.can_remove()) self.ui.rename.setVisible(self.current_view.can_rename()) self.ui.copy.setVisible(self.current_view.can_copy()) + self.ui.addurl.setVisible(self.current_view.model().can_add_url()) self.ui.details.setVisible(self.current_view.details() is not None) self.ui.context_menu.popup(e.globalPos()) def on_state_changed(self, state): c = state != 'disconnect' for act in ('search', 'add', 'addplay', 'replace', 'replaceplay', - 'addhighprio', 'remove', 'rename', 'copy', 'details', 'updatedb'): + 'addhighprio', 'remove', 'rename', 'copy', 'addurl', 'details', + 'updatedb'): getattr(self.ui, act).setEnabled(c) self.ui.dbpath.setEnabled(c) self.ui.plpath.setEnabled(c) @@ -125,6 +128,13 @@ def on_rename_triggered(self): def on_copy_triggered(self): self.current_view.copy_selected() + @Slot() + def on_addurl_triggered(self): + if self.current_view.model().can_add_url(): + url = input_url(self) + if url: + self.current_view.model().add_url(url) + @Slot() def on_details_triggered(self): d = self.current_view.details() diff --git a/qygmy/dialogs.py b/qygmy/dialogs.py index 7a88e2e..7ab8339 100644 --- a/qygmy/dialogs.py +++ b/qygmy/dialogs.py @@ -38,6 +38,15 @@ def exec_(self, name, info, title): super().exec_() +def input_url(parent): + url, ok = QInputDialog.getText(parent, + QApplication.translate('input_url', 'Add URL'), + QApplication.translate('input_url', 'URL:')) + if ok and url: + return url + return None + + class QygmyConfigParser(configparser.ConfigParser): def __init__(self, **kwargs): @@ -126,11 +135,13 @@ def retranslate(self): 'Disconnected)' ), 'current_song': self.tr( + '$if(%name%,[%name%] )' '' '$if2(%title%,%filename%)
' '%artist%$if(%album%, \u2014 %album%)' ), 'playlist_item': self.tr( + '$if(%name%,[%name%] )' '$if(%artist%,%artist% \u2014 )' '$if2(%title%,%filename%)' ), diff --git a/qygmy/formatter.py b/qygmy/formatter.py index c99c354..9d0b99a 100644 --- a/qygmy/formatter.py +++ b/qygmy/formatter.py @@ -50,6 +50,7 @@ def retranslate(self): ), 'details': ( (self.tr('%file%'), None), + (self.tr('Name:'), self.tr('%name%')), (self.tr('Title:'), self.tr('%title%')), (self.tr('Artist:'), self.tr('%artist%')), (self.tr('Album:'), self.tr('%album%')), @@ -64,7 +65,7 @@ def retranslate(self): ) } - standard_tags = {'file', 'directory', 'playlist', 'filename', 'title', + standard_tags = {'file', 'directory', 'playlist', 'filename', 'name', 'title', 'artist', 'album', 'date', 'track', 'totaltracks', 'disc', 'totaldiscs', 'comment', 'length', 'lastmodified', 'composer', 'performer', } @@ -80,7 +81,7 @@ def _prepare_song(self, song, html=True): song['prio'] = '0' for key in ['file', 'directory', 'playlist']: if key in song: - filename = song[key].rsplit('/', 1)[-1] + filename = song[key].rstrip('/').rsplit('/', 1)[-1] if filename: song['filename'] = filename if 'time' in song: diff --git a/qygmy/lists.py b/qygmy/lists.py index 952d605..2d11ca4 100644 --- a/qygmy/lists.py +++ b/qygmy/lists.py @@ -68,6 +68,9 @@ def can_set_priority(self, positions, prio): def can_copy(self, positions): return False + def can_add_url(self): + return False + @abstractmethod def item_chosen(self, pos): """i.e. double-clicked or Return pressed.""" @@ -177,6 +180,12 @@ def can_add_directly(self, item, pos, **kwargs): def add_one(self, item, pos, last, **kwargs): pass + def can_add_url(self): + return True + + def add_url(self, url): + self.add([{'file': url}]) + def can_remove(self, positions): return len(positions) > 0 diff --git a/qygmy/qygmy.py b/qygmy/qygmy.py index 73f9769..8a7b7e4 100644 --- a/qygmy/qygmy.py +++ b/qygmy/qygmy.py @@ -5,7 +5,7 @@ from .formatter import Formatter from .server import Server from .browser import Browser -from .dialogs import Info, Settings +from .dialogs import Info, Settings, input_url from .ui.main import Ui_main from .__version__ import version @@ -214,9 +214,9 @@ def on_state_changed(self, state): self.ui.play.setVisible(state != 'play') self.ui.pause.setVisible(state == 'play') for e in ('previous', 'play', 'pause', 'stop', 'next', 'volume', - 'add', 'clear', 'repeat', 'shuffle', 'single', 'consume', - 'updatedb', 'save', 'randomize', 'details', 'statistics', - 'louder', 'quieter', 'reverse', + 'add', 'addurl', 'clear', 'repeat', 'shuffle', 'single', + 'consume', 'updatedb', 'save', 'randomize', 'details', + 'statistics', 'louder', 'quieter', 'reverse', 'playback_menu', 'volume_menu', 'playlist_menu', 'outputs_menu'): getattr(self.ui, e).setEnabled(c) self.on_queue_selection_changed() @@ -253,6 +253,12 @@ def on_details_triggered(self): def on_statistics_triggered(self): self.info.exec_('statistics', self.srv.statistics(), 'MPD statistics') + @Slot() + def on_addurl_triggered(self): + url = input_url(self) + if url: + self.srv.queue.add_url(url) + @Slot() def on_save_triggered(self): name = None diff --git a/qygmy/translations/qygmy_pl.ts b/qygmy/translations/qygmy_pl.ts index edb5811..5a3b76d 100644 --- a/qygmy/translations/qygmy_pl.ts +++ b/qygmy/translations/qygmy_pl.ts @@ -3,7 +3,7 @@ Browser - + Details Szczegóły @@ -96,112 +96,112 @@ - + Title: Tytuł: - + %title% - + Artist: Artysta: - + %artist% - + Album: Album: - + %album% - + Date: Data: - + %date% - + Track: Ścieżka: - + %track%$if(%totaltracks%, / %totaltracks%,) - + Disc: Dysk: - + %disc%$if(%totaldiscs%, / %totaldiscs%,) - + Comment: Komentarz: - + %comment% - + Length: Czas: - + $if(%length%,$time(%length%),) - + Last modified: Ostatnio zmodyfikowany: - + %lastmodified% - + Composer: Kompozytor: - + %composer% - + Performer: Wykonawca: - + %performer% @@ -215,11 +215,21 @@ %mpdversion% + + + Name: + Nazwa: + + + + %name% + + Playlists - + New playlist Nowa lista @@ -227,32 +237,32 @@ Qygmy - + Error Błąd - + Save current playlist Zapisz listę - + Playlist name: Nazwa listy: - + About Qygmy O Qygmy - + Playlist with such name already exists. Do you want to replace it? Lista o tej nazwie już istnieje. Zastąpić? - + <h2>Qygmy</h2><p>version {version}</p><p>Simple MPD client written in Python and Qt/PySide.</p><p><a href="https://github.com/tsufeki/qygmy">https://github.com/tsufeki/qygmy</a></p> <h2>Qygmy</h2><p>wersja {version}</p><p>Prosty klient MPD napisany w Pythonie i Qt/PySide.</p><p><a href="https://github.com/tsufeki/qygmy">https://github.com/tsufeki/qygmy</a></p> @@ -260,67 +270,67 @@ SearchTags - + Title Tytuł - + Artist Artysta - + Album Album - + Genre Gatunek - + Comment Komentarz - + Composer Kompozytor - + Performer Wykonawca - + Date Data - + Track Ścieżka - + Disc Dysk - + Any Wszystko - + File name Nazwa pliku - + Name Nazwa @@ -328,23 +338,23 @@ Settings - + Qygmy$if(%playing%, / $if(%artist%,%artist% u2014 )$if2(%title%,%filename%)) - + $if3(%playing%%paused%,$time(%elapsed%)$if($and(%total%,$gt(%total%,0)), / $time(%total%)),%stopped%,Stopped,%connected%,Connected,Disconnected) $if3(%playing%%paused%,$time(%elapsed%)$if($and(%total%,$gt(%total%,0)), / $time(%total%)),%stopped%,Zatrzymany,%connected%,Połączony,Rozłączony) - - <span style="font-size: large; font-weight: bold">$if2(%title%,%filename%)</span><br>%artist%$if(%album%, u2014 %album%) + + $if(%name%,[%name%] )<span style="font-size: large; font-weight: bold">$if2(%title%,%filename%)</span><br>%artist%$if(%album%, u2014 %album%) - - $if(%artist%,%artist% u2014 )$if2(%title%,%filename%) + + $if(%name%,[%name%] )$if(%artist%,%artist% u2014 )$if2(%title%,%filename%) @@ -359,124 +369,134 @@ browser - + Music database Baza muzyki - + &Database &Baza - + &Playlists &Listy - + Tag to search Szukany tag - + &Search &Szukaj - + &Add selected &Dodaj zaznaczone - + Add selected songs to the current playlist Dodaj zaznaczone utwory do głównej listy - + &Close &Zamknij - + Close this window Zamknij to okno - + Ctrl+W - + Search Szukaj - + &Remove selected &Usuń zaznaczone - + Del - + Add selected and &play Dodaj zaznaczone i &odtwarzaj - + Shift+Return - + Song &details... &Szczegóły... - + Ctrl+I - + Re&name Zmień &nazwę - + F2 - + R&eplace the current playlist Za&stąp główną listę - + Rep&lace and play Zas&tąp i odtwarzaj - + C&opy selected &Kopiuj zaznaczone - - &Update the database + + Add with &high priority + Dodaj z &wysokim priorytetem + + + + Update the data&base Odśwież &bazę - - Add with &high priority - Dodaj z &wysokim priorytetem + + Add &URL... + Dodaj U&RL... + + + + Ctrl+U + @@ -487,293 +507,316 @@ Szczegóły + + input_url + + + Add URL + Dodaj URL + + + + URL: + URL: + + main - + &Playback &Odtwarzanie - + &Volume &Głośność - + Pla&ylist &Lista - + P&revious Pop&rzedni - + Previous song Poprzedni utwór - + Ctrl+P - + &Play &Odtwarzaj - + Space - + &Stop &Zatrzymaj - + Ctrl+S - + &Next &Następny - + Next Song Następny utwór - + Ctrl+N - + &Add... &Dodaj... - + Add to playlist... Dodaj do listy... - + Ctrl+L - + &Remove &Usuń - + Remove selected Usuń zaznaczone - + Del - + R&epeat Po&wtarzaj - + S&huffle &Losowo - + &Settings... &Ustawienia... - + Ctrl+O - + Volume Głośność - + &Clear &Opróżnij - + Clear playlist Opróżnij listę - + Dis&connect from MPD Rozłą&cz z MPD - + &Connect to MPD Połą&cz z MPD - + &Update the database Odśwież &bazę - + S&ingle track mode &Tryb pojedynczego utworu - + Single Pojedyn. - + Re&move songs after playback U&suń po odtworzeniu - + Consume Usuń po - + &Pause P&auzuj - + &Save... &Zapisz - + Ctrl+T - + Song &details... &Szczegóły - + Ctrl+I - + &Quit &Wyjście - + Ctrl+Q - + Randomi&ze &Wymieszaj - + &MPD statistics... Statystyki &MPD... - + &High priority Wysoki &priorytet - + Set high priority for selected songs Odtwórz zaznaczone z wyższym priorytetem - + Ctrl+H - + &Normal priority &Normalny priorytet - + Set normal priority for selected songs Odtwórz zaznaczone ze zwykłym priorytetem - + Ctrl+J - + &Louder &Głośniej - + Ctrl+E - + &Quieter &Ciszej - + Ctrl+D - + &About Qygmy... O &Qygmy... - + About Qt... O Qt... - + Re&verse Odw&róć - + C&opy selected &Kopiuj zaznaczone - + Audio &outputs Wyjścia &audio + + + Add &URL... + Dodaj UR&L... + + + + Ctrl+U + + settings diff --git a/qygmy/ui/browser.ui b/qygmy/ui/browser.ui index c47b8d7..573fab4 100644 --- a/qygmy/ui/browser.ui +++ b/qygmy/ui/browser.ui @@ -382,6 +382,7 @@ + @@ -518,7 +519,21 @@ - &Update the database + Update the data&base + + + false + + + + + Add &URL... + + + Ctrl+U + + + Qt::WindowShortcut false diff --git a/qygmy/ui/main.ui b/qygmy/ui/main.ui index 655c9f7..c1bc420 100644 --- a/qygmy/ui/main.ui +++ b/qygmy/ui/main.ui @@ -318,6 +318,14 @@ + + + Audio &outputs + + + true + + Pla&ylist @@ -326,6 +334,7 @@ true + @@ -334,14 +343,6 @@ - - - Audio &outputs - - - true - - @@ -756,6 +757,20 @@ false + + + Add &URL... + + + Ctrl+U + + + Qt::WindowShortcut + + + false + +