Esempio n. 1
0
 def _cachePlaylists(self):
     self.cache_playlists = {}
     conf = tanooki_library.get_or_create_config()
     for playlist_name, files in conf['playlists'].iteritems():
         self.cache_playlists[playlist_name] = {'urls': files,
                                                'names': [getSongName(url) for url in files],
                                                'icons': [getCoverArtPixmap(url) for url in files]}
Esempio n. 2
0
 def filesDropped(self, urls, internal_drop=False):
     valid_urls = []
     not_playlist = not self.config.playlist
     print urls
     if internal_drop:
         conf = tanooki_library.get_or_create_config()
         for album in [album for album in conf['library'].itervalues() if os.path.abspath(album['folder']).startswith(os.path.abspath(urls[0]))]:
             valid_urls = True
             self.config.playlist += album['songs']
             old_count = len(self.playlist)
             self.playlist.addItems(album['titles'])
             for i in range(old_count, old_count+len(album['songs'])):
                 self.playlist.item(i).setIcon(QtGui.QIcon(album['cover']))
     else:
         for url in urls:
             if os.path.isdir(url):
                 for filename in dirEntries(url, True, 'mp3'):
                     filename = os.path.join(url, filename)
                     valid_urls.append(filename)
                     self._addUrl(filename)
             elif os.path.exists(url) and url[url.rfind('.'):] == '.mp3':
                 valid_urls.append(url)
                 self._addUrl(url)
         self.config.playlist += valid_urls
     if not_playlist and valid_urls:
         self.config.idx = 0
         self._playIdx()
Esempio n. 3
0
 def appendAlbumPlaylist(self, album):
     conf = tanooki_library.get_or_create_config()
     for filename in conf['library'][album]['songs']:
             #song_file = File(filename)
             name = getSongName(filename)
             if unicode(self.search_name.text()).lower() in name.lower():
                 self.config.playlist.append(filename)
                 self._addUrl(filename)
