Browse Source

Add a debug mode

- a "[debug mode]" line is add when printing FIP datas
- a timestamp is used as suffix for Icecast2 metadata
Yann Weber 8 years ago
parent
commit
fe9df34ee6
2 changed files with 12 additions and 3 deletions
  1. 1
    0
      conf-sample.ini
  2. 11
    3
      fip_current.py

+ 1
- 0
conf-sample.ini View File

@@ -1,4 +1,5 @@
1 1
 [conf]
2
+debug=false
2 3
 host=127.0.0.1:8000
3 4
 mount=/fip.mp3
4 5
 login=admin

+ 11
- 3
fip_current.py View File

@@ -15,11 +15,13 @@
15 15
 # You should have received a copy of the GNU General Public License
16 16
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 17
 
18
+import time
18 19
 import requests
19 20
 import configparser
20 21
 from argparse import ArgumentParser
21 22
 
22 23
 API_URL = 'http://www.fipradio.fr/livemeta/7'
24
+DEBUG = False
23 25
 
24 26
 
25 27
 def main():
@@ -39,9 +41,10 @@ def main():
39 41
         default='conf.ini',
40 42
         help="Configuration file")
41 43
     args = parser.parse_args()
44
+    conf = configparser.ConfigParser()
45
+    conf.read(args.conf)
46
+    globals()['DEBUG'] = conf.get('conf', 'debug', fallback="False").lower() == 'true'
42 47
     if args.update:
43
-        conf = configparser.ConfigParser()
44
-        conf.read(args.conf)
45 48
         host = conf.get('conf', 'host', fallback='127.0.0.1:8000')
46 49
         mount = conf.get('conf', 'mount', fallback='/example.ogg')
47 50
         login = conf.get('conf', 'login', fallback='admin')
@@ -89,12 +92,15 @@ Album :\t\t{album}
89 92
 Visual :\t{image}
90 93
 Youtube :\t{youtube}
91 94
 """
92
-    return infos.format(
95
+    res = infos.format(
93 96
         title=item['title'].title(),
94 97
         author=item['authors'].title(),
95 98
         album=item['titreAlbum'].title(),
96 99
         image=item['visual'],
97 100
         youtube=item['lienYoutube'])
101
+    if globals()['DEBUG']:
102
+        res = "[debug mode]\n"+res
103
+    return res
98 104
 
99 105
 
100 106
 def icecast_infos():
@@ -106,6 +112,8 @@ def icecast_infos():
106 112
         infos += ' - '+item['authors'].title()
107 113
     if len(item['titreAlbum']):
108 114
         infos += ' ('+item['titreAlbum'].title()+')'
115
+    if globals()['DEBUG']:
116
+        infos = infos + str(time.time())
109 117
     return infos
110 118
 
111 119
 

Loading…
Cancel
Save