Ejemplo n.º 1
0
def test_textmessage(mocker):
    '''text message'''
    processor = DefaultProcessor()
    parser = Parser(is_replay=False)
    _json = _open_file("tests/testdata/default/textmessage.json")

    _, chatdata = parser.parse(parser.get_contents(json.loads(_json)))
    data = {
        "video_id": "",
        "timeout": 7,
        "chatdata": chatdata
    }

    ret = processor.process([data]).items[0]
    assert ret.chattype == "textMessage"
    assert ret.id == "dummy_id"
    assert ret.message == "dummy_message"
    assert ret.timestamp == 1570678496000
    assert ret.datetime == "2019-10-10 12:34:56"
    assert ret.author.name == "author_name"
    assert ret.author.channelId == "author_channel_id"
    assert ret.author.channelUrl == "http://www.youtube.com/channel/author_channel_id"
    assert ret.author.imageUrl == "https://yt3.ggpht.com/------------/AAAAAAAAAAA/AAAAAAAAAAA/xxxxxxxxxxxx/s64-x-x-xx-xx-xx-c0xffffff/photo.jpg"
    assert ret.author.badgeUrl == ""
    assert ret.author.isVerified is False
    assert ret.author.isChatOwner is False
    assert ret.author.isChatSponsor is False
    assert ret.author.isChatModerator is False
Ejemplo n.º 2
0
def test_sponsor_legacy(mocker):
    '''lagacy sponsor(membership)'''
    processor = DefaultProcessor()
    parser = Parser(is_replay=False)
    _json = _open_file("tests/testdata/default/newSponsor_lagacy.json")

    _, chatdata = parser.parse(parser.get_contents(json.loads(_json)))
    data = {
        "video_id": "",
        "timeout": 7,
        "chatdata": chatdata
    }
    
    ret = processor.process([data]).items[0]
    print(json.dumps(chatdata, ensure_ascii=False))
    assert ret.chattype == "newSponsor"
    assert ret.type == "newSponsor"
    assert ret.id == "dummy_id"
    assert ret.message == "新規メンバー / ようこそ、author_name!"
    assert ret.messageEx == ["新規メンバー / ようこそ、author_name!"]
    assert ret.timestamp == 1570678496000
    assert ret.datetime == "2019-10-10 12:34:56"
    assert ret.elapsedTime == ""
    assert ret.bgColor == 0
    assert ret.author.name == "author_name"
    assert ret.author.channelId == "author_channel_id"
    assert ret.author.channelUrl == "http://www.youtube.com/channel/author_channel_id"
    assert ret.author.imageUrl == "https://yt3.ggpht.com/------------/AAAAAAAAAAA/AAAAAAAAAAA/xxxxxxxxxxxx/s64-x-x-xx-xx-xx-c0xffffff/photo.jpg"
    assert ret.author.badgeUrl == ""
    assert ret.author.isVerified is False
    assert ret.author.isChatOwner is False
    assert ret.author.isChatSponsor is True
    assert ret.author.isChatModerator is False
Ejemplo n.º 3
0
def test_supersticker(mocker):
    '''supersticker'''
    processor = DefaultProcessor()
    parser = Parser(is_replay=False)
    _json = _open_file("tests/testdata/default/supersticker.json")

    _, chatdata = parser.parse(parser.get_contents(json.loads(_json)))
    data = {"video_id": "", "timeout": 7, "chatdata": chatdata}

    ret = processor.process([data]).items[0]
    assert ret.type == "superSticker"
    assert ret.id == "dummy_id"
    assert ret.message == ""
    assert ret.messageEx == []
    assert ret.timestamp == 1570678496000
    assert ret.datetime == "2019-10-10 12:34:56"
    assert ret.elapsedTime == ""
    assert ret.amountValue == 200
    assert ret.amountString == "¥200"
    assert ret.currency == "JPY"
    assert ret.bgColor == 4278237396
    assert ret.sticker == "https://lh3.googleusercontent.com/param_s=s72-rp"
    assert ret.author.name == "author_name"
    assert ret.author.channelId == "author_channel_id"
    assert ret.author.channelUrl == "http://www.youtube.com/channel/author_channel_id"
    assert ret.author.imageUrl == "https://yt3.ggpht.com/------------/AAAAAAAAAAA/AAAAAAAAAAA/xxxxxxxxxxxx/s64-x-x-xx-xx-xx-c0xffffff/photo.jpg"
    assert ret.author.badgeUrl == ""
    assert ret.author.isVerified is False
    assert ret.author.isChatOwner is False
    assert ret.author.isChatSponsor is False
    assert ret.author.isChatModerator is False
    assert ret.colors.backgroundColor == 4278237396
    assert ret.colors.moneyChipBackgroundColor == 4278248959
    assert ret.colors.moneyChipTextColor == 4278190080
    assert ret.colors.authorNameTextColor == 3003121664