Esempio n. 4
0
    def __init__(self, taskbar, g2tsg, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.setupUi(self)
        self.config = RuntimeConfig()
        self.icon = QtGui.QSystemTrayIcon(QtGui.QIcon(':/png/media/icon.png'))
        conf = tanooki_library.get_or_create_config()

        ischecked = conf.get('notification', False)
        self.notification.setChecked(ischecked)
        if ischecked:
            self.icon.show()

        self.config.g2tsg = g2tsg
        self.config.g2tsg.init_tanooki()

        self.taskbar = taskbar

        delegate = SpinBoxDelegate()
        self.albums.setItemDelegate(delegate)

        self.play_thread = QtCore.QThread(parent=self)
        self.paint_thread = QtCore.QThread(parent=self)
        self.slider_thread = QtCore.QThread(parent=self)
        self.volume_thread = QtCore.QThread(parent=self)
        self.gain_thread = QtCore.QThread(parent=self)

        self.gain_thread.run = self.getGainThread
        self.gain_thread.finished.connect(self.gainFinished)

        self.file_model = QtGui.QFileSystemModel(parent=self)

        self.setWindowTitle('Frey')
        self.setWindowIcon(QtGui.QIcon(':/png/media/icon.png'))
        self.setAcceptDrops(True)

        self.__class__.dropEvent = self.lbDropEvent
        self.__class__.dragEnterEvent = self.lbDragEnterEvent

        self._refreshFolderTree()
        self._showLibrary()
        self._refreshPlaylists()

        self.slider_thread.run = self._updateSlider
        self.slider_thread.start()
        self.seeker.setEnabled(False)

        self.volume_thread.run = self._updateVolume
        self.volume_thread.start()

        self.config_overlays()

        self.time.display("00:00")

        self.volume.setFocusPolicy(QtCore.Qt.NoFocus)
        self._connectSlots()
        self.albums.setEditTriggers(QTableWidget.NoEditTriggers)

        self._cachePlaylists()
Esempio n. 5
0
 def editAlbumEvent(self, event):
     i = self.albums.currentRow()
     j = self.albums.currentColumn()
     album = self.config.albumslist[i*self.config.num_col+j]
     conf = tanooki_library.get_or_create_config()
     songs = conf['library'][album]['songs']
     titles = conf['library'][album]['titles']
     self.config.songs_to_edit = [song for n, song in enumerate(songs) if unicode(self.search_name.text()).lower() in titles[n].lower()]
     self.editSongs()
Esempio n. 6
0
 def _savePlaylist(self):
     if self.config.playlist:
         text, ok = QtGui.QInputDialog.getText(self, "Playlist Name", "", QtGui.QLineEdit.Normal, get_random_name())
         text = unicode(text)
         if ok and text != '':
             conf = tanooki_library.get_or_create_config()
             conf['playlists'][text] = self.config.playlist[:]
             tanooki_library.save_config(conf)
             self._refreshPlaylists()
Esempio n. 7
0
    def _syncPlaylists(self, only_export=False):
        conf = tanooki_library.get_or_create_config()
        self.progresswidget.cover.setPixmap(QtGui.QPixmap(_fromUtf8(":/png/media/nocover.png")))
        self.progress_overlay.show()

        tanooki_itunes.export_playlists(conf['playlists'], self.progresswidget, only_export=only_export)

        if not only_export:
            self._refreshPlaylists()
        self.progress_overlay.hide()
Esempio n. 8
0
def from_itunes_to_sg(sg_playlists, itunes):
    playlists = get_itunes_playlists(itunes)

    #removing old versions
    #map(lambda x: x.delete(), [playlist for playlist in playlists if playlist.name in sg_playlists])

    for playlist in [p for p in playlists if not p.Name in sg_playlists]:
        sg_playlists[playlist.Name] = [get_track_location(track) for track in playlist.Tracks if get_track_location(track).endswith('.mp3')]
    conf = tanooki_library.get_or_create_config()
    conf['playlists'] = sg_playlists
    tanooki_library.save_config(conf)
Esempio n. 9
0
 def toggleNotification(self, ischecked):
     if not ischecked:
         self.icon.hide()
     else:
         self.icon.show()
         if self.config.playlist:
             self.updateNowPlaying(self.config.playlist[self.config.idx])
         else:
             self.icon.setIcon(QtGui.QIcon(':/png/media/icon.png'))
     conf = tanooki_library.get_or_create_config()
     conf['notification'] = ischecked
     tanooki_library.save_config(conf)
Esempio n. 10
0
    def display_overlay(self, album):
        if album is None:
            return
        conf = tanooki_library.get_or_create_config()
        for filename in conf['library'][album]['songs']:
            #song_file = File(filename)
            name = getSongName(filename)
            if unicode(self.search_name.text()).lower() in name.lower():
                self.config.overlay_songs.append(filename)
                QtGui.QListWidgetItem(name, self.overlay.album_songs)

        icon = QtGui.QIcon(conf['library'][album]['cover'])
        cover_width = self.overlay.cover.width()
        self.overlay.cover.setPixmap(icon.pixmap(cover_width, cover_width))
Esempio n. 11
0
    def _refreshFolderTree(self):
        conf = tanooki_library.get_or_create_config()
        self.file_model.setRootPath(conf['folder'])
        self.file_model.setFilter(QtCore.QDir.Dirs | QtCore.QDir.NoDotAndDotDot)
        self.current_path = ' '

        self.tree_filter = FilterModel(self, conf['folder'])
        self.tree_filter.setSourceModel(self.file_model)
        self.folder_tree.setModel(self.tree_filter)
        self.folder_tree.hideColumn(1)
        self.folder_tree.hideColumn(2)
        self.folder_tree.hideColumn(3)
        root_path = os.path.abspath(os.path.join(conf['folder'], os.path.pardir))
        self.folder_tree.setRootIndex(self.tree_filter.mapFromSource(self.file_model.index(root_path)))

        self.folder_tree.expandToDepth(1)
Esempio n. 12
0
    def _showLibrary(self):
        global cover_size
        self.config.search_query = unicode(self.search_name.text())

        self.albums.clear()
        conf = tanooki_library.get_or_create_config()
        self.albums.setSortingEnabled(False)
        i = 0
        j = 0

        albums = tanooki_library.find_albums_by_songname(self.config.search_query)
        albums = [album for album in albums if os.path.abspath(conf['library'][album]['folder']).startswith(os.path.abspath(self.current_path))]
        albums = [album for album in albums if unicode(self.search_artist.text()).lower() in conf['library'][album]['artist'].lower()]
        albums = [album for album in albums if unicode(self.search_album.text()).lower() in album.lower()]

        self.config.albumslist = []
        #num_albums = len(conf['library'])
        num_albums = len(albums)

        import math
        self.config.num_col = self.albums.width()//cover_size
        self.albums.setRowCount(int(math.ceil(float(num_albums)/self.config.num_col)))
        self.albums.setColumnCount(self.config.num_col)

        for k in range(self.albums.rowCount()):
            self.albums.setRowHeight(k, cover_size+20)
        for k in range(self.albums.columnCount()):
            self.albums.setColumnWidth(k, cover_size+1)

        #alb_art = [[album, conf['library'][album]['artist']] for album in conf['library']]
        alb_art = [[album, conf['library'][album]['artist']] for album in albums]
        album_sorted = [e[0] for e in sorted(alb_art, key=lambda e: e[1]+e[0])]

        for album in album_sorted:
            self.config.albumslist.append(album)
            html = '<img src="'+conf['library'][album]['cover']+'" /><br>'+album
            item = QtGui.QTableWidgetItem(html)
            item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsDragEnabled)
            self.albums.setItem(i, j, item)
            if j == self.config.num_col - 1:
                i += 1
            j = (j+1) % self.config.num_col
        while j < self.config.num_col:
            item = QtGui.QTableWidgetItem('')
            item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
            self.albums.setItem(i, j, item)
            j += 1
