Exemple #1
0
 def test_identify_artists(self):
     basicConfig(level=DEBUG)
     delete_db(dir=TEST_DIR)
     session = open_db(dir=TEST_DIR)()
     scan_dirs(session, ['/home/andrew/projects/personal/uykfe/data'])
     session.commit()
     identify_artists(dir=TEST_DIR)
Exemple #2
0
 def test_identify_artists(self):
     basicConfig(level=DEBUG)
     delete_db(dir=TEST_DIR)
     session = open_db(dir=TEST_DIR)()
     scan_dirs(session, ['/home/andrew/projects/personal/uykfe/data'])
     session.commit()
     identify_artists(dir=TEST_DIR)
Exemple #3
0
def tag_artists(dir=None, name=None):
    session = open_db(dir=dir, name=name)()
    try:
        lastfm = LastFm(**lastfm_kargs(dir=dir, name=name))
        for artist in session.query(LastFmArtist).filter(LastFmArtist.tagged == False).all():
            tag_artist(session, lastfm, artist)
    finally:
        session.close()
Exemple #4
0
def tag_artists(dir=None, name=None):
    session = open_db(dir=dir, name=name)()
    try:
        lastfm = LastFm(**lastfm_kargs(dir=dir, name=name))
        for artist in session.query(LastFmArtist).filter(
                LastFmArtist.tagged == False).all():
            tag_artist(session, lastfm, artist)
    finally:
        session.close()
Exemple #5
0
 def test_scan_mp3s(self):
     basicConfig(level=DEBUG)
     delete_db(dir=TEST_DIR)
     session = open_db(dir=TEST_DIR)()
     artist = LocalArtist(name="test artist")
     session.add(artist)
     track = LocalTrack(name="test track", url="test url", local_artist=artist.id)
     session.add(track)
     session.flush()
     assert session.query(LocalTrack).filter(LocalTrack.url == track.url).count() == 1
     scan_dirs(session, ["/home/andrew/projects/personal/uykfe/data"])
     assert session.query(LocalTrack).filter(LocalTrack.url == track.url).count() == 0
Exemple #6
0
 def test_create_local_artist(self):
     delete_db(dir=TEST_DIR)
     session_factory = open_db(dir=TEST_DIR)
     session = session_factory()
     artist = LocalArtist('test artist')
     session.add(artist)
     assert not artist.id
     session.commit()
     assert artist.id
     session.close()
     session = session_factory()
     assert session.query(LocalArtist).count()
     artists = session.query(LocalArtist).all()
     assert len(artists) == 1, artists
     assert artists[0].name == 'test artist', artists[0]
Exemple #7
0
 def test_create_local_artist(self):
     delete_db(dir=TEST_DIR)
     session_factory = open_db(dir=TEST_DIR)
     session = session_factory()
     artist = LocalArtist('test artist')
     session.add(artist)
     assert not artist.id
     session.commit()
     assert artist.id
     session.close()
     session = session_factory()
     assert session.query(LocalArtist).count()
     artists = session.query(LocalArtist).all()
     assert len(artists) == 1, artists
     assert artists[0].name == 'test artist', artists[0]
Exemple #8
0
 def test_scan_mp3s(self):
     basicConfig(level=DEBUG)
     delete_db(dir=TEST_DIR)
     session = open_db(dir=TEST_DIR)()
     artist = LocalArtist(name='test artist')
     session.add(artist)
     track = LocalTrack(name='test track',
                        url='test url',
                        local_artist=artist.id)
     session.add(track)
     session.flush()
     assert session.query(LocalTrack).filter(
         LocalTrack.url == track.url).count() == 1
     scan_dirs(session, ['/home/andrew/projects/personal/uykfe/data'])
     assert session.query(LocalTrack).filter(
         LocalTrack.url == track.url).count() == 0
