Exemplo n.º 1
0
    def _open_uri(self, uri, play=True):
        """
            Determines the type of a uri, imports it into a playlist, and
            starts playing it
        """
        from xl import playlist, trax
        if playlist.is_valid_playlist(uri):
            pl = playlist.import_playlist(uri)
            self.main.add_playlist(pl)
            if play:
                self.exaile.queue.play()
        else:
            pl = self.main.get_selected_playlist()
            column, descending = pl.get_sort_by()

            tracks = trax.get_tracks_from_uri(uri)
            tracks = trax.sort_tracks(pl.return_order_tags(column), tracks)

            try:
                pl.playlist.add_tracks(tracks)
                pl.playlist.set_current_pos(len(pl.playlist) - len(tracks))
                self.exaile.queue.play()
            # Catch empty directories
            except IndexError:
                pass
Exemplo n.º 2
0
    def _open_uri(self, uri, play=True):
        """
            Determines the type of a uri, imports it into a playlist, and
            starts playing it
        """
        from xl import playlist, trax
        if playlist.is_valid_playlist(uri):
            pl = playlist.import_playlist(uri)
            self.main.add_playlist(pl)
            if play:
                self.exaile.queue.play()
        else:
            pl = self.main.get_selected_playlist()
            column, descending = pl.get_sort_by()

            tracks = trax.get_tracks_from_uri(uri)
            tracks = trax.sort_tracks(pl.return_order_tags(column), tracks)

            try:
                pl.playlist.add_tracks(tracks)
                pl.playlist.set_current_pos(len(pl.playlist) - len(tracks))
                self.exaile.queue.play()
            # Catch empty directories
            except IndexError:
                pass
Exemplo n.º 3
0
    def _get_playlist(self, url, playlist_id):
        """
            Gets the playlist for the given url and id
        """
        if playlist_id not in self.playlists:
            set_status(_('Contacting SomaFM server...'))
            self.playlists[playlist_id] = playlist.import_playlist(url)
            set_status('')

        return self.playlists[playlist_id]
Exemplo n.º 4
0
    def _get_playlist(self, url, playlist_id):
        """
            Gets the playlist for the given url and id
        """
        if playlist_id not in self.playlists:
            set_status(_('Contacting SomaFM server...'))
            self.playlists[playlist_id] = playlist.import_playlist(url)
            set_status('')

        return self.playlists[playlist_id]
Exemplo n.º 5
0
    def _get_playlist(self, name, station_id):
        """
            Gets the playlist for the given name and id
        """
        if station_id in self.playlists:
            return self.playlists[station_id]
        url = self.icecast_url + '/listen/' + station_id + '/listen.xspf'
        set_status(_('Contacting Icecast server...'))

        self.playlists[station_id] = playlist.import_playlist(url)
        set_status('')
        return self.playlists[station_id]
Exemplo n.º 6
0
    def _do_add_playlist(self, name, uri):
        from xl import playlist, trax
        if playlist.is_valid_playlist(uri):
            pl = playlist.import_playlist(uri)
            pl.name = name
        else:
            pl = playlist.Playlist(name)
            tracks = trax.get_tracks_from_uri(uri)
            pl.extend(tracks)

        self.playlist_manager.save_playlist(pl)
        self._add_to_tree(pl)
Exemplo n.º 7
0
    def _do_add_playlist(self, name, uri):
        from xl import playlist, trax
        if playlist.is_valid_playlist(uri):
            pl = playlist.import_playlist(uri)
            pl.name = name
        else:
            pl = playlist.Playlist(name)
            tracks = trax.get_tracks_from_uri(uri)
            pl.extend(tracks)

        self.playlist_manager.save_playlist(pl)
        self._add_to_tree(pl)
Exemplo n.º 8
0
    def _get_playlist(self, name, station_id):
        """
            Gets the playlist for the given name and id
        """
        if station_id in self.playlists:
            return self.playlists[station_id]
        url = self.icecast_url + '/listen/' + station_id + '/listen.xspf'
        set_status(_('Contacting Icecast server...'))

        self.playlists[station_id] = playlist.import_playlist(url)
        set_status('')
        return self.playlists[station_id]
Exemplo n.º 9
0
    def _get_playlist(self, url, playlist_id):
        """
            Gets the playlist for the given url and id
        """
        if playlist_id not in self.playlists:
            set_status(_('Contacting SomaFM server...'))
            try:
                self.playlists[playlist_id] = playlist.import_playlist(url)
            except Exception:
                set_status(_("Error importing playlist"))
                logger.exception("Error importing playlist")
            set_status('')

        return self.playlists[playlist_id]
Exemplo n.º 10
0
    def _get_playlist(self, url, playlist_id):
        """
            Gets the playlist for the given url and id
        """
        if playlist_id not in self.playlists:
            set_status(_('Contacting SomaFM server...'))
            try:
                self.playlists[playlist_id] = playlist.import_playlist(url)
            except:
                set_status(_("Error importing playlist"))
                logger.exception("Error importing playlist")
            set_status('')

        return self.playlists[playlist_id]
