Exemple #1
0
    def on_generate_clicked(self, widget):

        output_fname = 'analysis'
        playlists = self._get_selected_playlists()

        # validate user selections

        tmpl_data = self._get_selected_template()
        if tmpl_data is None:
            self.info_bar.show_error("No template selected")
            return

        if len(playlists) < 1:
            self.info_bar.show_error("No playlist selected")
            return

        if len(playlists) == 1:
            pname = playlists[0].name
            output_fname = '%s%sanalysis.html' % (pname,
                                                  ' ' if ' ' in pname else '-')

        # get output file
        output_uri = dialogs.save(
            self.window,
            output_fname,
            'plugin/playlistanalyzer/dlg_location',
            None,
            _("Save analysis"),
        )

        if output_uri is None:
            return

        # figure out the output track list
        # -> if the user selects more than one playlist, we separate the
        #    track list with a None so it can be detected if necessary
        tracks = []
        for pl in playlists:
            if len(tracks) > 0:
                tracks.append(None)
            tracks.extend(pl)

        tagdata = self._get_tag_data()

        # generate, write it out
        try:
            kwargs = {
                'tagdata': json.dumps(tagdata),
                'playlist_names': [pl.name for pl in playlists],
                'data': json.dumps(self.plugin.generate_data(tracks, tagdata)),
                'title': self._get_title(),
            }

            self.plugin.write_to_file(tmpl_data['fname'], output_uri, **kwargs)
        except Exception as e:
            logger.exception("Error generating analysis")
            self.info_bar.show_error("Error generating analysis", str(e))
        else:
            # and that's all folks
            self.destroy()
Exemple #2
0
    def on_generate_clicked(self, widget):

        output_fname = 'analysis'
        playlists = self._get_selected_playlists()

        # validate user selections

        tmpl_data = self._get_selected_template()
        if tmpl_data is None:
            self.info_bar.show_error("No template selected")
            return

        if len(playlists) < 1:
            self.info_bar.show_error("No playlist selected")
            return

        if len(playlists) == 1:
            pname = playlists[0].name
            output_fname = '%s%sanalysis.html' % (pname, ' ' if ' ' in pname else '-')

        # get output file
        output_uri = dialogs.save(
            self.window,
            output_fname,
            'plugin/playlistanalyzer/dlg_location',
            None,
            _("Save analysis"),
        )

        if output_uri is None:
            return

        # figure out the output track list
        # -> if the user selects more than one playlist, we separate the
        #    track list with a None so it can be detected if necessary
        tracks = []
        for pl in playlists:
            if len(tracks) > 0:
                tracks.append(None)
            tracks.extend(pl)

        tagdata = self._get_tag_data()

        # generate, write it out
        try:
            kwargs = {
                'tagdata': json.dumps(tagdata),
                'playlist_names': [pl.name for pl in playlists],
                'data': json.dumps(self.plugin.generate_data(tracks, tagdata)),
                'title': self._get_title(),
            }

            self.plugin.write_to_file(tmpl_data['fname'], output_uri, **kwargs)
        except Exception as e:
            logger.exception("Error generating analysis")
            self.info_bar.show_error("Error generating analysis", str(e))
        else:
            # and that's all folks
            self.destroy()
Exemple #3
0
def export_tags(exaile):
    '''
        Exports all tags to a user specified JSON file
    '''

    uri = dialogs.save(
        parent=exaile.gui.main.window,
        output_fname='tags.json',
        output_setting='plugin/grouptagger/export_dir',
        title=_('Export tags to JSON'),
        extensions={'.json': 'grouptagger JSON export'},
    )

    if uri is not None:

        # collect the data
        trackdata = {}
        for strack in search.search_tracks_from_string(exaile.collection, ''):
            track = strack.track
            tags = list(sorted(get_track_groups(track)))
            if tags:
                trackdata[track.get_loc_for_io()] = tags

        data = {
            '_meta': {
                'date': time.strftime('%Y-%m-%d %H:%M:%S'),
                'exporter': 'Exaile/%s' % exaile.get_version(),
                'version': 1,
            },
            'tracks': trackdata,
        }

        # save it
        with GioFileOutputStream(Gio.File.new_for_uri(uri), 'w') as fp:
            json.dump(data,
                      fp,
                      sort_keys=True,
                      indent=4,
                      separators=(',', ': '))

        logger.info("Exported tags of %s tracks to %s", len(trackdata), uri)
Exemple #4
0
def export_tags(exaile):
    '''
        Exports all tags to a user specified JSON file
    '''

    uri = dialogs.save(
        parent=exaile.gui.main.window,
        output_fname='tags.json',
        output_setting='plugin/grouptagger/export_dir',
        title=_('Export tags to JSON'),
        extensions={'.json': 'grouptagger JSON export'},
    )

    if uri is not None:

        # collect the data
        trackdata = {}
        for strack in search.search_tracks_from_string(exaile.collection, ''):
            track = strack.track
            tags = list(sorted(get_track_groups(track)))
            if tags:
                trackdata[track.get_loc_for_io()] = tags

        data = {
            '_meta': {
                'date': time.strftime('%Y-%m-%d %H:%M:%S'),
                'exporter': 'Exaile/%s' % exaile.get_version(),
                'version': 1,
            },
            'tracks': trackdata,
        }

        # save it
        with GioFileOutputStream(Gio.File.new_for_uri(uri), 'w') as fp:
            json.dump(data, fp, sort_keys=True, indent=4, separators=(',', ': '))

        logger.info("Exported tags of %s tracks to %s", len(trackdata), uri)