Ejemplo n.º 4
0
def test_textmessage_replay_member(mocker):
    '''text message replay member'''
    processor = DefaultProcessor()
    parser = Parser(is_replay=True)
    _json = _open_file("tests/testdata/default/replay_member_text.json")

    _, chatdata = parser.parse(parser.get_contents(json.loads(_json))[0])
    data = {"video_id": "", "timeout": 7, "chatdata": chatdata}

    ret = processor.process([data]).items[0]
    assert ret.type == "textMessage"
    assert ret.id == "dummy_id"
    assert ret.message == "dummy_message"
    assert ret.messageEx == ["dummy_message"]
    assert ret.timestamp == 1570678496000
    assert ret.datetime == get_local_datetime(TEST_TIMETSTAMP)
    assert ret.elapsedTime == "1:23:45"
    assert ret.author.name == "author_name"
    assert ret.author.channelId == "author_channel_id"
    assert ret.author.channelUrl == "http://www.youtube.com/channel/author_channel_id"
    assert ret.author.imageUrl == "https://yt3.ggpht.com/------------/AAAAAAAAAAA/AAAAAAAAAAA/xxxxxxxxxxxx/s64-x-x-xx-xx-xx-c0xffffff/photo.jpg"
    assert ret.author.badgeUrl == "https://yt3.ggpht.com/X=s16-c-k"
    assert ret.author.isVerified is False
    assert ret.author.isChatOwner is False
    assert ret.author.isChatSponsor is True
    assert ret.author.isChatModerator is False
Ejemplo n.º 5
0
def test_arcparam_2(mocker):
    param = arcparam.getparam("SsjCnHOk-Sk")
    url=f"https://www.youtube.com/live_chat_replay/get_live_chat_replay?continuation={param}&pbj=1"
    resp = requests.Session().get(url,headers = config.headers)
    jsn = json.loads(resp.text)
    parser = Parser(is_replay=True)
    contents= parser.get_contents(jsn)
    _ , chatdata = parser.parse(contents)
    test_id = chatdata[0]["addChatItemAction"]["item"]["liveChatTextMessageRenderer"]["id"]
    assert test_id == "CjoKGkNMYXBzZTdudHVVQ0Zjc0IxZ0FkTnFnQjVREhxDSnlBNHV2bnR1VUNGV0dnd2dvZDd3NE5aZy0w"
Ejemplo n.º 6
0
def test_superchat(mocker):
    '''superchat'''
    processor = DefaultProcessor()
    parser = Parser(is_replay=False)
    _json = _open_file("tests/testdata/default/superchat.json")

    _, chatdata = parser.parse(parser.get_contents(json.loads(_json)))
    data = {
        "video_id": "",
        "timeout": 7,
        "chatdata": chatdata
    }
    
    ret = processor.process([data]).items[0]
    print(json.dumps(chatdata, ensure_ascii=False))
    assert ret.chattype == "superChat"
    assert ret.type == "superChat"
    assert ret.id == "dummy_id"
    assert ret.message == "dummy_message"
    assert ret.messageEx == ["dummy_message"]
    assert ret.timestamp == 1570678496000
    assert ret.datetime == "2019-10-10 12:34:56"
    assert ret.elapsedTime == ""
    assert ret.amountValue == 800
    assert ret.amountString == "¥800"
    assert ret.currency == "JPY"
    assert ret.bgColor == 4280150454
    assert ret.author.name == "author_name"
    assert ret.author.channelId == "author_channel_id"
    assert ret.author.channelUrl == "http://www.youtube.com/channel/author_channel_id"
    assert ret.author.imageUrl == "https://yt3.ggpht.com/------------/AAAAAAAAAAA/AAAAAAAAAAA/xxxxxxxxxxxx/s64-x-x-xx-xx-xx-c0xffffff/photo.jpg"
    assert ret.author.badgeUrl == ""
    assert ret.author.isVerified is False
    assert ret.author.isChatOwner is False
    assert ret.author.isChatSponsor is False
    assert ret.author.isChatModerator is False
    assert ret.colors.headerBackgroundColor == 4278239141
    assert ret.colors.headerTextColor == 4278190080
    assert ret.colors.bodyBackgroundColor == 4280150454
    assert ret.colors.bodyTextColor == 4278190080
    assert ret.colors.authorNameTextColor == 2315255808
    assert ret.colors.timestampColor == 2147483648
Ejemplo n.º 7
0
import json
from pytchat.parser.live import Parser
from pytchat.processors.speed.calculator import SpeedCalculator

parser = Parser(is_replay=False)


def test_speed_1(mocker):
    '''test speed calculation with normal json.
    test json has 15 chatdata, duration is 30 seconds,
    so the speed of chatdata is 30 chats/minute.
    '''

    processor = SpeedCalculator(capacity=30)

    _json = _open_file("tests/testdata/speed/speedtest_normal.json")

    _, chatdata = parser.parse(parser.get_contents(json.loads(_json)))
    data = {
        "video_id": "",
        "timeout": 10,
        "chatdata": chatdata
    }
    ret = processor.process([data])
    assert 30 == ret


def test_speed_2(mocker):
    '''test speed calculation with no valid chat data.
    '''
    processor = SpeedCalculator(capacity=30)
Ejemplo n.º 8
0
def load_chatdata(filepath):
    parser = Parser(is_replay=True)
    #print(json.loads(_open_file(filepath)))
    contents = parser.get_contents( json.loads(_open_file(filepath)))
    return parser.parse(contents)[1]