Exemple #9
0
def identify_artists(ignore, dir=None, name=None):
    LOG.info('Opening database.')
    session = open_db(dir=dir, name=name)()
    try:
        lastfm = LastFm(**lastfm_kargs(dir=dir, name=name))
        artists = session.query(LocalArtist).filter(LocalArtist.lastfm_artist == None).all()
        LOG.info('Read {0} artists.'.format(len(artists)))
        for artist in artists:
            if ignore:
                name = artist.name
            else:
                name = identify_artist(session, lastfm, artist)
            LOG.info('Identified {0} as {1}.'.format(artist.name, name))
            try:
                lastfm_artist = session.query(LastFmArtist).filter(LastFmArtist.name == name).one()
            except NoResultFound:
                lastfm_artist = LastFmArtist(name=name)
                session.add(lastfm_artist)
            artist.lastfm_artist = lastfm_artist
            session.commit()
    finally:
        session.close()
Exemple #10
0
 def test_open(self):
     basicConfig(level=DEBUG)
     assert open_db(dir=TEST_DIR)()
Exemple #11
0
def scan_config():
    session = open_db()()
    try:
        scan_dirs(session, mp3_dirs())
    finally:
        session.close()
Exemple #12
0
from uykfe.support.db import open_db
from uykfe.support.squeeze import SqueezeServer
from uykfe.sequence.base import sequence
from uykfe.args import build_weighted_parser, add_depth, set_logging
from uykfe.sequence.distance.distance import DistanceControl, DistanceState


if __name__ == '__main__':
    parser = build_weighted_parser('Add items to SqueezeCenter playlist as needed')
    add_depth(parser)
    parser.add_argument('-c', '--config', default='.uykferc', help='config file')
    args = parser.parse_args()
    set_logging(args.debug)
    squeeze = SqueezeServer(name=args.config)
    state = DistanceState(open_db()(), args.limit, args.unidirectional, squeeze)
    control = DistanceControl(state, args.localexp, args.depth, args.depthexp, args.unidirectional, args.neighbour)
    state.wait()
    for track in sequence(state, control):
        squeeze.playlist_add(track.url)
        state.wait()
Exemple #13
0
from uykfe.sequence.distance.distance import DistanceControl, DistanceState


LOG = getLogger(__name__)


if __name__ == '__main__':
    parser = build_weighted_parser('Print a playlist to stdout')
    add_depth(parser)
    add_inital_artist(parser)
    parser.add_argument('count', metavar='N', type=int, help='the number of entries')
    args = parser.parse_args()
    set_logging(args.debug)
    LOG.info('File system encoding {0}'.format(getfilesystemencoding()))
    LOG.info('Stdout encoding {0}'.format(stdout.encoding))
    session = open_db()()
    track = find_track(session, args.artist, args.track)
    state = DistanceState(session, args.limit, args.unidirectional)
    if track:
        state.record_track(track)
    control = DistanceControl(state, args.localexp, args.depth, args.depthexp, args.unidirectional, args.neighbour)
    stdout.buffer.write('#EXTM3U\n'.encode('utf8'))
    for track in islice(sequence(state, control), args.count):
        url = track.url
        if url.startswith('file://'):
            url = url[len('file://'):]
#        LOG.info(url)
#        print(url)
        stdout.buffer.write((url + '\n').encode('utf8'))

Exemple #14
0
#  into graph (from_id, to_id, weight)
#select *
#  from (select :id as from_id,
#               a.id as to_id,
#               count(*) as weight
#          from lastfm_artists as a,
#               lastfm_tagweights as w2,
#               (select w.weight, w.lastfm_tagword_id
#                  from lastfm_tagweights as w
#                 where lastfm_artist_id == :id) as w:id
#         where w2.lastfm_tagword_id == w:id.lastfm_tagword_id
#           and w2.lastfm_artist_id == a.id
#           and a.id != :id
#         group by a.name
#         order by weight desc)
# where weight > 1'''), params={'id': artist.id})
#    artist.linked = True
#    session.commit()
#    LOG.info('Linked {0}'.format(artist.name))
    

