Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
intranet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Leo Colisson
intranet
Commits
90bc6569
Commit
90bc6569
authored
Dec 17, 2014
by
Valentin Samir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[tv] Génération de playlist pour la tv
parent
d9bdc2ed
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
23 deletions
+63
-23
apps/tv/urls.py
apps/tv/urls.py
+5
-3
apps/tv/views.py
apps/tv/views.py
+45
-5
templates/tv/index.html
templates/tv/index.html
+13
-15
No files found.
apps/tv/urls.py
View file @
90bc6569
from
django.conf.urls
import
patterns
as
patterns
from
django.conf.urls
import
patterns
,
url
import
views
urlpatterns
=
patterns
(
''
,
(
'^$'
,
views
.
tv
),
(
'^auth$'
,
views
.
icecast_auth
),
url
(
'^$'
,
views
.
tv
,
name
=
"index"
),
url
(
'^auth$'
,
views
.
icecast_auth
,
name
=
"icecast_auth"
),
url
(
'^radio/(?P<radio>.+).m3u$'
,
views
.
radio_playlist
,
name
=
"radio_playlist"
),
url
(
'^(?P<tv>.+).m3u$'
,
views
.
tv_playlist
,
name
=
"tv_playlist"
),
)
apps/tv/views.py
View file @
90bc6569
...
...
@@ -14,12 +14,14 @@ import tv.radio.config as tv_config
from
django.conf
import
settings
import
django.shortcuts
from
django.shortcuts
import
redirect
from
django.views.decorators.csrf
import
csrf_exempt
from
django.http
import
HttpResponse
,
HttpResponseForbidden
from
django.http
import
HttpResponse
,
HttpResponseForbidden
,
HttpResponseNotFound
#from django.contrib.auth.decorators import login_required
from
django.contrib
import
messages
from
django.contrib.auth.models
import
User
from
django.template
import
RequestContext
from
django.core.urlresolvers
import
reverse
from
decorators
import
request_passes_test
...
...
@@ -57,6 +59,10 @@ def chaines():
except
:
return
{}
def
check_local
(
request
):
ip
=
ipaddr
.
IPAddress
(
get_client_ip
(
request
))
return
True
in
[
ip
in
net
for
net
in
net_crans
]
def
check_local_or_logged
(
request
):
ip
=
ipaddr
.
IPAddress
(
get_client_ip
(
request
))
return
True
in
[
ip
in
net
for
net
in
net_crans
]
or
request
.
user
.
is_authenticated
()
...
...
@@ -69,8 +75,18 @@ def tv(request):
tnt
=
[]
sat
=
[]
else
:
tnt
=
[(
name
,
"udp://@%s:1234"
%
tv_dns
.
idn
(
name
,
fqdn
=
True
,
charset
=
None
),
image_url_for_channel
(
ip
))
for
(
name
,
ip
)
in
chaines
().
get
(
'TNT'
,
{}).
items
()]
sat
=
[(
name
,
"udp://@%s:1234"
%
tv_dns
.
idn
(
name
,
fqdn
=
True
,
charset
=
None
),
image_url_for_channel
(
ip
))
for
(
name
,
ip
)
in
chaines
().
get
(
'SAT'
,
{}).
items
()]
tnt
=
[
(
name
,
"udp://@%s:1234"
%
tv_dns
.
idn
(
name
,
fqdn
=
True
,
charset
=
None
),
image_url_for_channel
(
ip
),
reverse
(
"tv:tv_playlist"
,
kwargs
=
{
'tv'
:
name
})
)
for
(
name
,
ip
)
in
chaines
().
get
(
'TNT'
,
{}).
items
()]
sat
=
[
(
name
,
"udp://@%s:1234"
%
tv_dns
.
idn
(
name
,
fqdn
=
True
,
charset
=
None
),
image_url_for_channel
(
ip
),
reverse
(
"tv:tv_playlist"
,
kwargs
=
{
'tv'
:
name
})
)
for
(
name
,
ip
)
in
chaines
().
get
(
'SAT'
,
{}).
items
()]
# radio=[(name, "udp://@%s:1234" % tv_dns.idn(name, fqdn=True, charset=None), image_url_for_channel(ip)) for (name, ip) in chaines().get('Radio', {}).items()]
radio
=
[]
user_auth
=
request
.
user
.
is_authenticated
()
...
...
@@ -81,8 +97,9 @@ def tv(request):
userpass
=
""
radio
.
append
(
(
name
,
"http://%stv.crans.org:8000/%s"
%
(
userpass
,
params
[
0
]),
image_url_for_channel
(
params
[
1
]))
"http://%stv.crans.org/%s"
%
(
userpass
,
params
[
0
]),
image_url_for_channel
(
params
[
1
]),
reverse
(
"tv:radio_playlist"
,
kwargs
=
{
'radio'
:
params
[
0
]})),
)
key
=
lambda
s
:
s
[
0
].
lower
()
tnt
.
sort
(
key
=
key
)
...
...
@@ -91,6 +108,23 @@ def tv(request):
params
=
{
'tnt'
:
tnt
,
'sat'
:
sat
,
'radio'
:
radio
,
'user'
:
request
.
user
}
return
django
.
shortcuts
.
render_to_response
(
"tv/index.html"
,
params
,
context_instance
=
RequestContext
(
request
))
@
request_passes_test
(
check_local_or_logged
)
def
radio_playlist
(
request
,
radio
):
if
radio
in
tv_config
.
multicast_tag
[
"Radio"
]:
if
request
.
user
.
is_authenticated
():
userpass
=
"%s:%s@"
%
(
request
.
user
.
username
,
radio_password
(
request
.
user
,
radio
))
else
:
userpass
=
""
return
HttpResponse
(
"http://%stv.crans.org/%s
\n
"
%
(
userpass
,
radio
),
content_type
=
"audio/x-mpegurl"
)
else
:
return
redirect
(
"tv:index"
)
def
tv_playlist
(
request
,
tv
):
if
check_local
(
request
):
return
HttpResponse
(
"udp://@%s:1234
\n
"
%
tv_dns
.
idn
(
tv
,
fqdn
=
True
,
charset
=
None
),
content_type
=
"audio/x-mpegurl"
)
else
:
return
redirect
(
"tv:index"
)
def
radio_password
(
user
,
radio
=
""
):
if
radio
.
startswith
(
"/"
):
radio
=
radio
[
1
:]
...
...
@@ -109,6 +143,12 @@ def icecast_auth(request):
return
HttpResponseForbidden
()
if
POST
[
"action"
]
==
"listener_add"
:
ip
=
ipaddr
.
IPAddress
(
POST
[
"ip"
])
if
str
(
ip
)
==
"127.0.0.1"
:
if
POST
.
get
(
'ClientHeader.x-auth'
,
''
)
!=
u
'4b4cdb4fb7556214dea60b639845d2d5'
:
# untrust proxy
return
HttpResponseForbidden
()
else
:
ip
=
ipaddr
.
IPAddress
(
POST
[
'ClientHeader.x-real-ip'
])
# Si ip crans on accepte
if
True
in
[
ip
in
net
for
net
in
net_crans
]:
return
response
...
...
templates/tv/index.html
View file @
90bc6569
...
...
@@ -85,14 +85,15 @@ function add(url, vlc){
}
catch
(
e
){}
}
function
play
(
url
){
if
(
!
test_vlc_plugin
()){
return
false
;
}
if
(
url
==
playing
){
return
false
;
}
else
{
playing
=
url
;
}
if
(
!
test_vlc_plugin
()){
playing
=
false
;
return
false
;
}
var
vlc
=
document
.
getElementById
(
"
vlc
"
);
document
.
getElementById
(
'
player_div
'
).
style
.
visibility
=
"
inherit
"
;
add
(
url
,
vlc
);
...
...
@@ -125,7 +126,7 @@ function warn_vlc_plugin(){
li
.
appendChild
(
document
.
createTextNode
(
'
Le
'
));
li
.
appendChild
(
a
);
li
.
appendChild
(
document
.
createTextNode
(
'
est nécessaire pour regarder la télévision ou écouter la radio.
'
));
li
.
setAttribute
(
"
class
"
,
"
warning
"
);
li
.
setAttribute
(
"
class
"
,
"
error
"
);
li
.
setAttribute
(
"
id
"
,
"
warning_vlc_plugin
"
);
ul
.
appendChild
(
li
);
...
...
@@ -137,15 +138,16 @@ function unwarn_vlc_plugin(){
}
}
function
play_radio
(
url
){
if
(
!
test_vlc_plugin
()){
return
false
;
}
document
.
getElementById
(
'
player_div
'
).
style
.
visibility
=
"
hidden
"
;
if
(
url
==
playing
){
return
false
;
}
else
{
playing
=
url
;
}
if
(
!
test_vlc_plugin
()){
playing
=
false
;
return
false
;
}
var
vlc
=
document
.
getElementById
(
"
vlc
"
);
add
(
url
,
vlc
);
volume
(
document
.
getElementById
(
"
volume_slide
"
).
value
);
...
...
@@ -198,8 +200,8 @@ function init(){
<input
id=
"volume_slide"
type=
"range"
min=
"0"
max=
"200"
onclick=
"volume(this.value)"
onchange=
"volume(this.value)"
/><span
id=
"range"
>
NaN%
</span>
{% if tnt %}
<ul>
{% for key, url, img in tnt %}
<li
class=
"tv"
><a
href=
"{{
url
}}"
onclick=
"return play('{{url}}')"
>
{% for key, url, img
, pls
in tnt %}
<li
class=
"tv"
><a
href=
"{{
pls
}}"
onclick=
"return play('{{url}}')"
>
<div
class=
"image_tv"
>
<img
src=
"{{img}}"
/>
<span
class=
"image_tv"
>
{{key}}
</span>
...
...
@@ -219,12 +221,8 @@ function init(){
</ul>
{% endif %}
</ul><br
clear=
"all"
/><ul>
{% for key, url, img in radio %}
{% if user.is_authenticated %}
<li
class=
"tv"
><a
href=
"{{url}}"
onclick=
"return play_radio('{{url}}')"
>
{% else %}
<li
class=
"tv"
><a
href=
"{{url}}.m3u"
onclick=
"return play_radio('{{url}}')"
>
{% endif %}
{% for key, url, img, pls in radio %}
<li
class=
"tv"
><a
href=
"{{pls}}"
onclick=
"return play_radio('{{url}}')"
>
<div
class=
"image_tv"
>
<img
src=
"{{img}}"
/>
<span
class=
"image_tv"
>
{{key}}
</span>
...
...
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