def get_id3info(url): ''' Function fetches data about mp3 files over HTTP. @param url: mp3 file address. @return bitrate, title, artist, id3tags_file ''' if not is_ServerSupportHTTPRange(url): log.warning("Server does not support HTTPRANGE! [%s]" % url) return [0, "", "", ""] url = url.replace(' ', '%20') # may not be needed req = urllib2.Request(url, headers=config.generic_http_headers) urlObj = urllib2.urlopen(req, timeout=config.get_id3info_timeout) tmpfile = utils.get_rand_filename(config.temp_dir) stringIO = StringIO() while True: stringIO.write(urlObj.read(8192)) with open(tmpfile, 'wb') as f: f.write(stringIO.getvalue()) try: audio = MP3(tmpfile) break except EOFError: # We still didn't fetch all the ID3 data. pass # log.debug("metadata is not in this %d KB chunk or not supported." % len(stringIO.getvalue())) except mutagen.mp3.HeaderNotFoundError: log.debug("HeaderNotFoundError: can't sync to an MPEG frame") stringIO.close() return [0, "", "", ""] stringIO.close() try: audioID3 = EasyID3(tmpfile) except mutagen.id3.ID3NoHeaderError: log.debug("no ID3data found (mutagen.id3.ID3NoHeaderError).") return [audio.info.bitrate, "", "", ""] except mutagen.id3.ID3BadUnsynchData: log.debug("Bad ID3 Unsynch Data (mutagen.id3.ID3BadUnsynchData)") return [audio.info.bitrate, "", "", ""] title = utils.fix_faulty_unicode( audioID3.get('title')[0]) if audioID3.get('title') else "" artist = utils.fix_faulty_unicode( audioID3.get('artist')[0]) if audioID3.get('artist') else "" return [audio.info.bitrate, title, artist, tmpfile]
def get_id3info(url): ''' Function fetches data about mp3 files over HTTP. @param url: mp3 file address. @return bitrate, title, artist, id3tags_file ''' if not is_ServerSupportHTTPRange(url): log.warning("Server does not support HTTPRANGE! [%s]" % url) return [0, "", "", ""] url = url.replace(' ', '%20') # may not be needed req = urllib2.Request(url, headers=config.generic_http_headers) urlObj = urllib2.urlopen(req, timeout=config.get_id3info_timeout) tmpfile = utils.get_rand_filename(config.temp_dir) stringIO = StringIO() while True: stringIO.write(urlObj.read(8192)) with open(tmpfile, 'wb') as f: f.write(stringIO.getvalue()) try: audio = MP3(tmpfile) break except EOFError: # We still didn't fetch all the ID3 data. pass # log.debug("metadata is not in this %d KB chunk or not supported." % len(stringIO.getvalue())) except mutagen.mp3.HeaderNotFoundError: log.debug("HeaderNotFoundError: can't sync to an MPEG frame") stringIO.close() return [0, "", "", ""] stringIO.close() try: audioID3 = EasyID3(tmpfile) except mutagen.id3.ID3NoHeaderError: log.debug("no ID3data found (mutagen.id3.ID3NoHeaderError).") return [audio.info.bitrate, "", "", ""] except mutagen.id3.ID3BadUnsynchData: log.debug("Bad ID3 Unsynch Data (mutagen.id3.ID3BadUnsynchData)") return [audio.info.bitrate, "", "", ""] title = utils.fix_faulty_unicode(audioID3.get('title')[0]) if audioID3.get('title') else "" artist = utils.fix_faulty_unicode(audioID3.get('artist')[0]) if audioID3.get('artist') else "" return [audio.info.bitrate, title, artist, tmpfile]
except Exception, e: log.warning("Exception %s ignored in GoogleImagesGrabberThread." % str(e)) self.output.emit(fn_list) def fetchPhoto(self, url): req = urllib2.Request(url, headers=config.generic_http_headers) try: urlObj = urllib2.urlopen(req, timeout=config.GoogleImagesGrabber_timeout) meta = urlObj.info() filesize = int(meta.getheaders("Content-Length")[0]) if filesize > config.GoogleImagesGrabber_maxsize: return "" except urllib2.URLError, IndexError: return "" with open(utils.get_rand_filename(config.temp_dir), 'wb') as f: f.write(urlObj.read()) x = f.name urlObj.close() return x def terminate(self): "Setting _terminated to True" self._terminated = True super(GoogleImagesGrabberThread, self).terminate() class LyricsGrabberThread(QtCore.QThread): MainResult = QtCore.pyqtSignal(utils.cls.LyricsData) MinorResult = QtCore.pyqtSignal(utils.cls.LyricsData) eof = QtCore.pyqtSignal() error = QtCore.pyqtSignal(object)
str(e)) self.output.emit(fn_list) def fetchPhoto(self, url): req = urllib2.Request(url, headers=config.generic_http_headers) try: urlObj = urllib2.urlopen( req, timeout=config.GoogleImagesGrabber_timeout) meta = urlObj.info() filesize = int(meta.getheaders("Content-Length")[0]) if filesize > config.GoogleImagesGrabber_maxsize: return "" except urllib2.URLError, IndexError: return "" with open(utils.get_rand_filename(config.temp_dir), 'wb') as f: f.write(urlObj.read()) x = f.name urlObj.close() return x def terminate(self): "Setting _terminated to True" self._terminated = True super(GoogleImagesGrabberThread, self).terminate() class LyricsGrabberThread(QtCore.QThread): MainResult = QtCore.pyqtSignal(utils.cls.LyricsData) MinorResult = QtCore.pyqtSignal(utils.cls.LyricsData) eof = QtCore.pyqtSignal()