Beispiel #1
0
def search_fuzzy_edit():
    try:
        params = eval(settings.getSetting('search_parameters'))
        params.update({'search': ''})
    except:
        log.error('Search Parameters not set !')
        return
    cmds = [
        ('search', _S(Msg.i30400)),
        ('artist', _T('artist') + ': '),
        ('title', _T('track') + ': '),
        ('album', _T('album') + ': '),
        ('albumartist', _S(Msg.i30402) + ': '),
        ('year', _S(Msg.i30403) + ': '),
    ]
    answer = 1
    while answer > 0:
        menue = [
            '%s%s' % (FOLDER_MASK % s_head, params.get(s_key))
            for s_key, s_head in cmds
        ]
        answer = xbmcgui.Dialog().select(_S(Msg.i30400), menue)
        if answer > 0:
            keyboard = xbmc.Keyboard(params.get(cmds[answer][0]),
                                     cmds[answer][1])
            keyboard.doModal()
            if keyboard.isConfirmed():
                value = keyboard.getText()
                params.update({cmds[answer][0]: value})
    if answer == 0:
        settings.setSetting('search_parameters', repr(params))
        xbmc.executebuiltin('Container.Refresh()')
    pass
Beispiel #2
0
def favorites_delete_all(what):
    ok = xbmcgui.Dialog().yesno(
        _S(Msg.i30430).format(what=_P(what)),
        _S(Msg.i30431).format(what=_P(what)))
    if ok:
        if what == 'playlists':
            session.user.favorites.delete_all(
                what=_T('Playlists'),
                action=session.user.favorites.playlists,
                remove=session.user.favorites.remove_playlist)
        elif what == 'artists':
            session.user.favorites.delete_all(
                what=_T('Artists'),
                action=session.user.favorites.artists,
                remove=session.user.favorites.remove_artist)
        elif what == 'albums':
            session.user.favorites.delete_all(
                what=_T('Albums'),
                action=session.user.favorites.albums,
                remove=session.user.favorites.remove_album)
        elif what == 'tracks':
            session.user.favorites.delete_all(
                what=_T('Tracks'),
                action=session.user.favorites.tracks,
                remove=session.user.favorites.remove_track)
        elif what == 'videos':
            session.user.favorites.delete_all(
                what=_T('Videos'),
                action=session.user.favorites.videos,
                remove=session.user.favorites.remove_video)
    return ok
Beispiel #3
0
 def add_search_result(self,
                       searchresults,
                       sort=None,
                       reverse=False,
                       end=True):
     headline = '[COLOR yellow]-------- %s --------[/COLOR]' if tidalAddon.getSetting(
         'color_mode') == 'true' else '-------- %s --------'
     xbmcplugin.setContent(tidalPlugin.handle, 'songs')
     if searchresults.artists.__len__() > 0:
         self.add_directory_item(_T('Artists'),
                                 tidalPlugin.url_for_path('/do_nothing'),
                                 isFolder=False,
                                 label=headline % _T('Artists'))
         if sort:
             searchresults.artists.sort(
                 key=lambda line: line.getSortField(sort), reverse=reverse)
         self.add_list_items(searchresults.artists, end=False)
     if searchresults.albums.__len__() > 0:
         self.add_directory_item(_T('Albums'),
                                 tidalPlugin.url_for_path('/do_nothing'),
                                 isFolder=False,
                                 label=headline % _T('Albums'))
         if sort:
             searchresults.albums.sort(
                 key=lambda line: line.getSortField(sort), reverse=reverse)
         self.add_list_items(searchresults.albums, end=False)
     if searchresults.playlists.__len__() > 0:
         self.add_directory_item(_T('Playlists'),
                                 tidalPlugin.url_for_path('/do_nothing'),
                                 isFolder=False,
                                 label=headline % _T('Playlists'))
         if sort:
             searchresults.playlists.sort(
                 key=lambda line: line.getSortField(sort), reverse=reverse)
         self.add_list_items(searchresults.playlists, end=False)
     if searchresults.tracks.__len__() > 0:
         self.add_directory_item(_T('Tracks'),
                                 tidalPlugin.url_for_path('/do_nothing'),
                                 isFolder=False,
                                 label=headline % _T('Tracks'))
         if sort:
             searchresults.tracks.sort(
                 key=lambda line: line.getSortField(sort), reverse=reverse)
         self.add_list_items(searchresults.tracks, end=False)
     if searchresults.videos.__len__() > 0:
         self.add_directory_item(_T('Videos'),
                                 tidalPlugin.url_for_path('/do_nothing'),
                                 isFolder=False,
                                 label=headline % _T('Videos'))
         if sort:
             searchresults.videos.sort(
                 key=lambda line: line.getSortField(sort), reverse=reverse)
         self.add_list_items(searchresults.videos, end=False)
     if end:
         self.add_list_items([], end=True)
