コード例 #1
0
ファイル: ogg_vorbis.py プロジェクト: infinityb/ireul-dead
def get_metadata(url):
    """Returns an iterable yielding the ICY metadata"""
    parse_result = urlparse.urlparse(url)
    hostname, addresses = resolve_netloc(parse_result.netloc)
    conn = None
    ex = list()
    for af, address in addresses:
        conn = socket.socket(af, socket.SOCK_STREAM)
        try:
            conn.connect(address)
            break
        except socket.error as e:
            ex.append(e)
    if conn is None:
        raise Exception(ex)
    conn.send("GET {mount} HTTP/1.1\r\n".format(mount=parse_result.path))
    conn.send("HOST: {hostname}\r\n".format(hostname=hostname))
    conn.send("User-Agent: ireul\r\n")
    conn.send("Icy-MetaData: 1\r\n")
    conn.send("\r\n")

    fileobj = conn.makefile()
    while True:
        buf = fileobj.readline()
        if buf == "\r\n": break
    return _yield_metainfo(fileobj)
コード例 #2
0
ファイル: icy_write_vorb.py プロジェクト: XiaonuoGantan/ireul
def send_stream(url, source_file_iter):
    """Returns an iterable yielding the ICY metadata"""
    parse_result = urlparse.urlparse(url)
    hostname, addresses = resolve_netloc(parse_result.netloc)
    conn = None
    for af, address in addresses:
        conn = socket.socket(af, socket.SOCK_STREAM)
        try:
            conn.connect(address)
            break
        except socket.error:
            continue
    conn.send("SOURCE {mount} HTTP/1.0\r\n".format(mount=parse_result.path))
    conn.send("Authorization: Basic c291cmNlOmNvY2ttZQ==\r\n")
    conn.send("HOST: {hostname}\r\n".format(hostname=hostname))
    conn.send("User-Agent: ireul\r\n")
    conn.send("Content-Type: application/ogg\r\n")
    conn.send("\r\n")

    fileobj = conn.makefile()
    fileobj.readline()
    fileobj.readline()


    ogg_stream_pre = compose(
            ogg_make_seq_monotonic,
            ogg_make_single_serial,
            )

    ogg_stream_post = compose(
            monitor_position,
            apply_timing,
            ogg_show_page,
            # ogg_fix_header,
            ogg_make_pos_monotonic,
            )

    # get all the pages
    def stream_pages():
        for track_derived in source_file_iter:
            for page in ogg_stream_pre(yield_pages(track_derived)):
                yield page

    # apply transforms and write them out
    for page in ogg_stream_post(stream_pages()):
        fileobj.write(page.write())
コード例 #3
0
ファイル: icy.py プロジェクト: XiaonuoGantan/ireul
def get_metadata(url):
    """Returns an iterable yielding the ICY metadata"""
    parse_result = urlparse.urlparse(url)
    hostname, addresses = resolve_netloc(parse_result.netloc)
    conn = None
    for af, address in addresses:
        conn = socket.socket(af, socket.SOCK_STREAM)
        try:
            conn.connect(address)
            break
        except socket.error:
            continue
    conn.send("GET {mount} HTTP/1.1\r\n".format(mount=parse_result.path))
    conn.send("HOST: {hostname}\r\n".format(hostname=hostname))
    conn.send("User-Agent: ireul\r\n")
    conn.send("Icy-MetaData: 1\r\n")
    conn.send("\r\n")
    return _yield_metainfo(conn.makefile())
コード例 #4
0
def send_stream(url, source_file_iter, pre_transforms=[], post_transforms=[]):
    """Returns an iterable yielding the ICY metadata"""
    parse_result = urlparse.urlparse(url)
    netloc = parse_result.netloc
    user_pass = None
    if '@' in netloc:
        user_pass, netloc = parse_result.netloc.split('@')
    hostname, addresses = resolve_netloc(netloc)
    conn = None
    for af, address in addresses:
        conn = socket.socket(af, socket.SOCK_STREAM)
        try:
            conn.connect(address)
            break
        except socket.error:
            continue
    conn.send("SOURCE {mount} HTTP/1.0\r\n".format(mount=parse_result.path))
    if user_pass:
        conn.send("Authorization: Basic %s\r\n" % b64encode(user_pass))
    conn.send("HOST: {hostname}\r\n".format(hostname=hostname))
    conn.send("User-Agent: ireul\r\n")
    conn.send("Content-Type: application/ogg\r\n")
    conn.send("\r\n")

    fileobj = conn.makefile()
    fileobj.readline()
    fileobj.readline()

    ogg_event_pre = compose(*pre_transforms)
    ogg_event_post = compose(*post_transforms)

    # get all the pages
    def stream_events():
        for track_derived in source_file_iter:
            for event in ogg_event_pre(yield_events(track_derived)):
                yield event

    # apply transforms and write them out
    for event in ogg_event_post(stream_events()):
        #import pdb; pdb.set_trace()
        if isinstance(event, OggPageEvent):
            fileobj.write(event.page.write())
        else:
            print "event : %r" % event