Esempio n. 13
0
    def _randomPlaylist(self, *args):
        not_playlist = not self.config.playlist
        conf = tanooki_library.get_or_create_config()

        random_songs = []
        for album in random.sample(conf['library'].values(), 30):
            idx = random.choice(range(len(album['songs'])))
            random_songs.append((album['songs'][idx], album['titles'][idx], album['cover']))

        self.config.playlist += [r[0] for r in random_songs]

        old_count = len(self.playlist)
        self.playlist.addItems([r[1] for r in random_songs])

        for idx, i in enumerate(range(old_count, old_count+len(random_songs))):
            self.playlist.item(i).setIcon(QtGui.QIcon(random_songs[idx][2]))

        if not_playlist and self.config.playlist:
            self.config.idx = 0
            self._playIdx()
Esempio n. 14
0
def sync_playlists(sg_playlists, itunes, only_export=False):
    it_playlists = get_itunes_playlists(itunes)

    for it_playlist in it_playlists:
        it_tracks = [os.path.abspath(get_track_location(t)) for t in it_playlist.Tracks if get_track_location(t).endswith('.mp3')]
        sg_tracks = [os.path.abspath(t) for t in sg_playlists[it_playlist.Name]]

        if not only_export:
            for it_track in [tr for tr in it_tracks if not tr in sg_tracks]:
                sg_playlists[it_playlist.Name].append(it_track)
        else:
            for it_track in [t for t in it_playlist.Tracks if get_track_location(t).endswith('.mp3') and
                             not os.path.abspath(get_track_location(t)) in sg_tracks]:
                it_track.Delete()

        for sg_track in [tr for tr in sg_tracks if not tr in it_tracks]:
            it_playlist = convert_user_playlist(it_playlist)
            it_playlist.AddFile(sg_track)

    if not only_export:
        conf = tanooki_library.get_or_create_config()
        conf['playlists'] = sg_playlists
        tanooki_library.save_config(conf)
Esempio n. 15
0
def export_playlists(sg_playlists, widget, only_export=False):

    try:
        qapp = QCoreApplication.instance()
        qapp.processEvents()
        widget.progressbar.setMaximum(100)
        widget.label.setText('Starting Itunes...')
        widget.emit(Qt.SIGNAL('updateProgress(int)'), 0)
        qapp.processEvents()

        if win32com.client.gencache.is_readonly:
            win32com.client.gencache.is_readonly = False
            win32com.client.gencache.Rebuild()
        from win32com.client.gencache import EnsureDispatch
        itunes = EnsureDispatch("iTunes.Application")

        widget.label.setText('Exporting to itunes...')
        widget.emit(Qt.SIGNAL('updateProgress(int)'), 25 if not only_export else 50)
        qapp.processEvents()
        from_sg_to_itunes(sg_playlists, widget, itunes)

        if not only_export:
            widget.label.setText('Importing to Super Gokya...')
            widget.emit(Qt.SIGNAL('updateProgress(int)'), 50)
            qapp.processEvents()
            from_itunes_to_sg(sg_playlists, itunes)

        widget.label.setText('Synchronizing playlists...')
        widget.emit(Qt.SIGNAL('updateProgress(int)'), 100)
        qapp.processEvents()
        sync_playlists(sg_playlists, itunes, only_export)
        conf = tanooki_library.get_or_create_config()
        conf['playlists'] = sg_playlists
        tanooki_library.save_config(conf)
    except Exception as e:
        open('bandicoot', 'a').write(str(datetime.datetime.now()) + '\t ' + str(e) + '\n')
Esempio n. 16
0
 def _deletePlaylist(self):
     item = self.playlists.takeItem(self.playlists.currentRow())
     conf = tanooki_library.get_or_create_config()
     del conf['playlists'][unicode(item.text())]
     tanooki_library.save_config(conf)
Esempio n. 17
0
 def _refreshPlaylists(self):
     conf = tanooki_library.get_or_create_config()
     self.playlists.clear()
     for playlist in conf['playlists']:
         QtGui.QListWidgetItem(playlist, self.playlists)