Exemplo n.º 1
0
    def post(self):
        self._require_registration()

        match_key = self.request.get("match_key")
        youtube_url = self.request.get("youtube_url")
        youtube_id = YouTubeVideoHelper.parse_id_from_url(youtube_url)

        status = SuggestionCreator.createMatchVideoYouTubeSuggestion(self.user_bundle.account.key, youtube_id, match_key)

        self.redirect('/suggest/match/video?match_key={}&status={}'.format(match_key, status))
    def post(self):
        self._require_registration()

        match_key = self.request.get("match_key")
        youtube_url = self.request.get("youtube_url")
        youtube_id = YouTubeVideoHelper.parse_id_from_url(youtube_url)

        status = SuggestionCreator.createMatchVideoYouTubeSuggestion(self.user_bundle.account.key, youtube_id, match_key)

        self.redirect('/suggest/match/video?match_key={}&status={}'.format(match_key, status))
Exemplo n.º 3
0
    def parseTeams(self, table):
        teams = []
        for tr in table.findAll('tr'):
            tds = tr.findAll('td')
            if len(tds) < 5:
                continue

            year_str = tds[0].getText()
            if not year_str.isdigit():
                continue

            team_num = re.search(r'^Team ([0-9]+)', tds[1].getText()).group(1)
            if not team_num.isdigit():
                continue

            video = tds[2].find('a')
            if video:
                video = YouTubeVideoHelper.parse_id_from_url(video['href'])

            presentation = tds[3].find('a')
            if presentation:
                presentation = YouTubeVideoHelper.parse_id_from_url(
                    presentation['href'])

            essay = tds[4].find('a')
            if essay:
                essay = essay['href']

                if essay[0] == '/':
                    essay = 'https://www.firstinspires.org' + essay

            teams.append({
                'team_id': 'frc' + team_num,
                'team_number': int(team_num),
                'year': int(year_str),
                'video': video,
                'presentation': presentation,
                'essay': essay,
            })

        return teams if teams != [] else None
    def parseTeams(self, table):
        teams = []
        for tr in table.findAll('tr'):
            tds = tr.findAll('td')
            if len(tds) < 5:
                continue

            year_str = tds[0].getText()
            if not year_str.isdigit():
                continue

            team_num = re.search(r'^Team ([0-9]+)', tds[1].getText()).group(1)
            if not team_num.isdigit():
                continue

            video = tds[2].find('a')
            if video:
                video = YouTubeVideoHelper.parse_id_from_url(video['href'])

            presentation = tds[3].find('a')
            if presentation:
                presentation = YouTubeVideoHelper.parse_id_from_url(presentation['href'])

            essay = tds[4].find('a')
            if essay:
                essay = essay['href']

                if essay[0] == '/':
                    essay = 'https://www.firstinspires.org' + essay

            teams.append({
                'team_id': 'frc' + team_num,
                'team_number': int(team_num),
                'year': int(year_str),
                'video': video,
                'presentation': presentation,
                'essay': essay,
            })

        return teams if teams != [] else None
