Internet radio browser GUI for music/video streams from various directory services.

βŒˆβŒ‹ βŽ‡ branch:  streamtuner2


Check-in [d840371943]

Overview
Comment:Channel plugin for reddit /r/*music* categories. Just filters out Youtube or direct MP3/Ogg links at the moment.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d840371943f0d7b352122c1fbeb4e022f92d6bf1
User & Date: mario on 2015-05-22 01:49:10
Other Links: manifest | tags
Context
2015-05-22
22:00
Use gtk-info/-error/-no for placeholder entries. check-in: 55408c97f8 user: mario tags: trunk
01:49
Channel plugin for reddit /r/*music* categories. Just filters out Youtube or direct MP3/Ogg links at the moment. check-in: d840371943 user: mario tags: trunk
2015-05-21
20:08
Remove config.find_in_dirs(), which is unused now. check-in: 11f270a726 user: mario tags: trunk
Changes

Added contrib/reddit.py version [64c5bb569c].














































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
# encoding: UTF-8
# api: streamtuner2
# title: redditβ›±music
# description: Music recommendations from reddit /r/music etc.
# version: 0.5
# type: channel
# url: http://reddit.com/r/Music
# category: playlist
# config:
#   { name: reddit_pages, type: int, value: 2, description: Number of pages to fetch. }
#   ( name: kill_soundcloud, type: boolean, value: 1, description: Filter soundcloud links (no player configurable). )
# png:
#   iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJ1BMVEUAAAAcICX/AABHSk1jZ299hYz/bmajq6//lY/d0M3C1+3T7P38+/iaLhuGAAAAAXRSTlMAQObYZgAAAAFiS0dEAIgF
#   HUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQffBRUXIyQbWArCAAAAh0lEQVQI12Pg3g0BDLtXrVq1eveq3Qy7gIxCU9dqEGO11/ZKbzBDenUIUM3u7cGi1UDFW0TE55wsdpZikAw/
#   eebMnMmHGVxqDuUc0zzpynD4zIk5J3vOSDNsOQMG1gy7bI5HTq85Ws2wu/jM9PIzrkArdhmXlzuuXg00eVd5+epVqxmgrtgNAOWeS1KYtcY4AAAAAElFTkSuQmCC
# priority: extra
#
# Just imports Youtube links from music-related subreddits.
# Those are usually new bands or fresh releases, or favorite
# user selections. Soundcloud and weblinks are filtered out.
#
# This plugin currently uses the old reddit API, which will
# be obsolete by August. It's thus a temporary channel, as
# migrating to OAuth or regressing to plain HTML extraction
# is not very enticing.


import json
import re
from config import *
from channels import *
import ahttp


# reddit.com
#
# Uses old API requests such as:
#  β†’ http://www.reddit.com/r/music/new.json?sort=new
#
class reddit (ChannelPlugin):

    # control attributes
    has_search = False
    listformat = "srv"
    audioformat = "video/youtube"
    titles = dict(playing="submitter", listeners="votes", bitrate=False)
    
    # just subreddit names to extract from
    categories = [
        "radioreddit",
        "Music",
        "music_discovery",
        "trueMusic",
        "futurebeats",
        "futurefunkairlines",
        "ElectronicMusic",
        ["acidhouse", "ambientmusic", "bigbeat", "breakbeat", "breakcore", "chillout",
        "darkstep", "deephouse", "DnB", "Dubstep", "EDM", "electronicdancemusic", "electrohouse",
        "electropop", "funkhouse", "gabber", "hardhouse", "house", "industrialmusic",
        "minimal", "partymusic", "psytrance", "Techno", "Trance", "tech_house", "witchhouse"],
        "indiewok",
        "Jazz",
        "ClassicalMusic",
        ["baroque", "composer", "contempory", "ChamberMusic",
        "choralmusic", "EarlyMusic", "ElitistClassical", "opera", "pianocovers"],
        "ListenToThis",
        "ListenToUs",
        "WhatIListenTo",
        "ListenToConcerts",
        "HeadBangToThis",
        "unheardof",
        "under10k",
        "MusicForConcentration", ["MusicToSleepTo"],
        "gamemusic", 
        "2010sMusic", ["2000sMusic", "90sMusic", "80sMusic", "70sMusic", "60sMusic",
        "50sMusic", "SoundsVintage"],
        "PopMusic",
        "Catchysongs",
        "CoverSongs",
        ["ICoveredASong", "MyMusic", "UserProduced", "RepublicOfMusic", "RoyaltyFreeMusic"],
        "musicvideos",
        "Frisson",
        "Turntablists",
    ]


    # static
    def update_categories(self):
        pass


    # Extract video/music news links
    def update_streams(self, cat, search=None):
        
        # radioreddit
        if cat == "radioreddit":
           return self.radioreddit()

        # collect links
        data = []
        after = ""
        for i in range(1, int(conf.reddit_pages) + 1):
            j = json.loads(ahttp.get(
                "http://www.reddit.com/r/{}/new.json?sort=new&after={}".format(
                    cat.lower(), after
                )
            ))
            if not j.get("data",[]).get("children"):
                break
            data += j["data"]["children"]
            after = j["data"]["after"]

        # convert
        r = []
        for row in (ls["data"] for ls in data):

            # find links in text posts
            text_urls = re.findall("\]\((https?://(?:www\.)?youtu[^\"\'\]\)]+)", row.get("selftext", ""))
            url_ext = (re.findall("\.(\w+)$", row["url"]) or [None])[0]
            listformat = "href"

            # Youtube
            if re.search("youtu", row["url"]):
                format = "video/youtube"
                listformat = "srv"
            # direct MP3/Ogg
            elif url_ext in ("mp3", "ogg", "flac", "aac", "aacp"):
                format = "audio/" + url_ext
                listformat = "srv"
                print row
                print url_ext
            # playlists?
            elif url_ext in ("m3u", "pls", "xspf"):
                listformat = url_ext
                format = "audio/x-unknown"
                print url_ext
            # links from selftext
            elif text_urls:
                row["url"] = text_urls[0]
            # filter out Soundcloud etc.
            else:
                continue

            # repack into streams list
            r.append(dict(
                title = row["title"],
                url = row["url"],
                genre = re.findall("\[(.+?)\]", row["title"] + "[-]")[0],
                playing = row["author"],
                listeners = row["score"],
                homepage = "http://reddit.com{}".format(row["permalink"]),
                img = row.get("thumbnail", ""),
                format = format,
                listformat = listformat,
            ))
        return r        


    # static station list
    def radioreddit(self):
        return [
            dict(
                genre=id, title=id.title(),
                url="http://cdn.audiopump.co/radioreddit/"+id+"_mp3_128k",
                format="audio/mpeg", homepage="http://radioreddit.com/",
                listformat="srv"
            )
            for id in [
                "main", "random", "rock", "metal", "indie",
                "electronic", "hiphop", "talk", "festival"
            ]
        ]