def test_selectVideoQuality_should_call_userSelectsVideoQuality_if_user_selected_that_option(self):
        sys.modules["__main__"].settings.getSetting.return_value = "0"
        player = YouTubePlayer()
        player.userSelectsVideoQuality = Mock()

        player.selectVideoQuality({},{35: "SD", 22: "720p", 37: "1080p"})

        player.userSelectsVideoQuality.assert_called_with({}, {35: 'SD', 37: '1080p', 22: '720p'})
Exemplo n.º 2
0
    def test_selectVideoQuality_should_call_userSelectsVideoQuality_if_user_selected_that_option(self):
        sys.modules["__main__"].settings.getSetting.return_value = "0"
        player = YouTubePlayer()
        player.userSelectsVideoQuality = Mock()

        player.selectVideoQuality({},{35: "SD", 22: "720p", 37: "1080p"})

        player.userSelectsVideoQuality.assert_called_with({}, {35: 'SD', 37: '1080p', 22: '720p'})
    def test_selectVideoQuality_should_prefer_SD_if_asked_to(self):
        sys.modules["__main__"].settings.getSetting.return_value = "2"
        player = YouTubePlayer()

        url = player.selectVideoQuality({"quality": "SD"},{37: "1080p", 22: "720p", 35: "SD"})

        assert(url[:url.find("|")].strip() == "SD")
    def test_selectVideoQuality_should_limit_to_sd_if_user_has_selected_that_option(self):
        sys.modules["__main__"].settings.getSetting.return_value = "1"
        player = YouTubePlayer()

        url = player.selectVideoQuality({},{35: "SD", 22: "720p", 37: "1080p"})

        assert(url[:url.find("|")].strip() == "SD")
    def test_selectVideoQuality_should_limit_to_720p_if_user_has_selected_that_option(self):
        sys.modules["__main__"].settings.getSetting.return_value = "2"
        player = YouTubePlayer()

        url = player.selectVideoQuality({},{35: "SD", 22: "720p", 37: "1080p"})

        assert(url == "720p | Mozilla/5.0 (MOCK)")
    def test_selectVideoQuality_should_not_add_user_agent_when_called_by_download_function(self):
        sys.modules["__main__"].settings.getSetting.return_value = "1"
        player = YouTubePlayer()

        url = player.selectVideoQuality({"action": "download"},{35: "SD", 22: "720p", 37: "1080p"})

        assert(url.find("|" + urllib.urlencode({'User-Agent':"Mozilla/5.0 (MOCK)"})) < 0)
Exemplo n.º 7
0
    def test_selectVideoQuality_should_not_add_user_agent_when_called_by_download_function(self):
        sys.modules["__main__"].settings.getSetting.return_value = "1"
        player = YouTubePlayer()

        url = player.selectVideoQuality({"action": "download"},{35: "SD", 22: "720p", 37: "1080p"})

        assert(url.find("|" + urllib.urlencode({'User-Agent':"Mozilla/5.0 (MOCK)"})) < 0)
Exemplo n.º 8
0
    def test_selectVideoQuality_should_choose_highest_sd_quality_if_only_multiple_sd_qualities_are_available(self):
        sys.modules["__main__"].settings.getSetting.return_value = "1"
        player = YouTubePlayer()

        url = player.selectVideoQuality({},{5: "1", 33: "2", 18: "3", 26: "4", 43: "5", 34: "6", 78: "7", 44: "8", 59: "9", 35: "10"})

        assert(url[:url.find("|")].strip() == "10")
Exemplo n.º 9
0
    def test_selectVideoQuality_should_limit_to_sd_if_user_has_selected_that_option(self):
        sys.modules["__main__"].settings.getSetting.return_value = "1"
        player = YouTubePlayer()

        url = player.selectVideoQuality({},{35: "SD", 22: "720p", 37: "1080p"})

        assert(url[:url.find("|")].strip() == "SD")
