Completed
Push — master ( 5c8ee4...f74340 )
by Felipe A.
50s
created

browsepy.plugin.player.register_plugin()   B

Complexity

Conditions 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 33
rs 8.8571
1
#!/usr/bin/env python
2
# -*- coding: UTF-8 -*-
3
4
import os.path
5
6
from flask import Blueprint, render_template, current_app, url_for
7
8
from browsepy.file import File
9
10
__basedir__= os.path.dirname(os.path.abspath(__file__))
11
12
player = Blueprint('player', __name__,
13
    url_prefix='/play',
14
    template_folder=os.path.join(__basedir__, 'templates'),
15
    static_folder=os.path.join(__basedir__, 'static'),
16
    )
17
18
media_map = {
19
    'audio/mpeg': 'mp3',
20
    'audio/mp4': 'mp4',
21
    'audio/ogg': 'ogg',
22
    'audio/webm': 'webm',
23
    'audio/wav': 'wav',
24
25
    'video/mpeg': 'mp4',
26
    'video/mp4': 'mp4',
27
    'video/ogg': 'ogg',
28
    'video/ogv': 'ogg',
29
    'video/webm': 'webm',
30
}
31
32
@player.route('/audio/<path:path>')
33
def audio(path):
34
    f = File.from_urlpath(path)
35
    m = media_map[f.type]
36
    return render_template('audio.player.html', file=f, directory=f, media_format=m)
37
38
@player.route('/video/<path:path>')
39
def video(path):
40
    return render_template('video.player.html')
41
42
@player.route('/list/<path:path>')
43
def playlist(path):
44
    return render_template('list.player.html')
45
46
def register_plugin(manager):
47
    manager.register_blueprint(player)
48
49
    style = manager.style_class('player.static', filename='css/browse.css')
50
    manager.register_widget(style)
51
    
52
    widget = manager.button_class(css='play')
53
    manager.register_action(
54
        'player.audio',
55
        widget,
56
        mimetypes=(
57
            'audio/mpeg',
58
            'audio/mp4',
59
            'audio/ogg',
60
            'audio/webm',
61
            'audio/wav',
62
        ))
63
    manager.register_action(
64
        'player.video',
65
        widget,
66
        mimetypes=(
67
            'video/mpeg',
68
            'video/mp4',
69
            'video/ogg',
70
            'video/ogv',
71
            'video/webm',
72
        ))
73
    manager.register_action(
74
        'player.playlist',
75
        widget,
76
        mimetypes=(
77
            'audio/x-mpegurl', # m3u, m3u8
78
            'audio/x-scpls', # pls
79
        ))
80