annotate libervia/backend/plugins/plugin_misc_radiocol.py @ 4340:ea72364131d5 default tip @

doc (components): Update Email Gateway documentation: A section has been added to explain how attachments are handled. fix 453
author Goffi <goffi@goffi.org>
date Tue, 03 Dec 2024 00:53:18 +0100
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
4 # SAT plugin for managing Radiocol
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
10 # (at your option) any later version.
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
15 # GNU Affero General Public License for more details.
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
20 from libervia.backend.core.i18n import _, D_
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
21 from libervia.backend.core.constants import Const as C
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
22 from libervia.backend.core.log import getLogger
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
23
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
24 log = getLogger(__name__)
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.words.xish import domish
577
593331663b80 plugin radiocol: songs are deleted once played (Q&D need to be reworked once file are properly transfered to server)
Goffi <goffi@goffi.org>
parents: 572
diff changeset
26 from twisted.internet import reactor
593331663b80 plugin radiocol: songs are deleted once played (Q&D need to be reworked once file are properly transfered to server)
Goffi <goffi@goffi.org>
parents: 572
diff changeset
27 from twisted.words.protocols.jabber import jid
849
c5a8f602662b plugin room_game, radiocol: RoomGame.send returns a Deferred.
souliane <souliane@mailoo.org>
parents: 828
diff changeset
28 from twisted.internet import defer
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
29 from libervia.backend.core import exceptions
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
30 import os.path
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
31 import copy
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
32 import time
577
593331663b80 plugin radiocol: songs are deleted once played (Q&D need to be reworked once file are properly transfered to server)
Goffi <goffi@goffi.org>
parents: 572
diff changeset
33 from os import unlink
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
34
1542
94901070478e plugins: added new MissingModule exceptions to plugins using third party modules
Goffi <goffi@goffi.org>
parents: 1411
diff changeset
35 try:
94901070478e plugins: added new MissingModule exceptions to plugins using third party modules
Goffi <goffi@goffi.org>
parents: 1411
diff changeset
36 from mutagen.oggvorbis import OggVorbis, OggVorbisHeaderError
94901070478e plugins: added new MissingModule exceptions to plugins using third party modules
Goffi <goffi@goffi.org>
parents: 1411
diff changeset
37 from mutagen.mp3 import MP3, HeaderNotFoundError
94901070478e plugins: added new MissingModule exceptions to plugins using third party modules
Goffi <goffi@goffi.org>
parents: 1411
diff changeset
38 from mutagen.easyid3 import EasyID3
94901070478e plugins: added new MissingModule exceptions to plugins using third party modules
Goffi <goffi@goffi.org>
parents: 1411
diff changeset
39 from mutagen.id3 import ID3NoHeaderError
94901070478e plugins: added new MissingModule exceptions to plugins using third party modules
Goffi <goffi@goffi.org>
parents: 1411
diff changeset
40 except ImportError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 raise exceptions.MissingModule(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
42 "Missing module Mutagen, please download/install from https://bitbucket.org/lazka/mutagen"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
43 )
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44
717
358018c5c398 plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents: 714
diff changeset
45
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
46 NC_RADIOCOL = "http://www.goffi.org/protocol/radiocol"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
47 RADIOC_TAG = "radiocol"
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
50 C.PI_NAME: "Radio collective plugin",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
51 C.PI_IMPORT_NAME: "Radiocol",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
52 C.PI_TYPE: "Exp",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
53 C.PI_PROTOCOLS: [],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
54 C.PI_DEPENDENCIES: ["XEP-0045", "XEP-0249", "ROOM-GAME"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
55 C.PI_MAIN: "Radiocol",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
56 C.PI_HANDLER: "yes",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 C.PI_DESCRIPTION: _("""Implementation of radio collective"""),
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 }
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
60
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
61 # Number of songs needed in the queue before we start playing
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
62 QUEUE_TO_START = 2
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
63 # Maximum number of songs in the queue (the song being currently played doesn't count)
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
64 QUEUE_LIMIT = 2
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
65
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66
718
074970227bc0 plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents: 717
diff changeset
67 class Radiocol(object):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
68 def inherit_from_room_game(self, host):
718
074970227bc0 plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents: 717
diff changeset
69 global RoomGame
074970227bc0 plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents: 717
diff changeset
70 RoomGame = host.plugins["ROOM-GAME"].__class__
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 self.__class__ = type(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
72 self.__class__.__name__, (self.__class__, RoomGame, object), {}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 )
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
76 log.info(_("Radio collective initialization"))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
77 self.inherit_from_room_game(host)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 RoomGame._init_(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
80 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
81 PLUGIN_INFO,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 (NC_RADIOCOL, RADIOC_TAG),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
83 game_init={
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
84 "queue": [],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
85 "upload": True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
86 "playing": None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
87 "playing_time": 0,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
88 "to_delete": {},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 },
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
90 )
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 self.host = host
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
92 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
93 "radiocol_launch",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 in_sign="asss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 out_sign="",
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
97 method=self._prepare_room,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
98 async_=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
99 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
100 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
101 "radiocol_create",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
102 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
103 in_sign="sass",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
104 out_sign="",
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
105 method=self._create_game,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
106 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
107 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
108 "radiocol_song_added",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
109 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
110 in_sign="sss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
111 out_sign="",
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
112 method=self._radiocol_song_added,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
113 async_=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
114 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
115 host.bridge.add_signal(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
116 "radiocol_players", ".plugin", signature="ssass"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
117 ) # room_jid, referee, players, profile
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
118 host.bridge.add_signal(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
119 "radiocol_started", ".plugin", signature="ssasais"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
120 ) # room_jid, referee, players, [QUEUE_TO_START, QUEUE_LIMIT], profile
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
121 host.bridge.add_signal(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
122 "radiocol_song_rejected", ".plugin", signature="sss"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
123 ) # room_jid, reason, profile
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
124 host.bridge.add_signal(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
125 "radiocol_preload", ".plugin", signature="ssssssss"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 ) # room_jid, timestamp, filename, title, artist, album, profile
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
127 host.bridge.add_signal(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
128 "radiocol_play", ".plugin", signature="sss"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 ) # room_jid, filename, profile
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
130 host.bridge.add_signal(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
131 "radiocol_no_upload", ".plugin", signature="ss"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
132 ) # room_jid, profile
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
133 host.bridge.add_signal(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
134 "radiocol_upload_ok", ".plugin", signature="ss"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
135 ) # room_jid, profile
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
137 def __create_preload_elt(self, sender, song_added_elt):
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
138 preload_elt = copy.deepcopy(song_added_elt)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
139 preload_elt.name = "preload"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 preload_elt["sender"] = sender
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
141 preload_elt["timestamp"] = str(time.time())
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
142 # attributes filename, title, artist, album, length have been copied
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
143 # XXX: the frontend should know the temporary directory where file is put
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
144 return preload_elt
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
145
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
146 def _radiocol_song_added(self, referee_s, song_path, profile):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
147 return self.radiocol_song_added(jid.JID(referee_s), song_path, profile)
1411
8767c0bb7d48 plugin radiocol: radiocolSongAdded now gets a JID as argument, add _radiocolSongAdded working with unicode for bridge calls
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
148
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
149 def radiocol_song_added(self, referee, song_path, profile):
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
150 """This method is called by libervia when a song has been uploaded
1411
8767c0bb7d48 plugin radiocol: radiocolSongAdded now gets a JID as argument, add _radiocolSongAdded working with unicode for bridge calls
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
151 @param referee (jid.JID): JID of the referee in the room (room userhost + '/' + nick)
8767c0bb7d48 plugin radiocol: radiocolSongAdded now gets a JID as argument, add _radiocolSongAdded working with unicode for bridge calls
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
152 @param song_path (unicode): absolute path of the song added
8767c0bb7d48 plugin radiocol: radiocolSongAdded now gets a JID as argument, add _radiocolSongAdded working with unicode for bridge calls
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
153 @param profile_key (unicode): %(doc_profile_key)s
849
c5a8f602662b plugin room_game, radiocol: RoomGame.send returns a Deferred.
souliane <souliane@mailoo.org>
parents: 828
diff changeset
154 @return: a Deferred instance
c5a8f602662b plugin room_game, radiocol: RoomGame.send returns a Deferred.
souliane <souliane@mailoo.org>
parents: 828
diff changeset
155 """
1359
83127a4c89ce plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1257
diff changeset
156 # XXX: this is a Q&D way for the proof of concept. In the future, the song should
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
157 # be streamed to the backend using XMPP file copy
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
158 # Here we cheat because we know we are on the same host, and we don't
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
159 # check data. Referee will have to parse the song himself to check it
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
160 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
161 if song_path.lower().endswith(".mp3"):
901
c238d2c02237 plugin radiocol: add MP3 support
souliane <souliane@mailoo.org>
parents: 849
diff changeset
162 actual_song = MP3(song_path)
c238d2c02237 plugin radiocol: add MP3 support
souliane <souliane@mailoo.org>
parents: 849
diff changeset
163 try:
c238d2c02237 plugin radiocol: add MP3 support
souliane <souliane@mailoo.org>
parents: 849
diff changeset
164 song = EasyID3(song_path)
c238d2c02237 plugin radiocol: add MP3 support
souliane <souliane@mailoo.org>
parents: 849
diff changeset
165
c238d2c02237 plugin radiocol: add MP3 support
souliane <souliane@mailoo.org>
parents: 849
diff changeset
166 class Info(object):
c238d2c02237 plugin radiocol: add MP3 support
souliane <souliane@mailoo.org>
parents: 849
diff changeset
167 def __init__(self, length):
c238d2c02237 plugin radiocol: add MP3 support
souliane <souliane@mailoo.org>
parents: 849
diff changeset
168 self.length = length
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169
901
c238d2c02237 plugin radiocol: add MP3 support
souliane <souliane@mailoo.org>
parents: 849
diff changeset
170 song.info = Info(actual_song.info.length)
c238d2c02237 plugin radiocol: add MP3 support
souliane <souliane@mailoo.org>
parents: 849
diff changeset
171 except ID3NoHeaderError:
c238d2c02237 plugin radiocol: add MP3 support
souliane <souliane@mailoo.org>
parents: 849
diff changeset
172 song = actual_song
c238d2c02237 plugin radiocol: add MP3 support
souliane <souliane@mailoo.org>
parents: 849
diff changeset
173 else:
c238d2c02237 plugin radiocol: add MP3 support
souliane <souliane@mailoo.org>
parents: 849
diff changeset
174 song = OggVorbis(song_path)
c238d2c02237 plugin radiocol: add MP3 support
souliane <souliane@mailoo.org>
parents: 849
diff changeset
175 except (OggVorbisHeaderError, HeaderNotFoundError):
1359
83127a4c89ce plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1257
diff changeset
176 # this file is not ogg vorbis nor mp3, we reject it
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
177 self.delete_file(song_path) # FIXME: same host trick (see note above)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
178 return defer.fail(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
179 exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
180 D_(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
181 "The uploaded file has been rejected, only Ogg Vorbis and MP3 songs are accepted."
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
182 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
183 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
184 )
901
c238d2c02237 plugin radiocol: add MP3 support
souliane <souliane@mailoo.org>
parents: 849
diff changeset
185
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
186 attrs = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
187 "filename": os.path.basename(song_path),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
188 "title": song.get("title", ["Unknown"])[0],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
189 "artist": song.get("artist", ["Unknown"])[0],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
190 "album": song.get("album", ["Unknown"])[0],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
191 "length": str(song.info.length),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
192 }
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
193 radio_data = self.games[
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
194 referee.userhostJID()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
195 ] # FIXME: referee comes from Libervia's client side, it's unsecure
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
196 radio_data["to_delete"][
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
197 attrs["filename"]
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
198 ] = song_path # FIXME: works only because of the same host trick, see the note under the docstring
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
199 return self.send(referee, ("", "song_added"), attrs, profile=profile)
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
200
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
201 def play_next(self, room_jid, profile):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
202 """ "Play next song in queue if exists, and put a timer
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
203 which trigger after the song has been played to play next one"""
1359
83127a4c89ce plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1257
diff changeset
204 # TODO: songs need to be erased once played or found invalids
577
593331663b80 plugin radiocol: songs are deleted once played (Q&D need to be reworked once file are properly transfered to server)
Goffi <goffi@goffi.org>
parents: 572
diff changeset
205 # ==> unlink done the Q&D way with the same host trick (see above)
1359
83127a4c89ce plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1257
diff changeset
206 radio_data = self.games[room_jid]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
207 if len(radio_data["players"]) == 0:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
208 log.debug(_("No more participants in the radiocol: cleaning data"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
209 radio_data["queue"] = []
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
210 for filename in radio_data["to_delete"]:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
211 self.delete_file(filename, radio_data)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
212 radio_data["to_delete"] = {}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
213 queue = radio_data["queue"]
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
214 if not queue:
1359
83127a4c89ce plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1257
diff changeset
215 # nothing left to play, we need to wait for uploads
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
216 radio_data["playing"] = None
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
217 return
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
218 song = queue.pop(0)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
219 filename, length = song["filename"], float(song["length"])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
220 self.send(room_jid, ("", "play"), {"filename": filename}, profile=profile)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
221 radio_data["playing"] = song
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
222 radio_data["playing_time"] = time.time()
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
223
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
224 if not radio_data["upload"] and len(queue) < QUEUE_LIMIT:
1359
83127a4c89ce plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1257
diff changeset
225 # upload is blocked and we now have resources to get more, we reactivate it
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
226 self.send(room_jid, ("", "upload_ok"), profile=profile)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
227 radio_data["upload"] = True
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
228
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
229 reactor.callLater(length, self.play_next, room_jid, profile)
1359
83127a4c89ce plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1257
diff changeset
230 # we wait more than the song length to delete the file, to manage poorly reactive networks/clients
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
231 reactor.callLater(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
232 length + 90, self.delete_file, filename, radio_data
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
233 ) # FIXME: same host trick (see above)
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
234
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
235 def delete_file(self, filename, radio_data=None):
764
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
236 """
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
237 Delete a previously uploaded file.
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
238 @param filename: filename to delete, or full filepath if radio_data is None
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
239 @param radio_data: current game data
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
240 @return: True if the file has been deleted
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
241 """
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
242 if radio_data:
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
243 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
244 file_to_delete = radio_data["to_delete"][filename]
764
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
245 except KeyError:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
246 log.error(_("INTERNAL ERROR: can't find full path of the song to delete"))
764
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
247 return False
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
248 else:
d0e809014ea2 plugin radiocol: fix wrong call of deleteFile
souliane <souliane@mailoo.org>
parents: 746
diff changeset
249 file_to_delete = filename
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
250 try:
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
251 unlink(file_to_delete)
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
252 except OSError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
253 log.error(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
254 _("INTERNAL ERROR: can't find %s on the file system" % file_to_delete)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
255 )
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
256 return False
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
257 return True
455
72522263cbc9 plugin RadioCol: basic functionnality working approximately
Goffi <goffi@goffi.org>
parents: 453
diff changeset
258
717
358018c5c398 plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents: 714
diff changeset
259 def room_game_cmd(self, mess_elt, profile):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
260 from_jid = jid.JID(mess_elt["from"])
1359
83127a4c89ce plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1257
diff changeset
261 room_jid = from_jid.userhostJID()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
262 nick = self.host.plugins["XEP-0045"].get_room_nick(room_jid, profile)
826
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
263
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
264 radio_elt = mess_elt.firstChildElement()
1359
83127a4c89ce plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1257
diff changeset
265 radio_data = self.games[room_jid]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
266 if "queue" in radio_data:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
267 queue = radio_data["queue"]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
268
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
269 from_referee = self.is_referee(room_jid, from_jid.resource)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
270 to_referee = self.is_referee(room_jid, jid.JID(mess_elt["to"]).user)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
271 is_player = self.is_player(room_jid, nick)
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
272 for elt in radio_elt.elements():
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
273 if not from_referee and not (to_referee and elt.name == "song_added"):
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
274 continue # sender must be referee, expect when a song is submitted
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
275 if not is_player and (elt.name not in ("started", "players")):
826
71f8e996f765 plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents: 825
diff changeset
276 continue # user is in the room but not playing
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
277
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
278 if elt.name in (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
279 "started",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
280 "players",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
281 ): # new game created and/or players list updated
717
358018c5c398 plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents: 714
diff changeset
282 players = []
358018c5c398 plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents: 714
diff changeset
283 for player in elt.elements():
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
284 players.append(str(player))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
285 signal = (
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
286 self.host.bridge.radiocol_started
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
287 if elt.name == "started"
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
288 else self.host.bridge.radiocol_players
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
289 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
290 signal(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
291 room_jid.userhost(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
292 from_jid.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
293 players,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
294 [QUEUE_TO_START, QUEUE_LIMIT],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
295 profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
296 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
297 elif elt.name == "preload": # a song is in queue and must be preloaded
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
298 self.host.bridge.radiocol_preload(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
299 room_jid.userhost(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
300 elt["timestamp"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
301 elt["filename"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
302 elt["title"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
303 elt["artist"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
304 elt["album"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
305 elt["sender"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
306 profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
307 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
308 elif elt.name == "play":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
309 self.host.bridge.radiocol_play(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
310 room_jid.userhost(), elt["filename"], profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
311 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
312 elif elt.name == "song_rejected": # a song has been refused
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
313 self.host.bridge.radiocol_song_rejected(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
314 room_jid.userhost(), elt["reason"], profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
315 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
316 elif elt.name == "no_upload":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
317 self.host.bridge.radiocol_no_upload(room_jid.userhost(), profile)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
318 elif elt.name == "upload_ok":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
319 self.host.bridge.radiocol_upload_ok(room_jid.userhost(), profile)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
320 elif elt.name == "song_added": # a song has been added
1359
83127a4c89ce plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1257
diff changeset
321 # FIXME: we are KISS for the proof of concept: every song is added, to a limit of 3 in queue.
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
322 # Need to manage some sort of rules to allow peoples to send songs
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
323 if len(queue) >= QUEUE_LIMIT:
1359
83127a4c89ce plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1257
diff changeset
324 # there are already too many songs in queue, we reject this one
83127a4c89ce plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1257
diff changeset
325 # FIXME: add an error code
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
326 self.send(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
327 from_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
328 ("", "song_rejected"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
329 {"reason": "Too many songs in queue"},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
330 profile=profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
331 )
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
332 return
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 577
diff changeset
333
1359
83127a4c89ce plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1257
diff changeset
334 # The song is accepted and added in queue
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
335 preload_elt = self.__create_preload_elt(from_jid.resource, elt)
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
336 queue.append(preload_elt)
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
337
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
338 if len(queue) >= QUEUE_LIMIT:
1359
83127a4c89ce plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1257
diff changeset
339 # We are at the limit, we refuse new upload until next play
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
340 self.send(room_jid, ("", "no_upload"), profile=profile)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
341 radio_data["upload"] = False
457
fbe7c9118ce4 plugin radiocol: working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 456
diff changeset
342
714
ecc5a5b34ee1 plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents: 712
diff changeset
343 self.send(room_jid, preload_elt, profile=profile)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
344 if not radio_data["playing"] and len(queue) == QUEUE_TO_START:
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
345 # We have not started playing yet, and we have QUEUE_TO_START
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
346 # songs in queue. We can now start the party :)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
347 self.play_next(room_jid, profile)
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
348 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
349 log.error(_("Unmanaged game element: %s") % elt.name)
746
539f278bc265 plugin room_games, radiocol: send the current queue to new players
souliane <souliane@mailoo.org>
parents: 718
diff changeset
350
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
351 def get_sync_data_for_player(self, room_jid, nick):
1359
83127a4c89ce plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1257
diff changeset
352 game_data = self.games[room_jid]
828
8f335c03eebb plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance
souliane <souliane@mailoo.org>
parents: 827
diff changeset
353 elements = []
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
354 if game_data["playing"]:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
355 preload = copy.deepcopy(game_data["playing"])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
356 current_time = game_data["playing_time"] + 1 if self.testing else time.time()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
357 preload["filename"] += "#t=%.2f" % (current_time - game_data["playing_time"])
828
8f335c03eebb plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance
souliane <souliane@mailoo.org>
parents: 827
diff changeset
358 elements.append(preload)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
359 play = domish.Element(("", "play"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
360 play["filename"] = preload["filename"]
828
8f335c03eebb plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance
souliane <souliane@mailoo.org>
parents: 827
diff changeset
361 elements.append(play)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
362 if len(game_data["queue"]) > 0:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
363 elements.extend(copy.deepcopy(game_data["queue"]))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
364 if len(game_data["queue"]) == QUEUE_LIMIT:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
365 elements.append(domish.Element(("", "no_upload")))
828
8f335c03eebb plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance
souliane <souliane@mailoo.org>
parents: 827
diff changeset
366 return elements