Skip to content

Commit

Permalink
Tagging revision 177 as version 0.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
zpchavez committed Jan 8, 2011
1 parent da6b7d9 commit f90cac6
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 421 deletions.
2 changes: 1 addition & 1 deletion src/boottunes.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ from dialogs.newversion import NewVersionDialog
from settings import getSettings, SettingsError
import data

__version__ = "0.1.8"
__version__ = "0.1.7"

class MainWindow(QMainWindow):
def __init__(self, parent=None):
Expand Down
2 changes: 1 addition & 1 deletion src/data/json/common-cities.json

Large diffs are not rendered by default.

85 changes: 30 additions & 55 deletions src/dialogs/queuedialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ def loadDirContents(self, dirOrDirs):

if isinstance(metadata, tuple):
for metadatum in metadata:
if not getSettings().isCompleted(metadatum['hash']):
if not getSettings().isCompleted(metadatum['hash']):
metadatum['cover'] = CoverArtRetriever.getCoverImageChoices(metadatum)[0][0]
self.addToQueue(metadatum)
self.queueListWidget.sortItems()
else:
if getSettings().isCompleted(metadata['hash']):
msgBox = QMessageBox(self)
msgBox.setWindowTitle('BootTunes')
msgBox.setText('This recording has already been converted.')
msgBox.setInformativeText('Do you want to convert it again?')
msgBox.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
Expand Down Expand Up @@ -255,23 +255,26 @@ def getMetadataFromDir(self, dirName):
metadata = TxtParser(fileHandle.read()).parseTxt()

fileHandle.close()

foundCount = 0
for k, v in metadata.iteritems():
if v:
foundCount += 1
if foundCount < 4 and not theFinalTxt:
continue

if metadata['tracklist'] == None:
raise QueueDialogError("Could not find a tracklist in " + txtFile)

validExtensions = ['*.flac', '*.shn', '*.m4a']

# Must contain valid audio files
qDir.setNameFilters(validExtensions)
filePaths = []
filePaths = []
fileNameEncoding = 'utf_8' if systemName == 'Darwin' else encoding
for file in qDir.entryList():
filePath = unicode(qDir.absolutePath() + '/' + file).encode(fileNameEncoding)
filePaths.append(filePath)
for file in qDir.entryList():
filePath = unicode(qDir.absolutePath() + '/' + file).encode(fileNameEncoding)
filePaths.append(filePath)
# The show could be split up between folders, e.g. CD1 and CD2
if len(filePaths) == 0:
qDir.setNameFilters('*')
Expand All @@ -280,31 +283,24 @@ def getMetadataFromDir(self, dirName):
qSubdir = QDir(qDir.absolutePath() + '/' + subdirStr)
qSubdir.setNameFilters(validExtensions)
for file in qSubdir.entryList():
filePaths.append(unicode(qSubdir.absolutePath()) + '/' + unicode(file))

filePaths.append(unicode(qSubdir.absolutePath()) + '/' + unicode(file))
if len(filePaths) == 0:
raise QueueDialogError("Directory does not contain any supported audio files (FLAC, SHN, ALAC)");

if metadata['tracklist'] == None:
metadata['tracklist'] = ['' for x in filePaths]

if len(metadata['tracklist']) < len(filePaths):
elif len(metadata['tracklist']) < len(filePaths):
raise QueueDialogError("More audio files found than tracks in the tracklist")

# If more tracks detected than files exist, assume the extra tracks are an error
del metadata['tracklist'][len(filePaths):]
del metadata['tracklist'][len(filePaths):]

nonParsedMetadata = {}
metadata['audioFiles'] = filePaths

nonParsedMetadata['audioFiles'] = filePaths

nonParsedMetadata['dir'] = qDir
metadata['dir'] = qDir
# Hash used for identicons and temp directory names
nonParsedMetadata['hash'] = hashlib.md5(metadata['comments'].encode('utf_8')).hexdigest()
metadata['hash'] = hashlib.md5(metadata['comments'].encode('utf_8')).hexdigest()
# The dir where all temporary files for this recording will be stored
nonParsedMetadata['tempDir'] = QDir(getSettings().settingsDir + '/' + nonParsedMetadata['hash'])
if not nonParsedMetadata['tempDir'].exists():
nonParsedMetadata['tempDir'].mkpath(nonParsedMetadata['tempDir'].absolutePath())
metadata['tempDir'] = QDir(getSettings().settingsDir + '/' + metadata['hash'])
if not metadata['tempDir'].exists():
metadata['tempDir'].mkpath(metadata['tempDir'].absolutePath())

try:
# Assume that an artist name found in the actual file metadata is more accurate
Expand All @@ -313,24 +309,17 @@ def getMetadataFromDir(self, dirName):
if self.loadingMultipleShows:
raise QueueDialogError('Malformed FLAC files. Load this show alone to fix.')
else:
metadata.update(nonParsedMetadata)
self.fixBadFlacFiles(metadata)
else:
audioFileMetadata = audioFile.get_metadata()
if audioFileMetadata and audioFileMetadata.artist_name:
txtParser = TxtParser(metadata['comments'])
txtParser.artist = audioFileMetadata.artist_name
metadata = txtParser.parseTxt()
metadata['artist'] = audioFileMetadata.artist_name
except audiotools.UnsupportedFile as e:
raise QueueDialogError(os.path.basename(filePaths[0]) + " is an unsupported file: ")