Beispiel #4
0
 def import_playlists(self, filename):
     try:
         ok = False
         f = xbmcvfs.File(filename, 'r')
         lines = f.read().split('\n')
         f.close()
         playlists = []
         names = []
         for line in lines:
             try:
                 if len(line) > 0:
                     item = eval(line)
                     names.append(item.get('title'))
                     playlists.append(item)
             except:
                 pass
         if len(names) < 1:
             return False
         selected = xbmcgui.Dialog().select(
             _S(Msg.i30432).format(what=_T('Playlist')), names)
         if selected < 0:
             return False
         item = playlists[selected]
         item_ids = []
         for bItem in item.get('ids'):
             bItem = '%s' % bItem
             if bItem not in item_ids:
                 item_ids.append(bItem)
         dialog = xbmcgui.Dialog()
         title = dialog.input(_T(Msg2.i30233),
                              item.get('title'),
                              type=xbmcgui.INPUT_ALPHANUM)
         if not title:
             return False
         description = dialog.input(_T(Msg2.i30234),
                                    item.get('description'),
                                    type=xbmcgui.INPUT_ALPHANUM)
         playlist = self.create_playlist(title, description)
         if playlist:
             ok = self.add_playlist_entries(playlist=playlist,
                                            item_ids=item_ids)
             if ok:
                 xbmcgui.Dialog().notification(
                     _T('Playlist'),
                     _S(Msg.i30429).format(n=playlist.title),
                     xbmcgui.NOTIFICATION_INFO)
     except Exception as e:
         log.logException(e)
     return ok
Beispiel #5
0
def favorites_import(what):
    path = settings.import_export_path
    if len(path) == 0 or not session.is_logged_in:
        return
    files = xbmcvfs.listdir(path)[1]
    files = [
        py2_decode(name) for name in files
        if py2_decode(name).startswith('favo_%s' % what)
    ]
    selected = xbmcgui.Dialog().select(path, files)
    if selected < 0:
        return
    name = os.path.join(path, files[selected])
    ok = False
    if what == 'playlists':
        ok = session.user.favorites.import_ids(
            what=_T('Playlists'),
            filename=name,
            action=session.user.favorites.add_playlist)
    elif what == 'artists':
        ok = session.user.favorites.import_ids(
            what=_T('Artists'),
            filename=name,
            action=session.user.favorites.add_artist)
    elif what == 'albums':
        ok = session.user.favorites.import_ids(
            what=_T('Albums'),
            filename=name,
            action=session.user.favorites.add_album)
    elif what == 'tracks':
        ok = session.user.favorites.import_ids(
            what=_T('Tracks'),
            filename=name,
            action=session.user.favorites.add_track)
    elif what == 'videos':
        ok = session.user.favorites.import_ids(
            what=_T('Videos'),
            filename=name,
            action=session.user.favorites.add_video)
    return ok
Beispiel #6
0
 def _http_error(self, e):
     try:
         if isinstance(e, HTTPError):
             r = e.response
             if r.status_code in [401, 403]:
                 msg = _T(Msg2.i30210)
             else:
                 msg = r.reason
             try:
                 msg = r.json().get('userMessage')
             except:
                 pass
             if r.status_code == 429:
                 # Too Many Requests. Disable Album Cache
                 self.abortAlbumThreads = True
             xbmcgui.Dialog().notification(
                 '%s Error %s' % (tidalPlugin.name, r.status_code), msg,
                 xbmcgui.NOTIFICATION_ERROR)
     except:
         pass
     traceback.print_exc()
