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

⌈⌋ ⎇ branch:  streamtuner2


Check-in [3c3ec8e447]

Overview
Comment:Fix missing url: plugin meta. Display bitrate and length. Fix more mutagen extraction faults.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3c3ec8e447d40dfd079969d930539bd9e213628c
User & Date: Oliver on 2016-12-23 21:33:43
Other Links: manifest | tags
Context
2016-12-23
21:36
Guard non-writeable gtk_dir / extra statusbar info. check-in: fdad9d9430 user: Oliver tags: trunk
21:33
Fix missing url: plugin meta. Display bitrate and length. Fix more mutagen extraction faults. check-in: 3c3ec8e447 user: Oliver tags: trunk
21:31
Workaround for file:/// paths on windows with mixed driver letters and backslashes. check-in: 4c8fadb925 user: Oliver tags: trunk
Changes

Modified contrib/file.py from [63bdb9da05] to [af89693d25].

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
# api: streamtuner2
# title: File browser
# description: Displays mp3/oggs or m3u/pls files from local media file directories.
# type: channel
# category: local
# version: 0.2
# priority: optional
# status: unsupported
# depends: python:mutagen, python:id3
# config:  
#   { name: file_browser_dir, type: text, value: "$XDG_MUSIC_DIR, ~/MP3", description: "List of directories to scan for audio files." },
#   { name: file_browser_ext, type: text, value: "mp3,ogg, m3u,pls,xspf, avi,flv,mpg,mp4", description: "File type/extension filter." },

# png:
#   iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMA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Mn57+JBka4v04IDs8JDD+RxGI8RoxPz1a6yyJJ/PGT9/rivXzZRSp3m9/kYAtFdWvm3PZt+1
#   kkQEtk1g2wRSEihV+badR7Va2vS8ceR5A9uYrimKv/LZ7MhU1VF7efnD2sWL3cb6+slzrT9IgKXFxT8W07S33GpZywsLHxzLep/Gcac3Gu0H9fp7Z3X1KLp27WT9+vXh8epq8vXdu7N+FPG61UIXBXZZAmCVJX8DADze5LjPkMQAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTUtMDUtMDVUMTU6MTA6NTkrMDI6MDBD/PY6AAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE1LTA1LTA1VDE1OjEwOjU5KzAyOjAwMqFOhgAAAABJRU5ErkJggg==
# png-orig:
#   https://openclipart.org/detail/168001/folder-icon-red-music
# extraction-method: os
#
# Local file browser. Presents files from configured directories.
# This is not what streamtuner2 is meant for. Therefore this is
# an optional plugin, and not overly well integrated.
#
# Bugs:
# Only loads directories on startup. Doesn't work when post-activated
# per pluginmanager2 for instance. And LANG=C breaks it on startup,
# if media directories contain anything but ASCII filenames.


# modules
import os
import re

from channels import *
from config import *

# ID3 libraries
try:
    from mutagen import File as get_meta
except:
    try:
        from ID3 import ID3
        log.INFO("Just basic ID3 support")
        get_meta = lambda fn: dict([(k.lower(),v) for k,v in ID3(fn).iteritems()])
    except:
        log.INIT("You are out of luck in regards to mp3 browsing. No ID3 support.")
        get_meta = lambda *x: {}














# work around mutagens difficult interface
def mutagen_postprocess(d):








    if d.get("TIT2"):







        return {
            "encoder": d["TENC"][0],
            "title": d["TIT2"][0],
            "artist": d["TPE1"][0],


#            "tyer?????????????": d["TYER"][0],
#            "track": d["TRCK"][0],













            "album": d["TALB"][0],
















        }
    else:
        return d