Exemplo n.º 11
0
    def open_uri(self, uri, play=True):
        """
            Determines the type of a uri, imports it into a playlist, and
            starts playing it
        """
        from xl import playlist, trax

        if playlist.is_valid_playlist(uri):
            try:
                playlist = playlist.import_playlist(uri)
            except playlist.InvalidPlaylistTypeError:
                pass
            else:
                self.main.playlist_container.create_tab_from_playlist(playlist)

                if play:
                    player.QUEUE.current_playlist = playlist
                    player.QUEUE.current_playlist.current_position = 0
                    player.QUEUE.play(playlist[0])
        else:
            page = self.main.get_selected_page()
            column = page.view.get_sort_column()
            reverse = False
            sort_by = common.BASE_SORT_TAGS

            if column:
                reverse = column.get_sort_order() == Gtk.SortType.DESCENDING
                sort_by = [column.name] + sort_by

            tracks = trax.get_tracks_from_uri(uri)
            tracks = trax.sort_tracks(sort_by, tracks, reverse=reverse)

            try:
                page.playlist.extend(tracks)
                page.playlist.current_position = len(
                    page.playlist) - len(tracks)

                if play:
                    player.QUEUE.current_playlist = page.playlist
                    player.QUEUE.play(tracks[0])
            # Catch empty directories
            except IndexError:
                pass
Exemplo n.º 12
0
    def open_uri(self, uri, play=True):
        """
            Determines the type of a uri, imports it into a playlist, and
            starts playing it
        """
        from xl import playlist, trax

        if playlist.is_valid_playlist(uri):
            try:
                playlist = playlist.import_playlist(uri)
            except playlist.InvalidPlaylistTypeError:
                pass
            else:
                self.main.playlist_container.create_tab_from_playlist(playlist)

                if play:
                    player.QUEUE.current_playlist = playlist
                    player.QUEUE.current_playlist.current_position = 0
                    player.QUEUE.play(playlist[0])
        else:
            page = self.main.get_selected_page()
            column = page.view.get_sort_column()
            reverse = False
            sort_by = common.BASE_SORT_TAGS

            if column:
                reverse = column.get_sort_order() == Gtk.SortType.DESCENDING
                sort_by = [column.name] + sort_by

            tracks = trax.get_tracks_from_uri(uri)
            tracks = trax.sort_tracks(sort_by, tracks, reverse=reverse)

            try:
                page.playlist.extend(tracks)
                page.playlist.current_position = len(page.playlist) - len(tracks)

                if play:
                    player.QUEUE.current_playlist = page.playlist
                    player.QUEUE.play(tracks[0])
            # Catch empty directories
            except IndexError:
                pass
Exemplo n.º 13
0
    def _handle_unknown_drag_data(self, loc):
        """
            Handles unknown drag data that has been recieved by
            drag_data_received.  Unknown drag data is classified as
            any loc (location) that is not in the collection of tracks
            (i.e. a new song, or a new playlist)

            @param loc:
                the location of the unknown drag data

            @returns: a 2 tuple in which the first part is a list of tracks
                and the second is a list of playlist
        """
        filetype = None
        info = urlparse.urlparse(loc)

        # don't use gio to test the filetype if it's a non-local file
        # (otherwise gio will try to connect to every remote url passed in and
        # cause the gui to hang)
        if info.scheme in ('file', ''):
            try:
                filetype = (
                    Gio.File.new_for_uri(loc)
                    .query_info('standard::type', Gio.FileQueryInfoFlags.NONE, None)
                    .get_file_type()
                )
            except GLib.Error:
                filetype = None

        if trax.is_valid_track(loc) or info.scheme not in ('file', ''):
            new_track = trax.Track(loc)
            return ([new_track], [])
        elif xl_playlist.is_valid_playlist(loc):
            # User is dragging a playlist into the playlist list
            # so we add all of the songs in the playlist
            # to the list
            new_playlist = xl_playlist.import_playlist(loc)
            return ([], [new_playlist])
        elif filetype == Gio.FileType.DIRECTORY:
            return (trax.get_tracks_from_uri(loc), [])
        else:  # We don't know what they dropped
            return ([], [])
Exemplo n.º 14
0
    def on_response(self, dialog, response):
        """
            Notifies about selected URIs
        """
        self.hide()

        if response == gtk.RESPONSE_OK:
            PlaylistImportDialog._last_location = self.get_current_folder_uri()
            
            playlists = []
            for uri in self.get_uris():            
                try:
                    playlists.append(import_playlist(uri))
                except InvalidPlaylistTypeError, e:
                    error(None, 'Invalid playlist "%s": %s' % (uri, e))
                    self.destroy()
                    return
                except Exception, e:
                    error(None, 'Invalid playlist "%s": (internal error): %s' % (uri, e))
                    self.destroy()
                    return