Skip to content

Commit

Permalink
Remote URLs support.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsufeki committed Jul 27, 2013
1 parent f16bf34 commit 8c60b4e
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 150 deletions.
3 changes: 2 additions & 1 deletion doc/templates.md
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion qygmy/browser.py
Expand Up @@ -2,6 +2,7 @@
from PySide.QtCore import *
from PySide.QtGui import *

from .dialogs import input_url
from .ui.browser import Ui_browser


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions qygmy/dialogs.py
Expand Up @@ -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):
Expand Down Expand Up @@ -126,11 +135,13 @@ def retranslate(self):
'Disconnected)'
),
'current_song': self.tr(
'$if(%name%,[%name%] )'
'<span style="font-size: large; font-weight: bold">'
'$if2(%title%,%filename%)</span><br>'
'%artist%$if(%album%, \u2014 %album%)'
),
'playlist_item': self.tr(
'$if(%name%,[%name%] )'
'$if(%artist%,%artist% \u2014 )'
'$if2(%title%,%filename%)'
),
Expand Down
5 changes: 3 additions & 2 deletions qygmy/formatter.py
Expand Up @@ -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%')),
Expand All @@ -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',
}
Expand All @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions qygmy/lists.py
Expand Up @@ -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."""
Expand Down Expand Up @@ -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

Expand Down
14 changes: 10 additions & 4 deletions qygmy/qygmy.py
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8c60b4e

Please sign in to comment.