示例#1
0
文件: playlist.py 项目: Robbt/uykfe
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'))

示例#2
0
文件: dump_graph.py 项目: Robbt/uykfe
                     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)
 dump(nodes, weighted_edges, args.white, args.black, args.flatten,
示例#3
0
文件: dump_graph.py 项目: Robbt/uykfe
        else:
            return grey
    except:
        raise ArgumentError('{0} is not an integer.'.format(value))
    
    
if __name__ == '__main__':
    parser = build_weighted_parser('Dump graph to file')
    add_inital_artist(parser)
    parser.add_argument('-n', '--edges', default=2, type=positive_int, help='minimum number of edges')
    parser.add_argument('-m', '--tracks', default=5, type=positive_int, help='minimum number of tracks')
    parser.add_argument('-w', '--white', default=192, type=level, help='white level')
    parser.add_argument('-b', '--black', default=64, type=level, help='black level')
    parser.add_argument('-f', '--flatten', 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)
    dump(nodes, weighted_edges, args.white, args.black, args.flatten, args.weights)