Example #1
0
    def show_thumbnails(self, _link_list):
        print('Converting url to image')

        # Thumbnail image
        def open_url(url):
            return lambda x: webbrowser.open_new(url)

        w = 150
        h = 80

        # self._image.place_forget();
        [button.place_forget() for button in self._thumbnail_list]

        for i, url in enumerate(_link_list):
            if i == 15:
                break
            thumbnail_url = get_thumbnail(url)
            print(thumbnail_url)
            response = get_verified_response(thumbnail_url)
            print(response.status)

            im = Image.open(io.BytesIO(response.data))
            im = im.resize((w, h), Image.ANTIALIAS)
            image = ImageTk.PhotoImage(im)

            thumbnail_button = Button(self, image=image, width=w, height=h)
            thumbnail_button.place(x=260 + (0 if i < 5 else
                                            (1.1 * w if i < 10 else 2.2 * w)),
                                   y=150 + (i % 5) * (h * 1.1))
            # self._lambda_list.append(lambda x: webbrowser.open_new(_link_list[i]))
            thumbnail_button.bind("<Button-1>", open_url(url))

            self._image.append(image)
            self._thumbnail_list.append(thumbnail_button)
Example #2
0
    def test_happy_path(self):
        """Tests if url is a valid youtube-link"""
        verified_youtube_url = 'https://www.youtube.com/watch?v=1XW1Ygatsz4'
        thumbnail_url = get_thumbnail(verified_youtube_url)
        response = get_verified_response(thumbnail_url)

        self.assertIsInstance(thumbnail_url, str)
        self.assertEquals(200, response.status)
Example #3
0
    def test_bad_path_no_thumbnail(self):
        """Tests if url is a valid youtube-link but no thumbnail"""
        unverified_youtube_url = 'https://www.youtube.com/watch?v=a8wrKC15QMk'
        thumbnail_url = get_thumbnail(unverified_youtube_url)
        response = get_verified_response(thumbnail_url)

        self.assertIsInstance(thumbnail_url, str)
        self.assertEquals(404, response.status)
Example #4
0
def filter_thumbnail_only(_list):
    """Returns list of filtered youtube hyper-links"""
    result = list()
    for count, href in enumerate(_list):
        if count > 15:
            break
        if get_verified_response(get_thumbnail(href)).status == 200:
            result.append(href)
    return result
Example #5
0
    def test_happy_path_import_is_filtered(self):
        """Tests if search term returns valid youtube links"""
        search_term = 'https://www.youtube.com/results?search_query=apple'
        imported_list = import_youtube_data(search_term)
        filtered_import_list = imported_list

        self.assertIsInstance(imported_list, list)
        self.assertEquals(len(filtered_import_list), len(imported_list))
        for href in imported_list:
            self.assertEquals(200, get_verified_response(href).status)
Example #6
0
def import_youtube_data(_youtube_url):
    """Returns list of urls from url response"""
    result = list()

    for i in range(3):
        response = get_verified_response(_youtube_url + '&page={}'.format(i))  # Get server response from url request
        if response is None:
            continue
        # print(response.data)
        soup = BeautifulSoup(response.data, 'html.parser')
        for vid in soup.findAll('a', attrs={'class': 'yt-uix-tile-link'}):  # Find all <a> tags on page
            result.append('https://www.youtube.com' + vid['href'])  # Extracting web links using 'href' property

    print('Length before filter: {}'.format(len(result)))
    result = filter_watch_only(result)
    result = filter_thumbnail_only(result)
    print('Length after filter: {}'.format(len(result)))
    return result
Example #7
0
 def test_positive_verification(self):
     """True if url is SNI verified"""
     verified_url = 'https://google.com/'
     self.assertNotEquals(None, get_verified_response(verified_url))
Example #8
0
 def test_response_code404(self):
     """True if response code is correct"""
     verified_url = 'https://www.gov.uk/404'
     self.assertEquals(404, get_verified_response(verified_url).status)
Example #9
0
 def test_response_code200(self):
     """True if response code is correct"""
     verified_url = 'https://google.com/'
     self.assertEquals(200, get_verified_response(verified_url).status)
Example #10
0
 def test_negative_verification(self):
     """True if url is not SNI verified"""
     unverified_url = 'https://badsni.com/'
     self.assertEquals(None, get_verified_response(unverified_url))