# file browser / mp3 directory listings
class file (ChannelPlugin):

    # data
    listtype = "href"
    streams = {}
    categories = []
    dir = []
    ext = []
    
    # display
    datamap = [ # coltitle   width	[ datasrc key, type, renderer, attrs ]	[cellrenderer2], ...
           ["",		20,	["state",	str,  "pixbuf",	{}],	],
           ["Genre",	65,	['genre',	str,	"t",	{"editable":8}],	],
           ["File",	160,	["filename",	str,	"t",	{"strikethrough":10, "cell-background":11, "cell-background-set":12}],	],
           ["Title",	205,	["title",	str,    "t",	{"editable":8}], ],
           ["Artist",	125,	["artist",	str,	"t",	{"editable":8}],	],
           ["Album", 	125,	["album",	str,	"t",	{"editable":8}],	],

           ["Bitrate",	35,	["bitrate",	int,	"t",	{}],	],
           ["Format",	50,	["format",	str,	None,	{}],	],

           [False,	0,	["editable",	bool,	None,	{}],	],
           [False,	0,	["favourite",	bool,	None,	{}],	],
           [False,	0,	["deleted",	bool,	None,	{}],	],
           [False,	0,	["search_col",	str,	None,	{}],	],
           [False,	0,	["search_set",	bool,	None,	{}],	],
    ]        
    rowmap = []












>



















|



















>
>
>
>
>
>
>
>
>
>
>
>



>
>
>
>
>
>
>
>

>
>
>
>
>
>
>

|
|
|
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



<
<
<














|
<
|
|
|
>
|
|
>







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
# api: streamtuner2
# title: File browser
# description: Displays mp3/oggs or m3u/pls files from local media file directories.
# type: channel
# category: local
# version: 0.2
# priority: optional
# status: unsupported
# depends: python:mutagen, python:id3
# config:  
#   { name: file_browser_dir, type: text, value: "$XDG_MUSIC_DIR, ~/MP3", description: "List of directories to scan for audio files." },
#   { name: file_browser_ext, type: text, value: "mp3,ogg, m3u,pls,xspf, avi,flv,mpg,mp4", description: "File type/extension filter." },
# url: http://freshcode.club/projects/streamtuner2
# png:
#   iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wUFDQsK23vYngAAA6lJREFUOMtFz8tu1FYAxvH/sc+xxx7bM8lkElAgISoV4qIgpEaomwg2bMqiQmo3lfowPElVVbQr3gBVqGJRGi6VEERFDROS0Ewmc/N47Bkf+7gLevke4Kfv
#   L374/vufxm/ffjnudJQoisoVonLDcN+sr39z7uXLXzfOn6cRhmSTCf3TUwa9HoN+H601ynXxwhA7ivhdCH48PkZOut0vdh48cKtej9C2iSyLsF7/xLpx4/5eu/1LZzSiaQx1z8O5cIHapUvVmpRkaUqcJMRpSjydmnEcP/2zKH6WOs/7mdZBVVXIqsKuKk4nE4qdnTueUncCpZh5HoHj4AqBVRQIrUFrLGPwlaLhOLiWtX93OPxKIuX+0HHWJ5ZF03VxpaRfFLRmM1rTKUGrRX1piUYQEIUhfhRRC0OqOMZxHIIwJIgiHFj77OnT+7KEd0Wt
#   tl0Kgev7NHyf5apCTSaoLEMlCZdu3uT85ib1hQWi1VWcMCTb3cXxPJxmExlF2LWaMFpvS4TYcx2nmpalsKoKJQSNMCQ6cwZPCMxgwKTbpfPoETWlWDx3jtblyyghEFpjSYmwbYQx6DyPJUJ0bKUKU5Yqn83QSqGVolQKGQSEGxssrK3RffyY6Zs3zK9epb6wgBWGCCFQjkOlFFVRoIfDkTRwYIRIDTR0nqPnc7RSFP/AhW2jfJ/WlSvQ7zPe3SU9OECdPYuwbUrXxSiFsW2KOB7IaZYdp3keV9DQ8znacSj+RaWkqtVACExR0NrcZPriBflw
#   SJqmWO32R9BxMEAxnfatJE37cZb1jWVRaP3x4XxOkecIy0J6HibPmY1GqHqdpa0tbNdlvLNDfnJCOR5jJhPMYECZpj2JlPEwSbqBEFTG/Jd85fZtNm/dIjk6Itnbw19e5tN79yiHQ5JnzxgfHDBrNvGjCOM4lElCkWWn1ufb2/M4TQ9LIQAoiwJTlrQ3NrCVQjoOw04Hf2UF5ftI3wchsOt1Zu/eoTsd9KtX5E+eYCaTnux2u1VRVe8N/y/PMn57+JBka4v04IDs8JDD+RxGI8RoxPz1a6yyJJ/PGT9/rivXzZRSp3m9/kYAtFdWvm3PZt+1
#   kkQEtk1g2wRSEihV+badR7Va2vS8ceR5A9uYrimKv/LZ7MhU1VF7efnD2sWL3cb6+slzrT9IgKXFxT8W07S33GpZywsLHxzLep/Gcac3Gu0H9fp7Z3X1KLp27WT9+vXh8epq8vXdu7N+FPG61UIXBXZZAmCVJX8DADze5LjPkMQAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTUtMDUtMDVUMTU6MTA6NTkrMDI6MDBD/PY6AAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE1LTA1LTA1VDE1OjEwOjU5KzAyOjAwMqFOhgAAAABJRU5ErkJggg==
# png-orig:
#   https://openclipart.org/detail/168001/folder-icon-red-music
# extraction-method: os
#
# Local file browser. Presents files from configured directories.
# This is not what streamtuner2 is meant for. Therefore this is
# an optional plugin, and not overly well integrated.
#
# Bugs:
# Only loads directories on startup. Doesn't work when post-activated
# per pluginmanager2 for instance. And LANG=C breaks it on startup,
# if media directories contain anything but ASCII filenames.

