diff --git a/README.md b/README.md index 09dba6b..575c662 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,12 @@ And that's it! If it doesn't work you can create an issue ## How to use? Please set the `SUBREDDIT` in `conf/config.ini` to select the desired subreddit to moderate. This only works when the Reddit account is moderator of the selected subreddit - + +## Features +- [x] Using Youtube, Last.fm and Soundcloud for detecting submissions with exceeding listen count +- [x] Report self-promotion posts using username and submission title +- [x] Post artist tags, album information and social media links using Musicbrainz + ## Contribute If you have features or bugfixes don't be shy to create a pull requests or bug report! diff --git a/blottertrax/description_provider.py b/blottertrax/description_provider.py index 60d9654..b2135a8 100644 --- a/blottertrax/description_provider.py +++ b/blottertrax/description_provider.py @@ -41,8 +41,8 @@ def get_reply(self, parsed_submission: ParsedSubmission) -> str: life_span = '' if has_life_span is False else '({} to {})'.format(life_span_begin, life_span_end) tags = ', '.join(map(lambda t: t['name'], artist['tag-list'][:5])) if has_tags else 'none' - socials = ', '.join(map(lambda u: '[{}]({})'.format(u['type'], u['target']), - artist['url-relation-list'])) if has_socials else 'none' + socials = ', '.join( + map(self.format_network_to_friendly_name, artist['url-relation-list'])) if has_socials else 'none' return templates.musicbrainz_artist_info.strip().format( artist['name'], @@ -58,3 +58,17 @@ def _get_artist_by_id(self, artist_id: str): return self.musicbrainz.get_artist_by_id( id=artist_id, includes=['tags', 'ratings', 'annotation', 'url-rels', 'user-tags'] )['artist'] + + @staticmethod + def format_network_to_friendly_name(info) -> str: + social_network = ['twitter.com', 'facebook.com', 'instagram.com'] + link_type = info['type'] + target = info['target'] + target = target.replace('(', '\(').replace(')', '\)') + + if link_type == 'social network': + for domain in social_network: + if domain in target: + link_type = domain.split('.')[0] + break + return '[{}]({})'.format(link_type, target) diff --git a/blottertrax/services/youtube.py b/blottertrax/services/youtube.py index bb17517..3832fd2 100644 --- a/blottertrax/services/youtube.py +++ b/blottertrax/services/youtube.py @@ -1,6 +1,5 @@ from typing import List from urllib import parse - from urllib.parse import urlparse import googleapiclient.discovery @@ -11,8 +10,6 @@ from blottertrax.value_objects.parsed_submission import ParsedSubmission from blottertrax.value_objects.service_result import ThresholdServiceResult -scopes = ["https://www.googleapis.com/auth/youtube.readonly"] - class Youtube(ThresholdService): config: Config = Config() diff --git a/tests/test_description_provider.py b/tests/test_description_provider.py new file mode 100644 index 0000000..e387803 --- /dev/null +++ b/tests/test_description_provider.py @@ -0,0 +1,22 @@ +import unittest + +from blottertrax.description_provider import DescriptionProvider + + +class MyTestCase(unittest.TestCase): + def test_format_network_to_friendly_name(self): + networks = [ + ('social network', 'https://facebook.com/linkedpage', '[facebook](https://facebook.com/linkedpage)'), + ('social network', 'https://twitter.com/linkedpage', '[twitter](https://twitter.com/linkedpage)'), + ('social network', 'https://instagram.com/linkedpage', '[instagram](https://instagram.com/linkedpage)'), + ('discogs', 'https://discogs.com/linkedpage', '[discogs](https://discogs.com/linkedpage)'), + ('some other database', 'https://some-other-database.com/linkedpage', '[some other database](https://some-other-database.com/linkedpage)'), + ('wikipedia', 'https://en.wikipedia.org/wiki/Caravan_(band)', '[wikipedia](https://en.wikipedia.org/wiki/Caravan_\(band\))'), + ] + for network_type, target, expected in networks: + formatted = DescriptionProvider.format_network_to_friendly_name({ + 'target': target, + 'type': network_type + }) + + self.assertEqual(expected, formatted)