Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Sublime Music
Sublime Music
Commits
7e03316e
Verified
Commit
7e03316e
authored
Feb 11, 2020
by
Sumner Evans
💬
Browse files
Create a token for every song played to reduce number of songs exposed at any given time
parent
6a542771
Pipeline
#117116106
passed with stages
in 7 minutes and 54 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
12 deletions
+25
-12
sublime/players.py
sublime/players.py
+25
-12
No files found.
sublime/players.py
View file @
7e03316e
import
logging
import
threading
from
uuid
import
UUID
from
urllib.parse
import
urlparse
import
base64
import
io
import
socket
import
logging
import
mimetypes
from
typing
import
Callable
,
List
,
Any
,
Optional
from
time
import
sleep
import
os
import
socket
import
threading
from
concurrent.futures
import
ThreadPoolExecutor
,
Future
from
time
import
sleep
from
typing
import
Callable
,
List
,
Any
,
Optional
from
urllib.parse
import
urlparse
from
uuid
import
UUID
import
pychromecast
import
mpv
import
bottle
import
mpv
import
pychromecast
from
sublime.config
import
AppConfiguration
from
sublime.cache_manager
import
CacheManager
...
...
@@ -219,12 +222,13 @@ class ChromecastPlayer(Player):
self
.
daemon
=
True
self
.
host
=
host
self
.
port
=
port
self
.
token
=
None
self
.
app
=
bottle
.
Bottle
()
@
self
.
app
.
route
(
'/'
)
def
index
():
return
'''
'
return
'''
<h1>Sublime Music Local Music Server</h1>
<p>
Sublime Music uses this port as a server for serving music
...
...
@@ -232,8 +236,10 @@ class ChromecastPlayer(Player):
</p>
'''
@
self
.
app
.
route
(
'/s
ong
/<id>'
)
@
self
.
app
.
route
(
'/s/<id>'
)
def
stream_song
(
id
):
if
bottle
.
request
.
query
.
get
(
't'
)
!=
self
.
token
:
raise
bottle
.
HTTPError
(
status
=
401
,
body
=
'Invalid token.'
)
song
=
CacheManager
.
get_song_details
(
id
).
result
()
filename
=
CacheManager
.
get_song_filename_or_stream
(
song
)[
0
]
with
open
(
filename
,
'rb'
)
as
fin
:
...
...
@@ -246,6 +252,9 @@ class ChromecastPlayer(Player):
bottle
.
response
.
set_header
(
'Accept-Ranges'
,
'bytes'
)
return
song_buffer
.
read
()
def
set_token
(
self
,
token
):
self
.
token
=
token
def
run
(
self
):
bottle
.
run
(
self
.
app
,
host
=
self
.
host
,
port
=
self
.
port
)
...
...
@@ -395,8 +404,12 @@ class ChromecastPlayer(Player):
# If it's a local file, then see if we can serve it over the LAN.
if
not
stream_scheme
:
if
self
.
serve_over_lan
:
token
=
base64
.
b64encode
(
os
.
urandom
(
64
)).
decode
(
'ascii'
)
for
r
in
((
'+'
,
'.'
),
(
'/'
,
'-'
),
(
'='
,
'_'
)):
token
=
token
.
replace
(
*
r
)
self
.
server_thread
.
set_token
(
token
)
host
=
f
'
{
self
.
host_ip
}
:
{
self
.
port
}
'
file_or_url
=
f
'http://
{
host
}
/s
ong
/
{
song
.
id
}
'
file_or_url
=
f
'http://
{
host
}
/s/
{
song
.
id
}
?t=
{
token
}
'
else
:
file_or_url
,
_
=
CacheManager
.
get_song_filename_or_stream
(
song
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment