forked from jmooremcc/plugin.program.super.favourites
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaylist.py
More file actions
117 lines (89 loc) · 2.89 KB
/
playlist.py
File metadata and controls
117 lines (89 loc) · 2.89 KB
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
#
# Copyright (C) 2015-
# Sean Poyser (seanpoyser@gmail.com)
#
# This Program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with XBMC; see the file COPYING. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
# http://www.gnu.org/copyleft/gpl.html
#
import xbmc
import os
import utils
import sfile
#PLAYLIST_EXT = '.m3u|.xsp|.strm'
PLAYLIST_EXT = '.m3u|.m3u8'
def play(cmd):
import sfile
if cmd.lower().startswith('activatewindow'):
playlist = cmd.split(',', 1)
playlist = playlist[-1][:-1]
cmd = 'PlayMedia(%s)' % playlist
elif sfile.exists(cmd):
#cmd = 'PlayMedia(%s)' % cmd
playFile(cmd)
return
xbmc.executebuiltin(cmd)
def playFile(path):
items = parse(sfile.readlines(path))
utils.playItems(items)
def getPlaylist():
root = utils.HOME.split(os.sep, 1)[0] + os.sep
playlist = xbmcgui.Dialog().browse(1, utils.GETTEXT(30148), 'files', PLAYLIST_EXT, False, False, root)
if playlist and playlist != root:
return playlist
return None
def parseFolder(folder):
try: current, dirs, files = sfile.walk(folder)
except: return []
items = []
for file in files:
try:
path = os.path.join(current, file)
file = file.rsplit('.', 1)
ext = file[-1]
file = file[0]
if ext in PLAYLIST_EXT:
items.append([path, file])
except:
pass
return items
def parse(playlist):
if len(playlist) == 0:
return []
items = []
path = ''
title = ''
try:
for line in playlist:
line = line.strip()
if line.startswith('#EXTINF:'):
title = line.split(':', 1)[-1].split(',', 1)[-1]
if len(title) == 0:
title = "Unnamed" #SJP
else:
path = line.replace('rtmp://$OPT:rtmp-raw=', '')
if len(path) > 0 and len(title) > 0:
items.append([title, path])
path = ''
title = ''
except:
pass
return items
def isPlaylist(cmd):
cmd = cmd.lower().replace(',return', '')
if cmd.endswith('.m3u")'):
return True
if cmd.endswith('.m3u8")'):
return True
return False