Ejemplo n.º 1
0
 def __call__(self, input_filename, output_filename):
     extension = '.' + os.path.splitext(input_filename)[1][1:].lower()
     if not output_filename.lower().endswith(extension):
         output_filename += extension
     make_target_directory(output_filename)
     if not skip_action(input_filename, output_filename):
         copyfile(input_filename, output_filename)
         status = self.STATUS_SKIPTAGS  # no need to copy tags
     else:
         status = self.STATUS_SKIP
     return output_filename, status
Ejemplo n.º 2
0
def copy_coverart(task, size=250, name='cover.jpg', format='jpeg'):
    '''
    Copy cover art for the transcoding task
    '''
    if not task.result:
        raise ValueError('can not process a task that is not finished yet')
    source = locate_coverart(task.source)
    if source:
        destination = os.path.join(os.path.dirname(task.result), name)
        if not skip_action(source, destination):
            make_target_directory(destination)
            image = Image.open(source)
            image.thumbnail((size, size))
            image.save(destination, format=format)
Ejemplo n.º 3
0
    def __call__(self, input_filename, output_filename):
        '''Transcode file from one format to another'''
        extension = '.' + self.extension.lower()
        if not output_filename.lower().endswith(extension):
            output_filename += extension

        make_target_directory(output_filename)
        if not skip_action(input_filename, output_filename):
            # ffmpeg format names usually match extension
            input_format = os.path.splitext(input_filename)[1][1:].lower()
            AudioSegment \
                .from_file(input_filename, input_format) \
                .export(output_filename, **self.export_params)
            status = self.STATUS_OK
        else:
            status = self.STATUS_SKIP
        return output_filename, status
Ejemplo n.º 4
0
def copy_lyrics(task, lyrics_finder=None):
    '''
    Copy lyrics for the transcoding task
    '''
    if not task.result:
        raise ValueError('can not process a task that is not finished yet')
    if lyrics_finder is None:
        lyrics_finder = read_lyrics
    destination = os.path.splitext(task.result)[0] + '.txt'
    if not os.path.exists(destination):
        try:
            artist = task.tags['artist'][0]
            title = task.tags['title'][0]
        except Exception:
            artist = task.path_elements['artist']
            title = task.path_elements['title']
        text = lyrics_finder(artist, title)
        if text:
            make_target_directory(destination)
            with open(destination, 'w') as f:
                f.write(text)
Ejemplo n.º 5
0
 def __call__(self, input_filename, output_filename):
     extension = os.path.splitext(input_filename)[1].lower()
     if not output_filename.lower().endswith(extension):
         output_filename += extension
     make_target_directory(output_filename)
     if not skip_action(input_filename, output_filename):
         if os.path.exists(output_filename):
             os.remove(output_filename)
         os.symlink(input_filename, output_filename)
         status = self.STATUS_SKIPTAGS
     else:
         status = self.STATUS_SKIP
     meta_dir = os.path.join(os.path.dirname(input_filename),
                             METADATA_DIRECTORY)
     if os.path.exists(meta_dir):
         meta_dest = os.path.join(os.path.dirname(output_filename),
                                  METADATA_DIRECTORY)
         try:
             os.symlink(meta_dir, meta_dest)
         except OSError:
             pass
     return output_filename, status