#from __future__ import print_function
# modules
import os
import re

from channels import *
from config import *

# ID3 libraries
try:
    from mutagen import File as get_meta
except:
    try:
        from ID3 import ID3
        log.INFO("Just basic ID3 support")
        get_meta = lambda fn: dict([(k.lower(),v) for k,v in ID3(fn).iteritems()])
    except:
        log.INIT("You are out of luck in regards to mp3 browsing. No ID3 support.")
        get_meta = lambda *x: {}


#Convert seconds to a time string "[[[DD:]HH:]MM:]SS".
def ddhhmmss(seconds):
    dhms = ''
    for scale in 86400, 3600, 60:
        result, seconds = divmod(seconds, scale)
        if dhms != '' or result > 0:
            dhms += '{0:02d}:'.format(result)
    dhms += '{0:02d}'.format(seconds)
    if len(dhms) == 2:
        dhms = "00:" + dhms
    return dhms

# work around mutagens difficult interface
def mutagen_postprocess(d):

    IDTitle = ""
    IDArtist = ""
    IDGenre = ""
    IDAlbum = ""

    #Beware: Keep the order MP3 - FLAC/OGG - MP4/M4A!
    #MP3
    if d.get("TIT2"):
        IDTitle = d["TIT2"][0]
        if d.get("TPE1"):
            IDArtist = d["TPE1"][0]
        if d.get("TCON"):
            IDGenre = d["TCON"][0]
        if d.get("TALB"):
            IDAlbum = d["TALB"][0]
        return {
            #"encoder": d["TENC"][0],            
            "title": IDTitle,
            "artist": IDArtist,
            "genre": IDGenre,
            "album": IDAlbum
            #"tyer?????????????": d["TYER"][0], (YEAR)
            #"track": d["TRCK"][0],
        }
    #FLAC/OGG
    elif d.get("title"):
        IDTitle = d["title"][0]
        if d.get("artist"):
            IDArtist = d["artist"][0]
        if d.get("album"):
            IDAlbum = d["album"][0]
        if d.get("genre"):
            IDGenre = d["genre"][0]
        return {
            "title": IDTitle,
            "artist": IDArtist,
            "album": IDAlbum,
            "genre": IDGenre
        }            
    #MP4/M4A
    elif d.get("\xa9nam"):
        IDTitle = d["\xa9nam"][0]
        if d.get("\xa9ART"):
            IDArtist = d["\xa9ART"][0]
        if d.get("\xa9alb"):
            IDAlbum = d["\xa9alb"][0]
        if d.get("\xa9gen"):
            IDGenre = d["\xa9gen"][0]
        return {
            "title": IDTitle,
            "artist": IDArtist,
            "genre": IDGenre,
            "album": IDAlbum
        }
    else:
        return d




