예제 #1
0
def test_caption_query_get_by_language_code_when_not_exists():
    caption1 = Caption(
        {"url": "url1", "name": {"simpleText": "name1"}, "languageCode": "en"}
    )
    caption2 = Caption(
        {"url": "url2", "name": {"simpleText": "name2"}, "languageCode": "fr"}
    )
    caption_query = CaptionQuery(captions=[caption1, caption2])
    assert caption_query.get_by_language_code("hello") is None
예제 #2
0
def test_download_caption_with_language_found(youtube):
    youtube.title = "video title"
    caption = Caption(
        {"url": "url1", "name": {"simpleText": "name1"}, "languageCode": "en"}
    )
    caption.download = MagicMock(return_value="file_path")
    youtube.captions = CaptionQuery([caption])
    cli.download_caption(youtube, "en")
    caption.download.assert_called_with(title="video title", output_path=None)
예제 #3
0
def test_caption_query_all():
    caption1 = Caption(
        {"url": "url1", "name": {"simpleText": "name1"}, "languageCode": "en"}
    )
    caption2 = Caption(
        {"url": "url2", "name": {"simpleText": "name2"}, "languageCode": "fr"}
    )
    caption_query = CaptionQuery(captions=[caption1, caption2])
    assert caption_query.captions == [caption1, caption2]
예제 #4
0
def test_download_caption_with_lang_not_found(youtube, print_available):
    # Given
    caption = Caption(
        {"url": "url1", "name": {"simpleText": "name1"}, "languageCode": "en"}
    )
    youtube.captions = CaptionQuery([caption])
    # When
    cli.download_caption(youtube, "blah")
    # Then
    print_available.assert_called_with(youtube.captions)
예제 #5
0
def test_repr():
    caption = Caption({
        "url": "url1",
        "name": {
            "simpleText": "name1"
        },
        "languageCode": "en"
    })
    assert str(caption) == '<Caption lang="name1" code="en">'

    caption_query = CaptionQuery(captions=[caption])
    assert repr(caption_query) == '{\'en\': <Caption lang="name1" code="en">}'
예제 #6
0
def test_download_caption_with_language_not_found(youtube):
    caption = Caption({
        "url": "url1",
        "name": {
            "simpleText": "name1"
        },
        "languageCode": "en"
    })
    youtube.captions = CaptionQuery([caption])
    with patch.object(youtube.captions, "all",
                      wraps=youtube.captions.all) as wrapped_all:
        cli.download_caption(youtube, "blah")
        wrapped_all.assert_called()
예제 #7
0
def test_print_available_captions(capsys):
    # Given
    caption1 = Caption(
        {"url": "url1", "name": {"simpleText": "name1"}, "languageCode": "en"}
    )
    caption2 = Caption(
        {"url": "url2", "name": {"simpleText": "name2"}, "languageCode": "fr"}
    )
    query = CaptionQuery([caption1, caption2])
    # When
    cli._print_available_captions(query)
    # Then
    captured = capsys.readouterr()
    assert captured.out == "Available caption codes are: en, fr\n"
예제 #8
0
def test_caption_query_get_by_language_code_when_not_exists():
    caption1 = Caption({
        "url": "url1",
        "name": {
            "simpleText": "name1"
        },
        "languageCode": "en"
    })
    caption2 = Caption({
        "url": "url2",
        "name": {
            "simpleText": "name2"
        },
        "languageCode": "fr"
    })
    caption_query = CaptionQuery(captions=[caption1, caption2])
    with pytest.raises(KeyError):
        assert caption_query["hello"] is not None
예제 #9
0
def test_caption_query_get_by_language_code_when_exists():
    caption1 = Caption({
        "url": "url1",
        "name": {
            "simpleText": "name1"
        },
        "languageCode": "en",
        "vssId": ".en"
    })
    caption2 = Caption({
        "url": "url2",
        "name": {
            "simpleText": "name2"
        },
        "languageCode": "fr",
        "vssId": ".fr"
    })
    caption_query = CaptionQuery(captions=[caption1, caption2])
    assert caption_query["en"] == caption1
예제 #10
0
def test_caption_query_sequence():
    caption1 = Caption({
        "url": "url1",
        "name": {
            "simpleText": "name1"
        },
        "languageCode": "en"
    })
    caption2 = Caption({
        "url": "url2",
        "name": {
            "simpleText": "name2"
        },
        "languageCode": "fr"
    })
    caption_query = CaptionQuery(captions=[caption1, caption2])
    assert len(caption_query) == 2
    assert caption_query["en"] == caption1
    assert caption_query["fr"] == caption2
    with pytest.raises(KeyError):
        assert caption_query["nada"] is not None
예제 #11
0
    def captions(self):
        """Interface to query caption tracks.

        :rtype: :class:`CaptionQuery <CaptionQuery>`.
        """
        return CaptionQuery([c for c in self.caption_tracks])
예제 #12
0
    def captions(self) -> CaptionQuery:
        """Interface to query caption tracks.

        :rtype: :class:`CaptionQuery <CaptionQuery>`.
        """
        return CaptionQuery(self.caption_tracks)
예제 #13
0
def _print_available_captions(captions: CaptionQuery) -> None:
    print("Available caption codes are: {}".format(", ".join(
        c.code for c in captions.all())))