예제 #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))
예제 #3
0
def yt_start(value):
    if '?t=' in value:  # Treat ?t= the same as #t=
        value = value.replace('?t=', '#t=')
    if '#t=' in value:
        sp = value.split('#t=')
        video_id = sp[0]
        old_ts = sp[1]
        total_seconds = YouTubeVideoHelper.time_to_seconds(old_ts)
        value = '%s?start=%i' % (video_id, total_seconds)

    return value
예제 #4
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
예제 #6
0
 def youtube_videos_formatted(self):
     """
     Get youtube video ids formatted for embedding
     """
     if self._youtube_videos is None:
         self._youtube_videos = []
         for video in self.youtube_videos:
             if '?t=' in video:  # Treat ?t= the same as #t=
                 video = video.replace('?t=', '#t=')
             if '#t=' in video:
                 sp = video.split('#t=')
                 video_id = sp[0]
                 old_ts = sp[1]
                 total_seconds = YouTubeVideoHelper.time_to_seconds(old_ts)
                 video = '%s?start=%i' % (video_id, total_seconds)
             self._youtube_videos.append(video)
     return self._youtube_videos
예제 #7
0
 def youtube_videos_formatted(self):
     """
     Get youtube video ids formatted for embedding
     """
     if self._youtube_videos is None:
         self._youtube_videos = []
         for video in self.youtube_videos:
             if '?t=' in video:  # Treat ?t= the same as #t=
                 video = video.replace('?t=', '#t=')
             if '#t=' in video:
                 sp = video.split('#t=')
                 video_id = sp[0]
                 old_ts = sp[1]
                 total_seconds = YouTubeVideoHelper.time_to_seconds(old_ts)
                 video = '%s?start=%i' % (video_id, total_seconds)
             self._youtube_videos.append(video)
     return self._youtube_videos
예제 #8
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')