summaryrefslogtreecommitdiff
path: root/nephilim/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'nephilim/common.py')
-rw-r--r--nephilim/common.py61
1 files changed, 1 insertions, 60 deletions
diff --git a/nephilim/common.py b/nephilim/common.py
index 35e041f..ddbb96b 100644
--- a/nephilim/common.py
+++ b/nephilim/common.py
@@ -16,8 +16,7 @@
# along with Nephilim. If not, see <http://www.gnu.org/licenses/>.
#
-from PyQt4 import QtCore, QtGui, QtNetwork
-from PyQt4.QtCore import pyqtSignal as Signal
+from PyQt4 import QtCore, QtGui
import socket
import logging
import os
@@ -106,64 +105,6 @@ def decode_htmlentities(string):
entity_re = re.compile(r'&(#?)(x?)(\w+);')
return entity_re.subn(substitute_entity, string)[0]
-class MetadataFetcher(QtCore.QObject):
- """A basic class for metadata fetchers. Provides a fetch(song) function,
- emits a finished(song, metadata) signal when done; lyrics is either a Python
- unicode string or None if not found."""
- #public, read-only
- logger = None
- name = ''
-
- #private
- nam = None # NetworkAccessManager
- rep = None # current NetworkReply.
- song = None # current song
-
- # SIGNALS
- finished = Signal(['song', 'metadata'])
-
- #### private ####
- def __init__(self, plugin):
- QtCore.QObject.__init__(self, plugin)
-
- self.nam = QtNetwork.QNetworkAccessManager()
- self.logger = plugin.logger
-
- def fetch2(self, song, url):
- """A private convenience function to initiate fetch process."""
- # abort any existing connections
- self.abort()
- self.song = song
-
- self.logger.info('Searching %s: %s.'%(self. name, url.toString()))
- self.rep = self.nam.get(QtNetwork.QNetworkRequest(url))
- self.rep.error.connect(self.handle_error)
-
- def finish(self, metadata = None):
- """A private convenience function to clean up and emit finished().
- Feel free to reimplement/not use it."""
- self.rep = None
- self.finished.emit(self.song, metadata)
- self.song = None
-
- def handle_error(self):
- """Print the error and abort."""
- self.logger.error(self.rep.errorString())
- self.abort()
- self.finish()
-
- #### public ####
- def fetch(self, song):
- """Reimplement this in subclasses."""
- pass
-
- def abort(self):
- """Abort all downloads currently in progress."""
- if self.rep:
- self.rep.blockSignals(True)
- self.rep.abort()
- self.rep = None
-
class SongsMimeData(QtCore.QMimeData):
# private
__songs = None