zeya team mailing list archive
-
zeya team
-
Mailing list archive
-
Message #00063
PATCH: PLS Support
Hello:
I have extended my earlier support for m3u playlist handling to now
support PLS playlists as well. It seems to work fine for me. please test it!
Please find the new pls.py file and the patch to the other files.
Let me know if you observe any weird/incorrect behavior.
Best,
Amit
--
Journal: http://amitksaha.wordpress.com
µ-blog: http://twitter.com/amitsaha
IRC: cornucopic on #scheme, #lisp, #math, #linux
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009, 2010 Amit Saha
#
# This file is part of Zeya.
#
# Zeya is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# Zeya 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 Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Zeya. If not, see <http://www.gnu.org/licenses/>.
# pls backend
import os.path
import sys
from backends import LibraryBackend
from backends import extract_metadata
class PlsBackend(LibraryBackend):
def __init__(self, file_path=None):
self.pls_file = file_path
# Check if the file exists so that we can fail-fast if necessary.
if not os.path.exists(self.pls_file):
print "Error: no pls file was found at %r." % (self.pls_file,)
print "Please check the pls file location, or try --backend=dir instead."
sys.exit(1)
def get_library_contents(self):
# Sequence of dicts contanining the metadata for all the songs.
library = []
# Dict mapping keys to the original filenames.
self.file_list = {}
next_index = 0
try:
for line in open(self.pls_file):
# Ignore lines in the pls file starting with '#'.
if line.startswith('#'):
continue
# only read lines starting with 'File'
if line.startswith('File'):
#read the filename into filename
filename = line.rstrip('\r\n')[line.find("=")+1:len(line)]
try:
metadata = extract_metadata(os.path.abspath(filename))
except ValueError:
continue
metadata['key'] = next_index
self.file_list[next_index] = filename
library.append(metadata)
next_index = next_index + 1
return library
except IOError:
print "Error: could not read the specified playlist (%r)" \
% (self.pls_file,)
sys.exit(1)
def get_filename_from_key(self, key):
return self.file_list[int(key)]
diff --git a/INSTALL b/INSTALL
index 68116cb..6f7acdc 100644
--- a/INSTALL
+++ b/INSTALL
@@ -42,9 +42,9 @@ INSTALLATION INSTRUCTIONS
$ zeya.py --backend=rhythmbox
- 'playlist': read files from the specified m3u playlist file
+ 'playlist': read files from the specified m3u or PLS playlist file
- $ zeya.py --backend=playlist --path=/path/to/your/m3u/file
+ $ zeya.py --backend=playlist --path=/path/to/your/m3u/pls/file
CLIENT SUPPORT
diff --git a/doc/zeya.1 b/doc/zeya.1
index 5ba4b20..a0b934a 100644
--- a/doc/zeya.1
+++ b/doc/zeya.1
@@ -43,7 +43,7 @@ rhythmbox
Read from current user's Rhythmbox library.
.TP
playlist
-Read from the playlist (.m3u file) specified by
+Read from the playlist (.m3u/.pls file) specified by
\*(T<\fB\-\-path\fR\*(T>.
.RE
.TP
diff --git a/options.py b/options.py
index a6eb6c4..3d9799f 100644
--- a/options.py
+++ b/options.py
@@ -117,7 +117,7 @@ Options:
--path=PATH
For --backend=dir, the directory in which to look for music. (Default: ./)
- For --backend=playlist, the absolute path to a .m3u file.
+ For --backend=playlist, the absolute path to a .m3u file, or a .pls file
-b, --bitrate=N
Specify the bitrate for output streams, in kbits/sec. (default: 64)
diff --git a/zeya.py b/zeya.py
index fc6e798..aa56972 100755
--- a/zeya.py
+++ b/zeya.py
@@ -309,8 +309,12 @@ def get_backend(backend_type):
from directory import DirectoryBackend
return DirectoryBackend(path)
elif backend_type == 'playlist':
- from m3u import M3uBackend
- return M3uBackend(path)
+ if path.endswith('m3u'):
+ from m3u import M3uBackend
+ return M3uBackend(path)
+ else:
+ from pls import PlsBackend
+ return PlsBackend(path)
else:
raise ValueError("Invalid backend %r" % (backend_type,))
Follow ups