Beispiel #7
0
def convert_to_playlist_run(item_type, from_pos, to_pos, playlist_id):
    playlist = session.get_playlist(playlist_id)
    if not playlist:
        log.error('Playlist "%s" not found.' % playlist_id)
        return
    listitems = item_info.getAllListItems()
    numItems = len(listitems)
    if numItems == 0:
        log.error('No ListItems found.')
        return
    pos = min(int(from_pos), numItems) - 1
    lastPos = min(int(to_pos), numItems) - 1
    numItems = lastPos - pos + 1
    progress = xbmcgui.DialogProgress()
    progress.create(_S(Msg.i30410))
    percent = 0
    line1 = ''
    line2 = ''
    line3 = _S(Msg.i30411)
    items = []
    while pos <= lastPos and not progress.iscanceled():
        li = listitems[pos]
        artist = li.get('Artist')
        title = li.get('Title')
        album = li.get(
            'Album') if not li.get('Compilation') else ''  # item.get('Title')
        albumartist = li.get('AlbumArtist') if not li.get(
            'Compilation') else ''  # item.get('Artist')
        year = '%s' % li.get('YearInt')
        percent = int((pos * 100) / numItems)
        line1 = '%s: %s' % (_T('artist'), artist)
        line2 = '%s: %s' % (_T('track'), title)
        progress.update(percent, "\n".join([line1, line2, line3]))
        log.info('Searching Title: %s - %s' % (artist, title))
        item_id = li.get('video_id',
                         None) if item_type.startswith('video') else li.get(
                             'track_id', None)
        if item_id:
            track = session.get_track(item_id, withAlbum=True)
            if track:
                line3 = 'TIDAL-ID %s: %s - %s (%s)' % (
                    track.id, track.artist.name, track.title, track.year)
                log.info('Found TIDAL Track-Id %s: %s - %s' %
                         (track.id, track.artist.name, track.title))
                items.append(track)
                pos = pos + 1
                continue
        result = session.search_fuzzy(artist,
                                      title,
                                      album,
                                      albumartist,
                                      year,
                                      limit=20)
        if item_type.startswith('track') and len(result.tracks) > 0:
            # Sort over matchLevel
            result.tracks.sort(key=lambda line: line.getSortField('match'),
                               reverse=True)
            # Take the first result (best matchLevel)
            track = result.tracks[0]
            line3 = 'ID %s: %s - %s (%s)' % (track.id, track.artist.name,
                                             track.title, track.year)
            log.info('Found Title Id %s: %s - %s' %
                     (track.id, track.artist.name, track.title))
            items.append(track)
        elif item_type.startswith('video') and len(result.videos) > 0:
            # Sort over matchLevel
            result.videos.sort(key=lambda line: line.getSortField('match'),
                               reverse=True)
            # Take the first result (best matchLevel)
            video = result.videos[0]
            line3 = 'ID %s: %s - %s (%s)' % (video.id, video.artist.name,
                                             video.title, video.year)
            log.info('Found Video Id %s: %s - %s' %
                     (video.id, video.artist.name, video.title))
            items.append(video)
        else:
            log.info('Title not found.')
            line3 = '%s: %s - %s' % (_S(
                Msg.i30412), li.get('Artist'), li.get('Title'))
        pos = pos + 1

    progress.update(percent, "\n".join([line1, line2, line3]))
    xbmc.sleep(2000)
    foundItems = len(items)
    line2 = _S(Msg.i30413).format(n=foundItems, m=numItems)
    if progress.iscanceled():
        yes = xbmcgui.Dialog().yesno(_S(Msg.i30414), _S(Msg.i30415), line2,
                                     _S(Msg.i30416))
        if not yes:
            progress.close()
            log.info('Search aborted by user.')
            return False
    if playlist and foundItems > 0:
        progress.update(99, "\n".join([_S(Msg.i30417), line2, _S(Msg.i30418)]))
        session.user.add_playlist_entries(
            playlist=playlist, item_ids=['%s' % item.id for item in items])
        progress.update(100, _S(Msg.i30417))
    xbmc.sleep(1000)
    progress.close()

    log.info('Search terminated successfully.')
    return True
