-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.py
executable file
·149 lines (123 loc) · 4.45 KB
/
main.py
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# The Flask part of iposonic
#
# author: Roberto Polli robipolli@gmail.com (c) 2012
#
# License AGPLv3
#
# TODO manage argv for:
# * music_folders
# * authentication backend
# * reset db
#
from __future__ import unicode_literals
import logging
logging.basicConfig(level=logging.INFO)
import sys
import os
os.path.supports_unicode_filenames = True
import argparse
from threading import Thread
from iposonic import Iposonic
from webapp import Dbh
from webapp import app, log
from authorizer import Authorizer
# Import all app views
# TODO move to a view module
import view.browse
import view.playlist
import view.user
import view.media
import view.list
def yappize():
try:
# profiling
import yappi
import signal
def signal_handler(signal_n, frame):
print('You pressed Ctrl+C!')
yappi.stop()
yappi.print_stats(open("yappi.out", "w"))
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
yappi.start()
except:
pass
def run(argc, argv):
parser = argparse.ArgumentParser(
description='Iposonic is a SubSonic compatible streaming server.'
+ 'Run with #python ./main.py -c /opt/music')
parser.add_argument('-c', dest='collection', metavar=None, type=str,
nargs="+", required=True,
help='Music collection path')
parser.add_argument('-t', dest='tmp_dir', metavar=None, type=str,
nargs=None, default=os.path.expanduser('~/.iposonic'),
help='Temporary directory, defaults to ~/.iposonic')
parser.add_argument('--profile', metavar=None, type=bool,
nargs='?', const=True, default=False,
help='profile with yappi')
parser.add_argument(
'--access-file', dest='access_file', action=None, type=str,
default=os.path.expanduser('~/.iposonic_auth'),
help='Access file for user authentication, defaults to ~/.iposonic_auth. Use --noauth to disable authentication.')
parser.add_argument(
'--noauth', dest='noauth', action=None, type=bool,
nargs='?', const=True, default=False,
help='Disable authentication.')
parser.add_argument(
'--free-coverart', dest='free_coverart', action=None, type=bool,
const=True, default=False, nargs='?',
help='Do not authenticate requests to getCoverArt. Default is False: iposonic requires authentication for every request.')
parser.add_argument('--resetdb', dest='resetdb', action=None, type=bool,
const=True, default=False, nargs='?',
help='Drop database and cache directories and recreate them.')
parser.add_argument(
'--rename-non-utf8', dest='rename_non_utf8', action=None, type=bool,
const=True, default=False, nargs='?',
help='Rename non utf8 files to utf8 guessing encoding. When false, iposonic support only utf8 filenames.')
args = parser.parse_args()
print(args)
if args.profile:
yappize()
app.config.update(args.__dict__)
for x in args.collection:
assert(os.path.isdir(x)), "Missing music folder: %s" % x
app.iposonic = Iposonic(args.collection, dbhandler=Dbh,
recreate_db=args.resetdb, tmp_dir=args.tmp_dir)
app.iposonic.db.init_db()
# While developing don't enforce authentication
# otherwise you can use a credential file
# or specify your users inline
skip_authentication = args.noauth
app.authorizer = Authorizer(
mock=skip_authentication, access_file=args.access_file)
#
# Run cover_art downloading thread
#
from mediamanager.cover_art import cover_art_worker, cover_art_mock
for i in range(1):
t = Thread(target=cover_art_worker, args=[app.iposonic.cache_dir])
t.daemon = True
t.start()
#
# Run scrobbling thread
#
from mediamanager.scrobble import scrobble_worker
for i in range(1):
t = Thread(target=scrobble_worker, args=[])
t.daemon = True
t.start()
#
# Run walker thread
#
from scanner import walk_music_folder
for i in range(1):
t = Thread(target=walk_music_folder, args=[app.iposonic])
t.daemon = True
t.start()
app.run(host='0.0.0.0', port=5000, debug=False)
if __name__ == "__main__":
argc, argv = len(sys.argv), sys.argv
run(argc, argv)