Exemplo n.º 10
0
    def test_selectVideoQuality_should_prefer_SD_if_asked_to(self):
        sys.modules["__main__"].settings.getSetting.return_value = "2"
        player = YouTubePlayer()

        url = player.selectVideoQuality({"quality": "SD"},{37: "1080p", 22: "720p", 35: "SD"})

        assert(url[:url.find("|")].strip() == "SD")
    def test_selectVideoQuality_should_add_user_agent_when_not_called_by_download_function(self):
        sys.modules["__main__"].settings.getSetting.return_value = "1"
        player = YouTubePlayer()

        url = player.selectVideoQuality({},{35: "SD", 22: "720p", 37: "1080p"})

        assert(url.find("| Mozilla/5.0 (MOCK)") > 0)
    def test_selectVideoQuality_should_choose_highest_sd_quality_if_only_multiple_sd_qualities_are_available(self):
        sys.modules["__main__"].settings.getSetting.return_value = "1"
        player = YouTubePlayer()

        url = player.selectVideoQuality({},{5: "1", 33: "2", 18: "3", 26: "4", 43: "5", 34: "6", 78: "7", 44: "8", 59: "9", 35: "10"})

        assert(url[:url.find("|")].strip() == "10")
    def test_selectVideoQuality_should_prefer_720p_if_asked_to(self):
        sys.modules["__main__"].settings.getSetting.return_value = "2"
        player = YouTubePlayer()

        url = player.selectVideoQuality({"quality": "720p"},{37: "1080p", 22: "720p", 35: "SD"})

        assert(url == "720p | Mozilla/5.0 (MOCK)")
    def test_selectVideoQuality_should_prefer_h264_over_vp8_for_720p_as_appletv2_cant_handle_vp8_properly(self):
        sys.modules["__main__"].settings.getSetting.return_value = "2"
        player = YouTubePlayer()

        url = player.selectVideoQuality({},{22: "h264", 45: "vp8"})

        print "url: " + repr(url)
        assert(url[:url.find("|")].strip() == "h264")
Exemplo n.º 15
0
    def test_selectVideoQuality_should_prefer_h264_over_vp8_for_720p_as_appletv2_cant_handle_vp8_properly(self):
        sys.modules["__main__"].settings.getSetting.return_value = "2"
        player = YouTubePlayer()

        url = player.selectVideoQuality({},{22: "h264", 45: "vp8"})

        print "url: " + repr(url)
        assert(url[:url.find("|")].strip() == "h264")
Exemplo n.º 16
0
    def test_selectVideoQuality_should_prefer_720p_if_asked_to(self):
        sys.modules["__main__"].settings.getSetting.return_value = "2"
        player = YouTubePlayer()

        url = player.selectVideoQuality({"quality": "720p"}, {
            37: "1080p",
            22: "720p",
            35: "SD"
        })

        assert (url == "720p | Mozilla/5.0 (MOCK)")
Exemplo n.º 17
0
    def test_selectVideoQuality_should_limit_to_720p_if_user_has_selected_that_option(
            self):
        sys.modules["__main__"].settings.getSetting.return_value = "2"
        player = YouTubePlayer()

        url = player.selectVideoQuality({}, {
            35: "SD",
            22: "720p",
            37: "1080p"
        })

        assert (url == "720p | Mozilla/5.0 (MOCK)")
Exemplo n.º 18
0
    def test_selectVideoQuality_should_add_user_agent_when_not_called_by_download_function(
            self):
        sys.modules["__main__"].settings.getSetting.return_value = "1"
        player = YouTubePlayer()

        url = player.selectVideoQuality({}, {
            35: "SD",
            22: "720p",
            37: "1080p"
        })

        assert (url.find("| Mozilla/5.0 (MOCK)") > 0)
    def test_buildVideoObject_should_call_selectVideoQuality_if_local_file_not_found_and_remote_links_found(self):
        sys.modules["__main__"].subtitles.getLocalFileSource.return_value = ""
        params = {"videoid": "some_id"}
        video = {"videoid": "some_id", "Title": "someTitle"}

        player = YouTubePlayer()
        player.getInfo = Mock()
        player.getInfo.return_value = (video, 200)

        player.extractVideoLinksFromYoutube = Mock()
        player.extractVideoLinksFromYoutube.return_value = ({22: "720p"}, {})
        player.selectVideoQuality = Mock()

        player.buildVideoObject(params)

        player.selectVideoQuality.assert_called_with(params,{22: "720p"})
Exemplo n.º 20
0
    def test_buildVideoObject_should_call_selectVideoQuality_if_local_file_not_found_and_remote_links_found(self):
        sys.modules["__main__"].subtitles.getLocalFileSource.return_value = ""
        params = {"videoid": "some_id"}
        video = {"videoid": "some_id", "Title": "someTitle"}

        player = YouTubePlayer()
        player.getInfo = Mock()
        player.getInfo.return_value = (video, 200)

        player.extractVideoLinksFromYoutube = Mock()
        player.extractVideoLinksFromYoutube.return_value = ({22: "720p"}, {})
        player.selectVideoQuality = Mock()

        player.buildVideoObject(params)

        player.selectVideoQuality.assert_called_with(params,{22: "720p"})