nonParsedMetadata['cover'] = CoverArtRetriever.getCoverImageChoices(nonParsedMetadata)[0][0]

metadata.update(nonParsedMetadata)

return metadata

except IOError as e:
except IOError as e:
raise QueueDialogError("Could not read file: " + txtFile + "<br /><br />" + e.args[1])
except UnicodeDecodeError as e:
raise QueueDialogError("Could not read file: " + txtFile + "<br /><br />" + e.args[4])
Expand Down Expand Up @@ -365,7 +354,7 @@ def addToQueue(self, metadata):
"""
detectedArtist = metadata['artist']

defaults = getSettings().getArtistDefaults(detectedArtist)
defaults = getSettings().getArtistDefaults(detectedArtist)
if defaults:
metadata['defaults'] = defaults

Expand Down Expand Up @@ -406,21 +395,15 @@ def addToQueue(self, metadata):
else:
albumTitle = albumTitle.replace('[' + placeHolder + ']', replacement)

if len(set(metadata['tracklist'])) == 1 and metadata['tracklist'][0] == '':
albumTitle += ' [empty tracklist]'
self.queueItemData[path]['valid'] = False

if not artistName:
artistName = '[missing artist]'
self.queueItemData[path]['valid'] = False

listItem.setText(artistName + ' - ' + albumTitle)
if self.queueItemData[path]['valid'] == False:
listItem.setBackground(QBrush(QColor(255, 0, 0)))
listItem.setForeground(QBrush(QColor(255, 255, 255)))
else:
listItem.setBackground(QBrush(QColor(255, 255, 255)))
listItem.setForeground(QBrush(QColor(0, 0, 0)))
metadata['albumTitle'] = albumTitle

def addToITunes(self):
Expand Down Expand Up @@ -542,7 +525,7 @@ def conversionComplete(self):
self.removeCompletedRecordings()

def badFlacFixingComplete(self):
"""
"""maps.google.com
Called on completion of FixBadFlacsThread.
"""
if hasattr(self, 'metadata') and self.metadata:
Expand Down Expand Up @@ -686,10 +669,8 @@ def run(self):

if 'defaults' in metadata:
artistName = metadata['defaults']['preferred_name'].decode('utf_8')
genre = metadata['defaults']['genre']
else:
artistName = metadata['artist']
genre = ''

parent.currentTrackName = metadata['tracklist'][parent.currentTrack]

Expand All @@ -704,22 +685,23 @@ def run(self):
comment = metadata['comments']
)
self.emit(SIGNAL("progress(int, QString)"), progressCounter, 'Converting "' + parent.currentTrackName + '"')

imageData = currentRecording['imageData']

alacMetadata.add_image(audiotools.Image.new(currentRecording['imageData'], 'cover', 0))
genre = metadata['defaults']['genre']
sourcePcm = currentRecording['pcmReaders'][parent.currentTrack]
targetFile = tempDirPath + '/' + unicode(parent.currentTrack) + u'.m4a'

# If on Mac, run as a separate process
if systemName == 'Darwin':
self.process = Process(
target=self.encodeProcess,
args=(targetFile, sourcePcm, alacMetadata, genre, imageData)
args=(targetFile, sourcePcm, alacMetadata, genre)
)
self.process.start()
while self.process.is_alive() and not self.isStopped():
pass
else:
self.encodeProcess(targetFile, sourcePcm, alacMetadata, genre, imageData)
self.encodeProcess(targetFile, sourcePcm, alacMetadata, genre)

if self.isStopped():
return
Expand Down Expand Up @@ -750,33 +732,26 @@ def run(self):
self.completed = True
self.stop()

def encodeProcess(self, targetFile, sourcePcm, alacMetadata, genre, imageData):
def encodeProcess(self, targetFile, sourcePcm, alacMetadata, genre):
"""
The actual m4a encoding process.
@type targetFile: unicode
@type sourcePcm: audiotool.PCMReader
@type alacMetadata: audiotools.MetaData
@type genre: unicode
@type imageData: str
"""
if re.match('^m4a$', self.extension, re.IGNORECASE):
shutil.copyfile(self.currentFile, targetFile)
alacFile = audiotools.open(targetFile)
else:
alacFile = audiotools.ALACAudio.from_pcm(targetFile, sourcePcm)
alacFile.set_metadata(alacMetadata)
metadata = alacFile.get_metadata()
# Set the "part of a compilation" flag to false
metadata = alacFile.get_metadata()
metadata['cpil'] = metadata.text_atom('data', '\x00\x00\x00\x15\x00\x00\x00\x00\x00')
metadata['\xa9gen'] = metadata.text_atom('\xa9gen', genre)
alacFile.set_metadata(metadata)
# Separately attempt to set the cover art, since a MemoryError may occur in large files
try:
metadata.add_image(audiotools.Image.new(imageData, 'cover', 0))
alacFile.set_metadata(metadata)
except MemoryError:
pass

def stop(self):
with QMutexLocker(self.mutex):
Expand Down
Loading

0 comments on commit f90cac6

Please sign in to comment.