Exemplo n.º 5
0
    def post(self):
        self._require_registration()

        match_key = self.request.get("match_key")

        status = None

        if self.request.get("youtube_url"):
            youtube_url = self.request.get("youtube_url")
            youtube_id = YouTubeVideoHelper.parse_id_from_url(youtube_url)

            status = SuggestionCreator.createMatchVideoYouTubeSuggestion(self.user_bundle.account.key, youtube_id, match_key)
        elif self.request.get("internet_archive_url"):
            internet_archive_url = self.request.get("internet_archive_url")
            internet_archive_id = InternetArchiveVideoHelper.parse_id_from_url(internet_archive_url)

            status = SuggestionCreator.createMatchVideoInternetArchiveSuggestion(self.user_bundle.account.key, internet_archive_id, match_key)
        else:
            status = 'bad_url'

        self.redirect('/suggest/match/video?match_key={}&status={}'.format(match_key, status))
    def test_parse_id_from_url(self):
        # Standard HTTP
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'http://www.youtube.com/watch?v=1v8_2dW7Kik'), '1v8_2dW7Kik')
        # Standard HTTPS
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://www.youtube.com/watch?v=1v8_2dW7Kik'), '1v8_2dW7Kik')

        # Short link HTTP
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'http://youtu.be/1v8_2dW7Kik'), '1v8_2dW7Kik')
        # Short link HTTPS
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://youtu.be/1v8_2dW7Kik'), '1v8_2dW7Kik')

        # Standard with start time
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://www.youtube.com/watch?v=1v8_2dW7Kik&t=21'),
            '1v8_2dW7Kik?t=21')
        # Short link with start time
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://youtu.be/1v8_2dW7Kik?t=21'), '1v8_2dW7Kik?t=21')

        # Many URL params
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://www.youtube.com/watch?v=1v8_2dW7Kik&feature=youtu.be'
            ), '1v8_2dW7Kik')
        # Short link many URL params
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://youtu.be/1v8_2dW7Kik?feature=youtu.be'),
            '1v8_2dW7Kik')

        # Many URL params with start time
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://www.youtube.com/watch?v=1v8_2dW7Kik&feature=youtu.be&t=11850'
            ), '1v8_2dW7Kik?t=11850')
        # Short link many URL params with start time
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://youtu.be/1v8_2dW7Kik?feature=youtu.be&t=11850'),
            '1v8_2dW7Kik?t=11850')

        # Bunch of inconsistent (partially outdated) formats
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://www.youtube.com/watch?v=1v8_2dW7Kik#t=11850'),
            '1v8_2dW7Kik?t=11850')
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://www.youtube.com/watch?v=1v8_2dW7Kik#t=1h'),
            '1v8_2dW7Kik?t=3600')
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://www.youtube.com/watch?v=1v8_2dW7Kik#t=1h1m'),
            '1v8_2dW7Kik?t=3660')
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://www.youtube.com/watch?v=1v8_2dW7Kik#t=3h17m30s'),
            '1v8_2dW7Kik?t=11850')
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://www.youtube.com/watch?v=1v8_2dW7Kik#t=1m'),
            '1v8_2dW7Kik?t=60')
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://www.youtube.com/watch?v=1v8_2dW7Kik#t=1m1s'),
            '1v8_2dW7Kik?t=61')
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://www.youtube.com/watch?v=1v8_2dW7Kik#t=1s'),
            '1v8_2dW7Kik?t=1')

        # Bunch of inconsistent (partially outdated) formats with short links
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://youtu.be/1v8_2dW7Kik#t=11850'), '1v8_2dW7Kik?t=11850')
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://youtu.be/1v8_2dW7Kik#t=1h'), '1v8_2dW7Kik?t=3600')
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://youtu.be/1v8_2dW7Kik#t=1h1m'), '1v8_2dW7Kik?t=3660')
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://youtu.be/1v8_2dW7Kik#t=3h17m30s'),
            '1v8_2dW7Kik?t=11850')
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://youtu.be/1v8_2dW7Kik#t=1m'), '1v8_2dW7Kik?t=60')
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://youtu.be/1v8_2dW7Kik#t=1m1s'), '1v8_2dW7Kik?t=61')
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://youtu.be/1v8_2dW7Kik#t=1s'), '1v8_2dW7Kik?t=1')

        # Not sure where this comes from, but it can happen
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://youtu.be/1v8_2dW7Kik?t=3h17m30s'),
            '1v8_2dW7Kik?t=11850')
        self.assertEqual(
            YouTubeVideoHelper.parse_id_from_url(
                'https://www.youtube.com/watch?v=1v8_2dW7Kik&t=3h17m30s'),
            '1v8_2dW7Kik?t=11850')
    def test_parse_id_from_url(self):
        # Standard HTTP
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('http://www.youtube.com/watch?v=1v8_2dW7Kik'), '1v8_2dW7Kik')
        # Standard HTTPS
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://www.youtube.com/watch?v=1v8_2dW7Kik'), '1v8_2dW7Kik')

        # Short link HTTP
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('http://youtu.be/1v8_2dW7Kik'), '1v8_2dW7Kik')
        # Short link HTTPS
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://youtu.be/1v8_2dW7Kik'), '1v8_2dW7Kik')

        # Standard with start time
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://www.youtube.com/watch?v=1v8_2dW7Kik&t=21'), '1v8_2dW7Kik?t=21')
        # Short link with start time
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://youtu.be/1v8_2dW7Kik?t=21'), '1v8_2dW7Kik?t=21')

        # Many URL params
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://www.youtube.com/watch?v=1v8_2dW7Kik&feature=youtu.be'), '1v8_2dW7Kik')
        # Short link many URL params
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://youtu.be/1v8_2dW7Kik?feature=youtu.be'), '1v8_2dW7Kik')

        # Many URL params with start time
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://www.youtube.com/watch?v=1v8_2dW7Kik&feature=youtu.be&t=11850'), '1v8_2dW7Kik?t=11850')
        # Short link many URL params with start time
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://youtu.be/1v8_2dW7Kik?feature=youtu.be&t=11850'), '1v8_2dW7Kik?t=11850')

        # Bunch of inconsistent (partially outdated) formats
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://www.youtube.com/watch?v=1v8_2dW7Kik#t=11850'), '1v8_2dW7Kik?t=11850')
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://www.youtube.com/watch?v=1v8_2dW7Kik#t=1h'), '1v8_2dW7Kik?t=3600')
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://www.youtube.com/watch?v=1v8_2dW7Kik#t=1h1m'), '1v8_2dW7Kik?t=3660')
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://www.youtube.com/watch?v=1v8_2dW7Kik#t=3h17m30s'), '1v8_2dW7Kik?t=11850')
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://www.youtube.com/watch?v=1v8_2dW7Kik#t=1m'), '1v8_2dW7Kik?t=60')
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://www.youtube.com/watch?v=1v8_2dW7Kik#t=1m1s'), '1v8_2dW7Kik?t=61')
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://www.youtube.com/watch?v=1v8_2dW7Kik#t=1s'), '1v8_2dW7Kik?t=1')

        # Bunch of inconsistent (partially outdated) formats with short links
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://youtu.be/1v8_2dW7Kik#t=11850'), '1v8_2dW7Kik?t=11850')
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://youtu.be/1v8_2dW7Kik#t=1h'), '1v8_2dW7Kik?t=3600')
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://youtu.be/1v8_2dW7Kik#t=1h1m'), '1v8_2dW7Kik?t=3660')
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://youtu.be/1v8_2dW7Kik#t=3h17m30s'), '1v8_2dW7Kik?t=11850')
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://youtu.be/1v8_2dW7Kik#t=1m'), '1v8_2dW7Kik?t=60')
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://youtu.be/1v8_2dW7Kik#t=1m1s'), '1v8_2dW7Kik?t=61')
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://youtu.be/1v8_2dW7Kik#t=1s'), '1v8_2dW7Kik?t=1')

        # Not sure where this comes from, but it can happen
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://youtu.be/1v8_2dW7Kik?t=3h17m30s'), '1v8_2dW7Kik?t=11850')
        self.assertEqual(YouTubeVideoHelper.parse_id_from_url('https://www.youtube.com/watch?v=1v8_2dW7Kik&t=3h17m30s'), '1v8_2dW7Kik?t=11850')