Skip to content

Commit 273c0de

Browse files
author
Joss
committed
Updated main.py
Songs can now be pulled from Reddit under the community guidelines.
1 parent fbf2c3b commit 273c0de

3 files changed

Lines changed: 77 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
RedditMusicBot
1+
MusicBot

main.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import praw
2+
import spotipy
3+
import spotipy.util as util
4+
# Songs should be in the format:
5+
# (Artist) - (Song)
6+
# Therefore splitting at '-' and stripping whitespace
7+
# Should give us a valid song title
8+
9+
def valid_artist_and_song(title, media):
10+
if '-' in title:
11+
if len(title) <= 80:
12+
if 'type' in media.keys():
13+
if media['type'] == 'youtube.com':
14+
return True
15+
return False
16+
17+
def non_BMP_check(title):
18+
return all(ord(char) in range(65535) for char in title)
19+
20+
21+
22+
def main():
23+
reddit = praw.Reddit('bot')
24+
25+
subreddit = reddit.subreddit('House')
26+
27+
28+
scope = 'user-library-read'
29+
#token = util.prompt_for_user_token('ry2gg4eh81ep1v42b1r6mubtw', scope,
30+
#client_id='1f6597e91b714ae4abe73a175b8a76d2',
31+
#client_secret='689d718acb5349ae8856f21bbd518437')
32+
spotify = spotipy.Spotify()
33+
34+
35+
titles = []
36+
for submission in subreddit.top('month', limit=None):
37+
if (submission.media is not None
38+
and valid_artist_and_song(submission.title,
39+
submission.media)
40+
and submission.score >= 5
41+
and non_BMP_check(submission.title)):
42+
43+
titles.append(submission.title)
44+
45+
results = spotify.search(q=titles[0], type='track')
46+
print(results)
47+
48+
49+
50+
if __name__ == '__main__':
51+
main()

praw.ini

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[DEFAULT]
2+
# A boolean to indicate whether or not to check for package updates.
3+
check_for_updates=True
4+
5+
# Object to kind mappings
6+
comment_kind=t1
7+
message_kind=t4
8+
redditor_kind=t2
9+
submission_kind=t3
10+
subreddit_kind=t5
11+
12+
# The URL prefix for OAuth-related requests.
13+
oauth_url=https://oauth.reddit.com
14+
15+
# The URL prefix for regular requests.
16+
reddit_url=https://www.reddit.com
17+
18+
# The URL prefix for short URLs.
19+
20+
[bot]
21+
client_id=DjTqbiK7yQyDwA
22+
client_secret= fvWVPp8GLPuAg8OgFWrg418VVUU
23+
password=
24+
username=
25+
user_agent = Music Bot 0.1

0 commit comments

Comments
 (0)