# file browser / mp3 directory listings
class file (ChannelPlugin):

    # data
    listtype = "href"
    streams = {}
    categories = []
    dir = []
    ext = []
    
    # display
    datamap = [ # coltitle   width	[ datasrc key, type, renderer, attrs ]	[cellrenderer2], ...
           ["",		20,	["state",	str,  "pixbuf",	{}],	],
           ["Genre",	65,	['genre',	str,	"t",	{"editable":9}],	],

           ["Title",	205,	["title",	str,    "t",	{"editable":9}], ],
           ["Artist",	160,	["artist",	str,	"t",	{}],	],
           ["Album", 	150,	["album",	str,	"t",	{}],	],
           ["Length", 	50,	["length",	str,	"t",	{}],	],
           ["Bitrate",	50,	["bitrate",	str,	"t",	{}],	],
           ["Format",	80,	["format",	str,	None,	{}],	],
           ["File",	160,	["filename",	str,	"t",	{"strikethrough":11, "cell-background":12, "cell-background-set":13}],	],
           [False,	0,	["editable",	bool,	None,	{}],	],
           [False,	0,	["favourite",	bool,	None,	{}],	],
           [False,	0,	["deleted",	bool,	None,	{}],	],
           [False,	0,	["search_col",	str,	None,	{}],	],
           [False,	0,	["search_set",	bool,	None,	{}],	],
    ]        
    rowmap = []
170
171
172
173
174
175
176
177
178
179
180





181
182
183











184
185



186
187
188
189
190

191
192
193
194
195
196
197
                self.streams[main] = self.streams[main_base]


    # extract meta data
    def file_entry(self, fn, dir):
        # basic data
        meta = {
            "title": fn,
            "filename": fn,
            "url": "file://" + dir + "/" + fn,
            "genre": "",





            "format": mime_fmt(fn[-3:]),
            "editable": True,
        }











        # add ID3
        meta.update(mutagen_postprocess(get_meta(dir + "/" + fn) or {}))



        return meta
        
    # check fn for .ext
    def we_like_that_extension(self, fn):
        return fn[-3:] in self.ext

    


    # same as init
    def update_categories(self):
        self.scan_dirs()








|



>
>
>
>
>
|
|
|
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>




|
>







227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
                self.streams[main] = self.streams[main_base]


    # extract meta data
    def file_entry(self, fn, dir):
        # basic data
        meta = {
            "title": "",
            "filename": fn,
            "url": "file://" + dir + "/" + fn,
            "genre": "",
            "album": "",
            "artist": "",
            "length": "n/a",
            "bitrate": "n/a",
#            "format": mime_fmt(fn[-3:]),
            "format": mime_fmt(fn[-(len(fn)-fn.rfind(".")-1):]),
            "editable": False,
            }
        try:
            streaminfo =get_meta(dir + "/" + fn)
            # add streaminfo
            if streaminfo.info: # no streaminfo.info, maybe ID3 available
                try:
                    if not streaminfo.info.bitrate == 0:
                        meta.update({"bitrate": streaminfo.info.bitrate/1000})
                except: #FLAC and M4A do not have bitrate property
                    pass
                if not streaminfo.info.length == 0.0: #FLAC sometimes have it...
                    meta.update({"length": ddhhmmss(int(streaminfo.info.length))})
            # add ID3
            meta.update(mutagen_postprocess(streaminfo) or {})
            
        except: # unsupported by Mutagen
            pass
        return meta
        
    # check fn for .ext
    def we_like_that_extension(self, fn):
 #       return fn[-3:] in self.ext
        return fn[-(len(fn)-fn.rfind(".")-1):] in self.ext
    


    # same as init
    def update_categories(self):
        self.scan_dirs()