if __name__ == '__main__':
    basicConfig(level=INFO)
    parser = ArgumentParser('Link related artists in the database')
    parser.add_argument('-u', '--upper', default=10, type=positive_int, help='initial number of edges')
    parser.add_argument('-l', '--lower', default=5, type=positive_int, help='final number of edges')
    args = parser.parse_args()
    link_artists(args.upper, args.lower, open_db()())

    
Exemple #15
0
    count = 0
    for artist in session.query(LastFmArtist).all():
        if artist.graph_out:
            graph.add_node(artist.id, artist)
            edges = list(artist.graph_out)
            edges.sort(key=lambda e: e.weight, reverse=True)
            for edge in edges[0:2]:
                target = edge.to_
                graph.add_node(target.id, target)
                graph.add_edge(artist.id, target.id, edge, create_nodes=False)
            if not count % 100:
                LOG.info('Added {0} nodes.'.format(count))
            count += 1
        else:
            LOG.warn('Discarding unconnected {0}.'.format(artist.name))
    return graph


def write_graph(graph):
    dot = Dot(graph)
    for node in graph:
        (_, artist, _, _) = graph.describe_node(node)
        #name = ''.join((c for c in normalize('NFD', artist.name) if category(c) != 'Mn' and c != '"'))
        name = ''.join(c for c in artist.name if c != '"')
        dot.node_style(node, label=name)
    dot.save_dot('uykfe.dot')
    
    
if __name__ == '__main__':
    write_graph(copy_to_graph(open_db()()))
Exemple #16
0
from uykfe.support.db import open_db
from uykfe.support.squeeze import SqueezeServer
from uykfe.sequence.base import sequence
from uykfe.args import build_weighted_parser, add_depth, set_logging
from uykfe.sequence.distance.distance import DistanceControl, DistanceState

if __name__ == '__main__':
    parser = build_weighted_parser(
        'Add items to SqueezeCenter playlist as needed')
    add_depth(parser)
    parser.add_argument('-c',
                        '--config',
                        default='.uykferc',
                        help='config file')
    args = parser.parse_args()
    set_logging(args.debug)
    squeeze = SqueezeServer(name=args.config)
    state = DistanceState(open_db()(), args.limit, args.unidirectional,
                          squeeze)
    control = DistanceControl(state, args.localexp, args.depth, args.depthexp,
                              args.unidirectional, args.neighbour)
    state.wait()
    for track in sequence(state, control):
        squeeze.playlist_add(track.url)
        state.wait()
Exemple #17
0
                     default=True,
                     action='store_false',
                     help='NO flatten edge colours?')
 parser.add_argument('-g',
                     '--weights',
                     default=False,
                     action='store_true',
                     help='flatten weights?')
 parser.add_argument('-z',
                     '--zero',
                     default=0,
                     type=float,
                     help='fractional lower limit for weights')
 args = parser.parse_args()
 set_logging(args.debug)
 session = open_db()()
 artist, track = None, find_track(session, args.artist, args.track)
 if track:
     artist = track.local_artist.lastfm_artist
 state = StaticState(session, args.limit)
 (nodes, edges, zero) = collect(session, args.zero)
 if artist:
     (nodes, edges) = restrict(nodes, dict((edge, edge) for edge in edges),
                               artist)
 (nodes, weighted_edges) = filter(nodes, edges, args.localexp, args.edges,
                                  args.tracks, args.limit, session, zero)
 if artist:
     (nodes, weighted_edges) = restrict(
         nodes,
         dict((edge, (weight, edge)) for (weight, edge) in weighted_edges),
         artist)
Exemple #18
0
def scan_config():
    session = open_db()()
    try:
        scan_dirs(session, mp3_dirs())
    finally:
        session.close()
Exemple #19
0
 def test_open(self):
     basicConfig(level=DEBUG)
     assert open_db(dir=TEST_DIR)()