예제 #1
0
    def test_it_should_detect_username_same_as_featured_artist(self):
        parsed = ParsedSubmission(True, 'url', 'NoMatch', 'redditor01rocks')
        sub = MockedSubmission("testredditor01rocks")
        self.assertTrue(SelfPromoDetector.is_self_promo(parsed, sub))

        parsed = ParsedSubmission(True, 'url', 'NoMatch', 'test redditor 01 rocks')
        sub = MockedSubmission("redditor01")
        self.assertTrue(SelfPromoDetector.is_self_promo(parsed, sub))
예제 #2
0
    def test_it_should_work_with_spaces_and_dashes(self):
        parsed = ParsedSubmission(True, 'url', 'Test_Red_Ditor')
        sub = MockedSubmission("TestRedditor")
        self.assertTrue(SelfPromoDetector.is_self_promo(parsed, sub))

        parsed = ParsedSubmission(True, 'url', 'te_str-edd-itor 01rocks')
        sub = MockedSubmission("TestRedditor")
        self.assertTrue(SelfPromoDetector.is_self_promo(parsed, sub))
예제 #3
0
 def create_parsed_submission_from_submission(
         cls, submission) -> ParsedSubmission:
     try:
         artist = cls.get_artist_name_from_submission_title(
             submission.title)
         song = cls.get_song_name_from_submission_title(
             submission.title, artist)
         return ParsedSubmission(True, submission.url, artist[0], artist[1],
                                 song)  # , submission.id)
     except Exception:
         # On any failures, pass back a ParsedSubmission object with success flag of False
         return ParsedSubmission(False, submission.url)
예제 #4
0
    def get_service_result(self, parsed_submission: ParsedSubmission) -> ThresholdServiceResult:
        url = parsed_submission.get_final_url()
        if 'soundcloud.com' not in url:
            return ThresholdServiceResult.error()

        response = requests.get(
            'https://api.soundcloud.com/resolve.json?url=' + url + '&client_id=' + self.config.SOUNDCLOUD.KEY
        )

        if response.status_code != 200:
            return ThresholdServiceResult.error()

        data = response.json()

        if ArrayUtil.safe_list_get(data, False, 'playback_count') is False:
            return ThresholdServiceResult.error()

        return ThresholdServiceResult(data['playback_count'] > self.Threshold, data['playback_count'], self.Threshold,
                                      'Soundcloud plays')
예제 #5
0
    def get_service_result(self, parsed_submission: ParsedSubmission) -> ThresholdServiceResult:
        """
        Get the v query from the url and use it to query for Youtube review statistics
        """
        final_url = urlparse(parsed_submission.get_final_url())

        if final_url.netloc not in self.youtubeUrls:
            return ThresholdServiceResult.error()

        query = parse.parse_qs(parse.urlsplit(final_url.geturl()).query)

        request = self.youtubeClient.videos().list(
            part="statistics",
            id=query['v'][0]
        )
        response = request.execute()
        view_count = int(response['items'][0]['statistics']['viewCount'])

        return ThresholdServiceResult(view_count > self.threshold, view_count, self.threshold, 'YouTube plays')
예제 #6
0
 def test_it_should_fail_on_short_user_names(self):
     parsed = ParsedSubmission(True, 'url', 'Test_Red_Ditor')
     sub = MockedSubmission("-------___e____") # Evals to just "e" inside detector
     self.assertFalse(SelfPromoDetector.is_self_promo(parsed, sub))
예제 #7
0
 def test_it_should_fail_on_no_match(self):
     parsed = ParsedSubmission(True, 'url', 'Nedl2dinin')
     sub = MockedSubmission("Not_Ned l1inin")
     self.assertFalse(SelfPromoDetector.is_self_promo(parsed, sub))
예제 #8
0
 def test_it_should_not_fail_on_failed_parsed_submission(self):
     parsed = ParsedSubmission(False, 'url')
     sub = MockedSubmission("testredditor01rocks")
     self.assertFalse(SelfPromoDetector.is_self_promo(parsed, sub))
 def test_it_should_know_excluded_artists(self):
     self.assertTrue(
         ExcludedArtists.is_excluded(
             ParsedSubmission(True, 'url', 'various artists')))
 def test_it_should_know_excluded_artists_case_insensitive(self):
     self.assertTrue(
         ExcludedArtists.is_excluded(
             ParsedSubmission(True, 'url', 'Anonymous')))