Beispiel #8
0
def convert_to_playlist(item_type):
    if not session.is_logged_in:
        xbmcgui.Dialog().notification(plugin.name, _S(Msg.i30404),
                                      xbmcgui.NOTIFICATION_ERROR)
        return
    # Submenu: Parameters for Playlist-Generation
    cmds = [
        ('action', _S(Msg.i30405)),
        ('playlist', _T('playlist') + ': '),
        ('Position', _S(Msg.i30406) + ': '),
        ('NumItems', _S(Msg.i30407) + ': '),
    ]
    item = item_info.getSelectedListItem()
    item['action'] = ''
    item['playlist_id'] = ''
    item['playlist'] = ''
    playlist_id = tidalSettings.default_videoplaylist_id if item_type.startswith(
        'video') else tidalSettings.default_trackplaylist_id
    if playlist_id:
        try:
            playlist = session.get_playlist(playlist_id)
            if playlist:
                item['playlist_id'] = playlist.id
                item['playlist'] = playlist.title
        except:
            pass
    numItems = item['NumItems']
    answer = 1
    while answer > 0:
        menue = [
            '%s%s' % (FOLDER_MASK % s_head, item.get(s_key))
            for s_key, s_head in cmds
        ]
        answer = xbmcgui.Dialog().select(_S(Msg.i30408), menue)
        if answer == 0 and not item['playlist_id']:
            answer = 1  # Playlist not set
        if answer > 0:
            if answer == 1:
                playlist = session.user.selectPlaylistDialog(_S(
                    Msg.i30409).format(
                        what=_P('tracks' if item_type.
                                startswith('track') else 'videos')),
                                                             allowNew=True)
                if playlist:
                    item['playlist_id'] = playlist.id
                    item['playlist'] = playlist.title
            elif answer >= 2 and answer <= 3:
                value = int(
                    '0%s' %
                    xbmcgui.Dialog().input(cmds[answer][1],
                                           str(item.get(cmds[answer][0])),
                                           type=xbmcgui.INPUT_NUMERIC))
                if ( answer == 2 and value <= numItems and value <= item['NumItems'] ) or \
                   ( answer == 3 and value <= numItems and value >= item['Position'] ):
                    item.update({cmds[answer][0]: value})
            else:
                keyboard = xbmc.Keyboard(item.get(cmds[answer][0]),
                                         cmds[answer][1])
                keyboard.doModal()
                if keyboard.isConfirmed():
                    value = keyboard.getText()
                    item.update({cmds[answer][0]: value})
    if answer == 0:
        convert_to_playlist_run(item_type, '0%s' % item['Position'],
                                '0%s' % item['NumItems'], item['playlist_id'])
Beispiel #9
0
 def search_thread(self):
     try:
         log.info('Search Thread %s started.' % currentThread().ident)
         while not xbmc.Monitor().waitForAbort(
                 timeout=0.01) and not self.abortThreads:
             try:
                 artist = self.artistQueue.get_nowait()
             except:
                 break
             try:
                 items = []
                 if not self.abortThreads and self.album_playlist.id:
                     items += self.session.get_artist_albums(
                         artist.id, limit=self.searchLimit)
                 if not self.abortThreads and (self.album_playlist.id
                                               or self.track_playlist.id):
                     items += self.session.get_artist_albums_ep_singles(
                         artist.id, limit=self.searchLimit)
                 if not self.abortThreads and self.video_playlist.id:
                     items += self.session.get_artist_videos(
                         artist.id, limit=self.searchLimit)
                 for item in items:
                     if self.abortThreads: break
                     try:
                         diff = datetime.today() - item.releaseDate
                         diff_days = diff.days
                     except:
                         diff_days = 1
                     if not item._userplaylists and diff_days < self.diffDays:
                         if isinstance(item, VideoItem):
                             if not '%s' % item.id in self.found_videos:
                                 log.info('Found new Video: %s' %
                                          item.getLabel(extended=False))
                                 self.found_videos.append('%s' % item.id)
                         elif isinstance(item, AlbumItem):
                             tracks = self.session.get_album_items(item.id)
                             for track in tracks:
                                 if track.available:
                                     # Use first Track in an Album as PlaylistItem
                                     if item.type == AlbumType.album or item.type == AlbumType.ep:
                                         if not '%s' % track.id in self.found_albums:
                                             log.info(
                                                 'Found new Album: %s' %
                                                 item.getLabel(
                                                     extended=False))
                                             self.found_albums.append(
                                                 '%s' % track.id)
                                     elif not track._userplaylists:
                                         if not '%s' % track.id in self.found_tracks:
                                             log.info(
                                                 'Found new Track: %s' %
                                                 item.getLabel(
                                                     extended=False))
                                             self.found_tracks.append(
                                                 '%s' % track.id)
                                     break
                     self.progress_update(heading='%s: %s' %
                                          (_T('artist'), artist.name))
                 pass
             except requests.HTTPError as e:
                 r = e.response
                 msg = 'Error'
                 try:
                     msg = r.reason
                     msg = r.json().get('userMessage')
                 except:
                     pass
                 #debug.log('Error getting Album ID %s' % album_id, xbmc.LOGERROR)
                 if r.status_code == 429 and not self.abortThreads:
                     self.abortThreads = True
                     log.error('Too many requests. Aborting Workers ...')
                     self.albumQueue._init(9999)
                     xbmcgui.Dialog().notification(
                         _S(Msg.i30437), msg, xbmcgui.NOTIFICATION_ERROR)
     except Exception as e:
         log.logException(e, 'Error in Search Thread')
         traceback.print_exc()
     self.runningThreads.pop(currentThread().ident, None)
     log.info('Search Thread %s terminated.' % currentThread().ident)
     return