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

⌈⌋ branch:  streamtuner2


Check-in [9cff8f85d7]

Overview
Comment:Catch unset time prior queueing. Use new FeaturePlugin class.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9cff8f85d79a9c842ea246a460bd984b7e4249bd
User & Date: mario on 2017-01-05 21:21:24
Other Links: manifest | tags
Context
2017-01-05
21:22
Detect more absent variables/login, introduce UI delay on submission. check-in: 9eeccf1f29 user: mario tags: trunk
21:21
Catch unset time prior queueing. Use new FeaturePlugin class. check-in: 9cff8f85d7 user: mario tags: trunk
21:20
Default background color for channel.warn() calls. check-in: 197656d143 user: mario tags: trunk
Changes

Modified channels/timer.py from [3136ca6563] to [54b6176f28].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# encoding: utf-8
# api: streamtuner2
# title: Recording timer
# description: Schedules play/record events for bookmarked radio stations.
# type: feature
# category: hook
# depends: kronos, action >= 1.1.1
# version: 0.7.7
# config: 
#   { name: timer_duration, type: select, select: "auto|streamripper|fpls", value: none, description: "Support for time ranges" }
#   { name: timer_crontab, type: bool, value: 0, description: "Utilize cron instead of runtime scheduler. (not implemented yet)" }
# priority: optional
# support: basic
#
# Provides an internal timer, to configure recording and playback times/intervals







|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# encoding: utf-8
# api: streamtuner2
# title: Recording timer
# description: Schedules play/record events for bookmarked radio stations.
# type: feature
# category: hook
# depends: kronos, action >= 1.1.1
# version: 0.7.8
# config: 
#   { name: timer_duration, type: select, select: "auto|streamripper|fpls", value: none, description: "Support for time ranges" }
#   { name: timer_crontab, type: bool, value: 0, description: "Utilize cron instead of runtime scheduler. (not implemented yet)" }
# priority: optional
# support: basic
#
# Provides an internal timer, to configure recording and playback times/intervals
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
import action
import copy
import re



# timed events (play/record) within bookmarks tab
class timer (object):

    # plugin info
    module = 'timer'
    meta = plugin_meta()
    
    # configuration settings
    timefield = "playing"
    
    # kronos scheduler list
    sched = None
    
    
    
    # prepare gui
    def __init__(self, parent):
        if not parent:
            return
        conf.add_plugin_defaults(self.meta, self.module)
          
        # keep reference to main window
        self.parent = parent

        self.bookmarks = parent.bookmarks
        
        # add menu
        uikit.add_menu([parent.streammenu, parent.streamactions], "Add timer for station", self.edit_timer, insert=4)
        
        # target channel
        if not self.bookmarks.streams.get("timer"):







|

<
<
<
<







<

|
<
<
<

<
<
>







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
import action
import copy
import re



# timed events (play/record) within bookmarks tab
class timer (FeaturePlugin):





    # configuration settings
    timefield = "playing"
    
    # kronos scheduler list
    sched = None
    
    

    # prepare gui
    def init2(self, parent):



          


        # bookmarks channel shortcut
        self.bookmarks = parent.bookmarks
        
        # add menu
        uikit.add_menu([parent.streammenu, parent.streamactions], "Add timer for station", self.edit_timer, insert=4)
        
        # target channel
        if not self.bookmarks.streams.get("timer"):
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

    # close dialog,get data
    def add_timer(self, *w):
        timespec = self.parent.timer_value.get_text()

        # basic check for consistency
        if not re.match("^(\w{2,3}|[*,;+])+\s+(\d+:\d+)\s*((\.\.+|-+)\s*(\d+:\d+))?\s+(record|play)", timespec):
            self.parent.status('<span background="orange">⛔ Danger, Will Robinson! → The given timer date/action is likely invalid.</span>', timeout=22, markup=1)

        # hide dialog
        self.parent.timer_dialog.hide()
        row = self.parent.row()
        row = copy.copy(row)

        # add data







|







95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

    # close dialog,get data
    def add_timer(self, *w):
        timespec = self.parent.timer_value.get_text()

        # basic check for consistency
        if not re.match("^(\w{2,3}|[*,;+])+\s+(\d+:\d+)\s*((\.\.+|-+)\s*(\d+:\d+))?\s+(record|play)", timespec):
            self.warn('Danger, Will Robinson! → The given timer date/action is likely invalid.', timeout=22)

        # hide dialog
        self.parent.timer_dialog.hide()
        row = self.parent.row()
        row = copy.copy(row)

        # add data
151
152
153
154
155
156
157

158
159

160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178

179
180
181
182
183
184
185
186
        # which action
        if row[self.timefield].find("rec")>=0:
            activity, action_method = "record", self.record
        else:
            activity, action_method = "play", self.play
        
        # add

        task = self.sched.add_daytime_task(action_method, activity, days, None, time, kronos.method.threaded, [row], {})


        log.QUEUE( activity, self.sched, (action_method, activity, days, None, time, kronos.method.threaded, [row], {}), task.get_schedule_time(True) )
    
    
    
    # converts Mon,Tue,... into numeric 1-7
    def days(self, s):
        weekdays = ["su", "mo", "tu", "we", "th", "fr", "sa", "su"]
        r = []
        if re.search("any|all|\*", s, re.I):
            return range(0,7)
        for day in re.findall("\w\w+", s.lower()):
            day = day[0:2]
            if day in weekdays:
                r.append(weekdays.index(day))
        return list(set(r))
        
    # get start time 18:00
    def time(self, s):
        r = re.search("(\d+):(\d+)", s)

        return int(r.group(1)), int(r.group(2))
        
    # convert "18:00-19:15" to minutes
    def duration(self, s):
        try:
            r = re.search("(\d+:\d+)\s*(\.\.+|-+)\s*(\d+:\d+)", s)
            start = self.time(r.group(1))
            end = self.time(r.group(3))







>
|
|
>
|


















>
|







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
174
175
176
177
178
179
180
        # which action
        if row[self.timefield].find("rec")>=0:
            activity, action_method = "record", self.record
        else:
            activity, action_method = "play", self.play
        
        # add
        if days and time and activity:
            task = self.sched.add_daytime_task(action_method, activity, days, None, time, kronos.method.threaded, [row], {})
            log.QUEUE( activity, self.sched, (action_method, activity, days, None, time, kronos.method.threaded, [row], {}), task.get_schedule_time(True) )
        else:
            log.ERR_QUEUE( activity, self.sched, (action_method, activity, days, None, time, kronos.method.threaded, [row], {}) )
    
    
    
    # converts Mon,Tue,... into numeric 1-7
    def days(self, s):
        weekdays = ["su", "mo", "tu", "we", "th", "fr", "sa", "su"]
        r = []
        if re.search("any|all|\*", s, re.I):
            return range(0,7)
        for day in re.findall("\w\w+", s.lower()):
            day = day[0:2]
            if day in weekdays:
                r.append(weekdays.index(day))
        return list(set(r))
        
    # get start time 18:00
    def time(self, s):
        r = re.search("(\d+):(\d+)", s)
        if r:
            return int(r.group(1)), int(r.group(2))
        
    # convert "18:00-19:15" to minutes
    def duration(self, s):
        try:
            r = re.search("(\d+:\d+)\s*(\.\.+|-+)\s*(\d+:\d+)", s)
            start = self.time(r.group(1))
            end = self.time(r.group(3))