<commit_before>from __future__ import unicode_literals

import logging

from mopidy.backends import base, listener
from mopidy.models import Playlist, Track

logger = logging.getLogger('mopidy.backends.radio')


class RadioPlaylistsProvider(base.BasePlaylistsProvider):

    def create(self, name):
        pass  # TODO

    def delete(self, uri):
        pass  # TODO

    def lookup(self, uri):
        for playlist in self.playlists:
            if playlist.uri == uri:
                return playlist

    def refresh(self):
        playlists = []
        for favorite in self.backend.config['radio']['favorites']:
            for station in self.backend.session.search_stations_by_string(favorite, 5):
                if station['name'] == favorite:
                    uri = 'radio://' + str(station['id'])
                    tracks = self.backend.library.lookup(uri)
                    playlist = Playlist(uri = uri,
                                        name = favorite,
                                        tracks = tracks)
                    playlists.append(playlist)
                    break
            else:
                logger.warning('Favorite radio station \'%s\' not found', favorite)
                <commit_msg>Defer playlist tracks lookup to refresh automatically.<commit_after>from __future__ import unicode_literals

import logging

from mopidy.backends import base, listener
from mopidy.models import Playlist, Track

logger = logging.getLogger('mopidy.backends.radio')


class RadioPlaylistsProvider(base.BasePlaylistsProvider):

    def create(self, name):
        pass  # TODO

    def delete(self, uri):
        pass  # TODO

    def lookup(self, uri):
        for playlist in self.playlists:
            if playlist.uri == uri:
                tracks = self.backend.library.lookup(uri)
                return playlist.copy(tracks=tracks)

    def refresh(self):
        playlists = []
        for favorite in self.backend.config['radio']['favorites']:
            for station in self.backend.session.search_stations_by_string(favorite, 5):
                if station['name'] == favorite:
                    uri = 'radio://' + str(station['id'])
                    playlist = Playlist(uri = uri,
                                        name = favorite)
                    playlists.append(playlist)
                    break
            else:
                logger.warning('Favorite radio station \'%s\' not found', favorite)
                
{'fraction_non_alphanumeric': 0.09131134352373291, 'fraction_numerical': 0.0008045052292839903, 'mean_word_length': 1.806997742663657, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4118931', 'n_tokens_mistral': 644, 'n_tokens_neox': 608, 'n_words': 162}