Ejemplo n.º 1
0
async def load(session, url):
    headers = {"Icy-MetaData": "1"}

    async with session.get(url, headers=headers) as response:
        # Find chunk size, metadata is included after each chunk
        offset = int(response.headers.get('icy-metaint'))

        # Check sane offset value (usually 16k)
        if not (1 < offset < 64 * 1024):
            raise Exception(f"invalid icy-metaint value: {offset}")

        # Skip first chunk
        await response.content.readexactly(offset)

        # Determine length of meta data from first byte
        b = await response.content.readexactly(1)
        length = b[0] * 16

        # Check sane length value (usually 32)
        if not (1 < length < 128):
            raise Exception(f"invalid meta length: {length}")

        # Read and decode metadata
        meta = await response.content.readexactly(length)

    meta = meta.decode("utf-8")
    match = re.search("StreamTitle='(.+)';", meta)
    if not match:
        raise Exception(f"metadata not found in: {meta}")

    return split_artist_title(match.group(1))
Ejemplo n.º 2
0
def parse_response(response):
    # Find chunk size, metadata is included after each chunk
    offset = int(response.headers.get('icy-metaint'))

    # Check sane offset value (usually 16k)
    if not (1 < offset < 64 * 1024):
        logger.error("invalid icy-metaint value: {}")
        return

    # Skip first chunk
    response.raw.read(offset)

    # Determine length of meta data from first byte
    length = response.raw.read(1)[0] * 16

    # Check sane length value (usually 32)
    if not (1 < length < 128):
        logger.error("invalid meta length: {}".format(length))
        return

    # Read and decode metadata
    meta = response.raw.read(length).decode("utf-8")
    match = re.search("StreamTitle='(.+)';", meta)
    if not match:
        logger.error("metadata not found in: '{}'")
        return

    artist, title = split_artist_title(match.group(1))

    # Skip commercials
    if artist.lower() == 'radio scrambler ducati':
        return None

    return artist.title(), title
Ejemplo n.º 3
0
async def load(session):
    url = 'http://www.radiostudent.hr/wp-admin/admin-ajax.php'

    response = await session.get(url, params={"action": "rsplaylist_api"})
    data = await response.json()
    artist_title = data['rows'][0]['played_song']

    return split_artist_title(artist_title)
Ejemplo n.º 4
0
async def load(session):
    url = "http://live.radio101.hr:9531/stats"
    params = {'sid': 1, 'json': 1, '_': timestamp_ms()}

    response = await session.get(url, params=params)
    contents = await response.json()

    return split_artist_title(contents['songtitle'])
Ejemplo n.º 5
0
def test_empty():
    assert split_artist_title("") is None
    assert split_artist_title("    ") is None
    assert split_artist_title("-") is None
    assert split_artist_title("  -  ") is None
    assert split_artist_title("foo") is None
    assert split_artist_title("foo -  ") is None
    assert split_artist_title("- foo") is None
Ejemplo n.º 6
0
async def load(session):
    url = 'http://streaming.antenazagreb.hr/stream/now_playing.php'

    response = await session.get(url, params={
        'the_stream': 'http://live.antenazagreb.hr:8000/;',
        '_': timestamp_ms(),
    })
    contents = await response.text()

    return split_artist_title(contents, normalize_case=True)
Ejemplo n.º 7
0
async def load(session):
    response = await session.get('https://808proxy.contrib.hr/7.html')
    contents = await response.text()

    match = re.search(r"<html><body>\d+,\d+,\d+,\d+,\d+,\d+,(.+)</body></html>", contents)
    if match:
        return split_artist_title(match.group(1))

    logger.error("Failed parsing file", extra=dict(contents=contents))
    return None
Ejemplo n.º 8
0
async def load(session):
    url = "https://stream.zabavni.hr/now_playing.php"
    params = {
        "the_stream": "https://test1.secure.com.hr:8585/;",
        "_": timestamp_ms()
    }

    response = await session.get(url, params=params)
    contents = await response.text()

    artist, title = split_artist_title(contents)

    return artist.title(), title
Ejemplo n.º 9
0
def test_split_artist_title_normalize_case():
    expected = {
        "foo-bar": ["Foo", "Bar"],
        "foo-bar-baz": ["Foo", "Bar-baz"],
        "foo-bar - baz": ["Foo-Bar", "Baz"],
        "foo-bar- baz": ["Foo-Bar", "Baz"],
        "foo-bar -baz": ["Foo-Bar", "Baz"],
        "a-ha - take on me": ["A-Ha", "Take on me"],
        "a-ha-take on me": ["A-Ha", "Take on me"],
        "a-ha -take on me": ["A-Ha", "Take on me"],
        "a-ha- take on me": ["A-Ha", "Take on me"],
        "the beatles - hey jude": ["The Beatles", "Hey jude"],
    }

    for k, v in expected.items():
        assert split_artist_title(k, normalize_case=True) == v
Ejemplo n.º 10
0
def test_split_artist_title():
    expected = {
        "foo-bar": ["foo", "bar"],
        "foo-bar-baz": ["foo", "bar-baz"],
        "foo-bar - baz": ["foo-bar", "baz"],
        "foo-bar   -   baz": ["foo-bar", "baz"],
        "foo-bar- baz": ["foo-bar", "baz"],
        "foo-bar-  baz": ["foo-bar", "baz"],
        "foo-bar -baz": ["foo-bar", "baz"],
        "foo-bar  -baz": ["foo-bar", "baz"],
        "a-ha - take on me": ["a-ha", "take on me"],
        "a-ha-take on me": ["a-ha", "take on me"],
        "the beatles - hey jude": ["the beatles", "hey jude"],
    }

    for k, v in expected.items():
        assert split_artist_title(k) == v